Replace gnome_program_init with gtk_init

This required some small reorganization of our setup code, but the end
result is that gnucash is now independent of libgnome.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22379 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Geert Janssens 2012-09-10 19:22:00 +00:00
parent 77bc7e3753
commit 3cf132b466
8 changed files with 148 additions and 237 deletions

View File

@ -861,11 +861,6 @@ then
AC_SUBST(GTK_CFLAGS)
AC_SUBST(GTK_LIBS)
PKG_CHECK_MODULES(GNOME, libgnomeui-2.0 >= 2.22)
AS_SCRUB_INCLUDE(GNOME_CFLAGS)
AC_SUBST(GNOME_CFLAGS)
AC_SUBST(GNOME_LIBS)
PKG_CHECK_MODULES(GNOMECANVAS, libgnomecanvas-2.0)
AS_SCRUB_INCLUDE(GNOMECANVAS_CFLAGS)
AC_SUBST(GNOMECANVAS_CFLAGS)

View File

@ -71,7 +71,6 @@ gnucash_LDADD = \
${GUILE_LIBS} \
${GLIB_LIBS} \
${GCONF_LIBS} \
${GNOME_LIBS} \
${GTK_LIBS}
GNUCASH_BIN_INSTALL_NAME=`echo ${BIN_NAME} | sed -e '$(transform)'`

View File

