r22398 - gnucash/trunk/src/bin - Parse arguments before initializing GTK so --add-price-quotes works

Mike Alexander mta at code.gnucash.org
Sun Sep 16 21:10:00 EDT 2012


Author: mta
Date: 2012-09-16 21:09:59 -0400 (Sun, 16 Sep 2012)
New Revision: 22398
Trac: http://svn.gnucash.org/trac/changeset/22398

Modified:
   gnucash/trunk/src/bin/gnucash-bin.c
Log:
Parse arguments before initializing GTK so --add-price-quotes works
when the GUI can't be initialized.  gtk_init_with_args fails before
parsing the arguments if the GUI can't be initialized.

Modified: gnucash/trunk/src/bin/gnucash-bin.c
===================================================================
--- gnucash/trunk/src/bin/gnucash-bin.c	2012-09-16 15:17:24 UTC (rev 22397)
+++ gnucash/trunk/src/bin/gnucash-bin.c	2012-09-17 01:09:59 UTC (rev 22398)
@@ -499,13 +499,8 @@
 /* Parse command line options, using GOption interface */
 
 static void
-gnucash_command_line(int *argc, char **argv)
+gnucash_command_line()
 {
-    const gchar *gconf_path = NULL;
-    GError *error = NULL;
-    GOptionContext *context;
-
-
     if (args_remaining)
         file_to_load = args_remaining[0];
 
@@ -800,6 +795,7 @@
 main(int argc, char ** argv)
 {
     GError *error = NULL;
+    GOptionContext *context;
 
 #if !defined(G_THREADS_ENABLED) || defined(G_THREADS_IMPL_NONE)
 #    error "No GLib thread implementation available!"
@@ -840,26 +836,31 @@
     qof_log_set_default(QOF_LOG_INFO);
 
     gnc_gtk_add_rc_file ();
-    if (!gtk_init_with_args (&argc, &argv,
-            _("- GnuCash personal and small business finance management"),
-            options,
-            GETTEXT_PACKAGE,
-            &error)
+    
+    /* Parse the arguments.  We can't let gtk_init_with_args do it since
+     * it fails if the GUI can't be initialized before parsing any arguments.
+     */
+    context = g_option_context_new (_("- GnuCash personal and small business finance management"));
+    g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
+    g_option_context_add_group (context, gtk_get_option_group(FALSE));
+    if (!g_option_context_parse (context, &argc, &argv, &error))
+    {
+        g_printerr (_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
+                    error->message, argv[0]);
+        g_error_free (error);
+        return 1;
+    }
+    g_option_context_free (context);
+    
+    if (!gtk_init_check (&argc, &argv)
         && !add_quotes_file)
     {
         g_printerr(_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
-                   _("Error: could not initialize graphical user interface and option add_price_quotes was not set."),
+                   _("Error: could not initialize graphical user interface and option add-price-quotes was not set."),
                    argv[0]);
         return 1;
     }
-    else if (error)
-    {
-        g_printerr (_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
-                    error->message, argv[0]);
-        g_error_free (error);
-        return 1;
-    }
-    gnucash_command_line(&argc, argv);
+    gnucash_command_line();
     gnc_print_unstable_message();
 
     gnc_module_system_init();



More information about the gnucash-changes mailing list