evolution-3.6.4/modules/mail/e-mail-shell-view-actions.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-shell-view-actions.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-shell-view-actions.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-view-actions.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-view-private.h"
  27 
  28 static void
  29 action_gal_save_custom_view_cb (GtkAction *action,
  30                                 EMailShellView *mail_shell_view)
  31 {
  32 	EMailShellContent *mail_shell_content;
  33 	EShellView *shell_view;
  34 	EMailView *mail_view;
  35 	GalViewInstance *view_instance;
  36 
  37 	/* All shell views repond to the activation of this action,
  38 	 * which is defined by EShellWindow.  But only the currently
  39 	 * active shell view proceeds with saving the custom view. */
  40 	shell_view = E_SHELL_VIEW (mail_shell_view);
  41 	if (!e_shell_view_is_active (shell_view))
  42 		return;
  43 
  44 	mail_shell_content = mail_shell_view->priv->mail_shell_content;
  45 	mail_view = e_mail_shell_content_get_mail_view (mail_shell_content);
  46 	view_instance = e_mail_view_get_view_instance (mail_view);
  47 
  48 	gal_view_instance_save_as (view_instance);
  49 }
  50 
  51 static void
  52 action_mail_account_disable_cb (GtkAction *action,
  53                                 EMailShellView *mail_shell_view)
  54 {
  55 	EMailShellSidebar *mail_shell_sidebar;
  56 	EShellView *shell_view;
  57 	EShellWindow *shell_window;
  58 	EShellBackend *shell_backend;
  59 	EMailBackend *backend;
  60 	EMailSession *session;
  61 	EMailAccountStore *account_store;
  62 	EMFolderTree *folder_tree;
  63 	CamelStore *store;
  64 
  65 	mail_shell_sidebar = mail_shell_view->priv->mail_shell_sidebar;
  66 
  67 	shell_view = E_SHELL_VIEW (mail_shell_view);
  68 	shell_backend = e_shell_view_get_shell_backend (shell_view);
  69 	shell_window = e_shell_view_get_shell_window (shell_view);
  70 
  71 	backend = E_MAIL_BACKEND (shell_backend);
  72 	session = e_mail_backend_get_session (backend);
  73 	account_store = e_mail_ui_session_get_account_store (E_MAIL_UI_SESSION (session));
  74 
  75 	folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar);
  76 	store = em_folder_tree_get_selected_store (folder_tree);
  77 	g_return_if_fail (store != NULL);
  78 
  79 	e_mail_account_store_disable_service (
  80 		account_store,
  81 		GTK_WINDOW (shell_window),
  82 		CAMEL_SERVICE (store));
  83 
  84 	e_shell_view_update_actions (shell_view);
  85 }
  86 
  87 static void
  88 action_mail_account_properties_cb (GtkAction *action,
  89                                    EMailShellView *mail_shell_view)
  90 {
  91 	EMailShellSidebar *mail_shell_sidebar;
  92 	EShell *shell;
  93 	EShellView *shell_view;
  94 	EShellWindow *shell_window;
  95 	EShellBackend *shell_backend;
  96 	ESourceRegistry *registry;
  97 	ESource *source;
  98 	EMFolderTree *folder_tree;
  99 	CamelService *service;
 100 	CamelStore *store;
 101 	const gchar *uid;
 102 
 103 	mail_shell_sidebar = mail_shell_view->priv->mail_shell_sidebar;
 104 
 105 	shell_view = E_SHELL_VIEW (mail_shell_view);
 106 	shell_backend = e_shell_view_get_shell_backend (shell_view);
 107 	shell_window = e_shell_view_get_shell_window (shell_view);
 108 	shell = e_shell_backend_get_shell (shell_backend);
 109 
 110 	folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar);
 111 	store = em_folder_tree_get_selected_store (folder_tree);
 112 	g_return_if_fail (store != NULL);
 113 
 114 	service = CAMEL_SERVICE (store);
 115 	uid = camel_service_get_uid (service);
 116 	registry = e_shell_get_registry (shell);
 117 	source = e_source_registry_ref_source (registry, uid);
 118 	g_return_if_fail (source != NULL);
 119 
 120 	e_mail_shell_backend_edit_account (
 121 		E_MAIL_SHELL_BACKEND (shell_backend),
 122 		GTK_WINDOW (shell_window), source);
 123 
 124 	g_object_unref (source);
 125 }
 126 
 127 static void
 128 action_mail_create_search_folder_cb (GtkAction *action,
 129                                      EMailShellView *mail_shell_view)
 130 {
 131 	EMailShellContent *mail_shell_content;
 132 	EMailReader *reader;
 133 	EShellView *shell_view;
 134 	EShellBackend *shell_backend;
 135 	EShellSearchbar *searchbar;
 136 	EFilterRule *search_rule;
 137 	EMVFolderRule *vfolder_rule;
 138 	EMailBackend *backend;
 139 	EMailSession *session;
 140 	EMailView *mail_view;
 141 	CamelFolder *folder;
 142 	const gchar *search_text;
 143 	gchar *folder_uri;
 144 	gchar *rule_name;
 145 
 146 	shell_view = E_SHELL_VIEW (mail_shell_view);
 147 	shell_backend = e_shell_view_get_shell_backend (shell_view);
 148 
 149 	mail_shell_content = mail_shell_view->priv->mail_shell_content;
 150 	mail_view = e_mail_shell_content_get_mail_view (mail_shell_content);
 151 	searchbar = e_mail_shell_content_get_searchbar (mail_shell_content);
 152 
 153 	search_rule = e_shell_view_get_search_rule (shell_view);
 154 	g_return_if_fail (search_rule != NULL);
 155 
 156 	search_text = e_shell_searchbar_get_search_text (searchbar);
 157 	if (search_text == NULL || *search_text == '\0')
 158 		search_text = "''";
 159 
 160 	reader = E_MAIL_READER (mail_view);
 161 	folder = e_mail_reader_get_folder (reader);
 162 
 163 	backend = E_MAIL_BACKEND (shell_backend);
 164 	session = e_mail_backend_get_session (backend);
 165 
 166 	search_rule = vfolder_clone_rule (session, search_rule);
 167 	g_return_if_fail (search_rule != NULL);
 168 
 169 	rule_name = g_strdup_printf ("%s %s", search_rule->name, search_text);
 170 	e_filter_rule_set_source (search_rule, E_FILTER_SOURCE_INCOMING);
 171 	e_filter_rule_set_name (search_rule, rule_name);
 172 	g_free (rule_name);
 173 
 174 	folder_uri = e_mail_folder_uri_from_folder (folder);
 175 
 176 	vfolder_rule = EM_VFOLDER_RULE (search_rule);
 177 	em_vfolder_rule_add_source (vfolder_rule, folder_uri);
 178 	vfolder_gui_add_rule (vfolder_rule);
 179 
 180 	g_free (folder_uri);
 181 }
 182 
 183 static void
 184 action_mail_download_finished_cb (CamelStore *store,
 185                                   GAsyncResult *result,
 186                                   EActivity *activity)
 187 {
 188 	EAlertSink *alert_sink;
 189 	GError *error = NULL;
 190 
 191 	alert_sink = e_activity_get_alert_sink (activity);
 192 
 193 	e_mail_store_prepare_for_offline_finish (store, result, &error);
 194 
 195 	if (e_activity_handle_cancellation (activity, error)) {
 196 		g_error_free (error);
 197 
 198 	} else if (error != NULL) {
 199 		e_alert_submit (
 200 			alert_sink, "mail:prepare-for-offline",
 201 			error->message, NULL);
 202 		g_error_free (error);
 203 	}
 204 
 205 	g_object_unref (activity);
 206 }
 207 
 208 static void
 209 action_mail_download_cb (GtkAction *action,
 210                          EMailShellView *mail_shell_view)
 211 {
 212 	EMailShellContent *mail_shell_content;
 213 	EMailView *mail_view;
 214 	EMailReader *reader;
 215 	EMailBackend *backend;
 216 	EMailSession *session;
 217 	GList *list, *link;
 218 
 219 	mail_shell_content = mail_shell_view->priv->mail_shell_content;
 220 	mail_view = e_mail_shell_content_get_mail_view (mail_shell_content);
 221 
 222 	reader = E_MAIL_READER (mail_view);
 223 	backend = e_mail_reader_get_backend (reader);
 224 	session = e_mail_backend_get_session (backend);
 225 
 226 	list = camel_session_list_services (CAMEL_SESSION (session));
 227 
 228 	for (link = list; link != NULL; link = g_list_next (link)) {
 229 		EActivity *activity;
 230 		CamelService *service;
 231 		GCancellable *cancellable;
 232 
 233 		service = CAMEL_SERVICE (link->data);
 234 
 235 		if (!CAMEL_IS_STORE (service))
 236 			continue;
 237 
 238 		activity = e_mail_reader_new_activity (reader);
 239 		cancellable = e_activity_get_cancellable (activity);
 240 
 241 		e_mail_store_prepare_for_offline (
 242 			CAMEL_STORE (service), G_PRIORITY_DEFAULT,
 243 			cancellable, (GAsyncReadyCallback)
 244 			action_mail_download_finished_cb, activity);
 245 	}
 246 
 247 	g_list_free_full (list, (GDestroyNotify) g_object_unref);
 248 }
 249 
 250 static void
 251 action_mail_flush_outbox_cb (GtkAction *action,
 252                              EMailShellView *mail_shell_view)
 253 {
 254 	EShellBackend *shell_backend;
 255 	EShellView *shell_view;
 256 	EMailBackend *backend;
 257 	EMailSession *session;
 258 
 259 	shell_view = E_SHELL_VIEW (mail_shell_view);
 260 	shell_backend = e_shell_view_get_shell_backend (shell_view);
 261 
 262 	backend = E_MAIL_BACKEND (shell_backend);
 263 	session = e_mail_backend_get_session (backend);
 264 
 265 	mail_send (session);
 266 }
 267 
 268 static void
 269 action_mail_folder_copy_cb (GtkAction *action,
 270                             EMailShellView *mail_shell_view)
 271 {
 272 	EMailShellSidebar *mail_shell_sidebar;
 273 	EShellContent *shell_content;
 274 	EShellWindow *shell_window;
 275 	EShellView *shell_view;
 276 	EMFolderTree *folder_tree;
 277 	EMailSession *session;
 278 	gchar *selected_uri;
 279 
 280 	shell_view = E_SHELL_VIEW (mail_shell_view);
 281 	shell_window = e_shell_view_get_shell_window (shell_view);
 282 	shell_content = e_shell_view_get_shell_content (shell_view);
 283 
 284 	mail_shell_sidebar = mail_shell_view->priv->mail_shell_sidebar;
 285 	folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar);
 286 	selected_uri = em_folder_tree_get_selected_uri (folder_tree);
 287 	session = em_folder_tree_get_session (folder_tree);
 288 	g_return_if_fail (selected_uri != NULL);
 289 
 290 	em_folder_utils_copy_folder (
 291 		GTK_WINDOW (shell_window),
 292 		session,
 293 		E_ALERT_SINK (shell_content),
 294 		selected_uri, FALSE);
 295 
 296 	g_free (selected_uri);
 297 }
 298 
 299 static void
 300 action_mail_folder_delete_cb (GtkAction *action,
 301                               EMailShellView *mail_shell_view)
 302 {
 303 	EMailShellContent *mail_shell_content;
 304 	EMailShellSidebar *mail_shell_sidebar;
 305 	EMailView *mail_view;
 306 	EMFolderTree *folder_tree;
 307 	CamelStore *selected_store = NULL;
 308 	gchar *selected_folder_name = NULL;
 309 
 310 	mail_shell_content = mail_shell_view->priv->mail_shell_content;
 311 	mail_view = e_mail_shell_content_get_mail_view (mail_shell_content);
 312 
 313 	mail_shell_sidebar = mail_shell_view->priv->mail_shell_sidebar;
 314 	folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar);
 315 
 316 	em_folder_tree_get_selected (
 317 		folder_tree, &selected_store, &selected_folder_name);
 318 	g_return_if_fail (CAMEL_IS_STORE (selected_store));
 319 	g_return_if_fail (selected_folder_name != NULL);
 320 
 321 	e_mail_reader_delete_folder_name (
 322 		E_MAIL_READER (mail_view),
 323 		selected_store, selected_folder_name);
 324 
 325 	g_object_unref (selected_store);
 326 	g_free (selected_folder_name);
 327 }
 328 
 329 static void
 330 action_mail_folder_expunge_cb (GtkAction *action,
 331                                EMailShellView *mail_shell_view)
 332 {
 333 	EMailShellContent *mail_shell_content;
 334 	EMailShellSidebar *mail_shell_sidebar;
 335 	EMailView *mail_view;
 336 	EMFolderTree *folder_tree;
 337 	CamelStore *selected_store = NULL;
 338 	gchar *selected_folder_name = NULL;
 339 
 340 	/* This handles both the "folder-expunge" and "account-expunge"
 341 	 * actions. */
 342 
 343 	mail_shell_content = mail_shell_view->priv->mail_shell_content;
 344 	mail_view = e_mail_shell_content_get_mail_view (mail_shell_content);
 345 
 346 	mail_shell_sidebar = mail_shell_view->priv->mail_shell_sidebar;
 347 	folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar);
 348 
 349 	/* Get the folder from the folder tree, not the message list.
 350 	 * This correctly handles the use case of right-clicking on
 351 	 * the "Trash" folder and selecting "Empty Trash" without
 352 	 * actually selecting the folder.  In that case the message
 353 	 * list would not contain the correct folder to expunge. */
 354 	em_folder_tree_get_selected (
 355 		folder_tree, &selected_store, &selected_folder_name);
 356 	g_return_if_fail (CAMEL_IS_STORE (selected_store));
 357 	g_return_if_fail (selected_folder_name != NULL);
 358 
 359 	e_mail_reader_expunge_folder_name (
 360 		E_MAIL_READER (mail_view),
 361 		selected_store, selected_folder_name);
 362 
 363 	g_object_unref (selected_store);
 364 	g_free (selected_folder_name);
 365 }
 366 
 367 static void
 368 action_mail_folder_mark_all_as_read_cb (GtkAction *action,
 369                                         EMailShellView *mail_shell_view)
 370 {
 371 	EShellView *shell_view;
 372 	EShellWindow *shell_window;
 373 	EShellBackend *shell_backend;
 374 	EMailShellContent *mail_shell_content;
 375 	EMailReader *reader;
 376 	EMailView *mail_view;
 377 	CamelFolder *folder;
 378 	GtkWindow *parent;
 379 	EMailBackend *backend;
 380 	EMailSession *session;
 381 	MailFolderCache *cache;
 382 	GtkWidget *message_list;
 383 	GPtrArray *uids;
 384 	const gchar *key;
 385 	const gchar *prompt;
 386 	guint ii;
 387 
 388 	shell_view = E_SHELL_VIEW (mail_shell_view);
 389 	shell_window = e_shell_view_get_shell_window (shell_view);
 390 	shell_backend = e_shell_view_get_shell_backend (shell_view);
 391 	parent = GTK_WINDOW (shell_window);
 392 
 393 	mail_shell_content = mail_shell_view->priv->mail_shell_content;
 394 	mail_view = e_mail_shell_content_get_mail_view (mail_shell_content);
 395 
 396 	reader = E_MAIL_READER (mail_view);
 397 
 398 	folder = e_mail_reader_get_folder (reader);
 399 	g_return_if_fail (folder != NULL);
 400 
 401 	backend = E_MAIL_BACKEND (shell_backend);
 402 	session = e_mail_backend_get_session (backend);
 403 	cache = e_mail_session_get_folder_cache (session);
 404 	key = "prompt-on-mark-all-read";
 405 
 406 	if (mail_folder_cache_get_folder_has_children (cache, folder, NULL))
 407 		prompt = "mail:ask-mark-all-read-sub";
 408 	else
 409 		prompt = "mail:ask-mark-all-read";
 410 
 411 	if (!em_utils_prompt_user (parent, key, prompt, NULL))
 412 		return;
 413 
 414 	message_list = e_mail_reader_get_message_list (reader);
 415 	g_return_if_fail (message_list != NULL);
 416 
 417 	uids = message_list_get_uids (MESSAGE_LIST (message_list));
 418 
 419 	camel_folder_freeze (folder);
 420 	for (ii = 0; ii < uids->len; ii++)
 421 		camel_folder_set_message_flags (
 422 			folder, uids->pdata[ii],
 423 			CAMEL_MESSAGE_SEEN, CAMEL_MESSAGE_SEEN);
 424 	camel_folder_thaw (folder);
 425 
 426 	em_utils_uids_free (uids);
 427 }
 428 
 429 static void
 430 action_mail_folder_move_cb (GtkAction *action,
 431                             EMailShellView *mail_shell_view)
 432 {
 433 	EMailShellSidebar *mail_shell_sidebar;
 434 	EShellContent *shell_content;
 435 	EShellWindow *shell_window;
 436 	EShellView *shell_view;
 437 	EMFolderTree *folder_tree;
 438 	EMailSession *session;
 439 	gchar *selected_uri;
 440 
 441 	shell_view = E_SHELL_VIEW (mail_shell_view);
 442 	shell_window = e_shell_view_get_shell_window (shell_view);
 443 	shell_content = e_shell_view_get_shell_content (shell_view);
 444 
 445 	mail_shell_sidebar = mail_shell_view->priv->mail_shell_sidebar;
 446 	folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar);
 447 	selected_uri = em_folder_tree_get_selected_uri (folder_tree);
 448 	session = em_folder_tree_get_session (folder_tree);
 449 	g_return_if_fail (selected_uri != NULL);
 450 
 451 	em_folder_utils_copy_folder (
 452 		GTK_WINDOW (shell_window),
 453 		session,
 454 		E_ALERT_SINK (shell_content),
 455 		selected_uri, TRUE);
 456 
 457 	g_free (selected_uri);
 458 }
 459 
 460 static void
 461 action_mail_folder_new_cb (GtkAction *action,
 462                            EMailShellView *mail_shell_view)
 463 {
 464 	EShellView *shell_view;
 465 	EShellWindow *shell_window;
 466 	EMailSession *session;
 467 	EMailShellSidebar *mail_shell_sidebar;
 468 	EMFolderTree *folder_tree;
 469 	gchar *selected_uri;
 470 
 471 	shell_view = E_SHELL_VIEW (mail_shell_view);
 472 	shell_window = e_shell_view_get_shell_window (shell_view);
 473 
 474 	mail_shell_sidebar = mail_shell_view->priv->mail_shell_sidebar;
 475 	folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar);
 476 
 477 	session = em_folder_tree_get_session (folder_tree);
 478 	selected_uri = em_folder_tree_get_selected_uri (folder_tree);
 479 
 480 	em_folder_utils_create_folder (
 481 		GTK_WINDOW (shell_window),
 482 		session, folder_tree, selected_uri);
 483 
 484 	g_free (selected_uri);
 485 }
 486 
 487 static void
 488 action_mail_folder_properties_cb (GtkAction *action,
 489                                   EMailShellView *mail_shell_view)
 490 {
 491 	EMailShellSidebar *mail_shell_sidebar;
 492 	EShellView *shell_view;
 493 	EShellWindow *shell_window;
 494 	EShellContent *shell_content;
 495 	EMFolderTree *folder_tree;
 496 	CamelStore *store;
 497 	gchar *folder_name;
 498 
 499 	shell_view = E_SHELL_VIEW (mail_shell_view);
 500 	shell_window = e_shell_view_get_shell_window (shell_view);
 501 	shell_content = e_shell_view_get_shell_content (shell_view);
 502 
 503 	mail_shell_sidebar = mail_shell_view->priv->mail_shell_sidebar;
 504 	folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar);
 505 
 506 	if (!em_folder_tree_get_selected (folder_tree, &store, &folder_name))
 507 		g_return_if_reached ();
 508 
 509 	em_folder_properties_show (
 510 		store, folder_name,
 511 		E_ALERT_SINK (shell_content),
 512 		GTK_WINDOW (shell_window));
 513 
 514 	g_object_unref (store);
 515 	g_free (folder_name);
 516 }
 517 
 518 static void
 519 action_mail_folder_refresh_cb (GtkAction *action,
 520                                EMailShellView *mail_shell_view)
 521 {
 522 	EMailShellContent *mail_shell_content;
 523 	EMailShellSidebar *mail_shell_sidebar;
 524 	EMailView *mail_view;
 525 	EMFolderTree *folder_tree;
 526 	CamelStore *selected_store = NULL;
 527 	gchar *selected_folder_name = NULL;
 528 
 529 	mail_shell_content = mail_shell_view->priv->mail_shell_content;
 530 	mail_view = e_mail_shell_content_get_mail_view (mail_shell_content);
 531 
 532 	mail_shell_sidebar = mail_shell_view->priv->mail_shell_sidebar;
 533 	folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar);
 534 
 535 	em_folder_tree_get_selected (
 536 		folder_tree, &selected_store, &selected_folder_name);
 537 	g_return_if_fail (CAMEL_IS_STORE (selected_store));
 538 	g_return_if_fail (selected_folder_name != NULL);
 539 
 540 	e_mail_reader_refresh_folder_name (
 541 		E_MAIL_READER (mail_view),
 542 		selected_store, selected_folder_name);
 543 
 544 	g_object_unref (selected_store);
 545 	g_free (selected_folder_name);
 546 }
 547 
 548 static void
 549 action_mail_folder_rename_cb (GtkAction *action,
 550                               EMailShellView *mail_shell_view)
 551 {
 552 	EMailShellSidebar *mail_shell_sidebar;
 553 	EMFolderTree *folder_tree;
 554 
 555 	mail_shell_sidebar = mail_shell_view->priv->mail_shell_sidebar;
 556 	folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar);
 557 
 558 	em_folder_tree_edit_selected (folder_tree);
 559 }
 560 
 561 static void
 562 action_mail_folder_select_thread_cb (GtkAction *action,
 563                                      EMailShellView *mail_shell_view)
 564 {
 565 	EMailShellContent *mail_shell_content;
 566 	GtkWidget *message_list;
 567 	EMailReader *reader;
 568 	EMailView *mail_view;
 569 
 570 	mail_shell_content = mail_shell_view->priv->mail_shell_content;
 571 	mail_view = e_mail_shell_content_get_mail_view (mail_shell_content);
 572 
 573 	reader = E_MAIL_READER (mail_view);
 574 	message_list = e_mail_reader_get_message_list (reader);
 575 
 576 	message_list_select_thread (MESSAGE_LIST (message_list));
 577 }
 578 
 579 static void
 580 action_mail_folder_select_subthread_cb (GtkAction *action,
 581                                         EMailShellView *mail_shell_view)
 582 {
 583 	EMailShellContent *mail_shell_content;
 584 	GtkWidget *message_list;
 585 	EMailReader *reader;
 586 	EMailView *mail_view;
 587 
 588 	mail_shell_content = mail_shell_view->priv->mail_shell_content;
 589 	mail_view = e_mail_shell_content_get_mail_view (mail_shell_content);
 590 
 591 	reader = E_MAIL_READER (mail_view);
 592 	message_list = e_mail_reader_get_message_list (reader);
 593 
 594 	message_list_select_subthread (MESSAGE_LIST (message_list));
 595 }
 596 
 597 static void
 598 action_mail_folder_unsubscribe_cb (GtkAction *action,
 599                                    EMailShellView *mail_shell_view)
 600 {
 601 	EMailShellContent *mail_shell_content;
 602 	EMailShellSidebar *mail_shell_sidebar;
 603 	EMailView *mail_view;
 604 	EMFolderTree *folder_tree;
 605 	CamelStore *selected_store = NULL;
 606 	gchar *selected_folder_name = NULL;
 607 
 608 	mail_shell_content = mail_shell_view->priv->mail_shell_content;
 609 	mail_view = e_mail_shell_content_get_mail_view (mail_shell_content);
 610 
 611 	mail_shell_sidebar = mail_shell_view->priv->mail_shell_sidebar;
 612 	folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar);
 613 
 614 	em_folder_tree_get_selected (
 615 		folder_tree, &selected_store, &selected_folder_name);
 616 	g_return_if_fail (CAMEL_IS_STORE (selected_store));
 617 	g_return_if_fail (selected_folder_name != NULL);
 618 
 619 	e_mail_reader_unsubscribe_folder_name (
 620 		E_MAIL_READER (mail_view),
 621 		selected_store, selected_folder_name);
 622 
 623 	g_object_unref (selected_store);
 624 	g_free (selected_folder_name);
 625 }
 626 
 627 static void
 628 action_mail_global_expunge_cb (GtkAction *action,
 629                                EMailShellView *mail_shell_view)
 630 {
 631 	EShellBackend *shell_backend;
 632 	EShellWindow *shell_window;
 633 	EShellView *shell_view;
 634 	EMailBackend *backend;
 635 	EMailSession *session;
 636 
 637 	shell_view = E_SHELL_VIEW (mail_shell_view);
 638 	shell_window = e_shell_view_get_shell_window (shell_view);
 639 	shell_backend = e_shell_view_get_shell_backend (shell_view);
 640 
 641 	backend = E_MAIL_BACKEND (shell_backend);
 642 	session = e_mail_backend_get_session (backend);
 643 
 644 	em_utils_empty_trash (
 645 		GTK_WIDGET (shell_window), session);
 646 }
 647 
 648 static void
 649 action_mail_label_cb (GtkToggleAction *action,
 650                       EMailShellView *mail_shell_view)
 651 {
 652 	EMailShellContent *mail_shell_content;
 653 	EMailReader *reader;
 654 	EMailView *mail_view;
 655 	CamelFolder *folder;
 656 	GPtrArray *uids;
 657 	const gchar *tag;
 658 	gint ii;
 659 
 660 	tag = g_object_get_data (G_OBJECT (action), "tag");
 661 	g_return_if_fail (tag != NULL);
 662 
 663 	mail_shell_content = mail_shell_view->priv->mail_shell_content;
 664 	mail_view = e_mail_shell_content_get_mail_view (mail_shell_content);
 665 
 666 	reader = E_MAIL_READER (mail_view);
 667 	folder = e_mail_reader_get_folder (reader);
 668 	uids = e_mail_reader_get_selected_uids (reader);
 669 
 670 	camel_folder_freeze (folder);
 671 	for (ii = 0; ii < uids->len; ii++) {
 672 		if (gtk_toggle_action_get_active (action))
 673 			camel_folder_set_message_user_flag (
 674 				folder, uids->pdata[ii], tag, TRUE);
 675 		else {
 676 			camel_folder_set_message_user_flag (
 677 				folder, uids->pdata[ii], tag, FALSE);
 678 			camel_folder_set_message_user_tag (
 679 				folder, uids->pdata[ii], "label", NULL);
 680 		}
 681 	}
 682 	camel_folder_thaw (folder);
 683 
 684 	em_utils_uids_free (uids);
 685 }
 686 
 687 static void
 688 action_mail_label_new_cb (GtkAction *action,
 689                           EMailShellView *mail_shell_view)
 690 {
 691 	EShellView *shell_view;
 692 	EShellWindow *shell_window;
 693 	EShellBackend *shell_backend;
 694 	EMailShellContent *mail_shell_content;
 695 	EMailLabelDialog *label_dialog;
 696 	EMailLabelListStore *label_store;
 697 	EMailBackend *backend;
 698 	EMailSession *session;
 699 	EMailReader *reader;
 700 	EMailView *mail_view;
 701 	CamelFolder *folder;
 702 	GtkTreeModel *model;
 703 	GtkTreeIter iter;
 704 	GtkWidget *dialog;
 705 	GPtrArray *uids;
 706 	GdkColor label_color;
 707 	const gchar *label_name;
 708 	gchar *label_tag;
 709 	gint n_children;
 710 	guint ii;
 711 
 712 	shell_view = E_SHELL_VIEW (mail_shell_view);
 713 	shell_window = e_shell_view_get_shell_window (shell_view);
 714 	shell_backend = e_shell_view_get_shell_backend (shell_view);
 715 
 716 	dialog = e_mail_label_dialog_new (GTK_WINDOW (shell_window));
 717 
 718 	gtk_window_set_title (GTK_WINDOW (dialog), _("Add Label"));
 719 
 720 	if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK)
 721 		goto exit;
 722 
 723 	backend = E_MAIL_BACKEND (shell_backend);
 724 	session = e_mail_backend_get_session (backend);
 725 	label_store = e_mail_ui_session_get_label_store (
 726 		E_MAIL_UI_SESSION (session));
 727 
 728 	label_dialog = E_MAIL_LABEL_DIALOG (dialog);
 729 	label_name = e_mail_label_dialog_get_label_name (label_dialog);
 730 	e_mail_label_dialog_get_label_color (label_dialog, &label_color);
 731 
 732 	e_mail_label_list_store_set (
 733 		label_store, NULL, label_name, &label_color);
 734 
 735 	/* XXX This is awkward.  We've added a new label to the list store
 736 	 *     but we don't have the new label's tag nor an iterator to use
 737 	 *     to fetch it.  We know the label was appended to the store,
 738 	 *     so we have to dig it out manually.  EMailLabelListStore API
 739 	 *     probably needs some rethinking. */
 740 	model = GTK_TREE_MODEL (label_store);
 741 	n_children = gtk_tree_model_iter_n_children (model, NULL);
 742 	gtk_tree_model_iter_nth_child (model, &iter, NULL, n_children - 1);
 743 	label_tag = e_mail_label_list_store_get_tag (label_store, &iter);
 744 
 745 	mail_shell_content = mail_shell_view->priv->mail_shell_content;
 746 	mail_view = e_mail_shell_content_get_mail_view (mail_shell_content);
 747 
 748 	reader = E_MAIL_READER (mail_view);
 749 	folder = e_mail_reader_get_folder (reader);
 750 	uids = e_mail_reader_get_selected_uids (reader);
 751 
 752 	for (ii = 0; ii < uids->len; ii++)
 753 		camel_folder_set_message_user_flag (
 754 			folder, uids->pdata[ii], label_tag, TRUE);
 755 
 756 	em_utils_uids_free (uids);
 757 
 758 	g_free (label_tag);
 759 
 760 exit:
 761 	gtk_widget_destroy (dialog);
 762 }
 763 
 764 static void
 765 action_mail_label_none_cb (GtkAction *action,
 766                            EMailShellView *mail_shell_view)
 767 {
 768 	EShellView *shell_view;
 769 	EShellBackend *shell_backend;
 770 	EMailBackend *backend;
 771 	EMailSession *session;
 772 	EMailShellContent *mail_shell_content;
 773 	EMailLabelListStore *label_store;
 774 	EMailReader *reader;
 775 	EMailView *mail_view;
 776 	CamelFolder *folder;
 777 	GtkTreeIter iter;
 778 	GPtrArray *uids;
 779 	gboolean valid;
 780 	guint ii;
 781 
 782 	shell_view = E_SHELL_VIEW (mail_shell_view);
 783 	shell_backend = e_shell_view_get_shell_backend (shell_view);
 784 
 785 	backend = E_MAIL_BACKEND (shell_backend);
 786 	session = e_mail_backend_get_session (backend);
 787 	label_store = e_mail_ui_session_get_label_store (
 788 		E_MAIL_UI_SESSION (session));
 789 
 790 	mail_shell_content = mail_shell_view->priv->mail_shell_content;
 791 	mail_view = e_mail_shell_content_get_mail_view (mail_shell_content);
 792 
 793 	reader = E_MAIL_READER (mail_view);
 794 	folder = e_mail_reader_get_folder (reader);
 795 	uids = e_mail_reader_get_selected_uids (reader);
 796 
 797 	valid = gtk_tree_model_get_iter_first (
 798 		GTK_TREE_MODEL (label_store), &iter);
 799 
 800 	while (valid) {
 801 		gchar *tag;
 802 
 803 		tag = e_mail_label_list_store_get_tag (label_store, &iter);
 804 
 805 		for (ii = 0; ii < uids->len; ii++) {
 806 			camel_folder_set_message_user_flag (
 807 				folder, uids->pdata[ii], tag, FALSE);
 808 			camel_folder_set_message_user_tag (
 809 				folder, uids->pdata[ii], "label", NULL);
 810 		}
 811 
 812 		g_free (tag);
 813 
 814 		valid = gtk_tree_model_iter_next (
 815 			GTK_TREE_MODEL (label_store), &iter);
 816 	}
 817 
 818 	em_utils_uids_free (uids);
 819 }
 820 
 821 static void
 822 action_mail_send_receive_cb (GtkAction *action,
 823                              EMailShellView *mail_shell_view)
 824 {
 825 	EShellView *shell_view;
 826 	EShellWindow *shell_window;
 827 	EShellBackend *shell_backend;
 828 	EMailBackend *backend;
 829 	EMailSession *session;
 830 
 831 	shell_view = E_SHELL_VIEW (mail_shell_view);
 832 	shell_window = e_shell_view_get_shell_window (shell_view);
 833 	shell_backend = e_shell_view_get_shell_backend (shell_view);
 834 
 835 	backend = E_MAIL_BACKEND (shell_backend);
 836 	session = e_mail_backend_get_session (backend);
 837 
 838 	mail_send_receive (GTK_WINDOW (shell_window), session);
 839 }
 840 
 841 static void
 842 action_mail_send_receive_receive_all_cb (GtkAction *action,
 843                                          EMailShellView *mail_shell_view)
 844 {
 845 	EShellView *shell_view;
 846 	EShellWindow *shell_window;
 847 	EShellBackend *shell_backend;
 848 	EMailBackend *backend;
 849 	EMailSession *session;
 850 
 851 	shell_view = E_SHELL_VIEW (mail_shell_view);
 852 	shell_window = e_shell_view_get_shell_window (shell_view);
 853 	shell_backend = e_shell_view_get_shell_backend (shell_view);
 854 
 855 	backend = E_MAIL_BACKEND (shell_backend);
 856 	session = e_mail_backend_get_session (backend);
 857 
 858 	mail_receive (GTK_WINDOW (shell_window), session);
 859 }
 860 
 861 static void
 862 action_mail_send_receive_send_all_cb (GtkAction *action,
 863                                       EMailShellView *mail_shell_view)
 864 {
 865 	EShellView *shell_view;
 866 	EShellBackend *shell_backend;
 867 	EMailBackend *backend;
 868 	EMailSession *session;
 869 
 870 	shell_view = E_SHELL_VIEW (mail_shell_view);
 871 	shell_backend = e_shell_view_get_shell_backend (shell_view);
 872 
 873 	backend = E_MAIL_BACKEND (shell_backend);
 874 	session = e_mail_backend_get_session (backend);
 875 
 876 	mail_send (session);
 877 }
 878 
 879 static void
 880 action_mail_show_deleted_cb (GtkToggleAction *action,
 881                              EMailShellView *mail_shell_view)
 882 {
 883 	EMailShellContent *mail_shell_content;
 884 	GtkWidget *message_list;
 885 	EMailReader *reader;
 886 	EMailView *mail_view;
 887 	gboolean active;
 888 
 889 	mail_shell_content = mail_shell_view->priv->mail_shell_content;
 890 	mail_view = e_mail_shell_content_get_mail_view (mail_shell_content);
 891 
 892 	reader = E_MAIL_READER (mail_view);
 893 	message_list = e_mail_reader_get_message_list (reader);
 894 
 895 	active = gtk_toggle_action_get_active (action);
 896 	message_list_set_hidedeleted (MESSAGE_LIST (message_list), !active);
 897 }
 898 
 899 static void
 900 action_mail_smart_backward_cb (GtkAction *action,
 901                                EMailShellView *mail_shell_view)
 902 {
 903 	EShell *shell;
 904 	EShellView *shell_view;
 905 	EShellWindow *shell_window;
 906 	EShellSettings *shell_settings;
 907 	EMailShellContent *mail_shell_content;
 908 	EMailShellSidebar *mail_shell_sidebar;
 909 	EMFolderTree *folder_tree;
 910 	EMailReader *reader;
 911 	EMailView *mail_view;
 912 	GtkWidget *message_list;
 913 	GtkToggleAction *toggle_action;
 914 	GtkWidget *window;
 915 	GtkAdjustment *adj;
 916 	EMailDisplay *display;
 917 	gboolean caret_mode;
 918 	gboolean magic_spacebar;
 919 	gdouble value;
 920 
 921 	/* This implements the so-called "Magic Backspace". */
 922 
 923 	shell_view = E_SHELL_VIEW (mail_shell_view);
 924 	shell_window = e_shell_view_get_shell_window (shell_view);
 925 	shell = e_shell_window_get_shell (shell_window);
 926 	shell_settings = e_shell_get_shell_settings (shell);
 927 
 928 	mail_shell_content = mail_shell_view->priv->mail_shell_content;
 929 	mail_view = e_mail_shell_content_get_mail_view (mail_shell_content);
 930 
 931 	mail_shell_sidebar = mail_shell_view->priv->mail_shell_sidebar;
 932 	folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar);
 933 
 934 	reader = E_MAIL_READER (mail_view);
 935 	display = e_mail_reader_get_mail_display (reader);
 936 	message_list = e_mail_reader_get_message_list (reader);
 937 
 938 	magic_spacebar = e_shell_settings_get_boolean (
 939 		shell_settings, "mail-magic-spacebar");
 940 
 941 	toggle_action = GTK_TOGGLE_ACTION (ACTION (MAIL_CARET_MODE));
 942 	caret_mode = gtk_toggle_action_get_active (toggle_action);
 943 
 944 	window = gtk_widget_get_parent (GTK_WIDGET (display));
 945 	if (!GTK_IS_SCROLLED_WINDOW (window))
 946 		return;
 947 
 948 	adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (window));
 949 	value = gtk_adjustment_get_value (adj);
 950 	if (value == 0) {
 951 
 952 		if (caret_mode || !magic_spacebar)
 953 			return;
 954 
 955                 /* XXX Are two separate calls really necessary? */
 956 
 957 		if (message_list_select (
 958 		    MESSAGE_LIST (message_list),
 959 		    MESSAGE_LIST_SELECT_PREVIOUS,
 960 		    0, CAMEL_MESSAGE_SEEN))
 961 			return;
 962 
 963 		if (message_list_select (
 964 		    MESSAGE_LIST (message_list),
 965 		    MESSAGE_LIST_SELECT_PREVIOUS |
 966 		    MESSAGE_LIST_SELECT_WRAP,
 967 		    0, CAMEL_MESSAGE_SEEN))
 968 			return;
 969 
 970 		em_folder_tree_select_next_path (folder_tree, TRUE);
 971 
 972 		gtk_widget_grab_focus (message_list);
 973 
 974 	} else {
 975 
 976 		gtk_adjustment_set_value (
 977 			adj,
 978 			value - gtk_adjustment_get_page_increment (adj));
 979 
 980 		return;
 981 	}
 982 }
 983 
 984 static void
 985 action_mail_smart_forward_cb (GtkAction *action,
 986                               EMailShellView *mail_shell_view)
 987 {
 988 	EShell *shell;
 989 	EShellView *shell_view;
 990 	EShellWindow *shell_window;
 991 	EShellSettings *shell_settings;
 992 	EMailShellContent *mail_shell_content;
 993 	EMailShellSidebar *mail_shell_sidebar;
 994 	EMFolderTree *folder_tree;
 995 	EMailReader *reader;
 996 	EMailView *mail_view;
 997 	GtkWidget *message_list;
 998 	GtkWidget *window;
 999 	GtkAdjustment *adj;
1000 	GtkToggleAction *toggle_action;
1001 	EMailDisplay *display;
1002 	gboolean caret_mode;
1003 	gboolean magic_spacebar;
1004 	gdouble value;
1005 	gdouble upper;
1006 
1007 	/* This implements the so-called "Magic Spacebar". */
1008 
1009 	shell_view = E_SHELL_VIEW (mail_shell_view);
1010 	shell_window = e_shell_view_get_shell_window (shell_view);
1011 	shell = e_shell_window_get_shell (shell_window);
1012 	shell_settings = e_shell_get_shell_settings (shell);
1013 
1014 	mail_shell_content = mail_shell_view->priv->mail_shell_content;
1015 	mail_view = e_mail_shell_content_get_mail_view (mail_shell_content);
1016 
1017 	mail_shell_sidebar = mail_shell_view->priv->mail_shell_sidebar;
1018 	folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar);
1019 
1020 	reader = E_MAIL_READER (mail_view);
1021 	display = e_mail_reader_get_mail_display (reader);
1022 	message_list = e_mail_reader_get_message_list (reader);
1023 
1024 	magic_spacebar = e_shell_settings_get_boolean (
1025 		shell_settings, "mail-magic-spacebar");
1026 
1027 	toggle_action = GTK_TOGGLE_ACTION (ACTION (MAIL_CARET_MODE));
1028 	caret_mode = gtk_toggle_action_get_active (toggle_action);
1029 
1030 	window = gtk_widget_get_parent (GTK_WIDGET (display));
1031 	if (!GTK_IS_SCROLLED_WINDOW (window))
1032 		return;
1033 
1034 	adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (window));
1035 	value = gtk_adjustment_get_value (adj);
1036 	upper = gtk_adjustment_get_upper (adj);
1037 	if (value + gtk_adjustment_get_page_size (adj) >= upper) {
1038 
1039 		if (caret_mode || !magic_spacebar)
1040 			return;
1041 
1042                 /* XXX Are two separate calls really necessary? */
1043 
1044 		if (message_list_select (
1045 		    MESSAGE_LIST (message_list),
1046 		    MESSAGE_LIST_SELECT_NEXT,
1047 		    0, CAMEL_MESSAGE_SEEN))
1048 			return;
1049 
1050 		if (message_list_select (
1051 		    MESSAGE_LIST (message_list),
1052 		    MESSAGE_LIST_SELECT_NEXT |
1053 		    MESSAGE_LIST_SELECT_WRAP,
1054 		    0, CAMEL_MESSAGE_SEEN))
1055 			return;
1056 
1057 		em_folder_tree_select_next_path (folder_tree, TRUE);
1058 
1059 		gtk_widget_grab_focus (message_list);
1060 
1061 	} else {
1062 
1063 		gtk_adjustment_set_value (
1064 			adj,
1065 			value + gtk_adjustment_get_page_increment (adj));
1066 
1067 		return;
1068 	}
1069 }
1070 
1071 static void
1072 action_mail_stop_cb (GtkAction *action,
1073                      EMailShellView *mail_shell_view)
1074 {
1075 	EShellView *shell_view;
1076 	EShellBackend *shell_backend;
1077 
1078 	shell_view = E_SHELL_VIEW (mail_shell_view);
1079 	shell_backend = e_shell_view_get_shell_backend (shell_view);
1080 
1081 	/* XXX There's some overlap here: activities submitted through
1082 	 *     the legacy MailMsg system might be cancelled twice, but
1083 	 *     it shouldn't cause problems. */
1084 
1085 	/* the old way */
1086 	mail_cancel_all ();
1087 
1088 	/* the new way */
1089 	e_shell_backend_cancel_all (shell_backend);
1090 }
1091 
1092 static void
1093 action_mail_threads_collapse_all_cb (GtkAction *action,
1094                                      EMailShellView *mail_shell_view)
1095 {
1096 	EMailShellContent *mail_shell_content;
1097 	GtkWidget *message_list;
1098 	EMailReader *reader;
1099 	EMailView *mail_view;
1100 
1101 	mail_shell_content = mail_shell_view->priv->mail_shell_content;
1102 	mail_view = e_mail_shell_content_get_mail_view (mail_shell_content);
1103 
1104 	reader = E_MAIL_READER (mail_view);
1105 	message_list = e_mail_reader_get_message_list (reader);
1106 
1107 	message_list_set_threaded_collapse_all (MESSAGE_LIST (message_list));
1108 }
1109 
1110 static void
1111 action_mail_threads_expand_all_cb (GtkAction *action,
1112                                    EMailShellView *mail_shell_view)
1113 {
1114 	EMailShellContent *mail_shell_content;
1115 	GtkWidget *message_list;
1116 	EMailReader *reader;
1117 	EMailView *mail_view;
1118 
1119 	mail_shell_content = mail_shell_view->priv->mail_shell_content;
1120 	mail_view = e_mail_shell_content_get_mail_view (mail_shell_content);
1121 
1122 	reader = E_MAIL_READER (mail_view);
1123 	message_list = e_mail_reader_get_message_list (reader);
1124 
1125 	message_list_set_threaded_expand_all (MESSAGE_LIST (message_list));
1126 }
1127 
1128 static void
1129 action_mail_tools_filters_cb (GtkAction *action,
1130                               EMailShellView *mail_shell_view)
1131 {
1132 	EShellBackend *shell_backend;
1133 	EShellContent *shell_content;
1134 	EShellWindow *shell_window;
1135 	EShellView *shell_view;
1136 	EMailBackend *backend;
1137 	EMailSession *session;
1138 
1139 	shell_view = E_SHELL_VIEW (mail_shell_view);
1140 	shell_window = e_shell_view_get_shell_window (shell_view);
1141 	shell_backend = e_shell_view_get_shell_backend (shell_view);
1142 	shell_content = e_shell_view_get_shell_content (shell_view);
1143 
1144 	backend = E_MAIL_BACKEND (shell_backend);
1145 	session = e_mail_backend_get_session (backend);
1146 
1147 	em_utils_edit_filters (
1148 		session,
1149 		E_ALERT_SINK (shell_content),
1150 		GTK_WINDOW (shell_window));
1151 }
1152 
1153 static void
1154 action_mail_tools_search_folders_cb (GtkAction *action,
1155                                      EMailShellView *mail_shell_view)
1156 {
1157 	EShellView *shell_view;
1158 	EShellWindow *shell_window;
1159 	EShellBackend *shell_backend;
1160 
1161 	shell_view = E_SHELL_VIEW (mail_shell_view);
1162 	shell_window = e_shell_view_get_shell_window (shell_view);
1163 	shell_backend = e_shell_view_get_shell_backend (shell_view);
1164 
1165 	vfolder_edit (
1166 		E_MAIL_BACKEND (shell_backend),
1167 		GTK_WINDOW (shell_window));
1168 }
1169 
1170 static void
1171 action_mail_tools_subscriptions_cb (GtkAction *action,
1172                                     EMailShellView *mail_shell_view)
1173 {
1174 	EMailShellSidebar *mail_shell_sidebar;
1175 	EShellWindow *shell_window;
1176 	EShellView *shell_view;
1177 	EMailSession *session;
1178 	EMFolderTree *folder_tree;
1179 	GtkWidget *dialog;
1180 	CamelStore *store;
1181 
1182 	shell_view = E_SHELL_VIEW (mail_shell_view);
1183 	shell_window = e_shell_view_get_shell_window (shell_view);
1184 
1185 	mail_shell_sidebar = mail_shell_view->priv->mail_shell_sidebar;
1186 	folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar);
1187 	store = em_folder_tree_get_selected_store (folder_tree);
1188 	session = em_folder_tree_get_session (folder_tree);
1189 
1190 	dialog = em_subscription_editor_new (
1191 		GTK_WINDOW (shell_window), session, store);
1192 	gtk_dialog_run (GTK_DIALOG (dialog));
1193 	gtk_widget_destroy (dialog);
1194 }
1195 
1196 static void
1197 action_mail_view_cb (GtkRadioAction *action,
1198                      GtkRadioAction *current,
1199                      EMailShellView *mail_shell_view)
1200 {
1201 	EMailShellContent *mail_shell_content;
1202 	GtkOrientation orientation;
1203 	EMailView *mail_view;
1204 
1205 	mail_shell_content = mail_shell_view->priv->mail_shell_content;
1206 	mail_view = e_mail_shell_content_get_mail_view (mail_shell_content);
1207 
1208 	switch (gtk_radio_action_get_current_value (action)) {
1209 		case 0:
1210 			orientation = GTK_ORIENTATION_VERTICAL;
1211 			break;
1212 		case 1:
1213 			orientation = GTK_ORIENTATION_HORIZONTAL;
1214 			break;
1215 		default:
1216 			g_return_if_reached ();
1217 	}
1218 
1219 	e_mail_view_set_orientation (mail_view, orientation);
1220 }
1221 
1222 static GtkActionEntry mail_entries[] = {
1223 
1224 	{ "mail-account-disable",
1225 	  NULL,
1226 	  N_("_Disable Account"),
1227 	  NULL,
1228 	  N_("Disable this account"),
1229 	  G_CALLBACK (action_mail_account_disable_cb) },
1230 
1231 	{ "mail-account-expunge",
1232 	  NULL,
1233 	  N_("_Empty Trash"),
1234 	  NULL,
1235 	  N_("Permanently remove all the deleted messages from all folders"),
1236 	  G_CALLBACK (action_mail_folder_expunge_cb) },
1237 
1238 	{ "mail-account-properties",
1239 	  GTK_STOCK_PROPERTIES,
1240 	  N_("_Properties"),
1241 	  NULL,
1242 	  N_("Edit properties of this account"),
1243 	  G_CALLBACK (action_mail_account_properties_cb) },
1244 
1245 	{ "mail-download",
1246 	  NULL,
1247 	  N_("_Download Messages for Offline Usage"),
1248 	  NULL,
1249 	  N_("Download messages of accounts and folders marked for offline usage"),
1250 	  G_CALLBACK (action_mail_download_cb) },
1251 
1252 	{ "mail-flush-outbox",
1253 	  "mail-send",
1254 	  N_("Fl_ush Outbox"),
1255 	  NULL,
1256 	  NULL,  /* XXX Add a tooltip! */
1257 	  G_CALLBACK (action_mail_flush_outbox_cb) },
1258 
1259 	{ "mail-folder-copy",
1260 	  "folder-copy",
1261 	  N_("_Copy Folder To..."),
1262 	  NULL,
1263 	  N_("Copy the selected folder into another folder"),
1264 	  G_CALLBACK (action_mail_folder_copy_cb) },
1265 
1266 	{ "mail-folder-delete",
1267 	  GTK_STOCK_DELETE,
1268 	  NULL,
1269 	  NULL,
1270 	  N_("Permanently remove this folder"),
1271 	  G_CALLBACK (action_mail_folder_delete_cb) },
1272 
1273 	{ "mail-folder-expunge",
1274 	  NULL,
1275 	  N_("E_xpunge"),
1276 	  "<Control>e",
1277 	  N_("Permanently remove all deleted messages from this folder"),
1278 	  G_CALLBACK (action_mail_folder_expunge_cb) },
1279 
1280 	{ "mail-folder-mark-all-as-read",
1281 	  "mail-read",
1282 	  N_("Mar_k All Messages as Read"),
1283 	  "<Control>slash",
1284 	  N_("Mark all messages in the folder as read"),
1285 	  G_CALLBACK (action_mail_folder_mark_all_as_read_cb) },
1286 
1287 	{ "mail-folder-move",
1288 	  "folder-move",
1289 	  N_("_Move Folder To..."),
1290 	  NULL,
1291 	  N_("Move the selected folder into another folder"),
1292 	  G_CALLBACK (action_mail_folder_move_cb) },
1293 
1294 	{ "mail-folder-new",
1295 	  "folder-new",
1296 	  N_("_New..."),
1297 	  NULL,
1298 	  N_("Create a new folder for storing mail"),
1299 	  G_CALLBACK (action_mail_folder_new_cb) },
1300 
1301 	{ "mail-folder-properties",
1302 	  GTK_STOCK_PROPERTIES,
1303 	  NULL,
1304 	  NULL,
1305 	  N_("Change the properties of this folder"),
1306 	  G_CALLBACK (action_mail_folder_properties_cb) },
1307 
1308 	{ "mail-folder-refresh",
1309 	  GTK_STOCK_REFRESH,
1310 	  NULL,
1311 	  "F5",
1312 	  N_("Refresh the folder"),
1313 	  G_CALLBACK (action_mail_folder_refresh_cb) },
1314 
1315 	{ "mail-folder-rename",
1316 	  NULL,
1317 	  N_("_Rename..."),
1318 	  "F2",
1319 	  N_("Change the name of this folder"),
1320 	  G_CALLBACK (action_mail_folder_rename_cb) },
1321 
1322 	{ "mail-folder-select-thread",
1323 	  NULL,
1324 	  N_("Select Message _Thread"),
1325 	  "<Control>h",
1326 	  N_("Select all messages in the same thread as the selected message"),
1327 	  G_CALLBACK (action_mail_folder_select_thread_cb) },
1328 
1329 	{ "mail-folder-select-subthread",
1330 	  NULL,
1331 	  N_("Select Message S_ubthread"),
1332 	  "<Shift><Control>h",
1333 	  N_("Select all replies to the currently selected message"),
1334 	  G_CALLBACK (action_mail_folder_select_subthread_cb) },
1335 
1336 	{ "mail-folder-unsubscribe",
1337 	  NULL,
1338 	  N_("_Unsubscribe"),
1339 	  NULL,
1340 	  N_("Unsubscribe from the selected folder"),
1341 	  G_CALLBACK (action_mail_folder_unsubscribe_cb) },
1342 
1343 	{ "mail-global-expunge",
1344 	  NULL,
1345 	  N_("Empty _Trash"),
1346 	  NULL,
1347 	  N_("Permanently remove all the deleted messages from all accounts"),
1348 	  G_CALLBACK (action_mail_global_expunge_cb) },
1349 
1350 	{ "mail-label-new",
1351 	  NULL,
1352 	  N_("_New Label"),
1353 	  NULL,
1354 	  NULL,  /* XXX Add a tooltip! */
1355 	  G_CALLBACK (action_mail_label_new_cb) },
1356 
1357 	/* Translators: "None" is used in the message label context menu.
1358 	 *              It removes all labels from the selected messages. */
1359 	{ "mail-label-none",
1360 	  NULL,
1361 	  N_("N_one"),
1362 	  NULL,
1363 	  NULL,  /* XXX Add a tooltip! */
1364 	  G_CALLBACK (action_mail_label_none_cb) },
1365 
1366 	/* This is the same as "mail-tools-subscriptions" but only
1367 	 * appears in the sidebar context menu when right-clicking
1368 	 * on a store that supports folder subscriptions.  No need
1369 	 * for a special callback because Folder->Subscriptions...
1370 	 * already tries to open the "Folder Subscriptions" dialog
1371 	 * according to the highlighted item in the sidebar, which
1372 	 * is exactly the behavior we want here. */
1373 	{ "mail-manage-subscriptions",
1374 	  NULL,
1375 	  N_("_Manage Subscriptions"),
1376 	  NULL,
1377 	  N_("Subscribe or unsubscribe to folders on remote servers"),
1378 	  G_CALLBACK (action_mail_tools_subscriptions_cb) },
1379 
1380 	{ "mail-send-receive",
1381 	  "mail-send-receive",
1382 	  N_("Send / _Receive"),
1383 	  "F9",
1384 	  N_("Send queued items and retrieve new items"),
1385 	  G_CALLBACK (action_mail_send_receive_cb) },
1386 
1387         { "mail-send-receive-receive-all",
1388 	  NULL,
1389 	  N_("R_eceive All"),
1390 	  NULL,
1391 	  N_("Receive new items from all accounts"),
1392 	  G_CALLBACK (action_mail_send_receive_receive_all_cb) },
1393 
1394         { "mail-send-receive-send-all",
1395 	  "mail-send",
1396 	  N_("_Send All"),
1397 	  NULL,
1398 	  N_("Send queued items in all accounts"),
1399 	  G_CALLBACK (action_mail_send_receive_send_all_cb) },
1400 
1401         { "mail-send-receive-submenu",
1402 	  "mail-send-receive",
1403 	  N_("Send / _Receive"),
1404 	  NULL,
1405 	  NULL,
1406 	  NULL },
1407 
1408 	{ "mail-smart-backward",
1409 	  NULL,
1410 	  NULL,  /* No menu item; key press only */
1411 	  NULL,
1412 	  NULL,
1413 	  G_CALLBACK (action_mail_smart_backward_cb) },
1414 
1415 	{ "mail-smart-forward",
1416 	  NULL,
1417 	  NULL,  /* No menu item; key press only */
1418 	  NULL,
1419 	  NULL,
1420 	  G_CALLBACK (action_mail_smart_forward_cb) },
1421 
1422 	{ "mail-stop",
1423 	  GTK_STOCK_STOP,
1424 	  N_("Cancel"),
1425 	  NULL,
1426 	  N_("Cancel the current mail operation"),
1427 	  G_CALLBACK (action_mail_stop_cb) },
1428 
1429 	{ "mail-threads-collapse-all",
1430 	  NULL,
1431 	  N_("Collapse All _Threads"),
1432 	  "<Shift><Control>b",
1433 	  N_("Collapse all message threads"),
1434 	  G_CALLBACK (action_mail_threads_collapse_all_cb) },
1435 
1436 	{ "mail-threads-expand-all",
1437 	  NULL,
1438 	  N_("E_xpand All Threads"),
1439 	  NULL,
1440 	  N_("Expand all message threads"),
1441 	  G_CALLBACK (action_mail_threads_expand_all_cb) },
1442 
1443 	{ "mail-tools-filters",
1444 	  NULL,
1445 	  N_("_Message Filters"),
1446 	  NULL,
1447 	  N_("Create or edit rules for filtering new mail"),
1448 	  G_CALLBACK (action_mail_tools_filters_cb) },
1449 
1450 	{ "mail-tools-subscriptions",
1451 	  NULL,
1452 	  N_("_Subscriptions..."),
1453 	  NULL,
1454 	  N_("Subscribe or unsubscribe to folders on remote servers"),
1455 	  G_CALLBACK (action_mail_tools_subscriptions_cb) },
1456 
1457 	/*** Menus ***/
1458 
1459 	{ "mail-folder-menu",
1460 	  NULL,
1461 	  N_("F_older"),
1462 	  NULL,
1463 	  NULL,
1464 	  NULL },
1465 
1466 	{ "mail-label-menu",
1467 	  NULL,
1468 	  N_("_Label"),
1469 	  NULL,
1470 	  NULL,
1471 	  NULL },
1472 
1473 	{ "mail-preview-menu",
1474 	  NULL,
1475 	  N_("_Preview"),
1476 	  NULL,
1477 	  NULL,
1478 	  NULL }
1479 };
1480 
1481 static GtkActionEntry search_folder_entries[] = {
1482 
1483 	{ "mail-create-search-folder",
1484 	  NULL,
1485 	  N_("C_reate Search Folder From Search..."),
1486 	  NULL,
1487 	  NULL,  /* XXX Add a tooltip! */
1488 	  G_CALLBACK (action_mail_create_search_folder_cb) },
1489 
1490 	{ "mail-tools-search-folders",
1491 	  NULL,
1492 	  N_("Search F_olders"),
1493 	  NULL,
1494 	  N_("Create or edit search folder definitions"),
1495 	  G_CALLBACK (action_mail_tools_search_folders_cb) },
1496 };
1497 
1498 static EPopupActionEntry mail_popup_entries[] = {
1499 
1500 	{ "mail-popup-account-disable",
1501 	  NULL,
1502 	  "mail-account-disable" },
1503 
1504 	{ "mail-popup-account-expunge",
1505 	  NULL,
1506 	  "mail-account-expunge" },
1507 
1508 	{ "mail-popup-account-properties",
1509 	  NULL,
1510 	  "mail-account-properties" },
1511 
1512 	{ "mail-popup-flush-outbox",
1513 	  NULL,
1514 	  "mail-flush-outbox" },
1515 
1516 	{ "mail-popup-folder-copy",
1517 	  NULL,
1518 	  "mail-folder-copy" },
1519 
1520 	{ "mail-popup-folder-delete",
1521 	  NULL,
1522 	  "mail-folder-delete" },
1523 
1524 	{ "mail-popup-folder-move",
1525 	  NULL,
1526 	  "mail-folder-move" },
1527 
1528 	{ "mail-popup-folder-new",
1529 	  N_("_New Folder..."),
1530 	  "mail-folder-new" },
1531 
1532 	{ "mail-popup-folder-properties",
1533 	  NULL,
1534 	  "mail-folder-properties" },
1535 
1536 	{ "mail-popup-folder-refresh",
1537 	  NULL,
1538 	  "mail-folder-refresh" },
1539 
1540 	{ "mail-popup-folder-rename",
1541 	  NULL,
1542 	  "mail-folder-rename" },
1543 
1544 	{ "mail-popup-folder-unsubscribe",
1545 	  NULL,
1546 	  "mail-folder-unsubscribe" },
1547 
1548 	{ "mail-popup-manage-subscriptions",
1549 	  NULL,
1550 	  "mail-manage-subscriptions" }
1551 };
1552 
1553 static GtkToggleActionEntry mail_toggle_entries[] = {
1554 
1555 	{ "mail-preview",
1556 	  NULL,
1557 	  N_("Show Message _Preview"),
1558 	  "<Control>m",
1559 	  N_("Show message preview pane"),
1560 	  NULL,  /* Handled by property bindings */
1561 	  TRUE },
1562 
1563 	{ "mail-show-deleted",
1564 	  NULL,
1565 	  N_("Show _Deleted Messages"),
1566 	  NULL,
1567 	  N_("Show deleted messages with a line through them"),
1568 	  G_CALLBACK (action_mail_show_deleted_cb),
1569 	  FALSE },
1570 
1571 	{ "mail-threads-group-by",
1572 	  NULL,
1573 	  N_("_Group By Threads"),
1574 	  "<Control>t",
1575 	  N_("Threaded message list"),
1576 	  NULL,  /* Handled by property bindings */
1577 	  FALSE },
1578 
1579 	{ "mail-vfolder-unmatched-enable",
1580 	  NULL,
1581 	  N_("_Unmatched Folder Enabled"),
1582 	  NULL,
1583 	  N_("Toggles whether Unmatched search folder is enabled"),
1584 	  NULL }
1585 };
1586 
1587 static GtkRadioActionEntry mail_view_entries[] = {
1588 
1589 	/* This action represents the initial active mail view.
1590 	 * It should not be visible in the UI, nor should it be
1591 	 * possible to switch to it from another shell view. */
1592 	{ "mail-view-initial",
1593 	  NULL,
1594 	  NULL,
1595 	  NULL,
1596 	  NULL,
1597 	  -1 },
1598 
1599 	{ "mail-view-classic",
1600 	  NULL,
1601 	  N_("_Classic View"),
1602 	  NULL,
1603 	  N_("Show message preview below the message list"),
1604 	  0 },
1605 
1606 	{ "mail-view-vertical",
1607 	  NULL,
1608 	  N_("_Vertical View"),
1609 	  NULL,
1610 	  N_("Show message preview alongside the message list"),
1611 	  1 }
1612 };
1613 
1614 static GtkRadioActionEntry mail_filter_entries[] = {
1615 
1616 	{ "mail-filter-all-messages",
1617 	  NULL,
1618 	  N_("All Messages"),
1619 	  NULL,
1620 	  NULL,  /* XXX Add a tooltip! */
1621 	  MAIL_FILTER_ALL_MESSAGES },
1622 
1623 	{ "mail-filter-important-messages",
1624 	  "emblem-important",
1625 	  N_("Important Messages"),
1626 	  NULL,
1627 	  NULL,  /* XXX Add a tooltip! */
1628 	  MAIL_FILTER_IMPORTANT_MESSAGES },
1629 
1630 	{ "mail-filter-last-5-days-messages",
1631 	  NULL,
1632 	  N_("Last 5 Days' Messages"),
1633 	  NULL,
1634 	  NULL,  /* XXX Add a tooltip! */
1635 	  MAIL_FILTER_LAST_5_DAYS_MESSAGES },
1636 
1637 	{ "mail-filter-messages-not-junk",
1638 	  "mail-mark-notjunk",
1639 	  N_("Messages Not Junk"),
1640 	  NULL,
1641 	  NULL,  /* XXX Add a tooltip! */
1642 	  MAIL_FILTER_MESSAGES_NOT_JUNK },
1643 
1644 	{ "mail-filter-messages-with-attachments",
1645 	  "mail-attachment",
1646 	  N_("Messages with Attachments"),
1647 	  NULL,
1648 	  NULL,  /* XXX Add a tooltip! */
1649 	  MAIL_FILTER_MESSAGES_WITH_ATTACHMENTS },
1650 
1651 	{ "mail-filter-no-label",
1652 	  NULL,
1653 	  N_("No Label"),
1654 	  NULL,
1655 	  NULL,  /* XXX Add a tooltip! */
1656 	  MAIL_FILTER_NO_LABEL },
1657 
1658 	{ "mail-filter-read-messages",
1659 	  "mail-read",
1660 	  N_("Read Messages"),
1661 	  NULL,
1662 	  NULL,  /* XXX Add a tooltip! */
1663 	  MAIL_FILTER_READ_MESSAGES },
1664 
1665 	{ "mail-filter-unread-messages",
1666 	  "mail-unread",
1667 	  N_("Unread Messages"),
1668 	  NULL,
1669 	  NULL,  /* XXX Add a tooltip! */
1670 	  MAIL_FILTER_UNREAD_MESSAGES }
1671 };
1672 
1673 static GtkRadioActionEntry mail_search_entries[] = {
1674 
1675 	{ "mail-search-advanced-hidden",
1676 	  NULL,
1677 	  N_("Advanced Search"),
1678 	  NULL,
1679 	  NULL,
1680 	  MAIL_SEARCH_ADVANCED },
1681 
1682 	{ "mail-search-body-contains",
1683 	  NULL,
1684 	  N_("Body contains"),
1685 	  NULL,
1686 	  NULL,  /* XXX Add a tooltip! */
1687 	  MAIL_SEARCH_BODY_CONTAINS },
1688 
1689 	{ "mail-search-message-contains",
1690 	  NULL,
1691 	  N_("Message contains"),
1692 	  NULL,
1693 	  NULL,  /* XXX Add a tooltip! */
1694 	  MAIL_SEARCH_MESSAGE_CONTAINS },
1695 
1696 	{ "mail-search-recipients-contain",
1697 	  NULL,
1698 	  N_("Recipients contain"),
1699 	  NULL,
1700 	  NULL,  /* XXX Add a tooltip! */
1701 	  MAIL_SEARCH_RECIPIENTS_CONTAIN },
1702 
1703 	{ "mail-search-sender-contains",
1704 	  NULL,
1705 	  N_("Sender contains"),
1706 	  NULL,
1707 	  NULL,  /* XXX Add a tooltip! */
1708 	  MAIL_SEARCH_SENDER_CONTAINS },
1709 
1710 	{ "mail-search-subject-contains",
1711 	  NULL,
1712 	  N_("Subject contains"),
1713 	  NULL,
1714 	  NULL,  /* XXX Add a tooltip! */
1715 	  MAIL_SEARCH_SUBJECT_CONTAINS },
1716 
1717 	{ "mail-search-subject-or-addresses-contain",
1718 	  NULL,
1719 	  N_("Subject or Addresses contain"),
1720 	  NULL,
1721 	  NULL,  /* XXX Add a tooltip! */
1722 	  MAIL_SEARCH_SUBJECT_OR_ADDRESSES_CONTAIN }
1723 };
1724 
1725 static GtkRadioActionEntry mail_scope_entries[] = {
1726 
1727 	{ "mail-scope-all-accounts",
1728 	  NULL,
1729 	  N_("All Accounts"),
1730 	  NULL,
1731 	  NULL,  /* XXX Add a tooltip! */
1732 	  MAIL_SCOPE_ALL_ACCOUNTS },
1733 
1734 	{ "mail-scope-current-account",
1735 	  NULL,
1736 	  N_("Current Account"),
1737 	  NULL,
1738 	  NULL,  /* XXX Add a tooltip! */
1739 	  MAIL_SCOPE_CURRENT_ACCOUNT },
1740 
1741 	{ "mail-scope-current-folder",
1742 	  NULL,
1743 	  N_("Current Folder"),
1744 	  NULL,
1745 	  NULL,  /* XXX Add a tooltip! */
1746 	  MAIL_SCOPE_CURRENT_FOLDER }
1747 };
1748 
1749 void
1750 e_mail_shell_view_actions_init (EMailShellView *mail_shell_view)
1751 {
1752 	EMailShellContent *mail_shell_content;
1753 	EShellView *shell_view;
1754 	EShellWindow *shell_window;
1755 	EShellBackend *shell_backend;
1756 	EShell *shell;
1757 	EShellSearchbar *searchbar;
1758 	EActionComboBox *combo_box;
1759 	EMailView *mail_view;
1760 	GtkActionGroup *action_group;
1761 	GtkAction *action;
1762 	GSettings *settings;
1763 
1764 	g_return_if_fail (E_IS_MAIL_SHELL_VIEW (mail_shell_view));
1765 
1766 	shell_view = E_SHELL_VIEW (mail_shell_view);
1767 	shell_window = e_shell_view_get_shell_window (shell_view);
1768 	shell_backend = e_shell_view_get_shell_backend (shell_view);
1769 	shell = e_shell_window_get_shell (shell_window);
1770 
1771 	mail_shell_content = mail_shell_view->priv->mail_shell_content;
1772 	mail_view = e_mail_shell_content_get_mail_view (mail_shell_content);
1773 	searchbar = e_mail_shell_content_get_searchbar (mail_shell_content);
1774 
1775 	/* Mail Actions */
1776 	action_group = ACTION_GROUP (MAIL);
1777 	gtk_action_group_add_actions (
1778 		action_group, mail_entries,
1779 		G_N_ELEMENTS (mail_entries), mail_shell_view);
1780 	gtk_action_group_add_toggle_actions (
1781 		action_group, mail_toggle_entries,
1782 		G_N_ELEMENTS (mail_toggle_entries), mail_shell_view);
1783 	gtk_action_group_add_radio_actions (
1784 		action_group, mail_view_entries,
1785 		G_N_ELEMENTS (mail_view_entries), -1,
1786 		G_CALLBACK (action_mail_view_cb), mail_shell_view);
1787 	gtk_action_group_add_radio_actions (
1788 		action_group, mail_search_entries,
1789 		G_N_ELEMENTS (mail_search_entries),
1790 		-1, NULL, NULL);
1791 	gtk_action_group_add_radio_actions (
1792 		action_group, mail_scope_entries,
1793 		G_N_ELEMENTS (mail_scope_entries),
1794 		MAIL_SCOPE_CURRENT_FOLDER, NULL, NULL);
1795 	e_action_group_add_popup_actions (
1796 		action_group, mail_popup_entries,
1797 		G_N_ELEMENTS (mail_popup_entries));
1798 
1799 	/* Search Folder Actions */
1800 	action_group = ACTION_GROUP (SEARCH_FOLDERS);
1801 	gtk_action_group_add_actions (
1802 		action_group, search_folder_entries,
1803 		G_N_ELEMENTS (search_folder_entries), mail_shell_view);
1804 
1805 	action = ACTION (MAIL_SCOPE_ALL_ACCOUNTS);
1806 	combo_box = e_shell_searchbar_get_scope_combo_box (searchbar);
1807 	e_action_combo_box_set_action (combo_box, GTK_RADIO_ACTION (action));
1808 	e_shell_searchbar_set_scope_visible (searchbar, TRUE);
1809 
1810 	/* Advanced Search Action */
1811 	action = ACTION (MAIL_SEARCH_ADVANCED_HIDDEN);
1812 	gtk_action_set_visible (action, FALSE);
1813 	e_shell_searchbar_set_search_option (
1814 		searchbar, GTK_RADIO_ACTION (action));
1815 
1816 	g_object_set (ACTION (MAIL_SEND_RECEIVE), "is-important", TRUE, NULL);
1817 
1818 	/* Bind GObject properties for GSettings keys. */
1819 
1820 	settings = g_settings_new ("org.gnome.evolution.mail");
1821 
1822 	g_settings_bind (
1823 		settings, "show-deleted",
1824 		ACTION (MAIL_SHOW_DELETED), "active",
1825 		G_SETTINGS_BIND_DEFAULT);
1826 
1827 	g_settings_bind (
1828 		settings, "layout",
1829 		ACTION (MAIL_VIEW_VERTICAL), "current-value",
1830 		G_SETTINGS_BIND_DEFAULT);
1831 
1832 	g_settings_bind (
1833 		settings, "enable-unmatched",
1834 		ACTION (MAIL_VFOLDER_UNMATCHED_ENABLE), "active",
1835 		G_SETTINGS_BIND_DEFAULT);
1836 
1837 	g_object_unref (settings);
1838 
1839 	/* Fine tuning. */
1840 
1841 	g_object_bind_property (
1842 		ACTION (MAIL_THREADS_GROUP_BY), "active",
1843 		ACTION (MAIL_FOLDER_SELECT_THREAD), "sensitive",
1844 		G_BINDING_SYNC_CREATE);
1845 
1846 	g_object_bind_property (
1847 		ACTION (MAIL_THREADS_GROUP_BY), "active",
1848 		ACTION (MAIL_FOLDER_SELECT_SUBTHREAD), "sensitive",
1849 		G_BINDING_SYNC_CREATE);
1850 
1851 	g_object_bind_property (
1852 		ACTION (MAIL_THREADS_GROUP_BY), "active",
1853 		ACTION (MAIL_THREADS_COLLAPSE_ALL), "sensitive",
1854 		G_BINDING_SYNC_CREATE);
1855 
1856 	g_object_bind_property (
1857 		ACTION (MAIL_THREADS_GROUP_BY), "active",
1858 		ACTION (MAIL_THREADS_EXPAND_ALL), "sensitive",
1859 		G_BINDING_SYNC_CREATE);
1860 
1861 	g_object_bind_property (
1862 		ACTION (MAIL_PREVIEW), "active",
1863 		mail_view, "preview-visible",
1864 		G_BINDING_BIDIRECTIONAL |
1865 		G_BINDING_SYNC_CREATE);
1866 
1867 	g_object_bind_property (
1868 		ACTION (MAIL_THREADS_GROUP_BY), "active",
1869 		mail_shell_content, "group-by-threads",
1870 		G_BINDING_BIDIRECTIONAL |
1871 		G_BINDING_SYNC_CREATE);
1872 
1873 	g_object_bind_property (
1874 		ACTION (MAIL_PREVIEW), "active",
1875 		ACTION (MAIL_VIEW_CLASSIC), "sensitive",
1876 		G_BINDING_SYNC_CREATE);
1877 
1878 	g_object_bind_property (
1879 		ACTION (MAIL_PREVIEW), "active",
1880 		ACTION (MAIL_VIEW_VERTICAL), "sensitive",
1881 		G_BINDING_SYNC_CREATE);
1882 
1883 	g_object_bind_property (
1884 		ACTION (MAIL_SHOW_DELETED), "active",
1885 		mail_view, "show-deleted",
1886 		G_BINDING_BIDIRECTIONAL |
1887 		G_BINDING_SYNC_CREATE);
1888 
1889 	g_object_bind_property (
1890 		shell_backend, "busy",
1891 		ACTION (MAIL_STOP), "sensitive",
1892 		G_BINDING_SYNC_CREATE);
1893 
1894 	g_object_bind_property (
1895 		shell, "online",
1896 		ACTION (MAIL_SEND_RECEIVE), "sensitive",
1897 		G_BINDING_SYNC_CREATE);
1898 
1899 	g_object_bind_property (
1900 		shell, "online",
1901 		ACTION (MAIL_SEND_RECEIVE_RECEIVE_ALL), "sensitive",
1902 		G_BINDING_SYNC_CREATE);
1903 
1904 	g_object_bind_property (
1905 		shell, "online",
1906 		ACTION (MAIL_SEND_RECEIVE_SEND_ALL), "sensitive",
1907 		G_BINDING_SYNC_CREATE);
1908 
1909 	g_object_bind_property (
1910 		shell, "online",
1911 		ACTION (MAIL_SEND_RECEIVE_SUBMENU), "sensitive",
1912 		G_BINDING_SYNC_CREATE);
1913 
1914 	/* Keep the sensitivity of "Create Search Folder from Search"
1915 	 * in sync with "Save Search" so that its only selectable when
1916 	 * showing search results. */
1917 	g_object_bind_property (
1918 		ACTION (SEARCH_SAVE), "sensitive",
1919 		ACTION (MAIL_CREATE_SEARCH_FOLDER), "sensitive",
1920 		G_BINDING_SYNC_CREATE);
1921 
1922 	g_object_bind_property (
1923 		shell, "online",
1924 		ACTION (MAIL_DOWNLOAD), "sensitive",
1925 		G_BINDING_SYNC_CREATE);
1926 
1927 	g_signal_connect (
1928 		ACTION (GAL_SAVE_CUSTOM_VIEW), "activate",
1929 		G_CALLBACK (action_gal_save_custom_view_cb), mail_shell_view);
1930 }
1931 
1932 /* Helper for e_mail_shell_view_update_popup_labels() */
1933 static void
1934 mail_shell_view_update_label_action (GtkToggleAction *action,
1935                                      EMailReader *reader,
1936                                      GPtrArray *uids,
1937                                      const gchar *label_tag)
1938 {
1939 	CamelFolder *folder;
1940 	gboolean exists = FALSE;
1941 	gboolean not_exists = FALSE;
1942 	gboolean sensitive;
1943 	guint ii;
1944 
1945 	folder = e_mail_reader_get_folder (reader);
1946 
1947 	/* Figure out the proper label action state for the selected
1948 	 * messages.  If all the selected messages have the given label,
1949 	 * make the toggle action active.  If all the selected message
1950 	 * DO NOT have the given label, make the toggle action inactive.
1951 	 * If some do and some don't, make the action insensitive. */
1952 
1953 	for (ii = 0; ii < uids->len && (!exists || !not_exists); ii++) {
1954 		const gchar *old_label;
1955 		gchar *new_label;
1956 
1957 		/* Check for new-style labels. */
1958 		if (camel_folder_get_message_user_flag (
1959 			folder, uids->pdata[ii], label_tag)) {
1960 			exists = TRUE;
1961 			continue;
1962 		}
1963 
1964 		/* Check for old-style labels. */
1965 		old_label = camel_folder_get_message_user_tag (
1966 			folder, uids->pdata[ii], "label");
1967 		if (old_label == NULL) {
1968 			not_exists = TRUE;
1969 			continue;
1970 		}
1971 
1972 		/* Convert old-style labels ("<name>") to "$Label<name>". */
1973 		new_label = g_alloca (strlen (old_label) + 10);
1974 		g_stpcpy (g_stpcpy (new_label, "$Label"), old_label);
1975 
1976 		if (strcmp (new_label, label_tag) == 0)
1977 			exists = TRUE;
1978 		else
1979 			not_exists = TRUE;
1980 	}
1981 
1982 	sensitive = !(exists && not_exists);
1983 	gtk_toggle_action_set_active (action, exists);
1984 	gtk_action_set_sensitive (GTK_ACTION (action), sensitive);
1985 }
1986 
1987 void
1988 e_mail_shell_view_update_popup_labels (EMailShellView *mail_shell_view)
1989 {
1990 	EShellView *shell_view;
1991 	EShellWindow *shell_window;
1992 	EShellBackend *shell_backend;
1993 	EMailShellContent *mail_shell_content;
1994 	EMailLabelListStore *label_store;
1995 	EMailBackend *backend;
1996 	EMailSession *session;
1997 	EMailReader *reader;
1998 	EMailView *mail_view;
1999 	GtkUIManager *ui_manager;
2000 	GtkActionGroup *action_group;
2001 	GtkTreeIter iter;
2002 	GPtrArray *uids;
2003 	const gchar *path;
2004 	gboolean valid;
2005 	guint merge_id;
2006 	gint ii = 0;
2007 
2008 	g_return_if_fail (E_IS_MAIL_SHELL_VIEW (mail_shell_view));
2009 
2010 	shell_view = E_SHELL_VIEW (mail_shell_view);
2011 	shell_window = e_shell_view_get_shell_window (shell_view);
2012 	shell_backend = e_shell_view_get_shell_backend (shell_view);
2013 	ui_manager = e_shell_window_get_ui_manager (shell_window);
2014 
2015 	backend = E_MAIL_BACKEND (shell_backend);
2016 	session = e_mail_backend_get_session (backend);
2017 	label_store = e_mail_ui_session_get_label_store (
2018 		E_MAIL_UI_SESSION (session));
2019 
2020 	action_group = ACTION_GROUP (MAIL_LABEL);
2021 	merge_id = mail_shell_view->priv->label_merge_id;
2022 	path = "/mail-message-popup/mail-label-menu/mail-label-actions";
2023 
2024 	/* Unmerge the previous menu items. */
2025 	gtk_ui_manager_remove_ui (ui_manager, merge_id);
2026 	e_action_group_remove_all_actions (action_group);
2027 	gtk_ui_manager_ensure_update (ui_manager);
2028 
2029 	mail_shell_content = mail_shell_view->priv->mail_shell_content;
2030 	mail_view = e_mail_shell_content_get_mail_view (mail_shell_content);
2031 
2032 	reader = E_MAIL_READER (mail_view);
2033 	uids = e_mail_reader_get_selected_uids (reader);
2034 
2035 	valid = gtk_tree_model_get_iter_first (
2036 		GTK_TREE_MODEL (label_store), &iter);
2037 
2038 	while (valid) {
2039 		EMailLabelAction *label_action;
2040 		GtkAction *action;
2041 		gchar *action_name;
2042 		gchar *stock_id;
2043 		gchar *label;
2044 		gchar *tag;
2045 
2046 		label = e_mail_label_list_store_get_name (
2047 			label_store, &iter);
2048 		stock_id = e_mail_label_list_store_get_stock_id (
2049 			label_store, &iter);
2050 		tag = e_mail_label_list_store_get_tag (
2051 			label_store, &iter);
2052 		action_name = g_strdup_printf ("mail-label-%d", ii);
2053 
2054 		/* XXX Add a tooltip! */
2055 		label_action = e_mail_label_action_new (
2056 			action_name, label, NULL, stock_id);
2057 
2058 		g_object_set_data_full (
2059 			G_OBJECT (label_action), "tag",
2060 			tag, (GDestroyNotify) g_free);
2061 
2062 		/* Configure the action before we connect to signals. */
2063 		mail_shell_view_update_label_action (
2064 			GTK_TOGGLE_ACTION (label_action),
2065 			reader, uids, tag);
2066 
2067 		g_signal_connect (
2068 			label_action, "toggled",
2069 			G_CALLBACK (action_mail_label_cb), mail_shell_view);
2070 
2071 		/* The action group takes ownership of the action. */
2072 		action = GTK_ACTION (label_action);
2073 		gtk_action_group_add_action (action_group, action);
2074 		g_object_unref (label_action);
2075 
2076 		gtk_ui_manager_add_ui (
2077 			ui_manager, merge_id, path, action_name,
2078 			action_name, GTK_UI_MANAGER_AUTO, FALSE);
2079 
2080 		g_free (label);
2081 		g_free (stock_id);
2082 		g_free (action_name);
2083 
2084 		valid = gtk_tree_model_iter_next (
2085 			GTK_TREE_MODEL (label_store), &iter);
2086 		ii++;
2087 	}
2088 
2089 	em_utils_uids_free (uids);
2090 }
2091 
2092 void
2093 e_mail_shell_view_update_search_filter (EMailShellView *mail_shell_view)
2094 {
2095 	EMailShellContent *mail_shell_content;
2096 	EShellView *shell_view;
2097 	EShellWindow *shell_window;
2098 	EShellBackend *shell_backend;
2099 	EShellSearchbar *searchbar;
2100 	EMailLabelListStore *label_store;
2101 	EMailBackend *backend;
2102 	EMailSession *session;
2103 	EActionComboBox *combo_box;
2104 	GtkActionGroup *action_group;
2105 	GtkRadioAction *radio_action;
2106 	GtkTreeIter iter;
2107 	GList *list;
2108 	GSList *group;
2109 	gboolean valid;
2110 	gint ii = 0;
2111 
2112 	g_return_if_fail (E_IS_MAIL_SHELL_VIEW (mail_shell_view));
2113 
2114 	shell_view = E_SHELL_VIEW (mail_shell_view);
2115 	shell_window = e_shell_view_get_shell_window (shell_view);
2116 	shell_backend = e_shell_view_get_shell_backend (shell_view);
2117 
2118 	backend = E_MAIL_BACKEND (shell_backend);
2119 	session = e_mail_backend_get_session (backend);
2120 	label_store = e_mail_ui_session_get_label_store (
2121 		E_MAIL_UI_SESSION (session));
2122 
2123 	action_group = ACTION_GROUP (MAIL_FILTER);
2124 	e_action_group_remove_all_actions (action_group);
2125 
2126 	/* Add the standard filter actions.  No callback is needed
2127 	 * because changes in the EActionComboBox are detected and
2128 	 * handled by EShellSearchbar. */
2129 	gtk_action_group_add_radio_actions (
2130 		action_group, mail_filter_entries,
2131 		G_N_ELEMENTS (mail_filter_entries),
2132 		MAIL_FILTER_ALL_MESSAGES, NULL, NULL);
2133 
2134 	/* Retrieve the radio group from an action we just added. */
2135 	list = gtk_action_group_list_actions (action_group);
2136 	radio_action = GTK_RADIO_ACTION (list->data);
2137 	group = gtk_radio_action_get_group (radio_action);
2138 	g_list_free (list);
2139 
2140 	valid = gtk_tree_model_get_iter_first (
2141 		GTK_TREE_MODEL (label_store), &iter);
2142 
2143 	while (valid) {
2144 		GtkAction *action;
2145 		gchar *action_name;
2146 		gchar *stock_id;
2147 		gchar *label;
2148 
2149 		label = e_mail_label_list_store_get_name (
2150 			label_store, &iter);
2151 		stock_id = e_mail_label_list_store_get_stock_id (
2152 			label_store, &iter);
2153 
2154 		action_name = g_strdup_printf ("mail-filter-label-%d", ii);
2155 		radio_action = gtk_radio_action_new (
2156 			action_name, label, NULL, stock_id, ii);
2157 		g_free (action_name);
2158 
2159 		gtk_radio_action_set_group (radio_action, group);
2160 		group = gtk_radio_action_get_group (radio_action);
2161 
2162 		/* The action group takes ownership of the action. */
2163 		action = GTK_ACTION (radio_action);
2164 		gtk_action_group_add_action (action_group, action);
2165 		g_object_unref (radio_action);
2166 
2167 		g_free (label);
2168 		g_free (stock_id);
2169 
2170 		valid = gtk_tree_model_iter_next (
2171 			GTK_TREE_MODEL (label_store), &iter);
2172 		ii++;
2173 	}
2174 
2175 	mail_shell_content = mail_shell_view->priv->mail_shell_content;
2176 	searchbar = e_mail_shell_content_get_searchbar (mail_shell_content);
2177 	combo_box = e_shell_searchbar_get_filter_combo_box (searchbar);
2178 
2179 	e_shell_view_block_execute_search (shell_view);
2180 
2181 	/* Use any action in the group; doesn't matter which. */
2182 	e_action_combo_box_set_action (combo_box, radio_action);
2183 
2184 	ii = MAIL_FILTER_UNREAD_MESSAGES;
2185 	e_action_combo_box_add_separator_after (combo_box, ii);
2186 
2187 	ii = MAIL_FILTER_READ_MESSAGES;
2188 	e_action_combo_box_add_separator_after (combo_box, ii);
2189 
2190 	e_shell_view_unblock_execute_search (shell_view);
2191 }