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.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22398 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Mike Alexander 2012-09-17 01:09:59 +00:00
parent c66dec15f7
commit 3f130f2c1b

View File

@ -499,13 +499,8 @@ load_user_config(void)
/* Parse command line options, using GOption interface */ /* Parse command line options, using GOption interface */
static void 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) if (args_remaining)
file_to_load = args_remaining[0]; file_to_load = args_remaining[0];
@ -800,6 +795,7 @@ int
main(int argc, char ** argv) main(int argc, char ** argv)
{ {
GError *error = NULL; GError *error = NULL;
GOptionContext *context;
#if !defined(G_THREADS_ENABLED) || defined(G_THREADS_IMPL_NONE) #if !defined(G_THREADS_ENABLED) || defined(G_THREADS_IMPL_NONE)
# error "No GLib thread implementation available!" # error "No GLib thread implementation available!"
@ -840,26 +836,31 @@ main(int argc, char ** argv)
qof_log_set_default(QOF_LOG_INFO); qof_log_set_default(QOF_LOG_INFO);
gnc_gtk_add_rc_file (); gnc_gtk_add_rc_file ();
if (!gtk_init_with_args (&argc, &argv,
_("- GnuCash personal and small business finance management"), /* Parse the arguments. We can't let gtk_init_with_args do it since
options, * it fails if the GUI can't be initialized before parsing any arguments.
GETTEXT_PACKAGE, */
&error) context = g_option_context_new (_("- GnuCash personal and small business finance management"));
&& !add_quotes_file) g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
{ g_option_context_add_group (context, gtk_get_option_group(FALSE));
g_printerr(_("%s\nRun '%s --help' to see a full list of available command line options.\n"), if (!g_option_context_parse (context, &argc, &argv, &error))
_("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"), g_printerr (_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
error->message, argv[0]); error->message, argv[0]);
g_error_free (error); g_error_free (error);
return 1; return 1;
} }
gnucash_command_line(&argc, argv); 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."),
argv[0]);
return 1;
}
gnucash_command_line();
gnc_print_unstable_message(); gnc_print_unstable_message();
gnc_module_system_init(); gnc_module_system_init();