grim/guifications3

Parents afeee984c3d3
Children ba7c5c1bba66
added gf_get_option_group to correctly support the GOptionContext command line argument handlers. Basically any program using gflib can just use gf_get_option_group and add it to their GOptionContext and all the argument handling with be done correctly
--- a/gflib/gflib/gf_core.c Sun Aug 02 19:37:42 2009 -0500
+++ b/gflib/gflib/gf_core.c Sun Aug 02 23:51:04 2009 -0500
@@ -55,7 +55,7 @@
*****************************************************************************/
static gchar *prefs_uri = NULL;
-static GOptionEntry entries[] = {
+static GOptionEntry gflib_args[] = {
{
"prefs-uri", 0, 0, G_OPTION_ARG_STRING, &prefs_uri,
"The uri describing the preference engine and options.",
@@ -82,24 +82,6 @@
#endif /* ENABLE_NLS */
}
-static void
-parse_arguments(gint *argc, gchar ***argv) {
- GOptionContext *ctx = NULL;
- GError *err = NULL;
-
- ctx = g_option_context_new(NULL);
- g_option_context_add_main_entries(ctx, entries, GETTEXT_PACKAGE);
- g_option_context_parse(ctx, argc, argv, &err);
- g_option_context_free(ctx);
-
- if(err) {
- fprintf(stderr, "%s\n", err->message);
- g_error_free(err);
-
- exit(1);
- }
-}
-
/******************************************************************************
* API
*****************************************************************************/
@@ -131,9 +113,6 @@
/* Initialize the GType system */
g_type_init();
- /* setup our command line arguments */
- parse_arguments(argc, argv);
-
/* setup the system log */
gf_log_init();
@@ -229,3 +208,27 @@
return "";
#endif
}
+
+/**
+ * gf_get_option_group:
+ *
+ * Returns a #GOptionGroup for the commandline arguments recognized by gflib.
+ * You should add this group to your #GOptionContext with
+ * g_option_context_add_group(), if you are using g_option_context_parse() to
+ * parse your commandline arguments.
+ *
+ * Returns: A #GOptionGroup for the command line arguments recognized by gflib.
+ */
+GOptionGroup *
+gf_get_option_group(void) {
+ GOptionGroup *group = NULL;
+
+ group = g_option_group_new("gflib", _("GfLib Options"),
+ _("Show gflib options"), NULL, NULL);
+
+ g_option_group_add_entries(group, gflib_args);
+ g_option_group_set_translation_domain(group, GETTEXT_PACKAGE);
+
+ return group;
+}
+
--- a/gflib/gflib/gf_core.h Sun Aug 02 19:37:42 2009 -0500
+++ b/gflib/gflib/gf_core.h Sun Aug 02 23:51:04 2009 -0500
@@ -31,6 +31,8 @@
const gchar *gf_lib_get_lib_version(void);
const gchar *gf_lib_get_website(void);
+GOptionGroup *gf_get_option_group(void);
+
G_END_DECLS
#endif /* GF_CORE_H */