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 view_external_link_cb (EvWindow *window,
347 EvLinkAction *action);
348 static void ev_window_load_file_remote (EvWindow *ev_window,
350 static void ev_window_media_player_key_pressed (EvWindow *window,
353 static void ev_window_update_max_min_scale (EvWindow *window);
355 static void ev_window_emit_closed (EvWindow *window);
356 static void ev_window_emit_doc_loaded (EvWindow *window);
358 static void ev_window_setup_bookmarks (EvWindow *window);
360 static guint ev_window_n_copies = 0;
362 G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW)
365 get_screen_dpi (EvWindow *window)
369 screen = gtk_window_get_screen (GTK_WINDOW (window));
370 return ev_document_misc_get_screen_dpi (screen);
374 ev_window_is_editing_toolbar (EvWindow *ev_window)
376 return egg_editable_toolbar_get_edit_mode (EGG_EDITABLE_TOOLBAR (ev_window->priv->toolbar));
380 ev_window_set_action_sensitive (EvWindow *ev_window,
384 GtkAction *action = gtk_action_group_get_action (ev_window->priv->action_group,
386 gtk_action_set_sensitive (action, sensitive);
391 ev_window_setup_action_sensitivity (EvWindow *ev_window)
393 EvDocument *document = ev_window->priv->document;
394 const EvDocumentInfo *info = NULL;
395 gboolean has_document = FALSE;
396 gboolean ok_to_print = TRUE;
397 gboolean ok_to_copy = TRUE;
398 gboolean has_properties = TRUE;
399 gboolean override_restrictions = TRUE;
400 gboolean can_get_text = FALSE;
401 gboolean has_pages = FALSE;
402 gboolean can_find = FALSE;
406 has_pages = ev_document_get_n_pages (document) > 0;
407 info = ev_document_get_info (document);
410 if (!info || info->fields_mask == 0) {
411 has_properties = FALSE;
414 if (has_document && EV_IS_SELECTION (document)) {
418 if (has_pages && EV_IS_DOCUMENT_FIND (document)) {
422 if (has_document && ev_window->priv->settings) {
423 override_restrictions =
424 g_settings_get_boolean (ev_window->priv->settings,
425 GS_OVERRIDE_RESTRICTIONS);
428 if (!override_restrictions && info && info->fields_mask & EV_DOCUMENT_INFO_PERMISSIONS) {
429 ok_to_print = (info->permissions & EV_DOCUMENT_PERMISSIONS_OK_TO_PRINT);
430 ok_to_copy = (info->permissions & EV_DOCUMENT_PERMISSIONS_OK_TO_COPY);
433 if (has_document && !ev_print_operation_exists_for_document(document))
436 if (has_document && ev_window->priv->lockdown_settings &&
437 g_settings_get_boolean (ev_window->priv->lockdown_settings, GS_LOCKDOWN_SAVE)) {
441 if (has_document && ev_window->priv->lockdown_settings &&
442 g_settings_get_boolean (ev_window->priv->lockdown_settings, GS_LOCKDOWN_PRINT)) {
447 ev_window_set_action_sensitive (ev_window, "FileOpenCopy", has_document);
448 ev_window_set_action_sensitive (ev_window, "FileSaveAs", has_document && ok_to_copy);
449 ev_window_set_action_sensitive (ev_window, "FilePrint", has_pages && ok_to_print);
450 ev_window_set_action_sensitive (ev_window, "FileProperties", has_document && has_properties);
451 ev_window_set_action_sensitive (ev_window, "FileOpenContainingFolder", has_document);
454 ev_window_set_action_sensitive (ev_window, "EditSelectAll", has_pages && can_get_text);
455 ev_window_set_action_sensitive (ev_window, "EditFind", can_find);
456 ev_window_set_action_sensitive (ev_window, "Slash", can_find);
457 ev_window_set_action_sensitive (ev_window, "EditRotateLeft", has_pages);
458 ev_window_set_action_sensitive (ev_window, "EditRotateRight", has_pages);
461 ev_window_set_action_sensitive (ev_window, "ViewToolbar", !ev_window_is_editing_toolbar (ev_window));
462 ev_window_set_action_sensitive (ev_window, "ViewContinuous", has_pages);
463 ev_window_set_action_sensitive (ev_window, "ViewDual", has_pages);
464 ev_window_set_action_sensitive (ev_window, "ViewBestFit", has_pages);
465 ev_window_set_action_sensitive (ev_window, "ViewPageWidth", has_pages);
466 ev_window_set_action_sensitive (ev_window, "ViewReload", has_pages);
467 ev_window_set_action_sensitive (ev_window, "ViewAutoscroll", has_pages);
468 ev_window_set_action_sensitive (ev_window, "ViewInvertedColors", has_pages);
471 ev_window_set_action_sensitive (ev_window, "BookmarksAdd",
472 has_pages && ev_window->priv->bookmarks);
474 /* Toolbar-specific actions: */
475 ev_window_set_action_sensitive (ev_window, PAGE_SELECTOR_ACTION, has_pages);
476 ev_window_set_action_sensitive (ev_window, ZOOM_CONTROL_ACTION, has_pages);
477 ev_window_set_action_sensitive (ev_window, NAVIGATION_ACTION, FALSE);
479 ev_window_update_actions (ev_window);
483 ev_window_update_actions (EvWindow *ev_window)
485 EvView *view = EV_VIEW (ev_window->priv->view);
486 int n_pages = 0, page = -1;
487 gboolean has_pages = FALSE;
488 gboolean presentation_mode;
489 gboolean can_find_in_page = FALSE;
490 EvSizingMode sizing_mode;
492 if (ev_window->priv->document) {
493 page = ev_document_model_get_page (ev_window->priv->model);
494 n_pages = ev_document_get_n_pages (ev_window->priv->document);
495 has_pages = n_pages > 0;
498 can_find_in_page = (ev_window->priv->find_job &&
499 ev_job_find_has_results (EV_JOB_FIND (ev_window->priv->find_job)));
501 ev_window_set_action_sensitive (ev_window, "EditCopy",
503 ev_view_get_has_selection (view));
504 ev_window_set_action_sensitive (ev_window, "EditFindNext",
505 has_pages && can_find_in_page);
506 ev_window_set_action_sensitive (ev_window, "EditFindPrevious",
507 has_pages && can_find_in_page);
508 ev_window_set_action_sensitive (ev_window, "F3",
509 has_pages && can_find_in_page);
511 presentation_mode = EV_WINDOW_IS_PRESENTATION (ev_window);
513 ev_window_set_action_sensitive (ev_window, "ViewZoomIn",
515 ev_view_can_zoom_in (view) &&
517 ev_window_set_action_sensitive (ev_window, "ViewZoomOut",
519 ev_view_can_zoom_out (view) &&
524 ev_window_set_action_sensitive (ev_window, "GoPreviousPage", page > 0);
525 ev_window_set_action_sensitive (ev_window, "GoNextPage", page < n_pages - 1);
526 ev_window_set_action_sensitive (ev_window, "GoFirstPage", page > 0);
527 ev_window_set_action_sensitive (ev_window, "GoLastPage", page < n_pages - 1);
529 ev_window_set_action_sensitive (ev_window, "GoFirstPage", FALSE);
530 ev_window_set_action_sensitive (ev_window, "GoPreviousPage", FALSE);
531 ev_window_set_action_sensitive (ev_window, "GoNextPage", FALSE);
532 ev_window_set_action_sensitive (ev_window, "GoLastPage", FALSE);
535 sizing_mode = ev_document_model_get_sizing_mode (ev_window->priv->model);
536 if (has_pages && sizing_mode != EV_SIZING_FIT_WIDTH && sizing_mode != EV_SIZING_BEST_FIT) {
541 action = gtk_action_group_get_action (ev_window->priv->action_group,
542 ZOOM_CONTROL_ACTION);
544 real_zoom = ev_document_model_get_scale (ev_window->priv->model);
545 real_zoom *= 72.0 / get_screen_dpi (ev_window);
546 zoom = ephy_zoom_get_nearest_zoom_level (real_zoom);
548 ephy_zoom_action_set_zoom_level (EPHY_ZOOM_ACTION (action), zoom);
553 ev_window_set_view_accels_sensitivity (EvWindow *window, gboolean sensitive)
557 can_find = window->priv->document &&
558 EV_IS_DOCUMENT_FIND (window->priv->document);
560 if (window->priv->action_group) {
561 ev_window_set_action_sensitive (window, "PageDown", sensitive);
562 ev_window_set_action_sensitive (window, "PageUp", sensitive);
563 ev_window_set_action_sensitive (window, "Space", sensitive);
564 ev_window_set_action_sensitive (window, "ShiftSpace", sensitive);
565 ev_window_set_action_sensitive (window, "BackSpace", sensitive);
566 ev_window_set_action_sensitive (window, "ShiftBackSpace", sensitive);
567 ev_window_set_action_sensitive (window, "Return", sensitive);
568 ev_window_set_action_sensitive (window, "ShiftReturn", sensitive);
569 ev_window_set_action_sensitive (window, "Plus", sensitive);
570 ev_window_set_action_sensitive (window, "Minus", sensitive);
571 ev_window_set_action_sensitive (window, "KpPlus", sensitive);
572 ev_window_set_action_sensitive (window, "KpMinus", sensitive);
573 ev_window_set_action_sensitive (window, "Equal", sensitive);
574 ev_window_set_action_sensitive (window, "p", sensitive);
575 ev_window_set_action_sensitive (window, "n", sensitive);
577 ev_window_set_action_sensitive (window, "Slash", sensitive && can_find);
582 set_widget_visibility (GtkWidget *widget, gboolean visible)
584 g_assert (GTK_IS_WIDGET (widget));
587 gtk_widget_show (widget);
589 gtk_widget_hide (widget);
593 update_chrome_visibility (EvWindow *window)
595 EvWindowPrivate *priv = window->priv;
596 gboolean menubar, toolbar, findbar, fullscreen_toolbar, sidebar;
597 gboolean fullscreen_mode, presentation, fullscreen;
599 presentation = EV_WINDOW_IS_PRESENTATION (window);
600 fullscreen = ev_document_model_get_fullscreen (priv->model);
601 fullscreen_mode = fullscreen || presentation;
603 menubar = (priv->chrome & EV_CHROME_MENUBAR) != 0 && !fullscreen_mode;
604 toolbar = ((priv->chrome & EV_CHROME_TOOLBAR) != 0 ||
605 (priv->chrome & EV_CHROME_RAISE_TOOLBAR) != 0) && !fullscreen_mode;
606 fullscreen_toolbar = ((priv->chrome & EV_CHROME_FULLSCREEN_TOOLBAR) != 0 ||
607 (priv->chrome & EV_CHROME_RAISE_TOOLBAR) != 0) && fullscreen;
608 findbar = (priv->chrome & EV_CHROME_FINDBAR) != 0;
609 sidebar = (priv->chrome & EV_CHROME_SIDEBAR) != 0 && priv->document && !presentation;
611 set_widget_visibility (priv->menubar, menubar);
612 set_widget_visibility (priv->toolbar, toolbar);
613 set_widget_visibility (priv->find_bar, findbar);
614 set_widget_visibility (priv->sidebar, sidebar);
616 ev_window_set_action_sensitive (window, "EditToolbar", toolbar);
618 if (priv->fullscreen_toolbar != NULL) {
619 set_widget_visibility (priv->fullscreen_toolbar, fullscreen_toolbar);
624 update_chrome_flag (EvWindow *window, EvChrome flag, gboolean active)
626 EvWindowPrivate *priv = window->priv;
629 priv->chrome |= flag;
631 priv->chrome &= ~flag;
636 update_sizing_buttons (EvWindow *window)
638 GtkActionGroup *action_group = window->priv->action_group;
640 gboolean best_fit, page_width;
642 switch (ev_document_model_get_sizing_mode (window->priv->model)) {
643 case EV_SIZING_BEST_FIT:
647 case EV_SIZING_FIT_WIDTH:
652 best_fit = page_width = FALSE;
656 action = gtk_action_group_get_action (action_group, "ViewBestFit");
657 g_signal_handlers_block_by_func
658 (action, G_CALLBACK (ev_window_cmd_view_best_fit), window);
659 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), best_fit);
660 g_signal_handlers_unblock_by_func
661 (action, G_CALLBACK (ev_window_cmd_view_best_fit), window);
663 action = gtk_action_group_get_action (action_group, "ViewPageWidth");
664 g_signal_handlers_block_by_func
665 (action, G_CALLBACK (ev_window_cmd_view_page_width), window);
666 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), page_width);
667 g_signal_handlers_unblock_by_func
668 (action, G_CALLBACK (ev_window_cmd_view_page_width), window);
670 action = gtk_action_group_get_action (window->priv->action_group,
671 ZOOM_CONTROL_ACTION);
673 ephy_zoom_action_set_zoom_level (EPHY_ZOOM_ACTION (action),
675 } else if (page_width) {
676 ephy_zoom_action_set_zoom_level (EPHY_ZOOM_ACTION (action),
677 EPHY_ZOOM_FIT_WIDTH);
682 update_chrome_actions (EvWindow *window)
684 EvWindowPrivate *priv = window->priv;
685 GtkActionGroup *action_group = priv->action_group;
688 action= gtk_action_group_get_action (action_group, "ViewToolbar");
689 g_signal_handlers_block_by_func
690 (action, G_CALLBACK (ev_window_view_toolbar_cb), window);
691 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
692 (priv->chrome & EV_CHROME_TOOLBAR) != 0);
693 g_signal_handlers_unblock_by_func
694 (action, G_CALLBACK (ev_window_view_toolbar_cb), window);
698 * ev_window_is_empty:
699 * @ev_window: The instance of the #EvWindow.
701 * It does look if there is any document loaded or if there is any job to load
704 * Returns: %TRUE if there isn't any document loaded or any any documente to be
705 * loaded, %FALSE in other case.
708 ev_window_is_empty (const EvWindow *ev_window)
710 g_return_val_if_fail (EV_IS_WINDOW (ev_window), FALSE);
712 return (ev_window->priv->document == NULL) &&
713 (ev_window->priv->load_job == NULL);
717 ev_window_set_message_area (EvWindow *window,
720 if (window->priv->message_area == area)
723 if (window->priv->message_area)
724 gtk_widget_destroy (window->priv->message_area);
725 window->priv->message_area = area;
730 gtk_box_pack_start (GTK_BOX (window->priv->view_box),
731 window->priv->message_area,
733 gtk_box_reorder_child (GTK_BOX (window->priv->view_box),
734 window->priv->message_area, 0);
735 g_object_add_weak_pointer (G_OBJECT (window->priv->message_area),
736 (gpointer) &(window->priv->message_area));
740 ev_window_message_area_response_cb (EvMessageArea *area,
744 ev_window_set_message_area (window, NULL);
748 ev_window_error_message (EvWindow *window,
757 if (window->priv->message_area)
760 va_start (args, format);
761 msg = g_strdup_vprintf (format, args);
764 area = ev_message_area_new (GTK_MESSAGE_ERROR,
772 ev_message_area_set_secondary_text (EV_MESSAGE_AREA (area), error->message);
773 g_signal_connect (area, "response",
774 G_CALLBACK (ev_window_message_area_response_cb),
776 gtk_widget_show (area);
777 ev_window_set_message_area (window, area);
781 ev_window_warning_message (EvWindow *window,
789 if (window->priv->message_area)
792 va_start (args, format);
793 msg = g_strdup_vprintf (format, args);
796 area = ev_message_area_new (GTK_MESSAGE_WARNING,
803 g_signal_connect (area, "response",
804 G_CALLBACK (ev_window_message_area_response_cb),
806 gtk_widget_show (area);
807 ev_window_set_message_area (window, area);
810 typedef struct _PageTitleData {
811 const gchar *page_label;
816 ev_window_find_page_title (GtkTreeModel *tree_model,
823 gtk_tree_model_get (tree_model, iter,
824 EV_DOCUMENT_LINKS_COLUMN_PAGE_LABEL, &page_string,
830 if (!strcmp (page_string, data->page_label)) {
831 gtk_tree_model_get (tree_model, iter,
832 EV_DOCUMENT_LINKS_COLUMN_MARKUP, &data->page_title,
834 g_free (page_string);
838 g_free (page_string);
843 ev_window_get_page_title (EvWindow *window,
844 const gchar *page_label)
846 if (EV_IS_DOCUMENT_LINKS (window->priv->document) &&
847 ev_document_links_has_document_links (EV_DOCUMENT_LINKS (window->priv->document))) {
851 data.page_label = page_label;
852 data.page_title = NULL;
854 g_object_get (G_OBJECT (window->priv->sidebar_links),
858 gtk_tree_model_foreach (model,
859 (GtkTreeModelForeachFunc)ev_window_find_page_title,
862 g_object_unref (model);
865 return data.page_title;
872 ev_window_add_history (EvWindow *window, gint page, EvLink *link)
874 gchar *page_label = NULL;
878 EvLinkAction *action;
881 if (window->priv->history == NULL)
884 if (!EV_IS_DOCUMENT_LINKS (window->priv->document))
888 action = g_object_ref (ev_link_get_action (link));
889 dest = ev_link_action_get_dest (action);
890 page_label = ev_document_links_get_dest_page_label (EV_DOCUMENT_LINKS (window->priv->document), dest);
892 dest = ev_link_dest_new_page (page);
893 action = ev_link_action_new_dest (dest);
894 page_label = ev_document_get_page_label (window->priv->document, page);
900 page_title = ev_window_get_page_title (window, page_label);
902 link_title = g_strdup_printf (_("Page %s — %s"), page_label, page_title);
905 link_title = g_strdup_printf (_("Page %s"), page_label);
908 real_link = ev_link_new (link_title, action);
910 ev_history_add_link (window->priv->history, real_link);
914 g_object_unref (real_link);
918 view_handle_link_cb (EvView *view, EvLink *link, EvWindow *window)
920 int current_page = ev_document_model_get_page (window->priv->model);
922 ev_window_add_history (window, 0, link);
923 ev_window_add_history (window, current_page, NULL);
927 view_selection_changed_cb (EvView *view,
930 ev_window_set_action_sensitive (window, "EditCopy",
931 ev_view_get_has_selection (view));
935 view_layers_changed_cb (EvView *view,
938 ev_sidebar_layers_update_layers_state (EV_SIDEBAR_LAYERS (window->priv->sidebar_layers));
942 ev_window_page_changed_cb (EvWindow *ev_window,
945 EvDocumentModel *model)
947 ev_window_update_actions (ev_window);
949 ev_window_update_find_status_message (ev_window);
951 if (abs (new_page - old_page) > 1) {
952 ev_window_add_history (ev_window, new_page, NULL);
953 ev_window_add_history (ev_window, old_page, NULL);
956 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window))
957 ev_metadata_set_int (ev_window->priv->metadata, "page", new_page);
961 ev_window_sidebar_get_current_page_id (EvWindow *ev_window)
963 GtkWidget *current_page;
966 g_object_get (ev_window->priv->sidebar,
967 "current_page", ¤t_page,
970 if (current_page == ev_window->priv->sidebar_links) {
971 id = LINKS_SIDEBAR_ID;
972 } else if (current_page == ev_window->priv->sidebar_thumbs) {
973 id = THUMBNAILS_SIDEBAR_ID;
974 } else if (current_page == ev_window->priv->sidebar_attachments) {
975 id = ATTACHMENTS_SIDEBAR_ID;
976 } else if (current_page == ev_window->priv->sidebar_layers) {
977 id = LAYERS_SIDEBAR_ID;
978 } else if (current_page == ev_window->priv->sidebar_annots) {
979 id = ANNOTS_SIDEBAR_ID;
980 } else if (current_page == ev_window->priv->sidebar_bookmarks) {
981 id = BOOKMARKS_SIDEBAR_ID;
983 g_assert_not_reached();
986 g_object_unref (current_page);
992 ev_window_sidebar_set_current_page (EvWindow *window,
993 const gchar *page_id)
995 EvDocument *document = window->priv->document;
996 EvSidebar *sidebar = EV_SIDEBAR (window->priv->sidebar);
997 GtkWidget *links = window->priv->sidebar_links;
998 GtkWidget *thumbs = window->priv->sidebar_thumbs;
999 GtkWidget *attachments = window->priv->sidebar_attachments;
1000 GtkWidget *annots = window->priv->sidebar_annots;
1001 GtkWidget *layers = window->priv->sidebar_layers;
1002 GtkWidget *bookmarks = window->priv->sidebar_bookmarks;
1004 if (strcmp (page_id, LINKS_SIDEBAR_ID) == 0 &&
1005 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (links), document)) {
1006 ev_sidebar_set_page (sidebar, links);
1007 } else if (strcmp (page_id, THUMBNAILS_SIDEBAR_ID) == 0 &&
1008 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (thumbs), document)) {
1009 ev_sidebar_set_page (sidebar, thumbs);
1010 } else if (strcmp (page_id, ATTACHMENTS_SIDEBAR_ID) == 0 &&
1011 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (attachments), document)) {
1012 ev_sidebar_set_page (sidebar, attachments);
1013 } else if (strcmp (page_id, LAYERS_SIDEBAR_ID) == 0 &&
1014 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (layers), document)) {
1015 ev_sidebar_set_page (sidebar, layers);
1016 } else if (strcmp (page_id, ANNOTS_SIDEBAR_ID) == 0 &&
1017 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (annots), document)) {
1018 ev_sidebar_set_page (sidebar, annots);
1019 } else if (strcmp (page_id, BOOKMARKS_SIDEBAR_ID) == 0 &&
1020 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (bookmarks), document)) {
1021 ev_sidebar_set_page (sidebar, bookmarks);
1026 update_document_mode (EvWindow *window, EvDocumentMode mode)
1028 if (mode == EV_DOCUMENT_MODE_PRESENTATION) {
1029 ev_window_run_presentation (window);
1031 else if (mode == EV_DOCUMENT_MODE_FULL_SCREEN) {
1032 ev_window_run_fullscreen (window);
1037 setup_chrome_from_metadata (EvWindow *window)
1039 EvChrome chrome = EV_CHROME_NORMAL;
1040 gboolean show_toolbar = TRUE;
1042 if (ev_window_is_empty (window)) {
1043 window->priv->chrome = chrome;
1048 if (!window->priv->metadata) {
1049 show_toolbar = g_settings_get_boolean (window->priv->default_settings, "show-toolbar");
1050 } else if (!ev_metadata_get_boolean (window->priv->metadata, "show_toolbar", &show_toolbar)) {
1051 if (window->priv->is_new_doc)
1052 show_toolbar = g_settings_get_boolean (window->priv->default_settings, "show-toolbar");
1056 chrome &= ~EV_CHROME_TOOLBAR;
1058 window->priv->chrome = chrome;
1062 setup_sidebar_from_metadata (EvWindow *window)
1064 EvDocument *document = window->priv->document;
1065 GSettings *settings = window->priv->default_settings;
1068 gboolean sidebar_visibility = TRUE;
1070 if (ev_window_is_empty (window))
1073 if (!window->priv->metadata) {
1074 sidebar_visibility = g_settings_get_boolean (settings, "show-sidebar");
1075 } else if (!ev_metadata_get_boolean (window->priv->metadata, "sidebar_visibility", &sidebar_visibility)) {
1076 if (window->priv->is_new_doc)
1077 sidebar_visibility = g_settings_get_boolean (settings, "show-sidebar");
1080 update_chrome_flag (window, EV_CHROME_SIDEBAR, sidebar_visibility);
1081 update_chrome_visibility (window);
1083 if (!window->priv->metadata) {
1084 /* Set default values */
1085 gtk_paned_set_position (GTK_PANED (window->priv->hpaned),
1086 g_settings_get_int (settings, "sidebar-size"));
1088 page_id = g_settings_get_string (settings, "sidebar-page");
1089 ev_window_sidebar_set_current_page (window, page_id);
1096 if (ev_metadata_get_int (window->priv->metadata, "sidebar_size", &sidebar_size)) {
1097 gtk_paned_set_position (GTK_PANED (window->priv->hpaned), sidebar_size);
1098 } else if (window->priv->is_new_doc) {
1099 gtk_paned_set_position (GTK_PANED (window->priv->hpaned),
1100 g_settings_get_int (settings, "sidebar-size"));
1106 if (ev_metadata_get_string (window->priv->metadata, "sidebar_page", &page_id)) {
1107 ev_window_sidebar_set_current_page (window, page_id);
1108 } else if (window->priv->is_new_doc) {
1109 page_id = g_settings_get_string (settings, "sidebar-page");
1110 ev_window_sidebar_set_current_page (window, page_id);
1116 setup_model_from_metadata (EvWindow *window)
1118 GSettings *settings = window->priv->default_settings;
1123 gboolean inverted_colors = FALSE;
1124 gboolean continuous = FALSE;
1125 gboolean dual_page = FALSE;
1126 gboolean fullscreen = FALSE;
1128 if (!window->priv->metadata) {
1129 /* Set default values */
1130 ev_document_model_set_sizing_mode (window->priv->model,
1131 g_settings_get_enum (settings, "sizing-mode"));
1132 ev_document_model_set_inverted_colors (window->priv->model,
1133 g_settings_get_boolean (settings, "inverted-colors"));
1134 ev_document_model_set_continuous (window->priv->model,
1135 g_settings_get_boolean (settings, "continuous"));
1136 ev_document_model_set_dual_page (window->priv->model,
1137 g_settings_get_boolean (settings, "dual-page"));
1138 fullscreen = g_settings_get_boolean (settings, "fullscreen");
1140 ev_window_run_fullscreen (window);
1146 if (!window->priv->dest &&
1147 ev_metadata_get_int (window->priv->metadata, "page", &page)) {
1148 ev_document_model_set_page (window->priv->model, page);
1152 if (ev_metadata_get_string (window->priv->metadata, "sizing_mode", &sizing_mode)) {
1153 GEnumValue *enum_value;
1155 enum_value = g_enum_get_value_by_nick
1156 (g_type_class_peek (EV_TYPE_SIZING_MODE), sizing_mode);
1157 ev_document_model_set_sizing_mode (window->priv->model, enum_value->value);
1158 } else if (window->priv->is_new_doc) {
1159 ev_document_model_set_sizing_mode (window->priv->model,
1160 g_settings_get_enum (settings, "sizing-mode"));
1164 if (ev_document_model_get_sizing_mode (window->priv->model) == EV_SIZING_FREE &&
1165 ev_metadata_get_double (window->priv->metadata, "zoom", &zoom)) {
1166 zoom *= get_screen_dpi (window) / 72.0;
1167 ev_document_model_set_scale (window->priv->model, zoom);
1171 if (ev_metadata_get_int (window->priv->metadata, "rotation", &rotation)) {
1186 ev_document_model_set_rotation (window->priv->model, rotation);
1189 /* Inverted Colors */
1190 if (ev_metadata_get_boolean (window->priv->metadata, "inverted-colors", &inverted_colors)) {
1191 ev_document_model_set_inverted_colors (window->priv->model, inverted_colors);
1192 } else if (window->priv->is_new_doc) {
1193 ev_document_model_set_inverted_colors (window->priv->model,
1194 g_settings_get_boolean (settings, "inverted-colors"));
1198 if (ev_metadata_get_boolean (window->priv->metadata, "continuous", &continuous)) {
1199 ev_document_model_set_continuous (window->priv->model, continuous);
1200 } else if (window->priv->is_new_doc) {
1201 ev_document_model_set_continuous (window->priv->model,
1202 g_settings_get_boolean (settings, "continuous"));
1206 if (ev_metadata_get_boolean (window->priv->metadata, "dual-page", &dual_page)) {
1207 ev_document_model_set_dual_page (window->priv->model, dual_page);
1208 } else if (window->priv->is_new_doc) {
1209 ev_document_model_set_dual_page (window->priv->model,
1210 g_settings_get_boolean (settings, "dual-page"));
1214 if (!ev_metadata_get_boolean (window->priv->metadata, "fullscreen", &fullscreen)) {
1215 if (window->priv->is_new_doc)
1216 fullscreen = g_settings_get_boolean (settings, "fullscreen");
1220 ev_window_run_fullscreen (window);
1224 setup_document_from_metadata (EvWindow *window)
1229 gdouble width_ratio;
1230 gdouble height_ratio;
1232 setup_sidebar_from_metadata (window);
1234 if (window->priv->metadata) {
1235 /* Make sure to not open a document on the last page,
1236 * since closing it on the last page most likely means the
1237 * user was finished reading the document. In that case, reopening should
1238 * show the first page. */
1239 page = ev_document_model_get_page (window->priv->model);
1240 n_pages = ev_document_get_n_pages (window->priv->document);
1241 if (page == n_pages - 1)
1242 ev_document_model_set_page (window->priv->model, 0);
1244 if (ev_metadata_get_int (window->priv->metadata, "window_width", &width) &&
1245 ev_metadata_get_int (window->priv->metadata, "window_height", &height))
1246 return; /* size was already set in setup_size_from_metadata */
1249 g_settings_get (window->priv->default_settings, "window-ratio", "(dd)", &width_ratio, &height_ratio);
1250 if (width_ratio > 0. && height_ratio > 0.) {
1251 gdouble document_width;
1252 gdouble document_height;
1255 gint request_height;
1257 ev_document_get_max_page_size (window->priv->document,
1258 &document_width, &document_height);
1260 request_width = (gint)(width_ratio * document_width + 0.5);
1261 request_height = (gint)(height_ratio * document_height + 0.5);
1263 screen = gtk_window_get_screen (GTK_WINDOW (window));
1265 request_width = MIN (request_width, gdk_screen_get_width (screen));
1266 request_height = MIN (request_height, gdk_screen_get_height (screen));
1269 if (request_width > 0 && request_height > 0) {
1270 gtk_window_resize (GTK_WINDOW (window),
1278 setup_size_from_metadata (EvWindow *window)
1286 if (!window->priv->metadata)
1289 if (ev_metadata_get_boolean (window->priv->metadata, "window_maximized", &maximized)) {
1291 gtk_window_maximize (GTK_WINDOW (window));
1294 gtk_window_unmaximize (GTK_WINDOW (window));
1298 if (ev_metadata_get_int (window->priv->metadata, "window_x", &x) &&
1299 ev_metadata_get_int (window->priv->metadata, "window_y", &y)) {
1300 gtk_window_move (GTK_WINDOW (window), x, y);
1303 if (ev_metadata_get_int (window->priv->metadata, "window_width", &width) &&
1304 ev_metadata_get_int (window->priv->metadata, "window_height", &height)) {
1305 gtk_window_resize (GTK_WINDOW (window), width, height);
1310 setup_view_from_metadata (EvWindow *window)
1312 gboolean presentation;
1314 if (!window->priv->metadata)
1318 if (ev_metadata_get_boolean (window->priv->metadata, "presentation", &presentation)) {
1320 ev_window_run_presentation (window);
1326 ev_window_clear_thumbnail_job (EvWindow *ev_window)
1328 if (ev_window->priv->thumbnail_job != NULL) {
1329 if (!ev_job_is_finished (ev_window->priv->thumbnail_job))
1330 ev_job_cancel (ev_window->priv->thumbnail_job);
1332 g_signal_handlers_disconnect_by_func (ev_window->priv->thumbnail_job,
1333 ev_window_set_icon_from_thumbnail,
1335 g_object_unref (ev_window->priv->thumbnail_job);
1336 ev_window->priv->thumbnail_job = NULL;
1341 ev_window_set_icon_from_thumbnail (EvJobThumbnail *job,
1342 EvWindow *ev_window)
1344 if (job->thumbnail) {
1345 if (ev_document_model_get_inverted_colors (ev_window->priv->model))
1346 ev_document_misc_invert_pixbuf (job->thumbnail);
1347 gtk_window_set_icon (GTK_WINDOW (ev_window),
1351 ev_window_clear_thumbnail_job (ev_window);
1355 ev_window_refresh_window_thumbnail (EvWindow *ev_window)
1360 EvDocument *document = ev_window->priv->document;
1362 if (ev_document_get_n_pages (document) <= 0 ||
1363 !ev_document_check_dimensions (document)) {
1367 ev_window_clear_thumbnail_job (ev_window);
1369 ev_document_get_page_size (document, 0, &page_width, NULL);
1370 scale = 128. / page_width;
1371 rotation = ev_document_model_get_rotation (ev_window->priv->model);
1373 ev_window->priv->thumbnail_job = ev_job_thumbnail_new (document, 0, rotation, scale);
1374 g_signal_connect (ev_window->priv->thumbnail_job, "finished",
1375 G_CALLBACK (ev_window_set_icon_from_thumbnail),
1377 ev_job_scheduler_push_job (ev_window->priv->thumbnail_job, EV_JOB_PRIORITY_NONE);
1381 override_restrictions_changed (GSettings *settings,
1383 EvWindow *ev_window)
1385 ev_window_setup_action_sensitivity (ev_window);
1389 lockdown_changed (GSettings *lockdown,
1391 EvWindow *ev_window)
1393 ev_window_setup_action_sensitivity (ev_window);
1397 ev_window_setup_document (EvWindow *ev_window)
1399 const EvDocumentInfo *info;
1400 EvDocument *document = ev_window->priv->document;
1403 ev_window->priv->setup_document_idle = 0;
1405 ev_window_refresh_window_thumbnail (ev_window);
1407 ev_window_set_page_mode (ev_window, PAGE_MODE_DOCUMENT);
1408 ev_window_title_set_document (ev_window->priv->title, document);
1409 ev_window_title_set_uri (ev_window->priv->title, ev_window->priv->uri);
1411 if (!ev_window->priv->settings) {
1412 ev_window->priv->settings = g_settings_new (GS_SCHEMA_NAME);
1413 g_signal_connect (ev_window->priv->settings,
1414 "changed::"GS_OVERRIDE_RESTRICTIONS,
1415 G_CALLBACK (override_restrictions_changed),
1419 #ifdef HAVE_DESKTOP_SCHEMAS
1420 if (!ev_window->priv->lockdown_settings) {
1421 ev_window->priv->lockdown_settings = g_settings_new (GS_LOCKDOWN_SCHEMA_NAME);
1422 g_signal_connect (ev_window->priv->lockdown_settings,
1424 G_CALLBACK (lockdown_changed),
1429 ev_window_setup_action_sensitivity (ev_window);
1431 if (ev_window->priv->history)
1432 g_object_unref (ev_window->priv->history);
1433 ev_window->priv->history = ev_history_new ();
1434 action = gtk_action_group_get_action (ev_window->priv->action_group, NAVIGATION_ACTION);
1435 ev_navigation_action_set_history (EV_NAVIGATION_ACTION (action), ev_window->priv->history);
1437 if (ev_window->priv->properties) {
1438 ev_properties_dialog_set_document (EV_PROPERTIES_DIALOG (ev_window->priv->properties),
1439 ev_window->priv->uri,
1440 ev_window->priv->document);
1443 info = ev_document_get_info (document);
1444 update_document_mode (ev_window, info->mode);
1446 if (EV_WINDOW_IS_PRESENTATION (ev_window))
1447 gtk_widget_grab_focus (ev_window->priv->presentation_view);
1449 gtk_widget_grab_focus (ev_window->priv->view);
1455 ev_window_set_document (EvWindow *ev_window, EvDocument *document)
1457 if (ev_window->priv->document == document)
1460 if (ev_window->priv->document)
1461 g_object_unref (ev_window->priv->document);
1462 ev_window->priv->document = g_object_ref (document);
1464 ev_window_update_max_min_scale (ev_window);
1466 ev_window_set_message_area (ev_window, NULL);
1468 if (ev_document_get_n_pages (document) <= 0) {
1469 ev_window_warning_message (ev_window, "%s",
1470 _("The document contains no pages"));
1471 } else if (!ev_document_check_dimensions (document)) {
1472 ev_window_warning_message (ev_window, "%s",
1473 _("The document contains only empty pages"));
1476 if (EV_WINDOW_IS_PRESENTATION (ev_window)) {
1479 current_page = ev_view_presentation_get_current_page (
1480 EV_VIEW_PRESENTATION (ev_window->priv->presentation_view));
1481 gtk_widget_destroy (ev_window->priv->presentation_view);
1482 ev_window->priv->presentation_view = NULL;
1484 /* Update the model with the current presentation page */
1485 ev_document_model_set_page (ev_window->priv->model, current_page);
1486 ev_window_run_presentation (ev_window);
1489 if (ev_window->priv->setup_document_idle > 0)
1490 g_source_remove (ev_window->priv->setup_document_idle);
1492 ev_window->priv->setup_document_idle = g_idle_add ((GSourceFunc)ev_window_setup_document, ev_window);
1496 ev_window_document_changed (EvWindow *ev_window,
1499 ev_window_reload_document (ev_window, NULL);
1503 ev_window_password_view_unlock (EvWindow *ev_window)
1505 const gchar *password;
1507 g_assert (ev_window->priv->load_job);
1509 password = ev_password_view_get_password (EV_PASSWORD_VIEW (ev_window->priv->password_view));
1510 ev_job_load_set_password (EV_JOB_LOAD (ev_window->priv->load_job), password);
1511 ev_job_scheduler_push_job (ev_window->priv->load_job, EV_JOB_PRIORITY_NONE);
1515 ev_window_clear_load_job (EvWindow *ev_window)
1517 if (ev_window->priv->load_job != NULL) {
1518 if (!ev_job_is_finished (ev_window->priv->load_job))
1519 ev_job_cancel (ev_window->priv->load_job);
1521 g_signal_handlers_disconnect_by_func (ev_window->priv->load_job, ev_window_load_job_cb, ev_window);
1522 g_object_unref (ev_window->priv->load_job);
1523 ev_window->priv->load_job = NULL;
1528 ev_window_clear_reload_job (EvWindow *ev_window)
1530 if (ev_window->priv->reload_job != NULL) {
1531 if (!ev_job_is_finished (ev_window->priv->reload_job))
1532 ev_job_cancel (ev_window->priv->reload_job);
1534 g_signal_handlers_disconnect_by_func (ev_window->priv->reload_job, ev_window_reload_job_cb, ev_window);
1535 g_object_unref (ev_window->priv->reload_job);
1536 ev_window->priv->reload_job = NULL;
1541 ev_window_clear_local_uri (EvWindow *ev_window)
1543 if (ev_window->priv->local_uri) {
1544 ev_tmp_uri_unlink (ev_window->priv->local_uri);
1545 g_free (ev_window->priv->local_uri);
1546 ev_window->priv->local_uri = NULL;
1551 ev_window_handle_link (EvWindow *ev_window,
1556 EvLinkAction *link_action;
1558 link_action = ev_link_action_new_dest (dest);
1559 link = ev_link_new (NULL, link_action);
1560 ev_view_handle_link (EV_VIEW (ev_window->priv->view), link);
1561 g_object_unref (link);
1565 /* This callback will executed when load job will be finished.
1567 * Since the flow of the error dialog is very confusing, we assume that both
1568 * document and uri will go away after this function is called, and thus we need
1569 * to ref/dup them. Additionally, it needs to clear
1570 * ev_window->priv->password_{uri,document}, and thus people who call this
1571 * function should _not_ necessarily expect those to exist after being
1574 ev_window_load_job_cb (EvJob *job,
1577 EvWindow *ev_window = EV_WINDOW (data);
1578 EvDocument *document = EV_JOB (job)->document;
1579 EvJobLoad *job_load = EV_JOB_LOAD (job);
1581 g_assert (job_load->uri);
1583 ev_view_set_loading (EV_VIEW (ev_window->priv->view), FALSE);
1586 if (!ev_job_is_failed (job)) {
1587 ev_document_model_set_document (ev_window->priv->model, document);
1590 ev_window_emit_doc_loaded (ev_window);
1592 setup_chrome_from_metadata (ev_window);
1593 update_chrome_actions (ev_window);
1594 setup_document_from_metadata (ev_window);
1595 setup_view_from_metadata (ev_window);
1597 ev_window_add_recent (ev_window, ev_window->priv->uri);
1599 ev_window_title_set_type (ev_window->priv->title,
1600 EV_WINDOW_TITLE_DOCUMENT);
1601 if (job_load->password) {
1602 GPasswordSave flags;
1604 flags = ev_password_view_get_password_save_flags (
1605 EV_PASSWORD_VIEW (ev_window->priv->password_view));
1606 ev_keyring_save_password (ev_window->priv->uri,
1611 ev_window_handle_link (ev_window, ev_window->priv->dest);
1612 /* Already unrefed by ev_link_action
1613 * FIXME: link action should inc dest ref counting
1614 * or not unref it at all
1616 ev_window->priv->dest = NULL;
1618 switch (ev_window->priv->window_mode) {
1619 case EV_WINDOW_MODE_FULLSCREEN:
1620 ev_window_run_fullscreen (ev_window);
1622 case EV_WINDOW_MODE_PRESENTATION:
1623 ev_window_run_presentation (ev_window);
1629 if (ev_window->priv->search_string && EV_IS_DOCUMENT_FIND (document)) {
1630 ev_window_cmd_edit_find (NULL, ev_window);
1631 egg_find_bar_set_search_string (EGG_FIND_BAR (ev_window->priv->find_bar),
1632 ev_window->priv->search_string);
1635 g_free (ev_window->priv->search_string);
1636 ev_window->priv->search_string = NULL;
1638 /* Create a monitor for the document */
1639 ev_window->priv->monitor = ev_file_monitor_new (ev_window->priv->uri);
1640 g_signal_connect_swapped (ev_window->priv->monitor, "changed",
1641 G_CALLBACK (ev_window_document_changed),
1644 ev_window_clear_load_job (ev_window);
1648 if (g_error_matches (job->error, EV_DOCUMENT_ERROR, EV_DOCUMENT_ERROR_ENCRYPTED)) {
1651 setup_view_from_metadata (ev_window);
1653 /* First look whether password is in keyring */
1654 password = ev_keyring_lookup_password (ev_window->priv->uri);
1656 if (job_load->password && strcmp (password, job_load->password) == 0) {
1657 /* Password in kering is wrong */
1658 ev_job_load_set_password (job_load, NULL);
1659 /* FIXME: delete password from keyring? */
1661 ev_job_load_set_password (job_load, password);
1662 ev_job_scheduler_push_job (job, EV_JOB_PRIORITY_NONE);
1670 /* We need to ask the user for a password */
1671 ev_window_title_set_uri (ev_window->priv->title,
1672 ev_window->priv->uri);
1673 ev_window_title_set_type (ev_window->priv->title,
1674 EV_WINDOW_TITLE_PASSWORD);
1676 ev_password_view_set_uri (EV_PASSWORD_VIEW (ev_window->priv->password_view),
1679 ev_window_set_page_mode (ev_window, PAGE_MODE_PASSWORD);
1681 ev_job_load_set_password (job_load, NULL);
1682 ev_password_view_ask_password (EV_PASSWORD_VIEW (ev_window->priv->password_view));
1684 ev_window_error_message (ev_window, job->error,
1685 "%s", _("Unable to open document"));
1686 ev_window_clear_load_job (ev_window);
1691 ev_window_reload_job_cb (EvJob *job,
1692 EvWindow *ev_window)
1696 if (ev_job_is_failed (job)) {
1697 ev_window_clear_reload_job (ev_window);
1698 ev_window->priv->in_reload = FALSE;
1699 if (ev_window->priv->dest) {
1700 g_object_unref (ev_window->priv->dest);
1701 ev_window->priv->dest = NULL;
1707 ev_document_model_set_document (ev_window->priv->model,
1709 if (ev_window->priv->dest) {
1710 ev_window_handle_link (ev_window, ev_window->priv->dest);
1711 /* Already unrefed by ev_link_action
1712 * FIXME: link action should inc dest ref counting
1713 * or not unref it at all
1715 ev_window->priv->dest = NULL;
1718 /* Restart the search after reloading */
1719 widget = gtk_window_get_focus (GTK_WINDOW (ev_window));
1720 if (widget && gtk_widget_get_ancestor (widget, EGG_TYPE_FIND_BAR)) {
1721 find_bar_search_changed_cb (EGG_FIND_BAR (ev_window->priv->find_bar),
1725 ev_window_clear_reload_job (ev_window);
1726 ev_window->priv->in_reload = FALSE;
1730 * ev_window_get_uri:
1731 * @ev_window: The instance of the #EvWindow.
1733 * It returns the uri of the document showed in the #EvWindow.
1735 * Returns: the uri of the document showed in the #EvWindow.
1738 ev_window_get_uri (EvWindow *ev_window)
1740 return ev_window->priv->uri;
1744 * ev_window_close_dialogs:
1745 * @ev_window: The window where dialogs will be closed.
1747 * It looks for password, print and properties dialogs and closes them and
1748 * frees them from memory. If there is any print job it does free it too.
1751 ev_window_close_dialogs (EvWindow *ev_window)
1753 if (ev_window->priv->print_dialog)
1754 gtk_widget_destroy (ev_window->priv->print_dialog);
1755 ev_window->priv->print_dialog = NULL;
1757 if (ev_window->priv->properties)
1758 gtk_widget_destroy (ev_window->priv->properties);
1759 ev_window->priv->properties = NULL;
1763 ev_window_clear_progress_idle (EvWindow *ev_window)
1765 if (ev_window->priv->progress_idle > 0)
1766 g_source_remove (ev_window->priv->progress_idle);
1767 ev_window->priv->progress_idle = 0;
1771 reset_progress_idle (EvWindow *ev_window)
1773 ev_window->priv->progress_idle = 0;
1777 ev_window_show_progress_message (EvWindow *ev_window,
1779 GSourceFunc function)
1781 if (ev_window->priv->progress_idle > 0)
1782 g_source_remove (ev_window->priv->progress_idle);
1783 ev_window->priv->progress_idle =
1784 g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
1787 (GDestroyNotify)reset_progress_idle);
1791 ev_window_reset_progress_cancellable (EvWindow *ev_window)
1793 if (ev_window->priv->progress_cancellable)
1794 g_cancellable_reset (ev_window->priv->progress_cancellable);
1796 ev_window->priv->progress_cancellable = g_cancellable_new ();
1800 ev_window_progress_response_cb (EvProgressMessageArea *area,
1802 EvWindow *ev_window)
1804 if (response == GTK_RESPONSE_CANCEL)
1805 g_cancellable_cancel (ev_window->priv->progress_cancellable);
1806 ev_window_set_message_area (ev_window, NULL);
1810 show_loading_progress (EvWindow *ev_window)
1814 gchar *display_name;
1816 if (ev_window->priv->message_area)
1819 text = g_uri_unescape_string (ev_window->priv->uri, NULL);
1820 display_name = g_markup_escape_text (text, -1);
1822 text = g_strdup_printf (_("Loading document from “%s”"),
1825 area = ev_progress_message_area_new (GTK_STOCK_OPEN,
1830 GTK_RESPONSE_CANCEL,
1832 g_signal_connect (area, "response",
1833 G_CALLBACK (ev_window_progress_response_cb),
1835 gtk_widget_show (area);
1836 ev_window_set_message_area (ev_window, area);
1839 g_free (display_name);
1845 ev_window_load_remote_failed (EvWindow *ev_window,
1848 ev_view_set_loading (EV_VIEW (ev_window->priv->view), FALSE);
1849 ev_window->priv->in_reload = FALSE;
1850 ev_window_error_message (ev_window, error,
1851 "%s", _("Unable to open document"));
1852 g_free (ev_window->priv->local_uri);
1853 ev_window->priv->local_uri = NULL;
1854 ev_window->priv->uri_mtime = 0;
1858 set_uri_mtime (GFile *source,
1859 GAsyncResult *async_result,
1860 EvWindow *ev_window)
1863 GError *error = NULL;
1865 info = g_file_query_info_finish (source, async_result, &error);
1868 ev_window->priv->uri_mtime = 0;
1869 g_error_free (error);
1873 g_file_info_get_modification_time (info, &mtime);
1874 ev_window->priv->uri_mtime = mtime.tv_sec;
1875 g_object_unref (info);
1878 g_object_unref (source);
1882 mount_volume_ready_cb (GFile *source,
1883 GAsyncResult *async_result,
1884 EvWindow *ev_window)
1886 GError *error = NULL;
1888 g_file_mount_enclosing_volume_finish (source, async_result, &error);
1891 ev_window_load_remote_failed (ev_window, error);
1892 g_object_unref (source);
1893 g_error_free (error);
1895 /* Volume successfully mounted,
1896 try opening the file again */
1897 ev_window_load_file_remote (ev_window, source);
1902 window_open_file_copy_ready_cb (GFile *source,
1903 GAsyncResult *async_result,
1904 EvWindow *ev_window)
1906 GError *error = NULL;
1908 ev_window_clear_progress_idle (ev_window);
1909 ev_window_set_message_area (ev_window, NULL);
1911 g_file_copy_finish (source, async_result, &error);
1913 ev_job_scheduler_push_job (ev_window->priv->load_job, EV_JOB_PRIORITY_NONE);
1914 g_file_query_info_async (source,
1915 G_FILE_ATTRIBUTE_TIME_MODIFIED,
1916 0, G_PRIORITY_DEFAULT,
1918 (GAsyncReadyCallback)set_uri_mtime,
1923 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_MOUNTED)) {
1924 GMountOperation *operation;
1926 operation = gtk_mount_operation_new (GTK_WINDOW (ev_window));
1927 g_file_mount_enclosing_volume (source,
1930 (GAsyncReadyCallback)mount_volume_ready_cb,
1932 g_object_unref (operation);
1933 } else if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
1934 ev_window_clear_load_job (ev_window);
1935 ev_window_clear_local_uri (ev_window);
1936 g_free (ev_window->priv->uri);
1937 ev_window->priv->uri = NULL;
1938 g_object_unref (source);
1940 ev_view_set_loading (EV_VIEW (ev_window->priv->view), FALSE);
1942 ev_window_load_remote_failed (ev_window, error);
1943 g_object_unref (source);
1946 g_error_free (error);
1950 window_open_file_copy_progress_cb (goffset n_bytes,
1951 goffset total_bytes,
1952 EvWindow *ev_window)
1957 if (!ev_window->priv->message_area)
1960 if (total_bytes <= 0)
1963 fraction = n_bytes / (gdouble)total_bytes;
1964 status = g_strdup_printf (_("Downloading document (%d%%)"),
1965 (gint)(fraction * 100));
1967 ev_progress_message_area_set_status (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
1969 ev_progress_message_area_set_fraction (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
1976 ev_window_load_file_remote (EvWindow *ev_window,
1981 if (!ev_window->priv->local_uri) {
1982 char *base_name, *template;
1986 /* We'd like to keep extension of source uri since
1987 * it helps to resolve some mime types, say cbz.
1989 base_name = g_file_get_basename (source_file);
1990 template = g_strdup_printf ("document.XXXXXX-%s", base_name);
1993 tmp_file = ev_mkstemp_file (template, &err);
1995 if (tmp_file == NULL) {
1996 ev_window_error_message (ev_window, err,
1997 "%s", _("Failed to load remote file."));
2002 ev_window->priv->local_uri = g_file_get_uri (tmp_file);
2003 g_object_unref (tmp_file);
2005 ev_job_load_set_uri (EV_JOB_LOAD (ev_window->priv->load_job),
2006 ev_window->priv->local_uri);
2009 ev_window_reset_progress_cancellable (ev_window);
2011 target_file = g_file_new_for_uri (ev_window->priv->local_uri);
2012 g_file_copy_async (source_file, target_file,
2013 G_FILE_COPY_OVERWRITE,
2015 ev_window->priv->progress_cancellable,
2016 (GFileProgressCallback)window_open_file_copy_progress_cb,
2018 (GAsyncReadyCallback)window_open_file_copy_ready_cb,
2020 g_object_unref (target_file);
2022 ev_window_show_progress_message (ev_window, 1,
2023 (GSourceFunc)show_loading_progress);
2027 ev_window_open_uri (EvWindow *ev_window,
2030 EvWindowRunMode mode,
2031 const gchar *search_string)
2035 ev_window->priv->in_reload = FALSE;
2037 if (ev_window->priv->uri &&
2038 g_ascii_strcasecmp (ev_window->priv->uri, uri) == 0) {
2039 ev_window_reload_document (ev_window, dest);
2043 if (ev_window->priv->monitor) {
2044 g_object_unref (ev_window->priv->monitor);
2045 ev_window->priv->monitor = NULL;
2048 ev_window_close_dialogs (ev_window);
2049 ev_window_clear_load_job (ev_window);
2050 ev_window_clear_local_uri (ev_window);
2052 ev_window->priv->window_mode = mode;
2054 if (ev_window->priv->uri)
2055 g_free (ev_window->priv->uri);
2056 ev_window->priv->uri = g_strdup (uri);
2058 if (ev_window->priv->metadata)
2059 g_object_unref (ev_window->priv->metadata);
2060 if (ev_window->priv->bookmarks)
2061 g_object_unref (ev_window->priv->bookmarks);
2063 source_file = g_file_new_for_uri (uri);
2064 if (!ev_file_is_temp (source_file) && ev_is_metadata_supported_for_file (source_file)) {
2065 ev_window->priv->metadata = ev_metadata_new (source_file);
2066 ev_window->priv->is_new_doc = ev_metadata_is_empty (ev_window->priv->metadata);
2068 ev_window->priv->metadata = NULL;
2071 if (ev_window->priv->metadata) {
2072 ev_window->priv->bookmarks = ev_bookmarks_new (ev_window->priv->metadata);
2073 ev_sidebar_bookmarks_set_bookmarks (EV_SIDEBAR_BOOKMARKS (ev_window->priv->sidebar_bookmarks),
2074 ev_window->priv->bookmarks);
2075 g_signal_connect_swapped (ev_window->priv->bookmarks, "changed",
2076 G_CALLBACK (ev_window_setup_bookmarks),
2079 ev_window->priv->bookmarks = NULL;
2082 if (ev_window->priv->search_string)
2083 g_free (ev_window->priv->search_string);
2084 ev_window->priv->search_string = search_string ?
2085 g_strdup (search_string) : NULL;
2087 if (ev_window->priv->dest)
2088 g_object_unref (ev_window->priv->dest);
2089 ev_window->priv->dest = dest ? g_object_ref (dest) : NULL;
2091 setup_size_from_metadata (ev_window);
2092 setup_model_from_metadata (ev_window);
2093 ev_window_setup_bookmarks (ev_window);
2095 ev_window->priv->load_job = ev_job_load_new (uri);
2096 g_signal_connect (ev_window->priv->load_job,
2098 G_CALLBACK (ev_window_load_job_cb),
2101 if (!g_file_is_native (source_file) && !ev_window->priv->local_uri) {
2102 ev_window_load_file_remote (ev_window, source_file);
2104 ev_view_set_loading (EV_VIEW (ev_window->priv->view), TRUE);
2105 g_object_unref (source_file);
2106 ev_job_scheduler_push_job (ev_window->priv->load_job, EV_JOB_PRIORITY_NONE);
2111 ev_window_open_document (EvWindow *ev_window,
2112 EvDocument *document,
2114 EvWindowRunMode mode,
2115 const gchar *search_string)
2117 if (document == ev_window->priv->document)
2120 ev_window_close_dialogs (ev_window);
2121 ev_window_clear_load_job (ev_window);
2122 ev_window_clear_local_uri (ev_window);
2124 if (ev_window->priv->monitor) {
2125 g_object_unref (ev_window->priv->monitor);
2126 ev_window->priv->monitor = NULL;
2129 if (ev_window->priv->uri)
2130 g_free (ev_window->priv->uri);
2131 ev_window->priv->uri = g_strdup (ev_document_get_uri (document));
2133 setup_size_from_metadata (ev_window);
2134 setup_model_from_metadata (ev_window);
2136 ev_document_model_set_document (ev_window->priv->model, document);
2138 setup_document_from_metadata (ev_window);
2139 setup_view_from_metadata (ev_window);
2143 EvLinkAction *link_action;
2145 link_action = ev_link_action_new_dest (dest);
2146 link = ev_link_new (NULL, link_action);
2147 ev_view_handle_link (EV_VIEW (ev_window->priv->view), link);
2148 /* FIXME: link action should inc dest ref counting
2149 * or not unref it at all
2151 g_object_ref (dest);
2152 g_object_unref (link);
2156 case EV_WINDOW_MODE_FULLSCREEN:
2157 ev_window_run_fullscreen (ev_window);
2159 case EV_WINDOW_MODE_PRESENTATION:
2160 ev_window_run_presentation (ev_window);
2166 if (search_string && EV_IS_DOCUMENT_FIND (document)) {
2167 ev_window_cmd_edit_find (NULL, ev_window);
2168 egg_find_bar_set_search_string (EGG_FIND_BAR (ev_window->priv->find_bar),
2172 /* Create a monitor for the document */
2173 ev_window->priv->monitor = ev_file_monitor_new (ev_window->priv->uri);
2174 g_signal_connect_swapped (ev_window->priv->monitor, "changed",
2175 G_CALLBACK (ev_window_document_changed),
2180 ev_window_reload_local (EvWindow *ev_window)
2184 uri = ev_window->priv->local_uri ? ev_window->priv->local_uri : ev_window->priv->uri;
2185 ev_window->priv->reload_job = ev_job_load_new (uri);
2186 g_signal_connect (ev_window->priv->reload_job, "finished",
2187 G_CALLBACK (ev_window_reload_job_cb),
2189 ev_job_scheduler_push_job (ev_window->priv->reload_job, EV_JOB_PRIORITY_NONE);
2193 show_reloading_progress (EvWindow *ev_window)
2198 if (ev_window->priv->message_area)
2201 text = g_strdup_printf (_("Reloading document from %s"),
2202 ev_window->priv->uri);
2203 area = ev_progress_message_area_new (GTK_STOCK_REFRESH,
2208 GTK_RESPONSE_CANCEL,
2210 g_signal_connect (area, "response",
2211 G_CALLBACK (ev_window_progress_response_cb),
2213 gtk_widget_show (area);
2214 ev_window_set_message_area (ev_window, area);
2221 reload_remote_copy_ready_cb (GFile *remote,
2222 GAsyncResult *async_result,
2223 EvWindow *ev_window)
2225 GError *error = NULL;
2227 ev_window_clear_progress_idle (ev_window);
2229 g_file_copy_finish (remote, async_result, &error);
2231 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
2232 ev_window_error_message (ev_window, error,
2233 "%s", _("Failed to reload document."));
2234 g_error_free (error);
2236 ev_window_reload_local (ev_window);
2239 g_object_unref (remote);
2243 reload_remote_copy_progress_cb (goffset n_bytes,
2244 goffset total_bytes,
2245 EvWindow *ev_window)
2250 if (!ev_window->priv->message_area)
2253 if (total_bytes <= 0)
2256 fraction = n_bytes / (gdouble)total_bytes;
2257 status = g_strdup_printf (_("Downloading document (%d%%)"),
2258 (gint)(fraction * 100));
2260 ev_progress_message_area_set_status (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
2262 ev_progress_message_area_set_fraction (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
2269 query_remote_uri_mtime_cb (GFile *remote,
2270 GAsyncResult *async_result,
2271 EvWindow *ev_window)
2275 GError *error = NULL;
2277 info = g_file_query_info_finish (remote, async_result, &error);
2279 g_error_free (error);
2280 g_object_unref (remote);
2281 ev_window_reload_local (ev_window);
2286 g_file_info_get_modification_time (info, &mtime);
2287 if (ev_window->priv->uri_mtime != mtime.tv_sec) {
2290 /* Remote file has changed */
2291 ev_window->priv->uri_mtime = mtime.tv_sec;
2293 ev_window_reset_progress_cancellable (ev_window);
2295 target_file = g_file_new_for_uri (ev_window->priv->local_uri);
2296 g_file_copy_async (remote, target_file,
2297 G_FILE_COPY_OVERWRITE,
2299 ev_window->priv->progress_cancellable,
2300 (GFileProgressCallback)reload_remote_copy_progress_cb,
2302 (GAsyncReadyCallback)reload_remote_copy_ready_cb,
2304 g_object_unref (target_file);
2305 ev_window_show_progress_message (ev_window, 1,
2306 (GSourceFunc)show_reloading_progress);
2308 g_object_unref (remote);
2309 ev_window_reload_local (ev_window);
2312 g_object_unref (info);
2316 ev_window_reload_remote (EvWindow *ev_window)
2320 remote = g_file_new_for_uri (ev_window->priv->uri);
2321 /* Reload the remote uri only if it has changed */
2322 g_file_query_info_async (remote,
2323 G_FILE_ATTRIBUTE_TIME_MODIFIED,
2324 0, G_PRIORITY_DEFAULT,
2326 (GAsyncReadyCallback)query_remote_uri_mtime_cb,
2331 ev_window_reload_document (EvWindow *ev_window,
2337 ev_window_clear_reload_job (ev_window);
2338 ev_window->priv->in_reload = TRUE;
2340 page = ev_document_model_get_page (ev_window->priv->model);
2342 if (ev_window->priv->dest)
2343 g_object_unref (ev_window->priv->dest);
2344 ev_window->priv->dest = dest ? g_object_ref (dest) : NULL;
2346 if (ev_window->priv->local_uri) {
2347 ev_window_reload_remote (ev_window);
2349 ev_window_reload_local (ev_window);
2354 file_open_dialog_response_cb (GtkWidget *chooser,
2356 EvWindow *ev_window)
2358 if (response_id == GTK_RESPONSE_OK) {
2362 uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (chooser));
2364 ev_application_open_uri_list (EV_APP, uris,
2365 gtk_window_get_screen (GTK_WINDOW (ev_window)),
2366 gtk_get_current_event_time ());
2368 g_slist_foreach (uris, (GFunc)g_free, NULL);
2369 g_slist_free (uris);
2371 uri = gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (chooser));
2372 ev_application_set_filechooser_uri (EV_APP,
2373 GTK_FILE_CHOOSER_ACTION_OPEN,
2378 gtk_widget_destroy (chooser);
2382 ev_window_cmd_file_open (GtkAction *action, EvWindow *window)
2385 const gchar *default_uri;
2386 gchar *parent_uri = NULL;
2388 chooser = gtk_file_chooser_dialog_new (_("Open Document"),
2389 GTK_WINDOW (window),
2390 GTK_FILE_CHOOSER_ACTION_OPEN,
2392 GTK_RESPONSE_CANCEL,
2393 GTK_STOCK_OPEN, GTK_RESPONSE_OK,
2396 ev_document_factory_add_filters (chooser, NULL);
2397 gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (chooser), TRUE);
2398 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser), FALSE);
2400 default_uri = ev_application_get_filechooser_uri (EV_APP, GTK_FILE_CHOOSER_ACTION_OPEN);
2401 if (!default_uri && window->priv->uri) {
2402 GFile *file, *parent;
2404 file = g_file_new_for_uri (window->priv->uri);
2405 parent = g_file_get_parent (file);
2407 parent_uri = g_file_get_uri (parent);
2408 default_uri = parent_uri;
2409 g_object_unref (parent);
2411 g_object_unref (file);
2415 gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (chooser), default_uri);
2417 const gchar *folder;
2419 folder = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
2420 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser),
2421 folder ? folder : g_get_home_dir ());
2423 g_free (parent_uri);
2425 g_signal_connect (chooser, "response",
2426 G_CALLBACK (file_open_dialog_response_cb),
2429 gtk_widget_show (chooser);
2433 ev_window_open_copy_at_dest (EvWindow *window,
2436 EvWindow *new_window = EV_WINDOW (ev_window_new ());
2438 ev_window_n_copies++;
2440 if (window->priv->metadata)
2441 new_window->priv->metadata = g_object_ref (window->priv->metadata);
2442 ev_window_open_document (new_window,
2443 window->priv->document,
2445 gtk_window_present (GTK_WINDOW (new_window));
2449 ev_window_cmd_file_open_copy (GtkAction *action, EvWindow *window)
2451 ev_window_open_copy_at_dest (window, NULL);
2455 ev_window_cmd_recent_file_activate (GtkAction *action,
2458 GtkRecentInfo *info;
2461 info = g_object_get_data (G_OBJECT (action), "gtk-recent-info");
2462 g_assert (info != NULL);
2464 uri = gtk_recent_info_get_uri (info);
2466 ev_application_open_uri_at_dest (EV_APP, uri,
2467 gtk_window_get_screen (GTK_WINDOW (window)),
2468 NULL, 0, NULL, gtk_get_current_event_time ());
2472 ev_window_open_recent_action_item_activated (EvOpenRecentAction *action,
2476 ev_application_open_uri_at_dest (EV_APP, uri,
2477 gtk_window_get_screen (GTK_WINDOW (window)),
2478 NULL, 0, NULL, gtk_get_current_event_time ());
2482 ev_window_add_recent (EvWindow *window, const char *filename)
2484 gtk_recent_manager_add_item (window->priv->recent_manager, filename);
2488 compare_recent_items (GtkRecentInfo *a, GtkRecentInfo *b)
2490 gboolean has_ev_a, has_ev_b;
2491 const gchar *evince = g_get_application_name ();
2493 has_ev_a = gtk_recent_info_has_application (a, evince);
2494 has_ev_b = gtk_recent_info_has_application (b, evince);
2496 if (has_ev_a && has_ev_b) {
2497 time_t time_a, time_b;
2499 time_a = gtk_recent_info_get_modified (a);
2500 time_b = gtk_recent_info_get_modified (b);
2502 return (time_b - time_a);
2503 } else if (has_ev_a) {
2505 } else if (has_ev_b) {
2513 * Doubles underscore to avoid spurious menu accels.
2516 ev_window_get_recent_file_label (gint index, const gchar *filename)
2524 is_rtl = (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL);
2526 g_return_val_if_fail (filename != NULL, NULL);
2528 length = strlen (filename);
2529 str = g_string_sized_new (length + 10);
2530 g_string_printf (str, "%s_%d. ", is_rtl ? "\xE2\x80\x8F" : "", index);
2533 end = filename + length;
2537 next = g_utf8_next_char (p);
2541 g_string_append (str, "__");
2544 g_string_append_len (str, p, next - p);
2551 return g_string_free (str, FALSE);
2555 ev_window_recent_action_connect_proxy_cb (GtkActionGroup *action_group,
2562 if (!GTK_IS_MENU_ITEM (proxy))
2565 label = GTK_LABEL (gtk_bin_get_child (GTK_BIN (proxy)));
2567 gtk_label_set_ellipsize (label, PANGO_ELLIPSIZE_MIDDLE);
2568 gtk_label_set_max_width_chars (label, MAX_RECENT_ITEM_LEN);
2572 ev_window_setup_recent (EvWindow *ev_window)
2576 const gchar *evince = g_get_application_name ();
2579 if (ev_window->priv->recent_ui_id > 0) {
2580 gtk_ui_manager_remove_ui (ev_window->priv->ui_manager,
2581 ev_window->priv->recent_ui_id);
2582 gtk_ui_manager_ensure_update (ev_window->priv->ui_manager);
2584 ev_window->priv->recent_ui_id = gtk_ui_manager_new_merge_id (ev_window->priv->ui_manager);
2586 if (ev_window->priv->recent_action_group) {
2587 gtk_ui_manager_remove_action_group (ev_window->priv->ui_manager,
2588 ev_window->priv->recent_action_group);
2589 g_object_unref (ev_window->priv->recent_action_group);
2591 ev_window->priv->recent_action_group = gtk_action_group_new ("RecentFilesActions");
2592 g_signal_connect (ev_window->priv->recent_action_group, "connect-proxy",
2593 G_CALLBACK (ev_window_recent_action_connect_proxy_cb), NULL);
2595 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
2596 ev_window->priv->recent_action_group, -1);
2598 items = gtk_recent_manager_get_items (ev_window->priv->recent_manager);
2599 items = g_list_sort (items, (GCompareFunc) compare_recent_items);
2601 for (l = items; l && l->data; l = g_list_next (l)) {
2602 GtkRecentInfo *info;
2606 const gchar *mime_type;
2607 gchar *content_type;
2610 info = (GtkRecentInfo *) l->data;
2612 if (!gtk_recent_info_has_application (info, evince) ||
2613 (gtk_recent_info_is_local (info) && !gtk_recent_info_exists (info)))
2616 action_name = g_strdup_printf ("RecentFile%u", i++);
2617 label = ev_window_get_recent_file_label (
2618 n_items + 1, gtk_recent_info_get_display_name (info));
2620 mime_type = gtk_recent_info_get_mime_type (info);
2621 content_type = g_content_type_from_mime_type (mime_type);
2622 if (content_type != NULL) {
2623 icon = g_content_type_get_icon (content_type);
2624 g_free (content_type);
2627 action = g_object_new (GTK_TYPE_ACTION,
2628 "name", action_name,
2631 "always-show-image", TRUE,
2634 g_object_set_data_full (G_OBJECT (action),
2636 gtk_recent_info_ref (info),
2637 (GDestroyNotify) gtk_recent_info_unref);
2639 g_signal_connect (action, "activate",
2640 G_CALLBACK (ev_window_cmd_recent_file_activate),
2641 (gpointer) ev_window);
2643 gtk_action_group_add_action (ev_window->priv->recent_action_group,
2645 g_object_unref (action);
2647 gtk_ui_manager_add_ui (ev_window->priv->ui_manager,
2648 ev_window->priv->recent_ui_id,
2649 "/MainMenu/FileMenu/RecentFilesMenu",
2652 GTK_UI_MANAGER_MENUITEM,
2654 g_free (action_name);
2657 g_object_unref (icon);
2663 g_list_foreach (items, (GFunc) gtk_recent_info_unref, NULL);
2664 g_list_free (items);
2668 show_saving_progress (GFile *dst)
2670 EvWindow *ev_window;
2674 EvSaveType save_type;
2676 ev_window = EV_WINDOW (g_object_get_data (G_OBJECT (dst), "ev-window"));
2677 ev_window->priv->progress_idle = 0;
2679 if (ev_window->priv->message_area)
2682 save_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dst), "save-type"));
2683 uri = g_file_get_uri (dst);
2684 switch (save_type) {
2685 case EV_SAVE_DOCUMENT:
2686 text = g_strdup_printf (_("Saving document to %s"), uri);
2688 case EV_SAVE_ATTACHMENT:
2689 text = g_strdup_printf (_("Saving attachment to %s"), uri);
2692 text = g_strdup_printf (_("Saving image to %s"), uri);
2695 g_assert_not_reached ();
2698 area = ev_progress_message_area_new (GTK_STOCK_SAVE,
2703 GTK_RESPONSE_CANCEL,
2705 g_signal_connect (area, "response",
2706 G_CALLBACK (ev_window_progress_response_cb),
2708 gtk_widget_show (area);
2709 ev_window_set_message_area (ev_window, area);
2716 window_save_file_copy_ready_cb (GFile *src,
2717 GAsyncResult *async_result,
2720 EvWindow *ev_window;
2721 GError *error = NULL;
2723 ev_window = EV_WINDOW (g_object_get_data (G_OBJECT (dst), "ev-window"));
2724 ev_window_clear_progress_idle (ev_window);
2726 if (g_file_copy_finish (src, async_result, &error)) {
2727 ev_tmp_file_unlink (src);
2731 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
2734 name = g_file_get_basename (dst);
2735 ev_window_error_message (ev_window, error,
2736 _("The file could not be saved as “%s”."),
2740 ev_tmp_file_unlink (src);
2741 g_error_free (error);
2745 window_save_file_copy_progress_cb (goffset n_bytes,
2746 goffset total_bytes,
2749 EvWindow *ev_window;
2750 EvSaveType save_type;
2754 ev_window = EV_WINDOW (g_object_get_data (G_OBJECT (dst), "ev-window"));
2756 if (!ev_window->priv->message_area)
2759 if (total_bytes <= 0)
2762 fraction = n_bytes / (gdouble)total_bytes;
2763 save_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dst), "save-type"));
2765 switch (save_type) {
2766 case EV_SAVE_DOCUMENT:
2767 status = g_strdup_printf (_("Uploading document (%d%%)"),
2768 (gint)(fraction * 100));
2770 case EV_SAVE_ATTACHMENT:
2771 status = g_strdup_printf (_("Uploading attachment (%d%%)"),
2772 (gint)(fraction * 100));
2775 status = g_strdup_printf (_("Uploading image (%d%%)"),
2776 (gint)(fraction * 100));
2779 g_assert_not_reached ();
2782 ev_progress_message_area_set_status (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
2784 ev_progress_message_area_set_fraction (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
2791 ev_window_save_remote (EvWindow *ev_window,
2792 EvSaveType save_type,
2796 ev_window_reset_progress_cancellable (ev_window);
2797 g_object_set_data (G_OBJECT (dst), "ev-window", ev_window);
2798 g_object_set_data (G_OBJECT (dst), "save-type", GINT_TO_POINTER (save_type));
2799 g_file_copy_async (src, dst,
2800 G_FILE_COPY_OVERWRITE,
2802 ev_window->priv->progress_cancellable,
2803 (GFileProgressCallback)window_save_file_copy_progress_cb,
2805 (GAsyncReadyCallback)window_save_file_copy_ready_cb,
2807 ev_window->priv->progress_idle =
2808 g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
2810 (GSourceFunc)show_saving_progress,
2816 ev_window_clear_save_job (EvWindow *ev_window)
2818 if (ev_window->priv->save_job != NULL) {
2819 if (!ev_job_is_finished (ev_window->priv->save_job))
2820 ev_job_cancel (ev_window->priv->save_job);
2822 g_signal_handlers_disconnect_by_func (ev_window->priv->save_job,
2823 ev_window_save_job_cb,
2825 g_object_unref (ev_window->priv->save_job);
2826 ev_window->priv->save_job = NULL;
2831 ev_window_save_job_cb (EvJob *job,
2834 if (ev_job_is_failed (job)) {
2835 ev_window_error_message (window, job->error,
2836 _("The file could not be saved as “%s”."),
2837 EV_JOB_SAVE (job)->uri);
2839 ev_window_add_recent (window, EV_JOB_SAVE (job)->uri);
2842 ev_window_clear_save_job (window);
2846 file_save_dialog_response_cb (GtkWidget *fc,
2848 EvWindow *ev_window)
2851 GFile *file, *parent;
2853 if (response_id != GTK_RESPONSE_OK) {
2854 gtk_widget_destroy (fc);
2858 uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
2859 file = g_file_new_for_uri (uri);
2860 parent = g_file_get_parent (file);
2861 g_object_unref (file);
2865 folder_uri = g_file_get_uri (parent);
2866 ev_application_set_filechooser_uri (EV_APP,
2867 GTK_FILE_CHOOSER_ACTION_SAVE,
2869 g_free (folder_uri);
2870 g_object_unref (parent);
2873 /* FIXME: remote copy should be done here rather than in the save job,
2874 * so that we can track progress and cancel the operation
2877 ev_window_clear_save_job (ev_window);
2878 ev_window->priv->save_job = ev_job_save_new (ev_window->priv->document,
2879 uri, ev_window->priv->uri);
2880 g_signal_connect (ev_window->priv->save_job, "finished",
2881 G_CALLBACK (ev_window_save_job_cb),
2883 /* The priority doesn't matter for this job */
2884 ev_job_scheduler_push_job (ev_window->priv->save_job, EV_JOB_PRIORITY_NONE);
2887 gtk_widget_destroy (fc);
2891 ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window)
2896 const gchar *default_uri;
2898 fc = gtk_file_chooser_dialog_new (
2900 GTK_WINDOW (ev_window), GTK_FILE_CHOOSER_ACTION_SAVE,
2901 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
2902 GTK_STOCK_SAVE, GTK_RESPONSE_OK,
2905 ev_document_factory_add_filters (fc, ev_window->priv->document);
2906 gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
2907 gtk_dialog_set_alternative_button_order (GTK_DIALOG (fc),
2909 GTK_RESPONSE_CANCEL,
2912 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (fc), FALSE);
2913 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
2914 file = g_file_new_for_uri (ev_window->priv->uri);
2915 base_name = g_file_get_basename (file);
2916 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc), base_name);
2918 default_uri = ev_application_get_filechooser_uri (EV_APP, GTK_FILE_CHOOSER_ACTION_SAVE);
2920 gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (fc), default_uri);
2922 const gchar *folder;
2924 folder = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
2925 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (fc),
2926 folder ? folder : g_get_home_dir ());
2929 g_object_unref (file);
2932 g_signal_connect (fc, "response",
2933 G_CALLBACK (file_save_dialog_response_cb),
2936 gtk_widget_show (fc);
2940 ev_window_cmd_open_containing_folder (GtkAction *action, EvWindow *ev_window)
2942 GtkWidget *ev_window_widget;
2946 ev_window_widget = GTK_WIDGET (ev_window);
2948 file = g_file_new_for_uri (ev_window->priv->uri);
2949 parent = g_file_get_parent (file);
2954 parent_uri = g_file_get_uri (parent);
2960 screen = gtk_widget_get_screen (ev_window_widget);
2961 timestamp = gtk_get_current_event_time ();
2964 if (!gtk_show_uri (screen, parent_uri, timestamp, &error)) {
2965 ev_window_error_message (ev_window, error, _("Could not open the containing folder"));
2966 g_error_free (error);
2969 g_free (parent_uri);
2974 g_object_unref (file);
2977 g_object_unref (parent);
2982 get_print_settings_file (void)
2984 GKeyFile *print_settings_file;
2986 GError *error = NULL;
2988 print_settings_file = g_key_file_new ();
2990 filename = g_build_filename (ev_application_get_dot_dir (EV_APP, FALSE),
2991 EV_PRINT_SETTINGS_FILE, NULL);
2992 if (!g_key_file_load_from_file (print_settings_file,
2994 G_KEY_FILE_KEEP_COMMENTS |
2995 G_KEY_FILE_KEEP_TRANSLATIONS,
2998 /* Don't warn if the file simply doesn't exist */
2999 if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
3000 g_warning ("%s", error->message);
3002 g_error_free (error);
3007 return print_settings_file;
3011 save_print_setting_file (GKeyFile *key_file)
3016 GError *error = NULL;
3018 filename = g_build_filename (ev_application_get_dot_dir (EV_APP, TRUE),
3019 EV_PRINT_SETTINGS_FILE, NULL);
3020 data = g_key_file_to_data (key_file, &data_length, NULL);
3021 g_file_set_contents (filename, data, data_length, &error);
3023 g_warning ("Failed to save print settings: %s", error->message);
3024 g_error_free (error);
3031 ev_window_save_print_settings (EvWindow *window,
3032 GtkPrintSettings *print_settings)
3037 key_file = get_print_settings_file ();
3038 gtk_print_settings_to_key_file (print_settings, key_file, EV_PRINT_SETTINGS_GROUP);
3040 /* Save print settings that are specific to the document */
3041 for (i = 0; i < G_N_ELEMENTS (document_print_settings); i++) {
3042 /* Remove it from global settings */
3043 g_key_file_remove_key (key_file, EV_PRINT_SETTINGS_GROUP,
3044 document_print_settings[i], NULL);
3046 if (window->priv->metadata) {
3049 value = gtk_print_settings_get (print_settings,
3050 document_print_settings[i]);
3051 ev_metadata_set_string (window->priv->metadata,
3052 document_print_settings[i], value);
3056 save_print_setting_file (key_file);
3057 g_key_file_free (key_file);
3061 ev_window_save_print_page_setup (EvWindow *window,
3062 GtkPageSetup *page_setup)
3066 key_file = get_print_settings_file ();
3067 gtk_page_setup_to_key_file (page_setup, key_file, EV_PAGE_SETUP_GROUP);
3069 /* Do not save document settings in global file */
3070 g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
3071 "page-setup-orientation", NULL);
3072 g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
3073 "page-setup-margin-top", NULL);
3074 g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
3075 "page-setup-margin-bottom", NULL);
3076 g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
3077 "page-setup-margin-left", NULL);
3078 g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
3079 "page-setup-margin-right", NULL);
3081 save_print_setting_file (key_file);
3082 g_key_file_free (key_file);
3084 if (!window->priv->metadata)
3087 /* Save page setup options that are specific to the document */
3088 ev_metadata_set_int (window->priv->metadata, "page-setup-orientation",
3089 gtk_page_setup_get_orientation (page_setup));
3090 ev_metadata_set_double (window->priv->metadata, "page-setup-margin-top",
3091 gtk_page_setup_get_top_margin (page_setup, GTK_UNIT_MM));
3092 ev_metadata_set_double (window->priv->metadata, "page-setup-margin-bottom",
3093 gtk_page_setup_get_bottom_margin (page_setup, GTK_UNIT_MM));
3094 ev_metadata_set_double (window->priv->metadata, "page-setup-margin-left",
3095 gtk_page_setup_get_left_margin (page_setup, GTK_UNIT_MM));
3096 ev_metadata_set_double (window->priv->metadata, "page-setup-margin-right",
3097 gtk_page_setup_get_right_margin (page_setup, GTK_UNIT_MM));
3101 ev_window_load_print_settings_from_metadata (EvWindow *window,
3102 GtkPrintSettings *print_settings)
3106 if (!window->priv->metadata)
3109 /* Load print setting that are specific to the document */
3110 for (i = 0; i < G_N_ELEMENTS (document_print_settings); i++) {
3111 gchar *value = NULL;
3113 ev_metadata_get_string (window->priv->metadata,
3114 document_print_settings[i], &value);
3115 gtk_print_settings_set (print_settings,
3116 document_print_settings[i], value);
3121 ev_window_load_print_page_setup_from_metadata (EvWindow *window,
3122 GtkPageSetup *page_setup)
3125 gdouble double_value;
3126 GtkPaperSize *paper_size = gtk_page_setup_get_paper_size (page_setup);
3128 /* Load page setup options that are specific to the document */
3129 if (window->priv->metadata &&
3130 ev_metadata_get_int (window->priv->metadata, "page-setup-orientation", &int_value)) {
3131 gtk_page_setup_set_orientation (page_setup, int_value);
3133 gtk_page_setup_set_orientation (page_setup, GTK_PAGE_ORIENTATION_PORTRAIT);
3136 if (window->priv->metadata &&
3137 ev_metadata_get_double (window->priv->metadata, "page-setup-margin-top", &double_value)) {
3138 gtk_page_setup_set_top_margin (page_setup, double_value, GTK_UNIT_MM);
3140 gtk_page_setup_set_top_margin (page_setup,
3141 gtk_paper_size_get_default_top_margin (paper_size, GTK_UNIT_MM),
3145 if (window->priv->metadata &&
3146 ev_metadata_get_double (window->priv->metadata, "page-setup-margin-bottom", &double_value)) {
3147 gtk_page_setup_set_bottom_margin (page_setup, double_value, GTK_UNIT_MM);
3149 gtk_page_setup_set_bottom_margin (page_setup,
3150 gtk_paper_size_get_default_bottom_margin (paper_size, GTK_UNIT_MM),
3154 if (window->priv->metadata &&
3155 ev_metadata_get_double (window->priv->metadata, "page-setup-margin-left", &double_value)) {
3156 gtk_page_setup_set_left_margin (page_setup, double_value, GTK_UNIT_MM);
3158 gtk_page_setup_set_left_margin (page_setup,
3159 gtk_paper_size_get_default_left_margin (paper_size, GTK_UNIT_MM),
3163 if (window->priv->metadata &&
3164 ev_metadata_get_double (window->priv->metadata, "page-setup-margin-right", &double_value)) {
3165 gtk_page_setup_set_right_margin (page_setup, double_value, GTK_UNIT_MM);
3167 gtk_page_setup_set_right_margin (page_setup,
3168 gtk_paper_size_get_default_right_margin (paper_size, GTK_UNIT_MM),
3173 static GtkPrintSettings *
3174 get_print_settings (GKeyFile *key_file)
3176 GtkPrintSettings *print_settings;
3178 print_settings = g_key_file_has_group (key_file, EV_PRINT_SETTINGS_GROUP) ?
3179 gtk_print_settings_new_from_key_file (key_file, EV_PRINT_SETTINGS_GROUP, NULL) :
3180 gtk_print_settings_new ();
3182 return print_settings ? print_settings : gtk_print_settings_new ();
3185 static GtkPageSetup *
3186 get_print_page_setup (GKeyFile *key_file)
3188 GtkPageSetup *page_setup;
3190 page_setup = g_key_file_has_group (key_file, EV_PAGE_SETUP_GROUP) ?
3191 gtk_page_setup_new_from_key_file (key_file, EV_PAGE_SETUP_GROUP, NULL) :
3192 gtk_page_setup_new ();
3194 return page_setup ? page_setup : gtk_page_setup_new ();
3198 ev_window_print_cancel (EvWindow *ev_window)
3200 EvPrintOperation *op;
3202 if (!ev_window->priv->print_queue)
3205 while ((op = g_queue_peek_tail (ev_window->priv->print_queue))) {
3206 ev_print_operation_cancel (op);
3211 ev_window_print_update_pending_jobs_message (EvWindow *ev_window,
3216 if (!EV_IS_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area) ||
3217 !ev_window->priv->print_queue)
3221 ev_window_set_message_area (ev_window, NULL);
3226 text = g_strdup_printf (ngettext ("%d pending job in queue",
3227 "%d pending jobs in queue",
3228 n_jobs - 1), n_jobs - 1);
3231 ev_message_area_set_secondary_text (EV_MESSAGE_AREA (ev_window->priv->message_area),
3237 destroy_window (GtkWidget *window)
3239 gtk_widget_destroy (window);
3245 ev_window_print_operation_done (EvPrintOperation *op,
3246 GtkPrintOperationResult result,
3247 EvWindow *ev_window)
3252 case GTK_PRINT_OPERATION_RESULT_APPLY: {
3253 GtkPrintSettings *print_settings;
3255 print_settings = ev_print_operation_get_print_settings (op);
3256 ev_window_save_print_settings (ev_window, print_settings);
3258 if (ev_print_operation_get_embed_page_setup (op)) {
3259 GtkPageSetup *page_setup;
3261 page_setup = ev_print_operation_get_default_page_setup (op);
3262 ev_window_save_print_page_setup (ev_window, page_setup);
3267 case GTK_PRINT_OPERATION_RESULT_ERROR: {
3269 GError *error = NULL;
3272 ev_print_operation_get_error (op, &error);
3274 /* The message area is already used by
3275 * the printing progress, so it's better to
3276 * use a popup dialog in this case
3278 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
3279 GTK_DIALOG_DESTROY_WITH_PARENT,
3282 "%s", _("Failed to print document"));
3283 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
3284 "%s", error->message);
3285 g_signal_connect (dialog, "response",
3286 G_CALLBACK (gtk_widget_destroy),
3288 gtk_widget_show (dialog);
3290 g_error_free (error);
3293 case GTK_PRINT_OPERATION_RESULT_CANCEL:
3298 g_queue_remove (ev_window->priv->print_queue, op);
3299 g_object_unref (op);
3300 n_jobs = g_queue_get_length (ev_window->priv->print_queue);
3301 ev_window_print_update_pending_jobs_message (ev_window, n_jobs);
3303 if (n_jobs == 0 && ev_window->priv->close_after_print)
3304 g_idle_add ((GSourceFunc)destroy_window,
3309 ev_window_print_progress_response_cb (EvProgressMessageArea *area,
3311 EvWindow *ev_window)
3313 if (response == GTK_RESPONSE_CANCEL) {
3314 EvPrintOperation *op;
3316 op = g_queue_peek_tail (ev_window->priv->print_queue);
3317 ev_print_operation_cancel (op);
3319 gtk_widget_hide (GTK_WIDGET (area));
3324 ev_window_print_operation_status_changed (EvPrintOperation *op,
3325 EvWindow *ev_window)
3327 const gchar *status;
3330 status = ev_print_operation_get_status (op);
3331 fraction = ev_print_operation_get_progress (op);
3333 if (!ev_window->priv->message_area) {
3335 const gchar *job_name;
3338 job_name = ev_print_operation_get_job_name (op);
3339 text = g_strdup_printf (_("Printing job “%s”"), job_name);
3341 area = ev_progress_message_area_new (GTK_STOCK_PRINT,
3346 GTK_RESPONSE_CANCEL,
3348 ev_window_print_update_pending_jobs_message (ev_window, 1);
3349 g_signal_connect (area, "response",
3350 G_CALLBACK (ev_window_print_progress_response_cb),
3352 gtk_widget_show (area);
3353 ev_window_set_message_area (ev_window, area);
3357 ev_progress_message_area_set_status (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
3359 ev_progress_message_area_set_fraction (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
3364 ev_window_print_operation_begin_print (EvPrintOperation *op,
3365 EvWindow *ev_window)
3367 if (!ev_window->priv->print_queue)
3368 ev_window->priv->print_queue = g_queue_new ();
3370 g_queue_push_head (ev_window->priv->print_queue, op);
3371 ev_window_print_update_pending_jobs_message (ev_window,
3372 g_queue_get_length (ev_window->priv->print_queue));
3376 ev_window_print_range (EvWindow *ev_window,
3380 EvPrintOperation *op;
3381 GKeyFile *print_settings_file;
3382 GtkPrintSettings *print_settings;
3383 GtkPageSetup *print_page_setup;
3385 gint document_last_page;
3386 gboolean embed_page_setup;
3388 g_return_if_fail (EV_IS_WINDOW (ev_window));
3389 g_return_if_fail (ev_window->priv->document != NULL);
3391 if (!ev_window->priv->print_queue)
3392 ev_window->priv->print_queue = g_queue_new ();
3394 op = ev_print_operation_new (ev_window->priv->document);
3396 g_warning ("%s", "Printing is not supported for document\n");
3400 g_signal_connect (op, "begin_print",
3401 G_CALLBACK (ev_window_print_operation_begin_print),
3402 (gpointer)ev_window);
3403 g_signal_connect (op, "status_changed",
3404 G_CALLBACK (ev_window_print_operation_status_changed),
3405 (gpointer)ev_window);
3406 g_signal_connect (op, "done",
3407 G_CALLBACK (ev_window_print_operation_done),
3408 (gpointer)ev_window);
3410 current_page = ev_document_model_get_page (ev_window->priv->model);
3411 document_last_page = ev_document_get_n_pages (ev_window->priv->document);
3413 print_settings_file = get_print_settings_file ();
3415 print_settings = get_print_settings (print_settings_file);
3416 ev_window_load_print_settings_from_metadata (ev_window, print_settings);
3418 print_page_setup = get_print_page_setup (print_settings_file);
3419 ev_window_load_print_page_setup_from_metadata (ev_window, print_page_setup);
3421 if (first_page != 1 || last_page != document_last_page) {
3424 /* Ranges in GtkPrint are 0 - N */
3425 range.start = first_page - 1;
3426 range.end = last_page - 1;
3428 gtk_print_settings_set_print_pages (print_settings,
3429 GTK_PRINT_PAGES_RANGES);
3430 gtk_print_settings_set_page_ranges (print_settings,
3434 ev_print_operation_set_job_name (op, gtk_window_get_title (GTK_WINDOW (ev_window)));
3435 ev_print_operation_set_current_page (op, current_page);
3436 ev_print_operation_set_print_settings (op, print_settings);
3437 ev_print_operation_set_default_page_setup (op, print_page_setup);
3438 embed_page_setup = ev_window->priv->lockdown_settings ?
3439 !g_settings_get_boolean (ev_window->priv->lockdown_settings,
3440 GS_LOCKDOWN_PRINT_SETUP) :
3442 ev_print_operation_set_embed_page_setup (op, embed_page_setup);
3444 g_object_unref (print_settings);
3445 g_object_unref (print_page_setup);
3446 g_key_file_free (print_settings_file);
3448 ev_print_operation_run (op, GTK_WINDOW (ev_window));
3452 ev_window_print (EvWindow *window)
3454 ev_window_print_range (window, 1,
3455 ev_document_get_n_pages (window->priv->document));
3459 ev_window_cmd_file_print (GtkAction *action, EvWindow *ev_window)
3461 ev_window_print (ev_window);
3465 ev_window_cmd_file_properties (GtkAction *action, EvWindow *ev_window)
3467 if (ev_window->priv->properties == NULL) {
3468 ev_window->priv->properties = ev_properties_dialog_new ();
3469 ev_properties_dialog_set_document (EV_PROPERTIES_DIALOG (ev_window->priv->properties),
3470 ev_window->priv->uri,
3471 ev_window->priv->document);
3472 g_object_add_weak_pointer (G_OBJECT (ev_window->priv->properties),
3473 (gpointer) &(ev_window->priv->properties));
3474 gtk_window_set_transient_for (GTK_WINDOW (ev_window->priv->properties),
3475 GTK_WINDOW (ev_window));
3478 ev_document_fc_mutex_lock ();
3479 gtk_widget_show (ev_window->priv->properties);
3480 ev_document_fc_mutex_unlock ();
3484 document_modified_confirmation_dialog_response (GtkDialog *dialog,
3486 EvWindow *ev_window)
3488 gtk_widget_destroy (GTK_WIDGET (dialog));
3491 case GTK_RESPONSE_YES:
3492 ev_window_cmd_save_as (NULL, ev_window);
3494 case GTK_RESPONSE_NO:
3495 gtk_widget_destroy (GTK_WIDGET (ev_window));
3497 case GTK_RESPONSE_CANCEL:
3504 ev_window_check_document_modified (EvWindow *ev_window)
3506 EvDocument *document = ev_window->priv->document;
3508 gchar *text, *markup;
3509 const gchar *secondary_text;
3514 if (EV_IS_DOCUMENT_FORMS (document) &&
3515 ev_document_forms_document_is_modified (EV_DOCUMENT_FORMS (document))) {
3516 secondary_text = _("Document contains form fields that have been filled out. "
3517 "If you don't save a copy, changes will be permanently lost.");
3518 } else if (EV_IS_DOCUMENT_ANNOTATIONS (document) &&
3519 ev_document_annotations_document_is_modified (EV_DOCUMENT_ANNOTATIONS (document))) {
3520 secondary_text = _("Document contains new or modified annotations. "
3521 "If you don't save a copy, changes will be permanently lost.");
3527 text = g_markup_printf_escaped (_("Save a copy of document “%s” before closing?"),
3528 gtk_window_get_title (GTK_WINDOW (ev_window)));
3530 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
3532 GTK_MESSAGE_QUESTION,
3536 markup = g_strdup_printf ("<b>%s</b>", text);
3539 gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), markup);
3542 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
3543 "%s", secondary_text);
3545 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
3546 _("Close _without Saving"),
3549 GTK_RESPONSE_CANCEL,
3553 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
3554 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
3557 GTK_RESPONSE_CANCEL,
3560 g_signal_connect (dialog, "response",
3561 G_CALLBACK (document_modified_confirmation_dialog_response),
3563 gtk_widget_show (dialog);
3569 print_jobs_confirmation_dialog_response (GtkDialog *dialog,
3571 EvWindow *ev_window)
3573 gtk_widget_destroy (GTK_WIDGET (dialog));
3576 case GTK_RESPONSE_YES:
3577 if (!ev_window->priv->print_queue ||
3578 g_queue_is_empty (ev_window->priv->print_queue))
3579 gtk_widget_destroy (GTK_WIDGET (ev_window));
3581 ev_window->priv->close_after_print = TRUE;
3583 case GTK_RESPONSE_NO:
3584 ev_window->priv->close_after_print = TRUE;
3585 if (ev_window->priv->print_queue &&
3586 !g_queue_is_empty (ev_window->priv->print_queue)) {
3587 gtk_widget_set_sensitive (GTK_WIDGET (ev_window), FALSE);
3588 ev_window_print_cancel (ev_window);
3590 gtk_widget_destroy (GTK_WIDGET (ev_window));
3593 case GTK_RESPONSE_CANCEL:
3595 ev_window->priv->close_after_print = FALSE;
3600 ev_window_check_print_queue (EvWindow *ev_window)
3603 gchar *text, *markup;
3606 n_print_jobs = ev_window->priv->print_queue ?
3607 g_queue_get_length (ev_window->priv->print_queue) : 0;
3609 if (n_print_jobs == 0)
3612 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
3614 GTK_MESSAGE_QUESTION,
3617 if (n_print_jobs == 1) {
3618 EvPrintOperation *op;
3619 const gchar *job_name;
3621 op = g_queue_peek_tail (ev_window->priv->print_queue);
3622 job_name = ev_print_operation_get_job_name (op);
3624 text = g_strdup_printf (_("Wait until print job “%s” finishes before closing?"),
3627 text = g_strdup_printf (_("There are %d print jobs active. "
3628 "Wait until print finishes before closing?"),
3632 markup = g_strdup_printf ("<b>%s</b>", text);
3635 gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), markup);
3638 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s",
3639 _("If you close the window, pending print "
3640 "jobs will not be printed."));
3642 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
3643 _("Cancel _print and Close"),
3646 GTK_RESPONSE_CANCEL,
3647 _("Close _after Printing"),
3650 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
3651 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
3654 GTK_RESPONSE_CANCEL,
3657 g_signal_connect (dialog, "response",
3658 G_CALLBACK (print_jobs_confirmation_dialog_response),
3660 gtk_widget_show (dialog);
3666 ev_window_close (EvWindow *ev_window)
3668 if (EV_WINDOW_IS_PRESENTATION (ev_window)) {
3671 /* Save current page */
3672 current_page = ev_view_presentation_get_current_page (
3673 EV_VIEW_PRESENTATION (ev_window->priv->presentation_view));
3674 ev_document_model_set_page (ev_window->priv->model, current_page);
3677 if (ev_window_check_document_modified (ev_window))
3680 if (ev_window_check_print_queue (ev_window))
3687 ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window)
3689 if (ev_window_close (ev_window))
3690 gtk_widget_destroy (GTK_WIDGET (ev_window));
3694 ev_window_cmd_focus_page_selector (GtkAction *act, EvWindow *window)
3698 update_chrome_flag (window, EV_CHROME_RAISE_TOOLBAR, TRUE);
3699 ev_window_set_action_sensitive (window, "ViewToolbar", FALSE);
3700 update_chrome_visibility (window);
3702 action = gtk_action_group_get_action (window->priv->action_group,
3703 PAGE_SELECTOR_ACTION);
3704 ev_page_action_grab_focus (EV_PAGE_ACTION (action));
3708 ev_window_cmd_scroll_forward (GtkAction *action, EvWindow *window)
3710 ev_view_scroll (EV_VIEW (window->priv->view), GTK_SCROLL_PAGE_FORWARD, FALSE);
3714 ev_window_cmd_scroll_backward (GtkAction *action, EvWindow *window)
3716 ev_view_scroll (EV_VIEW (window->priv->view), GTK_SCROLL_PAGE_BACKWARD, FALSE);
3720 ev_window_cmd_continuous (GtkAction *action, EvWindow *ev_window)
3722 gboolean continuous;
3724 ev_window_stop_presentation (ev_window, TRUE);
3725 continuous = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
3726 ev_document_model_set_continuous (ev_window->priv->model, continuous);
3730 ev_window_cmd_dual (GtkAction *action, EvWindow *ev_window)
3734 ev_window_stop_presentation (ev_window, TRUE);
3735 dual_page = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
3736 ev_document_model_set_dual_page (ev_window->priv->model, dual_page);
3740 ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window)
3742 ev_window_stop_presentation (ev_window, TRUE);
3744 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
3745 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_BEST_FIT);
3747 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FREE);
3749 ev_window_update_actions (ev_window);
3753 ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window)
3755 ev_window_stop_presentation (ev_window, TRUE);
3757 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
3758 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FIT_WIDTH);
3760 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FREE);
3762 ev_window_update_actions (ev_window);
3767 ev_window_cmd_edit_select_all (GtkAction *action, EvWindow *ev_window)
3769 g_return_if_fail (EV_IS_WINDOW (ev_window));
3771 ev_view_select_all (EV_VIEW (ev_window->priv->view));
3775 ev_window_cmd_edit_find (GtkAction *action, EvWindow *ev_window)
3777 g_return_if_fail (EV_IS_WINDOW (ev_window));
3779 if (ev_window->priv->document == NULL || !EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
3780 g_error ("Find action should be insensitive since document doesn't support find");
3784 update_chrome_flag (ev_window, EV_CHROME_FINDBAR, TRUE);
3785 update_chrome_visibility (ev_window);
3786 gtk_widget_grab_focus (ev_window->priv->find_bar);
3790 ev_window_cmd_edit_find_next (GtkAction *action, EvWindow *ev_window)
3792 g_return_if_fail (EV_IS_WINDOW (ev_window));
3794 update_chrome_flag (ev_window, EV_CHROME_FINDBAR, TRUE);
3795 update_chrome_visibility (ev_window);
3796 gtk_widget_grab_focus (ev_window->priv->find_bar);
3797 ev_view_find_next (EV_VIEW (ev_window->priv->view));
3801 ev_window_cmd_edit_find_previous (GtkAction *action, EvWindow *ev_window)
3803 g_return_if_fail (EV_IS_WINDOW (ev_window));
3805 update_chrome_flag (ev_window, EV_CHROME_FINDBAR, TRUE);
3806 update_chrome_visibility (ev_window);
3807 gtk_widget_grab_focus (ev_window->priv->find_bar);
3808 ev_view_find_previous (EV_VIEW (ev_window->priv->view));
3812 ev_window_cmd_edit_copy (GtkAction *action, EvWindow *ev_window)
3814 g_return_if_fail (EV_IS_WINDOW (ev_window));
3816 ev_view_copy (EV_VIEW (ev_window->priv->view));
3820 ev_window_sidebar_position_change_cb (GObject *object,
3822 EvWindow *ev_window)
3824 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window))
3825 ev_metadata_set_int (ev_window->priv->metadata, "sidebar_size",
3826 gtk_paned_get_position (GTK_PANED (object)));
3830 ev_window_update_fullscreen_action (EvWindow *window)
3834 action = gtk_action_group_get_action (window->priv->action_group, "ViewFullscreen");
3835 g_signal_handlers_block_by_func
3836 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
3837 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
3838 ev_document_model_get_fullscreen (window->priv->model));
3839 g_signal_handlers_unblock_by_func
3840 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
3844 fullscreen_toolbar_setup_item_properties (GtkUIManager *ui_manager)
3848 item = gtk_ui_manager_get_widget (ui_manager, "/FullscreenToolbar/GoPreviousPage");
3849 g_object_set (item, "is-important", FALSE, NULL);
3851 item = gtk_ui_manager_get_widget (ui_manager, "/FullscreenToolbar/GoNextPage");
3852 g_object_set (item, "is-important", FALSE, NULL);
3854 item = gtk_ui_manager_get_widget (ui_manager, "/FullscreenToolbar/StartPresentation");
3855 g_object_set (item, "is-important", TRUE, NULL);
3857 item = gtk_ui_manager_get_widget (ui_manager, "/FullscreenToolbar/LeaveFullscreen");
3858 g_object_set (item, "is-important", TRUE, NULL);
3862 fullscreen_toolbar_remove_shadow (GtkWidget *toolbar)
3864 GtkCssProvider *provider;
3866 gtk_widget_set_name (toolbar, "ev-fullscreen-toolbar");
3868 provider = gtk_css_provider_new ();
3869 gtk_css_provider_load_from_data (provider,
3870 "#ev-fullscreen-toolbar {\n"
3871 " -GtkToolbar-shadow-type: none; }",
3873 gtk_style_context_add_provider (gtk_widget_get_style_context (toolbar),
3874 GTK_STYLE_PROVIDER (provider),
3875 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
3876 g_object_unref (provider);
3880 ev_window_run_fullscreen (EvWindow *window)
3882 gboolean fullscreen_window = TRUE;
3884 if (ev_document_model_get_fullscreen (window->priv->model))
3887 if (!window->priv->fullscreen_toolbar) {
3888 window->priv->fullscreen_toolbar =
3889 gtk_ui_manager_get_widget (window->priv->ui_manager,
3890 "/FullscreenToolbar");
3892 gtk_toolbar_set_style (GTK_TOOLBAR (window->priv->fullscreen_toolbar),
3893 GTK_TOOLBAR_BOTH_HORIZ);
3894 fullscreen_toolbar_remove_shadow (window->priv->fullscreen_toolbar);
3895 fullscreen_toolbar_setup_item_properties (window->priv->ui_manager);
3897 gtk_box_pack_start (GTK_BOX (window->priv->main_box),
3898 window->priv->fullscreen_toolbar,
3900 gtk_box_reorder_child (GTK_BOX (window->priv->main_box),
3901 window->priv->fullscreen_toolbar, 1);
3904 if (EV_WINDOW_IS_PRESENTATION (window)) {
3905 ev_window_stop_presentation (window, FALSE);
3906 fullscreen_window = FALSE;
3909 g_object_set (G_OBJECT (window->priv->scrolled_window),
3910 "shadow-type", GTK_SHADOW_NONE,
3913 ev_document_model_set_fullscreen (window->priv->model, TRUE);
3914 ev_window_update_fullscreen_action (window);
3916 /* If the user doesn't have the main toolbar he/she won't probably want
3917 * the toolbar in fullscreen mode. See bug #483048
3919 update_chrome_flag (window, EV_CHROME_FULLSCREEN_TOOLBAR,
3920 (window->priv->chrome & EV_CHROME_TOOLBAR) != 0);
3921 update_chrome_visibility (window);
3923 if (fullscreen_window)
3924 gtk_window_fullscreen (GTK_WINDOW (window));
3925 gtk_widget_grab_focus (window->priv->view);
3927 if (window->priv->metadata && !ev_window_is_empty (window))
3928 ev_metadata_set_boolean (window->priv->metadata, "fullscreen", TRUE);
3932 ev_window_stop_fullscreen (EvWindow *window,
3933 gboolean unfullscreen_window)
3935 if (!ev_document_model_get_fullscreen (window->priv->model))
3938 g_object_set (G_OBJECT (window->priv->scrolled_window),
3939 "shadow-type", GTK_SHADOW_IN,
3942 ev_document_model_set_fullscreen (window->priv->model, FALSE);
3943 ev_window_update_fullscreen_action (window);
3944 update_chrome_flag (window, EV_CHROME_FULLSCREEN_TOOLBAR, FALSE);
3945 update_chrome_visibility (window);
3946 if (unfullscreen_window)
3947 gtk_window_unfullscreen (GTK_WINDOW (window));
3949 if (window->priv->metadata && !ev_window_is_empty (window))
3950 ev_metadata_set_boolean (window->priv->metadata, "fullscreen", FALSE);
3954 ev_window_cmd_view_fullscreen (GtkAction *action, EvWindow *window)
3956 gboolean fullscreen;
3958 fullscreen = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
3960 ev_window_run_fullscreen (window);
3962 ev_window_stop_fullscreen (window, TRUE);
3967 ev_window_update_presentation_action (EvWindow *window)
3971 action = gtk_action_group_get_action (window->priv->action_group, "ViewPresentation");
3972 g_signal_handlers_block_by_func
3973 (action, G_CALLBACK (ev_window_cmd_view_presentation), window);
3974 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
3975 EV_WINDOW_IS_PRESENTATION (window));
3976 g_signal_handlers_unblock_by_func
3977 (action, G_CALLBACK (ev_window_cmd_view_presentation), window);
3981 ev_window_view_presentation_finished (EvWindow *window)
3983 ev_window_stop_presentation (window, TRUE);
3987 ev_window_view_presentation_focus_in (EvWindow *window)
3989 ev_application_screensaver_disable (EV_APP);
3995 ev_window_view_presentation_focus_out (EvWindow *window)
3997 ev_application_screensaver_enable (EV_APP);
4003 ev_window_run_presentation (EvWindow *window)
4005 gboolean fullscreen_window = TRUE;
4008 gboolean inverted_colors;
4010 if (EV_WINDOW_IS_PRESENTATION (window))
4013 if (ev_document_model_get_fullscreen (window->priv->model)) {
4014 ev_window_stop_fullscreen (window, FALSE);
4015 fullscreen_window = FALSE;
4018 current_page = ev_document_model_get_page (window->priv->model);
4019 rotation = ev_document_model_get_rotation (window->priv->model);
4020 inverted_colors = ev_document_model_get_inverted_colors (window->priv->model);
4021 window->priv->presentation_view = ev_view_presentation_new (window->priv->document,
4025 g_signal_connect_swapped (window->priv->presentation_view, "finished",
4026 G_CALLBACK (ev_window_view_presentation_finished),
4028 g_signal_connect_swapped (window->priv->presentation_view, "external-link",
4029 G_CALLBACK (view_external_link_cb),
4031 g_signal_connect_swapped (window->priv->presentation_view, "focus-in-event",
4032 G_CALLBACK (ev_window_view_presentation_focus_in),
4034 g_signal_connect_swapped (window->priv->presentation_view, "focus-out-event",
4035 G_CALLBACK (ev_window_view_presentation_focus_out),
4038 gtk_box_pack_start (GTK_BOX (window->priv->main_box),
4039 window->priv->presentation_view,
4042 gtk_widget_hide (window->priv->hpaned);
4043 ev_window_update_presentation_action (window);
4044 update_chrome_visibility (window);
4046 gtk_widget_grab_focus (window->priv->presentation_view);
4047 if (fullscreen_window)
4048 gtk_window_fullscreen (GTK_WINDOW (window));
4050 gtk_widget_show (window->priv->presentation_view);
4052 ev_application_screensaver_disable (EV_APP);
4054 if (window->priv->metadata && !ev_window_is_empty (window))
4055 ev_metadata_set_boolean (window->priv->metadata, "presentation", TRUE);
4059 ev_window_stop_presentation (EvWindow *window,
4060 gboolean unfullscreen_window)
4065 if (!EV_WINDOW_IS_PRESENTATION (window))
4068 current_page = ev_view_presentation_get_current_page (EV_VIEW_PRESENTATION (window->priv->presentation_view));
4069 ev_document_model_set_page (window->priv->model, current_page);
4070 rotation = ev_view_presentation_get_rotation (EV_VIEW_PRESENTATION (window->priv->presentation_view));
4071 ev_document_model_set_rotation (window->priv->model, rotation);
4073 gtk_container_remove (GTK_CONTAINER (window->priv->main_box),
4074 window->priv->presentation_view);
4075 window->priv->presentation_view = NULL;
4077 gtk_widget_show (window->priv->hpaned);
4078 ev_window_update_presentation_action (window);
4079 update_chrome_visibility (window);
4080 if (unfullscreen_window)
4081 gtk_window_unfullscreen (GTK_WINDOW (window));
4083 gtk_widget_grab_focus (window->priv->view);
4085 ev_application_screensaver_enable (EV_APP);
4087 if (window->priv->metadata && !ev_window_is_empty (window))
4088 ev_metadata_set_boolean (window->priv->metadata, "presentation", FALSE);
4092 ev_window_cmd_view_presentation (GtkAction *action, EvWindow *window)
4094 gboolean presentation;
4096 presentation = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
4098 ev_window_run_presentation (window);
4103 ev_window_setup_gtk_settings (EvWindow *window)
4105 GtkSettings *settings;
4107 gchar *menubar_accel_accel;
4109 screen = gtk_window_get_screen (GTK_WINDOW (window));
4110 settings = gtk_settings_get_for_screen (screen);
4112 g_object_get (settings,
4113 "gtk-menu-bar-accel", &menubar_accel_accel,
4115 if (menubar_accel_accel != NULL && menubar_accel_accel[0] != '\0') {
4116 gtk_accelerator_parse (menubar_accel_accel,
4117 &window->priv->menubar_accel_keyval,
4118 &window->priv->menubar_accel_modifier);
4119 if (window->priv->menubar_accel_keyval == 0) {
4120 g_warning ("Failed to parse menu bar accelerator '%s'\n",
4121 menubar_accel_accel);
4124 window->priv->menubar_accel_keyval = 0;
4125 window->priv->menubar_accel_modifier = 0;
4128 g_free (menubar_accel_accel);
4132 ev_window_update_max_min_scale (EvWindow *window)
4136 gdouble min_width, min_height;
4137 gdouble width, height;
4139 gint rotation = ev_document_model_get_rotation (window->priv->model);
4141 if (!window->priv->document)
4144 dpi = get_screen_dpi (window) / 72.0;
4146 ev_document_get_min_page_size (window->priv->document, &min_width, &min_height);
4147 width = (rotation == 0 || rotation == 180) ? min_width : min_height;
4148 height = (rotation == 0 || rotation == 180) ? min_height : min_width;
4149 max_scale = sqrt (PAGE_CACHE_SIZE / (width * dpi * 4 * height * dpi));
4151 action = gtk_action_group_get_action (window->priv->action_group,
4152 ZOOM_CONTROL_ACTION);
4153 ephy_zoom_action_set_max_zoom_level (EPHY_ZOOM_ACTION (action), max_scale * dpi);
4155 ev_document_model_set_min_scale (window->priv->model, MIN_SCALE * dpi);
4156 ev_document_model_set_max_scale (window->priv->model, max_scale * dpi);
4160 ev_window_screen_changed (GtkWidget *widget,
4161 GdkScreen *old_screen)
4163 EvWindow *window = EV_WINDOW (widget);
4166 screen = gtk_widget_get_screen (widget);
4167 if (screen == old_screen)
4170 ev_window_setup_gtk_settings (window);
4171 ev_window_update_max_min_scale (window);
4173 if (GTK_WIDGET_CLASS (ev_window_parent_class)->screen_changed) {
4174 GTK_WIDGET_CLASS (ev_window_parent_class)->screen_changed (widget, old_screen);
4179 ev_window_state_event (GtkWidget *widget,
4180 GdkEventWindowState *event)
4182 EvWindow *window = EV_WINDOW (widget);
4184 if (GTK_WIDGET_CLASS (ev_window_parent_class)->window_state_event) {
4185 GTK_WIDGET_CLASS (ev_window_parent_class)->window_state_event (widget, event);
4188 if ((event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN) == 0)
4191 if (event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN) {
4192 if (ev_document_model_get_fullscreen (window->priv->model) || EV_WINDOW_IS_PRESENTATION (window))
4195 ev_window_run_fullscreen (window);
4197 if (ev_document_model_get_fullscreen (window->priv->model))
4198 ev_window_stop_fullscreen (window, FALSE);
4199 else if (EV_WINDOW_IS_PRESENTATION (window))
4200 ev_window_stop_presentation (window, FALSE);
4207 ev_window_set_page_mode (EvWindow *window,
4208 EvWindowPageMode page_mode)
4210 GtkWidget *child = NULL;
4211 GtkWidget *real_child;
4213 if (window->priv->page_mode == page_mode)
4216 window->priv->page_mode = page_mode;
4218 switch (page_mode) {
4219 case PAGE_MODE_DOCUMENT:
4220 child = window->priv->view;
4222 case PAGE_MODE_PASSWORD:
4223 child = window->priv->password_view;
4226 g_assert_not_reached ();
4229 real_child = gtk_bin_get_child (GTK_BIN (window->priv->scrolled_window));
4230 if (child != real_child) {
4231 gtk_container_remove (GTK_CONTAINER (window->priv->scrolled_window),
4233 gtk_container_add (GTK_CONTAINER (window->priv->scrolled_window),
4236 ev_window_update_actions (window);
4241 ev_window_cmd_edit_rotate_left (GtkAction *action, EvWindow *ev_window)
4245 if (EV_WINDOW_IS_PRESENTATION (ev_window)) {
4246 rotation = ev_view_presentation_get_rotation (EV_VIEW_PRESENTATION (ev_window->priv->presentation_view));
4247 ev_view_presentation_set_rotation (EV_VIEW_PRESENTATION (ev_window->priv->presentation_view),
4250 rotation = ev_document_model_get_rotation (ev_window->priv->model);
4252 ev_document_model_set_rotation (ev_window->priv->model, rotation - 90);
4257 ev_window_cmd_edit_rotate_right (GtkAction *action, EvWindow *ev_window)
4261 if (EV_WINDOW_IS_PRESENTATION (ev_window)) {
4262 rotation = ev_view_presentation_get_rotation (EV_VIEW_PRESENTATION (ev_window->priv->presentation_view));
4263 ev_view_presentation_set_rotation (EV_VIEW_PRESENTATION (ev_window->priv->presentation_view),
4266 rotation = ev_document_model_get_rotation (ev_window->priv->model);
4268 ev_document_model_set_rotation (ev_window->priv->model, rotation + 90);
4273 ev_window_cmd_view_inverted_colors (GtkAction *action, EvWindow *ev_window)
4275 gboolean inverted_colors = ev_document_model_get_inverted_colors (ev_window->priv->model);
4277 ev_document_model_set_inverted_colors (ev_window->priv->model, !inverted_colors);
4281 ev_window_cmd_edit_toolbar_cb (GtkDialog *dialog,
4283 EvWindow *ev_window)
4285 EggEditableToolbar *toolbar;
4286 gchar *toolbars_file;
4288 toolbar = EGG_EDITABLE_TOOLBAR (ev_window->priv->toolbar);
4289 egg_editable_toolbar_set_edit_mode (toolbar, FALSE);
4290 ev_window_set_action_sensitive (ev_window, "ViewToolbar", TRUE);
4292 toolbars_file = g_build_filename (ev_application_get_dot_dir (EV_APP, TRUE),
4293 "evince_toolbar.xml", NULL);
4294 egg_toolbars_model_save_toolbars (egg_editable_toolbar_get_model (toolbar),
4295 toolbars_file, "1.0");
4296 g_free (toolbars_file);
4298 gtk_widget_destroy (GTK_WIDGET (dialog));
4302 ev_window_cmd_edit_toolbar (GtkAction *action, EvWindow *ev_window)
4306 GtkWidget *content_area;
4307 EggEditableToolbar *toolbar;
4309 dialog = gtk_dialog_new_with_buttons (_("Toolbar Editor"),
4310 GTK_WINDOW (ev_window),
4311 GTK_DIALOG_DESTROY_WITH_PARENT,
4315 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
4316 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE);
4317 gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)), 5);
4318 gtk_box_set_spacing (GTK_BOX (content_area), 2);
4319 gtk_window_set_default_size (GTK_WINDOW (dialog), 500, 400);
4321 toolbar = EGG_EDITABLE_TOOLBAR (ev_window->priv->toolbar);
4322 editor = egg_toolbar_editor_new (ev_window->priv->ui_manager,
4323 egg_editable_toolbar_get_model (toolbar));
4325 gtk_container_set_border_width (GTK_CONTAINER (editor), 5);
4326 gtk_box_set_spacing (GTK_BOX (EGG_TOOLBAR_EDITOR (editor)), 5);
4328 gtk_box_pack_start (GTK_BOX (content_area), editor, TRUE, TRUE, 0);
4330 egg_editable_toolbar_set_edit_mode (toolbar, TRUE);
4331 ev_window_set_action_sensitive (ev_window, "ViewToolbar", FALSE);
4333 g_signal_connect (dialog, "response",
4334 G_CALLBACK (ev_window_cmd_edit_toolbar_cb),
4336 gtk_widget_show_all (dialog);
4340 ev_window_cmd_edit_save_settings (GtkAction *action, EvWindow *ev_window)
4342 EvWindowPrivate *priv = ev_window->priv;
4343 EvDocumentModel *model = priv->model;
4344 GSettings *settings = priv->default_settings;
4346 g_settings_set_boolean (settings, "continuous",
4347 ev_document_model_get_continuous (model));
4348 g_settings_set_boolean (settings, "dual-page",
4349 ev_document_model_get_dual_page (model));
4350 g_settings_set_boolean (settings, "fullscreen",
4351 ev_document_model_get_fullscreen (model));
4352 g_settings_set_boolean (settings, "inverted-colors",
4353 ev_document_model_get_inverted_colors (model));
4354 g_settings_set_enum (settings, "sizing-mode",
4355 ev_document_model_get_sizing_mode (model));
4356 g_settings_set_boolean (settings, "show-toolbar",
4357 gtk_widget_get_visible (priv->toolbar));
4358 g_settings_set_boolean (settings, "show-sidebar",
4359 gtk_widget_get_visible (priv->sidebar));
4360 g_settings_set_int (settings, "sidebar-size",
4361 gtk_paned_get_position (GTK_PANED (priv->hpaned)));
4362 g_settings_set_string (settings, "sidebar-page",
4363 ev_window_sidebar_get_current_page_id (ev_window));
4364 g_settings_apply (settings);
4368 ev_window_cmd_view_zoom_in (GtkAction *action, EvWindow *ev_window)
4370 g_return_if_fail (EV_IS_WINDOW (ev_window));
4372 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FREE);
4373 ev_view_zoom_in (EV_VIEW (ev_window->priv->view));
4377 ev_window_cmd_view_zoom_out (GtkAction *action, EvWindow *ev_window)
4379 g_return_if_fail (EV_IS_WINDOW (ev_window));
4381 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FREE);
4382 ev_view_zoom_out (EV_VIEW (ev_window->priv->view));
4386 ev_window_cmd_go_previous_page (GtkAction *action, EvWindow *ev_window)
4388 g_return_if_fail (EV_IS_WINDOW (ev_window));
4390 ev_view_previous_page (EV_VIEW (ev_window->priv->view));
4394 ev_window_cmd_go_next_page (GtkAction *action, EvWindow *ev_window)
4396 g_return_if_fail (EV_IS_WINDOW (ev_window));
4398 ev_view_next_page (EV_VIEW (ev_window->priv->view));
4402 ev_window_cmd_go_first_page (GtkAction *action, EvWindow *ev_window)
4404 g_return_if_fail (EV_IS_WINDOW (ev_window));
4406 ev_document_model_set_page (ev_window->priv->model, 0);
4410 ev_window_cmd_go_last_page (GtkAction *action, EvWindow *ev_window)
4412 g_return_if_fail (EV_IS_WINDOW (ev_window));
4414 ev_document_model_set_page (ev_window->priv->model,
4415 ev_document_get_n_pages (ev_window->priv->document) - 1);
4419 ev_window_cmd_go_forward (GtkAction *action, EvWindow *ev_window)
4421 int n_pages, current_page;
4423 g_return_if_fail (EV_IS_WINDOW (ev_window));
4425 n_pages = ev_document_get_n_pages (ev_window->priv->document);
4426 current_page = ev_document_model_get_page (ev_window->priv->model);
4428 if (current_page + 10 < n_pages) {
4429 ev_document_model_set_page (ev_window->priv->model, current_page + 10);
4434 ev_window_cmd_go_backward (GtkAction *action, EvWindow *ev_window)
4438 g_return_if_fail (EV_IS_WINDOW (ev_window));
4440 current_page = ev_document_model_get_page (ev_window->priv->model);
4442 if (current_page - 10 >= 0) {
4443 ev_document_model_set_page (ev_window->priv->model, current_page - 10);
4448 ev_window_cmd_bookmark_activate (GtkAction *action,
4451 guint page = ev_bookmark_action_get_page (EV_BOOKMARK_ACTION (action));
4453 ev_document_model_set_page (window->priv->model, page);
4457 compare_bookmarks (EvBookmark *a,
4460 return strcmp (a->title, b->title);
4464 ev_window_setup_bookmarks (EvWindow *window)
4468 if (!window->priv->bookmarks)
4471 if (window->priv->bookmarks_ui_id > 0) {
4472 gtk_ui_manager_remove_ui (window->priv->ui_manager,
4473 window->priv->bookmarks_ui_id);
4474 gtk_ui_manager_ensure_update (window->priv->ui_manager);
4476 window->priv->bookmarks_ui_id = gtk_ui_manager_new_merge_id (window->priv->ui_manager);
4478 if (window->priv->bookmarks_action_group) {
4479 gtk_ui_manager_remove_action_group (window->priv->ui_manager,
4480 window->priv->bookmarks_action_group);
4481 g_object_unref (window->priv->bookmarks_action_group);
4483 window->priv->bookmarks_action_group = gtk_action_group_new ("BookmarksActions");
4484 gtk_ui_manager_insert_action_group (window->priv->ui_manager,
4485 window->priv->bookmarks_action_group, -1);
4487 items = ev_bookmarks_get_bookmarks (window->priv->bookmarks);
4488 items = g_list_sort (items, (GCompareFunc)compare_bookmarks);
4490 for (l = items; l && l->data; l = g_list_next (l)) {
4491 EvBookmark *bm = (EvBookmark *)l->data;
4494 action = ev_bookmark_action_new (bm);
4495 g_signal_connect (action, "activate",
4496 G_CALLBACK (ev_window_cmd_bookmark_activate),
4498 gtk_action_group_add_action (window->priv->bookmarks_action_group,
4501 gtk_ui_manager_add_ui (window->priv->ui_manager,
4502 window->priv->bookmarks_ui_id,
4503 "/MainMenu/BookmarksMenu/BookmarksItems",
4504 gtk_action_get_label (action),
4505 gtk_action_get_name (action),
4506 GTK_UI_MANAGER_MENUITEM,
4509 g_object_unref (action);
4512 g_list_free (items);
4516 ev_window_cmd_bookmarks_add (GtkAction *action,
4523 bm.page = ev_document_model_get_page (window->priv->model);
4524 page_label = ev_document_get_page_label (window->priv->document, bm.page);
4525 page_title = ev_window_get_page_title (window, page_label);
4526 bm.title = page_title ? page_title : g_strdup_printf (_("Page %s"), page_label);
4527 g_free (page_label);
4529 /* EvBookmarks takes ownership of bookmark */
4530 ev_bookmarks_add (window->priv->bookmarks, &bm);
4534 ev_window_cmd_view_reload (GtkAction *action, EvWindow *ev_window)
4536 ev_window_reload_document (ev_window, NULL);
4540 ev_window_cmd_view_autoscroll (GtkAction *action, EvWindow *ev_window)
4542 ev_view_autoscroll_start (EV_VIEW (ev_window->priv->view));
4545 #if OFFLINE_HELP_ENABLED
4546 #define EV_HELP "ghelp:evince"
4548 #define EV_HELP "http://library.gnome.org/users/evince/stable/"
4552 ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
4554 GError *error = NULL;
4556 gtk_show_uri (gtk_window_get_screen (GTK_WINDOW (ev_window)),
4558 gtk_get_current_event_time (),
4561 ev_window_error_message (ev_window, error,
4562 "%s", _("There was an error displaying help"));
4563 g_error_free (error);
4568 ev_window_cmd_leave_fullscreen (GtkAction *action, EvWindow *window)
4570 ev_window_stop_fullscreen (window, TRUE);
4574 ev_window_cmd_start_presentation (GtkAction *action, EvWindow *window)
4576 ev_window_run_presentation (window);
4580 ev_window_cmd_escape (GtkAction *action, EvWindow *window)
4584 ev_view_autoscroll_stop (EV_VIEW (window->priv->view));
4586 widget = gtk_window_get_focus (GTK_WINDOW (window));
4587 if (widget && gtk_widget_get_ancestor (widget, EGG_TYPE_FIND_BAR)) {
4588 update_chrome_flag (window, EV_CHROME_FINDBAR, FALSE);
4589 update_chrome_visibility (window);
4590 gtk_widget_grab_focus (window->priv->view);
4592 gboolean fullscreen;
4594 fullscreen = ev_document_model_get_fullscreen (window->priv->model);
4597 ev_window_stop_fullscreen (window, TRUE);
4598 } else if (EV_WINDOW_IS_PRESENTATION (window)) {
4599 ev_window_stop_presentation (window, TRUE);
4600 gtk_widget_grab_focus (window->priv->view);
4602 gtk_widget_grab_focus (window->priv->view);
4605 if (fullscreen && EV_WINDOW_IS_PRESENTATION (window))
4606 g_warning ("Both fullscreen and presentation set somehow");
4611 save_sizing_mode (EvWindow *window)
4614 GEnumValue *enum_value;
4616 if (!window->priv->metadata || ev_window_is_empty (window))
4619 mode = ev_document_model_get_sizing_mode (window->priv->model);
4620 enum_value = g_enum_get_value (g_type_class_peek (EV_TYPE_SIZING_MODE), mode);
4621 ev_metadata_set_string (window->priv->metadata, "sizing_mode",
4622 enum_value->value_nick);
4626 ev_window_document_changed_cb (EvDocumentModel *model,
4628 EvWindow *ev_window)
4630 ev_window_set_document (ev_window,
4631 ev_document_model_get_document (model));
4635 ev_window_sizing_mode_changed_cb (EvDocumentModel *model,
4637 EvWindow *ev_window)
4639 EvSizingMode sizing_mode = ev_document_model_get_sizing_mode (model);
4641 g_object_set (ev_window->priv->scrolled_window,
4642 "hscrollbar-policy",
4643 sizing_mode == EV_SIZING_FREE ?
4644 GTK_POLICY_AUTOMATIC : GTK_POLICY_NEVER,
4645 "vscrollbar-policy", GTK_POLICY_AUTOMATIC,
4648 update_sizing_buttons (ev_window);
4649 save_sizing_mode (ev_window);
4653 ev_window_zoom_changed_cb (EvDocumentModel *model, GParamSpec *pspec, EvWindow *ev_window)
4655 ev_window_update_actions (ev_window);
4657 if (!ev_window->priv->metadata)
4660 if (ev_document_model_get_sizing_mode (model) == EV_SIZING_FREE && !ev_window_is_empty (ev_window)) {
4663 zoom = ev_document_model_get_scale (model);
4664 zoom *= 72.0 / get_screen_dpi (ev_window);
4665 ev_metadata_set_double (ev_window->priv->metadata, "zoom", zoom);
4670 ev_window_update_continuous_action (EvWindow *window)
4674 action = gtk_action_group_get_action (window->priv->action_group, "ViewContinuous");
4675 g_signal_handlers_block_by_func
4676 (action, G_CALLBACK (ev_window_cmd_continuous), window);
4677 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
4678 ev_document_model_get_continuous (window->priv->model));
4679 g_signal_handlers_unblock_by_func
4680 (action, G_CALLBACK (ev_window_cmd_continuous), window);
4684 ev_window_update_dual_page_action (EvWindow *window)
4688 action = gtk_action_group_get_action (window->priv->action_group, "ViewDual");
4689 g_signal_handlers_block_by_func
4690 (action, G_CALLBACK (ev_window_cmd_dual), window);
4691 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
4692 ev_document_model_get_dual_page (window->priv->model));
4693 g_signal_handlers_unblock_by_func
4694 (action, G_CALLBACK (ev_window_cmd_dual), window);
4698 ev_window_continuous_changed_cb (EvDocumentModel *model,
4700 EvWindow *ev_window)
4702 ev_window_update_continuous_action (ev_window);
4704 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window))
4705 ev_metadata_set_boolean (ev_window->priv->metadata, "continuous",
4706 ev_document_model_get_continuous (model));
4710 ev_window_rotation_changed_cb (EvDocumentModel *model,
4714 gint rotation = ev_document_model_get_rotation (model);
4716 if (window->priv->metadata && !ev_window_is_empty (window))
4717 ev_metadata_set_int (window->priv->metadata, "rotation",
4720 ev_window_update_max_min_scale (window);
4721 ev_window_refresh_window_thumbnail (window);
4725 ev_window_update_inverted_colors_action (EvWindow *window)
4729 action = gtk_action_group_get_action (window->priv->action_group, "ViewInvertedColors");
4730 g_signal_handlers_block_by_func
4731 (action, G_CALLBACK (ev_window_cmd_view_inverted_colors), window);
4732 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
4733 ev_document_model_get_inverted_colors (window->priv->model));
4734 g_signal_handlers_unblock_by_func
4735 (action, G_CALLBACK (ev_window_cmd_view_inverted_colors), window);
4739 ev_window_inverted_colors_changed_cb (EvDocumentModel *model,
4743 gboolean inverted_colors = ev_document_model_get_inverted_colors (model);
4745 ev_window_update_inverted_colors_action (window);
4747 if (window->priv->metadata && !ev_window_is_empty (window))
4748 ev_metadata_set_boolean (window->priv->metadata, "inverted-colors",
4751 ev_window_refresh_window_thumbnail (window);
4755 ev_window_dual_mode_changed_cb (EvDocumentModel *model,
4757 EvWindow *ev_window)
4759 ev_window_update_dual_page_action (ev_window);
4761 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window))
4762 ev_metadata_set_boolean (ev_window->priv->metadata, "dual-page",
4763 ev_document_model_get_dual_page (model));
4767 build_comments_string (EvDocument *document)
4769 gchar *comments = NULL;
4770 EvDocumentBackendInfo info;
4772 if (document && ev_document_get_backend_info (document, &info)) {
4773 comments = g_strdup_printf (
4774 _("Document Viewer\nUsing %s (%s)"),
4775 info.name, info.version);
4777 comments = g_strdup_printf (
4778 _("Document Viewer"));
4785 ev_window_cmd_help_about (GtkAction *action, EvWindow *ev_window)
4787 const char *authors[] = {
4788 "Martin Kretzschmar <m_kretzschmar@gmx.net>",
4789 "Jonathan Blandford <jrb@gnome.org>",
4790 "Marco Pesenti Gritti <marco@gnome.org>",
4791 "Nickolay V. Shmyrev <nshmyrev@yandex.ru>",
4792 "Bryan Clark <clarkbw@gnome.org>",
4793 "Carlos Garcia Campos <carlosgc@gnome.org>",
4794 "Wouter Bolsterlee <wbolster@gnome.org>",
4795 "Christian Persch <chpe" "\100" "gnome.org>",
4799 const char *documenters[] = {
4800 "Nickolay V. Shmyrev <nshmyrev@yandex.ru>",
4801 "Phil Bull <philbull@gmail.com>",
4802 "Tiffany Antpolski <tiffany.antopolski@gmail.com>",
4806 const char *license[] = {
4807 N_("Evince is free software; you can redistribute it and/or modify "
4808 "it under the terms of the GNU General Public License as published by "
4809 "the Free Software Foundation; either version 2 of the License, or "
4810 "(at your option) any later version.\n"),
4811 N_("Evince is distributed in the hope that it will be useful, "
4812 "but WITHOUT ANY WARRANTY; without even the implied warranty of "
4813 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
4814 "GNU General Public License for more details.\n"),
4815 N_("You should have received a copy of the GNU General Public License "
4816 "along with Evince; if not, write to the Free Software Foundation, Inc., "
4817 "51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n")
4820 char *license_trans;
4826 for (p = authors; *p; ++p)
4829 for (p = documenters; *p; ++p)
4833 license_trans = g_strconcat (_(license[0]), "\n", _(license[1]), "\n",
4834 _(license[2]), "\n", NULL);
4836 comments = build_comments_string (ev_window->priv->document);
4838 gtk_show_about_dialog (
4839 GTK_WINDOW (ev_window),
4840 "name", _("Evince"),
4843 _("© 1996–2010 The Evince authors"),
4844 "license", license_trans,
4845 "website", "http://www.gnome.org/projects/evince",
4846 "comments", comments,
4848 "documenters", documenters,
4849 "translator-credits", _("translator-credits"),
4850 "logo-icon-name", "evince",
4851 "wrap-license", TRUE,
4855 g_free (license_trans);
4859 ev_window_view_toolbar_cb (GtkAction *action, EvWindow *ev_window)
4863 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
4864 update_chrome_flag (ev_window, EV_CHROME_TOOLBAR, active);
4865 update_chrome_visibility (ev_window);
4866 if (ev_window->priv->metadata)
4867 ev_metadata_set_boolean (ev_window->priv->metadata, "show_toolbar", active);
4871 ev_window_view_sidebar_cb (GtkAction *action, EvWindow *ev_window)
4873 if (EV_WINDOW_IS_PRESENTATION (ev_window))
4876 update_chrome_flag (ev_window, EV_CHROME_SIDEBAR,
4877 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
4878 update_chrome_visibility (ev_window);
4882 ev_window_sidebar_current_page_changed_cb (EvSidebar *ev_sidebar,
4884 EvWindow *ev_window)
4886 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window)) {
4887 ev_metadata_set_string (ev_window->priv->metadata,
4889 ev_window_sidebar_get_current_page_id (ev_window));
4894 ev_window_sidebar_visibility_changed_cb (EvSidebar *ev_sidebar,
4896 EvWindow *ev_window)
4900 action = gtk_action_group_get_action (ev_window->priv->action_group, "ViewSidebar");
4902 if (!EV_WINDOW_IS_PRESENTATION (ev_window)) {
4903 gboolean visible = gtk_widget_get_visible (GTK_WIDGET (ev_sidebar));
4905 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible);
4907 if (ev_window->priv->metadata)
4908 ev_metadata_set_boolean (ev_window->priv->metadata, "sidebar_visibility",
4911 gtk_widget_grab_focus (ev_window->priv->view);
4916 view_menu_link_popup (EvWindow *ev_window,
4919 gboolean show_external = FALSE;
4920 gboolean show_internal = FALSE;
4923 if (ev_window->priv->link)
4924 g_object_unref (ev_window->priv->link);
4927 ev_window->priv->link = g_object_ref (link);
4929 ev_window->priv->link = NULL;
4931 if (ev_window->priv->link) {
4932 EvLinkAction *ev_action;
4934 ev_action = ev_link_get_action (link);
4936 switch (ev_link_action_get_action_type (ev_action)) {
4937 case EV_LINK_ACTION_TYPE_GOTO_DEST:
4938 case EV_LINK_ACTION_TYPE_GOTO_REMOTE:
4939 show_internal = TRUE;
4941 case EV_LINK_ACTION_TYPE_EXTERNAL_URI:
4942 case EV_LINK_ACTION_TYPE_LAUNCH:
4943 show_external = TRUE;
4951 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4953 gtk_action_set_visible (action, show_external);
4955 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4957 gtk_action_set_visible (action, show_external);
4959 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4961 gtk_action_set_visible (action, show_internal);
4963 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4964 "OpenLinkNewWindow");
4965 gtk_action_set_visible (action, show_internal);
4969 view_menu_image_popup (EvWindow *ev_window,
4973 gboolean show_image = FALSE;
4975 if (ev_window->priv->image)
4976 g_object_unref (ev_window->priv->image);
4979 ev_window->priv->image = g_object_ref (image);
4981 ev_window->priv->image = NULL;
4983 show_image = (ev_window->priv->image != NULL);
4985 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4987 gtk_action_set_visible (action, show_image);
4989 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4991 gtk_action_set_visible (action, show_image);
4995 view_menu_annot_popup (EvWindow *ev_window,
4996 EvAnnotation *annot)
4999 gboolean show_annot = FALSE;
5001 if (ev_window->priv->annot)
5002 g_object_unref (ev_window->priv->annot);
5003 ev_window->priv->annot = (annot) ? g_object_ref (annot) : NULL;
5005 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
5007 gtk_action_set_visible (action, (annot != NULL && EV_IS_ANNOTATION_MARKUP (annot)));
5009 if (annot && EV_IS_ANNOTATION_ATTACHMENT (annot)) {
5010 EvAttachment *attachment;
5012 attachment = ev_annotation_attachment_get_attachment (EV_ANNOTATION_ATTACHMENT (annot));
5015 if (ev_window->priv->attach_list) {
5016 g_list_foreach (ev_window->priv->attach_list,
5017 (GFunc) g_object_unref, NULL);
5018 g_list_free (ev_window->priv->attach_list);
5019 ev_window->priv->attach_list = NULL;
5021 ev_window->priv->attach_list =
5022 g_list_prepend (ev_window->priv->attach_list,
5023 g_object_ref (attachment));
5027 action = gtk_action_group_get_action (ev_window->priv->attachment_popup_action_group,
5029 gtk_action_set_visible (action, show_annot);
5031 action = gtk_action_group_get_action (ev_window->priv->attachment_popup_action_group,
5032 "SaveAttachmentAs");
5033 gtk_action_set_visible (action, show_annot);
5037 view_menu_popup_cb (EvView *view,
5039 EvWindow *ev_window)
5042 gboolean has_link = FALSE;
5043 gboolean has_image = FALSE;
5044 gboolean has_annot = FALSE;
5046 for (l = items; l; l = g_list_next (l)) {
5047 if (EV_IS_LINK (l->data)) {
5048 view_menu_link_popup (ev_window, EV_LINK (l->data));
5050 } else if (EV_IS_IMAGE (l->data)) {
5051 view_menu_image_popup (ev_window, EV_IMAGE (l->data));
5053 } else if (EV_IS_ANNOTATION (l->data)) {
5054 view_menu_annot_popup (ev_window, EV_ANNOTATION (l->data));
5060 view_menu_link_popup (ev_window, NULL);
5062 view_menu_image_popup (ev_window, NULL);
5064 view_menu_annot_popup (ev_window, NULL);
5066 gtk_menu_popup (GTK_MENU (ev_window->priv->view_popup),
5067 NULL, NULL, NULL, NULL,
5068 3, gtk_get_current_event_time ());
5073 attachment_bar_menu_popup_cb (EvSidebarAttachments *attachbar,
5075 EvWindow *ev_window)
5079 g_assert (attach_list != NULL);
5081 if (ev_window->priv->attach_list) {
5082 g_list_foreach (ev_window->priv->attach_list,
5083 (GFunc) g_object_unref, NULL);
5084 g_list_free (ev_window->priv->attach_list);
5087 ev_window->priv->attach_list = attach_list;
5089 popup = ev_window->priv->attachment_popup;
5091 gtk_menu_popup (GTK_MENU (popup), NULL, NULL,
5093 3, gtk_get_current_event_time ());
5099 ev_window_update_find_status_message (EvWindow *ev_window)
5103 if (!ev_window->priv->find_job)
5106 if (ev_job_is_finished (ev_window->priv->find_job)) {
5107 EvJobFind *job_find = EV_JOB_FIND (ev_window->priv->find_job);
5109 if (ev_job_find_has_results (job_find)) {
5112 n_results = ev_job_find_get_n_results (job_find,
5113 ev_document_model_get_page (ev_window->priv->model));
5114 /* TRANS: Sometimes this could be better translated as
5115 "%d hit(s) on this page". Therefore this string
5116 contains plural cases. */
5117 message = g_strdup_printf (ngettext ("%d found on this page",
5118 "%d found on this page",
5122 message = g_strdup (_("Not found"));
5127 percent = ev_job_find_get_progress (EV_JOB_FIND (ev_window->priv->find_job));
5128 message = g_strdup_printf (_("%3d%% remaining to search"),
5129 (gint) ((1.0 - percent) * 100));
5132 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar), message);
5137 ev_window_find_job_finished_cb (EvJobFind *job,
5138 EvWindow *ev_window)
5140 ev_window_update_find_status_message (ev_window);
5144 ev_window_find_job_updated_cb (EvJobFind *job,
5146 EvWindow *ev_window)
5148 ev_window_update_actions (ev_window);
5150 ev_view_find_changed (EV_VIEW (ev_window->priv->view),
5151 ev_job_find_get_results (job),
5153 ev_window_update_find_status_message (ev_window);
5157 ev_window_clear_find_job (EvWindow *ev_window)
5159 if (ev_window->priv->find_job != NULL) {
5160 if (!ev_job_is_finished (ev_window->priv->find_job))
5161 ev_job_cancel (ev_window->priv->find_job);
5163 g_signal_handlers_disconnect_by_func (ev_window->priv->find_job,
5164 ev_window_find_job_finished_cb,
5166 g_signal_handlers_disconnect_by_func (ev_window->priv->find_job,
5167 ev_window_find_job_updated_cb,
5169 g_object_unref (ev_window->priv->find_job);
5170 ev_window->priv->find_job = NULL;
5175 find_bar_previous_cb (EggFindBar *find_bar,
5176 EvWindow *ev_window)
5178 ev_view_find_previous (EV_VIEW (ev_window->priv->view));
5182 find_bar_next_cb (EggFindBar *find_bar,
5183 EvWindow *ev_window)
5185 ev_view_find_next (EV_VIEW (ev_window->priv->view));
5189 find_bar_close_cb (EggFindBar *find_bar,
5190 EvWindow *ev_window)
5192 ev_view_find_cancel (EV_VIEW (ev_window->priv->view));
5193 ev_window_clear_find_job (ev_window);
5194 update_chrome_flag (ev_window, EV_CHROME_FINDBAR, FALSE);
5195 update_chrome_visibility (ev_window);
5199 ev_window_search_start (EvWindow *ev_window)
5201 EggFindBar *find_bar = EGG_FIND_BAR (ev_window->priv->find_bar);
5202 const char *search_string;
5204 if (!ev_window->priv->document || !EV_IS_DOCUMENT_FIND (ev_window->priv->document))
5207 search_string = egg_find_bar_get_search_string (find_bar);
5209 ev_window_clear_find_job (ev_window);
5210 if (search_string && search_string[0]) {
5211 ev_window->priv->find_job = ev_job_find_new (ev_window->priv->document,
5212 ev_document_model_get_page (ev_window->priv->model),
5213 ev_document_get_n_pages (ev_window->priv->document),
5215 egg_find_bar_get_case_sensitive (find_bar));
5216 g_signal_connect (ev_window->priv->find_job, "finished",
5217 G_CALLBACK (ev_window_find_job_finished_cb),
5219 g_signal_connect (ev_window->priv->find_job, "updated",
5220 G_CALLBACK (ev_window_find_job_updated_cb),
5222 ev_job_scheduler_push_job (ev_window->priv->find_job, EV_JOB_PRIORITY_NONE);
5224 ev_window_update_actions (ev_window);
5225 egg_find_bar_set_status_text (find_bar, NULL);
5226 gtk_widget_queue_draw (GTK_WIDGET (ev_window->priv->view));
5231 find_bar_search_changed_cb (EggFindBar *find_bar,
5233 EvWindow *ev_window)
5235 /* Either the string or case sensitivity could have changed. */
5236 ev_view_find_search_changed (EV_VIEW (ev_window->priv->view));
5237 ev_window_search_start (ev_window);
5241 find_bar_visibility_changed_cb (EggFindBar *find_bar,
5243 EvWindow *ev_window)
5247 visible = gtk_widget_get_visible (GTK_WIDGET (find_bar));
5249 if (ev_window->priv->document &&
5250 EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
5251 ev_view_find_set_highlight_search (EV_VIEW (ev_window->priv->view), visible);
5252 ev_window_update_actions (ev_window);
5255 ev_window_search_start (ev_window);
5257 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar), NULL);
5262 find_bar_scroll (EggFindBar *find_bar,
5263 GtkScrollType scroll,
5264 EvWindow *ev_window)
5266 ev_view_scroll (EV_VIEW (ev_window->priv->view), scroll, FALSE);
5270 zoom_control_changed_cb (EphyZoomAction *action,
5272 EvWindow *ev_window)
5276 if (zoom == EPHY_ZOOM_BEST_FIT) {
5277 mode = EV_SIZING_BEST_FIT;
5278 } else if (zoom == EPHY_ZOOM_FIT_WIDTH) {
5279 mode = EV_SIZING_FIT_WIDTH;
5281 mode = EV_SIZING_FREE;
5284 ev_document_model_set_sizing_mode (ev_window->priv->model, mode);
5286 if (mode == EV_SIZING_FREE) {
5287 ev_document_model_set_scale (ev_window->priv->model,
5288 zoom * get_screen_dpi (ev_window) / 72.0);
5293 ev_window_drag_data_received (GtkWidget *widget,
5294 GdkDragContext *context,
5297 GtkSelectionData *selection_data,
5302 EvWindow *window = EV_WINDOW (widget);
5305 GSList *uri_list = NULL;
5308 source = gtk_drag_get_source_widget (context);
5309 if (source && widget == gtk_widget_get_toplevel (source)) {
5310 gtk_drag_finish (context, FALSE, FALSE, time);
5314 uris = gtk_selection_data_get_uris (selection_data);
5316 gtk_drag_finish (context, FALSE, FALSE, time);
5320 for (i = 0; uris[i]; i++) {
5321 uri_list = g_slist_prepend (uri_list, (gpointer) uris[i]);
5324 ev_application_open_uri_list (EV_APP, uri_list,
5325 gtk_window_get_screen (GTK_WINDOW (window)),
5327 gtk_drag_finish (context, TRUE, FALSE, time);
5330 g_slist_free (uri_list);
5334 ev_window_finalize (GObject *object)
5336 G_OBJECT_CLASS (ev_window_parent_class)->finalize (object);
5338 if (ev_window_n_copies == 0) {
5339 ev_application_shutdown (EV_APP);
5341 ev_window_n_copies--;
5346 ev_window_dispose (GObject *object)
5348 EvWindow *window = EV_WINDOW (object);
5349 EvWindowPrivate *priv = window->priv;
5350 GObject *mpkeys = ev_application_get_media_keys (EV_APP);
5353 g_signal_handlers_disconnect_by_func (mpkeys,
5354 ev_window_media_player_key_pressed,
5359 if (priv->dbus_object_id > 0) {
5360 ev_window_emit_closed (window);
5361 g_dbus_connection_unregister_object (ev_application_get_dbus_connection (EV_APP),
5362 priv->dbus_object_id);
5363 priv->dbus_object_id = 0;
5366 if (priv->dbus_object_path) {
5367 g_free (priv->dbus_object_path);
5368 priv->dbus_object_path = NULL;
5370 #endif /* ENABLE_DBUS */
5372 if (priv->bookmarks) {
5373 g_object_unref (priv->bookmarks);
5374 priv->bookmarks = NULL;
5377 if (priv->metadata) {
5378 g_object_unref (priv->metadata);
5379 priv->metadata = NULL;
5382 if (priv->setup_document_idle > 0) {
5383 g_source_remove (priv->setup_document_idle);
5384 priv->setup_document_idle = 0;
5387 if (priv->monitor) {
5388 g_object_unref (priv->monitor);
5389 priv->monitor = NULL;
5393 ev_window_title_free (priv->title);
5397 if (priv->ui_manager) {
5398 g_object_unref (priv->ui_manager);
5399 priv->ui_manager = NULL;
5402 if (priv->action_group) {
5403 g_object_unref (priv->action_group);
5404 priv->action_group = NULL;
5407 if (priv->view_popup_action_group) {
5408 g_object_unref (priv->view_popup_action_group);
5409 priv->view_popup_action_group = NULL;
5412 if (priv->attachment_popup_action_group) {
5413 g_object_unref (priv->attachment_popup_action_group);
5414 priv->attachment_popup_action_group = NULL;
5417 if (priv->recent_action_group) {
5418 g_object_unref (priv->recent_action_group);
5419 priv->recent_action_group = NULL;
5422 if (priv->bookmarks_action_group) {
5423 g_object_unref (priv->bookmarks_action_group);
5424 priv->bookmarks_action_group = NULL;
5427 if (priv->recent_manager) {
5428 g_signal_handlers_disconnect_by_func (priv->recent_manager,
5429 ev_window_setup_recent,
5431 priv->recent_manager = NULL;
5434 if (priv->settings) {
5435 g_object_unref (priv->settings);
5436 priv->settings = NULL;
5439 if (priv->default_settings) {
5440 g_settings_apply (priv->default_settings);
5441 g_object_unref (priv->default_settings);
5442 priv->default_settings = NULL;
5445 if (priv->lockdown_settings) {
5446 g_object_unref (priv->lockdown_settings);
5447 priv->lockdown_settings = NULL;
5450 priv->recent_ui_id = 0;
5453 g_signal_handlers_disconnect_by_func (priv->model,
5454 ev_window_page_changed_cb,
5456 g_object_unref (priv->model);
5460 if (priv->document) {
5461 g_object_unref (priv->document);
5462 priv->document = NULL;
5466 g_object_unref (priv->view);
5470 if (priv->password_view) {
5471 g_object_unref (priv->password_view);
5472 priv->password_view = NULL;
5475 if (priv->load_job) {
5476 ev_window_clear_load_job (window);
5479 if (priv->reload_job) {
5480 ev_window_clear_reload_job (window);
5483 if (priv->save_job) {
5484 ev_window_clear_save_job (window);
5487 if (priv->thumbnail_job) {
5488 ev_window_clear_thumbnail_job (window);
5491 if (priv->find_job) {
5492 ev_window_clear_find_job (window);
5495 if (priv->local_uri) {
5496 ev_window_clear_local_uri (window);
5497 priv->local_uri = NULL;
5500 ev_window_clear_progress_idle (window);
5501 if (priv->progress_cancellable) {
5502 g_object_unref (priv->progress_cancellable);
5503 priv->progress_cancellable = NULL;
5506 ev_window_close_dialogs (window);
5509 g_object_unref (priv->link);
5514 g_object_unref (priv->image);
5519 g_object_unref (priv->annot);
5523 if (priv->attach_list) {
5524 g_list_foreach (priv->attach_list,
5525 (GFunc) g_object_unref,
5527 g_list_free (priv->attach_list);
5528 priv->attach_list = NULL;
5531 if (priv->find_bar) {
5532 g_signal_handlers_disconnect_by_func
5533 (window->priv->find_bar,
5534 G_CALLBACK (find_bar_close_cb),
5536 priv->find_bar = NULL;
5544 if (priv->search_string) {
5545 g_free (priv->search_string);
5546 priv->search_string = NULL;
5550 g_object_unref (priv->dest);
5554 if (priv->history) {
5555 g_object_unref (priv->history);
5556 priv->history = NULL;
5559 if (priv->print_queue) {
5560 g_queue_free (priv->print_queue);
5561 priv->print_queue = NULL;
5564 G_OBJECT_CLASS (ev_window_parent_class)->dispose (object);
5568 menubar_deactivate_cb (GtkWidget *menubar,
5571 g_signal_handlers_disconnect_by_func (menubar,
5572 G_CALLBACK (menubar_deactivate_cb),
5575 gtk_menu_shell_deselect (GTK_MENU_SHELL (menubar));
5577 update_chrome_visibility (window);
5581 ev_window_key_press_event (GtkWidget *widget,
5584 EvWindow *ev_window = EV_WINDOW (widget);
5585 EvWindowPrivate *priv = ev_window->priv;
5586 gboolean handled = FALSE;
5588 /* Propagate the event to the view first
5589 * It's needed to be able to type in
5590 * annot popups windows
5593 g_object_ref (priv->view);
5594 if (gtk_widget_is_sensitive (priv->view))
5595 handled = gtk_widget_event (priv->view, (GdkEvent*) event);
5596 g_object_unref (priv->view);
5599 if (!handled && !EV_WINDOW_IS_PRESENTATION (ev_window)) {
5600 guint modifier = event->state & gtk_accelerator_get_default_mod_mask ();
5602 if (priv->menubar_accel_keyval != 0 &&
5603 event->keyval == priv->menubar_accel_keyval &&
5604 modifier == priv->menubar_accel_modifier) {
5605 if (!gtk_widget_get_visible (priv->menubar)) {
5606 g_signal_connect (priv->menubar, "deactivate",
5607 G_CALLBACK (menubar_deactivate_cb),
5610 gtk_widget_show (priv->menubar);
5611 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menubar),
5620 handled = GTK_WIDGET_CLASS (ev_window_parent_class)->key_press_event (widget, event);
5626 ev_window_delete_event (GtkWidget *widget,
5629 return !ev_window_close (EV_WINDOW (widget));
5633 ev_window_class_init (EvWindowClass *ev_window_class)
5635 GObjectClass *g_object_class = G_OBJECT_CLASS (ev_window_class);
5636 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (ev_window_class);
5638 g_object_class->dispose = ev_window_dispose;
5639 g_object_class->finalize = ev_window_finalize;
5641 widget_class->delete_event = ev_window_delete_event;
5642 widget_class->key_press_event = ev_window_key_press_event;
5643 widget_class->screen_changed = ev_window_screen_changed;
5644 widget_class->window_state_event = ev_window_state_event;
5645 widget_class->drag_data_received = ev_window_drag_data_received;
5647 g_type_class_add_private (g_object_class, sizeof (EvWindowPrivate));
5651 static const GtkActionEntry entries[] = {
5652 { "File", NULL, N_("_File") },
5653 { "Edit", NULL, N_("_Edit") },
5654 { "View", NULL, N_("_View") },
5655 { "Go", NULL, N_("_Go") },
5656 { "Bookmarks", NULL, N_("_Bookmarks") },
5657 { "Help", NULL, N_("_Help") },
5660 { "FileOpen", GTK_STOCK_OPEN, N_("_Open…"), "<control>O",
5661 N_("Open an existing document"),
5662 G_CALLBACK (ev_window_cmd_file_open) },
5663 { "FileOpenCopy", NULL, N_("Op_en a Copy"), "<control>N",
5664 N_("Open a copy of the current document in a new window"),
5665 G_CALLBACK (ev_window_cmd_file_open_copy) },
5666 { "FileSaveAs", GTK_STOCK_SAVE_AS, N_("_Save a Copy…"), "<control>S",
5667 N_("Save a copy of the current document"),
5668 G_CALLBACK (ev_window_cmd_save_as) },
5669 { "FileOpenContainingFolder", GTK_STOCK_DIRECTORY, N_("Open Containing _Folder"), NULL,
5670 N_("Show the folder which contains this file in the file manager"),
5671 G_CALLBACK (ev_window_cmd_open_containing_folder) },
5672 { "FilePrint", GTK_STOCK_PRINT, N_("_Print…"), "<control>P",
5673 N_("Print this document"),
5674 G_CALLBACK (ev_window_cmd_file_print) },
5675 { "FileProperties", GTK_STOCK_PROPERTIES, N_("P_roperties"), "<alt>Return", NULL,
5676 G_CALLBACK (ev_window_cmd_file_properties) },
5677 { "FileCloseWindow", GTK_STOCK_CLOSE, NULL, "<control>W", NULL,
5678 G_CALLBACK (ev_window_cmd_file_close_window) },
5681 { "EditCopy", GTK_STOCK_COPY, NULL, "<control>C", NULL,
5682 G_CALLBACK (ev_window_cmd_edit_copy) },
5683 { "EditSelectAll", GTK_STOCK_SELECT_ALL, N_("Select _All"), "<control>A", NULL,
5684 G_CALLBACK (ev_window_cmd_edit_select_all) },
5685 { "EditFind", GTK_STOCK_FIND, N_("_Find…"), "<control>F",
5686 N_("Find a word or phrase in the document"),
5687 G_CALLBACK (ev_window_cmd_edit_find) },
5688 { "EditFindNext", NULL, N_("Find Ne_xt"), "<control>G", NULL,
5689 G_CALLBACK (ev_window_cmd_edit_find_next) },
5690 { "EditFindPrevious", NULL, N_("Find Pre_vious"), "<shift><control>G", NULL,
5691 G_CALLBACK (ev_window_cmd_edit_find_previous) },
5692 { "EditToolbar", NULL, N_("T_oolbar"), NULL, NULL,
5693 G_CALLBACK (ev_window_cmd_edit_toolbar) },
5694 { "EditRotateLeft", EV_STOCK_ROTATE_LEFT, N_("Rotate _Left"), "<control>Left", NULL,
5695 G_CALLBACK (ev_window_cmd_edit_rotate_left) },
5696 { "EditRotateRight", EV_STOCK_ROTATE_RIGHT, N_("Rotate _Right"), "<control>Right", NULL,
5697 G_CALLBACK (ev_window_cmd_edit_rotate_right) },
5698 { "EditSaveSettings", NULL, N_("Save Current Settings as _Default"), "<control>T", NULL,
5699 G_CALLBACK (ev_window_cmd_edit_save_settings) },
5703 { "ViewZoomIn", GTK_STOCK_ZOOM_IN, NULL, "<control>plus",
5704 N_("Enlarge the document"),
5705 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5706 { "ViewZoomOut", GTK_STOCK_ZOOM_OUT, NULL, "<control>minus",
5707 N_("Shrink the document"),
5708 G_CALLBACK (ev_window_cmd_view_zoom_out) },
5709 { "ViewReload", GTK_STOCK_REFRESH, N_("_Reload"), "<control>R",
5710 N_("Reload the document"),
5711 G_CALLBACK (ev_window_cmd_view_reload) },
5713 { "ViewAutoscroll", GTK_STOCK_MEDIA_PLAY, N_("Auto_scroll"), NULL, NULL,
5714 G_CALLBACK (ev_window_cmd_view_autoscroll) },
5717 { "GoPreviousPage", GTK_STOCK_GO_UP, N_("_Previous Page"), "<control>Page_Up",
5718 N_("Go to the previous page"),
5719 G_CALLBACK (ev_window_cmd_go_previous_page) },
5720 { "GoNextPage", GTK_STOCK_GO_DOWN, N_("_Next Page"), "<control>Page_Down",
5721 N_("Go to the next page"),
5722 G_CALLBACK (ev_window_cmd_go_next_page) },
5723 { "GoFirstPage", GTK_STOCK_GOTO_TOP, N_("_First Page"), "<control>Home",
5724 N_("Go to the first page"),
5725 G_CALLBACK (ev_window_cmd_go_first_page) },
5726 { "GoLastPage", GTK_STOCK_GOTO_BOTTOM, N_("_Last Page"), "<control>End",
5727 N_("Go to the last page"),
5728 G_CALLBACK (ev_window_cmd_go_last_page) },
5730 /* Bookmarks menu */
5731 { "BookmarksAdd", GTK_STOCK_ADD, N_("_Add Bookmark"), "<control>D",
5732 N_("Add a bookmark for the current page"),
5733 G_CALLBACK (ev_window_cmd_bookmarks_add) },
5736 { "HelpContents", GTK_STOCK_HELP, N_("_Contents"), "F1", NULL,
5737 G_CALLBACK (ev_window_cmd_help_contents) },
5739 { "HelpAbout", GTK_STOCK_ABOUT, N_("_About"), NULL, NULL,
5740 G_CALLBACK (ev_window_cmd_help_about) },
5743 { "LeaveFullscreen", GTK_STOCK_LEAVE_FULLSCREEN, N_("Leave Fullscreen"), NULL,
5744 N_("Leave fullscreen mode"),
5745 G_CALLBACK (ev_window_cmd_leave_fullscreen) },
5746 { "StartPresentation", EV_STOCK_RUN_PRESENTATION, N_("Start Presentation"), NULL,
5747 N_("Start a presentation"),
5748 G_CALLBACK (ev_window_cmd_start_presentation) },
5751 { "Escape", NULL, "", "Escape", "",
5752 G_CALLBACK (ev_window_cmd_escape) },
5753 { "Slash", GTK_STOCK_FIND, NULL, "slash", NULL,
5754 G_CALLBACK (ev_window_cmd_edit_find) },
5755 { "F3", NULL, "", "F3", NULL,
5756 G_CALLBACK (ev_window_cmd_edit_find_next) },
5757 { "PageDown", NULL, "", "Page_Down", NULL,
5758 G_CALLBACK (ev_window_cmd_scroll_forward) },
5759 { "PageUp", NULL, "", "Page_Up", NULL,
5760 G_CALLBACK (ev_window_cmd_scroll_backward) },
5761 { "Space", NULL, "", "space", NULL,
5762 G_CALLBACK (ev_window_cmd_scroll_forward) },
5763 { "ShiftSpace", NULL, "", "<shift>space", NULL,
5764 G_CALLBACK (ev_window_cmd_scroll_backward) },
5765 { "BackSpace", NULL, "", "BackSpace", NULL,
5766 G_CALLBACK (ev_window_cmd_scroll_backward) },
5767 { "ShiftBackSpace", NULL, "", "<shift>BackSpace", NULL,
5768 G_CALLBACK (ev_window_cmd_scroll_forward) },
5769 { "Return", NULL, "", "Return", NULL,
5770 G_CALLBACK (ev_window_cmd_scroll_forward) },
5771 { "ShiftReturn", NULL, "", "<shift>Return", NULL,
5772 G_CALLBACK (ev_window_cmd_scroll_backward) },
5773 { "p", GTK_STOCK_GO_UP, "", "p", NULL,
5774 G_CALLBACK (ev_window_cmd_go_previous_page) },
5775 { "n", GTK_STOCK_GO_DOWN, "", "n", NULL,
5776 G_CALLBACK (ev_window_cmd_go_next_page) },
5777 { "Plus", GTK_STOCK_ZOOM_IN, NULL, "plus", NULL,
5778 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5779 { "CtrlEqual", GTK_STOCK_ZOOM_IN, NULL, "<control>equal", NULL,
5780 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5781 { "Equal", GTK_STOCK_ZOOM_IN, NULL, "equal", NULL,
5782 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5783 { "Minus", GTK_STOCK_ZOOM_OUT, NULL, "minus", NULL,
5784 G_CALLBACK (ev_window_cmd_view_zoom_out) },
5785 { "FocusPageSelector", NULL, "", "<control>l", NULL,
5786 G_CALLBACK (ev_window_cmd_focus_page_selector) },
5787 { "GoBackwardFast", NULL, "", "<shift>Page_Up", NULL,
5788 G_CALLBACK (ev_window_cmd_go_backward) },
5789 { "GoForwardFast", NULL, "", "<shift>Page_Down", NULL,
5790 G_CALLBACK (ev_window_cmd_go_forward) },
5791 { "KpPlus", GTK_STOCK_ZOOM_IN, NULL, "KP_Add", NULL,
5792 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5793 { "KpMinus", GTK_STOCK_ZOOM_OUT, NULL, "KP_Subtract", NULL,
5794 G_CALLBACK (ev_window_cmd_view_zoom_out) },
5795 { "CtrlKpPlus", GTK_STOCK_ZOOM_IN, NULL, "<control>KP_Add", NULL,
5796 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5797 { "CtrlKpMinus", GTK_STOCK_ZOOM_OUT, NULL, "<control>KP_Subtract", NULL,
5798 G_CALLBACK (ev_window_cmd_view_zoom_out) },
5799 { "CtrlInsert", GTK_STOCK_COPY, NULL, "<control>Insert", NULL,
5800 G_CALLBACK (ev_window_cmd_edit_copy) },
5804 static const GtkToggleActionEntry toggle_entries[] = {
5806 { "ViewToolbar", NULL, N_("_Toolbar"), NULL,
5807 N_("Show or hide the toolbar"),
5808 G_CALLBACK (ev_window_view_toolbar_cb), TRUE },
5809 { "ViewSidebar", GTK_STOCK_INDEX, N_("Side _Pane"), "F9",
5810 N_("Show or hide the side pane"),
5811 G_CALLBACK (ev_window_view_sidebar_cb), TRUE },
5812 { "ViewContinuous", EV_STOCK_VIEW_CONTINUOUS, N_("_Continuous"), NULL,
5813 N_("Show the entire document"),
5814 G_CALLBACK (ev_window_cmd_continuous), TRUE },
5815 { "ViewDual", EV_STOCK_VIEW_DUAL, N_("_Dual"), NULL,
5816 N_("Show two pages at once"),
5817 G_CALLBACK (ev_window_cmd_dual), FALSE },
5818 { "ViewFullscreen", GTK_STOCK_FULLSCREEN, N_("_Fullscreen"), "F11",
5819 N_("Expand the window to fill the screen"),
5820 G_CALLBACK (ev_window_cmd_view_fullscreen) },
5821 { "ViewPresentation", EV_STOCK_RUN_PRESENTATION, N_("Pre_sentation"), "F5",
5822 N_("Run document as a presentation"),
5823 G_CALLBACK (ev_window_cmd_view_presentation) },
5824 { "ViewBestFit", EV_STOCK_ZOOM_PAGE, N_("_Best Fit"), NULL,
5825 N_("Make the current document fill the window"),
5826 G_CALLBACK (ev_window_cmd_view_best_fit) },
5827 { "ViewPageWidth", EV_STOCK_ZOOM_WIDTH, N_("Fit Page _Width"), NULL,
5828 N_("Make the current document fill the window width"),
5829 G_CALLBACK (ev_window_cmd_view_page_width) },
5830 { "ViewInvertedColors", EV_STOCK_INVERTED_COLORS, N_("_Inverted Colors"), "<control>I",
5831 N_("Show page contents with the colors inverted"),
5832 G_CALLBACK (ev_window_cmd_view_inverted_colors) },
5836 /* Popups specific items */
5837 static const GtkActionEntry view_popup_entries [] = {
5839 { "OpenLink", GTK_STOCK_OPEN, N_("_Open Link"), NULL,
5840 NULL, G_CALLBACK (ev_view_popup_cmd_open_link) },
5841 { "GoLink", GTK_STOCK_GO_FORWARD, N_("_Go To"), NULL,
5842 NULL, G_CALLBACK (ev_view_popup_cmd_open_link) },
5843 { "OpenLinkNewWindow", NULL, N_("Open in New _Window"), NULL,
5844 NULL, G_CALLBACK (ev_view_popup_cmd_open_link_new_window) },
5845 { "CopyLinkAddress", NULL, N_("_Copy Link Address"), NULL,
5846 NULL, G_CALLBACK (ev_view_popup_cmd_copy_link_address) },
5847 { "SaveImageAs", NULL, N_("_Save Image As…"), NULL,
5848 NULL, G_CALLBACK (ev_view_popup_cmd_save_image_as) },
5849 { "CopyImage", NULL, N_("Copy _Image"), NULL,
5850 NULL, G_CALLBACK (ev_view_popup_cmd_copy_image) },
5851 { "AnnotProperties", NULL, N_("Annotation Properties…"), NULL,
5852 NULL, G_CALLBACK (ev_view_popup_cmd_annot_properties) }
5855 static const GtkActionEntry attachment_popup_entries [] = {
5856 { "OpenAttachment", GTK_STOCK_OPEN, N_("_Open Attachment"), NULL,
5857 NULL, G_CALLBACK (ev_attachment_popup_cmd_open_attachment) },
5858 { "SaveAttachmentAs", GTK_STOCK_SAVE_AS, N_("_Save Attachment As…"), NULL,
5859 NULL, G_CALLBACK (ev_attachment_popup_cmd_save_attachment_as) },
5863 sidebar_links_link_activated_cb (EvSidebarLinks *sidebar_links, EvLink *link, EvWindow *window)
5865 ev_view_handle_link (EV_VIEW (window->priv->view), link);
5869 activate_link_cb (EvPageAction *page_action, EvLink *link, EvWindow *window)
5871 ev_view_handle_link (EV_VIEW (window->priv->view), link);
5872 gtk_widget_grab_focus (window->priv->view);
5876 navigation_action_activate_link_cb (EvNavigationAction *action, EvLink *link, EvWindow *window)
5879 ev_view_handle_link (EV_VIEW (window->priv->view), link);
5880 gtk_widget_grab_focus (window->priv->view);
5884 sidebar_layers_visibility_changed (EvSidebarLayers *layers,
5887 ev_view_reload (EV_VIEW (window->priv->view));
5891 sidebar_annots_annot_activated_cb (EvSidebarAnnotations *sidebar_annots,
5892 EvMapping *annot_mapping,
5895 ev_view_focus_annotation (EV_VIEW (window->priv->view), annot_mapping);
5899 sidebar_annots_begin_annot_add (EvSidebarAnnotations *sidebar_annots,
5900 EvAnnotationType annot_type,
5903 ev_view_begin_add_annotation (EV_VIEW (window->priv->view), annot_type);
5907 view_annot_added (EvView *view,
5908 EvAnnotation *annot,
5911 ev_sidebar_annotations_annot_added (EV_SIDEBAR_ANNOTATIONS (window->priv->sidebar_annots),
5916 sidebar_annots_annot_add_cancelled (EvSidebarAnnotations *sidebar_annots,
5919 ev_view_cancel_add_annotation (EV_VIEW (window->priv->view));
5923 sidebar_bookmarks_add_bookmark (EvSidebarBookmarks *sidebar_bookmarks,
5926 ev_window_cmd_bookmarks_add (NULL, window);
5930 register_custom_actions (EvWindow *window, GtkActionGroup *group)
5934 action = g_object_new (EV_TYPE_PAGE_ACTION,
5935 "name", PAGE_SELECTOR_ACTION,
5937 "tooltip", _("Select Page"),
5938 "icon_name", "text-x-generic",
5939 "visible_overflown", FALSE,
5941 ev_page_action_set_model (EV_PAGE_ACTION (action),
5942 window->priv->model);
5943 g_signal_connect (action, "activate_link",
5944 G_CALLBACK (activate_link_cb), window);
5945 gtk_action_group_add_action (group, action);
5946 g_object_unref (action);
5948 action = g_object_new (EPHY_TYPE_ZOOM_ACTION,
5949 "name", ZOOM_CONTROL_ACTION,
5951 "stock_id", EV_STOCK_ZOOM,
5952 "tooltip", _("Adjust the zoom level"),
5955 g_signal_connect (action, "zoom_to_level",
5956 G_CALLBACK (zoom_control_changed_cb), window);
5957 gtk_action_group_add_action (group, action);
5958 g_object_unref (action);
5960 action = g_object_new (EV_TYPE_NAVIGATION_ACTION,
5961 "name", NAVIGATION_ACTION,
5962 "label", _("Navigation"),
5963 "is_important", TRUE,
5964 "short_label", _("Back"),
5965 "stock_id", GTK_STOCK_GO_DOWN,
5966 /*translators: this is the history action*/
5967 "tooltip", _("Move across visited pages"),
5969 g_signal_connect (action, "activate_link",
5970 G_CALLBACK (navigation_action_activate_link_cb), window);
5971 gtk_action_group_add_action (group, action);
5972 g_object_unref (action);
5974 action = g_object_new (EV_TYPE_OPEN_RECENT_ACTION,
5975 "name", "FileOpenRecent",
5976 "label", _("_Open…"),
5977 "tooltip", _("Open an existing document"),
5978 "stock_id", GTK_STOCK_OPEN,
5980 g_signal_connect (action, "activate",
5981 G_CALLBACK (ev_window_cmd_file_open), window);
5982 g_signal_connect (action, "item_activated",
5983 G_CALLBACK (ev_window_open_recent_action_item_activated),
5985 gtk_action_group_add_action (group, action);
5986 g_object_unref (action);
5990 set_action_properties (GtkActionGroup *action_group)
5994 action = gtk_action_group_get_action (action_group, "FileOpenContainingFolder");
5995 /*translators: this is the label for toolbar button*/
5996 g_object_set (action, "short_label", _("Open Folder"), NULL);
5998 action = gtk_action_group_get_action (action_group, "GoPreviousPage");
5999 g_object_set (action, "is-important", TRUE, NULL);
6000 /*translators: this is the label for toolbar button*/
6001 g_object_set (action, "short_label", _("Previous"), NULL);
6003 action = gtk_action_group_get_action (action_group, "GoNextPage");
6004 g_object_set (action, "is-important", TRUE, NULL);
6005 /*translators: this is the label for toolbar button*/
6006 g_object_set (action, "short_label", _("Next"), NULL);
6008 action = gtk_action_group_get_action (action_group, "ViewZoomIn");
6009 /*translators: this is the label for toolbar button*/
6010 g_object_set (action, "short_label", _("Zoom In"), NULL);
6012 action = gtk_action_group_get_action (action_group, "ViewZoomOut");
6013 /*translators: this is the label for toolbar button*/
6014 g_object_set (action, "short_label", _("Zoom Out"), NULL);
6016 action = gtk_action_group_get_action (action_group, "ViewBestFit");
6017 /*translators: this is the label for toolbar button*/
6018 g_object_set (action, "short_label", _("Best Fit"), NULL);
6020 action = gtk_action_group_get_action (action_group, "ViewPageWidth");
6021 /*translators: this is the label for toolbar button*/
6022 g_object_set (action, "short_label", _("Fit Width"), NULL);
6024 action = gtk_action_group_get_action (action_group, "LeaveFullscreen");
6025 g_object_set (action, "is-important", TRUE, NULL);
6029 sidebar_widget_model_set (EvSidebarLinks *ev_sidebar_links,
6031 EvWindow *ev_window)
6033 GtkTreeModel *model;
6036 g_object_get (G_OBJECT (ev_sidebar_links),
6040 action = gtk_action_group_get_action (ev_window->priv->action_group, PAGE_SELECTOR_ACTION);
6041 ev_page_action_set_links_model (EV_PAGE_ACTION (action), model);
6042 g_object_unref (model);
6046 view_actions_focus_in_cb (GtkWidget *widget, GdkEventFocus *event, EvWindow *window)
6051 keys = ev_application_get_media_keys (EV_APP);
6052 ev_media_player_keys_focused (EV_MEDIA_PLAYER_KEYS (keys));
6053 #endif /* ENABLE_DBUS */
6055 update_chrome_flag (window, EV_CHROME_RAISE_TOOLBAR, FALSE);
6056 ev_window_set_action_sensitive (window, "ViewToolbar",
6057 !ev_window_is_editing_toolbar (window));
6059 ev_window_set_view_accels_sensitivity (window, TRUE);
6061 update_chrome_visibility (window);
6067 view_actions_focus_out_cb (GtkWidget *widget, GdkEventFocus *event, EvWindow *window)
6069 ev_window_set_view_accels_sensitivity (window, FALSE);
6075 sidebar_page_main_widget_update_cb (GObject *ev_sidebar_page,
6077 EvWindow *ev_window)
6081 g_object_get (ev_sidebar_page, "main_widget", &widget, NULL);
6083 if (widget != NULL) {
6084 g_signal_connect_object (widget, "focus_in_event",
6085 G_CALLBACK (view_actions_focus_in_cb),
6087 g_signal_connect_object (widget, "focus_out_event",
6088 G_CALLBACK (view_actions_focus_out_cb),
6090 g_object_unref (widget);
6095 window_state_event_cb (EvWindow *window, GdkEventWindowState *event, gpointer dummy)
6097 if (!(event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN)) {
6100 maximized = event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED;
6101 if (window->priv->metadata && !ev_window_is_empty (window))
6102 ev_metadata_set_boolean (window->priv->metadata, "window_maximized", maximized);
6109 window_configure_event_cb (EvWindow *window, GdkEventConfigure *event, gpointer dummy)
6111 GdkWindowState state;
6112 gdouble document_width, document_height;
6114 if (!window->priv->metadata)
6117 state = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (window)));
6119 if (!(state & GDK_WINDOW_STATE_FULLSCREEN)) {
6120 if (window->priv->document) {
6121 ev_document_get_max_page_size (window->priv->document,
6122 &document_width, &document_height);
6123 g_settings_set (window->priv->default_settings, "window-ratio", "(dd)",
6124 (double)event->width / document_width,
6125 (double)event->height / document_height);
6127 ev_metadata_set_int (window->priv->metadata, "window_x", event->x);
6128 ev_metadata_set_int (window->priv->metadata, "window_y", event->y);
6129 ev_metadata_set_int (window->priv->metadata, "window_width", event->width);
6130 ev_metadata_set_int (window->priv->metadata, "window_height", event->height);
6138 launch_action (EvWindow *window, EvLinkAction *action)
6140 const char *filename = ev_link_action_get_filename (action);
6143 GList file_list = {NULL};
6144 GAppLaunchContext *context;
6145 GError *error = NULL;
6147 if (filename == NULL)
6150 if (g_path_is_absolute (filename)) {
6151 file = g_file_new_for_path (filename);
6156 dir = g_path_get_dirname (window->priv->uri);
6157 base_file = g_file_new_for_uri (dir);
6160 file = g_file_resolve_relative_path (base_file, filename);
6161 g_object_unref (base_file);
6164 app_info = g_file_query_default_handler (file, NULL, &error);
6166 ev_window_error_message (window, error,
6168 _("Unable to launch external application."));
6169 g_object_unref (file);
6170 g_error_free (error);
6175 context = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
6176 gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (context),
6177 gtk_window_get_screen (GTK_WINDOW (window)));
6178 gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (context),
6179 gtk_get_current_event_time ());
6181 file_list.data = file;
6182 if (!g_app_info_launch (app_info, &file_list, context, &error)) {
6183 ev_window_error_message (window, error,
6185 _("Unable to launch external application."));
6186 g_error_free (error);
6189 g_object_unref (app_info);
6190 g_object_unref (file);
6191 /* FIXMEchpe: unref launch context? */
6193 /* According to the PDF spec filename can be an executable. I'm not sure
6194 allowing to launch executables is a good idea though. -- marco */
6198 launch_external_uri (EvWindow *window, EvLinkAction *action)
6200 const gchar *uri = ev_link_action_get_uri (action);
6201 GError *error = NULL;
6203 GAppLaunchContext *context;
6205 context = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
6206 gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (context),
6207 gtk_window_get_screen (GTK_WINDOW (window)));
6208 gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (context),
6209 gtk_get_current_event_time ());
6211 if (!g_strstr_len (uri, strlen (uri), "://") &&
6212 !g_str_has_prefix (uri, "mailto:")) {
6215 /* Not a valid uri, assume http if it starts with www */
6216 if (g_str_has_prefix (uri, "www.")) {
6217 new_uri = g_strdup_printf ("http://%s", uri);
6219 GFile *file, *parent;
6221 file = g_file_new_for_uri (window->priv->uri);
6222 parent = g_file_get_parent (file);
6223 g_object_unref (file);
6225 gchar *parent_uri = g_file_get_uri (parent);
6227 new_uri = g_build_filename (parent_uri, uri, NULL);
6228 g_free (parent_uri);
6229 g_object_unref (parent);
6231 new_uri = g_strdup_printf ("file:///%s", uri);
6234 ret = g_app_info_launch_default_for_uri (new_uri, context, &error);
6237 ret = g_app_info_launch_default_for_uri (uri, context, &error);
6241 ev_window_error_message (window, error,
6242 "%s", _("Unable to open external link"));
6243 g_error_free (error);
6246 /* FIXMEchpe: unref launch context? */
6250 open_remote_link (EvWindow *window, EvLinkAction *action)
6255 dir = g_path_get_dirname (window->priv->uri);
6257 uri = g_build_filename (dir, ev_link_action_get_filename (action),
6261 ev_application_open_uri_at_dest (EV_APP, uri,
6262 gtk_window_get_screen (GTK_WINDOW (window)),
6263 ev_link_action_get_dest (action),
6266 gtk_get_current_event_time ());
6272 do_action_named (EvWindow *window, EvLinkAction *action)
6274 const gchar *name = ev_link_action_get_name (action);
6276 if (g_ascii_strcasecmp (name, "FirstPage") == 0) {
6277 ev_window_cmd_go_first_page (NULL, window);
6278 } else if (g_ascii_strcasecmp (name, "PrevPage") == 0) {
6279 ev_window_cmd_go_previous_page (NULL, window);
6280 } else if (g_ascii_strcasecmp (name, "NextPage") == 0) {
6281 ev_window_cmd_go_next_page (NULL, window);
6282 } else if (g_ascii_strcasecmp (name, "LastPage") == 0) {
6283 ev_window_cmd_go_last_page (NULL, window);
6284 } else if (g_ascii_strcasecmp (name, "GoToPage") == 0) {
6285 ev_window_cmd_focus_page_selector (NULL, window);
6286 } else if (g_ascii_strcasecmp (name, "Find") == 0) {
6287 ev_window_cmd_edit_find (NULL, window);
6288 } else if (g_ascii_strcasecmp (name, "Close") == 0) {
6289 ev_window_cmd_file_close_window (NULL, window);
6290 } else if (g_ascii_strcasecmp (name, "Print") == 0) {
6291 ev_window_cmd_file_print (NULL, window);
6293 g_warning ("Unimplemented named action: %s, please post a "
6294 "bug report in Evince bugzilla "
6295 "(http://bugzilla.gnome.org) with a testcase.",
6301 view_external_link_cb (EvWindow *window, EvLinkAction *action)
6303 switch (ev_link_action_get_action_type (action)) {
6304 case EV_LINK_ACTION_TYPE_GOTO_DEST: {
6307 dest = ev_link_action_get_dest (action);
6311 ev_window_open_copy_at_dest (window, dest);
6314 case EV_LINK_ACTION_TYPE_EXTERNAL_URI:
6315 launch_external_uri (window, action);
6317 case EV_LINK_ACTION_TYPE_LAUNCH:
6318 launch_action (window, action);
6320 case EV_LINK_ACTION_TYPE_GOTO_REMOTE:
6321 open_remote_link (window, action);
6323 case EV_LINK_ACTION_TYPE_NAMED:
6324 do_action_named (window, action);
6327 g_assert_not_reached ();
6332 ev_view_popup_cmd_open_link (GtkAction *action, EvWindow *window)
6334 ev_view_handle_link (EV_VIEW (window->priv->view), window->priv->link);
6338 ev_view_popup_cmd_open_link_new_window (GtkAction *action, EvWindow *window)
6340 EvLinkAction *ev_action = NULL;
6343 ev_action = ev_link_get_action (window->priv->link);
6347 dest = ev_link_action_get_dest (ev_action);
6351 ev_window_open_copy_at_dest (window, dest);
6355 ev_view_popup_cmd_copy_link_address (GtkAction *action, EvWindow *window)
6357 EvLinkAction *ev_action;
6359 ev_action = ev_link_get_action (window->priv->link);
6363 ev_view_copy_link_address (EV_VIEW (window->priv->view),
6368 create_file_from_uri_for_format (const gchar *uri,
6369 GdkPixbufFormat *format)
6373 gchar *uri_extension;
6376 extensions = gdk_pixbuf_format_get_extensions (format);
6377 for (i = 0; extensions[i]; i++) {
6378 if (g_str_has_suffix (uri, extensions[i])) {
6379 g_strfreev (extensions);
6380 return g_file_new_for_uri (uri);
6384 uri_extension = g_strconcat (uri, ".", extensions[0], NULL);
6385 target_file = g_file_new_for_uri (uri_extension);
6386 g_free (uri_extension);
6387 g_strfreev (extensions);
6393 image_save_dialog_response_cb (GtkWidget *fc,
6395 EvWindow *ev_window)
6399 GError *error = NULL;
6404 GdkPixbufFormat *format;
6405 GtkFileFilter *filter;
6407 if (response_id != GTK_RESPONSE_OK) {
6408 gtk_widget_destroy (fc);
6412 uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
6413 filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (fc));
6414 format = g_object_get_data (G_OBJECT (filter), "pixbuf-format");
6416 if (format == NULL) {
6417 format = get_gdk_pixbuf_format_by_extension (uri);
6420 if (format == NULL && g_strrstr (uri, ".") == NULL) {
6421 /* no extension found and no extension provided within uri */
6422 format = get_gdk_pixbuf_format_by_extension (".png");
6423 if (format == NULL) {
6424 /* no .png support, try .jpeg */
6425 format = get_gdk_pixbuf_format_by_extension (".jpeg");
6429 if (format == NULL) {
6430 ev_window_error_message (ev_window, NULL,
6432 _("Couldn't find appropriate format to save image"));
6434 gtk_widget_destroy (fc);
6439 target_file = create_file_from_uri_for_format (uri, format);
6442 is_native = g_file_is_native (target_file);
6444 filename = g_file_get_path (target_file);
6446 /* Create a temporary local file to save to */
6447 if (ev_mkstemp ("saveimage.XXXXXX", &filename, &error) == -1)
6451 ev_document_doc_mutex_lock ();
6452 pixbuf = ev_document_images_get_image (EV_DOCUMENT_IMAGES (ev_window->priv->document),
6453 ev_window->priv->image);
6454 ev_document_doc_mutex_unlock ();
6456 file_format = gdk_pixbuf_format_get_name (format);
6457 gdk_pixbuf_save (pixbuf, filename, file_format, &error, NULL);
6458 g_free (file_format);
6459 g_object_unref (pixbuf);
6463 ev_window_error_message (ev_window, error,
6464 "%s", _("The image could not be saved."));
6465 g_error_free (error);
6467 g_object_unref (target_file);
6468 gtk_widget_destroy (fc);
6476 source_file = g_file_new_for_path (filename);
6478 ev_window_save_remote (ev_window, EV_SAVE_IMAGE,
6479 source_file, target_file);
6480 g_object_unref (source_file);
6484 g_object_unref (target_file);
6485 gtk_widget_destroy (fc);
6489 ev_view_popup_cmd_save_image_as (GtkAction *action, EvWindow *window)
6493 if (!window->priv->image)
6496 fc = gtk_file_chooser_dialog_new (_("Save Image"),
6497 GTK_WINDOW (window),
6498 GTK_FILE_CHOOSER_ACTION_SAVE,
6500 GTK_RESPONSE_CANCEL,
6501 GTK_STOCK_SAVE, GTK_RESPONSE_OK,
6504 gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
6505 gtk_dialog_set_alternative_button_order (GTK_DIALOG (fc),
6507 GTK_RESPONSE_CANCEL,
6510 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (fc), FALSE);
6511 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
6513 file_chooser_dialog_add_writable_pixbuf_formats (GTK_FILE_CHOOSER (fc));
6515 g_signal_connect (fc, "response",
6516 G_CALLBACK (image_save_dialog_response_cb),
6519 gtk_widget_show (fc);
6523 ev_view_popup_cmd_copy_image (GtkAction *action, EvWindow *window)
6525 GtkClipboard *clipboard;
6528 if (!window->priv->image)
6531 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (window),
6532 GDK_SELECTION_CLIPBOARD);
6533 ev_document_doc_mutex_lock ();
6534 pixbuf = ev_document_images_get_image (EV_DOCUMENT_IMAGES (window->priv->document),
6535 window->priv->image);
6536 ev_document_doc_mutex_unlock ();
6538 gtk_clipboard_set_image (clipboard, pixbuf);
6539 g_object_unref (pixbuf);
6543 ev_view_popup_cmd_annot_properties (GtkAction *action,
6546 const gchar *author;
6549 gboolean popup_is_open;
6550 EvAnnotationPropertiesDialog *dialog;
6551 EvAnnotation *annot = window->priv->annot;
6552 EvAnnotationsSaveMask mask = EV_ANNOTATIONS_SAVE_NONE;
6557 dialog = EV_ANNOTATION_PROPERTIES_DIALOG (ev_annotation_properties_dialog_new_with_annotation (window->priv->annot));
6558 if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_APPLY) {
6559 gtk_widget_destroy (GTK_WIDGET (dialog));
6564 /* Set annotations changes */
6565 author = ev_annotation_properties_dialog_get_author (dialog);
6566 if (ev_annotation_markup_set_label (EV_ANNOTATION_MARKUP (annot), author))
6567 mask |= EV_ANNOTATIONS_SAVE_LABEL;
6569 ev_annotation_properties_dialog_get_color (dialog, &color);
6570 if (ev_annotation_set_color (annot, &color))
6571 mask |= EV_ANNOTATIONS_SAVE_COLOR;
6573 opacity = ev_annotation_properties_dialog_get_opacity (dialog);
6574 if (ev_annotation_markup_set_opacity (EV_ANNOTATION_MARKUP (annot), opacity))
6575 mask |= EV_ANNOTATIONS_SAVE_OPACITY;
6577 popup_is_open = ev_annotation_properties_dialog_get_popup_is_open (dialog);
6578 if (ev_annotation_markup_set_popup_is_open (EV_ANNOTATION_MARKUP (annot), popup_is_open))
6579 mask |= EV_ANNOTATIONS_SAVE_POPUP_IS_OPEN;
6581 if (EV_IS_ANNOTATION_TEXT (annot)) {
6582 EvAnnotationTextIcon icon;
6584 icon = ev_annotation_properties_dialog_get_text_icon (dialog);
6585 if (ev_annotation_text_set_icon (EV_ANNOTATION_TEXT (annot), icon))
6586 mask |= EV_ANNOTATIONS_SAVE_TEXT_ICON;
6589 if (mask != EV_ANNOTATIONS_SAVE_NONE) {
6590 ev_document_doc_mutex_lock ();
6591 ev_document_annotations_save_annotation (EV_DOCUMENT_ANNOTATIONS (window->priv->document),
6592 window->priv->annot,
6594 ev_document_doc_mutex_unlock ();
6596 /* FIXME: update annot region only */
6597 ev_view_reload (EV_VIEW (window->priv->view));
6600 gtk_widget_destroy (GTK_WIDGET (dialog));
6604 ev_attachment_popup_cmd_open_attachment (GtkAction *action, EvWindow *window)
6609 if (!window->priv->attach_list)
6612 screen = gtk_window_get_screen (GTK_WINDOW (window));
6614 for (l = window->priv->attach_list; l && l->data; l = g_list_next (l)) {
6615 EvAttachment *attachment;
6616 GError *error = NULL;
6618 attachment = (EvAttachment *) l->data;
6620 ev_attachment_open (attachment, screen, gtk_get_current_event_time (), &error);
6623 ev_window_error_message (window, error,
6624 "%s", _("Unable to open attachment"));
6625 g_error_free (error);
6631 attachment_save_dialog_response_cb (GtkWidget *fc,
6633 EvWindow *ev_window)
6638 GtkFileChooserAction fc_action;
6642 if (response_id != GTK_RESPONSE_OK) {
6643 gtk_widget_destroy (fc);
6647 uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
6648 target_file = g_file_new_for_uri (uri);
6649 g_object_get (G_OBJECT (fc), "action", &fc_action, NULL);
6650 is_dir = (fc_action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
6651 is_native = g_file_is_native (target_file);
6653 for (l = ev_window->priv->attach_list; l && l->data; l = g_list_next (l)) {
6654 EvAttachment *attachment;
6655 GFile *save_to = NULL;
6656 GError *error = NULL;
6658 attachment = (EvAttachment *) l->data;
6662 save_to = g_file_get_child (target_file,
6663 /* FIXMEchpe: file name encoding! */
6664 ev_attachment_get_name (attachment));
6666 save_to = g_object_ref (target_file);
6669 save_to = ev_mkstemp_file ("saveattachment.XXXXXX", &error);
6673 ev_attachment_save (attachment, save_to, &error);
6676 ev_window_error_message (ev_window, error,
6677 "%s", _("The attachment could not be saved."));
6678 g_error_free (error);
6679 g_object_unref (save_to);
6688 dest_file = g_file_get_child (target_file,
6689 ev_attachment_get_name (attachment));
6691 dest_file = g_object_ref (target_file);
6694 ev_window_save_remote (ev_window, EV_SAVE_ATTACHMENT,
6695 save_to, dest_file);
6697 g_object_unref (dest_file);
6700 g_object_unref (save_to);
6704 g_object_unref (target_file);
6706 gtk_widget_destroy (fc);
6710 ev_attachment_popup_cmd_save_attachment_as (GtkAction *action, EvWindow *window)
6713 EvAttachment *attachment = NULL;
6715 if (!window->priv->attach_list)
6718 if (g_list_length (window->priv->attach_list) == 1)
6719 attachment = (EvAttachment *) window->priv->attach_list->data;
6721 fc = gtk_file_chooser_dialog_new (
6722 _("Save Attachment"),
6723 GTK_WINDOW (window),
6724 attachment ? GTK_FILE_CHOOSER_ACTION_SAVE : GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
6726 GTK_RESPONSE_CANCEL,
6727 GTK_STOCK_SAVE, GTK_RESPONSE_OK,
6730 gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
6731 gtk_dialog_set_alternative_button_order (GTK_DIALOG (fc),
6733 GTK_RESPONSE_CANCEL,
6736 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
6737 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (fc), FALSE);
6740 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc),
6741 ev_attachment_get_name (attachment));
6743 g_signal_connect (fc, "response",
6744 G_CALLBACK (attachment_save_dialog_response_cb),
6747 gtk_widget_show (fc);
6751 ev_window_media_player_key_pressed (EvWindow *window,
6755 if (!gtk_window_is_active (GTK_WINDOW (window)))
6758 /* Note how Previous/Next only go to the
6759 * next/previous page despite their icon telling you
6760 * they should go to the beginning/end.
6762 * There's very few keyboards with FFW/RWD though,
6763 * so we stick the most useful keybinding on the most
6766 if (strcmp (key, "Play") == 0) {
6767 ev_window_run_presentation (window);
6768 } else if (strcmp (key, "Previous") == 0) {
6769 if (EV_WINDOW_IS_PRESENTATION (window))
6770 ev_view_presentation_previous_page (EV_VIEW_PRESENTATION (window->priv->presentation_view));
6772 ev_window_cmd_go_previous_page (NULL, window);
6773 } else if (strcmp (key, "Next") == 0) {
6774 if (EV_WINDOW_IS_PRESENTATION (window))
6775 ev_view_presentation_next_page (EV_VIEW_PRESENTATION (window->priv->presentation_view));
6777 ev_window_cmd_go_next_page (NULL, window);
6778 } else if (strcmp (key, "FastForward") == 0) {
6779 ev_window_cmd_go_last_page (NULL, window);
6780 } else if (strcmp (key, "Rewind") == 0) {
6781 ev_window_cmd_go_first_page (NULL, window);
6785 static EggToolbarsModel *
6786 get_toolbars_model (void)
6788 EggToolbarsModel *toolbars_model;
6789 gchar *toolbars_file;
6790 gchar *toolbars_path;
6793 toolbars_model = egg_toolbars_model_new ();
6795 toolbars_file = g_build_filename (ev_application_get_dot_dir (EV_APP, FALSE),
6796 "evince_toolbar.xml", NULL);
6797 toolbars_path = g_build_filename (ev_application_get_data_dir (EV_APP),
6798 "evince-toolbar.xml", NULL);
6799 egg_toolbars_model_load_names (toolbars_model, toolbars_path);
6801 if (!egg_toolbars_model_load_toolbars (toolbars_model, toolbars_file)) {
6802 egg_toolbars_model_load_toolbars (toolbars_model, toolbars_path);
6803 goto skip_conversion;
6806 /* Open item doesn't exist anymore,
6807 * convert it to OpenRecent for compatibility
6809 for (i = 0; i < egg_toolbars_model_n_items (toolbars_model, 0); i++) {
6812 item = egg_toolbars_model_item_nth (toolbars_model, 0, i);
6813 if (g_ascii_strcasecmp (item, "FileOpen") == 0) {
6814 egg_toolbars_model_remove_item (toolbars_model, 0, i);
6815 egg_toolbars_model_add_item (toolbars_model, 0, i,
6817 egg_toolbars_model_save_toolbars (toolbars_model, toolbars_file, "1.0");
6823 g_free (toolbars_file);
6824 g_free (toolbars_path);
6826 egg_toolbars_model_set_flags (toolbars_model, 0, EGG_TB_MODEL_NOT_REMOVABLE);
6828 return toolbars_model;
6833 ev_window_sync_source (EvWindow *window,
6836 GDBusConnection *connection;
6837 GError *error = NULL;
6842 if (window->priv->dbus_object_id <= 0)
6845 connection = ev_application_get_dbus_connection (EV_APP);
6849 timestamp = gtk_get_current_event_time ();
6850 if (g_path_is_absolute (link->filename)) {
6851 input_gfile = g_file_new_for_path (link->filename);
6853 GFile *gfile, *parent_gfile;
6855 gfile = g_file_new_for_uri (window->priv->uri);
6856 parent_gfile = g_file_get_parent (gfile);
6858 /* parent_gfile should never be NULL */
6859 if (parent_gfile == NULL) {
6860 g_printerr ("Document URI is '/'\n");
6864 input_gfile = g_file_get_child (parent_gfile, link->filename);
6865 g_object_unref (parent_gfile);
6866 g_object_unref (gfile);
6869 uri_input = g_file_get_uri (input_gfile);
6870 g_object_unref (input_gfile);
6872 g_dbus_connection_emit_signal (connection,
6874 window->priv->dbus_object_path,
6875 EV_WINDOW_DBUS_INTERFACE,
6877 g_variant_new ("(s(ii)u)",
6885 g_printerr ("Failed to emit DBus signal SyncSource: %s\n",
6887 g_error_free (error);
6892 ev_window_emit_closed (EvWindow *window)
6894 GDBusConnection *connection;
6895 GError *error = NULL;
6897 if (window->priv->dbus_object_id <= 0)
6900 connection = ev_application_get_dbus_connection (EV_APP);
6904 g_dbus_connection_emit_signal (connection,
6906 window->priv->dbus_object_path,
6907 EV_WINDOW_DBUS_INTERFACE,
6912 g_printerr ("Failed to emit DBus signal Closed: %s\n",
6914 g_error_free (error);
6919 /* If this is the last window call g_dbus_connection_flush_sync()
6920 * to make sure the signal is emitted.
6922 if (ev_application_get_n_windows (EV_APP) == 1)
6923 g_dbus_connection_flush_sync (connection, NULL, NULL);
6927 ev_window_emit_doc_loaded (EvWindow *window)
6929 GDBusConnection *connection;
6930 GError *error = NULL;
6932 if (window->priv->dbus_object_id <= 0)
6935 connection = ev_application_get_dbus_connection (EV_APP);
6939 g_dbus_connection_emit_signal (connection,
6941 window->priv->dbus_object_path,
6942 EV_WINDOW_DBUS_INTERFACE,
6944 g_variant_new("(s)", window->priv->uri),
6947 g_printerr ("Failed to emit DBus signal DocumentLoaded: %s\n",
6949 g_error_free (error);
6956 method_call_cb (GDBusConnection *connection,
6957 const gchar *sender,
6958 const gchar *object_path,
6959 const gchar *interface_name,
6960 const gchar *method_name,
6961 GVariant *parameters,
6962 GDBusMethodInvocation *invocation,
6965 EvWindow *window = EV_WINDOW (user_data);
6967 if (g_strcmp0 (method_name, "SyncView") != 0)
6970 if (window->priv->document && ev_document_has_synctex (window->priv->document)) {
6974 g_variant_get (parameters, "(&s(ii)u)", &link.filename, &link.line, &link.col, ×tamp);
6975 ev_view_highlight_forward_search (EV_VIEW (window->priv->view), &link);
6976 gtk_window_present_with_time (GTK_WINDOW (window), timestamp);
6979 g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
6982 static const char introspection_xml[] =
6984 "<interface name='org.gnome.evince.Window'>"
6985 "<method name='SyncView'>"
6986 "<arg type='s' name='source_file' direction='in'/>"
6987 "<arg type='(ii)' name='source_point' direction='in'/>"
6988 "<arg type='u' name='timestamp' direction='in'/>"
6990 "<signal name='SyncSource'>"
6991 "<arg type='s' name='source_file' direction='out'/>"
6992 "<arg type='(ii)' name='source_point' direction='out'/>"
6993 "<arg type='u' name='timestamp' direction='out'/>"
6995 "<signal name='Closed'/>"
6996 "<signal name='DocumentLoaded'>"
6997 "<arg type='s' name='uri' direction='out'/>"
7002 static const GDBusInterfaceVTable interface_vtable = {
7008 static GDBusNodeInfo *introspection_data;
7009 #endif /* ENABLE_DBUS */
7012 ev_window_init (EvWindow *ev_window)
7014 GtkActionGroup *action_group;
7015 GtkAccelGroup *accel_group;
7016 GError *error = NULL;
7017 GtkWidget *sidebar_widget;
7018 GtkWidget *menuitem;
7019 EggToolbarsModel *toolbars_model;
7023 GDBusConnection *connection;
7024 static gint window_id = 0;
7027 g_signal_connect (ev_window, "configure_event",
7028 G_CALLBACK (window_configure_event_cb), NULL);
7029 g_signal_connect (ev_window, "window_state_event",
7030 G_CALLBACK (window_state_event_cb), NULL);
7032 ev_window->priv = EV_WINDOW_GET_PRIVATE (ev_window);
7035 connection = ev_application_get_dbus_connection (EV_APP);
7037 if (!introspection_data) {
7038 introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, &error);
7039 if (error) g_warning ("%s\n", error->message);
7041 g_assert (introspection_data != NULL);
7043 ev_window->priv->dbus_object_path = g_strdup_printf (EV_WINDOW_DBUS_OBJECT_PATH, window_id++);
7044 ev_window->priv->dbus_object_id =
7045 g_dbus_connection_register_object (connection,
7046 ev_window->priv->dbus_object_path,
7047 introspection_data->interfaces[0],
7051 if (ev_window->priv->dbus_object_id == 0) {
7052 g_printerr ("Failed to register bus object %s: %s\n",
7053 ev_window->priv->dbus_object_path, error->message);
7054 g_error_free (error);
7055 g_free (ev_window->priv->dbus_object_path);
7056 ev_window->priv->dbus_object_path = NULL;
7061 #endif /* ENABLE_DBUS */
7063 ev_window->priv->model = ev_document_model_new ();
7065 ev_window->priv->page_mode = PAGE_MODE_DOCUMENT;
7066 ev_window->priv->title = ev_window_title_new (ev_window);
7068 ev_window->priv->main_box = gtk_vbox_new (FALSE, 0);
7069 gtk_container_add (GTK_CONTAINER (ev_window), ev_window->priv->main_box);
7070 gtk_widget_show (ev_window->priv->main_box);
7072 action_group = gtk_action_group_new ("MenuActions");
7073 ev_window->priv->action_group = action_group;
7074 gtk_action_group_set_translation_domain (action_group, NULL);
7075 gtk_action_group_add_actions (action_group, entries,
7076 G_N_ELEMENTS (entries), ev_window);
7077 gtk_action_group_add_toggle_actions (action_group, toggle_entries,
7078 G_N_ELEMENTS (toggle_entries),
7080 set_action_properties (action_group);
7081 register_custom_actions (ev_window, action_group);
7083 ev_window->priv->ui_manager = gtk_ui_manager_new ();
7084 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
7088 gtk_ui_manager_get_accel_group (ev_window->priv->ui_manager);
7089 gtk_window_add_accel_group (GTK_WINDOW (ev_window), accel_group);
7091 ev_window_set_view_accels_sensitivity (ev_window, FALSE);
7093 action_group = gtk_action_group_new ("ViewPopupActions");
7094 ev_window->priv->view_popup_action_group = action_group;
7095 gtk_action_group_set_translation_domain (action_group, NULL);
7096 gtk_action_group_add_actions (action_group, view_popup_entries,
7097 G_N_ELEMENTS (view_popup_entries),
7099 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
7102 action_group = gtk_action_group_new ("AttachmentPopupActions");
7103 ev_window->priv->attachment_popup_action_group = action_group;
7104 gtk_action_group_set_translation_domain (action_group, NULL);
7105 gtk_action_group_add_actions (action_group, attachment_popup_entries,
7106 G_N_ELEMENTS (attachment_popup_entries),
7108 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
7111 ui_path = g_build_filename (ev_application_get_data_dir (EV_APP),
7112 "evince-ui.xml", NULL);
7113 if (!gtk_ui_manager_add_ui_from_file (
7114 ev_window->priv->ui_manager, ui_path, &error))
7116 g_warning ("building menus failed: %s", error->message);
7117 g_error_free (error);
7121 ev_window->priv->recent_manager = gtk_recent_manager_get_default ();
7122 ev_window->priv->recent_action_group = NULL;
7123 ev_window->priv->recent_ui_id = 0;
7124 g_signal_connect_swapped (ev_window->priv->recent_manager,
7126 G_CALLBACK (ev_window_setup_recent),
7129 ev_window->priv->menubar =
7130 gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
7132 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box),
7133 ev_window->priv->menubar,
7135 menuitem = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
7136 "/MainMenu/EditMenu/EditRotateLeftMenu");
7137 gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menuitem), TRUE);
7138 menuitem = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
7139 "/MainMenu/EditMenu/EditRotateRightMenu");
7140 gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menuitem), TRUE);
7142 toolbars_model = get_toolbars_model ();
7143 ev_window->priv->toolbar = GTK_WIDGET
7144 (g_object_new (EGG_TYPE_EDITABLE_TOOLBAR,
7145 "ui-manager", ev_window->priv->ui_manager,
7146 "popup-path", "/ToolbarPopup",
7147 "model", toolbars_model,
7149 g_object_unref (toolbars_model);
7151 gtk_style_context_add_class
7152 (gtk_widget_get_style_context (GTK_WIDGET (ev_window->priv->toolbar)),
7153 GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
7155 egg_editable_toolbar_show (EGG_EDITABLE_TOOLBAR (ev_window->priv->toolbar),
7157 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box),
7158 ev_window->priv->toolbar,
7160 gtk_widget_show (ev_window->priv->toolbar);
7162 /* Add the main area */
7163 ev_window->priv->hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
7164 g_signal_connect (ev_window->priv->hpaned,
7166 G_CALLBACK (ev_window_sidebar_position_change_cb),
7169 gtk_paned_set_position (GTK_PANED (ev_window->priv->hpaned), SIDEBAR_DEFAULT_SIZE);
7170 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), ev_window->priv->hpaned,
7172 gtk_widget_show (ev_window->priv->hpaned);
7174 ev_window->priv->sidebar = ev_sidebar_new ();
7175 ev_sidebar_set_model (EV_SIDEBAR (ev_window->priv->sidebar),
7176 ev_window->priv->model);
7177 gtk_paned_pack1 (GTK_PANED (ev_window->priv->hpaned),
7178 ev_window->priv->sidebar, FALSE, FALSE);
7179 gtk_widget_show (ev_window->priv->sidebar);
7181 /* Stub sidebar, for now */
7183 sidebar_widget = ev_sidebar_thumbnails_new ();
7184 ev_window->priv->sidebar_thumbs = sidebar_widget;
7185 g_signal_connect (sidebar_widget,
7186 "notify::main-widget",
7187 G_CALLBACK (sidebar_page_main_widget_update_cb),
7189 sidebar_page_main_widget_update_cb (G_OBJECT (sidebar_widget), NULL, ev_window);
7190 gtk_widget_show (sidebar_widget);
7191 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7194 sidebar_widget = ev_sidebar_links_new ();
7195 ev_window->priv->sidebar_links = sidebar_widget;
7196 g_signal_connect (sidebar_widget,
7198 G_CALLBACK (sidebar_widget_model_set),
7200 g_signal_connect (sidebar_widget,
7202 G_CALLBACK (sidebar_links_link_activated_cb),
7204 sidebar_page_main_widget_update_cb (G_OBJECT (sidebar_widget), NULL, ev_window);
7205 gtk_widget_show (sidebar_widget);
7206 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7209 sidebar_widget = ev_sidebar_attachments_new ();
7210 ev_window->priv->sidebar_attachments = sidebar_widget;
7211 g_signal_connect_object (sidebar_widget,
7213 G_CALLBACK (attachment_bar_menu_popup_cb),
7215 gtk_widget_show (sidebar_widget);
7216 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7219 sidebar_widget = ev_sidebar_layers_new ();
7220 ev_window->priv->sidebar_layers = sidebar_widget;
7221 g_signal_connect (sidebar_widget,
7222 "layers_visibility_changed",
7223 G_CALLBACK (sidebar_layers_visibility_changed),
7225 gtk_widget_show (sidebar_widget);
7226 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7229 sidebar_widget = ev_sidebar_annotations_new ();
7230 ev_window->priv->sidebar_annots = sidebar_widget;
7231 g_signal_connect (sidebar_widget,
7233 G_CALLBACK (sidebar_annots_annot_activated_cb),
7235 g_signal_connect (sidebar_widget,
7237 G_CALLBACK (sidebar_annots_begin_annot_add),
7239 g_signal_connect (sidebar_widget,
7240 "annot_add_cancelled",
7241 G_CALLBACK (sidebar_annots_annot_add_cancelled),
7243 gtk_widget_show (sidebar_widget);
7244 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7247 sidebar_widget = ev_sidebar_bookmarks_new ();
7248 ev_window->priv->sidebar_bookmarks = sidebar_widget;
7249 g_signal_connect (sidebar_widget,
7251 G_CALLBACK (sidebar_bookmarks_add_bookmark),
7253 gtk_widget_show (sidebar_widget);
7254 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7257 ev_window->priv->view_box = gtk_vbox_new (FALSE, 0);
7258 ev_window->priv->scrolled_window =
7259 GTK_WIDGET (g_object_new (GTK_TYPE_SCROLLED_WINDOW,
7260 "shadow-type", GTK_SHADOW_IN,
7262 gtk_box_pack_start (GTK_BOX (ev_window->priv->view_box),
7263 ev_window->priv->scrolled_window,
7265 gtk_widget_show (ev_window->priv->scrolled_window);
7267 gtk_paned_add2 (GTK_PANED (ev_window->priv->hpaned),
7268 ev_window->priv->view_box);
7269 gtk_widget_show (ev_window->priv->view_box);
7271 ev_window->priv->view = ev_view_new ();
7272 ev_view_set_page_cache_size (EV_VIEW (ev_window->priv->view), PAGE_CACHE_SIZE);
7273 ev_view_set_model (EV_VIEW (ev_window->priv->view), ev_window->priv->model);
7275 ev_window->priv->password_view = ev_password_view_new (GTK_WINDOW (ev_window));
7276 g_signal_connect_swapped (ev_window->priv->password_view,
7278 G_CALLBACK (ev_window_password_view_unlock),
7280 g_signal_connect_object (ev_window->priv->view, "focus_in_event",
7281 G_CALLBACK (view_actions_focus_in_cb),
7283 g_signal_connect_object (ev_window->priv->view, "focus_out_event",
7284 G_CALLBACK (view_actions_focus_out_cb),
7286 g_signal_connect_swapped (ev_window->priv->view, "external-link",
7287 G_CALLBACK (view_external_link_cb),
7289 g_signal_connect_object (ev_window->priv->view, "handle-link",
7290 G_CALLBACK (view_handle_link_cb),
7292 g_signal_connect_object (ev_window->priv->view, "popup",
7293 G_CALLBACK (view_menu_popup_cb),
7295 g_signal_connect_object (ev_window->priv->view, "selection-changed",
7296 G_CALLBACK (view_selection_changed_cb),
7298 g_signal_connect_object (ev_window->priv->view, "annot-added",
7299 G_CALLBACK (view_annot_added),
7301 g_signal_connect_object (ev_window->priv->view, "layers-changed",
7302 G_CALLBACK (view_layers_changed_cb),
7305 g_signal_connect_swapped (ev_window->priv->view, "sync-source",
7306 G_CALLBACK (ev_window_sync_source),
7309 gtk_widget_show (ev_window->priv->view);
7310 gtk_widget_show (ev_window->priv->password_view);
7313 ev_window->priv->find_bar = egg_find_bar_new ();
7314 gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
7315 ev_window->priv->find_bar,
7318 /* We own a ref on these widgets, as we can swap them in and out */
7319 g_object_ref (ev_window->priv->view);
7320 g_object_ref (ev_window->priv->password_view);
7322 gtk_container_add (GTK_CONTAINER (ev_window->priv->scrolled_window),
7323 ev_window->priv->view);
7325 /* Connect to model signals */
7326 g_signal_connect_swapped (ev_window->priv->model,
7328 G_CALLBACK (ev_window_page_changed_cb),
7330 g_signal_connect (ev_window->priv->model,
7332 G_CALLBACK (ev_window_document_changed_cb),
7334 g_signal_connect (ev_window->priv->model,
7336 G_CALLBACK (ev_window_zoom_changed_cb),
7338 g_signal_connect (ev_window->priv->model,
7339 "notify::sizing-mode",
7340 G_CALLBACK (ev_window_sizing_mode_changed_cb),
7342 g_signal_connect (ev_window->priv->model,
7344 G_CALLBACK (ev_window_rotation_changed_cb),
7346 g_signal_connect (ev_window->priv->model,
7347 "notify::continuous",
7348 G_CALLBACK (ev_window_continuous_changed_cb),
7350 g_signal_connect (ev_window->priv->model,
7351 "notify::dual-page",
7352 G_CALLBACK (ev_window_dual_mode_changed_cb),
7354 g_signal_connect (ev_window->priv->model,
7355 "notify::inverted-colors",
7356 G_CALLBACK (ev_window_inverted_colors_changed_cb),
7359 /* Connect sidebar signals */
7360 g_signal_connect (ev_window->priv->sidebar,
7362 G_CALLBACK (ev_window_sidebar_visibility_changed_cb),
7364 g_signal_connect (ev_window->priv->sidebar,
7365 "notify::current-page",
7366 G_CALLBACK (ev_window_sidebar_current_page_changed_cb),
7369 /* Connect to find bar signals */
7370 g_signal_connect (ev_window->priv->find_bar,
7372 G_CALLBACK (find_bar_previous_cb),
7374 g_signal_connect (ev_window->priv->find_bar,
7376 G_CALLBACK (find_bar_next_cb),
7378 g_signal_connect (ev_window->priv->find_bar,
7380 G_CALLBACK (find_bar_close_cb),
7382 g_signal_connect (ev_window->priv->find_bar,
7383 "notify::search-string",
7384 G_CALLBACK (find_bar_search_changed_cb),
7386 g_signal_connect (ev_window->priv->find_bar,
7387 "notify::case-sensitive",
7388 G_CALLBACK (find_bar_search_changed_cb),
7390 g_signal_connect (ev_window->priv->find_bar,
7392 G_CALLBACK (find_bar_visibility_changed_cb),
7394 g_signal_connect (ev_window->priv->find_bar,
7396 G_CALLBACK (find_bar_scroll),
7400 ev_window->priv->view_popup = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
7402 ev_window->priv->link = NULL;
7404 ev_window->priv->attachment_popup = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
7405 "/AttachmentPopup");
7406 ev_window->priv->attach_list = NULL;
7408 /* Media player keys */
7409 mpkeys = ev_application_get_media_keys (EV_APP);
7411 g_signal_connect_swapped (mpkeys, "key_pressed",
7412 G_CALLBACK (ev_window_media_player_key_pressed),
7416 /* Give focus to the document view */
7417 gtk_widget_grab_focus (ev_window->priv->view);
7419 ev_window->priv->default_settings = g_settings_new (GS_SCHEMA_NAME".Default");
7420 g_settings_delay (ev_window->priv->default_settings);
7422 /* Set it user interface params */
7423 ev_window_setup_recent (ev_window);
7425 ev_window_setup_gtk_settings (ev_window);
7427 setup_chrome_from_metadata (ev_window);
7428 update_chrome_actions (ev_window);
7429 update_chrome_visibility (ev_window);
7431 gtk_window_set_default_size (GTK_WINDOW (ev_window), 600, 600);
7433 setup_view_from_metadata (ev_window);
7434 setup_sidebar_from_metadata (ev_window);
7436 ev_window_sizing_mode_changed_cb (ev_window->priv->model, NULL, ev_window);
7437 ev_window_setup_action_sensitivity (ev_window);
7440 gtk_drag_dest_set (GTK_WIDGET (ev_window),
7441 GTK_DEST_DEFAULT_ALL,
7444 gtk_drag_dest_add_uri_targets (GTK_WIDGET (ev_window));
7450 * Creates a #GtkWidget that represents the window.
7452 * Returns: the #GtkWidget that represents the window.
7455 ev_window_new (void)
7457 GtkWidget *ev_window;
7459 ev_window = GTK_WIDGET (g_object_new (EV_TYPE_WINDOW,
7460 "type", GTK_WINDOW_TOPLEVEL,
7467 ev_window_get_dbus_object_path (EvWindow *ev_window)
7470 return ev_window->priv->dbus_object_path;