1 /*
2 * e-mail-config-activity-page.c
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 * for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18 #include "e-mail-config-activity-page.h"
19
20 #include <camel/camel.h>
21
22 #define E_MAIL_CONFIG_ACTIVITY_PAGE_GET_PRIVATE(obj) \
23 (G_TYPE_INSTANCE_GET_PRIVATE \
24 ((obj), E_TYPE_MAIL_CONFIG_ACTIVITY_PAGE, EMailConfigActivityPagePrivate))
25
26 struct _EMailConfigActivityPagePrivate {
27 GtkWidget *box; /* not referenced */
28 GtkWidget *activity_bar; /* not referenced */
29 GtkWidget *alert_bar; /* not referenced */
30 };
31
32 /* Forward Declarations */
33 static void e_mail_config_activity_page_alert_sink_init
34 (EAlertSinkInterface *iface);
35
G_DEFINE_ABSTRACT_TYPE_WITH_CODE(EMailConfigActivityPage,e_mail_config_activity_page,GTK_TYPE_SCROLLED_WINDOW,G_IMPLEMENT_INTERFACE (E_TYPE_ALERT_SINK,e_mail_config_activity_page_alert_sink_init))36 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (
37 EMailConfigActivityPage,
38 e_mail_config_activity_page,
39 GTK_TYPE_SCROLLED_WINDOW,
40 G_IMPLEMENT_INTERFACE (
41 E_TYPE_ALERT_SINK,
42 e_mail_config_activity_page_alert_sink_init))
43
44 static void
45 mail_config_activity_page_constructed (GObject *object)
46 {
47 EMailConfigActivityPage *page;
48 GtkWidget *frame;
49 GtkWidget *widget;
50
51 page = E_MAIL_CONFIG_ACTIVITY_PAGE (object);
52
53 /* Chain up to parent's constructed() method. */
54 G_OBJECT_CLASS (e_mail_config_activity_page_parent_class)->constructed (object);
55
56 page->priv->box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
57
58 /* Does not matter what order the EActivityBar and EAlertBar are
59 * packed. They should never both be visible at the same time. */
60
61 frame = gtk_frame_new (NULL);
62 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
63 gtk_box_pack_end (GTK_BOX (page->priv->box), frame, FALSE, FALSE, 0);
64 /* Visibility is bound to the EActivityBar. */
65
66 widget = e_activity_bar_new ();
67 gtk_container_add (GTK_CONTAINER (frame), widget);
68 page->priv->activity_bar = widget; /* do not reference */
69 /* EActivityBar controls its own visibility. */
70
71 e_binding_bind_property (
72 widget, "visible",
73 frame, "visible",
74 G_BINDING_SYNC_CREATE);
75
76 frame = gtk_frame_new (NULL);
77 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
78 gtk_box_pack_end (GTK_BOX (page->priv->box), frame, FALSE, FALSE, 0);
79 /* Visibility is bound to the EAlertBar. */
80
81 widget = e_alert_bar_new ();
82 gtk_container_add (GTK_CONTAINER (frame), widget);
83 page->priv->alert_bar = widget; /* do not reference */
84 /* EAlertBar controls its own visibility. */
85
86 e_binding_bind_property (
87 widget, "visible",
88 frame, "visible",
89 G_BINDING_SYNC_CREATE);
90 }
91
92 static void
mail_config_activity_page_submit_alert(EAlertSink * alert_sink,EAlert * alert)93 mail_config_activity_page_submit_alert (EAlertSink *alert_sink,
94 EAlert *alert)
95 {
96 EMailConfigActivityPagePrivate *priv;
97
98 priv = E_MAIL_CONFIG_ACTIVITY_PAGE_GET_PRIVATE (alert_sink);
99
100 e_alert_bar_submit_alert (E_ALERT_BAR (priv->alert_bar), alert);
101 }
102
103 static void
e_mail_config_activity_page_class_init(EMailConfigActivityPageClass * class)104 e_mail_config_activity_page_class_init (EMailConfigActivityPageClass *class)
105 {
106 GObjectClass *object_class;
107
108 g_type_class_add_private (
109 class, sizeof (EMailConfigActivityPagePrivate));
110
111 object_class = G_OBJECT_CLASS (class);
112 object_class->constructed = mail_config_activity_page_constructed;
113 }
114
115 static void
e_mail_config_activity_page_alert_sink_init(EAlertSinkInterface * iface)116 e_mail_config_activity_page_alert_sink_init (EAlertSinkInterface *iface)
117 {
118 iface->submit_alert = mail_config_activity_page_submit_alert;
119 }
120
121 static void
e_mail_config_activity_page_init(EMailConfigActivityPage * page)122 e_mail_config_activity_page_init (EMailConfigActivityPage *page)
123 {
124 page->priv = E_MAIL_CONFIG_ACTIVITY_PAGE_GET_PRIVATE (page);
125 }
126
127 GtkWidget *
e_mail_config_activity_page_get_internal_box(EMailConfigActivityPage * page)128 e_mail_config_activity_page_get_internal_box (EMailConfigActivityPage *page)
129 {
130 g_return_val_if_fail (E_IS_MAIL_CONFIG_ACTIVITY_PAGE (page), NULL);
131
132 return page->priv->box;
133 }
134
135 EActivity *
e_mail_config_activity_page_new_activity(EMailConfigActivityPage * page)136 e_mail_config_activity_page_new_activity (EMailConfigActivityPage *page)
137 {
138 EActivity *activity;
139 EActivityBar *activity_bar;
140 GCancellable *cancellable;
141
142 g_return_val_if_fail (E_IS_MAIL_CONFIG_ACTIVITY_PAGE (page), NULL);
143
144 /* Clear any previous alerts. */
145 e_alert_bar_clear (E_ALERT_BAR (page->priv->alert_bar));
146
147 activity = e_activity_new ();
148
149 e_activity_set_alert_sink (activity, E_ALERT_SINK (page));
150
151 cancellable = camel_operation_new ();
152 e_activity_set_cancellable (activity, cancellable);
153 g_object_unref (cancellable);
154
155 activity_bar = E_ACTIVITY_BAR (page->priv->activity_bar);
156 e_activity_bar_set_activity (activity_bar, activity);
157
158 return activity;
159 }
160
161