evolution-3.6.4/modules/mail/e-mail-shell-content.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-shell-content.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-shell-content.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-shell-content.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  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 19  *
 20  */
 21 
 22 #ifdef HAVE_CONFIG_H
 23 #include <config.h>
 24 #endif
 25 
 26 #include "e-mail-shell-content.h"
 27 
 28 #include <glib/gi18n.h>
 29 
 30 #include <e-util/e-util-private.h>
 31 
 32 #include <widgets/menus/gal-view-etable.h>
 33 #include <widgets/menus/gal-view-instance.h>
 34 #include <widgets/misc/e-paned.h>
 35 #include <widgets/misc/e-preview-pane.h>
 36 #include <widgets/misc/e-search-bar.h>
 37 
 38 #include <libemail-engine/mail-ops.h>
 39 
 40 #include <mail/e-mail-paned-view.h>
 41 #include <mail/e-mail-notebook-view.h>
 42 #include <mail/e-mail-reader.h>
 43 #include <mail/e-mail-reader-utils.h>
 44 #include <mail/em-utils.h>
 45 #include <mail/message-list.h>
 46 
 47 #include "e-mail-shell-backend.h"
 48 #include "e-mail-shell-view-actions.h"
 49 
 50 #define E_MAIL_SHELL_CONTENT_GET_PRIVATE(obj) \
 51 	(G_TYPE_INSTANCE_GET_PRIVATE \
 52 	((obj), E_TYPE_MAIL_SHELL_CONTENT, EMailShellContentPrivate))
 53 
 54 struct _EMailShellContentPrivate {
 55 	EMailView *mail_view;
 56 };
 57 
 58 enum {
 59 	PROP_0,
 60 	PROP_FORWARD_STYLE,
 61 	PROP_GROUP_BY_THREADS,
 62 	PROP_MAIL_VIEW,
 63 	PROP_REPLY_STYLE
 64 };
 65 
 66 /* Forward Declarations */
 67 static void	e_mail_shell_content_reader_init
 68 					(EMailReaderInterface *interface);
 69 
 70 G_DEFINE_DYNAMIC_TYPE_EXTENDED (
 71 	EMailShellContent,
 72 	e_mail_shell_content,
 73 	E_TYPE_SHELL_CONTENT,
 74 	0,
 75 	G_IMPLEMENT_INTERFACE_DYNAMIC (
 76 		E_TYPE_MAIL_READER,
 77 		e_mail_shell_content_reader_init))
 78 
 79 static void
 80 reconnect_changed_event (EMailReader *child,
 81                          EMailReader *parent)
 82 {
 83 	g_signal_emit_by_name (parent, "changed");
 84 }
 85 
 86 static void
 87 reconnect_folder_loaded_event (EMailReader *child,
 88                EMailReader *parent)
 89 {
 90 	g_signal_emit_by_name (parent, "folder-loaded");
 91 }
 92 
 93 static void
 94 mail_shell_content_view_changed_cb (EMailView *view,
 95                                     EMailShellContent *content)
 96 {
 97 	g_object_freeze_notify (G_OBJECT (content));
 98 	g_object_notify (G_OBJECT (content), "group-by-threads");
 99 	g_object_thaw_notify (G_OBJECT (content));
100 }
101 
102 static void
103 mail_shell_content_set_property (GObject *object,
104                                  guint property_id,
105                                  const GValue *value,
106                                  GParamSpec *pspec)
107 {
108 	switch (property_id) {
109 		case PROP_FORWARD_STYLE:
110 			e_mail_reader_set_forward_style (
111 				E_MAIL_READER (object),
112 				g_value_get_enum (value));
113 			return;
114 
115 		case PROP_GROUP_BY_THREADS:
116 			e_mail_reader_set_group_by_threads (
117 				E_MAIL_READER (object),
118 				g_value_get_boolean (value));
119 			return;
120 
121 		case PROP_REPLY_STYLE:
122 			e_mail_reader_set_reply_style (
123 				E_MAIL_READER (object),
124 				g_value_get_enum (value));
125 			return;
126 	}
127 
128 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
129 }
130 
131 static void
132 mail_shell_content_get_property (GObject *object,
133                                  guint property_id,
134                                  GValue *value,
135                                  GParamSpec *pspec)
136 {
137 	switch (property_id) {
138 		case PROP_FORWARD_STYLE:
139 			g_value_set_enum (
140 				value, e_mail_reader_get_forward_style (
141 				E_MAIL_READER (object)));
142 			return;
143 
144 		case PROP_GROUP_BY_THREADS:
145 			g_value_set_boolean (
146 				value, e_mail_reader_get_group_by_threads (
147 				E_MAIL_READER (object)));
148 			return;
149 
150 		case PROP_MAIL_VIEW:
151 			g_value_set_object (
152 				value, e_mail_shell_content_get_mail_view (
153 				E_MAIL_SHELL_CONTENT (object)));
154 			return;
155 
156 		case PROP_REPLY_STYLE:
157 			g_value_set_enum (
158 				value, e_mail_reader_get_reply_style (
159 				E_MAIL_READER (object)));
160 			return;
161 	}
162 
163 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
164 }
165 
166 static void
167 mail_shell_content_dispose (GObject *object)
168 {
169 	EMailShellContentPrivate *priv;
170 
171 	priv = E_MAIL_SHELL_CONTENT_GET_PRIVATE (object);
172 
173 	if (priv->mail_view != NULL) {
174 		g_object_unref (priv->mail_view);
175 		priv->mail_view = NULL;
176 	}
177 
178 	/* Chain up to parent's dispose() method. */
179 	G_OBJECT_CLASS (e_mail_shell_content_parent_class)->dispose (object);
180 }
181 
182 static void
183 mail_shell_content_constructed (GObject *object)
184 {
185 	EMailShellContentPrivate *priv;
186 	EShellContent *shell_content;
187 	EShellView *shell_view;
188 	GtkWidget *container;
189 	GtkWidget *widget;
190 
191 	priv = E_MAIL_SHELL_CONTENT_GET_PRIVATE (object);
192 
193 	/* Chain up to parent's constructed () method. */
194 	G_OBJECT_CLASS (e_mail_shell_content_parent_class)->constructed (object);
195 
196 	shell_content = E_SHELL_CONTENT (object);
197 	shell_view = e_shell_content_get_shell_view (shell_content);
198 
199 	/* Build content widgets. */
200 
201 	container = GTK_WIDGET (object);
202 
203 	if (e_shell_get_express_mode (e_shell_get_default ())) {
204 		widget = e_mail_notebook_view_new (shell_view);
205 		g_signal_connect (
206 			widget, "view-changed",
207 			G_CALLBACK (mail_shell_content_view_changed_cb),
208 			object);
209 	} else
210 		widget = e_mail_paned_view_new (shell_view);
211 
212 	gtk_container_add (GTK_CONTAINER (container), widget);
213 	priv->mail_view = g_object_ref (widget);
214 	gtk_widget_show (widget);
215 
216 	g_signal_connect (
217 		widget, "changed",
218 		G_CALLBACK (reconnect_changed_event), object);
219 	g_signal_connect (
220 		widget, "folder-loaded",
221 		G_CALLBACK (reconnect_folder_loaded_event), object);
222 }
223 
224 static guint32
225 mail_shell_content_check_state (EShellContent *shell_content)
226 {
227 	EMailShellContent *mail_shell_content;
228 	EMailReader *reader;
229 
230 	mail_shell_content = E_MAIL_SHELL_CONTENT (shell_content);
231 
232 	/* Forward this to our internal EMailView, which
233 	 * also implements the EMailReader interface. */
234 	reader = E_MAIL_READER (mail_shell_content->priv->mail_view);
235 
236 	return e_mail_reader_check_state (reader);
237 }
238 
239 static void
240 mail_shell_content_focus_search_results (EShellContent *shell_content)
241 {
242 	EMailShellContent *mail_shell_content;
243 	GtkWidget *message_list;
244 	EMailReader *reader;
245 
246 	mail_shell_content = E_MAIL_SHELL_CONTENT (shell_content);
247 
248 	reader = E_MAIL_READER (mail_shell_content->priv->mail_view);
249 	message_list = e_mail_reader_get_message_list (reader);
250 
251 	gtk_widget_grab_focus (message_list);
252 }
253 
254 static guint
255 mail_shell_content_open_selected_mail (EMailReader *reader)
256 {
257 	EMailShellContent *mail_shell_content;
258 
259 	mail_shell_content = E_MAIL_SHELL_CONTENT (reader);
260 
261 	/* Forward this to our internal EMailView, which
262 	 * also implements the EMailReader interface. */
263 	reader = E_MAIL_READER (mail_shell_content->priv->mail_view);
264 
265 	return e_mail_reader_open_selected_mail (reader);
266 }
267 
268 static GtkActionGroup *
269 mail_shell_content_get_action_group (EMailReader *reader,
270                                      EMailReaderActionGroup group)
271 {
272 	EShellView *shell_view;
273 	EShellWindow *shell_window;
274 	EShellContent *shell_content;
275 	const gchar *group_name;
276 
277 	shell_content = E_SHELL_CONTENT (reader);
278 	shell_view = e_shell_content_get_shell_view (shell_content);
279 	shell_window = e_shell_view_get_shell_window (shell_view);
280 
281 	switch (group) {
282 		case E_MAIL_READER_ACTION_GROUP_STANDARD:
283 			group_name = "mail";
284 			break;
285 		case E_MAIL_READER_ACTION_GROUP_SEARCH_FOLDERS:
286 			group_name = "search-folders";
287 			break;
288 		default:
289 			g_return_val_if_reached (NULL);
290 	}
291 
292 	return e_shell_window_get_action_group (shell_window, group_name);
293 }
294 
295 static EMailBackend *
296 mail_shell_content_get_backend (EMailReader *reader)
297 {
298 	EMailShellContent *mail_shell_content;
299 
300 	mail_shell_content = E_MAIL_SHELL_CONTENT (reader);
301 
302 	/* Forward this to our internal EMailView, which
303 	 * also implements the EMailReader interface. */
304 	reader = E_MAIL_READER (mail_shell_content->priv->mail_view);
305 
306 	return e_mail_reader_get_backend (reader);
307 }
308 
309 static EMailDisplay *
310 mail_shell_content_get_mail_display (EMailReader *reader)
311 {
312 	EMailShellContent *mail_shell_content;
313 
314 	mail_shell_content = E_MAIL_SHELL_CONTENT (reader);
315 
316 	/* Forward this to our internal EMailView, which
317 	 * also implements the EMailReader interface. */
318 	reader = E_MAIL_READER (mail_shell_content->priv->mail_view);
319 	return e_mail_reader_get_mail_display (reader);
320 }
321 
322 static gboolean
323 mail_shell_content_get_hide_deleted (EMailReader *reader)
324 {
325 	EMailShellContent *mail_shell_content;
326 
327 	mail_shell_content = E_MAIL_SHELL_CONTENT (reader);
328 
329 	/* Forward this to our internal EMailView, which
330 	 * also implements the EMailReader interface. */
331 	reader = E_MAIL_READER (mail_shell_content->priv->mail_view);
332 
333 	return e_mail_reader_get_hide_deleted (reader);
334 }
335 
336 static GtkWidget *
337 mail_shell_content_get_message_list (EMailReader *reader)
338 {
339 	EMailShellContent *mail_shell_content;
340 
341 	mail_shell_content = E_MAIL_SHELL_CONTENT (reader);
342 
343 	/* Forward this to our internal EMailView, which
344 	 * also implements the EMailReader interface. */
345 	reader = E_MAIL_READER (mail_shell_content->priv->mail_view);
346 
347 	return e_mail_reader_get_message_list (reader);
348 }
349 
350 static GtkMenu *
351 mail_shell_content_get_popup_menu (EMailReader *reader)
352 {
353 	EMailShellContent *mail_shell_content;
354 
355 	mail_shell_content = E_MAIL_SHELL_CONTENT (reader);
356 
357 	/* Forward this to our internal EMailView, which
358 	 * also implements the EMailReader interface. */
359 	reader = E_MAIL_READER (mail_shell_content->priv->mail_view);
360 
361 	return e_mail_reader_get_popup_menu (reader);
362 }
363 
364 static EPreviewPane *
365 mail_shell_content_get_preview_pane (EMailReader *reader)
366 {
367 	EMailShellContent *mail_shell_content;
368 
369 	mail_shell_content = E_MAIL_SHELL_CONTENT (reader);
370 
371 	/* Forward this to our internal EMailView, which
372 	 * also implements the EMailReader interface. */
373 	reader = E_MAIL_READER (mail_shell_content->priv->mail_view);
374 
375 	return e_mail_reader_get_preview_pane (reader);
376 }
377 
378 static GtkWindow *
379 mail_shell_content_get_window (EMailReader *reader)
380 {
381 	EMailShellContent *mail_shell_content;
382 
383 	mail_shell_content = E_MAIL_SHELL_CONTENT (reader);
384 
385 	/* Forward this to our internal EMailView, which
386 	 * also implements the EMailReader interface. */
387 	reader = E_MAIL_READER (mail_shell_content->priv->mail_view);
388 
389 	return e_mail_reader_get_window (reader);
390 }
391 
392 static void
393 mail_shell_content_set_folder (EMailReader *reader,
394                                CamelFolder *folder)
395 {
396 	EMailShellContent *mail_shell_content;
397 
398 	mail_shell_content = E_MAIL_SHELL_CONTENT (reader);
399 
400 	/* Forward this to our internal EMailView, which
401 	 * also implements the EMailReader interface. */
402 	reader = E_MAIL_READER (mail_shell_content->priv->mail_view);
403 
404 	return e_mail_reader_set_folder (reader, folder);
405 }
406 
407 static void
408 e_mail_shell_content_class_init (EMailShellContentClass *class)
409 {
410 	GObjectClass *object_class;
411 	EShellContentClass *shell_content_class;
412 
413 	g_type_class_add_private (class, sizeof (EMailShellContentPrivate));
414 
415 	object_class = G_OBJECT_CLASS (class);
416 	object_class->set_property = mail_shell_content_set_property;
417 	object_class->get_property = mail_shell_content_get_property;
418 	object_class->dispose = mail_shell_content_dispose;
419 	object_class->constructed = mail_shell_content_constructed;
420 
421 	shell_content_class = E_SHELL_CONTENT_CLASS (class);
422 	shell_content_class->check_state = mail_shell_content_check_state;
423 	shell_content_class->focus_search_results =
424 		mail_shell_content_focus_search_results;
425 
426 	/* Inherited from EMailReader */
427 	g_object_class_override_property (
428 		object_class,
429 		PROP_FORWARD_STYLE,
430 		"forward-style");
431 
432 	/* Inherited from EMailReader */
433 	g_object_class_override_property (
434 		object_class,
435 		PROP_GROUP_BY_THREADS,
436 		"group-by-threads");
437 
438 	g_object_class_install_property (
439 		object_class,
440 		PROP_MAIL_VIEW,
441 		g_param_spec_object (
442 			"mail-view",
443 			"Mail View",
444 			NULL,
445 			E_TYPE_MAIL_VIEW,
446 			G_PARAM_READABLE));
447 
448 	/* Inherited from EMailReader */
449 	g_object_class_override_property (
450 		object_class,
451 		PROP_REPLY_STYLE,
452 		"reply-style");
453 }
454 
455 static void
456 e_mail_shell_content_class_finalize (EMailShellContentClass *class)
457 {
458 }
459 
460 static void
461 e_mail_shell_content_reader_init (EMailReaderInterface *interface)
462 {
463 	interface->get_action_group = mail_shell_content_get_action_group;
464 	interface->get_backend = mail_shell_content_get_backend;
465 	interface->get_mail_display = mail_shell_content_get_mail_display;
466 	interface->get_hide_deleted = mail_shell_content_get_hide_deleted;
467 	interface->get_message_list = mail_shell_content_get_message_list;
468 	interface->get_popup_menu = mail_shell_content_get_popup_menu;
469 	interface->get_preview_pane = mail_shell_content_get_preview_pane;
470 	interface->get_window = mail_shell_content_get_window;
471 	interface->set_folder = mail_shell_content_set_folder;
472 	interface->open_selected_mail = mail_shell_content_open_selected_mail;
473 }
474 
475 static void
476 e_mail_shell_content_init (EMailShellContent *mail_shell_content)
477 {
478 	mail_shell_content->priv =
479 		E_MAIL_SHELL_CONTENT_GET_PRIVATE (mail_shell_content);
480 
481 	/* Postpone widget construction until we have a shell view. */
482 }
483 
484 void
485 e_mail_shell_content_type_register (GTypeModule *type_module)
486 {
487 	/* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration
488 	 *     function, so we have to wrap it with a public function in
489 	 *     order to register types from a separate compilation unit. */
490 	e_mail_shell_content_register_type (type_module);
491 }
492 
493 GtkWidget *
494 e_mail_shell_content_new (EShellView *shell_view)
495 {
496 	g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
497 
498 	return g_object_new (
499 		E_TYPE_MAIL_SHELL_CONTENT,
500 		"shell-view", shell_view, NULL);
501 }
502 
503 EMailView *
504 e_mail_shell_content_get_mail_view (EMailShellContent *mail_shell_content)
505 {
506 	g_return_val_if_fail (
507 		E_IS_MAIL_SHELL_CONTENT (mail_shell_content), NULL);
508 
509 	return mail_shell_content->priv->mail_view;
510 }
511 
512 EShellSearchbar *
513 e_mail_shell_content_get_searchbar (EMailShellContent *mail_shell_content)
514 {
515 	GtkWidget *searchbar;
516 	EShellView *shell_view;
517 	EShellContent *shell_content;
518 
519 	g_return_val_if_fail (
520 		E_IS_MAIL_SHELL_CONTENT (mail_shell_content), NULL);
521 
522 	shell_content = E_SHELL_CONTENT (mail_shell_content);
523 	shell_view = e_shell_content_get_shell_view (shell_content);
524 	searchbar = e_shell_view_get_searchbar (shell_view);
525 
526 	return E_SHELL_SEARCHBAR (searchbar);
527 }