@ -28,7 +28,6 @@
#include <libguile.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <libgnome/libgnome.h>
#include "glib.h"
#include "gnc-module.h"
#include "gnc-path.h"
@ -74,12 +73,76 @@ static int is_development_version = FALSE;
#endif
/* Command-line option variables */
static int gnucash_show_version = 0;
static const char *add_quotes_file = NULL;
static int nofile = 0;
static const char *file_to_load = NULL;
static gchar **log_flags = NULL;
static gchar *log_to_filename = NULL;
static int gnucash_show_version = 0;
static int debugging = 0;
static int extra = 0;
static gchar **log_flags = NULL;
static gchar *log_to_filename = NULL;
static int nofile = 0;
static const gchar *gconf_path = NULL;
static const char *add_quotes_file = NULL;
static char *namespace_regexp = NULL;
static const char *file_to_load = NULL;
static gchar **args_remaining = NULL;
static GOptionEntry options[] =
{
{
"version", 'v', 0, G_OPTION_ARG_NONE, &gnucash_show_version,
N_("Show GnuCash version"), NULL
},
{
"debug", '\0', 0, G_OPTION_ARG_NONE, &debugging,
N_("Enable debugging mode: increasing logging to provide deep detail."), NULL
},
{
"extra", '\0', 0, G_OPTION_ARG_NONE, &extra,
N_("Enable extra/development/debugging features."), NULL
},
{
"log", '\0', 0, G_OPTION_ARG_STRING_ARRAY, &log_flags,
N_("Log level overrides, of the form \"log.ger.path={debug,info,warn,crit,error}\""),
NULL
},
{
"logto", '\0', 0, G_OPTION_ARG_STRING, &log_to_filename,
N_("File to log into; defaults to \"/tmp/gnucash.trace\"; can be \"stderr\" or \"stdout\"."),
NULL
},
{
"nofile", '\0', 0, G_OPTION_ARG_NONE, &nofile,
N_("Do not load the last file opened"), NULL
},
{
"gconf-path", '\0', 0, G_OPTION_ARG_STRING, &gconf_path,
N_("Set the prefix path for gconf queries"),
/* Translators: Argument description for autohelp; see
http://developer.gnome.org/doc/API/2.0/glib/glib-Commandline-option-parser.html */
N_("GCONFPATH")
},
{
"add-price-quotes", '\0', 0, G_OPTION_ARG_STRING, &add_quotes_file,
N_("Add price quotes to given GnuCash datafile"),
/* Translators: Argument description for autohelp; see
http://developer.gnome.org/doc/API/2.0/glib/glib-Commandline-option-parser.html */
N_("FILE")
},
{
"namespace", '\0', 0, G_OPTION_ARG_STRING, &namespace_regexp,
N_("Regular expression determining which namespace commodities will be retrieved"),
/* Translators: Argument description for autohelp; see
http://developer.gnome.org/doc/API/2.0/glib/glib-Commandline-option-parser.html */
N_("REGEXP")
},
{
G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &args_remaining, NULL, N_("[datafile]") },
{ NULL }
};
static void
gnc_print_unstable_message(void)
@ -438,82 +501,13 @@ load_user_config(void)
static void
gnucash_command_line(int *argc, char **argv)
{
int debugging = 0, extra = 0;
char *namespace_regexp = NULL;
const gchar *gconf_path = NULL;
GError *error = NULL;
GOptionContext *context;
GOptionEntry options[] =
{
{
"version", 'v', 0, G_OPTION_ARG_NONE, &gnucash_show_version,
_("Show GnuCash version"), NULL
},
{
"debug", '\0', 0, G_OPTION_ARG_NONE, &debugging,
_("Enable debugging mode: increasing logging to provide deep detail."), NULL
},
{
"extra", '\0', 0, G_OPTION_ARG_NONE, &extra,
_("Enable extra/development/debugging features."), NULL
},
{
"log", '\0', 0, G_OPTION_ARG_STRING_ARRAY, &log_flags,
_("Log level overrides, of the form \"log.ger.path={debug,info,warn,crit,error}\""),
NULL
},
{
"logto", '\0', 0, G_OPTION_ARG_STRING, &log_to_filename,
_("File to log into; defaults to \"/tmp/gnucash.trace\"; can be \"stderr\" or \"stdout\"."),
NULL
},
{
"nofile", '\0', 0, G_OPTION_ARG_NONE, &nofile,
_("Do not load the last file opened"), NULL
},
{
"gconf-path", '\0', 0, G_OPTION_ARG_STRING, &gconf_path,
_("Set the prefix path for gconf queries"),
/* Translators: Argument description for autohelp; see
http://developer.gnome.org/doc/API/2.0/glib/glib-Commandline-option-parser.html */
_("GCONFPATH")
},
{
"add-price-quotes", '\0', 0, G_OPTION_ARG_STRING, &add_quotes_file,
_("Add price quotes to given GnuCash datafile"),
/* Translators: Argument description for autohelp; see
http://developer.gnome.org/doc/API/2.0/glib/glib-Commandline-option-parser.html */
_("FILE")
},
{
"namespace", '\0', 0, G_OPTION_ARG_STRING, &namespace_regexp,
_("Regular expression determining which namespace commodities will be retrieved"),
/* Translators: Argument description for autohelp; see
http://developer.gnome.org/doc/API/2.0/glib/glib-Commandline-option-parser.html */
_("REGEXP")
},
{ NULL }
};
context = g_option_context_new (" [datafile]");
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_warning("Error parsing command line arguments: [%s]; try `gnucash --help` for available options.", error->message);
exit(1);
}
g_option_context_free (context);
if (error)
g_error_free(error);
if (*argc > 0)
file_to_load = argv[1];
if (args_remaining)
file_to_load = args_remaining[0];
if (gnucash_show_version)
{
@ -535,6 +529,7 @@ gnucash_command_line(int *argc, char **argv)
exit(0);
}
gnc_set_debugging(debugging);
gnc_set_extra(extra);
if (!gconf_path)
@ -547,7 +542,6 @@ gnucash_command_line(int *argc, char **argv)
}
gnc_set_gconf_path(g_strdup(gconf_path));
gnc_set_debugging(debugging);
if (namespace_regexp)
gnc_main_set_namespace_regexp(namespace_regexp);
@ -805,6 +799,8 @@ gnc_log_init()
int
main(int argc, char ** argv)
{
GError *error = NULL;
#if !defined(G_THREADS_ENABLED) || defined(G_THREADS_IMPL_NONE)
# error "No GLib thread implementation available!"
#endif
@ -843,45 +839,38 @@ main(int argc, char ** argv)
qof_log_init();
qof_log_set_default(QOF_LOG_INFO);
/* Note: setlocale will also be called later by gtk_init (which gets
* invoked by gnome_program_init), but that's too late. The locale
* must be properly set before parsing the command line arguments
* or filenames may be returned in a charset other than UTF-8 and
* not work with other glib calls.
*/
setlocale(LC_ALL, "");
gnc_gtk_add_rc_file ();
if (!gtk_init_with_args (&argc, &argv,
_("- GnuCash personal and small business finance management"),
options,
GETTEXT_PACKAGE,
&error)
&& !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;
}
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);
gnc_print_unstable_message();
gnc_module_system_init();
gnc_log_init();
if (add_quotes_file)
{
gchar *prefix = gnc_path_get_prefix ();
gchar *pkgsysconfdir = gnc_path_get_pkgsysconfdir ();
gchar *pkgdatadir = gnc_path_get_pkgdatadir ();
gchar *pkglibdir = gnc_path_get_pkglibdir ();
/* This option needs to run without a display, so we can't
initialize any GUI libraries. */
gnome_program_init(
PACKAGE, VERSION, LIBGNOME_MODULE,
argc, argv,
GNOME_PARAM_APP_PREFIX, prefix,
GNOME_PARAM_APP_SYSCONFDIR, pkgsysconfdir,
GNOME_PARAM_APP_DATADIR, pkgdatadir,
GNOME_PARAM_APP_LIBDIR, pkglibdir,
GNOME_PARAM_NONE);
g_free (prefix);
g_free (pkgsysconfdir);
g_free (pkgdatadir);
g_free (pkglibdir);
scm_boot_guile(argc, argv, inner_main_add_price_quotes, 0);
exit(0); /* never reached */
}
gnc_gnome_init (argc, argv, VERSION);
gnc_gui_init();
scm_boot_guile(argc, argv, inner_main, 0);
exit(0); /* never reached */

