Bug 793125 - Crash due to popup menus left attached too long
[evolution.git] / src / shell / e-shell-view.c
blob66bcc2cab5e2ec562d18cf742811d167d9b40f9f
1 /*
2 * e-shell-view.c
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 * for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
21 /**
22 * SECTION: e-shell-view
23 * @short_description: views within the main window
24 * @include: shell/e-shell-view.h
25 **/
27 #include "evolution-config.h"
29 #include "e-shell-view.h"
31 #include <string.h>
32 #include <glib/gi18n.h>
33 #include <libebackend/libebackend.h>
35 #include "e-shell-searchbar.h"
36 #include "e-shell-window-actions.h"
38 #define E_SHELL_VIEW_GET_PRIVATE(obj) \
39 (G_TYPE_INSTANCE_GET_PRIVATE \
40 ((obj), E_TYPE_SHELL_VIEW, EShellViewPrivate))
42 #define SIMPLE_SEARCHBAR_WIDTH 300
43 #define STATE_SAVE_TIMEOUT_SECONDS 3
45 struct _EShellViewPrivate {
46 GThread *main_thread; /* not referenced */
48 gpointer shell_window; /* weak pointer */
50 GKeyFile *state_key_file;
51 gpointer state_save_activity; /* weak pointer */
52 guint state_save_timeout_id;
54 GalViewInstance *view_instance;
55 gulong view_instance_changed_handler_id;
56 gulong view_instance_loaded_handler_id;
58 gchar *title;
59 gchar *view_id;
60 gint page_num;
61 guint merge_id;
63 GtkAction *action;
64 GtkSizeGroup *size_group;
65 GtkWidget *shell_content;
66 GtkWidget *shell_sidebar;
67 GtkWidget *shell_taskbar;
68 GtkWidget *searchbar;
70 EFilterRule *search_rule;
71 guint execute_search_blocked;
73 GtkWidget *preferences_window;
74 gulong preferences_hide_handler_id;
76 guint update_actions_idle_id;
79 enum {
80 PROP_0,
81 PROP_ACTION,
82 PROP_PAGE_NUM,
83 PROP_SEARCHBAR,
84 PROP_SEARCH_RULE,
85 PROP_SHELL_BACKEND,
86 PROP_SHELL_CONTENT,
87 PROP_SHELL_SIDEBAR,
88 PROP_SHELL_TASKBAR,
89 PROP_SHELL_WINDOW,
90 PROP_STATE_KEY_FILE,
91 PROP_TITLE,
92 PROP_VIEW_ID,
93 PROP_VIEW_INSTANCE
96 enum {
97 TOGGLED,
98 CLEAR_SEARCH,
99 CUSTOM_SEARCH,
100 EXECUTE_SEARCH,
101 UPDATE_ACTIONS,
102 LAST_SIGNAL
105 static gpointer parent_class;
106 static gulong signals[LAST_SIGNAL];
108 static void
109 shell_view_init_search_context (EShellViewClass *class)
111 EShellBackend *shell_backend;
112 ERuleContext *search_context;
113 const gchar *config_dir;
114 gchar *system_filename;
115 gchar *user_filename;
117 shell_backend = class->shell_backend;
119 /* Sanity check the class fields we need. */
120 g_return_if_fail (class->search_rules != NULL);
121 g_return_if_fail (E_IS_SHELL_BACKEND (shell_backend));
123 /* The basename for built-in searches is specified in the
124 * shell view class. All built-in search rules live in the
125 * same directory. */
126 system_filename = g_build_filename (
127 EVOLUTION_RULEDIR, class->search_rules, NULL);
129 /* The filename for custom saved searches is always of
130 * the form "$(shell_backend_config_dir)/searches.xml". */
131 config_dir = e_shell_backend_get_config_dir (shell_backend);
132 user_filename = g_build_filename (config_dir, "searches.xml", NULL);
134 /* Create the search context instance. Subclasses may override
135 * the GType so check that it's really an ERuleContext instance. */
136 search_context = g_object_new (class->search_context_type, NULL);
137 g_return_if_fail (E_IS_RULE_CONTEXT (search_context));
138 class->search_context = search_context;
140 e_rule_context_add_part_set (
141 search_context, "partset", E_TYPE_FILTER_PART,
142 e_rule_context_add_part, e_rule_context_next_part);
143 e_rule_context_add_rule_set (
144 search_context, "ruleset", E_TYPE_FILTER_RULE,
145 e_rule_context_add_rule, e_rule_context_next_rule);
146 e_rule_context_load (search_context, system_filename, user_filename);
148 g_free (system_filename);
149 g_free (user_filename);
152 static void
153 shell_view_init_view_collection (EShellViewClass *class)
155 EShellBackend *shell_backend;
156 const gchar *base_directory;
157 const gchar *name;
158 gchar *system_directory;
159 gchar *user_directory;
161 shell_backend = class->shell_backend;
162 g_return_if_fail (E_IS_SHELL_BACKEND (shell_backend));
163 name = E_SHELL_BACKEND_GET_CLASS (shell_backend)->name;
165 base_directory = EVOLUTION_GALVIEWSDIR;
166 system_directory = g_build_filename (base_directory, name, NULL);
168 base_directory = e_shell_backend_get_config_dir (shell_backend);
169 user_directory = g_build_filename (base_directory, "views", NULL);
171 /* The view collection is never destroyed. */
172 class->view_collection = gal_view_collection_new (
173 system_directory, user_directory);
175 g_free (system_directory);
176 g_free (user_directory);
179 static void
180 shell_view_update_view_id (EShellView *shell_view,
181 GalViewInstance *view_instance)
183 gchar *view_id;
185 view_id = gal_view_instance_get_current_view_id (view_instance);
186 e_shell_view_set_view_id (shell_view, view_id);
187 g_free (view_id);
190 static void
191 shell_view_load_state (EShellView *shell_view)
193 EShellBackend *shell_backend;
194 GKeyFile *key_file;
195 const gchar *config_dir;
196 gchar *filename;
197 GError *error = NULL;
199 shell_backend = e_shell_view_get_shell_backend (shell_view);
200 config_dir = e_shell_backend_get_config_dir (shell_backend);
201 filename = g_build_filename (config_dir, "state.ini", NULL);
203 /* XXX Should do this asynchronously. */
204 key_file = shell_view->priv->state_key_file;
205 g_key_file_load_from_file (key_file, filename, 0, &error);
207 if (error == NULL)
208 goto exit;
210 if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
211 g_warning ("%s", error->message);
213 g_error_free (error);
215 exit:
216 g_free (filename);
219 typedef struct {
220 EShellView *shell_view;
221 gchar *contents;
222 } SaveStateData;
224 static void
225 shell_view_save_state_done_cb (GFile *file,
226 GAsyncResult *result,
227 SaveStateData *data)
229 GError *error = NULL;
231 e_file_replace_contents_finish (file, result, NULL, &error);
233 if (error != NULL) {
234 g_warning ("%s", error->message);
235 g_error_free (error);
238 g_object_unref (data->shell_view);
239 g_free (data->contents);
240 g_slice_free (SaveStateData, data);
243 static EActivity *
244 shell_view_save_state (EShellView *shell_view,
245 gboolean immediately)
247 EShellBackend *shell_backend;
248 SaveStateData *data;
249 EActivity *activity;
250 GKeyFile *key_file;
251 GFile *file;
252 const gchar *config_dir;
253 gchar *contents;
254 gchar *path;
256 shell_backend = e_shell_view_get_shell_backend (shell_view);
257 config_dir = e_shell_backend_get_config_dir (shell_backend);
258 key_file = shell_view->priv->state_key_file;
260 contents = g_key_file_to_data (key_file, NULL, NULL);
261 g_return_val_if_fail (contents != NULL, NULL);
263 path = g_build_filename (config_dir, "state.ini", NULL);
264 if (immediately) {
265 g_file_set_contents (path, contents, -1, NULL);
267 g_free (path);
268 g_free (contents);
270 return NULL;
273 file = g_file_new_for_path (path);
274 g_free (path);
276 /* GIO does not copy the contents string, so we need to keep
277 * it in memory until saving is complete. We reference the
278 * shell view to keep it from being finalized while saving. */
279 data = g_slice_new (SaveStateData);
280 data->shell_view = g_object_ref (shell_view);
281 data->contents = contents;
283 /* The returned activity is a borrowed reference. */
284 activity = e_file_replace_contents_async (
285 file, contents, strlen (contents), NULL,
286 FALSE, G_FILE_CREATE_PRIVATE, (GAsyncReadyCallback)
287 shell_view_save_state_done_cb, data);
289 e_activity_set_text (
290 activity, (_("Saving user interface state")));
292 e_shell_backend_add_activity (shell_backend, activity);
294 g_object_unref (file);
296 return activity;
299 static gboolean
300 shell_view_state_timeout_cb (gpointer user_data)
302 EShellView *shell_view;
303 EActivity *activity;
305 shell_view = E_SHELL_VIEW (user_data);
307 /* If a save is still in progress, check back later. */
308 if (shell_view->priv->state_save_activity != NULL)
309 return TRUE;
311 activity = shell_view_save_state (shell_view, FALSE);
313 /* Set up a weak pointer that gets set to NULL when the
314 * activity finishes. This will tell us if we're still
315 * busy saving state data to disk on the next timeout. */
316 shell_view->priv->state_save_activity = activity;
317 g_object_add_weak_pointer (
318 G_OBJECT (shell_view->priv->state_save_activity),
319 &shell_view->priv->state_save_activity);
321 shell_view->priv->state_save_timeout_id = 0;
323 return FALSE;
326 static void
327 shell_view_emit_toggled (EShellView *shell_view)
329 g_signal_emit (shell_view, signals[TOGGLED], 0);
332 static void
333 shell_view_set_action (EShellView *shell_view,
334 GtkAction *action)
336 gchar *label;
338 g_return_if_fail (shell_view->priv->action == NULL);
340 shell_view->priv->action = g_object_ref (action);
342 g_object_get (action, "label", &label, NULL);
343 e_shell_view_set_title (shell_view, label);
344 g_free (label);
346 g_signal_connect_swapped (
347 action, "toggled",
348 G_CALLBACK (shell_view_emit_toggled), shell_view);
351 static void
352 shell_view_set_shell_window (EShellView *shell_view,
353 EShellWindow *shell_window)
355 g_return_if_fail (E_IS_SHELL_WINDOW (shell_window));
356 g_return_if_fail (shell_view->priv->shell_window == NULL);
358 shell_view->priv->shell_window = shell_window;
360 g_object_add_weak_pointer (
361 G_OBJECT (shell_window),
362 &shell_view->priv->shell_window);
365 static void
366 shell_view_set_property (GObject *object,
367 guint property_id,
368 const GValue *value,
369 GParamSpec *pspec)
371 switch (property_id) {
372 case PROP_ACTION:
373 shell_view_set_action (
374 E_SHELL_VIEW (object),
375 g_value_get_object (value));
376 return;
378 case PROP_PAGE_NUM:
379 e_shell_view_set_page_num (
380 E_SHELL_VIEW (object),
381 g_value_get_int (value));
382 return;
384 case PROP_SEARCH_RULE:
385 e_shell_view_set_search_rule (
386 E_SHELL_VIEW (object),
387 g_value_get_object (value));
388 return;
390 case PROP_SHELL_WINDOW:
391 shell_view_set_shell_window (
392 E_SHELL_VIEW (object),
393 g_value_get_object (value));
394 return;
396 case PROP_TITLE:
397 e_shell_view_set_title (
398 E_SHELL_VIEW (object),
399 g_value_get_string (value));
400 return;
402 case PROP_VIEW_ID:
403 e_shell_view_set_view_id (
404 E_SHELL_VIEW (object),
405 g_value_get_string (value));
406 return;
408 case PROP_VIEW_INSTANCE:
409 e_shell_view_set_view_instance (
410 E_SHELL_VIEW (object),
411 g_value_get_object (value));
412 return;
415 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
418 static void
419 shell_view_get_property (GObject *object,
420 guint property_id,
421 GValue *value,
422 GParamSpec *pspec)
424 switch (property_id) {
425 case PROP_ACTION:
426 g_value_set_object (
427 value, e_shell_view_get_action (
428 E_SHELL_VIEW (object)));
429 return;
431 case PROP_PAGE_NUM:
432 g_value_set_int (
433 value, e_shell_view_get_page_num (
434 E_SHELL_VIEW (object)));
435 return;
437 case PROP_SEARCHBAR:
438 g_value_set_object (
439 value, e_shell_view_get_searchbar (
440 E_SHELL_VIEW (object)));
441 return;
443 case PROP_SEARCH_RULE:
444 g_value_set_object (
445 value, e_shell_view_get_search_rule (
446 E_SHELL_VIEW (object)));
447 return;
449 case PROP_SHELL_BACKEND:
450 g_value_set_object (
451 value, e_shell_view_get_shell_backend (
452 E_SHELL_VIEW (object)));
453 return;
455 case PROP_SHELL_CONTENT:
456 g_value_set_object (
457 value, e_shell_view_get_shell_content (
458 E_SHELL_VIEW (object)));
459 return;
461 case PROP_SHELL_SIDEBAR:
462 g_value_set_object (
463 value, e_shell_view_get_shell_sidebar (
464 E_SHELL_VIEW (object)));
465 return;
467 case PROP_SHELL_TASKBAR:
468 g_value_set_object (
469 value, e_shell_view_get_shell_taskbar (
470 E_SHELL_VIEW (object)));
471 return;
473 case PROP_SHELL_WINDOW:
474 g_value_set_object (
475 value, e_shell_view_get_shell_window (
476 E_SHELL_VIEW (object)));
477 return;
479 case PROP_STATE_KEY_FILE:
480 g_value_set_pointer (
481 value, e_shell_view_get_state_key_file (
482 E_SHELL_VIEW (object)));
483 return;
485 case PROP_TITLE:
486 g_value_set_string (
487 value, e_shell_view_get_title (
488 E_SHELL_VIEW (object)));
489 return;
491 case PROP_VIEW_ID:
492 g_value_set_string (
493 value, e_shell_view_get_view_id (
494 E_SHELL_VIEW (object)));
495 return;
497 case PROP_VIEW_INSTANCE:
498 g_value_set_object (
499 value, e_shell_view_get_view_instance (
500 E_SHELL_VIEW (object)));
501 return;
504 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
507 static void
508 shell_view_dispose (GObject *object)
510 EShellViewPrivate *priv;
512 priv = E_SHELL_VIEW_GET_PRIVATE (object);
514 /* Expedite any pending state saves. */
515 if (priv->state_save_timeout_id > 0) {
516 g_source_remove (priv->state_save_timeout_id);
517 priv->state_save_timeout_id = 0;
518 if (priv->state_save_activity == NULL)
519 shell_view_save_state (E_SHELL_VIEW (object), TRUE);
522 if (priv->update_actions_idle_id > 0) {
523 g_source_remove (priv->update_actions_idle_id);
524 priv->update_actions_idle_id = 0;
527 if (priv->state_save_activity != NULL) {
528 g_object_remove_weak_pointer (
529 G_OBJECT (priv->state_save_activity),
530 &priv->state_save_activity);
531 priv->state_save_activity = NULL;
534 if (priv->view_instance_changed_handler_id > 0) {
535 g_signal_handler_disconnect (
536 priv->view_instance,
537 priv->view_instance_changed_handler_id);
538 priv->view_instance_changed_handler_id = 0;
541 if (priv->view_instance_loaded_handler_id > 0) {
542 g_signal_handler_disconnect (
543 priv->view_instance,
544 priv->view_instance_loaded_handler_id);
545 priv->view_instance_loaded_handler_id = 0;
548 if (priv->preferences_window != NULL) {
549 g_signal_handler_disconnect (
550 priv->preferences_window,
551 priv->preferences_hide_handler_id);
552 priv->preferences_hide_handler_id = 0;
555 if (priv->shell_window != NULL) {
556 g_object_remove_weak_pointer (
557 G_OBJECT (priv->shell_window), &priv->shell_window);
558 priv->shell_window = NULL;
561 g_clear_object (&priv->view_instance);
562 g_clear_object (&priv->shell_content);
563 g_clear_object (&priv->shell_sidebar);
564 g_clear_object (&priv->shell_taskbar);
565 g_clear_object (&priv->searchbar);
566 g_clear_object (&priv->search_rule);
567 g_clear_object (&priv->preferences_window);
569 /* Chain up to parent's dispose() method. */
570 G_OBJECT_CLASS (parent_class)->dispose (object);
573 static void
574 shell_view_finalize (GObject *object)
576 EShellViewPrivate *priv;
578 priv = E_SHELL_VIEW_GET_PRIVATE (object);
580 g_key_file_free (priv->state_key_file);
582 g_free (priv->title);
583 g_free (priv->view_id);
585 /* Chain up to parent's finalize() method. */
586 G_OBJECT_CLASS (parent_class)->finalize (object);
589 static void
590 shell_view_constructed (GObject *object)
592 EShell *shell;
593 EShellView *shell_view;
594 EShellBackend *shell_backend;
595 EShellViewClass *shell_view_class;
596 GtkWidget *widget;
597 gulong handler_id;
599 shell_view = E_SHELL_VIEW (object);
600 shell_view_class = E_SHELL_VIEW_GET_CLASS (shell_view);
602 shell_backend = e_shell_view_get_shell_backend (shell_view);
603 shell = e_shell_backend_get_shell (shell_backend);
605 shell_view_load_state (shell_view);
607 /* Invoke factory methods. */
609 /* Create the taskbar widget first so the content and
610 * sidebar widgets can access it during construction. */
611 widget = shell_view_class->new_shell_taskbar (shell_view);
612 shell_view->priv->shell_taskbar = g_object_ref_sink (widget);
613 gtk_widget_show (widget);
615 widget = shell_view_class->new_shell_content (shell_view);
616 shell_view->priv->shell_content = g_object_ref_sink (widget);
617 gtk_widget_show (widget);
619 widget = shell_view_class->new_shell_sidebar (shell_view);
620 shell_view->priv->shell_sidebar = g_object_ref_sink (widget);
621 gtk_widget_show (widget);
623 if (shell_view_class->construct_searchbar != NULL) {
624 widget = shell_view_class->construct_searchbar (shell_view);
625 shell_view->priv->searchbar = g_object_ref_sink (widget);
628 /* Size group should be safe to unreference now. */
629 g_object_unref (shell_view->priv->size_group);
630 shell_view->priv->size_group = NULL;
632 /* Update actions whenever the Preferences window is closed. */
633 widget = e_shell_get_preferences_window (shell);
634 shell_view->priv->preferences_window = g_object_ref (widget);
635 handler_id = g_signal_connect_swapped (
636 shell_view->priv->preferences_window, "hide",
637 G_CALLBACK (e_shell_view_update_actions_in_idle), shell_view);
638 shell_view->priv->preferences_hide_handler_id = handler_id;
640 e_extensible_load_extensions (E_EXTENSIBLE (object));
642 /* Chain up to parent's constructed() method. */
643 G_OBJECT_CLASS (parent_class)->constructed (object);
646 static GtkWidget *
647 shell_view_construct_searchbar (EShellView *shell_view)
649 EShellContent *shell_content;
650 EShellViewClass *shell_view_class;
651 GtkWidget *widget;
653 shell_content = e_shell_view_get_shell_content (shell_view);
655 shell_view_class = E_SHELL_VIEW_GET_CLASS (shell_view);
656 widget = shell_view_class->new_shell_searchbar (shell_view);
657 e_shell_content_set_searchbar (shell_content, widget);
658 gtk_widget_show (widget);
660 return widget;
663 static gchar *
664 shell_view_get_search_name (EShellView *shell_view)
666 EShellSearchbar *searchbar;
667 EFilterRule *rule;
668 const gchar *search_text;
670 rule = e_shell_view_get_search_rule (shell_view);
671 g_return_val_if_fail (E_IS_FILTER_RULE (rule), NULL);
673 searchbar = E_SHELL_SEARCHBAR (shell_view->priv->searchbar);
674 search_text = e_shell_searchbar_get_search_text (searchbar);
676 if (search_text == NULL || *search_text == '\0')
677 search_text = "''";
679 return g_strdup_printf ("%s %s", rule->name, search_text);
682 static void
683 shell_view_toggled (EShellView *shell_view)
685 EShellViewPrivate *priv = shell_view->priv;
686 EShellViewClass *shell_view_class;
687 EShellWindow *shell_window;
688 GtkUIManager *ui_manager;
689 const gchar *basename, *id;
690 gboolean view_is_active;
692 shell_view_class = E_SHELL_VIEW_GET_CLASS (shell_view);
693 shell_window = e_shell_view_get_shell_window (shell_view);
694 ui_manager = e_shell_window_get_ui_manager (shell_window);
695 view_is_active = e_shell_view_is_active (shell_view);
696 basename = shell_view_class->ui_definition;
697 id = shell_view_class->ui_manager_id;
699 if (view_is_active && priv->merge_id == 0) {
700 priv->merge_id = e_load_ui_manager_definition (
701 ui_manager, basename);
702 e_plugin_ui_enable_manager (ui_manager, id);
703 } else if (!view_is_active && priv->merge_id != 0) {
704 e_plugin_ui_disable_manager (ui_manager, id);
705 gtk_ui_manager_remove_ui (ui_manager, priv->merge_id);
706 gtk_ui_manager_ensure_update (ui_manager);
707 priv->merge_id = 0;
710 gtk_ui_manager_ensure_update (ui_manager);
713 static void
714 shell_view_clear_search (EShellView *shell_view)
716 e_shell_view_set_search_rule (shell_view, NULL);
717 e_shell_view_execute_search (shell_view);
720 static void
721 shell_view_custom_search (EShellView *shell_view,
722 EFilterRule *custom_rule)
724 e_shell_view_set_search_rule (shell_view, custom_rule);
725 e_shell_view_execute_search (shell_view);
728 static void
729 shell_view_update_actions (EShellView *shell_view)
731 EShellWindow *shell_window;
732 EFocusTracker *focus_tracker;
733 GtkAction *action;
734 GtkActionGroup *action_group;
736 g_return_if_fail (e_shell_view_is_active (shell_view));
738 shell_window = e_shell_view_get_shell_window (shell_view);
739 focus_tracker = e_shell_window_get_focus_tracker (shell_window);
741 e_focus_tracker_update_actions (focus_tracker);
743 action_group = E_SHELL_WINDOW_ACTION_GROUP_CUSTOM_RULES (shell_window);
744 gtk_action_group_set_sensitive (action_group, TRUE);
746 action = E_SHELL_WINDOW_ACTION_SEARCH_ADVANCED (shell_window);
747 gtk_action_set_sensitive (action, TRUE);
750 static void
751 e_shell_view_class_init (EShellViewClass *class)
753 GObjectClass *object_class;
755 parent_class = g_type_class_peek_parent (class);
756 g_type_class_add_private (class, sizeof (EShellViewPrivate));
758 object_class = G_OBJECT_CLASS (class);
759 object_class->set_property = shell_view_set_property;
760 object_class->get_property = shell_view_get_property;
761 object_class->dispose = shell_view_dispose;
762 object_class->finalize = shell_view_finalize;
763 object_class->constructed = shell_view_constructed;
765 class->search_context_type = E_TYPE_RULE_CONTEXT;
767 /* Default Factories */
768 class->new_shell_content = e_shell_content_new;
769 class->new_shell_sidebar = e_shell_sidebar_new;
770 class->new_shell_taskbar = e_shell_taskbar_new;
771 class->new_shell_searchbar = e_shell_searchbar_new;
773 class->construct_searchbar = shell_view_construct_searchbar;
774 class->get_search_name = shell_view_get_search_name;
776 class->toggled = shell_view_toggled;
777 class->clear_search = shell_view_clear_search;
778 class->custom_search = shell_view_custom_search;
779 class->update_actions = shell_view_update_actions;
782 * EShellView:action:
784 * The #GtkRadioAction registered with #EShellSwitcher.
786 g_object_class_install_property (
787 object_class,
788 PROP_ACTION,
789 g_param_spec_object (
790 "action",
791 "Switcher Action",
792 "The switcher action for this shell view",
793 GTK_TYPE_RADIO_ACTION,
794 G_PARAM_READWRITE |
795 G_PARAM_CONSTRUCT_ONLY |
796 G_PARAM_STATIC_STRINGS));
799 * EShellView:page-num
801 * The #GtkNotebook page number of the shell view.
803 g_object_class_install_property (
804 object_class,
805 PROP_PAGE_NUM,
806 g_param_spec_int (
807 "page-num",
808 "Page Number",
809 "The notebook page number of the shell view",
811 G_MAXINT,
813 G_PARAM_READWRITE |
814 G_PARAM_STATIC_STRINGS));
817 * EShellView:search-rule
819 * Criteria for the current search results.
821 g_object_class_install_property (
822 object_class,
823 PROP_SEARCH_RULE,
824 g_param_spec_object (
825 "search-rule",
826 "Search Rule",
827 "Criteria for the current search results",
828 E_TYPE_FILTER_RULE,
829 G_PARAM_READWRITE |
830 G_PARAM_STATIC_STRINGS));
833 * EShellView:shell-backend
835 * The #EShellBackend for this shell view.
837 g_object_class_install_property (
838 object_class,
839 PROP_SHELL_BACKEND,
840 g_param_spec_object (
841 "shell-backend",
842 "Shell Backend",
843 "The EShellBackend for this shell view",
844 E_TYPE_SHELL_BACKEND,
845 G_PARAM_READABLE |
846 G_PARAM_STATIC_STRINGS));
849 * EShellView:shell-content
851 * The content widget appears in an #EShellWindow<!-- -->'s
852 * right pane.
854 g_object_class_install_property (
855 object_class,
856 PROP_SHELL_CONTENT,
857 g_param_spec_object (
858 "shell-content",
859 "Shell Content Widget",
860 "The content widget appears in "
861 "a shell window's right pane",
862 E_TYPE_SHELL_CONTENT,
863 G_PARAM_READABLE |
864 G_PARAM_STATIC_STRINGS));
867 * EShellView:shell-sidebar
869 * The sidebar widget appears in an #EShellWindow<!-- -->'s
870 * left pane.
872 g_object_class_install_property (
873 object_class,
874 PROP_SHELL_SIDEBAR,
875 g_param_spec_object (
876 "shell-sidebar",
877 "Shell Sidebar Widget",
878 "The sidebar widget appears in "
879 "a shell window's left pane",
880 E_TYPE_SHELL_SIDEBAR,
881 G_PARAM_READABLE |
882 G_PARAM_STATIC_STRINGS));
885 * EShellView:shell-taskbar
887 * The taskbar widget appears at the bottom of an #EShellWindow.
889 g_object_class_install_property (
890 object_class,
891 PROP_SHELL_TASKBAR,
892 g_param_spec_object (
893 "shell-taskbar",
894 "Shell Taskbar Widget",
895 "The taskbar widget appears at "
896 "the bottom of a shell window",
897 E_TYPE_SHELL_TASKBAR,
898 G_PARAM_READABLE |
899 G_PARAM_STATIC_STRINGS));
902 * EShellView:shell-window
904 * The #EShellWindow to which the shell view belongs.
906 g_object_class_install_property (
907 object_class,
908 PROP_SHELL_WINDOW,
909 g_param_spec_object (
910 "shell-window",
911 "Shell Window",
912 "The window to which the shell view belongs",
913 E_TYPE_SHELL_WINDOW,
914 G_PARAM_READWRITE |
915 G_PARAM_CONSTRUCT_ONLY |
916 G_PARAM_STATIC_STRINGS));
919 * EShellView:state-key-file
921 * The #GKeyFile holding widget state data.
923 g_object_class_install_property (
924 object_class,
925 PROP_STATE_KEY_FILE,
926 g_param_spec_pointer (
927 "state-key-file",
928 "State Key File",
929 "The key file holding widget state data",
930 G_PARAM_READABLE |
931 G_PARAM_STATIC_STRINGS));
934 * EShellView:title
936 * The title of the shell view. Also serves as the #EShellWindow
937 * title when the shell view is active.
939 g_object_class_install_property (
940 object_class,
941 PROP_TITLE,
942 g_param_spec_string (
943 "title",
944 "Title",
945 "The title of the shell view",
946 NULL,
947 G_PARAM_READWRITE |
948 G_PARAM_STATIC_STRINGS));
951 * EShellView:view-id
953 * The current #GalView ID.
955 g_object_class_install_property (
956 object_class,
957 PROP_VIEW_ID,
958 g_param_spec_string (
959 "view-id",
960 "Current View ID",
961 "The current GAL view ID",
962 NULL,
963 G_PARAM_READWRITE |
964 G_PARAM_STATIC_STRINGS));
967 * EShellView:view-instance:
969 * The current #GalViewInstance.
971 g_object_class_install_property (
972 object_class,
973 PROP_VIEW_INSTANCE,
974 g_param_spec_object (
975 "view-instance",
976 "View Instance",
977 "The current view instance",
978 GAL_TYPE_VIEW_INSTANCE,
979 G_PARAM_READWRITE));
982 * EShellView::toggled
983 * @shell_view: the #EShellView which emitted the signal
985 * Emitted when @shell_view is activated or deactivated.
986 * Use e_shell_view_is_active() to find out which event has
987 * occurred. The shell view being deactivated is always
988 * notified before the shell view being activated.
990 * By default, #EShellView adds the UI definition file
991 * given in the <structfield>ui_definition</structfield>
992 * field of #EShellViewClass on activation, and removes the
993 * UI definition on deactivation.
995 signals[TOGGLED] = g_signal_new (
996 "toggled",
997 G_OBJECT_CLASS_TYPE (object_class),
998 G_SIGNAL_RUN_FIRST,
999 G_STRUCT_OFFSET (EShellViewClass, toggled),
1000 NULL, NULL,
1001 g_cclosure_marshal_VOID__VOID,
1002 G_TYPE_NONE, 0);
1005 * EShellView::clear-search
1006 * @shell_view: the #EShellView which emitted the signal
1008 * Clears the current search. See e_shell_view_clear_search() for
1009 * details.
1011 signals[CLEAR_SEARCH] = g_signal_new (
1012 "clear-search",
1013 G_OBJECT_CLASS_TYPE (object_class),
1014 G_SIGNAL_RUN_LAST,
1015 G_STRUCT_OFFSET (EShellViewClass, clear_search),
1016 NULL, NULL,
1017 g_cclosure_marshal_VOID__VOID,
1018 G_TYPE_NONE, 0);
1021 * EShellView::custom-search
1022 * @shell_view: the #EShellView which emitted the signal
1023 * @custom_rule: criteria for the custom search
1025 * Emitted when an advanced or saved search is about to be executed.
1026 * See e_shell_view_custom_search() for details.
1028 signals[CUSTOM_SEARCH] = g_signal_new (
1029 "custom-search",
1030 G_OBJECT_CLASS_TYPE (object_class),
1031 G_SIGNAL_RUN_LAST,
1032 G_STRUCT_OFFSET (EShellViewClass, custom_search),
1033 NULL, NULL,
1034 g_cclosure_marshal_VOID__OBJECT,
1035 G_TYPE_NONE, 1,
1036 E_TYPE_FILTER_RULE);
1039 * EShellView::execute-search
1040 * @shell_view: the #EShellView which emitted the signal
1042 * #EShellView subclasses should override the
1043 * <structfield>execute_search</structfield> method in
1044 * #EShellViewClass to execute the current search conditions.
1046 signals[EXECUTE_SEARCH] = g_signal_new (
1047 "execute-search",
1048 G_OBJECT_CLASS_TYPE (object_class),
1049 G_SIGNAL_RUN_FIRST,
1050 G_STRUCT_OFFSET (EShellViewClass, execute_search),
1051 NULL, NULL,
1052 g_cclosure_marshal_VOID__VOID,
1053 G_TYPE_NONE, 0);
1056 * EShellView::update-actions
1057 * @shell_view: the #EShellView which emitted the signal
1059 * #EShellView subclasses should override the
1060 * <structfield>update_actions</structfield> method in
1061 * #EShellViewClass to update sensitivities, labels, or any
1062 * other aspect of the #GtkAction<!-- -->s they have registered.
1064 * Plugins can also connect to this signal to be notified
1065 * when to update their own #GtkAction<!-- -->s.
1067 signals[UPDATE_ACTIONS] = g_signal_new (
1068 "update-actions",
1069 G_OBJECT_CLASS_TYPE (object_class),
1070 G_SIGNAL_RUN_FIRST,
1071 G_STRUCT_OFFSET (EShellViewClass, update_actions),
1072 NULL, NULL,
1073 g_cclosure_marshal_VOID__VOID,
1074 G_TYPE_NONE, 0);
1077 static void
1078 e_shell_view_init (EShellView *shell_view,
1079 EShellViewClass *class)
1081 GtkSizeGroup *size_group;
1083 /* XXX Our use of GInstanceInitFunc's 'class' parameter
1084 * prevents us from using G_DEFINE_ABSTRACT_TYPE. */
1086 if (class->search_context == NULL)
1087 shell_view_init_search_context (class);
1089 if (class->view_collection == NULL)
1090 shell_view_init_view_collection (class);
1092 size_group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
1094 shell_view->priv = E_SHELL_VIEW_GET_PRIVATE (shell_view);
1095 shell_view->priv->main_thread = g_thread_self ();
1096 shell_view->priv->state_key_file = g_key_file_new ();
1097 shell_view->priv->size_group = size_group;
1100 GType
1101 e_shell_view_get_type (void)
1103 static GType type = 0;
1105 if (G_UNLIKELY (type == 0)) {
1106 const GTypeInfo type_info = {
1107 sizeof (EShellViewClass),
1108 (GBaseInitFunc) NULL,
1109 (GBaseFinalizeFunc) NULL,
1110 (GClassInitFunc) e_shell_view_class_init,
1111 (GClassFinalizeFunc) NULL,
1112 NULL, /* class_data */
1113 sizeof (EShellView),
1114 0, /* n_preallocs */
1115 (GInstanceInitFunc) e_shell_view_init,
1116 NULL /* value_table */
1119 const GInterfaceInfo extensible_info = {
1120 (GInterfaceInitFunc) NULL,
1121 (GInterfaceFinalizeFunc) NULL,
1122 NULL /* interface_data */
1125 type = g_type_register_static (
1126 G_TYPE_OBJECT, "EShellView",
1127 &type_info, G_TYPE_FLAG_ABSTRACT);
1129 g_type_add_interface_static (
1130 type, E_TYPE_EXTENSIBLE, &extensible_info);
1133 return type;
1137 * e_shell_view_get_name:
1138 * @shell_view: an #EShellView
1140 * Returns the view name for @shell_view, which is also the name of
1141 * the corresponding #EShellBackend (see the <structfield>name</structfield>
1142 * field in #EShellBackendInfo).
1144 * Returns: the view name for @shell_view
1146 const gchar *
1147 e_shell_view_get_name (EShellView *shell_view)
1149 GtkAction *action;
1151 g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
1153 action = e_shell_view_get_action (shell_view);
1155 /* Switcher actions have a secret "view-name" data value.
1156 * This gets set in e_shell_window_create_switcher_actions(). */
1157 return g_object_get_data (G_OBJECT (action), "view-name");
1161 * e_shell_view_get_action:
1162 * @shell_view: an #EShellView
1164 * Returns the switcher action for @shell_view.
1166 * An #EShellWindow creates a #GtkRadioAction for each registered subclass
1167 * of #EShellView. This action gets passed to the #EShellSwitcher, which
1168 * displays a button that proxies the action. The icon at the top of the
1169 * sidebar also proxies the action. When @shell_view is active, the
1170 * action's icon becomes the #EShellWindow icon.
1172 * Returns: the switcher action for @shell_view
1174 GtkAction *
1175 e_shell_view_get_action (EShellView *shell_view)
1177 g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
1179 return shell_view->priv->action;
1183 * e_shell_view_get_title:
1184 * @shell_view: an #EShellView
1186 * Returns the title for @shell_view. When @shell_view is active, the
1187 * shell view's title becomes the #EShellWindow title.
1189 * Returns: the title for @shell_view
1191 const gchar *
1192 e_shell_view_get_title (EShellView *shell_view)
1194 g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
1196 return shell_view->priv->title;
1200 * e_shell_view_set_title:
1201 * @shell_view: an #EShellView
1202 * @title: a title for @shell_view
1204 * Sets the title for @shell_view. When @shell_view is active, the
1205 * shell view's title becomes the #EShellWindow title.
1207 void
1208 e_shell_view_set_title (EShellView *shell_view,
1209 const gchar *title)
1211 g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
1213 if (title == NULL)
1214 title = E_SHELL_VIEW_GET_CLASS (shell_view)->label;
1216 if (g_strcmp0 (shell_view->priv->title, title) == 0)
1217 return;
1219 g_free (shell_view->priv->title);
1220 shell_view->priv->title = g_strdup (title);
1222 g_object_notify (G_OBJECT (shell_view), "title");
1226 * e_shell_view_get_view_id:
1227 * @shell_view: an #EShellView
1229 * Returns the ID of the currently selected #GalView.
1231 * #EShellView subclasses are responsible for keeping this property in
1232 * sync with their #GalViewInstance. #EShellView itself just provides
1233 * a place to store the view ID, and emits a #GObject::notify signal
1234 * when the property changes.
1236 * Returns: the ID of the current #GalView
1238 const gchar *
1239 e_shell_view_get_view_id (EShellView *shell_view)
1241 g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
1243 return shell_view->priv->view_id;
1247 * e_shell_view_set_view_id:
1248 * @shell_view: an #EShellView
1249 * @view_id: a #GalView ID
1251 * Selects the #GalView whose ID is equal to @view_id.
1253 * #EShellView subclasses are responsible for keeping this property in
1254 * sync with their #GalViewInstance. #EShellView itself just provides
1255 * a place to store the view ID, and emits a #GObject::notify signal
1256 * when the property changes.
1258 void
1259 e_shell_view_set_view_id (EShellView *shell_view,
1260 const gchar *view_id)
1262 g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
1264 if (g_strcmp0 (shell_view->priv->view_id, view_id) == 0)
1265 return;
1267 g_free (shell_view->priv->view_id);
1268 shell_view->priv->view_id = g_strdup (view_id);
1270 g_object_notify (G_OBJECT (shell_view), "view-id");
1274 * e_shell_view_new_view_instance:
1275 * @shell_view: an #EShellView
1276 * @instance_id: a name for the #GalViewInstance
1278 * Convenience function creates a new #GalViewInstance from the
1279 * #GalViewCollection in @shell_view's #EShellViewClass.
1281 * Returns: a new #GalViewInstance
1283 GalViewInstance *
1284 e_shell_view_new_view_instance (EShellView *shell_view,
1285 const gchar *instance_id)
1287 EShellViewClass *class;
1288 GalViewCollection *view_collection;
1290 g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
1292 class = E_SHELL_VIEW_GET_CLASS (shell_view);
1294 view_collection = class->view_collection;
1296 return gal_view_instance_new (view_collection, instance_id);
1300 * e_shell_view_get_view_instance:
1301 * @shell_view: an #EShellView
1303 * Returns the current #GalViewInstance for @shell_view.
1305 * #EShellView subclasses are responsible for creating and configuring a
1306 * #GalViewInstance and handing it off so the @shell_view can monitor it
1307 * and perform common actions on it.
1309 * Returns: a #GalViewInstance, or %NULL
1311 GalViewInstance *
1312 e_shell_view_get_view_instance (EShellView *shell_view)
1314 g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
1316 return shell_view->priv->view_instance;
1320 * e_shell_view_set_view_instance:
1321 * @shell_view: an #EShellView
1322 * @view_instance: a #GalViewInstance, or %NULL
1324 * Sets the current #GalViewInstance for @shell_view.
1326 * #EShellView subclasses are responsible for creating and configuring a
1327 * #GalViewInstance and handing it off so the @shell_view can monitor it
1328 * and perform common actions on it.
1330 void
1331 e_shell_view_set_view_instance (EShellView *shell_view,
1332 GalViewInstance *view_instance)
1334 g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
1336 if (view_instance != NULL) {
1337 g_return_if_fail (GAL_IS_VIEW_INSTANCE (view_instance));
1338 g_object_ref (view_instance);
1341 if (shell_view->priv->view_instance_changed_handler_id > 0) {
1342 g_signal_handler_disconnect (
1343 shell_view->priv->view_instance,
1344 shell_view->priv->view_instance_changed_handler_id);
1345 shell_view->priv->view_instance_changed_handler_id = 0;
1348 if (shell_view->priv->view_instance_loaded_handler_id > 0) {
1349 g_signal_handler_disconnect (
1350 shell_view->priv->view_instance,
1351 shell_view->priv->view_instance_loaded_handler_id);
1352 shell_view->priv->view_instance_loaded_handler_id = 0;
1355 g_clear_object (&shell_view->priv->view_instance);
1357 shell_view->priv->view_instance = view_instance;
1359 if (view_instance != NULL) {
1360 gulong handler_id;
1362 handler_id = g_signal_connect_swapped (
1363 view_instance, "changed",
1364 G_CALLBACK (shell_view_update_view_id), shell_view);
1365 shell_view->priv->view_instance_changed_handler_id = handler_id;
1367 handler_id = g_signal_connect_swapped (
1368 view_instance, "loaded",
1369 G_CALLBACK (shell_view_update_view_id), shell_view);
1370 shell_view->priv->view_instance_loaded_handler_id = handler_id;
1373 g_object_notify (G_OBJECT (shell_view), "view-instance");
1377 * e_shell_view_get_shell_window:
1378 * @shell_view: an #EShellView
1380 * Returns the #EShellWindow to which @shell_view belongs.
1382 * Returns: the #EShellWindow to which @shell_view belongs
1384 EShellWindow *
1385 e_shell_view_get_shell_window (EShellView *shell_view)
1387 g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
1389 return E_SHELL_WINDOW (shell_view->priv->shell_window);
1393 * e_shell_view_is_active:
1394 * @shell_view: an #EShellView
1396 * Returns %TRUE if @shell_view is active. That is, if it's currently
1397 * visible in its #EShellWindow. An #EShellWindow can only display one
1398 * shell view at a time.
1400 * Technically this just checks the #GtkToggleAction:active property of
1401 * the shell view's switcher action. See e_shell_view_get_action().
1403 * Returns: %TRUE if @shell_view is active
1405 gboolean
1406 e_shell_view_is_active (EShellView *shell_view)
1408 GtkAction *action;
1410 g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), FALSE);
1412 action = e_shell_view_get_action (shell_view);
1414 return gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
1418 * e_shell_view_get_page_num:
1419 * @shell_view: an #EShellView
1421 * This function is only interesting to #EShellWindow. It returns the
1422 * #GtkNotebook page number for @shell_view. The rest of the application
1423 * should have no need for this.
1425 * Returns: the notebook page number for @shell_view
1427 gint
1428 e_shell_view_get_page_num (EShellView *shell_view)
1430 g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), -1);
1432 return shell_view->priv->page_num;
1436 * e_shell_view_set_page_num:
1437 * @shell_view: an #EShellView
1438 * @page_num: a notebook page number
1440 * This function is only interesting to #EShellWindow. It sets the
1441 * #GtkNotebook page number for @shell_view. The rest of the application
1442 * must never call this because it could mess up shell view switching.
1444 void
1445 e_shell_view_set_page_num (EShellView *shell_view,
1446 gint page_num)
1448 g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
1450 if (shell_view->priv->page_num == page_num)
1451 return;
1453 shell_view->priv->page_num = page_num;
1455 g_object_notify (G_OBJECT (shell_view), "page-num");
1459 * e_shell_view_get_search_name:
1460 * @shell_view: an #EShellView
1462 * Returns a newly-allocated string containing a suitable name for the
1463 * current search criteria. This is used as the suggested name in the
1464 * Save Search dialog. Free the returned string with g_free().
1466 * Returns: a name for the current search criteria
1468 gchar *
1469 e_shell_view_get_search_name (EShellView *shell_view)
1471 EShellViewClass *class;
1473 g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
1475 class = E_SHELL_VIEW_GET_CLASS (shell_view);
1476 g_return_val_if_fail (class->get_search_name != NULL, NULL);
1478 return class->get_search_name (shell_view);
1482 * e_shell_view_get_search_rule:
1483 * @shell_view: an #EShellView
1485 * Returns the search criteria used to generate the current search results.
1487 * Returns: the current search criteria
1489 EFilterRule *
1490 e_shell_view_get_search_rule (EShellView *shell_view)
1492 g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
1494 return shell_view->priv->search_rule;
1498 * e_shell_view_get_searchbar:
1499 * @shell_view: an #EShellView
1501 * Returns the searchbar widget for @shell_view.
1503 * Returns: the searchbar widget for @shell_view
1505 GtkWidget *
1506 e_shell_view_get_searchbar (EShellView *shell_view)
1508 g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
1510 return shell_view->priv->searchbar;
1514 * e_shell_view_set_search_rule:
1515 * @shell_view: an #EShellView
1516 * @search_rule: an #EFilterRule
1518 * Sets the search criteria used to generate the current search results.
1519 * Note that this will not trigger a search. e_shell_view_execute_search()
1520 * must be called explicitly.
1522 void
1523 e_shell_view_set_search_rule (EShellView *shell_view,
1524 EFilterRule *search_rule)
1526 g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
1528 if (shell_view->priv->search_rule == search_rule)
1529 return;
1531 if (search_rule != NULL) {
1532 g_return_if_fail (E_IS_FILTER_RULE (search_rule));
1533 g_object_ref (search_rule);
1536 if (shell_view->priv->search_rule != NULL)
1537 g_object_unref (shell_view->priv->search_rule);
1539 shell_view->priv->search_rule = search_rule;
1541 g_object_notify (G_OBJECT (shell_view), "search-rule");
1545 * e_shell_view_get_search_query:
1546 * @shell_view: an #EShellView
1548 * Converts the #EShellView:search-rule property to a newly-allocated
1549 * S-expression string. If the #EShellView:search-rule property is %NULL
1550 * the function returns %NULL.
1552 * Returns: an S-expression string, or %NULL
1554 gchar *
1555 e_shell_view_get_search_query (EShellView *shell_view)
1557 EFilterRule *rule;
1558 GString *string;
1560 g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
1562 rule = e_shell_view_get_search_rule (shell_view);
1563 if (rule == NULL)
1564 return NULL;
1566 string = g_string_sized_new (1024);
1567 e_filter_rule_build_code (rule, string);
1569 return g_string_free (string, FALSE);
1573 * e_shell_view_get_size_group:
1574 * @shell_view: an #EShellView
1576 * Returns a #GtkSizeGroup that #EShellContent and #EShellSidebar use
1577 * to keep the search bar and sidebar banner vertically aligned. The
1578 * rest of the application should have no need for this.
1580 * Note, this is only available during #EShellView construction.
1582 * Returns: a #GtkSizeGroup for internal use
1584 GtkSizeGroup *
1585 e_shell_view_get_size_group (EShellView *shell_view)
1587 g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
1589 return shell_view->priv->size_group;
1593 * e_shell_view_get_shell_backend:
1594 * @shell_view: an #EShellView
1596 * Returns the corresponding #EShellBackend for @shell_view.
1598 * Returns: the corresponding #EShellBackend for @shell_view
1600 EShellBackend *
1601 e_shell_view_get_shell_backend (EShellView *shell_view)
1603 EShellViewClass *class;
1605 g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
1607 class = E_SHELL_VIEW_GET_CLASS (shell_view);
1608 g_return_val_if_fail (class->shell_backend != NULL, NULL);
1610 return class->shell_backend;
1614 * e_shell_view_get_shell_content:
1615 * @shell_view: an #EShellView
1617 * Returns the #EShellContent instance for @shell_view.
1619 * By default, #EShellView creates a plain #EShellContent during
1620 * initialization. But #EShellView subclasses can override the
1621 * <structfield>new_shell_content</structfield> factory method
1622 * in #EShellViewClass to create a custom #EShellContent.
1624 * Returns: the #EShellContent instance for @shell_view
1626 EShellContent *
1627 e_shell_view_get_shell_content (EShellView *shell_view)
1629 g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
1631 return E_SHELL_CONTENT (shell_view->priv->shell_content);
1635 * e_shell_view_get_shell_sidebar:
1636 * @shell_view: an #EShellView
1638 * Returns the #EShellSidebar instance for @shell_view.
1640 * By default, #EShellView creates a plain #EShellSidebar during
1641 * initialization. But #EShellView subclasses can override the
1642 * <structfield>new_shell_sidebar</structfield> factory method
1643 * in #EShellViewClass to create a custom #EShellSidebar.
1645 * Returns: the #EShellSidebar instance for @shell_view
1647 EShellSidebar *
1648 e_shell_view_get_shell_sidebar (EShellView *shell_view)
1650 g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
1652 return E_SHELL_SIDEBAR (shell_view->priv->shell_sidebar);
1656 * e_shell_view_get_shell_taskbar:
1657 * @shell_view: an #EShellView
1659 * Returns the #EShellTaskbar instance for @shell_view.
1661 * By default, #EShellView creates a plain #EShellTaskbar during
1662 * initialization. But #EShellView subclasses can override the
1663 * <structfield>new_shell_taskbar</structfield> factory method
1664 * in #EShellViewClass to create a custom #EShellTaskbar.
1666 * Returns: the #EShellTaskbar instance for @shell_view
1668 EShellTaskbar *
1669 e_shell_view_get_shell_taskbar (EShellView *shell_view)
1671 g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
1673 return E_SHELL_TASKBAR (shell_view->priv->shell_taskbar);
1677 * e_shell_view_get_state_key_file:
1678 * @shell_view: an #EShellView
1680 * Returns the #GKeyFile holding widget state data for @shell_view.
1682 * Returns: the #GKeyFile for @shell_view
1684 GKeyFile *
1685 e_shell_view_get_state_key_file (EShellView *shell_view)
1687 g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
1689 return shell_view->priv->state_key_file;
1693 * e_shell_view_set_state_dirty:
1694 * @shell_view: an #EShellView
1696 * Marks the widget state data as modified (or "dirty") and schedules it
1697 * to be saved to disk after a short delay. The delay caps the frequency
1698 * of saving to disk.
1700 void
1701 e_shell_view_set_state_dirty (EShellView *shell_view)
1703 guint source_id;
1705 g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
1707 /* If a timeout is already scheduled, do nothing. */
1708 if (shell_view->priv->state_save_timeout_id > 0)
1709 return;
1711 source_id = e_named_timeout_add_seconds (
1712 STATE_SAVE_TIMEOUT_SECONDS,
1713 shell_view_state_timeout_cb, shell_view);
1715 shell_view->priv->state_save_timeout_id = source_id;
1719 * e_shell_view_clear_search:
1720 * @shell_view: an #EShellView
1722 * Emits the #EShellView::clear-search signal.
1724 * The default method sets the #EShellView:search-rule property to
1725 * %NULL and then emits the #EShellView::execute-search signal.
1727 void
1728 e_shell_view_clear_search (EShellView *shell_view)
1730 g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
1732 g_signal_emit (shell_view, signals[CLEAR_SEARCH], 0);
1736 * e_shell_view_custom_search:
1737 * @shell_view: an #EShellView
1738 * @custom_rule: an #EFilterRule
1740 * Emits the #EShellView::custom-search signal to indicate an advanced
1741 * or saved search is about to be executed.
1743 * The default method sets the #EShellView:search-rule property to
1744 * @custom_rule and then emits the #EShellView::execute-search signal.
1746 void
1747 e_shell_view_custom_search (EShellView *shell_view,
1748 EFilterRule *custom_rule)
1750 g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
1751 g_return_if_fail (E_IS_FILTER_RULE (custom_rule));
1753 g_signal_emit (shell_view, signals[CUSTOM_SEARCH], 0, custom_rule);
1757 * e_shell_view_execute_search:
1758 * @shell_view: an #EShellView
1760 * Emits the #EShellView::execute-search signal.
1762 * #EShellView subclasses should implement the
1763 * <structfield>execute_search</structfield> method in #EShellViewClass
1764 * to execute a search based on the current search conditions.
1766 void
1767 e_shell_view_execute_search (EShellView *shell_view)
1769 g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
1771 if (!e_shell_view_is_execute_search_blocked (shell_view))
1772 g_signal_emit (shell_view, signals[EXECUTE_SEARCH], 0);
1776 * e_shell_view_block_execute_search:
1777 * @shell_view: an #EShellView
1779 * Blocks e_shell_view_execute_search() in a way it does nothing.
1780 * Pair function for this is e_shell_view_unblock_execute_search().
1782 void
1783 e_shell_view_block_execute_search (EShellView *shell_view)
1785 g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
1786 g_return_if_fail (shell_view->priv->execute_search_blocked + 1 != 0);
1788 shell_view->priv->execute_search_blocked++;
1792 * e_shell_view_unblock_execute_search:
1793 * @shell_view: an #EShellView
1795 * Unblocks previously blocked e_shell_view_execute_search() with
1796 * function e_shell_view_block_execute_search().
1798 void
1799 e_shell_view_unblock_execute_search (EShellView *shell_view)
1801 g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
1802 g_return_if_fail (shell_view->priv->execute_search_blocked > 0);
1804 shell_view->priv->execute_search_blocked--;
1808 * e_shell_view_is_execute_search_blocked:
1809 * @shell_view: an #EShellView
1811 * Returns whether e_shell_view_execute_search() is blocked as a result
1812 * of previous e_shell_view_block_execute_search() calls.
1814 * Returns: %TRUE if e_shell_view_execute_search() is blocked
1816 gboolean
1817 e_shell_view_is_execute_search_blocked (EShellView *shell_view)
1819 g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), FALSE);
1821 return shell_view->priv->execute_search_blocked > 0;
1825 * e_shell_view_update_actions:
1826 * @shell_view: an #EShellView
1828 * Emits the #EShellView::update-actions signal.
1830 * #EShellView subclasses should implement the
1831 * <structfield>update_actions</structfield> method in #EShellViewClass
1832 * to update the various #GtkAction<!-- -->s based on the current
1833 * #EShellSidebar and #EShellContent selections. The
1834 * #EShellView::update-actions signal is typically emitted just before
1835 * showing a popup menu or just after the user selects an item in the
1836 * shell view.
1838 void
1839 e_shell_view_update_actions (EShellView *shell_view)
1841 g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
1843 if (e_shell_view_is_active (shell_view)) {
1844 if (shell_view->priv->update_actions_idle_id > 0) {
1845 g_source_remove (shell_view->priv->update_actions_idle_id);
1846 shell_view->priv->update_actions_idle_id = 0;
1849 g_signal_emit (shell_view, signals[UPDATE_ACTIONS], 0);
1853 static gboolean
1854 shell_view_call_update_actions_idle (gpointer user_data)
1856 EShellView *shell_view = user_data;
1858 g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), FALSE);
1860 shell_view->priv->update_actions_idle_id = 0;
1861 e_shell_view_update_actions (shell_view);
1863 return FALSE;
1867 * e_shell_view_update_actions_in_idle:
1868 * @shell_view: an #EShellView
1870 * Schedules e_shell_view_update_actions() call on idle.
1872 * Since: 3.10
1874 void
1875 e_shell_view_update_actions_in_idle (EShellView *shell_view)
1877 g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
1879 if (!e_shell_view_is_active (shell_view))
1880 return;
1882 if (shell_view->priv->update_actions_idle_id == 0)
1883 shell_view->priv->update_actions_idle_id = g_idle_add (
1884 shell_view_call_update_actions_idle, shell_view);
1887 static void
1888 e_shell_view_popup_menu_deactivate (GtkMenu *popup_menu,
1889 gpointer user_data)
1891 g_return_if_fail (GTK_IS_MENU (popup_menu));
1893 g_signal_handlers_disconnect_by_func (popup_menu, e_shell_view_popup_menu_deactivate, user_data);
1894 gtk_menu_detach (popup_menu);
1898 * e_shell_view_show_popup_menu:
1899 * @shell_view: an #EShellView
1900 * @widget_path: path in the UI definition
1901 * @button_event: a #GdkEvent, or %NULL
1903 * Displays a context-sensitive (or "popup") menu that is described in
1904 * the UI definition loaded into @shell_view<!-- -->'s user interface
1905 * manager. The menu will be shown at the current mouse cursor position.
1907 * The #EShellView::update-actions signal is emitted just prior to
1908 * showing the menu to give @shell_view and any plugins that extend
1909 * @shell_view a chance to update the menu's actions.
1911 * Returns: the popup menu being displayed
1913 GtkWidget *
1914 e_shell_view_show_popup_menu (EShellView *shell_view,
1915 const gchar *widget_path,
1916 GdkEvent *button_event)
1918 EShellWindow *shell_window;
1919 GtkWidget *menu;
1921 g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
1923 e_shell_view_update_actions (shell_view);
1925 shell_window = e_shell_view_get_shell_window (shell_view);
1926 menu = e_shell_window_get_managed_widget (shell_window, widget_path);
1927 g_return_val_if_fail (GTK_IS_MENU (menu), NULL);
1929 if (!gtk_menu_get_attach_widget (GTK_MENU (menu))) {
1930 gtk_menu_attach_to_widget (GTK_MENU (menu),
1931 GTK_WIDGET (shell_window),
1932 NULL);
1934 g_signal_connect (menu, "deactivate", G_CALLBACK (e_shell_view_popup_menu_deactivate), NULL);
1937 gtk_menu_popup_at_pointer (GTK_MENU (menu), button_event);
1939 return menu;
1943 * e_shell_view_write_source:
1944 * @shell_view: an #EShellView
1945 * @source: an #ESource
1947 * Submits the current contents of @source to the D-Bus service to be
1948 * written to disk and broadcast to other clients.
1950 * This function does not block: @shell_view will dispatch the operation
1951 * asynchronously and handle any errors.
1953 void
1954 e_shell_view_write_source (EShellView *shell_view,
1955 ESource *source)
1957 EActivity *activity;
1958 EAlertSink *alert_sink;
1959 EShellBackend *shell_backend;
1960 EShellContent *shell_content;
1962 g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
1963 g_return_if_fail (E_IS_SOURCE (source));
1965 shell_backend = e_shell_view_get_shell_backend (shell_view);
1966 shell_content = e_shell_view_get_shell_content (shell_view);
1968 alert_sink = E_ALERT_SINK (shell_content);
1969 activity = e_source_util_write (source, alert_sink);
1970 e_shell_backend_add_activity (shell_backend, activity);
1974 * e_shell_view_remove_source:
1975 * @shell_view: an #EShellView
1976 * @source: the #ESource to be removed
1978 * Requests the D-Bus service to delete the key files for @source and all of
1979 * its descendants and broadcast their removal to all clients.
1981 * This function does not block: @shell_view will dispatch the operation
1982 * asynchronously and handle any errors.
1984 void
1985 e_shell_view_remove_source (EShellView *shell_view,
1986 ESource *source)
1988 EActivity *activity;
1989 EAlertSink *alert_sink;
1990 EShellBackend *shell_backend;
1991 EShellContent *shell_content;
1993 g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
1994 g_return_if_fail (E_IS_SOURCE (source));
1996 shell_backend = e_shell_view_get_shell_backend (shell_view);
1997 shell_content = e_shell_view_get_shell_content (shell_view);
1999 alert_sink = E_ALERT_SINK (shell_content);
2000 activity = e_source_util_remove (source, alert_sink);
2001 e_shell_backend_add_activity (shell_backend, activity);
2005 * e_shell_view_remote_delete_source:
2006 * @shell_view: an #EShellView
2007 * @source: an #ESource
2009 * Deletes the resource represented by @source from a remote server.
2010 * The @source must be #ESource:remote-deletable. This will also delete
2011 * the key file for @source and broadcast its removal to all clients,
2012 * similar to e_shell_view_remove_source().
2014 * This function does not block; @shell_view will dispatch the operation
2015 * asynchronously and handle any errors.
2017 void
2018 e_shell_view_remote_delete_source (EShellView *shell_view,
2019 ESource *source)
2021 EActivity *activity;
2022 EAlertSink *alert_sink;
2023 EShellBackend *shell_backend;
2024 EShellContent *shell_content;
2026 g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
2027 g_return_if_fail (E_IS_SOURCE (source));
2029 shell_backend = e_shell_view_get_shell_backend (shell_view);
2030 shell_content = e_shell_view_get_shell_content (shell_view);
2032 alert_sink = E_ALERT_SINK (shell_content);
2033 activity = e_source_util_remote_delete (source, alert_sink);
2034 e_shell_backend_add_activity (shell_backend, activity);
2038 * e_shell_view_submit_thread_job:
2039 * @shell_view: an #EShellView instance
2040 * @description: user-friendly description of the job, to be shown in UI
2041 * @alert_ident: in case of an error, this alert identificator is used
2042 * for EAlert construction
2043 * @alert_arg_0: (allow-none): in case of an error, use this string as
2044 * the first argument to the EAlert construction; the second argument
2045 * is the actual error message; can be #NULL, in which case only
2046 * the error message is passed to the EAlert construction
2047 * @func: function to be run in a dedicated thread
2048 * @user_data: (allow-none): custom data passed into @func; can be #NULL
2049 * @free_user_data: (allow-none): function to be called on @user_data,
2050 * when the job is over; can be #NULL
2052 * Runs the @func in a dedicated thread. Any error is propagated to UI.
2053 * The cancellable passed into the @func is a #CamelOperation, thus
2054 * the caller can overwrite progress and description message on it.
2056 * Returns: (transfer full): Newly created #EActivity on success.
2057 * The caller is responsible to g_object_unref() it when done with it.
2059 * Note: The @free_user_data, if set, is called in the main thread.
2061 * Note: This function can be called only from the main thread.
2063 EActivity *
2064 e_shell_view_submit_thread_job (EShellView *shell_view,
2065 const gchar *description,
2066 const gchar *alert_ident,
2067 const gchar *alert_arg_0,
2068 EAlertSinkThreadJobFunc func,
2069 gpointer user_data,
2070 GDestroyNotify free_user_data)
2072 EShellBackend *shell_backend;
2073 EShellContent *shell_content;
2074 EActivity *activity;
2075 EAlertSink *alert_sink;
2077 g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
2078 g_return_val_if_fail (description != NULL, NULL);
2079 g_return_val_if_fail (func != NULL, NULL);
2080 g_return_val_if_fail (g_thread_self () == shell_view->priv->main_thread, NULL);
2082 shell_backend = e_shell_view_get_shell_backend (shell_view);
2083 shell_content = e_shell_view_get_shell_content (shell_view);
2085 alert_sink = E_ALERT_SINK (shell_content);
2087 activity = e_alert_sink_submit_thread_job (
2088 alert_sink,
2089 description,
2090 alert_ident,
2091 alert_arg_0,
2092 func,
2093 user_data,
2094 free_user_data);
2096 if (activity)
2097 e_shell_backend_add_activity (shell_backend, activity);
2099 return activity;