diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2013-04-25 22:43:42 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2013-04-25 23:42:04 +0800 |
commit | d4ae41915c2c0d63249aedf5bf1edc19f0bffed1 (patch) | |
tree | 6a62fd8540d96494eb6d0e6c0fe62db08d8518cb | |
parent | 3a0b447047afec2e00d36be56d0a2e325e2b7af1 (diff) | |
download | gsoc2013-evolution-d4ae41915c2c0d63249aedf5bf1edc19f0bffed1.tar.gz gsoc2013-evolution-d4ae41915c2c0d63249aedf5bf1edc19f0bffed1.tar.zst gsoc2013-evolution-d4ae41915c2c0d63249aedf5bf1edc19f0bffed1.zip |
EMemoShellSidebar: 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 sesms to be blocking
application shut down in some cases.
-rw-r--r-- | modules/calendar/e-memo-shell-sidebar.c | 109 |
1 files changed, 58 insertions, 51 deletions
diff --git a/modules/calendar/e-memo-shell-sidebar.c b/modules/calendar/e-memo-shell-sidebar.c index 46d170d644..f270ce39e1 100644 --- a/modules/calendar/e-memo-shell-sidebar.c +++ b/modules/calendar/e-memo-shell-sidebar.c @@ -53,12 +53,12 @@ struct _EMemoShellSidebarPrivate { /* Not referenced, only for pointer comparison. */ ESource *connecting_default_source_instance; - GCancellable *connecting_default_client; - GCancellable *loading_clients; + EActivity *connecting_default_client; }; struct _ConnectClosure { EMemoShellSidebar *memo_shell_sidebar; + EActivity *activity; /* For error messages. */ gchar *unique_display_name; @@ -89,25 +89,54 @@ connect_closure_new (EMemoShellSidebar *memo_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 (memo_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_memo_shell_sidebar_get_selector (memo_shell_sidebar); registry = e_source_selector_get_registry (selector); closure = g_slice_new0 (ConnectClosure); closure->memo_shell_sidebar = g_object_ref (memo_shell_sidebar); + closure->activity = e_activity_new (); closure->unique_display_name = e_source_registry_dup_unique_display_name ( registry, source, E_SOURCE_EXTENSION_MEMO_LIST); + text = g_strdup_printf ( + _("Opening memo list '%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->memo_shell_sidebar); + g_clear_object (&closure->memo_shell_sidebar); + g_clear_object (&closure->activity); g_free (closure->unique_display_name); @@ -182,19 +211,15 @@ memo_shell_sidebar_emit_status_message (EMemoShellSidebar *memo_shell_sidebar, } static void -memo_shell_sidebar_handle_connect_error (EMemoShellSidebar *memo_shell_sidebar, +memo_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 (memo_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); @@ -204,17 +229,17 @@ memo_shell_sidebar_handle_connect_error (EMemoShellSidebar *memo_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-memos", unique_display_name, NULL); } else { e_alert_submit ( - E_ALERT_SINK (shell_content), + alert_sink, "calendar:failed-open-memos", unique_display_name, error->message, @@ -241,13 +266,15 @@ memo_shell_sidebar_client_connect_cb (GObject *source_object, if (error != NULL) { memo_shell_sidebar_handle_connect_error ( - closure->memo_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_memo_shell_sidebar_add_client (closure->memo_shell_sidebar, client); g_object_unref (client); @@ -277,20 +304,19 @@ memo_shell_sidebar_default_connect_cb (GObject *source_object, ((client != NULL) && (error == NULL)) || ((client == NULL) && (error != NULL))); - if (priv->connecting_default_client) { - g_object_unref (priv->connecting_default_client); - priv->connecting_default_client = NULL; - } + g_clear_object (&priv->connecting_default_client); if (error != NULL) { memo_shell_sidebar_handle_connect_error ( - closure->memo_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) @@ -316,6 +342,7 @@ memo_shell_sidebar_set_default (EMemoShellSidebar *memo_shell_sidebar, { EMemoShellSidebarPrivate *priv; ESourceSelector *selector; + ConnectClosure *closure; priv = memo_shell_sidebar->priv; @@ -325,22 +352,23 @@ memo_shell_sidebar_set_default (EMemoShellSidebar *memo_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 (memo_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, - memo_shell_sidebar_default_connect_cb, - connect_closure_new (memo_shell_sidebar, source)); + e_activity_get_cancellable (closure->activity), + memo_shell_sidebar_default_connect_cb, closure); } static void @@ -472,17 +500,11 @@ memo_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_memo_shell_sidebar_parent_class)->dispose (object); } @@ -619,8 +641,6 @@ memo_shell_sidebar_client_removed (EMemoShellSidebar *memo_shell_sidebar, selector = e_memo_shell_sidebar_get_selector (memo_shell_sidebar); e_source_selector_unselect_source (selector, source); - - memo_shell_sidebar_emit_status_message (memo_shell_sidebar, NULL); } static void @@ -704,8 +724,6 @@ e_memo_shell_sidebar_init (EMemoShellSidebar *memo_shell_sidebar) memo_shell_sidebar->priv = E_MEMO_SHELL_SIDEBAR_GET_PRIVATE (memo_shell_sidebar); - memo_shell_sidebar->priv->loading_clients = g_cancellable_new (); - /* Postpone widget construction until we have a shell view. */ } @@ -768,33 +786,22 @@ void e_memo_shell_sidebar_add_source (EMemoShellSidebar *memo_shell_sidebar, ESource *source) { - ESourceRegistry *registry; ESourceSelector *selector; - gchar *display_name; - gchar *message; + ConnectClosure *closure; g_return_if_fail (E_IS_MEMO_SHELL_SIDEBAR (memo_shell_sidebar)); g_return_if_fail (E_IS_SOURCE (source)); selector = e_memo_shell_sidebar_get_selector (memo_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_MEMO_LIST); - - message = g_strdup_printf (_("Opening memo list '%s'"), display_name); - memo_shell_sidebar_emit_status_message (memo_shell_sidebar, message); - g_free (message); - - g_free (display_name); + closure = connect_closure_new (memo_shell_sidebar, source); e_client_selector_get_client ( E_CLIENT_SELECTOR (selector), source, - memo_shell_sidebar->priv->loading_clients, - memo_shell_sidebar_client_connect_cb, - connect_closure_new (memo_shell_sidebar, source)); + e_activity_get_cancellable (closure->activity), + memo_shell_sidebar_client_connect_cb, closure); } void |