[evolution/gnome-3-8] ECalShellSidebar: Submit an EActivity when obtaining an EClient.



commit fb9b84844d64363a40d436804ce7713c79af8f34
Author: Matthew Barnes <mbarnes redhat com>
Date:   Thu Apr 25 10:00:14 2013 -0400

    ECalShellSidebar: Submit an EActivity when obtaining an EClient.
    
    Remove this status message nonsense that I came up with during the
    kill-bonobo rewrite.  Instead submit a real EActivity to the shell
    backend.  Mismanagement of the status message seems to be blocking
    application shut down in some cases.
    
    (cherry picked from commit d39a6e140208ea2261a88fda5dc1b174c9dde4a6)

 modules/calendar/e-cal-shell-sidebar.c |  109 +++++++++++++++++---------------
 1 files changed, 58 insertions(+), 51 deletions(-)
---
diff --git a/modules/calendar/e-cal-shell-sidebar.c b/modules/calendar/e-cal-shell-sidebar.c
index 8f744f8..88cdea5 100644
--- a/modules/calendar/e-cal-shell-sidebar.c
+++ b/modules/calendar/e-cal-shell-sidebar.c
@@ -55,12 +55,12 @@ struct _ECalShellSidebarPrivate {
        /* Not referenced, only for pointer comparison. */
        ESource *connecting_default_source_instance;
 
-       GCancellable *connecting_default_client;
-       GCancellable *loading_clients;
+       EActivity *connecting_default_client;
 };
 
 struct _ConnectClosure {
        ECalShellSidebar *cal_shell_sidebar;
+       EActivity *activity;
 
        /* For error messages. */
        gchar *unique_display_name;
@@ -92,25 +92,54 @@ connect_closure_new (ECalShellSidebar *cal_shell_sidebar,
                      ESource *source)
 {
        ConnectClosure *closure;
+       EAlertSink *alert_sink;
+       GCancellable *cancellable;
        ESourceRegistry *registry;
        ESourceSelector *selector;
+       EShellView *shell_view;
+       EShellBackend *shell_backend;
+       EShellContent *shell_content;
+       EShellSidebar *shell_sidebar;
+       gchar *text;
+
+       shell_sidebar = E_SHELL_SIDEBAR (cal_shell_sidebar);
+       shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
+       shell_backend = e_shell_view_get_shell_backend (shell_view);
+       shell_content = e_shell_view_get_shell_content (shell_view);
 
        selector = e_cal_shell_sidebar_get_selector (cal_shell_sidebar);
        registry = e_source_selector_get_registry (selector);
 
        closure = g_slice_new0 (ConnectClosure);
        closure->cal_shell_sidebar = g_object_ref (cal_shell_sidebar);
+       closure->activity = e_activity_new ();
        closure->unique_display_name =
                e_source_registry_dup_unique_display_name (
                registry, source, E_SOURCE_EXTENSION_CALENDAR);
 
+       text = g_strdup_printf (
+               _("Opening calendar '%s'"),
+               closure->unique_display_name);
+       e_activity_set_text (closure->activity, text);
+       g_free (text);
+
+       alert_sink = E_ALERT_SINK (shell_content);
+       e_activity_set_alert_sink (closure->activity, alert_sink);
+
+       cancellable = g_cancellable_new ();
+       e_activity_set_cancellable (closure->activity, cancellable);
+       g_object_unref (cancellable);
+
+       e_shell_backend_add_activity (shell_backend, closure->activity);
+
        return closure;
 }
 
 static void
 connect_closure_free (ConnectClosure *closure)
 {
-       g_object_unref (closure->cal_shell_sidebar);
+       g_clear_object (&closure->cal_shell_sidebar);
+       g_clear_object (&closure->activity);
 
        g_free (closure->unique_display_name);
 
@@ -145,19 +174,15 @@ cal_shell_sidebar_emit_status_message (ECalShellSidebar *cal_shell_sidebar,
 }
 
 static void
-cal_shell_sidebar_handle_connect_error (ECalShellSidebar *cal_shell_sidebar,
+cal_shell_sidebar_handle_connect_error (EActivity *activity,
                                         const gchar *unique_display_name,
                                         const GError *error)
 {
-       EShellView *shell_view;
-       EShellContent *shell_content;
-       EShellSidebar *shell_sidebar;
+       EAlertSink *alert_sink;
        gboolean cancelled = FALSE;
        gboolean offline_error;
 
-       shell_sidebar = E_SHELL_SIDEBAR (cal_shell_sidebar);
-       shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
-       shell_content = e_shell_view_get_shell_content (shell_view);
+       alert_sink = e_activity_get_alert_sink (activity);
 
        cancelled |= g_error_matches (
                error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
@@ -167,17 +192,17 @@ cal_shell_sidebar_handle_connect_error (ECalShellSidebar *cal_shell_sidebar,
        offline_error = g_error_matches (
                error, E_CLIENT_ERROR, E_CLIENT_ERROR_REPOSITORY_OFFLINE);
 
-       if (cancelled) {
+       if (e_activity_handle_cancellation (activity, error)) {
                /* do nothing */
        } else if (offline_error) {
                e_alert_submit (
-                       E_ALERT_SINK (shell_content),
+                       alert_sink,
                        "calendar:prompt-no-contents-offline-calendar",
                        unique_display_name,
                        NULL);
        } else {
                e_alert_submit (
-                       E_ALERT_SINK (shell_content),
+                       alert_sink,
                        "calendar:failed-open-calendar",
                        unique_display_name,
                        error->message,
@@ -204,13 +229,15 @@ cal_shell_sidebar_client_connect_cb (GObject *source_object,
 
        if (error != NULL) {
                cal_shell_sidebar_handle_connect_error (
-                       closure->cal_shell_sidebar,
+                       closure->activity,
                        closure->unique_display_name,
                        error);
                g_error_free (error);
                goto exit;
        }
 
+       e_activity_set_state (closure->activity, E_ACTIVITY_COMPLETED);
+
        e_cal_shell_sidebar_add_client (closure->cal_shell_sidebar, client);
 
        g_object_unref (client);
@@ -240,20 +267,19 @@ cal_shell_sidebar_default_connect_cb (GObject *source_object,
                ((client != NULL) && (error == NULL)) ||
                ((client == NULL) && (error != NULL)));
 
-       if (priv->connecting_default_client != NULL) {
-               g_object_unref (priv->connecting_default_client);
-               priv->connecting_default_client = NULL;
-       }
+       g_clear_object (&priv->connecting_default_client);
 
        if (error != NULL) {
                cal_shell_sidebar_handle_connect_error (
-                       closure->cal_shell_sidebar,
+                       closure->activity,
                        closure->unique_display_name,
                        error);
                g_error_free (error);
                goto exit;
        }
 
+       e_activity_set_state (closure->activity, E_ACTIVITY_COMPLETED);
+
        source = e_client_get_source (client);
 
        if (source == priv->connecting_default_source_instance)
@@ -279,6 +305,7 @@ cal_shell_sidebar_set_default (ECalShellSidebar *cal_shell_sidebar,
 {
        ECalShellSidebarPrivate *priv;
        ESourceSelector *selector;
+       ConnectClosure *closure;
 
        priv = cal_shell_sidebar->priv;
 
@@ -288,22 +315,23 @@ cal_shell_sidebar_set_default (ECalShellSidebar *cal_shell_sidebar,
        if (source == priv->connecting_default_source_instance)
                return;
 
-       /* Cancel any unfinished previous request. */
+       /* Cancel the previous request if unfinished. */
        if (priv->connecting_default_client != NULL) {
-               g_cancellable_cancel (priv->connecting_default_client);
+               e_activity_cancel (priv->connecting_default_client);
                g_object_unref (priv->connecting_default_client);
                priv->connecting_default_client = NULL;
        }
 
+       closure = connect_closure_new (cal_shell_sidebar, source);
+
        /* it's only for pointer comparison, no need to ref it */
        priv->connecting_default_source_instance = source;
-       priv->connecting_default_client = g_cancellable_new ();
+       priv->connecting_default_client = g_object_ref (closure->activity);
 
        e_client_selector_get_client (
                E_CLIENT_SELECTOR (selector), source,
-               priv->connecting_default_client,
-               cal_shell_sidebar_default_connect_cb,
-               connect_closure_new (cal_shell_sidebar, source));
+               e_activity_get_cancellable (closure->activity),
+               cal_shell_sidebar_default_connect_cb, closure);
 }
 
 static void
@@ -468,17 +496,11 @@ cal_shell_sidebar_dispose (GObject *object)
        }
 
        if (priv->connecting_default_client != NULL) {
-               g_cancellable_cancel (priv->connecting_default_client);
+               e_activity_cancel (priv->connecting_default_client);
                g_object_unref (priv->connecting_default_client);
                priv->connecting_default_client = NULL;
        }
 
-       if (priv->loading_clients != NULL) {
-               g_cancellable_cancel (priv->loading_clients);
-               g_object_unref (priv->loading_clients);
-               priv->loading_clients = NULL;
-       }
-
        /* Chain up to parent's dispose() method. */
        G_OBJECT_CLASS (e_cal_shell_sidebar_parent_class)->dispose (object);
 }
@@ -665,8 +687,6 @@ cal_shell_sidebar_client_removed (ECalShellSidebar *cal_shell_sidebar,
 
        selector = e_cal_shell_sidebar_get_selector (cal_shell_sidebar);
        e_source_selector_unselect_source (selector, source);
-
-       cal_shell_sidebar_emit_status_message (cal_shell_sidebar, NULL);
 }
 
 static void
@@ -759,8 +779,6 @@ e_cal_shell_sidebar_init (ECalShellSidebar *cal_shell_sidebar)
        cal_shell_sidebar->priv =
                E_CAL_SHELL_SIDEBAR_GET_PRIVATE (cal_shell_sidebar);
 
-       cal_shell_sidebar->priv->loading_clients = g_cancellable_new ();
-
        /* Postpone widget construction until we have a shell view. */
 }
 
@@ -841,33 +859,22 @@ void
 e_cal_shell_sidebar_add_source (ECalShellSidebar *cal_shell_sidebar,
                                 ESource *source)
 {
-       ESourceRegistry *registry;
        ESourceSelector *selector;
-       gchar *display_name;
-       gchar *message;
+       ConnectClosure *closure;
 
        g_return_if_fail (E_IS_CAL_SHELL_SIDEBAR (cal_shell_sidebar));
        g_return_if_fail (E_IS_SOURCE (source));
 
        selector = e_cal_shell_sidebar_get_selector (cal_shell_sidebar);
-       registry = e_source_selector_get_registry (selector);
 
        e_source_selector_select_source (selector, source);
 
-       display_name = e_source_registry_dup_unique_display_name (
-               registry, source, E_SOURCE_EXTENSION_CALENDAR);
-
-       message = g_strdup_printf (_("Opening calendar '%s'"), display_name);
-       cal_shell_sidebar_emit_status_message (cal_shell_sidebar, message);
-       g_free (message);
-
-       g_free (display_name);
+       closure = connect_closure_new (cal_shell_sidebar, source);
 
        e_client_selector_get_client (
                E_CLIENT_SELECTOR (selector), source,
-               cal_shell_sidebar->priv->loading_clients,
-               cal_shell_sidebar_client_connect_cb,
-               connect_closure_new (cal_shell_sidebar, source));
+               e_activity_get_cancellable (closure->activity),
+               cal_shell_sidebar_client_connect_cb, closure);
 }
 
 void


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