From fd564be3203400024147469faaa7de0884861566 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Thu, 19 Feb 2009 01:36:04 +0000 Subject: Clean up the EMFormat stack. Add some GObject properties to bind to. Add some handy color conversion functions to e-util. svn path=/branches/kill-bonobo/; revision=37290 --- shell/e-shell-migrate.c | 14 +++++--------- shell/e-shell-window-private.c | 14 ++++++++------ shell/e-shell.c | 27 +++++++++++++++++++++++++-- shell/e-shell.h | 2 ++ 4 files changed, 40 insertions(+), 17 deletions(-) (limited to 'shell') diff --git a/shell/e-shell-migrate.c b/shell/e-shell-migrate.c index b4467028f4..aa3e1e0f97 100644 --- a/shell/e-shell-migrate.c +++ b/shell/e-shell-migrate.c @@ -85,7 +85,8 @@ shell_migrate_attempt (EShell *shell, } static void -shell_migrate_get_version (gint *major, +shell_migrate_get_version (EShell *shell, + gint *major, gint *minor, gint *micro) { @@ -97,9 +98,8 @@ shell_migrate_get_version (gint *major, old_data_dir = shell_migrate_get_old_data_dir (); key = GCONF_VERSION_KEY; - client = gconf_client_get_default (); + client = e_shell_get_gconf_client (shell); string = gconf_client_get_string (client, key, NULL); - g_object_unref (client); if (string != NULL) { /* Since 1.4.0 we've kept the version key in GConf. */ @@ -206,6 +206,7 @@ e_shell_migrate_attempt (EShell *shell) g_return_val_if_fail (E_IS_SHELL (shell), FALSE); + client = e_shell_get_gconf_client (shell); old_data_dir = shell_migrate_get_old_data_dir (); if (sscanf (BASE_VERSION, "%d.%d", &curr_major, &curr_minor) != 2) { @@ -215,7 +216,7 @@ e_shell_migrate_attempt (EShell *shell) curr_micro = atoi (UPGRADE_REVISION); - shell_migrate_get_version (&major, &minor, µ); + shell_migrate_get_version (shell, &major, &minor, µ); if (!(curr_major > major || (curr_major == major && curr_minor > minor) || @@ -253,10 +254,8 @@ e_shell_migrate_attempt (EShell *shell) _exit (EXIT_SUCCESS); /* Record a successful migration. */ - client = gconf_client_get_default (); string = g_strdup_printf ("%d.%d.%d", major, minor, micro); gconf_client_set_string (client, GCONF_VERSION_KEY, string, NULL); - g_object_unref (client); g_free (string); migrated = TRUE; @@ -264,7 +263,6 @@ e_shell_migrate_attempt (EShell *shell) check_old: key = GCONF_LAST_VERSION_KEY; - client = gconf_client_get_default (); /* Try to retrieve the last migrated version from GConf. */ string = gconf_client_get_string (client, key, NULL); @@ -321,8 +319,6 @@ check_old: gconf_client_set_string (client, key, string, NULL); g_free (string); - g_object_unref (client); - return TRUE; } diff --git a/shell/e-shell-window-private.c b/shell/e-shell-window-private.c index 02aac6cf10..bfaa87396b 100644 --- a/shell/e-shell-window-private.c +++ b/shell/e-shell-window-private.c @@ -26,13 +26,16 @@ shell_window_save_switcher_style_cb (GtkRadioAction *action, GtkRadioAction *current, EShellWindow *shell_window) { + EShell *shell; GConfClient *client; GtkToolbarStyle style; const gchar *key; const gchar *string; GError *error = NULL; - client = gconf_client_get_default (); + shell = e_shell_window_get_shell (shell_window); + client = e_shell_get_gconf_client (shell); + style = gtk_radio_action_get_current_value (action); key = "/apps/evolution/shell/view_defaults/buttons_style"; @@ -59,13 +62,12 @@ shell_window_save_switcher_style_cb (GtkRadioAction *action, g_warning ("%s", error->message); g_error_free (error); } - - g_object_unref (client); } static void shell_window_init_switcher_style (EShellWindow *shell_window) { + EShell *shell; GtkAction *action; GConfClient *client; GtkToolbarStyle style; @@ -76,7 +78,9 @@ shell_window_init_switcher_style (EShellWindow *shell_window) /* XXX GConfBridge doesn't let you convert between numeric properties * and string keys, so we have to create the binding manually. */ - client = gconf_client_get_default (); + shell = e_shell_window_get_shell (shell_window); + client = e_shell_get_gconf_client (shell); + action = ACTION (SWITCHER_STYLE_ICONS); key = "/apps/evolution/shell/view_defaults/buttons_style"; string = gconf_client_get_string (client, key, &error); @@ -99,8 +103,6 @@ shell_window_init_switcher_style (EShellWindow *shell_window) action, "changed", G_CALLBACK (shell_window_save_switcher_style_cb), shell_window); - - g_object_unref (client); } static void diff --git a/shell/e-shell.c b/shell/e-shell.c index e2d7761965..203e216344 100644 --- a/shell/e-shell.c +++ b/shell/e-shell.c @@ -40,6 +40,7 @@ struct _EShellPrivate { GList *watched_windows; EShellSettings *settings; + GConfClient *gconf_client; /* Shell Modules */ GList *loaded_modules; @@ -459,6 +460,11 @@ shell_dispose (GObject *object) priv->settings = NULL; } + if (priv->gconf_client != NULL) { + g_object_unref (priv->gconf_client); + priv->gconf_client = NULL; + } + g_list_foreach ( priv->loaded_modules, (GFunc) g_type_module_unuse, NULL); @@ -830,6 +836,7 @@ shell_init (EShell *shell) modules_by_scheme = g_hash_table_new (g_str_hash, g_str_equal); shell->priv->settings = g_object_new (E_TYPE_SHELL_SETTINGS, NULL); + shell->priv->gconf_client = gconf_client_get_default (); shell->priv->modules_by_name = modules_by_name; shell->priv->modules_by_scheme = modules_by_scheme; shell->priv->safe_mode = e_file_lock_exists (); @@ -1020,6 +1027,23 @@ e_shell_get_shell_settings (EShell *shell) return shell->priv->settings; } +/** + * e_shell_get_gconf_client: + * @shell: an #EShell + * + * Returns the default #GConfClient. This function is purely for + * convenience. The @shell owns the reference so you don't have to. + * + * Returns: the default #GConfClient + **/ +GConfClient * +e_shell_get_gconf_client (EShell *shell) +{ + g_return_val_if_fail (E_IS_SHELL (shell), NULL); + + return shell->priv->gconf_client; +} + /** * e_shell_create_shell_window: * @shell: an #EShell @@ -1055,10 +1079,9 @@ e_shell_create_shell_window (EShell *shell, const gchar *key; GError *error = NULL; - client = gconf_client_get_default (); + client = e_shell_get_gconf_client (shell); key = "/apps/evolution/shell/view_defaults/component_id"; gconf_client_set_string (client, key, view_name, &error); - g_object_unref (client); if (error != NULL) { g_warning ("%s", error->message); diff --git a/shell/e-shell.h b/shell/e-shell.h index 3f23779ee7..137900214d 100644 --- a/shell/e-shell.h +++ b/shell/e-shell.h @@ -29,6 +29,7 @@ #define E_SHELL_H #include +#include #include #include #include @@ -85,6 +86,7 @@ EShellModule * e_shell_get_module_by_name (EShell *shell, EShellModule * e_shell_get_module_by_scheme (EShell *shell, const gchar *scheme); EShellSettings *e_shell_get_shell_settings (EShell *shell); +GConfClient * e_shell_get_gconf_client (EShell *shell); GtkWidget * e_shell_create_shell_window (EShell *shell, const gchar *view_name); guint e_shell_handle_uris (EShell *shell, -- cgit v1.2.3