From 59928e69ed7b769585282ae2b11bca1a9e9a1ca9 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sun, 19 Dec 2010 13:30:45 -0500 Subject: Add e_shell_submit_alert(). An easy way to broadcast application-wide alerts to shell windows. These alerts will persist in all current and future shell windows until responded to (either programmatically or by the user). --- shell/e-shell.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ shell/e-shell.h | 3 +++ 2 files changed, 69 insertions(+) (limited to 'shell') diff --git a/shell/e-shell.c b/shell/e-shell.c index b52d77186b..b1891ce3b8 100644 --- a/shell/e-shell.c +++ b/shell/e-shell.c @@ -47,6 +47,7 @@ ((obj), E_TYPE_SHELL, EShellPrivate)) struct _EShellPrivate { + GQueue alerts; GList *watched_windows; EShellSettings *settings; GConfClient *gconf_client; @@ -132,6 +133,19 @@ shell_parse_debug_string (EShell *shell) e_shell_settings_enable_debug (shell->priv->settings); } +static void +shell_alert_response_cb (EShell *shell, + gint response_id, + EAlert *alert) +{ + g_signal_handlers_disconnect_by_func ( + alert, shell_alert_response_cb, shell); + + g_queue_remove (&shell->priv->alerts, alert); + + g_object_unref (alert); +} + static void shell_notify_online_cb (EShell *shell) { @@ -623,9 +637,16 @@ static void shell_dispose (GObject *object) { EShellPrivate *priv; + EAlert *alert; priv = E_SHELL_GET_PRIVATE (object); + while ((alert = g_queue_pop_head (&priv->alerts)) != NULL) { + g_signal_handlers_disconnect_by_func ( + alert, shell_alert_response_cb, object); + g_object_unref (alert); + } + if (priv->startup_view != NULL) { g_free (priv->startup_view); priv->startup_view = NULL; @@ -1156,6 +1177,8 @@ e_shell_init (EShell *shell) backends_by_name = g_hash_table_new (g_str_hash, g_str_equal); backends_by_scheme = g_hash_table_new (g_str_hash, g_str_equal); + g_queue_init (&shell->priv->alerts); + shell->priv->settings = g_object_new (E_TYPE_SHELL_SETTINGS, NULL); shell->priv->gconf_client = gconf_client_get_default (); shell->priv->preferences_window = e_preferences_window_new (shell); @@ -1432,6 +1455,7 @@ e_shell_create_shell_window (EShell *shell, GtkWidget *shell_window; UniqueMessageData *data; UniqueApp *app; + GList *link; g_return_val_if_fail (E_IS_SHELL (shell), NULL); @@ -1464,6 +1488,15 @@ e_shell_create_shell_window (EShell *shell, shell->priv->safe_mode, shell->priv->geometry); + /* Submit any outstanding alerts. */ + link = g_queue_peek_head_link (&shell->priv->alerts); + while (link != NULL) { + e_alert_sink_submit_alert ( + E_ALERT_SINK (shell_window), + E_ALERT (link->data)); + link = g_list_next (link); + } + /* Clear the first-time-only options. */ shell->priv->safe_mode = FALSE; g_free (shell->priv->geometry); @@ -1564,6 +1597,39 @@ unique: /* Send a message to the other Evolution process. */ return g_strv_length (uris); } +/** + * e_shell_submit_alert: + * @shell: an #EShell + * @alert: an #EAlert + * + * Broadcasts @alert to all #EShellWindows. This should only + * be used for application-wide alerts such as a network outage. Submit + * view-specific alerts to the appropriate #EShellContent instance. + **/ +void +e_shell_submit_alert (EShell *shell, + EAlert *alert) +{ + GList *list, *iter; + + g_return_if_fail (E_IS_SHELL (shell)); + g_return_if_fail (E_IS_ALERT (alert)); + + g_queue_push_tail (&shell->priv->alerts, g_object_ref (alert)); + + g_signal_connect_swapped ( + alert, "response", + G_CALLBACK (shell_alert_response_cb), shell); + + list = e_shell_get_watched_windows (shell); + + /* Submit the alert to all available EShellWindows. */ + for (iter = list; iter != NULL; iter = g_list_next (iter)) + if (E_IS_SHELL_WINDOW (iter->data)) + e_alert_sink_submit_alert ( + E_ALERT_SINK (iter->data), alert); +} + /** * e_shell_watch_window: * @shell: an #EShell diff --git a/shell/e-shell.h b/shell/e-shell.h index 3f037ba2d6..22aef9252f 100644 --- a/shell/e-shell.h +++ b/shell/e-shell.h @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -128,6 +129,8 @@ GtkWidget * e_shell_create_shell_window (EShell *shell, guint e_shell_handle_uris (EShell *shell, gchar **uris, gboolean do_import); +void e_shell_submit_alert (EShell *shell, + EAlert *alert); void e_shell_watch_window (EShell *shell, GtkWindow *window); GList * e_shell_get_watched_windows (EShell *shell); -- cgit v1.2.3