No issues found
Tool | Failure ID | Location | Function | Message | Data |
---|---|---|---|---|---|
clang-analyzer | no-output-found | e-mail-config-import-progress-page.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None | |
clang-analyzer | no-output-found | e-mail-config-import-progress-page.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None |
1 /*
2 * e-mail-config-import-progress-page.c
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with the program; if not, see <http://www.gnu.org/licenses/>
16 *
17 */
18
19 #include "e-mail-config-import-progress-page.h"
20
21 #include <config.h>
22 #include <glib/gi18n-lib.h>
23
24 #define E_MAIL_CONFIG_IMPORT_PROGRESS_PAGE_GET_PRIVATE(obj) \
25 (G_TYPE_INSTANCE_GET_PRIVATE \
26 ((obj), E_TYPE_MAIL_CONFIG_IMPORT_PROGRESS_PAGE, EMailConfigImportProgressPagePrivate))
27
28 struct _EMailConfigImportProgressPagePrivate {
29 EActivity *activity;
30 GtkWidget *progress_bar; /* not referenced */
31 GtkWidget *cancelled_msg; /* not referenced */
32 GtkWidget *completed_msg; /* not referenced */
33 };
34
35 enum {
36 PROP_0,
37 PROP_ACTIVITY
38 };
39
40 /* Forward Declarations */
41 static void e_mail_config_import_progress_page_interface_init
42 (EMailConfigPageInterface *interface);
43
44 G_DEFINE_DYNAMIC_TYPE_EXTENDED (
45 EMailConfigImportProgressPage,
46 e_mail_config_import_progress_page,
47 GTK_TYPE_BOX,
48 0,
49 G_IMPLEMENT_INTERFACE_DYNAMIC (
50 E_TYPE_MAIL_CONFIG_PAGE,
51 e_mail_config_import_progress_page_interface_init))
52
53 static gboolean
54 mail_config_import_progress_page_is_cancelled (GBinding *binding,
55 const GValue *source_value,
56 GValue *target_value,
57 gpointer unused)
58 {
59 EActivityState state;
60 gboolean is_cancelled;
61
62 state = g_value_get_enum (source_value);
63 is_cancelled = (state == E_ACTIVITY_CANCELLED);
64 g_value_set_boolean (target_value, is_cancelled);
65
66 return TRUE;
67 }
68
69 static gboolean
70 mail_config_import_progress_page_is_completed (GBinding *binding,
71 const GValue *source_value,
72 GValue *target_value,
73 gpointer unused)
74 {
75 EActivityState state;
76 gboolean is_completed;
77
78 state = g_value_get_enum (source_value);
79 is_completed = (state == E_ACTIVITY_COMPLETED);
80 g_value_set_boolean (target_value, is_completed);
81
82 return TRUE;
83 }
84
85 static gboolean
86 mail_config_import_progress_page_percent_to_fraction (GBinding *binding,
87 const GValue *source_value,
88 GValue *target_value,
89 gpointer unused)
90 {
91 gdouble fraction;
92
93 fraction = g_value_get_double (source_value) / 100.0;
94 g_value_set_double (target_value, CLAMP (fraction, 0.0, 1.0));
95
96 return TRUE;
97 }
98
99 static void
100 mail_config_import_progress_page_set_activity (EMailConfigImportProgressPage *page,
101 EActivity *activity)
102 {
103 g_return_if_fail (E_IS_ACTIVITY (activity));
104 g_return_if_fail (page->priv->activity == NULL);
105
106 page->priv->activity = g_object_ref (activity);
107 }
108
109 static void
110 mail_config_import_progress_page_set_property (GObject *object,
111 guint property_id,
112 const GValue *value,
113 GParamSpec *pspec)
114 {
115 switch (property_id) {
116 case PROP_ACTIVITY:
117 mail_config_import_progress_page_set_activity (
118 E_MAIL_CONFIG_IMPORT_PROGRESS_PAGE (object),
119 g_value_get_object (value));
120 return;
121 }
122
123 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
124 }
125
126 static void
127 mail_config_import_progress_page_get_property (GObject *object,
128 guint property_id,
129 GValue *value,
130 GParamSpec *pspec)
131 {
132 switch (property_id) {
133 case PROP_ACTIVITY:
134 g_value_set_object (
135 value,
136 e_mail_config_import_progress_page_get_activity (
137 E_MAIL_CONFIG_IMPORT_PROGRESS_PAGE (object)));
138 return;
139 }
140
141 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
142 }
143
144 static void
145 mail_config_import_progress_page_dispose (GObject *object)
146 {
147 EMailConfigImportProgressPagePrivate *priv;
148
149 priv = E_MAIL_CONFIG_IMPORT_PROGRESS_PAGE_GET_PRIVATE (object);
150
151 if (priv->activity != NULL) {
152 g_object_unref (priv->activity);
153 priv->activity = NULL;
154 }
155
156 /* Chain up to parent's dispose() method. */
157 G_OBJECT_CLASS (e_mail_config_import_progress_page_parent_class)->
158 dispose (object);
159 }
160
161 static void
162 mail_config_import_progress_page_constructed (GObject *object)
163 {
164 EMailConfigImportProgressPage *page;
165 GtkSizeGroup *size_group;
166 GtkWidget *container;
167 GtkWidget *widget;
168 EActivity *activity;
169
170 page = E_MAIL_CONFIG_IMPORT_PROGRESS_PAGE (object);
171
172 /* Chain up to parent's constructed() method. */
173 G_OBJECT_CLASS (e_mail_config_import_progress_page_parent_class)->
174 constructed (object);
175
176 gtk_orientable_set_orientation (
177 GTK_ORIENTABLE (page), GTK_ORIENTATION_VERTICAL);
178
179 gtk_box_set_spacing (GTK_BOX (page), 12);
180
181 gtk_widget_set_valign (GTK_WIDGET (page), GTK_ALIGN_CENTER);
182
183 activity = e_mail_config_import_progress_page_get_activity (page);
184
185 /* The activity state affects the "check-complete" result. */
186 g_signal_connect_swapped (
187 activity, "notify::state",
188 G_CALLBACK (e_mail_config_page_changed), page);
189
190 size_group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
191
192 /* Just a spacer. */
193 widget = gtk_alignment_new (0.5, 0.0, 0.0, 0.0);
194 gtk_size_group_add_widget (size_group, widget);
195 gtk_box_pack_start (GTK_BOX (page), widget, TRUE, TRUE, 0);
196 gtk_widget_show (widget);
197
198 widget = gtk_progress_bar_new ();
199 gtk_box_pack_start (GTK_BOX (page), widget, FALSE, FALSE, 0);
200 page->priv->progress_bar = widget; /* not referenced */
201 gtk_widget_show (widget);
202
203 g_object_bind_property (
204 activity, "text",
205 widget, "text",
206 G_BINDING_SYNC_CREATE);
207
208 g_object_bind_property_full (
209 activity, "percent",
210 widget, "fraction",
211 G_BINDING_SYNC_CREATE,
212 mail_config_import_progress_page_percent_to_fraction,
213 NULL,
214 NULL, (GDestroyNotify) NULL);
215
216 widget = gtk_vbox_new (FALSE, 12);
217 gtk_size_group_add_widget (size_group, widget);
218 gtk_box_pack_start (GTK_BOX (page), widget, TRUE, TRUE, 0);
219 gtk_widget_show (widget);
220
221 container = widget;
222
223 widget = gtk_alignment_new (0.5, 0.0, 0.0, 0.0);
224 gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
225 page->priv->cancelled_msg = widget; /* not referenced */
226
227 g_object_bind_property_full (
228 activity, "state",
229 widget, "visible",
230 G_BINDING_SYNC_CREATE,
231 mail_config_import_progress_page_is_cancelled,
232 NULL,
233 NULL, (GDestroyNotify) NULL);
234
235 widget = gtk_alignment_new (0.5, 0.0, 0.0, 0.0);
236 gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
237 page->priv->completed_msg = widget; /* not referenced */
238 gtk_widget_show (widget);
239
240 g_object_bind_property_full (
241 activity, "state",
242 widget, "visible",
243 G_BINDING_SYNC_CREATE,
244 mail_config_import_progress_page_is_completed,
245 NULL,
246 NULL, (GDestroyNotify) NULL);
247
248 container = page->priv->cancelled_msg;
249
250 widget = gtk_hbox_new (FALSE, 6);
251 gtk_container_add (GTK_CONTAINER (container), widget);
252 gtk_widget_show (widget);
253
254 container = widget;
255
256 widget = gtk_image_new_from_stock (
257 GTK_STOCK_CANCEL, GTK_ICON_SIZE_MENU);
258 gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
259 gtk_widget_show (widget);
260
261 widget = gtk_label_new (_("Import cancelled."));
262 gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
263 gtk_widget_show (widget);
264
265 container = page->priv->completed_msg;
266
267 widget = gtk_hbox_new (FALSE, 6);
268 gtk_container_add (GTK_CONTAINER (container), widget);
269 gtk_widget_show (widget);
270
271 container = widget;
272
273 widget = gtk_image_new_from_icon_name (
274 "emblem-default", GTK_ICON_SIZE_MENU);
275 gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
276 gtk_widget_show (widget);
277
278 widget = gtk_label_new _("Import complete.");
279 gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
280 gtk_widget_show (widget);
281
282 g_object_unref (size_group);
283 }
284
285 static gboolean
286 mail_config_import_progress_page_check_complete (EMailConfigPage *page)
287 {
288 EMailConfigImportProgressPagePrivate *priv;
289 gboolean complete;
290
291 priv = E_MAIL_CONFIG_IMPORT_PROGRESS_PAGE_GET_PRIVATE (page);
292
293 switch (e_activity_get_state (priv->activity)) {
294 case E_ACTIVITY_CANCELLED:
295 case E_ACTIVITY_COMPLETED:
296 complete = TRUE;
297 break;
298 default:
299 complete = FALSE;
300 break;
301 }
302
303 return complete;
304 }
305
306 static void
307 e_mail_config_import_progress_page_class_init (EMailConfigImportProgressPageClass *class)
308 {
309 GObjectClass *object_class;
310
311 g_type_class_add_private (
312 class, sizeof (EMailConfigImportProgressPagePrivate));
313
314 object_class = G_OBJECT_CLASS (class);
315 object_class->set_property = mail_config_import_progress_page_set_property;
316 object_class->get_property = mail_config_import_progress_page_get_property;
317 object_class->dispose = mail_config_import_progress_page_dispose;
318 object_class->constructed = mail_config_import_progress_page_constructed;
319
320 g_object_class_install_property (
321 object_class,
322 PROP_ACTIVITY,
323 g_param_spec_object (
324 "activity",
325 "Activity",
326 "Import activity",
327 E_TYPE_ACTIVITY,
328 G_PARAM_READWRITE |
329 G_PARAM_CONSTRUCT_ONLY));
330 }
331
332 static void
333 e_mail_config_import_progress_page_class_finalize (EMailConfigImportProgressPageClass *class)
334 {
335 }
336
337 static void
338 e_mail_config_import_progress_page_interface_init (EMailConfigPageInterface *interface)
339 {
340 /* Keep the title identical to EMailConfigImportPage
341 * so it's only shown once in the assistant sidebar. */
342 interface->title = _("Importing Files");
343 interface->sort_order = E_MAIL_CONFIG_IMPORT_PROGRESS_PAGE_SORT_ORDER;
344 interface->page_type = GTK_ASSISTANT_PAGE_PROGRESS;
345 interface->check_complete = mail_config_import_progress_page_check_complete;
346 }
347
348 static void
349 e_mail_config_import_progress_page_init (EMailConfigImportProgressPage *page)
350 {
351 page->priv = E_MAIL_CONFIG_IMPORT_PROGRESS_PAGE_GET_PRIVATE (page);
352 }
353
354 void
355 e_mail_config_import_progress_page_type_register (GTypeModule *type_module)
356 {
357 /* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration
358 * function, so we have to wrap it with a public function in
359 * order to register types from a separate compilation unit. */
360 e_mail_config_import_progress_page_register_type (type_module);
361 }
362
363 EMailConfigPage *
364 e_mail_config_import_progress_page_new (EActivity *activity)
365 {
366 g_return_val_if_fail (E_IS_ACTIVITY (activity), NULL);
367
368 return g_object_new (
369 E_TYPE_MAIL_CONFIG_IMPORT_PROGRESS_PAGE,
370 "activity", activity, NULL);
371 }
372
373 EActivity *
374 e_mail_config_import_progress_page_get_activity (EMailConfigImportProgressPage *page)
375 {
376 g_return_val_if_fail (
377 E_IS_MAIL_CONFIG_IMPORT_PROGRESS_PAGE (page), NULL);
378
379 return page->priv->activity;
380 }