aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2012-07-10 23:00:29 +0800
committerMatthew Barnes <mbarnes@redhat.com>2012-07-11 01:34:53 +0800
commitad10fa252667daba4f31e10096b4a8a838a41cba (patch)
treeba0f4851d5d7afead72a20e32836622092abb407
parent20973f9281767871e8db287cf55aceae7f68b6df (diff)
downloadgsoc2013-evolution-ad10fa252667daba4f31e10096b4a8a838a41cba.tar
gsoc2013-evolution-ad10fa252667daba4f31e10096b4a8a838a41cba.tar.gz
gsoc2013-evolution-ad10fa252667daba4f31e10096b4a8a838a41cba.tar.bz2
gsoc2013-evolution-ad10fa252667daba4f31e10096b4a8a838a41cba.tar.lz
gsoc2013-evolution-ad10fa252667daba4f31e10096b4a8a838a41cba.tar.xz
gsoc2013-evolution-ad10fa252667daba4f31e10096b4a8a838a41cba.tar.zst
gsoc2013-evolution-ad10fa252667daba4f31e10096b4a8a838a41cba.zip
Add EMailConfigActivityPage.
This is a convenient base class for EMailConfigPages that might need to run an asynchronous method and display an error message. It adds activity and alert bars to the bottom of the page, it implements the EAlertSink interface, and can create new EActivity instances.
-rw-r--r--mail/Makefile.am2
-rw-r--r--mail/e-mail-config-activity-page.c178
-rw-r--r--mail/e-mail-config-activity-page.h72
3 files changed, 252 insertions, 0 deletions
diff --git a/mail/Makefile.am b/mail/Makefile.am
index 9dda24f16d..09c274aad7 100644
--- a/mail/Makefile.am
+++ b/mail/Makefile.am
@@ -47,6 +47,7 @@ mailinclude_HEADERS = \
e-mail-autoconfig.h \
e-mail-backend.h \
e-mail-browser.h \
+ e-mail-config-activity-page.h \
e-mail-config-assistant.h \
e-mail-config-auth-check.h \
e-mail-config-confirm-page.h \
@@ -127,6 +128,7 @@ libevolution_mail_la_SOURCES = \
e-mail-autoconfig.c \
e-mail-backend.c \
e-mail-browser.c \
+ e-mail-config-activity-page.c \
e-mail-config-assistant.c \
e-mail-config-auth-check.c \
e-mail-config-confirm-page.c \
diff --git a/mail/e-mail-config-activity-page.c b/mail/e-mail-config-activity-page.c
new file mode 100644
index 0000000000..4328555f75
--- /dev/null
+++ b/mail/e-mail-config-activity-page.c
@@ -0,0 +1,178 @@
+/*
+ * e-mail-config-activity-page.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#include "e-mail-config-activity-page.h"
+
+#include <camel/camel.h>
+
+#include <libevolution-utils/e-alert-sink.h>
+#include <libevolution-utils/e-alert-dialog.h>
+#include <misc/e-activity-bar.h>
+#include <misc/e-alert-bar.h>
+
+#define E_MAIL_CONFIG_ACTIVITY_PAGE_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), E_TYPE_MAIL_CONFIG_ACTIVITY_PAGE, EMailConfigActivityPagePrivate))
+
+struct _EMailConfigActivityPagePrivate {
+ GtkWidget *activity_bar; /* not referenced */
+ GtkWidget *alert_bar; /* not referenced */
+};
+
+/* Forward Declarations */
+static void e_mail_config_activity_page_alert_sink_init
+ (EAlertSinkInterface *interface);
+
+G_DEFINE_ABSTRACT_TYPE_WITH_CODE (
+ EMailConfigActivityPage,
+ e_mail_config_activity_page,
+ GTK_TYPE_BOX,
+ G_IMPLEMENT_INTERFACE (
+ E_TYPE_ALERT_SINK,
+ e_mail_config_activity_page_alert_sink_init))
+
+static void
+mail_config_activity_page_constructed (GObject *object)
+{
+ EMailConfigActivityPage *page;
+ GtkWidget *frame;
+ GtkWidget *widget;
+
+ page = E_MAIL_CONFIG_ACTIVITY_PAGE (object);
+
+ /* Chain up to parent's constructed() method. */
+ G_OBJECT_CLASS (e_mail_config_activity_page_parent_class)->
+ constructed (object);
+
+ gtk_orientable_set_orientation (
+ GTK_ORIENTABLE (page), GTK_ORIENTATION_VERTICAL);
+
+ /* Does not matter what order the EActivityBar and EAlertBar are
+ * packed. They should never both be visible at the same time. */
+
+ frame = gtk_frame_new (NULL);
+ gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
+ gtk_box_pack_end (GTK_BOX (page), frame, FALSE, FALSE, 0);
+ /* Visibility is bound to the EActivityBar. */
+
+ widget = e_activity_bar_new ();
+ gtk_container_add (GTK_CONTAINER (frame), widget);
+ page->priv->activity_bar = widget; /* do not reference */
+ /* EActivityBar controls its own visibility. */
+
+ g_object_bind_property (
+ widget, "visible",
+ frame, "visible",
+ G_BINDING_SYNC_CREATE);
+
+ frame = gtk_frame_new (NULL);
+ gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
+ gtk_box_pack_end (GTK_BOX (page), frame, FALSE, FALSE, 0);
+ /* Visibility is bound to the EAlertBar. */
+
+ widget = e_alert_bar_new ();
+ gtk_container_add (GTK_CONTAINER (frame), widget);
+ page->priv->alert_bar = widget; /* do not reference */
+ /* EAlertBar controls its own visibility. */
+
+ g_object_bind_property (
+ widget, "visible",
+ frame, "visible",
+ G_BINDING_SYNC_CREATE);
+}
+
+static void
+mail_config_activity_page_submit_alert (EAlertSink *alert_sink,
+ EAlert *alert)
+{
+ EMailConfigActivityPagePrivate *priv;
+ EAlertBar *alert_bar;
+ GtkWidget *dialog;
+ gpointer parent;
+
+ priv = E_MAIL_CONFIG_ACTIVITY_PAGE_GET_PRIVATE (alert_sink);
+
+ parent = gtk_widget_get_toplevel (GTK_WIDGET (alert_sink));
+ parent = gtk_widget_is_toplevel (parent) ? parent : NULL;
+
+ switch (e_alert_get_message_type (alert)) {
+ case GTK_MESSAGE_INFO:
+ case GTK_MESSAGE_WARNING:
+ case GTK_MESSAGE_ERROR:
+ alert_bar = E_ALERT_BAR (priv->alert_bar);
+ e_alert_bar_add_alert (alert_bar, alert);
+ break;
+
+ default:
+ dialog = e_alert_dialog_new (parent, alert);
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ break;
+ }
+}
+
+static void
+e_mail_config_activity_page_class_init (EMailConfigActivityPageClass *class)
+{
+ GObjectClass *object_class;
+
+ g_type_class_add_private (
+ class, sizeof (EMailConfigActivityPagePrivate));
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->constructed = mail_config_activity_page_constructed;
+}
+
+static void
+e_mail_config_activity_page_alert_sink_init (EAlertSinkInterface *interface)
+{
+ interface->submit_alert = mail_config_activity_page_submit_alert;
+}
+
+static void
+e_mail_config_activity_page_init (EMailConfigActivityPage *page)
+{
+ page->priv = E_MAIL_CONFIG_ACTIVITY_PAGE_GET_PRIVATE (page);
+}
+
+EActivity *
+e_mail_config_activity_page_new_activity (EMailConfigActivityPage *page)
+{
+ EActivity *activity;
+ EActivityBar *activity_bar;
+ GCancellable *cancellable;
+
+ g_return_val_if_fail (E_IS_MAIL_CONFIG_ACTIVITY_PAGE (page), NULL);
+
+ /* Clear any previous alerts. */
+ e_alert_bar_clear (E_ALERT_BAR (page->priv->alert_bar));
+
+ activity = e_activity_new ();
+
+ e_activity_set_alert_sink (activity, E_ALERT_SINK (page));
+
+ cancellable = camel_operation_new ();
+ e_activity_set_cancellable (activity, cancellable);
+ g_object_unref (cancellable);
+
+ activity_bar = E_ACTIVITY_BAR (page->priv->activity_bar);
+ e_activity_bar_set_activity (activity_bar, activity);
+
+ return activity;
+}
+
diff --git a/mail/e-mail-config-activity-page.h b/mail/e-mail-config-activity-page.h
new file mode 100644
index 0000000000..62defe20fa
--- /dev/null
+++ b/mail/e-mail-config-activity-page.h
@@ -0,0 +1,72 @@
+/*
+ * e-mail-config-activity-page.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+/* This is a convenient base class for EMailConfigPages that might need
+ * to run an asynchronous method and display an error message. It adds
+ * activity and alert bars to the bottom of the page, it implements the
+ * EAlertSink interface, and can create new EActivity instances. */
+
+#ifndef E_MAIL_CONFIG_ACTIVITY_PAGE_H
+#define E_MAIL_CONFIG_ACTIVITY_PAGE_H
+
+#include <gtk/gtk.h>
+#include <e-util/e-activity.h>
+
+/* Standard GObject macros */
+#define E_TYPE_MAIL_CONFIG_ACTIVITY_PAGE \
+ (e_mail_config_activity_page_get_type ())
+#define E_MAIL_CONFIG_ACTIVITY_PAGE(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST \
+ ((obj), E_TYPE_MAIL_CONFIG_ACTIVITY_PAGE, EMailConfigActivityPage))
+#define E_MAIL_CONFIG_ACTIVITY_PAGE_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_CAST \
+ ((cls), E_TYPE_MAIL_CONFIG_ACTIVITY_PAGE, EMailConfigActivityPageClass))
+#define E_IS_MAIL_CONFIG_ACTIVITY_PAGE(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((obj), E_TYPE_MAIL_CONFIG_ACTIVITY_PAGE))
+#define E_IS_MAIL_CONFIG_ACTIVITY_PAGE_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_TYPE \
+ ((cls), E_TYPE_MAIL_CONFIG_ACTIVITY_PAGE))
+#define E_MAIL_CONFIG_ACTIVITY_PAGE_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS \
+ ((obj), E_TYPE_MAIL_CONFIG_ACTIVITY_PAGE, EMailConfigActivityPageClass))
+
+G_BEGIN_DECLS
+
+typedef struct _EMailConfigActivityPage EMailConfigActivityPage;
+typedef struct _EMailConfigActivityPageClass EMailConfigActivityPageClass;
+typedef struct _EMailConfigActivityPagePrivate EMailConfigActivityPagePrivate;
+
+struct _EMailConfigActivityPage {
+ GtkBox parent;
+ EMailConfigActivityPagePrivate *priv;
+};
+
+struct _EMailConfigActivityPageClass {
+ GtkBoxClass parent_class;
+};
+
+GType e_mail_config_activity_page_get_type
+ (void) G_GNUC_CONST;
+EActivity * e_mail_config_activity_page_new_activity
+ (EMailConfigActivityPage *page);
+
+G_END_DECLS
+
+#endif /* E_MAIL_CONFIG_ACTIVITY_PAGE_H */
+