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 GtkCssProvider *provider;
3849 gtk_widget_set_name (toolbar, "ev-fullscreen-toolbar");
3851 provider = gtk_css_provider_new ();
3852 gtk_css_provider_load_from_data (provider,
3853 "#ev-fullscreen-toolbar {\n"
3854 " -GtkToolbar-shadow-type: none; }",
3856 gtk_style_context_add_provider (gtk_widget_get_style_context (toolbar),
3857 GTK_STYLE_PROVIDER (provider),
3858 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
3859 g_object_unref (provider);
3863 ev_window_run_fullscreen (EvWindow *window)
3865 gboolean fullscreen_window = TRUE;
3867 if (ev_document_model_get_fullscreen (window->priv->model))
3870 if (!window->priv->fullscreen_toolbar) {
3871 window->priv->fullscreen_toolbar =
3872 gtk_ui_manager_get_widget (window->priv->ui_manager,
3873 "/FullscreenToolbar");
3875 gtk_toolbar_set_style (GTK_TOOLBAR (window->priv->fullscreen_toolbar),
3876 GTK_TOOLBAR_BOTH_HORIZ);
3877 fullscreen_toolbar_remove_shadow (window->priv->fullscreen_toolbar);
3878 fullscreen_toolbar_setup_item_properties (window->priv->ui_manager);
3880 gtk_box_pack_start (GTK_BOX (window->priv->main_box),
3881 window->priv->fullscreen_toolbar,
3883 gtk_box_reorder_child (GTK_BOX (window->priv->main_box),
3884 window->priv->fullscreen_toolbar, 1);
3887 if (EV_WINDOW_IS_PRESENTATION (window)) {
3888 ev_window_stop_presentation (window, FALSE);
3889 fullscreen_window = FALSE;
3892 g_object_set (G_OBJECT (window->priv->scrolled_window),
3893 "shadow-type", GTK_SHADOW_NONE,
3896 ev_document_model_set_fullscreen (window->priv->model, TRUE);
3897 ev_window_update_fullscreen_action (window);
3899 /* If the user doesn't have the main toolbar he/she won't probably want
3900 * the toolbar in fullscreen mode. See bug #483048
3902 update_chrome_flag (window, EV_CHROME_FULLSCREEN_TOOLBAR,
3903 (window->priv->chrome & EV_CHROME_TOOLBAR) != 0);
3904 update_chrome_visibility (window);
3906 if (fullscreen_window)
3907 gtk_window_fullscreen (GTK_WINDOW (window));
3908 gtk_widget_grab_focus (window->priv->view);
3910 if (window->priv->metadata && !ev_window_is_empty (window))
3911 ev_metadata_set_boolean (window->priv->metadata, "fullscreen", TRUE);
3915 ev_window_stop_fullscreen (EvWindow *window,
3916 gboolean unfullscreen_window)
3918 if (!ev_document_model_get_fullscreen (window->priv->model))
3921 g_object_set (G_OBJECT (window->priv->scrolled_window),
3922 "shadow-type", GTK_SHADOW_IN,
3925 ev_document_model_set_fullscreen (window->priv->model, FALSE);
3926 ev_window_update_fullscreen_action (window);
3927 update_chrome_flag (window, EV_CHROME_FULLSCREEN_TOOLBAR, FALSE);
3928 update_chrome_visibility (window);
3929 if (unfullscreen_window)
3930 gtk_window_unfullscreen (GTK_WINDOW (window));
3932 if (window->priv->metadata && !ev_window_is_empty (window))
3933 ev_metadata_set_boolean (window->priv->metadata, "fullscreen", FALSE);
3937 ev_window_cmd_view_fullscreen (GtkAction *action, EvWindow *window)
3939 gboolean fullscreen;
3941 fullscreen = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
3943 ev_window_run_fullscreen (window);
3945 ev_window_stop_fullscreen (window, TRUE);
3950 ev_window_update_presentation_action (EvWindow *window)
3954 action = gtk_action_group_get_action (window->priv->action_group, "ViewPresentation");
3955 g_signal_handlers_block_by_func
3956 (action, G_CALLBACK (ev_window_cmd_view_presentation), window);
3957 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
3958 EV_WINDOW_IS_PRESENTATION (window));
3959 g_signal_handlers_unblock_by_func
3960 (action, G_CALLBACK (ev_window_cmd_view_presentation), window);
3964 ev_window_view_presentation_finished (EvWindow *window)
3966 ev_window_stop_presentation (window, TRUE);
3970 ev_window_run_presentation (EvWindow *window)
3972 gboolean fullscreen_window = TRUE;
3975 gboolean inverted_colors;
3977 if (EV_WINDOW_IS_PRESENTATION (window))
3980 if (ev_document_model_get_fullscreen (window->priv->model)) {
3981 ev_window_stop_fullscreen (window, FALSE);
3982 fullscreen_window = FALSE;
3985 current_page = ev_document_model_get_page (window->priv->model);
3986 rotation = ev_document_model_get_rotation (window->priv->model);
3987 inverted_colors = ev_document_model_get_inverted_colors (window->priv->model);
3988 window->priv->presentation_view = ev_view_presentation_new (window->priv->document,
3992 g_signal_connect_swapped (window->priv->presentation_view, "finished",
3993 G_CALLBACK (ev_window_view_presentation_finished),
3996 gtk_box_pack_start (GTK_BOX (window->priv->main_box),
3997 window->priv->presentation_view,
4000 gtk_widget_hide (window->priv->hpaned);
4001 ev_window_update_presentation_action (window);
4002 update_chrome_visibility (window);
4004 gtk_widget_grab_focus (window->priv->presentation_view);
4005 if (fullscreen_window)
4006 gtk_window_fullscreen (GTK_WINDOW (window));
4008 gtk_widget_show (window->priv->presentation_view);
4010 ev_application_screensaver_disable (EV_APP);
4012 if (window->priv->metadata && !ev_window_is_empty (window))
4013 ev_metadata_set_boolean (window->priv->metadata, "presentation", TRUE);
4017 ev_window_stop_presentation (EvWindow *window,
4018 gboolean unfullscreen_window)
4022 if (!EV_WINDOW_IS_PRESENTATION (window))
4025 current_page = ev_view_presentation_get_current_page (EV_VIEW_PRESENTATION (window->priv->presentation_view));
4026 ev_document_model_set_page (window->priv->model, current_page);
4028 gtk_container_remove (GTK_CONTAINER (window->priv->main_box),
4029 window->priv->presentation_view);
4030 window->priv->presentation_view = NULL;
4032 gtk_widget_show (window->priv->hpaned);
4033 ev_window_update_presentation_action (window);
4034 update_chrome_visibility (window);
4035 if (unfullscreen_window)
4036 gtk_window_unfullscreen (GTK_WINDOW (window));
4038 gtk_widget_grab_focus (window->priv->view);
4040 ev_application_screensaver_enable (EV_APP);
4042 if (window->priv->metadata && !ev_window_is_empty (window))
4043 ev_metadata_set_boolean (window->priv->metadata, "presentation", FALSE);
4047 ev_window_cmd_view_presentation (GtkAction *action, EvWindow *window)
4049 gboolean presentation;
4051 presentation = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
4053 ev_window_run_presentation (window);
4058 ev_window_setup_gtk_settings (EvWindow *window)
4060 GtkSettings *settings;
4062 gchar *menubar_accel_accel;
4064 screen = gtk_window_get_screen (GTK_WINDOW (window));
4065 settings = gtk_settings_get_for_screen (screen);
4067 g_object_get (settings,
4068 "gtk-menu-bar-accel", &menubar_accel_accel,
4070 if (menubar_accel_accel != NULL && menubar_accel_accel[0] != '\0') {
4071 gtk_accelerator_parse (menubar_accel_accel,
4072 &window->priv->menubar_accel_keyval,
4073 &window->priv->menubar_accel_modifier);
4074 if (window->priv->menubar_accel_keyval == 0) {
4075 g_warning ("Failed to parse menu bar accelerator '%s'\n",
4076 menubar_accel_accel);
4079 window->priv->menubar_accel_keyval = 0;
4080 window->priv->menubar_accel_modifier = 0;
4083 g_free (menubar_accel_accel);
4087 ev_window_update_max_min_scale (EvWindow *window)
4091 gdouble min_width, min_height;
4092 gdouble width, height;
4094 gint rotation = ev_document_model_get_rotation (window->priv->model);
4096 if (!window->priv->document)
4099 dpi = get_screen_dpi (window) / 72.0;
4101 ev_document_get_min_page_size (window->priv->document, &min_width, &min_height);
4102 width = (rotation == 0 || rotation == 180) ? min_width : min_height;
4103 height = (rotation == 0 || rotation == 180) ? min_height : min_width;
4104 max_scale = sqrt (PAGE_CACHE_SIZE / (width * dpi * 4 * height * dpi));
4106 action = gtk_action_group_get_action (window->priv->action_group,
4107 ZOOM_CONTROL_ACTION);
4108 ephy_zoom_action_set_max_zoom_level (EPHY_ZOOM_ACTION (action), max_scale * dpi);
4110 ev_document_model_set_min_scale (window->priv->model, MIN_SCALE * dpi);
4111 ev_document_model_set_max_scale (window->priv->model, max_scale * dpi);
4115 ev_window_screen_changed (GtkWidget *widget,
4116 GdkScreen *old_screen)
4118 EvWindow *window = EV_WINDOW (widget);
4121 screen = gtk_widget_get_screen (widget);
4122 if (screen == old_screen)
4125 ev_window_setup_gtk_settings (window);
4126 ev_window_update_max_min_scale (window);
4128 if (GTK_WIDGET_CLASS (ev_window_parent_class)->screen_changed) {
4129 GTK_WIDGET_CLASS (ev_window_parent_class)->screen_changed (widget, old_screen);
4134 ev_window_state_event (GtkWidget *widget,
4135 GdkEventWindowState *event)
4137 EvWindow *window = EV_WINDOW (widget);
4139 if (GTK_WIDGET_CLASS (ev_window_parent_class)->window_state_event) {
4140 GTK_WIDGET_CLASS (ev_window_parent_class)->window_state_event (widget, event);
4143 if ((event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN) == 0)
4146 if (event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN) {
4147 if (ev_document_model_get_fullscreen (window->priv->model) || EV_WINDOW_IS_PRESENTATION (window))
4150 ev_window_run_fullscreen (window);
4152 if (ev_document_model_get_fullscreen (window->priv->model))
4153 ev_window_stop_fullscreen (window, FALSE);
4154 else if (EV_WINDOW_IS_PRESENTATION (window))
4155 ev_window_stop_presentation (window, FALSE);
4162 ev_window_set_page_mode (EvWindow *window,
4163 EvWindowPageMode page_mode)
4165 GtkWidget *child = NULL;
4166 GtkWidget *real_child;
4168 if (window->priv->page_mode == page_mode)
4171 window->priv->page_mode = page_mode;
4173 switch (page_mode) {
4174 case PAGE_MODE_DOCUMENT:
4175 child = window->priv->view;
4177 case PAGE_MODE_PASSWORD:
4178 child = window->priv->password_view;
4181 g_assert_not_reached ();
4184 real_child = gtk_bin_get_child (GTK_BIN (window->priv->scrolled_window));
4185 if (child != real_child) {
4186 gtk_container_remove (GTK_CONTAINER (window->priv->scrolled_window),
4188 gtk_container_add (GTK_CONTAINER (window->priv->scrolled_window),
4191 ev_window_update_actions (window);
4196 ev_window_cmd_edit_rotate_left (GtkAction *action, EvWindow *ev_window)
4198 gint rotation = ev_document_model_get_rotation (ev_window->priv->model);
4200 ev_document_model_set_rotation (ev_window->priv->model, rotation - 90);
4204 ev_window_cmd_edit_rotate_right (GtkAction *action, EvWindow *ev_window)
4206 gint rotation = ev_document_model_get_rotation (ev_window->priv->model);
4208 ev_document_model_set_rotation (ev_window->priv->model, rotation + 90);
4212 ev_window_cmd_view_inverted_colors (GtkAction *action, EvWindow *ev_window)
4214 gboolean inverted_colors = ev_document_model_get_inverted_colors (ev_window->priv->model);
4216 ev_document_model_set_inverted_colors (ev_window->priv->model, !inverted_colors);
4220 ev_window_cmd_edit_toolbar_cb (GtkDialog *dialog,
4222 EvWindow *ev_window)
4224 EggEditableToolbar *toolbar;
4225 gchar *toolbars_file;
4227 toolbar = EGG_EDITABLE_TOOLBAR (ev_window->priv->toolbar);
4228 egg_editable_toolbar_set_edit_mode (toolbar, FALSE);
4230 toolbars_file = g_build_filename (ev_application_get_dot_dir (EV_APP, TRUE),
4231 "evince_toolbar.xml", NULL);
4232 egg_toolbars_model_save_toolbars (egg_editable_toolbar_get_model (toolbar),
4233 toolbars_file, "1.0");
4234 g_free (toolbars_file);
4236 gtk_widget_destroy (GTK_WIDGET (dialog));
4240 ev_window_cmd_edit_toolbar (GtkAction *action, EvWindow *ev_window)
4244 GtkWidget *content_area;
4245 EggEditableToolbar *toolbar;
4247 dialog = gtk_dialog_new_with_buttons (_("Toolbar Editor"),
4248 GTK_WINDOW (ev_window),
4249 GTK_DIALOG_DESTROY_WITH_PARENT,
4253 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
4254 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE);
4255 gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)), 5);
4256 gtk_box_set_spacing (GTK_BOX (content_area), 2);
4257 gtk_window_set_default_size (GTK_WINDOW (dialog), 500, 400);
4259 toolbar = EGG_EDITABLE_TOOLBAR (ev_window->priv->toolbar);
4260 editor = egg_toolbar_editor_new (ev_window->priv->ui_manager,
4261 egg_editable_toolbar_get_model (toolbar));
4263 gtk_container_set_border_width (GTK_CONTAINER (editor), 5);
4264 gtk_box_set_spacing (GTK_BOX (EGG_TOOLBAR_EDITOR (editor)), 5);
4266 gtk_container_add (GTK_CONTAINER (content_area), editor);
4268 egg_editable_toolbar_set_edit_mode (toolbar, TRUE);
4270 g_signal_connect (dialog, "response",
4271 G_CALLBACK (ev_window_cmd_edit_toolbar_cb),
4273 gtk_widget_show_all (dialog);
4277 ev_window_cmd_edit_save_settings (GtkAction *action, EvWindow *ev_window)
4279 EvWindowPrivate *priv = ev_window->priv;
4280 EvDocumentModel *model = priv->model;
4281 GSettings *settings = priv->default_settings;
4283 g_settings_set_boolean (settings, "continuous",
4284 ev_document_model_get_continuous (model));
4285 g_settings_set_boolean (settings, "dual-page",
4286 ev_document_model_get_dual_page (model));
4287 g_settings_set_boolean (settings, "fullscreen",
4288 ev_document_model_get_fullscreen (model));
4289 g_settings_set_boolean (settings, "inverted-colors",
4290 ev_document_model_get_inverted_colors (model));
4291 g_settings_set_enum (settings, "sizing-mode",
4292 ev_document_model_get_sizing_mode (model));
4293 g_settings_set_boolean (settings, "show-toolbar",
4294 gtk_widget_get_visible (priv->toolbar));
4295 g_settings_set_boolean (settings, "show-sidebar",
4296 gtk_widget_get_visible (priv->sidebar));
4297 g_settings_set_int (settings, "sidebar-size",
4298 gtk_paned_get_position (GTK_PANED (priv->hpaned)));
4299 g_settings_set_string (settings, "sidebar-page",
4300 ev_window_sidebar_get_current_page_id (ev_window));
4301 g_settings_apply (settings);
4305 ev_window_cmd_view_zoom_in (GtkAction *action, EvWindow *ev_window)
4307 g_return_if_fail (EV_IS_WINDOW (ev_window));
4309 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FREE);
4310 ev_view_zoom_in (EV_VIEW (ev_window->priv->view));
4314 ev_window_cmd_view_zoom_out (GtkAction *action, EvWindow *ev_window)
4316 g_return_if_fail (EV_IS_WINDOW (ev_window));
4318 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FREE);
4319 ev_view_zoom_out (EV_VIEW (ev_window->priv->view));
4323 ev_window_cmd_go_previous_page (GtkAction *action, EvWindow *ev_window)
4325 g_return_if_fail (EV_IS_WINDOW (ev_window));
4327 ev_view_previous_page (EV_VIEW (ev_window->priv->view));
4331 ev_window_cmd_go_next_page (GtkAction *action, EvWindow *ev_window)
4333 g_return_if_fail (EV_IS_WINDOW (ev_window));
4335 ev_view_next_page (EV_VIEW (ev_window->priv->view));
4339 ev_window_cmd_go_first_page (GtkAction *action, EvWindow *ev_window)
4341 g_return_if_fail (EV_IS_WINDOW (ev_window));
4343 ev_document_model_set_page (ev_window->priv->model, 0);
4347 ev_window_cmd_go_last_page (GtkAction *action, EvWindow *ev_window)
4349 g_return_if_fail (EV_IS_WINDOW (ev_window));
4351 ev_document_model_set_page (ev_window->priv->model,
4352 ev_document_get_n_pages (ev_window->priv->document) - 1);
4356 ev_window_cmd_go_forward (GtkAction *action, EvWindow *ev_window)
4358 int n_pages, current_page;
4360 g_return_if_fail (EV_IS_WINDOW (ev_window));
4362 n_pages = ev_document_get_n_pages (ev_window->priv->document);
4363 current_page = ev_document_model_get_page (ev_window->priv->model);
4365 if (current_page + 10 < n_pages) {
4366 ev_document_model_set_page (ev_window->priv->model, current_page + 10);
4371 ev_window_cmd_go_backward (GtkAction *action, EvWindow *ev_window)
4375 g_return_if_fail (EV_IS_WINDOW (ev_window));
4377 current_page = ev_document_model_get_page (ev_window->priv->model);
4379 if (current_page - 10 >= 0) {
4380 ev_document_model_set_page (ev_window->priv->model, current_page - 10);
4385 ev_window_cmd_bookmark_activate (GtkAction *action,
4388 guint page = ev_bookmark_action_get_page (EV_BOOKMARK_ACTION (action));
4390 ev_document_model_set_page (window->priv->model, page);
4394 compare_bookmarks (EvBookmark *a,
4397 return strcmp (a->title, b->title);
4401 ev_window_setup_bookmarks (EvWindow *window)
4405 if (!window->priv->bookmarks)
4408 if (window->priv->bookmarks_ui_id > 0) {
4409 gtk_ui_manager_remove_ui (window->priv->ui_manager,
4410 window->priv->bookmarks_ui_id);
4411 gtk_ui_manager_ensure_update (window->priv->ui_manager);
4413 window->priv->bookmarks_ui_id = gtk_ui_manager_new_merge_id (window->priv->ui_manager);
4415 if (window->priv->bookmarks_action_group) {
4416 gtk_ui_manager_remove_action_group (window->priv->ui_manager,
4417 window->priv->bookmarks_action_group);
4418 g_object_unref (window->priv->bookmarks_action_group);
4420 window->priv->bookmarks_action_group = gtk_action_group_new ("BookmarksActions");
4421 gtk_ui_manager_insert_action_group (window->priv->ui_manager,
4422 window->priv->bookmarks_action_group, -1);
4424 items = ev_bookmarks_get_bookmarks (window->priv->bookmarks);
4425 items = g_list_sort (items, (GCompareFunc)compare_bookmarks);
4427 for (l = items; l && l->data; l = g_list_next (l)) {
4428 EvBookmark *bm = (EvBookmark *)l->data;
4431 action = ev_bookmark_action_new (bm);
4432 g_signal_connect (action, "activate",
4433 G_CALLBACK (ev_window_cmd_bookmark_activate),
4435 gtk_action_group_add_action (window->priv->bookmarks_action_group,
4438 gtk_ui_manager_add_ui (window->priv->ui_manager,
4439 window->priv->bookmarks_ui_id,
4440 "/MainMenu/BookmarksMenu/BookmarksItems",
4441 gtk_action_get_label (action),
4442 gtk_action_get_name (action),
4443 GTK_UI_MANAGER_MENUITEM,
4446 g_object_unref (action);
4449 g_list_free (items);
4453 ev_window_cmd_bookmarks_add (GtkAction *action,
4460 bm.page = ev_document_model_get_page (window->priv->model);
4461 page_label = ev_document_get_page_label (window->priv->document, bm.page);
4462 page_title = ev_window_get_page_title (window, page_label);
4463 bm.title = page_title ? page_title : g_strdup_printf (_("Page %s"), page_label);
4464 g_free (page_label);
4466 /* EvBookmarks takes ownership of bookmark */
4467 ev_bookmarks_add (window->priv->bookmarks, &bm);
4471 ev_window_cmd_view_reload (GtkAction *action, EvWindow *ev_window)
4473 ev_window_reload_document (ev_window, NULL);
4477 ev_window_cmd_view_autoscroll (GtkAction *action, EvWindow *ev_window)
4479 ev_view_autoscroll_start (EV_VIEW (ev_window->priv->view));
4482 #if OFFLINE_HELP_ENABLED
4483 #define EV_HELP "ghelp:evince"
4485 #define EV_HELP "http://library.gnome.org/users/evince/stable/"
4489 ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
4491 GError *error = NULL;
4493 gtk_show_uri (gtk_window_get_screen (GTK_WINDOW (ev_window)),
4495 gtk_get_current_event_time (),
4498 ev_window_error_message (ev_window, error,
4499 "%s", _("There was an error displaying help"));
4500 g_error_free (error);
4505 ev_window_cmd_leave_fullscreen (GtkAction *action, EvWindow *window)
4507 ev_window_stop_fullscreen (window, TRUE);
4511 ev_window_cmd_start_presentation (GtkAction *action, EvWindow *window)
4513 ev_window_run_presentation (window);
4517 ev_window_cmd_escape (GtkAction *action, EvWindow *window)
4521 ev_view_autoscroll_stop (EV_VIEW (window->priv->view));
4523 widget = gtk_window_get_focus (GTK_WINDOW (window));
4524 if (widget && gtk_widget_get_ancestor (widget, EGG_TYPE_FIND_BAR)) {
4525 update_chrome_flag (window, EV_CHROME_FINDBAR, FALSE);
4526 update_chrome_visibility (window);
4527 gtk_widget_grab_focus (window->priv->view);
4529 gboolean fullscreen;
4531 fullscreen = ev_document_model_get_fullscreen (window->priv->model);
4534 ev_window_stop_fullscreen (window, TRUE);
4535 } else if (EV_WINDOW_IS_PRESENTATION (window)) {
4536 ev_window_stop_presentation (window, TRUE);
4537 gtk_widget_grab_focus (window->priv->view);
4539 gtk_widget_grab_focus (window->priv->view);
4542 if (fullscreen && EV_WINDOW_IS_PRESENTATION (window))
4543 g_warning ("Both fullscreen and presentation set somehow");
4548 save_sizing_mode (EvWindow *window)
4551 GEnumValue *enum_value;
4553 if (!window->priv->metadata || ev_window_is_empty (window))
4556 mode = ev_document_model_get_sizing_mode (window->priv->model);
4557 enum_value = g_enum_get_value (g_type_class_peek (EV_TYPE_SIZING_MODE), mode);
4558 ev_metadata_set_string (window->priv->metadata, "sizing_mode",
4559 enum_value->value_nick);
4563 ev_window_document_changed_cb (EvDocumentModel *model,
4565 EvWindow *ev_window)
4567 ev_window_set_document (ev_window,
4568 ev_document_model_get_document (model));
4572 ev_window_sizing_mode_changed_cb (EvDocumentModel *model,
4574 EvWindow *ev_window)
4576 EvSizingMode sizing_mode = ev_document_model_get_sizing_mode (model);
4578 g_object_set (ev_window->priv->scrolled_window,
4579 "hscrollbar-policy",
4580 sizing_mode == EV_SIZING_FREE ?
4581 GTK_POLICY_AUTOMATIC : GTK_POLICY_NEVER,
4582 "vscrollbar-policy", GTK_POLICY_AUTOMATIC,
4585 update_sizing_buttons (ev_window);
4586 save_sizing_mode (ev_window);
4590 ev_window_zoom_changed_cb (EvDocumentModel *model, GParamSpec *pspec, EvWindow *ev_window)
4592 ev_window_update_actions (ev_window);
4594 if (!ev_window->priv->metadata)
4597 if (ev_document_model_get_sizing_mode (model) == EV_SIZING_FREE && !ev_window_is_empty (ev_window)) {
4600 zoom = ev_document_model_get_scale (model);
4601 zoom *= 72.0 / get_screen_dpi (ev_window);
4602 ev_metadata_set_double (ev_window->priv->metadata, "zoom", zoom);
4607 ev_window_update_continuous_action (EvWindow *window)
4611 action = gtk_action_group_get_action (window->priv->action_group, "ViewContinuous");
4612 g_signal_handlers_block_by_func
4613 (action, G_CALLBACK (ev_window_cmd_continuous), window);
4614 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
4615 ev_document_model_get_continuous (window->priv->model));
4616 g_signal_handlers_unblock_by_func
4617 (action, G_CALLBACK (ev_window_cmd_continuous), window);
4621 ev_window_update_dual_page_action (EvWindow *window)
4625 action = gtk_action_group_get_action (window->priv->action_group, "ViewDual");
4626 g_signal_handlers_block_by_func
4627 (action, G_CALLBACK (ev_window_cmd_dual), window);
4628 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
4629 ev_document_model_get_dual_page (window->priv->model));
4630 g_signal_handlers_unblock_by_func
4631 (action, G_CALLBACK (ev_window_cmd_dual), window);
4635 ev_window_continuous_changed_cb (EvDocumentModel *model,
4637 EvWindow *ev_window)
4639 ev_window_update_continuous_action (ev_window);
4641 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window))
4642 ev_metadata_set_boolean (ev_window->priv->metadata, "continuous",
4643 ev_document_model_get_continuous (model));
4647 ev_window_rotation_changed_cb (EvDocumentModel *model,
4651 gint rotation = ev_document_model_get_rotation (model);
4653 if (window->priv->metadata && !ev_window_is_empty (window))
4654 ev_metadata_set_int (window->priv->metadata, "rotation",
4657 ev_window_update_max_min_scale (window);
4658 ev_window_refresh_window_thumbnail (window);
4662 ev_window_update_inverted_colors_action (EvWindow *window)
4666 action = gtk_action_group_get_action (window->priv->action_group, "ViewInvertedColors");
4667 g_signal_handlers_block_by_func
4668 (action, G_CALLBACK (ev_window_cmd_view_inverted_colors), window);
4669 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
4670 ev_document_model_get_inverted_colors (window->priv->model));
4671 g_signal_handlers_unblock_by_func
4672 (action, G_CALLBACK (ev_window_cmd_view_inverted_colors), window);
4676 ev_window_inverted_colors_changed_cb (EvDocumentModel *model,
4680 gboolean inverted_colors = ev_document_model_get_inverted_colors (model);
4682 ev_window_update_inverted_colors_action (window);
4684 if (window->priv->metadata && !ev_window_is_empty (window))
4685 ev_metadata_set_boolean (window->priv->metadata, "inverted-colors",
4688 ev_window_refresh_window_thumbnail (window);
4692 ev_window_dual_mode_changed_cb (EvDocumentModel *model,
4694 EvWindow *ev_window)
4696 ev_window_update_dual_page_action (ev_window);
4698 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window))
4699 ev_metadata_set_boolean (ev_window->priv->metadata, "dual-page",
4700 ev_document_model_get_dual_page (model));
4704 build_comments_string (EvDocument *document)
4706 gchar *comments = NULL;
4707 EvDocumentBackendInfo info;
4709 if (document && ev_document_get_backend_info (document, &info)) {
4710 comments = g_strdup_printf (
4711 _("Document Viewer\nUsing %s (%s)"),
4712 info.name, info.version);
4714 comments = g_strdup_printf (
4715 _("Document Viewer"));
4722 ev_window_cmd_help_about (GtkAction *action, EvWindow *ev_window)
4724 const char *authors[] = {
4725 "Martin Kretzschmar <m_kretzschmar@gmx.net>",
4726 "Jonathan Blandford <jrb@gnome.org>",
4727 "Marco Pesenti Gritti <marco@gnome.org>",
4728 "Nickolay V. Shmyrev <nshmyrev@yandex.ru>",
4729 "Bryan Clark <clarkbw@gnome.org>",
4730 "Carlos Garcia Campos <carlosgc@gnome.org>",
4731 "Wouter Bolsterlee <wbolster@gnome.org>",
4732 "Christian Persch <chpe" "\100" "gnome.org>",
4736 const char *documenters[] = {
4737 "Nickolay V. Shmyrev <nshmyrev@yandex.ru>",
4741 const char *license[] = {
4742 N_("Evince is free software; you can redistribute it and/or modify "
4743 "it under the terms of the GNU General Public License as published by "
4744 "the Free Software Foundation; either version 2 of the License, or "
4745 "(at your option) any later version.\n"),
4746 N_("Evince is distributed in the hope that it will be useful, "
4747 "but WITHOUT ANY WARRANTY; without even the implied warranty of "
4748 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
4749 "GNU General Public License for more details.\n"),
4750 N_("You should have received a copy of the GNU General Public License "
4751 "along with Evince; if not, write to the Free Software Foundation, Inc., "
4752 "51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n")
4755 char *license_trans;
4761 for (p = authors; *p; ++p)
4764 for (p = documenters; *p; ++p)
4768 license_trans = g_strconcat (_(license[0]), "\n", _(license[1]), "\n",
4769 _(license[2]), "\n", NULL);
4771 comments = build_comments_string (ev_window->priv->document);
4773 gtk_show_about_dialog (
4774 GTK_WINDOW (ev_window),
4775 "name", _("Evince"),
4778 _("© 1996–2010 The Evince authors"),
4779 "license", license_trans,
4780 "website", "http://www.gnome.org/projects/evince",
4781 "comments", comments,
4783 "documenters", documenters,
4784 "translator-credits", _("translator-credits"),
4785 "logo-icon-name", "evince",
4786 "wrap-license", TRUE,
4790 g_free (license_trans);
4794 ev_window_view_toolbar_cb (GtkAction *action, EvWindow *ev_window)
4798 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
4799 update_chrome_flag (ev_window, EV_CHROME_TOOLBAR, active);
4800 update_chrome_visibility (ev_window);
4801 if (ev_window->priv->metadata)
4802 ev_metadata_set_boolean (ev_window->priv->metadata, "show_toolbar", active);
4806 ev_window_view_sidebar_cb (GtkAction *action, EvWindow *ev_window)
4808 if (EV_WINDOW_IS_PRESENTATION (ev_window))
4811 update_chrome_flag (ev_window, EV_CHROME_SIDEBAR,
4812 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
4813 update_chrome_visibility (ev_window);
4817 ev_window_sidebar_current_page_changed_cb (EvSidebar *ev_sidebar,
4819 EvWindow *ev_window)
4821 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window)) {
4822 ev_metadata_set_string (ev_window->priv->metadata,
4824 ev_window_sidebar_get_current_page_id (ev_window));
4829 ev_window_sidebar_visibility_changed_cb (EvSidebar *ev_sidebar,
4831 EvWindow *ev_window)
4835 action = gtk_action_group_get_action (ev_window->priv->action_group, "ViewSidebar");
4837 if (!EV_WINDOW_IS_PRESENTATION (ev_window)) {
4838 gboolean visible = gtk_widget_get_visible (GTK_WIDGET (ev_sidebar));
4840 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible);
4842 if (ev_window->priv->metadata)
4843 ev_metadata_set_boolean (ev_window->priv->metadata, "sidebar_visibility",
4849 view_menu_link_popup (EvWindow *ev_window,
4852 gboolean show_external = FALSE;
4853 gboolean show_internal = FALSE;
4856 if (ev_window->priv->link)
4857 g_object_unref (ev_window->priv->link);
4860 ev_window->priv->link = g_object_ref (link);
4862 ev_window->priv->link = NULL;
4864 if (ev_window->priv->link) {
4865 EvLinkAction *ev_action;
4867 ev_action = ev_link_get_action (link);
4869 switch (ev_link_action_get_action_type (ev_action)) {
4870 case EV_LINK_ACTION_TYPE_GOTO_DEST:
4871 case EV_LINK_ACTION_TYPE_GOTO_REMOTE:
4872 show_internal = TRUE;
4874 case EV_LINK_ACTION_TYPE_EXTERNAL_URI:
4875 case EV_LINK_ACTION_TYPE_LAUNCH:
4876 show_external = TRUE;
4884 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4886 gtk_action_set_visible (action, show_external);
4888 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4890 gtk_action_set_visible (action, show_external);
4892 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4894 gtk_action_set_visible (action, show_internal);
4896 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4897 "OpenLinkNewWindow");
4898 gtk_action_set_visible (action, show_internal);
4902 view_menu_image_popup (EvWindow *ev_window,
4906 gboolean show_image = FALSE;
4908 if (ev_window->priv->image)
4909 g_object_unref (ev_window->priv->image);
4912 ev_window->priv->image = g_object_ref (image);
4914 ev_window->priv->image = NULL;
4916 show_image = (ev_window->priv->image != NULL);
4918 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4920 gtk_action_set_visible (action, show_image);
4922 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4924 gtk_action_set_visible (action, show_image);
4928 view_menu_annot_popup (EvWindow *ev_window,
4929 EvAnnotation *annot)
4932 gboolean show_annot = FALSE;
4934 if (ev_window->priv->annot)
4935 g_object_unref (ev_window->priv->annot);
4936 ev_window->priv->annot = (annot) ? g_object_ref (annot) : NULL;
4938 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4940 gtk_action_set_visible (action, (annot != NULL && EV_IS_ANNOTATION_MARKUP (annot)));
4942 if (annot && EV_IS_ANNOTATION_ATTACHMENT (annot)) {
4943 EvAttachment *attachment;
4945 attachment = ev_annotation_attachment_get_attachment (EV_ANNOTATION_ATTACHMENT (annot));
4948 if (ev_window->priv->attach_list) {
4949 g_list_foreach (ev_window->priv->attach_list,
4950 (GFunc) g_object_unref, NULL);
4951 g_list_free (ev_window->priv->attach_list);
4952 ev_window->priv->attach_list = NULL;
4954 ev_window->priv->attach_list =
4955 g_list_prepend (ev_window->priv->attach_list,
4956 g_object_ref (attachment));
4960 action = gtk_action_group_get_action (ev_window->priv->attachment_popup_action_group,
4962 gtk_action_set_visible (action, show_annot);
4964 action = gtk_action_group_get_action (ev_window->priv->attachment_popup_action_group,
4965 "SaveAttachmentAs");
4966 gtk_action_set_visible (action, show_annot);
4970 view_menu_popup_cb (EvView *view,
4972 EvWindow *ev_window)
4975 gboolean has_link = FALSE;
4976 gboolean has_image = FALSE;
4977 gboolean has_annot = FALSE;
4979 for (l = items; l; l = g_list_next (l)) {
4980 if (EV_IS_LINK (l->data)) {
4981 view_menu_link_popup (ev_window, EV_LINK (l->data));
4983 } else if (EV_IS_IMAGE (l->data)) {
4984 view_menu_image_popup (ev_window, EV_IMAGE (l->data));
4986 } else if (EV_IS_ANNOTATION (l->data)) {
4987 view_menu_annot_popup (ev_window, EV_ANNOTATION (l->data));
4993 view_menu_link_popup (ev_window, NULL);
4995 view_menu_image_popup (ev_window, NULL);
4997 view_menu_annot_popup (ev_window, NULL);
4999 gtk_menu_popup (GTK_MENU (ev_window->priv->view_popup),
5000 NULL, NULL, NULL, NULL,
5001 3, gtk_get_current_event_time ());
5006 attachment_bar_menu_popup_cb (EvSidebarAttachments *attachbar,
5008 EvWindow *ev_window)
5012 g_assert (attach_list != NULL);
5014 if (ev_window->priv->attach_list) {
5015 g_list_foreach (ev_window->priv->attach_list,
5016 (GFunc) g_object_unref, NULL);
5017 g_list_free (ev_window->priv->attach_list);
5020 ev_window->priv->attach_list = attach_list;
5022 popup = ev_window->priv->attachment_popup;
5024 gtk_menu_popup (GTK_MENU (popup), NULL, NULL,
5026 3, gtk_get_current_event_time ());
5032 ev_window_update_find_status_message (EvWindow *ev_window)
5036 if (!ev_window->priv->find_job)
5039 if (ev_job_is_finished (ev_window->priv->find_job)) {
5040 EvJobFind *job_find = EV_JOB_FIND (ev_window->priv->find_job);
5042 if (ev_job_find_has_results (job_find)) {
5045 n_results = ev_job_find_get_n_results (job_find,
5046 ev_document_model_get_page (ev_window->priv->model));
5047 /* TRANS: Sometimes this could be better translated as
5048 "%d hit(s) on this page". Therefore this string
5049 contains plural cases. */
5050 message = g_strdup_printf (ngettext ("%d found on this page",
5051 "%d found on this page",
5055 message = g_strdup (_("Not found"));
5060 percent = ev_job_find_get_progress (EV_JOB_FIND (ev_window->priv->find_job));
5061 message = g_strdup_printf (_("%3d%% remaining to search"),
5062 (gint) ((1.0 - percent) * 100));
5065 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar), message);
5070 ev_window_find_job_finished_cb (EvJobFind *job,
5071 EvWindow *ev_window)
5073 ev_window_update_find_status_message (ev_window);
5077 ev_window_find_job_updated_cb (EvJobFind *job,
5079 EvWindow *ev_window)
5081 ev_window_update_actions (ev_window);
5083 ev_view_find_changed (EV_VIEW (ev_window->priv->view),
5084 ev_job_find_get_results (job),
5086 ev_window_update_find_status_message (ev_window);
5090 ev_window_clear_find_job (EvWindow *ev_window)
5092 if (ev_window->priv->find_job != NULL) {
5093 if (!ev_job_is_finished (ev_window->priv->find_job))
5094 ev_job_cancel (ev_window->priv->find_job);
5096 g_signal_handlers_disconnect_by_func (ev_window->priv->find_job,
5097 ev_window_find_job_finished_cb,
5099 g_signal_handlers_disconnect_by_func (ev_window->priv->find_job,
5100 ev_window_find_job_updated_cb,
5102 g_object_unref (ev_window->priv->find_job);
5103 ev_window->priv->find_job = NULL;
5108 find_bar_previous_cb (EggFindBar *find_bar,
5109 EvWindow *ev_window)
5111 ev_view_find_previous (EV_VIEW (ev_window->priv->view));
5115 find_bar_next_cb (EggFindBar *find_bar,
5116 EvWindow *ev_window)
5118 ev_view_find_next (EV_VIEW (ev_window->priv->view));
5122 find_bar_close_cb (EggFindBar *find_bar,
5123 EvWindow *ev_window)
5125 ev_view_find_cancel (EV_VIEW (ev_window->priv->view));
5126 ev_window_clear_find_job (ev_window);
5127 update_chrome_flag (ev_window, EV_CHROME_FINDBAR, FALSE);
5128 update_chrome_visibility (ev_window);
5132 find_bar_search_changed_cb (EggFindBar *find_bar,
5134 EvWindow *ev_window)
5136 gboolean case_sensitive;
5137 const char *search_string;
5139 if (!ev_window->priv->document || !EV_IS_DOCUMENT_FIND (ev_window->priv->document))
5142 /* Either the string or case sensitivity could have changed. */
5143 case_sensitive = egg_find_bar_get_case_sensitive (find_bar);
5144 search_string = egg_find_bar_get_search_string (find_bar);
5146 ev_view_find_search_changed (EV_VIEW (ev_window->priv->view));
5148 ev_window_clear_find_job (ev_window);
5150 if (search_string && search_string[0]) {
5151 ev_window->priv->find_job = ev_job_find_new (ev_window->priv->document,
5152 ev_document_model_get_page (ev_window->priv->model),
5153 ev_document_get_n_pages (ev_window->priv->document),
5156 g_signal_connect (ev_window->priv->find_job, "finished",
5157 G_CALLBACK (ev_window_find_job_finished_cb),
5159 g_signal_connect (ev_window->priv->find_job, "updated",
5160 G_CALLBACK (ev_window_find_job_updated_cb),
5162 ev_job_scheduler_push_job (ev_window->priv->find_job, EV_JOB_PRIORITY_NONE);
5164 ev_window_update_actions (ev_window);
5165 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar),
5167 gtk_widget_queue_draw (GTK_WIDGET (ev_window->priv->view));
5172 find_bar_visibility_changed_cb (EggFindBar *find_bar,
5174 EvWindow *ev_window)
5178 visible = gtk_widget_get_visible (GTK_WIDGET (find_bar));
5180 if (ev_window->priv->document &&
5181 EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
5182 ev_view_find_set_highlight_search (EV_VIEW (ev_window->priv->view), visible);
5183 ev_view_find_search_changed (EV_VIEW (ev_window->priv->view));
5184 ev_window_update_actions (ev_window);
5187 find_bar_search_changed_cb (find_bar, NULL, ev_window);
5189 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar), NULL);
5194 find_bar_scroll (EggFindBar *find_bar,
5195 GtkScrollType scroll,
5196 EvWindow *ev_window)
5198 ev_view_scroll (EV_VIEW (ev_window->priv->view), scroll, FALSE);
5202 zoom_control_changed_cb (EphyZoomAction *action,
5204 EvWindow *ev_window)
5208 if (zoom == EPHY_ZOOM_BEST_FIT) {
5209 mode = EV_SIZING_BEST_FIT;
5210 } else if (zoom == EPHY_ZOOM_FIT_WIDTH) {
5211 mode = EV_SIZING_FIT_WIDTH;
5213 mode = EV_SIZING_FREE;
5216 ev_document_model_set_sizing_mode (ev_window->priv->model, mode);
5218 if (mode == EV_SIZING_FREE) {
5219 ev_document_model_set_scale (ev_window->priv->model,
5220 zoom * get_screen_dpi (ev_window) / 72.0);
5225 ev_window_drag_data_received (GtkWidget *widget,
5226 GdkDragContext *context,
5229 GtkSelectionData *selection_data,
5234 EvWindow *window = EV_WINDOW (widget);
5237 GSList *uri_list = NULL;
5240 source = gtk_drag_get_source_widget (context);
5241 if (source && widget == gtk_widget_get_toplevel (source)) {
5242 gtk_drag_finish (context, FALSE, FALSE, time);
5246 uris = gtk_selection_data_get_uris (selection_data);
5248 gtk_drag_finish (context, FALSE, FALSE, time);
5252 for (i = 0; uris[i]; i++) {
5253 uri_list = g_slist_prepend (uri_list, (gpointer) uris[i]);
5256 ev_application_open_uri_list (EV_APP, uri_list,
5257 gtk_window_get_screen (GTK_WINDOW (window)),
5259 gtk_drag_finish (context, TRUE, FALSE, time);
5262 g_slist_free (uri_list);
5266 ev_window_finalize (GObject *object)
5268 G_OBJECT_CLASS (ev_window_parent_class)->finalize (object);
5270 if (ev_window_n_copies == 0) {
5271 ev_application_shutdown (EV_APP);
5273 ev_window_n_copies--;
5278 ev_window_dispose (GObject *object)
5280 EvWindow *window = EV_WINDOW (object);
5281 EvWindowPrivate *priv = window->priv;
5282 GObject *mpkeys = ev_application_get_media_keys (EV_APP);
5285 g_signal_handlers_disconnect_by_func (mpkeys,
5286 ev_window_media_player_key_pressed,
5291 if (priv->dbus_object_id > 0) {
5292 ev_window_emit_closed (window);
5293 g_dbus_connection_unregister_object (ev_application_get_dbus_connection (EV_APP),
5294 priv->dbus_object_id);
5295 priv->dbus_object_id = 0;
5298 if (priv->dbus_object_path) {
5299 g_free (priv->dbus_object_path);
5300 priv->dbus_object_path = NULL;
5302 #endif /* ENABLE_DBUS */
5304 if (priv->bookmarks) {
5305 g_object_unref (priv->bookmarks);
5306 priv->bookmarks = NULL;
5309 if (priv->metadata) {
5310 g_object_unref (priv->metadata);
5311 priv->metadata = NULL;
5314 if (priv->setup_document_idle > 0) {
5315 g_source_remove (priv->setup_document_idle);
5316 priv->setup_document_idle = 0;
5319 if (priv->monitor) {
5320 g_object_unref (priv->monitor);
5321 priv->monitor = NULL;
5325 ev_window_title_free (priv->title);
5329 if (priv->ui_manager) {
5330 g_object_unref (priv->ui_manager);
5331 priv->ui_manager = NULL;
5334 if (priv->action_group) {
5335 g_object_unref (priv->action_group);
5336 priv->action_group = NULL;
5339 if (priv->view_popup_action_group) {
5340 g_object_unref (priv->view_popup_action_group);
5341 priv->view_popup_action_group = NULL;
5344 if (priv->attachment_popup_action_group) {
5345 g_object_unref (priv->attachment_popup_action_group);
5346 priv->attachment_popup_action_group = NULL;
5349 if (priv->recent_action_group) {
5350 g_object_unref (priv->recent_action_group);
5351 priv->recent_action_group = NULL;
5354 if (priv->bookmarks_action_group) {
5355 g_object_unref (priv->bookmarks_action_group);
5356 priv->bookmarks_action_group = NULL;
5359 if (priv->recent_manager) {
5360 g_signal_handlers_disconnect_by_func (priv->recent_manager,
5361 ev_window_setup_recent,
5363 priv->recent_manager = NULL;
5366 if (priv->settings) {
5367 g_object_unref (priv->settings);
5368 priv->settings = NULL;
5371 if (priv->default_settings) {
5372 g_settings_apply (priv->default_settings);
5373 g_object_unref (priv->default_settings);
5374 priv->default_settings = NULL;
5377 if (priv->lockdown_settings) {
5378 g_object_unref (priv->lockdown_settings);
5379 priv->lockdown_settings = NULL;
5382 priv->recent_ui_id = 0;
5385 g_signal_handlers_disconnect_by_func (priv->model,
5386 ev_window_page_changed_cb,
5388 g_object_unref (priv->model);
5392 if (priv->document) {
5393 g_object_unref (priv->document);
5394 priv->document = NULL;
5398 g_object_unref (priv->view);
5402 if (priv->password_view) {
5403 g_object_unref (priv->password_view);
5404 priv->password_view = NULL;
5407 if (priv->load_job) {
5408 ev_window_clear_load_job (window);
5411 if (priv->reload_job) {
5412 ev_window_clear_reload_job (window);
5415 if (priv->save_job) {
5416 ev_window_clear_save_job (window);
5419 if (priv->thumbnail_job) {
5420 ev_window_clear_thumbnail_job (window);
5423 if (priv->find_job) {
5424 ev_window_clear_find_job (window);
5427 if (priv->local_uri) {
5428 ev_window_clear_local_uri (window);
5429 priv->local_uri = NULL;
5432 ev_window_clear_progress_idle (window);
5433 if (priv->progress_cancellable) {
5434 g_object_unref (priv->progress_cancellable);
5435 priv->progress_cancellable = NULL;
5438 ev_window_close_dialogs (window);
5441 g_object_unref (priv->link);
5446 g_object_unref (priv->image);
5451 g_object_unref (priv->annot);
5455 if (priv->attach_list) {
5456 g_list_foreach (priv->attach_list,
5457 (GFunc) g_object_unref,
5459 g_list_free (priv->attach_list);
5460 priv->attach_list = NULL;
5463 if (priv->find_bar) {
5464 g_signal_handlers_disconnect_by_func
5465 (window->priv->find_bar,
5466 G_CALLBACK (find_bar_close_cb),
5468 priv->find_bar = NULL;
5476 if (priv->search_string) {
5477 g_free (priv->search_string);
5478 priv->search_string = NULL;
5482 g_object_unref (priv->dest);
5486 if (priv->history) {
5487 g_object_unref (priv->history);
5488 priv->history = NULL;
5491 if (priv->print_queue) {
5492 g_queue_free (priv->print_queue);
5493 priv->print_queue = NULL;
5496 G_OBJECT_CLASS (ev_window_parent_class)->dispose (object);
5500 menubar_deactivate_cb (GtkWidget *menubar,
5503 g_signal_handlers_disconnect_by_func (menubar,
5504 G_CALLBACK (menubar_deactivate_cb),
5507 gtk_menu_shell_deselect (GTK_MENU_SHELL (menubar));
5509 update_chrome_visibility (window);
5513 ev_window_key_press_event (GtkWidget *widget,
5516 EvWindow *ev_window = EV_WINDOW (widget);
5517 EvWindowPrivate *priv = ev_window->priv;
5518 gboolean handled = FALSE;
5520 /* Propagate the event to the view first
5521 * It's needed to be able to type in
5522 * annot popups windows
5525 g_object_ref (priv->view);
5526 if (gtk_widget_is_sensitive (priv->view))
5527 handled = gtk_widget_event (priv->view, (GdkEvent*) event);
5528 g_object_unref (priv->view);
5531 if (!handled && !EV_WINDOW_IS_PRESENTATION (ev_window)) {
5532 guint modifier = event->state & gtk_accelerator_get_default_mod_mask ();
5534 if (priv->menubar_accel_keyval != 0 &&
5535 event->keyval == priv->menubar_accel_keyval &&
5536 modifier == priv->menubar_accel_modifier) {
5537 if (!gtk_widget_get_visible (priv->menubar)) {
5538 g_signal_connect (priv->menubar, "deactivate",
5539 G_CALLBACK (menubar_deactivate_cb),
5542 gtk_widget_show (priv->menubar);
5543 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menubar),
5552 handled = GTK_WIDGET_CLASS (ev_window_parent_class)->key_press_event (widget, event);
5558 ev_window_delete_event (GtkWidget *widget,
5561 return !ev_window_close (EV_WINDOW (widget));
5565 ev_window_class_init (EvWindowClass *ev_window_class)
5567 GObjectClass *g_object_class = G_OBJECT_CLASS (ev_window_class);
5568 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (ev_window_class);
5570 g_object_class->dispose = ev_window_dispose;
5571 g_object_class->finalize = ev_window_finalize;
5573 widget_class->delete_event = ev_window_delete_event;
5574 widget_class->key_press_event = ev_window_key_press_event;
5575 widget_class->screen_changed = ev_window_screen_changed;
5576 widget_class->window_state_event = ev_window_state_event;
5577 widget_class->drag_data_received = ev_window_drag_data_received;
5579 g_type_class_add_private (g_object_class, sizeof (EvWindowPrivate));
5583 static const GtkActionEntry entries[] = {
5584 { "File", NULL, N_("_File") },
5585 { "Edit", NULL, N_("_Edit") },
5586 { "View", NULL, N_("_View") },
5587 { "Go", NULL, N_("_Go") },
5588 { "Bookmarks", NULL, N_("_Bookmarks") },
5589 { "Help", NULL, N_("_Help") },
5592 { "FileOpen", GTK_STOCK_OPEN, N_("_Open…"), "<control>O",
5593 N_("Open an existing document"),
5594 G_CALLBACK (ev_window_cmd_file_open) },
5595 { "FileOpenCopy", NULL, N_("Op_en a Copy"), "<control>N",
5596 N_("Open a copy of the current document in a new window"),
5597 G_CALLBACK (ev_window_cmd_file_open_copy) },
5598 { "FileSaveAs", GTK_STOCK_SAVE_AS, N_("_Save a Copy…"), "<control>S",
5599 N_("Save a copy of the current document"),
5600 G_CALLBACK (ev_window_cmd_save_as) },
5601 { "FileOpenContainingFolder", GTK_STOCK_DIRECTORY, N_("Open Containing _Folder"), NULL,
5602 N_("Show the folder which contains this file in the file manager"),
5603 G_CALLBACK (ev_window_cmd_open_containing_folder) },
5604 { "FilePrint", GTK_STOCK_PRINT, N_("_Print…"), "<control>P",
5605 N_("Print this document"),
5606 G_CALLBACK (ev_window_cmd_file_print) },
5607 { "FileProperties", GTK_STOCK_PROPERTIES, N_("P_roperties"), "<alt>Return", NULL,
5608 G_CALLBACK (ev_window_cmd_file_properties) },
5609 { "FileCloseWindow", GTK_STOCK_CLOSE, NULL, "<control>W", NULL,
5610 G_CALLBACK (ev_window_cmd_file_close_window) },
5613 { "EditCopy", GTK_STOCK_COPY, NULL, "<control>C", NULL,
5614 G_CALLBACK (ev_window_cmd_edit_copy) },
5615 { "EditSelectAll", GTK_STOCK_SELECT_ALL, N_("Select _All"), "<control>A", NULL,
5616 G_CALLBACK (ev_window_cmd_edit_select_all) },
5617 { "EditFind", GTK_STOCK_FIND, N_("_Find…"), "<control>F",
5618 N_("Find a word or phrase in the document"),
5619 G_CALLBACK (ev_window_cmd_edit_find) },
5620 { "EditFindNext", NULL, N_("Find Ne_xt"), "<control>G", NULL,
5621 G_CALLBACK (ev_window_cmd_edit_find_next) },
5622 { "EditFindPrevious", NULL, N_("Find Pre_vious"), "<shift><control>G", NULL,
5623 G_CALLBACK (ev_window_cmd_edit_find_previous) },
5624 { "EditToolbar", NULL, N_("T_oolbar"), NULL, NULL,
5625 G_CALLBACK (ev_window_cmd_edit_toolbar) },
5626 { "EditRotateLeft", EV_STOCK_ROTATE_LEFT, N_("Rotate _Left"), "<control>Left", NULL,
5627 G_CALLBACK (ev_window_cmd_edit_rotate_left) },
5628 { "EditRotateRight", EV_STOCK_ROTATE_RIGHT, N_("Rotate _Right"), "<control>Right", NULL,
5629 G_CALLBACK (ev_window_cmd_edit_rotate_right) },
5630 { "EditSaveSettings", NULL, N_("Save Current Settings as _Default"), "<control>T", NULL,
5631 G_CALLBACK (ev_window_cmd_edit_save_settings) },
5635 { "ViewZoomIn", GTK_STOCK_ZOOM_IN, NULL, "<control>plus",
5636 N_("Enlarge the document"),
5637 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5638 { "ViewZoomOut", GTK_STOCK_ZOOM_OUT, NULL, "<control>minus",
5639 N_("Shrink the document"),
5640 G_CALLBACK (ev_window_cmd_view_zoom_out) },
5641 { "ViewReload", GTK_STOCK_REFRESH, N_("_Reload"), "<control>R",
5642 N_("Reload the document"),
5643 G_CALLBACK (ev_window_cmd_view_reload) },
5645 { "ViewAutoscroll", GTK_STOCK_MEDIA_PLAY, N_("Auto_scroll"), NULL, NULL,
5646 G_CALLBACK (ev_window_cmd_view_autoscroll) },
5649 { "GoPreviousPage", GTK_STOCK_GO_UP, N_("_Previous Page"), "<control>Page_Up",
5650 N_("Go to the previous page"),
5651 G_CALLBACK (ev_window_cmd_go_previous_page) },
5652 { "GoNextPage", GTK_STOCK_GO_DOWN, N_("_Next Page"), "<control>Page_Down",
5653 N_("Go to the next page"),
5654 G_CALLBACK (ev_window_cmd_go_next_page) },
5655 { "GoFirstPage", GTK_STOCK_GOTO_TOP, N_("_First Page"), "<control>Home",
5656 N_("Go to the first page"),
5657 G_CALLBACK (ev_window_cmd_go_first_page) },
5658 { "GoLastPage", GTK_STOCK_GOTO_BOTTOM, N_("_Last Page"), "<control>End",
5659 N_("Go to the last page"),
5660 G_CALLBACK (ev_window_cmd_go_last_page) },
5662 /* Bookmarks menu */
5663 { "BookmarksAdd", GTK_STOCK_ADD, N_("_Add Bookmark"), "<control>D",
5664 N_("Add a bookmark for the current page"),
5665 G_CALLBACK (ev_window_cmd_bookmarks_add) },
5668 { "HelpContents", GTK_STOCK_HELP, N_("_Contents"), "F1", NULL,
5669 G_CALLBACK (ev_window_cmd_help_contents) },
5671 { "HelpAbout", GTK_STOCK_ABOUT, N_("_About"), NULL, NULL,
5672 G_CALLBACK (ev_window_cmd_help_about) },
5675 { "LeaveFullscreen", GTK_STOCK_LEAVE_FULLSCREEN, N_("Leave Fullscreen"), NULL,
5676 N_("Leave fullscreen mode"),
5677 G_CALLBACK (ev_window_cmd_leave_fullscreen) },
5678 { "StartPresentation", EV_STOCK_RUN_PRESENTATION, N_("Start Presentation"), NULL,
5679 N_("Start a presentation"),
5680 G_CALLBACK (ev_window_cmd_start_presentation) },
5683 { "Escape", NULL, "", "Escape", "",
5684 G_CALLBACK (ev_window_cmd_escape) },
5685 { "Slash", GTK_STOCK_FIND, NULL, "slash", NULL,
5686 G_CALLBACK (ev_window_cmd_edit_find) },
5687 { "F3", NULL, "", "F3", NULL,
5688 G_CALLBACK (ev_window_cmd_edit_find_next) },
5689 { "PageDown", NULL, "", "Page_Down", NULL,
5690 G_CALLBACK (ev_window_cmd_scroll_forward) },
5691 { "PageUp", NULL, "", "Page_Up", NULL,
5692 G_CALLBACK (ev_window_cmd_scroll_backward) },
5693 { "Space", NULL, "", "space", NULL,
5694 G_CALLBACK (ev_window_cmd_scroll_forward) },
5695 { "ShiftSpace", NULL, "", "<shift>space", NULL,
5696 G_CALLBACK (ev_window_cmd_scroll_backward) },
5697 { "BackSpace", NULL, "", "BackSpace", NULL,
5698 G_CALLBACK (ev_window_cmd_scroll_backward) },
5699 { "ShiftBackSpace", NULL, "", "<shift>BackSpace", NULL,
5700 G_CALLBACK (ev_window_cmd_scroll_forward) },
5701 { "Return", NULL, "", "Return", NULL,
5702 G_CALLBACK (ev_window_cmd_scroll_forward) },
5703 { "ShiftReturn", NULL, "", "<shift>Return", NULL,
5704 G_CALLBACK (ev_window_cmd_scroll_backward) },
5705 { "p", GTK_STOCK_GO_UP, "", "p", NULL,
5706 G_CALLBACK (ev_window_cmd_go_previous_page) },
5707 { "n", GTK_STOCK_GO_DOWN, "", "n", NULL,
5708 G_CALLBACK (ev_window_cmd_go_next_page) },
5709 { "Plus", GTK_STOCK_ZOOM_IN, NULL, "plus", NULL,
5710 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5711 { "CtrlEqual", GTK_STOCK_ZOOM_IN, NULL, "<control>equal", NULL,
5712 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5713 { "Equal", GTK_STOCK_ZOOM_IN, NULL, "equal", NULL,
5714 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5715 { "Minus", GTK_STOCK_ZOOM_OUT, NULL, "minus", NULL,
5716 G_CALLBACK (ev_window_cmd_view_zoom_out) },
5717 { "FocusPageSelector", NULL, "", "<control>l", NULL,
5718 G_CALLBACK (ev_window_cmd_focus_page_selector) },
5719 { "GoBackwardFast", NULL, "", "<shift>Page_Up", NULL,
5720 G_CALLBACK (ev_window_cmd_go_backward) },
5721 { "GoForwardFast", NULL, "", "<shift>Page_Down", NULL,
5722 G_CALLBACK (ev_window_cmd_go_forward) },
5723 { "KpPlus", GTK_STOCK_ZOOM_IN, NULL, "KP_Add", NULL,
5724 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5725 { "KpMinus", GTK_STOCK_ZOOM_OUT, NULL, "KP_Subtract", NULL,
5726 G_CALLBACK (ev_window_cmd_view_zoom_out) },
5727 { "CtrlKpPlus", GTK_STOCK_ZOOM_IN, NULL, "<control>KP_Add", NULL,
5728 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5729 { "CtrlKpMinus", GTK_STOCK_ZOOM_OUT, NULL, "<control>KP_Subtract", NULL,
5730 G_CALLBACK (ev_window_cmd_view_zoom_out) },
5731 { "CtrlInsert", GTK_STOCK_COPY, NULL, "<control>Insert", NULL,
5732 G_CALLBACK (ev_window_cmd_edit_copy) },
5736 static const GtkToggleActionEntry toggle_entries[] = {
5738 { "ViewToolbar", NULL, N_("_Toolbar"), NULL,
5739 N_("Show or hide the toolbar"),
5740 G_CALLBACK (ev_window_view_toolbar_cb), TRUE },
5741 { "ViewSidebar", GTK_STOCK_INDEX, N_("Side _Pane"), "F9",
5742 N_("Show or hide the side pane"),
5743 G_CALLBACK (ev_window_view_sidebar_cb), TRUE },
5744 { "ViewContinuous", EV_STOCK_VIEW_CONTINUOUS, N_("_Continuous"), NULL,
5745 N_("Show the entire document"),
5746 G_CALLBACK (ev_window_cmd_continuous), TRUE },
5747 { "ViewDual", EV_STOCK_VIEW_DUAL, N_("_Dual"), NULL,
5748 N_("Show two pages at once"),
5749 G_CALLBACK (ev_window_cmd_dual), FALSE },
5750 { "ViewFullscreen", GTK_STOCK_FULLSCREEN, N_("_Fullscreen"), "F11",
5751 N_("Expand the window to fill the screen"),
5752 G_CALLBACK (ev_window_cmd_view_fullscreen) },
5753 { "ViewPresentation", EV_STOCK_RUN_PRESENTATION, N_("Pre_sentation"), "F5",
5754 N_("Run document as a presentation"),
5755 G_CALLBACK (ev_window_cmd_view_presentation) },
5756 { "ViewBestFit", EV_STOCK_ZOOM_PAGE, N_("_Best Fit"), NULL,
5757 N_("Make the current document fill the window"),
5758 G_CALLBACK (ev_window_cmd_view_best_fit) },
5759 { "ViewPageWidth", EV_STOCK_ZOOM_WIDTH, N_("Fit Page _Width"), NULL,
5760 N_("Make the current document fill the window width"),
5761 G_CALLBACK (ev_window_cmd_view_page_width) },
5762 { "ViewInvertedColors", EV_STOCK_INVERTED_COLORS, N_("_Inverted Colors"), "<control>I",
5763 N_("Show page contents with the colors inverted"),
5764 G_CALLBACK (ev_window_cmd_view_inverted_colors) },
5768 /* Popups specific items */
5769 static const GtkActionEntry view_popup_entries [] = {
5771 { "OpenLink", GTK_STOCK_OPEN, N_("_Open Link"), NULL,
5772 NULL, G_CALLBACK (ev_view_popup_cmd_open_link) },
5773 { "GoLink", GTK_STOCK_GO_FORWARD, N_("_Go To"), NULL,
5774 NULL, G_CALLBACK (ev_view_popup_cmd_open_link) },
5775 { "OpenLinkNewWindow", NULL, N_("Open in New _Window"), NULL,
5776 NULL, G_CALLBACK (ev_view_popup_cmd_open_link_new_window) },
5777 { "CopyLinkAddress", NULL, N_("_Copy Link Address"), NULL,
5778 NULL, G_CALLBACK (ev_view_popup_cmd_copy_link_address) },
5779 { "SaveImageAs", NULL, N_("_Save Image As…"), NULL,
5780 NULL, G_CALLBACK (ev_view_popup_cmd_save_image_as) },
5781 { "CopyImage", NULL, N_("Copy _Image"), NULL,
5782 NULL, G_CALLBACK (ev_view_popup_cmd_copy_image) },
5783 { "AnnotProperties", NULL, N_("Annotation Properties…"), NULL,
5784 NULL, G_CALLBACK (ev_view_popup_cmd_annot_properties) }
5787 static const GtkActionEntry attachment_popup_entries [] = {
5788 { "OpenAttachment", GTK_STOCK_OPEN, N_("_Open Attachment"), NULL,
5789 NULL, G_CALLBACK (ev_attachment_popup_cmd_open_attachment) },
5790 { "SaveAttachmentAs", GTK_STOCK_SAVE_AS, N_("_Save Attachment As…"), NULL,
5791 NULL, G_CALLBACK (ev_attachment_popup_cmd_save_attachment_as) },
5795 sidebar_links_link_activated_cb (EvSidebarLinks *sidebar_links, EvLink *link, EvWindow *window)
5797 ev_view_handle_link (EV_VIEW (window->priv->view), link);
5801 activate_link_cb (EvPageAction *page_action, EvLink *link, EvWindow *window)
5803 ev_view_handle_link (EV_VIEW (window->priv->view), link);
5804 gtk_widget_grab_focus (window->priv->view);
5808 navigation_action_activate_link_cb (EvNavigationAction *action, EvLink *link, EvWindow *window)
5811 ev_view_handle_link (EV_VIEW (window->priv->view), link);
5812 gtk_widget_grab_focus (window->priv->view);
5816 sidebar_layers_visibility_changed (EvSidebarLayers *layers,
5819 ev_view_reload (EV_VIEW (window->priv->view));
5823 sidebar_annots_annot_activated_cb (EvSidebarAnnotations *sidebar_annots,
5824 EvMapping *annot_mapping,
5827 ev_view_focus_annotation (EV_VIEW (window->priv->view), annot_mapping);
5831 sidebar_annots_begin_annot_add (EvSidebarAnnotations *sidebar_annots,
5832 EvAnnotationType annot_type,
5835 ev_view_begin_add_annotation (EV_VIEW (window->priv->view), annot_type);
5839 view_annot_added (EvView *view,
5840 EvAnnotation *annot,
5843 ev_sidebar_annotations_annot_added (EV_SIDEBAR_ANNOTATIONS (window->priv->sidebar_annots),
5848 sidebar_annots_annot_add_cancelled (EvSidebarAnnotations *sidebar_annots,
5851 ev_view_cancel_add_annotation (EV_VIEW (window->priv->view));
5855 sidebar_bookmarks_add_bookmark (EvSidebarBookmarks *sidebar_bookmarks,
5858 ev_window_cmd_bookmarks_add (NULL, window);
5862 register_custom_actions (EvWindow *window, GtkActionGroup *group)
5866 action = g_object_new (EV_TYPE_PAGE_ACTION,
5867 "name", PAGE_SELECTOR_ACTION,
5869 "tooltip", _("Select Page"),
5870 "icon_name", "text-x-generic",
5871 "visible_overflown", FALSE,
5873 ev_page_action_set_model (EV_PAGE_ACTION (action),
5874 window->priv->model);
5875 g_signal_connect (action, "activate_link",
5876 G_CALLBACK (activate_link_cb), window);
5877 gtk_action_group_add_action (group, action);
5878 g_object_unref (action);
5880 action = g_object_new (EPHY_TYPE_ZOOM_ACTION,
5881 "name", ZOOM_CONTROL_ACTION,
5883 "stock_id", EV_STOCK_ZOOM,
5884 "tooltip", _("Adjust the zoom level"),
5887 g_signal_connect (action, "zoom_to_level",
5888 G_CALLBACK (zoom_control_changed_cb), window);
5889 gtk_action_group_add_action (group, action);
5890 g_object_unref (action);
5892 action = g_object_new (EV_TYPE_NAVIGATION_ACTION,
5893 "name", NAVIGATION_ACTION,
5894 "label", _("Navigation"),
5895 "is_important", TRUE,
5896 "short_label", _("Back"),
5897 "stock_id", GTK_STOCK_GO_DOWN,
5898 /*translators: this is the history action*/
5899 "tooltip", _("Move across visited pages"),
5901 g_signal_connect (action, "activate_link",
5902 G_CALLBACK (navigation_action_activate_link_cb), window);
5903 gtk_action_group_add_action (group, action);
5904 g_object_unref (action);
5906 action = g_object_new (EV_TYPE_OPEN_RECENT_ACTION,
5907 "name", "FileOpenRecent",
5908 "label", _("_Open…"),
5909 "tooltip", _("Open an existing document"),
5910 "stock_id", GTK_STOCK_OPEN,
5912 g_signal_connect (action, "activate",
5913 G_CALLBACK (ev_window_cmd_file_open), window);
5914 g_signal_connect (action, "item_activated",
5915 G_CALLBACK (ev_window_open_recent_action_item_activated),
5917 gtk_action_group_add_action (group, action);
5918 g_object_unref (action);
5922 set_action_properties (GtkActionGroup *action_group)
5926 action = gtk_action_group_get_action (action_group, "FileOpenContainingFolder");
5927 /*translators: this is the label for toolbar button*/
5928 g_object_set (action, "short_label", _("Open Folder"), NULL);
5930 action = gtk_action_group_get_action (action_group, "GoPreviousPage");
5931 g_object_set (action, "is-important", TRUE, NULL);
5932 /*translators: this is the label for toolbar button*/
5933 g_object_set (action, "short_label", _("Previous"), NULL);
5935 action = gtk_action_group_get_action (action_group, "GoNextPage");
5936 g_object_set (action, "is-important", TRUE, NULL);
5937 /*translators: this is the label for toolbar button*/
5938 g_object_set (action, "short_label", _("Next"), NULL);
5940 action = gtk_action_group_get_action (action_group, "ViewZoomIn");
5941 /*translators: this is the label for toolbar button*/
5942 g_object_set (action, "short_label", _("Zoom In"), NULL);
5944 action = gtk_action_group_get_action (action_group, "ViewZoomOut");
5945 /*translators: this is the label for toolbar button*/
5946 g_object_set (action, "short_label", _("Zoom Out"), NULL);
5948 action = gtk_action_group_get_action (action_group, "ViewBestFit");
5949 /*translators: this is the label for toolbar button*/
5950 g_object_set (action, "short_label", _("Best Fit"), NULL);
5952 action = gtk_action_group_get_action (action_group, "ViewPageWidth");
5953 /*translators: this is the label for toolbar button*/
5954 g_object_set (action, "short_label", _("Fit Width"), NULL);
5956 action = gtk_action_group_get_action (action_group, "LeaveFullscreen");
5957 g_object_set (action, "is-important", TRUE, NULL);
5961 sidebar_widget_model_set (EvSidebarLinks *ev_sidebar_links,
5963 EvWindow *ev_window)
5965 GtkTreeModel *model;
5968 g_object_get (G_OBJECT (ev_sidebar_links),
5972 action = gtk_action_group_get_action (ev_window->priv->action_group, PAGE_SELECTOR_ACTION);
5973 ev_page_action_set_links_model (EV_PAGE_ACTION (action), model);
5974 g_object_unref (model);
5978 view_actions_focus_in_cb (GtkWidget *widget, GdkEventFocus *event, EvWindow *window)
5983 keys = ev_application_get_media_keys (EV_APP);
5984 ev_media_player_keys_focused (EV_MEDIA_PLAYER_KEYS (keys));
5985 #endif /* ENABLE_DBUS */
5987 update_chrome_flag (window, EV_CHROME_RAISE_TOOLBAR, FALSE);
5988 ev_window_set_action_sensitive (window, "ViewToolbar", TRUE);
5990 ev_window_set_view_accels_sensitivity (window, TRUE);
5992 update_chrome_visibility (window);
5998 view_actions_focus_out_cb (GtkWidget *widget, GdkEventFocus *event, EvWindow *window)
6000 ev_window_set_view_accels_sensitivity (window, FALSE);
6006 sidebar_page_main_widget_update_cb (GObject *ev_sidebar_page,
6008 EvWindow *ev_window)
6012 g_object_get (ev_sidebar_page, "main_widget", &widget, NULL);
6014 if (widget != NULL) {
6015 g_signal_connect_object (widget, "focus_in_event",
6016 G_CALLBACK (view_actions_focus_in_cb),
6018 g_signal_connect_object (widget, "focus_out_event",
6019 G_CALLBACK (view_actions_focus_out_cb),
6021 g_object_unref (widget);
6026 window_state_event_cb (EvWindow *window, GdkEventWindowState *event, gpointer dummy)
6028 if (!(event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN)) {
6031 maximized = event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED;
6032 if (window->priv->metadata && !ev_window_is_empty (window))
6033 ev_metadata_set_boolean (window->priv->metadata, "window_maximized", maximized);
6040 window_configure_event_cb (EvWindow *window, GdkEventConfigure *event, gpointer dummy)
6042 GdkWindowState state;
6043 gdouble document_width, document_height;
6045 if (!window->priv->metadata)
6048 state = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (window)));
6050 if (!(state & GDK_WINDOW_STATE_FULLSCREEN)) {
6051 if (window->priv->document) {
6052 ev_document_get_max_page_size (window->priv->document,
6053 &document_width, &document_height);
6054 g_settings_set (window->priv->default_settings, "window-ratio", "(dd)",
6055 (double)event->width / document_width,
6056 (double)event->height / document_height);
6058 ev_metadata_set_int (window->priv->metadata, "window_x", event->x);
6059 ev_metadata_set_int (window->priv->metadata, "window_y", event->y);
6060 ev_metadata_set_int (window->priv->metadata, "window_width", event->width);
6061 ev_metadata_set_int (window->priv->metadata, "window_height", event->height);
6069 launch_action (EvWindow *window, EvLinkAction *action)
6071 const char *filename = ev_link_action_get_filename (action);
6074 GList file_list = {NULL};
6075 GAppLaunchContext *context;
6076 GError *error = NULL;
6078 if (filename == NULL)
6081 if (g_path_is_absolute (filename)) {
6082 file = g_file_new_for_path (filename);
6087 dir = g_path_get_dirname (window->priv->uri);
6088 base_file = g_file_new_for_uri (dir);
6091 file = g_file_resolve_relative_path (base_file, filename);
6092 g_object_unref (base_file);
6095 app_info = g_file_query_default_handler (file, NULL, &error);
6097 ev_window_error_message (window, error,
6099 _("Unable to launch external application."));
6100 g_object_unref (file);
6101 g_error_free (error);
6106 context = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
6107 gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (context),
6108 gtk_window_get_screen (GTK_WINDOW (window)));
6109 gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (context),
6110 gtk_get_current_event_time ());
6112 file_list.data = file;
6113 if (!g_app_info_launch (app_info, &file_list, context, &error)) {
6114 ev_window_error_message (window, error,
6116 _("Unable to launch external application."));
6117 g_error_free (error);
6120 g_object_unref (app_info);
6121 g_object_unref (file);
6122 /* FIXMEchpe: unref launch context? */
6124 /* According to the PDF spec filename can be an executable. I'm not sure
6125 allowing to launch executables is a good idea though. -- marco */
6129 launch_external_uri (EvWindow *window, EvLinkAction *action)
6131 const gchar *uri = ev_link_action_get_uri (action);
6132 GError *error = NULL;
6134 GAppLaunchContext *context;
6136 context = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
6137 gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (context),
6138 gtk_window_get_screen (GTK_WINDOW (window)));
6139 gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (context),
6140 gtk_get_current_event_time ());
6142 if (!g_strstr_len (uri, strlen (uri), "://") &&
6143 !g_str_has_prefix (uri, "mailto:")) {
6146 /* Not a valid uri, assume http if it starts with www */
6147 if (g_str_has_prefix (uri, "www.")) {
6148 new_uri = g_strdup_printf ("http://%s", uri);
6150 GFile *file, *parent;
6152 file = g_file_new_for_uri (window->priv->uri);
6153 parent = g_file_get_parent (file);
6154 g_object_unref (file);
6156 gchar *parent_uri = g_file_get_uri (parent);
6158 new_uri = g_build_filename (parent_uri, uri, NULL);
6159 g_free (parent_uri);
6160 g_object_unref (parent);
6162 new_uri = g_strdup_printf ("file:///%s", uri);
6165 ret = g_app_info_launch_default_for_uri (new_uri, context, &error);
6168 ret = g_app_info_launch_default_for_uri (uri, context, &error);
6172 ev_window_error_message (window, error,
6173 "%s", _("Unable to open external link"));
6174 g_error_free (error);
6177 /* FIXMEchpe: unref launch context? */
6181 open_remote_link (EvWindow *window, EvLinkAction *action)
6186 dir = g_path_get_dirname (window->priv->uri);
6188 uri = g_build_filename (dir, ev_link_action_get_filename (action),
6192 ev_application_open_uri_at_dest (EV_APP, uri,
6193 gtk_window_get_screen (GTK_WINDOW (window)),
6194 ev_link_action_get_dest (action),
6197 gtk_get_current_event_time ());
6203 do_action_named (EvWindow *window, EvLinkAction *action)
6205 const gchar *name = ev_link_action_get_name (action);
6207 if (g_ascii_strcasecmp (name, "FirstPage") == 0) {
6208 ev_window_cmd_go_first_page (NULL, window);
6209 } else if (g_ascii_strcasecmp (name, "PrevPage") == 0) {
6210 ev_window_cmd_go_previous_page (NULL, window);
6211 } else if (g_ascii_strcasecmp (name, "NextPage") == 0) {
6212 ev_window_cmd_go_next_page (NULL, window);
6213 } else if (g_ascii_strcasecmp (name, "LastPage") == 0) {
6214 ev_window_cmd_go_last_page (NULL, window);
6215 } else if (g_ascii_strcasecmp (name, "GoToPage") == 0) {
6216 ev_window_cmd_focus_page_selector (NULL, window);
6217 } else if (g_ascii_strcasecmp (name, "Find") == 0) {
6218 ev_window_cmd_edit_find (NULL, window);
6219 } else if (g_ascii_strcasecmp (name, "Close") == 0) {
6220 ev_window_cmd_file_close_window (NULL, window);
6221 } else if (g_ascii_strcasecmp (name, "Print") == 0) {
6222 ev_window_cmd_file_print (NULL, window);
6224 g_warning ("Unimplemented named action: %s, please post a "
6225 "bug report in Evince bugzilla "
6226 "(http://bugzilla.gnome.org) with a testcase.",
6232 view_external_link_cb (EvView *view, EvLinkAction *action, EvWindow *window)
6234 switch (ev_link_action_get_action_type (action)) {
6235 case EV_LINK_ACTION_TYPE_GOTO_DEST: {
6238 dest = ev_link_action_get_dest (action);
6242 ev_window_open_copy_at_dest (window, dest);
6245 case EV_LINK_ACTION_TYPE_EXTERNAL_URI:
6246 launch_external_uri (window, action);
6248 case EV_LINK_ACTION_TYPE_LAUNCH:
6249 launch_action (window, action);
6251 case EV_LINK_ACTION_TYPE_GOTO_REMOTE:
6252 open_remote_link (window, action);
6254 case EV_LINK_ACTION_TYPE_NAMED:
6255 do_action_named (window, action);
6258 g_assert_not_reached ();
6263 ev_view_popup_cmd_open_link (GtkAction *action, EvWindow *window)
6265 ev_view_handle_link (EV_VIEW (window->priv->view), window->priv->link);
6269 ev_view_popup_cmd_open_link_new_window (GtkAction *action, EvWindow *window)
6271 EvLinkAction *ev_action = NULL;
6274 ev_action = ev_link_get_action (window->priv->link);
6278 dest = ev_link_action_get_dest (ev_action);
6282 ev_window_open_copy_at_dest (window, dest);
6286 ev_view_popup_cmd_copy_link_address (GtkAction *action, EvWindow *window)
6288 EvLinkAction *ev_action;
6290 ev_action = ev_link_get_action (window->priv->link);
6294 ev_view_copy_link_address (EV_VIEW (window->priv->view),
6300 image_save_dialog_response_cb (GtkWidget *fc,
6302 EvWindow *ev_window)
6306 GError *error = NULL;
6312 GdkPixbufFormat *format;
6313 GtkFileFilter *filter;
6315 if (response_id != GTK_RESPONSE_OK) {
6316 gtk_widget_destroy (fc);
6320 uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
6321 filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (fc));
6322 format = g_object_get_data (G_OBJECT (filter), "pixbuf-format");
6324 if (format == NULL) {
6325 format = get_gdk_pixbuf_format_by_extension (uri);
6328 if (format == NULL && g_strrstr (uri, ".") == NULL) {
6329 /* no extension found and no extension provided within uri */
6330 format = get_gdk_pixbuf_format_by_extension (".png");
6331 if (format == NULL) {
6332 /* no .png support, try .jpeg */
6333 format = get_gdk_pixbuf_format_by_extension (".jpeg");
6337 if (format == NULL) {
6338 ev_window_error_message (ev_window, NULL,
6340 _("Couldn't find appropriate format to save image"));
6342 gtk_widget_destroy (fc);
6347 extensions = gdk_pixbuf_format_get_extensions (format);
6348 if (!g_str_has_suffix (uri, extensions[0])) {
6349 gchar *uri_extension;
6351 uri_extension = g_strconcat (uri, ".", extensions[0], NULL);
6352 target_file = g_file_new_for_uri (uri_extension);
6353 g_free (uri_extension);
6355 target_file = g_file_new_for_uri (uri);
6357 g_strfreev (extensions);
6360 is_native = g_file_is_native (target_file);
6362 filename = g_file_get_path (target_file);
6364 /* Create a temporary local file to save to */
6365 if (ev_mkstemp ("saveimage.XXXXXX", &filename, &error) == -1)
6369 ev_document_doc_mutex_lock ();
6370 pixbuf = ev_document_images_get_image (EV_DOCUMENT_IMAGES (ev_window->priv->document),
6371 ev_window->priv->image);
6372 ev_document_doc_mutex_unlock ();
6374 file_format = gdk_pixbuf_format_get_name (format);
6375 gdk_pixbuf_save (pixbuf, filename, file_format, &error, NULL);
6376 g_free (file_format);
6377 g_object_unref (pixbuf);
6381 ev_window_error_message (ev_window, error,
6382 "%s", _("The image could not be saved."));
6383 g_error_free (error);
6385 g_object_unref (target_file);
6386 gtk_widget_destroy (fc);
6394 source_file = g_file_new_for_path (filename);
6396 ev_window_save_remote (ev_window, EV_SAVE_IMAGE,
6397 source_file, target_file);
6398 g_object_unref (source_file);
6402 g_object_unref (target_file);
6403 gtk_widget_destroy (fc);
6407 ev_view_popup_cmd_save_image_as (GtkAction *action, EvWindow *window)
6411 if (!window->priv->image)
6414 fc = gtk_file_chooser_dialog_new (_("Save Image"),
6415 GTK_WINDOW (window),
6416 GTK_FILE_CHOOSER_ACTION_SAVE,
6418 GTK_RESPONSE_CANCEL,
6419 GTK_STOCK_SAVE, GTK_RESPONSE_OK,
6422 gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
6423 gtk_dialog_set_alternative_button_order (GTK_DIALOG (fc),
6425 GTK_RESPONSE_CANCEL,
6428 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (fc), FALSE);
6429 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
6431 file_chooser_dialog_add_writable_pixbuf_formats (GTK_FILE_CHOOSER (fc));
6433 g_signal_connect (fc, "response",
6434 G_CALLBACK (image_save_dialog_response_cb),
6437 gtk_widget_show (fc);
6441 ev_view_popup_cmd_copy_image (GtkAction *action, EvWindow *window)
6443 GtkClipboard *clipboard;
6446 if (!window->priv->image)
6449 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (window),
6450 GDK_SELECTION_CLIPBOARD);
6451 ev_document_doc_mutex_lock ();
6452 pixbuf = ev_document_images_get_image (EV_DOCUMENT_IMAGES (window->priv->document),
6453 window->priv->image);
6454 ev_document_doc_mutex_unlock ();
6456 gtk_clipboard_set_image (clipboard, pixbuf);
6457 g_object_unref (pixbuf);
6461 ev_view_popup_cmd_annot_properties (GtkAction *action,
6464 const gchar *author;
6467 gboolean popup_is_open;
6468 EvAnnotationPropertiesDialog *dialog;
6469 EvAnnotation *annot = window->priv->annot;
6470 EvAnnotationsSaveMask mask = EV_ANNOTATIONS_SAVE_NONE;
6475 dialog = EV_ANNOTATION_PROPERTIES_DIALOG (ev_annotation_properties_dialog_new_with_annotation (window->priv->annot));
6476 if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_APPLY) {
6477 gtk_widget_destroy (GTK_WIDGET (dialog));
6482 /* Set annotations changes */
6483 author = ev_annotation_properties_dialog_get_author (dialog);
6484 if (ev_annotation_markup_set_label (EV_ANNOTATION_MARKUP (annot), author))
6485 mask |= EV_ANNOTATIONS_SAVE_LABEL;
6487 ev_annotation_properties_dialog_get_color (dialog, &color);
6488 if (ev_annotation_set_color (annot, &color))
6489 mask |= EV_ANNOTATIONS_SAVE_COLOR;
6491 opacity = ev_annotation_properties_dialog_get_opacity (dialog);
6492 if (ev_annotation_markup_set_opacity (EV_ANNOTATION_MARKUP (annot), opacity))
6493 mask |= EV_ANNOTATIONS_SAVE_OPACITY;
6495 popup_is_open = ev_annotation_properties_dialog_get_popup_is_open (dialog);
6496 if (ev_annotation_markup_set_popup_is_open (EV_ANNOTATION_MARKUP (annot), popup_is_open))
6497 mask |= EV_ANNOTATIONS_SAVE_POPUP_IS_OPEN;
6499 if (EV_IS_ANNOTATION_TEXT (annot)) {
6500 EvAnnotationTextIcon icon;
6502 icon = ev_annotation_properties_dialog_get_text_icon (dialog);
6503 if (ev_annotation_text_set_icon (EV_ANNOTATION_TEXT (annot), icon))
6504 mask |= EV_ANNOTATIONS_SAVE_TEXT_ICON;
6507 if (mask != EV_ANNOTATIONS_SAVE_NONE) {
6508 ev_document_doc_mutex_lock ();
6509 ev_document_annotations_save_annotation (EV_DOCUMENT_ANNOTATIONS (window->priv->document),
6510 window->priv->annot,
6512 ev_document_doc_mutex_unlock ();
6514 /* FIXME: update annot region only */
6515 ev_view_reload (EV_VIEW (window->priv->view));
6518 gtk_widget_destroy (GTK_WIDGET (dialog));
6522 ev_attachment_popup_cmd_open_attachment (GtkAction *action, EvWindow *window)
6527 if (!window->priv->attach_list)
6530 screen = gtk_window_get_screen (GTK_WINDOW (window));
6532 for (l = window->priv->attach_list; l && l->data; l = g_list_next (l)) {
6533 EvAttachment *attachment;
6534 GError *error = NULL;
6536 attachment = (EvAttachment *) l->data;
6538 ev_attachment_open (attachment, screen, gtk_get_current_event_time (), &error);
6541 ev_window_error_message (window, error,
6542 "%s", _("Unable to open attachment"));
6543 g_error_free (error);
6549 attachment_save_dialog_response_cb (GtkWidget *fc,
6551 EvWindow *ev_window)
6556 GtkFileChooserAction fc_action;
6560 if (response_id != GTK_RESPONSE_OK) {
6561 gtk_widget_destroy (fc);
6565 uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
6566 target_file = g_file_new_for_uri (uri);
6567 g_object_get (G_OBJECT (fc), "action", &fc_action, NULL);
6568 is_dir = (fc_action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
6569 is_native = g_file_is_native (target_file);
6571 for (l = ev_window->priv->attach_list; l && l->data; l = g_list_next (l)) {
6572 EvAttachment *attachment;
6573 GFile *save_to = NULL;
6574 GError *error = NULL;
6576 attachment = (EvAttachment *) l->data;
6580 save_to = g_file_get_child (target_file,
6581 /* FIXMEchpe: file name encoding! */
6582 ev_attachment_get_name (attachment));
6584 save_to = g_object_ref (target_file);
6587 save_to = ev_mkstemp_file ("saveattachment.XXXXXX", &error);
6591 ev_attachment_save (attachment, save_to, &error);
6594 ev_window_error_message (ev_window, error,
6595 "%s", _("The attachment could not be saved."));
6596 g_error_free (error);
6597 g_object_unref (save_to);
6606 dest_file = g_file_get_child (target_file,
6607 ev_attachment_get_name (attachment));
6609 dest_file = g_object_ref (target_file);
6612 ev_window_save_remote (ev_window, EV_SAVE_ATTACHMENT,
6613 save_to, dest_file);
6615 g_object_unref (dest_file);
6618 g_object_unref (save_to);
6622 g_object_unref (target_file);
6624 gtk_widget_destroy (fc);
6628 ev_attachment_popup_cmd_save_attachment_as (GtkAction *action, EvWindow *window)
6631 EvAttachment *attachment = NULL;
6633 if (!window->priv->attach_list)
6636 if (g_list_length (window->priv->attach_list) == 1)
6637 attachment = (EvAttachment *) window->priv->attach_list->data;
6639 fc = gtk_file_chooser_dialog_new (
6640 _("Save Attachment"),
6641 GTK_WINDOW (window),
6642 attachment ? GTK_FILE_CHOOSER_ACTION_SAVE : GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
6644 GTK_RESPONSE_CANCEL,
6645 GTK_STOCK_SAVE, GTK_RESPONSE_OK,
6648 gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
6649 gtk_dialog_set_alternative_button_order (GTK_DIALOG (fc),
6651 GTK_RESPONSE_CANCEL,
6654 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
6655 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (fc), FALSE);
6658 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc),
6659 ev_attachment_get_name (attachment));
6661 g_signal_connect (fc, "response",
6662 G_CALLBACK (attachment_save_dialog_response_cb),
6665 gtk_widget_show (fc);
6669 ev_window_media_player_key_pressed (EvWindow *window,
6673 if (!gtk_window_is_active (GTK_WINDOW (window)))
6676 /* Note how Previous/Next only go to the
6677 * next/previous page despite their icon telling you
6678 * they should go to the beginning/end.
6680 * There's very few keyboards with FFW/RWD though,
6681 * so we stick the most useful keybinding on the most
6684 if (strcmp (key, "Play") == 0) {
6685 ev_window_run_presentation (window);
6686 } else if (strcmp (key, "Previous") == 0) {
6687 ev_window_cmd_go_previous_page (NULL, window);
6688 } else if (strcmp (key, "Next") == 0) {
6689 ev_window_cmd_go_next_page (NULL, window);
6690 } else if (strcmp (key, "FastForward") == 0) {
6691 ev_window_cmd_go_last_page (NULL, window);
6692 } else if (strcmp (key, "Rewind") == 0) {
6693 ev_window_cmd_go_first_page (NULL, window);
6697 static EggToolbarsModel *
6698 get_toolbars_model (void)
6700 EggToolbarsModel *toolbars_model;
6701 gchar *toolbars_file;
6702 gchar *toolbars_path;
6705 toolbars_model = egg_toolbars_model_new ();
6707 toolbars_file = g_build_filename (ev_application_get_dot_dir (EV_APP, FALSE),
6708 "evince_toolbar.xml", NULL);
6709 toolbars_path = g_build_filename (ev_application_get_data_dir (EV_APP),
6710 "evince-toolbar.xml", NULL);
6711 egg_toolbars_model_load_names (toolbars_model, toolbars_path);
6713 if (!egg_toolbars_model_load_toolbars (toolbars_model, toolbars_file)) {
6714 egg_toolbars_model_load_toolbars (toolbars_model, toolbars_path);
6715 goto skip_conversion;
6718 /* Open item doesn't exist anymore,
6719 * convert it to OpenRecent for compatibility
6721 for (i = 0; i < egg_toolbars_model_n_items (toolbars_model, 0); i++) {
6724 item = egg_toolbars_model_item_nth (toolbars_model, 0, i);
6725 if (g_ascii_strcasecmp (item, "FileOpen") == 0) {
6726 egg_toolbars_model_remove_item (toolbars_model, 0, i);
6727 egg_toolbars_model_add_item (toolbars_model, 0, i,
6729 egg_toolbars_model_save_toolbars (toolbars_model, toolbars_file, "1.0");
6735 g_free (toolbars_file);
6736 g_free (toolbars_path);
6738 egg_toolbars_model_set_flags (toolbars_model, 0, EGG_TB_MODEL_NOT_REMOVABLE);
6740 return toolbars_model;
6745 ev_window_sync_source (EvWindow *window,
6748 GDBusConnection *connection;
6749 GError *error = NULL;
6754 if (window->priv->dbus_object_id <= 0)
6757 connection = ev_application_get_dbus_connection (EV_APP);
6761 timestamp = gtk_get_current_event_time ();
6762 if (g_path_is_absolute (link->filename)) {
6763 input_gfile = g_file_new_for_path (link->filename);
6765 GFile *gfile, *parent_gfile;
6767 gfile = g_file_new_for_uri (window->priv->uri);
6768 parent_gfile = g_file_get_parent (gfile);
6770 /* parent_gfile should never be NULL */
6771 if (parent_gfile == NULL) {
6772 g_printerr ("Document URI is '/'\n");
6776 input_gfile = g_file_get_child (parent_gfile, link->filename);
6777 g_object_unref (parent_gfile);
6778 g_object_unref (gfile);
6781 uri_input = g_file_get_uri (input_gfile);
6782 g_object_unref (input_gfile);
6784 g_dbus_connection_emit_signal (connection,
6786 window->priv->dbus_object_path,
6787 EV_WINDOW_DBUS_INTERFACE,
6789 g_variant_new ("(s(ii)u)",
6797 g_printerr ("Failed to emit DBus signal SyncSource: %s\n",
6799 g_error_free (error);
6804 ev_window_emit_closed (EvWindow *window)
6806 GDBusConnection *connection;
6807 GError *error = NULL;
6809 if (window->priv->dbus_object_id <= 0)
6812 connection = ev_application_get_dbus_connection (EV_APP);
6816 g_dbus_connection_emit_signal (connection,
6818 window->priv->dbus_object_path,
6819 EV_WINDOW_DBUS_INTERFACE,
6824 g_printerr ("Failed to emit DBus signal Closed: %s\n",
6826 g_error_free (error);
6831 /* If this is the last window call g_dbus_connection_flush_sync()
6832 * to make sure the signal is emitted.
6834 if (ev_application_get_n_windows (EV_APP) == 1)
6835 g_dbus_connection_flush_sync (connection, NULL, NULL);
6839 ev_window_emit_doc_loaded (EvWindow *window)
6841 GDBusConnection *connection;
6842 GError *error = NULL;
6844 if (window->priv->dbus_object_id <= 0)
6847 connection = ev_application_get_dbus_connection (EV_APP);
6851 g_dbus_connection_emit_signal (connection,
6853 window->priv->dbus_object_path,
6854 EV_WINDOW_DBUS_INTERFACE,
6856 g_variant_new("(s)", window->priv->uri),
6859 g_printerr ("Failed to emit DBus signal DocumentLoaded: %s\n",
6861 g_error_free (error);
6868 method_call_cb (GDBusConnection *connection,
6869 const gchar *sender,
6870 const gchar *object_path,
6871 const gchar *interface_name,
6872 const gchar *method_name,
6873 GVariant *parameters,
6874 GDBusMethodInvocation *invocation,
6877 EvWindow *window = EV_WINDOW (user_data);
6879 if (g_strcmp0 (method_name, "SyncView") != 0)
6882 if (window->priv->document && ev_document_has_synctex (window->priv->document)) {
6886 g_variant_get (parameters, "(&s(ii)u)", &link.filename, &link.line, &link.col, ×tamp);
6887 ev_view_highlight_forward_search (EV_VIEW (window->priv->view), &link);
6888 gtk_window_present_with_time (GTK_WINDOW (window), timestamp);
6891 g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
6894 static const char introspection_xml[] =
6896 "<interface name='org.gnome.evince.Window'>"
6897 "<method name='SyncView'>"
6898 "<arg type='s' name='source_file' direction='in'/>"
6899 "<arg type='(ii)' name='source_point' direction='in'/>"
6900 "<arg type='u' name='timestamp' direction='in'/>"
6902 "<signal name='SyncSource'>"
6903 "<arg type='s' name='source_file' direction='out'/>"
6904 "<arg type='(ii)' name='source_point' direction='out'/>"
6905 "<arg type='u' name='timestamp' direction='out'/>"
6907 "<signal name='Closed'/>"
6908 "<signal name='DocumentLoaded'>"
6909 "<arg type='s' name='uri' direction='out'/>"
6914 static const GDBusInterfaceVTable interface_vtable = {
6920 static GDBusNodeInfo *introspection_data;
6921 #endif /* ENABLE_DBUS */
6924 ev_window_init (EvWindow *ev_window)
6926 GtkActionGroup *action_group;
6927 GtkAccelGroup *accel_group;
6928 GError *error = NULL;
6929 GtkWidget *sidebar_widget;
6930 GtkWidget *menuitem;
6931 EggToolbarsModel *toolbars_model;
6935 GDBusConnection *connection;
6936 static gint window_id = 0;
6939 g_signal_connect (ev_window, "configure_event",
6940 G_CALLBACK (window_configure_event_cb), NULL);
6941 g_signal_connect (ev_window, "window_state_event",
6942 G_CALLBACK (window_state_event_cb), NULL);
6944 ev_window->priv = EV_WINDOW_GET_PRIVATE (ev_window);
6947 connection = ev_application_get_dbus_connection (EV_APP);
6949 if (!introspection_data) {
6950 introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, &error);
6951 if (error) g_warning ("%s\n", error->message);
6953 g_assert (introspection_data != NULL);
6955 ev_window->priv->dbus_object_path = g_strdup_printf (EV_WINDOW_DBUS_OBJECT_PATH, window_id++);
6956 ev_window->priv->dbus_object_id =
6957 g_dbus_connection_register_object (connection,
6958 ev_window->priv->dbus_object_path,
6959 introspection_data->interfaces[0],
6963 if (ev_window->priv->dbus_object_id == 0) {
6964 g_printerr ("Failed to register bus object %s: %s\n",
6965 ev_window->priv->dbus_object_path, error->message);
6966 g_error_free (error);
6967 g_free (ev_window->priv->dbus_object_path);
6968 ev_window->priv->dbus_object_path = NULL;
6973 #endif /* ENABLE_DBUS */
6975 ev_window->priv->model = ev_document_model_new ();
6977 ev_window->priv->page_mode = PAGE_MODE_DOCUMENT;
6978 ev_window->priv->title = ev_window_title_new (ev_window);
6980 ev_window->priv->main_box = gtk_vbox_new (FALSE, 0);
6981 gtk_container_add (GTK_CONTAINER (ev_window), ev_window->priv->main_box);
6982 gtk_widget_show (ev_window->priv->main_box);
6984 action_group = gtk_action_group_new ("MenuActions");
6985 ev_window->priv->action_group = action_group;
6986 gtk_action_group_set_translation_domain (action_group, NULL);
6987 gtk_action_group_add_actions (action_group, entries,
6988 G_N_ELEMENTS (entries), ev_window);
6989 gtk_action_group_add_toggle_actions (action_group, toggle_entries,
6990 G_N_ELEMENTS (toggle_entries),
6992 set_action_properties (action_group);
6993 register_custom_actions (ev_window, action_group);
6995 ev_window->priv->ui_manager = gtk_ui_manager_new ();
6996 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
7000 gtk_ui_manager_get_accel_group (ev_window->priv->ui_manager);
7001 gtk_window_add_accel_group (GTK_WINDOW (ev_window), accel_group);
7003 ev_window_set_view_accels_sensitivity (ev_window, FALSE);
7005 action_group = gtk_action_group_new ("ViewPopupActions");
7006 ev_window->priv->view_popup_action_group = action_group;
7007 gtk_action_group_set_translation_domain (action_group, NULL);
7008 gtk_action_group_add_actions (action_group, view_popup_entries,
7009 G_N_ELEMENTS (view_popup_entries),
7011 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
7014 action_group = gtk_action_group_new ("AttachmentPopupActions");
7015 ev_window->priv->attachment_popup_action_group = action_group;
7016 gtk_action_group_set_translation_domain (action_group, NULL);
7017 gtk_action_group_add_actions (action_group, attachment_popup_entries,
7018 G_N_ELEMENTS (attachment_popup_entries),
7020 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
7023 ui_path = g_build_filename (ev_application_get_data_dir (EV_APP),
7024 "evince-ui.xml", NULL);
7025 if (!gtk_ui_manager_add_ui_from_file (
7026 ev_window->priv->ui_manager, ui_path, &error))
7028 g_warning ("building menus failed: %s", error->message);
7029 g_error_free (error);
7033 ev_window->priv->recent_manager = gtk_recent_manager_get_default ();
7034 ev_window->priv->recent_action_group = NULL;
7035 ev_window->priv->recent_ui_id = 0;
7036 g_signal_connect_swapped (ev_window->priv->recent_manager,
7038 G_CALLBACK (ev_window_setup_recent),
7041 ev_window->priv->menubar =
7042 gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
7044 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box),
7045 ev_window->priv->menubar,
7047 menuitem = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
7048 "/MainMenu/EditMenu/EditRotateLeftMenu");
7049 gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menuitem), TRUE);
7050 menuitem = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
7051 "/MainMenu/EditMenu/EditRotateRightMenu");
7052 gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menuitem), TRUE);
7054 toolbars_model = get_toolbars_model ();
7055 ev_window->priv->toolbar = GTK_WIDGET
7056 (g_object_new (EGG_TYPE_EDITABLE_TOOLBAR,
7057 "ui-manager", ev_window->priv->ui_manager,
7058 "popup-path", "/ToolbarPopup",
7059 "model", toolbars_model,
7061 g_object_unref (toolbars_model);
7063 egg_editable_toolbar_show (EGG_EDITABLE_TOOLBAR (ev_window->priv->toolbar),
7065 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box),
7066 ev_window->priv->toolbar,
7068 gtk_widget_show (ev_window->priv->toolbar);
7070 /* Add the main area */
7071 ev_window->priv->hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
7072 g_signal_connect (ev_window->priv->hpaned,
7074 G_CALLBACK (ev_window_sidebar_position_change_cb),
7077 gtk_paned_set_position (GTK_PANED (ev_window->priv->hpaned), SIDEBAR_DEFAULT_SIZE);
7078 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), ev_window->priv->hpaned,
7080 gtk_widget_show (ev_window->priv->hpaned);
7082 ev_window->priv->sidebar = ev_sidebar_new ();
7083 ev_sidebar_set_model (EV_SIDEBAR (ev_window->priv->sidebar),
7084 ev_window->priv->model);
7085 gtk_paned_pack1 (GTK_PANED (ev_window->priv->hpaned),
7086 ev_window->priv->sidebar, FALSE, FALSE);
7087 gtk_widget_show (ev_window->priv->sidebar);
7089 /* Stub sidebar, for now */
7091 sidebar_widget = ev_sidebar_thumbnails_new ();
7092 ev_window->priv->sidebar_thumbs = sidebar_widget;
7093 g_signal_connect (sidebar_widget,
7094 "notify::main-widget",
7095 G_CALLBACK (sidebar_page_main_widget_update_cb),
7097 sidebar_page_main_widget_update_cb (G_OBJECT (sidebar_widget), NULL, ev_window);
7098 gtk_widget_show (sidebar_widget);
7099 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7102 sidebar_widget = ev_sidebar_links_new ();
7103 ev_window->priv->sidebar_links = sidebar_widget;
7104 g_signal_connect (sidebar_widget,
7106 G_CALLBACK (sidebar_widget_model_set),
7108 g_signal_connect (sidebar_widget,
7110 G_CALLBACK (sidebar_links_link_activated_cb),
7112 sidebar_page_main_widget_update_cb (G_OBJECT (sidebar_widget), NULL, ev_window);
7113 gtk_widget_show (sidebar_widget);
7114 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7117 sidebar_widget = ev_sidebar_attachments_new ();
7118 ev_window->priv->sidebar_attachments = sidebar_widget;
7119 g_signal_connect_object (sidebar_widget,
7121 G_CALLBACK (attachment_bar_menu_popup_cb),
7123 gtk_widget_show (sidebar_widget);
7124 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7127 sidebar_widget = ev_sidebar_layers_new ();
7128 ev_window->priv->sidebar_layers = sidebar_widget;
7129 g_signal_connect (sidebar_widget,
7130 "layers_visibility_changed",
7131 G_CALLBACK (sidebar_layers_visibility_changed),
7133 gtk_widget_show (sidebar_widget);
7134 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7137 sidebar_widget = ev_sidebar_annotations_new ();
7138 ev_window->priv->sidebar_annots = sidebar_widget;
7139 g_signal_connect (sidebar_widget,
7141 G_CALLBACK (sidebar_annots_annot_activated_cb),
7143 g_signal_connect (sidebar_widget,
7145 G_CALLBACK (sidebar_annots_begin_annot_add),
7147 g_signal_connect (sidebar_widget,
7148 "annot_add_cancelled",
7149 G_CALLBACK (sidebar_annots_annot_add_cancelled),
7151 gtk_widget_show (sidebar_widget);
7152 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7155 sidebar_widget = ev_sidebar_bookmarks_new ();
7156 ev_window->priv->sidebar_bookmarks = sidebar_widget;
7157 g_signal_connect (sidebar_widget,
7159 G_CALLBACK (sidebar_bookmarks_add_bookmark),
7161 gtk_widget_show (sidebar_widget);
7162 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7165 ev_window->priv->view_box = gtk_vbox_new (FALSE, 0);
7166 ev_window->priv->scrolled_window =
7167 GTK_WIDGET (g_object_new (GTK_TYPE_SCROLLED_WINDOW,
7168 "shadow-type", GTK_SHADOW_IN,
7170 gtk_box_pack_start (GTK_BOX (ev_window->priv->view_box),
7171 ev_window->priv->scrolled_window,
7173 gtk_widget_show (ev_window->priv->scrolled_window);
7175 gtk_paned_add2 (GTK_PANED (ev_window->priv->hpaned),
7176 ev_window->priv->view_box);
7177 gtk_widget_show (ev_window->priv->view_box);
7179 ev_window->priv->view = ev_view_new ();
7180 ev_view_set_page_cache_size (EV_VIEW (ev_window->priv->view), PAGE_CACHE_SIZE);
7181 ev_view_set_model (EV_VIEW (ev_window->priv->view), ev_window->priv->model);
7183 ev_window->priv->password_view = ev_password_view_new (GTK_WINDOW (ev_window));
7184 g_signal_connect_swapped (ev_window->priv->password_view,
7186 G_CALLBACK (ev_window_password_view_unlock),
7188 g_signal_connect_object (ev_window->priv->view, "focus_in_event",
7189 G_CALLBACK (view_actions_focus_in_cb),
7191 g_signal_connect_object (ev_window->priv->view, "focus_out_event",
7192 G_CALLBACK (view_actions_focus_out_cb),
7194 g_signal_connect_object (ev_window->priv->view, "external-link",
7195 G_CALLBACK (view_external_link_cb),
7197 g_signal_connect_object (ev_window->priv->view, "handle-link",
7198 G_CALLBACK (view_handle_link_cb),
7200 g_signal_connect_object (ev_window->priv->view, "popup",
7201 G_CALLBACK (view_menu_popup_cb),
7203 g_signal_connect_object (ev_window->priv->view, "selection-changed",
7204 G_CALLBACK (view_selection_changed_cb),
7206 g_signal_connect_object (ev_window->priv->view, "annot-added",
7207 G_CALLBACK (view_annot_added),
7209 g_signal_connect_object (ev_window->priv->view, "layers-changed",
7210 G_CALLBACK (view_layers_changed_cb),
7213 g_signal_connect_swapped (ev_window->priv->view, "sync-source",
7214 G_CALLBACK (ev_window_sync_source),
7217 gtk_widget_show (ev_window->priv->view);
7218 gtk_widget_show (ev_window->priv->password_view);
7221 ev_window->priv->find_bar = egg_find_bar_new ();
7222 gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
7223 ev_window->priv->find_bar,
7226 /* We own a ref on these widgets, as we can swap them in and out */
7227 g_object_ref (ev_window->priv->view);
7228 g_object_ref (ev_window->priv->password_view);
7230 gtk_container_add (GTK_CONTAINER (ev_window->priv->scrolled_window),
7231 ev_window->priv->view);
7233 /* Connect to model signals */
7234 g_signal_connect_swapped (ev_window->priv->model,
7236 G_CALLBACK (ev_window_page_changed_cb),
7238 g_signal_connect (ev_window->priv->model,
7240 G_CALLBACK (ev_window_document_changed_cb),
7242 g_signal_connect (ev_window->priv->model,
7244 G_CALLBACK (ev_window_zoom_changed_cb),
7246 g_signal_connect (ev_window->priv->model,
7247 "notify::sizing-mode",
7248 G_CALLBACK (ev_window_sizing_mode_changed_cb),
7250 g_signal_connect (ev_window->priv->model,
7252 G_CALLBACK (ev_window_rotation_changed_cb),
7254 g_signal_connect (ev_window->priv->model,
7255 "notify::continuous",
7256 G_CALLBACK (ev_window_continuous_changed_cb),
7258 g_signal_connect (ev_window->priv->model,
7259 "notify::dual-page",
7260 G_CALLBACK (ev_window_dual_mode_changed_cb),
7262 g_signal_connect (ev_window->priv->model,
7263 "notify::inverted-colors",
7264 G_CALLBACK (ev_window_inverted_colors_changed_cb),
7267 /* Connect sidebar signals */
7268 g_signal_connect (ev_window->priv->sidebar,
7270 G_CALLBACK (ev_window_sidebar_visibility_changed_cb),
7272 g_signal_connect (ev_window->priv->sidebar,
7273 "notify::current-page",
7274 G_CALLBACK (ev_window_sidebar_current_page_changed_cb),
7277 /* Connect to find bar signals */
7278 g_signal_connect (ev_window->priv->find_bar,
7280 G_CALLBACK (find_bar_previous_cb),
7282 g_signal_connect (ev_window->priv->find_bar,
7284 G_CALLBACK (find_bar_next_cb),
7286 g_signal_connect (ev_window->priv->find_bar,
7288 G_CALLBACK (find_bar_close_cb),
7290 g_signal_connect (ev_window->priv->find_bar,
7291 "notify::search-string",
7292 G_CALLBACK (find_bar_search_changed_cb),
7294 g_signal_connect (ev_window->priv->find_bar,
7295 "notify::case-sensitive",
7296 G_CALLBACK (find_bar_search_changed_cb),
7298 g_signal_connect (ev_window->priv->find_bar,
7300 G_CALLBACK (find_bar_visibility_changed_cb),
7302 g_signal_connect (ev_window->priv->find_bar,
7304 G_CALLBACK (find_bar_scroll),
7308 ev_window->priv->view_popup = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
7310 ev_window->priv->link = NULL;
7312 ev_window->priv->attachment_popup = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
7313 "/AttachmentPopup");
7314 ev_window->priv->attach_list = NULL;
7316 /* Media player keys */
7317 mpkeys = ev_application_get_media_keys (EV_APP);
7319 g_signal_connect_swapped (mpkeys, "key_pressed",
7320 G_CALLBACK (ev_window_media_player_key_pressed),
7324 /* Give focus to the document view */
7325 gtk_widget_grab_focus (ev_window->priv->view);
7327 ev_window->priv->default_settings = g_settings_new (GS_SCHEMA_NAME".Default");
7328 g_settings_delay (ev_window->priv->default_settings);
7330 /* Set it user interface params */
7331 ev_window_setup_recent (ev_window);
7333 ev_window_setup_gtk_settings (ev_window);
7335 setup_chrome_from_metadata (ev_window);
7336 update_chrome_actions (ev_window);
7337 update_chrome_visibility (ev_window);
7339 gtk_window_set_default_size (GTK_WINDOW (ev_window), 600, 600);
7341 setup_view_from_metadata (ev_window);
7342 setup_sidebar_from_metadata (ev_window);
7344 ev_window_sizing_mode_changed_cb (ev_window->priv->model, NULL, ev_window);
7345 ev_window_setup_action_sensitivity (ev_window);
7348 gtk_drag_dest_set (GTK_WIDGET (ev_window),
7349 GTK_DEST_DEFAULT_ALL,
7352 gtk_drag_dest_add_uri_targets (GTK_WIDGET (ev_window));
7358 * Creates a #GtkWidget that represents the window.
7360 * Returns: the #GtkWidget that represents the window.
7363 ev_window_new (void)
7365 GtkWidget *ev_window;
7367 ev_window = GTK_WIDGET (g_object_new (EV_TYPE_WINDOW,
7368 "type", GTK_WINDOW_TOPLEVEL,
7375 ev_window_get_dbus_object_path (EvWindow *ev_window)
7378 return ev_window->priv->dbus_object_path;