From 37d437ae1c69c8c70f5a289ec59363fe21836255 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Fri, 12 Dec 2008 15:49:15 +0000 Subject: Add empathy_init(), empathy_gtk_init() and empathy_gtk_init_with_args(). They have to be called by any process using libempathy. svn path=/trunk/; revision=1966 --- libempathy-gtk/Makefile.am | 1 + libempathy-gtk/empathy-ui-utils.c | 41 +++++++++++++++++++++++++++++++++++++++ libempathy-gtk/empathy-ui-utils.h | 8 ++++++++ libempathy/Makefile.am | 1 + libempathy/empathy-utils.c | 27 ++++++++++++++++++++++++++ libempathy/empathy-utils.h | 1 + src/Makefile.am | 6 ------ src/empathy-logs.c | 16 ++++----------- src/empathy.c | 23 +++++----------------- 9 files changed, 88 insertions(+), 36 deletions(-) diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am index 17cfa4dc6..d2801762d 100644 --- a/libempathy-gtk/Makefile.am +++ b/libempathy-gtk/Makefile.am @@ -2,6 +2,7 @@ AM_CPPFLAGS = \ -I. \ -I$(top_srcdir) \ -DDATADIR=\""$(datadir)"\" \ + -DPKGDATADIR=\""$(pkgdatadir)"\" \ $(EMPATHY_CFLAGS) \ $(ENCHANT_CFLAGS) \ $(WARN_CFLAGS) diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c index cd5cf0766..693bd8137 100644 --- a/libempathy-gtk/empathy-ui-utils.c +++ b/libempathy-gtk/empathy-ui-utils.c @@ -49,6 +49,47 @@ #include #include +void +empathy_gtk_init (int *argc, char ***argv) +{ + static gboolean initialized = FALSE; + + if (initialized) + return; + + empathy_init (); + gtk_init (argc, argv); + gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), + PKGDATADIR G_DIR_SEPARATOR_S "icons"); + + initialized = TRUE; +} + +gboolean +empathy_gtk_init_with_args (int *argc, + char ***argv, + char *parameter_string, + GOptionEntry *entries, + char *translation_domain, + GError **error) +{ + static gboolean initialized = FALSE; + gboolean ret; + + if (initialized) + return TRUE; + + empathy_init (); + ret = gtk_init_with_args (argc, argv, parameter_string, entries, + translation_domain, error); + gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), + PKGDATADIR G_DIR_SEPARATOR_S "icons"); + + initialized = TRUE; + + return ret; +} + struct SizeData { gint width; gint height; diff --git a/libempathy-gtk/empathy-ui-utils.h b/libempathy-gtk/empathy-ui-utils.h index 4a6efc6d0..777ce8ee0 100644 --- a/libempathy-gtk/empathy-ui-utils.h +++ b/libempathy-gtk/empathy-ui-utils.h @@ -46,6 +46,14 @@ G_BEGIN_DECLS #define G_STR_EMPTY(x) ((x) == NULL || (x)[0] == '\0') +void empathy_gtk_init (int *argc, + char ***argv); +gboolean empathy_gtk_init_with_args (int *argc, + char ***argv, + char *parameter_string, + GOptionEntry *entries, + char *translation_domain, + GError **error); /* Glade */ void empathy_glade_get_file_simple (const gchar *filename, const gchar *root, diff --git a/libempathy/Makefile.am b/libempathy/Makefile.am index a25c1e799..fd6424b57 100644 --- a/libempathy/Makefile.am +++ b/libempathy/Makefile.am @@ -3,6 +3,7 @@ AM_CPPFLAGS = \ -I$(top_srcdir) \ -I$(top_builddir) \ -DDATADIR=\""$(datadir)"\" \ + -DLOCALEDIR=\""$(datadir)/locale"\" \ $(LIBEMPATHY_CFLAGS) \ $(WARN_CFLAGS) diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c index 671595e68..dc06081f3 100644 --- a/libempathy/empathy-utils.c +++ b/libempathy/empathy-utils.c @@ -43,6 +43,33 @@ #define DEBUG_FLAG EMPATHY_DEBUG_OTHER #include "empathy-debug.h" +void +empathy_init (void) +{ + static gboolean initialized = FALSE; + + if (initialized) + return; + + /* Setup glib. Threads are required for async GIO. */ + g_thread_init (NULL); + g_type_init (); + + /* Setup gettext */ + bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); + textdomain (GETTEXT_PACKAGE); + + /* Setup debug output for empathy and telepathy-glib */ + if (g_getenv ("EMPATHY_TIMING") != NULL) { + g_log_set_default_handler (tp_debug_timestamped_log_handler, NULL); + } + empathy_debug_set_flags (g_getenv ("EMPATHY_DEBUG")); + tp_debug_divert_messages (g_getenv ("EMPATHY_LOGFILE")); + + initialized = TRUE; +} + gchar * empathy_substring (const gchar *str, gint start, diff --git a/libempathy/empathy-utils.h b/libempathy/empathy-utils.h index 51ddd231f..9147b6991 100644 --- a/libempathy/empathy-utils.h +++ b/libempathy/empathy-utils.h @@ -42,6 +42,7 @@ G_BEGIN_DECLS +void empathy_init (void); /* Strings */ gchar * empathy_substring (const gchar *str, gint start, diff --git a/src/Makefile.am b/src/Makefile.am index 4112f65e4..d9c2b2aa4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,11 +1,5 @@ AM_CPPFLAGS = \ -I$(top_srcdir) \ - -DPREFIX="\"$(prefix)"\" \ - -DSYSCONFDIR=\""$(sysconfdir)"\" \ - -DDATADIR=\""$(datadir)"\" \ - -DPKGDATADIR=\""$(pkgdatadir)"\" \ - -DLIBDIR=\""$(libdir)"\" \ - -DLOCALEDIR=\""$(datadir)/locale"\" \ $(EMPATHY_CFLAGS) \ $(WARN_CFLAGS) diff --git a/src/empathy-logs.c b/src/empathy-logs.c index f49207ebf..f805f9094 100644 --- a/src/empathy-logs.c +++ b/src/empathy-logs.c @@ -21,15 +21,13 @@ */ #include - -#include #include - #include #include #include #include +#include static void destroy_cb (GtkWidget *dialog, @@ -43,16 +41,10 @@ main (int argc, char *argv[]) { GtkWidget *window; - gtk_init (&argc, &argv); - - if (g_getenv ("EMPATHY_TIMING") != NULL) { - g_log_set_default_handler (tp_debug_timestamped_log_handler, NULL); - } - empathy_debug_set_flags (g_getenv ("EMPATHY_DEBUG")); - tp_debug_divert_messages (g_getenv ("EMPATHY_LOGFILE")); + empathy_gtk_init (&argc, &argv); + g_set_application_name (PACKAGE_NAME); + gtk_window_set_default_icon_name ("empathy"); - gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), - PKGDATADIR G_DIR_SEPARATOR_S "icons"); window = empathy_log_window_show (NULL, NULL, FALSE, NULL); g_signal_connect (window, "destroy", diff --git a/src/empathy.c b/src/empathy.c index dc295be6d..8a0bf5abd 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -44,6 +44,7 @@ #include #include +#include #include @@ -400,30 +401,16 @@ main (int argc, char *argv[]) { NULL } }; - bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - startup_timestamp = get_startup_timestamp (); - if (!gtk_init_with_args (&argc, &argv, - _("- Empathy Instant Messenger"), - options, GETTEXT_PACKAGE, &error)) { - g_warning ("Error in gtk init: %s", error->message); + if (!empathy_gtk_init_with_args (&argc, &argv, + _("- Empathy Instant Messenger"), + options, GETTEXT_PACKAGE, &error)) { + g_warning ("Error in empathy init: %s", error->message); return EXIT_FAILURE; } - - if (g_getenv ("EMPATHY_TIMING") != NULL) { - g_log_set_default_handler (tp_debug_timestamped_log_handler, NULL); - } - empathy_debug_set_flags (g_getenv ("EMPATHY_DEBUG")); - tp_debug_divert_messages (g_getenv ("EMPATHY_LOGFILE")); - g_set_application_name (PACKAGE_NAME); - gtk_window_set_default_icon_name ("empathy"); - gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), - PKGDATADIR G_DIR_SEPARATOR_S "icons"); /* Setting up the bacon connection */ connection = bacon_message_connection_new ("empathy"); -- cgit v1.2.3