[evolution] EShell: Add a read-only "client-cache" property.



commit 208d779b00a410dc1f1734ad1c8b3ccdc53db3d3
Author: Matthew Barnes <mbarnes redhat com>
Date:   Wed Feb 13 09:52:28 2013 -0500

    EShell: Add a read-only "client-cache" property.
    
    Give EShell its own EClientCache.  This should be used throughout
    Evolution, wherever an EClient is needed.
    
    New functions:
    
        e_shell_get_client_cache()

 doc/reference/libeshell/libeshell-sections.txt |    1 +
 shell/e-shell.c                                |   86 ++++++++++++++++++++++--
 shell/e-shell.h                                |    1 +
 3 files changed, 82 insertions(+), 6 deletions(-)
---
diff --git a/doc/reference/libeshell/libeshell-sections.txt b/doc/reference/libeshell/libeshell-sections.txt
index eaec920..5734ef3 100644
--- a/doc/reference/libeshell/libeshell-sections.txt
+++ b/doc/reference/libeshell/libeshell-sections.txt
@@ -8,6 +8,7 @@ e_shell_get_shell_backends
 e_shell_get_canonical_name
 e_shell_get_backend_by_name
 e_shell_get_backend_by_scheme
+e_shell_get_client_cache
 e_shell_get_shell_settings
 e_shell_get_registry
 e_shell_create_shell_window
diff --git a/shell/e-shell.c b/shell/e-shell.c
index f938f45..00bcd61 100644
--- a/shell/e-shell.c
+++ b/shell/e-shell.c
@@ -49,6 +49,7 @@ struct _EShellPrivate {
        GQueue alerts;
        EShellSettings *settings;
        ESourceRegistry *registry;
+       EClientCache *client_cache;
        GtkWidget *preferences_window;
 
        /* Shell Backends */
@@ -66,6 +67,8 @@ struct _EShellPrivate {
 
        guint inhibit_cookie;
 
+       gulong backend_died_handler_id;
+
        guint auto_reconnect            : 1;
        guint express_mode              : 1;
        guint meego_mode                : 1;
@@ -80,6 +83,7 @@ struct _EShellPrivate {
 
 enum {
        PROP_0,
+       PROP_CLIENT_CACHE,
        PROP_EXPRESS_MODE,
        PROP_MEEGO_MODE,
        PROP_SMALL_SCREEN_MODE,
@@ -518,6 +522,17 @@ shell_process_backend (EShellBackend *shell_backend,
 }
 
 static void
+shell_backend_died_cb (EClientCache *client_cache,
+                       EClient *client,
+                       EAlert *alert,
+                       EShell *shell)
+{
+       /* Backend crashes are quite serious.
+        * Post the alert to all shell views. */
+       e_shell_submit_alert (shell, alert);
+}
+
+static void
 shell_sm_quit_cb (EShell *shell,
                   gpointer user_data)
 {
@@ -623,6 +638,12 @@ shell_get_property (GObject *object,
                     GParamSpec *pspec)
 {
        switch (property_id) {
+               case PROP_CLIENT_CACHE:
+                       g_value_set_object (
+                               value, e_shell_get_client_cache (
+                               E_SHELL (object)));
+                       return;
+
                case PROP_EXPRESS_MODE:
                        g_value_set_boolean (
                                value, e_shell_get_express_mode (
@@ -695,6 +716,13 @@ shell_dispose (GObject *object)
                g_object_unref (alert);
        }
 
+       if (priv->backend_died_handler_id > 0) {
+               g_signal_handler_disconnect (
+                       priv->client_cache,
+                       priv->backend_died_handler_id);
+               priv->backend_died_handler_id = 0;
+       }
+
        if (priv->startup_view != NULL) {
                g_free (priv->startup_view);
                priv->startup_view = NULL;
@@ -710,6 +738,11 @@ shell_dispose (GObject *object)
                priv->registry = NULL;
        }
 
+       if (priv->client_cache != NULL) {
+               g_object_unref (priv->client_cache);
+               priv->client_cache = NULL;
+       }
+
        if (priv->preferences_window != NULL) {
                g_object_unref (priv->preferences_window);
                priv->preferences_window = NULL;
@@ -839,19 +872,29 @@ shell_initable_init (GInitable *initable,
                      GError **error)
 {
        GApplication *application = G_APPLICATION (initable);
-       EShellPrivate *priv;
-
-       priv = E_SHELL_GET_PRIVATE (initable);
+       EShell *shell = E_SHELL (initable);
+       ESourceRegistry *registry;
+       gulong handler_id;
 
        shell_add_actions (application);
 
-       priv->registry = e_source_registry_new_sync (cancellable, error);
-       if (priv->registry == NULL)
+       if (!g_application_register (application, cancellable, error))
                return FALSE;
 
-       if (!g_application_register (application, cancellable, error))
+       registry = e_source_registry_new_sync (cancellable, error);
+       if (registry == NULL)
                return FALSE;
 
+       shell->priv->registry = g_object_ref (registry);
+       shell->priv->client_cache = e_client_cache_new (registry);
+
+       handler_id = g_signal_connect (
+               shell->priv->client_cache, "backend-died",
+               G_CALLBACK (shell_backend_died_cb), shell);
+       shell->priv->backend_died_handler_id = handler_id;
+
+       g_object_unref (registry);
+
        return TRUE;
 }
 
@@ -879,6 +922,21 @@ e_shell_class_init (EShellClass *class)
        gtk_application_class->window_added = shell_window_added;
 
        /**
+        * EShell:client-cache:
+        *
+        * Shared #EClient instances.
+        **/
+       g_object_class_install_property (
+               object_class,
+               PROP_CLIENT_CACHE,
+               g_param_spec_object (
+                       "client-cache",
+                       "Client Cache",
+                       "Shared EClient instances",
+                       E_TYPE_CLIENT_CACHE,
+                       G_PARAM_READABLE));
+
+       /**
         * EShell:express-mode
         *
         * Express mode alters Evolution's user interface to be more
@@ -1372,6 +1430,22 @@ e_shell_get_backend_by_scheme (EShell *shell,
 }
 
 /**
+ * e_shell_get_client_cache:
+ * @shell: an #EShell
+ *
+ * Returns the #EClientCache instance for @shell.
+ *
+ * Returns: the #EClientCache instance for @shell
+ **/
+EClientCache *
+e_shell_get_client_cache (EShell *shell)
+{
+       g_return_val_if_fail (E_IS_SHELL (shell), NULL);
+
+       return shell->priv->client_cache;
+}
+
+/**
  * e_shell_get_shell_settings:
  * @shell: an #EShell
  *
diff --git a/shell/e-shell.h b/shell/e-shell.h
index a0ef1f6..bdbbf09 100644
--- a/shell/e-shell.h
+++ b/shell/e-shell.h
@@ -116,6 +116,7 @@ EShellBackend *     e_shell_get_backend_by_name     (EShell *shell,
                                                 const gchar *name);
 EShellBackend *        e_shell_get_backend_by_scheme   (EShell *shell,
                                                 const gchar *scheme);
+EClientCache * e_shell_get_client_cache        (EShell *shell);
 EShellSettings *e_shell_get_shell_settings     (EShell *shell);
 ESourceRegistry *
                e_shell_get_registry            (EShell *shell);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]