evolution-3.6.4/mail/e-mail-notebook-view.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-notebook-view.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-notebook-view.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  * This program is free software; you can redistribute it and/or
  3  * modify it under the terms of the GNU Lesser General Public
  4  * License as published by the Free Software Foundation; either
  5  * version 2 of the License, or (at your option) version 3.
  6  *
  7  * This program is distributed in the hope that it will be useful,
  8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 10  * Lesser General Public License for more details.
 11  *
 12  * You should have received a copy of the GNU Lesser General Public
 13  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 14  *
 15  *
 16  * Authors:
 17  *		Srinivasa Ragavan <sragavan@gnome.org>
 18  *
 19  * Copyright (C) 2010 Intel corporation. (www.intel.com)
 20  *
 21  */
 22 
 23 #ifdef HAVE_CONFIG_H
 24 #include <config.h>
 25 #endif
 26 
 27 #include <glib/gi18n.h>
 28 
 29 #include "mail/e-mail-reader.h"
 30 #include "mail/message-list.h"
 31 #include "mail/em-folder-tree.h"
 32 #include "e-mail-notebook-view.h"
 33 #include "e-mail-folder-pane.h"
 34 #include "libemail-engine/e-mail-folder-utils.h"
 35 #include "e-mail-message-pane.h"
 36 
 37 #include <shell/e-shell-window-actions.h>
 38 
 39 #define E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE(obj) \
 40 	(G_TYPE_INSTANCE_GET_PRIVATE \
 41 	((obj), E_TYPE_MAIL_NOTEBOOK_VIEW, EMailNotebookViewPrivate))
 42 
 43 struct _EMailNotebookViewPrivate {
 44 	GtkNotebook *book;
 45 	EMailView *current_view;
 46 	GHashTable *views;
 47 	gboolean inited;
 48 };
 49 
 50 enum {
 51 	PROP_0,
 52 	PROP_FORWARD_STYLE,
 53 	PROP_GROUP_BY_THREADS,
 54 	PROP_REPLY_STYLE
 55 };
 56 
 57 #define E_SHELL_WINDOW_ACTION_GROUP_MAIL(window) \
 58 	E_SHELL_WINDOW_ACTION_GROUP ((window), "mail")
 59 
 60 /* Forward Declarations */
 61 static void e_mail_notebook_view_reader_init (EMailReaderInterface *interface);
 62 
 63 G_DEFINE_TYPE_WITH_CODE (
 64 	EMailNotebookView, e_mail_notebook_view, E_TYPE_MAIL_VIEW,
 65 	G_IMPLEMENT_INTERFACE (
 66 		E_TYPE_MAIL_READER, e_mail_notebook_view_reader_init)
 67 	G_IMPLEMENT_INTERFACE (
 68 		E_TYPE_EXTENSIBLE, NULL))
 69 
 70 static gint
 71 emnv_get_page_num (EMailNotebookView *view,
 72                    GtkWidget *widget)
 73 {
 74 	EMailNotebookViewPrivate *priv = view->priv;
 75 	gint i, n;
 76 
 77 	n = gtk_notebook_get_n_pages (priv->book);
 78 
 79 	for (i = 0; i < n; i++) {
 80 		GtkWidget *curr = gtk_notebook_get_nth_page (priv->book, i);
 81 		if (curr == widget)
 82 			return i;
 83 	}
 84 
 85 	return 0;
 86 }
 87 
 88 static void
 89 mnv_page_changed (GtkNotebook *book,
 90                   GtkWidget *page,
 91                   guint page_num,
 92                   EMailView *view)
 93 {
 94 	EMailNotebookViewPrivate *priv;
 95 	EShellView *shell_view;
 96 	EShellSidebar *shell_sidebar;
 97 	EMFolderTree *folder_tree;
 98 	EMailView *mview;
 99 	CamelFolder *folder;
100 
101 	priv = E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE (view);
102 
103 	shell_view = e_mail_view_get_shell_view (view);
104 	shell_sidebar = e_shell_view_get_shell_sidebar (shell_view);
105 
106 	page = gtk_notebook_get_nth_page (book, page_num);
107 	folder = e_mail_reader_get_folder (E_MAIL_READER (page));
108 	mview = E_MAIL_VIEW (page);
109 
110 	g_object_get (shell_sidebar, "folder-tree", &folder_tree, NULL);
111 
112 	if (folder != NULL && E_IS_MAIL_FOLDER_PANE (mview)) {
113 		gchar *folder_uri;
114 
115 		folder_uri = e_mail_folder_uri_from_folder (folder);
116 		em_folder_tree_set_selected (folder_tree, folder_uri, FALSE);
117 		g_free (folder_uri);
118 	}
119 
120 	if (mview != priv->current_view) {
121 		e_mail_view_set_previous_view (mview, priv->current_view);
122 		priv->current_view = mview;
123 	}
124 
125 	/* For EMailReader related changes to EShellView */
126 	g_signal_emit_by_name (view, "changed");
127 	g_signal_emit_by_name (view, "folder-loaded");
128 
129 	/* For EMailShellContent related changes */
130 	g_signal_emit_by_name (view, "view-changed");
131 
132 	g_object_unref (folder_tree);
133 }
134 
135 static void
136 tab_remove_gtk_cb (GtkWidget *button,
137                    EMailNotebookView *view)
138 {
139 	EMailView *page = g_object_get_data ((GObject *) button, "page");
140 	EMailView *prev;
141 	gint num;
142 
143 	if (gtk_notebook_get_n_pages (view->priv->book) == 1)
144 		return;
145 
146 	if (E_IS_MAIL_FOLDER_PANE (page)) {
147 		CamelFolder *folder;
148 		gchar *folder_uri;
149 
150 		folder = e_mail_reader_get_folder (E_MAIL_READER (page));
151 		folder_uri = e_mail_folder_uri_from_folder (folder);
152 		g_hash_table_remove (view->priv->views, folder_uri);
153 		g_free (folder_uri);
154 	}
155 
156 	prev = e_mail_view_get_previous_view (page);
157 	if (prev) {
158 		num = emnv_get_page_num (view, (GtkWidget *) prev);
159 		gtk_notebook_set_current_page (view->priv->book, num);
160 	}
161 	gtk_notebook_remove_page (
162 		view->priv->book,
163 		gtk_notebook_page_num (view->priv->book, (GtkWidget *) page));
164 
165 }
166 
167 static void
168 adjust_label_size_request (GtkWidget *view,
169                            GtkAllocation *allocation,
170                            GtkWidget *label)
171 {
172 	GtkRequisition requisition;
173 	gint max_width = allocation->width / 2;
174 
175 	/* We make sure the label is not over-ellipisized, but doesn't
176 	 * get too big to cause the tab to not fit either. */
177 	gtk_widget_get_preferred_size (label, NULL, &requisition);
178 	if (requisition.width < max_width)
179 		gtk_widget_set_size_request (label, requisition.width, -1);
180 	else
181 		gtk_widget_set_size_request (label, max_width, -1);
182 }
183 
184 static void
185 disconnect_label_adjusting (EMailNotebookView *view,
186                             GtkWidget *label)
187 {
188 	g_signal_handlers_disconnect_by_func (
189 		view,
190 		adjust_label_size_request,
191 		label);
192 }
193 
194 static GtkWidget *
195 create_tab_label (EMailNotebookView *view,
196                   EMailView *page,
197                   const gchar *str)
198 {
199 	GtkWidget *container, *widget;
200 	GtkAllocation allocation;
201 
202 	widget = gtk_hbox_new (FALSE, 0);
203 	gtk_widget_show (widget);
204 	container = widget;
205 
206 	widget = gtk_label_new (str);
207 	gtk_label_set_ellipsize (GTK_LABEL (widget), PANGO_ELLIPSIZE_END);
208 	gtk_widget_show (widget);
209 	gtk_box_pack_start (GTK_BOX (container), widget, TRUE, FALSE, 0);
210 
211 	gtk_widget_get_allocation (GTK_WIDGET (view), &allocation);
212 	adjust_label_size_request (GTK_WIDGET (view), &allocation, widget);
213 
214 	g_signal_connect (
215 		view, "size-allocate",
216 		G_CALLBACK (adjust_label_size_request), widget);
217 
218 	g_object_weak_ref (
219 		G_OBJECT (widget),
220 		(GWeakNotify) disconnect_label_adjusting,
221 		view);
222 
223 	widget = gtk_button_new ();
224 	gtk_button_set_relief (GTK_BUTTON (widget), GTK_RELIEF_NONE);
225 	gtk_button_set_image (
226 		GTK_BUTTON (widget), gtk_image_new_from_stock (
227 		"gtk-close", GTK_ICON_SIZE_MENU));
228 	gtk_widget_show_all (widget);
229 	gtk_box_pack_end (GTK_BOX (container), widget, FALSE, FALSE, 0);
230 	g_object_set_data ((GObject *) widget, "page", page);
231 	g_object_set_data ((GObject *) page, "close-button", widget);
232 
233 	g_signal_connect (
234 		widget, "clicked",
235 		G_CALLBACK (tab_remove_gtk_cb), view);
236 
237 	return container;
238 }
239 
240 static void
241 mail_notebook_view_constructed (GObject *object)
242 {
243 	EMailNotebookViewPrivate *priv;
244 	EShellView *shell_view;
245 	GtkWidget *container;
246 	GtkWidget *widget;
247 
248 	priv = E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE (object);
249 
250 	container = GTK_WIDGET (object);
251 
252 	widget = gtk_notebook_new ();
253 	priv->book = (GtkNotebook *) widget;
254 	gtk_widget_show (widget);
255 	gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
256 
257 	gtk_notebook_set_scrollable ((GtkNotebook *) widget, TRUE);
258 
259 	gtk_notebook_set_show_border ((GtkNotebook *) widget, FALSE);
260 
261 	shell_view = e_mail_view_get_shell_view (E_MAIL_VIEW (object));
262 	priv->current_view = e_mail_folder_pane_new (shell_view);
263 	e_mail_view_set_preview_visible (priv->current_view, FALSE);
264 	gtk_widget_show (GTK_WIDGET (priv->current_view));
265 
266 	gtk_notebook_append_page (
267 		priv->book, GTK_WIDGET (priv->current_view),
268 		create_tab_label (E_MAIL_NOTEBOOK_VIEW (object),
269 		priv->current_view, _("Please select a folder")));
270 
271 	g_signal_connect (
272 		priv->book, "switch-page",
273 		G_CALLBACK (mnv_page_changed), object);
274 
275 	e_extensible_load_extensions (E_EXTENSIBLE (object));
276 
277 	/* Chain up to parent's constructed() method. */
278 	G_OBJECT_CLASS (e_mail_notebook_view_parent_class)->constructed (object);
279 }
280 
281 static void
282 mail_notebook_view_set_property (GObject *object,
283                                  guint property_id,
284                                  const GValue *value,
285                                  GParamSpec *pspec)
286 {
287 	EMailNotebookView *notebook_view;
288 	EMailView *current_view;
289 
290 	notebook_view = E_MAIL_NOTEBOOK_VIEW (object);
291 	current_view = notebook_view->priv->current_view;
292 
293 	switch (property_id) {
294 		case PROP_FORWARD_STYLE:
295 			e_mail_reader_set_forward_style (
296 				E_MAIL_READER (current_view),
297 				g_value_get_enum (value));
298 			return;
299 
300 		case PROP_GROUP_BY_THREADS:
301 			e_mail_reader_set_group_by_threads (
302 				E_MAIL_READER (current_view),
303 				g_value_get_boolean (value));
304 			return;
305 
306 		case PROP_REPLY_STYLE:
307 			e_mail_reader_set_reply_style (
308 				E_MAIL_READER (current_view),
309 				g_value_get_enum (value));
310 			return;
311 	}
312 
313 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
314 }
315 
316 static void
317 mail_notebook_view_get_property (GObject *object,
318                                  guint property_id,
319                                  GValue *value,
320                                  GParamSpec *pspec)
321 {
322 	EMailNotebookView *notebook_view;
323 	EMailView *current_view;
324 
325 	notebook_view = E_MAIL_NOTEBOOK_VIEW (object);
326 	current_view = notebook_view->priv->current_view;
327 
328 	switch (property_id) {
329 		case PROP_FORWARD_STYLE:
330 			g_value_set_enum (
331 				value,
332 				e_mail_reader_get_forward_style (
333 				E_MAIL_READER (current_view)));
334 			return;
335 
336 		case PROP_GROUP_BY_THREADS:
337 			g_value_set_boolean (
338 				value,
339 				e_mail_reader_get_group_by_threads (
340 				E_MAIL_READER (current_view)));
341 			return;
342 
343 		case PROP_REPLY_STYLE:
344 			g_value_set_enum (
345 				value,
346 				e_mail_reader_get_reply_style (
347 				E_MAIL_READER (current_view)));
348 			return;
349 	}
350 
351 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
352 }
353 
354 static void
355 mail_notebook_view_set_search_strings (EMailView *view,
356                                        GSList *search_strings)
357 {
358 	EMailNotebookView *notebook_view;
359 	EMailView *current_view;
360 
361 	notebook_view = E_MAIL_NOTEBOOK_VIEW (view);
362 	current_view = notebook_view->priv->current_view;
363 
364 	e_mail_view_set_search_strings (current_view, search_strings);
365 }
366 
367 static GalViewInstance *
368 mail_notebook_view_get_view_instance (EMailView *view)
369 {
370 	EMailNotebookView *notebook_view;
371 	EMailView *current_view;
372 
373 	notebook_view = E_MAIL_NOTEBOOK_VIEW (view);
374 	current_view = notebook_view->priv->current_view;
375 
376 	if (current_view == NULL)
377 		return NULL;
378 
379 	return e_mail_view_get_view_instance (current_view);
380 }
381 
382 static void
383 mail_notebook_view_update_view_instance (EMailView *view)
384 {
385 	EMailNotebookView *notebook_view;
386 	EMailView *current_view;
387 
388 	notebook_view = E_MAIL_NOTEBOOK_VIEW (view);
389 	current_view = notebook_view->priv->current_view;
390 
391 	if (current_view == NULL)
392 		return;
393 
394 	e_mail_view_update_view_instance (current_view);
395 }
396 
397 static void
398 mail_notebook_view_set_orientation (EMailView *view,
399                                     GtkOrientation orientation)
400 {
401 	EMailNotebookView *notebook_view;
402 	EMailView *current_view;
403 
404 	notebook_view = E_MAIL_NOTEBOOK_VIEW (view);
405 	current_view = notebook_view->priv->current_view;
406 
407 	if (current_view == NULL)
408 		return;
409 
410 	e_mail_view_set_orientation (current_view, orientation);
411 }
412 
413 static GtkOrientation
414 mail_notebook_view_get_orientation (EMailView *view)
415 {
416 	EMailNotebookView *notebook_view;
417 	EMailView *current_view;
418 
419 	notebook_view = E_MAIL_NOTEBOOK_VIEW (view);
420 	current_view = notebook_view->priv->current_view;
421 
422 	if (current_view == NULL)
423 		return GTK_ORIENTATION_VERTICAL;
424 
425 	return e_mail_view_get_orientation (current_view);
426 }
427 
428 static gboolean
429 mail_notebook_view_get_show_deleted (EMailView *view)
430 {
431 	EMailNotebookView *notebook_view;
432 	EMailView *current_view;
433 
434 	notebook_view = E_MAIL_NOTEBOOK_VIEW (view);
435 	current_view = notebook_view->priv->current_view;
436 
437 	if (current_view == NULL)
438 		return FALSE;
439 
440 	return e_mail_view_get_show_deleted (current_view);
441 }
442 
443 static void
444 mail_notebook_view_set_show_deleted (EMailView *view,
445                                      gboolean show_deleted)
446 {
447 	EMailNotebookView *notebook_view;
448 	EMailView *current_view;
449 
450 	notebook_view = E_MAIL_NOTEBOOK_VIEW (view);
451 	current_view = notebook_view->priv->current_view;
452 
453 	if (current_view == NULL)
454 		return;
455 
456 	e_mail_view_set_show_deleted (current_view, show_deleted);
457 }
458 
459 static gboolean
460 mail_notebook_view_get_preview_visible (EMailView *view)
461 {
462 	EMailNotebookView *notebook_view;
463 	EMailView *current_view;
464 
465 	notebook_view = E_MAIL_NOTEBOOK_VIEW (view);
466 	current_view = notebook_view->priv->current_view;
467 
468 	if (current_view == NULL)
469 		return FALSE;
470 
471 	return e_mail_view_get_preview_visible (current_view);
472 }
473 
474 static void
475 mail_notebook_view_set_preview_visible (EMailView *view,
476                                         gboolean preview_visible)
477 {
478 	EMailNotebookView *notebook_view;
479 	EMailView *current_view;
480 
481 	notebook_view = E_MAIL_NOTEBOOK_VIEW (view);
482 	current_view = notebook_view->priv->current_view;
483 
484 	if (current_view == NULL)
485 		return;
486 
487 	e_mail_view_set_preview_visible (current_view, preview_visible);
488 }
489 
490 static GtkActionGroup *
491 mail_notebook_view_get_action_group (EMailReader *reader,
492                                      EMailReaderActionGroup group)
493 {
494 	EMailView *view;
495 	EShellView *shell_view;
496 	EShellWindow *shell_window;
497 	const gchar *group_name;
498 
499 	view = E_MAIL_VIEW (reader);
500 	shell_view = e_mail_view_get_shell_view (view);
501 	shell_window = e_shell_view_get_shell_window (shell_view);
502 
503 	switch (group) {
504 		case E_MAIL_READER_ACTION_GROUP_STANDARD:
505 			group_name = "mail";
506 			break;
507 		case E_MAIL_READER_ACTION_GROUP_SEARCH_FOLDERS:
508 			group_name = "search-folders";
509 			break;
510 		default:
511 			g_return_val_if_reached (NULL);
512 	}
513 
514 	return e_shell_window_get_action_group (shell_window, group_name);
515 }
516 
517 static EAlertSink *
518 mail_notebook_view_get_alert_sink (EMailReader *reader)
519 {
520 	EMailView *view;
521 	EShellView *shell_view;
522 	EShellContent *shell_content;
523 
524 	view = E_MAIL_VIEW (reader);
525 	shell_view = e_mail_view_get_shell_view (view);
526 	shell_content = e_shell_view_get_shell_content (shell_view);
527 
528 	return E_ALERT_SINK (shell_content);
529 }
530 
531 static EMailBackend *
532 mail_notebook_view_get_backend (EMailReader *reader)
533 {
534 	EMailView *view;
535 	EShellView *shell_view;
536 	EShellBackend *shell_backend;
537 
538 	view = E_MAIL_VIEW (reader);
539 	shell_view = e_mail_view_get_shell_view (view);
540 	shell_backend = e_shell_view_get_shell_backend (shell_view);
541 
542 	return E_MAIL_BACKEND (shell_backend);
543 }
544 
545 static EMailDisplay *
546 mail_notebook_view_get_mail_display (EMailReader *reader)
547 {
548 	EMailNotebookViewPrivate *priv;
549 
550 	priv = E_MAIL_NOTEBOOK_VIEW (reader)->priv;
551 
552 	if (priv->current_view == NULL)
553 		return NULL;
554 
555 	return e_mail_reader_get_mail_display (E_MAIL_READER (priv->current_view));
556 }
557 
558 static gboolean
559 mail_notebook_view_get_hide_deleted (EMailReader *reader)
560 {
561 	EMailNotebookView *notebook_view;
562 	EMailView *current_view;
563 
564 	notebook_view = E_MAIL_NOTEBOOK_VIEW (reader);
565 	current_view = notebook_view->priv->current_view;
566 
567 	if (current_view == NULL)
568 		return FALSE;
569 
570 	reader = E_MAIL_READER (current_view);
571 
572 	return e_mail_reader_get_hide_deleted (reader);
573 }
574 
575 static GtkWidget *
576 mail_notebook_view_get_message_list (EMailReader *reader)
577 {
578 	EMailNotebookView *notebook_view;
579 	EMailView *current_view;
580 
581 	notebook_view = E_MAIL_NOTEBOOK_VIEW (reader);
582 	current_view = notebook_view->priv->current_view;
583 
584 	if (current_view == NULL)
585 		return NULL;
586 
587 	reader = E_MAIL_READER (current_view);
588 
589 	return e_mail_reader_get_message_list (reader);
590 }
591 
592 static GtkMenu *
593 mail_notebook_view_get_popup_menu (EMailReader *reader)
594 {
595 	EMailNotebookView *notebook_view;
596 	EMailView *current_view;
597 
598 	notebook_view = E_MAIL_NOTEBOOK_VIEW (reader);
599 	current_view = notebook_view->priv->current_view;
600 
601 	if (current_view == NULL)
602 		return NULL;
603 
604 	reader = E_MAIL_READER (current_view);
605 
606 	return e_mail_reader_get_popup_menu (reader);
607 }
608 
609 static EPreviewPane *
610 mail_notebook_view_get_preview_pane (EMailReader *reader)
611 {
612 	EMailNotebookView *notebook_view;
613 	EMailView *current_view;
614 
615 	notebook_view = E_MAIL_NOTEBOOK_VIEW (reader);
616 	current_view = notebook_view->priv->current_view;
617 
618 	if (current_view == NULL)
619 		return NULL;
620 
621 	reader = E_MAIL_READER (current_view);
622 
623 	return e_mail_reader_get_preview_pane (reader);
624 }
625 
626 static GtkWindow *
627 mail_notebook_view_get_window (EMailReader *reader)
628 {
629 	EMailView *view;
630 	EShellWindow *shell_window;
631 	EShellView *shell_view;
632 
633 	view = E_MAIL_VIEW (reader);
634 	shell_view = e_mail_view_get_shell_view (view);
635 	shell_window = e_shell_view_get_shell_window (shell_view);
636 
637 	return GTK_WINDOW (shell_window);
638 }
639 
640 static void
641 reconnect_changed_event (EMailReader *child,
642                          EMailReader *parent)
643 {
644 	g_signal_emit_by_name (parent, "changed");
645 }
646 
647 static void
648 reconnect_folder_loaded_event (EMailReader *child,
649                                EMailReader *parent)
650 {
651 	g_signal_emit_by_name (parent, "folder-loaded");
652 }
653 
654 static void
655 mail_netbook_view_open_mail (EMailView *view,
656                              const gchar *uid,
657                              EMailNotebookView *nview)
658 {
659 	EMailNotebookViewPrivate *priv;
660 	EShellView *shell_view;
661 	CamelFolder *folder;
662 	EMailView *pane;
663 	gint page;
664 	CamelMessageInfo *info;
665 	gint pos;
666 
667 	priv = nview->priv;
668 
669 	shell_view = e_mail_view_get_shell_view (E_MAIL_VIEW (nview));
670 	pos = emnv_get_page_num (nview, GTK_WIDGET (priv->current_view));
671 	pane = e_mail_message_pane_new (shell_view);
672 	e_mail_view_set_previous_view (pane, priv->current_view);
673 	E_MAIL_MESSAGE_PANE (pane)->parent_folder_view = priv->current_view;
674 	priv->current_view = pane;
675 
676 	gtk_widget_show (GTK_WIDGET (pane));
677 
678 	folder = e_mail_reader_get_folder (E_MAIL_READER (view));
679 
680 	info = camel_folder_get_message_info (folder, uid);
681 
682 	page = gtk_notebook_insert_page (
683 		priv->book, GTK_WIDGET (pane),
684 		create_tab_label (nview, priv->current_view,
685 		camel_message_info_subject (info)), pos + 1);
686 
687 	gtk_notebook_set_current_page (priv->book, page);
688 
689 	g_signal_connect (
690 		E_MAIL_READER (pane), "changed",
691 		G_CALLBACK (reconnect_changed_event), nview);
692 	g_signal_connect (
693 		E_MAIL_READER (pane), "folder-loaded",
694 		G_CALLBACK (reconnect_folder_loaded_event), nview);
695 	e_mail_reader_set_folder (
696 		E_MAIL_READER (pane), folder);
697 	e_mail_reader_set_group_by_threads (
698 		E_MAIL_READER (pane),
699 		e_mail_reader_get_group_by_threads (E_MAIL_READER (view)));
700 
701 	e_mail_reader_enable_show_folder (E_MAIL_READER (pane));
702 	e_mail_reader_set_message (E_MAIL_READER (pane), uid);
703 	camel_message_info_free (info);
704 }
705 
706 static void
707 mail_notebook_view_set_folder (EMailReader *reader,
708                                CamelFolder *folder)
709 {
710 	EMailNotebookViewPrivate *priv;
711 	GtkWidget *new_view;
712 	gchar *folder_uri;
713 
714 	if (folder == NULL)
715 		return;
716 
717 	priv = E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE (reader);
718 
719 	folder_uri = e_mail_folder_uri_from_folder (folder);
720 	new_view = g_hash_table_lookup (priv->views, folder_uri);
721 	g_free (folder_uri);
722 
723 	if (new_view) {
724 		gint curr = emnv_get_page_num (E_MAIL_NOTEBOOK_VIEW (reader), new_view);
725 
726 		priv->current_view = (EMailView *) new_view;
727 		gtk_notebook_set_current_page (priv->book, curr);
728 		return;
729 	}
730 
731 	/* FIXME Redundant NULL check. */
732 	if (folder != NULL) {
733 		gint page;
734 
735 		if (priv->inited) {
736 			EMailView *old_view = priv->current_view;
737 			EShellView *shell_view;
738 
739 			shell_view = e_mail_view_get_shell_view (E_MAIL_VIEW (reader));
740 			priv->current_view = e_mail_folder_pane_new (shell_view);
741 			gtk_widget_show ((GtkWidget *) priv->current_view);
742 			e_mail_view_set_previous_view (priv->current_view, old_view);
743 			page = gtk_notebook_append_page (
744 				priv->book, (GtkWidget *) priv->current_view,
745 				create_tab_label (
746 					E_MAIL_NOTEBOOK_VIEW (reader),
747 					priv->current_view,
748 					camel_folder_get_full_name (folder)));
749 			gtk_notebook_set_current_page (priv->book, page);
750 
751 		} else {
752 			priv->inited = TRUE;
753 			gtk_notebook_set_tab_label (
754 				priv->book,
755 				GTK_WIDGET (priv->current_view),
756 				create_tab_label (
757 					E_MAIL_NOTEBOOK_VIEW (reader),
758 					priv->current_view,
759 					camel_folder_get_full_name (folder)));
760 		}
761 
762 		e_mail_reader_set_folder (E_MAIL_READER (priv->current_view), folder);
763 
764 		folder_uri = e_mail_folder_uri_from_folder (folder);
765 		g_hash_table_insert (priv->views, folder_uri, priv->current_view);
766 		g_signal_connect (
767 			priv->current_view, "changed",
768 			G_CALLBACK (reconnect_changed_event), reader);
769 		g_signal_connect (
770 			priv->current_view, "folder-loaded",
771 			G_CALLBACK (reconnect_folder_loaded_event), reader);
772 		g_signal_connect (
773 			priv->current_view, "open-mail",
774 			G_CALLBACK (mail_netbook_view_open_mail), reader);
775 	}
776 }
777 
778 static gboolean
779 mail_notebook_view_enable_show_folder (EMailReader *reader)
780 {
781 	EMailNotebookView *notebook_view;
782 	EMailView *current_view;
783 
784 	notebook_view = E_MAIL_NOTEBOOK_VIEW (reader);
785 	current_view = notebook_view->priv->current_view;
786 
787 	if (current_view == NULL)
788 		return FALSE;
789 
790 	reader = E_MAIL_READER (current_view);
791 
792 	return e_mail_reader_get_enable_show_folder (reader);
793 }
794 
795 static guint
796 mail_notebook_view_open_selected_mail (EMailReader *reader)
797 {
798 	EMailNotebookView *notebook_view;
799 	EMailView *current_view;
800 
801 	notebook_view = E_MAIL_NOTEBOOK_VIEW (reader);
802 	current_view = notebook_view->priv->current_view;
803 
804 	if (current_view == NULL)
805 		return 0;
806 
807 	reader = E_MAIL_READER (current_view);
808 
809 	return e_mail_reader_open_selected_mail (reader);
810 }
811 
812 static void
813 e_mail_notebook_view_class_init (EMailNotebookViewClass *class)
814 {
815 	GObjectClass *object_class;
816 	EMailViewClass *mail_view_class;
817 
818 	g_type_class_add_private (class, sizeof (EMailNotebookViewPrivate));
819 
820 	object_class = G_OBJECT_CLASS (class);
821 	object_class->constructed = mail_notebook_view_constructed;
822 	object_class->set_property = mail_notebook_view_set_property;
823 	object_class->get_property = mail_notebook_view_get_property;
824 
825 	mail_view_class = E_MAIL_VIEW_CLASS (class);
826 	mail_view_class->set_search_strings = mail_notebook_view_set_search_strings;
827 	mail_view_class->get_view_instance = mail_notebook_view_get_view_instance;
828 	mail_view_class->update_view_instance = mail_notebook_view_update_view_instance;
829 	mail_view_class->set_orientation = mail_notebook_view_set_orientation;
830 	mail_view_class->get_orientation = mail_notebook_view_get_orientation;
831 	mail_view_class->get_show_deleted = mail_notebook_view_get_show_deleted;
832 	mail_view_class->set_show_deleted = mail_notebook_view_set_show_deleted;
833 	mail_view_class->get_preview_visible = mail_notebook_view_get_preview_visible;
834 	mail_view_class->set_preview_visible = mail_notebook_view_set_preview_visible;
835 
836 	/* Inherited from EMailReader */
837 	g_object_class_override_property (
838 		object_class,
839 		PROP_FORWARD_STYLE,
840 		"forward-style");
841 
842 	/* Inherited from EMailReader */
843 	g_object_class_override_property (
844 		object_class,
845 		PROP_GROUP_BY_THREADS,
846 		"group-by-threads");
847 
848 	/* Inherited from EMailReader */
849 	g_object_class_override_property (
850 		object_class,
851 		PROP_REPLY_STYLE,
852 		"reply-style");
853 }
854 
855 static void
856 e_mail_notebook_view_reader_init (EMailReaderInterface *interface)
857 {
858 	interface->get_action_group = mail_notebook_view_get_action_group;
859 	interface->get_alert_sink = mail_notebook_view_get_alert_sink;
860 	interface->get_backend = mail_notebook_view_get_backend;
861 	interface->get_mail_display = mail_notebook_view_get_mail_display;
862 	interface->get_hide_deleted = mail_notebook_view_get_hide_deleted;
863 	interface->get_message_list = mail_notebook_view_get_message_list;
864 	interface->get_popup_menu = mail_notebook_view_get_popup_menu;
865 	interface->get_preview_pane = mail_notebook_view_get_preview_pane;
866 	interface->get_window = mail_notebook_view_get_window;
867 	interface->set_folder = mail_notebook_view_set_folder;
868 	interface->open_selected_mail = mail_notebook_view_open_selected_mail;
869 	interface->enable_show_folder = mail_notebook_view_enable_show_folder;
870 }
871 
872 static void
873 e_mail_notebook_view_init (EMailNotebookView *view)
874 {
875 	view->priv = E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE (view);
876 	view->priv->inited = FALSE;
877 	view->priv->views = g_hash_table_new (g_str_hash, g_str_equal);
878 }
879 
880 static void
881 emnv_show_folder (EMailNotebookView *view,
882                   gpointer not_used)
883 {
884 	gint pos;
885 	EMailNotebookViewPrivate *priv = view->priv;
886 
887 	pos = emnv_get_page_num (
888 		view, (GtkWidget *) E_MAIL_MESSAGE_PANE (
889 		priv->current_view)->parent_folder_view);
890 
891 	gtk_notebook_set_current_page (priv->book, pos);
892 
893 }
894 
895 static void
896 emnv_show_prevtab (EMailNotebookView *view,
897                    gpointer not_used)
898 {
899 	gint pos;
900 	EMailNotebookViewPrivate *priv = view->priv;
901 
902 	pos = emnv_get_page_num (
903 		view, (GtkWidget *) E_MAIL_MESSAGE_PANE (
904 		priv->current_view)->parent_folder_view);
905 
906 	pos = gtk_notebook_get_current_page (priv->book);
907 	if (pos > 0)
908 		gtk_notebook_set_current_page (priv->book, pos - 1);
909 
910 }
911 
912 static void
913 emnv_show_nexttab (EMailNotebookView *view,
914                    gpointer not_used)
915 {
916 	gint pos;
917 	EMailNotebookViewPrivate *priv = view->priv;
918 
919 	pos = gtk_notebook_get_current_page (priv->book);
920 	if (pos < (gtk_notebook_get_n_pages (priv->book) - 1))
921 		gtk_notebook_set_current_page (priv->book, pos + 1);
922 
923 }
924 
925 static void
926 emnv_close_tab (EMailNotebookView *view,
927                 gpointer not_used)
928 {
929 	EMailNotebookViewPrivate *priv = view->priv;
930 
931 	tab_remove_gtk_cb (
932 		g_object_get_data (
933 			G_OBJECT (priv->current_view), "close-button"),
934 		view);
935 }
936 
937 GtkWidget *
938 e_mail_notebook_view_new (EShellView *shell_view)
939 {
940 	GtkWidget *widget;
941 
942 	g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
943 
944 	widget = g_object_new (
945 		E_TYPE_MAIL_NOTEBOOK_VIEW,
946 		"shell-view", shell_view, NULL);
947 	g_signal_connect (
948 		widget, "show-folder",
949 		G_CALLBACK (emnv_show_folder), widget);
950 	g_signal_connect (
951 		widget, "show-next-tab",
952 		G_CALLBACK (emnv_show_nexttab), widget);
953 	g_signal_connect (
954 		widget, "show-previous-tab",
955 		G_CALLBACK (emnv_show_prevtab), widget);
956 	g_signal_connect (
957 		widget, "close-tab",
958 		G_CALLBACK (emnv_close_tab), widget);
959 
960 	return widget;
961 }