1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /* this file is part of evince, a gnome document viewer
4 * Copyright (C) 2009 Juanjo Marín <juanj.marin@juntadeandalucia.es>
5 * Copyright (C) 2008 Carlos Garcia Campos
6 * Copyright (C) 2004 Martin Kretzschmar
7 * Copyright (C) 2004 Red Hat, Inc.
8 * Copyright (C) 2000, 2001, 2002, 2003, 2004 Marco Pesenti Gritti
9 * Copyright © 2003, 2004, 2005, 2009 Christian Persch
12 * Martin Kretzschmar <martink@gnome.org>
14 * Evince is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * Evince is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
39 #include <glib/gstdio.h>
40 #include <glib/gi18n.h>
44 #include "egg-editable-toolbar.h"
45 #include "egg-toolbar-editor.h"
46 #include "egg-toolbars-model.h"
48 #include "eggfindbar.h"
50 #include "ephy-zoom-action.h"
51 #include "ephy-zoom.h"
53 #include "ev-application.h"
54 #include "ev-dualscreen.h"
55 #include "ev-document-factory.h"
56 #include "ev-document-find.h"
57 #include "ev-document-fonts.h"
58 #include "ev-document-images.h"
59 #include "ev-document-links.h"
60 #include "ev-document-annotations.h"
61 #include "ev-document-type-builtins.h"
62 #include "ev-document-misc.h"
63 #include "ev-file-exporter.h"
64 #include "ev-file-helpers.h"
65 #include "ev-file-monitor.h"
66 #include "ev-history.h"
68 #include "ev-job-scheduler.h"
70 #include "ev-message-area.h"
71 #include "ev-metadata.h"
72 #include "ev-navigation-action.h"
73 #include "ev-open-recent-action.h"
74 #include "ev-page-action.h"
75 #include "ev-password-view.h"
76 #include "ev-properties-dialog.h"
77 #include "ev-sidebar-annotations.h"
78 #include "ev-sidebar-attachments.h"
79 #include "ev-sidebar-bookmarks.h"
80 #include "ev-sidebar.h"
81 #include "ev-sidebar-links.h"
82 #include "ev-sidebar-page.h"
83 #include "ev-sidebar-thumbnails.h"
84 #include "ev-sidebar-layers.h"
85 #include "ev-stock-icons.h"
87 #include "ev-keyring.h"
89 #include "ev-view-presentation.h"
90 #include "ev-view-type-builtins.h"
91 #include "ev-window.h"
92 #include "ev-window-title.h"
93 #include "ev-print-operation.h"
94 #include "ev-progress-message-area.h"
95 #include "ev-annotation-properties-dialog.h"
96 #include "ev-bookmarks.h"
97 #include "ev-bookmark-action.h"
100 #include "ev-media-player-keys.h"
101 #endif /* ENABLE_DBUS */
109 EV_CHROME_MENUBAR = 1 << 0,
110 EV_CHROME_TOOLBAR = 1 << 1,
111 EV_CHROME_FINDBAR = 1 << 2,
112 EV_CHROME_RAISE_TOOLBAR = 1 << 3,
113 EV_CHROME_FULLSCREEN_TOOLBAR = 1 << 4,
114 EV_CHROME_SIDEBAR = 1 << 5,
115 EV_CHROME_NORMAL = EV_CHROME_MENUBAR | EV_CHROME_TOOLBAR | EV_CHROME_SIDEBAR
124 struct _EvWindowPrivate {
135 GtkWidget *scrolled_window;
137 GtkWidget *presentation_view;
138 GtkWidget *message_area;
139 GtkWidget *password_view;
140 GtkWidget *sidebar_thumbs;
141 GtkWidget *sidebar_links;
142 GtkWidget *sidebar_attachments;
143 GtkWidget *sidebar_layers;
144 GtkWidget *sidebar_annots;
145 GtkWidget *sidebar_bookmarks;
149 GSettings *default_settings;
150 GSettings *lockdown_settings;
153 guint menubar_accel_keyval;
154 GdkModifierType menubar_accel_modifier;
156 /* Progress Messages */
158 GCancellable *progress_cancellable;
161 GtkWidget *properties;
162 GtkWidget *print_dialog;
165 GtkActionGroup *action_group;
166 GtkActionGroup *view_popup_action_group;
167 GtkActionGroup *attachment_popup_action_group;
168 GtkRecentManager *recent_manager;
169 GtkActionGroup *recent_action_group;
171 GtkActionGroup *bookmarks_action_group;
172 guint bookmarks_ui_id;
173 GtkUIManager *ui_manager;
175 /* Fullscreen mode */
176 GtkWidget *fullscreen_toolbar;
179 GtkWidget *view_popup;
184 /* Popup attachment */
185 GtkWidget *attachment_popup;
189 EvDocumentModel *model;
194 EvFileMonitor *monitor;
195 guint setup_document_idle;
197 EvDocument *document;
199 EvWindowPageMode page_mode;
200 EvWindowTitle *title;
201 EvMetadata *metadata;
202 EvBookmarks *bookmarks;
207 gchar *search_string;
208 EvWindowRunMode window_mode;
212 EvJob *thumbnail_job;
218 GtkPrintSettings *print_settings;
219 GtkPageSetup *print_page_setup;
220 gboolean close_after_print;
224 guint dbus_object_id;
225 gchar *dbus_object_path;
229 #define EV_WINDOW_GET_PRIVATE(object) \
230 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_WINDOW, EvWindowPrivate))
232 #define EV_WINDOW_IS_PRESENTATION(w) (w->priv->presentation_view != NULL)
234 #define PAGE_SELECTOR_ACTION "PageSelector"
235 #define ZOOM_CONTROL_ACTION "ViewZoom"
236 #define NAVIGATION_ACTION "Navigation"
238 #define GS_LOCKDOWN_SCHEMA_NAME "org.gnome.desktop.lockdown"
239 #define GS_LOCKDOWN_SAVE "disable-save-to-disk"
240 #define GS_LOCKDOWN_PRINT "disable-printing"
241 #define GS_LOCKDOWN_PRINT_SETUP "disable-print-setup"
244 #define EV_WINDOW_DBUS_OBJECT_PATH "/org/gnome/evince/Window/%d"
245 #define EV_WINDOW_DBUS_INTERFACE "org.gnome.evince.Window"
248 #define GS_SCHEMA_NAME "org.gnome.Evince"
249 #define GS_OVERRIDE_RESTRICTIONS "override-restrictions"
251 #define SIDEBAR_DEFAULT_SIZE 132
252 #define LINKS_SIDEBAR_ID "links"
253 #define THUMBNAILS_SIDEBAR_ID "thumbnails"
254 #define ATTACHMENTS_SIDEBAR_ID "attachments"
255 #define LAYERS_SIDEBAR_ID "layers"
256 #define ANNOTS_SIDEBAR_ID "annotations"
257 #define BOOKMARKS_SIDEBAR_ID "bookmarks"
259 #define EV_PRINT_SETTINGS_FILE "print-settings"
260 #define EV_PRINT_SETTINGS_GROUP "Print Settings"
261 #define EV_PAGE_SETUP_GROUP "Page Setup"
263 #define EV_TOOLBARS_FILENAME "evince-toolbar.xml"
265 #define MIN_SCALE 0.05409
266 #define PAGE_CACHE_SIZE 52428800 /* 50MB */
268 #define MAX_RECENT_ITEM_LEN (40)
270 static const gchar *document_print_settings[] = {
271 GTK_PRINT_SETTINGS_N_COPIES,
272 GTK_PRINT_SETTINGS_COLLATE,
273 GTK_PRINT_SETTINGS_REVERSE,
274 GTK_PRINT_SETTINGS_NUMBER_UP,
275 GTK_PRINT_SETTINGS_SCALE,
276 GTK_PRINT_SETTINGS_PRINT_PAGES,
277 GTK_PRINT_SETTINGS_PAGE_RANGES,
278 GTK_PRINT_SETTINGS_PAGE_SET,
279 GTK_PRINT_SETTINGS_OUTPUT_URI
282 static void ev_window_update_actions (EvWindow *ev_window);
283 static void ev_window_sidebar_visibility_changed_cb (EvSidebar *ev_sidebar,
285 EvWindow *ev_window);
286 static void ev_window_view_toolbar_cb (GtkAction *action,
287 EvWindow *ev_window);
288 static void ev_window_set_page_mode (EvWindow *window,
289 EvWindowPageMode page_mode);
290 static void ev_window_load_job_cb (EvJob *job,
292 static void ev_window_reload_document (EvWindow *window,
294 static void ev_window_reload_job_cb (EvJob *job,
296 static void ev_window_set_icon_from_thumbnail (EvJobThumbnail *job,
297 EvWindow *ev_window);
298 static void ev_window_save_job_cb (EvJob *save,
300 static void ev_window_sizing_mode_changed_cb (EvDocumentModel *model,
302 EvWindow *ev_window);
303 static void ev_window_zoom_changed_cb (EvDocumentModel *model,
305 EvWindow *ev_window);
306 static void ev_window_add_recent (EvWindow *window,
307 const char *filename);
308 static void ev_window_run_fullscreen (EvWindow *window);
309 static void ev_window_stop_fullscreen (EvWindow *window,
310 gboolean unfullscreen_window);
311 static void ev_window_cmd_view_fullscreen (GtkAction *action,
313 static void ev_window_cmd_view_presentation (GtkAction *action,
315 static void ev_view_popup_cmd_open_link (GtkAction *action,
317 static void ev_view_popup_cmd_open_link_new_window (GtkAction *action,
319 static void ev_view_popup_cmd_copy_link_address (GtkAction *action,
321 static void ev_view_popup_cmd_save_image_as (GtkAction *action,
323 static void ev_view_popup_cmd_copy_image (GtkAction *action,
325 static void ev_view_popup_cmd_annot_properties (GtkAction *action,
327 static void ev_attachment_popup_cmd_open_attachment (GtkAction *action,
329 static void ev_attachment_popup_cmd_save_attachment_as (GtkAction *action,
331 static void ev_window_cmd_view_best_fit (GtkAction *action,
332 EvWindow *ev_window);
333 static void ev_window_cmd_view_page_width (GtkAction *action,
334 EvWindow *ev_window);
335 static void view_handle_link_cb (EvView *view,
338 static void ev_window_update_find_status_message (EvWindow *ev_window);
339 static void ev_window_cmd_edit_find (GtkAction *action,
340 EvWindow *ev_window);
341 static void find_bar_search_changed_cb (EggFindBar *find_bar,
343 EvWindow *ev_window);
344 static void view_external_link_cb (EvWindow *window,
345 EvLinkAction *action);
346 static void ev_window_load_file_remote (EvWindow *ev_window,
348 static void ev_window_media_player_key_pressed (EvWindow *window,
351 static void ev_window_update_max_min_scale (EvWindow *window);
353 static void ev_window_emit_closed (EvWindow *window);
354 static void ev_window_emit_doc_loaded (EvWindow *window);
356 static void ev_window_setup_bookmarks (EvWindow *window);
358 static guint ev_window_n_copies = 0;
360 G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW)
363 get_screen_dpi (EvWindow *window)
367 screen = gtk_window_get_screen (GTK_WINDOW (window));
368 return ev_document_misc_get_screen_dpi (screen);
372 ev_window_is_editing_toolbar (EvWindow *ev_window)
374 return egg_editable_toolbar_get_edit_mode (EGG_EDITABLE_TOOLBAR (ev_window->priv->toolbar));
378 ev_window_set_action_sensitive (EvWindow *ev_window,
382 GtkAction *action = gtk_action_group_get_action (ev_window->priv->action_group,
384 gtk_action_set_sensitive (action, sensitive);
389 ev_window_setup_action_sensitivity (EvWindow *ev_window)
391 EvDocument *document = ev_window->priv->document;
392 const EvDocumentInfo *info = NULL;
393 gboolean has_document = FALSE;
394 gboolean ok_to_print = TRUE;
395 gboolean ok_to_copy = TRUE;
396 gboolean has_properties = TRUE;
397 gboolean override_restrictions = TRUE;
398 gboolean can_get_text = FALSE;
399 gboolean has_pages = FALSE;
400 gboolean can_find = FALSE;
404 has_pages = ev_document_get_n_pages (document) > 0;
405 info = ev_document_get_info (document);
408 if (!info || info->fields_mask == 0) {
409 has_properties = FALSE;
412 if (has_document && EV_IS_SELECTION (document)) {
416 if (has_pages && EV_IS_DOCUMENT_FIND (document)) {
420 if (has_document && ev_window->priv->settings) {
421 override_restrictions =
422 g_settings_get_boolean (ev_window->priv->settings,
423 GS_OVERRIDE_RESTRICTIONS);
426 if (!override_restrictions && info && info->fields_mask & EV_DOCUMENT_INFO_PERMISSIONS) {
427 ok_to_print = (info->permissions & EV_DOCUMENT_PERMISSIONS_OK_TO_PRINT);
428 ok_to_copy = (info->permissions & EV_DOCUMENT_PERMISSIONS_OK_TO_COPY);
431 if (has_document && !ev_print_operation_exists_for_document(document))
434 if (has_document && ev_window->priv->lockdown_settings &&
435 g_settings_get_boolean (ev_window->priv->lockdown_settings, GS_LOCKDOWN_SAVE)) {
439 if (has_document && ev_window->priv->lockdown_settings &&
440 g_settings_get_boolean (ev_window->priv->lockdown_settings, GS_LOCKDOWN_PRINT)) {
445 ev_window_set_action_sensitive (ev_window, "FileOpenCopy", has_document);
446 ev_window_set_action_sensitive (ev_window, "FileSaveAs", has_document && ok_to_copy);
447 ev_window_set_action_sensitive (ev_window, "FilePrint", has_pages && ok_to_print);
448 ev_window_set_action_sensitive (ev_window, "FileProperties", has_document && has_properties);
449 ev_window_set_action_sensitive (ev_window, "FileOpenContainingFolder", has_document);
452 ev_window_set_action_sensitive (ev_window, "EditSelectAll", has_pages && can_get_text);
453 ev_window_set_action_sensitive (ev_window, "EditFind", can_find);
454 ev_window_set_action_sensitive (ev_window, "Slash", can_find);
455 ev_window_set_action_sensitive (ev_window, "EditRotateLeft", has_pages);
456 ev_window_set_action_sensitive (ev_window, "EditRotateRight", has_pages);
459 ev_window_set_action_sensitive (ev_window, "ViewToolbar", !ev_window_is_editing_toolbar (ev_window));
460 ev_window_set_action_sensitive (ev_window, "ViewContinuous", has_pages);
461 ev_window_set_action_sensitive (ev_window, "ViewDual", has_pages);
462 ev_window_set_action_sensitive (ev_window, "ViewBestFit", has_pages);
463 ev_window_set_action_sensitive (ev_window, "ViewPageWidth", has_pages);
464 ev_window_set_action_sensitive (ev_window, "ViewReload", has_pages);
465 ev_window_set_action_sensitive (ev_window, "ViewAutoscroll", has_pages);
466 ev_window_set_action_sensitive (ev_window, "ViewInvertedColors", has_pages);
469 ev_window_set_action_sensitive (ev_window, "BookmarksAdd",
470 has_pages && ev_window->priv->bookmarks);
472 /* Toolbar-specific actions: */
473 ev_window_set_action_sensitive (ev_window, PAGE_SELECTOR_ACTION, has_pages);
474 ev_window_set_action_sensitive (ev_window, ZOOM_CONTROL_ACTION, has_pages);
475 ev_window_set_action_sensitive (ev_window, NAVIGATION_ACTION, FALSE);
477 ev_window_update_actions (ev_window);
481 ev_window_update_actions (EvWindow *ev_window)
483 EvView *view = EV_VIEW (ev_window->priv->view);
484 int n_pages = 0, page = -1;
485 gboolean has_pages = FALSE;
486 gboolean presentation_mode;
487 gboolean can_find_in_page = FALSE;
488 EvSizingMode sizing_mode;
490 if (ev_window->priv->document) {
491 page = ev_document_model_get_page (ev_window->priv->model);
492 n_pages = ev_document_get_n_pages (ev_window->priv->document);
493 has_pages = n_pages > 0;
496 can_find_in_page = (ev_window->priv->find_job &&
497 ev_job_find_has_results (EV_JOB_FIND (ev_window->priv->find_job)));
499 ev_window_set_action_sensitive (ev_window, "EditCopy",
501 ev_view_get_has_selection (view));
502 ev_window_set_action_sensitive (ev_window, "EditFindNext",
503 has_pages && can_find_in_page);
504 ev_window_set_action_sensitive (ev_window, "EditFindPrevious",
505 has_pages && can_find_in_page);
506 ev_window_set_action_sensitive (ev_window, "F3",
507 has_pages && can_find_in_page);
509 presentation_mode = EV_WINDOW_IS_PRESENTATION (ev_window);
511 ev_window_set_action_sensitive (ev_window, "ViewZoomIn",
513 ev_view_can_zoom_in (view) &&
515 ev_window_set_action_sensitive (ev_window, "ViewZoomOut",
517 ev_view_can_zoom_out (view) &&
522 ev_window_set_action_sensitive (ev_window, "GoPreviousPage", page > 0);
523 ev_window_set_action_sensitive (ev_window, "GoNextPage", page < n_pages - 1);
524 ev_window_set_action_sensitive (ev_window, "GoFirstPage", page > 0);
525 ev_window_set_action_sensitive (ev_window, "GoLastPage", page < n_pages - 1);
527 ev_window_set_action_sensitive (ev_window, "GoFirstPage", FALSE);
528 ev_window_set_action_sensitive (ev_window, "GoPreviousPage", FALSE);
529 ev_window_set_action_sensitive (ev_window, "GoNextPage", FALSE);
530 ev_window_set_action_sensitive (ev_window, "GoLastPage", FALSE);
533 sizing_mode = ev_document_model_get_sizing_mode (ev_window->priv->model);
534 if (has_pages && sizing_mode != EV_SIZING_FIT_WIDTH && sizing_mode != EV_SIZING_BEST_FIT) {
539 action = gtk_action_group_get_action (ev_window->priv->action_group,
540 ZOOM_CONTROL_ACTION);
542 real_zoom = ev_document_model_get_scale (ev_window->priv->model);
543 real_zoom *= 72.0 / get_screen_dpi (ev_window);
544 zoom = ephy_zoom_get_nearest_zoom_level (real_zoom);
546 ephy_zoom_action_set_zoom_level (EPHY_ZOOM_ACTION (action), zoom);
551 ev_window_set_view_accels_sensitivity (EvWindow *window, gboolean sensitive)
555 can_find = window->priv->document &&
556 EV_IS_DOCUMENT_FIND (window->priv->document);
558 if (window->priv->action_group) {
559 ev_window_set_action_sensitive (window, "PageDown", sensitive);
560 ev_window_set_action_sensitive (window, "PageUp", sensitive);
561 ev_window_set_action_sensitive (window, "Space", sensitive);
562 ev_window_set_action_sensitive (window, "ShiftSpace", sensitive);
563 ev_window_set_action_sensitive (window, "BackSpace", sensitive);
564 ev_window_set_action_sensitive (window, "ShiftBackSpace", sensitive);
565 ev_window_set_action_sensitive (window, "Return", sensitive);
566 ev_window_set_action_sensitive (window, "ShiftReturn", sensitive);
567 ev_window_set_action_sensitive (window, "Plus", sensitive);
568 ev_window_set_action_sensitive (window, "Minus", sensitive);
569 ev_window_set_action_sensitive (window, "KpPlus", sensitive);
570 ev_window_set_action_sensitive (window, "KpMinus", sensitive);
571 ev_window_set_action_sensitive (window, "Equal", sensitive);
572 ev_window_set_action_sensitive (window, "p", sensitive);
573 ev_window_set_action_sensitive (window, "n", sensitive);
575 ev_window_set_action_sensitive (window, "Slash", sensitive && can_find);
580 set_widget_visibility (GtkWidget *widget, gboolean visible)
582 g_assert (GTK_IS_WIDGET (widget));
585 gtk_widget_show (widget);
587 gtk_widget_hide (widget);
591 update_chrome_visibility (EvWindow *window)
593 EvWindowPrivate *priv = window->priv;
594 gboolean menubar, toolbar, findbar, fullscreen_toolbar, sidebar;
595 gboolean fullscreen_mode, presentation, fullscreen;
597 presentation = EV_WINDOW_IS_PRESENTATION (window);
598 fullscreen = ev_document_model_get_fullscreen (priv->model);
599 fullscreen_mode = fullscreen || presentation;
601 menubar = (priv->chrome & EV_CHROME_MENUBAR) != 0 && !fullscreen_mode;
602 toolbar = ((priv->chrome & EV_CHROME_TOOLBAR) != 0 ||
603 (priv->chrome & EV_CHROME_RAISE_TOOLBAR) != 0) && !fullscreen_mode;
604 fullscreen_toolbar = ((priv->chrome & EV_CHROME_FULLSCREEN_TOOLBAR) != 0 ||
605 (priv->chrome & EV_CHROME_RAISE_TOOLBAR) != 0) && fullscreen;
606 findbar = (priv->chrome & EV_CHROME_FINDBAR) != 0;
607 sidebar = (priv->chrome & EV_CHROME_SIDEBAR) != 0 && priv->document && !presentation;
609 set_widget_visibility (priv->menubar, menubar);
610 set_widget_visibility (priv->toolbar, toolbar);
611 set_widget_visibility (priv->find_bar, findbar);
612 set_widget_visibility (priv->sidebar, sidebar);
614 ev_window_set_action_sensitive (window, "EditToolbar", toolbar);
616 if (priv->fullscreen_toolbar != NULL) {
617 set_widget_visibility (priv->fullscreen_toolbar, fullscreen_toolbar);
622 update_chrome_flag (EvWindow *window, EvChrome flag, gboolean active)
624 EvWindowPrivate *priv = window->priv;
627 priv->chrome |= flag;
629 priv->chrome &= ~flag;
634 update_sizing_buttons (EvWindow *window)
636 GtkActionGroup *action_group = window->priv->action_group;
638 gboolean best_fit, page_width;
640 switch (ev_document_model_get_sizing_mode (window->priv->model)) {
641 case EV_SIZING_BEST_FIT:
645 case EV_SIZING_FIT_WIDTH:
650 best_fit = page_width = FALSE;
654 action = gtk_action_group_get_action (action_group, "ViewBestFit");
655 g_signal_handlers_block_by_func
656 (action, G_CALLBACK (ev_window_cmd_view_best_fit), window);
657 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), best_fit);
658 g_signal_handlers_unblock_by_func
659 (action, G_CALLBACK (ev_window_cmd_view_best_fit), window);
661 action = gtk_action_group_get_action (action_group, "ViewPageWidth");
662 g_signal_handlers_block_by_func
663 (action, G_CALLBACK (ev_window_cmd_view_page_width), window);
664 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), page_width);
665 g_signal_handlers_unblock_by_func
666 (action, G_CALLBACK (ev_window_cmd_view_page_width), window);
668 action = gtk_action_group_get_action (window->priv->action_group,
669 ZOOM_CONTROL_ACTION);
671 ephy_zoom_action_set_zoom_level (EPHY_ZOOM_ACTION (action),
673 } else if (page_width) {
674 ephy_zoom_action_set_zoom_level (EPHY_ZOOM_ACTION (action),
675 EPHY_ZOOM_FIT_WIDTH);
680 update_chrome_actions (EvWindow *window)
682 EvWindowPrivate *priv = window->priv;
683 GtkActionGroup *action_group = priv->action_group;
686 action= gtk_action_group_get_action (action_group, "ViewToolbar");
687 g_signal_handlers_block_by_func
688 (action, G_CALLBACK (ev_window_view_toolbar_cb), window);
689 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
690 (priv->chrome & EV_CHROME_TOOLBAR) != 0);
691 g_signal_handlers_unblock_by_func
692 (action, G_CALLBACK (ev_window_view_toolbar_cb), window);
696 * ev_window_is_empty:
697 * @ev_window: The instance of the #EvWindow.
699 * It does look if there is any document loaded or if there is any job to load
702 * Returns: %TRUE if there isn't any document loaded or any any documente to be
703 * loaded, %FALSE in other case.
706 ev_window_is_empty (const EvWindow *ev_window)
708 g_return_val_if_fail (EV_IS_WINDOW (ev_window), FALSE);
710 return (ev_window->priv->document == NULL) &&
711 (ev_window->priv->load_job == NULL);
715 ev_window_set_message_area (EvWindow *window,
718 if (window->priv->message_area == area)
721 if (window->priv->message_area)
722 gtk_widget_destroy (window->priv->message_area);
723 window->priv->message_area = area;
728 gtk_box_pack_start (GTK_BOX (window->priv->view_box),
729 window->priv->message_area,
731 gtk_box_reorder_child (GTK_BOX (window->priv->view_box),
732 window->priv->message_area, 0);
733 g_object_add_weak_pointer (G_OBJECT (window->priv->message_area),
734 (gpointer) &(window->priv->message_area));
738 ev_window_message_area_response_cb (EvMessageArea *area,
742 ev_window_set_message_area (window, NULL);
746 ev_window_error_message (EvWindow *window,
755 if (window->priv->message_area)
758 va_start (args, format);
759 msg = g_strdup_vprintf (format, args);
762 area = ev_message_area_new (GTK_MESSAGE_ERROR,
770 ev_message_area_set_secondary_text (EV_MESSAGE_AREA (area), error->message);
771 g_signal_connect (area, "response",
772 G_CALLBACK (ev_window_message_area_response_cb),
774 gtk_widget_show (area);
775 ev_window_set_message_area (window, area);
779 ev_window_warning_message (EvWindow *window,
787 if (window->priv->message_area)
790 va_start (args, format);
791 msg = g_strdup_vprintf (format, args);
794 area = ev_message_area_new (GTK_MESSAGE_WARNING,
801 g_signal_connect (area, "response",
802 G_CALLBACK (ev_window_message_area_response_cb),
804 gtk_widget_show (area);
805 ev_window_set_message_area (window, area);
808 typedef struct _PageTitleData {
809 const gchar *page_label;
814 ev_window_find_page_title (GtkTreeModel *tree_model,
821 gtk_tree_model_get (tree_model, iter,
822 EV_DOCUMENT_LINKS_COLUMN_PAGE_LABEL, &page_string,
828 if (!strcmp (page_string, data->page_label)) {
829 gtk_tree_model_get (tree_model, iter,
830 EV_DOCUMENT_LINKS_COLUMN_MARKUP, &data->page_title,
832 g_free (page_string);
836 g_free (page_string);
841 ev_window_get_page_title (EvWindow *window,
842 const gchar *page_label)
844 if (EV_IS_DOCUMENT_LINKS (window->priv->document) &&
845 ev_document_links_has_document_links (EV_DOCUMENT_LINKS (window->priv->document))) {
849 data.page_label = page_label;
850 data.page_title = NULL;
852 g_object_get (G_OBJECT (window->priv->sidebar_links),
856 gtk_tree_model_foreach (model,
857 (GtkTreeModelForeachFunc)ev_window_find_page_title,
860 g_object_unref (model);
863 return data.page_title;
870 ev_window_add_history (EvWindow *window, gint page, EvLink *link)
872 gchar *page_label = NULL;
876 EvLinkAction *action;
879 if (window->priv->history == NULL)
882 if (!EV_IS_DOCUMENT_LINKS (window->priv->document))
886 action = g_object_ref (ev_link_get_action (link));
887 dest = ev_link_action_get_dest (action);
888 page_label = ev_document_links_get_dest_page_label (EV_DOCUMENT_LINKS (window->priv->document), dest);
890 dest = ev_link_dest_new_page (page);
891 action = ev_link_action_new_dest (dest);
892 page_label = ev_document_get_page_label (window->priv->document, page);
898 page_title = ev_window_get_page_title (window, page_label);
900 link_title = g_strdup_printf (_("Page %s — %s"), page_label, page_title);
903 link_title = g_strdup_printf (_("Page %s"), page_label);
906 real_link = ev_link_new (link_title, action);
908 ev_history_add_link (window->priv->history, real_link);
912 g_object_unref (real_link);
916 view_handle_link_cb (EvView *view, EvLink *link, EvWindow *window)
918 int current_page = ev_document_model_get_page (window->priv->model);
920 ev_window_add_history (window, 0, link);
921 ev_window_add_history (window, current_page, NULL);
925 view_selection_changed_cb (EvView *view,
928 ev_window_set_action_sensitive (window, "EditCopy",
929 ev_view_get_has_selection (view));
933 view_layers_changed_cb (EvView *view,
936 ev_sidebar_layers_update_layers_state (EV_SIDEBAR_LAYERS (window->priv->sidebar_layers));
940 ev_window_page_changed_cb (EvWindow *ev_window,
943 EvDocumentModel *model)
945 ev_window_update_actions (ev_window);
947 ev_window_update_find_status_message (ev_window);
949 if (abs (new_page - old_page) > 1) {
950 ev_window_add_history (ev_window, new_page, NULL);
951 ev_window_add_history (ev_window, old_page, NULL);
954 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window))
955 ev_metadata_set_int (ev_window->priv->metadata, "page", new_page);
959 ev_window_sidebar_get_current_page_id (EvWindow *ev_window)
961 GtkWidget *current_page;
964 g_object_get (ev_window->priv->sidebar,
965 "current_page", ¤t_page,
968 if (current_page == ev_window->priv->sidebar_links) {
969 id = LINKS_SIDEBAR_ID;
970 } else if (current_page == ev_window->priv->sidebar_thumbs) {
971 id = THUMBNAILS_SIDEBAR_ID;
972 } else if (current_page == ev_window->priv->sidebar_attachments) {
973 id = ATTACHMENTS_SIDEBAR_ID;
974 } else if (current_page == ev_window->priv->sidebar_layers) {
975 id = LAYERS_SIDEBAR_ID;
976 } else if (current_page == ev_window->priv->sidebar_annots) {
977 id = ANNOTS_SIDEBAR_ID;
978 } else if (current_page == ev_window->priv->sidebar_bookmarks) {
979 id = BOOKMARKS_SIDEBAR_ID;
981 g_assert_not_reached();
984 g_object_unref (current_page);
990 ev_window_sidebar_set_current_page (EvWindow *window,
991 const gchar *page_id)
993 EvDocument *document = window->priv->document;
994 EvSidebar *sidebar = EV_SIDEBAR (window->priv->sidebar);
995 GtkWidget *links = window->priv->sidebar_links;
996 GtkWidget *thumbs = window->priv->sidebar_thumbs;
997 GtkWidget *attachments = window->priv->sidebar_attachments;
998 GtkWidget *annots = window->priv->sidebar_annots;
999 GtkWidget *layers = window->priv->sidebar_layers;
1000 GtkWidget *bookmarks = window->priv->sidebar_bookmarks;
1002 if (strcmp (page_id, LINKS_SIDEBAR_ID) == 0 &&
1003 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (links), document)) {
1004 ev_sidebar_set_page (sidebar, links);
1005 } else if (strcmp (page_id, THUMBNAILS_SIDEBAR_ID) == 0 &&
1006 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (thumbs), document)) {
1007 ev_sidebar_set_page (sidebar, thumbs);
1008 } else if (strcmp (page_id, ATTACHMENTS_SIDEBAR_ID) == 0 &&
1009 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (attachments), document)) {
1010 ev_sidebar_set_page (sidebar, attachments);
1011 } else if (strcmp (page_id, LAYERS_SIDEBAR_ID) == 0 &&
1012 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (layers), document)) {
1013 ev_sidebar_set_page (sidebar, layers);
1014 } else if (strcmp (page_id, ANNOTS_SIDEBAR_ID) == 0 &&
1015 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (annots), document)) {
1016 ev_sidebar_set_page (sidebar, annots);
1017 } else if (strcmp (page_id, BOOKMARKS_SIDEBAR_ID) == 0 &&
1018 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (bookmarks), document)) {
1019 ev_sidebar_set_page (sidebar, bookmarks);
1024 update_document_mode (EvWindow *window, EvDocumentMode mode)
1026 if (mode == EV_DOCUMENT_MODE_PRESENTATION) {
1027 ev_window_run_presentation (window);
1029 else if (mode == EV_DOCUMENT_MODE_FULL_SCREEN) {
1030 ev_window_run_fullscreen (window);
1035 setup_chrome_from_metadata (EvWindow *window)
1037 EvChrome chrome = EV_CHROME_NORMAL;
1038 gboolean show_toolbar = TRUE;
1040 if (ev_window_is_empty (window)) {
1041 window->priv->chrome = chrome;
1046 if (!window->priv->metadata) {
1047 show_toolbar = g_settings_get_boolean (window->priv->default_settings, "show-toolbar");
1048 } else if (!ev_metadata_get_boolean (window->priv->metadata, "show_toolbar", &show_toolbar)) {
1049 if (window->priv->is_new_doc)
1050 show_toolbar = g_settings_get_boolean (window->priv->default_settings, "show-toolbar");
1054 chrome &= ~EV_CHROME_TOOLBAR;
1056 window->priv->chrome = chrome;
1060 setup_sidebar_from_metadata (EvWindow *window)
1062 EvDocument *document = window->priv->document;
1063 GSettings *settings = window->priv->default_settings;
1066 gboolean sidebar_visibility = TRUE;
1068 if (ev_window_is_empty (window))
1071 if (!window->priv->metadata) {
1072 sidebar_visibility = g_settings_get_boolean (settings, "show-sidebar");
1073 } else if (!ev_metadata_get_boolean (window->priv->metadata, "sidebar_visibility", &sidebar_visibility)) {
1074 if (window->priv->is_new_doc)
1075 sidebar_visibility = g_settings_get_boolean (settings, "show-sidebar");
1078 update_chrome_flag (window, EV_CHROME_SIDEBAR, sidebar_visibility);
1079 update_chrome_visibility (window);
1081 if (!window->priv->metadata) {
1082 /* Set default values */
1083 gtk_paned_set_position (GTK_PANED (window->priv->hpaned),
1084 g_settings_get_int (settings, "sidebar-size"));
1086 page_id = g_settings_get_string (settings, "sidebar-page");
1087 ev_window_sidebar_set_current_page (window, page_id);
1094 if (ev_metadata_get_int (window->priv->metadata, "sidebar_size", &sidebar_size)) {
1095 gtk_paned_set_position (GTK_PANED (window->priv->hpaned), sidebar_size);
1096 } else if (window->priv->is_new_doc) {
1097 gtk_paned_set_position (GTK_PANED (window->priv->hpaned),
1098 g_settings_get_int (settings, "sidebar-size"));
1104 if (ev_metadata_get_string (window->priv->metadata, "sidebar_page", &page_id)) {
1105 ev_window_sidebar_set_current_page (window, page_id);
1106 } else if (window->priv->is_new_doc) {
1107 page_id = g_settings_get_string (settings, "sidebar-page");
1108 ev_window_sidebar_set_current_page (window, page_id);
1114 setup_model_from_metadata (EvWindow *window)
1116 GSettings *settings = window->priv->default_settings;
1121 gboolean inverted_colors = FALSE;
1122 gboolean continuous = FALSE;
1123 gboolean dual_page = FALSE;
1124 gboolean fullscreen = FALSE;
1126 if (!window->priv->metadata) {
1127 /* Set default values */
1128 ev_document_model_set_sizing_mode (window->priv->model,
1129 g_settings_get_enum (settings, "sizing-mode"));
1130 ev_document_model_set_inverted_colors (window->priv->model,
1131 g_settings_get_boolean (settings, "inverted-colors"));
1132 ev_document_model_set_continuous (window->priv->model,
1133 g_settings_get_boolean (settings, "continuous"));
1134 ev_document_model_set_dual_page (window->priv->model,
1135 g_settings_get_boolean (settings, "dual-page"));
1136 fullscreen = g_settings_get_boolean (settings, "fullscreen");
1138 ev_window_run_fullscreen (window);
1144 if (!window->priv->dest &&
1145 ev_metadata_get_int (window->priv->metadata, "page", &page)) {
1146 ev_document_model_set_page (window->priv->model, page);
1150 if (ev_metadata_get_string (window->priv->metadata, "sizing_mode", &sizing_mode)) {
1151 GEnumValue *enum_value;
1153 enum_value = g_enum_get_value_by_nick
1154 (g_type_class_peek (EV_TYPE_SIZING_MODE), sizing_mode);
1155 ev_document_model_set_sizing_mode (window->priv->model, enum_value->value);
1156 } else if (window->priv->is_new_doc) {
1157 ev_document_model_set_sizing_mode (window->priv->model,
1158 g_settings_get_enum (settings, "sizing-mode"));
1162 if (ev_document_model_get_sizing_mode (window->priv->model) == EV_SIZING_FREE &&
1163 ev_metadata_get_double (window->priv->metadata, "zoom", &zoom)) {
1164 zoom *= get_screen_dpi (window) / 72.0;
1165 ev_document_model_set_scale (window->priv->model, zoom);
1169 if (ev_metadata_get_int (window->priv->metadata, "rotation", &rotation)) {
1184 ev_document_model_set_rotation (window->priv->model, rotation);
1187 /* Inverted Colors */
1188 if (ev_metadata_get_boolean (window->priv->metadata, "inverted-colors", &inverted_colors)) {
1189 ev_document_model_set_inverted_colors (window->priv->model, inverted_colors);
1190 } else if (window->priv->is_new_doc) {
1191 ev_document_model_set_inverted_colors (window->priv->model,
1192 g_settings_get_boolean (settings, "inverted-colors"));
1196 if (ev_metadata_get_boolean (window->priv->metadata, "continuous", &continuous)) {
1197 ev_document_model_set_continuous (window->priv->model, continuous);
1198 } else if (window->priv->is_new_doc) {
1199 ev_document_model_set_continuous (window->priv->model,
1200 g_settings_get_boolean (settings, "continuous"));
1204 if (ev_metadata_get_boolean (window->priv->metadata, "dual-page", &dual_page)) {
1205 ev_document_model_set_dual_page (window->priv->model, dual_page);
1206 } else if (window->priv->is_new_doc) {
1207 ev_document_model_set_dual_page (window->priv->model,
1208 g_settings_get_boolean (settings, "dual-page"));
1212 if (!ev_metadata_get_boolean (window->priv->metadata, "fullscreen", &fullscreen)) {
1213 if (window->priv->is_new_doc)
1214 fullscreen = g_settings_get_boolean (settings, "fullscreen");
1218 ev_window_run_fullscreen (window);
1222 setup_document_from_metadata (EvWindow *window)
1227 gdouble width_ratio;
1228 gdouble height_ratio;
1230 setup_sidebar_from_metadata (window);
1232 if (window->priv->metadata) {
1233 /* Make sure to not open a document on the last page,
1234 * since closing it on the last page most likely means the
1235 * user was finished reading the document. In that case, reopening should
1236 * show the first page. */
1237 page = ev_document_model_get_page (window->priv->model);
1238 n_pages = ev_document_get_n_pages (window->priv->document);
1239 if (page == n_pages - 1)
1240 ev_document_model_set_page (window->priv->model, 0);
1242 if (ev_metadata_get_int (window->priv->metadata, "window_width", &width) &&
1243 ev_metadata_get_int (window->priv->metadata, "window_height", &height))
1244 return; /* size was already set in setup_size_from_metadata */
1247 g_settings_get (window->priv->default_settings, "window-ratio", "(dd)", &width_ratio, &height_ratio);
1248 if (width_ratio > 0. && height_ratio > 0.) {
1249 gdouble document_width;
1250 gdouble document_height;
1253 gint request_height;
1255 ev_document_get_max_page_size (window->priv->document,
1256 &document_width, &document_height);
1258 request_width = (gint)(width_ratio * document_width + 0.5);
1259 request_height = (gint)(height_ratio * document_height + 0.5);
1261 screen = gtk_window_get_screen (GTK_WINDOW (window));
1263 request_width = MIN (request_width, gdk_screen_get_width (screen));
1264 request_height = MIN (request_height, gdk_screen_get_height (screen));
1267 if (request_width > 0 && request_height > 0) {
1268 gtk_window_resize (GTK_WINDOW (window),
1276 setup_size_from_metadata (EvWindow *window)
1284 if (!window->priv->metadata)
1287 if (ev_metadata_get_boolean (window->priv->metadata, "window_maximized", &maximized)) {
1289 gtk_window_maximize (GTK_WINDOW (window));
1292 gtk_window_unmaximize (GTK_WINDOW (window));
1296 if (ev_metadata_get_int (window->priv->metadata, "window_x", &x) &&
1297 ev_metadata_get_int (window->priv->metadata, "window_y", &y)) {
1298 gtk_window_move (GTK_WINDOW (window), x, y);
1301 if (ev_metadata_get_int (window->priv->metadata, "window_width", &width) &&
1302 ev_metadata_get_int (window->priv->metadata, "window_height", &height)) {
1303 gtk_window_resize (GTK_WINDOW (window), width, height);
1308 setup_view_from_metadata (EvWindow *window)
1310 gboolean presentation;
1312 if (!window->priv->metadata)
1316 if (ev_metadata_get_boolean (window->priv->metadata, "presentation", &presentation)) {
1318 ev_window_run_presentation (window);
1324 ev_window_clear_thumbnail_job (EvWindow *ev_window)
1326 if (ev_window->priv->thumbnail_job != NULL) {
1327 if (!ev_job_is_finished (ev_window->priv->thumbnail_job))
1328 ev_job_cancel (ev_window->priv->thumbnail_job);
1330 g_signal_handlers_disconnect_by_func (ev_window->priv->thumbnail_job,
1331 ev_window_set_icon_from_thumbnail,
1333 g_object_unref (ev_window->priv->thumbnail_job);
1334 ev_window->priv->thumbnail_job = NULL;
1339 ev_window_set_icon_from_thumbnail (EvJobThumbnail *job,
1340 EvWindow *ev_window)
1342 if (job->thumbnail) {
1343 if (ev_document_model_get_inverted_colors (ev_window->priv->model))
1344 ev_document_misc_invert_pixbuf (job->thumbnail);
1345 gtk_window_set_icon (GTK_WINDOW (ev_window),
1349 ev_window_clear_thumbnail_job (ev_window);
1353 ev_window_refresh_window_thumbnail (EvWindow *ev_window)
1358 EvDocument *document = ev_window->priv->document;
1360 if (ev_document_get_n_pages (document) <= 0 ||
1361 !ev_document_check_dimensions (document)) {
1365 ev_window_clear_thumbnail_job (ev_window);
1367 ev_document_get_page_size (document, 0, &page_width, NULL);
1368 scale = 128. / page_width;
1369 rotation = ev_document_model_get_rotation (ev_window->priv->model);
1371 ev_window->priv->thumbnail_job = ev_job_thumbnail_new (document, 0, rotation, scale);
1372 g_signal_connect (ev_window->priv->thumbnail_job, "finished",
1373 G_CALLBACK (ev_window_set_icon_from_thumbnail),
1375 ev_job_scheduler_push_job (ev_window->priv->thumbnail_job, EV_JOB_PRIORITY_NONE);
1379 override_restrictions_changed (GSettings *settings,
1381 EvWindow *ev_window)
1383 ev_window_setup_action_sensitivity (ev_window);
1387 lockdown_changed (GSettings *lockdown,
1389 EvWindow *ev_window)
1391 ev_window_setup_action_sensitivity (ev_window);
1395 ev_window_setup_document (EvWindow *ev_window)
1397 const EvDocumentInfo *info;
1398 EvDocument *document = ev_window->priv->document;
1401 ev_window->priv->setup_document_idle = 0;
1403 ev_window_refresh_window_thumbnail (ev_window);
1405 ev_window_set_page_mode (ev_window, PAGE_MODE_DOCUMENT);
1406 ev_window_title_set_document (ev_window->priv->title, document);
1407 ev_window_title_set_uri (ev_window->priv->title, ev_window->priv->uri);
1409 if (!ev_window->priv->settings) {
1410 ev_window->priv->settings = g_settings_new (GS_SCHEMA_NAME);
1411 g_signal_connect (ev_window->priv->settings,
1412 "changed::"GS_OVERRIDE_RESTRICTIONS,
1413 G_CALLBACK (override_restrictions_changed),
1417 #ifdef HAVE_DESKTOP_SCHEMAS
1418 if (!ev_window->priv->lockdown_settings) {
1419 ev_window->priv->lockdown_settings = g_settings_new (GS_LOCKDOWN_SCHEMA_NAME);
1420 g_signal_connect (ev_window->priv->lockdown_settings,
1422 G_CALLBACK (lockdown_changed),
1427 ev_window_setup_action_sensitivity (ev_window);
1429 if (ev_window->priv->history)
1430 g_object_unref (ev_window->priv->history);
1431 ev_window->priv->history = ev_history_new ();
1432 action = gtk_action_group_get_action (ev_window->priv->action_group, NAVIGATION_ACTION);
1433 ev_navigation_action_set_history (EV_NAVIGATION_ACTION (action), ev_window->priv->history);
1435 if (ev_window->priv->properties) {
1436 ev_properties_dialog_set_document (EV_PROPERTIES_DIALOG (ev_window->priv->properties),
1437 ev_window->priv->uri,
1438 ev_window->priv->document);
1441 info = ev_document_get_info (document);
1442 update_document_mode (ev_window, info->mode);
1444 if (EV_WINDOW_IS_PRESENTATION (ev_window))
1445 gtk_widget_grab_focus (ev_window->priv->presentation_view);
1447 gtk_widget_grab_focus (ev_window->priv->view);
1453 ev_window_set_document (EvWindow *ev_window, EvDocument *document)
1455 if (ev_window->priv->document == document)
1458 if (ev_window->priv->document)
1459 g_object_unref (ev_window->priv->document);
1460 ev_window->priv->document = g_object_ref (document);
1462 ev_window_update_max_min_scale (ev_window);
1464 ev_window_set_message_area (ev_window, NULL);
1466 if (ev_document_get_n_pages (document) <= 0) {
1467 ev_window_warning_message (ev_window, "%s",
1468 _("The document contains no pages"));
1469 } else if (!ev_document_check_dimensions (document)) {
1470 ev_window_warning_message (ev_window, "%s",
1471 _("The document contains only empty pages"));
1474 if (EV_WINDOW_IS_PRESENTATION (ev_window)) {
1477 current_page = ev_view_presentation_get_current_page (
1478 EV_VIEW_PRESENTATION (ev_window->priv->presentation_view));
1479 gtk_widget_destroy (ev_window->priv->presentation_view);
1480 ev_window->priv->presentation_view = NULL;
1482 /* Update the model with the current presentation page */
1483 ev_document_model_set_page (ev_window->priv->model, current_page);
1484 ev_window_run_presentation (ev_window);
1487 if (ev_window->priv->setup_document_idle > 0)
1488 g_source_remove (ev_window->priv->setup_document_idle);
1490 ev_window->priv->setup_document_idle = g_idle_add ((GSourceFunc)ev_window_setup_document, ev_window);
1494 ev_window_document_changed (EvWindow *ev_window,
1497 ev_window_reload_document (ev_window, NULL);
1501 ev_window_password_view_unlock (EvWindow *ev_window)
1503 const gchar *password;
1505 g_assert (ev_window->priv->load_job);
1507 password = ev_password_view_get_password (EV_PASSWORD_VIEW (ev_window->priv->password_view));
1508 ev_job_load_set_password (EV_JOB_LOAD (ev_window->priv->load_job), password);
1509 ev_job_scheduler_push_job (ev_window->priv->load_job, EV_JOB_PRIORITY_NONE);
1513 ev_window_clear_load_job (EvWindow *ev_window)
1515 if (ev_window->priv->load_job != NULL) {
1516 if (!ev_job_is_finished (ev_window->priv->load_job))
1517 ev_job_cancel (ev_window->priv->load_job);
1519 g_signal_handlers_disconnect_by_func (ev_window->priv->load_job, ev_window_load_job_cb, ev_window);
1520 g_object_unref (ev_window->priv->load_job);
1521 ev_window->priv->load_job = NULL;
1526 ev_window_clear_reload_job (EvWindow *ev_window)
1528 if (ev_window->priv->reload_job != NULL) {
1529 if (!ev_job_is_finished (ev_window->priv->reload_job))
1530 ev_job_cancel (ev_window->priv->reload_job);
1532 g_signal_handlers_disconnect_by_func (ev_window->priv->reload_job, ev_window_reload_job_cb, ev_window);
1533 g_object_unref (ev_window->priv->reload_job);
1534 ev_window->priv->reload_job = NULL;
1539 ev_window_clear_local_uri (EvWindow *ev_window)
1541 if (ev_window->priv->local_uri) {
1542 ev_tmp_uri_unlink (ev_window->priv->local_uri);
1543 g_free (ev_window->priv->local_uri);
1544 ev_window->priv->local_uri = NULL;
1549 ev_window_handle_link (EvWindow *ev_window,
1554 EvLinkAction *link_action;
1556 link_action = ev_link_action_new_dest (dest);
1557 link = ev_link_new (NULL, link_action);
1558 ev_view_handle_link (EV_VIEW (ev_window->priv->view), link);
1559 g_object_unref (link);
1563 /* This callback will executed when load job will be finished.
1565 * Since the flow of the error dialog is very confusing, we assume that both
1566 * document and uri will go away after this function is called, and thus we need
1567 * to ref/dup them. Additionally, it needs to clear
1568 * ev_window->priv->password_{uri,document}, and thus people who call this
1569 * function should _not_ necessarily expect those to exist after being
1572 ev_window_load_job_cb (EvJob *job,
1575 EvWindow *ev_window = EV_WINDOW (data);
1576 EvDocument *document = EV_JOB (job)->document;
1577 EvJobLoad *job_load = EV_JOB_LOAD (job);
1579 g_assert (job_load->uri);
1581 ev_view_set_loading (EV_VIEW (ev_window->priv->view), FALSE);
1584 if (!ev_job_is_failed (job)) {
1585 ev_document_model_set_document (ev_window->priv->model, document);
1588 ev_window_emit_doc_loaded (ev_window);
1590 setup_chrome_from_metadata (ev_window);
1591 update_chrome_actions (ev_window);
1592 setup_document_from_metadata (ev_window);
1593 setup_view_from_metadata (ev_window);
1595 ev_window_add_recent (ev_window, ev_window->priv->uri);
1597 ev_window_title_set_type (ev_window->priv->title,
1598 EV_WINDOW_TITLE_DOCUMENT);
1599 if (job_load->password) {
1600 GPasswordSave flags;
1602 flags = ev_password_view_get_password_save_flags (
1603 EV_PASSWORD_VIEW (ev_window->priv->password_view));
1604 ev_keyring_save_password (ev_window->priv->uri,
1609 ev_window_handle_link (ev_window, ev_window->priv->dest);
1610 /* Already unrefed by ev_link_action
1611 * FIXME: link action should inc dest ref counting
1612 * or not unref it at all
1614 ev_window->priv->dest = NULL;
1616 switch (ev_window->priv->window_mode) {
1617 case EV_WINDOW_MODE_FULLSCREEN:
1618 ev_window_run_fullscreen (ev_window);
1620 case EV_WINDOW_MODE_PRESENTATION:
1621 ev_window_run_presentation (ev_window);
1627 if (ev_window->priv->search_string && EV_IS_DOCUMENT_FIND (document)) {
1628 ev_window_cmd_edit_find (NULL, ev_window);
1629 egg_find_bar_set_search_string (EGG_FIND_BAR (ev_window->priv->find_bar),
1630 ev_window->priv->search_string);
1633 g_free (ev_window->priv->search_string);
1634 ev_window->priv->search_string = NULL;
1636 /* Create a monitor for the document */
1637 ev_window->priv->monitor = ev_file_monitor_new (ev_window->priv->uri);
1638 g_signal_connect_swapped (ev_window->priv->monitor, "changed",
1639 G_CALLBACK (ev_window_document_changed),
1642 ev_window_clear_load_job (ev_window);
1646 if (g_error_matches (job->error, EV_DOCUMENT_ERROR, EV_DOCUMENT_ERROR_ENCRYPTED)) {
1649 setup_view_from_metadata (ev_window);
1651 /* First look whether password is in keyring */
1652 password = ev_keyring_lookup_password (ev_window->priv->uri);
1654 if (job_load->password && strcmp (password, job_load->password) == 0) {
1655 /* Password in kering is wrong */
1656 ev_job_load_set_password (job_load, NULL);
1657 /* FIXME: delete password from keyring? */
1659 ev_job_load_set_password (job_load, password);
1660 ev_job_scheduler_push_job (job, EV_JOB_PRIORITY_NONE);
1668 /* We need to ask the user for a password */
1669 ev_window_title_set_uri (ev_window->priv->title,
1670 ev_window->priv->uri);
1671 ev_window_title_set_type (ev_window->priv->title,
1672 EV_WINDOW_TITLE_PASSWORD);
1674 ev_password_view_set_uri (EV_PASSWORD_VIEW (ev_window->priv->password_view),
1677 ev_window_set_page_mode (ev_window, PAGE_MODE_PASSWORD);
1679 ev_job_load_set_password (job_load, NULL);
1680 ev_password_view_ask_password (EV_PASSWORD_VIEW (ev_window->priv->password_view));
1682 ev_window_error_message (ev_window, job->error,
1683 "%s", _("Unable to open document"));
1684 ev_window_clear_load_job (ev_window);
1689 ev_window_reload_job_cb (EvJob *job,
1690 EvWindow *ev_window)
1694 if (ev_job_is_failed (job)) {
1695 ev_window_clear_reload_job (ev_window);
1696 ev_window->priv->in_reload = FALSE;
1697 if (ev_window->priv->dest) {
1698 g_object_unref (ev_window->priv->dest);
1699 ev_window->priv->dest = NULL;
1705 ev_document_model_set_document (ev_window->priv->model,
1707 if (ev_window->priv->dest) {
1708 ev_window_handle_link (ev_window, ev_window->priv->dest);
1709 /* Already unrefed by ev_link_action
1710 * FIXME: link action should inc dest ref counting
1711 * or not unref it at all
1713 ev_window->priv->dest = NULL;
1716 /* Restart the search after reloading */
1717 widget = gtk_window_get_focus (GTK_WINDOW (ev_window));
1718 if (widget && gtk_widget_get_ancestor (widget, EGG_TYPE_FIND_BAR)) {
1719 find_bar_search_changed_cb (EGG_FIND_BAR (ev_window->priv->find_bar),
1723 ev_window_clear_reload_job (ev_window);
1724 ev_window->priv->in_reload = FALSE;
1728 * ev_window_get_uri:
1729 * @ev_window: The instance of the #EvWindow.
1731 * It returns the uri of the document showed in the #EvWindow.
1733 * Returns: the uri of the document showed in the #EvWindow.
1736 ev_window_get_uri (EvWindow *ev_window)
1738 return ev_window->priv->uri;
1742 * ev_window_close_dialogs:
1743 * @ev_window: The window where dialogs will be closed.
1745 * It looks for password, print and properties dialogs and closes them and
1746 * frees them from memory. If there is any print job it does free it too.
1749 ev_window_close_dialogs (EvWindow *ev_window)
1751 if (ev_window->priv->print_dialog)
1752 gtk_widget_destroy (ev_window->priv->print_dialog);
1753 ev_window->priv->print_dialog = NULL;
1755 if (ev_window->priv->properties)
1756 gtk_widget_destroy (ev_window->priv->properties);
1757 ev_window->priv->properties = NULL;
1761 ev_window_clear_progress_idle (EvWindow *ev_window)
1763 if (ev_window->priv->progress_idle > 0)
1764 g_source_remove (ev_window->priv->progress_idle);
1765 ev_window->priv->progress_idle = 0;
1769 reset_progress_idle (EvWindow *ev_window)
1771 ev_window->priv->progress_idle = 0;
1775 ev_window_show_progress_message (EvWindow *ev_window,
1777 GSourceFunc function)
1779 if (ev_window->priv->progress_idle > 0)
1780 g_source_remove (ev_window->priv->progress_idle);
1781 ev_window->priv->progress_idle =
1782 g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
1785 (GDestroyNotify)reset_progress_idle);
1789 ev_window_reset_progress_cancellable (EvWindow *ev_window)
1791 if (ev_window->priv->progress_cancellable)
1792 g_cancellable_reset (ev_window->priv->progress_cancellable);
1794 ev_window->priv->progress_cancellable = g_cancellable_new ();
1798 ev_window_progress_response_cb (EvProgressMessageArea *area,
1800 EvWindow *ev_window)
1802 if (response == GTK_RESPONSE_CANCEL)
1803 g_cancellable_cancel (ev_window->priv->progress_cancellable);
1804 ev_window_set_message_area (ev_window, NULL);
1808 show_loading_progress (EvWindow *ev_window)
1812 gchar *display_name;
1814 if (ev_window->priv->message_area)
1817 text = g_uri_unescape_string (ev_window->priv->uri, NULL);
1818 display_name = g_markup_escape_text (text, -1);
1820 text = g_strdup_printf (_("Loading document from “%s”"),
1823 area = ev_progress_message_area_new (GTK_STOCK_OPEN,
1828 GTK_RESPONSE_CANCEL,
1830 g_signal_connect (area, "response",
1831 G_CALLBACK (ev_window_progress_response_cb),
1833 gtk_widget_show (area);
1834 ev_window_set_message_area (ev_window, area);
1837 g_free (display_name);
1843 ev_window_load_remote_failed (EvWindow *ev_window,
1846 ev_view_set_loading (EV_VIEW (ev_window->priv->view), FALSE);
1847 ev_window->priv->in_reload = FALSE;
1848 ev_window_error_message (ev_window, error,
1849 "%s", _("Unable to open document"));
1850 g_free (ev_window->priv->local_uri);
1851 ev_window->priv->local_uri = NULL;
1852 ev_window->priv->uri_mtime = 0;
1856 set_uri_mtime (GFile *source,
1857 GAsyncResult *async_result,
1858 EvWindow *ev_window)
1861 GError *error = NULL;
1863 info = g_file_query_info_finish (source, async_result, &error);
1866 ev_window->priv->uri_mtime = 0;
1867 g_error_free (error);
1871 g_file_info_get_modification_time (info, &mtime);
1872 ev_window->priv->uri_mtime = mtime.tv_sec;
1873 g_object_unref (info);
1876 g_object_unref (source);
1880 mount_volume_ready_cb (GFile *source,
1881 GAsyncResult *async_result,
1882 EvWindow *ev_window)
1884 GError *error = NULL;
1886 g_file_mount_enclosing_volume_finish (source, async_result, &error);
1889 ev_window_load_remote_failed (ev_window, error);
1890 g_object_unref (source);
1891 g_error_free (error);
1893 /* Volume successfully mounted,
1894 try opening the file again */
1895 ev_window_load_file_remote (ev_window, source);
1900 window_open_file_copy_ready_cb (GFile *source,
1901 GAsyncResult *async_result,
1902 EvWindow *ev_window)
1904 GError *error = NULL;
1906 ev_window_clear_progress_idle (ev_window);
1907 ev_window_set_message_area (ev_window, NULL);
1909 g_file_copy_finish (source, async_result, &error);
1911 ev_job_scheduler_push_job (ev_window->priv->load_job, EV_JOB_PRIORITY_NONE);
1912 g_file_query_info_async (source,
1913 G_FILE_ATTRIBUTE_TIME_MODIFIED,
1914 0, G_PRIORITY_DEFAULT,
1916 (GAsyncReadyCallback)set_uri_mtime,
1921 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_MOUNTED)) {
1922 GMountOperation *operation;
1924 operation = gtk_mount_operation_new (GTK_WINDOW (ev_window));
1925 g_file_mount_enclosing_volume (source,
1928 (GAsyncReadyCallback)mount_volume_ready_cb,
1930 g_object_unref (operation);
1931 } else if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
1932 ev_window_clear_load_job (ev_window);
1933 ev_window_clear_local_uri (ev_window);
1934 g_free (ev_window->priv->uri);
1935 ev_window->priv->uri = NULL;
1936 g_object_unref (source);
1938 ev_view_set_loading (EV_VIEW (ev_window->priv->view), FALSE);
1940 ev_window_load_remote_failed (ev_window, error);
1941 g_object_unref (source);
1944 g_error_free (error);
1948 window_open_file_copy_progress_cb (goffset n_bytes,
1949 goffset total_bytes,
1950 EvWindow *ev_window)
1955 if (!ev_window->priv->message_area)
1958 if (total_bytes <= 0)
1961 fraction = n_bytes / (gdouble)total_bytes;
1962 status = g_strdup_printf (_("Downloading document (%d%%)"),
1963 (gint)(fraction * 100));
1965 ev_progress_message_area_set_status (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
1967 ev_progress_message_area_set_fraction (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
1974 ev_window_load_file_remote (EvWindow *ev_window,
1979 if (!ev_window->priv->local_uri) {
1980 char *base_name, *template;
1984 /* We'd like to keep extension of source uri since
1985 * it helps to resolve some mime types, say cbz.
1987 base_name = g_file_get_basename (source_file);
1988 template = g_strdup_printf ("document.XXXXXX-%s", base_name);
1991 tmp_file = ev_mkstemp_file (template, &err);
1993 if (tmp_file == NULL) {
1994 ev_window_error_message (ev_window, err,
1995 "%s", _("Failed to load remote file."));
2000 ev_window->priv->local_uri = g_file_get_uri (tmp_file);
2001 g_object_unref (tmp_file);
2003 ev_job_load_set_uri (EV_JOB_LOAD (ev_window->priv->load_job),
2004 ev_window->priv->local_uri);
2007 ev_window_reset_progress_cancellable (ev_window);
2009 target_file = g_file_new_for_uri (ev_window->priv->local_uri);
2010 g_file_copy_async (source_file, target_file,
2011 G_FILE_COPY_OVERWRITE,
2013 ev_window->priv->progress_cancellable,
2014 (GFileProgressCallback)window_open_file_copy_progress_cb,
2016 (GAsyncReadyCallback)window_open_file_copy_ready_cb,
2018 g_object_unref (target_file);
2020 ev_window_show_progress_message (ev_window, 1,
2021 (GSourceFunc)show_loading_progress);
2025 ev_window_open_uri (EvWindow *ev_window,
2028 EvWindowRunMode mode,
2029 const gchar *search_string)
2033 ev_window->priv->in_reload = FALSE;
2035 if (ev_window->priv->uri &&
2036 g_ascii_strcasecmp (ev_window->priv->uri, uri) == 0) {
2037 ev_window_reload_document (ev_window, dest);
2041 if (ev_window->priv->monitor) {
2042 g_object_unref (ev_window->priv->monitor);
2043 ev_window->priv->monitor = NULL;
2046 ev_window_close_dialogs (ev_window);
2047 ev_window_clear_load_job (ev_window);
2048 ev_window_clear_local_uri (ev_window);
2050 ev_window->priv->window_mode = mode;
2052 if (ev_window->priv->uri)
2053 g_free (ev_window->priv->uri);
2054 ev_window->priv->uri = g_strdup (uri);
2056 if (ev_window->priv->metadata)
2057 g_object_unref (ev_window->priv->metadata);
2058 if (ev_window->priv->bookmarks)
2059 g_object_unref (ev_window->priv->bookmarks);
2061 source_file = g_file_new_for_uri (uri);
2062 if (!ev_file_is_temp (source_file) && ev_is_metadata_supported_for_file (source_file)) {
2063 ev_window->priv->metadata = ev_metadata_new (source_file);
2064 ev_window->priv->is_new_doc = ev_metadata_is_empty (ev_window->priv->metadata);
2066 ev_window->priv->metadata = NULL;
2069 if (ev_window->priv->metadata) {
2070 ev_window->priv->bookmarks = ev_bookmarks_new (ev_window->priv->metadata);
2071 ev_sidebar_bookmarks_set_bookmarks (EV_SIDEBAR_BOOKMARKS (ev_window->priv->sidebar_bookmarks),
2072 ev_window->priv->bookmarks);
2073 g_signal_connect_swapped (ev_window->priv->bookmarks, "changed",
2074 G_CALLBACK (ev_window_setup_bookmarks),
2077 ev_window->priv->bookmarks = NULL;
2080 if (ev_window->priv->search_string)
2081 g_free (ev_window->priv->search_string);
2082 ev_window->priv->search_string = search_string ?
2083 g_strdup (search_string) : NULL;
2085 if (ev_window->priv->dest)
2086 g_object_unref (ev_window->priv->dest);
2087 ev_window->priv->dest = dest ? g_object_ref (dest) : NULL;
2089 setup_size_from_metadata (ev_window);
2090 setup_model_from_metadata (ev_window);
2091 ev_window_setup_bookmarks (ev_window);
2093 ev_window->priv->load_job = ev_job_load_new (uri);
2094 g_signal_connect (ev_window->priv->load_job,
2096 G_CALLBACK (ev_window_load_job_cb),
2099 if (!g_file_is_native (source_file) && !ev_window->priv->local_uri) {
2100 ev_window_load_file_remote (ev_window, source_file);
2102 ev_view_set_loading (EV_VIEW (ev_window->priv->view), TRUE);
2103 g_object_unref (source_file);
2104 ev_job_scheduler_push_job (ev_window->priv->load_job, EV_JOB_PRIORITY_NONE);
2109 ev_window_open_document (EvWindow *ev_window,
2110 EvDocument *document,
2112 EvWindowRunMode mode,
2113 const gchar *search_string)
2115 if (document == ev_window->priv->document)
2118 ev_window_close_dialogs (ev_window);
2119 ev_window_clear_load_job (ev_window);
2120 ev_window_clear_local_uri (ev_window);
2122 if (ev_window->priv->monitor) {
2123 g_object_unref (ev_window->priv->monitor);
2124 ev_window->priv->monitor = NULL;
2127 if (ev_window->priv->uri)
2128 g_free (ev_window->priv->uri);
2129 ev_window->priv->uri = g_strdup (ev_document_get_uri (document));
2131 setup_size_from_metadata (ev_window);
2132 setup_model_from_metadata (ev_window);
2134 ev_document_model_set_document (ev_window->priv->model, document);
2136 setup_document_from_metadata (ev_window);
2137 setup_view_from_metadata (ev_window);
2141 EvLinkAction *link_action;
2143 link_action = ev_link_action_new_dest (dest);
2144 link = ev_link_new (NULL, link_action);
2145 ev_view_handle_link (EV_VIEW (ev_window->priv->view), link);
2146 /* FIXME: link action should inc dest ref counting
2147 * or not unref it at all
2149 g_object_ref (dest);
2150 g_object_unref (link);
2154 case EV_WINDOW_MODE_FULLSCREEN:
2155 ev_window_run_fullscreen (ev_window);
2157 case EV_WINDOW_MODE_PRESENTATION:
2158 ev_window_run_presentation (ev_window);
2164 if (search_string && EV_IS_DOCUMENT_FIND (document)) {
2165 ev_window_cmd_edit_find (NULL, ev_window);
2166 egg_find_bar_set_search_string (EGG_FIND_BAR (ev_window->priv->find_bar),
2170 /* Create a monitor for the document */
2171 ev_window->priv->monitor = ev_file_monitor_new (ev_window->priv->uri);
2172 g_signal_connect_swapped (ev_window->priv->monitor, "changed",
2173 G_CALLBACK (ev_window_document_changed),
2178 ev_window_reload_local (EvWindow *ev_window)
2182 uri = ev_window->priv->local_uri ? ev_window->priv->local_uri : ev_window->priv->uri;
2183 ev_window->priv->reload_job = ev_job_load_new (uri);
2184 g_signal_connect (ev_window->priv->reload_job, "finished",
2185 G_CALLBACK (ev_window_reload_job_cb),
2187 ev_job_scheduler_push_job (ev_window->priv->reload_job, EV_JOB_PRIORITY_NONE);
2191 show_reloading_progress (EvWindow *ev_window)
2196 if (ev_window->priv->message_area)
2199 text = g_strdup_printf (_("Reloading document from %s"),
2200 ev_window->priv->uri);
2201 area = ev_progress_message_area_new (GTK_STOCK_REFRESH,
2206 GTK_RESPONSE_CANCEL,
2208 g_signal_connect (area, "response",
2209 G_CALLBACK (ev_window_progress_response_cb),
2211 gtk_widget_show (area);
2212 ev_window_set_message_area (ev_window, area);
2219 reload_remote_copy_ready_cb (GFile *remote,
2220 GAsyncResult *async_result,
2221 EvWindow *ev_window)
2223 GError *error = NULL;
2225 ev_window_clear_progress_idle (ev_window);
2227 g_file_copy_finish (remote, async_result, &error);
2229 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
2230 ev_window_error_message (ev_window, error,
2231 "%s", _("Failed to reload document."));
2232 g_error_free (error);
2234 ev_window_reload_local (ev_window);
2237 g_object_unref (remote);
2241 reload_remote_copy_progress_cb (goffset n_bytes,
2242 goffset total_bytes,
2243 EvWindow *ev_window)
2248 if (!ev_window->priv->message_area)
2251 if (total_bytes <= 0)
2254 fraction = n_bytes / (gdouble)total_bytes;
2255 status = g_strdup_printf (_("Downloading document (%d%%)"),
2256 (gint)(fraction * 100));
2258 ev_progress_message_area_set_status (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
2260 ev_progress_message_area_set_fraction (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
2267 query_remote_uri_mtime_cb (GFile *remote,
2268 GAsyncResult *async_result,
2269 EvWindow *ev_window)
2273 GError *error = NULL;
2275 info = g_file_query_info_finish (remote, async_result, &error);
2277 g_error_free (error);
2278 g_object_unref (remote);
2279 ev_window_reload_local (ev_window);
2284 g_file_info_get_modification_time (info, &mtime);
2285 if (ev_window->priv->uri_mtime != mtime.tv_sec) {
2288 /* Remote file has changed */
2289 ev_window->priv->uri_mtime = mtime.tv_sec;
2291 ev_window_reset_progress_cancellable (ev_window);
2293 target_file = g_file_new_for_uri (ev_window->priv->local_uri);
2294 g_file_copy_async (remote, target_file,
2295 G_FILE_COPY_OVERWRITE,
2297 ev_window->priv->progress_cancellable,
2298 (GFileProgressCallback)reload_remote_copy_progress_cb,
2300 (GAsyncReadyCallback)reload_remote_copy_ready_cb,
2302 g_object_unref (target_file);
2303 ev_window_show_progress_message (ev_window, 1,
2304 (GSourceFunc)show_reloading_progress);
2306 g_object_unref (remote);
2307 ev_window_reload_local (ev_window);
2310 g_object_unref (info);
2314 ev_window_reload_remote (EvWindow *ev_window)
2318 remote = g_file_new_for_uri (ev_window->priv->uri);
2319 /* Reload the remote uri only if it has changed */
2320 g_file_query_info_async (remote,
2321 G_FILE_ATTRIBUTE_TIME_MODIFIED,
2322 0, G_PRIORITY_DEFAULT,
2324 (GAsyncReadyCallback)query_remote_uri_mtime_cb,
2329 ev_window_reload_document (EvWindow *ev_window,
2335 ev_window_clear_reload_job (ev_window);
2336 ev_window->priv->in_reload = TRUE;
2338 page = ev_document_model_get_page (ev_window->priv->model);
2340 if (ev_window->priv->dest)
2341 g_object_unref (ev_window->priv->dest);
2342 ev_window->priv->dest = dest ? g_object_ref (dest) : NULL;
2344 if (ev_window->priv->local_uri) {
2345 ev_window_reload_remote (ev_window);
2347 ev_window_reload_local (ev_window);
2352 file_open_dialog_response_cb (GtkWidget *chooser,
2354 EvWindow *ev_window)
2356 if (response_id == GTK_RESPONSE_OK) {
2360 uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (chooser));
2362 ev_application_open_uri_list (EV_APP, uris,
2363 gtk_window_get_screen (GTK_WINDOW (ev_window)),
2364 gtk_get_current_event_time ());
2366 g_slist_foreach (uris, (GFunc)g_free, NULL);
2367 g_slist_free (uris);
2369 uri = gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (chooser));
2370 ev_application_set_filechooser_uri (EV_APP,
2371 GTK_FILE_CHOOSER_ACTION_OPEN,
2376 gtk_widget_destroy (chooser);
2380 ev_window_cmd_file_open (GtkAction *action, EvWindow *window)
2383 const gchar *default_uri;
2384 gchar *parent_uri = NULL;
2386 chooser = gtk_file_chooser_dialog_new (_("Open Document"),
2387 GTK_WINDOW (window),
2388 GTK_FILE_CHOOSER_ACTION_OPEN,
2390 GTK_RESPONSE_CANCEL,
2391 GTK_STOCK_OPEN, GTK_RESPONSE_OK,
2394 ev_document_factory_add_filters (chooser, NULL);
2395 gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (chooser), TRUE);
2396 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser), FALSE);
2398 default_uri = ev_application_get_filechooser_uri (EV_APP, GTK_FILE_CHOOSER_ACTION_OPEN);
2399 if (!default_uri && window->priv->uri) {
2400 GFile *file, *parent;
2402 file = g_file_new_for_uri (window->priv->uri);
2403 parent = g_file_get_parent (file);
2405 parent_uri = g_file_get_uri (parent);
2406 default_uri = parent_uri;
2407 g_object_unref (parent);
2409 g_object_unref (file);
2413 gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (chooser), default_uri);
2415 const gchar *folder;
2417 folder = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
2418 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser),
2419 folder ? folder : g_get_home_dir ());
2421 g_free (parent_uri);
2423 g_signal_connect (chooser, "response",
2424 G_CALLBACK (file_open_dialog_response_cb),
2427 gtk_widget_show (chooser);
2431 ev_window_open_copy_at_dest (EvWindow *window,
2434 EvWindow *new_window = EV_WINDOW (ev_window_new ());
2436 ev_window_n_copies++;
2438 if (window->priv->metadata)
2439 new_window->priv->metadata = g_object_ref (window->priv->metadata);
2440 ev_window_open_document (new_window,
2441 window->priv->document,
2443 gtk_window_present (GTK_WINDOW (new_window));
2447 ev_window_cmd_file_open_copy (GtkAction *action, EvWindow *window)
2449 ev_window_open_copy_at_dest (window, NULL);
2453 ev_window_cmd_recent_file_activate (GtkAction *action,
2456 GtkRecentInfo *info;
2459 info = g_object_get_data (G_OBJECT (action), "gtk-recent-info");
2460 g_assert (info != NULL);
2462 uri = gtk_recent_info_get_uri (info);
2464 ev_application_open_uri_at_dest (EV_APP, uri,
2465 gtk_window_get_screen (GTK_WINDOW (window)),
2466 NULL, 0, NULL, gtk_get_current_event_time ());
2470 ev_window_open_recent_action_item_activated (EvOpenRecentAction *action,
2474 ev_application_open_uri_at_dest (EV_APP, uri,
2475 gtk_window_get_screen (GTK_WINDOW (window)),
2476 NULL, 0, NULL, gtk_get_current_event_time ());
2480 ev_window_add_recent (EvWindow *window, const char *filename)
2482 gtk_recent_manager_add_item (window->priv->recent_manager, filename);
2486 compare_recent_items (GtkRecentInfo *a, GtkRecentInfo *b)
2488 gboolean has_ev_a, has_ev_b;
2489 const gchar *evince = g_get_application_name ();
2491 has_ev_a = gtk_recent_info_has_application (a, evince);
2492 has_ev_b = gtk_recent_info_has_application (b, evince);
2494 if (has_ev_a && has_ev_b) {
2495 time_t time_a, time_b;
2497 time_a = gtk_recent_info_get_modified (a);
2498 time_b = gtk_recent_info_get_modified (b);
2500 return (time_b - time_a);
2501 } else if (has_ev_a) {
2503 } else if (has_ev_b) {
2511 * Doubles underscore to avoid spurious menu accels.
2514 ev_window_get_recent_file_label (gint index, const gchar *filename)
2522 is_rtl = (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL);
2524 g_return_val_if_fail (filename != NULL, NULL);
2526 length = strlen (filename);
2527 str = g_string_sized_new (length + 10);
2528 g_string_printf (str, "%s_%d. ", is_rtl ? "\xE2\x80\x8F" : "", index);
2531 end = filename + length;
2535 next = g_utf8_next_char (p);
2539 g_string_append (str, "__");
2542 g_string_append_len (str, p, next - p);
2549 return g_string_free (str, FALSE);
2553 ev_window_recent_action_connect_proxy_cb (GtkActionGroup *action_group,
2560 if (!GTK_IS_MENU_ITEM (proxy))
2563 label = GTK_LABEL (gtk_bin_get_child (GTK_BIN (proxy)));
2565 gtk_label_set_ellipsize (label, PANGO_ELLIPSIZE_MIDDLE);
2566 gtk_label_set_max_width_chars (label, MAX_RECENT_ITEM_LEN);
2570 ev_window_setup_recent (EvWindow *ev_window)
2574 const gchar *evince = g_get_application_name ();
2577 if (ev_window->priv->recent_ui_id > 0) {
2578 gtk_ui_manager_remove_ui (ev_window->priv->ui_manager,
2579 ev_window->priv->recent_ui_id);
2580 gtk_ui_manager_ensure_update (ev_window->priv->ui_manager);
2582 ev_window->priv->recent_ui_id = gtk_ui_manager_new_merge_id (ev_window->priv->ui_manager);
2584 if (ev_window->priv->recent_action_group) {
2585 gtk_ui_manager_remove_action_group (ev_window->priv->ui_manager,
2586 ev_window->priv->recent_action_group);
2587 g_object_unref (ev_window->priv->recent_action_group);
2589 ev_window->priv->recent_action_group = gtk_action_group_new ("RecentFilesActions");
2590 g_signal_connect (ev_window->priv->recent_action_group, "connect-proxy",
2591 G_CALLBACK (ev_window_recent_action_connect_proxy_cb), NULL);
2593 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
2594 ev_window->priv->recent_action_group, -1);
2596 items = gtk_recent_manager_get_items (ev_window->priv->recent_manager);
2597 items = g_list_sort (items, (GCompareFunc) compare_recent_items);
2599 for (l = items; l && l->data; l = g_list_next (l)) {
2600 GtkRecentInfo *info;
2604 const gchar *mime_type;
2605 gchar *content_type;
2608 info = (GtkRecentInfo *) l->data;
2610 if (!gtk_recent_info_has_application (info, evince) ||
2611 (gtk_recent_info_is_local (info) && !gtk_recent_info_exists (info)))
2614 action_name = g_strdup_printf ("RecentFile%u", i++);
2615 label = ev_window_get_recent_file_label (
2616 n_items + 1, gtk_recent_info_get_display_name (info));
2618 mime_type = gtk_recent_info_get_mime_type (info);
2619 content_type = g_content_type_from_mime_type (mime_type);
2620 if (content_type != NULL) {
2621 icon = g_content_type_get_icon (content_type);
2622 g_free (content_type);
2625 action = g_object_new (GTK_TYPE_ACTION,
2626 "name", action_name,
2629 "always-show-image", TRUE,
2632 g_object_set_data_full (G_OBJECT (action),
2634 gtk_recent_info_ref (info),
2635 (GDestroyNotify) gtk_recent_info_unref);
2637 g_signal_connect (action, "activate",
2638 G_CALLBACK (ev_window_cmd_recent_file_activate),
2639 (gpointer) ev_window);
2641 gtk_action_group_add_action (ev_window->priv->recent_action_group,
2643 g_object_unref (action);
2645 gtk_ui_manager_add_ui (ev_window->priv->ui_manager,
2646 ev_window->priv->recent_ui_id,
2647 "/MainMenu/FileMenu/RecentFilesMenu",
2650 GTK_UI_MANAGER_MENUITEM,
2652 g_free (action_name);
2655 g_object_unref (icon);
2661 g_list_foreach (items, (GFunc) gtk_recent_info_unref, NULL);
2662 g_list_free (items);
2666 show_saving_progress (GFile *dst)
2668 EvWindow *ev_window;
2672 EvSaveType save_type;
2674 ev_window = EV_WINDOW (g_object_get_data (G_OBJECT (dst), "ev-window"));
2675 ev_window->priv->progress_idle = 0;
2677 if (ev_window->priv->message_area)
2680 save_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dst), "save-type"));
2681 uri = g_file_get_uri (dst);
2682 switch (save_type) {
2683 case EV_SAVE_DOCUMENT:
2684 text = g_strdup_printf (_("Saving document to %s"), uri);
2686 case EV_SAVE_ATTACHMENT:
2687 text = g_strdup_printf (_("Saving attachment to %s"), uri);
2690 text = g_strdup_printf (_("Saving image to %s"), uri);
2693 g_assert_not_reached ();
2696 area = ev_progress_message_area_new (GTK_STOCK_SAVE,
2701 GTK_RESPONSE_CANCEL,
2703 g_signal_connect (area, "response",
2704 G_CALLBACK (ev_window_progress_response_cb),
2706 gtk_widget_show (area);
2707 ev_window_set_message_area (ev_window, area);
2714 window_save_file_copy_ready_cb (GFile *src,
2715 GAsyncResult *async_result,
2718 EvWindow *ev_window;
2719 GError *error = NULL;
2721 ev_window = EV_WINDOW (g_object_get_data (G_OBJECT (dst), "ev-window"));
2722 ev_window_clear_progress_idle (ev_window);
2724 if (g_file_copy_finish (src, async_result, &error)) {
2725 ev_tmp_file_unlink (src);
2729 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
2732 name = g_file_get_basename (dst);
2733 ev_window_error_message (ev_window, error,
2734 _("The file could not be saved as “%s”."),
2738 ev_tmp_file_unlink (src);
2739 g_error_free (error);
2743 window_save_file_copy_progress_cb (goffset n_bytes,
2744 goffset total_bytes,
2747 EvWindow *ev_window;
2748 EvSaveType save_type;
2752 ev_window = EV_WINDOW (g_object_get_data (G_OBJECT (dst), "ev-window"));
2754 if (!ev_window->priv->message_area)
2757 if (total_bytes <= 0)
2760 fraction = n_bytes / (gdouble)total_bytes;
2761 save_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dst), "save-type"));
2763 switch (save_type) {
2764 case EV_SAVE_DOCUMENT:
2765 status = g_strdup_printf (_("Uploading document (%d%%)"),
2766 (gint)(fraction * 100));
2768 case EV_SAVE_ATTACHMENT:
2769 status = g_strdup_printf (_("Uploading attachment (%d%%)"),
2770 (gint)(fraction * 100));
2773 status = g_strdup_printf (_("Uploading image (%d%%)"),
2774 (gint)(fraction * 100));
2777 g_assert_not_reached ();
2780 ev_progress_message_area_set_status (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
2782 ev_progress_message_area_set_fraction (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
2789 ev_window_save_remote (EvWindow *ev_window,
2790 EvSaveType save_type,
2794 ev_window_reset_progress_cancellable (ev_window);
2795 g_object_set_data (G_OBJECT (dst), "ev-window", ev_window);
2796 g_object_set_data (G_OBJECT (dst), "save-type", GINT_TO_POINTER (save_type));
2797 g_file_copy_async (src, dst,
2798 G_FILE_COPY_OVERWRITE,
2800 ev_window->priv->progress_cancellable,
2801 (GFileProgressCallback)window_save_file_copy_progress_cb,
2803 (GAsyncReadyCallback)window_save_file_copy_ready_cb,
2805 ev_window->priv->progress_idle =
2806 g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
2808 (GSourceFunc)show_saving_progress,
2814 ev_window_clear_save_job (EvWindow *ev_window)
2816 if (ev_window->priv->save_job != NULL) {
2817 if (!ev_job_is_finished (ev_window->priv->save_job))
2818 ev_job_cancel (ev_window->priv->save_job);
2820 g_signal_handlers_disconnect_by_func (ev_window->priv->save_job,
2821 ev_window_save_job_cb,
2823 g_object_unref (ev_window->priv->save_job);
2824 ev_window->priv->save_job = NULL;
2829 ev_window_save_job_cb (EvJob *job,
2832 if (ev_job_is_failed (job)) {
2833 ev_window_error_message (window, job->error,
2834 _("The file could not be saved as “%s”."),
2835 EV_JOB_SAVE (job)->uri);
2837 ev_window_add_recent (window, EV_JOB_SAVE (job)->uri);
2840 ev_window_clear_save_job (window);
2844 file_save_dialog_response_cb (GtkWidget *fc,
2846 EvWindow *ev_window)
2849 GFile *file, *parent;
2851 if (response_id != GTK_RESPONSE_OK) {
2852 gtk_widget_destroy (fc);
2856 uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
2857 file = g_file_new_for_uri (uri);
2858 parent = g_file_get_parent (file);
2859 g_object_unref (file);
2863 folder_uri = g_file_get_uri (parent);
2864 ev_application_set_filechooser_uri (EV_APP,
2865 GTK_FILE_CHOOSER_ACTION_SAVE,
2867 g_free (folder_uri);
2868 g_object_unref (parent);
2871 /* FIXME: remote copy should be done here rather than in the save job,
2872 * so that we can track progress and cancel the operation
2875 ev_window_clear_save_job (ev_window);
2876 ev_window->priv->save_job = ev_job_save_new (ev_window->priv->document,
2877 uri, ev_window->priv->uri);
2878 g_signal_connect (ev_window->priv->save_job, "finished",
2879 G_CALLBACK (ev_window_save_job_cb),
2881 /* The priority doesn't matter for this job */
2882 ev_job_scheduler_push_job (ev_window->priv->save_job, EV_JOB_PRIORITY_NONE);
2885 gtk_widget_destroy (fc);
2889 ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window)
2894 const gchar *default_uri;
2896 fc = gtk_file_chooser_dialog_new (
2898 GTK_WINDOW (ev_window), GTK_FILE_CHOOSER_ACTION_SAVE,
2899 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
2900 GTK_STOCK_SAVE, GTK_RESPONSE_OK,
2903 ev_document_factory_add_filters (fc, ev_window->priv->document);
2904 gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
2905 gtk_dialog_set_alternative_button_order (GTK_DIALOG (fc),
2907 GTK_RESPONSE_CANCEL,
2910 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (fc), FALSE);
2911 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
2912 file = g_file_new_for_uri (ev_window->priv->uri);
2913 base_name = g_file_get_basename (file);
2914 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc), base_name);
2916 default_uri = ev_application_get_filechooser_uri (EV_APP, GTK_FILE_CHOOSER_ACTION_SAVE);
2918 gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (fc), default_uri);
2920 const gchar *folder;
2922 folder = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
2923 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (fc),
2924 folder ? folder : g_get_home_dir ());
2927 g_object_unref (file);
2930 g_signal_connect (fc, "response",
2931 G_CALLBACK (file_save_dialog_response_cb),
2934 gtk_widget_show (fc);
2938 ev_window_cmd_open_containing_folder (GtkAction *action, EvWindow *ev_window)
2940 GtkWidget *ev_window_widget;
2944 ev_window_widget = GTK_WIDGET (ev_window);
2946 file = g_file_new_for_uri (ev_window->priv->uri);
2947 parent = g_file_get_parent (file);
2952 parent_uri = g_file_get_uri (parent);
2958 screen = gtk_widget_get_screen (ev_window_widget);
2959 timestamp = gtk_get_current_event_time ();
2962 if (!gtk_show_uri (screen, parent_uri, timestamp, &error)) {
2963 ev_window_error_message (ev_window, error, _("Could not open the containing folder"));
2964 g_error_free (error);
2967 g_free (parent_uri);
2972 g_object_unref (file);
2975 g_object_unref (parent);
2980 get_print_settings_file (void)
2982 GKeyFile *print_settings_file;
2984 GError *error = NULL;
2986 print_settings_file = g_key_file_new ();
2988 filename = g_build_filename (ev_application_get_dot_dir (EV_APP, FALSE),
2989 EV_PRINT_SETTINGS_FILE, NULL);
2990 if (!g_key_file_load_from_file (print_settings_file,
2992 G_KEY_FILE_KEEP_COMMENTS |
2993 G_KEY_FILE_KEEP_TRANSLATIONS,
2996 /* Don't warn if the file simply doesn't exist */
2997 if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
2998 g_warning ("%s", error->message);
3000 g_error_free (error);
3005 return print_settings_file;
3009 save_print_setting_file (GKeyFile *key_file)
3014 GError *error = NULL;
3016 filename = g_build_filename (ev_application_get_dot_dir (EV_APP, TRUE),
3017 EV_PRINT_SETTINGS_FILE, NULL);
3018 data = g_key_file_to_data (key_file, &data_length, NULL);
3019 g_file_set_contents (filename, data, data_length, &error);
3021 g_warning ("Failed to save print settings: %s", error->message);
3022 g_error_free (error);
3029 ev_window_save_print_settings (EvWindow *window,
3030 GtkPrintSettings *print_settings)
3035 key_file = get_print_settings_file ();
3036 gtk_print_settings_to_key_file (print_settings, key_file, EV_PRINT_SETTINGS_GROUP);
3038 /* Save print settings that are specific to the document */
3039 for (i = 0; i < G_N_ELEMENTS (document_print_settings); i++) {
3040 /* Remove it from global settings */
3041 g_key_file_remove_key (key_file, EV_PRINT_SETTINGS_GROUP,
3042 document_print_settings[i], NULL);
3044 if (window->priv->metadata) {
3047 value = gtk_print_settings_get (print_settings,
3048 document_print_settings[i]);
3049 ev_metadata_set_string (window->priv->metadata,
3050 document_print_settings[i], value);
3054 save_print_setting_file (key_file);
3055 g_key_file_free (key_file);
3059 ev_window_save_print_page_setup (EvWindow *window,
3060 GtkPageSetup *page_setup)
3064 key_file = get_print_settings_file ();
3065 gtk_page_setup_to_key_file (page_setup, key_file, EV_PAGE_SETUP_GROUP);
3067 /* Do not save document settings in global file */
3068 g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
3069 "page-setup-orientation", NULL);
3070 g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
3071 "page-setup-margin-top", NULL);
3072 g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
3073 "page-setup-margin-bottom", NULL);
3074 g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
3075 "page-setup-margin-left", NULL);
3076 g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
3077 "page-setup-margin-right", NULL);
3079 save_print_setting_file (key_file);
3080 g_key_file_free (key_file);
3082 if (!window->priv->metadata)
3085 /* Save page setup options that are specific to the document */
3086 ev_metadata_set_int (window->priv->metadata, "page-setup-orientation",
3087 gtk_page_setup_get_orientation (page_setup));
3088 ev_metadata_set_double (window->priv->metadata, "page-setup-margin-top",
3089 gtk_page_setup_get_top_margin (page_setup, GTK_UNIT_MM));
3090 ev_metadata_set_double (window->priv->metadata, "page-setup-margin-bottom",
3091 gtk_page_setup_get_bottom_margin (page_setup, GTK_UNIT_MM));
3092 ev_metadata_set_double (window->priv->metadata, "page-setup-margin-left",
3093 gtk_page_setup_get_left_margin (page_setup, GTK_UNIT_MM));
3094 ev_metadata_set_double (window->priv->metadata, "page-setup-margin-right",
3095 gtk_page_setup_get_right_margin (page_setup, GTK_UNIT_MM));
3099 ev_window_load_print_settings_from_metadata (EvWindow *window,
3100 GtkPrintSettings *print_settings)
3104 if (!window->priv->metadata)
3107 /* Load print setting that are specific to the document */
3108 for (i = 0; i < G_N_ELEMENTS (document_print_settings); i++) {
3109 gchar *value = NULL;
3111 ev_metadata_get_string (window->priv->metadata,
3112 document_print_settings[i], &value);
3113 gtk_print_settings_set (print_settings,
3114 document_print_settings[i], value);
3119 ev_window_load_print_page_setup_from_metadata (EvWindow *window,
3120 GtkPageSetup *page_setup)
3123 gdouble double_value;
3124 GtkPaperSize *paper_size = gtk_page_setup_get_paper_size (page_setup);
3126 /* Load page setup options that are specific to the document */
3127 if (window->priv->metadata &&
3128 ev_metadata_get_int (window->priv->metadata, "page-setup-orientation", &int_value)) {
3129 gtk_page_setup_set_orientation (page_setup, int_value);
3131 gtk_page_setup_set_orientation (page_setup, GTK_PAGE_ORIENTATION_PORTRAIT);
3134 if (window->priv->metadata &&
3135 ev_metadata_get_double (window->priv->metadata, "page-setup-margin-top", &double_value)) {
3136 gtk_page_setup_set_top_margin (page_setup, double_value, GTK_UNIT_MM);
3138 gtk_page_setup_set_top_margin (page_setup,
3139 gtk_paper_size_get_default_top_margin (paper_size, GTK_UNIT_MM),
3143 if (window->priv->metadata &&
3144 ev_metadata_get_double (window->priv->metadata, "page-setup-margin-bottom", &double_value)) {
3145 gtk_page_setup_set_bottom_margin (page_setup, double_value, GTK_UNIT_MM);
3147 gtk_page_setup_set_bottom_margin (page_setup,
3148 gtk_paper_size_get_default_bottom_margin (paper_size, GTK_UNIT_MM),
3152 if (window->priv->metadata &&
3153 ev_metadata_get_double (window->priv->metadata, "page-setup-margin-left", &double_value)) {
3154 gtk_page_setup_set_left_margin (page_setup, double_value, GTK_UNIT_MM);
3156 gtk_page_setup_set_left_margin (page_setup,
3157 gtk_paper_size_get_default_left_margin (paper_size, GTK_UNIT_MM),
3161 if (window->priv->metadata &&
3162 ev_metadata_get_double (window->priv->metadata, "page-setup-margin-right", &double_value)) {
3163 gtk_page_setup_set_right_margin (page_setup, double_value, GTK_UNIT_MM);
3165 gtk_page_setup_set_right_margin (page_setup,
3166 gtk_paper_size_get_default_right_margin (paper_size, GTK_UNIT_MM),
3171 static GtkPrintSettings *
3172 get_print_settings (GKeyFile *key_file)
3174 GtkPrintSettings *print_settings;
3176 print_settings = g_key_file_has_group (key_file, EV_PRINT_SETTINGS_GROUP) ?
3177 gtk_print_settings_new_from_key_file (key_file, EV_PRINT_SETTINGS_GROUP, NULL) :
3178 gtk_print_settings_new ();
3180 return print_settings ? print_settings : gtk_print_settings_new ();
3183 static GtkPageSetup *
3184 get_print_page_setup (GKeyFile *key_file)
3186 GtkPageSetup *page_setup;
3188 page_setup = g_key_file_has_group (key_file, EV_PAGE_SETUP_GROUP) ?
3189 gtk_page_setup_new_from_key_file (key_file, EV_PAGE_SETUP_GROUP, NULL) :
3190 gtk_page_setup_new ();
3192 return page_setup ? page_setup : gtk_page_setup_new ();
3196 ev_window_print_cancel (EvWindow *ev_window)
3198 EvPrintOperation *op;
3200 if (!ev_window->priv->print_queue)
3203 while ((op = g_queue_peek_tail (ev_window->priv->print_queue))) {
3204 ev_print_operation_cancel (op);
3209 ev_window_print_update_pending_jobs_message (EvWindow *ev_window,
3214 if (!EV_IS_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area) ||
3215 !ev_window->priv->print_queue)
3219 ev_window_set_message_area (ev_window, NULL);
3224 text = g_strdup_printf (ngettext ("%d pending job in queue",
3225 "%d pending jobs in queue",
3226 n_jobs - 1), n_jobs - 1);
3229 ev_message_area_set_secondary_text (EV_MESSAGE_AREA (ev_window->priv->message_area),
3235 destroy_window (GtkWidget *window)
3237 gtk_widget_destroy (window);
3243 ev_window_print_operation_done (EvPrintOperation *op,
3244 GtkPrintOperationResult result,
3245 EvWindow *ev_window)
3250 case GTK_PRINT_OPERATION_RESULT_APPLY: {
3251 GtkPrintSettings *print_settings;
3253 print_settings = ev_print_operation_get_print_settings (op);
3254 ev_window_save_print_settings (ev_window, print_settings);
3256 if (ev_print_operation_get_embed_page_setup (op)) {
3257 GtkPageSetup *page_setup;
3259 page_setup = ev_print_operation_get_default_page_setup (op);
3260 ev_window_save_print_page_setup (ev_window, page_setup);
3265 case GTK_PRINT_OPERATION_RESULT_ERROR: {
3267 GError *error = NULL;
3270 ev_print_operation_get_error (op, &error);
3272 /* The message area is already used by
3273 * the printing progress, so it's better to
3274 * use a popup dialog in this case
3276 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
3277 GTK_DIALOG_DESTROY_WITH_PARENT,
3280 "%s", _("Failed to print document"));
3281 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
3282 "%s", error->message);
3283 g_signal_connect (dialog, "response",
3284 G_CALLBACK (gtk_widget_destroy),
3286 gtk_widget_show (dialog);
3288 g_error_free (error);
3291 case GTK_PRINT_OPERATION_RESULT_CANCEL:
3296 g_queue_remove (ev_window->priv->print_queue, op);
3297 g_object_unref (op);
3298 n_jobs = g_queue_get_length (ev_window->priv->print_queue);
3299 ev_window_print_update_pending_jobs_message (ev_window, n_jobs);
3301 if (n_jobs == 0 && ev_window->priv->close_after_print)
3302 g_idle_add ((GSourceFunc)destroy_window,
3307 ev_window_print_progress_response_cb (EvProgressMessageArea *area,
3309 EvWindow *ev_window)
3311 if (response == GTK_RESPONSE_CANCEL) {
3312 EvPrintOperation *op;
3314 op = g_queue_peek_tail (ev_window->priv->print_queue);
3315 ev_print_operation_cancel (op);
3317 gtk_widget_hide (GTK_WIDGET (area));
3322 ev_window_print_operation_status_changed (EvPrintOperation *op,
3323 EvWindow *ev_window)
3325 const gchar *status;
3328 status = ev_print_operation_get_status (op);
3329 fraction = ev_print_operation_get_progress (op);
3331 if (!ev_window->priv->message_area) {
3333 const gchar *job_name;
3336 job_name = ev_print_operation_get_job_name (op);
3337 text = g_strdup_printf (_("Printing job “%s”"), job_name);
3339 area = ev_progress_message_area_new (GTK_STOCK_PRINT,
3344 GTK_RESPONSE_CANCEL,
3346 ev_window_print_update_pending_jobs_message (ev_window, 1);
3347 g_signal_connect (area, "response",
3348 G_CALLBACK (ev_window_print_progress_response_cb),
3350 gtk_widget_show (area);
3351 ev_window_set_message_area (ev_window, area);
3355 ev_progress_message_area_set_status (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
3357 ev_progress_message_area_set_fraction (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
3362 ev_window_print_operation_begin_print (EvPrintOperation *op,
3363 EvWindow *ev_window)
3365 if (!ev_window->priv->print_queue)
3366 ev_window->priv->print_queue = g_queue_new ();
3368 g_queue_push_head (ev_window->priv->print_queue, op);
3369 ev_window_print_update_pending_jobs_message (ev_window,
3370 g_queue_get_length (ev_window->priv->print_queue));
3374 ev_window_print_range (EvWindow *ev_window,
3378 EvPrintOperation *op;
3379 GKeyFile *print_settings_file;
3380 GtkPrintSettings *print_settings;
3381 GtkPageSetup *print_page_setup;
3383 gint document_last_page;
3384 gboolean embed_page_setup;
3386 g_return_if_fail (EV_IS_WINDOW (ev_window));
3387 g_return_if_fail (ev_window->priv->document != NULL);
3389 if (!ev_window->priv->print_queue)
3390 ev_window->priv->print_queue = g_queue_new ();
3392 op = ev_print_operation_new (ev_window->priv->document);
3394 g_warning ("%s", "Printing is not supported for document\n");
3398 g_signal_connect (op, "begin_print",
3399 G_CALLBACK (ev_window_print_operation_begin_print),
3400 (gpointer)ev_window);
3401 g_signal_connect (op, "status_changed",
3402 G_CALLBACK (ev_window_print_operation_status_changed),
3403 (gpointer)ev_window);
3404 g_signal_connect (op, "done",
3405 G_CALLBACK (ev_window_print_operation_done),
3406 (gpointer)ev_window);
3408 current_page = ev_document_model_get_page (ev_window->priv->model);
3409 document_last_page = ev_document_get_n_pages (ev_window->priv->document);
3411 print_settings_file = get_print_settings_file ();
3413 print_settings = get_print_settings (print_settings_file);
3414 ev_window_load_print_settings_from_metadata (ev_window, print_settings);
3416 print_page_setup = get_print_page_setup (print_settings_file);
3417 ev_window_load_print_page_setup_from_metadata (ev_window, print_page_setup);
3419 if (first_page != 1 || last_page != document_last_page) {
3422 /* Ranges in GtkPrint are 0 - N */
3423 range.start = first_page - 1;
3424 range.end = last_page - 1;
3426 gtk_print_settings_set_print_pages (print_settings,
3427 GTK_PRINT_PAGES_RANGES);
3428 gtk_print_settings_set_page_ranges (print_settings,
3432 ev_print_operation_set_job_name (op, gtk_window_get_title (GTK_WINDOW (ev_window)));
3433 ev_print_operation_set_current_page (op, current_page);
3434 ev_print_operation_set_print_settings (op, print_settings);
3435 ev_print_operation_set_default_page_setup (op, print_page_setup);
3436 embed_page_setup = ev_window->priv->lockdown_settings ?
3437 !g_settings_get_boolean (ev_window->priv->lockdown_settings,
3438 GS_LOCKDOWN_PRINT_SETUP) :
3440 ev_print_operation_set_embed_page_setup (op, embed_page_setup);
3442 g_object_unref (print_settings);
3443 g_object_unref (print_page_setup);
3444 g_key_file_free (print_settings_file);
3446 ev_print_operation_run (op, GTK_WINDOW (ev_window));
3450 ev_window_print (EvWindow *window)
3452 ev_window_print_range (window, 1,
3453 ev_document_get_n_pages (window->priv->document));
3457 ev_window_cmd_file_print (GtkAction *action, EvWindow *ev_window)
3459 ev_window_print (ev_window);
3463 ev_window_cmd_file_properties (GtkAction *action, EvWindow *ev_window)
3465 if (ev_window->priv->properties == NULL) {
3466 ev_window->priv->properties = ev_properties_dialog_new ();
3467 ev_properties_dialog_set_document (EV_PROPERTIES_DIALOG (ev_window->priv->properties),
3468 ev_window->priv->uri,
3469 ev_window->priv->document);
3470 g_object_add_weak_pointer (G_OBJECT (ev_window->priv->properties),
3471 (gpointer) &(ev_window->priv->properties));
3472 gtk_window_set_transient_for (GTK_WINDOW (ev_window->priv->properties),
3473 GTK_WINDOW (ev_window));
3476 ev_document_fc_mutex_lock ();
3477 gtk_widget_show (ev_window->priv->properties);
3478 ev_document_fc_mutex_unlock ();
3482 document_modified_confirmation_dialog_response (GtkDialog *dialog,
3484 EvWindow *ev_window)
3486 gtk_widget_destroy (GTK_WIDGET (dialog));
3489 case GTK_RESPONSE_YES:
3490 ev_window_cmd_save_as (NULL, ev_window);
3492 case GTK_RESPONSE_NO:
3493 gtk_widget_destroy (GTK_WIDGET (ev_window));
3495 case GTK_RESPONSE_CANCEL:
3502 ev_window_check_document_modified (EvWindow *ev_window)
3504 EvDocument *document = ev_window->priv->document;
3506 gchar *text, *markup;
3507 const gchar *secondary_text;
3512 if (EV_IS_DOCUMENT_FORMS (document) &&
3513 ev_document_forms_document_is_modified (EV_DOCUMENT_FORMS (document))) {
3514 secondary_text = _("Document contains form fields that have been filled out. "
3515 "If you don't save a copy, changes will be permanently lost.");
3516 } else if (EV_IS_DOCUMENT_ANNOTATIONS (document) &&
3517 ev_document_annotations_document_is_modified (EV_DOCUMENT_ANNOTATIONS (document))) {
3518 secondary_text = _("Document contains new or modified annotations. "
3519 "If you don't save a copy, changes will be permanently lost.");
3525 text = g_markup_printf_escaped (_("Save a copy of document “%s” before closing?"),
3526 gtk_window_get_title (GTK_WINDOW (ev_window)));
3528 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
3530 GTK_MESSAGE_QUESTION,
3534 markup = g_strdup_printf ("<b>%s</b>", text);
3537 gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), markup);
3540 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
3541 "%s", secondary_text);
3543 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
3544 _("Close _without Saving"),
3547 GTK_RESPONSE_CANCEL,
3551 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
3552 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
3555 GTK_RESPONSE_CANCEL,
3558 g_signal_connect (dialog, "response",
3559 G_CALLBACK (document_modified_confirmation_dialog_response),
3561 gtk_widget_show (dialog);
3567 print_jobs_confirmation_dialog_response (GtkDialog *dialog,
3569 EvWindow *ev_window)
3571 gtk_widget_destroy (GTK_WIDGET (dialog));
3574 case GTK_RESPONSE_YES:
3575 if (!ev_window->priv->print_queue ||
3576 g_queue_is_empty (ev_window->priv->print_queue))
3577 gtk_widget_destroy (GTK_WIDGET (ev_window));
3579 ev_window->priv->close_after_print = TRUE;
3581 case GTK_RESPONSE_NO:
3582 ev_window->priv->close_after_print = TRUE;
3583 if (ev_window->priv->print_queue &&
3584 !g_queue_is_empty (ev_window->priv->print_queue)) {
3585 gtk_widget_set_sensitive (GTK_WIDGET (ev_window), FALSE);
3586 ev_window_print_cancel (ev_window);
3588 gtk_widget_destroy (GTK_WIDGET (ev_window));
3591 case GTK_RESPONSE_CANCEL:
3593 ev_window->priv->close_after_print = FALSE;
3598 ev_window_check_print_queue (EvWindow *ev_window)
3601 gchar *text, *markup;
3604 n_print_jobs = ev_window->priv->print_queue ?
3605 g_queue_get_length (ev_window->priv->print_queue) : 0;
3607 if (n_print_jobs == 0)
3610 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
3612 GTK_MESSAGE_QUESTION,
3615 if (n_print_jobs == 1) {
3616 EvPrintOperation *op;
3617 const gchar *job_name;
3619 op = g_queue_peek_tail (ev_window->priv->print_queue);
3620 job_name = ev_print_operation_get_job_name (op);
3622 text = g_strdup_printf (_("Wait until print job “%s” finishes before closing?"),
3625 text = g_strdup_printf (_("There are %d print jobs active. "
3626 "Wait until print finishes before closing?"),
3630 markup = g_strdup_printf ("<b>%s</b>", text);
3633 gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), markup);
3636 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s",
3637 _("If you close the window, pending print "
3638 "jobs will not be printed."));
3640 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
3641 _("Cancel _print and Close"),
3644 GTK_RESPONSE_CANCEL,
3645 _("Close _after Printing"),
3648 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
3649 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
3652 GTK_RESPONSE_CANCEL,
3655 g_signal_connect (dialog, "response",
3656 G_CALLBACK (print_jobs_confirmation_dialog_response),
3658 gtk_widget_show (dialog);
3664 ev_window_close (EvWindow *ev_window)
3666 if (EV_WINDOW_IS_PRESENTATION (ev_window)) {
3669 /* Save current page */
3670 current_page = ev_view_presentation_get_current_page (
3671 EV_VIEW_PRESENTATION (ev_window->priv->presentation_view));
3672 ev_document_model_set_page (ev_window->priv->model, current_page);
3675 if (ev_window_check_document_modified (ev_window))
3678 if (ev_window_check_print_queue (ev_window))
3685 ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window)
3687 if (ev_window_close (ev_window))
3688 gtk_widget_destroy (GTK_WIDGET (ev_window));
3692 ev_window_cmd_focus_page_selector (GtkAction *act, EvWindow *window)
3696 update_chrome_flag (window, EV_CHROME_RAISE_TOOLBAR, TRUE);
3697 ev_window_set_action_sensitive (window, "ViewToolbar", FALSE);
3698 update_chrome_visibility (window);
3700 action = gtk_action_group_get_action (window->priv->action_group,
3701 PAGE_SELECTOR_ACTION);
3702 ev_page_action_grab_focus (EV_PAGE_ACTION (action));
3706 ev_window_cmd_scroll_forward (GtkAction *action, EvWindow *window)
3708 ev_view_scroll (EV_VIEW (window->priv->view), GTK_SCROLL_PAGE_FORWARD, FALSE);
3712 ev_window_cmd_scroll_backward (GtkAction *action, EvWindow *window)
3714 ev_view_scroll (EV_VIEW (window->priv->view), GTK_SCROLL_PAGE_BACKWARD, FALSE);
3718 ev_window_cmd_continuous (GtkAction *action, EvWindow *ev_window)
3720 gboolean continuous;
3722 ev_window_stop_presentation (ev_window, TRUE);
3723 continuous = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
3724 ev_document_model_set_continuous (ev_window->priv->model, continuous);
3728 ev_window_cmd_dual (GtkAction *action, EvWindow *ev_window)
3732 ev_window_stop_presentation (ev_window, TRUE);
3733 dual_page = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
3734 ev_document_model_set_dual_page (ev_window->priv->model, dual_page);
3738 ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window)
3740 ev_window_stop_presentation (ev_window, TRUE);
3742 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
3743 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_BEST_FIT);
3745 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FREE);
3747 ev_window_update_actions (ev_window);
3751 ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window)
3753 ev_window_stop_presentation (ev_window, TRUE);
3755 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
3756 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FIT_WIDTH);
3758 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FREE);
3760 ev_window_update_actions (ev_window);
3765 ev_window_cmd_edit_select_all (GtkAction *action, EvWindow *ev_window)
3767 g_return_if_fail (EV_IS_WINDOW (ev_window));
3769 ev_view_select_all (EV_VIEW (ev_window->priv->view));
3773 ev_window_cmd_edit_find (GtkAction *action, EvWindow *ev_window)
3775 g_return_if_fail (EV_IS_WINDOW (ev_window));
3777 if (ev_window->priv->document == NULL || !EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
3778 g_error ("Find action should be insensitive since document doesn't support find");
3782 update_chrome_flag (ev_window, EV_CHROME_FINDBAR, TRUE);
3783 update_chrome_visibility (ev_window);
3784 gtk_widget_grab_focus (ev_window->priv->find_bar);
3788 ev_window_cmd_edit_find_next (GtkAction *action, EvWindow *ev_window)
3790 g_return_if_fail (EV_IS_WINDOW (ev_window));
3792 update_chrome_flag (ev_window, EV_CHROME_FINDBAR, TRUE);
3793 update_chrome_visibility (ev_window);
3794 gtk_widget_grab_focus (ev_window->priv->find_bar);
3795 ev_view_find_next (EV_VIEW (ev_window->priv->view));
3799 ev_window_cmd_edit_find_previous (GtkAction *action, EvWindow *ev_window)
3801 g_return_if_fail (EV_IS_WINDOW (ev_window));
3803 update_chrome_flag (ev_window, EV_CHROME_FINDBAR, TRUE);
3804 update_chrome_visibility (ev_window);
3805 gtk_widget_grab_focus (ev_window->priv->find_bar);
3806 ev_view_find_previous (EV_VIEW (ev_window->priv->view));
3810 ev_window_cmd_edit_copy (GtkAction *action, EvWindow *ev_window)
3812 g_return_if_fail (EV_IS_WINDOW (ev_window));
3814 ev_view_copy (EV_VIEW (ev_window->priv->view));
3818 ev_window_sidebar_position_change_cb (GObject *object,
3820 EvWindow *ev_window)
3822 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window))
3823 ev_metadata_set_int (ev_window->priv->metadata, "sidebar_size",
3824 gtk_paned_get_position (GTK_PANED (object)));
3828 ev_window_update_fullscreen_action (EvWindow *window)
3832 action = gtk_action_group_get_action (window->priv->action_group, "ViewFullscreen");
3833 g_signal_handlers_block_by_func
3834 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
3835 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
3836 ev_document_model_get_fullscreen (window->priv->model));
3837 g_signal_handlers_unblock_by_func
3838 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
3842 fullscreen_toolbar_setup_item_properties (GtkUIManager *ui_manager)
3846 item = gtk_ui_manager_get_widget (ui_manager, "/FullscreenToolbar/GoPreviousPage");
3847 g_object_set (item, "is-important", FALSE, NULL);
3849 item = gtk_ui_manager_get_widget (ui_manager, "/FullscreenToolbar/GoNextPage");
3850 g_object_set (item, "is-important", FALSE, NULL);
3852 item = gtk_ui_manager_get_widget (ui_manager, "/FullscreenToolbar/StartPresentation");
3853 g_object_set (item, "is-important", TRUE, NULL);
3855 item = gtk_ui_manager_get_widget (ui_manager, "/FullscreenToolbar/LeaveFullscreen");
3856 g_object_set (item, "is-important", TRUE, NULL);
3860 fullscreen_toolbar_remove_shadow (GtkWidget *toolbar)
3862 GtkCssProvider *provider;
3864 gtk_widget_set_name (toolbar, "ev-fullscreen-toolbar");
3866 provider = gtk_css_provider_new ();
3867 gtk_css_provider_load_from_data (provider,
3868 "#ev-fullscreen-toolbar {\n"
3869 " -GtkToolbar-shadow-type: none; }",
3871 gtk_style_context_add_provider (gtk_widget_get_style_context (toolbar),
3872 GTK_STYLE_PROVIDER (provider),
3873 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
3874 g_object_unref (provider);
3878 ev_window_run_fullscreen (EvWindow *window)
3880 gboolean fullscreen_window = TRUE;
3882 if (ev_document_model_get_fullscreen (window->priv->model))
3885 if (!window->priv->fullscreen_toolbar) {
3886 window->priv->fullscreen_toolbar =
3887 gtk_ui_manager_get_widget (window->priv->ui_manager,
3888 "/FullscreenToolbar");
3890 gtk_toolbar_set_style (GTK_TOOLBAR (window->priv->fullscreen_toolbar),
3891 GTK_TOOLBAR_BOTH_HORIZ);
3892 fullscreen_toolbar_remove_shadow (window->priv->fullscreen_toolbar);
3893 fullscreen_toolbar_setup_item_properties (window->priv->ui_manager);
3895 gtk_box_pack_start (GTK_BOX (window->priv->main_box),
3896 window->priv->fullscreen_toolbar,
3898 gtk_box_reorder_child (GTK_BOX (window->priv->main_box),
3899 window->priv->fullscreen_toolbar, 1);
3902 if (EV_WINDOW_IS_PRESENTATION (window)) {
3903 ev_window_stop_presentation (window, FALSE);
3904 fullscreen_window = FALSE;
3907 g_object_set (G_OBJECT (window->priv->scrolled_window),
3908 "shadow-type", GTK_SHADOW_NONE,
3911 ev_document_model_set_fullscreen (window->priv->model, TRUE);
3912 ev_window_update_fullscreen_action (window);
3914 /* If the user doesn't have the main toolbar he/she won't probably want
3915 * the toolbar in fullscreen mode. See bug #483048
3917 update_chrome_flag (window, EV_CHROME_FULLSCREEN_TOOLBAR,
3918 (window->priv->chrome & EV_CHROME_TOOLBAR) != 0);
3919 update_chrome_visibility (window);
3921 if (fullscreen_window)
3922 gtk_window_fullscreen (GTK_WINDOW (window));
3923 gtk_widget_grab_focus (window->priv->view);
3925 if (window->priv->metadata && !ev_window_is_empty (window))
3926 ev_metadata_set_boolean (window->priv->metadata, "fullscreen", TRUE);
3930 ev_window_stop_fullscreen (EvWindow *window,
3931 gboolean unfullscreen_window)
3933 if (!ev_document_model_get_fullscreen (window->priv->model))
3936 g_object_set (G_OBJECT (window->priv->scrolled_window),
3937 "shadow-type", GTK_SHADOW_IN,
3940 ev_document_model_set_fullscreen (window->priv->model, FALSE);
3941 ev_window_update_fullscreen_action (window);
3942 update_chrome_flag (window, EV_CHROME_FULLSCREEN_TOOLBAR, FALSE);
3943 update_chrome_visibility (window);
3944 if (unfullscreen_window)
3945 gtk_window_unfullscreen (GTK_WINDOW (window));
3947 if (window->priv->metadata && !ev_window_is_empty (window))
3948 ev_metadata_set_boolean (window->priv->metadata, "fullscreen", FALSE);
3952 ev_window_cmd_view_fullscreen (GtkAction *action, EvWindow *window)
3954 gboolean fullscreen;
3956 fullscreen = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
3958 ev_window_run_fullscreen (window);
3960 ev_window_stop_fullscreen (window, TRUE);
3965 ev_window_update_presentation_action (EvWindow *window)
3969 action = gtk_action_group_get_action (window->priv->action_group, "ViewPresentation");
3970 g_signal_handlers_block_by_func
3971 (action, G_CALLBACK (ev_window_cmd_view_presentation), window);
3972 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
3973 EV_WINDOW_IS_PRESENTATION (window));
3974 g_signal_handlers_unblock_by_func
3975 (action, G_CALLBACK (ev_window_cmd_view_presentation), window);
3979 ev_window_view_presentation_finished (EvWindow *window)
3981 ev_window_stop_presentation (window, TRUE);
3985 ev_window_view_presentation_focus_in (EvWindow *window)
3987 ev_application_screensaver_disable (EV_APP);
3993 ev_window_view_presentation_focus_out (EvWindow *window)
3995 ev_application_screensaver_enable (EV_APP);
4001 ev_window_run_presentation (EvWindow *window)
4003 gboolean fullscreen_window = TRUE;
4006 gboolean inverted_colors;
4008 if (EV_WINDOW_IS_PRESENTATION (window))
4011 if (ev_document_model_get_fullscreen (window->priv->model)) {
4012 ev_window_stop_fullscreen (window, FALSE);
4013 fullscreen_window = FALSE;
4016 current_page = ev_document_model_get_page (window->priv->model);
4017 rotation = ev_document_model_get_rotation (window->priv->model);
4018 inverted_colors = ev_document_model_get_inverted_colors (window->priv->model);
4019 window->priv->presentation_view = ev_view_presentation_new (window->priv->document,
4024 g_signal_connect_swapped (window->priv->presentation_view, "finished",
4025 G_CALLBACK (ev_window_view_presentation_finished),
4027 g_signal_connect_swapped (window->priv->presentation_view, "external-link",
4028 G_CALLBACK (view_external_link_cb),
4030 g_signal_connect_swapped (window->priv->presentation_view, "focus-in-event",
4031 G_CALLBACK (ev_window_view_presentation_focus_in),
4033 g_signal_connect_swapped (window->priv->presentation_view, "focus-out-event",
4034 G_CALLBACK (ev_window_view_presentation_focus_out),
4037 gtk_box_pack_start (GTK_BOX (window->priv->main_box),
4038 window->priv->presentation_view,
4041 gtk_widget_hide (window->priv->hpaned);
4042 ev_window_update_presentation_action (window);
4043 update_chrome_visibility (window);
4045 gtk_widget_grab_focus (window->priv->presentation_view);
4046 if (fullscreen_window)
4047 gtk_window_fullscreen (GTK_WINDOW (window));
4049 gtk_widget_show (window->priv->presentation_view);
4051 ev_application_screensaver_disable (EV_APP);
4053 if (window->priv->metadata && !ev_window_is_empty (window))
4054 ev_metadata_set_boolean (window->priv->metadata, "presentation", TRUE);
4056 if ( get_num_monitors(GTK_WINDOW(window)) > 1) {
4057 EvDSCWindow *control = ev_dscwindow_get_control();
4058 gtk_window_present (GTK_WINDOW (control));
4059 ev_dscwindow_set_presentation (control, window,
4060 window->priv->document,
4061 EV_VIEW_PRESENTATION(window->priv->presentation_view));
4066 ev_window_stop_presentation (EvWindow *window,
4067 gboolean unfullscreen_window)
4072 if (!EV_WINDOW_IS_PRESENTATION (window))
4075 current_page = ev_view_presentation_get_current_page (EV_VIEW_PRESENTATION (window->priv->presentation_view));
4076 ev_document_model_set_page (window->priv->model, current_page);
4077 rotation = ev_view_presentation_get_rotation (EV_VIEW_PRESENTATION (window->priv->presentation_view));
4078 ev_document_model_set_rotation (window->priv->model, rotation);
4080 gtk_container_remove (GTK_CONTAINER (window->priv->main_box),
4081 window->priv->presentation_view);
4082 window->priv->presentation_view = NULL;
4084 gtk_widget_show (window->priv->hpaned);
4085 ev_window_update_presentation_action (window);
4086 update_chrome_visibility (window);
4087 if (unfullscreen_window)
4088 gtk_window_unfullscreen (GTK_WINDOW (window));
4090 gtk_widget_grab_focus (window->priv->view);
4092 ev_application_screensaver_enable (EV_APP);
4094 if (window->priv->metadata && !ev_window_is_empty (window))
4095 ev_metadata_set_boolean (window->priv->metadata, "presentation", FALSE);
4099 ev_window_cmd_view_presentation (GtkAction *action, EvWindow *window)
4101 gboolean presentation;
4103 presentation = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
4105 ev_window_run_presentation (window);
4110 ev_window_setup_gtk_settings (EvWindow *window)
4112 GtkSettings *settings;
4114 gchar *menubar_accel_accel;
4116 screen = gtk_window_get_screen (GTK_WINDOW (window));
4117 settings = gtk_settings_get_for_screen (screen);
4119 g_object_get (settings,
4120 "gtk-menu-bar-accel", &menubar_accel_accel,
4122 if (menubar_accel_accel != NULL && menubar_accel_accel[0] != '\0') {
4123 gtk_accelerator_parse (menubar_accel_accel,
4124 &window->priv->menubar_accel_keyval,
4125 &window->priv->menubar_accel_modifier);
4126 if (window->priv->menubar_accel_keyval == 0) {
4127 g_warning ("Failed to parse menu bar accelerator '%s'\n",
4128 menubar_accel_accel);
4131 window->priv->menubar_accel_keyval = 0;
4132 window->priv->menubar_accel_modifier = 0;
4135 g_free (menubar_accel_accel);
4139 ev_window_update_max_min_scale (EvWindow *window)
4143 gdouble min_width, min_height;
4144 gdouble width, height;
4146 gint rotation = ev_document_model_get_rotation (window->priv->model);
4148 if (!window->priv->document)
4151 dpi = get_screen_dpi (window) / 72.0;
4153 ev_document_get_min_page_size (window->priv->document, &min_width, &min_height);
4154 width = (rotation == 0 || rotation == 180) ? min_width : min_height;
4155 height = (rotation == 0 || rotation == 180) ? min_height : min_width;
4156 max_scale = sqrt (PAGE_CACHE_SIZE / (width * dpi * 4 * height * dpi));
4158 action = gtk_action_group_get_action (window->priv->action_group,
4159 ZOOM_CONTROL_ACTION);
4160 ephy_zoom_action_set_max_zoom_level (EPHY_ZOOM_ACTION (action), max_scale * dpi);
4162 ev_document_model_set_min_scale (window->priv->model, MIN_SCALE * dpi);
4163 ev_document_model_set_max_scale (window->priv->model, max_scale * dpi);
4167 ev_window_screen_changed (GtkWidget *widget,
4168 GdkScreen *old_screen)
4170 EvWindow *window = EV_WINDOW (widget);
4173 screen = gtk_widget_get_screen (widget);
4174 if (screen == old_screen)
4177 ev_window_setup_gtk_settings (window);
4178 ev_window_update_max_min_scale (window);
4180 if (GTK_WIDGET_CLASS (ev_window_parent_class)->screen_changed) {
4181 GTK_WIDGET_CLASS (ev_window_parent_class)->screen_changed (widget, old_screen);
4186 ev_window_state_event (GtkWidget *widget,
4187 GdkEventWindowState *event)
4189 EvWindow *window = EV_WINDOW (widget);
4191 if (GTK_WIDGET_CLASS (ev_window_parent_class)->window_state_event) {
4192 GTK_WIDGET_CLASS (ev_window_parent_class)->window_state_event (widget, event);
4195 if ((event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN) == 0)
4198 if (event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN) {
4199 if (ev_document_model_get_fullscreen (window->priv->model) || EV_WINDOW_IS_PRESENTATION (window))
4202 ev_window_run_fullscreen (window);
4204 if (ev_document_model_get_fullscreen (window->priv->model))
4205 ev_window_stop_fullscreen (window, FALSE);
4206 else if (EV_WINDOW_IS_PRESENTATION (window))
4207 ev_window_stop_presentation (window, FALSE);
4214 ev_window_set_page_mode (EvWindow *window,
4215 EvWindowPageMode page_mode)
4217 GtkWidget *child = NULL;
4218 GtkWidget *real_child;
4220 if (window->priv->page_mode == page_mode)
4223 window->priv->page_mode = page_mode;
4225 switch (page_mode) {
4226 case PAGE_MODE_DOCUMENT:
4227 child = window->priv->view;
4229 case PAGE_MODE_PASSWORD:
4230 child = window->priv->password_view;
4233 g_assert_not_reached ();
4236 real_child = gtk_bin_get_child (GTK_BIN (window->priv->scrolled_window));
4237 if (child != real_child) {
4238 gtk_container_remove (GTK_CONTAINER (window->priv->scrolled_window),
4240 gtk_container_add (GTK_CONTAINER (window->priv->scrolled_window),
4243 ev_window_update_actions (window);
4248 ev_window_cmd_edit_rotate_left (GtkAction *action, EvWindow *ev_window)
4252 if (EV_WINDOW_IS_PRESENTATION (ev_window)) {
4253 rotation = ev_view_presentation_get_rotation (EV_VIEW_PRESENTATION (ev_window->priv->presentation_view));
4254 ev_view_presentation_set_rotation (EV_VIEW_PRESENTATION (ev_window->priv->presentation_view),
4257 rotation = ev_document_model_get_rotation (ev_window->priv->model);
4259 ev_document_model_set_rotation (ev_window->priv->model, rotation - 90);
4264 ev_window_cmd_edit_rotate_right (GtkAction *action, EvWindow *ev_window)
4268 if (EV_WINDOW_IS_PRESENTATION (ev_window)) {
4269 rotation = ev_view_presentation_get_rotation (EV_VIEW_PRESENTATION (ev_window->priv->presentation_view));
4270 ev_view_presentation_set_rotation (EV_VIEW_PRESENTATION (ev_window->priv->presentation_view),
4273 rotation = ev_document_model_get_rotation (ev_window->priv->model);
4275 ev_document_model_set_rotation (ev_window->priv->model, rotation + 90);
4280 ev_window_cmd_view_inverted_colors (GtkAction *action, EvWindow *ev_window)
4282 gboolean inverted_colors = ev_document_model_get_inverted_colors (ev_window->priv->model);
4284 ev_document_model_set_inverted_colors (ev_window->priv->model, !inverted_colors);
4288 ev_window_cmd_edit_toolbar_cb (GtkDialog *dialog,
4290 EvWindow *ev_window)
4292 EggEditableToolbar *toolbar;
4293 gchar *toolbars_file;
4295 toolbar = EGG_EDITABLE_TOOLBAR (ev_window->priv->toolbar);
4296 egg_editable_toolbar_set_edit_mode (toolbar, FALSE);
4297 ev_window_set_action_sensitive (ev_window, "ViewToolbar", TRUE);
4299 toolbars_file = g_build_filename (ev_application_get_dot_dir (EV_APP, TRUE),
4300 "evince_toolbar.xml", NULL);
4301 egg_toolbars_model_save_toolbars (egg_editable_toolbar_get_model (toolbar),
4302 toolbars_file, "1.0");
4303 g_free (toolbars_file);
4305 gtk_widget_destroy (GTK_WIDGET (dialog));
4309 ev_window_cmd_edit_toolbar (GtkAction *action, EvWindow *ev_window)
4313 GtkWidget *content_area;
4314 EggEditableToolbar *toolbar;
4316 dialog = gtk_dialog_new_with_buttons (_("Toolbar Editor"),
4317 GTK_WINDOW (ev_window),
4318 GTK_DIALOG_DESTROY_WITH_PARENT,
4322 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
4323 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE);
4324 gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)), 5);
4325 gtk_box_set_spacing (GTK_BOX (content_area), 2);
4326 gtk_window_set_default_size (GTK_WINDOW (dialog), 500, 400);
4328 toolbar = EGG_EDITABLE_TOOLBAR (ev_window->priv->toolbar);
4329 editor = egg_toolbar_editor_new (ev_window->priv->ui_manager,
4330 egg_editable_toolbar_get_model (toolbar));
4332 gtk_container_set_border_width (GTK_CONTAINER (editor), 5);
4333 gtk_box_set_spacing (GTK_BOX (EGG_TOOLBAR_EDITOR (editor)), 5);
4335 gtk_box_pack_start (GTK_BOX (content_area), editor, TRUE, TRUE, 0);
4337 egg_editable_toolbar_set_edit_mode (toolbar, TRUE);
4338 ev_window_set_action_sensitive (ev_window, "ViewToolbar", FALSE);
4340 g_signal_connect (dialog, "response",
4341 G_CALLBACK (ev_window_cmd_edit_toolbar_cb),
4343 gtk_widget_show_all (dialog);
4347 ev_window_cmd_edit_save_settings (GtkAction *action, EvWindow *ev_window)
4349 EvWindowPrivate *priv = ev_window->priv;
4350 EvDocumentModel *model = priv->model;
4351 GSettings *settings = priv->default_settings;
4353 g_settings_set_boolean (settings, "continuous",
4354 ev_document_model_get_continuous (model));
4355 g_settings_set_boolean (settings, "dual-page",
4356 ev_document_model_get_dual_page (model));
4357 g_settings_set_boolean (settings, "fullscreen",
4358 ev_document_model_get_fullscreen (model));
4359 g_settings_set_boolean (settings, "inverted-colors",
4360 ev_document_model_get_inverted_colors (model));
4361 g_settings_set_enum (settings, "sizing-mode",
4362 ev_document_model_get_sizing_mode (model));
4363 g_settings_set_boolean (settings, "show-toolbar",
4364 gtk_widget_get_visible (priv->toolbar));
4365 g_settings_set_boolean (settings, "show-sidebar",
4366 gtk_widget_get_visible (priv->sidebar));
4367 g_settings_set_int (settings, "sidebar-size",
4368 gtk_paned_get_position (GTK_PANED (priv->hpaned)));
4369 g_settings_set_string (settings, "sidebar-page",
4370 ev_window_sidebar_get_current_page_id (ev_window));
4371 g_settings_apply (settings);
4375 ev_window_cmd_view_zoom_in (GtkAction *action, EvWindow *ev_window)
4377 g_return_if_fail (EV_IS_WINDOW (ev_window));
4379 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FREE);
4380 ev_view_zoom_in (EV_VIEW (ev_window->priv->view));
4384 ev_window_cmd_view_zoom_out (GtkAction *action, EvWindow *ev_window)
4386 g_return_if_fail (EV_IS_WINDOW (ev_window));
4388 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FREE);
4389 ev_view_zoom_out (EV_VIEW (ev_window->priv->view));
4393 ev_window_cmd_go_previous_page (GtkAction *action, EvWindow *ev_window)
4395 g_return_if_fail (EV_IS_WINDOW (ev_window));
4397 ev_view_previous_page (EV_VIEW (ev_window->priv->view));
4401 ev_window_cmd_go_next_page (GtkAction *action, EvWindow *ev_window)
4403 g_return_if_fail (EV_IS_WINDOW (ev_window));
4405 ev_view_next_page (EV_VIEW (ev_window->priv->view));
4409 ev_window_cmd_go_first_page (GtkAction *action, EvWindow *ev_window)
4411 g_return_if_fail (EV_IS_WINDOW (ev_window));
4413 ev_document_model_set_page (ev_window->priv->model, 0);
4417 ev_window_cmd_go_last_page (GtkAction *action, EvWindow *ev_window)
4419 g_return_if_fail (EV_IS_WINDOW (ev_window));
4421 ev_document_model_set_page (ev_window->priv->model,
4422 ev_document_get_n_pages (ev_window->priv->document) - 1);
4426 ev_window_cmd_go_forward (GtkAction *action, EvWindow *ev_window)
4428 int n_pages, current_page;
4430 g_return_if_fail (EV_IS_WINDOW (ev_window));
4432 n_pages = ev_document_get_n_pages (ev_window->priv->document);
4433 current_page = ev_document_model_get_page (ev_window->priv->model);
4435 if (current_page + 10 < n_pages) {
4436 ev_document_model_set_page (ev_window->priv->model, current_page + 10);
4441 ev_window_cmd_go_backward (GtkAction *action, EvWindow *ev_window)
4445 g_return_if_fail (EV_IS_WINDOW (ev_window));
4447 current_page = ev_document_model_get_page (ev_window->priv->model);
4449 if (current_page - 10 >= 0) {
4450 ev_document_model_set_page (ev_window->priv->model, current_page - 10);
4455 ev_window_cmd_bookmark_activate (GtkAction *action,
4458 guint page = ev_bookmark_action_get_page (EV_BOOKMARK_ACTION (action));
4460 ev_document_model_set_page (window->priv->model, page);
4464 compare_bookmarks (EvBookmark *a,
4467 return strcmp (a->title, b->title);
4471 ev_window_setup_bookmarks (EvWindow *window)
4475 if (!window->priv->bookmarks)
4478 if (window->priv->bookmarks_ui_id > 0) {
4479 gtk_ui_manager_remove_ui (window->priv->ui_manager,
4480 window->priv->bookmarks_ui_id);
4481 gtk_ui_manager_ensure_update (window->priv->ui_manager);
4483 window->priv->bookmarks_ui_id = gtk_ui_manager_new_merge_id (window->priv->ui_manager);
4485 if (window->priv->bookmarks_action_group) {
4486 gtk_ui_manager_remove_action_group (window->priv->ui_manager,
4487 window->priv->bookmarks_action_group);
4488 g_object_unref (window->priv->bookmarks_action_group);
4490 window->priv->bookmarks_action_group = gtk_action_group_new ("BookmarksActions");
4491 gtk_ui_manager_insert_action_group (window->priv->ui_manager,
4492 window->priv->bookmarks_action_group, -1);
4494 items = ev_bookmarks_get_bookmarks (window->priv->bookmarks);
4495 items = g_list_sort (items, (GCompareFunc)compare_bookmarks);
4497 for (l = items; l && l->data; l = g_list_next (l)) {
4498 EvBookmark *bm = (EvBookmark *)l->data;
4501 action = ev_bookmark_action_new (bm);
4502 g_signal_connect (action, "activate",
4503 G_CALLBACK (ev_window_cmd_bookmark_activate),
4505 gtk_action_group_add_action (window->priv->bookmarks_action_group,
4508 gtk_ui_manager_add_ui (window->priv->ui_manager,
4509 window->priv->bookmarks_ui_id,
4510 "/MainMenu/BookmarksMenu/BookmarksItems",
4511 gtk_action_get_label (action),
4512 gtk_action_get_name (action),
4513 GTK_UI_MANAGER_MENUITEM,
4516 g_object_unref (action);
4519 g_list_free (items);
4523 ev_window_cmd_bookmarks_add (GtkAction *action,
4530 bm.page = ev_document_model_get_page (window->priv->model);
4531 page_label = ev_document_get_page_label (window->priv->document, bm.page);
4532 page_title = ev_window_get_page_title (window, page_label);
4533 bm.title = page_title ? page_title : g_strdup_printf (_("Page %s"), page_label);
4534 g_free (page_label);
4536 /* EvBookmarks takes ownership of bookmark */
4537 ev_bookmarks_add (window->priv->bookmarks, &bm);
4541 ev_window_cmd_view_reload (GtkAction *action, EvWindow *ev_window)
4543 ev_window_reload_document (ev_window, NULL);
4547 ev_window_cmd_view_autoscroll (GtkAction *action, EvWindow *ev_window)
4549 ev_view_autoscroll_start (EV_VIEW (ev_window->priv->view));
4552 #if OFFLINE_HELP_ENABLED
4553 #define EV_HELP "ghelp:evince"
4555 #define EV_HELP "http://library.gnome.org/users/evince/stable/"
4559 ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
4561 GError *error = NULL;
4563 gtk_show_uri (gtk_window_get_screen (GTK_WINDOW (ev_window)),
4565 gtk_get_current_event_time (),
4568 ev_window_error_message (ev_window, error,
4569 "%s", _("There was an error displaying help"));
4570 g_error_free (error);
4575 ev_window_cmd_leave_fullscreen (GtkAction *action, EvWindow *window)
4577 ev_window_stop_fullscreen (window, TRUE);
4581 ev_window_cmd_start_presentation (GtkAction *action, EvWindow *window)
4583 ev_window_run_presentation (window);
4587 ev_window_cmd_escape (GtkAction *action, EvWindow *window)
4591 ev_view_autoscroll_stop (EV_VIEW (window->priv->view));
4593 widget = gtk_window_get_focus (GTK_WINDOW (window));
4594 if (widget && gtk_widget_get_ancestor (widget, EGG_TYPE_FIND_BAR)) {
4595 update_chrome_flag (window, EV_CHROME_FINDBAR, FALSE);
4596 update_chrome_visibility (window);
4597 gtk_widget_grab_focus (window->priv->view);
4599 gboolean fullscreen;
4601 fullscreen = ev_document_model_get_fullscreen (window->priv->model);
4604 ev_window_stop_fullscreen (window, TRUE);
4605 } else if (EV_WINDOW_IS_PRESENTATION (window)) {
4606 ev_window_stop_presentation (window, TRUE);
4607 gtk_widget_grab_focus (window->priv->view);
4609 gtk_widget_grab_focus (window->priv->view);
4612 if (fullscreen && EV_WINDOW_IS_PRESENTATION (window))
4613 g_warning ("Both fullscreen and presentation set somehow");
4618 save_sizing_mode (EvWindow *window)
4621 GEnumValue *enum_value;
4623 if (!window->priv->metadata || ev_window_is_empty (window))
4626 mode = ev_document_model_get_sizing_mode (window->priv->model);
4627 enum_value = g_enum_get_value (g_type_class_peek (EV_TYPE_SIZING_MODE), mode);
4628 ev_metadata_set_string (window->priv->metadata, "sizing_mode",
4629 enum_value->value_nick);
4633 ev_window_document_changed_cb (EvDocumentModel *model,
4635 EvWindow *ev_window)
4637 ev_window_set_document (ev_window,
4638 ev_document_model_get_document (model));
4642 ev_window_sizing_mode_changed_cb (EvDocumentModel *model,
4644 EvWindow *ev_window)
4646 EvSizingMode sizing_mode = ev_document_model_get_sizing_mode (model);
4648 g_object_set (ev_window->priv->scrolled_window,
4649 "hscrollbar-policy",
4650 sizing_mode == EV_SIZING_FREE ?
4651 GTK_POLICY_AUTOMATIC : GTK_POLICY_NEVER,
4652 "vscrollbar-policy", GTK_POLICY_AUTOMATIC,
4655 update_sizing_buttons (ev_window);
4656 save_sizing_mode (ev_window);
4660 ev_window_zoom_changed_cb (EvDocumentModel *model, GParamSpec *pspec, EvWindow *ev_window)
4662 ev_window_update_actions (ev_window);
4664 if (!ev_window->priv->metadata)
4667 if (ev_document_model_get_sizing_mode (model) == EV_SIZING_FREE && !ev_window_is_empty (ev_window)) {
4670 zoom = ev_document_model_get_scale (model);
4671 zoom *= 72.0 / get_screen_dpi (ev_window);
4672 ev_metadata_set_double (ev_window->priv->metadata, "zoom", zoom);
4677 ev_window_update_continuous_action (EvWindow *window)
4681 action = gtk_action_group_get_action (window->priv->action_group, "ViewContinuous");
4682 g_signal_handlers_block_by_func
4683 (action, G_CALLBACK (ev_window_cmd_continuous), window);
4684 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
4685 ev_document_model_get_continuous (window->priv->model));
4686 g_signal_handlers_unblock_by_func
4687 (action, G_CALLBACK (ev_window_cmd_continuous), window);
4691 ev_window_update_dual_page_action (EvWindow *window)
4695 action = gtk_action_group_get_action (window->priv->action_group, "ViewDual");
4696 g_signal_handlers_block_by_func
4697 (action, G_CALLBACK (ev_window_cmd_dual), window);
4698 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
4699 ev_document_model_get_dual_page (window->priv->model));
4700 g_signal_handlers_unblock_by_func
4701 (action, G_CALLBACK (ev_window_cmd_dual), window);
4705 ev_window_continuous_changed_cb (EvDocumentModel *model,
4707 EvWindow *ev_window)
4709 ev_window_update_continuous_action (ev_window);
4711 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window))
4712 ev_metadata_set_boolean (ev_window->priv->metadata, "continuous",
4713 ev_document_model_get_continuous (model));
4717 ev_window_rotation_changed_cb (EvDocumentModel *model,
4721 gint rotation = ev_document_model_get_rotation (model);
4723 if (window->priv->metadata && !ev_window_is_empty (window))
4724 ev_metadata_set_int (window->priv->metadata, "rotation",
4727 ev_window_update_max_min_scale (window);
4728 ev_window_refresh_window_thumbnail (window);
4732 ev_window_update_inverted_colors_action (EvWindow *window)
4736 action = gtk_action_group_get_action (window->priv->action_group, "ViewInvertedColors");
4737 g_signal_handlers_block_by_func
4738 (action, G_CALLBACK (ev_window_cmd_view_inverted_colors), window);
4739 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
4740 ev_document_model_get_inverted_colors (window->priv->model));
4741 g_signal_handlers_unblock_by_func
4742 (action, G_CALLBACK (ev_window_cmd_view_inverted_colors), window);
4746 ev_window_inverted_colors_changed_cb (EvDocumentModel *model,
4750 gboolean inverted_colors = ev_document_model_get_inverted_colors (model);
4752 ev_window_update_inverted_colors_action (window);
4754 if (window->priv->metadata && !ev_window_is_empty (window))
4755 ev_metadata_set_boolean (window->priv->metadata, "inverted-colors",
4758 ev_window_refresh_window_thumbnail (window);
4762 ev_window_dual_mode_changed_cb (EvDocumentModel *model,
4764 EvWindow *ev_window)
4766 ev_window_update_dual_page_action (ev_window);
4768 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window))
4769 ev_metadata_set_boolean (ev_window->priv->metadata, "dual-page",
4770 ev_document_model_get_dual_page (model));
4774 build_comments_string (EvDocument *document)
4776 gchar *comments = NULL;
4777 EvDocumentBackendInfo info;
4779 if (document && ev_document_get_backend_info (document, &info)) {
4780 comments = g_strdup_printf (
4781 _("Document Viewer\nUsing %s (%s)"),
4782 info.name, info.version);
4784 comments = g_strdup_printf (
4785 _("Document Viewer"));
4792 ev_window_cmd_help_about (GtkAction *action, EvWindow *ev_window)
4794 const char *authors[] = {
4795 "Martin Kretzschmar <m_kretzschmar@gmx.net>",
4796 "Jonathan Blandford <jrb@gnome.org>",
4797 "Marco Pesenti Gritti <marco@gnome.org>",
4798 "Nickolay V. Shmyrev <nshmyrev@yandex.ru>",
4799 "Bryan Clark <clarkbw@gnome.org>",
4800 "Carlos Garcia Campos <carlosgc@gnome.org>",
4801 "Wouter Bolsterlee <wbolster@gnome.org>",
4802 "Christian Persch <chpe" "\100" "gnome.org>",
4806 const char *documenters[] = {
4807 "Nickolay V. Shmyrev <nshmyrev@yandex.ru>",
4808 "Phil Bull <philbull@gmail.com>",
4809 "Tiffany Antpolski <tiffany.antopolski@gmail.com>",
4813 const char *license[] = {
4814 N_("Evince is free software; you can redistribute it and/or modify "
4815 "it under the terms of the GNU General Public License as published by "
4816 "the Free Software Foundation; either version 2 of the License, or "
4817 "(at your option) any later version.\n"),
4818 N_("Evince is distributed in the hope that it will be useful, "
4819 "but WITHOUT ANY WARRANTY; without even the implied warranty of "
4820 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
4821 "GNU General Public License for more details.\n"),
4822 N_("You should have received a copy of the GNU General Public License "
4823 "along with Evince; if not, write to the Free Software Foundation, Inc., "
4824 "51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n")
4827 char *license_trans;
4833 for (p = authors; *p; ++p)
4836 for (p = documenters; *p; ++p)
4840 license_trans = g_strconcat (_(license[0]), "\n", _(license[1]), "\n",
4841 _(license[2]), "\n", NULL);
4843 comments = build_comments_string (ev_window->priv->document);
4845 gtk_show_about_dialog (
4846 GTK_WINDOW (ev_window),
4847 "name", _("Evince"),
4850 _("© 1996–2010 The Evince authors"),
4851 "license", license_trans,
4852 "website", "http://www.gnome.org/projects/evince",
4853 "comments", comments,
4855 "documenters", documenters,
4856 "translator-credits", _("translator-credits"),
4857 "logo-icon-name", "evince",
4858 "wrap-license", TRUE,
4862 g_free (license_trans);
4866 ev_window_view_toolbar_cb (GtkAction *action, EvWindow *ev_window)
4870 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
4871 update_chrome_flag (ev_window, EV_CHROME_TOOLBAR, active);
4872 update_chrome_visibility (ev_window);
4873 if (ev_window->priv->metadata)
4874 ev_metadata_set_boolean (ev_window->priv->metadata, "show_toolbar", active);
4878 ev_window_view_sidebar_cb (GtkAction *action, EvWindow *ev_window)
4880 if (EV_WINDOW_IS_PRESENTATION (ev_window))
4883 update_chrome_flag (ev_window, EV_CHROME_SIDEBAR,
4884 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
4885 update_chrome_visibility (ev_window);
4889 ev_window_sidebar_current_page_changed_cb (EvSidebar *ev_sidebar,
4891 EvWindow *ev_window)
4893 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window)) {
4894 ev_metadata_set_string (ev_window->priv->metadata,
4896 ev_window_sidebar_get_current_page_id (ev_window));
4901 ev_window_sidebar_visibility_changed_cb (EvSidebar *ev_sidebar,
4903 EvWindow *ev_window)
4907 action = gtk_action_group_get_action (ev_window->priv->action_group, "ViewSidebar");
4909 if (!EV_WINDOW_IS_PRESENTATION (ev_window)) {
4910 gboolean visible = gtk_widget_get_visible (GTK_WIDGET (ev_sidebar));
4912 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible);
4914 if (ev_window->priv->metadata)
4915 ev_metadata_set_boolean (ev_window->priv->metadata, "sidebar_visibility",
4918 gtk_widget_grab_focus (ev_window->priv->view);
4923 view_menu_link_popup (EvWindow *ev_window,
4926 gboolean show_external = FALSE;
4927 gboolean show_internal = FALSE;
4930 if (ev_window->priv->link)
4931 g_object_unref (ev_window->priv->link);
4934 ev_window->priv->link = g_object_ref (link);
4936 ev_window->priv->link = NULL;
4938 if (ev_window->priv->link) {
4939 EvLinkAction *ev_action;
4941 ev_action = ev_link_get_action (link);
4943 switch (ev_link_action_get_action_type (ev_action)) {
4944 case EV_LINK_ACTION_TYPE_GOTO_DEST:
4945 case EV_LINK_ACTION_TYPE_GOTO_REMOTE:
4946 show_internal = TRUE;
4948 case EV_LINK_ACTION_TYPE_EXTERNAL_URI:
4949 case EV_LINK_ACTION_TYPE_LAUNCH:
4950 show_external = TRUE;
4958 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4960 gtk_action_set_visible (action, show_external);
4962 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4964 gtk_action_set_visible (action, show_external);
4966 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4968 gtk_action_set_visible (action, show_internal);
4970 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4971 "OpenLinkNewWindow");
4972 gtk_action_set_visible (action, show_internal);
4976 view_menu_image_popup (EvWindow *ev_window,
4980 gboolean show_image = FALSE;
4982 if (ev_window->priv->image)
4983 g_object_unref (ev_window->priv->image);
4986 ev_window->priv->image = g_object_ref (image);
4988 ev_window->priv->image = NULL;
4990 show_image = (ev_window->priv->image != NULL);
4992 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4994 gtk_action_set_visible (action, show_image);
4996 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4998 gtk_action_set_visible (action, show_image);
5002 view_menu_annot_popup (EvWindow *ev_window,
5003 EvAnnotation *annot)
5006 gboolean show_annot = FALSE;
5008 if (ev_window->priv->annot)
5009 g_object_unref (ev_window->priv->annot);
5010 ev_window->priv->annot = (annot) ? g_object_ref (annot) : NULL;
5012 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
5014 gtk_action_set_visible (action, (annot != NULL && EV_IS_ANNOTATION_MARKUP (annot)));
5016 if (annot && EV_IS_ANNOTATION_ATTACHMENT (annot)) {
5017 EvAttachment *attachment;
5019 attachment = ev_annotation_attachment_get_attachment (EV_ANNOTATION_ATTACHMENT (annot));
5022 if (ev_window->priv->attach_list) {
5023 g_list_foreach (ev_window->priv->attach_list,
5024 (GFunc) g_object_unref, NULL);
5025 g_list_free (ev_window->priv->attach_list);
5026 ev_window->priv->attach_list = NULL;
5028 ev_window->priv->attach_list =
5029 g_list_prepend (ev_window->priv->attach_list,
5030 g_object_ref (attachment));
5034 action = gtk_action_group_get_action (ev_window->priv->attachment_popup_action_group,
5036 gtk_action_set_visible (action, show_annot);
5038 action = gtk_action_group_get_action (ev_window->priv->attachment_popup_action_group,
5039 "SaveAttachmentAs");
5040 gtk_action_set_visible (action, show_annot);
5044 view_menu_popup_cb (EvView *view,
5046 EvWindow *ev_window)
5049 gboolean has_link = FALSE;
5050 gboolean has_image = FALSE;
5051 gboolean has_annot = FALSE;
5053 for (l = items; l; l = g_list_next (l)) {
5054 if (EV_IS_LINK (l->data)) {
5055 view_menu_link_popup (ev_window, EV_LINK (l->data));
5057 } else if (EV_IS_IMAGE (l->data)) {
5058 view_menu_image_popup (ev_window, EV_IMAGE (l->data));
5060 } else if (EV_IS_ANNOTATION (l->data)) {
5061 view_menu_annot_popup (ev_window, EV_ANNOTATION (l->data));
5067 view_menu_link_popup (ev_window, NULL);
5069 view_menu_image_popup (ev_window, NULL);
5071 view_menu_annot_popup (ev_window, NULL);
5073 gtk_menu_popup (GTK_MENU (ev_window->priv->view_popup),
5074 NULL, NULL, NULL, NULL,
5075 3, gtk_get_current_event_time ());
5080 attachment_bar_menu_popup_cb (EvSidebarAttachments *attachbar,
5082 EvWindow *ev_window)
5086 g_assert (attach_list != NULL);
5088 if (ev_window->priv->attach_list) {
5089 g_list_foreach (ev_window->priv->attach_list,
5090 (GFunc) g_object_unref, NULL);
5091 g_list_free (ev_window->priv->attach_list);
5094 ev_window->priv->attach_list = attach_list;
5096 popup = ev_window->priv->attachment_popup;
5098 gtk_menu_popup (GTK_MENU (popup), NULL, NULL,
5100 3, gtk_get_current_event_time ());
5106 ev_window_update_find_status_message (EvWindow *ev_window)
5110 if (!ev_window->priv->find_job)
5113 if (ev_job_is_finished (ev_window->priv->find_job)) {
5114 EvJobFind *job_find = EV_JOB_FIND (ev_window->priv->find_job);
5116 if (ev_job_find_has_results (job_find)) {
5119 n_results = ev_job_find_get_n_results (job_find,
5120 ev_document_model_get_page (ev_window->priv->model));
5121 /* TRANS: Sometimes this could be better translated as
5122 "%d hit(s) on this page". Therefore this string
5123 contains plural cases. */
5124 message = g_strdup_printf (ngettext ("%d found on this page",
5125 "%d found on this page",
5129 message = g_strdup (_("Not found"));
5134 percent = ev_job_find_get_progress (EV_JOB_FIND (ev_window->priv->find_job));
5135 message = g_strdup_printf (_("%3d%% remaining to search"),
5136 (gint) ((1.0 - percent) * 100));
5139 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar), message);
5144 ev_window_find_job_finished_cb (EvJobFind *job,
5145 EvWindow *ev_window)
5147 ev_window_update_find_status_message (ev_window);
5151 ev_window_find_job_updated_cb (EvJobFind *job,
5153 EvWindow *ev_window)
5155 ev_window_update_actions (ev_window);
5157 ev_view_find_changed (EV_VIEW (ev_window->priv->view),
5158 ev_job_find_get_results (job),
5160 ev_window_update_find_status_message (ev_window);
5164 ev_window_clear_find_job (EvWindow *ev_window)
5166 if (ev_window->priv->find_job != NULL) {
5167 if (!ev_job_is_finished (ev_window->priv->find_job))
5168 ev_job_cancel (ev_window->priv->find_job);
5170 g_signal_handlers_disconnect_by_func (ev_window->priv->find_job,
5171 ev_window_find_job_finished_cb,
5173 g_signal_handlers_disconnect_by_func (ev_window->priv->find_job,
5174 ev_window_find_job_updated_cb,
5176 g_object_unref (ev_window->priv->find_job);
5177 ev_window->priv->find_job = NULL;
5182 find_bar_previous_cb (EggFindBar *find_bar,
5183 EvWindow *ev_window)
5185 ev_view_find_previous (EV_VIEW (ev_window->priv->view));
5189 find_bar_next_cb (EggFindBar *find_bar,
5190 EvWindow *ev_window)
5192 ev_view_find_next (EV_VIEW (ev_window->priv->view));
5196 find_bar_close_cb (EggFindBar *find_bar,
5197 EvWindow *ev_window)
5199 ev_view_find_cancel (EV_VIEW (ev_window->priv->view));
5200 ev_window_clear_find_job (ev_window);
5201 update_chrome_flag (ev_window, EV_CHROME_FINDBAR, FALSE);
5202 update_chrome_visibility (ev_window);
5206 ev_window_search_start (EvWindow *ev_window)
5208 EggFindBar *find_bar = EGG_FIND_BAR (ev_window->priv->find_bar);
5209 const char *search_string;
5211 if (!ev_window->priv->document || !EV_IS_DOCUMENT_FIND (ev_window->priv->document))
5214 search_string = egg_find_bar_get_search_string (find_bar);
5216 ev_window_clear_find_job (ev_window);
5217 if (search_string && search_string[0]) {
5218 ev_window->priv->find_job = ev_job_find_new (ev_window->priv->document,
5219 ev_document_model_get_page (ev_window->priv->model),
5220 ev_document_get_n_pages (ev_window->priv->document),
5222 egg_find_bar_get_case_sensitive (find_bar));
5223 g_signal_connect (ev_window->priv->find_job, "finished",
5224 G_CALLBACK (ev_window_find_job_finished_cb),
5226 g_signal_connect (ev_window->priv->find_job, "updated",
5227 G_CALLBACK (ev_window_find_job_updated_cb),
5229 ev_job_scheduler_push_job (ev_window->priv->find_job, EV_JOB_PRIORITY_NONE);
5231 ev_window_update_actions (ev_window);
5232 egg_find_bar_set_status_text (find_bar, NULL);
5233 gtk_widget_queue_draw (GTK_WIDGET (ev_window->priv->view));
5238 find_bar_search_changed_cb (EggFindBar *find_bar,
5240 EvWindow *ev_window)
5242 /* Either the string or case sensitivity could have changed. */
5243 ev_view_find_search_changed (EV_VIEW (ev_window->priv->view));
5244 ev_window_search_start (ev_window);
5248 find_bar_visibility_changed_cb (EggFindBar *find_bar,
5250 EvWindow *ev_window)
5254 visible = gtk_widget_get_visible (GTK_WIDGET (find_bar));
5256 if (ev_window->priv->document &&
5257 EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
5258 ev_view_find_set_highlight_search (EV_VIEW (ev_window->priv->view), visible);
5259 ev_window_update_actions (ev_window);
5262 ev_window_search_start (ev_window);
5264 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar), NULL);
5269 find_bar_scroll (EggFindBar *find_bar,
5270 GtkScrollType scroll,
5271 EvWindow *ev_window)
5273 ev_view_scroll (EV_VIEW (ev_window->priv->view), scroll, FALSE);
5277 zoom_control_changed_cb (EphyZoomAction *action,
5279 EvWindow *ev_window)
5283 if (zoom == EPHY_ZOOM_BEST_FIT) {
5284 mode = EV_SIZING_BEST_FIT;
5285 } else if (zoom == EPHY_ZOOM_FIT_WIDTH) {
5286 mode = EV_SIZING_FIT_WIDTH;
5288 mode = EV_SIZING_FREE;
5291 ev_document_model_set_sizing_mode (ev_window->priv->model, mode);
5293 if (mode == EV_SIZING_FREE) {
5294 ev_document_model_set_scale (ev_window->priv->model,
5295 zoom * get_screen_dpi (ev_window) / 72.0);
5300 ev_window_drag_data_received (GtkWidget *widget,
5301 GdkDragContext *context,
5304 GtkSelectionData *selection_data,
5309 EvWindow *window = EV_WINDOW (widget);
5312 GSList *uri_list = NULL;
5315 source = gtk_drag_get_source_widget (context);
5316 if (source && widget == gtk_widget_get_toplevel (source)) {
5317 gtk_drag_finish (context, FALSE, FALSE, time);
5321 uris = gtk_selection_data_get_uris (selection_data);
5323 gtk_drag_finish (context, FALSE, FALSE, time);
5327 for (i = 0; uris[i]; i++) {
5328 uri_list = g_slist_prepend (uri_list, (gpointer) uris[i]);
5331 ev_application_open_uri_list (EV_APP, uri_list,
5332 gtk_window_get_screen (GTK_WINDOW (window)),
5334 gtk_drag_finish (context, TRUE, FALSE, time);
5337 g_slist_free (uri_list);
5341 ev_window_finalize (GObject *object)
5343 G_OBJECT_CLASS (ev_window_parent_class)->finalize (object);
5345 if (ev_window_n_copies == 0) {
5346 ev_application_shutdown (EV_APP);
5348 ev_window_n_copies--;
5353 ev_window_dispose (GObject *object)
5355 EvWindow *window = EV_WINDOW (object);
5356 EvWindowPrivate *priv = window->priv;
5357 GObject *mpkeys = ev_application_get_media_keys (EV_APP);
5360 g_signal_handlers_disconnect_by_func (mpkeys,
5361 ev_window_media_player_key_pressed,
5366 if (priv->dbus_object_id > 0) {
5367 ev_window_emit_closed (window);
5368 g_dbus_connection_unregister_object (ev_application_get_dbus_connection (EV_APP),
5369 priv->dbus_object_id);
5370 priv->dbus_object_id = 0;
5373 if (priv->dbus_object_path) {
5374 g_free (priv->dbus_object_path);
5375 priv->dbus_object_path = NULL;
5377 #endif /* ENABLE_DBUS */
5379 if (priv->bookmarks) {
5380 g_object_unref (priv->bookmarks);
5381 priv->bookmarks = NULL;
5384 if (priv->metadata) {
5385 g_object_unref (priv->metadata);
5386 priv->metadata = NULL;
5389 if (priv->setup_document_idle > 0) {
5390 g_source_remove (priv->setup_document_idle);
5391 priv->setup_document_idle = 0;
5394 if (priv->monitor) {
5395 g_object_unref (priv->monitor);
5396 priv->monitor = NULL;
5400 ev_window_title_free (priv->title);
5404 if (priv->ui_manager) {
5405 g_object_unref (priv->ui_manager);
5406 priv->ui_manager = NULL;
5409 if (priv->action_group) {
5410 g_object_unref (priv->action_group);
5411 priv->action_group = NULL;
5414 if (priv->view_popup_action_group) {
5415 g_object_unref (priv->view_popup_action_group);
5416 priv->view_popup_action_group = NULL;
5419 if (priv->attachment_popup_action_group) {
5420 g_object_unref (priv->attachment_popup_action_group);
5421 priv->attachment_popup_action_group = NULL;
5424 if (priv->recent_action_group) {
5425 g_object_unref (priv->recent_action_group);
5426 priv->recent_action_group = NULL;
5429 if (priv->bookmarks_action_group) {
5430 g_object_unref (priv->bookmarks_action_group);
5431 priv->bookmarks_action_group = NULL;
5434 if (priv->recent_manager) {
5435 g_signal_handlers_disconnect_by_func (priv->recent_manager,
5436 ev_window_setup_recent,
5438 priv->recent_manager = NULL;
5441 if (priv->settings) {
5442 g_object_unref (priv->settings);
5443 priv->settings = NULL;
5446 if (priv->default_settings) {
5447 g_settings_apply (priv->default_settings);
5448 g_object_unref (priv->default_settings);
5449 priv->default_settings = NULL;
5452 if (priv->lockdown_settings) {
5453 g_object_unref (priv->lockdown_settings);
5454 priv->lockdown_settings = NULL;
5457 priv->recent_ui_id = 0;
5460 g_signal_handlers_disconnect_by_func (priv->model,
5461 ev_window_page_changed_cb,
5463 g_object_unref (priv->model);
5467 if (priv->document) {
5468 g_object_unref (priv->document);
5469 priv->document = NULL;
5473 g_object_unref (priv->view);
5477 if (priv->password_view) {
5478 g_object_unref (priv->password_view);
5479 priv->password_view = NULL;
5482 if (priv->load_job) {
5483 ev_window_clear_load_job (window);
5486 if (priv->reload_job) {
5487 ev_window_clear_reload_job (window);
5490 if (priv->save_job) {
5491 ev_window_clear_save_job (window);
5494 if (priv->thumbnail_job) {
5495 ev_window_clear_thumbnail_job (window);
5498 if (priv->find_job) {
5499 ev_window_clear_find_job (window);
5502 if (priv->local_uri) {
5503 ev_window_clear_local_uri (window);
5504 priv->local_uri = NULL;
5507 ev_window_clear_progress_idle (window);
5508 if (priv->progress_cancellable) {
5509 g_object_unref (priv->progress_cancellable);
5510 priv->progress_cancellable = NULL;
5513 ev_window_close_dialogs (window);
5516 g_object_unref (priv->link);
5521 g_object_unref (priv->image);
5526 g_object_unref (priv->annot);
5530 if (priv->attach_list) {
5531 g_list_foreach (priv->attach_list,
5532 (GFunc) g_object_unref,
5534 g_list_free (priv->attach_list);
5535 priv->attach_list = NULL;
5538 if (priv->find_bar) {
5539 g_signal_handlers_disconnect_by_func
5540 (window->priv->find_bar,
5541 G_CALLBACK (find_bar_close_cb),
5543 priv->find_bar = NULL;
5551 if (priv->search_string) {
5552 g_free (priv->search_string);
5553 priv->search_string = NULL;
5557 g_object_unref (priv->dest);
5561 if (priv->history) {
5562 g_object_unref (priv->history);
5563 priv->history = NULL;
5566 if (priv->print_queue) {
5567 g_queue_free (priv->print_queue);
5568 priv->print_queue = NULL;
5571 G_OBJECT_CLASS (ev_window_parent_class)->dispose (object);
5575 menubar_deactivate_cb (GtkWidget *menubar,
5578 g_signal_handlers_disconnect_by_func (menubar,
5579 G_CALLBACK (menubar_deactivate_cb),
5582 gtk_menu_shell_deselect (GTK_MENU_SHELL (menubar));
5584 update_chrome_visibility (window);
5588 ev_window_key_press_event (GtkWidget *widget,
5591 EvWindow *ev_window = EV_WINDOW (widget);
5592 EvWindowPrivate *priv = ev_window->priv;
5593 gboolean handled = FALSE;
5595 /* Propagate the event to the view first
5596 * It's needed to be able to type in
5597 * annot popups windows
5600 g_object_ref (priv->view);
5601 if (gtk_widget_is_sensitive (priv->view))
5602 handled = gtk_widget_event (priv->view, (GdkEvent*) event);
5603 g_object_unref (priv->view);
5606 if (!handled && !EV_WINDOW_IS_PRESENTATION (ev_window)) {
5607 guint modifier = event->state & gtk_accelerator_get_default_mod_mask ();
5609 if (priv->menubar_accel_keyval != 0 &&
5610 event->keyval == priv->menubar_accel_keyval &&
5611 modifier == priv->menubar_accel_modifier) {
5612 if (!gtk_widget_get_visible (priv->menubar)) {
5613 g_signal_connect (priv->menubar, "deactivate",
5614 G_CALLBACK (menubar_deactivate_cb),
5617 gtk_widget_show (priv->menubar);
5618 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menubar),
5627 handled = GTK_WIDGET_CLASS (ev_window_parent_class)->key_press_event (widget, event);
5633 ev_window_delete_event (GtkWidget *widget,
5636 return !ev_window_close (EV_WINDOW (widget));
5640 ev_window_class_init (EvWindowClass *ev_window_class)
5642 GObjectClass *g_object_class = G_OBJECT_CLASS (ev_window_class);
5643 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (ev_window_class);
5645 g_object_class->dispose = ev_window_dispose;
5646 g_object_class->finalize = ev_window_finalize;
5648 widget_class->delete_event = ev_window_delete_event;
5649 widget_class->key_press_event = ev_window_key_press_event;
5650 widget_class->screen_changed = ev_window_screen_changed;
5651 widget_class->window_state_event = ev_window_state_event;
5652 widget_class->drag_data_received = ev_window_drag_data_received;
5654 g_type_class_add_private (g_object_class, sizeof (EvWindowPrivate));
5658 static const GtkActionEntry entries[] = {
5659 { "File", NULL, N_("_File") },
5660 { "Edit", NULL, N_("_Edit") },
5661 { "View", NULL, N_("_View") },
5662 { "Go", NULL, N_("_Go") },
5663 { "Bookmarks", NULL, N_("_Bookmarks") },
5664 { "Help", NULL, N_("_Help") },
5667 { "FileOpen", GTK_STOCK_OPEN, N_("_Open…"), "<control>O",
5668 N_("Open an existing document"),
5669 G_CALLBACK (ev_window_cmd_file_open) },
5670 { "FileOpenCopy", NULL, N_("Op_en a Copy"), "<control>N",
5671 N_("Open a copy of the current document in a new window"),
5672 G_CALLBACK (ev_window_cmd_file_open_copy) },
5673 { "FileSaveAs", GTK_STOCK_SAVE_AS, N_("_Save a Copy…"), "<control>S",
5674 N_("Save a copy of the current document"),
5675 G_CALLBACK (ev_window_cmd_save_as) },
5676 { "FileOpenContainingFolder", GTK_STOCK_DIRECTORY, N_("Open Containing _Folder"), NULL,
5677 N_("Show the folder which contains this file in the file manager"),
5678 G_CALLBACK (ev_window_cmd_open_containing_folder) },
5679 { "FilePrint", GTK_STOCK_PRINT, N_("_Print…"), "<control>P",
5680 N_("Print this document"),
5681 G_CALLBACK (ev_window_cmd_file_print) },
5682 { "FileProperties", GTK_STOCK_PROPERTIES, N_("P_roperties"), "<alt>Return", NULL,
5683 G_CALLBACK (ev_window_cmd_file_properties) },
5684 { "FileCloseWindow", GTK_STOCK_CLOSE, NULL, "<control>W", NULL,
5685 G_CALLBACK (ev_window_cmd_file_close_window) },
5688 { "EditCopy", GTK_STOCK_COPY, NULL, "<control>C", NULL,
5689 G_CALLBACK (ev_window_cmd_edit_copy) },
5690 { "EditSelectAll", GTK_STOCK_SELECT_ALL, N_("Select _All"), "<control>A", NULL,
5691 G_CALLBACK (ev_window_cmd_edit_select_all) },
5692 { "EditFind", GTK_STOCK_FIND, N_("_Find…"), "<control>F",
5693 N_("Find a word or phrase in the document"),
5694 G_CALLBACK (ev_window_cmd_edit_find) },
5695 { "EditFindNext", NULL, N_("Find Ne_xt"), "<control>G", NULL,
5696 G_CALLBACK (ev_window_cmd_edit_find_next) },
5697 { "EditFindPrevious", NULL, N_("Find Pre_vious"), "<shift><control>G", NULL,
5698 G_CALLBACK (ev_window_cmd_edit_find_previous) },
5699 { "EditToolbar", NULL, N_("T_oolbar"), NULL, NULL,
5700 G_CALLBACK (ev_window_cmd_edit_toolbar) },
5701 { "EditRotateLeft", EV_STOCK_ROTATE_LEFT, N_("Rotate _Left"), "<control>Left", NULL,
5702 G_CALLBACK (ev_window_cmd_edit_rotate_left) },
5703 { "EditRotateRight", EV_STOCK_ROTATE_RIGHT, N_("Rotate _Right"), "<control>Right", NULL,
5704 G_CALLBACK (ev_window_cmd_edit_rotate_right) },
5705 { "EditSaveSettings", NULL, N_("Save Current Settings as _Default"), "<control>T", NULL,
5706 G_CALLBACK (ev_window_cmd_edit_save_settings) },
5710 { "ViewZoomIn", GTK_STOCK_ZOOM_IN, NULL, "<control>plus",
5711 N_("Enlarge the document"),
5712 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5713 { "ViewZoomOut", GTK_STOCK_ZOOM_OUT, NULL, "<control>minus",
5714 N_("Shrink the document"),
5715 G_CALLBACK (ev_window_cmd_view_zoom_out) },
5716 { "ViewReload", GTK_STOCK_REFRESH, N_("_Reload"), "<control>R",
5717 N_("Reload the document"),
5718 G_CALLBACK (ev_window_cmd_view_reload) },
5720 { "ViewAutoscroll", GTK_STOCK_MEDIA_PLAY, N_("Auto_scroll"), NULL, NULL,
5721 G_CALLBACK (ev_window_cmd_view_autoscroll) },
5724 { "GoPreviousPage", GTK_STOCK_GO_UP, N_("_Previous Page"), "<control>Page_Up",
5725 N_("Go to the previous page"),
5726 G_CALLBACK (ev_window_cmd_go_previous_page) },
5727 { "GoNextPage", GTK_STOCK_GO_DOWN, N_("_Next Page"), "<control>Page_Down",
5728 N_("Go to the next page"),
5729 G_CALLBACK (ev_window_cmd_go_next_page) },
5730 { "GoFirstPage", GTK_STOCK_GOTO_TOP, N_("_First Page"), "<control>Home",
5731 N_("Go to the first page"),
5732 G_CALLBACK (ev_window_cmd_go_first_page) },
5733 { "GoLastPage", GTK_STOCK_GOTO_BOTTOM, N_("_Last Page"), "<control>End",
5734 N_("Go to the last page"),
5735 G_CALLBACK (ev_window_cmd_go_last_page) },
5737 /* Bookmarks menu */
5738 { "BookmarksAdd", GTK_STOCK_ADD, N_("_Add Bookmark"), "<control>D",
5739 N_("Add a bookmark for the current page"),
5740 G_CALLBACK (ev_window_cmd_bookmarks_add) },
5743 { "HelpContents", GTK_STOCK_HELP, N_("_Contents"), "F1", NULL,
5744 G_CALLBACK (ev_window_cmd_help_contents) },
5746 { "HelpAbout", GTK_STOCK_ABOUT, N_("_About"), NULL, NULL,
5747 G_CALLBACK (ev_window_cmd_help_about) },
5750 { "LeaveFullscreen", GTK_STOCK_LEAVE_FULLSCREEN, N_("Leave Fullscreen"), NULL,
5751 N_("Leave fullscreen mode"),
5752 G_CALLBACK (ev_window_cmd_leave_fullscreen) },
5753 { "StartPresentation", EV_STOCK_RUN_PRESENTATION, N_("Start Presentation"), NULL,
5754 N_("Start a presentation"),
5755 G_CALLBACK (ev_window_cmd_start_presentation) },
5758 { "Escape", NULL, "", "Escape", "",
5759 G_CALLBACK (ev_window_cmd_escape) },
5760 { "Slash", GTK_STOCK_FIND, NULL, "slash", NULL,
5761 G_CALLBACK (ev_window_cmd_edit_find) },
5762 { "F3", NULL, "", "F3", NULL,
5763 G_CALLBACK (ev_window_cmd_edit_find_next) },
5764 { "PageDown", NULL, "", "Page_Down", NULL,
5765 G_CALLBACK (ev_window_cmd_scroll_forward) },
5766 { "PageUp", NULL, "", "Page_Up", NULL,
5767 G_CALLBACK (ev_window_cmd_scroll_backward) },
5768 { "Space", NULL, "", "space", NULL,
5769 G_CALLBACK (ev_window_cmd_scroll_forward) },
5770 { "ShiftSpace", NULL, "", "<shift>space", NULL,
5771 G_CALLBACK (ev_window_cmd_scroll_backward) },
5772 { "BackSpace", NULL, "", "BackSpace", NULL,
5773 G_CALLBACK (ev_window_cmd_scroll_backward) },
5774 { "ShiftBackSpace", NULL, "", "<shift>BackSpace", NULL,
5775 G_CALLBACK (ev_window_cmd_scroll_forward) },
5776 { "Return", NULL, "", "Return", NULL,
5777 G_CALLBACK (ev_window_cmd_scroll_forward) },
5778 { "ShiftReturn", NULL, "", "<shift>Return", NULL,
5779 G_CALLBACK (ev_window_cmd_scroll_backward) },
5780 { "p", GTK_STOCK_GO_UP, "", "p", NULL,
5781 G_CALLBACK (ev_window_cmd_go_previous_page) },
5782 { "n", GTK_STOCK_GO_DOWN, "", "n", NULL,
5783 G_CALLBACK (ev_window_cmd_go_next_page) },
5784 { "Plus", GTK_STOCK_ZOOM_IN, NULL, "plus", NULL,
5785 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5786 { "CtrlEqual", GTK_STOCK_ZOOM_IN, NULL, "<control>equal", NULL,
5787 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5788 { "Equal", GTK_STOCK_ZOOM_IN, NULL, "equal", NULL,
5789 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5790 { "Minus", GTK_STOCK_ZOOM_OUT, NULL, "minus", NULL,
5791 G_CALLBACK (ev_window_cmd_view_zoom_out) },
5792 { "FocusPageSelector", NULL, "", "<control>l", NULL,
5793 G_CALLBACK (ev_window_cmd_focus_page_selector) },
5794 { "GoBackwardFast", NULL, "", "<shift>Page_Up", NULL,
5795 G_CALLBACK (ev_window_cmd_go_backward) },
5796 { "GoForwardFast", NULL, "", "<shift>Page_Down", NULL,
5797 G_CALLBACK (ev_window_cmd_go_forward) },
5798 { "KpPlus", GTK_STOCK_ZOOM_IN, NULL, "KP_Add", NULL,
5799 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5800 { "KpMinus", GTK_STOCK_ZOOM_OUT, NULL, "KP_Subtract", NULL,
5801 G_CALLBACK (ev_window_cmd_view_zoom_out) },
5802 { "CtrlKpPlus", GTK_STOCK_ZOOM_IN, NULL, "<control>KP_Add", NULL,
5803 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5804 { "CtrlKpMinus", GTK_STOCK_ZOOM_OUT, NULL, "<control>KP_Subtract", NULL,
5805 G_CALLBACK (ev_window_cmd_view_zoom_out) },
5806 { "CtrlInsert", GTK_STOCK_COPY, NULL, "<control>Insert", NULL,
5807 G_CALLBACK (ev_window_cmd_edit_copy) },
5811 static const GtkToggleActionEntry toggle_entries[] = {
5813 { "ViewToolbar", NULL, N_("_Toolbar"), NULL,
5814 N_("Show or hide the toolbar"),
5815 G_CALLBACK (ev_window_view_toolbar_cb), TRUE },
5816 { "ViewSidebar", GTK_STOCK_INDEX, N_("Side _Pane"), "F9",
5817 N_("Show or hide the side pane"),
5818 G_CALLBACK (ev_window_view_sidebar_cb), TRUE },
5819 { "ViewContinuous", EV_STOCK_VIEW_CONTINUOUS, N_("_Continuous"), NULL,
5820 N_("Show the entire document"),
5821 G_CALLBACK (ev_window_cmd_continuous), TRUE },
5822 { "ViewDual", EV_STOCK_VIEW_DUAL, N_("_Dual"), NULL,
5823 N_("Show two pages at once"),
5824 G_CALLBACK (ev_window_cmd_dual), FALSE },
5825 { "ViewFullscreen", GTK_STOCK_FULLSCREEN, N_("_Fullscreen"), "F11",
5826 N_("Expand the window to fill the screen"),
5827 G_CALLBACK (ev_window_cmd_view_fullscreen) },
5828 { "ViewPresentation", EV_STOCK_RUN_PRESENTATION, N_("Pre_sentation"), "F5",
5829 N_("Run document as a presentation"),
5830 G_CALLBACK (ev_window_cmd_view_presentation) },
5831 { "ViewBestFit", EV_STOCK_ZOOM_PAGE, N_("_Best Fit"), NULL,
5832 N_("Make the current document fill the window"),
5833 G_CALLBACK (ev_window_cmd_view_best_fit) },
5834 { "ViewPageWidth", EV_STOCK_ZOOM_WIDTH, N_("Fit Page _Width"), NULL,
5835 N_("Make the current document fill the window width"),
5836 G_CALLBACK (ev_window_cmd_view_page_width) },
5837 { "ViewInvertedColors", EV_STOCK_INVERTED_COLORS, N_("_Inverted Colors"), "<control>I",
5838 N_("Show page contents with the colors inverted"),
5839 G_CALLBACK (ev_window_cmd_view_inverted_colors) },
5843 /* Popups specific items */
5844 static const GtkActionEntry view_popup_entries [] = {
5846 { "OpenLink", GTK_STOCK_OPEN, N_("_Open Link"), NULL,
5847 NULL, G_CALLBACK (ev_view_popup_cmd_open_link) },
5848 { "GoLink", GTK_STOCK_GO_FORWARD, N_("_Go To"), NULL,
5849 NULL, G_CALLBACK (ev_view_popup_cmd_open_link) },
5850 { "OpenLinkNewWindow", NULL, N_("Open in New _Window"), NULL,
5851 NULL, G_CALLBACK (ev_view_popup_cmd_open_link_new_window) },
5852 { "CopyLinkAddress", NULL, N_("_Copy Link Address"), NULL,
5853 NULL, G_CALLBACK (ev_view_popup_cmd_copy_link_address) },
5854 { "SaveImageAs", NULL, N_("_Save Image As…"), NULL,
5855 NULL, G_CALLBACK (ev_view_popup_cmd_save_image_as) },
5856 { "CopyImage", NULL, N_("Copy _Image"), NULL,
5857 NULL, G_CALLBACK (ev_view_popup_cmd_copy_image) },
5858 { "AnnotProperties", NULL, N_("Annotation Properties…"), NULL,
5859 NULL, G_CALLBACK (ev_view_popup_cmd_annot_properties) }
5862 static const GtkActionEntry attachment_popup_entries [] = {
5863 { "OpenAttachment", GTK_STOCK_OPEN, N_("_Open Attachment"), NULL,
5864 NULL, G_CALLBACK (ev_attachment_popup_cmd_open_attachment) },
5865 { "SaveAttachmentAs", GTK_STOCK_SAVE_AS, N_("_Save Attachment As…"), NULL,
5866 NULL, G_CALLBACK (ev_attachment_popup_cmd_save_attachment_as) },
5870 sidebar_links_link_activated_cb (EvSidebarLinks *sidebar_links, EvLink *link, EvWindow *window)
5872 ev_view_handle_link (EV_VIEW (window->priv->view), link);
5876 activate_link_cb (EvPageAction *page_action, EvLink *link, EvWindow *window)
5878 ev_view_handle_link (EV_VIEW (window->priv->view), link);
5879 gtk_widget_grab_focus (window->priv->view);
5883 navigation_action_activate_link_cb (EvNavigationAction *action, EvLink *link, EvWindow *window)
5886 ev_view_handle_link (EV_VIEW (window->priv->view), link);
5887 gtk_widget_grab_focus (window->priv->view);
5891 sidebar_layers_visibility_changed (EvSidebarLayers *layers,
5894 ev_view_reload (EV_VIEW (window->priv->view));
5898 sidebar_annots_annot_activated_cb (EvSidebarAnnotations *sidebar_annots,
5899 EvMapping *annot_mapping,
5902 ev_view_focus_annotation (EV_VIEW (window->priv->view), annot_mapping);
5906 sidebar_annots_begin_annot_add (EvSidebarAnnotations *sidebar_annots,
5907 EvAnnotationType annot_type,
5910 ev_view_begin_add_annotation (EV_VIEW (window->priv->view), annot_type);
5914 view_annot_added (EvView *view,
5915 EvAnnotation *annot,
5918 ev_sidebar_annotations_annot_added (EV_SIDEBAR_ANNOTATIONS (window->priv->sidebar_annots),
5923 sidebar_annots_annot_add_cancelled (EvSidebarAnnotations *sidebar_annots,
5926 ev_view_cancel_add_annotation (EV_VIEW (window->priv->view));
5930 sidebar_bookmarks_add_bookmark (EvSidebarBookmarks *sidebar_bookmarks,
5933 ev_window_cmd_bookmarks_add (NULL, window);
5937 register_custom_actions (EvWindow *window, GtkActionGroup *group)
5941 action = g_object_new (EV_TYPE_PAGE_ACTION,
5942 "name", PAGE_SELECTOR_ACTION,
5944 "tooltip", _("Select Page"),
5945 "icon_name", "text-x-generic",
5946 "visible_overflown", FALSE,
5948 ev_page_action_set_model (EV_PAGE_ACTION (action),
5949 window->priv->model);
5950 g_signal_connect (action, "activate_link",
5951 G_CALLBACK (activate_link_cb), window);
5952 gtk_action_group_add_action (group, action);
5953 g_object_unref (action);
5955 action = g_object_new (EPHY_TYPE_ZOOM_ACTION,
5956 "name", ZOOM_CONTROL_ACTION,
5958 "stock_id", EV_STOCK_ZOOM,
5959 "tooltip", _("Adjust the zoom level"),
5962 g_signal_connect (action, "zoom_to_level",
5963 G_CALLBACK (zoom_control_changed_cb), window);
5964 gtk_action_group_add_action (group, action);
5965 g_object_unref (action);
5967 action = g_object_new (EV_TYPE_NAVIGATION_ACTION,
5968 "name", NAVIGATION_ACTION,
5969 "label", _("Navigation"),
5970 "is_important", TRUE,
5971 "short_label", _("Back"),
5972 "stock_id", GTK_STOCK_GO_DOWN,
5973 /*translators: this is the history action*/
5974 "tooltip", _("Move across visited pages"),
5976 g_signal_connect (action, "activate_link",
5977 G_CALLBACK (navigation_action_activate_link_cb), window);
5978 gtk_action_group_add_action (group, action);
5979 g_object_unref (action);
5981 action = g_object_new (EV_TYPE_OPEN_RECENT_ACTION,
5982 "name", "FileOpenRecent",
5983 "label", _("_Open…"),
5984 "tooltip", _("Open an existing document"),
5985 "stock_id", GTK_STOCK_OPEN,
5987 g_signal_connect (action, "activate",
5988 G_CALLBACK (ev_window_cmd_file_open), window);
5989 g_signal_connect (action, "item_activated",
5990 G_CALLBACK (ev_window_open_recent_action_item_activated),
5992 gtk_action_group_add_action (group, action);
5993 g_object_unref (action);
5997 set_action_properties (GtkActionGroup *action_group)
6001 action = gtk_action_group_get_action (action_group, "FileOpenContainingFolder");
6002 /*translators: this is the label for toolbar button*/
6003 g_object_set (action, "short_label", _("Open Folder"), NULL);
6005 action = gtk_action_group_get_action (action_group, "GoPreviousPage");
6006 g_object_set (action, "is-important", TRUE, NULL);
6007 /*translators: this is the label for toolbar button*/
6008 g_object_set (action, "short_label", _("Previous"), NULL);
6010 action = gtk_action_group_get_action (action_group, "GoNextPage");
6011 g_object_set (action, "is-important", TRUE, NULL);
6012 /*translators: this is the label for toolbar button*/
6013 g_object_set (action, "short_label", _("Next"), NULL);
6015 action = gtk_action_group_get_action (action_group, "ViewZoomIn");
6016 /*translators: this is the label for toolbar button*/
6017 g_object_set (action, "short_label", _("Zoom In"), NULL);
6019 action = gtk_action_group_get_action (action_group, "ViewZoomOut");
6020 /*translators: this is the label for toolbar button*/
6021 g_object_set (action, "short_label", _("Zoom Out"), NULL);
6023 action = gtk_action_group_get_action (action_group, "ViewBestFit");
6024 /*translators: this is the label for toolbar button*/
6025 g_object_set (action, "short_label", _("Best Fit"), NULL);
6027 action = gtk_action_group_get_action (action_group, "ViewPageWidth");
6028 /*translators: this is the label for toolbar button*/
6029 g_object_set (action, "short_label", _("Fit Width"), NULL);
6031 action = gtk_action_group_get_action (action_group, "LeaveFullscreen");
6032 g_object_set (action, "is-important", TRUE, NULL);
6036 sidebar_widget_model_set (EvSidebarLinks *ev_sidebar_links,
6038 EvWindow *ev_window)
6040 GtkTreeModel *model;
6043 g_object_get (G_OBJECT (ev_sidebar_links),
6047 action = gtk_action_group_get_action (ev_window->priv->action_group, PAGE_SELECTOR_ACTION);
6048 ev_page_action_set_links_model (EV_PAGE_ACTION (action), model);
6049 g_object_unref (model);
6053 view_actions_focus_in_cb (GtkWidget *widget, GdkEventFocus *event, EvWindow *window)
6058 keys = ev_application_get_media_keys (EV_APP);
6059 ev_media_player_keys_focused (EV_MEDIA_PLAYER_KEYS (keys));
6060 #endif /* ENABLE_DBUS */
6062 update_chrome_flag (window, EV_CHROME_RAISE_TOOLBAR, FALSE);
6063 ev_window_set_action_sensitive (window, "ViewToolbar",
6064 !ev_window_is_editing_toolbar (window));
6066 ev_window_set_view_accels_sensitivity (window, TRUE);
6068 update_chrome_visibility (window);
6074 view_actions_focus_out_cb (GtkWidget *widget, GdkEventFocus *event, EvWindow *window)
6076 ev_window_set_view_accels_sensitivity (window, FALSE);
6082 sidebar_page_main_widget_update_cb (GObject *ev_sidebar_page,
6084 EvWindow *ev_window)
6088 g_object_get (ev_sidebar_page, "main_widget", &widget, NULL);
6090 if (widget != NULL) {
6091 g_signal_connect_object (widget, "focus_in_event",
6092 G_CALLBACK (view_actions_focus_in_cb),
6094 g_signal_connect_object (widget, "focus_out_event",
6095 G_CALLBACK (view_actions_focus_out_cb),
6097 g_object_unref (widget);
6102 window_state_event_cb (EvWindow *window, GdkEventWindowState *event, gpointer dummy)
6104 if (!(event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN)) {
6107 maximized = event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED;
6108 if (window->priv->metadata && !ev_window_is_empty (window))
6109 ev_metadata_set_boolean (window->priv->metadata, "window_maximized", maximized);
6116 window_configure_event_cb (EvWindow *window, GdkEventConfigure *event, gpointer dummy)
6118 GdkWindowState state;
6119 gdouble document_width, document_height;
6121 if (!window->priv->metadata)
6124 state = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (window)));
6126 if (!(state & GDK_WINDOW_STATE_FULLSCREEN)) {
6127 if (window->priv->document) {
6128 ev_document_get_max_page_size (window->priv->document,
6129 &document_width, &document_height);
6130 g_settings_set (window->priv->default_settings, "window-ratio", "(dd)",
6131 (double)event->width / document_width,
6132 (double)event->height / document_height);
6134 ev_metadata_set_int (window->priv->metadata, "window_x", event->x);
6135 ev_metadata_set_int (window->priv->metadata, "window_y", event->y);
6136 ev_metadata_set_int (window->priv->metadata, "window_width", event->width);
6137 ev_metadata_set_int (window->priv->metadata, "window_height", event->height);
6145 launch_action (EvWindow *window, EvLinkAction *action)
6147 const char *filename = ev_link_action_get_filename (action);
6150 GList file_list = {NULL};
6151 GAppLaunchContext *context;
6152 GError *error = NULL;
6154 if (filename == NULL)
6157 if (g_path_is_absolute (filename)) {
6158 file = g_file_new_for_path (filename);
6163 dir = g_path_get_dirname (window->priv->uri);
6164 base_file = g_file_new_for_uri (dir);
6167 file = g_file_resolve_relative_path (base_file, filename);
6168 g_object_unref (base_file);
6171 app_info = g_file_query_default_handler (file, NULL, &error);
6173 ev_window_error_message (window, error,
6175 _("Unable to launch external application."));
6176 g_object_unref (file);
6177 g_error_free (error);
6182 context = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
6183 gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (context),
6184 gtk_window_get_screen (GTK_WINDOW (window)));
6185 gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (context),
6186 gtk_get_current_event_time ());
6188 file_list.data = file;
6189 if (!g_app_info_launch (app_info, &file_list, context, &error)) {
6190 ev_window_error_message (window, error,
6192 _("Unable to launch external application."));
6193 g_error_free (error);
6196 g_object_unref (app_info);
6197 g_object_unref (file);
6198 /* FIXMEchpe: unref launch context? */
6200 /* According to the PDF spec filename can be an executable. I'm not sure
6201 allowing to launch executables is a good idea though. -- marco */
6205 launch_external_uri (EvWindow *window, EvLinkAction *action)
6207 const gchar *uri = ev_link_action_get_uri (action);
6208 GError *error = NULL;
6210 GAppLaunchContext *context;
6212 context = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
6213 gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (context),
6214 gtk_window_get_screen (GTK_WINDOW (window)));
6215 gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (context),
6216 gtk_get_current_event_time ());
6218 if (!g_strstr_len (uri, strlen (uri), "://") &&
6219 !g_str_has_prefix (uri, "mailto:")) {
6222 /* Not a valid uri, assume http if it starts with www */
6223 if (g_str_has_prefix (uri, "www.")) {
6224 new_uri = g_strdup_printf ("http://%s", uri);
6226 GFile *file, *parent;
6228 file = g_file_new_for_uri (window->priv->uri);
6229 parent = g_file_get_parent (file);
6230 g_object_unref (file);
6232 gchar *parent_uri = g_file_get_uri (parent);
6234 new_uri = g_build_filename (parent_uri, uri, NULL);
6235 g_free (parent_uri);
6236 g_object_unref (parent);
6238 new_uri = g_strdup_printf ("file:///%s", uri);
6241 ret = g_app_info_launch_default_for_uri (new_uri, context, &error);
6244 ret = g_app_info_launch_default_for_uri (uri, context, &error);
6248 ev_window_error_message (window, error,
6249 "%s", _("Unable to open external link"));
6250 g_error_free (error);
6253 /* FIXMEchpe: unref launch context? */
6257 open_remote_link (EvWindow *window, EvLinkAction *action)
6262 dir = g_path_get_dirname (window->priv->uri);
6264 uri = g_build_filename (dir, ev_link_action_get_filename (action),
6268 ev_application_open_uri_at_dest (EV_APP, uri,
6269 gtk_window_get_screen (GTK_WINDOW (window)),
6270 ev_link_action_get_dest (action),
6273 gtk_get_current_event_time ());
6279 do_action_named (EvWindow *window, EvLinkAction *action)
6281 const gchar *name = ev_link_action_get_name (action);
6283 if (g_ascii_strcasecmp (name, "FirstPage") == 0) {
6284 ev_window_cmd_go_first_page (NULL, window);
6285 } else if (g_ascii_strcasecmp (name, "PrevPage") == 0) {
6286 ev_window_cmd_go_previous_page (NULL, window);
6287 } else if (g_ascii_strcasecmp (name, "NextPage") == 0) {
6288 ev_window_cmd_go_next_page (NULL, window);
6289 } else if (g_ascii_strcasecmp (name, "LastPage") == 0) {
6290 ev_window_cmd_go_last_page (NULL, window);
6291 } else if (g_ascii_strcasecmp (name, "GoToPage") == 0) {
6292 ev_window_cmd_focus_page_selector (NULL, window);
6293 } else if (g_ascii_strcasecmp (name, "Find") == 0) {
6294 ev_window_cmd_edit_find (NULL, window);
6295 } else if (g_ascii_strcasecmp (name, "Close") == 0) {
6296 ev_window_cmd_file_close_window (NULL, window);
6297 } else if (g_ascii_strcasecmp (name, "Print") == 0) {
6298 ev_window_cmd_file_print (NULL, window);
6300 g_warning ("Unimplemented named action: %s, please post a "
6301 "bug report in Evince bugzilla "
6302 "(http://bugzilla.gnome.org) with a testcase.",
6308 view_external_link_cb (EvWindow *window, EvLinkAction *action)
6310 switch (ev_link_action_get_action_type (action)) {
6311 case EV_LINK_ACTION_TYPE_GOTO_DEST: {
6314 dest = ev_link_action_get_dest (action);
6318 ev_window_open_copy_at_dest (window, dest);
6321 case EV_LINK_ACTION_TYPE_EXTERNAL_URI:
6322 launch_external_uri (window, action);
6324 case EV_LINK_ACTION_TYPE_LAUNCH:
6325 launch_action (window, action);
6327 case EV_LINK_ACTION_TYPE_GOTO_REMOTE:
6328 open_remote_link (window, action);
6330 case EV_LINK_ACTION_TYPE_NAMED:
6331 do_action_named (window, action);
6334 g_assert_not_reached ();
6339 ev_view_popup_cmd_open_link (GtkAction *action, EvWindow *window)
6341 ev_view_handle_link (EV_VIEW (window->priv->view), window->priv->link);
6345 ev_view_popup_cmd_open_link_new_window (GtkAction *action, EvWindow *window)
6347 EvLinkAction *ev_action = NULL;
6350 ev_action = ev_link_get_action (window->priv->link);
6354 dest = ev_link_action_get_dest (ev_action);
6358 ev_window_open_copy_at_dest (window, dest);
6362 ev_view_popup_cmd_copy_link_address (GtkAction *action, EvWindow *window)
6364 EvLinkAction *ev_action;
6366 ev_action = ev_link_get_action (window->priv->link);
6370 ev_view_copy_link_address (EV_VIEW (window->priv->view),
6375 create_file_from_uri_for_format (const gchar *uri,
6376 GdkPixbufFormat *format)
6380 gchar *uri_extension;
6383 extensions = gdk_pixbuf_format_get_extensions (format);
6384 for (i = 0; extensions[i]; i++) {
6385 if (g_str_has_suffix (uri, extensions[i])) {
6386 g_strfreev (extensions);
6387 return g_file_new_for_uri (uri);
6391 uri_extension = g_strconcat (uri, ".", extensions[0], NULL);
6392 target_file = g_file_new_for_uri (uri_extension);
6393 g_free (uri_extension);
6394 g_strfreev (extensions);
6400 image_save_dialog_response_cb (GtkWidget *fc,
6402 EvWindow *ev_window)
6406 GError *error = NULL;
6411 GdkPixbufFormat *format;
6412 GtkFileFilter *filter;
6414 if (response_id != GTK_RESPONSE_OK) {
6415 gtk_widget_destroy (fc);
6419 uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
6420 filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (fc));
6421 format = g_object_get_data (G_OBJECT (filter), "pixbuf-format");
6423 if (format == NULL) {
6424 format = get_gdk_pixbuf_format_by_extension (uri);
6427 if (format == NULL && g_strrstr (uri, ".") == NULL) {
6428 /* no extension found and no extension provided within uri */
6429 format = get_gdk_pixbuf_format_by_extension (".png");
6430 if (format == NULL) {
6431 /* no .png support, try .jpeg */
6432 format = get_gdk_pixbuf_format_by_extension (".jpeg");
6436 if (format == NULL) {
6437 ev_window_error_message (ev_window, NULL,
6439 _("Couldn't find appropriate format to save image"));
6441 gtk_widget_destroy (fc);
6446 target_file = create_file_from_uri_for_format (uri, format);
6449 is_native = g_file_is_native (target_file);
6451 filename = g_file_get_path (target_file);
6453 /* Create a temporary local file to save to */
6454 if (ev_mkstemp ("saveimage.XXXXXX", &filename, &error) == -1)
6458 ev_document_doc_mutex_lock ();
6459 pixbuf = ev_document_images_get_image (EV_DOCUMENT_IMAGES (ev_window->priv->document),
6460 ev_window->priv->image);
6461 ev_document_doc_mutex_unlock ();
6463 file_format = gdk_pixbuf_format_get_name (format);
6464 gdk_pixbuf_save (pixbuf, filename, file_format, &error, NULL);
6465 g_free (file_format);
6466 g_object_unref (pixbuf);
6470 ev_window_error_message (ev_window, error,
6471 "%s", _("The image could not be saved."));
6472 g_error_free (error);
6474 g_object_unref (target_file);
6475 gtk_widget_destroy (fc);
6483 source_file = g_file_new_for_path (filename);
6485 ev_window_save_remote (ev_window, EV_SAVE_IMAGE,
6486 source_file, target_file);
6487 g_object_unref (source_file);
6491 g_object_unref (target_file);
6492 gtk_widget_destroy (fc);
6496 ev_view_popup_cmd_save_image_as (GtkAction *action, EvWindow *window)
6500 if (!window->priv->image)
6503 fc = gtk_file_chooser_dialog_new (_("Save Image"),
6504 GTK_WINDOW (window),
6505 GTK_FILE_CHOOSER_ACTION_SAVE,
6507 GTK_RESPONSE_CANCEL,
6508 GTK_STOCK_SAVE, GTK_RESPONSE_OK,
6511 gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
6512 gtk_dialog_set_alternative_button_order (GTK_DIALOG (fc),
6514 GTK_RESPONSE_CANCEL,
6517 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (fc), FALSE);
6518 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
6520 file_chooser_dialog_add_writable_pixbuf_formats (GTK_FILE_CHOOSER (fc));
6522 g_signal_connect (fc, "response",
6523 G_CALLBACK (image_save_dialog_response_cb),
6526 gtk_widget_show (fc);
6530 ev_view_popup_cmd_copy_image (GtkAction *action, EvWindow *window)
6532 GtkClipboard *clipboard;
6535 if (!window->priv->image)
6538 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (window),
6539 GDK_SELECTION_CLIPBOARD);
6540 ev_document_doc_mutex_lock ();
6541 pixbuf = ev_document_images_get_image (EV_DOCUMENT_IMAGES (window->priv->document),
6542 window->priv->image);
6543 ev_document_doc_mutex_unlock ();
6545 gtk_clipboard_set_image (clipboard, pixbuf);
6546 g_object_unref (pixbuf);
6550 ev_view_popup_cmd_annot_properties (GtkAction *action,
6553 const gchar *author;
6556 gboolean popup_is_open;
6557 EvAnnotationPropertiesDialog *dialog;
6558 EvAnnotation *annot = window->priv->annot;
6559 EvAnnotationsSaveMask mask = EV_ANNOTATIONS_SAVE_NONE;
6564 dialog = EV_ANNOTATION_PROPERTIES_DIALOG (ev_annotation_properties_dialog_new_with_annotation (window->priv->annot));
6565 if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_APPLY) {
6566 gtk_widget_destroy (GTK_WIDGET (dialog));
6571 /* Set annotations changes */
6572 author = ev_annotation_properties_dialog_get_author (dialog);
6573 if (ev_annotation_markup_set_label (EV_ANNOTATION_MARKUP (annot), author))
6574 mask |= EV_ANNOTATIONS_SAVE_LABEL;
6576 ev_annotation_properties_dialog_get_color (dialog, &color);
6577 if (ev_annotation_set_color (annot, &color))
6578 mask |= EV_ANNOTATIONS_SAVE_COLOR;
6580 opacity = ev_annotation_properties_dialog_get_opacity (dialog);
6581 if (ev_annotation_markup_set_opacity (EV_ANNOTATION_MARKUP (annot), opacity))
6582 mask |= EV_ANNOTATIONS_SAVE_OPACITY;
6584 popup_is_open = ev_annotation_properties_dialog_get_popup_is_open (dialog);
6585 if (ev_annotation_markup_set_popup_is_open (EV_ANNOTATION_MARKUP (annot), popup_is_open))
6586 mask |= EV_ANNOTATIONS_SAVE_POPUP_IS_OPEN;
6588 if (EV_IS_ANNOTATION_TEXT (annot)) {
6589 EvAnnotationTextIcon icon;
6591 icon = ev_annotation_properties_dialog_get_text_icon (dialog);
6592 if (ev_annotation_text_set_icon (EV_ANNOTATION_TEXT (annot), icon))
6593 mask |= EV_ANNOTATIONS_SAVE_TEXT_ICON;
6596 if (mask != EV_ANNOTATIONS_SAVE_NONE) {
6597 ev_document_doc_mutex_lock ();
6598 ev_document_annotations_save_annotation (EV_DOCUMENT_ANNOTATIONS (window->priv->document),
6599 window->priv->annot,
6601 ev_document_doc_mutex_unlock ();
6603 /* FIXME: update annot region only */
6604 ev_view_reload (EV_VIEW (window->priv->view));
6607 gtk_widget_destroy (GTK_WIDGET (dialog));
6611 ev_attachment_popup_cmd_open_attachment (GtkAction *action, EvWindow *window)
6616 if (!window->priv->attach_list)
6619 screen = gtk_window_get_screen (GTK_WINDOW (window));
6621 for (l = window->priv->attach_list; l && l->data; l = g_list_next (l)) {
6622 EvAttachment *attachment;
6623 GError *error = NULL;
6625 attachment = (EvAttachment *) l->data;
6627 ev_attachment_open (attachment, screen, gtk_get_current_event_time (), &error);
6630 ev_window_error_message (window, error,
6631 "%s", _("Unable to open attachment"));
6632 g_error_free (error);
6638 attachment_save_dialog_response_cb (GtkWidget *fc,
6640 EvWindow *ev_window)
6645 GtkFileChooserAction fc_action;
6649 if (response_id != GTK_RESPONSE_OK) {
6650 gtk_widget_destroy (fc);
6654 uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
6655 target_file = g_file_new_for_uri (uri);
6656 g_object_get (G_OBJECT (fc), "action", &fc_action, NULL);
6657 is_dir = (fc_action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
6658 is_native = g_file_is_native (target_file);
6660 for (l = ev_window->priv->attach_list; l && l->data; l = g_list_next (l)) {
6661 EvAttachment *attachment;
6662 GFile *save_to = NULL;
6663 GError *error = NULL;
6665 attachment = (EvAttachment *) l->data;
6669 save_to = g_file_get_child (target_file,
6670 /* FIXMEchpe: file name encoding! */
6671 ev_attachment_get_name (attachment));
6673 save_to = g_object_ref (target_file);
6676 save_to = ev_mkstemp_file ("saveattachment.XXXXXX", &error);
6680 ev_attachment_save (attachment, save_to, &error);
6683 ev_window_error_message (ev_window, error,
6684 "%s", _("The attachment could not be saved."));
6685 g_error_free (error);
6686 g_object_unref (save_to);
6695 dest_file = g_file_get_child (target_file,
6696 ev_attachment_get_name (attachment));
6698 dest_file = g_object_ref (target_file);
6701 ev_window_save_remote (ev_window, EV_SAVE_ATTACHMENT,
6702 save_to, dest_file);
6704 g_object_unref (dest_file);
6707 g_object_unref (save_to);
6711 g_object_unref (target_file);
6713 gtk_widget_destroy (fc);
6717 ev_attachment_popup_cmd_save_attachment_as (GtkAction *action, EvWindow *window)
6720 EvAttachment *attachment = NULL;
6722 if (!window->priv->attach_list)
6725 if (g_list_length (window->priv->attach_list) == 1)
6726 attachment = (EvAttachment *) window->priv->attach_list->data;
6728 fc = gtk_file_chooser_dialog_new (
6729 _("Save Attachment"),
6730 GTK_WINDOW (window),
6731 attachment ? GTK_FILE_CHOOSER_ACTION_SAVE : GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
6733 GTK_RESPONSE_CANCEL,
6734 GTK_STOCK_SAVE, GTK_RESPONSE_OK,
6737 gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
6738 gtk_dialog_set_alternative_button_order (GTK_DIALOG (fc),
6740 GTK_RESPONSE_CANCEL,
6743 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
6744 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (fc), FALSE);
6747 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc),
6748 ev_attachment_get_name (attachment));
6750 g_signal_connect (fc, "response",
6751 G_CALLBACK (attachment_save_dialog_response_cb),
6754 gtk_widget_show (fc);
6758 ev_window_media_player_key_pressed (EvWindow *window,
6762 if (!gtk_window_is_active (GTK_WINDOW (window)))
6765 /* Note how Previous/Next only go to the
6766 * next/previous page despite their icon telling you
6767 * they should go to the beginning/end.
6769 * There's very few keyboards with FFW/RWD though,
6770 * so we stick the most useful keybinding on the most
6773 if (strcmp (key, "Play") == 0) {
6774 ev_window_run_presentation (window);
6775 } else if (strcmp (key, "Previous") == 0) {
6776 if (EV_WINDOW_IS_PRESENTATION (window))
6777 ev_view_presentation_previous_page (EV_VIEW_PRESENTATION (window->priv->presentation_view));
6779 ev_window_cmd_go_previous_page (NULL, window);
6780 } else if (strcmp (key, "Next") == 0) {
6781 if (EV_WINDOW_IS_PRESENTATION (window))
6782 ev_view_presentation_next_page (EV_VIEW_PRESENTATION (window->priv->presentation_view));
6784 ev_window_cmd_go_next_page (NULL, window);
6785 } else if (strcmp (key, "FastForward") == 0) {
6786 ev_window_cmd_go_last_page (NULL, window);
6787 } else if (strcmp (key, "Rewind") == 0) {
6788 ev_window_cmd_go_first_page (NULL, window);
6792 static EggToolbarsModel *
6793 get_toolbars_model (void)
6795 EggToolbarsModel *toolbars_model;
6796 gchar *toolbars_file;
6797 gchar *toolbars_path;
6800 toolbars_model = egg_toolbars_model_new ();
6802 toolbars_file = g_build_filename (ev_application_get_dot_dir (EV_APP, FALSE),
6803 "evince_toolbar.xml", NULL);
6804 toolbars_path = g_build_filename (ev_application_get_data_dir (EV_APP),
6805 "evince-toolbar.xml", NULL);
6806 egg_toolbars_model_load_names (toolbars_model, toolbars_path);
6808 if (!egg_toolbars_model_load_toolbars (toolbars_model, toolbars_file)) {
6809 egg_toolbars_model_load_toolbars (toolbars_model, toolbars_path);
6810 goto skip_conversion;
6813 /* Open item doesn't exist anymore,
6814 * convert it to OpenRecent for compatibility
6816 for (i = 0; i < egg_toolbars_model_n_items (toolbars_model, 0); i++) {
6819 item = egg_toolbars_model_item_nth (toolbars_model, 0, i);
6820 if (g_ascii_strcasecmp (item, "FileOpen") == 0) {
6821 egg_toolbars_model_remove_item (toolbars_model, 0, i);
6822 egg_toolbars_model_add_item (toolbars_model, 0, i,
6824 egg_toolbars_model_save_toolbars (toolbars_model, toolbars_file, "1.0");
6830 g_free (toolbars_file);
6831 g_free (toolbars_path);
6833 egg_toolbars_model_set_flags (toolbars_model, 0, EGG_TB_MODEL_NOT_REMOVABLE);
6835 return toolbars_model;
6840 ev_window_sync_source (EvWindow *window,
6843 GDBusConnection *connection;
6844 GError *error = NULL;
6849 if (window->priv->dbus_object_id <= 0)
6852 connection = ev_application_get_dbus_connection (EV_APP);
6856 timestamp = gtk_get_current_event_time ();
6857 if (g_path_is_absolute (link->filename)) {
6858 input_gfile = g_file_new_for_path (link->filename);
6860 GFile *gfile, *parent_gfile;
6862 gfile = g_file_new_for_uri (window->priv->uri);
6863 parent_gfile = g_file_get_parent (gfile);
6865 /* parent_gfile should never be NULL */
6866 if (parent_gfile == NULL) {
6867 g_printerr ("Document URI is '/'\n");
6871 input_gfile = g_file_get_child (parent_gfile, link->filename);
6872 g_object_unref (parent_gfile);
6873 g_object_unref (gfile);
6876 uri_input = g_file_get_uri (input_gfile);
6877 g_object_unref (input_gfile);
6879 g_dbus_connection_emit_signal (connection,
6881 window->priv->dbus_object_path,
6882 EV_WINDOW_DBUS_INTERFACE,
6884 g_variant_new ("(s(ii)u)",
6892 g_printerr ("Failed to emit DBus signal SyncSource: %s\n",
6894 g_error_free (error);
6899 ev_window_emit_closed (EvWindow *window)
6901 GDBusConnection *connection;
6902 GError *error = NULL;
6904 if (window->priv->dbus_object_id <= 0)
6907 connection = ev_application_get_dbus_connection (EV_APP);
6911 g_dbus_connection_emit_signal (connection,
6913 window->priv->dbus_object_path,
6914 EV_WINDOW_DBUS_INTERFACE,
6919 g_printerr ("Failed to emit DBus signal Closed: %s\n",
6921 g_error_free (error);
6926 /* If this is the last window call g_dbus_connection_flush_sync()
6927 * to make sure the signal is emitted.
6929 if (ev_application_get_n_windows (EV_APP) == 1)
6930 g_dbus_connection_flush_sync (connection, NULL, NULL);
6934 ev_window_emit_doc_loaded (EvWindow *window)
6936 GDBusConnection *connection;
6937 GError *error = NULL;
6939 if (window->priv->dbus_object_id <= 0)
6942 connection = ev_application_get_dbus_connection (EV_APP);
6946 g_dbus_connection_emit_signal (connection,
6948 window->priv->dbus_object_path,
6949 EV_WINDOW_DBUS_INTERFACE,
6951 g_variant_new("(s)", window->priv->uri),
6954 g_printerr ("Failed to emit DBus signal DocumentLoaded: %s\n",
6956 g_error_free (error);
6963 method_call_cb (GDBusConnection *connection,
6964 const gchar *sender,
6965 const gchar *object_path,
6966 const gchar *interface_name,
6967 const gchar *method_name,
6968 GVariant *parameters,
6969 GDBusMethodInvocation *invocation,
6972 EvWindow *window = EV_WINDOW (user_data);
6974 if (g_strcmp0 (method_name, "SyncView") != 0)
6977 if (window->priv->document && ev_document_has_synctex (window->priv->document)) {
6981 g_variant_get (parameters, "(&s(ii)u)", &link.filename, &link.line, &link.col, ×tamp);
6982 ev_view_highlight_forward_search (EV_VIEW (window->priv->view), &link);
6983 gtk_window_present_with_time (GTK_WINDOW (window), timestamp);
6986 g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
6989 static const char introspection_xml[] =
6991 "<interface name='org.gnome.evince.Window'>"
6992 "<method name='SyncView'>"
6993 "<arg type='s' name='source_file' direction='in'/>"
6994 "<arg type='(ii)' name='source_point' direction='in'/>"
6995 "<arg type='u' name='timestamp' direction='in'/>"
6997 "<signal name='SyncSource'>"
6998 "<arg type='s' name='source_file' direction='out'/>"
6999 "<arg type='(ii)' name='source_point' direction='out'/>"
7000 "<arg type='u' name='timestamp' direction='out'/>"
7002 "<signal name='Closed'/>"
7003 "<signal name='DocumentLoaded'>"
7004 "<arg type='s' name='uri' direction='out'/>"
7009 static const GDBusInterfaceVTable interface_vtable = {
7015 static GDBusNodeInfo *introspection_data;
7016 #endif /* ENABLE_DBUS */
7019 ev_window_init (EvWindow *ev_window)
7021 GtkActionGroup *action_group;
7022 GtkAccelGroup *accel_group;
7023 GError *error = NULL;
7024 GtkWidget *sidebar_widget;
7025 GtkWidget *menuitem;
7026 EggToolbarsModel *toolbars_model;
7030 GDBusConnection *connection;
7031 static gint window_id = 0;
7034 g_signal_connect (ev_window, "configure_event",
7035 G_CALLBACK (window_configure_event_cb), NULL);
7036 g_signal_connect (ev_window, "window_state_event",
7037 G_CALLBACK (window_state_event_cb), NULL);
7039 ev_window->priv = EV_WINDOW_GET_PRIVATE (ev_window);
7042 connection = ev_application_get_dbus_connection (EV_APP);
7044 if (!introspection_data) {
7045 introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, &error);
7046 if (error) g_warning ("%s\n", error->message);
7048 g_assert (introspection_data != NULL);
7050 ev_window->priv->dbus_object_path = g_strdup_printf (EV_WINDOW_DBUS_OBJECT_PATH, window_id++);
7051 ev_window->priv->dbus_object_id =
7052 g_dbus_connection_register_object (connection,
7053 ev_window->priv->dbus_object_path,
7054 introspection_data->interfaces[0],
7058 if (ev_window->priv->dbus_object_id == 0) {
7059 g_printerr ("Failed to register bus object %s: %s\n",
7060 ev_window->priv->dbus_object_path, error->message);
7061 g_error_free (error);
7062 g_free (ev_window->priv->dbus_object_path);
7063 ev_window->priv->dbus_object_path = NULL;
7068 #endif /* ENABLE_DBUS */
7070 ev_window->priv->model = ev_document_model_new ();
7072 ev_window->priv->page_mode = PAGE_MODE_DOCUMENT;
7073 ev_window->priv->title = ev_window_title_new (ev_window);
7075 ev_window->priv->main_box = gtk_vbox_new (FALSE, 0);
7076 gtk_container_add (GTK_CONTAINER (ev_window), ev_window->priv->main_box);
7077 gtk_widget_show (ev_window->priv->main_box);
7079 action_group = gtk_action_group_new ("MenuActions");
7080 ev_window->priv->action_group = action_group;
7081 gtk_action_group_set_translation_domain (action_group, NULL);
7082 gtk_action_group_add_actions (action_group, entries,
7083 G_N_ELEMENTS (entries), ev_window);
7084 gtk_action_group_add_toggle_actions (action_group, toggle_entries,
7085 G_N_ELEMENTS (toggle_entries),
7087 set_action_properties (action_group);
7088 register_custom_actions (ev_window, action_group);
7090 ev_window->priv->ui_manager = gtk_ui_manager_new ();
7091 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
7095 gtk_ui_manager_get_accel_group (ev_window->priv->ui_manager);
7096 gtk_window_add_accel_group (GTK_WINDOW (ev_window), accel_group);
7098 ev_window_set_view_accels_sensitivity (ev_window, FALSE);
7100 action_group = gtk_action_group_new ("ViewPopupActions");
7101 ev_window->priv->view_popup_action_group = action_group;
7102 gtk_action_group_set_translation_domain (action_group, NULL);
7103 gtk_action_group_add_actions (action_group, view_popup_entries,
7104 G_N_ELEMENTS (view_popup_entries),
7106 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
7109 action_group = gtk_action_group_new ("AttachmentPopupActions");
7110 ev_window->priv->attachment_popup_action_group = action_group;
7111 gtk_action_group_set_translation_domain (action_group, NULL);
7112 gtk_action_group_add_actions (action_group, attachment_popup_entries,
7113 G_N_ELEMENTS (attachment_popup_entries),
7115 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
7118 ui_path = g_build_filename (ev_application_get_data_dir (EV_APP),
7119 "evince-ui.xml", NULL);
7120 if (!gtk_ui_manager_add_ui_from_file (
7121 ev_window->priv->ui_manager, ui_path, &error))
7123 g_warning ("building menus failed: %s", error->message);
7124 g_error_free (error);
7128 ev_window->priv->recent_manager = gtk_recent_manager_get_default ();
7129 ev_window->priv->recent_action_group = NULL;
7130 ev_window->priv->recent_ui_id = 0;
7131 g_signal_connect_swapped (ev_window->priv->recent_manager,
7133 G_CALLBACK (ev_window_setup_recent),
7136 ev_window->priv->menubar =
7137 gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
7139 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box),
7140 ev_window->priv->menubar,
7142 menuitem = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
7143 "/MainMenu/EditMenu/EditRotateLeftMenu");
7144 gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menuitem), TRUE);
7145 menuitem = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
7146 "/MainMenu/EditMenu/EditRotateRightMenu");
7147 gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menuitem), TRUE);
7149 toolbars_model = get_toolbars_model ();
7150 ev_window->priv->toolbar = GTK_WIDGET
7151 (g_object_new (EGG_TYPE_EDITABLE_TOOLBAR,
7152 "ui-manager", ev_window->priv->ui_manager,
7153 "popup-path", "/ToolbarPopup",
7154 "model", toolbars_model,
7156 g_object_unref (toolbars_model);
7158 gtk_style_context_add_class
7159 (gtk_widget_get_style_context (GTK_WIDGET (ev_window->priv->toolbar)),
7160 GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
7162 egg_editable_toolbar_show (EGG_EDITABLE_TOOLBAR (ev_window->priv->toolbar),
7164 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box),
7165 ev_window->priv->toolbar,
7167 gtk_widget_show (ev_window->priv->toolbar);
7169 /* Add the main area */
7170 ev_window->priv->hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
7171 g_signal_connect (ev_window->priv->hpaned,
7173 G_CALLBACK (ev_window_sidebar_position_change_cb),
7176 gtk_paned_set_position (GTK_PANED (ev_window->priv->hpaned), SIDEBAR_DEFAULT_SIZE);
7177 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), ev_window->priv->hpaned,
7179 gtk_widget_show (ev_window->priv->hpaned);
7181 ev_window->priv->sidebar = ev_sidebar_new ();
7182 ev_sidebar_set_model (EV_SIDEBAR (ev_window->priv->sidebar),
7183 ev_window->priv->model);
7184 gtk_paned_pack1 (GTK_PANED (ev_window->priv->hpaned),
7185 ev_window->priv->sidebar, FALSE, FALSE);
7186 gtk_widget_show (ev_window->priv->sidebar);
7188 /* Stub sidebar, for now */
7190 sidebar_widget = ev_sidebar_thumbnails_new ();
7191 ev_window->priv->sidebar_thumbs = sidebar_widget;
7192 g_signal_connect (sidebar_widget,
7193 "notify::main-widget",
7194 G_CALLBACK (sidebar_page_main_widget_update_cb),
7196 sidebar_page_main_widget_update_cb (G_OBJECT (sidebar_widget), NULL, ev_window);
7197 gtk_widget_show (sidebar_widget);
7198 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7201 sidebar_widget = ev_sidebar_links_new ();
7202 ev_window->priv->sidebar_links = sidebar_widget;
7203 g_signal_connect (sidebar_widget,
7205 G_CALLBACK (sidebar_widget_model_set),
7207 g_signal_connect (sidebar_widget,
7209 G_CALLBACK (sidebar_links_link_activated_cb),
7211 sidebar_page_main_widget_update_cb (G_OBJECT (sidebar_widget), NULL, ev_window);
7212 gtk_widget_show (sidebar_widget);
7213 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7216 sidebar_widget = ev_sidebar_attachments_new ();
7217 ev_window->priv->sidebar_attachments = sidebar_widget;
7218 g_signal_connect_object (sidebar_widget,
7220 G_CALLBACK (attachment_bar_menu_popup_cb),
7222 gtk_widget_show (sidebar_widget);
7223 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7226 sidebar_widget = ev_sidebar_layers_new ();
7227 ev_window->priv->sidebar_layers = sidebar_widget;
7228 g_signal_connect (sidebar_widget,
7229 "layers_visibility_changed",
7230 G_CALLBACK (sidebar_layers_visibility_changed),
7232 gtk_widget_show (sidebar_widget);
7233 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7236 sidebar_widget = ev_sidebar_annotations_new ();
7237 ev_window->priv->sidebar_annots = sidebar_widget;
7238 g_signal_connect (sidebar_widget,
7240 G_CALLBACK (sidebar_annots_annot_activated_cb),
7242 g_signal_connect (sidebar_widget,
7244 G_CALLBACK (sidebar_annots_begin_annot_add),
7246 g_signal_connect (sidebar_widget,
7247 "annot_add_cancelled",
7248 G_CALLBACK (sidebar_annots_annot_add_cancelled),
7250 gtk_widget_show (sidebar_widget);
7251 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7254 sidebar_widget = ev_sidebar_bookmarks_new ();
7255 ev_window->priv->sidebar_bookmarks = sidebar_widget;
7256 g_signal_connect (sidebar_widget,
7258 G_CALLBACK (sidebar_bookmarks_add_bookmark),
7260 gtk_widget_show (sidebar_widget);
7261 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7264 ev_window->priv->view_box = gtk_vbox_new (FALSE, 0);
7265 ev_window->priv->scrolled_window =
7266 GTK_WIDGET (g_object_new (GTK_TYPE_SCROLLED_WINDOW,
7267 "shadow-type", GTK_SHADOW_IN,
7269 gtk_box_pack_start (GTK_BOX (ev_window->priv->view_box),
7270 ev_window->priv->scrolled_window,
7272 gtk_widget_show (ev_window->priv->scrolled_window);
7274 gtk_paned_add2 (GTK_PANED (ev_window->priv->hpaned),
7275 ev_window->priv->view_box);
7276 gtk_widget_show (ev_window->priv->view_box);
7278 ev_window->priv->view = ev_view_new ();
7279 ev_view_set_page_cache_size (EV_VIEW (ev_window->priv->view), PAGE_CACHE_SIZE);
7280 ev_view_set_model (EV_VIEW (ev_window->priv->view), ev_window->priv->model);
7282 ev_window->priv->password_view = ev_password_view_new (GTK_WINDOW (ev_window));
7283 g_signal_connect_swapped (ev_window->priv->password_view,
7285 G_CALLBACK (ev_window_password_view_unlock),
7287 g_signal_connect_object (ev_window->priv->view, "focus_in_event",
7288 G_CALLBACK (view_actions_focus_in_cb),
7290 g_signal_connect_object (ev_window->priv->view, "focus_out_event",
7291 G_CALLBACK (view_actions_focus_out_cb),
7293 g_signal_connect_swapped (ev_window->priv->view, "external-link",
7294 G_CALLBACK (view_external_link_cb),
7296 g_signal_connect_object (ev_window->priv->view, "handle-link",
7297 G_CALLBACK (view_handle_link_cb),
7299 g_signal_connect_object (ev_window->priv->view, "popup",
7300 G_CALLBACK (view_menu_popup_cb),
7302 g_signal_connect_object (ev_window->priv->view, "selection-changed",
7303 G_CALLBACK (view_selection_changed_cb),
7305 g_signal_connect_object (ev_window->priv->view, "annot-added",
7306 G_CALLBACK (view_annot_added),
7308 g_signal_connect_object (ev_window->priv->view, "layers-changed",
7309 G_CALLBACK (view_layers_changed_cb),
7312 g_signal_connect_swapped (ev_window->priv->view, "sync-source",
7313 G_CALLBACK (ev_window_sync_source),
7316 gtk_widget_show (ev_window->priv->view);
7317 gtk_widget_show (ev_window->priv->password_view);
7320 ev_window->priv->find_bar = egg_find_bar_new ();
7321 gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
7322 ev_window->priv->find_bar,
7325 /* We own a ref on these widgets, as we can swap them in and out */
7326 g_object_ref (ev_window->priv->view);
7327 g_object_ref (ev_window->priv->password_view);
7329 gtk_container_add (GTK_CONTAINER (ev_window->priv->scrolled_window),
7330 ev_window->priv->view);
7332 /* Connect to model signals */
7333 g_signal_connect_swapped (ev_window->priv->model,
7335 G_CALLBACK (ev_window_page_changed_cb),
7337 g_signal_connect (ev_window->priv->model,
7339 G_CALLBACK (ev_window_document_changed_cb),
7341 g_signal_connect (ev_window->priv->model,
7343 G_CALLBACK (ev_window_zoom_changed_cb),
7345 g_signal_connect (ev_window->priv->model,
7346 "notify::sizing-mode",
7347 G_CALLBACK (ev_window_sizing_mode_changed_cb),
7349 g_signal_connect (ev_window->priv->model,
7351 G_CALLBACK (ev_window_rotation_changed_cb),
7353 g_signal_connect (ev_window->priv->model,
7354 "notify::continuous",
7355 G_CALLBACK (ev_window_continuous_changed_cb),
7357 g_signal_connect (ev_window->priv->model,
7358 "notify::dual-page",
7359 G_CALLBACK (ev_window_dual_mode_changed_cb),
7361 g_signal_connect (ev_window->priv->model,
7362 "notify::inverted-colors",
7363 G_CALLBACK (ev_window_inverted_colors_changed_cb),
7366 /* Connect sidebar signals */
7367 g_signal_connect (ev_window->priv->sidebar,
7369 G_CALLBACK (ev_window_sidebar_visibility_changed_cb),
7371 g_signal_connect (ev_window->priv->sidebar,
7372 "notify::current-page",
7373 G_CALLBACK (ev_window_sidebar_current_page_changed_cb),
7376 /* Connect to find bar signals */
7377 g_signal_connect (ev_window->priv->find_bar,
7379 G_CALLBACK (find_bar_previous_cb),
7381 g_signal_connect (ev_window->priv->find_bar,
7383 G_CALLBACK (find_bar_next_cb),
7385 g_signal_connect (ev_window->priv->find_bar,
7387 G_CALLBACK (find_bar_close_cb),
7389 g_signal_connect (ev_window->priv->find_bar,
7390 "notify::search-string",
7391 G_CALLBACK (find_bar_search_changed_cb),
7393 g_signal_connect (ev_window->priv->find_bar,
7394 "notify::case-sensitive",
7395 G_CALLBACK (find_bar_search_changed_cb),
7397 g_signal_connect (ev_window->priv->find_bar,
7399 G_CALLBACK (find_bar_visibility_changed_cb),
7401 g_signal_connect (ev_window->priv->find_bar,
7403 G_CALLBACK (find_bar_scroll),
7407 ev_window->priv->view_popup = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
7409 ev_window->priv->link = NULL;
7411 ev_window->priv->attachment_popup = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
7412 "/AttachmentPopup");
7413 ev_window->priv->attach_list = NULL;
7415 /* Media player keys */
7416 mpkeys = ev_application_get_media_keys (EV_APP);
7418 g_signal_connect_swapped (mpkeys, "key_pressed",
7419 G_CALLBACK (ev_window_media_player_key_pressed),
7423 /* Give focus to the document view */
7424 gtk_widget_grab_focus (ev_window->priv->view);
7426 ev_window->priv->default_settings = g_settings_new (GS_SCHEMA_NAME".Default");
7427 g_settings_delay (ev_window->priv->default_settings);
7429 /* Set it user interface params */
7430 ev_window_setup_recent (ev_window);
7432 ev_window_setup_gtk_settings (ev_window);
7434 setup_chrome_from_metadata (ev_window);
7435 update_chrome_actions (ev_window);
7436 update_chrome_visibility (ev_window);
7438 gtk_window_set_default_size (GTK_WINDOW (ev_window), 600, 600);
7440 setup_view_from_metadata (ev_window);
7441 setup_sidebar_from_metadata (ev_window);
7443 ev_window_sizing_mode_changed_cb (ev_window->priv->model, NULL, ev_window);
7444 ev_window_setup_action_sensitivity (ev_window);
7447 gtk_drag_dest_set (GTK_WIDGET (ev_window),
7448 GTK_DEST_DEFAULT_ALL,
7451 gtk_drag_dest_add_uri_targets (GTK_WIDGET (ev_window));
7457 * Creates a #GtkWidget that represents the window.
7459 * Returns: the #GtkWidget that represents the window.
7462 ev_window_new (void)
7464 GtkWidget *ev_window;
7466 ev_window = GTK_WIDGET (g_object_new (EV_TYPE_WINDOW,
7467 "type", GTK_WINDOW_TOPLEVEL,
7474 ev_window_get_dbus_object_path (EvWindow *ev_window)
7477 return ev_window->priv->dbus_object_path;