View File

@ -42,7 +42,7 @@ gchar *gnc_path_get_bindir()
}
/** Returns the libdir path, usually
* "$prefix/lib". Needed for gnome_program_init().
* "$prefix/lib".
*
* @returns A newly allocated string. */
gchar *gnc_path_get_libdir()
@ -52,7 +52,7 @@ gchar *gnc_path_get_libdir()
}
/** Returns the datadir path, usually
* "$prefix/share/gnucash". Needed for gnome_program_init().
* "$prefix/share/gnucash". Needed for gnc_gnome_locate_*().
*
* @returns A newly allocated string. */
gchar *gnc_path_get_pkgdatadir()
@ -78,7 +78,7 @@ gchar *gnc_path_get_pkgdocdir()
}
/** Returns the sysconfdir path, usually
* "$prefix/etc/gnucash". Needed for gnome_program_init().
* "$prefix/etc/gnucash".
*
* @returns A newly allocated string. */
gchar *gnc_path_get_pkgsysconfdir()

View File

@ -26,7 +26,7 @@
#include <glib.h>
/** Returns the installation prefix path, usually
* "$prefix". Needed for gnome_program_init().
* "$prefix".
*
* @returns A newly allocated string. */
gchar *gnc_path_get_prefix(void);
@ -38,13 +38,13 @@ gchar *gnc_path_get_prefix(void);
gchar *gnc_path_get_bindir(void);
/** Returns the libdir path, usually
* "$prefix/lib". Needed for gnome_program_init(void).
* "$prefix/lib".
*
* @returns A newly allocated string. */
gchar *gnc_path_get_libdir(void);
/** Returns the pkgdatadir path, usually
* "$prefix/share/gnucash". Needed for gnome_program_init(void).
* "$prefix/share/gnucash". Needed for gnc_gnome_locate_*().
*
* @returns A newly allocated string. */
gchar *gnc_path_get_pkgdatadir(void);
@ -56,7 +56,7 @@ gchar *gnc_path_get_pkgdatadir(void);
gchar *gnc_path_get_pkgdocdir(void);
/** Returns the pkgsysconfdir path, usually
* "$prefix/etc/gnucash". Needed for gnome_program_init(void).
* "$prefix/etc/gnucash".
*
* @returns A newly allocated string. */
gchar *gnc_path_get_pkgsysconfdir(void);

