evolution-3.6.4/modules/startup-wizard/e-mail-config-import-page.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-config-import-page.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-config-import-page.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
  1 /*
  2  * e-mail-config-import-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-page.h"
 20 
 21 #include <config.h>
 22 #include <glib/gi18n-lib.h>
 23 
 24 #include <e-util/e-import.h>
 25 
 26 #define E_MAIL_CONFIG_IMPORT_PAGE_GET_PRIVATE(obj) \
 27 	(G_TYPE_INSTANCE_GET_PRIVATE \
 28 	((obj), E_TYPE_MAIL_CONFIG_IMPORT_PAGE, EMailConfigImportPagePrivate))
 29 
 30 typedef struct _AsyncContext AsyncContext;
 31 
 32 struct _EMailConfigImportPagePrivate {
 33 	EImport *import;
 34 	EImportTarget *import_target;
 35 	GSList *available_importers;
 36 };
 37 
 38 struct _AsyncContext {
 39 	EMailConfigImportPage *page;
 40 	GQueue pending_importers;
 41 	EActivity *activity;
 42 	GCancellable *cancellable;
 43 	gulong cancel_id;
 44 };
 45 
 46 /* Forward Declarations */
 47 static void	e_mail_config_import_page_interface_init
 48 					(EMailConfigPageInterface *interface);
 49 static gboolean	mail_config_import_page_next	(gpointer user_data);
 50 
 51 G_DEFINE_DYNAMIC_TYPE_EXTENDED (
 52 	EMailConfigImportPage,
 53 	e_mail_config_import_page,
 54 	GTK_TYPE_BOX,
 55 	0,
 56 	G_IMPLEMENT_INTERFACE_DYNAMIC (
 57 		E_TYPE_MAIL_CONFIG_PAGE,
 58 		e_mail_config_import_page_interface_init))
 59 
 60 static void
 61 async_context_free (AsyncContext *async_context)
 62 {
 63 	if (async_context->page != NULL)
 64 		g_object_unref (async_context->page);
 65 
 66 	if (async_context->activity != NULL)
 67 		g_object_unref (async_context->activity);
 68 
 69 	if (async_context->cancellable != NULL) {
 70 		g_cancellable_disconnect (
 71 			async_context->cancellable,
 72 			async_context->cancel_id);
 73 		g_object_unref (async_context->cancellable);
 74 	}
 75 
 76 	g_queue_clear (&async_context->pending_importers);
 77 
 78 	g_slice_free (AsyncContext, async_context);
 79 }
 80 
 81 static void
 82 mail_config_import_page_status (EImport *import,
 83                                 const gchar *what,
 84                                 gint percent,
 85                                 GSimpleAsyncResult *simple)
 86 {
 87 	AsyncContext *async_context;
 88 
 89 	async_context = g_simple_async_result_get_op_res_gpointer (simple);
 90 
 91 	e_activity_set_text (async_context->activity, what);
 92 	e_activity_set_percent (async_context->activity, (gdouble) percent);
 93 }
 94 
 95 static void
 96 mail_config_import_page_complete (EImport *import,
 97                                   GSimpleAsyncResult *simple)
 98 {
 99 	/* Schedule the next importer to start. */
100 	g_idle_add (mail_config_import_page_next, simple);
101 }
102 
103 static gboolean
104 mail_config_import_page_next (gpointer user_data)
105 {
106 	GSimpleAsyncResult *simple;
107 	AsyncContext *async_context;
108 	GCancellable *cancellable;
109 	EImportImporter *next_importer;
110 	GError *error = NULL;
111 
112 	simple = G_SIMPLE_ASYNC_RESULT (user_data);
113 	async_context = g_simple_async_result_get_op_res_gpointer (simple);
114 	cancellable = async_context->cancellable;
115 
116 	/* Pop the completed importer and peek at the next one. */
117 	g_queue_pop_head (&async_context->pending_importers);
118 	next_importer = g_queue_peek_head (&async_context->pending_importers);
119 
120 	if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
121 		g_simple_async_result_take_error (simple, error);
122 		g_simple_async_result_complete (simple);
123 		g_object_unref (simple);
124 
125 	} else if (next_importer != NULL) {
126 		e_import_import (
127 			async_context->page->priv->import,
128 			async_context->page->priv->import_target,
129 			next_importer,
130 			(EImportStatusFunc) mail_config_import_page_status,
131 			(EImportCompleteFunc) mail_config_import_page_complete,
132 			simple);
133 
134 	} else {
135 		g_simple_async_result_complete (simple);
136 		g_object_unref (simple);
137 	}
138 
139 	return FALSE;
140 }
141 
142 static void
143 mail_config_import_page_cancelled (GCancellable *cancellable,
144                                    AsyncContext *async_context)
145 {
146 	GQueue *pending_importers;
147 	EImportImporter *current_importer;
148 
149 	pending_importers = &async_context->pending_importers;
150 	current_importer = g_queue_peek_head (pending_importers);
151 	g_return_if_fail (current_importer != NULL);
152 
153 	e_import_cancel (
154 		async_context->page->priv->import,
155 		async_context->page->priv->import_target,
156 		current_importer);
157 }
158 
159 static void
160 mail_config_import_page_dispose (GObject *object)
161 {
162 	EMailConfigImportPagePrivate *priv;
163 
164 	priv = E_MAIL_CONFIG_IMPORT_PAGE_GET_PRIVATE (object);
165 
166 	if (priv->import != NULL) {
167 		e_import_target_free (
168 			priv->import,
169 			priv->import_target);
170 		g_object_unref (priv->import);
171 		priv->import_target = NULL;
172 		priv->import = NULL;
173 	}
174 
175 	g_slist_free (priv->available_importers);
176 	priv->available_importers = NULL;
177 
178 	/* Chain up to parent's dispose() method. */
179 	G_OBJECT_CLASS (e_mail_config_import_page_parent_class)->
180 		dispose (object);
181 }
182 
183 static void
184 mail_config_import_page_constructed (GObject *object)
185 {
186 	EMailConfigImportPage *page;
187 	GtkWidget *widget;
188 	GtkWidget *container;
189 	GSList *list, *link;
190 	const gchar *text;
191 	gint row = 0;
192 
193 	page = E_MAIL_CONFIG_IMPORT_PAGE (object);
194 
195 	/* Chain up to parent's constructed() method. */
196 	G_OBJECT_CLASS (e_mail_config_import_page_parent_class)->
197 		constructed (object);
198 
199 	gtk_orientable_set_orientation (
200 		GTK_ORIENTABLE (page), GTK_ORIENTATION_VERTICAL);
201 
202 	gtk_box_set_spacing (GTK_BOX (page), 24);
203 
204 	text = _("Please select the information "
205 		 "that you would like to import:");
206 	widget = gtk_label_new (text);
207 	gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
208 	gtk_box_pack_start (GTK_BOX (page), widget, FALSE, FALSE, 0);
209 	gtk_widget_show (widget);
210 
211 	widget = gtk_grid_new ();
212 	gtk_grid_set_row_spacing (GTK_GRID (widget), 12);
213 	gtk_grid_set_column_spacing (GTK_GRID (widget), 12);
214 	gtk_box_pack_start (GTK_BOX (page), widget, FALSE, FALSE, 0);
215 	gtk_widget_show (widget);
216 
217 	container = widget;
218 
219 	list = page->priv->available_importers;
220 
221 	for (link = list; link != NULL; link = link->next) {
222 		EImportImporter *importer = link->data;
223 		gchar *from_text;
224 
225 		widget = e_import_get_widget (
226 			page->priv->import,
227 			page->priv->import_target, importer);
228 		if (widget == NULL)
229 			continue;
230 		gtk_grid_attach (GTK_GRID (container), widget, 1, row, 1, 1);
231 		gtk_widget_show (widget);
232 
233 		from_text = g_strdup_printf (_("From %s:"), importer->name);
234 		widget = gtk_label_new (from_text);
235 		gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.0);
236 		gtk_grid_attach (GTK_GRID (container), widget, 0, row, 1, 1);
237 		gtk_widget_show (widget);
238 
239 		row++;
240 	}
241 }
242 
243 static void
244 e_mail_config_import_page_class_init (EMailConfigImportPageClass *class)
245 {
246 	GObjectClass *object_class;
247 
248 	g_type_class_add_private (
249 		class, sizeof (EMailConfigImportPagePrivate));
250 
251 	object_class = G_OBJECT_CLASS (class);
252 	object_class->dispose = mail_config_import_page_dispose;
253 	object_class->constructed = mail_config_import_page_constructed;
254 }
255 
256 static void
257 e_mail_config_import_page_class_finalize (EMailConfigImportPageClass *class)
258 {
259 }
260 
261 static void
262 e_mail_config_import_page_interface_init (EMailConfigPageInterface *interface)
263 {
264 	interface->title = _("Importing Files");
265 	interface->sort_order = E_MAIL_CONFIG_IMPORT_PAGE_SORT_ORDER;
266 }
267 
268 static void
269 e_mail_config_import_page_init (EMailConfigImportPage *page)
270 {
271 	page->priv = E_MAIL_CONFIG_IMPORT_PAGE_GET_PRIVATE (page);
272 
273 	page->priv->import =
274 		e_import_new ("org.gnome.evolution.shell.importer");
275 	page->priv->import_target = (EImportTarget *)
276 		e_import_target_new_home (page->priv->import);
277 	page->priv->available_importers = e_import_get_importers (
278 		page->priv->import, page->priv->import_target);
279 }
280 
281 void
282 e_mail_config_import_page_type_register (GTypeModule *type_module)
283 {
284 	/* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration
285 	 *     function, so we have to wrap it with a public function in
286 	 *     order to register types from a separate compilation unit. */
287 	e_mail_config_import_page_register_type (type_module);
288 }
289 
290 EMailConfigPage *
291 e_mail_config_import_page_new (void)
292 {
293 	return g_object_new (E_TYPE_MAIL_CONFIG_IMPORT_PAGE, NULL);
294 }
295 
296 guint
297 e_mail_config_import_page_get_n_importers (EMailConfigImportPage *page)
298 {
299 	g_return_val_if_fail (E_IS_MAIL_CONFIG_IMPORT_PAGE (page), 0);
300 
301 	return g_slist_length (page->priv->available_importers);
302 }
303 
304 void
305 e_mail_config_import_page_import (EMailConfigImportPage *page,
306                                   EActivity *activity,
307                                   GAsyncReadyCallback callback,
308                                   gpointer user_data)
309 {
310 	GSimpleAsyncResult *simple;
311 	AsyncContext *async_context;
312 	GCancellable *cancellable;
313 	EImportImporter *first_importer;
314 	GSList *list, *link;
315 
316 	g_return_if_fail (E_IS_MAIL_CONFIG_IMPORT_PAGE (page));
317 	g_return_if_fail (E_IS_ACTIVITY (activity));
318 
319 	cancellable = e_activity_get_cancellable (activity);
320 
321 	async_context = g_slice_new0 (AsyncContext);
322 	async_context->page = g_object_ref (page);
323 	async_context->activity = g_object_ref (activity);
324 
325 	list = page->priv->available_importers;
326 
327 	for (link = list; link != NULL; link = g_slist_next (link)) {
328 		EImportImporter *importer = link->data;
329 		g_queue_push_tail (&async_context->pending_importers, importer);
330 	}
331 
332 	if (G_IS_CANCELLABLE (cancellable)) {
333 		async_context->cancellable = g_object_ref (cancellable);
334 		async_context->cancel_id = g_cancellable_connect (
335 			cancellable,
336 			G_CALLBACK (mail_config_import_page_cancelled),
337 			async_context, (GDestroyNotify) NULL);
338 	}
339 
340 	simple = g_simple_async_result_new (
341 		G_OBJECT (page), callback, user_data,
342 		e_mail_config_import_page_import);
343 
344 	g_simple_async_result_set_op_res_gpointer (
345 		simple, async_context, (GDestroyNotify) async_context_free);
346 
347 	/* Start the first importer. */
348 
349 	first_importer = g_queue_peek_head (&async_context->pending_importers);
350 
351 	if (first_importer != NULL)
352 		e_import_import (
353 			async_context->page->priv->import,
354 			async_context->page->priv->import_target,
355 			first_importer,
356 			(EImportStatusFunc) mail_config_import_page_status,
357 			(EImportCompleteFunc) mail_config_import_page_complete,
358 			simple);
359 	else
360 		g_simple_async_result_complete_in_idle (simple);
361 }
362 
363 gboolean
364 e_mail_config_import_page_import_finish (EMailConfigImportPage *page,
365                                          GAsyncResult *result,
366                                          GError **error)
367 {
368 	GSimpleAsyncResult *simple;
369 
370 	g_return_val_if_fail (
371 		g_simple_async_result_is_valid (
372 		result, G_OBJECT (page),
373 		e_mail_config_import_page_import), FALSE);
374 
375 	simple = G_SIMPLE_ASYNC_RESULT (result);
376 
377 	/* Assume success unless a GError is set. */
378 	return !g_simple_async_result_propagate_error (simple, error);
379 }