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-document-factory.h"
55 #include "ev-document-find.h"
56 #include "ev-document-fonts.h"
57 #include "ev-document-images.h"
58 #include "ev-document-links.h"
59 #include "ev-document-annotations.h"
60 #include "ev-document-type-builtins.h"
61 #include "ev-document-misc.h"
62 #include "ev-file-exporter.h"
63 #include "ev-file-helpers.h"
64 #include "ev-file-monitor.h"
65 #include "ev-history.h"
67 #include "ev-job-scheduler.h"
69 #include "ev-message-area.h"
70 #include "ev-metadata.h"
71 #include "ev-navigation-action.h"
72 #include "ev-open-recent-action.h"
73 #include "ev-page-action.h"
74 #include "ev-password-view.h"
75 #include "ev-properties-dialog.h"
76 #include "ev-sidebar-annotations.h"
77 #include "ev-sidebar-attachments.h"
78 #include "ev-sidebar-bookmarks.h"
79 #include "ev-sidebar.h"
80 #include "ev-sidebar-links.h"
81 #include "ev-sidebar-page.h"
82 #include "ev-sidebar-thumbnails.h"
83 #include "ev-sidebar-layers.h"
84 #include "ev-stock-icons.h"
86 #include "ev-keyring.h"
88 #include "ev-view-presentation.h"
89 #include "ev-view-type-builtins.h"
90 #include "ev-window.h"
91 #include "ev-window-title.h"
92 #include "ev-print-operation.h"
93 #include "ev-progress-message-area.h"
94 #include "ev-annotation-properties-dialog.h"
95 #include "ev-bookmarks.h"
96 #include "ev-bookmark-action.h"
99 #include "ev-media-player-keys.h"
100 #endif /* ENABLE_DBUS */
108 EV_CHROME_MENUBAR = 1 << 0,
109 EV_CHROME_TOOLBAR = 1 << 1,
110 EV_CHROME_FINDBAR = 1 << 2,
111 EV_CHROME_RAISE_TOOLBAR = 1 << 3,
112 EV_CHROME_FULLSCREEN_TOOLBAR = 1 << 4,
113 EV_CHROME_SIDEBAR = 1 << 5,
114 EV_CHROME_NORMAL = EV_CHROME_MENUBAR | EV_CHROME_TOOLBAR | EV_CHROME_SIDEBAR
123 struct _EvWindowPrivate {
134 GtkWidget *scrolled_window;
136 GtkWidget *presentation_view;
137 GtkWidget *message_area;
138 GtkWidget *password_view;
139 GtkWidget *sidebar_thumbs;
140 GtkWidget *sidebar_links;
141 GtkWidget *sidebar_attachments;
142 GtkWidget *sidebar_layers;
143 GtkWidget *sidebar_annots;
144 GtkWidget *sidebar_bookmarks;
148 GSettings *default_settings;
149 GSettings *lockdown_settings;
152 guint menubar_accel_keyval;
153 GdkModifierType menubar_accel_modifier;
155 /* Progress Messages */
157 GCancellable *progress_cancellable;
160 GtkWidget *properties;
161 GtkWidget *print_dialog;
164 GtkActionGroup *action_group;
165 GtkActionGroup *view_popup_action_group;
166 GtkActionGroup *attachment_popup_action_group;
167 GtkRecentManager *recent_manager;
168 GtkActionGroup *recent_action_group;
170 GtkActionGroup *bookmarks_action_group;
171 guint bookmarks_ui_id;
172 GtkUIManager *ui_manager;
174 /* Fullscreen mode */
175 GtkWidget *fullscreen_toolbar;
178 GtkWidget *view_popup;
183 /* Popup attachment */
184 GtkWidget *attachment_popup;
188 EvDocumentModel *model;
193 EvFileMonitor *monitor;
194 guint setup_document_idle;
196 EvDocument *document;
198 EvWindowPageMode page_mode;
199 EvWindowTitle *title;
200 EvMetadata *metadata;
201 EvBookmarks *bookmarks;
206 gchar *search_string;
207 EvWindowRunMode window_mode;
211 EvJob *thumbnail_job;
217 GtkPrintSettings *print_settings;
218 GtkPageSetup *print_page_setup;
219 gboolean close_after_print;
223 guint dbus_object_id;
224 gchar *dbus_object_path;
228 #define EV_WINDOW_GET_PRIVATE(object) \
229 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_WINDOW, EvWindowPrivate))
231 #define EV_WINDOW_IS_PRESENTATION(w) (w->priv->presentation_view != NULL)
233 #define PAGE_SELECTOR_ACTION "PageSelector"
234 #define ZOOM_CONTROL_ACTION "ViewZoom"
235 #define NAVIGATION_ACTION "Navigation"
237 #define GS_LOCKDOWN_SCHEMA_NAME "org.gnome.desktop.lockdown"
238 #define GS_LOCKDOWN_SAVE "disable-save-to-disk"
239 #define GS_LOCKDOWN_PRINT "disable-printing"
240 #define GS_LOCKDOWN_PRINT_SETUP "disable-print-setup"
243 #define EV_WINDOW_DBUS_OBJECT_PATH "/org/gnome/evince/Window/%d"
244 #define EV_WINDOW_DBUS_INTERFACE "org.gnome.evince.Window"
247 #define GS_SCHEMA_NAME "org.gnome.Evince"
248 #define GS_OVERRIDE_RESTRICTIONS "override-restrictions"
250 #define SIDEBAR_DEFAULT_SIZE 132
251 #define LINKS_SIDEBAR_ID "links"
252 #define THUMBNAILS_SIDEBAR_ID "thumbnails"
253 #define ATTACHMENTS_SIDEBAR_ID "attachments"
254 #define LAYERS_SIDEBAR_ID "layers"
255 #define ANNOTS_SIDEBAR_ID "annotations"
256 #define BOOKMARKS_SIDEBAR_ID "bookmarks"
258 #define EV_PRINT_SETTINGS_FILE "print-settings"
259 #define EV_PRINT_SETTINGS_GROUP "Print Settings"
260 #define EV_PAGE_SETUP_GROUP "Page Setup"
262 #define EV_TOOLBARS_FILENAME "evince-toolbar.xml"
264 #define MIN_SCALE 0.05409
265 #define PAGE_CACHE_SIZE 52428800 /* 50MB */
267 #define MAX_RECENT_ITEM_LEN (40)
269 static const gchar *document_print_settings[] = {
270 GTK_PRINT_SETTINGS_N_COPIES,
271 GTK_PRINT_SETTINGS_COLLATE,
272 GTK_PRINT_SETTINGS_REVERSE,
273 GTK_PRINT_SETTINGS_NUMBER_UP,
274 GTK_PRINT_SETTINGS_SCALE,
275 GTK_PRINT_SETTINGS_PRINT_PAGES,
276 GTK_PRINT_SETTINGS_PAGE_RANGES,
277 GTK_PRINT_SETTINGS_PAGE_SET,
278 GTK_PRINT_SETTINGS_OUTPUT_URI
281 static void ev_window_update_actions (EvWindow *ev_window);
282 static void ev_window_sidebar_visibility_changed_cb (EvSidebar *ev_sidebar,
284 EvWindow *ev_window);
285 static void ev_window_view_toolbar_cb (GtkAction *action,
286 EvWindow *ev_window);
287 static void ev_window_set_page_mode (EvWindow *window,
288 EvWindowPageMode page_mode);
289 static void ev_window_load_job_cb (EvJob *job,
291 static void ev_window_reload_document (EvWindow *window,
293 static void ev_window_reload_job_cb (EvJob *job,
295 static void ev_window_set_icon_from_thumbnail (EvJobThumbnail *job,
296 EvWindow *ev_window);
297 static void ev_window_save_job_cb (EvJob *save,
299 static void ev_window_sizing_mode_changed_cb (EvDocumentModel *model,
301 EvWindow *ev_window);
302 static void ev_window_zoom_changed_cb (EvDocumentModel *model,
304 EvWindow *ev_window);
305 static void ev_window_add_recent (EvWindow *window,
306 const char *filename);
307 static void ev_window_run_fullscreen (EvWindow *window);
308 static void ev_window_stop_fullscreen (EvWindow *window,
309 gboolean unfullscreen_window);
310 static void ev_window_cmd_view_fullscreen (GtkAction *action,
312 static void ev_window_run_presentation (EvWindow *window);
313 static void ev_window_stop_presentation (EvWindow *window,
314 gboolean unfullscreen_window);
315 static void ev_window_cmd_view_presentation (GtkAction *action,
317 static void ev_view_popup_cmd_open_link (GtkAction *action,
319 static void ev_view_popup_cmd_open_link_new_window (GtkAction *action,
321 static void ev_view_popup_cmd_copy_link_address (GtkAction *action,
323 static void ev_view_popup_cmd_save_image_as (GtkAction *action,
325 static void ev_view_popup_cmd_copy_image (GtkAction *action,
327 static void ev_view_popup_cmd_annot_properties (GtkAction *action,
329 static void ev_attachment_popup_cmd_open_attachment (GtkAction *action,
331 static void ev_attachment_popup_cmd_save_attachment_as (GtkAction *action,
333 static void ev_window_cmd_view_best_fit (GtkAction *action,
334 EvWindow *ev_window);
335 static void ev_window_cmd_view_page_width (GtkAction *action,
336 EvWindow *ev_window);
337 static void view_handle_link_cb (EvView *view,
340 static void ev_window_update_find_status_message (EvWindow *ev_window);
341 static void ev_window_cmd_edit_find (GtkAction *action,
342 EvWindow *ev_window);
343 static void find_bar_search_changed_cb (EggFindBar *find_bar,
345 EvWindow *ev_window);
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_set_action_sensitive (EvWindow *ev_window,
376 GtkAction *action = gtk_action_group_get_action (ev_window->priv->action_group,
378 gtk_action_set_sensitive (action, sensitive);
383 ev_window_setup_action_sensitivity (EvWindow *ev_window)
385 EvDocument *document = ev_window->priv->document;
386 const EvDocumentInfo *info = NULL;
387 gboolean has_document = FALSE;
388 gboolean ok_to_print = TRUE;
389 gboolean ok_to_copy = TRUE;
390 gboolean has_properties = TRUE;
391 gboolean override_restrictions = TRUE;
392 gboolean can_get_text = FALSE;
393 gboolean has_pages = FALSE;
394 gboolean can_find = FALSE;
398 has_pages = ev_document_get_n_pages (document) > 0;
399 info = ev_document_get_info (document);
402 if (!info || info->fields_mask == 0) {
403 has_properties = FALSE;
406 if (has_document && EV_IS_SELECTION (document)) {
410 if (has_pages && EV_IS_DOCUMENT_FIND (document)) {
414 if (has_document && ev_window->priv->settings) {
415 override_restrictions =
416 g_settings_get_boolean (ev_window->priv->settings,
417 GS_OVERRIDE_RESTRICTIONS);
420 if (!override_restrictions && info && info->fields_mask & EV_DOCUMENT_INFO_PERMISSIONS) {
421 ok_to_print = (info->permissions & EV_DOCUMENT_PERMISSIONS_OK_TO_PRINT);
422 ok_to_copy = (info->permissions & EV_DOCUMENT_PERMISSIONS_OK_TO_COPY);
425 if (has_document && !ev_print_operation_exists_for_document(document))
428 if (has_document && ev_window->priv->lockdown_settings &&
429 g_settings_get_boolean (ev_window->priv->lockdown_settings, GS_LOCKDOWN_SAVE)) {
433 if (has_document && ev_window->priv->lockdown_settings &&
434 g_settings_get_boolean (ev_window->priv->lockdown_settings, GS_LOCKDOWN_PRINT)) {
439 ev_window_set_action_sensitive (ev_window, "FileOpenCopy", has_document);
440 ev_window_set_action_sensitive (ev_window, "FileSaveAs", has_document && ok_to_copy);
441 ev_window_set_action_sensitive (ev_window, "FilePrint", has_pages && ok_to_print);
442 ev_window_set_action_sensitive (ev_window, "FileProperties", has_document && has_properties);
445 ev_window_set_action_sensitive (ev_window, "EditSelectAll", has_pages && can_get_text);
446 ev_window_set_action_sensitive (ev_window, "EditFind", can_find);
447 ev_window_set_action_sensitive (ev_window, "Slash", can_find);
448 ev_window_set_action_sensitive (ev_window, "EditRotateLeft", has_pages);
449 ev_window_set_action_sensitive (ev_window, "EditRotateRight", has_pages);
452 ev_window_set_action_sensitive (ev_window, "ViewContinuous", has_pages);
453 ev_window_set_action_sensitive (ev_window, "ViewDual", has_pages);
454 ev_window_set_action_sensitive (ev_window, "ViewBestFit", has_pages);
455 ev_window_set_action_sensitive (ev_window, "ViewPageWidth", has_pages);
456 ev_window_set_action_sensitive (ev_window, "ViewReload", has_pages);
457 ev_window_set_action_sensitive (ev_window, "ViewAutoscroll", has_pages);
458 ev_window_set_action_sensitive (ev_window, "ViewInvertedColors", has_pages);
461 ev_window_set_action_sensitive (ev_window, "BookmarksAdd",
462 has_pages && ev_window->priv->bookmarks);
464 /* Toolbar-specific actions: */
465 ev_window_set_action_sensitive (ev_window, PAGE_SELECTOR_ACTION, has_pages);
466 ev_window_set_action_sensitive (ev_window, ZOOM_CONTROL_ACTION, has_pages);
467 ev_window_set_action_sensitive (ev_window, NAVIGATION_ACTION, FALSE);
469 ev_window_update_actions (ev_window);
473 ev_window_update_actions (EvWindow *ev_window)
475 EvView *view = EV_VIEW (ev_window->priv->view);
476 int n_pages = 0, page = -1;
477 gboolean has_pages = FALSE;
478 gboolean presentation_mode;
479 gboolean can_find_in_page = FALSE;
480 EvSizingMode sizing_mode;
482 if (ev_window->priv->document) {
483 page = ev_document_model_get_page (ev_window->priv->model);
484 n_pages = ev_document_get_n_pages (ev_window->priv->document);
485 has_pages = n_pages > 0;
488 can_find_in_page = (ev_window->priv->find_job &&
489 ev_job_find_has_results (EV_JOB_FIND (ev_window->priv->find_job)));
491 ev_window_set_action_sensitive (ev_window, "EditCopy",
493 ev_view_get_has_selection (view));
494 ev_window_set_action_sensitive (ev_window, "EditFindNext",
495 has_pages && can_find_in_page);
496 ev_window_set_action_sensitive (ev_window, "EditFindPrevious",
497 has_pages && can_find_in_page);
498 ev_window_set_action_sensitive (ev_window, "F3",
499 has_pages && can_find_in_page);
501 presentation_mode = EV_WINDOW_IS_PRESENTATION (ev_window);
503 ev_window_set_action_sensitive (ev_window, "ViewZoomIn",
505 ev_view_can_zoom_in (view) &&
507 ev_window_set_action_sensitive (ev_window, "ViewZoomOut",
509 ev_view_can_zoom_out (view) &&
514 ev_window_set_action_sensitive (ev_window, "GoPreviousPage", page > 0);
515 ev_window_set_action_sensitive (ev_window, "GoNextPage", page < n_pages - 1);
516 ev_window_set_action_sensitive (ev_window, "GoFirstPage", page > 0);
517 ev_window_set_action_sensitive (ev_window, "GoLastPage", page < n_pages - 1);
519 ev_window_set_action_sensitive (ev_window, "GoFirstPage", FALSE);
520 ev_window_set_action_sensitive (ev_window, "GoPreviousPage", FALSE);
521 ev_window_set_action_sensitive (ev_window, "GoNextPage", FALSE);
522 ev_window_set_action_sensitive (ev_window, "GoLastPage", FALSE);
525 sizing_mode = ev_document_model_get_sizing_mode (ev_window->priv->model);
526 if (has_pages && sizing_mode != EV_SIZING_FIT_WIDTH && sizing_mode != EV_SIZING_BEST_FIT) {
531 action = gtk_action_group_get_action (ev_window->priv->action_group,
532 ZOOM_CONTROL_ACTION);
534 real_zoom = ev_document_model_get_scale (ev_window->priv->model);
535 real_zoom *= 72.0 / get_screen_dpi (ev_window);
536 zoom = ephy_zoom_get_nearest_zoom_level (real_zoom);
538 ephy_zoom_action_set_zoom_level (EPHY_ZOOM_ACTION (action), zoom);
543 ev_window_set_view_accels_sensitivity (EvWindow *window, gboolean sensitive)
547 can_find = window->priv->document &&
548 EV_IS_DOCUMENT_FIND (window->priv->document);
550 if (window->priv->action_group) {
551 ev_window_set_action_sensitive (window, "PageDown", sensitive);
552 ev_window_set_action_sensitive (window, "PageUp", sensitive);
553 ev_window_set_action_sensitive (window, "Space", sensitive);
554 ev_window_set_action_sensitive (window, "ShiftSpace", sensitive);
555 ev_window_set_action_sensitive (window, "BackSpace", sensitive);
556 ev_window_set_action_sensitive (window, "ShiftBackSpace", sensitive);
557 ev_window_set_action_sensitive (window, "Return", sensitive);
558 ev_window_set_action_sensitive (window, "ShiftReturn", sensitive);
559 ev_window_set_action_sensitive (window, "Plus", sensitive);
560 ev_window_set_action_sensitive (window, "Minus", sensitive);
561 ev_window_set_action_sensitive (window, "KpPlus", sensitive);
562 ev_window_set_action_sensitive (window, "KpMinus", sensitive);
563 ev_window_set_action_sensitive (window, "Equal", sensitive);
564 ev_window_set_action_sensitive (window, "p", sensitive);
565 ev_window_set_action_sensitive (window, "n", sensitive);
567 ev_window_set_action_sensitive (window, "Slash", sensitive && can_find);
572 set_widget_visibility (GtkWidget *widget, gboolean visible)
574 g_assert (GTK_IS_WIDGET (widget));
577 gtk_widget_show (widget);
579 gtk_widget_hide (widget);
583 update_chrome_visibility (EvWindow *window)
585 EvWindowPrivate *priv = window->priv;
586 gboolean menubar, toolbar, findbar, fullscreen_toolbar, sidebar;
587 gboolean fullscreen_mode, presentation, fullscreen;
589 presentation = EV_WINDOW_IS_PRESENTATION (window);
590 fullscreen = ev_document_model_get_fullscreen (priv->model);
591 fullscreen_mode = fullscreen || presentation;
593 menubar = (priv->chrome & EV_CHROME_MENUBAR) != 0 && !fullscreen_mode;
594 toolbar = ((priv->chrome & EV_CHROME_TOOLBAR) != 0 ||
595 (priv->chrome & EV_CHROME_RAISE_TOOLBAR) != 0) && !fullscreen_mode;
596 fullscreen_toolbar = ((priv->chrome & EV_CHROME_FULLSCREEN_TOOLBAR) != 0 ||
597 (priv->chrome & EV_CHROME_RAISE_TOOLBAR) != 0) && fullscreen;
598 findbar = (priv->chrome & EV_CHROME_FINDBAR) != 0;
599 sidebar = (priv->chrome & EV_CHROME_SIDEBAR) != 0 && priv->document && !presentation;
601 set_widget_visibility (priv->menubar, menubar);
602 set_widget_visibility (priv->toolbar, toolbar);
603 set_widget_visibility (priv->find_bar, findbar);
604 set_widget_visibility (priv->sidebar, sidebar);
606 ev_window_set_action_sensitive (window, "EditToolbar", toolbar);
608 if (priv->fullscreen_toolbar != NULL) {
609 set_widget_visibility (priv->fullscreen_toolbar, fullscreen_toolbar);
614 update_chrome_flag (EvWindow *window, EvChrome flag, gboolean active)
616 EvWindowPrivate *priv = window->priv;
619 priv->chrome |= flag;
621 priv->chrome &= ~flag;
626 update_sizing_buttons (EvWindow *window)
628 GtkActionGroup *action_group = window->priv->action_group;
630 gboolean best_fit, page_width;
632 switch (ev_document_model_get_sizing_mode (window->priv->model)) {
633 case EV_SIZING_BEST_FIT:
637 case EV_SIZING_FIT_WIDTH:
642 best_fit = page_width = FALSE;
646 action = gtk_action_group_get_action (action_group, "ViewBestFit");
647 g_signal_handlers_block_by_func
648 (action, G_CALLBACK (ev_window_cmd_view_best_fit), window);
649 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), best_fit);
650 g_signal_handlers_unblock_by_func
651 (action, G_CALLBACK (ev_window_cmd_view_best_fit), window);
653 action = gtk_action_group_get_action (action_group, "ViewPageWidth");
654 g_signal_handlers_block_by_func
655 (action, G_CALLBACK (ev_window_cmd_view_page_width), window);
656 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), page_width);
657 g_signal_handlers_unblock_by_func
658 (action, G_CALLBACK (ev_window_cmd_view_page_width), window);
660 action = gtk_action_group_get_action (window->priv->action_group,
661 ZOOM_CONTROL_ACTION);
663 ephy_zoom_action_set_zoom_level (EPHY_ZOOM_ACTION (action),
665 } else if (page_width) {
666 ephy_zoom_action_set_zoom_level (EPHY_ZOOM_ACTION (action),
667 EPHY_ZOOM_FIT_WIDTH);
672 update_chrome_actions (EvWindow *window)
674 EvWindowPrivate *priv = window->priv;
675 GtkActionGroup *action_group = priv->action_group;
678 action= gtk_action_group_get_action (action_group, "ViewToolbar");
679 g_signal_handlers_block_by_func
680 (action, G_CALLBACK (ev_window_view_toolbar_cb), window);
681 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
682 (priv->chrome & EV_CHROME_TOOLBAR) != 0);
683 g_signal_handlers_unblock_by_func
684 (action, G_CALLBACK (ev_window_view_toolbar_cb), window);
688 * ev_window_is_empty:
689 * @ev_window: The instance of the #EvWindow.
691 * It does look if there is any document loaded or if there is any job to load
694 * Returns: %TRUE if there isn't any document loaded or any any documente to be
695 * loaded, %FALSE in other case.
698 ev_window_is_empty (const EvWindow *ev_window)
700 g_return_val_if_fail (EV_IS_WINDOW (ev_window), FALSE);
702 return (ev_window->priv->document == NULL) &&
703 (ev_window->priv->load_job == NULL);
707 ev_window_set_message_area (EvWindow *window,
710 if (window->priv->message_area == area)
713 if (window->priv->message_area)
714 gtk_widget_destroy (window->priv->message_area);
715 window->priv->message_area = area;
720 gtk_box_pack_start (GTK_BOX (window->priv->view_box),
721 window->priv->message_area,
723 gtk_box_reorder_child (GTK_BOX (window->priv->view_box),
724 window->priv->message_area, 0);
725 g_object_add_weak_pointer (G_OBJECT (window->priv->message_area),
726 (gpointer) &(window->priv->message_area));
730 ev_window_message_area_response_cb (EvMessageArea *area,
734 ev_window_set_message_area (window, NULL);
738 ev_window_error_message (EvWindow *window,
747 if (window->priv->message_area)
750 va_start (args, format);
751 msg = g_strdup_vprintf (format, args);
754 area = ev_message_area_new (GTK_MESSAGE_ERROR,
762 ev_message_area_set_secondary_text (EV_MESSAGE_AREA (area), error->message);
763 g_signal_connect (area, "response",
764 G_CALLBACK (ev_window_message_area_response_cb),
766 gtk_widget_show (area);
767 ev_window_set_message_area (window, area);
771 ev_window_warning_message (EvWindow *window,
779 if (window->priv->message_area)
782 va_start (args, format);
783 msg = g_strdup_vprintf (format, args);
786 area = ev_message_area_new (GTK_MESSAGE_WARNING,
793 g_signal_connect (area, "response",
794 G_CALLBACK (ev_window_message_area_response_cb),
796 gtk_widget_show (area);
797 ev_window_set_message_area (window, area);
800 typedef struct _PageTitleData {
801 const gchar *page_label;
806 ev_window_find_page_title (GtkTreeModel *tree_model,
813 gtk_tree_model_get (tree_model, iter,
814 EV_DOCUMENT_LINKS_COLUMN_PAGE_LABEL, &page_string,
820 if (!strcmp (page_string, data->page_label)) {
821 gtk_tree_model_get (tree_model, iter,
822 EV_DOCUMENT_LINKS_COLUMN_MARKUP, &data->page_title,
824 g_free (page_string);
828 g_free (page_string);
833 ev_window_get_page_title (EvWindow *window,
834 const gchar *page_label)
836 if (EV_IS_DOCUMENT_LINKS (window->priv->document) &&
837 ev_document_links_has_document_links (EV_DOCUMENT_LINKS (window->priv->document))) {
841 data.page_label = page_label;
842 data.page_title = NULL;
844 g_object_get (G_OBJECT (window->priv->sidebar_links),
848 gtk_tree_model_foreach (model,
849 (GtkTreeModelForeachFunc)ev_window_find_page_title,
852 g_object_unref (model);
855 return data.page_title;
862 ev_window_add_history (EvWindow *window, gint page, EvLink *link)
864 gchar *page_label = NULL;
868 EvLinkAction *action;
871 if (window->priv->history == NULL)
874 if (!EV_IS_DOCUMENT_LINKS (window->priv->document))
878 action = g_object_ref (ev_link_get_action (link));
879 dest = ev_link_action_get_dest (action);
880 page_label = ev_document_links_get_dest_page_label (EV_DOCUMENT_LINKS (window->priv->document), dest);
882 dest = ev_link_dest_new_page (page);
883 action = ev_link_action_new_dest (dest);
884 page_label = ev_document_get_page_label (window->priv->document, page);
890 page_title = ev_window_get_page_title (window, page_label);
892 link_title = g_strdup_printf (_("Page %s — %s"), page_label, page_title);
895 link_title = g_strdup_printf (_("Page %s"), page_label);
898 real_link = ev_link_new (link_title, action);
900 ev_history_add_link (window->priv->history, real_link);
904 g_object_unref (real_link);
908 view_handle_link_cb (EvView *view, EvLink *link, EvWindow *window)
910 int current_page = ev_document_model_get_page (window->priv->model);
912 ev_window_add_history (window, 0, link);
913 ev_window_add_history (window, current_page, NULL);
917 view_selection_changed_cb (EvView *view,
920 ev_window_set_action_sensitive (window, "EditCopy",
921 ev_view_get_has_selection (view));
925 view_layers_changed_cb (EvView *view,
928 ev_sidebar_layers_update_layers_state (EV_SIDEBAR_LAYERS (window->priv->sidebar_layers));
932 ev_window_page_changed_cb (EvWindow *ev_window,
935 EvDocumentModel *model)
937 ev_window_update_actions (ev_window);
939 ev_window_update_find_status_message (ev_window);
941 if (abs (new_page - old_page) > 1) {
942 ev_window_add_history (ev_window, new_page, NULL);
943 ev_window_add_history (ev_window, old_page, NULL);
946 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window))
947 ev_metadata_set_int (ev_window->priv->metadata, "page", new_page);
951 ev_window_sidebar_get_current_page_id (EvWindow *ev_window)
953 GtkWidget *current_page;
956 g_object_get (ev_window->priv->sidebar,
957 "current_page", ¤t_page,
960 if (current_page == ev_window->priv->sidebar_links) {
961 id = LINKS_SIDEBAR_ID;
962 } else if (current_page == ev_window->priv->sidebar_thumbs) {
963 id = THUMBNAILS_SIDEBAR_ID;
964 } else if (current_page == ev_window->priv->sidebar_attachments) {
965 id = ATTACHMENTS_SIDEBAR_ID;
966 } else if (current_page == ev_window->priv->sidebar_layers) {
967 id = LAYERS_SIDEBAR_ID;
968 } else if (current_page == ev_window->priv->sidebar_annots) {
969 id = ANNOTS_SIDEBAR_ID;
970 } else if (current_page == ev_window->priv->sidebar_bookmarks) {
971 id = BOOKMARKS_SIDEBAR_ID;
973 g_assert_not_reached();
976 g_object_unref (current_page);
982 ev_window_sidebar_set_current_page (EvWindow *window,
983 const gchar *page_id)
985 EvDocument *document = window->priv->document;
986 EvSidebar *sidebar = EV_SIDEBAR (window->priv->sidebar);
987 GtkWidget *links = window->priv->sidebar_links;
988 GtkWidget *thumbs = window->priv->sidebar_thumbs;
989 GtkWidget *attachments = window->priv->sidebar_attachments;
990 GtkWidget *annots = window->priv->sidebar_annots;
991 GtkWidget *layers = window->priv->sidebar_layers;
992 GtkWidget *bookmarks = window->priv->sidebar_bookmarks;
994 if (strcmp (page_id, LINKS_SIDEBAR_ID) == 0 &&
995 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (links), document)) {
996 ev_sidebar_set_page (sidebar, links);
997 } else if (strcmp (page_id, THUMBNAILS_SIDEBAR_ID) == 0 &&
998 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (thumbs), document)) {
999 ev_sidebar_set_page (sidebar, thumbs);
1000 } else if (strcmp (page_id, ATTACHMENTS_SIDEBAR_ID) == 0 &&
1001 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (attachments), document)) {
1002 ev_sidebar_set_page (sidebar, attachments);
1003 } else if (strcmp (page_id, LAYERS_SIDEBAR_ID) == 0 &&
1004 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (layers), document)) {
1005 ev_sidebar_set_page (sidebar, layers);
1006 } else if (strcmp (page_id, ANNOTS_SIDEBAR_ID) == 0 &&
1007 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (annots), document)) {
1008 ev_sidebar_set_page (sidebar, annots);
1009 } else if (strcmp (page_id, BOOKMARKS_SIDEBAR_ID) == 0 &&
1010 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (bookmarks), document)) {
1011 ev_sidebar_set_page (sidebar, bookmarks);
1016 update_document_mode (EvWindow *window, EvDocumentMode mode)
1018 if (mode == EV_DOCUMENT_MODE_PRESENTATION) {
1019 ev_window_run_presentation (window);
1021 else if (mode == EV_DOCUMENT_MODE_FULL_SCREEN) {
1022 ev_window_run_fullscreen (window);
1027 setup_chrome_from_metadata (EvWindow *window)
1029 EvChrome chrome = EV_CHROME_NORMAL;
1030 gboolean show_toolbar = TRUE;
1032 if (ev_window_is_empty (window)) {
1033 window->priv->chrome = chrome;
1038 if (!window->priv->metadata) {
1039 show_toolbar = g_settings_get_boolean (window->priv->default_settings, "show-toolbar");
1040 } else if (!ev_metadata_get_boolean (window->priv->metadata, "show_toolbar", &show_toolbar)) {
1041 if (window->priv->is_new_doc)
1042 show_toolbar = g_settings_get_boolean (window->priv->default_settings, "show-toolbar");
1046 chrome &= ~EV_CHROME_TOOLBAR;
1048 window->priv->chrome = chrome;
1052 setup_sidebar_from_metadata (EvWindow *window)
1054 EvDocument *document = window->priv->document;
1055 GSettings *settings = window->priv->default_settings;
1058 gboolean sidebar_visibility = TRUE;
1060 if (ev_window_is_empty (window))
1063 if (!window->priv->metadata) {
1064 sidebar_visibility = g_settings_get_boolean (settings, "show-sidebar");
1065 } else if (!ev_metadata_get_boolean (window->priv->metadata, "sidebar_visibility", &sidebar_visibility)) {
1066 if (window->priv->is_new_doc)
1067 sidebar_visibility = g_settings_get_boolean (settings, "show-sidebar");
1070 update_chrome_flag (window, EV_CHROME_SIDEBAR, sidebar_visibility);
1071 update_chrome_visibility (window);
1073 if (!window->priv->metadata) {
1074 /* Set default values */
1075 gtk_paned_set_position (GTK_PANED (window->priv->hpaned),
1076 g_settings_get_int (settings, "sidebar-size"));
1078 page_id = g_settings_get_string (settings, "sidebar-page");
1079 ev_window_sidebar_set_current_page (window, page_id);
1086 if (ev_metadata_get_int (window->priv->metadata, "sidebar_size", &sidebar_size)) {
1087 gtk_paned_set_position (GTK_PANED (window->priv->hpaned), sidebar_size);
1088 } else if (window->priv->is_new_doc) {
1089 gtk_paned_set_position (GTK_PANED (window->priv->hpaned),
1090 g_settings_get_int (settings, "sidebar-size"));
1096 if (ev_metadata_get_string (window->priv->metadata, "sidebar_page", &page_id)) {
1097 ev_window_sidebar_set_current_page (window, page_id);
1098 } else if (window->priv->is_new_doc) {
1099 page_id = g_settings_get_string (settings, "sidebar-page");
1100 ev_window_sidebar_set_current_page (window, page_id);
1106 setup_model_from_metadata (EvWindow *window)
1108 GSettings *settings = window->priv->default_settings;
1113 gboolean inverted_colors = FALSE;
1114 gboolean continuous = FALSE;
1115 gboolean dual_page = FALSE;
1116 gboolean fullscreen = FALSE;
1118 if (!window->priv->metadata) {
1119 /* Set default values */
1120 ev_document_model_set_sizing_mode (window->priv->model,
1121 g_settings_get_enum (settings, "sizing-mode"));
1122 ev_document_model_set_inverted_colors (window->priv->model,
1123 g_settings_get_boolean (settings, "inverted-colors"));
1124 ev_document_model_set_continuous (window->priv->model,
1125 g_settings_get_boolean (settings, "continuous"));
1126 ev_document_model_set_dual_page (window->priv->model,
1127 g_settings_get_boolean (settings, "dual-page"));
1128 fullscreen = g_settings_get_boolean (settings, "fullscreen");
1130 ev_window_run_fullscreen (window);
1136 if (!window->priv->dest &&
1137 ev_metadata_get_int (window->priv->metadata, "page", &page)) {
1138 ev_document_model_set_page (window->priv->model, page);
1142 if (ev_metadata_get_string (window->priv->metadata, "sizing_mode", &sizing_mode)) {
1143 GEnumValue *enum_value;
1145 enum_value = g_enum_get_value_by_nick
1146 (g_type_class_peek (EV_TYPE_SIZING_MODE), sizing_mode);
1147 ev_document_model_set_sizing_mode (window->priv->model, enum_value->value);
1148 } else if (window->priv->is_new_doc) {
1149 ev_document_model_set_sizing_mode (window->priv->model,
1150 g_settings_get_enum (settings, "sizing-mode"));
1154 if (ev_document_model_get_sizing_mode (window->priv->model) == EV_SIZING_FREE &&
1155 ev_metadata_get_double (window->priv->metadata, "zoom", &zoom)) {
1156 zoom *= get_screen_dpi (window) / 72.0;
1157 ev_document_model_set_scale (window->priv->model, zoom);
1161 if (ev_metadata_get_int (window->priv->metadata, "rotation", &rotation)) {
1176 ev_document_model_set_rotation (window->priv->model, rotation);
1179 /* Inverted Colors */
1180 if (ev_metadata_get_boolean (window->priv->metadata, "inverted-colors", &inverted_colors)) {
1181 ev_document_model_set_inverted_colors (window->priv->model, inverted_colors);
1182 } else if (window->priv->is_new_doc) {
1183 ev_document_model_set_inverted_colors (window->priv->model,
1184 g_settings_get_boolean (settings, "inverted-colors"));
1188 if (ev_metadata_get_boolean (window->priv->metadata, "continuous", &continuous)) {
1189 ev_document_model_set_continuous (window->priv->model, continuous);
1190 } else if (window->priv->is_new_doc) {
1191 ev_document_model_set_continuous (window->priv->model,
1192 g_settings_get_boolean (settings, "continuous"));
1196 if (ev_metadata_get_boolean (window->priv->metadata, "dual-page", &dual_page)) {
1197 ev_document_model_set_dual_page (window->priv->model, dual_page);
1198 } else if (window->priv->is_new_doc) {
1199 ev_document_model_set_dual_page (window->priv->model,
1200 g_settings_get_boolean (settings, "dual-page"));
1204 if (!ev_metadata_get_boolean (window->priv->metadata, "fullscreen", &fullscreen)) {
1205 if (window->priv->is_new_doc)
1206 fullscreen = g_settings_get_boolean (settings, "fullscreen");
1210 ev_window_run_fullscreen (window);
1214 setup_document_from_metadata (EvWindow *window)
1219 gdouble width_ratio;
1220 gdouble height_ratio;
1222 setup_sidebar_from_metadata (window);
1224 if (window->priv->metadata) {
1225 /* Make sure to not open a document on the last page,
1226 * since closing it on the last page most likely means the
1227 * user was finished reading the document. In that case, reopening should
1228 * show the first page. */
1229 page = ev_document_model_get_page (window->priv->model);
1230 n_pages = ev_document_get_n_pages (window->priv->document);
1231 if (page == n_pages - 1)
1232 ev_document_model_set_page (window->priv->model, 0);
1234 if (ev_metadata_get_int (window->priv->metadata, "window_width", &width) &&
1235 ev_metadata_get_int (window->priv->metadata, "window_height", &height))
1236 return; /* size was already set in setup_size_from_metadata */
1239 g_settings_get (window->priv->default_settings, "window-ratio", "(dd)", &width_ratio, &height_ratio);
1240 if (width_ratio > 0. && height_ratio > 0.) {
1241 gdouble document_width;
1242 gdouble document_height;
1245 gint request_height;
1247 ev_document_get_max_page_size (window->priv->document,
1248 &document_width, &document_height);
1250 request_width = (gint)(width_ratio * document_width + 0.5);
1251 request_height = (gint)(height_ratio * document_height + 0.5);
1253 screen = gtk_window_get_screen (GTK_WINDOW (window));
1255 request_width = MIN (request_width, gdk_screen_get_width (screen));
1256 request_height = MIN (request_height, gdk_screen_get_height (screen));
1259 if (request_width > 0 && request_height > 0) {
1260 gtk_window_resize (GTK_WINDOW (window),
1268 setup_size_from_metadata (EvWindow *window)
1276 if (!window->priv->metadata)
1279 if (ev_metadata_get_boolean (window->priv->metadata, "window_maximized", &maximized)) {
1281 gtk_window_maximize (GTK_WINDOW (window));
1284 gtk_window_unmaximize (GTK_WINDOW (window));
1288 if (ev_metadata_get_int (window->priv->metadata, "window_x", &x) &&
1289 ev_metadata_get_int (window->priv->metadata, "window_y", &y)) {
1290 gtk_window_move (GTK_WINDOW (window), x, y);
1293 if (ev_metadata_get_int (window->priv->metadata, "window_width", &width) &&
1294 ev_metadata_get_int (window->priv->metadata, "window_height", &height)) {
1295 gtk_window_resize (GTK_WINDOW (window), width, height);
1300 setup_view_from_metadata (EvWindow *window)
1302 gboolean presentation;
1304 if (!window->priv->metadata)
1308 if (ev_metadata_get_boolean (window->priv->metadata, "presentation", &presentation)) {
1310 ev_window_run_presentation (window);
1316 ev_window_clear_thumbnail_job (EvWindow *ev_window)
1318 if (ev_window->priv->thumbnail_job != NULL) {
1319 if (!ev_job_is_finished (ev_window->priv->thumbnail_job))
1320 ev_job_cancel (ev_window->priv->thumbnail_job);
1322 g_signal_handlers_disconnect_by_func (ev_window->priv->thumbnail_job,
1323 ev_window_set_icon_from_thumbnail,
1325 g_object_unref (ev_window->priv->thumbnail_job);
1326 ev_window->priv->thumbnail_job = NULL;
1331 ev_window_set_icon_from_thumbnail (EvJobThumbnail *job,
1332 EvWindow *ev_window)
1334 if (job->thumbnail) {
1335 if (ev_document_model_get_inverted_colors (ev_window->priv->model))
1336 ev_document_misc_invert_pixbuf (job->thumbnail);
1337 gtk_window_set_icon (GTK_WINDOW (ev_window),
1341 ev_window_clear_thumbnail_job (ev_window);
1345 ev_window_refresh_window_thumbnail (EvWindow *ev_window)
1350 EvDocument *document = ev_window->priv->document;
1352 if (ev_document_get_n_pages (document) <= 0 ||
1353 !ev_document_check_dimensions (document)) {
1357 ev_window_clear_thumbnail_job (ev_window);
1359 ev_document_get_page_size (document, 0, &page_width, NULL);
1360 scale = 128. / page_width;
1361 rotation = ev_document_model_get_rotation (ev_window->priv->model);
1363 ev_window->priv->thumbnail_job = ev_job_thumbnail_new (document, 0, rotation, scale);
1364 g_signal_connect (ev_window->priv->thumbnail_job, "finished",
1365 G_CALLBACK (ev_window_set_icon_from_thumbnail),
1367 ev_job_scheduler_push_job (ev_window->priv->thumbnail_job, EV_JOB_PRIORITY_NONE);
1371 override_restrictions_changed (GSettings *settings,
1373 EvWindow *ev_window)
1375 ev_window_setup_action_sensitivity (ev_window);
1379 lockdown_changed (GSettings *lockdown,
1381 EvWindow *ev_window)
1383 ev_window_setup_action_sensitivity (ev_window);
1387 ev_window_setup_document (EvWindow *ev_window)
1389 const EvDocumentInfo *info;
1390 EvDocument *document = ev_window->priv->document;
1393 ev_window->priv->setup_document_idle = 0;
1395 ev_window_refresh_window_thumbnail (ev_window);
1397 ev_window_set_page_mode (ev_window, PAGE_MODE_DOCUMENT);
1398 ev_window_title_set_document (ev_window->priv->title, document);
1399 ev_window_title_set_uri (ev_window->priv->title, ev_window->priv->uri);
1401 if (!ev_window->priv->settings) {
1402 ev_window->priv->settings = g_settings_new (GS_SCHEMA_NAME);
1403 g_signal_connect (ev_window->priv->settings,
1404 "changed::"GS_OVERRIDE_RESTRICTIONS,
1405 G_CALLBACK (override_restrictions_changed),
1409 #ifdef HAVE_DESKTOP_SCHEMAS
1410 if (!ev_window->priv->lockdown_settings) {
1411 ev_window->priv->lockdown_settings = g_settings_new (GS_LOCKDOWN_SCHEMA_NAME);
1412 g_signal_connect (ev_window->priv->lockdown_settings,
1414 G_CALLBACK (lockdown_changed),
1419 ev_window_setup_action_sensitivity (ev_window);
1421 if (ev_window->priv->history)
1422 g_object_unref (ev_window->priv->history);
1423 ev_window->priv->history = ev_history_new ();
1424 action = gtk_action_group_get_action (ev_window->priv->action_group, NAVIGATION_ACTION);
1425 ev_navigation_action_set_history (EV_NAVIGATION_ACTION (action), ev_window->priv->history);
1427 if (ev_window->priv->properties) {
1428 ev_properties_dialog_set_document (EV_PROPERTIES_DIALOG (ev_window->priv->properties),
1429 ev_window->priv->uri,
1430 ev_window->priv->document);
1433 info = ev_document_get_info (document);
1434 update_document_mode (ev_window, info->mode);
1436 if (EV_WINDOW_IS_PRESENTATION (ev_window))
1437 gtk_widget_grab_focus (ev_window->priv->presentation_view);
1439 gtk_widget_grab_focus (ev_window->priv->view);
1445 ev_window_set_document (EvWindow *ev_window, EvDocument *document)
1447 if (ev_window->priv->document == document)
1450 if (ev_window->priv->document)
1451 g_object_unref (ev_window->priv->document);
1452 ev_window->priv->document = g_object_ref (document);
1454 ev_window_update_max_min_scale (ev_window);
1456 ev_window_set_message_area (ev_window, NULL);
1458 if (ev_document_get_n_pages (document) <= 0) {
1459 ev_window_warning_message (ev_window, "%s",
1460 _("The document contains no pages"));
1461 } else if (!ev_document_check_dimensions (document)) {
1462 ev_window_warning_message (ev_window, "%s",
1463 _("The document contains only empty pages"));
1466 if (EV_WINDOW_IS_PRESENTATION (ev_window)) {
1467 gtk_widget_destroy (ev_window->priv->presentation_view);
1468 ev_window->priv->presentation_view = NULL;
1469 ev_window_run_presentation (ev_window);
1472 if (ev_window->priv->setup_document_idle > 0)
1473 g_source_remove (ev_window->priv->setup_document_idle);
1475 ev_window->priv->setup_document_idle = g_idle_add ((GSourceFunc)ev_window_setup_document, ev_window);
1479 ev_window_document_changed (EvWindow *ev_window,
1482 ev_window_reload_document (ev_window, NULL);
1486 ev_window_password_view_unlock (EvWindow *ev_window)
1488 const gchar *password;
1490 g_assert (ev_window->priv->load_job);
1492 password = ev_password_view_get_password (EV_PASSWORD_VIEW (ev_window->priv->password_view));
1493 ev_job_load_set_password (EV_JOB_LOAD (ev_window->priv->load_job), password);
1494 ev_job_scheduler_push_job (ev_window->priv->load_job, EV_JOB_PRIORITY_NONE);
1498 ev_window_clear_load_job (EvWindow *ev_window)
1500 if (ev_window->priv->load_job != NULL) {
1501 if (!ev_job_is_finished (ev_window->priv->load_job))
1502 ev_job_cancel (ev_window->priv->load_job);
1504 g_signal_handlers_disconnect_by_func (ev_window->priv->load_job, ev_window_load_job_cb, ev_window);
1505 g_object_unref (ev_window->priv->load_job);
1506 ev_window->priv->load_job = NULL;
1511 ev_window_clear_reload_job (EvWindow *ev_window)
1513 if (ev_window->priv->reload_job != NULL) {
1514 if (!ev_job_is_finished (ev_window->priv->reload_job))
1515 ev_job_cancel (ev_window->priv->reload_job);
1517 g_signal_handlers_disconnect_by_func (ev_window->priv->reload_job, ev_window_reload_job_cb, ev_window);
1518 g_object_unref (ev_window->priv->reload_job);
1519 ev_window->priv->reload_job = NULL;
1524 ev_window_clear_local_uri (EvWindow *ev_window)
1526 if (ev_window->priv->local_uri) {
1527 ev_tmp_uri_unlink (ev_window->priv->local_uri);
1528 g_free (ev_window->priv->local_uri);
1529 ev_window->priv->local_uri = NULL;
1534 ev_window_handle_link (EvWindow *ev_window,
1539 EvLinkAction *link_action;
1541 link_action = ev_link_action_new_dest (dest);
1542 link = ev_link_new (NULL, link_action);
1543 ev_view_handle_link (EV_VIEW (ev_window->priv->view), link);
1544 g_object_unref (link);
1548 /* This callback will executed when load job will be finished.
1550 * Since the flow of the error dialog is very confusing, we assume that both
1551 * document and uri will go away after this function is called, and thus we need
1552 * to ref/dup them. Additionally, it needs to clear
1553 * ev_window->priv->password_{uri,document}, and thus people who call this
1554 * function should _not_ necessarily expect those to exist after being
1557 ev_window_load_job_cb (EvJob *job,
1560 EvWindow *ev_window = EV_WINDOW (data);
1561 EvDocument *document = EV_JOB (job)->document;
1562 EvJobLoad *job_load = EV_JOB_LOAD (job);
1564 g_assert (job_load->uri);
1566 ev_view_set_loading (EV_VIEW (ev_window->priv->view), FALSE);
1569 if (!ev_job_is_failed (job)) {
1570 ev_document_model_set_document (ev_window->priv->model, document);
1573 ev_window_emit_doc_loaded (ev_window);
1575 setup_chrome_from_metadata (ev_window);
1576 update_chrome_actions (ev_window);
1577 setup_document_from_metadata (ev_window);
1578 setup_view_from_metadata (ev_window);
1580 ev_window_add_recent (ev_window, ev_window->priv->uri);
1582 ev_window_title_set_type (ev_window->priv->title,
1583 EV_WINDOW_TITLE_DOCUMENT);
1584 if (job_load->password) {
1585 GPasswordSave flags;
1587 flags = ev_password_view_get_password_save_flags (
1588 EV_PASSWORD_VIEW (ev_window->priv->password_view));
1589 ev_keyring_save_password (ev_window->priv->uri,
1594 ev_window_handle_link (ev_window, ev_window->priv->dest);
1595 /* Already unrefed by ev_link_action
1596 * FIXME: link action should inc dest ref counting
1597 * or not unref it at all
1599 ev_window->priv->dest = NULL;
1601 switch (ev_window->priv->window_mode) {
1602 case EV_WINDOW_MODE_FULLSCREEN:
1603 ev_window_run_fullscreen (ev_window);
1605 case EV_WINDOW_MODE_PRESENTATION:
1606 ev_window_run_presentation (ev_window);
1612 if (ev_window->priv->search_string && EV_IS_DOCUMENT_FIND (document)) {
1613 ev_window_cmd_edit_find (NULL, ev_window);
1614 egg_find_bar_set_search_string (EGG_FIND_BAR (ev_window->priv->find_bar),
1615 ev_window->priv->search_string);
1618 g_free (ev_window->priv->search_string);
1619 ev_window->priv->search_string = NULL;
1621 /* Create a monitor for the document */
1622 ev_window->priv->monitor = ev_file_monitor_new (ev_window->priv->uri);
1623 g_signal_connect_swapped (ev_window->priv->monitor, "changed",
1624 G_CALLBACK (ev_window_document_changed),
1627 ev_window_clear_load_job (ev_window);
1631 if (g_error_matches (job->error, EV_DOCUMENT_ERROR, EV_DOCUMENT_ERROR_ENCRYPTED)) {
1634 setup_view_from_metadata (ev_window);
1636 /* First look whether password is in keyring */
1637 password = ev_keyring_lookup_password (ev_window->priv->uri);
1639 if (job_load->password && strcmp (password, job_load->password) == 0) {
1640 /* Password in kering is wrong */
1641 ev_job_load_set_password (job_load, NULL);
1642 /* FIXME: delete password from keyring? */
1644 ev_job_load_set_password (job_load, password);
1645 ev_job_scheduler_push_job (job, EV_JOB_PRIORITY_NONE);
1653 /* We need to ask the user for a password */
1654 ev_window_title_set_uri (ev_window->priv->title,
1655 ev_window->priv->uri);
1656 ev_window_title_set_type (ev_window->priv->title,
1657 EV_WINDOW_TITLE_PASSWORD);
1659 ev_password_view_set_uri (EV_PASSWORD_VIEW (ev_window->priv->password_view),
1662 ev_window_set_page_mode (ev_window, PAGE_MODE_PASSWORD);
1664 ev_job_load_set_password (job_load, NULL);
1665 ev_password_view_ask_password (EV_PASSWORD_VIEW (ev_window->priv->password_view));
1667 ev_window_error_message (ev_window, job->error,
1668 "%s", _("Unable to open document"));
1669 ev_window_clear_load_job (ev_window);
1674 ev_window_reload_job_cb (EvJob *job,
1675 EvWindow *ev_window)
1679 if (ev_job_is_failed (job)) {
1680 ev_window_clear_reload_job (ev_window);
1681 ev_window->priv->in_reload = FALSE;
1682 if (ev_window->priv->dest) {
1683 g_object_unref (ev_window->priv->dest);
1684 ev_window->priv->dest = NULL;
1690 ev_document_model_set_document (ev_window->priv->model,
1692 if (ev_window->priv->dest) {
1693 ev_window_handle_link (ev_window, ev_window->priv->dest);
1694 /* Already unrefed by ev_link_action
1695 * FIXME: link action should inc dest ref counting
1696 * or not unref it at all
1698 ev_window->priv->dest = NULL;
1701 /* Restart the search after reloading */
1702 widget = gtk_window_get_focus (GTK_WINDOW (ev_window));
1703 if (widget && gtk_widget_get_ancestor (widget, EGG_TYPE_FIND_BAR)) {
1704 find_bar_search_changed_cb (EGG_FIND_BAR (ev_window->priv->find_bar),
1708 ev_window_clear_reload_job (ev_window);
1709 ev_window->priv->in_reload = FALSE;
1713 * ev_window_get_uri:
1714 * @ev_window: The instance of the #EvWindow.
1716 * It returns the uri of the document showed in the #EvWindow.
1718 * Returns: the uri of the document showed in the #EvWindow.
1721 ev_window_get_uri (EvWindow *ev_window)
1723 return ev_window->priv->uri;
1727 * ev_window_close_dialogs:
1728 * @ev_window: The window where dialogs will be closed.
1730 * It looks for password, print and properties dialogs and closes them and
1731 * frees them from memory. If there is any print job it does free it too.
1734 ev_window_close_dialogs (EvWindow *ev_window)
1736 if (ev_window->priv->print_dialog)
1737 gtk_widget_destroy (ev_window->priv->print_dialog);
1738 ev_window->priv->print_dialog = NULL;
1740 if (ev_window->priv->properties)
1741 gtk_widget_destroy (ev_window->priv->properties);
1742 ev_window->priv->properties = NULL;
1746 ev_window_clear_progress_idle (EvWindow *ev_window)
1748 if (ev_window->priv->progress_idle > 0)
1749 g_source_remove (ev_window->priv->progress_idle);
1750 ev_window->priv->progress_idle = 0;
1754 reset_progress_idle (EvWindow *ev_window)
1756 ev_window->priv->progress_idle = 0;
1760 ev_window_show_progress_message (EvWindow *ev_window,
1762 GSourceFunc function)
1764 if (ev_window->priv->progress_idle > 0)
1765 g_source_remove (ev_window->priv->progress_idle);
1766 ev_window->priv->progress_idle =
1767 g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
1770 (GDestroyNotify)reset_progress_idle);
1774 ev_window_reset_progress_cancellable (EvWindow *ev_window)
1776 if (ev_window->priv->progress_cancellable)
1777 g_cancellable_reset (ev_window->priv->progress_cancellable);
1779 ev_window->priv->progress_cancellable = g_cancellable_new ();
1783 ev_window_progress_response_cb (EvProgressMessageArea *area,
1785 EvWindow *ev_window)
1787 if (response == GTK_RESPONSE_CANCEL)
1788 g_cancellable_cancel (ev_window->priv->progress_cancellable);
1789 ev_window_set_message_area (ev_window, NULL);
1793 show_loading_progress (EvWindow *ev_window)
1797 gchar *display_name;
1799 if (ev_window->priv->message_area)
1802 text = g_uri_unescape_string (ev_window->priv->uri, NULL);
1803 display_name = g_markup_escape_text (text, -1);
1805 text = g_strdup_printf (_("Loading document from “%s”"),
1808 area = ev_progress_message_area_new (GTK_STOCK_OPEN,
1813 GTK_RESPONSE_CANCEL,
1815 g_signal_connect (area, "response",
1816 G_CALLBACK (ev_window_progress_response_cb),
1818 gtk_widget_show (area);
1819 ev_window_set_message_area (ev_window, area);
1822 g_free (display_name);
1828 ev_window_load_remote_failed (EvWindow *ev_window,
1831 ev_view_set_loading (EV_VIEW (ev_window->priv->view), FALSE);
1832 ev_window->priv->in_reload = FALSE;
1833 ev_window_error_message (ev_window, error,
1834 "%s", _("Unable to open document"));
1835 g_free (ev_window->priv->local_uri);
1836 ev_window->priv->local_uri = NULL;
1837 ev_window->priv->uri_mtime = 0;
1841 set_uri_mtime (GFile *source,
1842 GAsyncResult *async_result,
1843 EvWindow *ev_window)
1846 GError *error = NULL;
1848 info = g_file_query_info_finish (source, async_result, &error);
1851 ev_window->priv->uri_mtime = 0;
1852 g_error_free (error);
1856 g_file_info_get_modification_time (info, &mtime);
1857 ev_window->priv->uri_mtime = mtime.tv_sec;
1858 g_object_unref (info);
1861 g_object_unref (source);
1865 mount_volume_ready_cb (GFile *source,
1866 GAsyncResult *async_result,
1867 EvWindow *ev_window)
1869 GError *error = NULL;
1871 g_file_mount_enclosing_volume_finish (source, async_result, &error);
1874 ev_window_load_remote_failed (ev_window, error);
1875 g_object_unref (source);
1876 g_error_free (error);
1878 /* Volume successfully mounted,
1879 try opening the file again */
1880 ev_window_load_file_remote (ev_window, source);
1885 window_open_file_copy_ready_cb (GFile *source,
1886 GAsyncResult *async_result,
1887 EvWindow *ev_window)
1889 GError *error = NULL;
1891 ev_window_clear_progress_idle (ev_window);
1892 ev_window_set_message_area (ev_window, NULL);
1894 g_file_copy_finish (source, async_result, &error);
1896 ev_job_scheduler_push_job (ev_window->priv->load_job, EV_JOB_PRIORITY_NONE);
1897 g_file_query_info_async (source,
1898 G_FILE_ATTRIBUTE_TIME_MODIFIED,
1899 0, G_PRIORITY_DEFAULT,
1901 (GAsyncReadyCallback)set_uri_mtime,
1906 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_MOUNTED)) {
1907 GMountOperation *operation;
1909 operation = gtk_mount_operation_new (GTK_WINDOW (ev_window));
1910 g_file_mount_enclosing_volume (source,
1913 (GAsyncReadyCallback)mount_volume_ready_cb,
1915 g_object_unref (operation);
1916 } else if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
1917 ev_window_clear_load_job (ev_window);
1918 ev_window_clear_local_uri (ev_window);
1919 g_free (ev_window->priv->uri);
1920 ev_window->priv->uri = NULL;
1921 g_object_unref (source);
1923 ev_view_set_loading (EV_VIEW (ev_window->priv->view), FALSE);
1925 ev_window_load_remote_failed (ev_window, error);
1926 g_object_unref (source);
1929 g_error_free (error);
1933 window_open_file_copy_progress_cb (goffset n_bytes,
1934 goffset total_bytes,
1935 EvWindow *ev_window)
1940 if (!ev_window->priv->message_area)
1943 if (total_bytes <= 0)
1946 fraction = n_bytes / (gdouble)total_bytes;
1947 status = g_strdup_printf (_("Downloading document (%d%%)"),
1948 (gint)(fraction * 100));
1950 ev_progress_message_area_set_status (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
1952 ev_progress_message_area_set_fraction (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
1959 ev_window_load_file_remote (EvWindow *ev_window,
1964 if (!ev_window->priv->local_uri) {
1965 char *base_name, *template;
1969 /* We'd like to keep extension of source uri since
1970 * it helps to resolve some mime types, say cbz.
1972 base_name = g_file_get_basename (source_file);
1973 template = g_strdup_printf ("document.XXXXXX-%s", base_name);
1976 tmp_file = ev_mkstemp_file (template, &err);
1978 if (tmp_file == NULL) {
1979 ev_window_error_message (ev_window, err,
1980 "%s", _("Failed to load remote file."));
1985 ev_window->priv->local_uri = g_file_get_uri (tmp_file);
1986 g_object_unref (tmp_file);
1988 ev_job_load_set_uri (EV_JOB_LOAD (ev_window->priv->load_job),
1989 ev_window->priv->local_uri);
1992 ev_window_reset_progress_cancellable (ev_window);
1994 target_file = g_file_new_for_uri (ev_window->priv->local_uri);
1995 g_file_copy_async (source_file, target_file,
1996 G_FILE_COPY_OVERWRITE,
1998 ev_window->priv->progress_cancellable,
1999 (GFileProgressCallback)window_open_file_copy_progress_cb,
2001 (GAsyncReadyCallback)window_open_file_copy_ready_cb,
2003 g_object_unref (target_file);
2005 ev_window_show_progress_message (ev_window, 1,
2006 (GSourceFunc)show_loading_progress);
2010 ev_window_open_uri (EvWindow *ev_window,
2013 EvWindowRunMode mode,
2014 const gchar *search_string)
2018 ev_window->priv->in_reload = FALSE;
2020 if (ev_window->priv->uri &&
2021 g_ascii_strcasecmp (ev_window->priv->uri, uri) == 0) {
2022 ev_window_reload_document (ev_window, dest);
2026 if (ev_window->priv->monitor) {
2027 g_object_unref (ev_window->priv->monitor);
2028 ev_window->priv->monitor = NULL;
2031 ev_window_close_dialogs (ev_window);
2032 ev_window_clear_load_job (ev_window);
2033 ev_window_clear_local_uri (ev_window);
2035 ev_window->priv->window_mode = mode;
2037 if (ev_window->priv->uri)
2038 g_free (ev_window->priv->uri);
2039 ev_window->priv->uri = g_strdup (uri);
2041 if (ev_window->priv->metadata)
2042 g_object_unref (ev_window->priv->metadata);
2043 if (ev_window->priv->bookmarks)
2044 g_object_unref (ev_window->priv->bookmarks);
2046 source_file = g_file_new_for_uri (uri);
2047 if (!ev_file_is_temp (source_file) && ev_is_metadata_supported_for_file (source_file)) {
2048 ev_window->priv->metadata = ev_metadata_new (source_file);
2049 ev_window->priv->is_new_doc = ev_metadata_is_empty (ev_window->priv->metadata);
2051 ev_window->priv->metadata = NULL;
2054 if (ev_window->priv->metadata) {
2055 ev_window->priv->bookmarks = ev_bookmarks_new (ev_window->priv->metadata);
2056 ev_sidebar_bookmarks_set_bookmarks (EV_SIDEBAR_BOOKMARKS (ev_window->priv->sidebar_bookmarks),
2057 ev_window->priv->bookmarks);
2058 g_signal_connect_swapped (ev_window->priv->bookmarks, "changed",
2059 G_CALLBACK (ev_window_setup_bookmarks),
2062 ev_window->priv->bookmarks = NULL;
2065 if (ev_window->priv->search_string)
2066 g_free (ev_window->priv->search_string);
2067 ev_window->priv->search_string = search_string ?
2068 g_strdup (search_string) : NULL;
2070 if (ev_window->priv->dest)
2071 g_object_unref (ev_window->priv->dest);
2072 ev_window->priv->dest = dest ? g_object_ref (dest) : NULL;
2074 setup_size_from_metadata (ev_window);
2075 setup_model_from_metadata (ev_window);
2076 ev_window_setup_bookmarks (ev_window);
2078 ev_window->priv->load_job = ev_job_load_new (uri);
2079 g_signal_connect (ev_window->priv->load_job,
2081 G_CALLBACK (ev_window_load_job_cb),
2084 if (!g_file_is_native (source_file) && !ev_window->priv->local_uri) {
2085 ev_window_load_file_remote (ev_window, source_file);
2087 ev_view_set_loading (EV_VIEW (ev_window->priv->view), TRUE);
2088 g_object_unref (source_file);
2089 ev_job_scheduler_push_job (ev_window->priv->load_job, EV_JOB_PRIORITY_NONE);
2094 ev_window_open_document (EvWindow *ev_window,
2095 EvDocument *document,
2097 EvWindowRunMode mode,
2098 const gchar *search_string)
2100 if (document == ev_window->priv->document)
2103 ev_window_close_dialogs (ev_window);
2104 ev_window_clear_load_job (ev_window);
2105 ev_window_clear_local_uri (ev_window);
2107 if (ev_window->priv->monitor) {
2108 g_object_unref (ev_window->priv->monitor);
2109 ev_window->priv->monitor = NULL;
2112 if (ev_window->priv->uri)
2113 g_free (ev_window->priv->uri);
2114 ev_window->priv->uri = g_strdup (ev_document_get_uri (document));
2116 setup_size_from_metadata (ev_window);
2117 setup_model_from_metadata (ev_window);
2119 ev_document_model_set_document (ev_window->priv->model, document);
2121 setup_document_from_metadata (ev_window);
2122 setup_view_from_metadata (ev_window);
2126 EvLinkAction *link_action;
2128 link_action = ev_link_action_new_dest (dest);
2129 link = ev_link_new (NULL, link_action);
2130 ev_view_handle_link (EV_VIEW (ev_window->priv->view), link);
2131 /* FIXME: link action should inc dest ref counting
2132 * or not unref it at all
2134 g_object_ref (dest);
2135 g_object_unref (link);
2139 case EV_WINDOW_MODE_FULLSCREEN:
2140 ev_window_run_fullscreen (ev_window);
2142 case EV_WINDOW_MODE_PRESENTATION:
2143 ev_window_run_presentation (ev_window);
2149 if (search_string && EV_IS_DOCUMENT_FIND (document)) {
2150 ev_window_cmd_edit_find (NULL, ev_window);
2151 egg_find_bar_set_search_string (EGG_FIND_BAR (ev_window->priv->find_bar),
2155 /* Create a monitor for the document */
2156 ev_window->priv->monitor = ev_file_monitor_new (ev_window->priv->uri);
2157 g_signal_connect_swapped (ev_window->priv->monitor, "changed",
2158 G_CALLBACK (ev_window_document_changed),
2163 ev_window_reload_local (EvWindow *ev_window)
2167 uri = ev_window->priv->local_uri ? ev_window->priv->local_uri : ev_window->priv->uri;
2168 ev_window->priv->reload_job = ev_job_load_new (uri);
2169 g_signal_connect (ev_window->priv->reload_job, "finished",
2170 G_CALLBACK (ev_window_reload_job_cb),
2172 ev_job_scheduler_push_job (ev_window->priv->reload_job, EV_JOB_PRIORITY_NONE);
2176 show_reloading_progress (EvWindow *ev_window)
2181 if (ev_window->priv->message_area)
2184 text = g_strdup_printf (_("Reloading document from %s"),
2185 ev_window->priv->uri);
2186 area = ev_progress_message_area_new (GTK_STOCK_REFRESH,
2191 GTK_RESPONSE_CANCEL,
2193 g_signal_connect (area, "response",
2194 G_CALLBACK (ev_window_progress_response_cb),
2196 gtk_widget_show (area);
2197 ev_window_set_message_area (ev_window, area);
2204 reload_remote_copy_ready_cb (GFile *remote,
2205 GAsyncResult *async_result,
2206 EvWindow *ev_window)
2208 GError *error = NULL;
2210 ev_window_clear_progress_idle (ev_window);
2212 g_file_copy_finish (remote, async_result, &error);
2214 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
2215 ev_window_error_message (ev_window, error,
2216 "%s", _("Failed to reload document."));
2217 g_error_free (error);
2219 ev_window_reload_local (ev_window);
2222 g_object_unref (remote);
2226 reload_remote_copy_progress_cb (goffset n_bytes,
2227 goffset total_bytes,
2228 EvWindow *ev_window)
2233 if (!ev_window->priv->message_area)
2236 if (total_bytes <= 0)
2239 fraction = n_bytes / (gdouble)total_bytes;
2240 status = g_strdup_printf (_("Downloading document (%d%%)"),
2241 (gint)(fraction * 100));
2243 ev_progress_message_area_set_status (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
2245 ev_progress_message_area_set_fraction (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
2252 query_remote_uri_mtime_cb (GFile *remote,
2253 GAsyncResult *async_result,
2254 EvWindow *ev_window)
2258 GError *error = NULL;
2260 info = g_file_query_info_finish (remote, async_result, &error);
2262 g_error_free (error);
2263 g_object_unref (remote);
2264 ev_window_reload_local (ev_window);
2269 g_file_info_get_modification_time (info, &mtime);
2270 if (ev_window->priv->uri_mtime != mtime.tv_sec) {
2273 /* Remote file has changed */
2274 ev_window->priv->uri_mtime = mtime.tv_sec;
2276 ev_window_reset_progress_cancellable (ev_window);
2278 target_file = g_file_new_for_uri (ev_window->priv->local_uri);
2279 g_file_copy_async (remote, target_file,
2280 G_FILE_COPY_OVERWRITE,
2282 ev_window->priv->progress_cancellable,
2283 (GFileProgressCallback)reload_remote_copy_progress_cb,
2285 (GAsyncReadyCallback)reload_remote_copy_ready_cb,
2287 g_object_unref (target_file);
2288 ev_window_show_progress_message (ev_window, 1,
2289 (GSourceFunc)show_reloading_progress);
2291 g_object_unref (remote);
2292 ev_window_reload_local (ev_window);
2295 g_object_unref (info);
2299 ev_window_reload_remote (EvWindow *ev_window)
2303 remote = g_file_new_for_uri (ev_window->priv->uri);
2304 /* Reload the remote uri only if it has changed */
2305 g_file_query_info_async (remote,
2306 G_FILE_ATTRIBUTE_TIME_MODIFIED,
2307 0, G_PRIORITY_DEFAULT,
2309 (GAsyncReadyCallback)query_remote_uri_mtime_cb,
2314 ev_window_reload_document (EvWindow *ev_window,
2320 ev_window_clear_reload_job (ev_window);
2321 ev_window->priv->in_reload = TRUE;
2323 page = ev_document_model_get_page (ev_window->priv->model);
2325 if (ev_window->priv->dest)
2326 g_object_unref (ev_window->priv->dest);
2327 ev_window->priv->dest = dest ? g_object_ref (dest) : NULL;
2329 if (ev_window->priv->local_uri) {
2330 ev_window_reload_remote (ev_window);
2332 ev_window_reload_local (ev_window);
2337 file_open_dialog_response_cb (GtkWidget *chooser,
2339 EvWindow *ev_window)
2341 if (response_id == GTK_RESPONSE_OK) {
2345 uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (chooser));
2347 ev_application_open_uri_list (EV_APP, uris,
2348 gtk_window_get_screen (GTK_WINDOW (ev_window)),
2349 gtk_get_current_event_time ());
2351 g_slist_foreach (uris, (GFunc)g_free, NULL);
2352 g_slist_free (uris);
2354 uri = gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (chooser));
2355 ev_application_set_filechooser_uri (EV_APP,
2356 GTK_FILE_CHOOSER_ACTION_OPEN,
2361 gtk_widget_destroy (chooser);
2365 ev_window_cmd_file_open (GtkAction *action, EvWindow *window)
2368 const gchar *default_uri;
2369 gchar *parent_uri = NULL;
2371 chooser = gtk_file_chooser_dialog_new (_("Open Document"),
2372 GTK_WINDOW (window),
2373 GTK_FILE_CHOOSER_ACTION_OPEN,
2375 GTK_RESPONSE_CANCEL,
2376 GTK_STOCK_OPEN, GTK_RESPONSE_OK,
2379 ev_document_factory_add_filters (chooser, NULL);
2380 gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (chooser), TRUE);
2381 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser), FALSE);
2383 default_uri = ev_application_get_filechooser_uri (EV_APP, GTK_FILE_CHOOSER_ACTION_OPEN);
2384 if (!default_uri && window->priv->uri) {
2385 GFile *file, *parent;
2387 file = g_file_new_for_uri (window->priv->uri);
2388 parent = g_file_get_parent (file);
2390 parent_uri = g_file_get_uri (parent);
2391 default_uri = parent_uri;
2392 g_object_unref (parent);
2394 g_object_unref (file);
2398 gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (chooser), default_uri);
2400 const gchar *folder;
2402 folder = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
2403 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser),
2404 folder ? folder : g_get_home_dir ());
2406 g_free (parent_uri);
2408 g_signal_connect (chooser, "response",
2409 G_CALLBACK (file_open_dialog_response_cb),
2412 gtk_widget_show (chooser);
2416 ev_window_open_copy_at_dest (EvWindow *window,
2419 EvWindow *new_window = EV_WINDOW (ev_window_new ());
2421 ev_window_n_copies++;
2423 if (window->priv->metadata)
2424 new_window->priv->metadata = g_object_ref (window->priv->metadata);
2425 ev_window_open_document (new_window,
2426 window->priv->document,
2428 gtk_window_present (GTK_WINDOW (new_window));
2432 ev_window_cmd_file_open_copy (GtkAction *action, EvWindow *window)
2434 ev_window_open_copy_at_dest (window, NULL);
2438 ev_window_cmd_recent_file_activate (GtkAction *action,
2441 GtkRecentInfo *info;
2444 info = g_object_get_data (G_OBJECT (action), "gtk-recent-info");
2445 g_assert (info != NULL);
2447 uri = gtk_recent_info_get_uri (info);
2449 ev_application_open_uri_at_dest (EV_APP, uri,
2450 gtk_window_get_screen (GTK_WINDOW (window)),
2451 NULL, 0, NULL, gtk_get_current_event_time ());
2455 ev_window_open_recent_action_item_activated (EvOpenRecentAction *action,
2459 ev_application_open_uri_at_dest (EV_APP, uri,
2460 gtk_window_get_screen (GTK_WINDOW (window)),
2461 NULL, 0, NULL, gtk_get_current_event_time ());
2465 ev_window_add_recent (EvWindow *window, const char *filename)
2467 gtk_recent_manager_add_item (window->priv->recent_manager, filename);
2471 compare_recent_items (GtkRecentInfo *a, GtkRecentInfo *b)
2473 gboolean has_ev_a, has_ev_b;
2474 const gchar *evince = g_get_application_name ();
2476 has_ev_a = gtk_recent_info_has_application (a, evince);
2477 has_ev_b = gtk_recent_info_has_application (b, evince);
2479 if (has_ev_a && has_ev_b) {
2480 time_t time_a, time_b;
2482 time_a = gtk_recent_info_get_modified (a);
2483 time_b = gtk_recent_info_get_modified (b);
2485 return (time_b - time_a);
2486 } else if (has_ev_a) {
2488 } else if (has_ev_b) {
2496 * Doubles underscore to avoid spurious menu accels.
2499 ev_window_get_recent_file_label (gint index, const gchar *filename)
2507 is_rtl = (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL);
2509 g_return_val_if_fail (filename != NULL, NULL);
2511 length = strlen (filename);
2512 str = g_string_sized_new (length + 10);
2513 g_string_printf (str, "%s_%d. ", is_rtl ? "\xE2\x80\x8F" : "", index);
2516 end = filename + length;
2520 next = g_utf8_next_char (p);
2524 g_string_append (str, "__");
2527 g_string_append_len (str, p, next - p);
2534 return g_string_free (str, FALSE);
2538 ev_window_recent_action_connect_proxy_cb (GtkActionGroup *action_group,
2545 if (!GTK_IS_MENU_ITEM (proxy))
2548 label = GTK_LABEL (gtk_bin_get_child (GTK_BIN (proxy)));
2550 gtk_label_set_ellipsize (label, PANGO_ELLIPSIZE_MIDDLE);
2551 gtk_label_set_max_width_chars (label, MAX_RECENT_ITEM_LEN);
2555 ev_window_setup_recent (EvWindow *ev_window)
2559 const gchar *evince = g_get_application_name ();
2562 if (ev_window->priv->recent_ui_id > 0) {
2563 gtk_ui_manager_remove_ui (ev_window->priv->ui_manager,
2564 ev_window->priv->recent_ui_id);
2565 gtk_ui_manager_ensure_update (ev_window->priv->ui_manager);
2567 ev_window->priv->recent_ui_id = gtk_ui_manager_new_merge_id (ev_window->priv->ui_manager);
2569 if (ev_window->priv->recent_action_group) {
2570 gtk_ui_manager_remove_action_group (ev_window->priv->ui_manager,
2571 ev_window->priv->recent_action_group);
2572 g_object_unref (ev_window->priv->recent_action_group);
2574 ev_window->priv->recent_action_group = gtk_action_group_new ("RecentFilesActions");
2575 g_signal_connect (ev_window->priv->recent_action_group, "connect-proxy",
2576 G_CALLBACK (ev_window_recent_action_connect_proxy_cb), NULL);
2578 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
2579 ev_window->priv->recent_action_group, -1);
2581 items = gtk_recent_manager_get_items (ev_window->priv->recent_manager);
2582 items = g_list_sort (items, (GCompareFunc) compare_recent_items);
2584 for (l = items; l && l->data; l = g_list_next (l)) {
2585 GtkRecentInfo *info;
2589 const gchar *mime_type;
2590 gchar *content_type;
2593 info = (GtkRecentInfo *) l->data;
2595 if (!gtk_recent_info_has_application (info, evince) ||
2596 (gtk_recent_info_is_local (info) && !gtk_recent_info_exists (info)))
2599 action_name = g_strdup_printf ("RecentFile%u", i++);
2600 label = ev_window_get_recent_file_label (
2601 n_items + 1, gtk_recent_info_get_display_name (info));
2603 mime_type = gtk_recent_info_get_mime_type (info);
2604 content_type = g_content_type_from_mime_type (mime_type);
2605 if (content_type != NULL) {
2606 icon = g_content_type_get_icon (content_type);
2607 g_free (content_type);
2610 action = g_object_new (GTK_TYPE_ACTION,
2611 "name", action_name,
2614 "always-show-image", TRUE,
2617 g_object_set_data_full (G_OBJECT (action),
2619 gtk_recent_info_ref (info),
2620 (GDestroyNotify) gtk_recent_info_unref);
2622 g_signal_connect (action, "activate",
2623 G_CALLBACK (ev_window_cmd_recent_file_activate),
2624 (gpointer) ev_window);
2626 gtk_action_group_add_action (ev_window->priv->recent_action_group,
2628 g_object_unref (action);
2630 gtk_ui_manager_add_ui (ev_window->priv->ui_manager,
2631 ev_window->priv->recent_ui_id,
2632 "/MainMenu/FileMenu/RecentFilesMenu",
2635 GTK_UI_MANAGER_MENUITEM,
2637 g_free (action_name);
2640 g_object_unref (icon);
2646 g_list_foreach (items, (GFunc) gtk_recent_info_unref, NULL);
2647 g_list_free (items);
2651 show_saving_progress (GFile *dst)
2653 EvWindow *ev_window;
2657 EvSaveType save_type;
2659 ev_window = EV_WINDOW (g_object_get_data (G_OBJECT (dst), "ev-window"));
2660 ev_window->priv->progress_idle = 0;
2662 if (ev_window->priv->message_area)
2665 save_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dst), "save-type"));
2666 uri = g_file_get_uri (dst);
2667 switch (save_type) {
2668 case EV_SAVE_DOCUMENT:
2669 text = g_strdup_printf (_("Saving document to %s"), uri);
2671 case EV_SAVE_ATTACHMENT:
2672 text = g_strdup_printf (_("Saving attachment to %s"), uri);
2675 text = g_strdup_printf (_("Saving image to %s"), uri);
2678 g_assert_not_reached ();
2681 area = ev_progress_message_area_new (GTK_STOCK_SAVE,
2686 GTK_RESPONSE_CANCEL,
2688 g_signal_connect (area, "response",
2689 G_CALLBACK (ev_window_progress_response_cb),
2691 gtk_widget_show (area);
2692 ev_window_set_message_area (ev_window, area);
2699 window_save_file_copy_ready_cb (GFile *src,
2700 GAsyncResult *async_result,
2703 EvWindow *ev_window;
2704 GError *error = NULL;
2706 ev_window = EV_WINDOW (g_object_get_data (G_OBJECT (dst), "ev-window"));
2707 ev_window_clear_progress_idle (ev_window);
2709 if (g_file_copy_finish (src, async_result, &error)) {
2710 ev_tmp_file_unlink (src);
2714 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
2717 name = g_file_get_basename (dst);
2718 ev_window_error_message (ev_window, error,
2719 _("The file could not be saved as “%s”."),
2723 ev_tmp_file_unlink (src);
2724 g_error_free (error);
2728 window_save_file_copy_progress_cb (goffset n_bytes,
2729 goffset total_bytes,
2732 EvWindow *ev_window;
2733 EvSaveType save_type;
2737 ev_window = EV_WINDOW (g_object_get_data (G_OBJECT (dst), "ev-window"));
2739 if (!ev_window->priv->message_area)
2742 if (total_bytes <= 0)
2745 fraction = n_bytes / (gdouble)total_bytes;
2746 save_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dst), "save-type"));
2748 switch (save_type) {
2749 case EV_SAVE_DOCUMENT:
2750 status = g_strdup_printf (_("Uploading document (%d%%)"),
2751 (gint)(fraction * 100));
2753 case EV_SAVE_ATTACHMENT:
2754 status = g_strdup_printf (_("Uploading attachment (%d%%)"),
2755 (gint)(fraction * 100));
2758 status = g_strdup_printf (_("Uploading image (%d%%)"),
2759 (gint)(fraction * 100));
2762 g_assert_not_reached ();
2765 ev_progress_message_area_set_status (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
2767 ev_progress_message_area_set_fraction (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
2774 ev_window_save_remote (EvWindow *ev_window,
2775 EvSaveType save_type,
2779 ev_window_reset_progress_cancellable (ev_window);
2780 g_object_set_data (G_OBJECT (dst), "ev-window", ev_window);
2781 g_object_set_data (G_OBJECT (dst), "save-type", GINT_TO_POINTER (save_type));
2782 g_file_copy_async (src, dst,
2783 G_FILE_COPY_OVERWRITE,
2785 ev_window->priv->progress_cancellable,
2786 (GFileProgressCallback)window_save_file_copy_progress_cb,
2788 (GAsyncReadyCallback)window_save_file_copy_ready_cb,
2790 ev_window->priv->progress_idle =
2791 g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
2793 (GSourceFunc)show_saving_progress,
2799 ev_window_clear_save_job (EvWindow *ev_window)
2801 if (ev_window->priv->save_job != NULL) {
2802 if (!ev_job_is_finished (ev_window->priv->save_job))
2803 ev_job_cancel (ev_window->priv->save_job);
2805 g_signal_handlers_disconnect_by_func (ev_window->priv->save_job,
2806 ev_window_save_job_cb,
2808 g_object_unref (ev_window->priv->save_job);
2809 ev_window->priv->save_job = NULL;
2814 ev_window_save_job_cb (EvJob *job,
2817 if (ev_job_is_failed (job)) {
2818 ev_window_error_message (window, job->error,
2819 _("The file could not be saved as “%s”."),
2820 EV_JOB_SAVE (job)->uri);
2822 ev_window_add_recent (window, EV_JOB_SAVE (job)->uri);
2825 ev_window_clear_save_job (window);
2829 file_save_dialog_response_cb (GtkWidget *fc,
2831 EvWindow *ev_window)
2834 GFile *file, *parent;
2836 if (response_id != GTK_RESPONSE_OK) {
2837 gtk_widget_destroy (fc);
2841 uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
2842 file = g_file_new_for_uri (uri);
2843 parent = g_file_get_parent (file);
2844 g_object_unref (file);
2848 folder_uri = g_file_get_uri (parent);
2849 ev_application_set_filechooser_uri (EV_APP,
2850 GTK_FILE_CHOOSER_ACTION_SAVE,
2852 g_free (folder_uri);
2853 g_object_unref (parent);
2856 /* FIXME: remote copy should be done here rather than in the save job,
2857 * so that we can track progress and cancel the operation
2860 ev_window_clear_save_job (ev_window);
2861 ev_window->priv->save_job = ev_job_save_new (ev_window->priv->document,
2862 uri, ev_window->priv->uri);
2863 g_signal_connect (ev_window->priv->save_job, "finished",
2864 G_CALLBACK (ev_window_save_job_cb),
2866 /* The priority doesn't matter for this job */
2867 ev_job_scheduler_push_job (ev_window->priv->save_job, EV_JOB_PRIORITY_NONE);
2870 gtk_widget_destroy (fc);
2874 ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window)
2879 const gchar *default_uri;
2881 fc = gtk_file_chooser_dialog_new (
2883 GTK_WINDOW (ev_window), GTK_FILE_CHOOSER_ACTION_SAVE,
2884 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
2885 GTK_STOCK_SAVE, GTK_RESPONSE_OK,
2888 ev_document_factory_add_filters (fc, ev_window->priv->document);
2889 gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
2890 gtk_dialog_set_alternative_button_order (GTK_DIALOG (fc),
2892 GTK_RESPONSE_CANCEL,
2895 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (fc), FALSE);
2896 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
2897 file = g_file_new_for_uri (ev_window->priv->uri);
2898 base_name = g_file_get_basename (file);
2899 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc), base_name);
2901 default_uri = ev_application_get_filechooser_uri (EV_APP, GTK_FILE_CHOOSER_ACTION_SAVE);
2903 gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (fc), default_uri);
2905 const gchar *folder;
2907 folder = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
2908 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (fc),
2909 folder ? folder : g_get_home_dir ());
2912 g_object_unref (file);
2915 g_signal_connect (fc, "response",
2916 G_CALLBACK (file_save_dialog_response_cb),
2919 gtk_widget_show (fc);
2923 ev_window_cmd_open_containing_folder (GtkAction *action, EvWindow *ev_window)
2925 GtkWidget *ev_window_widget;
2929 ev_window_widget = GTK_WIDGET (ev_window);
2931 file = g_file_new_for_uri (ev_window->priv->uri);
2932 parent = g_file_get_parent (file);
2937 parent_uri = g_file_get_uri (parent);
2943 screen = gtk_widget_get_screen (ev_window_widget);
2944 timestamp = gtk_get_current_event_time ();
2947 if (!gtk_show_uri (screen, parent_uri, timestamp, &error)) {
2948 ev_window_error_message (ev_window, error, _("Could not open the containing folder"));
2949 g_error_free (error);
2952 g_free (parent_uri);
2957 g_object_unref (file);
2960 g_object_unref (parent);
2965 get_print_settings_file (void)
2967 GKeyFile *print_settings_file;
2969 GError *error = NULL;
2971 print_settings_file = g_key_file_new ();
2973 filename = g_build_filename (ev_application_get_dot_dir (EV_APP, FALSE),
2974 EV_PRINT_SETTINGS_FILE, NULL);
2975 if (!g_key_file_load_from_file (print_settings_file,
2977 G_KEY_FILE_KEEP_COMMENTS |
2978 G_KEY_FILE_KEEP_TRANSLATIONS,
2981 /* Don't warn if the file simply doesn't exist */
2982 if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
2983 g_warning ("%s", error->message);
2985 g_error_free (error);
2990 return print_settings_file;
2994 save_print_setting_file (GKeyFile *key_file)
2999 GError *error = NULL;
3001 filename = g_build_filename (ev_application_get_dot_dir (EV_APP, TRUE),
3002 EV_PRINT_SETTINGS_FILE, NULL);
3003 data = g_key_file_to_data (key_file, &data_length, NULL);
3004 g_file_set_contents (filename, data, data_length, &error);
3006 g_warning ("Failed to save print settings: %s", error->message);
3007 g_error_free (error);
3014 ev_window_save_print_settings (EvWindow *window,
3015 GtkPrintSettings *print_settings)
3020 key_file = get_print_settings_file ();
3021 gtk_print_settings_to_key_file (print_settings, key_file, EV_PRINT_SETTINGS_GROUP);
3023 /* Save print settings that are specific to the document */
3024 for (i = 0; i < G_N_ELEMENTS (document_print_settings); i++) {
3025 /* Remove it from global settings */
3026 g_key_file_remove_key (key_file, EV_PRINT_SETTINGS_GROUP,
3027 document_print_settings[i], NULL);
3029 if (window->priv->metadata) {
3032 value = gtk_print_settings_get (print_settings,
3033 document_print_settings[i]);
3034 ev_metadata_set_string (window->priv->metadata,
3035 document_print_settings[i], value);
3039 save_print_setting_file (key_file);
3040 g_key_file_free (key_file);
3044 ev_window_save_print_page_setup (EvWindow *window,
3045 GtkPageSetup *page_setup)
3049 key_file = get_print_settings_file ();
3050 gtk_page_setup_to_key_file (page_setup, key_file, EV_PAGE_SETUP_GROUP);
3052 /* Do not save document settings in global file */
3053 g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
3054 "page-setup-orientation", NULL);
3055 g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
3056 "page-setup-margin-top", NULL);
3057 g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
3058 "page-setup-margin-bottom", NULL);
3059 g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
3060 "page-setup-margin-left", NULL);
3061 g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
3062 "page-setup-margin-right", NULL);
3064 save_print_setting_file (key_file);
3065 g_key_file_free (key_file);
3067 if (!window->priv->metadata)
3070 /* Save page setup options that are specific to the document */
3071 ev_metadata_set_int (window->priv->metadata, "page-setup-orientation",
3072 gtk_page_setup_get_orientation (page_setup));
3073 ev_metadata_set_double (window->priv->metadata, "page-setup-margin-top",
3074 gtk_page_setup_get_top_margin (page_setup, GTK_UNIT_MM));
3075 ev_metadata_set_double (window->priv->metadata, "page-setup-margin-bottom",
3076 gtk_page_setup_get_bottom_margin (page_setup, GTK_UNIT_MM));
3077 ev_metadata_set_double (window->priv->metadata, "page-setup-margin-left",
3078 gtk_page_setup_get_left_margin (page_setup, GTK_UNIT_MM));
3079 ev_metadata_set_double (window->priv->metadata, "page-setup-margin-right",
3080 gtk_page_setup_get_right_margin (page_setup, GTK_UNIT_MM));
3084 ev_window_load_print_settings_from_metadata (EvWindow *window,
3085 GtkPrintSettings *print_settings)
3089 if (!window->priv->metadata)
3092 /* Load print setting that are specific to the document */
3093 for (i = 0; i < G_N_ELEMENTS (document_print_settings); i++) {
3094 gchar *value = NULL;
3096 ev_metadata_get_string (window->priv->metadata,
3097 document_print_settings[i], &value);
3098 gtk_print_settings_set (print_settings,
3099 document_print_settings[i], value);
3104 ev_window_load_print_page_setup_from_metadata (EvWindow *window,
3105 GtkPageSetup *page_setup)
3108 gdouble double_value;
3109 GtkPaperSize *paper_size = gtk_page_setup_get_paper_size (page_setup);
3111 /* Load page setup options that are specific to the document */
3112 if (window->priv->metadata &&
3113 ev_metadata_get_int (window->priv->metadata, "page-setup-orientation", &int_value)) {
3114 gtk_page_setup_set_orientation (page_setup, int_value);
3116 gtk_page_setup_set_orientation (page_setup, GTK_PAGE_ORIENTATION_PORTRAIT);
3119 if (window->priv->metadata &&
3120 ev_metadata_get_double (window->priv->metadata, "page-setup-margin-top", &double_value)) {
3121 gtk_page_setup_set_top_margin (page_setup, double_value, GTK_UNIT_MM);
3123 gtk_page_setup_set_top_margin (page_setup,
3124 gtk_paper_size_get_default_top_margin (paper_size, GTK_UNIT_MM),
3128 if (window->priv->metadata &&
3129 ev_metadata_get_double (window->priv->metadata, "page-setup-margin-bottom", &double_value)) {
3130 gtk_page_setup_set_bottom_margin (page_setup, double_value, GTK_UNIT_MM);
3132 gtk_page_setup_set_bottom_margin (page_setup,
3133 gtk_paper_size_get_default_bottom_margin (paper_size, GTK_UNIT_MM),
3137 if (window->priv->metadata &&
3138 ev_metadata_get_double (window->priv->metadata, "page-setup-margin-left", &double_value)) {
3139 gtk_page_setup_set_left_margin (page_setup, double_value, GTK_UNIT_MM);
3141 gtk_page_setup_set_left_margin (page_setup,
3142 gtk_paper_size_get_default_left_margin (paper_size, GTK_UNIT_MM),
3146 if (window->priv->metadata &&
3147 ev_metadata_get_double (window->priv->metadata, "page-setup-margin-right", &double_value)) {
3148 gtk_page_setup_set_right_margin (page_setup, double_value, GTK_UNIT_MM);
3150 gtk_page_setup_set_right_margin (page_setup,
3151 gtk_paper_size_get_default_right_margin (paper_size, GTK_UNIT_MM),
3156 static GtkPrintSettings *
3157 get_print_settings (GKeyFile *key_file)
3159 GtkPrintSettings *print_settings;
3161 print_settings = g_key_file_has_group (key_file, EV_PRINT_SETTINGS_GROUP) ?
3162 gtk_print_settings_new_from_key_file (key_file, EV_PRINT_SETTINGS_GROUP, NULL) :
3163 gtk_print_settings_new ();
3165 return print_settings ? print_settings : gtk_print_settings_new ();
3168 static GtkPageSetup *
3169 get_print_page_setup (GKeyFile *key_file)
3171 GtkPageSetup *page_setup;
3173 page_setup = g_key_file_has_group (key_file, EV_PAGE_SETUP_GROUP) ?
3174 gtk_page_setup_new_from_key_file (key_file, EV_PAGE_SETUP_GROUP, NULL) :
3175 gtk_page_setup_new ();
3177 return page_setup ? page_setup : gtk_page_setup_new ();
3181 ev_window_print_cancel (EvWindow *ev_window)
3183 EvPrintOperation *op;
3185 if (!ev_window->priv->print_queue)
3188 while ((op = g_queue_peek_tail (ev_window->priv->print_queue))) {
3189 ev_print_operation_cancel (op);
3194 ev_window_print_update_pending_jobs_message (EvWindow *ev_window,
3199 if (!EV_IS_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area) ||
3200 !ev_window->priv->print_queue)
3204 ev_window_set_message_area (ev_window, NULL);
3209 text = g_strdup_printf (ngettext ("%d pending job in queue",
3210 "%d pending jobs in queue",
3211 n_jobs - 1), n_jobs - 1);
3214 ev_message_area_set_secondary_text (EV_MESSAGE_AREA (ev_window->priv->message_area),
3220 destroy_window (GtkWidget *window)
3222 gtk_widget_destroy (window);
3228 ev_window_print_operation_done (EvPrintOperation *op,
3229 GtkPrintOperationResult result,
3230 EvWindow *ev_window)
3235 case GTK_PRINT_OPERATION_RESULT_APPLY: {
3236 GtkPrintSettings *print_settings;
3238 print_settings = ev_print_operation_get_print_settings (op);
3239 ev_window_save_print_settings (ev_window, print_settings);
3241 if (ev_print_operation_get_embed_page_setup (op)) {
3242 GtkPageSetup *page_setup;
3244 page_setup = ev_print_operation_get_default_page_setup (op);
3245 ev_window_save_print_page_setup (ev_window, page_setup);
3250 case GTK_PRINT_OPERATION_RESULT_ERROR: {
3252 GError *error = NULL;
3255 ev_print_operation_get_error (op, &error);
3257 /* The message area is already used by
3258 * the printing progress, so it's better to
3259 * use a popup dialog in this case
3261 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
3262 GTK_DIALOG_DESTROY_WITH_PARENT,
3265 "%s", _("Failed to print document"));
3266 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
3267 "%s", error->message);
3268 g_signal_connect (dialog, "response",
3269 G_CALLBACK (gtk_widget_destroy),
3271 gtk_widget_show (dialog);
3273 g_error_free (error);
3276 case GTK_PRINT_OPERATION_RESULT_CANCEL:
3281 g_queue_remove (ev_window->priv->print_queue, op);
3282 g_object_unref (op);
3283 n_jobs = g_queue_get_length (ev_window->priv->print_queue);
3284 ev_window_print_update_pending_jobs_message (ev_window, n_jobs);
3286 if (n_jobs == 0 && ev_window->priv->close_after_print)
3287 g_idle_add ((GSourceFunc)destroy_window,
3292 ev_window_print_progress_response_cb (EvProgressMessageArea *area,
3294 EvWindow *ev_window)
3296 if (response == GTK_RESPONSE_CANCEL) {
3297 EvPrintOperation *op;
3299 op = g_queue_peek_tail (ev_window->priv->print_queue);
3300 ev_print_operation_cancel (op);
3302 gtk_widget_hide (GTK_WIDGET (area));
3307 ev_window_print_operation_status_changed (EvPrintOperation *op,
3308 EvWindow *ev_window)
3310 const gchar *status;
3313 status = ev_print_operation_get_status (op);
3314 fraction = ev_print_operation_get_progress (op);
3316 if (!ev_window->priv->message_area) {
3318 const gchar *job_name;
3321 job_name = ev_print_operation_get_job_name (op);
3322 text = g_strdup_printf (_("Printing job “%s”"), job_name);
3324 area = ev_progress_message_area_new (GTK_STOCK_PRINT,
3329 GTK_RESPONSE_CANCEL,
3331 ev_window_print_update_pending_jobs_message (ev_window, 1);
3332 g_signal_connect (area, "response",
3333 G_CALLBACK (ev_window_print_progress_response_cb),
3335 gtk_widget_show (area);
3336 ev_window_set_message_area (ev_window, area);
3340 ev_progress_message_area_set_status (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
3342 ev_progress_message_area_set_fraction (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
3347 ev_window_print_operation_begin_print (EvPrintOperation *op,
3348 EvWindow *ev_window)
3350 if (!ev_window->priv->print_queue)
3351 ev_window->priv->print_queue = g_queue_new ();
3353 g_queue_push_head (ev_window->priv->print_queue, op);
3354 ev_window_print_update_pending_jobs_message (ev_window,
3355 g_queue_get_length (ev_window->priv->print_queue));
3359 ev_window_print_range (EvWindow *ev_window,
3363 EvPrintOperation *op;
3364 GKeyFile *print_settings_file;
3365 GtkPrintSettings *print_settings;
3366 GtkPageSetup *print_page_setup;
3368 gint document_last_page;
3369 gboolean embed_page_setup;
3371 g_return_if_fail (EV_IS_WINDOW (ev_window));
3372 g_return_if_fail (ev_window->priv->document != NULL);
3374 if (!ev_window->priv->print_queue)
3375 ev_window->priv->print_queue = g_queue_new ();
3377 op = ev_print_operation_new (ev_window->priv->document);
3379 g_warning ("%s", "Printing is not supported for document\n");
3383 g_signal_connect (op, "begin_print",
3384 G_CALLBACK (ev_window_print_operation_begin_print),
3385 (gpointer)ev_window);
3386 g_signal_connect (op, "status_changed",
3387 G_CALLBACK (ev_window_print_operation_status_changed),
3388 (gpointer)ev_window);
3389 g_signal_connect (op, "done",
3390 G_CALLBACK (ev_window_print_operation_done),
3391 (gpointer)ev_window);
3393 current_page = ev_document_model_get_page (ev_window->priv->model);
3394 document_last_page = ev_document_get_n_pages (ev_window->priv->document);
3396 print_settings_file = get_print_settings_file ();
3398 print_settings = get_print_settings (print_settings_file);
3399 ev_window_load_print_settings_from_metadata (ev_window, print_settings);
3401 print_page_setup = get_print_page_setup (print_settings_file);
3402 ev_window_load_print_page_setup_from_metadata (ev_window, print_page_setup);
3404 if (first_page != 1 || last_page != document_last_page) {
3407 /* Ranges in GtkPrint are 0 - N */
3408 range.start = first_page - 1;
3409 range.end = last_page - 1;
3411 gtk_print_settings_set_print_pages (print_settings,
3412 GTK_PRINT_PAGES_RANGES);
3413 gtk_print_settings_set_page_ranges (print_settings,
3417 ev_print_operation_set_job_name (op, gtk_window_get_title (GTK_WINDOW (ev_window)));
3418 ev_print_operation_set_current_page (op, current_page);
3419 ev_print_operation_set_print_settings (op, print_settings);
3420 ev_print_operation_set_default_page_setup (op, print_page_setup);
3421 embed_page_setup = ev_window->priv->lockdown_settings ?
3422 !g_settings_get_boolean (ev_window->priv->lockdown_settings,
3423 GS_LOCKDOWN_PRINT_SETUP) :
3425 ev_print_operation_set_embed_page_setup (op, embed_page_setup);
3427 g_object_unref (print_settings);
3428 g_object_unref (print_page_setup);
3429 g_key_file_free (print_settings_file);
3431 ev_print_operation_run (op, GTK_WINDOW (ev_window));
3435 ev_window_print (EvWindow *window)
3437 ev_window_print_range (window, 1,
3438 ev_document_get_n_pages (window->priv->document));
3442 ev_window_cmd_file_print (GtkAction *action, EvWindow *ev_window)
3444 ev_window_print (ev_window);
3448 ev_window_cmd_file_properties (GtkAction *action, EvWindow *ev_window)
3450 if (ev_window->priv->properties == NULL) {
3451 ev_window->priv->properties = ev_properties_dialog_new ();
3452 ev_properties_dialog_set_document (EV_PROPERTIES_DIALOG (ev_window->priv->properties),
3453 ev_window->priv->uri,
3454 ev_window->priv->document);
3455 g_object_add_weak_pointer (G_OBJECT (ev_window->priv->properties),
3456 (gpointer) &(ev_window->priv->properties));
3457 gtk_window_set_transient_for (GTK_WINDOW (ev_window->priv->properties),
3458 GTK_WINDOW (ev_window));
3461 ev_document_fc_mutex_lock ();
3462 gtk_widget_show (ev_window->priv->properties);
3463 ev_document_fc_mutex_unlock ();
3467 document_modified_confirmation_dialog_response (GtkDialog *dialog,
3469 EvWindow *ev_window)
3471 gtk_widget_destroy (GTK_WIDGET (dialog));
3474 case GTK_RESPONSE_YES:
3475 ev_window_cmd_save_as (NULL, ev_window);
3477 case GTK_RESPONSE_NO:
3478 gtk_widget_destroy (GTK_WIDGET (ev_window));
3480 case GTK_RESPONSE_CANCEL:
3487 ev_window_check_document_modified (EvWindow *ev_window)
3489 EvDocument *document = ev_window->priv->document;
3491 gchar *text, *markup;
3492 const gchar *secondary_text;
3497 if (EV_IS_DOCUMENT_FORMS (document) &&
3498 ev_document_forms_document_is_modified (EV_DOCUMENT_FORMS (document))) {
3499 secondary_text = _("Document contains form fields that have been filled out. "
3500 "If you don't save a copy, changes will be permanently lost.");
3501 } else if (EV_IS_DOCUMENT_ANNOTATIONS (document) &&
3502 ev_document_annotations_document_is_modified (EV_DOCUMENT_ANNOTATIONS (document))) {
3503 secondary_text = _("Document contains new or modified annotations. "
3504 "If you don't save a copy, changes will be permanently lost.");
3510 text = g_markup_printf_escaped (_("Save a copy of document “%s” before closing?"),
3511 gtk_window_get_title (GTK_WINDOW (ev_window)));
3513 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
3515 GTK_MESSAGE_QUESTION,
3519 markup = g_strdup_printf ("<b>%s</b>", text);
3522 gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), markup);
3525 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
3526 "%s", secondary_text);
3528 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
3529 _("Close _without Saving"),
3532 GTK_RESPONSE_CANCEL,
3536 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
3537 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
3540 GTK_RESPONSE_CANCEL,
3543 g_signal_connect (dialog, "response",
3544 G_CALLBACK (document_modified_confirmation_dialog_response),
3546 gtk_widget_show (dialog);
3552 print_jobs_confirmation_dialog_response (GtkDialog *dialog,
3554 EvWindow *ev_window)
3556 gtk_widget_destroy (GTK_WIDGET (dialog));
3559 case GTK_RESPONSE_YES:
3560 if (!ev_window->priv->print_queue ||
3561 g_queue_is_empty (ev_window->priv->print_queue))
3562 gtk_widget_destroy (GTK_WIDGET (ev_window));
3564 ev_window->priv->close_after_print = TRUE;
3566 case GTK_RESPONSE_NO:
3567 ev_window->priv->close_after_print = TRUE;
3568 if (ev_window->priv->print_queue &&
3569 !g_queue_is_empty (ev_window->priv->print_queue)) {
3570 gtk_widget_set_sensitive (GTK_WIDGET (ev_window), FALSE);
3571 ev_window_print_cancel (ev_window);
3573 gtk_widget_destroy (GTK_WIDGET (ev_window));
3576 case GTK_RESPONSE_CANCEL:
3578 ev_window->priv->close_after_print = FALSE;
3583 ev_window_check_print_queue (EvWindow *ev_window)
3586 gchar *text, *markup;
3589 n_print_jobs = ev_window->priv->print_queue ?
3590 g_queue_get_length (ev_window->priv->print_queue) : 0;
3592 if (n_print_jobs == 0)
3595 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
3597 GTK_MESSAGE_QUESTION,
3600 if (n_print_jobs == 1) {
3601 EvPrintOperation *op;
3602 const gchar *job_name;
3604 op = g_queue_peek_tail (ev_window->priv->print_queue);
3605 job_name = ev_print_operation_get_job_name (op);
3607 text = g_strdup_printf (_("Wait until print job “%s” finishes before closing?"),
3610 text = g_strdup_printf (_("There are %d print jobs active. "
3611 "Wait until print finishes before closing?"),
3615 markup = g_strdup_printf ("<b>%s</b>", text);
3618 gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), markup);
3621 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s",
3622 _("If you close the window, pending print "
3623 "jobs will not be printed."));
3625 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
3626 _("Cancel _print and Close"),
3629 GTK_RESPONSE_CANCEL,
3630 _("Close _after Printing"),
3633 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
3634 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
3637 GTK_RESPONSE_CANCEL,
3640 g_signal_connect (dialog, "response",
3641 G_CALLBACK (print_jobs_confirmation_dialog_response),
3643 gtk_widget_show (dialog);
3649 ev_window_close (EvWindow *ev_window)
3651 if (EV_WINDOW_IS_PRESENTATION (ev_window)) {
3654 /* Save current page */
3655 current_page = ev_view_presentation_get_current_page (
3656 EV_VIEW_PRESENTATION (ev_window->priv->presentation_view));
3657 ev_document_model_set_page (ev_window->priv->model, current_page);
3660 if (ev_window_check_document_modified (ev_window))
3663 if (ev_window_check_print_queue (ev_window))
3670 ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window)
3672 if (ev_window_close (ev_window))
3673 gtk_widget_destroy (GTK_WIDGET (ev_window));
3677 ev_window_cmd_focus_page_selector (GtkAction *act, EvWindow *window)
3681 update_chrome_flag (window, EV_CHROME_RAISE_TOOLBAR, TRUE);
3682 ev_window_set_action_sensitive (window, "ViewToolbar", FALSE);
3683 update_chrome_visibility (window);
3685 action = gtk_action_group_get_action (window->priv->action_group,
3686 PAGE_SELECTOR_ACTION);
3687 ev_page_action_grab_focus (EV_PAGE_ACTION (action));
3691 ev_window_cmd_scroll_forward (GtkAction *action, EvWindow *window)
3693 ev_view_scroll (EV_VIEW (window->priv->view), GTK_SCROLL_PAGE_FORWARD, FALSE);
3697 ev_window_cmd_scroll_backward (GtkAction *action, EvWindow *window)
3699 ev_view_scroll (EV_VIEW (window->priv->view), GTK_SCROLL_PAGE_BACKWARD, FALSE);
3703 ev_window_cmd_continuous (GtkAction *action, EvWindow *ev_window)
3705 gboolean continuous;
3707 ev_window_stop_presentation (ev_window, TRUE);
3708 continuous = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
3709 ev_document_model_set_continuous (ev_window->priv->model, continuous);
3713 ev_window_cmd_dual (GtkAction *action, EvWindow *ev_window)
3717 ev_window_stop_presentation (ev_window, TRUE);
3718 dual_page = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
3719 ev_document_model_set_dual_page (ev_window->priv->model, dual_page);
3723 ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window)
3725 ev_window_stop_presentation (ev_window, TRUE);
3727 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
3728 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_BEST_FIT);
3730 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FREE);
3732 ev_window_update_actions (ev_window);
3736 ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window)
3738 ev_window_stop_presentation (ev_window, TRUE);
3740 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
3741 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FIT_WIDTH);
3743 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FREE);
3745 ev_window_update_actions (ev_window);
3750 ev_window_cmd_edit_select_all (GtkAction *action, EvWindow *ev_window)
3752 g_return_if_fail (EV_IS_WINDOW (ev_window));
3754 ev_view_select_all (EV_VIEW (ev_window->priv->view));
3758 ev_window_cmd_edit_find (GtkAction *action, EvWindow *ev_window)
3760 g_return_if_fail (EV_IS_WINDOW (ev_window));
3762 if (ev_window->priv->document == NULL || !EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
3763 g_error ("Find action should be insensitive since document doesn't support find");
3767 update_chrome_flag (ev_window, EV_CHROME_FINDBAR, TRUE);
3768 update_chrome_visibility (ev_window);
3769 gtk_widget_grab_focus (ev_window->priv->find_bar);
3773 ev_window_cmd_edit_find_next (GtkAction *action, EvWindow *ev_window)
3775 g_return_if_fail (EV_IS_WINDOW (ev_window));
3777 update_chrome_flag (ev_window, EV_CHROME_FINDBAR, TRUE);
3778 update_chrome_visibility (ev_window);
3779 gtk_widget_grab_focus (ev_window->priv->find_bar);
3780 ev_view_find_next (EV_VIEW (ev_window->priv->view));
3784 ev_window_cmd_edit_find_previous (GtkAction *action, EvWindow *ev_window)
3786 g_return_if_fail (EV_IS_WINDOW (ev_window));
3788 update_chrome_flag (ev_window, EV_CHROME_FINDBAR, TRUE);
3789 update_chrome_visibility (ev_window);
3790 gtk_widget_grab_focus (ev_window->priv->find_bar);
3791 ev_view_find_previous (EV_VIEW (ev_window->priv->view));
3795 ev_window_cmd_edit_copy (GtkAction *action, EvWindow *ev_window)
3797 g_return_if_fail (EV_IS_WINDOW (ev_window));
3799 ev_view_copy (EV_VIEW (ev_window->priv->view));
3803 ev_window_sidebar_position_change_cb (GObject *object,
3805 EvWindow *ev_window)
3807 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window))
3808 ev_metadata_set_int (ev_window->priv->metadata, "sidebar_size",
3809 gtk_paned_get_position (GTK_PANED (object)));
3813 ev_window_update_fullscreen_action (EvWindow *window)
3817 action = gtk_action_group_get_action (window->priv->action_group, "ViewFullscreen");
3818 g_signal_handlers_block_by_func
3819 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
3820 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
3821 ev_document_model_get_fullscreen (window->priv->model));
3822 g_signal_handlers_unblock_by_func
3823 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
3827 fullscreen_toolbar_setup_item_properties (GtkUIManager *ui_manager)
3831 item = gtk_ui_manager_get_widget (ui_manager, "/FullscreenToolbar/GoPreviousPage");
3832 g_object_set (item, "is-important", FALSE, NULL);
3834 item = gtk_ui_manager_get_widget (ui_manager, "/FullscreenToolbar/GoNextPage");
3835 g_object_set (item, "is-important", FALSE, NULL);
3837 item = gtk_ui_manager_get_widget (ui_manager, "/FullscreenToolbar/StartPresentation");
3838 g_object_set (item, "is-important", TRUE, NULL);
3840 item = gtk_ui_manager_get_widget (ui_manager, "/FullscreenToolbar/LeaveFullscreen");
3841 g_object_set (item, "is-important", TRUE, NULL);
3845 fullscreen_toolbar_remove_shadow (GtkWidget *toolbar)
3847 static gboolean done = FALSE;
3850 gtk_rc_parse_string (
3852 " style \"fullscreen-toolbar-style\"\n"
3854 " GtkToolbar::shadow-type=GTK_SHADOW_NONE\n"
3857 " widget \"*.fullscreen-toolbar\" style \"fullscreen-toolbar-style\"\n"
3862 gtk_widget_set_name (toolbar, "fullscreen-toolbar");
3866 ev_window_run_fullscreen (EvWindow *window)
3868 gboolean fullscreen_window = TRUE;
3870 if (ev_document_model_get_fullscreen (window->priv->model))
3873 if (!window->priv->fullscreen_toolbar) {
3874 window->priv->fullscreen_toolbar =
3875 gtk_ui_manager_get_widget (window->priv->ui_manager,
3876 "/FullscreenToolbar");
3878 gtk_toolbar_set_style (GTK_TOOLBAR (window->priv->fullscreen_toolbar),
3879 GTK_TOOLBAR_BOTH_HORIZ);
3880 fullscreen_toolbar_remove_shadow (window->priv->fullscreen_toolbar);
3881 fullscreen_toolbar_setup_item_properties (window->priv->ui_manager);
3883 gtk_box_pack_start (GTK_BOX (window->priv->main_box),
3884 window->priv->fullscreen_toolbar,
3886 gtk_box_reorder_child (GTK_BOX (window->priv->main_box),
3887 window->priv->fullscreen_toolbar, 1);
3890 if (EV_WINDOW_IS_PRESENTATION (window)) {
3891 ev_window_stop_presentation (window, FALSE);
3892 fullscreen_window = FALSE;
3895 g_object_set (G_OBJECT (window->priv->scrolled_window),
3896 "shadow-type", GTK_SHADOW_NONE,
3899 ev_document_model_set_fullscreen (window->priv->model, TRUE);
3900 ev_window_update_fullscreen_action (window);
3902 /* If the user doesn't have the main toolbar he/she won't probably want
3903 * the toolbar in fullscreen mode. See bug #483048
3905 update_chrome_flag (window, EV_CHROME_FULLSCREEN_TOOLBAR,
3906 (window->priv->chrome & EV_CHROME_TOOLBAR) != 0);
3907 update_chrome_visibility (window);
3909 if (fullscreen_window)
3910 gtk_window_fullscreen (GTK_WINDOW (window));
3911 gtk_widget_grab_focus (window->priv->view);
3913 if (window->priv->metadata && !ev_window_is_empty (window))
3914 ev_metadata_set_boolean (window->priv->metadata, "fullscreen", TRUE);
3918 ev_window_stop_fullscreen (EvWindow *window,
3919 gboolean unfullscreen_window)
3921 if (!ev_document_model_get_fullscreen (window->priv->model))
3924 g_object_set (G_OBJECT (window->priv->scrolled_window),
3925 "shadow-type", GTK_SHADOW_IN,
3928 ev_document_model_set_fullscreen (window->priv->model, FALSE);
3929 ev_window_update_fullscreen_action (window);
3930 update_chrome_flag (window, EV_CHROME_FULLSCREEN_TOOLBAR, FALSE);
3931 update_chrome_visibility (window);
3932 if (unfullscreen_window)
3933 gtk_window_unfullscreen (GTK_WINDOW (window));
3935 if (window->priv->metadata && !ev_window_is_empty (window))
3936 ev_metadata_set_boolean (window->priv->metadata, "fullscreen", FALSE);
3940 ev_window_cmd_view_fullscreen (GtkAction *action, EvWindow *window)
3942 gboolean fullscreen;
3944 fullscreen = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
3946 ev_window_run_fullscreen (window);
3948 ev_window_stop_fullscreen (window, TRUE);
3953 ev_window_update_presentation_action (EvWindow *window)
3957 action = gtk_action_group_get_action (window->priv->action_group, "ViewPresentation");
3958 g_signal_handlers_block_by_func
3959 (action, G_CALLBACK (ev_window_cmd_view_presentation), window);
3960 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
3961 EV_WINDOW_IS_PRESENTATION (window));
3962 g_signal_handlers_unblock_by_func
3963 (action, G_CALLBACK (ev_window_cmd_view_presentation), window);
3967 ev_window_view_presentation_finished (EvWindow *window)
3969 ev_window_stop_presentation (window, TRUE);
3973 ev_window_run_presentation (EvWindow *window)
3975 gboolean fullscreen_window = TRUE;
3978 gboolean inverted_colors;
3980 if (EV_WINDOW_IS_PRESENTATION (window))
3983 if (ev_document_model_get_fullscreen (window->priv->model)) {
3984 ev_window_stop_fullscreen (window, FALSE);
3985 fullscreen_window = FALSE;
3988 current_page = ev_document_model_get_page (window->priv->model);
3989 rotation = ev_document_model_get_rotation (window->priv->model);
3990 inverted_colors = ev_document_model_get_inverted_colors (window->priv->model);
3991 window->priv->presentation_view = ev_view_presentation_new (window->priv->document,
3995 g_signal_connect_swapped (window->priv->presentation_view, "finished",
3996 G_CALLBACK (ev_window_view_presentation_finished),
3999 gtk_box_pack_start (GTK_BOX (window->priv->main_box),
4000 window->priv->presentation_view,
4003 gtk_widget_hide (window->priv->hpaned);
4004 ev_window_update_presentation_action (window);
4005 update_chrome_visibility (window);
4007 gtk_widget_grab_focus (window->priv->presentation_view);
4008 if (fullscreen_window)
4009 gtk_window_fullscreen (GTK_WINDOW (window));
4011 gtk_widget_show (window->priv->presentation_view);
4013 ev_application_screensaver_disable (EV_APP);
4015 if (window->priv->metadata && !ev_window_is_empty (window))
4016 ev_metadata_set_boolean (window->priv->metadata, "presentation", TRUE);
4020 ev_window_stop_presentation (EvWindow *window,
4021 gboolean unfullscreen_window)
4025 if (!EV_WINDOW_IS_PRESENTATION (window))
4028 current_page = ev_view_presentation_get_current_page (EV_VIEW_PRESENTATION (window->priv->presentation_view));
4029 ev_document_model_set_page (window->priv->model, current_page);
4031 gtk_container_remove (GTK_CONTAINER (window->priv->main_box),
4032 window->priv->presentation_view);
4033 window->priv->presentation_view = NULL;
4035 gtk_widget_show (window->priv->hpaned);
4036 ev_window_update_presentation_action (window);
4037 update_chrome_visibility (window);
4038 if (unfullscreen_window)
4039 gtk_window_unfullscreen (GTK_WINDOW (window));
4041 gtk_widget_grab_focus (window->priv->view);
4043 ev_application_screensaver_enable (EV_APP);
4045 if (window->priv->metadata && !ev_window_is_empty (window))
4046 ev_metadata_set_boolean (window->priv->metadata, "presentation", FALSE);
4050 ev_window_cmd_view_presentation (GtkAction *action, EvWindow *window)
4052 gboolean presentation;
4054 presentation = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
4056 ev_window_run_presentation (window);
4061 ev_window_setup_gtk_settings (EvWindow *window)
4063 GtkSettings *settings;
4065 gchar *menubar_accel_accel;
4067 screen = gtk_window_get_screen (GTK_WINDOW (window));
4068 settings = gtk_settings_get_for_screen (screen);
4070 g_object_get (settings,
4071 "gtk-menu-bar-accel", &menubar_accel_accel,
4073 if (menubar_accel_accel != NULL && menubar_accel_accel[0] != '\0') {
4074 gtk_accelerator_parse (menubar_accel_accel,
4075 &window->priv->menubar_accel_keyval,
4076 &window->priv->menubar_accel_modifier);
4077 if (window->priv->menubar_accel_keyval == 0) {
4078 g_warning ("Failed to parse menu bar accelerator '%s'\n",
4079 menubar_accel_accel);
4082 window->priv->menubar_accel_keyval = 0;
4083 window->priv->menubar_accel_modifier = 0;
4086 g_free (menubar_accel_accel);
4090 ev_window_update_max_min_scale (EvWindow *window)
4094 gdouble min_width, min_height;
4095 gdouble width, height;
4097 gint rotation = ev_document_model_get_rotation (window->priv->model);
4099 if (!window->priv->document)
4102 dpi = get_screen_dpi (window) / 72.0;
4104 ev_document_get_min_page_size (window->priv->document, &min_width, &min_height);
4105 width = (rotation == 0 || rotation == 180) ? min_width : min_height;
4106 height = (rotation == 0 || rotation == 180) ? min_height : min_width;
4107 max_scale = sqrt (PAGE_CACHE_SIZE / (width * dpi * 4 * height * dpi));
4109 action = gtk_action_group_get_action (window->priv->action_group,
4110 ZOOM_CONTROL_ACTION);
4111 ephy_zoom_action_set_max_zoom_level (EPHY_ZOOM_ACTION (action), max_scale * dpi);
4113 ev_document_model_set_min_scale (window->priv->model, MIN_SCALE * dpi);
4114 ev_document_model_set_max_scale (window->priv->model, max_scale * dpi);
4118 ev_window_screen_changed (GtkWidget *widget,
4119 GdkScreen *old_screen)
4121 EvWindow *window = EV_WINDOW (widget);
4124 screen = gtk_widget_get_screen (widget);
4125 if (screen == old_screen)
4128 ev_window_setup_gtk_settings (window);
4129 ev_window_update_max_min_scale (window);
4131 if (GTK_WIDGET_CLASS (ev_window_parent_class)->screen_changed) {
4132 GTK_WIDGET_CLASS (ev_window_parent_class)->screen_changed (widget, old_screen);
4137 ev_window_state_event (GtkWidget *widget,
4138 GdkEventWindowState *event)
4140 EvWindow *window = EV_WINDOW (widget);
4142 if (GTK_WIDGET_CLASS (ev_window_parent_class)->window_state_event) {
4143 GTK_WIDGET_CLASS (ev_window_parent_class)->window_state_event (widget, event);
4146 if ((event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN) == 0)
4149 if (event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN) {
4150 if (ev_document_model_get_fullscreen (window->priv->model) || EV_WINDOW_IS_PRESENTATION (window))
4153 ev_window_run_fullscreen (window);
4155 if (ev_document_model_get_fullscreen (window->priv->model))
4156 ev_window_stop_fullscreen (window, FALSE);
4157 else if (EV_WINDOW_IS_PRESENTATION (window))
4158 ev_window_stop_presentation (window, FALSE);
4165 ev_window_set_page_mode (EvWindow *window,
4166 EvWindowPageMode page_mode)
4168 GtkWidget *child = NULL;
4169 GtkWidget *real_child;
4171 if (window->priv->page_mode == page_mode)
4174 window->priv->page_mode = page_mode;
4176 switch (page_mode) {
4177 case PAGE_MODE_DOCUMENT:
4178 child = window->priv->view;
4180 case PAGE_MODE_PASSWORD:
4181 child = window->priv->password_view;
4184 g_assert_not_reached ();
4187 real_child = gtk_bin_get_child (GTK_BIN (window->priv->scrolled_window));
4188 if (child != real_child) {
4189 gtk_container_remove (GTK_CONTAINER (window->priv->scrolled_window),
4191 gtk_container_add (GTK_CONTAINER (window->priv->scrolled_window),
4194 ev_window_update_actions (window);
4199 ev_window_cmd_edit_rotate_left (GtkAction *action, EvWindow *ev_window)
4201 gint rotation = ev_document_model_get_rotation (ev_window->priv->model);
4203 ev_document_model_set_rotation (ev_window->priv->model, rotation - 90);
4207 ev_window_cmd_edit_rotate_right (GtkAction *action, EvWindow *ev_window)
4209 gint rotation = ev_document_model_get_rotation (ev_window->priv->model);
4211 ev_document_model_set_rotation (ev_window->priv->model, rotation + 90);
4215 ev_window_cmd_view_inverted_colors (GtkAction *action, EvWindow *ev_window)
4217 gboolean inverted_colors = ev_document_model_get_inverted_colors (ev_window->priv->model);
4219 ev_document_model_set_inverted_colors (ev_window->priv->model, !inverted_colors);
4223 ev_window_cmd_edit_toolbar_cb (GtkDialog *dialog,
4225 EvWindow *ev_window)
4227 EggEditableToolbar *toolbar;
4228 gchar *toolbars_file;
4230 toolbar = EGG_EDITABLE_TOOLBAR (ev_window->priv->toolbar);
4231 egg_editable_toolbar_set_edit_mode (toolbar, FALSE);
4233 toolbars_file = g_build_filename (ev_application_get_dot_dir (EV_APP, TRUE),
4234 "evince_toolbar.xml", NULL);
4235 egg_toolbars_model_save_toolbars (egg_editable_toolbar_get_model (toolbar),
4236 toolbars_file, "1.0");
4237 g_free (toolbars_file);
4239 gtk_widget_destroy (GTK_WIDGET (dialog));
4243 ev_window_cmd_edit_toolbar (GtkAction *action, EvWindow *ev_window)
4247 GtkWidget *content_area;
4248 EggEditableToolbar *toolbar;
4250 dialog = gtk_dialog_new_with_buttons (_("Toolbar Editor"),
4251 GTK_WINDOW (ev_window),
4252 GTK_DIALOG_DESTROY_WITH_PARENT,
4256 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
4257 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE);
4258 gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)), 5);
4259 gtk_box_set_spacing (GTK_BOX (content_area), 2);
4260 gtk_window_set_default_size (GTK_WINDOW (dialog), 500, 400);
4262 toolbar = EGG_EDITABLE_TOOLBAR (ev_window->priv->toolbar);
4263 editor = egg_toolbar_editor_new (ev_window->priv->ui_manager,
4264 egg_editable_toolbar_get_model (toolbar));
4266 gtk_container_set_border_width (GTK_CONTAINER (editor), 5);
4267 gtk_box_set_spacing (GTK_BOX (EGG_TOOLBAR_EDITOR (editor)), 5);
4269 gtk_container_add (GTK_CONTAINER (content_area), editor);
4271 egg_editable_toolbar_set_edit_mode (toolbar, TRUE);
4273 g_signal_connect (dialog, "response",
4274 G_CALLBACK (ev_window_cmd_edit_toolbar_cb),
4276 gtk_widget_show_all (dialog);
4280 ev_window_cmd_edit_save_settings (GtkAction *action, EvWindow *ev_window)
4282 EvWindowPrivate *priv = ev_window->priv;
4283 EvDocumentModel *model = priv->model;
4284 GSettings *settings = priv->default_settings;
4286 g_settings_set_boolean (settings, "continuous",
4287 ev_document_model_get_continuous (model));
4288 g_settings_set_boolean (settings, "dual-page",
4289 ev_document_model_get_dual_page (model));
4290 g_settings_set_boolean (settings, "fullscreen",
4291 ev_document_model_get_fullscreen (model));
4292 g_settings_set_boolean (settings, "inverted-colors",
4293 ev_document_model_get_inverted_colors (model));
4294 g_settings_set_enum (settings, "sizing-mode",
4295 ev_document_model_get_sizing_mode (model));
4296 g_settings_set_boolean (settings, "show-toolbar",
4297 gtk_widget_get_visible (priv->toolbar));
4298 g_settings_set_boolean (settings, "show-sidebar",
4299 gtk_widget_get_visible (priv->sidebar));
4300 g_settings_set_int (settings, "sidebar-size",
4301 gtk_paned_get_position (GTK_PANED (priv->hpaned)));
4302 g_settings_set_string (settings, "sidebar-page",
4303 ev_window_sidebar_get_current_page_id (ev_window));
4304 g_settings_apply (settings);
4308 ev_window_cmd_view_zoom_in (GtkAction *action, EvWindow *ev_window)
4310 g_return_if_fail (EV_IS_WINDOW (ev_window));
4312 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FREE);
4313 ev_view_zoom_in (EV_VIEW (ev_window->priv->view));
4317 ev_window_cmd_view_zoom_out (GtkAction *action, EvWindow *ev_window)
4319 g_return_if_fail (EV_IS_WINDOW (ev_window));
4321 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FREE);
4322 ev_view_zoom_out (EV_VIEW (ev_window->priv->view));
4326 ev_window_cmd_go_previous_page (GtkAction *action, EvWindow *ev_window)
4328 g_return_if_fail (EV_IS_WINDOW (ev_window));
4330 ev_view_previous_page (EV_VIEW (ev_window->priv->view));
4334 ev_window_cmd_go_next_page (GtkAction *action, EvWindow *ev_window)
4336 g_return_if_fail (EV_IS_WINDOW (ev_window));
4338 ev_view_next_page (EV_VIEW (ev_window->priv->view));
4342 ev_window_cmd_go_first_page (GtkAction *action, EvWindow *ev_window)
4344 g_return_if_fail (EV_IS_WINDOW (ev_window));
4346 ev_document_model_set_page (ev_window->priv->model, 0);
4350 ev_window_cmd_go_last_page (GtkAction *action, EvWindow *ev_window)
4352 g_return_if_fail (EV_IS_WINDOW (ev_window));
4354 ev_document_model_set_page (ev_window->priv->model,
4355 ev_document_get_n_pages (ev_window->priv->document) - 1);
4359 ev_window_cmd_go_forward (GtkAction *action, EvWindow *ev_window)
4361 int n_pages, current_page;
4363 g_return_if_fail (EV_IS_WINDOW (ev_window));
4365 n_pages = ev_document_get_n_pages (ev_window->priv->document);
4366 current_page = ev_document_model_get_page (ev_window->priv->model);
4368 if (current_page + 10 < n_pages) {
4369 ev_document_model_set_page (ev_window->priv->model, current_page + 10);
4374 ev_window_cmd_go_backward (GtkAction *action, EvWindow *ev_window)
4378 g_return_if_fail (EV_IS_WINDOW (ev_window));
4380 current_page = ev_document_model_get_page (ev_window->priv->model);
4382 if (current_page - 10 >= 0) {
4383 ev_document_model_set_page (ev_window->priv->model, current_page - 10);
4388 ev_window_cmd_bookmark_activate (GtkAction *action,
4391 guint page = ev_bookmark_action_get_page (EV_BOOKMARK_ACTION (action));
4393 ev_document_model_set_page (window->priv->model, page);
4397 compare_bookmarks (EvBookmark *a,
4400 return strcmp (a->title, b->title);
4404 ev_window_setup_bookmarks (EvWindow *window)
4408 if (!window->priv->bookmarks)
4411 if (window->priv->bookmarks_ui_id > 0) {
4412 gtk_ui_manager_remove_ui (window->priv->ui_manager,
4413 window->priv->bookmarks_ui_id);
4414 gtk_ui_manager_ensure_update (window->priv->ui_manager);
4416 window->priv->bookmarks_ui_id = gtk_ui_manager_new_merge_id (window->priv->ui_manager);
4418 if (window->priv->bookmarks_action_group) {
4419 gtk_ui_manager_remove_action_group (window->priv->ui_manager,
4420 window->priv->bookmarks_action_group);
4421 g_object_unref (window->priv->bookmarks_action_group);
4423 window->priv->bookmarks_action_group = gtk_action_group_new ("BookmarksActions");
4424 gtk_ui_manager_insert_action_group (window->priv->ui_manager,
4425 window->priv->bookmarks_action_group, -1);
4427 items = ev_bookmarks_get_bookmarks (window->priv->bookmarks);
4428 items = g_list_sort (items, (GCompareFunc)compare_bookmarks);
4430 for (l = items; l && l->data; l = g_list_next (l)) {
4431 EvBookmark *bm = (EvBookmark *)l->data;
4434 action = ev_bookmark_action_new (bm);
4435 g_signal_connect (action, "activate",
4436 G_CALLBACK (ev_window_cmd_bookmark_activate),
4438 gtk_action_group_add_action (window->priv->bookmarks_action_group,
4441 gtk_ui_manager_add_ui (window->priv->ui_manager,
4442 window->priv->bookmarks_ui_id,
4443 "/MainMenu/BookmarksMenu/BookmarksItems",
4444 gtk_action_get_label (action),
4445 gtk_action_get_name (action),
4446 GTK_UI_MANAGER_MENUITEM,
4449 g_object_unref (action);
4452 g_list_free (items);
4456 ev_window_cmd_bookmarks_add (GtkAction *action,
4463 bm.page = ev_document_model_get_page (window->priv->model);
4464 page_label = ev_document_get_page_label (window->priv->document, bm.page);
4465 page_title = ev_window_get_page_title (window, page_label);
4466 bm.title = page_title ? page_title : g_strdup_printf (_("Page %s"), page_label);
4467 g_free (page_label);
4469 /* EvBookmarks takes ownership of bookmark */
4470 ev_bookmarks_add (window->priv->bookmarks, &bm);
4474 ev_window_cmd_view_reload (GtkAction *action, EvWindow *ev_window)
4476 ev_window_reload_document (ev_window, NULL);
4480 ev_window_cmd_view_autoscroll (GtkAction *action, EvWindow *ev_window)
4482 ev_view_autoscroll_start (EV_VIEW (ev_window->priv->view));
4485 #if OFFLINE_HELP_ENABLED
4486 #define EV_HELP "ghelp:evince"
4488 #define EV_HELP "http://library.gnome.org/users/evince/stable/"
4492 ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
4494 GError *error = NULL;
4496 gtk_show_uri (gtk_window_get_screen (GTK_WINDOW (ev_window)),
4498 gtk_get_current_event_time (),
4501 ev_window_error_message (ev_window, error,
4502 "%s", _("There was an error displaying help"));
4503 g_error_free (error);
4508 ev_window_cmd_leave_fullscreen (GtkAction *action, EvWindow *window)
4510 ev_window_stop_fullscreen (window, TRUE);
4514 ev_window_cmd_start_presentation (GtkAction *action, EvWindow *window)
4516 ev_window_run_presentation (window);
4520 ev_window_cmd_escape (GtkAction *action, EvWindow *window)
4524 ev_view_autoscroll_stop (EV_VIEW (window->priv->view));
4526 widget = gtk_window_get_focus (GTK_WINDOW (window));
4527 if (widget && gtk_widget_get_ancestor (widget, EGG_TYPE_FIND_BAR)) {
4528 update_chrome_flag (window, EV_CHROME_FINDBAR, FALSE);
4529 update_chrome_visibility (window);
4530 gtk_widget_grab_focus (window->priv->view);
4532 gboolean fullscreen;
4534 fullscreen = ev_document_model_get_fullscreen (window->priv->model);
4537 ev_window_stop_fullscreen (window, TRUE);
4538 } else if (EV_WINDOW_IS_PRESENTATION (window)) {
4539 ev_window_stop_presentation (window, TRUE);
4540 gtk_widget_grab_focus (window->priv->view);
4542 gtk_widget_grab_focus (window->priv->view);
4545 if (fullscreen && EV_WINDOW_IS_PRESENTATION (window))
4546 g_warning ("Both fullscreen and presentation set somehow");
4551 save_sizing_mode (EvWindow *window)
4554 GEnumValue *enum_value;
4556 if (!window->priv->metadata || ev_window_is_empty (window))
4559 mode = ev_document_model_get_sizing_mode (window->priv->model);
4560 enum_value = g_enum_get_value (g_type_class_peek (EV_TYPE_SIZING_MODE), mode);
4561 ev_metadata_set_string (window->priv->metadata, "sizing_mode",
4562 enum_value->value_nick);
4566 ev_window_document_changed_cb (EvDocumentModel *model,
4568 EvWindow *ev_window)
4570 ev_window_set_document (ev_window,
4571 ev_document_model_get_document (model));
4575 ev_window_sizing_mode_changed_cb (EvDocumentModel *model,
4577 EvWindow *ev_window)
4579 EvSizingMode sizing_mode = ev_document_model_get_sizing_mode (model);
4581 g_object_set (ev_window->priv->scrolled_window,
4582 "hscrollbar-policy",
4583 sizing_mode == EV_SIZING_FREE ?
4584 GTK_POLICY_AUTOMATIC : GTK_POLICY_NEVER,
4585 "vscrollbar-policy", GTK_POLICY_AUTOMATIC,
4588 update_sizing_buttons (ev_window);
4589 save_sizing_mode (ev_window);
4593 ev_window_zoom_changed_cb (EvDocumentModel *model, GParamSpec *pspec, EvWindow *ev_window)
4595 ev_window_update_actions (ev_window);
4597 if (!ev_window->priv->metadata)
4600 if (ev_document_model_get_sizing_mode (model) == EV_SIZING_FREE && !ev_window_is_empty (ev_window)) {
4603 zoom = ev_document_model_get_scale (model);
4604 zoom *= 72.0 / get_screen_dpi (ev_window);
4605 ev_metadata_set_double (ev_window->priv->metadata, "zoom", zoom);
4610 ev_window_update_continuous_action (EvWindow *window)
4614 action = gtk_action_group_get_action (window->priv->action_group, "ViewContinuous");
4615 g_signal_handlers_block_by_func
4616 (action, G_CALLBACK (ev_window_cmd_continuous), window);
4617 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
4618 ev_document_model_get_continuous (window->priv->model));
4619 g_signal_handlers_unblock_by_func
4620 (action, G_CALLBACK (ev_window_cmd_continuous), window);
4624 ev_window_update_dual_page_action (EvWindow *window)
4628 action = gtk_action_group_get_action (window->priv->action_group, "ViewDual");
4629 g_signal_handlers_block_by_func
4630 (action, G_CALLBACK (ev_window_cmd_dual), window);
4631 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
4632 ev_document_model_get_dual_page (window->priv->model));
4633 g_signal_handlers_unblock_by_func
4634 (action, G_CALLBACK (ev_window_cmd_dual), window);
4638 ev_window_continuous_changed_cb (EvDocumentModel *model,
4640 EvWindow *ev_window)
4642 ev_window_update_continuous_action (ev_window);
4644 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window))
4645 ev_metadata_set_boolean (ev_window->priv->metadata, "continuous",
4646 ev_document_model_get_continuous (model));
4650 ev_window_rotation_changed_cb (EvDocumentModel *model,
4654 gint rotation = ev_document_model_get_rotation (model);
4656 if (window->priv->metadata && !ev_window_is_empty (window))
4657 ev_metadata_set_int (window->priv->metadata, "rotation",
4660 ev_window_update_max_min_scale (window);
4661 ev_window_refresh_window_thumbnail (window);
4665 ev_window_update_inverted_colors_action (EvWindow *window)
4669 action = gtk_action_group_get_action (window->priv->action_group, "ViewInvertedColors");
4670 g_signal_handlers_block_by_func
4671 (action, G_CALLBACK (ev_window_cmd_view_inverted_colors), window);
4672 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
4673 ev_document_model_get_inverted_colors (window->priv->model));
4674 g_signal_handlers_unblock_by_func
4675 (action, G_CALLBACK (ev_window_cmd_view_inverted_colors), window);
4679 ev_window_inverted_colors_changed_cb (EvDocumentModel *model,
4683 gboolean inverted_colors = ev_document_model_get_inverted_colors (model);
4685 ev_window_update_inverted_colors_action (window);
4687 if (window->priv->metadata && !ev_window_is_empty (window))
4688 ev_metadata_set_boolean (window->priv->metadata, "inverted-colors",
4691 ev_window_refresh_window_thumbnail (window);
4695 ev_window_dual_mode_changed_cb (EvDocumentModel *model,
4697 EvWindow *ev_window)
4699 ev_window_update_dual_page_action (ev_window);
4701 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window))
4702 ev_metadata_set_boolean (ev_window->priv->metadata, "dual-page",
4703 ev_document_model_get_dual_page (model));
4707 build_comments_string (EvDocument *document)
4709 gchar *comments = NULL;
4710 EvDocumentBackendInfo info;
4712 if (document && ev_document_get_backend_info (document, &info)) {
4713 comments = g_strdup_printf (
4714 _("Document Viewer\nUsing %s (%s)"),
4715 info.name, info.version);
4717 comments = g_strdup_printf (
4718 _("Document Viewer"));
4725 ev_window_cmd_help_about (GtkAction *action, EvWindow *ev_window)
4727 const char *authors[] = {
4728 "Martin Kretzschmar <m_kretzschmar@gmx.net>",
4729 "Jonathan Blandford <jrb@gnome.org>",
4730 "Marco Pesenti Gritti <marco@gnome.org>",
4731 "Nickolay V. Shmyrev <nshmyrev@yandex.ru>",
4732 "Bryan Clark <clarkbw@gnome.org>",
4733 "Carlos Garcia Campos <carlosgc@gnome.org>",
4734 "Wouter Bolsterlee <wbolster@gnome.org>",
4735 "Christian Persch <chpe" "\100" "gnome.org>",
4739 const char *documenters[] = {
4740 "Nickolay V. Shmyrev <nshmyrev@yandex.ru>",
4744 const char *license[] = {
4745 N_("Evince is free software; you can redistribute it and/or modify "
4746 "it under the terms of the GNU General Public License as published by "
4747 "the Free Software Foundation; either version 2 of the License, or "
4748 "(at your option) any later version.\n"),
4749 N_("Evince is distributed in the hope that it will be useful, "
4750 "but WITHOUT ANY WARRANTY; without even the implied warranty of "
4751 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
4752 "GNU General Public License for more details.\n"),
4753 N_("You should have received a copy of the GNU General Public License "
4754 "along with Evince; if not, write to the Free Software Foundation, Inc., "
4755 "51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n")
4758 char *license_trans;
4764 for (p = authors; *p; ++p)
4767 for (p = documenters; *p; ++p)
4771 license_trans = g_strconcat (_(license[0]), "\n", _(license[1]), "\n",
4772 _(license[2]), "\n", NULL);
4774 comments = build_comments_string (ev_window->priv->document);
4776 gtk_show_about_dialog (
4777 GTK_WINDOW (ev_window),
4778 "name", _("Evince"),
4781 _("© 1996–2010 The Evince authors"),
4782 "license", license_trans,
4783 "website", "http://www.gnome.org/projects/evince",
4784 "comments", comments,
4786 "documenters", documenters,
4787 "translator-credits", _("translator-credits"),
4788 "logo-icon-name", "evince",
4789 "wrap-license", TRUE,
4793 g_free (license_trans);
4797 ev_window_view_toolbar_cb (GtkAction *action, EvWindow *ev_window)
4801 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
4802 update_chrome_flag (ev_window, EV_CHROME_TOOLBAR, active);
4803 update_chrome_visibility (ev_window);
4804 if (ev_window->priv->metadata)
4805 ev_metadata_set_boolean (ev_window->priv->metadata, "show_toolbar", active);
4809 ev_window_view_sidebar_cb (GtkAction *action, EvWindow *ev_window)
4811 if (EV_WINDOW_IS_PRESENTATION (ev_window))
4814 update_chrome_flag (ev_window, EV_CHROME_SIDEBAR,
4815 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
4816 update_chrome_visibility (ev_window);
4820 ev_window_sidebar_current_page_changed_cb (EvSidebar *ev_sidebar,
4822 EvWindow *ev_window)
4824 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window)) {
4825 ev_metadata_set_string (ev_window->priv->metadata,
4827 ev_window_sidebar_get_current_page_id (ev_window));
4832 ev_window_sidebar_visibility_changed_cb (EvSidebar *ev_sidebar,
4834 EvWindow *ev_window)
4838 action = gtk_action_group_get_action (ev_window->priv->action_group, "ViewSidebar");
4840 if (!EV_WINDOW_IS_PRESENTATION (ev_window)) {
4841 gboolean visible = gtk_widget_get_visible (GTK_WIDGET (ev_sidebar));
4843 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible);
4845 if (ev_window->priv->metadata)
4846 ev_metadata_set_boolean (ev_window->priv->metadata, "sidebar_visibility",
4852 view_menu_link_popup (EvWindow *ev_window,
4855 gboolean show_external = FALSE;
4856 gboolean show_internal = FALSE;
4859 if (ev_window->priv->link)
4860 g_object_unref (ev_window->priv->link);
4863 ev_window->priv->link = g_object_ref (link);
4865 ev_window->priv->link = NULL;
4867 if (ev_window->priv->link) {
4868 EvLinkAction *ev_action;
4870 ev_action = ev_link_get_action (link);
4872 switch (ev_link_action_get_action_type (ev_action)) {
4873 case EV_LINK_ACTION_TYPE_GOTO_DEST:
4874 case EV_LINK_ACTION_TYPE_GOTO_REMOTE:
4875 show_internal = TRUE;
4877 case EV_LINK_ACTION_TYPE_EXTERNAL_URI:
4878 case EV_LINK_ACTION_TYPE_LAUNCH:
4879 show_external = TRUE;
4887 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4889 gtk_action_set_visible (action, show_external);
4891 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4893 gtk_action_set_visible (action, show_external);
4895 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4897 gtk_action_set_visible (action, show_internal);
4899 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4900 "OpenLinkNewWindow");
4901 gtk_action_set_visible (action, show_internal);
4905 view_menu_image_popup (EvWindow *ev_window,
4909 gboolean show_image = FALSE;
4911 if (ev_window->priv->image)
4912 g_object_unref (ev_window->priv->image);
4915 ev_window->priv->image = g_object_ref (image);
4917 ev_window->priv->image = NULL;
4919 show_image = (ev_window->priv->image != NULL);
4921 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4923 gtk_action_set_visible (action, show_image);
4925 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4927 gtk_action_set_visible (action, show_image);
4931 view_menu_annot_popup (EvWindow *ev_window,
4932 EvAnnotation *annot)
4935 gboolean show_annot = FALSE;
4937 if (ev_window->priv->annot)
4938 g_object_unref (ev_window->priv->annot);
4939 ev_window->priv->annot = (annot) ? g_object_ref (annot) : NULL;
4941 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4943 gtk_action_set_visible (action, (annot != NULL && EV_IS_ANNOTATION_MARKUP (annot)));
4945 if (annot && EV_IS_ANNOTATION_ATTACHMENT (annot)) {
4946 EvAttachment *attachment;
4948 attachment = ev_annotation_attachment_get_attachment (EV_ANNOTATION_ATTACHMENT (annot));
4951 if (ev_window->priv->attach_list) {
4952 g_list_foreach (ev_window->priv->attach_list,
4953 (GFunc) g_object_unref, NULL);
4954 g_list_free (ev_window->priv->attach_list);
4955 ev_window->priv->attach_list = NULL;
4957 ev_window->priv->attach_list =
4958 g_list_prepend (ev_window->priv->attach_list,
4959 g_object_ref (attachment));
4963 action = gtk_action_group_get_action (ev_window->priv->attachment_popup_action_group,
4965 gtk_action_set_visible (action, show_annot);
4967 action = gtk_action_group_get_action (ev_window->priv->attachment_popup_action_group,
4968 "SaveAttachmentAs");
4969 gtk_action_set_visible (action, show_annot);
4973 view_menu_popup_cb (EvView *view,
4975 EvWindow *ev_window)
4978 gboolean has_link = FALSE;
4979 gboolean has_image = FALSE;
4980 gboolean has_annot = FALSE;
4982 for (l = items; l; l = g_list_next (l)) {
4983 if (EV_IS_LINK (l->data)) {
4984 view_menu_link_popup (ev_window, EV_LINK (l->data));
4986 } else if (EV_IS_IMAGE (l->data)) {
4987 view_menu_image_popup (ev_window, EV_IMAGE (l->data));
4989 } else if (EV_IS_ANNOTATION (l->data)) {
4990 view_menu_annot_popup (ev_window, EV_ANNOTATION (l->data));
4996 view_menu_link_popup (ev_window, NULL);
4998 view_menu_image_popup (ev_window, NULL);
5000 view_menu_annot_popup (ev_window, NULL);
5002 gtk_menu_popup (GTK_MENU (ev_window->priv->view_popup),
5003 NULL, NULL, NULL, NULL,
5004 3, gtk_get_current_event_time ());
5009 attachment_bar_menu_popup_cb (EvSidebarAttachments *attachbar,
5011 EvWindow *ev_window)
5015 g_assert (attach_list != NULL);
5017 if (ev_window->priv->attach_list) {
5018 g_list_foreach (ev_window->priv->attach_list,
5019 (GFunc) g_object_unref, NULL);
5020 g_list_free (ev_window->priv->attach_list);
5023 ev_window->priv->attach_list = attach_list;
5025 popup = ev_window->priv->attachment_popup;
5027 gtk_menu_popup (GTK_MENU (popup), NULL, NULL,
5029 3, gtk_get_current_event_time ());
5035 ev_window_update_find_status_message (EvWindow *ev_window)
5039 if (!ev_window->priv->find_job)
5042 if (ev_job_is_finished (ev_window->priv->find_job)) {
5043 EvJobFind *job_find = EV_JOB_FIND (ev_window->priv->find_job);
5045 if (ev_job_find_has_results (job_find)) {
5048 n_results = ev_job_find_get_n_results (job_find,
5049 ev_document_model_get_page (ev_window->priv->model));
5050 /* TRANS: Sometimes this could be better translated as
5051 "%d hit(s) on this page". Therefore this string
5052 contains plural cases. */
5053 message = g_strdup_printf (ngettext ("%d found on this page",
5054 "%d found on this page",
5058 message = g_strdup (_("Not found"));
5063 percent = ev_job_find_get_progress (EV_JOB_FIND (ev_window->priv->find_job));
5064 message = g_strdup_printf (_("%3d%% remaining to search"),
5065 (gint) ((1.0 - percent) * 100));
5068 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar), message);
5073 ev_window_find_job_finished_cb (EvJobFind *job,
5074 EvWindow *ev_window)
5076 ev_window_update_find_status_message (ev_window);
5080 ev_window_find_job_updated_cb (EvJobFind *job,
5082 EvWindow *ev_window)
5084 ev_window_update_actions (ev_window);
5086 ev_view_find_changed (EV_VIEW (ev_window->priv->view),
5087 ev_job_find_get_results (job),
5089 ev_window_update_find_status_message (ev_window);
5093 ev_window_clear_find_job (EvWindow *ev_window)
5095 if (ev_window->priv->find_job != NULL) {
5096 if (!ev_job_is_finished (ev_window->priv->find_job))
5097 ev_job_cancel (ev_window->priv->find_job);
5099 g_signal_handlers_disconnect_by_func (ev_window->priv->find_job,
5100 ev_window_find_job_finished_cb,
5102 g_signal_handlers_disconnect_by_func (ev_window->priv->find_job,
5103 ev_window_find_job_updated_cb,
5105 g_object_unref (ev_window->priv->find_job);
5106 ev_window->priv->find_job = NULL;
5111 find_bar_previous_cb (EggFindBar *find_bar,
5112 EvWindow *ev_window)
5114 ev_view_find_previous (EV_VIEW (ev_window->priv->view));
5118 find_bar_next_cb (EggFindBar *find_bar,
5119 EvWindow *ev_window)
5121 ev_view_find_next (EV_VIEW (ev_window->priv->view));
5125 find_bar_close_cb (EggFindBar *find_bar,
5126 EvWindow *ev_window)
5128 ev_view_find_cancel (EV_VIEW (ev_window->priv->view));
5129 ev_window_clear_find_job (ev_window);
5130 update_chrome_flag (ev_window, EV_CHROME_FINDBAR, FALSE);
5131 update_chrome_visibility (ev_window);
5135 find_bar_search_changed_cb (EggFindBar *find_bar,
5137 EvWindow *ev_window)
5139 gboolean case_sensitive;
5140 const char *search_string;
5142 if (!ev_window->priv->document || !EV_IS_DOCUMENT_FIND (ev_window->priv->document))
5145 /* Either the string or case sensitivity could have changed. */
5146 case_sensitive = egg_find_bar_get_case_sensitive (find_bar);
5147 search_string = egg_find_bar_get_search_string (find_bar);
5149 ev_view_find_search_changed (EV_VIEW (ev_window->priv->view));
5151 ev_window_clear_find_job (ev_window);
5153 if (search_string && search_string[0]) {
5154 ev_window->priv->find_job = ev_job_find_new (ev_window->priv->document,
5155 ev_document_model_get_page (ev_window->priv->model),
5156 ev_document_get_n_pages (ev_window->priv->document),
5159 g_signal_connect (ev_window->priv->find_job, "finished",
5160 G_CALLBACK (ev_window_find_job_finished_cb),
5162 g_signal_connect (ev_window->priv->find_job, "updated",
5163 G_CALLBACK (ev_window_find_job_updated_cb),
5165 ev_job_scheduler_push_job (ev_window->priv->find_job, EV_JOB_PRIORITY_NONE);
5167 ev_window_update_actions (ev_window);
5168 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar),
5170 gtk_widget_queue_draw (GTK_WIDGET (ev_window->priv->view));
5175 find_bar_visibility_changed_cb (EggFindBar *find_bar,
5177 EvWindow *ev_window)
5181 visible = gtk_widget_get_visible (GTK_WIDGET (find_bar));
5183 if (ev_window->priv->document &&
5184 EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
5185 ev_view_find_set_highlight_search (EV_VIEW (ev_window->priv->view), visible);
5186 ev_view_find_search_changed (EV_VIEW (ev_window->priv->view));
5187 ev_window_update_actions (ev_window);
5190 find_bar_search_changed_cb (find_bar, NULL, ev_window);
5192 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar), NULL);
5197 find_bar_scroll (EggFindBar *find_bar,
5198 GtkScrollType scroll,
5199 EvWindow *ev_window)
5201 ev_view_scroll (EV_VIEW (ev_window->priv->view), scroll, FALSE);
5205 zoom_control_changed_cb (EphyZoomAction *action,
5207 EvWindow *ev_window)
5211 if (zoom == EPHY_ZOOM_BEST_FIT) {
5212 mode = EV_SIZING_BEST_FIT;
5213 } else if (zoom == EPHY_ZOOM_FIT_WIDTH) {
5214 mode = EV_SIZING_FIT_WIDTH;
5216 mode = EV_SIZING_FREE;
5219 ev_document_model_set_sizing_mode (ev_window->priv->model, mode);
5221 if (mode == EV_SIZING_FREE) {
5222 ev_document_model_set_scale (ev_window->priv->model,
5223 zoom * get_screen_dpi (ev_window) / 72.0);
5228 ev_window_drag_data_received (GtkWidget *widget,
5229 GdkDragContext *context,
5232 GtkSelectionData *selection_data,
5237 EvWindow *window = EV_WINDOW (widget);
5240 GSList *uri_list = NULL;
5243 source = gtk_drag_get_source_widget (context);
5244 if (source && widget == gtk_widget_get_toplevel (source)) {
5245 gtk_drag_finish (context, FALSE, FALSE, time);
5249 uris = gtk_selection_data_get_uris (selection_data);
5251 gtk_drag_finish (context, FALSE, FALSE, time);
5255 for (i = 0; uris[i]; i++) {
5256 uri_list = g_slist_prepend (uri_list, (gpointer) uris[i]);
5259 ev_application_open_uri_list (EV_APP, uri_list,
5260 gtk_window_get_screen (GTK_WINDOW (window)),
5262 gtk_drag_finish (context, TRUE, FALSE, time);
5265 g_slist_free (uri_list);
5269 ev_window_finalize (GObject *object)
5271 G_OBJECT_CLASS (ev_window_parent_class)->finalize (object);
5273 if (ev_window_n_copies == 0) {
5274 ev_application_shutdown (EV_APP);
5276 ev_window_n_copies--;
5281 ev_window_dispose (GObject *object)
5283 EvWindow *window = EV_WINDOW (object);
5284 EvWindowPrivate *priv = window->priv;
5285 GObject *mpkeys = ev_application_get_media_keys (EV_APP);
5288 g_signal_handlers_disconnect_by_func (mpkeys,
5289 ev_window_media_player_key_pressed,
5294 if (priv->dbus_object_id > 0) {
5295 ev_window_emit_closed (window);
5296 g_dbus_connection_unregister_object (ev_application_get_dbus_connection (EV_APP),
5297 priv->dbus_object_id);
5298 priv->dbus_object_id = 0;
5301 if (priv->dbus_object_path) {
5302 g_free (priv->dbus_object_path);
5303 priv->dbus_object_path = NULL;
5305 #endif /* ENABLE_DBUS */
5307 if (priv->bookmarks) {
5308 g_object_unref (priv->bookmarks);
5309 priv->bookmarks = NULL;
5312 if (priv->metadata) {
5313 g_object_unref (priv->metadata);
5314 priv->metadata = NULL;
5317 if (priv->setup_document_idle > 0) {
5318 g_source_remove (priv->setup_document_idle);
5319 priv->setup_document_idle = 0;
5322 if (priv->monitor) {
5323 g_object_unref (priv->monitor);
5324 priv->monitor = NULL;
5328 ev_window_title_free (priv->title);
5332 if (priv->ui_manager) {
5333 g_object_unref (priv->ui_manager);
5334 priv->ui_manager = NULL;
5337 if (priv->action_group) {
5338 g_object_unref (priv->action_group);
5339 priv->action_group = NULL;
5342 if (priv->view_popup_action_group) {
5343 g_object_unref (priv->view_popup_action_group);
5344 priv->view_popup_action_group = NULL;
5347 if (priv->attachment_popup_action_group) {
5348 g_object_unref (priv->attachment_popup_action_group);
5349 priv->attachment_popup_action_group = NULL;
5352 if (priv->recent_action_group) {
5353 g_object_unref (priv->recent_action_group);
5354 priv->recent_action_group = NULL;
5357 if (priv->bookmarks_action_group) {
5358 g_object_unref (priv->bookmarks_action_group);
5359 priv->bookmarks_action_group = NULL;
5362 if (priv->recent_manager) {
5363 g_signal_handlers_disconnect_by_func (priv->recent_manager,
5364 ev_window_setup_recent,
5366 priv->recent_manager = NULL;
5369 if (priv->settings) {
5370 g_object_unref (priv->settings);
5371 priv->settings = NULL;
5374 if (priv->default_settings) {
5375 g_settings_apply (priv->default_settings);
5376 g_object_unref (priv->default_settings);
5377 priv->default_settings = NULL;
5380 if (priv->lockdown_settings) {
5381 g_object_unref (priv->lockdown_settings);
5382 priv->lockdown_settings = NULL;
5385 priv->recent_ui_id = 0;
5388 g_signal_handlers_disconnect_by_func (priv->model,
5389 ev_window_page_changed_cb,
5391 g_object_unref (priv->model);
5395 if (priv->document) {
5396 g_object_unref (priv->document);
5397 priv->document = NULL;
5401 g_object_unref (priv->view);
5405 if (priv->password_view) {
5406 g_object_unref (priv->password_view);
5407 priv->password_view = NULL;
5410 if (priv->load_job) {
5411 ev_window_clear_load_job (window);
5414 if (priv->reload_job) {
5415 ev_window_clear_reload_job (window);
5418 if (priv->save_job) {
5419 ev_window_clear_save_job (window);
5422 if (priv->thumbnail_job) {
5423 ev_window_clear_thumbnail_job (window);
5426 if (priv->find_job) {
5427 ev_window_clear_find_job (window);
5430 if (priv->local_uri) {
5431 ev_window_clear_local_uri (window);
5432 priv->local_uri = NULL;
5435 ev_window_clear_progress_idle (window);
5436 if (priv->progress_cancellable) {
5437 g_object_unref (priv->progress_cancellable);
5438 priv->progress_cancellable = NULL;
5441 ev_window_close_dialogs (window);
5444 g_object_unref (priv->link);
5449 g_object_unref (priv->image);
5454 g_object_unref (priv->annot);
5458 if (priv->attach_list) {
5459 g_list_foreach (priv->attach_list,
5460 (GFunc) g_object_unref,
5462 g_list_free (priv->attach_list);
5463 priv->attach_list = NULL;
5466 if (priv->find_bar) {
5467 g_signal_handlers_disconnect_by_func
5468 (window->priv->find_bar,
5469 G_CALLBACK (find_bar_close_cb),
5471 priv->find_bar = NULL;
5479 if (priv->search_string) {
5480 g_free (priv->search_string);
5481 priv->search_string = NULL;
5485 g_object_unref (priv->dest);
5489 if (priv->history) {
5490 g_object_unref (priv->history);
5491 priv->history = NULL;
5494 if (priv->print_queue) {
5495 g_queue_free (priv->print_queue);
5496 priv->print_queue = NULL;
5499 G_OBJECT_CLASS (ev_window_parent_class)->dispose (object);
5503 menubar_deactivate_cb (GtkWidget *menubar,
5506 g_signal_handlers_disconnect_by_func (menubar,
5507 G_CALLBACK (menubar_deactivate_cb),
5510 gtk_menu_shell_deselect (GTK_MENU_SHELL (menubar));
5512 update_chrome_visibility (window);
5516 ev_window_key_press_event (GtkWidget *widget,
5519 EvWindow *ev_window = EV_WINDOW (widget);
5520 EvWindowPrivate *priv = ev_window->priv;
5521 gboolean handled = FALSE;
5523 /* Propagate the event to the view first
5524 * It's needed to be able to type in
5525 * annot popups windows
5528 g_object_ref (priv->view);
5529 if (gtk_widget_is_sensitive (priv->view))
5530 handled = gtk_widget_event (priv->view, (GdkEvent*) event);
5531 g_object_unref (priv->view);
5534 if (!handled && !EV_WINDOW_IS_PRESENTATION (ev_window)) {
5535 guint modifier = event->state & gtk_accelerator_get_default_mod_mask ();
5537 if (priv->menubar_accel_keyval != 0 &&
5538 event->keyval == priv->menubar_accel_keyval &&
5539 modifier == priv->menubar_accel_modifier) {
5540 if (!gtk_widget_get_visible (priv->menubar)) {
5541 g_signal_connect (priv->menubar, "deactivate",
5542 G_CALLBACK (menubar_deactivate_cb),
5545 gtk_widget_show (priv->menubar);
5546 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menubar),
5555 handled = GTK_WIDGET_CLASS (ev_window_parent_class)->key_press_event (widget, event);
5561 ev_window_delete_event (GtkWidget *widget,
5564 return !ev_window_close (EV_WINDOW (widget));
5568 ev_window_class_init (EvWindowClass *ev_window_class)
5570 GObjectClass *g_object_class = G_OBJECT_CLASS (ev_window_class);
5571 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (ev_window_class);
5573 g_object_class->dispose = ev_window_dispose;
5574 g_object_class->finalize = ev_window_finalize;
5576 widget_class->delete_event = ev_window_delete_event;
5577 widget_class->key_press_event = ev_window_key_press_event;
5578 widget_class->screen_changed = ev_window_screen_changed;
5579 widget_class->window_state_event = ev_window_state_event;
5580 widget_class->drag_data_received = ev_window_drag_data_received;
5582 g_type_class_add_private (g_object_class, sizeof (EvWindowPrivate));
5586 static const GtkActionEntry entries[] = {
5587 { "File", NULL, N_("_File") },
5588 { "Edit", NULL, N_("_Edit") },
5589 { "View", NULL, N_("_View") },
5590 { "Go", NULL, N_("_Go") },
5591 { "Bookmarks", NULL, N_("_Bookmarks") },
5592 { "Help", NULL, N_("_Help") },
5595 { "FileOpen", GTK_STOCK_OPEN, N_("_Open…"), "<control>O",
5596 N_("Open an existing document"),
5597 G_CALLBACK (ev_window_cmd_file_open) },
5598 { "FileOpenCopy", NULL, N_("Op_en a Copy"), "<control>N",
5599 N_("Open a copy of the current document in a new window"),
5600 G_CALLBACK (ev_window_cmd_file_open_copy) },
5601 { "FileSaveAs", GTK_STOCK_SAVE_AS, N_("_Save a Copy…"), "<control>S",
5602 N_("Save a copy of the current document"),
5603 G_CALLBACK (ev_window_cmd_save_as) },
5604 { "FileOpenContainingFolder", GTK_STOCK_DIRECTORY, N_("Open Containing _Folder"), NULL,
5605 N_("Show the folder which contains this file in the file manager"),
5606 G_CALLBACK (ev_window_cmd_open_containing_folder) },
5607 { "FilePrint", GTK_STOCK_PRINT, N_("_Print…"), "<control>P",
5608 N_("Print this document"),
5609 G_CALLBACK (ev_window_cmd_file_print) },
5610 { "FileProperties", GTK_STOCK_PROPERTIES, N_("P_roperties"), "<alt>Return", NULL,
5611 G_CALLBACK (ev_window_cmd_file_properties) },
5612 { "FileCloseWindow", GTK_STOCK_CLOSE, NULL, "<control>W", NULL,
5613 G_CALLBACK (ev_window_cmd_file_close_window) },
5616 { "EditCopy", GTK_STOCK_COPY, NULL, "<control>C", NULL,
5617 G_CALLBACK (ev_window_cmd_edit_copy) },
5618 { "EditSelectAll", GTK_STOCK_SELECT_ALL, N_("Select _All"), "<control>A", NULL,
5619 G_CALLBACK (ev_window_cmd_edit_select_all) },
5620 { "EditFind", GTK_STOCK_FIND, N_("_Find…"), "<control>F",
5621 N_("Find a word or phrase in the document"),
5622 G_CALLBACK (ev_window_cmd_edit_find) },
5623 { "EditFindNext", NULL, N_("Find Ne_xt"), "<control>G", NULL,
5624 G_CALLBACK (ev_window_cmd_edit_find_next) },
5625 { "EditFindPrevious", NULL, N_("Find Pre_vious"), "<shift><control>G", NULL,
5626 G_CALLBACK (ev_window_cmd_edit_find_previous) },
5627 { "EditToolbar", NULL, N_("T_oolbar"), NULL, NULL,
5628 G_CALLBACK (ev_window_cmd_edit_toolbar) },
5629 { "EditRotateLeft", EV_STOCK_ROTATE_LEFT, N_("Rotate _Left"), "<control>Left", NULL,
5630 G_CALLBACK (ev_window_cmd_edit_rotate_left) },
5631 { "EditRotateRight", EV_STOCK_ROTATE_RIGHT, N_("Rotate _Right"), "<control>Right", NULL,
5632 G_CALLBACK (ev_window_cmd_edit_rotate_right) },
5633 { "EditSaveSettings", NULL, N_("Save Current Settings as _Default"), "<control>T", NULL,
5634 G_CALLBACK (ev_window_cmd_edit_save_settings) },
5638 { "ViewZoomIn", GTK_STOCK_ZOOM_IN, NULL, "<control>plus",
5639 N_("Enlarge the document"),
5640 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5641 { "ViewZoomOut", GTK_STOCK_ZOOM_OUT, NULL, "<control>minus",
5642 N_("Shrink the document"),
5643 G_CALLBACK (ev_window_cmd_view_zoom_out) },
5644 { "ViewReload", GTK_STOCK_REFRESH, N_("_Reload"), "<control>R",
5645 N_("Reload the document"),
5646 G_CALLBACK (ev_window_cmd_view_reload) },
5648 { "ViewAutoscroll", GTK_STOCK_MEDIA_PLAY, N_("Auto_scroll"), NULL, NULL,
5649 G_CALLBACK (ev_window_cmd_view_autoscroll) },
5652 { "GoPreviousPage", GTK_STOCK_GO_UP, N_("_Previous Page"), "<control>Page_Up",
5653 N_("Go to the previous page"),
5654 G_CALLBACK (ev_window_cmd_go_previous_page) },
5655 { "GoNextPage", GTK_STOCK_GO_DOWN, N_("_Next Page"), "<control>Page_Down",
5656 N_("Go to the next page"),
5657 G_CALLBACK (ev_window_cmd_go_next_page) },
5658 { "GoFirstPage", GTK_STOCK_GOTO_TOP, N_("_First Page"), "<control>Home",
5659 N_("Go to the first page"),
5660 G_CALLBACK (ev_window_cmd_go_first_page) },
5661 { "GoLastPage", GTK_STOCK_GOTO_BOTTOM, N_("_Last Page"), "<control>End",
5662 N_("Go to the last page"),
5663 G_CALLBACK (ev_window_cmd_go_last_page) },
5665 /* Bookmarks menu */
5666 { "BookmarksAdd", GTK_STOCK_ADD, N_("_Add Bookmark"), "<control>D",
5667 N_("Add a bookmark for the current page"),
5668 G_CALLBACK (ev_window_cmd_bookmarks_add) },
5671 { "HelpContents", GTK_STOCK_HELP, N_("_Contents"), "F1", NULL,
5672 G_CALLBACK (ev_window_cmd_help_contents) },
5674 { "HelpAbout", GTK_STOCK_ABOUT, N_("_About"), NULL, NULL,
5675 G_CALLBACK (ev_window_cmd_help_about) },
5678 { "LeaveFullscreen", GTK_STOCK_LEAVE_FULLSCREEN, N_("Leave Fullscreen"), NULL,
5679 N_("Leave fullscreen mode"),
5680 G_CALLBACK (ev_window_cmd_leave_fullscreen) },
5681 { "StartPresentation", EV_STOCK_RUN_PRESENTATION, N_("Start Presentation"), NULL,
5682 N_("Start a presentation"),
5683 G_CALLBACK (ev_window_cmd_start_presentation) },
5686 { "Escape", NULL, "", "Escape", "",
5687 G_CALLBACK (ev_window_cmd_escape) },
5688 { "Slash", GTK_STOCK_FIND, NULL, "slash", NULL,
5689 G_CALLBACK (ev_window_cmd_edit_find) },
5690 { "F3", NULL, "", "F3", NULL,
5691 G_CALLBACK (ev_window_cmd_edit_find_next) },
5692 { "PageDown", NULL, "", "Page_Down", NULL,
5693 G_CALLBACK (ev_window_cmd_scroll_forward) },
5694 { "PageUp", NULL, "", "Page_Up", NULL,
5695 G_CALLBACK (ev_window_cmd_scroll_backward) },
5696 { "Space", NULL, "", "space", NULL,
5697 G_CALLBACK (ev_window_cmd_scroll_forward) },
5698 { "ShiftSpace", NULL, "", "<shift>space", NULL,
5699 G_CALLBACK (ev_window_cmd_scroll_backward) },
5700 { "BackSpace", NULL, "", "BackSpace", NULL,
5701 G_CALLBACK (ev_window_cmd_scroll_backward) },
5702 { "ShiftBackSpace", NULL, "", "<shift>BackSpace", NULL,
5703 G_CALLBACK (ev_window_cmd_scroll_forward) },
5704 { "Return", NULL, "", "Return", NULL,
5705 G_CALLBACK (ev_window_cmd_scroll_forward) },
5706 { "ShiftReturn", NULL, "", "<shift>Return", NULL,
5707 G_CALLBACK (ev_window_cmd_scroll_backward) },
5708 { "p", GTK_STOCK_GO_UP, "", "p", NULL,
5709 G_CALLBACK (ev_window_cmd_go_previous_page) },
5710 { "n", GTK_STOCK_GO_DOWN, "", "n", NULL,
5711 G_CALLBACK (ev_window_cmd_go_next_page) },
5712 { "Plus", GTK_STOCK_ZOOM_IN, NULL, "plus", NULL,
5713 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5714 { "CtrlEqual", GTK_STOCK_ZOOM_IN, NULL, "<control>equal", NULL,
5715 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5716 { "Equal", GTK_STOCK_ZOOM_IN, NULL, "equal", NULL,
5717 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5718 { "Minus", GTK_STOCK_ZOOM_OUT, NULL, "minus", NULL,
5719 G_CALLBACK (ev_window_cmd_view_zoom_out) },
5720 { "FocusPageSelector", NULL, "", "<control>l", NULL,
5721 G_CALLBACK (ev_window_cmd_focus_page_selector) },
5722 { "GoBackwardFast", NULL, "", "<shift>Page_Up", NULL,
5723 G_CALLBACK (ev_window_cmd_go_backward) },
5724 { "GoForwardFast", NULL, "", "<shift>Page_Down", NULL,
5725 G_CALLBACK (ev_window_cmd_go_forward) },
5726 { "KpPlus", GTK_STOCK_ZOOM_IN, NULL, "KP_Add", NULL,
5727 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5728 { "KpMinus", GTK_STOCK_ZOOM_OUT, NULL, "KP_Subtract", NULL,
5729 G_CALLBACK (ev_window_cmd_view_zoom_out) },
5730 { "CtrlKpPlus", GTK_STOCK_ZOOM_IN, NULL, "<control>KP_Add", NULL,
5731 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5732 { "CtrlKpMinus", GTK_STOCK_ZOOM_OUT, NULL, "<control>KP_Subtract", NULL,
5733 G_CALLBACK (ev_window_cmd_view_zoom_out) },
5734 { "CtrlInsert", GTK_STOCK_COPY, NULL, "<control>Insert", NULL,
5735 G_CALLBACK (ev_window_cmd_edit_copy) },
5739 static const GtkToggleActionEntry toggle_entries[] = {
5741 { "ViewToolbar", NULL, N_("_Toolbar"), NULL,
5742 N_("Show or hide the toolbar"),
5743 G_CALLBACK (ev_window_view_toolbar_cb), TRUE },
5744 { "ViewSidebar", GTK_STOCK_INDEX, N_("Side _Pane"), "F9",
5745 N_("Show or hide the side pane"),
5746 G_CALLBACK (ev_window_view_sidebar_cb), TRUE },
5747 { "ViewContinuous", EV_STOCK_VIEW_CONTINUOUS, N_("_Continuous"), NULL,
5748 N_("Show the entire document"),
5749 G_CALLBACK (ev_window_cmd_continuous), TRUE },
5750 { "ViewDual", EV_STOCK_VIEW_DUAL, N_("_Dual"), NULL,
5751 N_("Show two pages at once"),
5752 G_CALLBACK (ev_window_cmd_dual), FALSE },
5753 { "ViewFullscreen", GTK_STOCK_FULLSCREEN, N_("_Fullscreen"), "F11",
5754 N_("Expand the window to fill the screen"),
5755 G_CALLBACK (ev_window_cmd_view_fullscreen) },
5756 { "ViewPresentation", EV_STOCK_RUN_PRESENTATION, N_("Pre_sentation"), "F5",
5757 N_("Run document as a presentation"),
5758 G_CALLBACK (ev_window_cmd_view_presentation) },
5759 { "ViewBestFit", EV_STOCK_ZOOM_PAGE, N_("_Best Fit"), NULL,
5760 N_("Make the current document fill the window"),
5761 G_CALLBACK (ev_window_cmd_view_best_fit) },
5762 { "ViewPageWidth", EV_STOCK_ZOOM_WIDTH, N_("Fit Page _Width"), NULL,
5763 N_("Make the current document fill the window width"),
5764 G_CALLBACK (ev_window_cmd_view_page_width) },
5765 { "ViewInvertedColors", EV_STOCK_INVERTED_COLORS, N_("_Inverted Colors"), "<control>I",
5766 N_("Show page contents with the colors inverted"),
5767 G_CALLBACK (ev_window_cmd_view_inverted_colors) },
5771 /* Popups specific items */
5772 static const GtkActionEntry view_popup_entries [] = {
5774 { "OpenLink", GTK_STOCK_OPEN, N_("_Open Link"), NULL,
5775 NULL, G_CALLBACK (ev_view_popup_cmd_open_link) },
5776 { "GoLink", GTK_STOCK_GO_FORWARD, N_("_Go To"), NULL,
5777 NULL, G_CALLBACK (ev_view_popup_cmd_open_link) },
5778 { "OpenLinkNewWindow", NULL, N_("Open in New _Window"), NULL,
5779 NULL, G_CALLBACK (ev_view_popup_cmd_open_link_new_window) },
5780 { "CopyLinkAddress", NULL, N_("_Copy Link Address"), NULL,
5781 NULL, G_CALLBACK (ev_view_popup_cmd_copy_link_address) },
5782 { "SaveImageAs", NULL, N_("_Save Image As…"), NULL,
5783 NULL, G_CALLBACK (ev_view_popup_cmd_save_image_as) },
5784 { "CopyImage", NULL, N_("Copy _Image"), NULL,
5785 NULL, G_CALLBACK (ev_view_popup_cmd_copy_image) },
5786 { "AnnotProperties", NULL, N_("Annotation Properties…"), NULL,
5787 NULL, G_CALLBACK (ev_view_popup_cmd_annot_properties) }
5790 static const GtkActionEntry attachment_popup_entries [] = {
5791 { "OpenAttachment", GTK_STOCK_OPEN, N_("_Open Attachment"), NULL,
5792 NULL, G_CALLBACK (ev_attachment_popup_cmd_open_attachment) },
5793 { "SaveAttachmentAs", GTK_STOCK_SAVE_AS, N_("_Save Attachment As…"), NULL,
5794 NULL, G_CALLBACK (ev_attachment_popup_cmd_save_attachment_as) },
5798 sidebar_links_link_activated_cb (EvSidebarLinks *sidebar_links, EvLink *link, EvWindow *window)
5800 ev_view_handle_link (EV_VIEW (window->priv->view), link);
5804 activate_link_cb (EvPageAction *page_action, EvLink *link, EvWindow *window)
5806 ev_view_handle_link (EV_VIEW (window->priv->view), link);
5807 gtk_widget_grab_focus (window->priv->view);
5811 navigation_action_activate_link_cb (EvNavigationAction *action, EvLink *link, EvWindow *window)
5814 ev_view_handle_link (EV_VIEW (window->priv->view), link);
5815 gtk_widget_grab_focus (window->priv->view);
5819 sidebar_layers_visibility_changed (EvSidebarLayers *layers,
5822 ev_view_reload (EV_VIEW (window->priv->view));
5826 sidebar_annots_annot_activated_cb (EvSidebarAnnotations *sidebar_annots,
5827 EvMapping *annot_mapping,
5830 ev_view_focus_annotation (EV_VIEW (window->priv->view), annot_mapping);
5834 sidebar_annots_begin_annot_add (EvSidebarAnnotations *sidebar_annots,
5835 EvAnnotationType annot_type,
5838 ev_view_begin_add_annotation (EV_VIEW (window->priv->view), annot_type);
5842 view_annot_added (EvView *view,
5843 EvAnnotation *annot,
5846 ev_sidebar_annotations_annot_added (EV_SIDEBAR_ANNOTATIONS (window->priv->sidebar_annots),
5851 sidebar_annots_annot_add_cancelled (EvSidebarAnnotations *sidebar_annots,
5854 ev_view_cancel_add_annotation (EV_VIEW (window->priv->view));
5858 sidebar_bookmarks_add_bookmark (EvSidebarBookmarks *sidebar_bookmarks,
5861 ev_window_cmd_bookmarks_add (NULL, window);
5865 register_custom_actions (EvWindow *window, GtkActionGroup *group)
5869 action = g_object_new (EV_TYPE_PAGE_ACTION,
5870 "name", PAGE_SELECTOR_ACTION,
5872 "tooltip", _("Select Page"),
5873 "icon_name", "text-x-generic",
5874 "visible_overflown", FALSE,
5876 ev_page_action_set_model (EV_PAGE_ACTION (action),
5877 window->priv->model);
5878 g_signal_connect (action, "activate_link",
5879 G_CALLBACK (activate_link_cb), window);
5880 gtk_action_group_add_action (group, action);
5881 g_object_unref (action);
5883 action = g_object_new (EPHY_TYPE_ZOOM_ACTION,
5884 "name", ZOOM_CONTROL_ACTION,
5886 "stock_id", EV_STOCK_ZOOM,
5887 "tooltip", _("Adjust the zoom level"),
5890 g_signal_connect (action, "zoom_to_level",
5891 G_CALLBACK (zoom_control_changed_cb), window);
5892 gtk_action_group_add_action (group, action);
5893 g_object_unref (action);
5895 action = g_object_new (EV_TYPE_NAVIGATION_ACTION,
5896 "name", NAVIGATION_ACTION,
5897 "label", _("Navigation"),
5898 "is_important", TRUE,
5899 "short_label", _("Back"),
5900 "stock_id", GTK_STOCK_GO_DOWN,
5901 /*translators: this is the history action*/
5902 "tooltip", _("Move across visited pages"),
5904 g_signal_connect (action, "activate_link",
5905 G_CALLBACK (navigation_action_activate_link_cb), window);
5906 gtk_action_group_add_action (group, action);
5907 g_object_unref (action);
5909 action = g_object_new (EV_TYPE_OPEN_RECENT_ACTION,
5910 "name", "FileOpenRecent",
5911 "label", _("_Open…"),
5912 "tooltip", _("Open an existing document"),
5913 "stock_id", GTK_STOCK_OPEN,
5915 g_signal_connect (action, "activate",
5916 G_CALLBACK (ev_window_cmd_file_open), window);
5917 g_signal_connect (action, "item_activated",
5918 G_CALLBACK (ev_window_open_recent_action_item_activated),
5920 gtk_action_group_add_action (group, action);
5921 g_object_unref (action);
5925 set_action_properties (GtkActionGroup *action_group)
5929 action = gtk_action_group_get_action (action_group, "FileOpenContainingFolder");
5930 /*translators: this is the label for toolbar button*/
5931 g_object_set (action, "short_label", _("Open Folder"), NULL);
5933 action = gtk_action_group_get_action (action_group, "GoPreviousPage");
5934 g_object_set (action, "is-important", TRUE, NULL);
5935 /*translators: this is the label for toolbar button*/
5936 g_object_set (action, "short_label", _("Previous"), NULL);
5938 action = gtk_action_group_get_action (action_group, "GoNextPage");
5939 g_object_set (action, "is-important", TRUE, NULL);
5940 /*translators: this is the label for toolbar button*/
5941 g_object_set (action, "short_label", _("Next"), NULL);
5943 action = gtk_action_group_get_action (action_group, "ViewZoomIn");
5944 /*translators: this is the label for toolbar button*/
5945 g_object_set (action, "short_label", _("Zoom In"), NULL);
5947 action = gtk_action_group_get_action (action_group, "ViewZoomOut");
5948 /*translators: this is the label for toolbar button*/
5949 g_object_set (action, "short_label", _("Zoom Out"), NULL);
5951 action = gtk_action_group_get_action (action_group, "ViewBestFit");
5952 /*translators: this is the label for toolbar button*/
5953 g_object_set (action, "short_label", _("Best Fit"), NULL);
5955 action = gtk_action_group_get_action (action_group, "ViewPageWidth");
5956 /*translators: this is the label for toolbar button*/
5957 g_object_set (action, "short_label", _("Fit Width"), NULL);
5959 action = gtk_action_group_get_action (action_group, "LeaveFullscreen");
5960 g_object_set (action, "is-important", TRUE, NULL);
5964 sidebar_widget_model_set (EvSidebarLinks *ev_sidebar_links,
5966 EvWindow *ev_window)
5968 GtkTreeModel *model;
5971 g_object_get (G_OBJECT (ev_sidebar_links),
5975 action = gtk_action_group_get_action (ev_window->priv->action_group, PAGE_SELECTOR_ACTION);
5976 ev_page_action_set_links_model (EV_PAGE_ACTION (action), model);
5977 g_object_unref (model);
5981 view_actions_focus_in_cb (GtkWidget *widget, GdkEventFocus *event, EvWindow *window)
5986 keys = ev_application_get_media_keys (EV_APP);
5987 ev_media_player_keys_focused (EV_MEDIA_PLAYER_KEYS (keys));
5988 #endif /* ENABLE_DBUS */
5990 update_chrome_flag (window, EV_CHROME_RAISE_TOOLBAR, FALSE);
5991 ev_window_set_action_sensitive (window, "ViewToolbar", TRUE);
5993 ev_window_set_view_accels_sensitivity (window, TRUE);
5995 update_chrome_visibility (window);
6001 view_actions_focus_out_cb (GtkWidget *widget, GdkEventFocus *event, EvWindow *window)
6003 ev_window_set_view_accels_sensitivity (window, FALSE);
6009 sidebar_page_main_widget_update_cb (GObject *ev_sidebar_page,
6011 EvWindow *ev_window)
6015 g_object_get (ev_sidebar_page, "main_widget", &widget, NULL);
6017 if (widget != NULL) {
6018 g_signal_connect_object (widget, "focus_in_event",
6019 G_CALLBACK (view_actions_focus_in_cb),
6021 g_signal_connect_object (widget, "focus_out_event",
6022 G_CALLBACK (view_actions_focus_out_cb),
6024 g_object_unref (widget);
6029 window_state_event_cb (EvWindow *window, GdkEventWindowState *event, gpointer dummy)
6031 if (!(event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN)) {
6034 maximized = event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED;
6035 if (window->priv->metadata && !ev_window_is_empty (window))
6036 ev_metadata_set_boolean (window->priv->metadata, "window_maximized", maximized);
6043 window_configure_event_cb (EvWindow *window, GdkEventConfigure *event, gpointer dummy)
6045 GdkWindowState state;
6046 gdouble document_width, document_height;
6048 if (!window->priv->metadata)
6051 state = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (window)));
6053 if (!(state & GDK_WINDOW_STATE_FULLSCREEN)) {
6054 if (window->priv->document) {
6055 ev_document_get_max_page_size (window->priv->document,
6056 &document_width, &document_height);
6057 g_settings_set (window->priv->default_settings, "window-ratio", "(dd)",
6058 (double)event->width / document_width,
6059 (double)event->height / document_height);
6061 ev_metadata_set_int (window->priv->metadata, "window_x", event->x);
6062 ev_metadata_set_int (window->priv->metadata, "window_y", event->y);
6063 ev_metadata_set_int (window->priv->metadata, "window_width", event->width);
6064 ev_metadata_set_int (window->priv->metadata, "window_height", event->height);
6072 launch_action (EvWindow *window, EvLinkAction *action)
6074 const char *filename = ev_link_action_get_filename (action);
6077 GList file_list = {NULL};
6078 GAppLaunchContext *context;
6079 GError *error = NULL;
6081 if (filename == NULL)
6084 if (g_path_is_absolute (filename)) {
6085 file = g_file_new_for_path (filename);
6090 dir = g_path_get_dirname (window->priv->uri);
6091 base_file = g_file_new_for_uri (dir);
6094 file = g_file_resolve_relative_path (base_file, filename);
6095 g_object_unref (base_file);
6098 app_info = g_file_query_default_handler (file, NULL, &error);
6100 ev_window_error_message (window, error,
6102 _("Unable to launch external application."));
6103 g_object_unref (file);
6104 g_error_free (error);
6109 context = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
6110 gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (context),
6111 gtk_window_get_screen (GTK_WINDOW (window)));
6112 gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (context),
6113 gtk_get_current_event_time ());
6115 file_list.data = file;
6116 if (!g_app_info_launch (app_info, &file_list, context, &error)) {
6117 ev_window_error_message (window, error,
6119 _("Unable to launch external application."));
6120 g_error_free (error);
6123 g_object_unref (app_info);
6124 g_object_unref (file);
6125 /* FIXMEchpe: unref launch context? */
6127 /* According to the PDF spec filename can be an executable. I'm not sure
6128 allowing to launch executables is a good idea though. -- marco */
6132 launch_external_uri (EvWindow *window, EvLinkAction *action)
6134 const gchar *uri = ev_link_action_get_uri (action);
6135 GError *error = NULL;
6137 GAppLaunchContext *context;
6139 context = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
6140 gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (context),
6141 gtk_window_get_screen (GTK_WINDOW (window)));
6142 gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (context),
6143 gtk_get_current_event_time ());
6145 if (!g_strstr_len (uri, strlen (uri), "://") &&
6146 !g_str_has_prefix (uri, "mailto:")) {
6149 /* Not a valid uri, assume http if it starts with www */
6150 if (g_str_has_prefix (uri, "www.")) {
6151 new_uri = g_strdup_printf ("http://%s", uri);
6153 GFile *file, *parent;
6155 file = g_file_new_for_uri (window->priv->uri);
6156 parent = g_file_get_parent (file);
6157 g_object_unref (file);
6159 gchar *parent_uri = g_file_get_uri (parent);
6161 new_uri = g_build_filename (parent_uri, uri, NULL);
6162 g_free (parent_uri);
6163 g_object_unref (parent);
6165 new_uri = g_strdup_printf ("file:///%s", uri);
6168 ret = g_app_info_launch_default_for_uri (new_uri, context, &error);
6171 ret = g_app_info_launch_default_for_uri (uri, context, &error);
6175 ev_window_error_message (window, error,
6176 "%s", _("Unable to open external link"));
6177 g_error_free (error);
6180 /* FIXMEchpe: unref launch context? */
6184 open_remote_link (EvWindow *window, EvLinkAction *action)
6189 dir = g_path_get_dirname (window->priv->uri);
6191 uri = g_build_filename (dir, ev_link_action_get_filename (action),
6195 ev_application_open_uri_at_dest (EV_APP, uri,
6196 gtk_window_get_screen (GTK_WINDOW (window)),
6197 ev_link_action_get_dest (action),
6200 gtk_get_current_event_time ());
6206 do_action_named (EvWindow *window, EvLinkAction *action)
6208 const gchar *name = ev_link_action_get_name (action);
6210 if (g_ascii_strcasecmp (name, "FirstPage") == 0) {
6211 ev_window_cmd_go_first_page (NULL, window);
6212 } else if (g_ascii_strcasecmp (name, "PrevPage") == 0) {
6213 ev_window_cmd_go_previous_page (NULL, window);
6214 } else if (g_ascii_strcasecmp (name, "NextPage") == 0) {
6215 ev_window_cmd_go_next_page (NULL, window);
6216 } else if (g_ascii_strcasecmp (name, "LastPage") == 0) {
6217 ev_window_cmd_go_last_page (NULL, window);
6218 } else if (g_ascii_strcasecmp (name, "GoToPage") == 0) {
6219 ev_window_cmd_focus_page_selector (NULL, window);
6220 } else if (g_ascii_strcasecmp (name, "Find") == 0) {
6221 ev_window_cmd_edit_find (NULL, window);
6222 } else if (g_ascii_strcasecmp (name, "Close") == 0) {
6223 ev_window_cmd_file_close_window (NULL, window);
6224 } else if (g_ascii_strcasecmp (name, "Print") == 0) {
6225 ev_window_cmd_file_print (NULL, window);
6227 g_warning ("Unimplemented named action: %s, please post a "
6228 "bug report in Evince bugzilla "
6229 "(http://bugzilla.gnome.org) with a testcase.",
6235 view_external_link_cb (EvView *view, EvLinkAction *action, EvWindow *window)
6237 switch (ev_link_action_get_action_type (action)) {
6238 case EV_LINK_ACTION_TYPE_GOTO_DEST: {
6241 dest = ev_link_action_get_dest (action);
6245 ev_window_open_copy_at_dest (window, dest);
6248 case EV_LINK_ACTION_TYPE_EXTERNAL_URI:
6249 launch_external_uri (window, action);
6251 case EV_LINK_ACTION_TYPE_LAUNCH:
6252 launch_action (window, action);
6254 case EV_LINK_ACTION_TYPE_GOTO_REMOTE:
6255 open_remote_link (window, action);
6257 case EV_LINK_ACTION_TYPE_NAMED:
6258 do_action_named (window, action);
6261 g_assert_not_reached ();
6266 ev_view_popup_cmd_open_link (GtkAction *action, EvWindow *window)
6268 ev_view_handle_link (EV_VIEW (window->priv->view), window->priv->link);
6272 ev_view_popup_cmd_open_link_new_window (GtkAction *action, EvWindow *window)
6274 EvLinkAction *ev_action = NULL;
6277 ev_action = ev_link_get_action (window->priv->link);
6281 dest = ev_link_action_get_dest (ev_action);
6285 ev_window_open_copy_at_dest (window, dest);
6289 ev_view_popup_cmd_copy_link_address (GtkAction *action, EvWindow *window)
6291 EvLinkAction *ev_action;
6293 ev_action = ev_link_get_action (window->priv->link);
6297 ev_view_copy_link_address (EV_VIEW (window->priv->view),
6303 image_save_dialog_response_cb (GtkWidget *fc,
6305 EvWindow *ev_window)
6309 GError *error = NULL;
6315 GdkPixbufFormat *format;
6316 GtkFileFilter *filter;
6318 if (response_id != GTK_RESPONSE_OK) {
6319 gtk_widget_destroy (fc);
6323 uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
6324 filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (fc));
6325 format = g_object_get_data (G_OBJECT (filter), "pixbuf-format");
6327 if (format == NULL) {
6328 format = get_gdk_pixbuf_format_by_extension (uri);
6331 if (format == NULL && g_strrstr (uri, ".") == NULL) {
6332 /* no extension found and no extension provided within uri */
6333 format = get_gdk_pixbuf_format_by_extension (".png");
6334 if (format == NULL) {
6335 /* no .png support, try .jpeg */
6336 format = get_gdk_pixbuf_format_by_extension (".jpeg");
6340 if (format == NULL) {
6341 ev_window_error_message (ev_window, NULL,
6343 _("Couldn't find appropriate format to save image"));
6345 gtk_widget_destroy (fc);
6350 extensions = gdk_pixbuf_format_get_extensions (format);
6351 if (!g_str_has_suffix (uri, extensions[0])) {
6352 gchar *uri_extension;
6354 uri_extension = g_strconcat (uri, ".", extensions[0], NULL);
6355 target_file = g_file_new_for_uri (uri_extension);
6356 g_free (uri_extension);
6358 target_file = g_file_new_for_uri (uri);
6360 g_strfreev (extensions);
6363 is_native = g_file_is_native (target_file);
6365 filename = g_file_get_path (target_file);
6367 /* Create a temporary local file to save to */
6368 if (ev_mkstemp ("saveimage.XXXXXX", &filename, &error) == -1)
6372 ev_document_doc_mutex_lock ();
6373 pixbuf = ev_document_images_get_image (EV_DOCUMENT_IMAGES (ev_window->priv->document),
6374 ev_window->priv->image);
6375 ev_document_doc_mutex_unlock ();
6377 file_format = gdk_pixbuf_format_get_name (format);
6378 gdk_pixbuf_save (pixbuf, filename, file_format, &error, NULL);
6379 g_free (file_format);
6380 g_object_unref (pixbuf);
6384 ev_window_error_message (ev_window, error,
6385 "%s", _("The image could not be saved."));
6386 g_error_free (error);
6388 g_object_unref (target_file);
6389 gtk_widget_destroy (fc);
6397 source_file = g_file_new_for_path (filename);
6399 ev_window_save_remote (ev_window, EV_SAVE_IMAGE,
6400 source_file, target_file);
6401 g_object_unref (source_file);
6405 g_object_unref (target_file);
6406 gtk_widget_destroy (fc);
6410 ev_view_popup_cmd_save_image_as (GtkAction *action, EvWindow *window)
6414 if (!window->priv->image)
6417 fc = gtk_file_chooser_dialog_new (_("Save Image"),
6418 GTK_WINDOW (window),
6419 GTK_FILE_CHOOSER_ACTION_SAVE,
6421 GTK_RESPONSE_CANCEL,
6422 GTK_STOCK_SAVE, GTK_RESPONSE_OK,
6425 gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
6426 gtk_dialog_set_alternative_button_order (GTK_DIALOG (fc),
6428 GTK_RESPONSE_CANCEL,
6431 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (fc), FALSE);
6432 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
6434 file_chooser_dialog_add_writable_pixbuf_formats (GTK_FILE_CHOOSER (fc));
6436 g_signal_connect (fc, "response",
6437 G_CALLBACK (image_save_dialog_response_cb),
6440 gtk_widget_show (fc);
6444 ev_view_popup_cmd_copy_image (GtkAction *action, EvWindow *window)
6446 GtkClipboard *clipboard;
6449 if (!window->priv->image)
6452 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (window),
6453 GDK_SELECTION_CLIPBOARD);
6454 ev_document_doc_mutex_lock ();
6455 pixbuf = ev_document_images_get_image (EV_DOCUMENT_IMAGES (window->priv->document),
6456 window->priv->image);
6457 ev_document_doc_mutex_unlock ();
6459 gtk_clipboard_set_image (clipboard, pixbuf);
6460 g_object_unref (pixbuf);
6464 ev_view_popup_cmd_annot_properties (GtkAction *action,
6467 const gchar *author;
6470 gboolean popup_is_open;
6471 EvAnnotationPropertiesDialog *dialog;
6472 EvAnnotation *annot = window->priv->annot;
6473 EvAnnotationsSaveMask mask = EV_ANNOTATIONS_SAVE_NONE;
6478 dialog = EV_ANNOTATION_PROPERTIES_DIALOG (ev_annotation_properties_dialog_new_with_annotation (window->priv->annot));
6479 if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_APPLY) {
6480 gtk_widget_destroy (GTK_WIDGET (dialog));
6485 /* Set annotations changes */
6486 author = ev_annotation_properties_dialog_get_author (dialog);
6487 if (ev_annotation_markup_set_label (EV_ANNOTATION_MARKUP (annot), author))
6488 mask |= EV_ANNOTATIONS_SAVE_LABEL;
6490 ev_annotation_properties_dialog_get_color (dialog, &color);
6491 if (ev_annotation_set_color (annot, &color))
6492 mask |= EV_ANNOTATIONS_SAVE_COLOR;
6494 opacity = ev_annotation_properties_dialog_get_opacity (dialog);
6495 if (ev_annotation_markup_set_opacity (EV_ANNOTATION_MARKUP (annot), opacity))
6496 mask |= EV_ANNOTATIONS_SAVE_OPACITY;
6498 popup_is_open = ev_annotation_properties_dialog_get_popup_is_open (dialog);
6499 if (ev_annotation_markup_set_popup_is_open (EV_ANNOTATION_MARKUP (annot), popup_is_open))
6500 mask |= EV_ANNOTATIONS_SAVE_POPUP_IS_OPEN;
6502 if (EV_IS_ANNOTATION_TEXT (annot)) {
6503 EvAnnotationTextIcon icon;
6505 icon = ev_annotation_properties_dialog_get_text_icon (dialog);
6506 if (ev_annotation_text_set_icon (EV_ANNOTATION_TEXT (annot), icon))
6507 mask |= EV_ANNOTATIONS_SAVE_TEXT_ICON;
6510 if (mask != EV_ANNOTATIONS_SAVE_NONE) {
6511 ev_document_doc_mutex_lock ();
6512 ev_document_annotations_save_annotation (EV_DOCUMENT_ANNOTATIONS (window->priv->document),
6513 window->priv->annot,
6515 ev_document_doc_mutex_unlock ();
6517 /* FIXME: update annot region only */
6518 ev_view_reload (EV_VIEW (window->priv->view));
6521 gtk_widget_destroy (GTK_WIDGET (dialog));
6525 ev_attachment_popup_cmd_open_attachment (GtkAction *action, EvWindow *window)
6530 if (!window->priv->attach_list)
6533 screen = gtk_window_get_screen (GTK_WINDOW (window));
6535 for (l = window->priv->attach_list; l && l->data; l = g_list_next (l)) {
6536 EvAttachment *attachment;
6537 GError *error = NULL;
6539 attachment = (EvAttachment *) l->data;
6541 ev_attachment_open (attachment, screen, gtk_get_current_event_time (), &error);
6544 ev_window_error_message (window, error,
6545 "%s", _("Unable to open attachment"));
6546 g_error_free (error);
6552 attachment_save_dialog_response_cb (GtkWidget *fc,
6554 EvWindow *ev_window)
6559 GtkFileChooserAction fc_action;
6563 if (response_id != GTK_RESPONSE_OK) {
6564 gtk_widget_destroy (fc);
6568 uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
6569 target_file = g_file_new_for_uri (uri);
6570 g_object_get (G_OBJECT (fc), "action", &fc_action, NULL);
6571 is_dir = (fc_action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
6572 is_native = g_file_is_native (target_file);
6574 for (l = ev_window->priv->attach_list; l && l->data; l = g_list_next (l)) {
6575 EvAttachment *attachment;
6576 GFile *save_to = NULL;
6577 GError *error = NULL;
6579 attachment = (EvAttachment *) l->data;
6583 save_to = g_file_get_child (target_file,
6584 /* FIXMEchpe: file name encoding! */
6585 ev_attachment_get_name (attachment));
6587 save_to = g_object_ref (target_file);
6590 save_to = ev_mkstemp_file ("saveattachment.XXXXXX", &error);
6594 ev_attachment_save (attachment, save_to, &error);
6597 ev_window_error_message (ev_window, error,
6598 "%s", _("The attachment could not be saved."));
6599 g_error_free (error);
6600 g_object_unref (save_to);
6609 dest_file = g_file_get_child (target_file,
6610 ev_attachment_get_name (attachment));
6612 dest_file = g_object_ref (target_file);
6615 ev_window_save_remote (ev_window, EV_SAVE_ATTACHMENT,
6616 save_to, dest_file);
6618 g_object_unref (dest_file);
6621 g_object_unref (save_to);
6625 g_object_unref (target_file);
6627 gtk_widget_destroy (fc);
6631 ev_attachment_popup_cmd_save_attachment_as (GtkAction *action, EvWindow *window)
6634 EvAttachment *attachment = NULL;
6636 if (!window->priv->attach_list)
6639 if (g_list_length (window->priv->attach_list) == 1)
6640 attachment = (EvAttachment *) window->priv->attach_list->data;
6642 fc = gtk_file_chooser_dialog_new (
6643 _("Save Attachment"),
6644 GTK_WINDOW (window),
6645 attachment ? GTK_FILE_CHOOSER_ACTION_SAVE : GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
6647 GTK_RESPONSE_CANCEL,
6648 GTK_STOCK_SAVE, GTK_RESPONSE_OK,
6651 gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
6652 gtk_dialog_set_alternative_button_order (GTK_DIALOG (fc),
6654 GTK_RESPONSE_CANCEL,
6657 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
6658 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (fc), FALSE);
6661 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc),
6662 ev_attachment_get_name (attachment));
6664 g_signal_connect (fc, "response",
6665 G_CALLBACK (attachment_save_dialog_response_cb),
6668 gtk_widget_show (fc);
6672 ev_window_media_player_key_pressed (EvWindow *window,
6676 if (!gtk_window_is_active (GTK_WINDOW (window)))
6679 /* Note how Previous/Next only go to the
6680 * next/previous page despite their icon telling you
6681 * they should go to the beginning/end.
6683 * There's very few keyboards with FFW/RWD though,
6684 * so we stick the most useful keybinding on the most
6687 if (strcmp (key, "Play") == 0) {
6688 ev_window_run_presentation (window);
6689 } else if (strcmp (key, "Previous") == 0) {
6690 ev_window_cmd_go_previous_page (NULL, window);
6691 } else if (strcmp (key, "Next") == 0) {
6692 ev_window_cmd_go_next_page (NULL, window);
6693 } else if (strcmp (key, "FastForward") == 0) {
6694 ev_window_cmd_go_last_page (NULL, window);
6695 } else if (strcmp (key, "Rewind") == 0) {
6696 ev_window_cmd_go_first_page (NULL, window);
6700 static EggToolbarsModel *
6701 get_toolbars_model (void)
6703 EggToolbarsModel *toolbars_model;
6704 gchar *toolbars_file;
6705 gchar *toolbars_path;
6708 toolbars_model = egg_toolbars_model_new ();
6710 toolbars_file = g_build_filename (ev_application_get_dot_dir (EV_APP, FALSE),
6711 "evince_toolbar.xml", NULL);
6712 toolbars_path = g_build_filename (ev_application_get_data_dir (EV_APP),
6713 "evince-toolbar.xml", NULL);
6714 egg_toolbars_model_load_names (toolbars_model, toolbars_path);
6716 if (!egg_toolbars_model_load_toolbars (toolbars_model, toolbars_file)) {
6717 egg_toolbars_model_load_toolbars (toolbars_model, toolbars_path);
6718 goto skip_conversion;
6721 /* Open item doesn't exist anymore,
6722 * convert it to OpenRecent for compatibility
6724 for (i = 0; i < egg_toolbars_model_n_items (toolbars_model, 0); i++) {
6727 item = egg_toolbars_model_item_nth (toolbars_model, 0, i);
6728 if (g_ascii_strcasecmp (item, "FileOpen") == 0) {
6729 egg_toolbars_model_remove_item (toolbars_model, 0, i);
6730 egg_toolbars_model_add_item (toolbars_model, 0, i,
6732 egg_toolbars_model_save_toolbars (toolbars_model, toolbars_file, "1.0");
6738 g_free (toolbars_file);
6739 g_free (toolbars_path);
6741 egg_toolbars_model_set_flags (toolbars_model, 0, EGG_TB_MODEL_NOT_REMOVABLE);
6743 return toolbars_model;
6748 ev_window_sync_source (EvWindow *window,
6751 GDBusConnection *connection;
6752 GError *error = NULL;
6757 if (window->priv->dbus_object_id <= 0)
6760 connection = ev_application_get_dbus_connection (EV_APP);
6764 timestamp = gtk_get_current_event_time ();
6765 if (g_path_is_absolute (link->filename)) {
6766 input_gfile = g_file_new_for_path (link->filename);
6768 GFile *gfile, *parent_gfile;
6770 gfile = g_file_new_for_uri (window->priv->uri);
6771 parent_gfile = g_file_get_parent (gfile);
6773 /* parent_gfile should never be NULL */
6774 if (parent_gfile == NULL) {
6775 g_printerr ("Document URI is '/'\n");
6779 input_gfile = g_file_get_child (parent_gfile, link->filename);
6780 g_object_unref (parent_gfile);
6781 g_object_unref (gfile);
6784 uri_input = g_file_get_uri (input_gfile);
6785 g_object_unref (input_gfile);
6787 g_dbus_connection_emit_signal (connection,
6789 window->priv->dbus_object_path,
6790 EV_WINDOW_DBUS_INTERFACE,
6792 g_variant_new ("(s(ii)u)",
6800 g_printerr ("Failed to emit DBus signal SyncSource: %s\n",
6802 g_error_free (error);
6807 ev_window_emit_closed (EvWindow *window)
6809 GDBusConnection *connection;
6810 GError *error = NULL;
6812 if (window->priv->dbus_object_id <= 0)
6815 connection = ev_application_get_dbus_connection (EV_APP);
6819 g_dbus_connection_emit_signal (connection,
6821 window->priv->dbus_object_path,
6822 EV_WINDOW_DBUS_INTERFACE,
6827 g_printerr ("Failed to emit DBus signal Closed: %s\n",
6829 g_error_free (error);
6834 /* If this is the last window call g_dbus_connection_flush_sync()
6835 * to make sure the signal is emitted.
6837 if (ev_application_get_n_windows (EV_APP) == 1)
6838 g_dbus_connection_flush_sync (connection, NULL, NULL);
6842 ev_window_emit_doc_loaded (EvWindow *window)
6844 GDBusConnection *connection;
6845 GError *error = NULL;
6847 if (window->priv->dbus_object_id <= 0)
6850 connection = ev_application_get_dbus_connection (EV_APP);
6854 g_dbus_connection_emit_signal (connection,
6856 window->priv->dbus_object_path,
6857 EV_WINDOW_DBUS_INTERFACE,
6859 g_variant_new("(s)", window->priv->uri),
6862 g_printerr ("Failed to emit DBus signal DocumentLoaded: %s\n",
6864 g_error_free (error);
6871 method_call_cb (GDBusConnection *connection,
6872 const gchar *sender,
6873 const gchar *object_path,
6874 const gchar *interface_name,
6875 const gchar *method_name,
6876 GVariant *parameters,
6877 GDBusMethodInvocation *invocation,
6880 EvWindow *window = EV_WINDOW (user_data);
6882 if (g_strcmp0 (method_name, "SyncView") != 0)
6885 if (window->priv->document && ev_document_has_synctex (window->priv->document)) {
6889 g_variant_get (parameters, "(&s(ii)u)", &link.filename, &link.line, &link.col, ×tamp);
6890 ev_view_highlight_forward_search (EV_VIEW (window->priv->view), &link);
6891 gtk_window_present_with_time (GTK_WINDOW (window), timestamp);
6894 g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
6897 static const char introspection_xml[] =
6899 "<interface name='org.gnome.evince.Window'>"
6900 "<method name='SyncView'>"
6901 "<arg type='s' name='source_file' direction='in'/>"
6902 "<arg type='(ii)' name='source_point' direction='in'/>"
6903 "<arg type='u' name='timestamp' direction='in'/>"
6905 "<signal name='SyncSource'>"
6906 "<arg type='s' name='source_file' direction='out'/>"
6907 "<arg type='(ii)' name='source_point' direction='out'/>"
6908 "<arg type='u' name='timestamp' direction='out'/>"
6910 "<signal name='Closed'/>"
6911 "<signal name='DocumentLoaded'>"
6912 "<arg type='s' name='uri' direction='out'/>"
6917 static const GDBusInterfaceVTable interface_vtable = {
6923 static GDBusNodeInfo *introspection_data;
6924 #endif /* ENABLE_DBUS */
6927 ev_window_init (EvWindow *ev_window)
6929 GtkActionGroup *action_group;
6930 GtkAccelGroup *accel_group;
6931 GError *error = NULL;
6932 GtkWidget *sidebar_widget;
6933 GtkWidget *menuitem;
6934 EggToolbarsModel *toolbars_model;
6938 GDBusConnection *connection;
6939 static gint window_id = 0;
6942 g_signal_connect (ev_window, "configure_event",
6943 G_CALLBACK (window_configure_event_cb), NULL);
6944 g_signal_connect (ev_window, "window_state_event",
6945 G_CALLBACK (window_state_event_cb), NULL);
6947 ev_window->priv = EV_WINDOW_GET_PRIVATE (ev_window);
6950 connection = ev_application_get_dbus_connection (EV_APP);
6952 if (!introspection_data) {
6953 introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, &error);
6954 if (error) g_warning ("%s\n", error->message);
6956 g_assert (introspection_data != NULL);
6958 ev_window->priv->dbus_object_path = g_strdup_printf (EV_WINDOW_DBUS_OBJECT_PATH, window_id++);
6959 ev_window->priv->dbus_object_id =
6960 g_dbus_connection_register_object (connection,
6961 ev_window->priv->dbus_object_path,
6962 introspection_data->interfaces[0],
6966 if (ev_window->priv->dbus_object_id == 0) {
6967 g_printerr ("Failed to register bus object %s: %s\n",
6968 ev_window->priv->dbus_object_path, error->message);
6969 g_error_free (error);
6970 g_free (ev_window->priv->dbus_object_path);
6971 ev_window->priv->dbus_object_path = NULL;
6976 #endif /* ENABLE_DBUS */
6978 ev_window->priv->model = ev_document_model_new ();
6980 ev_window->priv->page_mode = PAGE_MODE_DOCUMENT;
6981 ev_window->priv->title = ev_window_title_new (ev_window);
6983 ev_window->priv->main_box = gtk_vbox_new (FALSE, 0);
6984 gtk_container_add (GTK_CONTAINER (ev_window), ev_window->priv->main_box);
6985 gtk_widget_show (ev_window->priv->main_box);
6987 action_group = gtk_action_group_new ("MenuActions");
6988 ev_window->priv->action_group = action_group;
6989 gtk_action_group_set_translation_domain (action_group, NULL);
6990 gtk_action_group_add_actions (action_group, entries,
6991 G_N_ELEMENTS (entries), ev_window);
6992 gtk_action_group_add_toggle_actions (action_group, toggle_entries,
6993 G_N_ELEMENTS (toggle_entries),
6995 set_action_properties (action_group);
6996 register_custom_actions (ev_window, action_group);
6998 ev_window->priv->ui_manager = gtk_ui_manager_new ();
6999 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
7003 gtk_ui_manager_get_accel_group (ev_window->priv->ui_manager);
7004 gtk_window_add_accel_group (GTK_WINDOW (ev_window), accel_group);
7006 ev_window_set_view_accels_sensitivity (ev_window, FALSE);
7008 action_group = gtk_action_group_new ("ViewPopupActions");
7009 ev_window->priv->view_popup_action_group = action_group;
7010 gtk_action_group_set_translation_domain (action_group, NULL);
7011 gtk_action_group_add_actions (action_group, view_popup_entries,
7012 G_N_ELEMENTS (view_popup_entries),
7014 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
7017 action_group = gtk_action_group_new ("AttachmentPopupActions");
7018 ev_window->priv->attachment_popup_action_group = action_group;
7019 gtk_action_group_set_translation_domain (action_group, NULL);
7020 gtk_action_group_add_actions (action_group, attachment_popup_entries,
7021 G_N_ELEMENTS (attachment_popup_entries),
7023 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
7026 ui_path = g_build_filename (ev_application_get_data_dir (EV_APP),
7027 "evince-ui.xml", NULL);
7028 if (!gtk_ui_manager_add_ui_from_file (
7029 ev_window->priv->ui_manager, ui_path, &error))
7031 g_warning ("building menus failed: %s", error->message);
7032 g_error_free (error);
7036 ev_window->priv->recent_manager = gtk_recent_manager_get_default ();
7037 ev_window->priv->recent_action_group = NULL;
7038 ev_window->priv->recent_ui_id = 0;
7039 g_signal_connect_swapped (ev_window->priv->recent_manager,
7041 G_CALLBACK (ev_window_setup_recent),
7044 ev_window->priv->menubar =
7045 gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
7047 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box),
7048 ev_window->priv->menubar,
7050 menuitem = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
7051 "/MainMenu/EditMenu/EditRotateLeftMenu");
7052 gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menuitem), TRUE);
7053 menuitem = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
7054 "/MainMenu/EditMenu/EditRotateRightMenu");
7055 gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menuitem), TRUE);
7057 toolbars_model = get_toolbars_model ();
7058 ev_window->priv->toolbar = GTK_WIDGET
7059 (g_object_new (EGG_TYPE_EDITABLE_TOOLBAR,
7060 "ui-manager", ev_window->priv->ui_manager,
7061 "popup-path", "/ToolbarPopup",
7062 "model", toolbars_model,
7064 g_object_unref (toolbars_model);
7066 egg_editable_toolbar_show (EGG_EDITABLE_TOOLBAR (ev_window->priv->toolbar),
7068 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box),
7069 ev_window->priv->toolbar,
7071 gtk_widget_show (ev_window->priv->toolbar);
7073 /* Add the main area */
7074 ev_window->priv->hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
7075 g_signal_connect (ev_window->priv->hpaned,
7077 G_CALLBACK (ev_window_sidebar_position_change_cb),
7080 gtk_paned_set_position (GTK_PANED (ev_window->priv->hpaned), SIDEBAR_DEFAULT_SIZE);
7081 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), ev_window->priv->hpaned,
7083 gtk_widget_show (ev_window->priv->hpaned);
7085 ev_window->priv->sidebar = ev_sidebar_new ();
7086 ev_sidebar_set_model (EV_SIDEBAR (ev_window->priv->sidebar),
7087 ev_window->priv->model);
7088 gtk_paned_pack1 (GTK_PANED (ev_window->priv->hpaned),
7089 ev_window->priv->sidebar, FALSE, FALSE);
7090 gtk_widget_show (ev_window->priv->sidebar);
7092 /* Stub sidebar, for now */
7094 sidebar_widget = ev_sidebar_thumbnails_new ();
7095 ev_window->priv->sidebar_thumbs = sidebar_widget;
7096 g_signal_connect (sidebar_widget,
7097 "notify::main-widget",
7098 G_CALLBACK (sidebar_page_main_widget_update_cb),
7100 sidebar_page_main_widget_update_cb (G_OBJECT (sidebar_widget), NULL, ev_window);
7101 gtk_widget_show (sidebar_widget);
7102 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7105 sidebar_widget = ev_sidebar_links_new ();
7106 ev_window->priv->sidebar_links = sidebar_widget;
7107 g_signal_connect (sidebar_widget,
7109 G_CALLBACK (sidebar_widget_model_set),
7111 g_signal_connect (sidebar_widget,
7113 G_CALLBACK (sidebar_links_link_activated_cb),
7115 sidebar_page_main_widget_update_cb (G_OBJECT (sidebar_widget), NULL, ev_window);
7116 gtk_widget_show (sidebar_widget);
7117 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7120 sidebar_widget = ev_sidebar_attachments_new ();
7121 ev_window->priv->sidebar_attachments = sidebar_widget;
7122 g_signal_connect_object (sidebar_widget,
7124 G_CALLBACK (attachment_bar_menu_popup_cb),
7126 gtk_widget_show (sidebar_widget);
7127 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7130 sidebar_widget = ev_sidebar_layers_new ();
7131 ev_window->priv->sidebar_layers = sidebar_widget;
7132 g_signal_connect (sidebar_widget,
7133 "layers_visibility_changed",
7134 G_CALLBACK (sidebar_layers_visibility_changed),
7136 gtk_widget_show (sidebar_widget);
7137 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7140 sidebar_widget = ev_sidebar_annotations_new ();
7141 ev_window->priv->sidebar_annots = sidebar_widget;
7142 g_signal_connect (sidebar_widget,
7144 G_CALLBACK (sidebar_annots_annot_activated_cb),
7146 g_signal_connect (sidebar_widget,
7148 G_CALLBACK (sidebar_annots_begin_annot_add),
7150 g_signal_connect (sidebar_widget,
7151 "annot_add_cancelled",
7152 G_CALLBACK (sidebar_annots_annot_add_cancelled),
7154 gtk_widget_show (sidebar_widget);
7155 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7158 sidebar_widget = ev_sidebar_bookmarks_new ();
7159 ev_window->priv->sidebar_bookmarks = sidebar_widget;
7160 g_signal_connect (sidebar_widget,
7162 G_CALLBACK (sidebar_bookmarks_add_bookmark),
7164 gtk_widget_show (sidebar_widget);
7165 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7168 ev_window->priv->view_box = gtk_vbox_new (FALSE, 0);
7169 ev_window->priv->scrolled_window =
7170 GTK_WIDGET (g_object_new (GTK_TYPE_SCROLLED_WINDOW,
7171 "shadow-type", GTK_SHADOW_IN,
7173 gtk_box_pack_start (GTK_BOX (ev_window->priv->view_box),
7174 ev_window->priv->scrolled_window,
7176 gtk_widget_show (ev_window->priv->scrolled_window);
7178 gtk_paned_add2 (GTK_PANED (ev_window->priv->hpaned),
7179 ev_window->priv->view_box);
7180 gtk_widget_show (ev_window->priv->view_box);
7182 ev_window->priv->view = ev_view_new ();
7183 ev_view_set_page_cache_size (EV_VIEW (ev_window->priv->view), PAGE_CACHE_SIZE);
7184 ev_view_set_model (EV_VIEW (ev_window->priv->view), ev_window->priv->model);
7186 ev_window->priv->password_view = ev_password_view_new (GTK_WINDOW (ev_window));
7187 g_signal_connect_swapped (ev_window->priv->password_view,
7189 G_CALLBACK (ev_window_password_view_unlock),
7191 g_signal_connect_object (ev_window->priv->view, "focus_in_event",
7192 G_CALLBACK (view_actions_focus_in_cb),
7194 g_signal_connect_object (ev_window->priv->view, "focus_out_event",
7195 G_CALLBACK (view_actions_focus_out_cb),
7197 g_signal_connect_object (ev_window->priv->view, "external-link",
7198 G_CALLBACK (view_external_link_cb),
7200 g_signal_connect_object (ev_window->priv->view, "handle-link",
7201 G_CALLBACK (view_handle_link_cb),
7203 g_signal_connect_object (ev_window->priv->view, "popup",
7204 G_CALLBACK (view_menu_popup_cb),
7206 g_signal_connect_object (ev_window->priv->view, "selection-changed",
7207 G_CALLBACK (view_selection_changed_cb),
7209 g_signal_connect_object (ev_window->priv->view, "annot-added",
7210 G_CALLBACK (view_annot_added),
7212 g_signal_connect_object (ev_window->priv->view, "layers-changed",
7213 G_CALLBACK (view_layers_changed_cb),
7216 g_signal_connect_swapped (ev_window->priv->view, "sync-source",
7217 G_CALLBACK (ev_window_sync_source),
7220 gtk_widget_show (ev_window->priv->view);
7221 gtk_widget_show (ev_window->priv->password_view);
7224 ev_window->priv->find_bar = egg_find_bar_new ();
7225 gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
7226 ev_window->priv->find_bar,
7229 /* We own a ref on these widgets, as we can swap them in and out */
7230 g_object_ref (ev_window->priv->view);
7231 g_object_ref (ev_window->priv->password_view);
7233 gtk_container_add (GTK_CONTAINER (ev_window->priv->scrolled_window),
7234 ev_window->priv->view);
7236 /* Connect to model signals */
7237 g_signal_connect_swapped (ev_window->priv->model,
7239 G_CALLBACK (ev_window_page_changed_cb),
7241 g_signal_connect (ev_window->priv->model,
7243 G_CALLBACK (ev_window_document_changed_cb),
7245 g_signal_connect (ev_window->priv->model,
7247 G_CALLBACK (ev_window_zoom_changed_cb),
7249 g_signal_connect (ev_window->priv->model,
7250 "notify::sizing-mode",
7251 G_CALLBACK (ev_window_sizing_mode_changed_cb),
7253 g_signal_connect (ev_window->priv->model,
7255 G_CALLBACK (ev_window_rotation_changed_cb),
7257 g_signal_connect (ev_window->priv->model,
7258 "notify::continuous",
7259 G_CALLBACK (ev_window_continuous_changed_cb),
7261 g_signal_connect (ev_window->priv->model,
7262 "notify::dual-page",
7263 G_CALLBACK (ev_window_dual_mode_changed_cb),
7265 g_signal_connect (ev_window->priv->model,
7266 "notify::inverted-colors",
7267 G_CALLBACK (ev_window_inverted_colors_changed_cb),
7270 /* Connect sidebar signals */
7271 g_signal_connect (ev_window->priv->sidebar,
7273 G_CALLBACK (ev_window_sidebar_visibility_changed_cb),
7275 g_signal_connect (ev_window->priv->sidebar,
7276 "notify::current-page",
7277 G_CALLBACK (ev_window_sidebar_current_page_changed_cb),
7280 /* Connect to find bar signals */
7281 g_signal_connect (ev_window->priv->find_bar,
7283 G_CALLBACK (find_bar_previous_cb),
7285 g_signal_connect (ev_window->priv->find_bar,
7287 G_CALLBACK (find_bar_next_cb),
7289 g_signal_connect (ev_window->priv->find_bar,
7291 G_CALLBACK (find_bar_close_cb),
7293 g_signal_connect (ev_window->priv->find_bar,
7294 "notify::search-string",
7295 G_CALLBACK (find_bar_search_changed_cb),
7297 g_signal_connect (ev_window->priv->find_bar,
7298 "notify::case-sensitive",
7299 G_CALLBACK (find_bar_search_changed_cb),
7301 g_signal_connect (ev_window->priv->find_bar,
7303 G_CALLBACK (find_bar_visibility_changed_cb),
7305 g_signal_connect (ev_window->priv->find_bar,
7307 G_CALLBACK (find_bar_scroll),
7311 ev_window->priv->view_popup = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
7313 ev_window->priv->link = NULL;
7315 ev_window->priv->attachment_popup = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
7316 "/AttachmentPopup");
7317 ev_window->priv->attach_list = NULL;
7319 /* Media player keys */
7320 mpkeys = ev_application_get_media_keys (EV_APP);
7322 g_signal_connect_swapped (mpkeys, "key_pressed",
7323 G_CALLBACK (ev_window_media_player_key_pressed),
7327 /* Give focus to the document view */
7328 gtk_widget_grab_focus (ev_window->priv->view);
7330 ev_window->priv->default_settings = g_settings_new (GS_SCHEMA_NAME".Default");
7331 g_settings_delay (ev_window->priv->default_settings);
7333 /* Set it user interface params */
7334 ev_window_setup_recent (ev_window);
7336 ev_window_setup_gtk_settings (ev_window);
7338 setup_chrome_from_metadata (ev_window);
7339 update_chrome_actions (ev_window);
7340 update_chrome_visibility (ev_window);
7342 gtk_window_set_default_size (GTK_WINDOW (ev_window), 600, 600);
7344 setup_view_from_metadata (ev_window);
7345 setup_sidebar_from_metadata (ev_window);
7347 ev_window_sizing_mode_changed_cb (ev_window->priv->model, NULL, ev_window);
7348 ev_window_setup_action_sensitivity (ev_window);
7351 gtk_drag_dest_set (GTK_WIDGET (ev_window),
7352 GTK_DEST_DEFAULT_ALL,
7355 gtk_drag_dest_add_uri_targets (GTK_WIDGET (ev_window));
7361 * Creates a #GtkWidget that represents the window.
7363 * Returns: the #GtkWidget that represents the window.
7366 ev_window_new (void)
7368 GtkWidget *ev_window;
7370 ev_window = GTK_WIDGET (g_object_new (EV_TYPE_WINDOW,
7371 "type", GTK_WINDOW_TOPLEVEL,
7378 ev_window_get_dbus_object_path (EvWindow *ev_window)
7381 return ev_window->priv->dbus_object_path;