View File

@ -16,7 +16,6 @@ AM_CPPFLAGS = \
-I${top_srcdir}/src/libqof/qof \
${GLIB_CFLAGS} \
${GTK_CFLAGS} \
${GNOME_CFLAGS} \
${GCONF_CFLAGS} \
${GNOME_KEYRING_CFLAGS} \
${GUILE_INCS} \
@ -199,7 +198,7 @@ libgncmod_gnome_utils_la_LIBADD = \
${top_builddir}/src/app-utils/libgncmod-app-utils.la \
$(top_builddir)/lib/libc/libc-missing.la \
${top_builddir}/src/libqof/qof/libgnc-qof.la \
${GNOME_LIBS} \
${GTK_LIBS} \
${GCONF_LIBS} \
${GNOME_KEYRING_LIBS} \
${GUILE_LIBS} \

View File

@ -23,7 +23,6 @@
#include "config.h"
#include <gnome.h>
#include <glib/gi18n.h>
#include <libguile.h>
#include <gconf/gconf.h>
@ -62,7 +61,6 @@
#endif
static QofLogModule log_module = GNC_MOD_GUI;
static GnomeProgram *gnucash_program = NULL;
static int gnome_is_running = FALSE;
static int gnome_is_terminating = FALSE;
static int gnome_is_initialized = FALSE;
@ -170,7 +168,7 @@ gnc_configure_date_completion (void)
}
}
static void
void
gnc_gtk_add_rc_file (void)
{
const gchar *var;
@ -185,116 +183,6 @@ gnc_gtk_add_rc_file (void)
}
}
void
gnc_gnome_init (int argc, char **argv, const char * version)
{
gchar *prefix = gnc_path_get_prefix ();
gchar *pkgsysconfdir = gnc_path_get_pkgsysconfdir ();
gchar *pkgdatadir = gnc_path_get_pkgdatadir ();
gchar *pkglibdir = gnc_path_get_pkglibdir ();
gboolean installation_ok = TRUE;
/* Verify all the various directory before proceeding */
if (!g_file_test(pkgdatadir, G_FILE_TEST_IS_DIR))
{
g_critical("The installation data directory \"%s\" was not found. Your installation is incomplete and cannot be run.", pkgdatadir);
installation_ok = FALSE;
}
if (!g_file_test(pkglibdir, G_FILE_TEST_IS_DIR))
{
g_critical("The installation lib directory \"%s\" was not found. Your installation is incomplete and cannot be run.", pkglibdir);
installation_ok = FALSE;
}
if (!g_file_test(pkgsysconfdir, G_FILE_TEST_IS_DIR))
{
g_critical("The installation sysconf directory \"%s\" was not found. Your installation is incomplete and cannot be run.", pkgsysconfdir);
installation_ok = FALSE;
}
gnc_gtk_add_rc_file();
gnucash_program = gnome_program_init(
"gnucash", version, LIBGNOMEUI_MODULE,
argc, argv,
GNOME_PARAM_APP_PREFIX, prefix,
GNOME_PARAM_APP_SYSCONFDIR, pkgsysconfdir,
GNOME_PARAM_APP_DATADIR, pkgdatadir,
GNOME_PARAM_APP_LIBDIR, pkglibdir,
GNOME_PARAM_NONE);
if (!installation_ok)
{
/* The following string does not need translation because if
* it shows up, the program is unusable anyway. */
gnc_error_dialog(NULL, "The installation directories were not found.\n\ndatadir=%s\nlibdir=%s\nsysconfdir=%s\n\nYour installation is incomplete and cannot be run.",
pkgdatadir, pkglibdir, pkgsysconfdir);
/* gnc_error_dialog must not be called before gnome_program_init. */
}
g_free (prefix);
g_free (pkgsysconfdir);
g_free (pkgdatadir);
g_free (pkglibdir);
/* Did the installation directory check fail? Terminate
* immediately because it will inevitably fail in the glade file
* lookup. */
if (!installation_ok)
{
/* No correct installation? Shut down immediately. */
exit(-1);
}
#ifdef G_OS_WIN32
/* workaround for bug #421792 */
xmlCleanupInputCallbacks();
#endif
/* initialization required for gtkhtml (is it also needed for webkit?) */
gtk_widget_set_default_colormap (gdk_rgb_get_colormap ());
/* use custom icon */
{
int idx;
char *icon_filenames[] = {"gnucash-icon-16x16.png",
"gnucash-icon-32x32.png",
"gnucash-icon-48x48.png",
NULL
};
GList *icons = NULL;
char *fullname;
for (idx = 0; icon_filenames[idx] != NULL; idx++)
{
GdkPixbuf *buf = NULL;
fullname = gnc_filepath_locate_pixmap(icon_filenames[idx]);
if (fullname == NULL)
{
g_warning("couldn't find icon file [%s]", icon_filenames[idx]);
continue;
}
buf = gnc_gnome_get_gdkpixbuf(fullname);
if (buf == NULL)
{
g_warning("error loading image from [%s]", fullname);
g_free(fullname);
continue;
}
g_free(fullname);
icons = g_list_append(icons, buf);
}
gtk_window_set_default_icon_list(icons);
g_list_foreach(icons, (GFunc)g_object_unref, NULL);
g_list_free(icons);
}
assistant_gconf_install_check_schemas();
return;
}
#ifdef MAC_INTEGRATION
/* Don't be alarmed if this function looks strange to you: It's
@ -659,17 +547,54 @@ gnc_gui_init(void)
#ifdef MAC_INTEGRATION
gchar *data_dir;
#endif
int idx;
char *icon_filenames[] = {"gnucash-icon-16x16.png",
"gnucash-icon-32x32.png",
"gnucash-icon-48x48.png",
NULL
};
GList *icons = NULL;
char *fullname;
ENTER ("");
if (gnome_is_initialized)
{
return main_window;
/* use custom icon */
for (idx = 0; icon_filenames[idx] != NULL; idx++)
{
GdkPixbuf *buf = NULL;
fullname = gnc_filepath_locate_pixmap(icon_filenames[idx]);
if (fullname == NULL)
{
g_warning("couldn't find icon file [%s]", icon_filenames[idx]);
continue;
}
buf = gnc_gnome_get_gdkpixbuf(fullname);
if (buf == NULL)
{
g_warning("error loading image from [%s]", fullname);
g_free(fullname);
continue;
}
g_free(fullname);
icons = g_list_append(icons, buf);
}
gtk_window_set_default_icon_list(icons);
g_list_foreach(icons, (GFunc)g_object_unref, NULL);
g_list_free(icons);
/* initialization required for gtkhtml (is it also needed for webkit?) */
gtk_widget_set_default_colormap (gdk_rgb_get_colormap ());
g_set_application_name(PACKAGE_NAME);
gnc_show_splash_screen();
assistant_gconf_install_check_schemas();
gnome_is_initialized = TRUE;

View File

@ -37,8 +37,10 @@
#include <gnc-main-window.h>
/** Initialize the Gnome libraries. */
void gnc_gnome_init (int argc, char **argv, const char * version);
/** Load a gtk resource configuration file to customize gtk
* appearance and behviour.
*/
void gnc_gtk_add_rc_file (void);
/** Launch the default gnome help browser and open to a given link
* within a given file. This routine will display an error message
@ -86,6 +88,8 @@ GdkPixbuf * gnc_gnome_get_gdkpixbuf (const char *name);
*/
void gnc_shutdown (int exit_status);
/** Initialize the gnucash gui */
GncMainWindow *gnc_gui_init (void);
int gnc_ui_start_event_loop (void);
gboolean gnucash_ui_is_running (void);