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_set_action_sensitive (EvWindow *ev_window,
378 GtkAction *action = gtk_action_group_get_action (ev_window->priv->action_group,
380 gtk_action_set_sensitive (action, sensitive);
385 ev_window_setup_action_sensitivity (EvWindow *ev_window)
387 EvDocument *document = ev_window->priv->document;
388 const EvDocumentInfo *info = NULL;
389 gboolean has_document = FALSE;
390 gboolean ok_to_print = TRUE;
391 gboolean ok_to_copy = TRUE;
392 gboolean has_properties = TRUE;
393 gboolean override_restrictions = TRUE;
394 gboolean can_get_text = FALSE;
395 gboolean has_pages = FALSE;
396 gboolean can_find = FALSE;
400 has_pages = ev_document_get_n_pages (document) > 0;
401 info = ev_document_get_info (document);
404 if (!info || info->fields_mask == 0) {
405 has_properties = FALSE;
408 if (has_document && EV_IS_SELECTION (document)) {
412 if (has_pages && EV_IS_DOCUMENT_FIND (document)) {
416 if (has_document && ev_window->priv->settings) {
417 override_restrictions =
418 g_settings_get_boolean (ev_window->priv->settings,
419 GS_OVERRIDE_RESTRICTIONS);
422 if (!override_restrictions && info && info->fields_mask & EV_DOCUMENT_INFO_PERMISSIONS) {
423 ok_to_print = (info->permissions & EV_DOCUMENT_PERMISSIONS_OK_TO_PRINT);
424 ok_to_copy = (info->permissions & EV_DOCUMENT_PERMISSIONS_OK_TO_COPY);
427 if (has_document && !ev_print_operation_exists_for_document(document))
430 if (has_document && ev_window->priv->lockdown_settings &&
431 g_settings_get_boolean (ev_window->priv->lockdown_settings, GS_LOCKDOWN_SAVE)) {
435 if (has_document && ev_window->priv->lockdown_settings &&
436 g_settings_get_boolean (ev_window->priv->lockdown_settings, GS_LOCKDOWN_PRINT)) {
441 ev_window_set_action_sensitive (ev_window, "FileOpenCopy", has_document);
442 ev_window_set_action_sensitive (ev_window, "FileSaveAs", has_document && ok_to_copy);
443 ev_window_set_action_sensitive (ev_window, "FilePrint", has_pages && ok_to_print);
444 ev_window_set_action_sensitive (ev_window, "FileProperties", has_document && has_properties);
447 ev_window_set_action_sensitive (ev_window, "EditSelectAll", has_pages && can_get_text);
448 ev_window_set_action_sensitive (ev_window, "EditFind", can_find);
449 ev_window_set_action_sensitive (ev_window, "Slash", can_find);
450 ev_window_set_action_sensitive (ev_window, "EditRotateLeft", has_pages);
451 ev_window_set_action_sensitive (ev_window, "EditRotateRight", has_pages);
454 ev_window_set_action_sensitive (ev_window, "ViewContinuous", has_pages);
455 ev_window_set_action_sensitive (ev_window, "ViewDual", has_pages);
456 ev_window_set_action_sensitive (ev_window, "ViewBestFit", has_pages);
457 ev_window_set_action_sensitive (ev_window, "ViewPageWidth", has_pages);
458 ev_window_set_action_sensitive (ev_window, "ViewReload", has_pages);
459 ev_window_set_action_sensitive (ev_window, "ViewAutoscroll", has_pages);
460 ev_window_set_action_sensitive (ev_window, "ViewInvertedColors", has_pages);
463 ev_window_set_action_sensitive (ev_window, "BookmarksAdd",
464 has_pages && ev_window->priv->bookmarks);
466 /* Toolbar-specific actions: */
467 ev_window_set_action_sensitive (ev_window, PAGE_SELECTOR_ACTION, has_pages);
468 ev_window_set_action_sensitive (ev_window, ZOOM_CONTROL_ACTION, has_pages);
469 ev_window_set_action_sensitive (ev_window, NAVIGATION_ACTION, FALSE);
471 ev_window_update_actions (ev_window);
475 ev_window_update_actions (EvWindow *ev_window)
477 EvView *view = EV_VIEW (ev_window->priv->view);
478 int n_pages = 0, page = -1;
479 gboolean has_pages = FALSE;
480 gboolean presentation_mode;
481 gboolean can_find_in_page = FALSE;
482 EvSizingMode sizing_mode;
484 if (ev_window->priv->document) {
485 page = ev_document_model_get_page (ev_window->priv->model);
486 n_pages = ev_document_get_n_pages (ev_window->priv->document);
487 has_pages = n_pages > 0;
490 can_find_in_page = (ev_window->priv->find_job &&
491 ev_job_find_has_results (EV_JOB_FIND (ev_window->priv->find_job)));
493 ev_window_set_action_sensitive (ev_window, "EditCopy",
495 ev_view_get_has_selection (view));
496 ev_window_set_action_sensitive (ev_window, "EditFindNext",
497 has_pages && can_find_in_page);
498 ev_window_set_action_sensitive (ev_window, "EditFindPrevious",
499 has_pages && can_find_in_page);
500 ev_window_set_action_sensitive (ev_window, "F3",
501 has_pages && can_find_in_page);
503 presentation_mode = EV_WINDOW_IS_PRESENTATION (ev_window);
505 ev_window_set_action_sensitive (ev_window, "ViewZoomIn",
507 ev_view_can_zoom_in (view) &&
509 ev_window_set_action_sensitive (ev_window, "ViewZoomOut",
511 ev_view_can_zoom_out (view) &&
516 ev_window_set_action_sensitive (ev_window, "GoPreviousPage", page > 0);
517 ev_window_set_action_sensitive (ev_window, "GoNextPage", page < n_pages - 1);
518 ev_window_set_action_sensitive (ev_window, "GoFirstPage", page > 0);
519 ev_window_set_action_sensitive (ev_window, "GoLastPage", page < n_pages - 1);
521 ev_window_set_action_sensitive (ev_window, "GoFirstPage", FALSE);
522 ev_window_set_action_sensitive (ev_window, "GoPreviousPage", FALSE);
523 ev_window_set_action_sensitive (ev_window, "GoNextPage", FALSE);
524 ev_window_set_action_sensitive (ev_window, "GoLastPage", FALSE);
527 sizing_mode = ev_document_model_get_sizing_mode (ev_window->priv->model);
528 if (has_pages && sizing_mode != EV_SIZING_FIT_WIDTH && sizing_mode != EV_SIZING_BEST_FIT) {
533 action = gtk_action_group_get_action (ev_window->priv->action_group,
534 ZOOM_CONTROL_ACTION);
536 real_zoom = ev_document_model_get_scale (ev_window->priv->model);
537 real_zoom *= 72.0 / get_screen_dpi (ev_window);
538 zoom = ephy_zoom_get_nearest_zoom_level (real_zoom);
540 ephy_zoom_action_set_zoom_level (EPHY_ZOOM_ACTION (action), zoom);
545 ev_window_set_view_accels_sensitivity (EvWindow *window, gboolean sensitive)
549 can_find = window->priv->document &&
550 EV_IS_DOCUMENT_FIND (window->priv->document);
552 if (window->priv->action_group) {
553 ev_window_set_action_sensitive (window, "PageDown", sensitive);
554 ev_window_set_action_sensitive (window, "PageUp", sensitive);
555 ev_window_set_action_sensitive (window, "Space", sensitive);
556 ev_window_set_action_sensitive (window, "ShiftSpace", sensitive);
557 ev_window_set_action_sensitive (window, "BackSpace", sensitive);
558 ev_window_set_action_sensitive (window, "ShiftBackSpace", sensitive);
559 ev_window_set_action_sensitive (window, "Return", sensitive);
560 ev_window_set_action_sensitive (window, "ShiftReturn", sensitive);
561 ev_window_set_action_sensitive (window, "Plus", sensitive);
562 ev_window_set_action_sensitive (window, "Minus", sensitive);
563 ev_window_set_action_sensitive (window, "KpPlus", sensitive);
564 ev_window_set_action_sensitive (window, "KpMinus", sensitive);
565 ev_window_set_action_sensitive (window, "Equal", sensitive);
566 ev_window_set_action_sensitive (window, "p", sensitive);
567 ev_window_set_action_sensitive (window, "n", sensitive);
569 ev_window_set_action_sensitive (window, "Slash", sensitive && can_find);
574 set_widget_visibility (GtkWidget *widget, gboolean visible)
576 g_assert (GTK_IS_WIDGET (widget));
579 gtk_widget_show (widget);
581 gtk_widget_hide (widget);
585 update_chrome_visibility (EvWindow *window)
587 EvWindowPrivate *priv = window->priv;
588 gboolean menubar, toolbar, findbar, fullscreen_toolbar, sidebar;
589 gboolean fullscreen_mode, presentation, fullscreen;
591 presentation = EV_WINDOW_IS_PRESENTATION (window);
592 fullscreen = ev_document_model_get_fullscreen (priv->model);
593 fullscreen_mode = fullscreen || presentation;
595 menubar = (priv->chrome & EV_CHROME_MENUBAR) != 0 && !fullscreen_mode;
596 toolbar = ((priv->chrome & EV_CHROME_TOOLBAR) != 0 ||
597 (priv->chrome & EV_CHROME_RAISE_TOOLBAR) != 0) && !fullscreen_mode;
598 fullscreen_toolbar = ((priv->chrome & EV_CHROME_FULLSCREEN_TOOLBAR) != 0 ||
599 (priv->chrome & EV_CHROME_RAISE_TOOLBAR) != 0) && fullscreen;
600 findbar = (priv->chrome & EV_CHROME_FINDBAR) != 0;
601 sidebar = (priv->chrome & EV_CHROME_SIDEBAR) != 0 && priv->document && !presentation;
603 set_widget_visibility (priv->menubar, menubar);
604 set_widget_visibility (priv->toolbar, toolbar);
605 set_widget_visibility (priv->find_bar, findbar);
606 set_widget_visibility (priv->sidebar, sidebar);
608 ev_window_set_action_sensitive (window, "EditToolbar", toolbar);
610 if (priv->fullscreen_toolbar != NULL) {
611 set_widget_visibility (priv->fullscreen_toolbar, fullscreen_toolbar);
616 update_chrome_flag (EvWindow *window, EvChrome flag, gboolean active)
618 EvWindowPrivate *priv = window->priv;
621 priv->chrome |= flag;
623 priv->chrome &= ~flag;
628 update_sizing_buttons (EvWindow *window)
630 GtkActionGroup *action_group = window->priv->action_group;
632 gboolean best_fit, page_width;
634 switch (ev_document_model_get_sizing_mode (window->priv->model)) {
635 case EV_SIZING_BEST_FIT:
639 case EV_SIZING_FIT_WIDTH:
644 best_fit = page_width = FALSE;
648 action = gtk_action_group_get_action (action_group, "ViewBestFit");
649 g_signal_handlers_block_by_func
650 (action, G_CALLBACK (ev_window_cmd_view_best_fit), window);
651 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), best_fit);
652 g_signal_handlers_unblock_by_func
653 (action, G_CALLBACK (ev_window_cmd_view_best_fit), window);
655 action = gtk_action_group_get_action (action_group, "ViewPageWidth");
656 g_signal_handlers_block_by_func
657 (action, G_CALLBACK (ev_window_cmd_view_page_width), window);
658 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), page_width);
659 g_signal_handlers_unblock_by_func
660 (action, G_CALLBACK (ev_window_cmd_view_page_width), window);
662 action = gtk_action_group_get_action (window->priv->action_group,
663 ZOOM_CONTROL_ACTION);
665 ephy_zoom_action_set_zoom_level (EPHY_ZOOM_ACTION (action),
667 } else if (page_width) {
668 ephy_zoom_action_set_zoom_level (EPHY_ZOOM_ACTION (action),
669 EPHY_ZOOM_FIT_WIDTH);
674 update_chrome_actions (EvWindow *window)
676 EvWindowPrivate *priv = window->priv;
677 GtkActionGroup *action_group = priv->action_group;
680 action= gtk_action_group_get_action (action_group, "ViewToolbar");
681 g_signal_handlers_block_by_func
682 (action, G_CALLBACK (ev_window_view_toolbar_cb), window);
683 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
684 (priv->chrome & EV_CHROME_TOOLBAR) != 0);
685 g_signal_handlers_unblock_by_func
686 (action, G_CALLBACK (ev_window_view_toolbar_cb), window);
690 * ev_window_is_empty:
691 * @ev_window: The instance of the #EvWindow.
693 * It does look if there is any document loaded or if there is any job to load
696 * Returns: %TRUE if there isn't any document loaded or any any documente to be
697 * loaded, %FALSE in other case.
700 ev_window_is_empty (const EvWindow *ev_window)
702 g_return_val_if_fail (EV_IS_WINDOW (ev_window), FALSE);
704 return (ev_window->priv->document == NULL) &&
705 (ev_window->priv->load_job == NULL);
709 ev_window_set_message_area (EvWindow *window,
712 if (window->priv->message_area == area)
715 if (window->priv->message_area)
716 gtk_widget_destroy (window->priv->message_area);
717 window->priv->message_area = area;
722 gtk_box_pack_start (GTK_BOX (window->priv->view_box),
723 window->priv->message_area,
725 gtk_box_reorder_child (GTK_BOX (window->priv->view_box),
726 window->priv->message_area, 0);
727 g_object_add_weak_pointer (G_OBJECT (window->priv->message_area),
728 (gpointer) &(window->priv->message_area));
732 ev_window_message_area_response_cb (EvMessageArea *area,
736 ev_window_set_message_area (window, NULL);
740 ev_window_error_message (EvWindow *window,
749 if (window->priv->message_area)
752 va_start (args, format);
753 msg = g_strdup_vprintf (format, args);
756 area = ev_message_area_new (GTK_MESSAGE_ERROR,
764 ev_message_area_set_secondary_text (EV_MESSAGE_AREA (area), error->message);
765 g_signal_connect (area, "response",
766 G_CALLBACK (ev_window_message_area_response_cb),
768 gtk_widget_show (area);
769 ev_window_set_message_area (window, area);
773 ev_window_warning_message (EvWindow *window,
781 if (window->priv->message_area)
784 va_start (args, format);
785 msg = g_strdup_vprintf (format, args);
788 area = ev_message_area_new (GTK_MESSAGE_WARNING,
795 g_signal_connect (area, "response",
796 G_CALLBACK (ev_window_message_area_response_cb),
798 gtk_widget_show (area);
799 ev_window_set_message_area (window, area);
802 typedef struct _PageTitleData {
803 const gchar *page_label;
808 ev_window_find_page_title (GtkTreeModel *tree_model,
815 gtk_tree_model_get (tree_model, iter,
816 EV_DOCUMENT_LINKS_COLUMN_PAGE_LABEL, &page_string,
822 if (!strcmp (page_string, data->page_label)) {
823 gtk_tree_model_get (tree_model, iter,
824 EV_DOCUMENT_LINKS_COLUMN_MARKUP, &data->page_title,
826 g_free (page_string);
830 g_free (page_string);
835 ev_window_get_page_title (EvWindow *window,
836 const gchar *page_label)
838 if (EV_IS_DOCUMENT_LINKS (window->priv->document) &&
839 ev_document_links_has_document_links (EV_DOCUMENT_LINKS (window->priv->document))) {
843 data.page_label = page_label;
844 data.page_title = NULL;
846 g_object_get (G_OBJECT (window->priv->sidebar_links),
850 gtk_tree_model_foreach (model,
851 (GtkTreeModelForeachFunc)ev_window_find_page_title,
854 g_object_unref (model);
857 return data.page_title;
864 ev_window_add_history (EvWindow *window, gint page, EvLink *link)
866 gchar *page_label = NULL;
870 EvLinkAction *action;
873 if (window->priv->history == NULL)
876 if (!EV_IS_DOCUMENT_LINKS (window->priv->document))
880 action = g_object_ref (ev_link_get_action (link));
881 dest = ev_link_action_get_dest (action);
882 page_label = ev_document_links_get_dest_page_label (EV_DOCUMENT_LINKS (window->priv->document), dest);
884 dest = ev_link_dest_new_page (page);
885 action = ev_link_action_new_dest (dest);
886 page_label = ev_document_get_page_label (window->priv->document, page);
892 page_title = ev_window_get_page_title (window, page_label);
894 link_title = g_strdup_printf (_("Page %s — %s"), page_label, page_title);
897 link_title = g_strdup_printf (_("Page %s"), page_label);
900 real_link = ev_link_new (link_title, action);
902 ev_history_add_link (window->priv->history, real_link);
906 g_object_unref (real_link);
910 view_handle_link_cb (EvView *view, EvLink *link, EvWindow *window)
912 int current_page = ev_document_model_get_page (window->priv->model);
914 ev_window_add_history (window, 0, link);
915 ev_window_add_history (window, current_page, NULL);
919 view_selection_changed_cb (EvView *view,
922 ev_window_set_action_sensitive (window, "EditCopy",
923 ev_view_get_has_selection (view));
927 view_layers_changed_cb (EvView *view,
930 ev_sidebar_layers_update_layers_state (EV_SIDEBAR_LAYERS (window->priv->sidebar_layers));
934 ev_window_page_changed_cb (EvWindow *ev_window,
937 EvDocumentModel *model)
939 ev_window_update_actions (ev_window);
941 ev_window_update_find_status_message (ev_window);
943 if (abs (new_page - old_page) > 1) {
944 ev_window_add_history (ev_window, new_page, NULL);
945 ev_window_add_history (ev_window, old_page, NULL);
948 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window))
949 ev_metadata_set_int (ev_window->priv->metadata, "page", new_page);
953 ev_window_sidebar_get_current_page_id (EvWindow *ev_window)
955 GtkWidget *current_page;
958 g_object_get (ev_window->priv->sidebar,
959 "current_page", ¤t_page,
962 if (current_page == ev_window->priv->sidebar_links) {
963 id = LINKS_SIDEBAR_ID;
964 } else if (current_page == ev_window->priv->sidebar_thumbs) {
965 id = THUMBNAILS_SIDEBAR_ID;
966 } else if (current_page == ev_window->priv->sidebar_attachments) {
967 id = ATTACHMENTS_SIDEBAR_ID;
968 } else if (current_page == ev_window->priv->sidebar_layers) {
969 id = LAYERS_SIDEBAR_ID;
970 } else if (current_page == ev_window->priv->sidebar_annots) {
971 id = ANNOTS_SIDEBAR_ID;
972 } else if (current_page == ev_window->priv->sidebar_bookmarks) {
973 id = BOOKMARKS_SIDEBAR_ID;
975 g_assert_not_reached();
978 g_object_unref (current_page);
984 ev_window_sidebar_set_current_page (EvWindow *window,
985 const gchar *page_id)
987 EvDocument *document = window->priv->document;
988 EvSidebar *sidebar = EV_SIDEBAR (window->priv->sidebar);
989 GtkWidget *links = window->priv->sidebar_links;
990 GtkWidget *thumbs = window->priv->sidebar_thumbs;
991 GtkWidget *attachments = window->priv->sidebar_attachments;
992 GtkWidget *annots = window->priv->sidebar_annots;
993 GtkWidget *layers = window->priv->sidebar_layers;
994 GtkWidget *bookmarks = window->priv->sidebar_bookmarks;
996 if (strcmp (page_id, LINKS_SIDEBAR_ID) == 0 &&
997 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (links), document)) {
998 ev_sidebar_set_page (sidebar, links);
999 } else if (strcmp (page_id, THUMBNAILS_SIDEBAR_ID) == 0 &&
1000 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (thumbs), document)) {
1001 ev_sidebar_set_page (sidebar, thumbs);
1002 } else if (strcmp (page_id, ATTACHMENTS_SIDEBAR_ID) == 0 &&
1003 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (attachments), document)) {
1004 ev_sidebar_set_page (sidebar, attachments);
1005 } else if (strcmp (page_id, LAYERS_SIDEBAR_ID) == 0 &&
1006 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (layers), document)) {
1007 ev_sidebar_set_page (sidebar, layers);
1008 } else if (strcmp (page_id, ANNOTS_SIDEBAR_ID) == 0 &&
1009 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (annots), document)) {
1010 ev_sidebar_set_page (sidebar, annots);
1011 } else if (strcmp (page_id, BOOKMARKS_SIDEBAR_ID) == 0 &&
1012 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (bookmarks), document)) {
1013 ev_sidebar_set_page (sidebar, bookmarks);
1018 update_document_mode (EvWindow *window, EvDocumentMode mode)
1020 if (mode == EV_DOCUMENT_MODE_PRESENTATION) {
1021 ev_window_run_presentation (window);
1023 else if (mode == EV_DOCUMENT_MODE_FULL_SCREEN) {
1024 ev_window_run_fullscreen (window);
1029 setup_chrome_from_metadata (EvWindow *window)
1031 EvChrome chrome = EV_CHROME_NORMAL;
1032 gboolean show_toolbar = TRUE;
1034 if (ev_window_is_empty (window)) {
1035 window->priv->chrome = chrome;
1040 if (!window->priv->metadata) {
1041 show_toolbar = g_settings_get_boolean (window->priv->default_settings, "show-toolbar");
1042 } else if (!ev_metadata_get_boolean (window->priv->metadata, "show_toolbar", &show_toolbar)) {
1043 if (window->priv->is_new_doc)
1044 show_toolbar = g_settings_get_boolean (window->priv->default_settings, "show-toolbar");
1048 chrome &= ~EV_CHROME_TOOLBAR;
1050 window->priv->chrome = chrome;
1054 setup_sidebar_from_metadata (EvWindow *window)
1056 EvDocument *document = window->priv->document;
1057 GSettings *settings = window->priv->default_settings;
1060 gboolean sidebar_visibility = TRUE;
1062 if (ev_window_is_empty (window))
1065 if (!window->priv->metadata) {
1066 sidebar_visibility = g_settings_get_boolean (settings, "show-sidebar");
1067 } else if (!ev_metadata_get_boolean (window->priv->metadata, "sidebar_visibility", &sidebar_visibility)) {
1068 if (window->priv->is_new_doc)
1069 sidebar_visibility = g_settings_get_boolean (settings, "show-sidebar");
1072 update_chrome_flag (window, EV_CHROME_SIDEBAR, sidebar_visibility);
1073 update_chrome_visibility (window);
1075 if (!window->priv->metadata) {
1076 /* Set default values */
1077 gtk_paned_set_position (GTK_PANED (window->priv->hpaned),
1078 g_settings_get_int (settings, "sidebar-size"));
1080 page_id = g_settings_get_string (settings, "sidebar-page");
1081 ev_window_sidebar_set_current_page (window, page_id);
1088 if (ev_metadata_get_int (window->priv->metadata, "sidebar_size", &sidebar_size)) {
1089 gtk_paned_set_position (GTK_PANED (window->priv->hpaned), sidebar_size);
1090 } else if (window->priv->is_new_doc) {
1091 gtk_paned_set_position (GTK_PANED (window->priv->hpaned),
1092 g_settings_get_int (settings, "sidebar-size"));
1098 if (ev_metadata_get_string (window->priv->metadata, "sidebar_page", &page_id)) {
1099 ev_window_sidebar_set_current_page (window, page_id);
1100 } else if (window->priv->is_new_doc) {
1101 page_id = g_settings_get_string (settings, "sidebar-page");
1102 ev_window_sidebar_set_current_page (window, page_id);
1108 setup_model_from_metadata (EvWindow *window)
1110 GSettings *settings = window->priv->default_settings;
1115 gboolean inverted_colors = FALSE;
1116 gboolean continuous = FALSE;
1117 gboolean dual_page = FALSE;
1118 gboolean fullscreen = FALSE;
1120 if (!window->priv->metadata) {
1121 /* Set default values */
1122 ev_document_model_set_sizing_mode (window->priv->model,
1123 g_settings_get_enum (settings, "sizing-mode"));
1124 ev_document_model_set_inverted_colors (window->priv->model,
1125 g_settings_get_boolean (settings, "inverted-colors"));
1126 ev_document_model_set_continuous (window->priv->model,
1127 g_settings_get_boolean (settings, "continuous"));
1128 ev_document_model_set_dual_page (window->priv->model,
1129 g_settings_get_boolean (settings, "dual-page"));
1130 fullscreen = g_settings_get_boolean (settings, "fullscreen");
1132 ev_window_run_fullscreen (window);
1138 if (!window->priv->dest &&
1139 ev_metadata_get_int (window->priv->metadata, "page", &page)) {
1140 ev_document_model_set_page (window->priv->model, page);
1144 if (ev_metadata_get_string (window->priv->metadata, "sizing_mode", &sizing_mode)) {
1145 GEnumValue *enum_value;
1147 enum_value = g_enum_get_value_by_nick
1148 (g_type_class_peek (EV_TYPE_SIZING_MODE), sizing_mode);
1149 ev_document_model_set_sizing_mode (window->priv->model, enum_value->value);
1150 } else if (window->priv->is_new_doc) {
1151 ev_document_model_set_sizing_mode (window->priv->model,
1152 g_settings_get_enum (settings, "sizing-mode"));
1156 if (ev_document_model_get_sizing_mode (window->priv->model) == EV_SIZING_FREE &&
1157 ev_metadata_get_double (window->priv->metadata, "zoom", &zoom)) {
1158 zoom *= get_screen_dpi (window) / 72.0;
1159 ev_document_model_set_scale (window->priv->model, zoom);
1163 if (ev_metadata_get_int (window->priv->metadata, "rotation", &rotation)) {
1178 ev_document_model_set_rotation (window->priv->model, rotation);
1181 /* Inverted Colors */
1182 if (ev_metadata_get_boolean (window->priv->metadata, "inverted-colors", &inverted_colors)) {
1183 ev_document_model_set_inverted_colors (window->priv->model, inverted_colors);
1184 } else if (window->priv->is_new_doc) {
1185 ev_document_model_set_inverted_colors (window->priv->model,
1186 g_settings_get_boolean (settings, "inverted-colors"));
1190 if (ev_metadata_get_boolean (window->priv->metadata, "continuous", &continuous)) {
1191 ev_document_model_set_continuous (window->priv->model, continuous);
1192 } else if (window->priv->is_new_doc) {
1193 ev_document_model_set_continuous (window->priv->model,
1194 g_settings_get_boolean (settings, "continuous"));
1198 if (ev_metadata_get_boolean (window->priv->metadata, "dual-page", &dual_page)) {
1199 ev_document_model_set_dual_page (window->priv->model, dual_page);
1200 } else if (window->priv->is_new_doc) {
1201 ev_document_model_set_dual_page (window->priv->model,
1202 g_settings_get_boolean (settings, "dual-page"));
1206 if (!ev_metadata_get_boolean (window->priv->metadata, "fullscreen", &fullscreen)) {
1207 if (window->priv->is_new_doc)
1208 fullscreen = g_settings_get_boolean (settings, "fullscreen");
1212 ev_window_run_fullscreen (window);
1216 setup_document_from_metadata (EvWindow *window)
1221 gdouble width_ratio;
1222 gdouble height_ratio;
1224 setup_sidebar_from_metadata (window);
1226 if (window->priv->metadata) {
1227 /* Make sure to not open a document on the last page,
1228 * since closing it on the last page most likely means the
1229 * user was finished reading the document. In that case, reopening should
1230 * show the first page. */
1231 page = ev_document_model_get_page (window->priv->model);
1232 n_pages = ev_document_get_n_pages (window->priv->document);
1233 if (page == n_pages - 1)
1234 ev_document_model_set_page (window->priv->model, 0);
1236 if (ev_metadata_get_int (window->priv->metadata, "window_width", &width) &&
1237 ev_metadata_get_int (window->priv->metadata, "window_height", &height))
1238 return; /* size was already set in setup_size_from_metadata */
1241 g_settings_get (window->priv->default_settings, "window-ratio", "(dd)", &width_ratio, &height_ratio);
1242 if (width_ratio > 0. && height_ratio > 0.) {
1243 gdouble document_width;
1244 gdouble document_height;
1247 gint request_height;
1249 ev_document_get_max_page_size (window->priv->document,
1250 &document_width, &document_height);
1252 request_width = (gint)(width_ratio * document_width + 0.5);
1253 request_height = (gint)(height_ratio * document_height + 0.5);
1255 screen = gtk_window_get_screen (GTK_WINDOW (window));
1257 request_width = MIN (request_width, gdk_screen_get_width (screen));
1258 request_height = MIN (request_height, gdk_screen_get_height (screen));
1261 if (request_width > 0 && request_height > 0) {
1262 gtk_window_resize (GTK_WINDOW (window),
1270 setup_size_from_metadata (EvWindow *window)
1278 if (!window->priv->metadata)
1281 if (ev_metadata_get_boolean (window->priv->metadata, "window_maximized", &maximized)) {
1283 gtk_window_maximize (GTK_WINDOW (window));
1286 gtk_window_unmaximize (GTK_WINDOW (window));
1290 if (ev_metadata_get_int (window->priv->metadata, "window_x", &x) &&
1291 ev_metadata_get_int (window->priv->metadata, "window_y", &y)) {
1292 gtk_window_move (GTK_WINDOW (window), x, y);
1295 if (ev_metadata_get_int (window->priv->metadata, "window_width", &width) &&
1296 ev_metadata_get_int (window->priv->metadata, "window_height", &height)) {
1297 gtk_window_resize (GTK_WINDOW (window), width, height);
1302 setup_view_from_metadata (EvWindow *window)
1304 gboolean presentation;
1306 if (!window->priv->metadata)
1310 if (ev_metadata_get_boolean (window->priv->metadata, "presentation", &presentation)) {
1312 ev_window_run_presentation (window);
1318 ev_window_clear_thumbnail_job (EvWindow *ev_window)
1320 if (ev_window->priv->thumbnail_job != NULL) {
1321 if (!ev_job_is_finished (ev_window->priv->thumbnail_job))
1322 ev_job_cancel (ev_window->priv->thumbnail_job);
1324 g_signal_handlers_disconnect_by_func (ev_window->priv->thumbnail_job,
1325 ev_window_set_icon_from_thumbnail,
1327 g_object_unref (ev_window->priv->thumbnail_job);
1328 ev_window->priv->thumbnail_job = NULL;
1333 ev_window_set_icon_from_thumbnail (EvJobThumbnail *job,
1334 EvWindow *ev_window)
1336 if (job->thumbnail) {
1337 if (ev_document_model_get_inverted_colors (ev_window->priv->model))
1338 ev_document_misc_invert_pixbuf (job->thumbnail);
1339 gtk_window_set_icon (GTK_WINDOW (ev_window),
1343 ev_window_clear_thumbnail_job (ev_window);
1347 ev_window_refresh_window_thumbnail (EvWindow *ev_window)
1352 EvDocument *document = ev_window->priv->document;
1354 if (ev_document_get_n_pages (document) <= 0 ||
1355 !ev_document_check_dimensions (document)) {
1359 ev_window_clear_thumbnail_job (ev_window);
1361 ev_document_get_page_size (document, 0, &page_width, NULL);
1362 scale = 128. / page_width;
1363 rotation = ev_document_model_get_rotation (ev_window->priv->model);
1365 ev_window->priv->thumbnail_job = ev_job_thumbnail_new (document, 0, rotation, scale);
1366 g_signal_connect (ev_window->priv->thumbnail_job, "finished",
1367 G_CALLBACK (ev_window_set_icon_from_thumbnail),
1369 ev_job_scheduler_push_job (ev_window->priv->thumbnail_job, EV_JOB_PRIORITY_NONE);
1373 override_restrictions_changed (GSettings *settings,
1375 EvWindow *ev_window)
1377 ev_window_setup_action_sensitivity (ev_window);
1381 lockdown_changed (GSettings *lockdown,
1383 EvWindow *ev_window)
1385 ev_window_setup_action_sensitivity (ev_window);
1389 ev_window_setup_document (EvWindow *ev_window)
1391 const EvDocumentInfo *info;
1392 EvDocument *document = ev_window->priv->document;
1395 ev_window->priv->setup_document_idle = 0;
1397 ev_window_refresh_window_thumbnail (ev_window);
1399 ev_window_set_page_mode (ev_window, PAGE_MODE_DOCUMENT);
1400 ev_window_title_set_document (ev_window->priv->title, document);
1401 ev_window_title_set_uri (ev_window->priv->title, ev_window->priv->uri);
1403 if (!ev_window->priv->settings) {
1404 ev_window->priv->settings = g_settings_new (GS_SCHEMA_NAME);
1405 g_signal_connect (ev_window->priv->settings,
1406 "changed::"GS_OVERRIDE_RESTRICTIONS,
1407 G_CALLBACK (override_restrictions_changed),
1411 #ifdef HAVE_DESKTOP_SCHEMAS
1412 if (!ev_window->priv->lockdown_settings) {
1413 ev_window->priv->lockdown_settings = g_settings_new (GS_LOCKDOWN_SCHEMA_NAME);
1414 g_signal_connect (ev_window->priv->lockdown_settings,
1416 G_CALLBACK (lockdown_changed),
1421 ev_window_setup_action_sensitivity (ev_window);
1423 if (ev_window->priv->history)
1424 g_object_unref (ev_window->priv->history);
1425 ev_window->priv->history = ev_history_new ();
1426 action = gtk_action_group_get_action (ev_window->priv->action_group, NAVIGATION_ACTION);
1427 ev_navigation_action_set_history (EV_NAVIGATION_ACTION (action), ev_window->priv->history);
1429 if (ev_window->priv->properties) {
1430 ev_properties_dialog_set_document (EV_PROPERTIES_DIALOG (ev_window->priv->properties),
1431 ev_window->priv->uri,
1432 ev_window->priv->document);
1435 info = ev_document_get_info (document);
1436 update_document_mode (ev_window, info->mode);
1438 if (EV_WINDOW_IS_PRESENTATION (ev_window))
1439 gtk_widget_grab_focus (ev_window->priv->presentation_view);
1441 gtk_widget_grab_focus (ev_window->priv->view);
1447 ev_window_set_document (EvWindow *ev_window, EvDocument *document)
1449 if (ev_window->priv->document == document)
1452 if (ev_window->priv->document)
1453 g_object_unref (ev_window->priv->document);
1454 ev_window->priv->document = g_object_ref (document);
1456 ev_window_update_max_min_scale (ev_window);
1458 ev_window_set_message_area (ev_window, NULL);
1460 if (ev_document_get_n_pages (document) <= 0) {
1461 ev_window_warning_message (ev_window, "%s",
1462 _("The document contains no pages"));
1463 } else if (!ev_document_check_dimensions (document)) {
1464 ev_window_warning_message (ev_window, "%s",
1465 _("The document contains only empty pages"));
1468 if (EV_WINDOW_IS_PRESENTATION (ev_window)) {
1469 gtk_widget_destroy (ev_window->priv->presentation_view);
1470 ev_window->priv->presentation_view = NULL;
1471 ev_window_run_presentation (ev_window);
1474 if (ev_window->priv->setup_document_idle > 0)
1475 g_source_remove (ev_window->priv->setup_document_idle);
1477 ev_window->priv->setup_document_idle = g_idle_add ((GSourceFunc)ev_window_setup_document, ev_window);
1481 ev_window_document_changed (EvWindow *ev_window,
1484 ev_window_reload_document (ev_window, NULL);
1488 ev_window_password_view_unlock (EvWindow *ev_window)
1490 const gchar *password;
1492 g_assert (ev_window->priv->load_job);
1494 password = ev_password_view_get_password (EV_PASSWORD_VIEW (ev_window->priv->password_view));
1495 ev_job_load_set_password (EV_JOB_LOAD (ev_window->priv->load_job), password);
1496 ev_job_scheduler_push_job (ev_window->priv->load_job, EV_JOB_PRIORITY_NONE);
1500 ev_window_clear_load_job (EvWindow *ev_window)
1502 if (ev_window->priv->load_job != NULL) {
1503 if (!ev_job_is_finished (ev_window->priv->load_job))
1504 ev_job_cancel (ev_window->priv->load_job);
1506 g_signal_handlers_disconnect_by_func (ev_window->priv->load_job, ev_window_load_job_cb, ev_window);
1507 g_object_unref (ev_window->priv->load_job);
1508 ev_window->priv->load_job = NULL;
1513 ev_window_clear_reload_job (EvWindow *ev_window)
1515 if (ev_window->priv->reload_job != NULL) {
1516 if (!ev_job_is_finished (ev_window->priv->reload_job))
1517 ev_job_cancel (ev_window->priv->reload_job);
1519 g_signal_handlers_disconnect_by_func (ev_window->priv->reload_job, ev_window_reload_job_cb, ev_window);
1520 g_object_unref (ev_window->priv->reload_job);
1521 ev_window->priv->reload_job = NULL;
1526 ev_window_clear_local_uri (EvWindow *ev_window)
1528 if (ev_window->priv->local_uri) {
1529 ev_tmp_uri_unlink (ev_window->priv->local_uri);
1530 g_free (ev_window->priv->local_uri);
1531 ev_window->priv->local_uri = NULL;
1536 ev_window_handle_link (EvWindow *ev_window,
1541 EvLinkAction *link_action;
1543 link_action = ev_link_action_new_dest (dest);
1544 link = ev_link_new (NULL, link_action);
1545 ev_view_handle_link (EV_VIEW (ev_window->priv->view), link);
1546 g_object_unref (link);
1550 /* This callback will executed when load job will be finished.
1552 * Since the flow of the error dialog is very confusing, we assume that both
1553 * document and uri will go away after this function is called, and thus we need
1554 * to ref/dup them. Additionally, it needs to clear
1555 * ev_window->priv->password_{uri,document}, and thus people who call this
1556 * function should _not_ necessarily expect those to exist after being
1559 ev_window_load_job_cb (EvJob *job,
1562 EvWindow *ev_window = EV_WINDOW (data);
1563 EvDocument *document = EV_JOB (job)->document;
1564 EvJobLoad *job_load = EV_JOB_LOAD (job);
1566 g_assert (job_load->uri);
1568 ev_view_set_loading (EV_VIEW (ev_window->priv->view), FALSE);
1571 if (!ev_job_is_failed (job)) {
1572 ev_document_model_set_document (ev_window->priv->model, document);
1575 ev_window_emit_doc_loaded (ev_window);
1577 setup_chrome_from_metadata (ev_window);
1578 update_chrome_actions (ev_window);
1579 setup_document_from_metadata (ev_window);
1580 setup_view_from_metadata (ev_window);
1582 ev_window_add_recent (ev_window, ev_window->priv->uri);
1584 ev_window_title_set_type (ev_window->priv->title,
1585 EV_WINDOW_TITLE_DOCUMENT);
1586 if (job_load->password) {
1587 GPasswordSave flags;
1589 flags = ev_password_view_get_password_save_flags (
1590 EV_PASSWORD_VIEW (ev_window->priv->password_view));
1591 ev_keyring_save_password (ev_window->priv->uri,
1596 ev_window_handle_link (ev_window, ev_window->priv->dest);
1597 /* Already unrefed by ev_link_action
1598 * FIXME: link action should inc dest ref counting
1599 * or not unref it at all
1601 ev_window->priv->dest = NULL;
1603 switch (ev_window->priv->window_mode) {
1604 case EV_WINDOW_MODE_FULLSCREEN:
1605 ev_window_run_fullscreen (ev_window);
1607 case EV_WINDOW_MODE_PRESENTATION:
1608 ev_window_run_presentation (ev_window);
1614 if (ev_window->priv->search_string && EV_IS_DOCUMENT_FIND (document)) {
1615 ev_window_cmd_edit_find (NULL, ev_window);
1616 egg_find_bar_set_search_string (EGG_FIND_BAR (ev_window->priv->find_bar),
1617 ev_window->priv->search_string);
1620 g_free (ev_window->priv->search_string);
1621 ev_window->priv->search_string = NULL;
1623 /* Create a monitor for the document */
1624 ev_window->priv->monitor = ev_file_monitor_new (ev_window->priv->uri);
1625 g_signal_connect_swapped (ev_window->priv->monitor, "changed",
1626 G_CALLBACK (ev_window_document_changed),
1629 ev_window_clear_load_job (ev_window);
1633 if (g_error_matches (job->error, EV_DOCUMENT_ERROR, EV_DOCUMENT_ERROR_ENCRYPTED)) {
1636 setup_view_from_metadata (ev_window);
1638 /* First look whether password is in keyring */
1639 password = ev_keyring_lookup_password (ev_window->priv->uri);
1641 if (job_load->password && strcmp (password, job_load->password) == 0) {
1642 /* Password in kering is wrong */
1643 ev_job_load_set_password (job_load, NULL);
1644 /* FIXME: delete password from keyring? */
1646 ev_job_load_set_password (job_load, password);
1647 ev_job_scheduler_push_job (job, EV_JOB_PRIORITY_NONE);
1655 /* We need to ask the user for a password */
1656 ev_window_title_set_uri (ev_window->priv->title,
1657 ev_window->priv->uri);
1658 ev_window_title_set_type (ev_window->priv->title,
1659 EV_WINDOW_TITLE_PASSWORD);
1661 ev_password_view_set_uri (EV_PASSWORD_VIEW (ev_window->priv->password_view),
1664 ev_window_set_page_mode (ev_window, PAGE_MODE_PASSWORD);
1666 ev_job_load_set_password (job_load, NULL);
1667 ev_password_view_ask_password (EV_PASSWORD_VIEW (ev_window->priv->password_view));
1669 ev_window_error_message (ev_window, job->error,
1670 "%s", _("Unable to open document"));
1671 ev_window_clear_load_job (ev_window);
1676 ev_window_reload_job_cb (EvJob *job,
1677 EvWindow *ev_window)
1681 if (ev_job_is_failed (job)) {
1682 ev_window_clear_reload_job (ev_window);
1683 ev_window->priv->in_reload = FALSE;
1684 if (ev_window->priv->dest) {
1685 g_object_unref (ev_window->priv->dest);
1686 ev_window->priv->dest = NULL;
1692 ev_document_model_set_document (ev_window->priv->model,
1694 if (ev_window->priv->dest) {
1695 ev_window_handle_link (ev_window, ev_window->priv->dest);
1696 /* Already unrefed by ev_link_action
1697 * FIXME: link action should inc dest ref counting
1698 * or not unref it at all
1700 ev_window->priv->dest = NULL;
1703 /* Restart the search after reloading */
1704 widget = gtk_window_get_focus (GTK_WINDOW (ev_window));
1705 if (widget && gtk_widget_get_ancestor (widget, EGG_TYPE_FIND_BAR)) {
1706 find_bar_search_changed_cb (EGG_FIND_BAR (ev_window->priv->find_bar),
1710 ev_window_clear_reload_job (ev_window);
1711 ev_window->priv->in_reload = FALSE;
1715 * ev_window_get_uri:
1716 * @ev_window: The instance of the #EvWindow.
1718 * It returns the uri of the document showed in the #EvWindow.
1720 * Returns: the uri of the document showed in the #EvWindow.
1723 ev_window_get_uri (EvWindow *ev_window)
1725 return ev_window->priv->uri;
1729 * ev_window_close_dialogs:
1730 * @ev_window: The window where dialogs will be closed.
1732 * It looks for password, print and properties dialogs and closes them and
1733 * frees them from memory. If there is any print job it does free it too.
1736 ev_window_close_dialogs (EvWindow *ev_window)
1738 if (ev_window->priv->print_dialog)
1739 gtk_widget_destroy (ev_window->priv->print_dialog);
1740 ev_window->priv->print_dialog = NULL;
1742 if (ev_window->priv->properties)
1743 gtk_widget_destroy (ev_window->priv->properties);
1744 ev_window->priv->properties = NULL;
1748 ev_window_clear_progress_idle (EvWindow *ev_window)
1750 if (ev_window->priv->progress_idle > 0)
1751 g_source_remove (ev_window->priv->progress_idle);
1752 ev_window->priv->progress_idle = 0;
1756 reset_progress_idle (EvWindow *ev_window)
1758 ev_window->priv->progress_idle = 0;
1762 ev_window_show_progress_message (EvWindow *ev_window,
1764 GSourceFunc function)
1766 if (ev_window->priv->progress_idle > 0)
1767 g_source_remove (ev_window->priv->progress_idle);
1768 ev_window->priv->progress_idle =
1769 g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
1772 (GDestroyNotify)reset_progress_idle);
1776 ev_window_reset_progress_cancellable (EvWindow *ev_window)
1778 if (ev_window->priv->progress_cancellable)
1779 g_cancellable_reset (ev_window->priv->progress_cancellable);
1781 ev_window->priv->progress_cancellable = g_cancellable_new ();
1785 ev_window_progress_response_cb (EvProgressMessageArea *area,
1787 EvWindow *ev_window)
1789 if (response == GTK_RESPONSE_CANCEL)
1790 g_cancellable_cancel (ev_window->priv->progress_cancellable);
1791 ev_window_set_message_area (ev_window, NULL);
1795 show_loading_progress (EvWindow *ev_window)
1799 gchar *display_name;
1801 if (ev_window->priv->message_area)
1804 text = g_uri_unescape_string (ev_window->priv->uri, NULL);
1805 display_name = g_markup_escape_text (text, -1);
1807 text = g_strdup_printf (_("Loading document from “%s”"),
1810 area = ev_progress_message_area_new (GTK_STOCK_OPEN,
1815 GTK_RESPONSE_CANCEL,
1817 g_signal_connect (area, "response",
1818 G_CALLBACK (ev_window_progress_response_cb),
1820 gtk_widget_show (area);
1821 ev_window_set_message_area (ev_window, area);
1824 g_free (display_name);
1830 ev_window_load_remote_failed (EvWindow *ev_window,
1833 ev_view_set_loading (EV_VIEW (ev_window->priv->view), FALSE);
1834 ev_window->priv->in_reload = FALSE;
1835 ev_window_error_message (ev_window, error,
1836 "%s", _("Unable to open document"));
1837 g_free (ev_window->priv->local_uri);
1838 ev_window->priv->local_uri = NULL;
1839 ev_window->priv->uri_mtime = 0;
1843 set_uri_mtime (GFile *source,
1844 GAsyncResult *async_result,
1845 EvWindow *ev_window)
1848 GError *error = NULL;
1850 info = g_file_query_info_finish (source, async_result, &error);
1853 ev_window->priv->uri_mtime = 0;
1854 g_error_free (error);
1858 g_file_info_get_modification_time (info, &mtime);
1859 ev_window->priv->uri_mtime = mtime.tv_sec;
1860 g_object_unref (info);
1863 g_object_unref (source);
1867 mount_volume_ready_cb (GFile *source,
1868 GAsyncResult *async_result,
1869 EvWindow *ev_window)
1871 GError *error = NULL;
1873 g_file_mount_enclosing_volume_finish (source, async_result, &error);
1876 ev_window_load_remote_failed (ev_window, error);
1877 g_object_unref (source);
1878 g_error_free (error);
1880 /* Volume successfully mounted,
1881 try opening the file again */
1882 ev_window_load_file_remote (ev_window, source);
1887 window_open_file_copy_ready_cb (GFile *source,
1888 GAsyncResult *async_result,
1889 EvWindow *ev_window)
1891 GError *error = NULL;
1893 ev_window_clear_progress_idle (ev_window);
1894 ev_window_set_message_area (ev_window, NULL);
1896 g_file_copy_finish (source, async_result, &error);
1898 ev_job_scheduler_push_job (ev_window->priv->load_job, EV_JOB_PRIORITY_NONE);
1899 g_file_query_info_async (source,
1900 G_FILE_ATTRIBUTE_TIME_MODIFIED,
1901 0, G_PRIORITY_DEFAULT,
1903 (GAsyncReadyCallback)set_uri_mtime,
1908 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_MOUNTED)) {
1909 GMountOperation *operation;
1911 operation = gtk_mount_operation_new (GTK_WINDOW (ev_window));
1912 g_file_mount_enclosing_volume (source,
1915 (GAsyncReadyCallback)mount_volume_ready_cb,
1917 g_object_unref (operation);
1918 } else if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
1919 ev_window_clear_load_job (ev_window);
1920 ev_window_clear_local_uri (ev_window);
1921 g_free (ev_window->priv->uri);
1922 ev_window->priv->uri = NULL;
1923 g_object_unref (source);
1925 ev_view_set_loading (EV_VIEW (ev_window->priv->view), FALSE);
1927 ev_window_load_remote_failed (ev_window, error);
1928 g_object_unref (source);
1931 g_error_free (error);
1935 window_open_file_copy_progress_cb (goffset n_bytes,
1936 goffset total_bytes,
1937 EvWindow *ev_window)
1942 if (!ev_window->priv->message_area)
1945 if (total_bytes <= 0)
1948 fraction = n_bytes / (gdouble)total_bytes;
1949 status = g_strdup_printf (_("Downloading document (%d%%)"),
1950 (gint)(fraction * 100));
1952 ev_progress_message_area_set_status (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
1954 ev_progress_message_area_set_fraction (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
1961 ev_window_load_file_remote (EvWindow *ev_window,
1966 if (!ev_window->priv->local_uri) {
1967 char *base_name, *template;
1971 /* We'd like to keep extension of source uri since
1972 * it helps to resolve some mime types, say cbz.
1974 base_name = g_file_get_basename (source_file);
1975 template = g_strdup_printf ("document.XXXXXX-%s", base_name);
1978 tmp_file = ev_mkstemp_file (template, &err);
1980 if (tmp_file == NULL) {
1981 ev_window_error_message (ev_window, err,
1982 "%s", _("Failed to load remote file."));
1987 ev_window->priv->local_uri = g_file_get_uri (tmp_file);
1988 g_object_unref (tmp_file);
1990 ev_job_load_set_uri (EV_JOB_LOAD (ev_window->priv->load_job),
1991 ev_window->priv->local_uri);
1994 ev_window_reset_progress_cancellable (ev_window);
1996 target_file = g_file_new_for_uri (ev_window->priv->local_uri);
1997 g_file_copy_async (source_file, target_file,
1998 G_FILE_COPY_OVERWRITE,
2000 ev_window->priv->progress_cancellable,
2001 (GFileProgressCallback)window_open_file_copy_progress_cb,
2003 (GAsyncReadyCallback)window_open_file_copy_ready_cb,
2005 g_object_unref (target_file);
2007 ev_window_show_progress_message (ev_window, 1,
2008 (GSourceFunc)show_loading_progress);
2012 ev_window_open_uri (EvWindow *ev_window,
2015 EvWindowRunMode mode,
2016 const gchar *search_string)
2020 ev_window->priv->in_reload = FALSE;
2022 if (ev_window->priv->uri &&
2023 g_ascii_strcasecmp (ev_window->priv->uri, uri) == 0) {
2024 ev_window_reload_document (ev_window, dest);
2028 if (ev_window->priv->monitor) {
2029 g_object_unref (ev_window->priv->monitor);
2030 ev_window->priv->monitor = NULL;
2033 ev_window_close_dialogs (ev_window);
2034 ev_window_clear_load_job (ev_window);
2035 ev_window_clear_local_uri (ev_window);
2037 ev_window->priv->window_mode = mode;
2039 if (ev_window->priv->uri)
2040 g_free (ev_window->priv->uri);
2041 ev_window->priv->uri = g_strdup (uri);
2043 if (ev_window->priv->metadata)
2044 g_object_unref (ev_window->priv->metadata);
2045 if (ev_window->priv->bookmarks)
2046 g_object_unref (ev_window->priv->bookmarks);
2048 source_file = g_file_new_for_uri (uri);
2049 if (!ev_file_is_temp (source_file) && ev_is_metadata_supported_for_file (source_file)) {
2050 ev_window->priv->metadata = ev_metadata_new (source_file);
2051 ev_window->priv->is_new_doc = ev_metadata_is_empty (ev_window->priv->metadata);
2053 ev_window->priv->metadata = NULL;
2056 if (ev_window->priv->metadata) {
2057 ev_window->priv->bookmarks = ev_bookmarks_new (ev_window->priv->metadata);
2058 ev_sidebar_bookmarks_set_bookmarks (EV_SIDEBAR_BOOKMARKS (ev_window->priv->sidebar_bookmarks),
2059 ev_window->priv->bookmarks);
2060 g_signal_connect_swapped (ev_window->priv->bookmarks, "changed",
2061 G_CALLBACK (ev_window_setup_bookmarks),
2064 ev_window->priv->bookmarks = NULL;
2067 if (ev_window->priv->search_string)
2068 g_free (ev_window->priv->search_string);
2069 ev_window->priv->search_string = search_string ?
2070 g_strdup (search_string) : NULL;
2072 if (ev_window->priv->dest)
2073 g_object_unref (ev_window->priv->dest);
2074 ev_window->priv->dest = dest ? g_object_ref (dest) : NULL;
2076 setup_size_from_metadata (ev_window);
2077 setup_model_from_metadata (ev_window);
2078 ev_window_setup_bookmarks (ev_window);
2080 ev_window->priv->load_job = ev_job_load_new (uri);
2081 g_signal_connect (ev_window->priv->load_job,
2083 G_CALLBACK (ev_window_load_job_cb),
2086 if (!g_file_is_native (source_file) && !ev_window->priv->local_uri) {
2087 ev_window_load_file_remote (ev_window, source_file);
2089 ev_view_set_loading (EV_VIEW (ev_window->priv->view), TRUE);
2090 g_object_unref (source_file);
2091 ev_job_scheduler_push_job (ev_window->priv->load_job, EV_JOB_PRIORITY_NONE);
2096 ev_window_open_document (EvWindow *ev_window,
2097 EvDocument *document,
2099 EvWindowRunMode mode,
2100 const gchar *search_string)
2102 if (document == ev_window->priv->document)
2105 ev_window_close_dialogs (ev_window);
2106 ev_window_clear_load_job (ev_window);
2107 ev_window_clear_local_uri (ev_window);
2109 if (ev_window->priv->monitor) {
2110 g_object_unref (ev_window->priv->monitor);
2111 ev_window->priv->monitor = NULL;
2114 if (ev_window->priv->uri)
2115 g_free (ev_window->priv->uri);
2116 ev_window->priv->uri = g_strdup (ev_document_get_uri (document));
2118 setup_size_from_metadata (ev_window);
2119 setup_model_from_metadata (ev_window);
2121 ev_document_model_set_document (ev_window->priv->model, document);
2123 setup_document_from_metadata (ev_window);
2124 setup_view_from_metadata (ev_window);
2128 EvLinkAction *link_action;
2130 link_action = ev_link_action_new_dest (dest);
2131 link = ev_link_new (NULL, link_action);
2132 ev_view_handle_link (EV_VIEW (ev_window->priv->view), link);
2133 /* FIXME: link action should inc dest ref counting
2134 * or not unref it at all
2136 g_object_ref (dest);
2137 g_object_unref (link);
2141 case EV_WINDOW_MODE_FULLSCREEN:
2142 ev_window_run_fullscreen (ev_window);
2144 case EV_WINDOW_MODE_PRESENTATION:
2145 ev_window_run_presentation (ev_window);
2151 if (search_string && EV_IS_DOCUMENT_FIND (document)) {
2152 ev_window_cmd_edit_find (NULL, ev_window);
2153 egg_find_bar_set_search_string (EGG_FIND_BAR (ev_window->priv->find_bar),
2157 /* Create a monitor for the document */
2158 ev_window->priv->monitor = ev_file_monitor_new (ev_window->priv->uri);
2159 g_signal_connect_swapped (ev_window->priv->monitor, "changed",
2160 G_CALLBACK (ev_window_document_changed),
2165 ev_window_reload_local (EvWindow *ev_window)
2169 uri = ev_window->priv->local_uri ? ev_window->priv->local_uri : ev_window->priv->uri;
2170 ev_window->priv->reload_job = ev_job_load_new (uri);
2171 g_signal_connect (ev_window->priv->reload_job, "finished",
2172 G_CALLBACK (ev_window_reload_job_cb),
2174 ev_job_scheduler_push_job (ev_window->priv->reload_job, EV_JOB_PRIORITY_NONE);
2178 show_reloading_progress (EvWindow *ev_window)
2183 if (ev_window->priv->message_area)
2186 text = g_strdup_printf (_("Reloading document from %s"),
2187 ev_window->priv->uri);
2188 area = ev_progress_message_area_new (GTK_STOCK_REFRESH,
2193 GTK_RESPONSE_CANCEL,
2195 g_signal_connect (area, "response",
2196 G_CALLBACK (ev_window_progress_response_cb),
2198 gtk_widget_show (area);
2199 ev_window_set_message_area (ev_window, area);
2206 reload_remote_copy_ready_cb (GFile *remote,
2207 GAsyncResult *async_result,
2208 EvWindow *ev_window)
2210 GError *error = NULL;
2212 ev_window_clear_progress_idle (ev_window);
2214 g_file_copy_finish (remote, async_result, &error);
2216 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
2217 ev_window_error_message (ev_window, error,
2218 "%s", _("Failed to reload document."));
2219 g_error_free (error);
2221 ev_window_reload_local (ev_window);
2224 g_object_unref (remote);
2228 reload_remote_copy_progress_cb (goffset n_bytes,
2229 goffset total_bytes,
2230 EvWindow *ev_window)
2235 if (!ev_window->priv->message_area)
2238 if (total_bytes <= 0)
2241 fraction = n_bytes / (gdouble)total_bytes;
2242 status = g_strdup_printf (_("Downloading document (%d%%)"),
2243 (gint)(fraction * 100));
2245 ev_progress_message_area_set_status (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
2247 ev_progress_message_area_set_fraction (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
2254 query_remote_uri_mtime_cb (GFile *remote,
2255 GAsyncResult *async_result,
2256 EvWindow *ev_window)
2260 GError *error = NULL;
2262 info = g_file_query_info_finish (remote, async_result, &error);
2264 g_error_free (error);
2265 g_object_unref (remote);
2266 ev_window_reload_local (ev_window);
2271 g_file_info_get_modification_time (info, &mtime);
2272 if (ev_window->priv->uri_mtime != mtime.tv_sec) {
2275 /* Remote file has changed */
2276 ev_window->priv->uri_mtime = mtime.tv_sec;
2278 ev_window_reset_progress_cancellable (ev_window);
2280 target_file = g_file_new_for_uri (ev_window->priv->local_uri);
2281 g_file_copy_async (remote, target_file,
2282 G_FILE_COPY_OVERWRITE,
2284 ev_window->priv->progress_cancellable,
2285 (GFileProgressCallback)reload_remote_copy_progress_cb,
2287 (GAsyncReadyCallback)reload_remote_copy_ready_cb,
2289 g_object_unref (target_file);
2290 ev_window_show_progress_message (ev_window, 1,
2291 (GSourceFunc)show_reloading_progress);
2293 g_object_unref (remote);
2294 ev_window_reload_local (ev_window);
2297 g_object_unref (info);
2301 ev_window_reload_remote (EvWindow *ev_window)
2305 remote = g_file_new_for_uri (ev_window->priv->uri);
2306 /* Reload the remote uri only if it has changed */
2307 g_file_query_info_async (remote,
2308 G_FILE_ATTRIBUTE_TIME_MODIFIED,
2309 0, G_PRIORITY_DEFAULT,
2311 (GAsyncReadyCallback)query_remote_uri_mtime_cb,
2316 ev_window_reload_document (EvWindow *ev_window,
2322 ev_window_clear_reload_job (ev_window);
2323 ev_window->priv->in_reload = TRUE;
2325 page = ev_document_model_get_page (ev_window->priv->model);
2327 if (ev_window->priv->dest)
2328 g_object_unref (ev_window->priv->dest);
2329 ev_window->priv->dest = dest ? g_object_ref (dest) : NULL;
2331 if (ev_window->priv->local_uri) {
2332 ev_window_reload_remote (ev_window);
2334 ev_window_reload_local (ev_window);
2339 file_open_dialog_response_cb (GtkWidget *chooser,
2341 EvWindow *ev_window)
2343 if (response_id == GTK_RESPONSE_OK) {
2347 uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (chooser));
2349 ev_application_open_uri_list (EV_APP, uris,
2350 gtk_window_get_screen (GTK_WINDOW (ev_window)),
2351 gtk_get_current_event_time ());
2353 g_slist_foreach (uris, (GFunc)g_free, NULL);
2354 g_slist_free (uris);
2356 uri = gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (chooser));
2357 ev_application_set_filechooser_uri (EV_APP,
2358 GTK_FILE_CHOOSER_ACTION_OPEN,
2363 gtk_widget_destroy (chooser);
2367 ev_window_cmd_file_open (GtkAction *action, EvWindow *window)
2370 const gchar *default_uri;
2371 gchar *parent_uri = NULL;
2373 chooser = gtk_file_chooser_dialog_new (_("Open Document"),
2374 GTK_WINDOW (window),
2375 GTK_FILE_CHOOSER_ACTION_OPEN,
2377 GTK_RESPONSE_CANCEL,
2378 GTK_STOCK_OPEN, GTK_RESPONSE_OK,
2381 ev_document_factory_add_filters (chooser, NULL);
2382 gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (chooser), TRUE);
2383 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser), FALSE);
2385 default_uri = ev_application_get_filechooser_uri (EV_APP, GTK_FILE_CHOOSER_ACTION_OPEN);
2386 if (!default_uri && window->priv->uri) {
2387 GFile *file, *parent;
2389 file = g_file_new_for_uri (window->priv->uri);
2390 parent = g_file_get_parent (file);
2392 parent_uri = g_file_get_uri (parent);
2393 default_uri = parent_uri;
2394 g_object_unref (parent);
2396 g_object_unref (file);
2400 gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (chooser), default_uri);
2402 const gchar *folder;
2404 folder = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
2405 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser),
2406 folder ? folder : g_get_home_dir ());
2408 g_free (parent_uri);
2410 g_signal_connect (chooser, "response",
2411 G_CALLBACK (file_open_dialog_response_cb),
2414 gtk_widget_show (chooser);
2418 ev_window_open_copy_at_dest (EvWindow *window,
2421 EvWindow *new_window = EV_WINDOW (ev_window_new ());
2423 ev_window_n_copies++;
2425 if (window->priv->metadata)
2426 new_window->priv->metadata = g_object_ref (window->priv->metadata);
2427 ev_window_open_document (new_window,
2428 window->priv->document,
2430 gtk_window_present (GTK_WINDOW (new_window));
2434 ev_window_cmd_file_open_copy (GtkAction *action, EvWindow *window)
2436 ev_window_open_copy_at_dest (window, NULL);
2440 ev_window_cmd_recent_file_activate (GtkAction *action,
2443 GtkRecentInfo *info;
2446 info = g_object_get_data (G_OBJECT (action), "gtk-recent-info");
2447 g_assert (info != NULL);
2449 uri = gtk_recent_info_get_uri (info);
2451 ev_application_open_uri_at_dest (EV_APP, uri,
2452 gtk_window_get_screen (GTK_WINDOW (window)),
2453 NULL, 0, NULL, gtk_get_current_event_time ());
2457 ev_window_open_recent_action_item_activated (EvOpenRecentAction *action,
2461 ev_application_open_uri_at_dest (EV_APP, uri,
2462 gtk_window_get_screen (GTK_WINDOW (window)),
2463 NULL, 0, NULL, gtk_get_current_event_time ());
2467 ev_window_add_recent (EvWindow *window, const char *filename)
2469 gtk_recent_manager_add_item (window->priv->recent_manager, filename);
2473 compare_recent_items (GtkRecentInfo *a, GtkRecentInfo *b)
2475 gboolean has_ev_a, has_ev_b;
2476 const gchar *evince = g_get_application_name ();
2478 has_ev_a = gtk_recent_info_has_application (a, evince);
2479 has_ev_b = gtk_recent_info_has_application (b, evince);
2481 if (has_ev_a && has_ev_b) {
2482 time_t time_a, time_b;
2484 time_a = gtk_recent_info_get_modified (a);
2485 time_b = gtk_recent_info_get_modified (b);
2487 return (time_b - time_a);
2488 } else if (has_ev_a) {
2490 } else if (has_ev_b) {
2498 * Doubles underscore to avoid spurious menu accels.
2501 ev_window_get_recent_file_label (gint index, const gchar *filename)
2509 is_rtl = (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL);
2511 g_return_val_if_fail (filename != NULL, NULL);
2513 length = strlen (filename);
2514 str = g_string_sized_new (length + 10);
2515 g_string_printf (str, "%s_%d. ", is_rtl ? "\xE2\x80\x8F" : "", index);
2518 end = filename + length;
2522 next = g_utf8_next_char (p);
2526 g_string_append (str, "__");
2529 g_string_append_len (str, p, next - p);
2536 return g_string_free (str, FALSE);
2540 ev_window_recent_action_connect_proxy_cb (GtkActionGroup *action_group,
2547 if (!GTK_IS_MENU_ITEM (proxy))
2550 label = GTK_LABEL (gtk_bin_get_child (GTK_BIN (proxy)));
2552 gtk_label_set_ellipsize (label, PANGO_ELLIPSIZE_MIDDLE);
2553 gtk_label_set_max_width_chars (label, MAX_RECENT_ITEM_LEN);
2557 ev_window_setup_recent (EvWindow *ev_window)
2561 const gchar *evince = g_get_application_name ();
2564 if (ev_window->priv->recent_ui_id > 0) {
2565 gtk_ui_manager_remove_ui (ev_window->priv->ui_manager,
2566 ev_window->priv->recent_ui_id);
2567 gtk_ui_manager_ensure_update (ev_window->priv->ui_manager);
2569 ev_window->priv->recent_ui_id = gtk_ui_manager_new_merge_id (ev_window->priv->ui_manager);
2571 if (ev_window->priv->recent_action_group) {
2572 gtk_ui_manager_remove_action_group (ev_window->priv->ui_manager,
2573 ev_window->priv->recent_action_group);
2574 g_object_unref (ev_window->priv->recent_action_group);
2576 ev_window->priv->recent_action_group = gtk_action_group_new ("RecentFilesActions");
2577 g_signal_connect (ev_window->priv->recent_action_group, "connect-proxy",
2578 G_CALLBACK (ev_window_recent_action_connect_proxy_cb), NULL);
2580 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
2581 ev_window->priv->recent_action_group, -1);
2583 items = gtk_recent_manager_get_items (ev_window->priv->recent_manager);
2584 items = g_list_sort (items, (GCompareFunc) compare_recent_items);
2586 for (l = items; l && l->data; l = g_list_next (l)) {
2587 GtkRecentInfo *info;
2591 const gchar *mime_type;
2592 gchar *content_type;
2595 info = (GtkRecentInfo *) l->data;
2597 if (!gtk_recent_info_has_application (info, evince) ||
2598 (gtk_recent_info_is_local (info) && !gtk_recent_info_exists (info)))
2601 action_name = g_strdup_printf ("RecentFile%u", i++);
2602 label = ev_window_get_recent_file_label (
2603 n_items + 1, gtk_recent_info_get_display_name (info));
2605 mime_type = gtk_recent_info_get_mime_type (info);
2606 content_type = g_content_type_from_mime_type (mime_type);
2607 if (content_type != NULL) {
2608 icon = g_content_type_get_icon (content_type);
2609 g_free (content_type);
2612 action = g_object_new (GTK_TYPE_ACTION,
2613 "name", action_name,
2616 "always-show-image", TRUE,
2619 g_object_set_data_full (G_OBJECT (action),
2621 gtk_recent_info_ref (info),
2622 (GDestroyNotify) gtk_recent_info_unref);
2624 g_signal_connect (action, "activate",
2625 G_CALLBACK (ev_window_cmd_recent_file_activate),
2626 (gpointer) ev_window);
2628 gtk_action_group_add_action (ev_window->priv->recent_action_group,
2630 g_object_unref (action);
2632 gtk_ui_manager_add_ui (ev_window->priv->ui_manager,
2633 ev_window->priv->recent_ui_id,
2634 "/MainMenu/FileMenu/RecentFilesMenu",
2637 GTK_UI_MANAGER_MENUITEM,
2639 g_free (action_name);
2642 g_object_unref (icon);
2648 g_list_foreach (items, (GFunc) gtk_recent_info_unref, NULL);
2649 g_list_free (items);
2653 show_saving_progress (GFile *dst)
2655 EvWindow *ev_window;
2659 EvSaveType save_type;
2661 ev_window = EV_WINDOW (g_object_get_data (G_OBJECT (dst), "ev-window"));
2662 ev_window->priv->progress_idle = 0;
2664 if (ev_window->priv->message_area)
2667 save_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dst), "save-type"));
2668 uri = g_file_get_uri (dst);
2669 switch (save_type) {
2670 case EV_SAVE_DOCUMENT:
2671 text = g_strdup_printf (_("Saving document to %s"), uri);
2673 case EV_SAVE_ATTACHMENT:
2674 text = g_strdup_printf (_("Saving attachment to %s"), uri);
2677 text = g_strdup_printf (_("Saving image to %s"), uri);
2680 g_assert_not_reached ();
2683 area = ev_progress_message_area_new (GTK_STOCK_SAVE,
2688 GTK_RESPONSE_CANCEL,
2690 g_signal_connect (area, "response",
2691 G_CALLBACK (ev_window_progress_response_cb),
2693 gtk_widget_show (area);
2694 ev_window_set_message_area (ev_window, area);
2701 window_save_file_copy_ready_cb (GFile *src,
2702 GAsyncResult *async_result,
2705 EvWindow *ev_window;
2706 GError *error = NULL;
2708 ev_window = EV_WINDOW (g_object_get_data (G_OBJECT (dst), "ev-window"));
2709 ev_window_clear_progress_idle (ev_window);
2711 if (g_file_copy_finish (src, async_result, &error)) {
2712 ev_tmp_file_unlink (src);
2716 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
2719 name = g_file_get_basename (dst);
2720 ev_window_error_message (ev_window, error,
2721 _("The file could not be saved as “%s”."),
2725 ev_tmp_file_unlink (src);
2726 g_error_free (error);
2730 window_save_file_copy_progress_cb (goffset n_bytes,
2731 goffset total_bytes,
2734 EvWindow *ev_window;
2735 EvSaveType save_type;
2739 ev_window = EV_WINDOW (g_object_get_data (G_OBJECT (dst), "ev-window"));
2741 if (!ev_window->priv->message_area)
2744 if (total_bytes <= 0)
2747 fraction = n_bytes / (gdouble)total_bytes;
2748 save_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dst), "save-type"));
2750 switch (save_type) {
2751 case EV_SAVE_DOCUMENT:
2752 status = g_strdup_printf (_("Uploading document (%d%%)"),
2753 (gint)(fraction * 100));
2755 case EV_SAVE_ATTACHMENT:
2756 status = g_strdup_printf (_("Uploading attachment (%d%%)"),
2757 (gint)(fraction * 100));
2760 status = g_strdup_printf (_("Uploading image (%d%%)"),
2761 (gint)(fraction * 100));
2764 g_assert_not_reached ();
2767 ev_progress_message_area_set_status (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
2769 ev_progress_message_area_set_fraction (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
2776 ev_window_save_remote (EvWindow *ev_window,
2777 EvSaveType save_type,
2781 ev_window_reset_progress_cancellable (ev_window);
2782 g_object_set_data (G_OBJECT (dst), "ev-window", ev_window);
2783 g_object_set_data (G_OBJECT (dst), "save-type", GINT_TO_POINTER (save_type));
2784 g_file_copy_async (src, dst,
2785 G_FILE_COPY_OVERWRITE,
2787 ev_window->priv->progress_cancellable,
2788 (GFileProgressCallback)window_save_file_copy_progress_cb,
2790 (GAsyncReadyCallback)window_save_file_copy_ready_cb,
2792 ev_window->priv->progress_idle =
2793 g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
2795 (GSourceFunc)show_saving_progress,
2801 ev_window_clear_save_job (EvWindow *ev_window)
2803 if (ev_window->priv->save_job != NULL) {
2804 if (!ev_job_is_finished (ev_window->priv->save_job))
2805 ev_job_cancel (ev_window->priv->save_job);
2807 g_signal_handlers_disconnect_by_func (ev_window->priv->save_job,
2808 ev_window_save_job_cb,
2810 g_object_unref (ev_window->priv->save_job);
2811 ev_window->priv->save_job = NULL;
2816 ev_window_save_job_cb (EvJob *job,
2819 if (ev_job_is_failed (job)) {
2820 ev_window_error_message (window, job->error,
2821 _("The file could not be saved as “%s”."),
2822 EV_JOB_SAVE (job)->uri);
2824 ev_window_add_recent (window, EV_JOB_SAVE (job)->uri);
2827 ev_window_clear_save_job (window);
2831 file_save_dialog_response_cb (GtkWidget *fc,
2833 EvWindow *ev_window)
2836 GFile *file, *parent;
2838 if (response_id != GTK_RESPONSE_OK) {
2839 gtk_widget_destroy (fc);
2843 uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
2844 file = g_file_new_for_uri (uri);
2845 parent = g_file_get_parent (file);
2846 g_object_unref (file);
2850 folder_uri = g_file_get_uri (parent);
2851 ev_application_set_filechooser_uri (EV_APP,
2852 GTK_FILE_CHOOSER_ACTION_SAVE,
2854 g_free (folder_uri);
2855 g_object_unref (parent);
2858 /* FIXME: remote copy should be done here rather than in the save job,
2859 * so that we can track progress and cancel the operation
2862 ev_window_clear_save_job (ev_window);
2863 ev_window->priv->save_job = ev_job_save_new (ev_window->priv->document,
2864 uri, ev_window->priv->uri);
2865 g_signal_connect (ev_window->priv->save_job, "finished",
2866 G_CALLBACK (ev_window_save_job_cb),
2868 /* The priority doesn't matter for this job */
2869 ev_job_scheduler_push_job (ev_window->priv->save_job, EV_JOB_PRIORITY_NONE);
2872 gtk_widget_destroy (fc);
2876 ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window)
2881 const gchar *default_uri;
2883 fc = gtk_file_chooser_dialog_new (
2885 GTK_WINDOW (ev_window), GTK_FILE_CHOOSER_ACTION_SAVE,
2886 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
2887 GTK_STOCK_SAVE, GTK_RESPONSE_OK,
2890 ev_document_factory_add_filters (fc, ev_window->priv->document);
2891 gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
2892 gtk_dialog_set_alternative_button_order (GTK_DIALOG (fc),
2894 GTK_RESPONSE_CANCEL,
2897 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (fc), FALSE);
2898 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
2899 file = g_file_new_for_uri (ev_window->priv->uri);
2900 base_name = g_file_get_basename (file);
2901 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc), base_name);
2903 default_uri = ev_application_get_filechooser_uri (EV_APP, GTK_FILE_CHOOSER_ACTION_SAVE);
2905 gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (fc), default_uri);
2907 const gchar *folder;
2909 folder = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
2910 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (fc),
2911 folder ? folder : g_get_home_dir ());
2914 g_object_unref (file);
2917 g_signal_connect (fc, "response",
2918 G_CALLBACK (file_save_dialog_response_cb),
2921 gtk_widget_show (fc);
2925 ev_window_cmd_open_containing_folder (GtkAction *action, EvWindow *ev_window)
2927 GtkWidget *ev_window_widget;
2931 ev_window_widget = GTK_WIDGET (ev_window);
2933 file = g_file_new_for_uri (ev_window->priv->uri);
2934 parent = g_file_get_parent (file);
2939 parent_uri = g_file_get_uri (parent);
2945 screen = gtk_widget_get_screen (ev_window_widget);
2946 timestamp = gtk_get_current_event_time ();
2949 if (!gtk_show_uri (screen, parent_uri, timestamp, &error)) {
2950 ev_window_error_message (ev_window, error, _("Could not open the containing folder"));
2951 g_error_free (error);
2954 g_free (parent_uri);
2959 g_object_unref (file);
2962 g_object_unref (parent);
2967 get_print_settings_file (void)
2969 GKeyFile *print_settings_file;
2971 GError *error = NULL;
2973 print_settings_file = g_key_file_new ();
2975 filename = g_build_filename (ev_application_get_dot_dir (EV_APP, FALSE),
2976 EV_PRINT_SETTINGS_FILE, NULL);
2977 if (!g_key_file_load_from_file (print_settings_file,
2979 G_KEY_FILE_KEEP_COMMENTS |
2980 G_KEY_FILE_KEEP_TRANSLATIONS,
2983 /* Don't warn if the file simply doesn't exist */
2984 if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
2985 g_warning ("%s", error->message);
2987 g_error_free (error);
2992 return print_settings_file;
2996 save_print_setting_file (GKeyFile *key_file)
3001 GError *error = NULL;
3003 filename = g_build_filename (ev_application_get_dot_dir (EV_APP, TRUE),
3004 EV_PRINT_SETTINGS_FILE, NULL);
3005 data = g_key_file_to_data (key_file, &data_length, NULL);
3006 g_file_set_contents (filename, data, data_length, &error);
3008 g_warning ("Failed to save print settings: %s", error->message);
3009 g_error_free (error);
3016 ev_window_save_print_settings (EvWindow *window,
3017 GtkPrintSettings *print_settings)
3022 key_file = get_print_settings_file ();
3023 gtk_print_settings_to_key_file (print_settings, key_file, EV_PRINT_SETTINGS_GROUP);
3025 /* Save print settings that are specific to the document */
3026 for (i = 0; i < G_N_ELEMENTS (document_print_settings); i++) {
3027 /* Remove it from global settings */
3028 g_key_file_remove_key (key_file, EV_PRINT_SETTINGS_GROUP,
3029 document_print_settings[i], NULL);
3031 if (window->priv->metadata) {
3034 value = gtk_print_settings_get (print_settings,
3035 document_print_settings[i]);
3036 ev_metadata_set_string (window->priv->metadata,
3037 document_print_settings[i], value);
3041 save_print_setting_file (key_file);
3042 g_key_file_free (key_file);
3046 ev_window_save_print_page_setup (EvWindow *window,
3047 GtkPageSetup *page_setup)
3051 key_file = get_print_settings_file ();
3052 gtk_page_setup_to_key_file (page_setup, key_file, EV_PAGE_SETUP_GROUP);
3054 /* Do not save document settings in global file */
3055 g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
3056 "page-setup-orientation", NULL);
3057 g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
3058 "page-setup-margin-top", NULL);
3059 g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
3060 "page-setup-margin-bottom", NULL);
3061 g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
3062 "page-setup-margin-left", NULL);
3063 g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
3064 "page-setup-margin-right", NULL);
3066 save_print_setting_file (key_file);
3067 g_key_file_free (key_file);
3069 if (!window->priv->metadata)
3072 /* Save page setup options that are specific to the document */
3073 ev_metadata_set_int (window->priv->metadata, "page-setup-orientation",
3074 gtk_page_setup_get_orientation (page_setup));
3075 ev_metadata_set_double (window->priv->metadata, "page-setup-margin-top",
3076 gtk_page_setup_get_top_margin (page_setup, GTK_UNIT_MM));
3077 ev_metadata_set_double (window->priv->metadata, "page-setup-margin-bottom",
3078 gtk_page_setup_get_bottom_margin (page_setup, GTK_UNIT_MM));
3079 ev_metadata_set_double (window->priv->metadata, "page-setup-margin-left",
3080 gtk_page_setup_get_left_margin (page_setup, GTK_UNIT_MM));
3081 ev_metadata_set_double (window->priv->metadata, "page-setup-margin-right",
3082 gtk_page_setup_get_right_margin (page_setup, GTK_UNIT_MM));
3086 ev_window_load_print_settings_from_metadata (EvWindow *window,
3087 GtkPrintSettings *print_settings)
3091 if (!window->priv->metadata)
3094 /* Load print setting that are specific to the document */
3095 for (i = 0; i < G_N_ELEMENTS (document_print_settings); i++) {
3096 gchar *value = NULL;
3098 ev_metadata_get_string (window->priv->metadata,
3099 document_print_settings[i], &value);
3100 gtk_print_settings_set (print_settings,
3101 document_print_settings[i], value);
3106 ev_window_load_print_page_setup_from_metadata (EvWindow *window,
3107 GtkPageSetup *page_setup)
3110 gdouble double_value;
3111 GtkPaperSize *paper_size = gtk_page_setup_get_paper_size (page_setup);
3113 /* Load page setup options that are specific to the document */
3114 if (window->priv->metadata &&
3115 ev_metadata_get_int (window->priv->metadata, "page-setup-orientation", &int_value)) {
3116 gtk_page_setup_set_orientation (page_setup, int_value);
3118 gtk_page_setup_set_orientation (page_setup, GTK_PAGE_ORIENTATION_PORTRAIT);
3121 if (window->priv->metadata &&
3122 ev_metadata_get_double (window->priv->metadata, "page-setup-margin-top", &double_value)) {
3123 gtk_page_setup_set_top_margin (page_setup, double_value, GTK_UNIT_MM);
3125 gtk_page_setup_set_top_margin (page_setup,
3126 gtk_paper_size_get_default_top_margin (paper_size, GTK_UNIT_MM),
3130 if (window->priv->metadata &&
3131 ev_metadata_get_double (window->priv->metadata, "page-setup-margin-bottom", &double_value)) {
3132 gtk_page_setup_set_bottom_margin (page_setup, double_value, GTK_UNIT_MM);
3134 gtk_page_setup_set_bottom_margin (page_setup,
3135 gtk_paper_size_get_default_bottom_margin (paper_size, GTK_UNIT_MM),
3139 if (window->priv->metadata &&
3140 ev_metadata_get_double (window->priv->metadata, "page-setup-margin-left", &double_value)) {
3141 gtk_page_setup_set_left_margin (page_setup, double_value, GTK_UNIT_MM);
3143 gtk_page_setup_set_left_margin (page_setup,
3144 gtk_paper_size_get_default_left_margin (paper_size, GTK_UNIT_MM),
3148 if (window->priv->metadata &&
3149 ev_metadata_get_double (window->priv->metadata, "page-setup-margin-right", &double_value)) {
3150 gtk_page_setup_set_right_margin (page_setup, double_value, GTK_UNIT_MM);
3152 gtk_page_setup_set_right_margin (page_setup,
3153 gtk_paper_size_get_default_right_margin (paper_size, GTK_UNIT_MM),
3158 static GtkPrintSettings *
3159 get_print_settings (GKeyFile *key_file)
3161 GtkPrintSettings *print_settings;
3163 print_settings = g_key_file_has_group (key_file, EV_PRINT_SETTINGS_GROUP) ?
3164 gtk_print_settings_new_from_key_file (key_file, EV_PRINT_SETTINGS_GROUP, NULL) :
3165 gtk_print_settings_new ();
3167 return print_settings ? print_settings : gtk_print_settings_new ();
3170 static GtkPageSetup *
3171 get_print_page_setup (GKeyFile *key_file)
3173 GtkPageSetup *page_setup;
3175 page_setup = g_key_file_has_group (key_file, EV_PAGE_SETUP_GROUP) ?
3176 gtk_page_setup_new_from_key_file (key_file, EV_PAGE_SETUP_GROUP, NULL) :
3177 gtk_page_setup_new ();
3179 return page_setup ? page_setup : gtk_page_setup_new ();
3183 ev_window_print_cancel (EvWindow *ev_window)
3185 EvPrintOperation *op;
3187 if (!ev_window->priv->print_queue)
3190 while ((op = g_queue_peek_tail (ev_window->priv->print_queue))) {
3191 ev_print_operation_cancel (op);
3196 ev_window_print_update_pending_jobs_message (EvWindow *ev_window,
3201 if (!EV_IS_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area) ||
3202 !ev_window->priv->print_queue)
3206 ev_window_set_message_area (ev_window, NULL);
3211 text = g_strdup_printf (ngettext ("%d pending job in queue",
3212 "%d pending jobs in queue",
3213 n_jobs - 1), n_jobs - 1);
3216 ev_message_area_set_secondary_text (EV_MESSAGE_AREA (ev_window->priv->message_area),
3222 destroy_window (GtkWidget *window)
3224 gtk_widget_destroy (window);
3230 ev_window_print_operation_done (EvPrintOperation *op,
3231 GtkPrintOperationResult result,
3232 EvWindow *ev_window)
3237 case GTK_PRINT_OPERATION_RESULT_APPLY: {
3238 GtkPrintSettings *print_settings;
3240 print_settings = ev_print_operation_get_print_settings (op);
3241 ev_window_save_print_settings (ev_window, print_settings);
3243 if (ev_print_operation_get_embed_page_setup (op)) {
3244 GtkPageSetup *page_setup;
3246 page_setup = ev_print_operation_get_default_page_setup (op);
3247 ev_window_save_print_page_setup (ev_window, page_setup);
3252 case GTK_PRINT_OPERATION_RESULT_ERROR: {
3254 GError *error = NULL;
3257 ev_print_operation_get_error (op, &error);
3259 /* The message area is already used by
3260 * the printing progress, so it's better to
3261 * use a popup dialog in this case
3263 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
3264 GTK_DIALOG_DESTROY_WITH_PARENT,
3267 "%s", _("Failed to print document"));
3268 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
3269 "%s", error->message);
3270 g_signal_connect (dialog, "response",
3271 G_CALLBACK (gtk_widget_destroy),
3273 gtk_widget_show (dialog);
3275 g_error_free (error);
3278 case GTK_PRINT_OPERATION_RESULT_CANCEL:
3283 g_queue_remove (ev_window->priv->print_queue, op);
3284 g_object_unref (op);
3285 n_jobs = g_queue_get_length (ev_window->priv->print_queue);
3286 ev_window_print_update_pending_jobs_message (ev_window, n_jobs);
3288 if (n_jobs == 0 && ev_window->priv->close_after_print)
3289 g_idle_add ((GSourceFunc)destroy_window,
3294 ev_window_print_progress_response_cb (EvProgressMessageArea *area,
3296 EvWindow *ev_window)
3298 if (response == GTK_RESPONSE_CANCEL) {
3299 EvPrintOperation *op;
3301 op = g_queue_peek_tail (ev_window->priv->print_queue);
3302 ev_print_operation_cancel (op);
3304 gtk_widget_hide (GTK_WIDGET (area));
3309 ev_window_print_operation_status_changed (EvPrintOperation *op,
3310 EvWindow *ev_window)
3312 const gchar *status;
3315 status = ev_print_operation_get_status (op);
3316 fraction = ev_print_operation_get_progress (op);
3318 if (!ev_window->priv->message_area) {
3320 const gchar *job_name;
3323 job_name = ev_print_operation_get_job_name (op);
3324 text = g_strdup_printf (_("Printing job “%s”"), job_name);
3326 area = ev_progress_message_area_new (GTK_STOCK_PRINT,
3331 GTK_RESPONSE_CANCEL,
3333 ev_window_print_update_pending_jobs_message (ev_window, 1);
3334 g_signal_connect (area, "response",
3335 G_CALLBACK (ev_window_print_progress_response_cb),
3337 gtk_widget_show (area);
3338 ev_window_set_message_area (ev_window, area);
3342 ev_progress_message_area_set_status (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
3344 ev_progress_message_area_set_fraction (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
3349 ev_window_print_operation_begin_print (EvPrintOperation *op,
3350 EvWindow *ev_window)
3352 if (!ev_window->priv->print_queue)
3353 ev_window->priv->print_queue = g_queue_new ();
3355 g_queue_push_head (ev_window->priv->print_queue, op);
3356 ev_window_print_update_pending_jobs_message (ev_window,
3357 g_queue_get_length (ev_window->priv->print_queue));
3361 ev_window_print_range (EvWindow *ev_window,
3365 EvPrintOperation *op;
3366 GKeyFile *print_settings_file;
3367 GtkPrintSettings *print_settings;
3368 GtkPageSetup *print_page_setup;
3370 gint document_last_page;
3371 gboolean embed_page_setup;
3373 g_return_if_fail (EV_IS_WINDOW (ev_window));
3374 g_return_if_fail (ev_window->priv->document != NULL);
3376 if (!ev_window->priv->print_queue)
3377 ev_window->priv->print_queue = g_queue_new ();
3379 op = ev_print_operation_new (ev_window->priv->document);
3381 g_warning ("%s", "Printing is not supported for document\n");
3385 g_signal_connect (op, "begin_print",
3386 G_CALLBACK (ev_window_print_operation_begin_print),
3387 (gpointer)ev_window);
3388 g_signal_connect (op, "status_changed",
3389 G_CALLBACK (ev_window_print_operation_status_changed),
3390 (gpointer)ev_window);
3391 g_signal_connect (op, "done",
3392 G_CALLBACK (ev_window_print_operation_done),
3393 (gpointer)ev_window);
3395 current_page = ev_document_model_get_page (ev_window->priv->model);
3396 document_last_page = ev_document_get_n_pages (ev_window->priv->document);
3398 print_settings_file = get_print_settings_file ();
3400 print_settings = get_print_settings (print_settings_file);
3401 ev_window_load_print_settings_from_metadata (ev_window, print_settings);
3403 print_page_setup = get_print_page_setup (print_settings_file);
3404 ev_window_load_print_page_setup_from_metadata (ev_window, print_page_setup);
3406 if (first_page != 1 || last_page != document_last_page) {
3409 /* Ranges in GtkPrint are 0 - N */
3410 range.start = first_page - 1;
3411 range.end = last_page - 1;
3413 gtk_print_settings_set_print_pages (print_settings,
3414 GTK_PRINT_PAGES_RANGES);
3415 gtk_print_settings_set_page_ranges (print_settings,
3419 ev_print_operation_set_job_name (op, gtk_window_get_title (GTK_WINDOW (ev_window)));
3420 ev_print_operation_set_current_page (op, current_page);
3421 ev_print_operation_set_print_settings (op, print_settings);
3422 ev_print_operation_set_default_page_setup (op, print_page_setup);
3423 embed_page_setup = ev_window->priv->lockdown_settings ?
3424 !g_settings_get_boolean (ev_window->priv->lockdown_settings,
3425 GS_LOCKDOWN_PRINT_SETUP) :
3427 ev_print_operation_set_embed_page_setup (op, embed_page_setup);
3429 g_object_unref (print_settings);
3430 g_object_unref (print_page_setup);
3431 g_key_file_free (print_settings_file);
3433 ev_print_operation_run (op, GTK_WINDOW (ev_window));
3437 ev_window_print (EvWindow *window)
3439 ev_window_print_range (window, 1,
3440 ev_document_get_n_pages (window->priv->document));
3444 ev_window_cmd_file_print (GtkAction *action, EvWindow *ev_window)
3446 ev_window_print (ev_window);
3450 ev_window_cmd_file_properties (GtkAction *action, EvWindow *ev_window)
3452 if (ev_window->priv->properties == NULL) {
3453 ev_window->priv->properties = ev_properties_dialog_new ();
3454 ev_properties_dialog_set_document (EV_PROPERTIES_DIALOG (ev_window->priv->properties),
3455 ev_window->priv->uri,
3456 ev_window->priv->document);
3457 g_object_add_weak_pointer (G_OBJECT (ev_window->priv->properties),
3458 (gpointer) &(ev_window->priv->properties));
3459 gtk_window_set_transient_for (GTK_WINDOW (ev_window->priv->properties),
3460 GTK_WINDOW (ev_window));
3463 ev_document_fc_mutex_lock ();
3464 gtk_widget_show (ev_window->priv->properties);
3465 ev_document_fc_mutex_unlock ();
3469 document_modified_confirmation_dialog_response (GtkDialog *dialog,
3471 EvWindow *ev_window)
3473 gtk_widget_destroy (GTK_WIDGET (dialog));
3476 case GTK_RESPONSE_YES:
3477 ev_window_cmd_save_as (NULL, ev_window);
3479 case GTK_RESPONSE_NO:
3480 gtk_widget_destroy (GTK_WIDGET (ev_window));
3482 case GTK_RESPONSE_CANCEL:
3489 ev_window_check_document_modified (EvWindow *ev_window)
3491 EvDocument *document = ev_window->priv->document;
3493 gchar *text, *markup;
3494 const gchar *secondary_text;
3499 if (EV_IS_DOCUMENT_FORMS (document) &&
3500 ev_document_forms_document_is_modified (EV_DOCUMENT_FORMS (document))) {
3501 secondary_text = _("Document contains form fields that have been filled out. "
3502 "If you don't save a copy, changes will be permanently lost.");
3503 } else if (EV_IS_DOCUMENT_ANNOTATIONS (document) &&
3504 ev_document_annotations_document_is_modified (EV_DOCUMENT_ANNOTATIONS (document))) {
3505 secondary_text = _("Document contains new or modified annotations. "
3506 "If you don't save a copy, changes will be permanently lost.");
3512 text = g_markup_printf_escaped (_("Save a copy of document “%s” before closing?"),
3513 gtk_window_get_title (GTK_WINDOW (ev_window)));
3515 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
3517 GTK_MESSAGE_QUESTION,
3521 markup = g_strdup_printf ("<b>%s</b>", text);
3524 gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), markup);
3527 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
3528 "%s", secondary_text);
3530 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
3531 _("Close _without Saving"),
3534 GTK_RESPONSE_CANCEL,
3538 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
3539 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
3542 GTK_RESPONSE_CANCEL,
3545 g_signal_connect (dialog, "response",
3546 G_CALLBACK (document_modified_confirmation_dialog_response),
3548 gtk_widget_show (dialog);
3554 print_jobs_confirmation_dialog_response (GtkDialog *dialog,
3556 EvWindow *ev_window)
3558 gtk_widget_destroy (GTK_WIDGET (dialog));
3561 case GTK_RESPONSE_YES:
3562 if (!ev_window->priv->print_queue ||
3563 g_queue_is_empty (ev_window->priv->print_queue))
3564 gtk_widget_destroy (GTK_WIDGET (ev_window));
3566 ev_window->priv->close_after_print = TRUE;
3568 case GTK_RESPONSE_NO:
3569 ev_window->priv->close_after_print = TRUE;
3570 if (ev_window->priv->print_queue &&
3571 !g_queue_is_empty (ev_window->priv->print_queue)) {
3572 gtk_widget_set_sensitive (GTK_WIDGET (ev_window), FALSE);
3573 ev_window_print_cancel (ev_window);
3575 gtk_widget_destroy (GTK_WIDGET (ev_window));
3578 case GTK_RESPONSE_CANCEL:
3580 ev_window->priv->close_after_print = FALSE;
3585 ev_window_check_print_queue (EvWindow *ev_window)
3588 gchar *text, *markup;
3591 n_print_jobs = ev_window->priv->print_queue ?
3592 g_queue_get_length (ev_window->priv->print_queue) : 0;
3594 if (n_print_jobs == 0)
3597 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
3599 GTK_MESSAGE_QUESTION,
3602 if (n_print_jobs == 1) {
3603 EvPrintOperation *op;
3604 const gchar *job_name;
3606 op = g_queue_peek_tail (ev_window->priv->print_queue);
3607 job_name = ev_print_operation_get_job_name (op);
3609 text = g_strdup_printf (_("Wait until print job “%s” finishes before closing?"),
3612 text = g_strdup_printf (_("There are %d print jobs active. "
3613 "Wait until print finishes before closing?"),
3617 markup = g_strdup_printf ("<b>%s</b>", text);
3620 gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), markup);
3623 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s",
3624 _("If you close the window, pending print "
3625 "jobs will not be printed."));
3627 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
3628 _("Cancel _print and Close"),
3631 GTK_RESPONSE_CANCEL,
3632 _("Close _after Printing"),
3635 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
3636 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
3639 GTK_RESPONSE_CANCEL,
3642 g_signal_connect (dialog, "response",
3643 G_CALLBACK (print_jobs_confirmation_dialog_response),
3645 gtk_widget_show (dialog);
3651 ev_window_close (EvWindow *ev_window)
3653 if (EV_WINDOW_IS_PRESENTATION (ev_window)) {
3656 /* Save current page */
3657 current_page = ev_view_presentation_get_current_page (
3658 EV_VIEW_PRESENTATION (ev_window->priv->presentation_view));
3659 ev_document_model_set_page (ev_window->priv->model, current_page);
3662 if (ev_window_check_document_modified (ev_window))
3665 if (ev_window_check_print_queue (ev_window))
3672 ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window)
3674 if (ev_window_close (ev_window))
3675 gtk_widget_destroy (GTK_WIDGET (ev_window));
3679 ev_window_cmd_focus_page_selector (GtkAction *act, EvWindow *window)
3683 update_chrome_flag (window, EV_CHROME_RAISE_TOOLBAR, TRUE);
3684 ev_window_set_action_sensitive (window, "ViewToolbar", FALSE);
3685 update_chrome_visibility (window);
3687 action = gtk_action_group_get_action (window->priv->action_group,
3688 PAGE_SELECTOR_ACTION);
3689 ev_page_action_grab_focus (EV_PAGE_ACTION (action));
3693 ev_window_cmd_scroll_forward (GtkAction *action, EvWindow *window)
3695 ev_view_scroll (EV_VIEW (window->priv->view), GTK_SCROLL_PAGE_FORWARD, FALSE);
3699 ev_window_cmd_scroll_backward (GtkAction *action, EvWindow *window)
3701 ev_view_scroll (EV_VIEW (window->priv->view), GTK_SCROLL_PAGE_BACKWARD, FALSE);
3705 ev_window_cmd_continuous (GtkAction *action, EvWindow *ev_window)
3707 gboolean continuous;
3709 ev_window_stop_presentation (ev_window, TRUE);
3710 continuous = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
3711 ev_document_model_set_continuous (ev_window->priv->model, continuous);
3715 ev_window_cmd_dual (GtkAction *action, EvWindow *ev_window)
3719 ev_window_stop_presentation (ev_window, TRUE);
3720 dual_page = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
3721 ev_document_model_set_dual_page (ev_window->priv->model, dual_page);
3725 ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window)
3727 ev_window_stop_presentation (ev_window, TRUE);
3729 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
3730 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_BEST_FIT);
3732 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FREE);
3734 ev_window_update_actions (ev_window);
3738 ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window)
3740 ev_window_stop_presentation (ev_window, TRUE);
3742 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
3743 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FIT_WIDTH);
3745 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FREE);
3747 ev_window_update_actions (ev_window);
3752 ev_window_cmd_edit_select_all (GtkAction *action, EvWindow *ev_window)
3754 g_return_if_fail (EV_IS_WINDOW (ev_window));
3756 ev_view_select_all (EV_VIEW (ev_window->priv->view));
3760 ev_window_cmd_edit_find (GtkAction *action, EvWindow *ev_window)
3762 g_return_if_fail (EV_IS_WINDOW (ev_window));
3764 if (ev_window->priv->document == NULL || !EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
3765 g_error ("Find action should be insensitive since document doesn't support find");
3769 update_chrome_flag (ev_window, EV_CHROME_FINDBAR, TRUE);
3770 update_chrome_visibility (ev_window);
3771 gtk_widget_grab_focus (ev_window->priv->find_bar);
3775 ev_window_cmd_edit_find_next (GtkAction *action, EvWindow *ev_window)
3777 g_return_if_fail (EV_IS_WINDOW (ev_window));
3779 update_chrome_flag (ev_window, EV_CHROME_FINDBAR, TRUE);
3780 update_chrome_visibility (ev_window);
3781 gtk_widget_grab_focus (ev_window->priv->find_bar);
3782 ev_view_find_next (EV_VIEW (ev_window->priv->view));
3786 ev_window_cmd_edit_find_previous (GtkAction *action, EvWindow *ev_window)
3788 g_return_if_fail (EV_IS_WINDOW (ev_window));
3790 update_chrome_flag (ev_window, EV_CHROME_FINDBAR, TRUE);
3791 update_chrome_visibility (ev_window);
3792 gtk_widget_grab_focus (ev_window->priv->find_bar);
3793 ev_view_find_previous (EV_VIEW (ev_window->priv->view));
3797 ev_window_cmd_edit_copy (GtkAction *action, EvWindow *ev_window)
3799 g_return_if_fail (EV_IS_WINDOW (ev_window));
3801 ev_view_copy (EV_VIEW (ev_window->priv->view));
3805 ev_window_sidebar_position_change_cb (GObject *object,
3807 EvWindow *ev_window)
3809 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window))
3810 ev_metadata_set_int (ev_window->priv->metadata, "sidebar_size",
3811 gtk_paned_get_position (GTK_PANED (object)));
3815 ev_window_update_fullscreen_action (EvWindow *window)
3819 action = gtk_action_group_get_action (window->priv->action_group, "ViewFullscreen");
3820 g_signal_handlers_block_by_func
3821 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
3822 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
3823 ev_document_model_get_fullscreen (window->priv->model));
3824 g_signal_handlers_unblock_by_func
3825 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
3829 fullscreen_toolbar_setup_item_properties (GtkUIManager *ui_manager)
3833 item = gtk_ui_manager_get_widget (ui_manager, "/FullscreenToolbar/GoPreviousPage");
3834 g_object_set (item, "is-important", FALSE, NULL);
3836 item = gtk_ui_manager_get_widget (ui_manager, "/FullscreenToolbar/GoNextPage");
3837 g_object_set (item, "is-important", FALSE, NULL);
3839 item = gtk_ui_manager_get_widget (ui_manager, "/FullscreenToolbar/StartPresentation");
3840 g_object_set (item, "is-important", TRUE, NULL);
3842 item = gtk_ui_manager_get_widget (ui_manager, "/FullscreenToolbar/LeaveFullscreen");
3843 g_object_set (item, "is-important", TRUE, NULL);
3847 fullscreen_toolbar_remove_shadow (GtkWidget *toolbar)
3849 GtkCssProvider *provider;
3851 gtk_widget_set_name (toolbar, "ev-fullscreen-toolbar");
3853 provider = gtk_css_provider_new ();
3854 gtk_css_provider_load_from_data (provider,
3855 "#ev-fullscreen-toolbar {\n"
3856 " -GtkToolbar-shadow-type: none; }",
3858 gtk_style_context_add_provider (gtk_widget_get_style_context (toolbar),
3859 GTK_STYLE_PROVIDER (provider),
3860 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
3861 g_object_unref (provider);
3865 ev_window_run_fullscreen (EvWindow *window)
3867 gboolean fullscreen_window = TRUE;
3869 if (ev_document_model_get_fullscreen (window->priv->model))
3872 if (!window->priv->fullscreen_toolbar) {
3873 window->priv->fullscreen_toolbar =
3874 gtk_ui_manager_get_widget (window->priv->ui_manager,
3875 "/FullscreenToolbar");
3877 gtk_toolbar_set_style (GTK_TOOLBAR (window->priv->fullscreen_toolbar),
3878 GTK_TOOLBAR_BOTH_HORIZ);
3879 fullscreen_toolbar_remove_shadow (window->priv->fullscreen_toolbar);
3880 fullscreen_toolbar_setup_item_properties (window->priv->ui_manager);
3882 gtk_box_pack_start (GTK_BOX (window->priv->main_box),
3883 window->priv->fullscreen_toolbar,
3885 gtk_box_reorder_child (GTK_BOX (window->priv->main_box),
3886 window->priv->fullscreen_toolbar, 1);
3889 if (EV_WINDOW_IS_PRESENTATION (window)) {
3890 ev_window_stop_presentation (window, FALSE);
3891 fullscreen_window = FALSE;
3894 g_object_set (G_OBJECT (window->priv->scrolled_window),
3895 "shadow-type", GTK_SHADOW_NONE,
3898 ev_document_model_set_fullscreen (window->priv->model, TRUE);
3899 ev_window_update_fullscreen_action (window);
3901 /* If the user doesn't have the main toolbar he/she won't probably want
3902 * the toolbar in fullscreen mode. See bug #483048
3904 update_chrome_flag (window, EV_CHROME_FULLSCREEN_TOOLBAR,
3905 (window->priv->chrome & EV_CHROME_TOOLBAR) != 0);
3906 update_chrome_visibility (window);
3908 if (fullscreen_window)
3909 gtk_window_fullscreen (GTK_WINDOW (window));
3910 gtk_widget_grab_focus (window->priv->view);
3912 if (window->priv->metadata && !ev_window_is_empty (window))
3913 ev_metadata_set_boolean (window->priv->metadata, "fullscreen", TRUE);
3917 ev_window_stop_fullscreen (EvWindow *window,
3918 gboolean unfullscreen_window)
3920 if (!ev_document_model_get_fullscreen (window->priv->model))
3923 g_object_set (G_OBJECT (window->priv->scrolled_window),
3924 "shadow-type", GTK_SHADOW_IN,
3927 ev_document_model_set_fullscreen (window->priv->model, FALSE);
3928 ev_window_update_fullscreen_action (window);
3929 update_chrome_flag (window, EV_CHROME_FULLSCREEN_TOOLBAR, FALSE);
3930 update_chrome_visibility (window);
3931 if (unfullscreen_window)
3932 gtk_window_unfullscreen (GTK_WINDOW (window));
3934 if (window->priv->metadata && !ev_window_is_empty (window))
3935 ev_metadata_set_boolean (window->priv->metadata, "fullscreen", FALSE);
3939 ev_window_cmd_view_fullscreen (GtkAction *action, EvWindow *window)
3941 gboolean fullscreen;
3943 fullscreen = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
3945 ev_window_run_fullscreen (window);
3947 ev_window_stop_fullscreen (window, TRUE);
3952 ev_window_update_presentation_action (EvWindow *window)
3956 action = gtk_action_group_get_action (window->priv->action_group, "ViewPresentation");
3957 g_signal_handlers_block_by_func
3958 (action, G_CALLBACK (ev_window_cmd_view_presentation), window);
3959 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
3960 EV_WINDOW_IS_PRESENTATION (window));
3961 g_signal_handlers_unblock_by_func
3962 (action, G_CALLBACK (ev_window_cmd_view_presentation), window);
3966 ev_window_view_presentation_finished (EvWindow *window)
3968 ev_window_stop_presentation (window, TRUE);
3972 ev_window_run_presentation (EvWindow *window)
3974 gboolean fullscreen_window = TRUE;
3977 gboolean inverted_colors;
3979 if (EV_WINDOW_IS_PRESENTATION (window))
3982 if (ev_document_model_get_fullscreen (window->priv->model)) {
3983 ev_window_stop_fullscreen (window, FALSE);
3984 fullscreen_window = FALSE;
3987 current_page = ev_document_model_get_page (window->priv->model);
3988 rotation = ev_document_model_get_rotation (window->priv->model);
3989 inverted_colors = ev_document_model_get_inverted_colors (window->priv->model);
3990 window->priv->presentation_view = ev_view_presentation_new (window->priv->document,
3994 g_signal_connect_swapped (window->priv->presentation_view, "finished",
3995 G_CALLBACK (ev_window_view_presentation_finished),
3997 g_signal_connect_swapped (window->priv->presentation_view, "external-link",
3998 G_CALLBACK (view_external_link_cb),
4001 gtk_box_pack_start (GTK_BOX (window->priv->main_box),
4002 window->priv->presentation_view,
4005 gtk_widget_hide (window->priv->hpaned);
4006 ev_window_update_presentation_action (window);
4007 update_chrome_visibility (window);
4009 gtk_widget_grab_focus (window->priv->presentation_view);
4010 if (fullscreen_window)
4011 gtk_window_fullscreen (GTK_WINDOW (window));
4013 gtk_widget_show (window->priv->presentation_view);
4015 ev_application_screensaver_disable (EV_APP);
4017 if (window->priv->metadata && !ev_window_is_empty (window))
4018 ev_metadata_set_boolean (window->priv->metadata, "presentation", TRUE);
4022 ev_window_stop_presentation (EvWindow *window,
4023 gboolean unfullscreen_window)
4027 if (!EV_WINDOW_IS_PRESENTATION (window))
4030 current_page = ev_view_presentation_get_current_page (EV_VIEW_PRESENTATION (window->priv->presentation_view));
4031 ev_document_model_set_page (window->priv->model, current_page);
4033 gtk_container_remove (GTK_CONTAINER (window->priv->main_box),
4034 window->priv->presentation_view);
4035 window->priv->presentation_view = NULL;
4037 gtk_widget_show (window->priv->hpaned);
4038 ev_window_update_presentation_action (window);
4039 update_chrome_visibility (window);
4040 if (unfullscreen_window)
4041 gtk_window_unfullscreen (GTK_WINDOW (window));
4043 gtk_widget_grab_focus (window->priv->view);
4045 ev_application_screensaver_enable (EV_APP);
4047 if (window->priv->metadata && !ev_window_is_empty (window))
4048 ev_metadata_set_boolean (window->priv->metadata, "presentation", FALSE);
4052 ev_window_cmd_view_presentation (GtkAction *action, EvWindow *window)
4054 gboolean presentation;
4056 presentation = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
4058 ev_window_run_presentation (window);
4063 ev_window_setup_gtk_settings (EvWindow *window)
4065 GtkSettings *settings;
4067 gchar *menubar_accel_accel;
4069 screen = gtk_window_get_screen (GTK_WINDOW (window));
4070 settings = gtk_settings_get_for_screen (screen);
4072 g_object_get (settings,
4073 "gtk-menu-bar-accel", &menubar_accel_accel,
4075 if (menubar_accel_accel != NULL && menubar_accel_accel[0] != '\0') {
4076 gtk_accelerator_parse (menubar_accel_accel,
4077 &window->priv->menubar_accel_keyval,
4078 &window->priv->menubar_accel_modifier);
4079 if (window->priv->menubar_accel_keyval == 0) {
4080 g_warning ("Failed to parse menu bar accelerator '%s'\n",
4081 menubar_accel_accel);
4084 window->priv->menubar_accel_keyval = 0;
4085 window->priv->menubar_accel_modifier = 0;
4088 g_free (menubar_accel_accel);
4092 ev_window_update_max_min_scale (EvWindow *window)
4096 gdouble min_width, min_height;
4097 gdouble width, height;
4099 gint rotation = ev_document_model_get_rotation (window->priv->model);
4101 if (!window->priv->document)
4104 dpi = get_screen_dpi (window) / 72.0;
4106 ev_document_get_min_page_size (window->priv->document, &min_width, &min_height);
4107 width = (rotation == 0 || rotation == 180) ? min_width : min_height;
4108 height = (rotation == 0 || rotation == 180) ? min_height : min_width;
4109 max_scale = sqrt (PAGE_CACHE_SIZE / (width * dpi * 4 * height * dpi));
4111 action = gtk_action_group_get_action (window->priv->action_group,
4112 ZOOM_CONTROL_ACTION);
4113 ephy_zoom_action_set_max_zoom_level (EPHY_ZOOM_ACTION (action), max_scale * dpi);
4115 ev_document_model_set_min_scale (window->priv->model, MIN_SCALE * dpi);
4116 ev_document_model_set_max_scale (window->priv->model, max_scale * dpi);
4120 ev_window_screen_changed (GtkWidget *widget,
4121 GdkScreen *old_screen)
4123 EvWindow *window = EV_WINDOW (widget);
4126 screen = gtk_widget_get_screen (widget);
4127 if (screen == old_screen)
4130 ev_window_setup_gtk_settings (window);
4131 ev_window_update_max_min_scale (window);
4133 if (GTK_WIDGET_CLASS (ev_window_parent_class)->screen_changed) {
4134 GTK_WIDGET_CLASS (ev_window_parent_class)->screen_changed (widget, old_screen);
4139 ev_window_state_event (GtkWidget *widget,
4140 GdkEventWindowState *event)
4142 EvWindow *window = EV_WINDOW (widget);
4144 if (GTK_WIDGET_CLASS (ev_window_parent_class)->window_state_event) {
4145 GTK_WIDGET_CLASS (ev_window_parent_class)->window_state_event (widget, event);
4148 if ((event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN) == 0)
4151 if (event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN) {
4152 if (ev_document_model_get_fullscreen (window->priv->model) || EV_WINDOW_IS_PRESENTATION (window))
4155 ev_window_run_fullscreen (window);
4157 if (ev_document_model_get_fullscreen (window->priv->model))
4158 ev_window_stop_fullscreen (window, FALSE);
4159 else if (EV_WINDOW_IS_PRESENTATION (window))
4160 ev_window_stop_presentation (window, FALSE);
4167 ev_window_set_page_mode (EvWindow *window,
4168 EvWindowPageMode page_mode)
4170 GtkWidget *child = NULL;
4171 GtkWidget *real_child;
4173 if (window->priv->page_mode == page_mode)
4176 window->priv->page_mode = page_mode;
4178 switch (page_mode) {
4179 case PAGE_MODE_DOCUMENT:
4180 child = window->priv->view;
4182 case PAGE_MODE_PASSWORD:
4183 child = window->priv->password_view;
4186 g_assert_not_reached ();
4189 real_child = gtk_bin_get_child (GTK_BIN (window->priv->scrolled_window));
4190 if (child != real_child) {
4191 gtk_container_remove (GTK_CONTAINER (window->priv->scrolled_window),
4193 gtk_container_add (GTK_CONTAINER (window->priv->scrolled_window),
4196 ev_window_update_actions (window);
4201 ev_window_cmd_edit_rotate_left (GtkAction *action, EvWindow *ev_window)
4203 gint rotation = ev_document_model_get_rotation (ev_window->priv->model);
4205 ev_document_model_set_rotation (ev_window->priv->model, rotation - 90);
4209 ev_window_cmd_edit_rotate_right (GtkAction *action, EvWindow *ev_window)
4211 gint rotation = ev_document_model_get_rotation (ev_window->priv->model);
4213 ev_document_model_set_rotation (ev_window->priv->model, rotation + 90);
4217 ev_window_cmd_view_inverted_colors (GtkAction *action, EvWindow *ev_window)
4219 gboolean inverted_colors = ev_document_model_get_inverted_colors (ev_window->priv->model);
4221 ev_document_model_set_inverted_colors (ev_window->priv->model, !inverted_colors);
4225 ev_window_cmd_edit_toolbar_cb (GtkDialog *dialog,
4227 EvWindow *ev_window)
4229 EggEditableToolbar *toolbar;
4230 gchar *toolbars_file;
4232 toolbar = EGG_EDITABLE_TOOLBAR (ev_window->priv->toolbar);
4233 egg_editable_toolbar_set_edit_mode (toolbar, FALSE);
4235 toolbars_file = g_build_filename (ev_application_get_dot_dir (EV_APP, TRUE),
4236 "evince_toolbar.xml", NULL);
4237 egg_toolbars_model_save_toolbars (egg_editable_toolbar_get_model (toolbar),
4238 toolbars_file, "1.0");
4239 g_free (toolbars_file);
4241 gtk_widget_destroy (GTK_WIDGET (dialog));
4245 ev_window_cmd_edit_toolbar (GtkAction *action, EvWindow *ev_window)
4249 GtkWidget *content_area;
4250 EggEditableToolbar *toolbar;
4252 dialog = gtk_dialog_new_with_buttons (_("Toolbar Editor"),
4253 GTK_WINDOW (ev_window),
4254 GTK_DIALOG_DESTROY_WITH_PARENT,
4258 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
4259 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE);
4260 gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)), 5);
4261 gtk_box_set_spacing (GTK_BOX (content_area), 2);
4262 gtk_window_set_default_size (GTK_WINDOW (dialog), 500, 400);
4264 toolbar = EGG_EDITABLE_TOOLBAR (ev_window->priv->toolbar);
4265 editor = egg_toolbar_editor_new (ev_window->priv->ui_manager,
4266 egg_editable_toolbar_get_model (toolbar));
4268 gtk_container_set_border_width (GTK_CONTAINER (editor), 5);
4269 gtk_box_set_spacing (GTK_BOX (EGG_TOOLBAR_EDITOR (editor)), 5);
4271 gtk_container_add (GTK_CONTAINER (content_area), editor);
4273 egg_editable_toolbar_set_edit_mode (toolbar, TRUE);
4275 g_signal_connect (dialog, "response",
4276 G_CALLBACK (ev_window_cmd_edit_toolbar_cb),
4278 gtk_widget_show_all (dialog);
4282 ev_window_cmd_edit_save_settings (GtkAction *action, EvWindow *ev_window)
4284 EvWindowPrivate *priv = ev_window->priv;
4285 EvDocumentModel *model = priv->model;
4286 GSettings *settings = priv->default_settings;
4288 g_settings_set_boolean (settings, "continuous",
4289 ev_document_model_get_continuous (model));
4290 g_settings_set_boolean (settings, "dual-page",
4291 ev_document_model_get_dual_page (model));
4292 g_settings_set_boolean (settings, "fullscreen",
4293 ev_document_model_get_fullscreen (model));
4294 g_settings_set_boolean (settings, "inverted-colors",
4295 ev_document_model_get_inverted_colors (model));
4296 g_settings_set_enum (settings, "sizing-mode",
4297 ev_document_model_get_sizing_mode (model));
4298 g_settings_set_boolean (settings, "show-toolbar",
4299 gtk_widget_get_visible (priv->toolbar));
4300 g_settings_set_boolean (settings, "show-sidebar",
4301 gtk_widget_get_visible (priv->sidebar));
4302 g_settings_set_int (settings, "sidebar-size",
4303 gtk_paned_get_position (GTK_PANED (priv->hpaned)));
4304 g_settings_set_string (settings, "sidebar-page",
4305 ev_window_sidebar_get_current_page_id (ev_window));
4306 g_settings_apply (settings);
4310 ev_window_cmd_view_zoom_in (GtkAction *action, EvWindow *ev_window)
4312 g_return_if_fail (EV_IS_WINDOW (ev_window));
4314 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FREE);
4315 ev_view_zoom_in (EV_VIEW (ev_window->priv->view));
4319 ev_window_cmd_view_zoom_out (GtkAction *action, EvWindow *ev_window)
4321 g_return_if_fail (EV_IS_WINDOW (ev_window));
4323 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FREE);
4324 ev_view_zoom_out (EV_VIEW (ev_window->priv->view));
4328 ev_window_cmd_go_previous_page (GtkAction *action, EvWindow *ev_window)
4330 g_return_if_fail (EV_IS_WINDOW (ev_window));
4332 ev_view_previous_page (EV_VIEW (ev_window->priv->view));
4336 ev_window_cmd_go_next_page (GtkAction *action, EvWindow *ev_window)
4338 g_return_if_fail (EV_IS_WINDOW (ev_window));
4340 ev_view_next_page (EV_VIEW (ev_window->priv->view));
4344 ev_window_cmd_go_first_page (GtkAction *action, EvWindow *ev_window)
4346 g_return_if_fail (EV_IS_WINDOW (ev_window));
4348 ev_document_model_set_page (ev_window->priv->model, 0);
4352 ev_window_cmd_go_last_page (GtkAction *action, EvWindow *ev_window)
4354 g_return_if_fail (EV_IS_WINDOW (ev_window));
4356 ev_document_model_set_page (ev_window->priv->model,
4357 ev_document_get_n_pages (ev_window->priv->document) - 1);
4361 ev_window_cmd_go_forward (GtkAction *action, EvWindow *ev_window)
4363 int n_pages, current_page;
4365 g_return_if_fail (EV_IS_WINDOW (ev_window));
4367 n_pages = ev_document_get_n_pages (ev_window->priv->document);
4368 current_page = ev_document_model_get_page (ev_window->priv->model);
4370 if (current_page + 10 < n_pages) {
4371 ev_document_model_set_page (ev_window->priv->model, current_page + 10);
4376 ev_window_cmd_go_backward (GtkAction *action, EvWindow *ev_window)
4380 g_return_if_fail (EV_IS_WINDOW (ev_window));
4382 current_page = ev_document_model_get_page (ev_window->priv->model);
4384 if (current_page - 10 >= 0) {
4385 ev_document_model_set_page (ev_window->priv->model, current_page - 10);
4390 ev_window_cmd_bookmark_activate (GtkAction *action,
4393 guint page = ev_bookmark_action_get_page (EV_BOOKMARK_ACTION (action));
4395 ev_document_model_set_page (window->priv->model, page);
4399 compare_bookmarks (EvBookmark *a,
4402 return strcmp (a->title, b->title);
4406 ev_window_setup_bookmarks (EvWindow *window)
4410 if (!window->priv->bookmarks)
4413 if (window->priv->bookmarks_ui_id > 0) {
4414 gtk_ui_manager_remove_ui (window->priv->ui_manager,
4415 window->priv->bookmarks_ui_id);
4416 gtk_ui_manager_ensure_update (window->priv->ui_manager);
4418 window->priv->bookmarks_ui_id = gtk_ui_manager_new_merge_id (window->priv->ui_manager);
4420 if (window->priv->bookmarks_action_group) {
4421 gtk_ui_manager_remove_action_group (window->priv->ui_manager,
4422 window->priv->bookmarks_action_group);
4423 g_object_unref (window->priv->bookmarks_action_group);
4425 window->priv->bookmarks_action_group = gtk_action_group_new ("BookmarksActions");
4426 gtk_ui_manager_insert_action_group (window->priv->ui_manager,
4427 window->priv->bookmarks_action_group, -1);
4429 items = ev_bookmarks_get_bookmarks (window->priv->bookmarks);
4430 items = g_list_sort (items, (GCompareFunc)compare_bookmarks);
4432 for (l = items; l && l->data; l = g_list_next (l)) {
4433 EvBookmark *bm = (EvBookmark *)l->data;
4436 action = ev_bookmark_action_new (bm);
4437 g_signal_connect (action, "activate",
4438 G_CALLBACK (ev_window_cmd_bookmark_activate),
4440 gtk_action_group_add_action (window->priv->bookmarks_action_group,
4443 gtk_ui_manager_add_ui (window->priv->ui_manager,
4444 window->priv->bookmarks_ui_id,
4445 "/MainMenu/BookmarksMenu/BookmarksItems",
4446 gtk_action_get_label (action),
4447 gtk_action_get_name (action),
4448 GTK_UI_MANAGER_MENUITEM,
4451 g_object_unref (action);
4454 g_list_free (items);
4458 ev_window_cmd_bookmarks_add (GtkAction *action,
4465 bm.page = ev_document_model_get_page (window->priv->model);
4466 page_label = ev_document_get_page_label (window->priv->document, bm.page);
4467 page_title = ev_window_get_page_title (window, page_label);
4468 bm.title = page_title ? page_title : g_strdup_printf (_("Page %s"), page_label);
4469 g_free (page_label);
4471 /* EvBookmarks takes ownership of bookmark */
4472 ev_bookmarks_add (window->priv->bookmarks, &bm);
4476 ev_window_cmd_view_reload (GtkAction *action, EvWindow *ev_window)
4478 ev_window_reload_document (ev_window, NULL);
4482 ev_window_cmd_view_autoscroll (GtkAction *action, EvWindow *ev_window)
4484 ev_view_autoscroll_start (EV_VIEW (ev_window->priv->view));
4487 #if OFFLINE_HELP_ENABLED
4488 #define EV_HELP "ghelp:evince"
4490 #define EV_HELP "http://library.gnome.org/users/evince/stable/"
4494 ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
4496 GError *error = NULL;
4498 gtk_show_uri (gtk_window_get_screen (GTK_WINDOW (ev_window)),
4500 gtk_get_current_event_time (),
4503 ev_window_error_message (ev_window, error,
4504 "%s", _("There was an error displaying help"));
4505 g_error_free (error);
4510 ev_window_cmd_leave_fullscreen (GtkAction *action, EvWindow *window)
4512 ev_window_stop_fullscreen (window, TRUE);
4516 ev_window_cmd_start_presentation (GtkAction *action, EvWindow *window)
4518 ev_window_run_presentation (window);
4522 ev_window_cmd_escape (GtkAction *action, EvWindow *window)
4526 ev_view_autoscroll_stop (EV_VIEW (window->priv->view));
4528 widget = gtk_window_get_focus (GTK_WINDOW (window));
4529 if (widget && gtk_widget_get_ancestor (widget, EGG_TYPE_FIND_BAR)) {
4530 update_chrome_flag (window, EV_CHROME_FINDBAR, FALSE);
4531 update_chrome_visibility (window);
4532 gtk_widget_grab_focus (window->priv->view);
4534 gboolean fullscreen;
4536 fullscreen = ev_document_model_get_fullscreen (window->priv->model);
4539 ev_window_stop_fullscreen (window, TRUE);
4540 } else if (EV_WINDOW_IS_PRESENTATION (window)) {
4541 ev_window_stop_presentation (window, TRUE);
4542 gtk_widget_grab_focus (window->priv->view);
4544 gtk_widget_grab_focus (window->priv->view);
4547 if (fullscreen && EV_WINDOW_IS_PRESENTATION (window))
4548 g_warning ("Both fullscreen and presentation set somehow");
4553 save_sizing_mode (EvWindow *window)
4556 GEnumValue *enum_value;
4558 if (!window->priv->metadata || ev_window_is_empty (window))
4561 mode = ev_document_model_get_sizing_mode (window->priv->model);
4562 enum_value = g_enum_get_value (g_type_class_peek (EV_TYPE_SIZING_MODE), mode);
4563 ev_metadata_set_string (window->priv->metadata, "sizing_mode",
4564 enum_value->value_nick);
4568 ev_window_document_changed_cb (EvDocumentModel *model,
4570 EvWindow *ev_window)
4572 ev_window_set_document (ev_window,
4573 ev_document_model_get_document (model));
4577 ev_window_sizing_mode_changed_cb (EvDocumentModel *model,
4579 EvWindow *ev_window)
4581 EvSizingMode sizing_mode = ev_document_model_get_sizing_mode (model);
4583 g_object_set (ev_window->priv->scrolled_window,
4584 "hscrollbar-policy",
4585 sizing_mode == EV_SIZING_FREE ?
4586 GTK_POLICY_AUTOMATIC : GTK_POLICY_NEVER,
4587 "vscrollbar-policy", GTK_POLICY_AUTOMATIC,
4590 update_sizing_buttons (ev_window);
4591 save_sizing_mode (ev_window);
4595 ev_window_zoom_changed_cb (EvDocumentModel *model, GParamSpec *pspec, EvWindow *ev_window)
4597 ev_window_update_actions (ev_window);
4599 if (!ev_window->priv->metadata)
4602 if (ev_document_model_get_sizing_mode (model) == EV_SIZING_FREE && !ev_window_is_empty (ev_window)) {
4605 zoom = ev_document_model_get_scale (model);
4606 zoom *= 72.0 / get_screen_dpi (ev_window);
4607 ev_metadata_set_double (ev_window->priv->metadata, "zoom", zoom);
4612 ev_window_update_continuous_action (EvWindow *window)
4616 action = gtk_action_group_get_action (window->priv->action_group, "ViewContinuous");
4617 g_signal_handlers_block_by_func
4618 (action, G_CALLBACK (ev_window_cmd_continuous), window);
4619 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
4620 ev_document_model_get_continuous (window->priv->model));
4621 g_signal_handlers_unblock_by_func
4622 (action, G_CALLBACK (ev_window_cmd_continuous), window);
4626 ev_window_update_dual_page_action (EvWindow *window)
4630 action = gtk_action_group_get_action (window->priv->action_group, "ViewDual");
4631 g_signal_handlers_block_by_func
4632 (action, G_CALLBACK (ev_window_cmd_dual), window);
4633 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
4634 ev_document_model_get_dual_page (window->priv->model));
4635 g_signal_handlers_unblock_by_func
4636 (action, G_CALLBACK (ev_window_cmd_dual), window);
4640 ev_window_continuous_changed_cb (EvDocumentModel *model,
4642 EvWindow *ev_window)
4644 ev_window_update_continuous_action (ev_window);
4646 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window))
4647 ev_metadata_set_boolean (ev_window->priv->metadata, "continuous",
4648 ev_document_model_get_continuous (model));
4652 ev_window_rotation_changed_cb (EvDocumentModel *model,
4656 gint rotation = ev_document_model_get_rotation (model);
4658 if (window->priv->metadata && !ev_window_is_empty (window))
4659 ev_metadata_set_int (window->priv->metadata, "rotation",
4662 ev_window_update_max_min_scale (window);
4663 ev_window_refresh_window_thumbnail (window);
4667 ev_window_update_inverted_colors_action (EvWindow *window)
4671 action = gtk_action_group_get_action (window->priv->action_group, "ViewInvertedColors");
4672 g_signal_handlers_block_by_func
4673 (action, G_CALLBACK (ev_window_cmd_view_inverted_colors), window);
4674 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
4675 ev_document_model_get_inverted_colors (window->priv->model));
4676 g_signal_handlers_unblock_by_func
4677 (action, G_CALLBACK (ev_window_cmd_view_inverted_colors), window);
4681 ev_window_inverted_colors_changed_cb (EvDocumentModel *model,
4685 gboolean inverted_colors = ev_document_model_get_inverted_colors (model);
4687 ev_window_update_inverted_colors_action (window);
4689 if (window->priv->metadata && !ev_window_is_empty (window))
4690 ev_metadata_set_boolean (window->priv->metadata, "inverted-colors",
4693 ev_window_refresh_window_thumbnail (window);
4697 ev_window_dual_mode_changed_cb (EvDocumentModel *model,
4699 EvWindow *ev_window)
4701 ev_window_update_dual_page_action (ev_window);
4703 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window))
4704 ev_metadata_set_boolean (ev_window->priv->metadata, "dual-page",
4705 ev_document_model_get_dual_page (model));
4709 build_comments_string (EvDocument *document)
4711 gchar *comments = NULL;
4712 EvDocumentBackendInfo info;
4714 if (document && ev_document_get_backend_info (document, &info)) {
4715 comments = g_strdup_printf (
4716 _("Document Viewer\nUsing %s (%s)"),
4717 info.name, info.version);
4719 comments = g_strdup_printf (
4720 _("Document Viewer"));
4727 ev_window_cmd_help_about (GtkAction *action, EvWindow *ev_window)
4729 const char *authors[] = {
4730 "Martin Kretzschmar <m_kretzschmar@gmx.net>",
4731 "Jonathan Blandford <jrb@gnome.org>",
4732 "Marco Pesenti Gritti <marco@gnome.org>",
4733 "Nickolay V. Shmyrev <nshmyrev@yandex.ru>",
4734 "Bryan Clark <clarkbw@gnome.org>",
4735 "Carlos Garcia Campos <carlosgc@gnome.org>",
4736 "Wouter Bolsterlee <wbolster@gnome.org>",
4737 "Christian Persch <chpe" "\100" "gnome.org>",
4741 const char *documenters[] = {
4742 "Nickolay V. Shmyrev <nshmyrev@yandex.ru>",
4746 const char *license[] = {
4747 N_("Evince is free software; you can redistribute it and/or modify "
4748 "it under the terms of the GNU General Public License as published by "
4749 "the Free Software Foundation; either version 2 of the License, or "
4750 "(at your option) any later version.\n"),
4751 N_("Evince is distributed in the hope that it will be useful, "
4752 "but WITHOUT ANY WARRANTY; without even the implied warranty of "
4753 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
4754 "GNU General Public License for more details.\n"),
4755 N_("You should have received a copy of the GNU General Public License "
4756 "along with Evince; if not, write to the Free Software Foundation, Inc., "
4757 "51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n")
4760 char *license_trans;
4766 for (p = authors; *p; ++p)
4769 for (p = documenters; *p; ++p)
4773 license_trans = g_strconcat (_(license[0]), "\n", _(license[1]), "\n",
4774 _(license[2]), "\n", NULL);
4776 comments = build_comments_string (ev_window->priv->document);
4778 gtk_show_about_dialog (
4779 GTK_WINDOW (ev_window),
4780 "name", _("Evince"),
4783 _("© 1996–2010 The Evince authors"),
4784 "license", license_trans,
4785 "website", "http://www.gnome.org/projects/evince",
4786 "comments", comments,
4788 "documenters", documenters,
4789 "translator-credits", _("translator-credits"),
4790 "logo-icon-name", "evince",
4791 "wrap-license", TRUE,
4795 g_free (license_trans);
4799 ev_window_view_toolbar_cb (GtkAction *action, EvWindow *ev_window)
4803 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
4804 update_chrome_flag (ev_window, EV_CHROME_TOOLBAR, active);
4805 update_chrome_visibility (ev_window);
4806 if (ev_window->priv->metadata)
4807 ev_metadata_set_boolean (ev_window->priv->metadata, "show_toolbar", active);
4811 ev_window_view_sidebar_cb (GtkAction *action, EvWindow *ev_window)
4813 if (EV_WINDOW_IS_PRESENTATION (ev_window))
4816 update_chrome_flag (ev_window, EV_CHROME_SIDEBAR,
4817 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
4818 update_chrome_visibility (ev_window);
4822 ev_window_sidebar_current_page_changed_cb (EvSidebar *ev_sidebar,
4824 EvWindow *ev_window)
4826 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window)) {
4827 ev_metadata_set_string (ev_window->priv->metadata,
4829 ev_window_sidebar_get_current_page_id (ev_window));
4834 ev_window_sidebar_visibility_changed_cb (EvSidebar *ev_sidebar,
4836 EvWindow *ev_window)
4840 action = gtk_action_group_get_action (ev_window->priv->action_group, "ViewSidebar");
4842 if (!EV_WINDOW_IS_PRESENTATION (ev_window)) {
4843 gboolean visible = gtk_widget_get_visible (GTK_WIDGET (ev_sidebar));
4845 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible);
4847 if (ev_window->priv->metadata)
4848 ev_metadata_set_boolean (ev_window->priv->metadata, "sidebar_visibility",
4854 view_menu_link_popup (EvWindow *ev_window,
4857 gboolean show_external = FALSE;
4858 gboolean show_internal = FALSE;
4861 if (ev_window->priv->link)
4862 g_object_unref (ev_window->priv->link);
4865 ev_window->priv->link = g_object_ref (link);
4867 ev_window->priv->link = NULL;
4869 if (ev_window->priv->link) {
4870 EvLinkAction *ev_action;
4872 ev_action = ev_link_get_action (link);
4874 switch (ev_link_action_get_action_type (ev_action)) {
4875 case EV_LINK_ACTION_TYPE_GOTO_DEST:
4876 case EV_LINK_ACTION_TYPE_GOTO_REMOTE:
4877 show_internal = TRUE;
4879 case EV_LINK_ACTION_TYPE_EXTERNAL_URI:
4880 case EV_LINK_ACTION_TYPE_LAUNCH:
4881 show_external = TRUE;
4889 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4891 gtk_action_set_visible (action, show_external);
4893 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4895 gtk_action_set_visible (action, show_external);
4897 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4899 gtk_action_set_visible (action, show_internal);
4901 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4902 "OpenLinkNewWindow");
4903 gtk_action_set_visible (action, show_internal);
4907 view_menu_image_popup (EvWindow *ev_window,
4911 gboolean show_image = FALSE;
4913 if (ev_window->priv->image)
4914 g_object_unref (ev_window->priv->image);
4917 ev_window->priv->image = g_object_ref (image);
4919 ev_window->priv->image = NULL;
4921 show_image = (ev_window->priv->image != NULL);
4923 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4925 gtk_action_set_visible (action, show_image);
4927 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4929 gtk_action_set_visible (action, show_image);
4933 view_menu_annot_popup (EvWindow *ev_window,
4934 EvAnnotation *annot)
4937 gboolean show_annot = FALSE;
4939 if (ev_window->priv->annot)
4940 g_object_unref (ev_window->priv->annot);
4941 ev_window->priv->annot = (annot) ? g_object_ref (annot) : NULL;
4943 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4945 gtk_action_set_visible (action, (annot != NULL && EV_IS_ANNOTATION_MARKUP (annot)));
4947 if (annot && EV_IS_ANNOTATION_ATTACHMENT (annot)) {
4948 EvAttachment *attachment;
4950 attachment = ev_annotation_attachment_get_attachment (EV_ANNOTATION_ATTACHMENT (annot));
4953 if (ev_window->priv->attach_list) {
4954 g_list_foreach (ev_window->priv->attach_list,
4955 (GFunc) g_object_unref, NULL);
4956 g_list_free (ev_window->priv->attach_list);
4957 ev_window->priv->attach_list = NULL;
4959 ev_window->priv->attach_list =
4960 g_list_prepend (ev_window->priv->attach_list,
4961 g_object_ref (attachment));
4965 action = gtk_action_group_get_action (ev_window->priv->attachment_popup_action_group,
4967 gtk_action_set_visible (action, show_annot);
4969 action = gtk_action_group_get_action (ev_window->priv->attachment_popup_action_group,
4970 "SaveAttachmentAs");
4971 gtk_action_set_visible (action, show_annot);
4975 view_menu_popup_cb (EvView *view,
4977 EvWindow *ev_window)
4980 gboolean has_link = FALSE;
4981 gboolean has_image = FALSE;
4982 gboolean has_annot = FALSE;
4984 for (l = items; l; l = g_list_next (l)) {
4985 if (EV_IS_LINK (l->data)) {
4986 view_menu_link_popup (ev_window, EV_LINK (l->data));
4988 } else if (EV_IS_IMAGE (l->data)) {
4989 view_menu_image_popup (ev_window, EV_IMAGE (l->data));
4991 } else if (EV_IS_ANNOTATION (l->data)) {
4992 view_menu_annot_popup (ev_window, EV_ANNOTATION (l->data));
4998 view_menu_link_popup (ev_window, NULL);
5000 view_menu_image_popup (ev_window, NULL);
5002 view_menu_annot_popup (ev_window, NULL);
5004 gtk_menu_popup (GTK_MENU (ev_window->priv->view_popup),
5005 NULL, NULL, NULL, NULL,
5006 3, gtk_get_current_event_time ());
5011 attachment_bar_menu_popup_cb (EvSidebarAttachments *attachbar,
5013 EvWindow *ev_window)
5017 g_assert (attach_list != NULL);
5019 if (ev_window->priv->attach_list) {
5020 g_list_foreach (ev_window->priv->attach_list,
5021 (GFunc) g_object_unref, NULL);
5022 g_list_free (ev_window->priv->attach_list);
5025 ev_window->priv->attach_list = attach_list;
5027 popup = ev_window->priv->attachment_popup;
5029 gtk_menu_popup (GTK_MENU (popup), NULL, NULL,
5031 3, gtk_get_current_event_time ());
5037 ev_window_update_find_status_message (EvWindow *ev_window)
5041 if (!ev_window->priv->find_job)
5044 if (ev_job_is_finished (ev_window->priv->find_job)) {
5045 EvJobFind *job_find = EV_JOB_FIND (ev_window->priv->find_job);
5047 if (ev_job_find_has_results (job_find)) {
5050 n_results = ev_job_find_get_n_results (job_find,
5051 ev_document_model_get_page (ev_window->priv->model));
5052 /* TRANS: Sometimes this could be better translated as
5053 "%d hit(s) on this page". Therefore this string
5054 contains plural cases. */
5055 message = g_strdup_printf (ngettext ("%d found on this page",
5056 "%d found on this page",
5060 message = g_strdup (_("Not found"));
5065 percent = ev_job_find_get_progress (EV_JOB_FIND (ev_window->priv->find_job));
5066 message = g_strdup_printf (_("%3d%% remaining to search"),
5067 (gint) ((1.0 - percent) * 100));
5070 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar), message);
5075 ev_window_find_job_finished_cb (EvJobFind *job,
5076 EvWindow *ev_window)
5078 ev_window_update_find_status_message (ev_window);
5082 ev_window_find_job_updated_cb (EvJobFind *job,
5084 EvWindow *ev_window)
5086 ev_window_update_actions (ev_window);
5088 ev_view_find_changed (EV_VIEW (ev_window->priv->view),
5089 ev_job_find_get_results (job),
5091 ev_window_update_find_status_message (ev_window);
5095 ev_window_clear_find_job (EvWindow *ev_window)
5097 if (ev_window->priv->find_job != NULL) {
5098 if (!ev_job_is_finished (ev_window->priv->find_job))
5099 ev_job_cancel (ev_window->priv->find_job);
5101 g_signal_handlers_disconnect_by_func (ev_window->priv->find_job,
5102 ev_window_find_job_finished_cb,
5104 g_signal_handlers_disconnect_by_func (ev_window->priv->find_job,
5105 ev_window_find_job_updated_cb,
5107 g_object_unref (ev_window->priv->find_job);
5108 ev_window->priv->find_job = NULL;
5113 find_bar_previous_cb (EggFindBar *find_bar,
5114 EvWindow *ev_window)
5116 ev_view_find_previous (EV_VIEW (ev_window->priv->view));
5120 find_bar_next_cb (EggFindBar *find_bar,
5121 EvWindow *ev_window)
5123 ev_view_find_next (EV_VIEW (ev_window->priv->view));
5127 find_bar_close_cb (EggFindBar *find_bar,
5128 EvWindow *ev_window)
5130 ev_view_find_cancel (EV_VIEW (ev_window->priv->view));
5131 ev_window_clear_find_job (ev_window);
5132 update_chrome_flag (ev_window, EV_CHROME_FINDBAR, FALSE);
5133 update_chrome_visibility (ev_window);
5137 find_bar_search_changed_cb (EggFindBar *find_bar,
5139 EvWindow *ev_window)
5141 gboolean case_sensitive;
5142 const char *search_string;
5144 if (!ev_window->priv->document || !EV_IS_DOCUMENT_FIND (ev_window->priv->document))
5147 /* Either the string or case sensitivity could have changed. */
5148 case_sensitive = egg_find_bar_get_case_sensitive (find_bar);
5149 search_string = egg_find_bar_get_search_string (find_bar);
5151 ev_view_find_search_changed (EV_VIEW (ev_window->priv->view));
5153 ev_window_clear_find_job (ev_window);
5155 if (search_string && search_string[0]) {
5156 ev_window->priv->find_job = ev_job_find_new (ev_window->priv->document,
5157 ev_document_model_get_page (ev_window->priv->model),
5158 ev_document_get_n_pages (ev_window->priv->document),
5161 g_signal_connect (ev_window->priv->find_job, "finished",
5162 G_CALLBACK (ev_window_find_job_finished_cb),
5164 g_signal_connect (ev_window->priv->find_job, "updated",
5165 G_CALLBACK (ev_window_find_job_updated_cb),
5167 ev_job_scheduler_push_job (ev_window->priv->find_job, EV_JOB_PRIORITY_NONE);
5169 ev_window_update_actions (ev_window);
5170 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar),
5172 gtk_widget_queue_draw (GTK_WIDGET (ev_window->priv->view));
5177 find_bar_visibility_changed_cb (EggFindBar *find_bar,
5179 EvWindow *ev_window)
5183 visible = gtk_widget_get_visible (GTK_WIDGET (find_bar));
5185 if (ev_window->priv->document &&
5186 EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
5187 ev_view_find_set_highlight_search (EV_VIEW (ev_window->priv->view), visible);
5188 ev_view_find_search_changed (EV_VIEW (ev_window->priv->view));
5189 ev_window_update_actions (ev_window);
5192 find_bar_search_changed_cb (find_bar, NULL, ev_window);
5194 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar), NULL);
5199 find_bar_scroll (EggFindBar *find_bar,
5200 GtkScrollType scroll,
5201 EvWindow *ev_window)
5203 ev_view_scroll (EV_VIEW (ev_window->priv->view), scroll, FALSE);
5207 zoom_control_changed_cb (EphyZoomAction *action,
5209 EvWindow *ev_window)
5213 if (zoom == EPHY_ZOOM_BEST_FIT) {
5214 mode = EV_SIZING_BEST_FIT;
5215 } else if (zoom == EPHY_ZOOM_FIT_WIDTH) {
5216 mode = EV_SIZING_FIT_WIDTH;
5218 mode = EV_SIZING_FREE;
5221 ev_document_model_set_sizing_mode (ev_window->priv->model, mode);
5223 if (mode == EV_SIZING_FREE) {
5224 ev_document_model_set_scale (ev_window->priv->model,
5225 zoom * get_screen_dpi (ev_window) / 72.0);
5230 ev_window_drag_data_received (GtkWidget *widget,
5231 GdkDragContext *context,
5234 GtkSelectionData *selection_data,
5239 EvWindow *window = EV_WINDOW (widget);
5242 GSList *uri_list = NULL;
5245 source = gtk_drag_get_source_widget (context);
5246 if (source && widget == gtk_widget_get_toplevel (source)) {
5247 gtk_drag_finish (context, FALSE, FALSE, time);
5251 uris = gtk_selection_data_get_uris (selection_data);
5253 gtk_drag_finish (context, FALSE, FALSE, time);
5257 for (i = 0; uris[i]; i++) {
5258 uri_list = g_slist_prepend (uri_list, (gpointer) uris[i]);
5261 ev_application_open_uri_list (EV_APP, uri_list,
5262 gtk_window_get_screen (GTK_WINDOW (window)),
5264 gtk_drag_finish (context, TRUE, FALSE, time);
5267 g_slist_free (uri_list);
5271 ev_window_finalize (GObject *object)
5273 G_OBJECT_CLASS (ev_window_parent_class)->finalize (object);
5275 if (ev_window_n_copies == 0) {
5276 ev_application_shutdown (EV_APP);
5278 ev_window_n_copies--;
5283 ev_window_dispose (GObject *object)
5285 EvWindow *window = EV_WINDOW (object);
5286 EvWindowPrivate *priv = window->priv;
5287 GObject *mpkeys = ev_application_get_media_keys (EV_APP);
5290 g_signal_handlers_disconnect_by_func (mpkeys,
5291 ev_window_media_player_key_pressed,
5296 if (priv->dbus_object_id > 0) {
5297 ev_window_emit_closed (window);
5298 g_dbus_connection_unregister_object (ev_application_get_dbus_connection (EV_APP),
5299 priv->dbus_object_id);
5300 priv->dbus_object_id = 0;
5303 if (priv->dbus_object_path) {
5304 g_free (priv->dbus_object_path);
5305 priv->dbus_object_path = NULL;
5307 #endif /* ENABLE_DBUS */
5309 if (priv->bookmarks) {
5310 g_object_unref (priv->bookmarks);
5311 priv->bookmarks = NULL;
5314 if (priv->metadata) {
5315 g_object_unref (priv->metadata);
5316 priv->metadata = NULL;
5319 if (priv->setup_document_idle > 0) {
5320 g_source_remove (priv->setup_document_idle);
5321 priv->setup_document_idle = 0;
5324 if (priv->monitor) {
5325 g_object_unref (priv->monitor);
5326 priv->monitor = NULL;
5330 ev_window_title_free (priv->title);
5334 if (priv->ui_manager) {
5335 g_object_unref (priv->ui_manager);
5336 priv->ui_manager = NULL;
5339 if (priv->action_group) {
5340 g_object_unref (priv->action_group);
5341 priv->action_group = NULL;
5344 if (priv->view_popup_action_group) {
5345 g_object_unref (priv->view_popup_action_group);
5346 priv->view_popup_action_group = NULL;
5349 if (priv->attachment_popup_action_group) {
5350 g_object_unref (priv->attachment_popup_action_group);
5351 priv->attachment_popup_action_group = NULL;
5354 if (priv->recent_action_group) {
5355 g_object_unref (priv->recent_action_group);
5356 priv->recent_action_group = NULL;
5359 if (priv->bookmarks_action_group) {
5360 g_object_unref (priv->bookmarks_action_group);
5361 priv->bookmarks_action_group = NULL;
5364 if (priv->recent_manager) {
5365 g_signal_handlers_disconnect_by_func (priv->recent_manager,
5366 ev_window_setup_recent,
5368 priv->recent_manager = NULL;
5371 if (priv->settings) {
5372 g_object_unref (priv->settings);
5373 priv->settings = NULL;
5376 if (priv->default_settings) {
5377 g_settings_apply (priv->default_settings);
5378 g_object_unref (priv->default_settings);
5379 priv->default_settings = NULL;
5382 if (priv->lockdown_settings) {
5383 g_object_unref (priv->lockdown_settings);
5384 priv->lockdown_settings = NULL;
5387 priv->recent_ui_id = 0;
5390 g_signal_handlers_disconnect_by_func (priv->model,
5391 ev_window_page_changed_cb,
5393 g_object_unref (priv->model);
5397 if (priv->document) {
5398 g_object_unref (priv->document);
5399 priv->document = NULL;
5403 g_object_unref (priv->view);
5407 if (priv->password_view) {
5408 g_object_unref (priv->password_view);
5409 priv->password_view = NULL;
5412 if (priv->load_job) {
5413 ev_window_clear_load_job (window);
5416 if (priv->reload_job) {
5417 ev_window_clear_reload_job (window);
5420 if (priv->save_job) {
5421 ev_window_clear_save_job (window);
5424 if (priv->thumbnail_job) {
5425 ev_window_clear_thumbnail_job (window);
5428 if (priv->find_job) {
5429 ev_window_clear_find_job (window);
5432 if (priv->local_uri) {
5433 ev_window_clear_local_uri (window);
5434 priv->local_uri = NULL;
5437 ev_window_clear_progress_idle (window);
5438 if (priv->progress_cancellable) {
5439 g_object_unref (priv->progress_cancellable);
5440 priv->progress_cancellable = NULL;
5443 ev_window_close_dialogs (window);
5446 g_object_unref (priv->link);
5451 g_object_unref (priv->image);
5456 g_object_unref (priv->annot);
5460 if (priv->attach_list) {
5461 g_list_foreach (priv->attach_list,
5462 (GFunc) g_object_unref,
5464 g_list_free (priv->attach_list);
5465 priv->attach_list = NULL;
5468 if (priv->find_bar) {
5469 g_signal_handlers_disconnect_by_func
5470 (window->priv->find_bar,
5471 G_CALLBACK (find_bar_close_cb),
5473 priv->find_bar = NULL;
5481 if (priv->search_string) {
5482 g_free (priv->search_string);
5483 priv->search_string = NULL;
5487 g_object_unref (priv->dest);
5491 if (priv->history) {
5492 g_object_unref (priv->history);
5493 priv->history = NULL;
5496 if (priv->print_queue) {
5497 g_queue_free (priv->print_queue);
5498 priv->print_queue = NULL;
5501 G_OBJECT_CLASS (ev_window_parent_class)->dispose (object);
5505 menubar_deactivate_cb (GtkWidget *menubar,
5508 g_signal_handlers_disconnect_by_func (menubar,
5509 G_CALLBACK (menubar_deactivate_cb),
5512 gtk_menu_shell_deselect (GTK_MENU_SHELL (menubar));
5514 update_chrome_visibility (window);
5518 ev_window_key_press_event (GtkWidget *widget,
5521 EvWindow *ev_window = EV_WINDOW (widget);
5522 EvWindowPrivate *priv = ev_window->priv;
5523 gboolean handled = FALSE;
5525 /* Propagate the event to the view first
5526 * It's needed to be able to type in
5527 * annot popups windows
5530 g_object_ref (priv->view);
5531 if (gtk_widget_is_sensitive (priv->view))
5532 handled = gtk_widget_event (priv->view, (GdkEvent*) event);
5533 g_object_unref (priv->view);
5536 if (!handled && !EV_WINDOW_IS_PRESENTATION (ev_window)) {
5537 guint modifier = event->state & gtk_accelerator_get_default_mod_mask ();
5539 if (priv->menubar_accel_keyval != 0 &&
5540 event->keyval == priv->menubar_accel_keyval &&
5541 modifier == priv->menubar_accel_modifier) {
5542 if (!gtk_widget_get_visible (priv->menubar)) {
5543 g_signal_connect (priv->menubar, "deactivate",
5544 G_CALLBACK (menubar_deactivate_cb),
5547 gtk_widget_show (priv->menubar);
5548 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menubar),
5557 handled = GTK_WIDGET_CLASS (ev_window_parent_class)->key_press_event (widget, event);
5563 ev_window_delete_event (GtkWidget *widget,
5566 return !ev_window_close (EV_WINDOW (widget));
5570 ev_window_class_init (EvWindowClass *ev_window_class)
5572 GObjectClass *g_object_class = G_OBJECT_CLASS (ev_window_class);
5573 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (ev_window_class);
5575 g_object_class->dispose = ev_window_dispose;
5576 g_object_class->finalize = ev_window_finalize;
5578 widget_class->delete_event = ev_window_delete_event;
5579 widget_class->key_press_event = ev_window_key_press_event;
5580 widget_class->screen_changed = ev_window_screen_changed;
5581 widget_class->window_state_event = ev_window_state_event;
5582 widget_class->drag_data_received = ev_window_drag_data_received;
5584 g_type_class_add_private (g_object_class, sizeof (EvWindowPrivate));
5588 static const GtkActionEntry entries[] = {
5589 { "File", NULL, N_("_File") },
5590 { "Edit", NULL, N_("_Edit") },
5591 { "View", NULL, N_("_View") },
5592 { "Go", NULL, N_("_Go") },
5593 { "Bookmarks", NULL, N_("_Bookmarks") },
5594 { "Help", NULL, N_("_Help") },
5597 { "FileOpen", GTK_STOCK_OPEN, N_("_Open…"), "<control>O",
5598 N_("Open an existing document"),
5599 G_CALLBACK (ev_window_cmd_file_open) },
5600 { "FileOpenCopy", NULL, N_("Op_en a Copy"), "<control>N",
5601 N_("Open a copy of the current document in a new window"),
5602 G_CALLBACK (ev_window_cmd_file_open_copy) },
5603 { "FileSaveAs", GTK_STOCK_SAVE_AS, N_("_Save a Copy…"), "<control>S",
5604 N_("Save a copy of the current document"),
5605 G_CALLBACK (ev_window_cmd_save_as) },
5606 { "FileOpenContainingFolder", GTK_STOCK_DIRECTORY, N_("Open Containing _Folder"), NULL,
5607 N_("Show the folder which contains this file in the file manager"),
5608 G_CALLBACK (ev_window_cmd_open_containing_folder) },
5609 { "FilePrint", GTK_STOCK_PRINT, N_("_Print…"), "<control>P",
5610 N_("Print this document"),
5611 G_CALLBACK (ev_window_cmd_file_print) },
5612 { "FileProperties", GTK_STOCK_PROPERTIES, N_("P_roperties"), "<alt>Return", NULL,
5613 G_CALLBACK (ev_window_cmd_file_properties) },
5614 { "FileCloseWindow", GTK_STOCK_CLOSE, NULL, "<control>W", NULL,
5615 G_CALLBACK (ev_window_cmd_file_close_window) },
5618 { "EditCopy", GTK_STOCK_COPY, NULL, "<control>C", NULL,
5619 G_CALLBACK (ev_window_cmd_edit_copy) },
5620 { "EditSelectAll", GTK_STOCK_SELECT_ALL, N_("Select _All"), "<control>A", NULL,
5621 G_CALLBACK (ev_window_cmd_edit_select_all) },
5622 { "EditFind", GTK_STOCK_FIND, N_("_Find…"), "<control>F",
5623 N_("Find a word or phrase in the document"),
5624 G_CALLBACK (ev_window_cmd_edit_find) },
5625 { "EditFindNext", NULL, N_("Find Ne_xt"), "<control>G", NULL,
5626 G_CALLBACK (ev_window_cmd_edit_find_next) },
5627 { "EditFindPrevious", NULL, N_("Find Pre_vious"), "<shift><control>G", NULL,
5628 G_CALLBACK (ev_window_cmd_edit_find_previous) },
5629 { "EditToolbar", NULL, N_("T_oolbar"), NULL, NULL,
5630 G_CALLBACK (ev_window_cmd_edit_toolbar) },
5631 { "EditRotateLeft", EV_STOCK_ROTATE_LEFT, N_("Rotate _Left"), "<control>Left", NULL,
5632 G_CALLBACK (ev_window_cmd_edit_rotate_left) },
5633 { "EditRotateRight", EV_STOCK_ROTATE_RIGHT, N_("Rotate _Right"), "<control>Right", NULL,
5634 G_CALLBACK (ev_window_cmd_edit_rotate_right) },
5635 { "EditSaveSettings", NULL, N_("Save Current Settings as _Default"), "<control>T", NULL,
5636 G_CALLBACK (ev_window_cmd_edit_save_settings) },
5640 { "ViewZoomIn", GTK_STOCK_ZOOM_IN, NULL, "<control>plus",
5641 N_("Enlarge the document"),
5642 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5643 { "ViewZoomOut", GTK_STOCK_ZOOM_OUT, NULL, "<control>minus",
5644 N_("Shrink the document"),
5645 G_CALLBACK (ev_window_cmd_view_zoom_out) },
5646 { "ViewReload", GTK_STOCK_REFRESH, N_("_Reload"), "<control>R",
5647 N_("Reload the document"),
5648 G_CALLBACK (ev_window_cmd_view_reload) },
5650 { "ViewAutoscroll", GTK_STOCK_MEDIA_PLAY, N_("Auto_scroll"), NULL, NULL,
5651 G_CALLBACK (ev_window_cmd_view_autoscroll) },
5654 { "GoPreviousPage", GTK_STOCK_GO_UP, N_("_Previous Page"), "<control>Page_Up",
5655 N_("Go to the previous page"),
5656 G_CALLBACK (ev_window_cmd_go_previous_page) },
5657 { "GoNextPage", GTK_STOCK_GO_DOWN, N_("_Next Page"), "<control>Page_Down",
5658 N_("Go to the next page"),
5659 G_CALLBACK (ev_window_cmd_go_next_page) },
5660 { "GoFirstPage", GTK_STOCK_GOTO_TOP, N_("_First Page"), "<control>Home",
5661 N_("Go to the first page"),
5662 G_CALLBACK (ev_window_cmd_go_first_page) },
5663 { "GoLastPage", GTK_STOCK_GOTO_BOTTOM, N_("_Last Page"), "<control>End",
5664 N_("Go to the last page"),
5665 G_CALLBACK (ev_window_cmd_go_last_page) },
5667 /* Bookmarks menu */
5668 { "BookmarksAdd", GTK_STOCK_ADD, N_("_Add Bookmark"), "<control>D",
5669 N_("Add a bookmark for the current page"),
5670 G_CALLBACK (ev_window_cmd_bookmarks_add) },
5673 { "HelpContents", GTK_STOCK_HELP, N_("_Contents"), "F1", NULL,
5674 G_CALLBACK (ev_window_cmd_help_contents) },
5676 { "HelpAbout", GTK_STOCK_ABOUT, N_("_About"), NULL, NULL,
5677 G_CALLBACK (ev_window_cmd_help_about) },
5680 { "LeaveFullscreen", GTK_STOCK_LEAVE_FULLSCREEN, N_("Leave Fullscreen"), NULL,
5681 N_("Leave fullscreen mode"),
5682 G_CALLBACK (ev_window_cmd_leave_fullscreen) },
5683 { "StartPresentation", EV_STOCK_RUN_PRESENTATION, N_("Start Presentation"), NULL,
5684 N_("Start a presentation"),
5685 G_CALLBACK (ev_window_cmd_start_presentation) },
5688 { "Escape", NULL, "", "Escape", "",
5689 G_CALLBACK (ev_window_cmd_escape) },
5690 { "Slash", GTK_STOCK_FIND, NULL, "slash", NULL,
5691 G_CALLBACK (ev_window_cmd_edit_find) },
5692 { "F3", NULL, "", "F3", NULL,
5693 G_CALLBACK (ev_window_cmd_edit_find_next) },
5694 { "PageDown", NULL, "", "Page_Down", NULL,
5695 G_CALLBACK (ev_window_cmd_scroll_forward) },
5696 { "PageUp", NULL, "", "Page_Up", NULL,
5697 G_CALLBACK (ev_window_cmd_scroll_backward) },
5698 { "Space", NULL, "", "space", NULL,
5699 G_CALLBACK (ev_window_cmd_scroll_forward) },
5700 { "ShiftSpace", NULL, "", "<shift>space", NULL,
5701 G_CALLBACK (ev_window_cmd_scroll_backward) },
5702 { "BackSpace", NULL, "", "BackSpace", NULL,
5703 G_CALLBACK (ev_window_cmd_scroll_backward) },
5704 { "ShiftBackSpace", NULL, "", "<shift>BackSpace", NULL,
5705 G_CALLBACK (ev_window_cmd_scroll_forward) },
5706 { "Return", NULL, "", "Return", NULL,
5707 G_CALLBACK (ev_window_cmd_scroll_forward) },
5708 { "ShiftReturn", NULL, "", "<shift>Return", NULL,
5709 G_CALLBACK (ev_window_cmd_scroll_backward) },
5710 { "p", GTK_STOCK_GO_UP, "", "p", NULL,
5711 G_CALLBACK (ev_window_cmd_go_previous_page) },
5712 { "n", GTK_STOCK_GO_DOWN, "", "n", NULL,
5713 G_CALLBACK (ev_window_cmd_go_next_page) },
5714 { "Plus", GTK_STOCK_ZOOM_IN, NULL, "plus", NULL,
5715 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5716 { "CtrlEqual", GTK_STOCK_ZOOM_IN, NULL, "<control>equal", NULL,
5717 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5718 { "Equal", GTK_STOCK_ZOOM_IN, NULL, "equal", NULL,
5719 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5720 { "Minus", GTK_STOCK_ZOOM_OUT, NULL, "minus", NULL,
5721 G_CALLBACK (ev_window_cmd_view_zoom_out) },
5722 { "FocusPageSelector", NULL, "", "<control>l", NULL,
5723 G_CALLBACK (ev_window_cmd_focus_page_selector) },
5724 { "GoBackwardFast", NULL, "", "<shift>Page_Up", NULL,
5725 G_CALLBACK (ev_window_cmd_go_backward) },
5726 { "GoForwardFast", NULL, "", "<shift>Page_Down", NULL,
5727 G_CALLBACK (ev_window_cmd_go_forward) },
5728 { "KpPlus", GTK_STOCK_ZOOM_IN, NULL, "KP_Add", NULL,
5729 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5730 { "KpMinus", GTK_STOCK_ZOOM_OUT, NULL, "KP_Subtract", NULL,
5731 G_CALLBACK (ev_window_cmd_view_zoom_out) },
5732 { "CtrlKpPlus", GTK_STOCK_ZOOM_IN, NULL, "<control>KP_Add", NULL,
5733 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5734 { "CtrlKpMinus", GTK_STOCK_ZOOM_OUT, NULL, "<control>KP_Subtract", NULL,
5735 G_CALLBACK (ev_window_cmd_view_zoom_out) },
5736 { "CtrlInsert", GTK_STOCK_COPY, NULL, "<control>Insert", NULL,
5737 G_CALLBACK (ev_window_cmd_edit_copy) },
5741 static const GtkToggleActionEntry toggle_entries[] = {
5743 { "ViewToolbar", NULL, N_("_Toolbar"), NULL,
5744 N_("Show or hide the toolbar"),
5745 G_CALLBACK (ev_window_view_toolbar_cb), TRUE },
5746 { "ViewSidebar", GTK_STOCK_INDEX, N_("Side _Pane"), "F9",
5747 N_("Show or hide the side pane"),
5748 G_CALLBACK (ev_window_view_sidebar_cb), TRUE },
5749 { "ViewContinuous", EV_STOCK_VIEW_CONTINUOUS, N_("_Continuous"), NULL,
5750 N_("Show the entire document"),
5751 G_CALLBACK (ev_window_cmd_continuous), TRUE },
5752 { "ViewDual", EV_STOCK_VIEW_DUAL, N_("_Dual"), NULL,
5753 N_("Show two pages at once"),
5754 G_CALLBACK (ev_window_cmd_dual), FALSE },
5755 { "ViewFullscreen", GTK_STOCK_FULLSCREEN, N_("_Fullscreen"), "F11",
5756 N_("Expand the window to fill the screen"),
5757 G_CALLBACK (ev_window_cmd_view_fullscreen) },
5758 { "ViewPresentation", EV_STOCK_RUN_PRESENTATION, N_("Pre_sentation"), "F5",
5759 N_("Run document as a presentation"),
5760 G_CALLBACK (ev_window_cmd_view_presentation) },
5761 { "ViewBestFit", EV_STOCK_ZOOM_PAGE, N_("_Best Fit"), NULL,
5762 N_("Make the current document fill the window"),
5763 G_CALLBACK (ev_window_cmd_view_best_fit) },
5764 { "ViewPageWidth", EV_STOCK_ZOOM_WIDTH, N_("Fit Page _Width"), NULL,
5765 N_("Make the current document fill the window width"),
5766 G_CALLBACK (ev_window_cmd_view_page_width) },
5767 { "ViewInvertedColors", EV_STOCK_INVERTED_COLORS, N_("_Inverted Colors"), "<control>I",
5768 N_("Show page contents with the colors inverted"),
5769 G_CALLBACK (ev_window_cmd_view_inverted_colors) },
5773 /* Popups specific items */
5774 static const GtkActionEntry view_popup_entries [] = {
5776 { "OpenLink", GTK_STOCK_OPEN, N_("_Open Link"), NULL,
5777 NULL, G_CALLBACK (ev_view_popup_cmd_open_link) },
5778 { "GoLink", GTK_STOCK_GO_FORWARD, N_("_Go To"), NULL,
5779 NULL, G_CALLBACK (ev_view_popup_cmd_open_link) },
5780 { "OpenLinkNewWindow", NULL, N_("Open in New _Window"), NULL,
5781 NULL, G_CALLBACK (ev_view_popup_cmd_open_link_new_window) },
5782 { "CopyLinkAddress", NULL, N_("_Copy Link Address"), NULL,
5783 NULL, G_CALLBACK (ev_view_popup_cmd_copy_link_address) },
5784 { "SaveImageAs", NULL, N_("_Save Image As…"), NULL,
5785 NULL, G_CALLBACK (ev_view_popup_cmd_save_image_as) },
5786 { "CopyImage", NULL, N_("Copy _Image"), NULL,
5787 NULL, G_CALLBACK (ev_view_popup_cmd_copy_image) },
5788 { "AnnotProperties", NULL, N_("Annotation Properties…"), NULL,
5789 NULL, G_CALLBACK (ev_view_popup_cmd_annot_properties) }
5792 static const GtkActionEntry attachment_popup_entries [] = {
5793 { "OpenAttachment", GTK_STOCK_OPEN, N_("_Open Attachment"), NULL,
5794 NULL, G_CALLBACK (ev_attachment_popup_cmd_open_attachment) },
5795 { "SaveAttachmentAs", GTK_STOCK_SAVE_AS, N_("_Save Attachment As…"), NULL,
5796 NULL, G_CALLBACK (ev_attachment_popup_cmd_save_attachment_as) },
5800 sidebar_links_link_activated_cb (EvSidebarLinks *sidebar_links, EvLink *link, EvWindow *window)
5802 ev_view_handle_link (EV_VIEW (window->priv->view), link);
5806 activate_link_cb (EvPageAction *page_action, EvLink *link, EvWindow *window)
5808 ev_view_handle_link (EV_VIEW (window->priv->view), link);
5809 gtk_widget_grab_focus (window->priv->view);
5813 navigation_action_activate_link_cb (EvNavigationAction *action, EvLink *link, EvWindow *window)
5816 ev_view_handle_link (EV_VIEW (window->priv->view), link);
5817 gtk_widget_grab_focus (window->priv->view);
5821 sidebar_layers_visibility_changed (EvSidebarLayers *layers,
5824 ev_view_reload (EV_VIEW (window->priv->view));
5828 sidebar_annots_annot_activated_cb (EvSidebarAnnotations *sidebar_annots,
5829 EvMapping *annot_mapping,
5832 ev_view_focus_annotation (EV_VIEW (window->priv->view), annot_mapping);
5836 sidebar_annots_begin_annot_add (EvSidebarAnnotations *sidebar_annots,
5837 EvAnnotationType annot_type,
5840 ev_view_begin_add_annotation (EV_VIEW (window->priv->view), annot_type);
5844 view_annot_added (EvView *view,
5845 EvAnnotation *annot,
5848 ev_sidebar_annotations_annot_added (EV_SIDEBAR_ANNOTATIONS (window->priv->sidebar_annots),
5853 sidebar_annots_annot_add_cancelled (EvSidebarAnnotations *sidebar_annots,
5856 ev_view_cancel_add_annotation (EV_VIEW (window->priv->view));
5860 sidebar_bookmarks_add_bookmark (EvSidebarBookmarks *sidebar_bookmarks,
5863 ev_window_cmd_bookmarks_add (NULL, window);
5867 register_custom_actions (EvWindow *window, GtkActionGroup *group)
5871 action = g_object_new (EV_TYPE_PAGE_ACTION,
5872 "name", PAGE_SELECTOR_ACTION,
5874 "tooltip", _("Select Page"),
5875 "icon_name", "text-x-generic",
5876 "visible_overflown", FALSE,
5878 ev_page_action_set_model (EV_PAGE_ACTION (action),
5879 window->priv->model);
5880 g_signal_connect (action, "activate_link",
5881 G_CALLBACK (activate_link_cb), window);
5882 gtk_action_group_add_action (group, action);
5883 g_object_unref (action);
5885 action = g_object_new (EPHY_TYPE_ZOOM_ACTION,
5886 "name", ZOOM_CONTROL_ACTION,
5888 "stock_id", EV_STOCK_ZOOM,
5889 "tooltip", _("Adjust the zoom level"),
5892 g_signal_connect (action, "zoom_to_level",
5893 G_CALLBACK (zoom_control_changed_cb), window);
5894 gtk_action_group_add_action (group, action);
5895 g_object_unref (action);
5897 action = g_object_new (EV_TYPE_NAVIGATION_ACTION,
5898 "name", NAVIGATION_ACTION,
5899 "label", _("Navigation"),
5900 "is_important", TRUE,
5901 "short_label", _("Back"),
5902 "stock_id", GTK_STOCK_GO_DOWN,
5903 /*translators: this is the history action*/
5904 "tooltip", _("Move across visited pages"),
5906 g_signal_connect (action, "activate_link",
5907 G_CALLBACK (navigation_action_activate_link_cb), window);
5908 gtk_action_group_add_action (group, action);
5909 g_object_unref (action);
5911 action = g_object_new (EV_TYPE_OPEN_RECENT_ACTION,
5912 "name", "FileOpenRecent",
5913 "label", _("_Open…"),
5914 "tooltip", _("Open an existing document"),
5915 "stock_id", GTK_STOCK_OPEN,
5917 g_signal_connect (action, "activate",
5918 G_CALLBACK (ev_window_cmd_file_open), window);
5919 g_signal_connect (action, "item_activated",
5920 G_CALLBACK (ev_window_open_recent_action_item_activated),
5922 gtk_action_group_add_action (group, action);
5923 g_object_unref (action);
5927 set_action_properties (GtkActionGroup *action_group)
5931 action = gtk_action_group_get_action (action_group, "FileOpenContainingFolder");
5932 /*translators: this is the label for toolbar button*/
5933 g_object_set (action, "short_label", _("Open Folder"), NULL);
5935 action = gtk_action_group_get_action (action_group, "GoPreviousPage");
5936 g_object_set (action, "is-important", TRUE, NULL);
5937 /*translators: this is the label for toolbar button*/
5938 g_object_set (action, "short_label", _("Previous"), NULL);
5940 action = gtk_action_group_get_action (action_group, "GoNextPage");
5941 g_object_set (action, "is-important", TRUE, NULL);
5942 /*translators: this is the label for toolbar button*/
5943 g_object_set (action, "short_label", _("Next"), NULL);
5945 action = gtk_action_group_get_action (action_group, "ViewZoomIn");
5946 /*translators: this is the label for toolbar button*/
5947 g_object_set (action, "short_label", _("Zoom In"), NULL);
5949 action = gtk_action_group_get_action (action_group, "ViewZoomOut");
5950 /*translators: this is the label for toolbar button*/
5951 g_object_set (action, "short_label", _("Zoom Out"), NULL);
5953 action = gtk_action_group_get_action (action_group, "ViewBestFit");
5954 /*translators: this is the label for toolbar button*/
5955 g_object_set (action, "short_label", _("Best Fit"), NULL);
5957 action = gtk_action_group_get_action (action_group, "ViewPageWidth");
5958 /*translators: this is the label for toolbar button*/
5959 g_object_set (action, "short_label", _("Fit Width"), NULL);
5961 action = gtk_action_group_get_action (action_group, "LeaveFullscreen");
5962 g_object_set (action, "is-important", TRUE, NULL);
5966 sidebar_widget_model_set (EvSidebarLinks *ev_sidebar_links,
5968 EvWindow *ev_window)
5970 GtkTreeModel *model;
5973 g_object_get (G_OBJECT (ev_sidebar_links),
5977 action = gtk_action_group_get_action (ev_window->priv->action_group, PAGE_SELECTOR_ACTION);
5978 ev_page_action_set_links_model (EV_PAGE_ACTION (action), model);
5979 g_object_unref (model);
5983 view_actions_focus_in_cb (GtkWidget *widget, GdkEventFocus *event, EvWindow *window)
5988 keys = ev_application_get_media_keys (EV_APP);
5989 ev_media_player_keys_focused (EV_MEDIA_PLAYER_KEYS (keys));
5990 #endif /* ENABLE_DBUS */
5992 update_chrome_flag (window, EV_CHROME_RAISE_TOOLBAR, FALSE);
5993 ev_window_set_action_sensitive (window, "ViewToolbar", TRUE);
5995 ev_window_set_view_accels_sensitivity (window, TRUE);
5997 update_chrome_visibility (window);
6003 view_actions_focus_out_cb (GtkWidget *widget, GdkEventFocus *event, EvWindow *window)
6005 ev_window_set_view_accels_sensitivity (window, FALSE);
6011 sidebar_page_main_widget_update_cb (GObject *ev_sidebar_page,
6013 EvWindow *ev_window)
6017 g_object_get (ev_sidebar_page, "main_widget", &widget, NULL);
6019 if (widget != NULL) {
6020 g_signal_connect_object (widget, "focus_in_event",
6021 G_CALLBACK (view_actions_focus_in_cb),
6023 g_signal_connect_object (widget, "focus_out_event",
6024 G_CALLBACK (view_actions_focus_out_cb),
6026 g_object_unref (widget);
6031 window_state_event_cb (EvWindow *window, GdkEventWindowState *event, gpointer dummy)
6033 if (!(event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN)) {
6036 maximized = event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED;
6037 if (window->priv->metadata && !ev_window_is_empty (window))
6038 ev_metadata_set_boolean (window->priv->metadata, "window_maximized", maximized);
6045 window_configure_event_cb (EvWindow *window, GdkEventConfigure *event, gpointer dummy)
6047 GdkWindowState state;
6048 gdouble document_width, document_height;
6050 if (!window->priv->metadata)
6053 state = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (window)));
6055 if (!(state & GDK_WINDOW_STATE_FULLSCREEN)) {
6056 if (window->priv->document) {
6057 ev_document_get_max_page_size (window->priv->document,
6058 &document_width, &document_height);
6059 g_settings_set (window->priv->default_settings, "window-ratio", "(dd)",
6060 (double)event->width / document_width,
6061 (double)event->height / document_height);
6063 ev_metadata_set_int (window->priv->metadata, "window_x", event->x);
6064 ev_metadata_set_int (window->priv->metadata, "window_y", event->y);
6065 ev_metadata_set_int (window->priv->metadata, "window_width", event->width);
6066 ev_metadata_set_int (window->priv->metadata, "window_height", event->height);
6074 launch_action (EvWindow *window, EvLinkAction *action)
6076 const char *filename = ev_link_action_get_filename (action);
6079 GList file_list = {NULL};
6080 GAppLaunchContext *context;
6081 GError *error = NULL;
6083 if (filename == NULL)
6086 if (g_path_is_absolute (filename)) {
6087 file = g_file_new_for_path (filename);
6092 dir = g_path_get_dirname (window->priv->uri);
6093 base_file = g_file_new_for_uri (dir);
6096 file = g_file_resolve_relative_path (base_file, filename);
6097 g_object_unref (base_file);
6100 app_info = g_file_query_default_handler (file, NULL, &error);
6102 ev_window_error_message (window, error,
6104 _("Unable to launch external application."));
6105 g_object_unref (file);
6106 g_error_free (error);
6111 context = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
6112 gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (context),
6113 gtk_window_get_screen (GTK_WINDOW (window)));
6114 gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (context),
6115 gtk_get_current_event_time ());
6117 file_list.data = file;
6118 if (!g_app_info_launch (app_info, &file_list, context, &error)) {
6119 ev_window_error_message (window, error,
6121 _("Unable to launch external application."));
6122 g_error_free (error);
6125 g_object_unref (app_info);
6126 g_object_unref (file);
6127 /* FIXMEchpe: unref launch context? */
6129 /* According to the PDF spec filename can be an executable. I'm not sure
6130 allowing to launch executables is a good idea though. -- marco */
6134 launch_external_uri (EvWindow *window, EvLinkAction *action)
6136 const gchar *uri = ev_link_action_get_uri (action);
6137 GError *error = NULL;
6139 GAppLaunchContext *context;
6141 context = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
6142 gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (context),
6143 gtk_window_get_screen (GTK_WINDOW (window)));
6144 gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (context),
6145 gtk_get_current_event_time ());
6147 if (!g_strstr_len (uri, strlen (uri), "://") &&
6148 !g_str_has_prefix (uri, "mailto:")) {
6151 /* Not a valid uri, assume http if it starts with www */
6152 if (g_str_has_prefix (uri, "www.")) {
6153 new_uri = g_strdup_printf ("http://%s", uri);
6155 GFile *file, *parent;
6157 file = g_file_new_for_uri (window->priv->uri);
6158 parent = g_file_get_parent (file);
6159 g_object_unref (file);
6161 gchar *parent_uri = g_file_get_uri (parent);
6163 new_uri = g_build_filename (parent_uri, uri, NULL);
6164 g_free (parent_uri);
6165 g_object_unref (parent);
6167 new_uri = g_strdup_printf ("file:///%s", uri);
6170 ret = g_app_info_launch_default_for_uri (new_uri, context, &error);
6173 ret = g_app_info_launch_default_for_uri (uri, context, &error);
6177 ev_window_error_message (window, error,
6178 "%s", _("Unable to open external link"));
6179 g_error_free (error);
6182 /* FIXMEchpe: unref launch context? */
6186 open_remote_link (EvWindow *window, EvLinkAction *action)
6191 dir = g_path_get_dirname (window->priv->uri);
6193 uri = g_build_filename (dir, ev_link_action_get_filename (action),
6197 ev_application_open_uri_at_dest (EV_APP, uri,
6198 gtk_window_get_screen (GTK_WINDOW (window)),
6199 ev_link_action_get_dest (action),
6202 gtk_get_current_event_time ());
6208 do_action_named (EvWindow *window, EvLinkAction *action)
6210 const gchar *name = ev_link_action_get_name (action);
6212 if (g_ascii_strcasecmp (name, "FirstPage") == 0) {
6213 ev_window_cmd_go_first_page (NULL, window);
6214 } else if (g_ascii_strcasecmp (name, "PrevPage") == 0) {
6215 ev_window_cmd_go_previous_page (NULL, window);
6216 } else if (g_ascii_strcasecmp (name, "NextPage") == 0) {
6217 ev_window_cmd_go_next_page (NULL, window);
6218 } else if (g_ascii_strcasecmp (name, "LastPage") == 0) {
6219 ev_window_cmd_go_last_page (NULL, window);
6220 } else if (g_ascii_strcasecmp (name, "GoToPage") == 0) {
6221 ev_window_cmd_focus_page_selector (NULL, window);
6222 } else if (g_ascii_strcasecmp (name, "Find") == 0) {
6223 ev_window_cmd_edit_find (NULL, window);
6224 } else if (g_ascii_strcasecmp (name, "Close") == 0) {
6225 ev_window_cmd_file_close_window (NULL, window);
6226 } else if (g_ascii_strcasecmp (name, "Print") == 0) {
6227 ev_window_cmd_file_print (NULL, window);
6229 g_warning ("Unimplemented named action: %s, please post a "
6230 "bug report in Evince bugzilla "
6231 "(http://bugzilla.gnome.org) with a testcase.",
6237 view_external_link_cb (EvWindow *window, EvLinkAction *action)
6239 switch (ev_link_action_get_action_type (action)) {
6240 case EV_LINK_ACTION_TYPE_GOTO_DEST: {
6243 dest = ev_link_action_get_dest (action);
6247 ev_window_open_copy_at_dest (window, dest);
6250 case EV_LINK_ACTION_TYPE_EXTERNAL_URI:
6251 launch_external_uri (window, action);
6253 case EV_LINK_ACTION_TYPE_LAUNCH:
6254 launch_action (window, action);
6256 case EV_LINK_ACTION_TYPE_GOTO_REMOTE:
6257 open_remote_link (window, action);
6259 case EV_LINK_ACTION_TYPE_NAMED:
6260 do_action_named (window, action);
6263 g_assert_not_reached ();
6268 ev_view_popup_cmd_open_link (GtkAction *action, EvWindow *window)
6270 ev_view_handle_link (EV_VIEW (window->priv->view), window->priv->link);
6274 ev_view_popup_cmd_open_link_new_window (GtkAction *action, EvWindow *window)
6276 EvLinkAction *ev_action = NULL;
6279 ev_action = ev_link_get_action (window->priv->link);
6283 dest = ev_link_action_get_dest (ev_action);
6287 ev_window_open_copy_at_dest (window, dest);
6291 ev_view_popup_cmd_copy_link_address (GtkAction *action, EvWindow *window)
6293 EvLinkAction *ev_action;
6295 ev_action = ev_link_get_action (window->priv->link);
6299 ev_view_copy_link_address (EV_VIEW (window->priv->view),
6305 image_save_dialog_response_cb (GtkWidget *fc,
6307 EvWindow *ev_window)
6311 GError *error = NULL;
6317 GdkPixbufFormat *format;
6318 GtkFileFilter *filter;
6320 if (response_id != GTK_RESPONSE_OK) {
6321 gtk_widget_destroy (fc);
6325 uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
6326 filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (fc));
6327 format = g_object_get_data (G_OBJECT (filter), "pixbuf-format");
6329 if (format == NULL) {
6330 format = get_gdk_pixbuf_format_by_extension (uri);
6333 if (format == NULL && g_strrstr (uri, ".") == NULL) {
6334 /* no extension found and no extension provided within uri */
6335 format = get_gdk_pixbuf_format_by_extension (".png");
6336 if (format == NULL) {
6337 /* no .png support, try .jpeg */
6338 format = get_gdk_pixbuf_format_by_extension (".jpeg");
6342 if (format == NULL) {
6343 ev_window_error_message (ev_window, NULL,
6345 _("Couldn't find appropriate format to save image"));
6347 gtk_widget_destroy (fc);
6352 extensions = gdk_pixbuf_format_get_extensions (format);
6353 if (!g_str_has_suffix (uri, extensions[0])) {
6354 gchar *uri_extension;
6356 uri_extension = g_strconcat (uri, ".", extensions[0], NULL);
6357 target_file = g_file_new_for_uri (uri_extension);
6358 g_free (uri_extension);
6360 target_file = g_file_new_for_uri (uri);
6362 g_strfreev (extensions);
6365 is_native = g_file_is_native (target_file);
6367 filename = g_file_get_path (target_file);
6369 /* Create a temporary local file to save to */
6370 if (ev_mkstemp ("saveimage.XXXXXX", &filename, &error) == -1)
6374 ev_document_doc_mutex_lock ();
6375 pixbuf = ev_document_images_get_image (EV_DOCUMENT_IMAGES (ev_window->priv->document),
6376 ev_window->priv->image);
6377 ev_document_doc_mutex_unlock ();
6379 file_format = gdk_pixbuf_format_get_name (format);
6380 gdk_pixbuf_save (pixbuf, filename, file_format, &error, NULL);
6381 g_free (file_format);
6382 g_object_unref (pixbuf);
6386 ev_window_error_message (ev_window, error,
6387 "%s", _("The image could not be saved."));
6388 g_error_free (error);
6390 g_object_unref (target_file);
6391 gtk_widget_destroy (fc);
6399 source_file = g_file_new_for_path (filename);
6401 ev_window_save_remote (ev_window, EV_SAVE_IMAGE,
6402 source_file, target_file);
6403 g_object_unref (source_file);
6407 g_object_unref (target_file);
6408 gtk_widget_destroy (fc);
6412 ev_view_popup_cmd_save_image_as (GtkAction *action, EvWindow *window)
6416 if (!window->priv->image)
6419 fc = gtk_file_chooser_dialog_new (_("Save Image"),
6420 GTK_WINDOW (window),
6421 GTK_FILE_CHOOSER_ACTION_SAVE,
6423 GTK_RESPONSE_CANCEL,
6424 GTK_STOCK_SAVE, GTK_RESPONSE_OK,
6427 gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
6428 gtk_dialog_set_alternative_button_order (GTK_DIALOG (fc),
6430 GTK_RESPONSE_CANCEL,
6433 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (fc), FALSE);
6434 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
6436 file_chooser_dialog_add_writable_pixbuf_formats (GTK_FILE_CHOOSER (fc));
6438 g_signal_connect (fc, "response",
6439 G_CALLBACK (image_save_dialog_response_cb),
6442 gtk_widget_show (fc);
6446 ev_view_popup_cmd_copy_image (GtkAction *action, EvWindow *window)
6448 GtkClipboard *clipboard;
6451 if (!window->priv->image)
6454 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (window),
6455 GDK_SELECTION_CLIPBOARD);
6456 ev_document_doc_mutex_lock ();
6457 pixbuf = ev_document_images_get_image (EV_DOCUMENT_IMAGES (window->priv->document),
6458 window->priv->image);
6459 ev_document_doc_mutex_unlock ();
6461 gtk_clipboard_set_image (clipboard, pixbuf);
6462 g_object_unref (pixbuf);
6466 ev_view_popup_cmd_annot_properties (GtkAction *action,
6469 const gchar *author;
6472 gboolean popup_is_open;
6473 EvAnnotationPropertiesDialog *dialog;
6474 EvAnnotation *annot = window->priv->annot;
6475 EvAnnotationsSaveMask mask = EV_ANNOTATIONS_SAVE_NONE;
6480 dialog = EV_ANNOTATION_PROPERTIES_DIALOG (ev_annotation_properties_dialog_new_with_annotation (window->priv->annot));
6481 if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_APPLY) {
6482 gtk_widget_destroy (GTK_WIDGET (dialog));
6487 /* Set annotations changes */
6488 author = ev_annotation_properties_dialog_get_author (dialog);
6489 if (ev_annotation_markup_set_label (EV_ANNOTATION_MARKUP (annot), author))
6490 mask |= EV_ANNOTATIONS_SAVE_LABEL;
6492 ev_annotation_properties_dialog_get_color (dialog, &color);
6493 if (ev_annotation_set_color (annot, &color))
6494 mask |= EV_ANNOTATIONS_SAVE_COLOR;
6496 opacity = ev_annotation_properties_dialog_get_opacity (dialog);
6497 if (ev_annotation_markup_set_opacity (EV_ANNOTATION_MARKUP (annot), opacity))
6498 mask |= EV_ANNOTATIONS_SAVE_OPACITY;
6500 popup_is_open = ev_annotation_properties_dialog_get_popup_is_open (dialog);
6501 if (ev_annotation_markup_set_popup_is_open (EV_ANNOTATION_MARKUP (annot), popup_is_open))
6502 mask |= EV_ANNOTATIONS_SAVE_POPUP_IS_OPEN;
6504 if (EV_IS_ANNOTATION_TEXT (annot)) {
6505 EvAnnotationTextIcon icon;
6507 icon = ev_annotation_properties_dialog_get_text_icon (dialog);
6508 if (ev_annotation_text_set_icon (EV_ANNOTATION_TEXT (annot), icon))
6509 mask |= EV_ANNOTATIONS_SAVE_TEXT_ICON;
6512 if (mask != EV_ANNOTATIONS_SAVE_NONE) {
6513 ev_document_doc_mutex_lock ();
6514 ev_document_annotations_save_annotation (EV_DOCUMENT_ANNOTATIONS (window->priv->document),
6515 window->priv->annot,
6517 ev_document_doc_mutex_unlock ();
6519 /* FIXME: update annot region only */
6520 ev_view_reload (EV_VIEW (window->priv->view));
6523 gtk_widget_destroy (GTK_WIDGET (dialog));
6527 ev_attachment_popup_cmd_open_attachment (GtkAction *action, EvWindow *window)
6532 if (!window->priv->attach_list)
6535 screen = gtk_window_get_screen (GTK_WINDOW (window));
6537 for (l = window->priv->attach_list; l && l->data; l = g_list_next (l)) {
6538 EvAttachment *attachment;
6539 GError *error = NULL;
6541 attachment = (EvAttachment *) l->data;
6543 ev_attachment_open (attachment, screen, gtk_get_current_event_time (), &error);
6546 ev_window_error_message (window, error,
6547 "%s", _("Unable to open attachment"));
6548 g_error_free (error);
6554 attachment_save_dialog_response_cb (GtkWidget *fc,
6556 EvWindow *ev_window)
6561 GtkFileChooserAction fc_action;
6565 if (response_id != GTK_RESPONSE_OK) {
6566 gtk_widget_destroy (fc);
6570 uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
6571 target_file = g_file_new_for_uri (uri);
6572 g_object_get (G_OBJECT (fc), "action", &fc_action, NULL);
6573 is_dir = (fc_action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
6574 is_native = g_file_is_native (target_file);
6576 for (l = ev_window->priv->attach_list; l && l->data; l = g_list_next (l)) {
6577 EvAttachment *attachment;
6578 GFile *save_to = NULL;
6579 GError *error = NULL;
6581 attachment = (EvAttachment *) l->data;
6585 save_to = g_file_get_child (target_file,
6586 /* FIXMEchpe: file name encoding! */
6587 ev_attachment_get_name (attachment));
6589 save_to = g_object_ref (target_file);
6592 save_to = ev_mkstemp_file ("saveattachment.XXXXXX", &error);
6596 ev_attachment_save (attachment, save_to, &error);
6599 ev_window_error_message (ev_window, error,
6600 "%s", _("The attachment could not be saved."));
6601 g_error_free (error);
6602 g_object_unref (save_to);
6611 dest_file = g_file_get_child (target_file,
6612 ev_attachment_get_name (attachment));
6614 dest_file = g_object_ref (target_file);
6617 ev_window_save_remote (ev_window, EV_SAVE_ATTACHMENT,
6618 save_to, dest_file);
6620 g_object_unref (dest_file);
6623 g_object_unref (save_to);
6627 g_object_unref (target_file);
6629 gtk_widget_destroy (fc);
6633 ev_attachment_popup_cmd_save_attachment_as (GtkAction *action, EvWindow *window)
6636 EvAttachment *attachment = NULL;
6638 if (!window->priv->attach_list)
6641 if (g_list_length (window->priv->attach_list) == 1)
6642 attachment = (EvAttachment *) window->priv->attach_list->data;
6644 fc = gtk_file_chooser_dialog_new (
6645 _("Save Attachment"),
6646 GTK_WINDOW (window),
6647 attachment ? GTK_FILE_CHOOSER_ACTION_SAVE : GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
6649 GTK_RESPONSE_CANCEL,
6650 GTK_STOCK_SAVE, GTK_RESPONSE_OK,
6653 gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
6654 gtk_dialog_set_alternative_button_order (GTK_DIALOG (fc),
6656 GTK_RESPONSE_CANCEL,
6659 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
6660 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (fc), FALSE);
6663 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc),
6664 ev_attachment_get_name (attachment));
6666 g_signal_connect (fc, "response",
6667 G_CALLBACK (attachment_save_dialog_response_cb),
6670 gtk_widget_show (fc);
6674 ev_window_media_player_key_pressed (EvWindow *window,
6678 if (!gtk_window_is_active (GTK_WINDOW (window)))
6681 /* Note how Previous/Next only go to the
6682 * next/previous page despite their icon telling you
6683 * they should go to the beginning/end.
6685 * There's very few keyboards with FFW/RWD though,
6686 * so we stick the most useful keybinding on the most
6689 if (strcmp (key, "Play") == 0) {
6690 ev_window_run_presentation (window);
6691 } else if (strcmp (key, "Previous") == 0) {
6692 ev_window_cmd_go_previous_page (NULL, window);
6693 } else if (strcmp (key, "Next") == 0) {
6694 ev_window_cmd_go_next_page (NULL, window);
6695 } else if (strcmp (key, "FastForward") == 0) {
6696 ev_window_cmd_go_last_page (NULL, window);
6697 } else if (strcmp (key, "Rewind") == 0) {
6698 ev_window_cmd_go_first_page (NULL, window);
6702 static EggToolbarsModel *
6703 get_toolbars_model (void)
6705 EggToolbarsModel *toolbars_model;
6706 gchar *toolbars_file;
6707 gchar *toolbars_path;
6710 toolbars_model = egg_toolbars_model_new ();
6712 toolbars_file = g_build_filename (ev_application_get_dot_dir (EV_APP, FALSE),
6713 "evince_toolbar.xml", NULL);
6714 toolbars_path = g_build_filename (ev_application_get_data_dir (EV_APP),
6715 "evince-toolbar.xml", NULL);
6716 egg_toolbars_model_load_names (toolbars_model, toolbars_path);
6718 if (!egg_toolbars_model_load_toolbars (toolbars_model, toolbars_file)) {
6719 egg_toolbars_model_load_toolbars (toolbars_model, toolbars_path);
6720 goto skip_conversion;
6723 /* Open item doesn't exist anymore,
6724 * convert it to OpenRecent for compatibility
6726 for (i = 0; i < egg_toolbars_model_n_items (toolbars_model, 0); i++) {
6729 item = egg_toolbars_model_item_nth (toolbars_model, 0, i);
6730 if (g_ascii_strcasecmp (item, "FileOpen") == 0) {
6731 egg_toolbars_model_remove_item (toolbars_model, 0, i);
6732 egg_toolbars_model_add_item (toolbars_model, 0, i,
6734 egg_toolbars_model_save_toolbars (toolbars_model, toolbars_file, "1.0");
6740 g_free (toolbars_file);
6741 g_free (toolbars_path);
6743 egg_toolbars_model_set_flags (toolbars_model, 0, EGG_TB_MODEL_NOT_REMOVABLE);
6745 return toolbars_model;
6750 ev_window_sync_source (EvWindow *window,
6753 GDBusConnection *connection;
6754 GError *error = NULL;
6759 if (window->priv->dbus_object_id <= 0)
6762 connection = ev_application_get_dbus_connection (EV_APP);
6766 timestamp = gtk_get_current_event_time ();
6767 if (g_path_is_absolute (link->filename)) {
6768 input_gfile = g_file_new_for_path (link->filename);
6770 GFile *gfile, *parent_gfile;
6772 gfile = g_file_new_for_uri (window->priv->uri);
6773 parent_gfile = g_file_get_parent (gfile);
6775 /* parent_gfile should never be NULL */
6776 if (parent_gfile == NULL) {
6777 g_printerr ("Document URI is '/'\n");
6781 input_gfile = g_file_get_child (parent_gfile, link->filename);
6782 g_object_unref (parent_gfile);
6783 g_object_unref (gfile);
6786 uri_input = g_file_get_uri (input_gfile);
6787 g_object_unref (input_gfile);
6789 g_dbus_connection_emit_signal (connection,
6791 window->priv->dbus_object_path,
6792 EV_WINDOW_DBUS_INTERFACE,
6794 g_variant_new ("(s(ii)u)",
6802 g_printerr ("Failed to emit DBus signal SyncSource: %s\n",
6804 g_error_free (error);
6809 ev_window_emit_closed (EvWindow *window)
6811 GDBusConnection *connection;
6812 GError *error = NULL;
6814 if (window->priv->dbus_object_id <= 0)
6817 connection = ev_application_get_dbus_connection (EV_APP);
6821 g_dbus_connection_emit_signal (connection,
6823 window->priv->dbus_object_path,
6824 EV_WINDOW_DBUS_INTERFACE,
6829 g_printerr ("Failed to emit DBus signal Closed: %s\n",
6831 g_error_free (error);
6836 /* If this is the last window call g_dbus_connection_flush_sync()
6837 * to make sure the signal is emitted.
6839 if (ev_application_get_n_windows (EV_APP) == 1)
6840 g_dbus_connection_flush_sync (connection, NULL, NULL);
6844 ev_window_emit_doc_loaded (EvWindow *window)
6846 GDBusConnection *connection;
6847 GError *error = NULL;
6849 if (window->priv->dbus_object_id <= 0)
6852 connection = ev_application_get_dbus_connection (EV_APP);
6856 g_dbus_connection_emit_signal (connection,
6858 window->priv->dbus_object_path,
6859 EV_WINDOW_DBUS_INTERFACE,
6861 g_variant_new("(s)", window->priv->uri),
6864 g_printerr ("Failed to emit DBus signal DocumentLoaded: %s\n",
6866 g_error_free (error);
6873 method_call_cb (GDBusConnection *connection,
6874 const gchar *sender,
6875 const gchar *object_path,
6876 const gchar *interface_name,
6877 const gchar *method_name,
6878 GVariant *parameters,
6879 GDBusMethodInvocation *invocation,
6882 EvWindow *window = EV_WINDOW (user_data);
6884 if (g_strcmp0 (method_name, "SyncView") != 0)
6887 if (window->priv->document && ev_document_has_synctex (window->priv->document)) {
6891 g_variant_get (parameters, "(&s(ii)u)", &link.filename, &link.line, &link.col, ×tamp);
6892 ev_view_highlight_forward_search (EV_VIEW (window->priv->view), &link);
6893 gtk_window_present_with_time (GTK_WINDOW (window), timestamp);
6896 g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
6899 static const char introspection_xml[] =
6901 "<interface name='org.gnome.evince.Window'>"
6902 "<method name='SyncView'>"
6903 "<arg type='s' name='source_file' direction='in'/>"
6904 "<arg type='(ii)' name='source_point' direction='in'/>"
6905 "<arg type='u' name='timestamp' direction='in'/>"
6907 "<signal name='SyncSource'>"
6908 "<arg type='s' name='source_file' direction='out'/>"
6909 "<arg type='(ii)' name='source_point' direction='out'/>"
6910 "<arg type='u' name='timestamp' direction='out'/>"
6912 "<signal name='Closed'/>"
6913 "<signal name='DocumentLoaded'>"
6914 "<arg type='s' name='uri' direction='out'/>"
6919 static const GDBusInterfaceVTable interface_vtable = {
6925 static GDBusNodeInfo *introspection_data;
6926 #endif /* ENABLE_DBUS */
6929 ev_window_init (EvWindow *ev_window)
6931 GtkActionGroup *action_group;
6932 GtkAccelGroup *accel_group;
6933 GError *error = NULL;
6934 GtkWidget *sidebar_widget;
6935 GtkWidget *menuitem;
6936 EggToolbarsModel *toolbars_model;
6940 GDBusConnection *connection;
6941 static gint window_id = 0;
6944 g_signal_connect (ev_window, "configure_event",
6945 G_CALLBACK (window_configure_event_cb), NULL);
6946 g_signal_connect (ev_window, "window_state_event",
6947 G_CALLBACK (window_state_event_cb), NULL);
6949 ev_window->priv = EV_WINDOW_GET_PRIVATE (ev_window);
6952 connection = ev_application_get_dbus_connection (EV_APP);
6954 if (!introspection_data) {
6955 introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, &error);
6956 if (error) g_warning ("%s\n", error->message);
6958 g_assert (introspection_data != NULL);
6960 ev_window->priv->dbus_object_path = g_strdup_printf (EV_WINDOW_DBUS_OBJECT_PATH, window_id++);
6961 ev_window->priv->dbus_object_id =
6962 g_dbus_connection_register_object (connection,
6963 ev_window->priv->dbus_object_path,
6964 introspection_data->interfaces[0],
6968 if (ev_window->priv->dbus_object_id == 0) {
6969 g_printerr ("Failed to register bus object %s: %s\n",
6970 ev_window->priv->dbus_object_path, error->message);
6971 g_error_free (error);
6972 g_free (ev_window->priv->dbus_object_path);
6973 ev_window->priv->dbus_object_path = NULL;
6978 #endif /* ENABLE_DBUS */
6980 ev_window->priv->model = ev_document_model_new ();
6982 ev_window->priv->page_mode = PAGE_MODE_DOCUMENT;
6983 ev_window->priv->title = ev_window_title_new (ev_window);
6985 ev_window->priv->main_box = gtk_vbox_new (FALSE, 0);
6986 gtk_container_add (GTK_CONTAINER (ev_window), ev_window->priv->main_box);
6987 gtk_widget_show (ev_window->priv->main_box);
6989 action_group = gtk_action_group_new ("MenuActions");
6990 ev_window->priv->action_group = action_group;
6991 gtk_action_group_set_translation_domain (action_group, NULL);
6992 gtk_action_group_add_actions (action_group, entries,
6993 G_N_ELEMENTS (entries), ev_window);
6994 gtk_action_group_add_toggle_actions (action_group, toggle_entries,
6995 G_N_ELEMENTS (toggle_entries),
6997 set_action_properties (action_group);
6998 register_custom_actions (ev_window, action_group);
7000 ev_window->priv->ui_manager = gtk_ui_manager_new ();
7001 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
7005 gtk_ui_manager_get_accel_group (ev_window->priv->ui_manager);
7006 gtk_window_add_accel_group (GTK_WINDOW (ev_window), accel_group);
7008 ev_window_set_view_accels_sensitivity (ev_window, FALSE);
7010 action_group = gtk_action_group_new ("ViewPopupActions");
7011 ev_window->priv->view_popup_action_group = action_group;
7012 gtk_action_group_set_translation_domain (action_group, NULL);
7013 gtk_action_group_add_actions (action_group, view_popup_entries,
7014 G_N_ELEMENTS (view_popup_entries),
7016 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
7019 action_group = gtk_action_group_new ("AttachmentPopupActions");
7020 ev_window->priv->attachment_popup_action_group = action_group;
7021 gtk_action_group_set_translation_domain (action_group, NULL);
7022 gtk_action_group_add_actions (action_group, attachment_popup_entries,
7023 G_N_ELEMENTS (attachment_popup_entries),
7025 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
7028 ui_path = g_build_filename (ev_application_get_data_dir (EV_APP),
7029 "evince-ui.xml", NULL);
7030 if (!gtk_ui_manager_add_ui_from_file (
7031 ev_window->priv->ui_manager, ui_path, &error))
7033 g_warning ("building menus failed: %s", error->message);
7034 g_error_free (error);
7038 ev_window->priv->recent_manager = gtk_recent_manager_get_default ();
7039 ev_window->priv->recent_action_group = NULL;
7040 ev_window->priv->recent_ui_id = 0;
7041 g_signal_connect_swapped (ev_window->priv->recent_manager,
7043 G_CALLBACK (ev_window_setup_recent),
7046 ev_window->priv->menubar =
7047 gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
7049 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box),
7050 ev_window->priv->menubar,
7052 menuitem = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
7053 "/MainMenu/EditMenu/EditRotateLeftMenu");
7054 gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menuitem), TRUE);
7055 menuitem = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
7056 "/MainMenu/EditMenu/EditRotateRightMenu");
7057 gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menuitem), TRUE);
7059 toolbars_model = get_toolbars_model ();
7060 ev_window->priv->toolbar = GTK_WIDGET
7061 (g_object_new (EGG_TYPE_EDITABLE_TOOLBAR,
7062 "ui-manager", ev_window->priv->ui_manager,
7063 "popup-path", "/ToolbarPopup",
7064 "model", toolbars_model,
7066 g_object_unref (toolbars_model);
7068 egg_editable_toolbar_show (EGG_EDITABLE_TOOLBAR (ev_window->priv->toolbar),
7070 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box),
7071 ev_window->priv->toolbar,
7073 gtk_widget_show (ev_window->priv->toolbar);
7075 /* Add the main area */
7076 ev_window->priv->hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
7077 g_signal_connect (ev_window->priv->hpaned,
7079 G_CALLBACK (ev_window_sidebar_position_change_cb),
7082 gtk_paned_set_position (GTK_PANED (ev_window->priv->hpaned), SIDEBAR_DEFAULT_SIZE);
7083 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), ev_window->priv->hpaned,
7085 gtk_widget_show (ev_window->priv->hpaned);
7087 ev_window->priv->sidebar = ev_sidebar_new ();
7088 ev_sidebar_set_model (EV_SIDEBAR (ev_window->priv->sidebar),
7089 ev_window->priv->model);
7090 gtk_paned_pack1 (GTK_PANED (ev_window->priv->hpaned),
7091 ev_window->priv->sidebar, FALSE, FALSE);
7092 gtk_widget_show (ev_window->priv->sidebar);
7094 /* Stub sidebar, for now */
7096 sidebar_widget = ev_sidebar_thumbnails_new ();
7097 ev_window->priv->sidebar_thumbs = sidebar_widget;
7098 g_signal_connect (sidebar_widget,
7099 "notify::main-widget",
7100 G_CALLBACK (sidebar_page_main_widget_update_cb),
7102 sidebar_page_main_widget_update_cb (G_OBJECT (sidebar_widget), NULL, ev_window);
7103 gtk_widget_show (sidebar_widget);
7104 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7107 sidebar_widget = ev_sidebar_links_new ();
7108 ev_window->priv->sidebar_links = sidebar_widget;
7109 g_signal_connect (sidebar_widget,
7111 G_CALLBACK (sidebar_widget_model_set),
7113 g_signal_connect (sidebar_widget,
7115 G_CALLBACK (sidebar_links_link_activated_cb),
7117 sidebar_page_main_widget_update_cb (G_OBJECT (sidebar_widget), NULL, ev_window);
7118 gtk_widget_show (sidebar_widget);
7119 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7122 sidebar_widget = ev_sidebar_attachments_new ();
7123 ev_window->priv->sidebar_attachments = sidebar_widget;
7124 g_signal_connect_object (sidebar_widget,
7126 G_CALLBACK (attachment_bar_menu_popup_cb),
7128 gtk_widget_show (sidebar_widget);
7129 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7132 sidebar_widget = ev_sidebar_layers_new ();
7133 ev_window->priv->sidebar_layers = sidebar_widget;
7134 g_signal_connect (sidebar_widget,
7135 "layers_visibility_changed",
7136 G_CALLBACK (sidebar_layers_visibility_changed),
7138 gtk_widget_show (sidebar_widget);
7139 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7142 sidebar_widget = ev_sidebar_annotations_new ();
7143 ev_window->priv->sidebar_annots = sidebar_widget;
7144 g_signal_connect (sidebar_widget,
7146 G_CALLBACK (sidebar_annots_annot_activated_cb),
7148 g_signal_connect (sidebar_widget,
7150 G_CALLBACK (sidebar_annots_begin_annot_add),
7152 g_signal_connect (sidebar_widget,
7153 "annot_add_cancelled",
7154 G_CALLBACK (sidebar_annots_annot_add_cancelled),
7156 gtk_widget_show (sidebar_widget);
7157 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7160 sidebar_widget = ev_sidebar_bookmarks_new ();
7161 ev_window->priv->sidebar_bookmarks = sidebar_widget;
7162 g_signal_connect (sidebar_widget,
7164 G_CALLBACK (sidebar_bookmarks_add_bookmark),
7166 gtk_widget_show (sidebar_widget);
7167 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
7170 ev_window->priv->view_box = gtk_vbox_new (FALSE, 0);
7171 ev_window->priv->scrolled_window =
7172 GTK_WIDGET (g_object_new (GTK_TYPE_SCROLLED_WINDOW,
7173 "shadow-type", GTK_SHADOW_IN,
7175 gtk_box_pack_start (GTK_BOX (ev_window->priv->view_box),
7176 ev_window->priv->scrolled_window,
7178 gtk_widget_show (ev_window->priv->scrolled_window);
7180 gtk_paned_add2 (GTK_PANED (ev_window->priv->hpaned),
7181 ev_window->priv->view_box);
7182 gtk_widget_show (ev_window->priv->view_box);
7184 ev_window->priv->view = ev_view_new ();
7185 ev_view_set_page_cache_size (EV_VIEW (ev_window->priv->view), PAGE_CACHE_SIZE);
7186 ev_view_set_model (EV_VIEW (ev_window->priv->view), ev_window->priv->model);
7188 ev_window->priv->password_view = ev_password_view_new (GTK_WINDOW (ev_window));
7189 g_signal_connect_swapped (ev_window->priv->password_view,
7191 G_CALLBACK (ev_window_password_view_unlock),
7193 g_signal_connect_object (ev_window->priv->view, "focus_in_event",
7194 G_CALLBACK (view_actions_focus_in_cb),
7196 g_signal_connect_object (ev_window->priv->view, "focus_out_event",
7197 G_CALLBACK (view_actions_focus_out_cb),
7199 g_signal_connect_swapped (ev_window->priv->view, "external-link",
7200 G_CALLBACK (view_external_link_cb),
7202 g_signal_connect_object (ev_window->priv->view, "handle-link",
7203 G_CALLBACK (view_handle_link_cb),
7205 g_signal_connect_object (ev_window->priv->view, "popup",
7206 G_CALLBACK (view_menu_popup_cb),
7208 g_signal_connect_object (ev_window->priv->view, "selection-changed",
7209 G_CALLBACK (view_selection_changed_cb),
7211 g_signal_connect_object (ev_window->priv->view, "annot-added",
7212 G_CALLBACK (view_annot_added),
7214 g_signal_connect_object (ev_window->priv->view, "layers-changed",
7215 G_CALLBACK (view_layers_changed_cb),
7218 g_signal_connect_swapped (ev_window->priv->view, "sync-source",
7219 G_CALLBACK (ev_window_sync_source),
7222 gtk_widget_show (ev_window->priv->view);
7223 gtk_widget_show (ev_window->priv->password_view);
7226 ev_window->priv->find_bar = egg_find_bar_new ();
7227 gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
7228 ev_window->priv->find_bar,
7231 /* We own a ref on these widgets, as we can swap them in and out */
7232 g_object_ref (ev_window->priv->view);
7233 g_object_ref (ev_window->priv->password_view);
7235 gtk_container_add (GTK_CONTAINER (ev_window->priv->scrolled_window),
7236 ev_window->priv->view);
7238 /* Connect to model signals */
7239 g_signal_connect_swapped (ev_window->priv->model,
7241 G_CALLBACK (ev_window_page_changed_cb),
7243 g_signal_connect (ev_window->priv->model,
7245 G_CALLBACK (ev_window_document_changed_cb),
7247 g_signal_connect (ev_window->priv->model,
7249 G_CALLBACK (ev_window_zoom_changed_cb),
7251 g_signal_connect (ev_window->priv->model,
7252 "notify::sizing-mode",
7253 G_CALLBACK (ev_window_sizing_mode_changed_cb),
7255 g_signal_connect (ev_window->priv->model,
7257 G_CALLBACK (ev_window_rotation_changed_cb),
7259 g_signal_connect (ev_window->priv->model,
7260 "notify::continuous",
7261 G_CALLBACK (ev_window_continuous_changed_cb),
7263 g_signal_connect (ev_window->priv->model,
7264 "notify::dual-page",
7265 G_CALLBACK (ev_window_dual_mode_changed_cb),
7267 g_signal_connect (ev_window->priv->model,
7268 "notify::inverted-colors",
7269 G_CALLBACK (ev_window_inverted_colors_changed_cb),
7272 /* Connect sidebar signals */
7273 g_signal_connect (ev_window->priv->sidebar,
7275 G_CALLBACK (ev_window_sidebar_visibility_changed_cb),
7277 g_signal_connect (ev_window->priv->sidebar,
7278 "notify::current-page",
7279 G_CALLBACK (ev_window_sidebar_current_page_changed_cb),
7282 /* Connect to find bar signals */
7283 g_signal_connect (ev_window->priv->find_bar,
7285 G_CALLBACK (find_bar_previous_cb),
7287 g_signal_connect (ev_window->priv->find_bar,
7289 G_CALLBACK (find_bar_next_cb),
7291 g_signal_connect (ev_window->priv->find_bar,
7293 G_CALLBACK (find_bar_close_cb),
7295 g_signal_connect (ev_window->priv->find_bar,
7296 "notify::search-string",
7297 G_CALLBACK (find_bar_search_changed_cb),
7299 g_signal_connect (ev_window->priv->find_bar,
7300 "notify::case-sensitive",
7301 G_CALLBACK (find_bar_search_changed_cb),
7303 g_signal_connect (ev_window->priv->find_bar,
7305 G_CALLBACK (find_bar_visibility_changed_cb),
7307 g_signal_connect (ev_window->priv->find_bar,
7309 G_CALLBACK (find_bar_scroll),
7313 ev_window->priv->view_popup = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
7315 ev_window->priv->link = NULL;
7317 ev_window->priv->attachment_popup = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
7318 "/AttachmentPopup");
7319 ev_window->priv->attach_list = NULL;
7321 /* Media player keys */
7322 mpkeys = ev_application_get_media_keys (EV_APP);
7324 g_signal_connect_swapped (mpkeys, "key_pressed",
7325 G_CALLBACK (ev_window_media_player_key_pressed),
7329 /* Give focus to the document view */
7330 gtk_widget_grab_focus (ev_window->priv->view);
7332 ev_window->priv->default_settings = g_settings_new (GS_SCHEMA_NAME".Default");
7333 g_settings_delay (ev_window->priv->default_settings);
7335 /* Set it user interface params */
7336 ev_window_setup_recent (ev_window);
7338 ev_window_setup_gtk_settings (ev_window);
7340 setup_chrome_from_metadata (ev_window);
7341 update_chrome_actions (ev_window);
7342 update_chrome_visibility (ev_window);
7344 gtk_window_set_default_size (GTK_WINDOW (ev_window), 600, 600);
7346 setup_view_from_metadata (ev_window);
7347 setup_sidebar_from_metadata (ev_window);
7349 ev_window_sizing_mode_changed_cb (ev_window->priv->model, NULL, ev_window);
7350 ev_window_setup_action_sensitivity (ev_window);
7353 gtk_drag_dest_set (GTK_WIDGET (ev_window),
7354 GTK_DEST_DEFAULT_ALL,
7357 gtk_drag_dest_add_uri_targets (GTK_WIDGET (ev_window));
7363 * Creates a #GtkWidget that represents the window.
7365 * Returns: the #GtkWidget that represents the window.
7368 ev_window_new (void)
7370 GtkWidget *ev_window;
7372 ev_window = GTK_WIDGET (g_object_new (EV_TYPE_WINDOW,
7373 "type", GTK_WINDOW_TOPLEVEL,
7380 ev_window_get_dbus_object_path (EvWindow *ev_window)
7383 return ev_window->priv->dbus_object_path;