diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2010-10-16 02:49:36 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2010-10-18 22:57:36 +0800 |
commit | 2197e6401ec8c5e1b77fa51e085ac068daa39e6a (patch) | |
tree | 2eb7a7d3e6113a41da3ee5305a9be662ef1c8f45 /shell | |
parent | 776d7f50b565424e4ab5306af56986e59c00d3b9 (diff) | |
download | gsoc2013-evolution-2197e6401ec8c5e1b77fa51e085ac068daa39e6a.tar gsoc2013-evolution-2197e6401ec8c5e1b77fa51e085ac068daa39e6a.tar.gz gsoc2013-evolution-2197e6401ec8c5e1b77fa51e085ac068daa39e6a.tar.bz2 gsoc2013-evolution-2197e6401ec8c5e1b77fa51e085ac068daa39e6a.tar.lz gsoc2013-evolution-2197e6401ec8c5e1b77fa51e085ac068daa39e6a.tar.xz gsoc2013-evolution-2197e6401ec8c5e1b77fa51e085ac068daa39e6a.tar.zst gsoc2013-evolution-2197e6401ec8c5e1b77fa51e085ac068daa39e6a.zip |
Implement EAlertSinkInterface in EShellContent.
Use the same alert handling policy as the composer.
Diffstat (limited to 'shell')
-rw-r--r-- | shell/e-shell-content.c | 154 | ||||
-rw-r--r-- | shell/e-shell-content.h | 2 | ||||
-rw-r--r-- | shell/e-shell-view.c | 13 |
3 files changed, 155 insertions, 14 deletions
diff --git a/shell/e-shell-content.c b/shell/e-shell-content.c index fd7645fe9f..2648783831 100644 --- a/shell/e-shell-content.c +++ b/shell/e-shell-content.c @@ -29,6 +29,8 @@ #include <glib/gi18n.h> +#include "e-util/e-alert-dialog.h" +#include "e-util/e-alert-sink.h" #include "e-util/e-extensible.h" #include "e-util/e-util.h" #include "e-util/e-alert-dialog.h" @@ -49,6 +51,7 @@ struct _EShellContentPrivate { gpointer shell_view; /* weak pointer */ + GtkWidget *alert_bar; GtkWidget *searchbar; /* not referenced */ /* Custom search rules. */ @@ -57,14 +60,21 @@ struct _EShellContentPrivate { enum { PROP_0, + PROP_ALERT_BAR, PROP_SHELL_VIEW }; +/* Forward Declarations */ +static void e_shell_content_alert_sink_init + (EAlertSinkInterface *interface); + G_DEFINE_TYPE_WITH_CODE ( EShellContent, e_shell_content, GTK_TYPE_BIN, G_IMPLEMENT_INTERFACE ( + E_TYPE_ALERT_SINK, e_shell_content_alert_sink_init) + G_IMPLEMENT_INTERFACE ( E_TYPE_EXTENSIBLE, NULL)); static void @@ -118,6 +128,12 @@ shell_content_get_property (GObject *object, GParamSpec *pspec) { switch (property_id) { + case PROP_ALERT_BAR: + g_value_set_object ( + value, e_shell_content_get_alert_bar ( + E_SHELL_CONTENT (object))); + return; + case PROP_SHELL_VIEW: g_value_set_object ( value, e_shell_content_get_shell_view ( @@ -141,9 +157,9 @@ shell_content_dispose (GObject *object) priv->shell_view = NULL; } - if (priv->user_filename) { - g_free (priv->user_filename); - priv->user_filename = NULL; + if (priv->alert_bar != NULL) { + g_object_unref (priv->alert_bar); + priv->alert_bar = NULL; } /* Chain up to parent's dispose() method. */ @@ -151,17 +167,36 @@ shell_content_dispose (GObject *object) } static void +shell_content_finalize (GObject *object) +{ + EShellContentPrivate *priv; + + priv = E_SHELL_CONTENT_GET_PRIVATE (object); + + g_free (priv->user_filename); + + /* Chain up to parent's finalize() method. */ + G_OBJECT_CLASS (e_shell_content_parent_class)->finalize (object); +} + +static void shell_content_constructed (GObject *object) { EShellContent *shell_content; EShellBackend *shell_backend; EShellView *shell_view; + GtkWidget *widget; const gchar *config_dir; shell_content = E_SHELL_CONTENT (object); shell_view = e_shell_content_get_shell_view (shell_content); shell_backend = e_shell_view_get_shell_backend (shell_view); + widget = e_alert_bar_new (); + gtk_widget_set_parent (widget, GTK_WIDGET (shell_content)); + shell_content->priv->alert_bar = g_object_ref_sink (widget); + /* EAlertBar controls its own visibility. */ + /* XXX Regenerate the filename for custom saved search as done * in shell_view_init_search_context(). ERuleContext ought * to remember the filename when loading rules so you don't @@ -189,6 +224,10 @@ shell_content_size_request (GtkWidget *widget, child = gtk_bin_get_child (GTK_BIN (widget)); gtk_widget_size_request (child, requisition); + gtk_widget_size_request (priv->alert_bar, &child_requisition); + requisition->width = MAX (requisition->width, child_requisition.width); + requisition->height += child_requisition.height; + if (priv->searchbar == NULL) return; @@ -210,21 +249,40 @@ shell_content_size_allocate (GtkWidget *widget, gtk_widget_set_allocation (widget, allocation); - child = priv->searchbar; + child_allocation.x = allocation->x; + child_allocation.width = allocation->width; - if (child == NULL) - child_requisition.height = 0; + /* Alert bar gets to be as tall as it wants. */ + + child = priv->alert_bar; + child_allocation.y = allocation->y; + + if (gtk_widget_get_visible (child)) + gtk_widget_size_request (child, &child_requisition); else + child_requisition.height = 0; + + child_allocation.height = child_requisition.height; + + gtk_widget_size_allocate (child, &child_allocation); + + /* So does the search bar (if we have one). */ + + child = priv->searchbar; + child_allocation.y += child_requisition.height; + + if (child != NULL) gtk_widget_size_request (child, &child_requisition); + else + child_requisition.height = 0; - child_allocation.x = allocation->x; - child_allocation.y = allocation->y; - child_allocation.width = allocation->width; child_allocation.height = child_requisition.height; if (child != NULL) gtk_widget_size_allocate (child, &child_allocation); + /* The GtkBin child gets whatever vertical space is left. */ + child_allocation.y += child_requisition.height; child_allocation.height = allocation->height - child_requisition.height; @@ -243,6 +301,12 @@ shell_content_remove (GtkContainer *container, priv = E_SHELL_CONTENT_GET_PRIVATE (container); + if (widget == priv->alert_bar) { + gtk_widget_unparent (priv->alert_bar); + priv->alert_bar = NULL; + return; + } + if (widget == priv->searchbar) { gtk_widget_unparent (priv->searchbar); priv->searchbar = NULL; @@ -264,6 +328,9 @@ shell_content_forall (GtkContainer *container, priv = E_SHELL_CONTENT_GET_PRIVATE (container); + if (priv->alert_bar != NULL) + callback (priv->alert_bar, callback_data); + if (priv->searchbar != NULL) callback (priv->searchbar, callback_data); @@ -273,6 +340,38 @@ shell_content_forall (GtkContainer *container, } static void +shell_content_submit_alert (EAlertSink *alert_sink, + EAlert *alert) +{ + EShellView *shell_view; + EShellWindow *shell_window; + EShellContent *shell_content; + EAlertBar *alert_bar; + GtkWidget *dialog; + GtkWindow *parent; + + shell_content = E_SHELL_CONTENT (alert_sink); + shell_view = e_shell_content_get_shell_view (shell_content); + shell_window = e_shell_view_get_shell_window (shell_view); + alert_bar = e_shell_content_get_alert_bar (shell_content); + + switch (e_alert_get_message_type (alert)) { + case GTK_MESSAGE_INFO: + case GTK_MESSAGE_WARNING: + case GTK_MESSAGE_ERROR: + e_alert_bar_add_alert (alert_bar, alert); + break; + + default: + parent = GTK_WINDOW (shell_window); + dialog = e_alert_dialog_new (parent, alert); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + break; + } +} + +static void e_shell_content_class_init (EShellContentClass *class) { GObjectClass *object_class; @@ -285,6 +384,7 @@ e_shell_content_class_init (EShellContentClass *class) object_class->set_property = shell_content_set_property; object_class->get_property = shell_content_get_property; object_class->dispose = shell_content_dispose; + object_class->finalize = shell_content_finalize; object_class->constructed = shell_content_constructed; widget_class = GTK_WIDGET_CLASS (class); @@ -295,6 +395,20 @@ e_shell_content_class_init (EShellContentClass *class) container_class->remove = shell_content_remove; container_class->forall = shell_content_forall; + /* EShellContent:alert-bar + * + * Displays informational and error messages. + **/ + g_object_class_install_property ( + object_class, + PROP_ALERT_BAR, + g_param_spec_object ( + "alert-bar", + "Alert Bar", + "Displays informational and error messages", + E_TYPE_ALERT_BAR, + G_PARAM_READABLE)); + /** * EShellContent:shell-view * @@ -313,6 +427,12 @@ e_shell_content_class_init (EShellContentClass *class) } static void +e_shell_content_alert_sink_init (EAlertSinkInterface *interface) +{ + interface->submit_alert = shell_content_submit_alert; +} + +static void e_shell_content_init (EShellContent *shell_content) { shell_content->priv = E_SHELL_CONTENT_GET_PRIVATE (shell_content); @@ -416,6 +536,22 @@ e_shell_content_focus_search_results (EShellContent *shell_content) } /** + * e_shell_content_get_alert_bar: + * @shell_content: an #EShellContent + * + * Returns the #EAlertBar used to display informational and error messages. + * + * Returns: the #EAlertBar for @shell_content + **/ +EAlertBar * +e_shell_content_get_alert_bar (EShellContent *shell_content) +{ + g_return_val_if_fail (E_IS_SHELL_CONTENT (shell_content), NULL); + + return E_ALERT_BAR (shell_content->priv->alert_bar); +} + +/** * e_shell_content_get_shell_view: * @shell_content: an #EShellContent * diff --git a/shell/e-shell-content.h b/shell/e-shell-content.h index a92ac346b8..099c841655 100644 --- a/shell/e-shell-content.h +++ b/shell/e-shell-content.h @@ -22,6 +22,7 @@ #ifndef E_SHELL_CONTENT_H #define E_SHELL_CONTENT_H +#include <misc/e-alert-bar.h> #include <shell/e-shell-common.h> /* Standard GObject macros */ @@ -78,6 +79,7 @@ void e_shell_content_set_searchbar (EShellContent *shell_content, guint32 e_shell_content_check_state (EShellContent *shell_content); void e_shell_content_focus_search_results (EShellContent *shell_content); +EAlertBar * e_shell_content_get_alert_bar (EShellContent *shell_content); struct _EShellView * e_shell_content_get_shell_view (EShellContent *shell_content); const gchar * e_shell_content_get_view_id (EShellContent *shell_content); diff --git a/shell/e-shell-view.c b/shell/e-shell-view.c index 94b381f4c5..18300c4672 100644 --- a/shell/e-shell-view.c +++ b/shell/e-shell-view.c @@ -765,7 +765,7 @@ shell_view_update_actions (EShellView *shell_view) } static void -shell_view_class_init (EShellViewClass *class) +e_shell_view_class_init (EShellViewClass *class) { GObjectClass *object_class; @@ -1065,11 +1065,14 @@ shell_view_class_init (EShellViewClass *class) } static void -shell_view_init (EShellView *shell_view, - EShellViewClass *class) +e_shell_view_init (EShellView *shell_view, + EShellViewClass *class) { GtkSizeGroup *size_group; + /* XXX Our use of GInstanceInitFunc's 'class' parameter + * prevents us from using G_DEFINE_ABSTRACT_TYPE. */ + if (class->search_context == NULL) shell_view_init_search_context (class); @@ -1093,12 +1096,12 @@ e_shell_view_get_type (void) sizeof (EShellViewClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, - (GClassInitFunc) shell_view_class_init, + (GClassInitFunc) e_shell_view_class_init, (GClassFinalizeFunc) NULL, NULL, /* class_data */ sizeof (EShellView), 0, /* n_preallocs */ - (GInstanceInitFunc) shell_view_init, + (GInstanceInitFunc) e_shell_view_init, NULL /* value_table */ }; |