Updated Spanish translation
[evolution.git] / shell / e-shell-window-private.c
blobf9e21b1bdf0ca0a9f217d294bf28281cb4adde83
1 /*
2 * e-shell-window-private.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 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
25 #include "e-shell-window-private.h"
27 static void
28 shell_window_save_switcher_style_cb (GtkRadioAction *action,
29 GtkRadioAction *current,
30 EShellWindow *shell_window)
32 GSettings *settings;
33 GtkToolbarStyle style;
34 const gchar *string;
36 settings = e_util_ref_settings ("org.gnome.evolution.shell");
38 style = gtk_radio_action_get_current_value (action);
40 switch (style) {
41 case GTK_TOOLBAR_ICONS:
42 string = "icons";
43 break;
45 case GTK_TOOLBAR_TEXT:
46 string = "text";
47 break;
49 case GTK_TOOLBAR_BOTH:
50 case GTK_TOOLBAR_BOTH_HORIZ:
51 string = "both";
52 break;
54 default:
55 string = "toolbar";
56 break;
59 g_settings_set_string (settings, "buttons-style", string);
60 g_object_unref (settings);
63 static void
64 shell_window_init_switcher_style (EShellWindow *shell_window)
66 GtkAction *action;
67 GSettings *settings;
68 GtkToolbarStyle style;
69 gchar *string;
71 settings = e_util_ref_settings ("org.gnome.evolution.shell");
73 action = ACTION (SWITCHER_STYLE_ICONS);
74 string = g_settings_get_string (settings, "buttons-style");
75 g_object_unref (settings);
77 if (string != NULL) {
78 if (strcmp (string, "icons") == 0)
79 style = GTK_TOOLBAR_ICONS;
80 else if (strcmp (string, "text") == 0)
81 style = GTK_TOOLBAR_TEXT;
82 else if (strcmp (string, "both") == 0)
83 style = GTK_TOOLBAR_BOTH_HORIZ;
84 else
85 style = -1;
87 gtk_radio_action_set_current_value (
88 GTK_RADIO_ACTION (action), style);
90 g_free (string);
93 g_signal_connect (
94 action, "changed",
95 G_CALLBACK (shell_window_save_switcher_style_cb),
96 shell_window);
99 static void
100 shell_window_menu_item_select_cb (EShellWindow *shell_window,
101 GtkWidget *widget)
103 GtkAction *action;
104 GtkActivatable *activatable;
105 GtkLabel *label;
106 const gchar *tooltip;
108 activatable = GTK_ACTIVATABLE (widget);
109 action = gtk_activatable_get_related_action (activatable);
110 tooltip = gtk_action_get_tooltip (action);
112 if (tooltip == NULL)
113 return;
115 label = GTK_LABEL (shell_window->priv->tooltip_label);
116 gtk_label_set_text (label, tooltip);
118 gtk_widget_show (shell_window->priv->tooltip_label);
119 gtk_widget_hide (shell_window->priv->status_notebook);
122 static void
123 shell_window_menu_item_deselect_cb (EShellWindow *shell_window)
125 gtk_widget_hide (shell_window->priv->tooltip_label);
126 gtk_widget_show (shell_window->priv->status_notebook);
129 static void
130 shell_window_connect_proxy_cb (EShellWindow *shell_window,
131 GtkAction *action,
132 GtkWidget *proxy)
134 if (!GTK_IS_MENU_ITEM (proxy))
135 return;
137 g_signal_connect_swapped (
138 proxy, "select",
139 G_CALLBACK (shell_window_menu_item_select_cb),
140 shell_window);
142 g_signal_connect_swapped (
143 proxy, "deselect",
144 G_CALLBACK (shell_window_menu_item_deselect_cb),
145 shell_window);
148 static GtkWidget *
149 shell_window_construct_menubar (EShellWindow *shell_window)
151 EShellWindowClass *class;
153 class = E_SHELL_WINDOW_GET_CLASS (shell_window);
154 if (class->construct_menubar == NULL)
155 return NULL;
157 return class->construct_menubar (shell_window);
160 static GtkWidget *
161 shell_window_construct_toolbar (EShellWindow *shell_window)
163 EShellWindowClass *class;
165 class = E_SHELL_WINDOW_GET_CLASS (shell_window);
166 if (class->construct_toolbar == NULL)
167 return NULL;
169 return class->construct_toolbar (shell_window);
172 static GtkWidget *
173 shell_window_construct_sidebar (EShellWindow *shell_window)
175 EShellWindowClass *class;
177 class = E_SHELL_WINDOW_GET_CLASS (shell_window);
178 if (class->construct_sidebar == NULL)
179 return NULL;
181 return class->construct_sidebar (shell_window);
184 static GtkWidget *
185 shell_window_construct_content (EShellWindow *shell_window)
187 EShellWindowClass *class;
189 class = E_SHELL_WINDOW_GET_CLASS (shell_window);
190 if (class->construct_content == NULL)
191 return NULL;
193 return class->construct_content (shell_window);
196 static GtkWidget *
197 shell_window_construct_taskbar (EShellWindow *shell_window)
199 EShellWindowClass *class;
201 class = E_SHELL_WINDOW_GET_CLASS (shell_window);
202 if (class->construct_taskbar == NULL)
203 return NULL;
205 return class->construct_taskbar (shell_window);
208 void
209 e_shell_window_private_init (EShellWindow *shell_window)
211 EShellWindowPrivate *priv = shell_window->priv;
212 GHashTable *loaded_views;
213 GArray *signal_handler_ids;
215 loaded_views = g_hash_table_new_full (
216 g_str_hash, g_str_equal,
217 (GDestroyNotify) g_free,
218 (GDestroyNotify) g_object_unref);
220 signal_handler_ids = g_array_new (FALSE, FALSE, sizeof (gulong));
222 priv->ui_manager = gtk_ui_manager_new ();
223 priv->loaded_views = loaded_views;
224 priv->signal_handler_ids = signal_handler_ids;
226 /* XXX This kind of violates the shell window being unaware
227 * of specific shell views, but we need a sane fallback. */
228 priv->active_view = "mail";
230 e_shell_window_add_action_group (shell_window, "shell");
231 e_shell_window_add_action_group (shell_window, "gal-view");
232 e_shell_window_add_action_group (shell_window, "new-item");
233 e_shell_window_add_action_group (shell_window, "new-source");
234 e_shell_window_add_action_group (shell_window, "custom-rules");
235 e_shell_window_add_action_group (shell_window, "switcher");
236 e_shell_window_add_action_group (shell_window, "new-window");
237 e_shell_window_add_action_group (shell_window, "lockdown-application-handlers");
238 e_shell_window_add_action_group (shell_window, "lockdown-printing");
239 e_shell_window_add_action_group (shell_window, "lockdown-print-setup");
240 e_shell_window_add_action_group (shell_window, "lockdown-save-to-disk");
242 gtk_window_set_title (GTK_WINDOW (shell_window), _("Evolution"));
244 g_signal_connect_swapped (
245 priv->ui_manager, "connect-proxy",
246 G_CALLBACK (shell_window_connect_proxy_cb), shell_window);
249 static gboolean
250 shell_window_check_is_main_instance (GtkApplication *application,
251 GtkWindow *window)
253 GList *windows, *link;
255 g_return_val_if_fail (GTK_IS_APPLICATION (application), FALSE);
256 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
258 windows = gtk_application_get_windows (application);
259 for (link = windows; link; link = g_list_next (link)) {
260 GtkWindow *wnd = link->data;
262 if (E_IS_SHELL_WINDOW (wnd) && wnd != window)
263 return FALSE;
266 return TRUE;
269 void
270 e_shell_window_private_constructed (EShellWindow *shell_window)
272 EShellWindowPrivate *priv = shell_window->priv;
273 EShell *shell;
274 GtkAction *action;
275 GtkAccelGroup *accel_group;
276 GtkUIManager *ui_manager;
277 GtkBox *box;
278 GtkPaned *paned;
279 GtkWidget *widget;
280 GtkWindow *window;
281 guint merge_id;
282 const gchar *id;
283 GSettings *settings;
285 #ifndef G_OS_WIN32
286 GtkActionGroup *action_group;
287 #endif
289 window = GTK_WINDOW (shell_window);
291 shell = e_shell_window_get_shell (shell_window);
292 shell_window->priv->is_main_instance = shell_window_check_is_main_instance (GTK_APPLICATION (shell), window);
294 ui_manager = e_shell_window_get_ui_manager (shell_window);
296 /* Defer actions and menu merging until we have set express mode */
298 e_shell_window_actions_init (shell_window);
300 accel_group = gtk_ui_manager_get_accel_group (ui_manager);
301 gtk_window_add_accel_group (GTK_WINDOW (shell_window), accel_group);
303 merge_id = gtk_ui_manager_new_merge_id (ui_manager);
304 priv->custom_rule_merge_id = merge_id;
306 merge_id = gtk_ui_manager_new_merge_id (ui_manager);
307 priv->gal_view_merge_id = merge_id;
309 /* Construct window widgets. */
311 widget = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
312 gtk_container_add (GTK_CONTAINER (shell_window), widget);
313 gtk_widget_show (widget);
315 box = GTK_BOX (widget);
317 widget = shell_window_construct_menubar (shell_window);
318 if (widget != NULL)
319 gtk_box_pack_start (box, widget, FALSE, FALSE, 0);
321 widget = shell_window_construct_toolbar (shell_window);
322 if (widget != NULL)
323 gtk_box_pack_start (box, widget, FALSE, FALSE, 0);
325 widget = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
326 gtk_box_pack_start (box, widget, TRUE, TRUE, 0);
327 priv->content_pane = g_object_ref (widget);
328 gtk_widget_show (widget);
330 widget = shell_window_construct_taskbar (shell_window);
331 if (widget != NULL)
332 gtk_box_pack_start (box, widget, FALSE, FALSE, 0);
334 paned = GTK_PANED (priv->content_pane);
336 widget = shell_window_construct_sidebar (shell_window);
337 if (widget != NULL)
338 gtk_paned_pack1 (paned, widget, FALSE, FALSE);
340 widget = shell_window_construct_content (shell_window);
341 if (widget != NULL)
342 gtk_paned_pack2 (paned, widget, TRUE, FALSE);
344 /* Create the switcher actions before we set the initial
345 * shell view, because the shell view relies on them for
346 * default settings during construction. */
347 e_shell_window_create_switcher_actions (shell_window);
349 /* Bunch of chores to do when the active view changes. */
351 e_signal_connect_notify (
352 shell_window, "notify::active-view",
353 G_CALLBACK (e_shell_window_update_icon), NULL);
355 e_signal_connect_notify (
356 shell_window, "notify::active-view",
357 G_CALLBACK (e_shell_window_update_title), NULL);
359 e_signal_connect_notify (
360 shell_window, "notify::active-view",
361 G_CALLBACK (e_shell_window_update_view_menu), NULL);
363 e_signal_connect_notify (
364 shell_window, "notify::active-view",
365 G_CALLBACK (e_shell_window_update_search_menu), NULL);
367 #ifndef G_OS_WIN32
368 /* Support lockdown. */
370 settings = e_util_ref_settings ("org.gnome.desktop.lockdown");
372 action_group = ACTION_GROUP (LOCKDOWN_PRINTING);
374 g_settings_bind (
375 settings, "disable-printing",
376 action_group, "visible",
377 G_SETTINGS_BIND_GET |
378 G_SETTINGS_BIND_INVERT_BOOLEAN);
380 action_group = ACTION_GROUP (LOCKDOWN_PRINT_SETUP);
382 g_settings_bind (
383 settings, "disable-print-setup",
384 action_group, "visible",
385 G_SETTINGS_BIND_GET |
386 G_SETTINGS_BIND_INVERT_BOOLEAN);
388 action_group = ACTION_GROUP (LOCKDOWN_SAVE_TO_DISK);
390 g_settings_bind (
391 settings, "disable-save-to-disk",
392 action_group, "visible",
393 G_SETTINGS_BIND_GET |
394 G_SETTINGS_BIND_INVERT_BOOLEAN);
396 g_object_unref (settings);
397 #endif /* G_OS_WIN32 */
399 /* Bind GObject properties to GObject properties. */
401 action = ACTION (WORK_OFFLINE);
403 e_binding_bind_property (
404 shell, "online",
405 action, "visible",
406 G_BINDING_SYNC_CREATE);
408 e_binding_bind_property (
409 shell, "network-available",
410 action, "sensitive",
411 G_BINDING_SYNC_CREATE);
413 action = ACTION (WORK_ONLINE);
415 e_binding_bind_property (
416 shell, "online",
417 action, "visible",
418 G_BINDING_SYNC_CREATE |
419 G_BINDING_INVERT_BOOLEAN);
421 e_binding_bind_property (
422 shell, "network-available",
423 action, "sensitive",
424 G_BINDING_SYNC_CREATE);
426 /* Bind GObject properties to GSettings keys. */
428 settings = e_util_ref_settings ("org.gnome.evolution.shell");
430 /* Use G_SETTINGS_BIND_GET_NO_CHANGES so shell windows
431 * are initialized to the most recently used shell view,
432 * but still allows different windows to show different
433 * views at once. */
434 g_settings_bind (
435 settings, "default-component-id",
436 shell_window, "active-view",
437 G_SETTINGS_BIND_DEFAULT |
438 G_SETTINGS_BIND_GET_NO_CHANGES);
440 if (e_shell_window_is_main_instance (shell_window)) {
441 g_settings_bind (
442 settings, "folder-bar-width",
443 priv->content_pane, "position",
444 G_SETTINGS_BIND_DEFAULT);
446 g_settings_bind (
447 settings, "sidebar-visible",
448 shell_window, "sidebar-visible",
449 G_SETTINGS_BIND_DEFAULT);
451 g_settings_bind (
452 settings, "statusbar-visible",
453 shell_window, "taskbar-visible",
454 G_SETTINGS_BIND_DEFAULT);
456 g_settings_bind (
457 settings, "buttons-visible",
458 shell_window, "switcher-visible",
459 G_SETTINGS_BIND_DEFAULT);
461 g_settings_bind (
462 settings, "toolbar-visible",
463 shell_window, "toolbar-visible",
464 G_SETTINGS_BIND_DEFAULT);
465 } else {
466 g_settings_bind (
467 settings, "folder-bar-width-sub",
468 priv->content_pane, "position",
469 G_SETTINGS_BIND_DEFAULT |
470 G_SETTINGS_BIND_GET_NO_CHANGES);
472 g_settings_bind (
473 settings, "sidebar-visible-sub",
474 shell_window, "sidebar-visible",
475 G_SETTINGS_BIND_DEFAULT |
476 G_SETTINGS_BIND_GET_NO_CHANGES);
478 g_settings_bind (
479 settings, "statusbar-visible-sub",
480 shell_window, "taskbar-visible",
481 G_SETTINGS_BIND_DEFAULT |
482 G_SETTINGS_BIND_GET_NO_CHANGES);
484 g_settings_bind (
485 settings, "buttons-visible-sub",
486 shell_window, "switcher-visible",
487 G_SETTINGS_BIND_DEFAULT |
488 G_SETTINGS_BIND_GET_NO_CHANGES);
490 g_settings_bind (
491 settings, "toolbar-visible-sub",
492 shell_window, "toolbar-visible",
493 G_SETTINGS_BIND_DEFAULT |
494 G_SETTINGS_BIND_GET_NO_CHANGES);
497 /* Configure the initial size and position of the window by way
498 * of either a user-supplied geometry string or the last recorded
499 * values. Note that if a geometry string is applied, the window
500 * size and position are -not- recorded. */
501 if (priv->geometry != NULL) {
502 if (!gtk_window_parse_geometry (window, priv->geometry))
503 g_printerr (
504 "Failed to parse geometry '%s'\n",
505 priv->geometry);
506 g_free (priv->geometry);
507 priv->geometry = NULL;
508 } else {
509 gtk_window_set_default_size (window, 640, 480);
510 e_restore_window (
511 window, "/org/gnome/evolution/shell/window/",
512 E_RESTORE_WINDOW_SIZE | E_RESTORE_WINDOW_POSITION);
515 shell_window_init_switcher_style (shell_window);
517 id = "org.gnome.evolution.shell";
518 e_plugin_ui_register_manager (ui_manager, id, shell_window);
519 e_plugin_ui_enable_manager (ui_manager, id);
521 gtk_application_add_window (GTK_APPLICATION (shell), window);
523 g_object_unref (settings);
526 void
527 e_shell_window_private_dispose (EShellWindow *shell_window)
529 EShellWindowPrivate *priv = shell_window->priv;
531 /* Need to disconnect handlers before we unref the shell. */
532 if (priv->signal_handler_ids != NULL) {
533 GArray *array = priv->signal_handler_ids;
534 gulong handler_id;
535 guint ii;
537 for (ii = 0; ii < array->len; ii++) {
538 handler_id = g_array_index (array, gulong, ii);
539 g_signal_handler_disconnect (priv->shell, handler_id);
542 g_array_free (array, TRUE);
543 priv->signal_handler_ids = NULL;
546 if (priv->shell != NULL) {
547 g_object_remove_weak_pointer (
548 G_OBJECT (priv->shell), &priv->shell);
549 priv->shell = NULL;
552 g_clear_object (&priv->focus_tracker);
553 g_clear_object (&priv->ui_manager);
555 g_hash_table_remove_all (priv->loaded_views);
557 g_clear_object (&priv->alert_bar);
558 g_clear_object (&priv->content_pane);
559 g_clear_object (&priv->content_notebook);
560 g_clear_object (&priv->sidebar_notebook);
561 g_clear_object (&priv->switcher);
562 g_clear_object (&priv->tooltip_label);
563 g_clear_object (&priv->status_notebook);
565 priv->destroyed = TRUE;
568 void
569 e_shell_window_private_finalize (EShellWindow *shell_window)
571 EShellWindowPrivate *priv = shell_window->priv;
573 g_hash_table_destroy (priv->loaded_views);
575 g_free (priv->geometry);
578 void
579 e_shell_window_switch_to_view (EShellWindow *shell_window,
580 const gchar *view_name)
582 EShellView *shell_view;
584 g_return_if_fail (E_IS_SHELL_WINDOW (shell_window));
585 g_return_if_fail (view_name != NULL);
587 if (shell_window->priv->active_view == view_name)
588 return;
590 shell_view = e_shell_window_get_shell_view (shell_window, view_name);
592 shell_window->priv->active_view = view_name;
593 g_object_notify (G_OBJECT (shell_window), "active-view");
595 e_shell_view_update_actions (shell_view);
598 void
599 e_shell_window_update_icon (EShellWindow *shell_window)
601 EShellView *shell_view;
602 GtkAction *action;
603 const gchar *view_name;
604 gchar *icon_name = NULL;
606 g_return_if_fail (E_IS_SHELL_WINDOW (shell_window));
608 view_name = e_shell_window_get_active_view (shell_window);
609 shell_view = e_shell_window_get_shell_view (shell_window, view_name);
611 action = e_shell_view_get_action (shell_view);
612 g_object_get (action, "icon-name", &icon_name, NULL);
613 gtk_window_set_icon_name (GTK_WINDOW (shell_window), icon_name);
614 g_free (icon_name);
617 void
618 e_shell_window_update_title (EShellWindow *shell_window)
620 EShellView *shell_view;
621 const gchar *view_title;
622 const gchar *view_name;
623 gchar *window_title;
625 g_return_if_fail (E_IS_SHELL_WINDOW (shell_window));
627 view_name = e_shell_window_get_active_view (shell_window);
628 shell_view = e_shell_window_get_shell_view (shell_window, view_name);
629 view_title = e_shell_view_get_title (shell_view);
631 /* Translators: This is used for the main window title. */
632 window_title = g_strdup_printf (_("%s - Evolution"), view_title);
633 gtk_window_set_title (GTK_WINDOW (shell_window), window_title);
634 g_free (window_title);