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.h"
79 #include "ev-sidebar-links.h"
80 #include "ev-sidebar-page.h"
81 #include "ev-sidebar-thumbnails.h"
82 #include "ev-sidebar-layers.h"
83 #include "ev-stock-icons.h"
85 #include "ev-keyring.h"
87 #include "ev-view-presentation.h"
88 #include "ev-view-type-builtins.h"
89 #include "ev-window.h"
90 #include "ev-window-title.h"
91 #include "ev-print-operation.h"
92 #include "ev-progress-message-area.h"
93 #include "ev-annotation-properties-dialog.h"
96 #include "ev-media-player-keys.h"
97 #endif /* ENABLE_DBUS */
105 EV_CHROME_MENUBAR = 1 << 0,
106 EV_CHROME_TOOLBAR = 1 << 1,
107 EV_CHROME_FINDBAR = 1 << 2,
108 EV_CHROME_RAISE_TOOLBAR = 1 << 3,
109 EV_CHROME_FULLSCREEN_TOOLBAR = 1 << 4,
110 EV_CHROME_SIDEBAR = 1 << 5,
111 EV_CHROME_NORMAL = EV_CHROME_MENUBAR | EV_CHROME_TOOLBAR | EV_CHROME_SIDEBAR
120 struct _EvWindowPrivate {
131 GtkWidget *scrolled_window;
133 GtkWidget *presentation_view;
134 GtkWidget *message_area;
135 GtkWidget *password_view;
136 GtkWidget *sidebar_thumbs;
137 GtkWidget *sidebar_links;
138 GtkWidget *sidebar_attachments;
139 GtkWidget *sidebar_layers;
140 GtkWidget *sidebar_annots;
144 GSettings *default_settings;
145 GSettings *lockdown_settings;
148 guint menubar_accel_keyval;
149 GdkModifierType menubar_accel_modifier;
151 /* Progress Messages */
153 GCancellable *progress_cancellable;
156 GtkWidget *properties;
157 GtkWidget *print_dialog;
160 GtkActionGroup *action_group;
161 GtkActionGroup *view_popup_action_group;
162 GtkActionGroup *attachment_popup_action_group;
163 GtkRecentManager *recent_manager;
164 GtkActionGroup *recent_action_group;
166 GtkUIManager *ui_manager;
168 /* Fullscreen mode */
169 GtkWidget *fullscreen_toolbar;
172 GtkWidget *view_popup;
177 /* Popup attachment */
178 GtkWidget *attachment_popup;
182 EvDocumentModel *model;
187 EvFileMonitor *monitor;
188 guint setup_document_idle;
190 EvDocument *document;
192 EvWindowPageMode page_mode;
193 EvWindowTitle *title;
194 EvMetadata *metadata;
199 gchar *search_string;
200 EvWindowRunMode window_mode;
204 EvJob *thumbnail_job;
210 GtkPrintSettings *print_settings;
211 GtkPageSetup *print_page_setup;
212 gboolean close_after_print;
216 guint dbus_object_id;
217 gchar *dbus_object_path;
221 #define EV_WINDOW_GET_PRIVATE(object) \
222 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_WINDOW, EvWindowPrivate))
224 #define EV_WINDOW_IS_PRESENTATION(w) (w->priv->presentation_view != NULL)
226 #define PAGE_SELECTOR_ACTION "PageSelector"
227 #define ZOOM_CONTROL_ACTION "ViewZoom"
228 #define NAVIGATION_ACTION "Navigation"
230 #define GS_LOCKDOWN_SCHEMA_NAME "org.gnome.desktop.lockdown"
231 #define GS_LOCKDOWN_SAVE "disable-save-to-disk"
232 #define GS_LOCKDOWN_PRINT "disable-printing"
233 #define GS_LOCKDOWN_PRINT_SETUP "disable-print-setup"
236 #define EV_WINDOW_DBUS_OBJECT_PATH "/org/gnome/evince/Window/%d"
237 #define EV_WINDOW_DBUS_INTERFACE "org.gnome.evince.Window"
240 #define GS_SCHEMA_NAME "org.gnome.Evince"
241 #define GS_OVERRIDE_RESTRICTIONS "override-restrictions"
243 #define SIDEBAR_DEFAULT_SIZE 132
244 #define LINKS_SIDEBAR_ID "links"
245 #define THUMBNAILS_SIDEBAR_ID "thumbnails"
246 #define ATTACHMENTS_SIDEBAR_ID "attachments"
247 #define LAYERS_SIDEBAR_ID "layers"
248 #define ANNOTS_SIDEBAR_ID "annotations"
250 #define EV_PRINT_SETTINGS_FILE "print-settings"
251 #define EV_PRINT_SETTINGS_GROUP "Print Settings"
252 #define EV_PAGE_SETUP_GROUP "Page Setup"
254 #define EV_TOOLBARS_FILENAME "evince-toolbar.xml"
256 #define MIN_SCALE 0.05409
257 #define PAGE_CACHE_SIZE 52428800 /* 50MB */
259 #define MAX_RECENT_ITEM_LEN (40)
261 static const gchar *document_print_settings[] = {
262 GTK_PRINT_SETTINGS_N_COPIES,
263 GTK_PRINT_SETTINGS_COLLATE,
264 GTK_PRINT_SETTINGS_REVERSE,
265 GTK_PRINT_SETTINGS_NUMBER_UP,
266 GTK_PRINT_SETTINGS_SCALE,
267 GTK_PRINT_SETTINGS_PRINT_PAGES,
268 GTK_PRINT_SETTINGS_PAGE_RANGES,
269 GTK_PRINT_SETTINGS_PAGE_SET,
270 GTK_PRINT_SETTINGS_OUTPUT_URI
273 static void ev_window_update_actions (EvWindow *ev_window);
274 static void ev_window_sidebar_visibility_changed_cb (EvSidebar *ev_sidebar,
276 EvWindow *ev_window);
277 static void ev_window_view_toolbar_cb (GtkAction *action,
278 EvWindow *ev_window);
279 static void ev_window_set_page_mode (EvWindow *window,
280 EvWindowPageMode page_mode);
281 static void ev_window_load_job_cb (EvJob *job,
283 static void ev_window_reload_document (EvWindow *window,
285 static void ev_window_reload_job_cb (EvJob *job,
287 static void ev_window_set_icon_from_thumbnail (EvJobThumbnail *job,
288 EvWindow *ev_window);
289 static void ev_window_save_job_cb (EvJob *save,
291 static void ev_window_sizing_mode_changed_cb (EvDocumentModel *model,
293 EvWindow *ev_window);
294 static void ev_window_zoom_changed_cb (EvDocumentModel *model,
296 EvWindow *ev_window);
297 static void ev_window_add_recent (EvWindow *window,
298 const char *filename);
299 static void ev_window_run_fullscreen (EvWindow *window);
300 static void ev_window_stop_fullscreen (EvWindow *window,
301 gboolean unfullscreen_window);
302 static void ev_window_cmd_view_fullscreen (GtkAction *action,
304 static void ev_window_run_presentation (EvWindow *window);
305 static void ev_window_stop_presentation (EvWindow *window,
306 gboolean unfullscreen_window);
307 static void ev_window_cmd_view_presentation (GtkAction *action,
309 static void ev_view_popup_cmd_open_link (GtkAction *action,
311 static void ev_view_popup_cmd_open_link_new_window (GtkAction *action,
313 static void ev_view_popup_cmd_copy_link_address (GtkAction *action,
315 static void ev_view_popup_cmd_save_image_as (GtkAction *action,
317 static void ev_view_popup_cmd_copy_image (GtkAction *action,
319 static void ev_view_popup_cmd_annot_properties (GtkAction *action,
321 static void ev_attachment_popup_cmd_open_attachment (GtkAction *action,
323 static void ev_attachment_popup_cmd_save_attachment_as (GtkAction *action,
325 static void ev_window_cmd_view_best_fit (GtkAction *action,
326 EvWindow *ev_window);
327 static void ev_window_cmd_view_page_width (GtkAction *action,
328 EvWindow *ev_window);
329 static void view_handle_link_cb (EvView *view,
332 static void ev_window_update_find_status_message (EvWindow *ev_window);
333 static void ev_window_cmd_edit_find (GtkAction *action,
334 EvWindow *ev_window);
335 static void find_bar_search_changed_cb (EggFindBar *find_bar,
337 EvWindow *ev_window);
338 static void ev_window_load_file_remote (EvWindow *ev_window,
340 static void ev_window_media_player_key_pressed (EvWindow *window,
343 static void ev_window_update_max_min_scale (EvWindow *window);
345 static void ev_window_emit_closed (EvWindow *window);
346 static void ev_window_emit_doc_loaded (EvWindow *window);
349 static guint ev_window_n_copies = 0;
351 G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW)
354 get_screen_dpi (EvWindow *window)
358 screen = gtk_window_get_screen (GTK_WINDOW (window));
359 return ev_document_misc_get_screen_dpi (screen);
363 ev_window_set_action_sensitive (EvWindow *ev_window,
367 GtkAction *action = gtk_action_group_get_action (ev_window->priv->action_group,
369 gtk_action_set_sensitive (action, sensitive);
374 ev_window_setup_action_sensitivity (EvWindow *ev_window)
376 EvDocument *document = ev_window->priv->document;
377 const EvDocumentInfo *info = NULL;
378 gboolean has_document = FALSE;
379 gboolean ok_to_print = TRUE;
380 gboolean ok_to_copy = TRUE;
381 gboolean has_properties = TRUE;
382 gboolean override_restrictions = TRUE;
383 gboolean can_get_text = FALSE;
384 gboolean has_pages = FALSE;
385 gboolean can_find = FALSE;
389 has_pages = ev_document_get_n_pages (document) > 0;
390 info = ev_document_get_info (document);
393 if (!info || info->fields_mask == 0) {
394 has_properties = FALSE;
397 if (has_document && EV_IS_SELECTION (document)) {
401 if (has_pages && EV_IS_DOCUMENT_FIND (document)) {
405 if (has_document && ev_window->priv->settings) {
406 override_restrictions =
407 g_settings_get_boolean (ev_window->priv->settings,
408 GS_OVERRIDE_RESTRICTIONS);
411 if (!override_restrictions && info && info->fields_mask & EV_DOCUMENT_INFO_PERMISSIONS) {
412 ok_to_print = (info->permissions & EV_DOCUMENT_PERMISSIONS_OK_TO_PRINT);
413 ok_to_copy = (info->permissions & EV_DOCUMENT_PERMISSIONS_OK_TO_COPY);
416 if (has_document && !ev_print_operation_exists_for_document(document))
419 if (has_document && ev_window->priv->lockdown_settings &&
420 g_settings_get_boolean (ev_window->priv->lockdown_settings, GS_LOCKDOWN_SAVE)) {
424 if (has_document && ev_window->priv->lockdown_settings &&
425 g_settings_get_boolean (ev_window->priv->lockdown_settings, GS_LOCKDOWN_PRINT)) {
430 ev_window_set_action_sensitive (ev_window, "FileOpenCopy", has_document);
431 ev_window_set_action_sensitive (ev_window, "FileSaveAs", has_document && ok_to_copy);
432 ev_window_set_action_sensitive (ev_window, "FilePrint", has_pages && ok_to_print);
433 ev_window_set_action_sensitive (ev_window, "FileProperties", has_document && has_properties);
436 ev_window_set_action_sensitive (ev_window, "EditSelectAll", has_pages && can_get_text);
437 ev_window_set_action_sensitive (ev_window, "EditFind", can_find);
438 ev_window_set_action_sensitive (ev_window, "Slash", can_find);
439 ev_window_set_action_sensitive (ev_window, "EditRotateLeft", has_pages);
440 ev_window_set_action_sensitive (ev_window, "EditRotateRight", has_pages);
443 ev_window_set_action_sensitive (ev_window, "ViewContinuous", has_pages);
444 ev_window_set_action_sensitive (ev_window, "ViewDual", has_pages);
445 ev_window_set_action_sensitive (ev_window, "ViewBestFit", has_pages);
446 ev_window_set_action_sensitive (ev_window, "ViewPageWidth", has_pages);
447 ev_window_set_action_sensitive (ev_window, "ViewReload", has_pages);
448 ev_window_set_action_sensitive (ev_window, "ViewAutoscroll", has_pages);
449 ev_window_set_action_sensitive (ev_window, "ViewInvertedColors", has_pages);
451 /* Toolbar-specific actions: */
452 ev_window_set_action_sensitive (ev_window, PAGE_SELECTOR_ACTION, has_pages);
453 ev_window_set_action_sensitive (ev_window, ZOOM_CONTROL_ACTION, has_pages);
454 ev_window_set_action_sensitive (ev_window, NAVIGATION_ACTION, FALSE);
456 ev_window_update_actions (ev_window);
460 ev_window_update_actions (EvWindow *ev_window)
462 EvView *view = EV_VIEW (ev_window->priv->view);
463 int n_pages = 0, page = -1;
464 gboolean has_pages = FALSE;
465 gboolean presentation_mode;
466 gboolean can_find_in_page = FALSE;
467 EvSizingMode sizing_mode;
469 if (ev_window->priv->document) {
470 page = ev_document_model_get_page (ev_window->priv->model);
471 n_pages = ev_document_get_n_pages (ev_window->priv->document);
472 has_pages = n_pages > 0;
475 can_find_in_page = (ev_window->priv->find_job &&
476 ev_job_find_has_results (EV_JOB_FIND (ev_window->priv->find_job)));
478 ev_window_set_action_sensitive (ev_window, "EditCopy",
480 ev_view_get_has_selection (view));
481 ev_window_set_action_sensitive (ev_window, "EditFindNext",
482 has_pages && can_find_in_page);
483 ev_window_set_action_sensitive (ev_window, "EditFindPrevious",
484 has_pages && can_find_in_page);
485 ev_window_set_action_sensitive (ev_window, "F3",
486 has_pages && can_find_in_page);
488 presentation_mode = EV_WINDOW_IS_PRESENTATION (ev_window);
490 ev_window_set_action_sensitive (ev_window, "ViewZoomIn",
492 ev_view_can_zoom_in (view) &&
494 ev_window_set_action_sensitive (ev_window, "ViewZoomOut",
496 ev_view_can_zoom_out (view) &&
501 ev_window_set_action_sensitive (ev_window, "GoPreviousPage", page > 0);
502 ev_window_set_action_sensitive (ev_window, "GoNextPage", page < n_pages - 1);
503 ev_window_set_action_sensitive (ev_window, "GoFirstPage", page > 0);
504 ev_window_set_action_sensitive (ev_window, "GoLastPage", page < n_pages - 1);
506 ev_window_set_action_sensitive (ev_window, "GoFirstPage", FALSE);
507 ev_window_set_action_sensitive (ev_window, "GoPreviousPage", FALSE);
508 ev_window_set_action_sensitive (ev_window, "GoNextPage", FALSE);
509 ev_window_set_action_sensitive (ev_window, "GoLastPage", FALSE);
512 sizing_mode = ev_document_model_get_sizing_mode (ev_window->priv->model);
513 if (has_pages && sizing_mode != EV_SIZING_FIT_WIDTH && sizing_mode != EV_SIZING_BEST_FIT) {
518 action = gtk_action_group_get_action (ev_window->priv->action_group,
519 ZOOM_CONTROL_ACTION);
521 real_zoom = ev_document_model_get_scale (ev_window->priv->model);
522 real_zoom *= 72.0 / get_screen_dpi (ev_window);
523 zoom = ephy_zoom_get_nearest_zoom_level (real_zoom);
525 ephy_zoom_action_set_zoom_level (EPHY_ZOOM_ACTION (action), zoom);
530 ev_window_set_view_accels_sensitivity (EvWindow *window, gboolean sensitive)
534 can_find = window->priv->document &&
535 EV_IS_DOCUMENT_FIND (window->priv->document);
537 if (window->priv->action_group) {
538 ev_window_set_action_sensitive (window, "PageDown", sensitive);
539 ev_window_set_action_sensitive (window, "PageUp", sensitive);
540 ev_window_set_action_sensitive (window, "Space", sensitive);
541 ev_window_set_action_sensitive (window, "ShiftSpace", sensitive);
542 ev_window_set_action_sensitive (window, "BackSpace", sensitive);
543 ev_window_set_action_sensitive (window, "ShiftBackSpace", sensitive);
544 ev_window_set_action_sensitive (window, "Return", sensitive);
545 ev_window_set_action_sensitive (window, "ShiftReturn", sensitive);
546 ev_window_set_action_sensitive (window, "Plus", sensitive);
547 ev_window_set_action_sensitive (window, "Minus", sensitive);
548 ev_window_set_action_sensitive (window, "KpPlus", sensitive);
549 ev_window_set_action_sensitive (window, "KpMinus", sensitive);
550 ev_window_set_action_sensitive (window, "Equal", sensitive);
551 ev_window_set_action_sensitive (window, "p", sensitive);
552 ev_window_set_action_sensitive (window, "n", sensitive);
554 ev_window_set_action_sensitive (window, "Slash", sensitive && can_find);
559 set_widget_visibility (GtkWidget *widget, gboolean visible)
561 g_assert (GTK_IS_WIDGET (widget));
564 gtk_widget_show (widget);
566 gtk_widget_hide (widget);
570 update_chrome_visibility (EvWindow *window)
572 EvWindowPrivate *priv = window->priv;
573 gboolean menubar, toolbar, findbar, fullscreen_toolbar, sidebar;
574 gboolean fullscreen_mode, presentation, fullscreen;
576 presentation = EV_WINDOW_IS_PRESENTATION (window);
577 fullscreen = ev_document_model_get_fullscreen (priv->model);
578 fullscreen_mode = fullscreen || presentation;
580 menubar = (priv->chrome & EV_CHROME_MENUBAR) != 0 && !fullscreen_mode;
581 toolbar = ((priv->chrome & EV_CHROME_TOOLBAR) != 0 ||
582 (priv->chrome & EV_CHROME_RAISE_TOOLBAR) != 0) && !fullscreen_mode;
583 fullscreen_toolbar = ((priv->chrome & EV_CHROME_FULLSCREEN_TOOLBAR) != 0 ||
584 (priv->chrome & EV_CHROME_RAISE_TOOLBAR) != 0) && fullscreen;
585 findbar = (priv->chrome & EV_CHROME_FINDBAR) != 0;
586 sidebar = (priv->chrome & EV_CHROME_SIDEBAR) != 0 && priv->document && !presentation;
588 set_widget_visibility (priv->menubar, menubar);
589 set_widget_visibility (priv->toolbar, toolbar);
590 set_widget_visibility (priv->find_bar, findbar);
591 set_widget_visibility (priv->sidebar, sidebar);
593 ev_window_set_action_sensitive (window, "EditToolbar", toolbar);
595 if (priv->fullscreen_toolbar != NULL) {
596 set_widget_visibility (priv->fullscreen_toolbar, fullscreen_toolbar);
601 update_chrome_flag (EvWindow *window, EvChrome flag, gboolean active)
603 EvWindowPrivate *priv = window->priv;
606 priv->chrome |= flag;
608 priv->chrome &= ~flag;
613 update_sizing_buttons (EvWindow *window)
615 GtkActionGroup *action_group = window->priv->action_group;
617 gboolean best_fit, page_width;
619 switch (ev_document_model_get_sizing_mode (window->priv->model)) {
620 case EV_SIZING_BEST_FIT:
624 case EV_SIZING_FIT_WIDTH:
629 best_fit = page_width = FALSE;
633 action = gtk_action_group_get_action (action_group, "ViewBestFit");
634 g_signal_handlers_block_by_func
635 (action, G_CALLBACK (ev_window_cmd_view_best_fit), window);
636 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), best_fit);
637 g_signal_handlers_unblock_by_func
638 (action, G_CALLBACK (ev_window_cmd_view_best_fit), window);
640 action = gtk_action_group_get_action (action_group, "ViewPageWidth");
641 g_signal_handlers_block_by_func
642 (action, G_CALLBACK (ev_window_cmd_view_page_width), window);
643 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), page_width);
644 g_signal_handlers_unblock_by_func
645 (action, G_CALLBACK (ev_window_cmd_view_page_width), window);
647 action = gtk_action_group_get_action (window->priv->action_group,
648 ZOOM_CONTROL_ACTION);
650 ephy_zoom_action_set_zoom_level (EPHY_ZOOM_ACTION (action),
652 } else if (page_width) {
653 ephy_zoom_action_set_zoom_level (EPHY_ZOOM_ACTION (action),
654 EPHY_ZOOM_FIT_WIDTH);
659 update_chrome_actions (EvWindow *window)
661 EvWindowPrivate *priv = window->priv;
662 GtkActionGroup *action_group = priv->action_group;
665 action= gtk_action_group_get_action (action_group, "ViewToolbar");
666 g_signal_handlers_block_by_func
667 (action, G_CALLBACK (ev_window_view_toolbar_cb), window);
668 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
669 (priv->chrome & EV_CHROME_TOOLBAR) != 0);
670 g_signal_handlers_unblock_by_func
671 (action, G_CALLBACK (ev_window_view_toolbar_cb), window);
675 * ev_window_is_empty:
676 * @ev_window: The instance of the #EvWindow.
678 * It does look if there is any document loaded or if there is any job to load
681 * Returns: %TRUE if there isn't any document loaded or any any documente to be
682 * loaded, %FALSE in other case.
685 ev_window_is_empty (const EvWindow *ev_window)
687 g_return_val_if_fail (EV_IS_WINDOW (ev_window), FALSE);
689 return (ev_window->priv->document == NULL) &&
690 (ev_window->priv->load_job == NULL);
694 ev_window_set_message_area (EvWindow *window,
697 if (window->priv->message_area == area)
700 if (window->priv->message_area)
701 gtk_widget_destroy (window->priv->message_area);
702 window->priv->message_area = area;
707 gtk_box_pack_start (GTK_BOX (window->priv->view_box),
708 window->priv->message_area,
710 gtk_box_reorder_child (GTK_BOX (window->priv->view_box),
711 window->priv->message_area, 0);
712 g_object_add_weak_pointer (G_OBJECT (window->priv->message_area),
713 (gpointer) &(window->priv->message_area));
717 ev_window_message_area_response_cb (EvMessageArea *area,
721 ev_window_set_message_area (window, NULL);
725 ev_window_error_message (EvWindow *window,
734 if (window->priv->message_area)
737 va_start (args, format);
738 msg = g_strdup_vprintf (format, args);
741 area = ev_message_area_new (GTK_MESSAGE_ERROR,
749 ev_message_area_set_secondary_text (EV_MESSAGE_AREA (area), error->message);
750 g_signal_connect (area, "response",
751 G_CALLBACK (ev_window_message_area_response_cb),
753 gtk_widget_show (area);
754 ev_window_set_message_area (window, area);
758 ev_window_warning_message (EvWindow *window,
766 if (window->priv->message_area)
769 va_start (args, format);
770 msg = g_strdup_vprintf (format, args);
773 area = ev_message_area_new (GTK_MESSAGE_WARNING,
780 g_signal_connect (area, "response",
781 G_CALLBACK (ev_window_message_area_response_cb),
783 gtk_widget_show (area);
784 ev_window_set_message_area (window, area);
787 typedef struct _FindTask {
788 const gchar *page_label;
793 ev_window_find_chapter (GtkTreeModel *tree_model,
798 FindTask *task = (FindTask *)data;
801 gtk_tree_model_get (tree_model, iter,
802 EV_DOCUMENT_LINKS_COLUMN_PAGE_LABEL, &page_string,
808 if (!strcmp (page_string, task->page_label)) {
809 gtk_tree_model_get (tree_model, iter,
810 EV_DOCUMENT_LINKS_COLUMN_MARKUP, &task->chapter,
812 g_free (page_string);
816 g_free (page_string);
821 ev_window_add_history (EvWindow *window, gint page, EvLink *link)
823 gchar *page_label = NULL;
827 EvLinkAction *action;
830 if (window->priv->history == NULL)
833 if (!EV_IS_DOCUMENT_LINKS (window->priv->document))
837 action = g_object_ref (ev_link_get_action (link));
838 dest = ev_link_action_get_dest (action);
839 page_label = ev_document_links_get_dest_page_label (EV_DOCUMENT_LINKS (window->priv->document), dest);
841 dest = ev_link_dest_new_page (page);
842 action = ev_link_action_new_dest (dest);
843 page_label = ev_document_get_page_label (window->priv->document, page);
849 find_task.page_label = page_label;
850 find_task.chapter = NULL;
852 if (ev_document_links_has_document_links (EV_DOCUMENT_LINKS (window->priv->document))) {
855 g_object_get (G_OBJECT (window->priv->sidebar_links), "model", &model, NULL);
858 gtk_tree_model_foreach (model,
859 ev_window_find_chapter,
862 g_object_unref (model);
866 if (find_task.chapter)
867 link_title = g_strdup_printf (_("Page %s — %s"), page_label, find_task.chapter);
869 link_title = g_strdup_printf (_("Page %s"), page_label);
871 real_link = ev_link_new (link_title, action);
873 ev_history_add_link (window->priv->history, real_link);
875 g_free (find_task.chapter);
878 g_object_unref (real_link);
882 view_handle_link_cb (EvView *view, EvLink *link, EvWindow *window)
884 int current_page = ev_document_model_get_page (window->priv->model);
886 ev_window_add_history (window, 0, link);
887 ev_window_add_history (window, current_page, NULL);
891 view_selection_changed_cb (EvView *view,
894 ev_window_set_action_sensitive (window, "EditCopy",
895 ev_view_get_has_selection (view));
899 view_layers_changed_cb (EvView *view,
902 ev_sidebar_layers_update_layers_state (EV_SIDEBAR_LAYERS (window->priv->sidebar_layers));
906 ev_window_page_changed_cb (EvWindow *ev_window,
909 EvDocumentModel *model)
911 ev_window_update_actions (ev_window);
913 ev_window_update_find_status_message (ev_window);
915 if (abs (new_page - old_page) > 1) {
916 ev_window_add_history (ev_window, new_page, NULL);
917 ev_window_add_history (ev_window, old_page, NULL);
920 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window))
921 ev_metadata_set_int (ev_window->priv->metadata, "page", new_page);
925 ev_window_sidebar_get_current_page_id (EvWindow *ev_window)
927 GtkWidget *current_page;
930 g_object_get (ev_window->priv->sidebar,
931 "current_page", ¤t_page,
934 if (current_page == ev_window->priv->sidebar_links) {
935 id = LINKS_SIDEBAR_ID;
936 } else if (current_page == ev_window->priv->sidebar_thumbs) {
937 id = THUMBNAILS_SIDEBAR_ID;
938 } else if (current_page == ev_window->priv->sidebar_attachments) {
939 id = ATTACHMENTS_SIDEBAR_ID;
940 } else if (current_page == ev_window->priv->sidebar_layers) {
941 id = LAYERS_SIDEBAR_ID;
942 } else if (current_page == ev_window->priv->sidebar_annots) {
943 id = ANNOTS_SIDEBAR_ID;
945 g_assert_not_reached();
948 g_object_unref (current_page);
954 ev_window_sidebar_set_current_page (EvWindow *window,
955 const gchar *page_id)
957 EvDocument *document = window->priv->document;
958 EvSidebar *sidebar = EV_SIDEBAR (window->priv->sidebar);
959 GtkWidget *links = window->priv->sidebar_links;
960 GtkWidget *thumbs = window->priv->sidebar_thumbs;
961 GtkWidget *attachments = window->priv->sidebar_attachments;
962 GtkWidget *annots = window->priv->sidebar_annots;
963 GtkWidget *layers = window->priv->sidebar_layers;
965 if (strcmp (page_id, LINKS_SIDEBAR_ID) == 0 &&
966 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (links), document)) {
967 ev_sidebar_set_page (sidebar, links);
968 } else if (strcmp (page_id, THUMBNAILS_SIDEBAR_ID) == 0 &&
969 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (thumbs), document)) {
970 ev_sidebar_set_page (sidebar, thumbs);
971 } else if (strcmp (page_id, ATTACHMENTS_SIDEBAR_ID) == 0 &&
972 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (attachments), document)) {
973 ev_sidebar_set_page (sidebar, attachments);
974 } else if (strcmp (page_id, LAYERS_SIDEBAR_ID) == 0 &&
975 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (layers), document)) {
976 ev_sidebar_set_page (sidebar, layers);
977 } else if (strcmp (page_id, ANNOTS_SIDEBAR_ID) == 0 &&
978 ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (annots), document)) {
979 ev_sidebar_set_page (sidebar, annots);
984 update_document_mode (EvWindow *window, EvDocumentMode mode)
986 if (mode == EV_DOCUMENT_MODE_PRESENTATION) {
987 ev_window_run_presentation (window);
989 else if (mode == EV_DOCUMENT_MODE_FULL_SCREEN) {
990 ev_window_run_fullscreen (window);
995 setup_chrome_from_metadata (EvWindow *window)
997 EvChrome chrome = EV_CHROME_NORMAL;
998 gboolean show_toolbar = TRUE;
1000 if (ev_window_is_empty (window)) {
1001 window->priv->chrome = chrome;
1006 if (!window->priv->metadata) {
1007 show_toolbar = g_settings_get_boolean (window->priv->default_settings, "show-toolbar");
1008 } else if (!ev_metadata_get_boolean (window->priv->metadata, "show_toolbar", &show_toolbar)) {
1009 if (window->priv->is_new_doc)
1010 show_toolbar = g_settings_get_boolean (window->priv->default_settings, "show-toolbar");
1014 chrome &= ~EV_CHROME_TOOLBAR;
1016 window->priv->chrome = chrome;
1020 setup_sidebar_from_metadata (EvWindow *window)
1022 EvDocument *document = window->priv->document;
1023 GSettings *settings = window->priv->default_settings;
1026 gboolean sidebar_visibility = TRUE;
1028 if (ev_window_is_empty (window))
1031 if (!window->priv->metadata) {
1032 sidebar_visibility = g_settings_get_boolean (settings, "show-sidebar");
1033 } else if (!ev_metadata_get_boolean (window->priv->metadata, "sidebar_visibility", &sidebar_visibility)) {
1034 if (window->priv->is_new_doc)
1035 sidebar_visibility = g_settings_get_boolean (settings, "show-sidebar");
1038 update_chrome_flag (window, EV_CHROME_SIDEBAR, sidebar_visibility);
1039 update_chrome_visibility (window);
1041 if (!window->priv->metadata) {
1042 /* Set default values */
1043 gtk_paned_set_position (GTK_PANED (window->priv->hpaned),
1044 g_settings_get_int (settings, "sidebar-size"));
1046 page_id = g_settings_get_string (settings, "sidebar-page");
1047 ev_window_sidebar_set_current_page (window, page_id);
1054 if (ev_metadata_get_int (window->priv->metadata, "sidebar_size", &sidebar_size)) {
1055 gtk_paned_set_position (GTK_PANED (window->priv->hpaned), sidebar_size);
1056 } else if (window->priv->is_new_doc) {
1057 gtk_paned_set_position (GTK_PANED (window->priv->hpaned),
1058 g_settings_get_int (settings, "sidebar-size"));
1064 if (ev_metadata_get_string (window->priv->metadata, "sidebar_page", &page_id)) {
1065 ev_window_sidebar_set_current_page (window, page_id);
1066 } else if (window->priv->is_new_doc) {
1067 page_id = g_settings_get_string (settings, "sidebar-page");
1068 ev_window_sidebar_set_current_page (window, page_id);
1074 setup_model_from_metadata (EvWindow *window)
1076 GSettings *settings = window->priv->default_settings;
1081 gboolean inverted_colors = FALSE;
1082 gboolean continuous = FALSE;
1083 gboolean dual_page = FALSE;
1084 gboolean fullscreen = FALSE;
1086 if (!window->priv->metadata) {
1087 /* Set default values */
1088 ev_document_model_set_sizing_mode (window->priv->model,
1089 g_settings_get_enum (settings, "sizing-mode"));
1090 ev_document_model_set_inverted_colors (window->priv->model,
1091 g_settings_get_boolean (settings, "inverted-colors"));
1092 ev_document_model_set_continuous (window->priv->model,
1093 g_settings_get_boolean (settings, "continuous"));
1094 ev_document_model_set_dual_page (window->priv->model,
1095 g_settings_get_boolean (settings, "dual-page"));
1096 fullscreen = g_settings_get_boolean (settings, "fullscreen");
1098 ev_window_run_fullscreen (window);
1104 if (!window->priv->dest &&
1105 ev_metadata_get_int (window->priv->metadata, "page", &page)) {
1106 ev_document_model_set_page (window->priv->model, page);
1110 if (ev_metadata_get_string (window->priv->metadata, "sizing_mode", &sizing_mode)) {
1111 GEnumValue *enum_value;
1113 enum_value = g_enum_get_value_by_nick
1114 (g_type_class_peek (EV_TYPE_SIZING_MODE), sizing_mode);
1115 ev_document_model_set_sizing_mode (window->priv->model, enum_value->value);
1116 } else if (window->priv->is_new_doc) {
1117 ev_document_model_set_sizing_mode (window->priv->model,
1118 g_settings_get_enum (settings, "sizing-mode"));
1122 if (ev_document_model_get_sizing_mode (window->priv->model) == EV_SIZING_FREE &&
1123 ev_metadata_get_double (window->priv->metadata, "zoom", &zoom)) {
1124 zoom *= get_screen_dpi (window) / 72.0;
1125 ev_document_model_set_scale (window->priv->model, zoom);
1129 if (ev_metadata_get_int (window->priv->metadata, "rotation", &rotation)) {
1144 ev_document_model_set_rotation (window->priv->model, rotation);
1147 /* Inverted Colors */
1148 if (ev_metadata_get_boolean (window->priv->metadata, "inverted-colors", &inverted_colors)) {
1149 ev_document_model_set_inverted_colors (window->priv->model, inverted_colors);
1150 } else if (window->priv->is_new_doc) {
1151 ev_document_model_set_inverted_colors (window->priv->model,
1152 g_settings_get_boolean (settings, "inverted-colors"));
1156 if (ev_metadata_get_boolean (window->priv->metadata, "continuous", &continuous)) {
1157 ev_document_model_set_continuous (window->priv->model, continuous);
1158 } else if (window->priv->is_new_doc) {
1159 ev_document_model_set_continuous (window->priv->model,
1160 g_settings_get_boolean (settings, "continuous"));
1164 if (ev_metadata_get_boolean (window->priv->metadata, "dual-page", &dual_page)) {
1165 ev_document_model_set_dual_page (window->priv->model, dual_page);
1166 } else if (window->priv->is_new_doc) {
1167 ev_document_model_set_dual_page (window->priv->model,
1168 g_settings_get_boolean (settings, "dual-page"));
1172 if (!ev_metadata_get_boolean (window->priv->metadata, "fullscreen", &fullscreen)) {
1173 if (window->priv->is_new_doc)
1174 fullscreen = g_settings_get_boolean (settings, "fullscreen");
1178 ev_window_run_fullscreen (window);
1182 setup_document_from_metadata (EvWindow *window)
1187 gdouble width_ratio;
1188 gdouble height_ratio;
1190 setup_sidebar_from_metadata (window);
1192 if (window->priv->metadata) {
1193 /* Make sure to not open a document on the last page,
1194 * since closing it on the last page most likely means the
1195 * user was finished reading the document. In that case, reopening should
1196 * show the first page. */
1197 page = ev_document_model_get_page (window->priv->model);
1198 n_pages = ev_document_get_n_pages (window->priv->document);
1199 if (page == n_pages - 1)
1200 ev_document_model_set_page (window->priv->model, 0);
1202 if (ev_metadata_get_int (window->priv->metadata, "window_width", &width) &&
1203 ev_metadata_get_int (window->priv->metadata, "window_height", &height))
1204 return; /* size was already set in setup_size_from_metadata */
1207 g_settings_get (window->priv->default_settings, "window-ratio", "(dd)", &width_ratio, &height_ratio);
1208 if (width_ratio > 0. && height_ratio > 0.) {
1209 gdouble document_width;
1210 gdouble document_height;
1213 gint request_height;
1215 ev_document_get_max_page_size (window->priv->document,
1216 &document_width, &document_height);
1218 request_width = (gint)(width_ratio * document_width + 0.5);
1219 request_height = (gint)(height_ratio * document_height + 0.5);
1221 screen = gtk_window_get_screen (GTK_WINDOW (window));
1223 request_width = MIN (request_width, gdk_screen_get_width (screen));
1224 request_height = MIN (request_height, gdk_screen_get_height (screen));
1227 if (request_width > 0 && request_height > 0) {
1228 gtk_window_resize (GTK_WINDOW (window),
1236 setup_size_from_metadata (EvWindow *window)
1244 if (!window->priv->metadata)
1247 if (ev_metadata_get_boolean (window->priv->metadata, "window_maximized", &maximized)) {
1249 gtk_window_maximize (GTK_WINDOW (window));
1252 gtk_window_unmaximize (GTK_WINDOW (window));
1256 if (ev_metadata_get_int (window->priv->metadata, "window_x", &x) &&
1257 ev_metadata_get_int (window->priv->metadata, "window_y", &y)) {
1258 gtk_window_move (GTK_WINDOW (window), x, y);
1261 if (ev_metadata_get_int (window->priv->metadata, "window_width", &width) &&
1262 ev_metadata_get_int (window->priv->metadata, "window_height", &height)) {
1263 gtk_window_resize (GTK_WINDOW (window), width, height);
1268 setup_view_from_metadata (EvWindow *window)
1270 gboolean presentation;
1272 if (!window->priv->metadata)
1276 if (ev_metadata_get_boolean (window->priv->metadata, "presentation", &presentation)) {
1278 ev_window_run_presentation (window);
1284 ev_window_clear_thumbnail_job (EvWindow *ev_window)
1286 if (ev_window->priv->thumbnail_job != NULL) {
1287 if (!ev_job_is_finished (ev_window->priv->thumbnail_job))
1288 ev_job_cancel (ev_window->priv->thumbnail_job);
1290 g_signal_handlers_disconnect_by_func (ev_window->priv->thumbnail_job,
1291 ev_window_set_icon_from_thumbnail,
1293 g_object_unref (ev_window->priv->thumbnail_job);
1294 ev_window->priv->thumbnail_job = NULL;
1299 ev_window_set_icon_from_thumbnail (EvJobThumbnail *job,
1300 EvWindow *ev_window)
1302 if (job->thumbnail) {
1303 if (ev_document_model_get_inverted_colors (ev_window->priv->model))
1304 ev_document_misc_invert_pixbuf (job->thumbnail);
1305 gtk_window_set_icon (GTK_WINDOW (ev_window),
1309 ev_window_clear_thumbnail_job (ev_window);
1313 ev_window_refresh_window_thumbnail (EvWindow *ev_window)
1318 EvDocument *document = ev_window->priv->document;
1320 if (ev_document_get_n_pages (document) <= 0 ||
1321 !ev_document_check_dimensions (document)) {
1325 ev_window_clear_thumbnail_job (ev_window);
1327 ev_document_get_page_size (document, 0, &page_width, NULL);
1328 scale = 128. / page_width;
1329 rotation = ev_document_model_get_rotation (ev_window->priv->model);
1331 ev_window->priv->thumbnail_job = ev_job_thumbnail_new (document, 0, rotation, scale);
1332 g_signal_connect (ev_window->priv->thumbnail_job, "finished",
1333 G_CALLBACK (ev_window_set_icon_from_thumbnail),
1335 ev_job_scheduler_push_job (ev_window->priv->thumbnail_job, EV_JOB_PRIORITY_NONE);
1339 override_restrictions_changed (GSettings *settings,
1341 EvWindow *ev_window)
1343 ev_window_setup_action_sensitivity (ev_window);
1347 lockdown_changed (GSettings *lockdown,
1349 EvWindow *ev_window)
1351 ev_window_setup_action_sensitivity (ev_window);
1355 ev_window_setup_document (EvWindow *ev_window)
1357 const EvDocumentInfo *info;
1358 EvDocument *document = ev_window->priv->document;
1361 ev_window->priv->setup_document_idle = 0;
1363 ev_window_refresh_window_thumbnail (ev_window);
1365 ev_window_set_page_mode (ev_window, PAGE_MODE_DOCUMENT);
1366 ev_window_title_set_document (ev_window->priv->title, document);
1367 ev_window_title_set_uri (ev_window->priv->title, ev_window->priv->uri);
1369 if (!ev_window->priv->settings) {
1370 ev_window->priv->settings = g_settings_new (GS_SCHEMA_NAME);
1371 g_signal_connect (ev_window->priv->settings,
1372 "changed::"GS_OVERRIDE_RESTRICTIONS,
1373 G_CALLBACK (override_restrictions_changed),
1377 #ifdef HAVE_DESKTOP_SCHEMAS
1378 if (!ev_window->priv->lockdown_settings) {
1379 ev_window->priv->lockdown_settings = g_settings_new (GS_LOCKDOWN_SCHEMA_NAME);
1380 g_signal_connect (ev_window->priv->lockdown_settings,
1382 G_CALLBACK (lockdown_changed),
1387 ev_window_setup_action_sensitivity (ev_window);
1389 if (ev_window->priv->history)
1390 g_object_unref (ev_window->priv->history);
1391 ev_window->priv->history = ev_history_new ();
1392 action = gtk_action_group_get_action (ev_window->priv->action_group, NAVIGATION_ACTION);
1393 ev_navigation_action_set_history (EV_NAVIGATION_ACTION (action), ev_window->priv->history);
1395 if (ev_window->priv->properties) {
1396 ev_properties_dialog_set_document (EV_PROPERTIES_DIALOG (ev_window->priv->properties),
1397 ev_window->priv->uri,
1398 ev_window->priv->document);
1401 info = ev_document_get_info (document);
1402 update_document_mode (ev_window, info->mode);
1404 if (EV_WINDOW_IS_PRESENTATION (ev_window))
1405 gtk_widget_grab_focus (ev_window->priv->presentation_view);
1407 gtk_widget_grab_focus (ev_window->priv->view);
1413 ev_window_set_document (EvWindow *ev_window, EvDocument *document)
1415 if (ev_window->priv->document == document)
1418 if (ev_window->priv->document)
1419 g_object_unref (ev_window->priv->document);
1420 ev_window->priv->document = g_object_ref (document);
1422 ev_window_update_max_min_scale (ev_window);
1424 ev_window_set_message_area (ev_window, NULL);
1426 if (ev_document_get_n_pages (document) <= 0) {
1427 ev_window_warning_message (ev_window, "%s",
1428 _("The document contains no pages"));
1429 } else if (!ev_document_check_dimensions (document)) {
1430 ev_window_warning_message (ev_window, "%s",
1431 _("The document contains only empty pages"));
1434 if (EV_WINDOW_IS_PRESENTATION (ev_window)) {
1435 gtk_widget_destroy (ev_window->priv->presentation_view);
1436 ev_window->priv->presentation_view = NULL;
1437 ev_window_run_presentation (ev_window);
1440 if (ev_window->priv->setup_document_idle > 0)
1441 g_source_remove (ev_window->priv->setup_document_idle);
1443 ev_window->priv->setup_document_idle = g_idle_add ((GSourceFunc)ev_window_setup_document, ev_window);
1447 ev_window_document_changed (EvWindow *ev_window,
1450 ev_window_reload_document (ev_window, NULL);
1454 ev_window_password_view_unlock (EvWindow *ev_window)
1456 const gchar *password;
1458 g_assert (ev_window->priv->load_job);
1460 password = ev_password_view_get_password (EV_PASSWORD_VIEW (ev_window->priv->password_view));
1461 ev_job_load_set_password (EV_JOB_LOAD (ev_window->priv->load_job), password);
1462 ev_job_scheduler_push_job (ev_window->priv->load_job, EV_JOB_PRIORITY_NONE);
1466 ev_window_clear_load_job (EvWindow *ev_window)
1468 if (ev_window->priv->load_job != NULL) {
1469 if (!ev_job_is_finished (ev_window->priv->load_job))
1470 ev_job_cancel (ev_window->priv->load_job);
1472 g_signal_handlers_disconnect_by_func (ev_window->priv->load_job, ev_window_load_job_cb, ev_window);
1473 g_object_unref (ev_window->priv->load_job);
1474 ev_window->priv->load_job = NULL;
1479 ev_window_clear_reload_job (EvWindow *ev_window)
1481 if (ev_window->priv->reload_job != NULL) {
1482 if (!ev_job_is_finished (ev_window->priv->reload_job))
1483 ev_job_cancel (ev_window->priv->reload_job);
1485 g_signal_handlers_disconnect_by_func (ev_window->priv->reload_job, ev_window_reload_job_cb, ev_window);
1486 g_object_unref (ev_window->priv->reload_job);
1487 ev_window->priv->reload_job = NULL;
1492 ev_window_clear_local_uri (EvWindow *ev_window)
1494 if (ev_window->priv->local_uri) {
1495 ev_tmp_uri_unlink (ev_window->priv->local_uri);
1496 g_free (ev_window->priv->local_uri);
1497 ev_window->priv->local_uri = NULL;
1502 ev_window_handle_link (EvWindow *ev_window,
1507 EvLinkAction *link_action;
1509 link_action = ev_link_action_new_dest (dest);
1510 link = ev_link_new (NULL, link_action);
1511 ev_view_handle_link (EV_VIEW (ev_window->priv->view), link);
1512 g_object_unref (link);
1516 /* This callback will executed when load job will be finished.
1518 * Since the flow of the error dialog is very confusing, we assume that both
1519 * document and uri will go away after this function is called, and thus we need
1520 * to ref/dup them. Additionally, it needs to clear
1521 * ev_window->priv->password_{uri,document}, and thus people who call this
1522 * function should _not_ necessarily expect those to exist after being
1525 ev_window_load_job_cb (EvJob *job,
1528 EvWindow *ev_window = EV_WINDOW (data);
1529 EvDocument *document = EV_JOB (job)->document;
1530 EvJobLoad *job_load = EV_JOB_LOAD (job);
1532 g_assert (job_load->uri);
1534 ev_view_set_loading (EV_VIEW (ev_window->priv->view), FALSE);
1537 if (!ev_job_is_failed (job)) {
1538 ev_document_model_set_document (ev_window->priv->model, document);
1541 ev_window_emit_doc_loaded (ev_window);
1543 setup_chrome_from_metadata (ev_window);
1544 update_chrome_actions (ev_window);
1545 setup_document_from_metadata (ev_window);
1546 setup_view_from_metadata (ev_window);
1548 ev_window_add_recent (ev_window, ev_window->priv->uri);
1550 ev_window_title_set_type (ev_window->priv->title,
1551 EV_WINDOW_TITLE_DOCUMENT);
1552 if (job_load->password) {
1553 GPasswordSave flags;
1555 flags = ev_password_view_get_password_save_flags (
1556 EV_PASSWORD_VIEW (ev_window->priv->password_view));
1557 ev_keyring_save_password (ev_window->priv->uri,
1562 ev_window_handle_link (ev_window, ev_window->priv->dest);
1563 /* Already unrefed by ev_link_action
1564 * FIXME: link action should inc dest ref counting
1565 * or not unref it at all
1567 ev_window->priv->dest = NULL;
1569 switch (ev_window->priv->window_mode) {
1570 case EV_WINDOW_MODE_FULLSCREEN:
1571 ev_window_run_fullscreen (ev_window);
1573 case EV_WINDOW_MODE_PRESENTATION:
1574 ev_window_run_presentation (ev_window);
1580 if (ev_window->priv->search_string && EV_IS_DOCUMENT_FIND (document)) {
1581 ev_window_cmd_edit_find (NULL, ev_window);
1582 egg_find_bar_set_search_string (EGG_FIND_BAR (ev_window->priv->find_bar),
1583 ev_window->priv->search_string);
1586 g_free (ev_window->priv->search_string);
1587 ev_window->priv->search_string = NULL;
1589 /* Create a monitor for the document */
1590 ev_window->priv->monitor = ev_file_monitor_new (ev_window->priv->uri);
1591 g_signal_connect_swapped (ev_window->priv->monitor, "changed",
1592 G_CALLBACK (ev_window_document_changed),
1595 ev_window_clear_load_job (ev_window);
1599 if (g_error_matches (job->error, EV_DOCUMENT_ERROR, EV_DOCUMENT_ERROR_ENCRYPTED)) {
1602 setup_view_from_metadata (ev_window);
1604 /* First look whether password is in keyring */
1605 password = ev_keyring_lookup_password (ev_window->priv->uri);
1607 if (job_load->password && strcmp (password, job_load->password) == 0) {
1608 /* Password in kering is wrong */
1609 ev_job_load_set_password (job_load, NULL);
1610 /* FIXME: delete password from keyring? */
1612 ev_job_load_set_password (job_load, password);
1613 ev_job_scheduler_push_job (job, EV_JOB_PRIORITY_NONE);
1621 /* We need to ask the user for a password */
1622 ev_window_title_set_uri (ev_window->priv->title,
1623 ev_window->priv->uri);
1624 ev_window_title_set_type (ev_window->priv->title,
1625 EV_WINDOW_TITLE_PASSWORD);
1627 ev_password_view_set_uri (EV_PASSWORD_VIEW (ev_window->priv->password_view),
1630 ev_window_set_page_mode (ev_window, PAGE_MODE_PASSWORD);
1632 ev_job_load_set_password (job_load, NULL);
1633 ev_password_view_ask_password (EV_PASSWORD_VIEW (ev_window->priv->password_view));
1635 ev_window_error_message (ev_window, job->error,
1636 "%s", _("Unable to open document"));
1637 ev_window_clear_load_job (ev_window);
1642 ev_window_reload_job_cb (EvJob *job,
1643 EvWindow *ev_window)
1647 if (ev_job_is_failed (job)) {
1648 ev_window_clear_reload_job (ev_window);
1649 ev_window->priv->in_reload = FALSE;
1650 if (ev_window->priv->dest) {
1651 g_object_unref (ev_window->priv->dest);
1652 ev_window->priv->dest = NULL;
1658 ev_document_model_set_document (ev_window->priv->model,
1660 if (ev_window->priv->dest) {
1661 ev_window_handle_link (ev_window, ev_window->priv->dest);
1662 /* Already unrefed by ev_link_action
1663 * FIXME: link action should inc dest ref counting
1664 * or not unref it at all
1666 ev_window->priv->dest = NULL;
1669 /* Restart the search after reloading */
1670 widget = gtk_window_get_focus (GTK_WINDOW (ev_window));
1671 if (widget && gtk_widget_get_ancestor (widget, EGG_TYPE_FIND_BAR)) {
1672 find_bar_search_changed_cb (EGG_FIND_BAR (ev_window->priv->find_bar),
1676 ev_window_clear_reload_job (ev_window);
1677 ev_window->priv->in_reload = FALSE;
1681 * ev_window_get_uri:
1682 * @ev_window: The instance of the #EvWindow.
1684 * It returns the uri of the document showed in the #EvWindow.
1686 * Returns: the uri of the document showed in the #EvWindow.
1689 ev_window_get_uri (EvWindow *ev_window)
1691 return ev_window->priv->uri;
1695 * ev_window_close_dialogs:
1696 * @ev_window: The window where dialogs will be closed.
1698 * It looks for password, print and properties dialogs and closes them and
1699 * frees them from memory. If there is any print job it does free it too.
1702 ev_window_close_dialogs (EvWindow *ev_window)
1704 if (ev_window->priv->print_dialog)
1705 gtk_widget_destroy (ev_window->priv->print_dialog);
1706 ev_window->priv->print_dialog = NULL;
1708 if (ev_window->priv->properties)
1709 gtk_widget_destroy (ev_window->priv->properties);
1710 ev_window->priv->properties = NULL;
1714 ev_window_clear_progress_idle (EvWindow *ev_window)
1716 if (ev_window->priv->progress_idle > 0)
1717 g_source_remove (ev_window->priv->progress_idle);
1718 ev_window->priv->progress_idle = 0;
1722 reset_progress_idle (EvWindow *ev_window)
1724 ev_window->priv->progress_idle = 0;
1728 ev_window_show_progress_message (EvWindow *ev_window,
1730 GSourceFunc function)
1732 if (ev_window->priv->progress_idle > 0)
1733 g_source_remove (ev_window->priv->progress_idle);
1734 ev_window->priv->progress_idle =
1735 g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
1738 (GDestroyNotify)reset_progress_idle);
1742 ev_window_reset_progress_cancellable (EvWindow *ev_window)
1744 if (ev_window->priv->progress_cancellable)
1745 g_cancellable_reset (ev_window->priv->progress_cancellable);
1747 ev_window->priv->progress_cancellable = g_cancellable_new ();
1751 ev_window_progress_response_cb (EvProgressMessageArea *area,
1753 EvWindow *ev_window)
1755 if (response == GTK_RESPONSE_CANCEL)
1756 g_cancellable_cancel (ev_window->priv->progress_cancellable);
1757 ev_window_set_message_area (ev_window, NULL);
1761 show_loading_progress (EvWindow *ev_window)
1765 gchar *display_name;
1767 if (ev_window->priv->message_area)
1770 text = g_uri_unescape_string (ev_window->priv->uri, NULL);
1771 display_name = g_markup_escape_text (text, -1);
1773 text = g_strdup_printf (_("Loading document from “%s”"),
1776 area = ev_progress_message_area_new (GTK_STOCK_OPEN,
1781 GTK_RESPONSE_CANCEL,
1783 g_signal_connect (area, "response",
1784 G_CALLBACK (ev_window_progress_response_cb),
1786 gtk_widget_show (area);
1787 ev_window_set_message_area (ev_window, area);
1790 g_free (display_name);
1796 ev_window_load_remote_failed (EvWindow *ev_window,
1799 ev_view_set_loading (EV_VIEW (ev_window->priv->view), FALSE);
1800 ev_window->priv->in_reload = FALSE;
1801 ev_window_error_message (ev_window, error,
1802 "%s", _("Unable to open document"));
1803 g_free (ev_window->priv->local_uri);
1804 ev_window->priv->local_uri = NULL;
1805 ev_window->priv->uri_mtime = 0;
1809 set_uri_mtime (GFile *source,
1810 GAsyncResult *async_result,
1811 EvWindow *ev_window)
1814 GError *error = NULL;
1816 info = g_file_query_info_finish (source, async_result, &error);
1819 ev_window->priv->uri_mtime = 0;
1820 g_error_free (error);
1824 g_file_info_get_modification_time (info, &mtime);
1825 ev_window->priv->uri_mtime = mtime.tv_sec;
1826 g_object_unref (info);
1829 g_object_unref (source);
1833 mount_volume_ready_cb (GFile *source,
1834 GAsyncResult *async_result,
1835 EvWindow *ev_window)
1837 GError *error = NULL;
1839 g_file_mount_enclosing_volume_finish (source, async_result, &error);
1842 ev_window_load_remote_failed (ev_window, error);
1843 g_object_unref (source);
1844 g_error_free (error);
1846 /* Volume successfully mounted,
1847 try opening the file again */
1848 ev_window_load_file_remote (ev_window, source);
1853 window_open_file_copy_ready_cb (GFile *source,
1854 GAsyncResult *async_result,
1855 EvWindow *ev_window)
1857 GError *error = NULL;
1859 ev_window_clear_progress_idle (ev_window);
1860 ev_window_set_message_area (ev_window, NULL);
1862 g_file_copy_finish (source, async_result, &error);
1864 ev_job_scheduler_push_job (ev_window->priv->load_job, EV_JOB_PRIORITY_NONE);
1865 g_file_query_info_async (source,
1866 G_FILE_ATTRIBUTE_TIME_MODIFIED,
1867 0, G_PRIORITY_DEFAULT,
1869 (GAsyncReadyCallback)set_uri_mtime,
1874 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_MOUNTED)) {
1875 GMountOperation *operation;
1877 operation = gtk_mount_operation_new (GTK_WINDOW (ev_window));
1878 g_file_mount_enclosing_volume (source,
1881 (GAsyncReadyCallback)mount_volume_ready_cb,
1883 g_object_unref (operation);
1884 } else if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
1885 ev_window_clear_load_job (ev_window);
1886 ev_window_clear_local_uri (ev_window);
1887 g_free (ev_window->priv->uri);
1888 ev_window->priv->uri = NULL;
1889 g_object_unref (source);
1891 ev_view_set_loading (EV_VIEW (ev_window->priv->view), FALSE);
1893 ev_window_load_remote_failed (ev_window, error);
1894 g_object_unref (source);
1897 g_error_free (error);
1901 window_open_file_copy_progress_cb (goffset n_bytes,
1902 goffset total_bytes,
1903 EvWindow *ev_window)
1908 if (!ev_window->priv->message_area)
1911 if (total_bytes <= 0)
1914 fraction = n_bytes / (gdouble)total_bytes;
1915 status = g_strdup_printf (_("Downloading document (%d%%)"),
1916 (gint)(fraction * 100));
1918 ev_progress_message_area_set_status (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
1920 ev_progress_message_area_set_fraction (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
1927 ev_window_load_file_remote (EvWindow *ev_window,
1932 if (!ev_window->priv->local_uri) {
1933 char *base_name, *template;
1937 /* We'd like to keep extension of source uri since
1938 * it helps to resolve some mime types, say cbz.
1940 base_name = g_file_get_basename (source_file);
1941 template = g_strdup_printf ("document.XXXXXX-%s", base_name);
1944 tmp_file = ev_mkstemp_file (template, &err);
1946 if (tmp_file == NULL) {
1947 ev_window_error_message (ev_window, err,
1948 "%s", _("Failed to load remote file."));
1953 ev_window->priv->local_uri = g_file_get_uri (tmp_file);
1954 g_object_unref (tmp_file);
1956 ev_job_load_set_uri (EV_JOB_LOAD (ev_window->priv->load_job),
1957 ev_window->priv->local_uri);
1960 ev_window_reset_progress_cancellable (ev_window);
1962 target_file = g_file_new_for_uri (ev_window->priv->local_uri);
1963 g_file_copy_async (source_file, target_file,
1964 G_FILE_COPY_OVERWRITE,
1966 ev_window->priv->progress_cancellable,
1967 (GFileProgressCallback)window_open_file_copy_progress_cb,
1969 (GAsyncReadyCallback)window_open_file_copy_ready_cb,
1971 g_object_unref (target_file);
1973 ev_window_show_progress_message (ev_window, 1,
1974 (GSourceFunc)show_loading_progress);
1978 ev_window_open_uri (EvWindow *ev_window,
1981 EvWindowRunMode mode,
1982 const gchar *search_string)
1986 ev_window->priv->in_reload = FALSE;
1988 if (ev_window->priv->uri &&
1989 g_ascii_strcasecmp (ev_window->priv->uri, uri) == 0) {
1990 ev_window_reload_document (ev_window, dest);
1994 if (ev_window->priv->monitor) {
1995 g_object_unref (ev_window->priv->monitor);
1996 ev_window->priv->monitor = NULL;
1999 ev_window_close_dialogs (ev_window);
2000 ev_window_clear_load_job (ev_window);
2001 ev_window_clear_local_uri (ev_window);
2003 ev_window->priv->window_mode = mode;
2005 if (ev_window->priv->uri)
2006 g_free (ev_window->priv->uri);
2007 ev_window->priv->uri = g_strdup (uri);
2009 if (ev_window->priv->metadata)
2010 g_object_unref (ev_window->priv->metadata);
2012 source_file = g_file_new_for_uri (uri);
2013 if (!ev_file_is_temp (source_file) && ev_is_metadata_supported_for_file (source_file)) {
2014 ev_window->priv->metadata = ev_metadata_new (source_file);
2015 ev_window->priv->is_new_doc = ev_metadata_is_empty (ev_window->priv->metadata);
2017 ev_window->priv->metadata = NULL;
2020 if (ev_window->priv->search_string)
2021 g_free (ev_window->priv->search_string);
2022 ev_window->priv->search_string = search_string ?
2023 g_strdup (search_string) : NULL;
2025 if (ev_window->priv->dest)
2026 g_object_unref (ev_window->priv->dest);
2027 ev_window->priv->dest = dest ? g_object_ref (dest) : NULL;
2029 setup_size_from_metadata (ev_window);
2030 setup_model_from_metadata (ev_window);
2032 ev_window->priv->load_job = ev_job_load_new (uri);
2033 g_signal_connect (ev_window->priv->load_job,
2035 G_CALLBACK (ev_window_load_job_cb),
2038 if (!g_file_is_native (source_file) && !ev_window->priv->local_uri) {
2039 ev_window_load_file_remote (ev_window, source_file);
2041 ev_view_set_loading (EV_VIEW (ev_window->priv->view), TRUE);
2042 g_object_unref (source_file);
2043 ev_job_scheduler_push_job (ev_window->priv->load_job, EV_JOB_PRIORITY_NONE);
2048 ev_window_open_document (EvWindow *ev_window,
2049 EvDocument *document,
2051 EvWindowRunMode mode,
2052 const gchar *search_string)
2054 if (document == ev_window->priv->document)
2057 ev_window_close_dialogs (ev_window);
2058 ev_window_clear_load_job (ev_window);
2059 ev_window_clear_local_uri (ev_window);
2061 if (ev_window->priv->monitor) {
2062 g_object_unref (ev_window->priv->monitor);
2063 ev_window->priv->monitor = NULL;
2066 if (ev_window->priv->uri)
2067 g_free (ev_window->priv->uri);
2068 ev_window->priv->uri = g_strdup (ev_document_get_uri (document));
2070 setup_size_from_metadata (ev_window);
2071 setup_model_from_metadata (ev_window);
2073 ev_document_model_set_document (ev_window->priv->model, document);
2075 setup_document_from_metadata (ev_window);
2076 setup_view_from_metadata (ev_window);
2080 EvLinkAction *link_action;
2082 link_action = ev_link_action_new_dest (dest);
2083 link = ev_link_new (NULL, link_action);
2084 ev_view_handle_link (EV_VIEW (ev_window->priv->view), link);
2085 /* FIXME: link action should inc dest ref counting
2086 * or not unref it at all
2088 g_object_ref (dest);
2089 g_object_unref (link);
2093 case EV_WINDOW_MODE_FULLSCREEN:
2094 ev_window_run_fullscreen (ev_window);
2096 case EV_WINDOW_MODE_PRESENTATION:
2097 ev_window_run_presentation (ev_window);
2103 if (search_string && EV_IS_DOCUMENT_FIND (document)) {
2104 ev_window_cmd_edit_find (NULL, ev_window);
2105 egg_find_bar_set_search_string (EGG_FIND_BAR (ev_window->priv->find_bar),
2109 /* Create a monitor for the document */
2110 ev_window->priv->monitor = ev_file_monitor_new (ev_window->priv->uri);
2111 g_signal_connect_swapped (ev_window->priv->monitor, "changed",
2112 G_CALLBACK (ev_window_document_changed),
2117 ev_window_reload_local (EvWindow *ev_window)
2121 uri = ev_window->priv->local_uri ? ev_window->priv->local_uri : ev_window->priv->uri;
2122 ev_window->priv->reload_job = ev_job_load_new (uri);
2123 g_signal_connect (ev_window->priv->reload_job, "finished",
2124 G_CALLBACK (ev_window_reload_job_cb),
2126 ev_job_scheduler_push_job (ev_window->priv->reload_job, EV_JOB_PRIORITY_NONE);
2130 show_reloading_progress (EvWindow *ev_window)
2135 if (ev_window->priv->message_area)
2138 text = g_strdup_printf (_("Reloading document from %s"),
2139 ev_window->priv->uri);
2140 area = ev_progress_message_area_new (GTK_STOCK_REFRESH,
2145 GTK_RESPONSE_CANCEL,
2147 g_signal_connect (area, "response",
2148 G_CALLBACK (ev_window_progress_response_cb),
2150 gtk_widget_show (area);
2151 ev_window_set_message_area (ev_window, area);
2158 reload_remote_copy_ready_cb (GFile *remote,
2159 GAsyncResult *async_result,
2160 EvWindow *ev_window)
2162 GError *error = NULL;
2164 ev_window_clear_progress_idle (ev_window);
2166 g_file_copy_finish (remote, async_result, &error);
2168 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
2169 ev_window_error_message (ev_window, error,
2170 "%s", _("Failed to reload document."));
2171 g_error_free (error);
2173 ev_window_reload_local (ev_window);
2176 g_object_unref (remote);
2180 reload_remote_copy_progress_cb (goffset n_bytes,
2181 goffset total_bytes,
2182 EvWindow *ev_window)
2187 if (!ev_window->priv->message_area)
2190 if (total_bytes <= 0)
2193 fraction = n_bytes / (gdouble)total_bytes;
2194 status = g_strdup_printf (_("Downloading document (%d%%)"),
2195 (gint)(fraction * 100));
2197 ev_progress_message_area_set_status (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
2199 ev_progress_message_area_set_fraction (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
2206 query_remote_uri_mtime_cb (GFile *remote,
2207 GAsyncResult *async_result,
2208 EvWindow *ev_window)
2212 GError *error = NULL;
2214 info = g_file_query_info_finish (remote, async_result, &error);
2216 g_error_free (error);
2217 g_object_unref (remote);
2218 ev_window_reload_local (ev_window);
2223 g_file_info_get_modification_time (info, &mtime);
2224 if (ev_window->priv->uri_mtime != mtime.tv_sec) {
2227 /* Remote file has changed */
2228 ev_window->priv->uri_mtime = mtime.tv_sec;
2230 ev_window_reset_progress_cancellable (ev_window);
2232 target_file = g_file_new_for_uri (ev_window->priv->local_uri);
2233 g_file_copy_async (remote, target_file,
2234 G_FILE_COPY_OVERWRITE,
2236 ev_window->priv->progress_cancellable,
2237 (GFileProgressCallback)reload_remote_copy_progress_cb,
2239 (GAsyncReadyCallback)reload_remote_copy_ready_cb,
2241 g_object_unref (target_file);
2242 ev_window_show_progress_message (ev_window, 1,
2243 (GSourceFunc)show_reloading_progress);
2245 g_object_unref (remote);
2246 ev_window_reload_local (ev_window);
2249 g_object_unref (info);
2253 ev_window_reload_remote (EvWindow *ev_window)
2257 remote = g_file_new_for_uri (ev_window->priv->uri);
2258 /* Reload the remote uri only if it has changed */
2259 g_file_query_info_async (remote,
2260 G_FILE_ATTRIBUTE_TIME_MODIFIED,
2261 0, G_PRIORITY_DEFAULT,
2263 (GAsyncReadyCallback)query_remote_uri_mtime_cb,
2268 ev_window_reload_document (EvWindow *ev_window,
2274 ev_window_clear_reload_job (ev_window);
2275 ev_window->priv->in_reload = TRUE;
2277 page = ev_document_model_get_page (ev_window->priv->model);
2279 if (ev_window->priv->dest)
2280 g_object_unref (ev_window->priv->dest);
2281 ev_window->priv->dest = dest ? g_object_ref (dest) : NULL;
2283 if (ev_window->priv->local_uri) {
2284 ev_window_reload_remote (ev_window);
2286 ev_window_reload_local (ev_window);
2291 file_open_dialog_response_cb (GtkWidget *chooser,
2293 EvWindow *ev_window)
2295 if (response_id == GTK_RESPONSE_OK) {
2299 uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (chooser));
2301 ev_application_open_uri_list (EV_APP, uris,
2302 gtk_window_get_screen (GTK_WINDOW (ev_window)),
2303 gtk_get_current_event_time ());
2305 g_slist_foreach (uris, (GFunc)g_free, NULL);
2306 g_slist_free (uris);
2308 uri = gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (chooser));
2309 ev_application_set_filechooser_uri (EV_APP,
2310 GTK_FILE_CHOOSER_ACTION_OPEN,
2315 gtk_widget_destroy (chooser);
2319 ev_window_cmd_file_open (GtkAction *action, EvWindow *window)
2322 const gchar *default_uri;
2323 gchar *parent_uri = NULL;
2325 chooser = gtk_file_chooser_dialog_new (_("Open Document"),
2326 GTK_WINDOW (window),
2327 GTK_FILE_CHOOSER_ACTION_OPEN,
2329 GTK_RESPONSE_CANCEL,
2330 GTK_STOCK_OPEN, GTK_RESPONSE_OK,
2333 ev_document_factory_add_filters (chooser, NULL);
2334 gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (chooser), TRUE);
2335 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser), FALSE);
2337 default_uri = ev_application_get_filechooser_uri (EV_APP, GTK_FILE_CHOOSER_ACTION_OPEN);
2338 if (!default_uri && window->priv->uri) {
2339 GFile *file, *parent;
2341 file = g_file_new_for_uri (window->priv->uri);
2342 parent = g_file_get_parent (file);
2344 parent_uri = g_file_get_uri (parent);
2345 default_uri = parent_uri;
2346 g_object_unref (parent);
2348 g_object_unref (file);
2352 gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (chooser), default_uri);
2354 const gchar *folder;
2356 folder = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
2357 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser),
2358 folder ? folder : g_get_home_dir ());
2360 g_free (parent_uri);
2362 g_signal_connect (chooser, "response",
2363 G_CALLBACK (file_open_dialog_response_cb),
2366 gtk_widget_show (chooser);
2370 ev_window_open_copy_at_dest (EvWindow *window,
2373 EvWindow *new_window = EV_WINDOW (ev_window_new ());
2375 ev_window_n_copies++;
2377 if (window->priv->metadata)
2378 new_window->priv->metadata = g_object_ref (window->priv->metadata);
2379 ev_window_open_document (new_window,
2380 window->priv->document,
2382 gtk_window_present (GTK_WINDOW (new_window));
2386 ev_window_cmd_file_open_copy (GtkAction *action, EvWindow *window)
2388 ev_window_open_copy_at_dest (window, NULL);
2392 ev_window_cmd_recent_file_activate (GtkAction *action,
2395 GtkRecentInfo *info;
2398 info = g_object_get_data (G_OBJECT (action), "gtk-recent-info");
2399 g_assert (info != NULL);
2401 uri = gtk_recent_info_get_uri (info);
2403 ev_application_open_uri_at_dest (EV_APP, uri,
2404 gtk_window_get_screen (GTK_WINDOW (window)),
2405 NULL, 0, NULL, gtk_get_current_event_time ());
2409 ev_window_open_recent_action_item_activated (EvOpenRecentAction *action,
2413 ev_application_open_uri_at_dest (EV_APP, uri,
2414 gtk_window_get_screen (GTK_WINDOW (window)),
2415 NULL, 0, NULL, gtk_get_current_event_time ());
2419 ev_window_add_recent (EvWindow *window, const char *filename)
2421 gtk_recent_manager_add_item (window->priv->recent_manager, filename);
2425 compare_recent_items (GtkRecentInfo *a, GtkRecentInfo *b)
2427 gboolean has_ev_a, has_ev_b;
2428 const gchar *evince = g_get_application_name ();
2430 has_ev_a = gtk_recent_info_has_application (a, evince);
2431 has_ev_b = gtk_recent_info_has_application (b, evince);
2433 if (has_ev_a && has_ev_b) {
2434 time_t time_a, time_b;
2436 time_a = gtk_recent_info_get_modified (a);
2437 time_b = gtk_recent_info_get_modified (b);
2439 return (time_b - time_a);
2440 } else if (has_ev_a) {
2442 } else if (has_ev_b) {
2450 * Doubles underscore to avoid spurious menu accels.
2453 ev_window_get_recent_file_label (gint index, const gchar *filename)
2461 is_rtl = (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL);
2463 g_return_val_if_fail (filename != NULL, NULL);
2465 length = strlen (filename);
2466 str = g_string_sized_new (length + 10);
2467 g_string_printf (str, "%s_%d. ", is_rtl ? "\xE2\x80\x8F" : "", index);
2470 end = filename + length;
2474 next = g_utf8_next_char (p);
2478 g_string_append (str, "__");
2481 g_string_append_len (str, p, next - p);
2488 return g_string_free (str, FALSE);
2492 ev_window_recent_action_connect_proxy_cb (GtkActionGroup *action_group,
2499 if (!GTK_IS_MENU_ITEM (proxy))
2502 label = GTK_LABEL (gtk_bin_get_child (GTK_BIN (proxy)));
2504 gtk_label_set_ellipsize (label, PANGO_ELLIPSIZE_MIDDLE);
2505 gtk_label_set_max_width_chars (label, MAX_RECENT_ITEM_LEN);
2509 ev_window_setup_recent (EvWindow *ev_window)
2513 const gchar *evince = g_get_application_name ();
2516 if (ev_window->priv->recent_ui_id > 0) {
2517 gtk_ui_manager_remove_ui (ev_window->priv->ui_manager,
2518 ev_window->priv->recent_ui_id);
2519 gtk_ui_manager_ensure_update (ev_window->priv->ui_manager);
2521 ev_window->priv->recent_ui_id = gtk_ui_manager_new_merge_id (ev_window->priv->ui_manager);
2523 if (ev_window->priv->recent_action_group) {
2524 gtk_ui_manager_remove_action_group (ev_window->priv->ui_manager,
2525 ev_window->priv->recent_action_group);
2526 g_object_unref (ev_window->priv->recent_action_group);
2528 ev_window->priv->recent_action_group = gtk_action_group_new ("RecentFilesActions");
2529 g_signal_connect (ev_window->priv->recent_action_group, "connect-proxy",
2530 G_CALLBACK (ev_window_recent_action_connect_proxy_cb), NULL);
2532 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
2533 ev_window->priv->recent_action_group, -1);
2535 items = gtk_recent_manager_get_items (ev_window->priv->recent_manager);
2536 items = g_list_sort (items, (GCompareFunc) compare_recent_items);
2538 for (l = items; l && l->data; l = g_list_next (l)) {
2539 GtkRecentInfo *info;
2543 const gchar *mime_type;
2544 gchar *content_type;
2547 info = (GtkRecentInfo *) l->data;
2549 if (!gtk_recent_info_has_application (info, evince) ||
2550 (gtk_recent_info_is_local (info) && !gtk_recent_info_exists (info)))
2553 action_name = g_strdup_printf ("RecentFile%u", i++);
2554 label = ev_window_get_recent_file_label (
2555 n_items + 1, gtk_recent_info_get_display_name (info));
2557 mime_type = gtk_recent_info_get_mime_type (info);
2558 content_type = g_content_type_from_mime_type (mime_type);
2559 if (content_type != NULL) {
2560 icon = g_content_type_get_icon (content_type);
2561 g_free (content_type);
2564 action = g_object_new (GTK_TYPE_ACTION,
2565 "name", action_name,
2568 "always-show-image", TRUE,
2571 g_object_set_data_full (G_OBJECT (action),
2573 gtk_recent_info_ref (info),
2574 (GDestroyNotify) gtk_recent_info_unref);
2576 g_signal_connect (action, "activate",
2577 G_CALLBACK (ev_window_cmd_recent_file_activate),
2578 (gpointer) ev_window);
2580 gtk_action_group_add_action (ev_window->priv->recent_action_group,
2582 g_object_unref (action);
2584 gtk_ui_manager_add_ui (ev_window->priv->ui_manager,
2585 ev_window->priv->recent_ui_id,
2586 "/MainMenu/FileMenu/RecentFilesMenu",
2589 GTK_UI_MANAGER_MENUITEM,
2591 g_free (action_name);
2594 g_object_unref (icon);
2600 g_list_foreach (items, (GFunc) gtk_recent_info_unref, NULL);
2601 g_list_free (items);
2605 show_saving_progress (GFile *dst)
2607 EvWindow *ev_window;
2611 EvSaveType save_type;
2613 ev_window = EV_WINDOW (g_object_get_data (G_OBJECT (dst), "ev-window"));
2614 ev_window->priv->progress_idle = 0;
2616 if (ev_window->priv->message_area)
2619 save_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dst), "save-type"));
2620 uri = g_file_get_uri (dst);
2621 switch (save_type) {
2622 case EV_SAVE_DOCUMENT:
2623 text = g_strdup_printf (_("Saving document to %s"), uri);
2625 case EV_SAVE_ATTACHMENT:
2626 text = g_strdup_printf (_("Saving attachment to %s"), uri);
2629 text = g_strdup_printf (_("Saving image to %s"), uri);
2632 g_assert_not_reached ();
2635 area = ev_progress_message_area_new (GTK_STOCK_SAVE,
2640 GTK_RESPONSE_CANCEL,
2642 g_signal_connect (area, "response",
2643 G_CALLBACK (ev_window_progress_response_cb),
2645 gtk_widget_show (area);
2646 ev_window_set_message_area (ev_window, area);
2653 window_save_file_copy_ready_cb (GFile *src,
2654 GAsyncResult *async_result,
2657 EvWindow *ev_window;
2658 GError *error = NULL;
2660 ev_window = EV_WINDOW (g_object_get_data (G_OBJECT (dst), "ev-window"));
2661 ev_window_clear_progress_idle (ev_window);
2663 if (g_file_copy_finish (src, async_result, &error)) {
2664 ev_tmp_file_unlink (src);
2668 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
2671 name = g_file_get_basename (dst);
2672 ev_window_error_message (ev_window, error,
2673 _("The file could not be saved as “%s”."),
2677 ev_tmp_file_unlink (src);
2678 g_error_free (error);
2682 window_save_file_copy_progress_cb (goffset n_bytes,
2683 goffset total_bytes,
2686 EvWindow *ev_window;
2687 EvSaveType save_type;
2691 ev_window = EV_WINDOW (g_object_get_data (G_OBJECT (dst), "ev-window"));
2693 if (!ev_window->priv->message_area)
2696 if (total_bytes <= 0)
2699 fraction = n_bytes / (gdouble)total_bytes;
2700 save_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dst), "save-type"));
2702 switch (save_type) {
2703 case EV_SAVE_DOCUMENT:
2704 status = g_strdup_printf (_("Uploading document (%d%%)"),
2705 (gint)(fraction * 100));
2707 case EV_SAVE_ATTACHMENT:
2708 status = g_strdup_printf (_("Uploading attachment (%d%%)"),
2709 (gint)(fraction * 100));
2712 status = g_strdup_printf (_("Uploading image (%d%%)"),
2713 (gint)(fraction * 100));
2716 g_assert_not_reached ();
2719 ev_progress_message_area_set_status (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
2721 ev_progress_message_area_set_fraction (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
2728 ev_window_save_remote (EvWindow *ev_window,
2729 EvSaveType save_type,
2733 ev_window_reset_progress_cancellable (ev_window);
2734 g_object_set_data (G_OBJECT (dst), "ev-window", ev_window);
2735 g_object_set_data (G_OBJECT (dst), "save-type", GINT_TO_POINTER (save_type));
2736 g_file_copy_async (src, dst,
2737 G_FILE_COPY_OVERWRITE,
2739 ev_window->priv->progress_cancellable,
2740 (GFileProgressCallback)window_save_file_copy_progress_cb,
2742 (GAsyncReadyCallback)window_save_file_copy_ready_cb,
2744 ev_window->priv->progress_idle =
2745 g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
2747 (GSourceFunc)show_saving_progress,
2753 ev_window_clear_save_job (EvWindow *ev_window)
2755 if (ev_window->priv->save_job != NULL) {
2756 if (!ev_job_is_finished (ev_window->priv->save_job))
2757 ev_job_cancel (ev_window->priv->save_job);
2759 g_signal_handlers_disconnect_by_func (ev_window->priv->save_job,
2760 ev_window_save_job_cb,
2762 g_object_unref (ev_window->priv->save_job);
2763 ev_window->priv->save_job = NULL;
2768 ev_window_save_job_cb (EvJob *job,
2771 if (ev_job_is_failed (job)) {
2772 ev_window_error_message (window, job->error,
2773 _("The file could not be saved as “%s”."),
2774 EV_JOB_SAVE (job)->uri);
2776 ev_window_add_recent (window, EV_JOB_SAVE (job)->uri);
2779 ev_window_clear_save_job (window);
2783 file_save_dialog_response_cb (GtkWidget *fc,
2785 EvWindow *ev_window)
2788 GFile *file, *parent;
2790 if (response_id != GTK_RESPONSE_OK) {
2791 gtk_widget_destroy (fc);
2795 uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
2796 file = g_file_new_for_uri (uri);
2797 parent = g_file_get_parent (file);
2798 g_object_unref (file);
2802 folder_uri = g_file_get_uri (parent);
2803 ev_application_set_filechooser_uri (EV_APP,
2804 GTK_FILE_CHOOSER_ACTION_SAVE,
2806 g_free (folder_uri);
2807 g_object_unref (parent);
2810 /* FIXME: remote copy should be done here rather than in the save job,
2811 * so that we can track progress and cancel the operation
2814 ev_window_clear_save_job (ev_window);
2815 ev_window->priv->save_job = ev_job_save_new (ev_window->priv->document,
2816 uri, ev_window->priv->uri);
2817 g_signal_connect (ev_window->priv->save_job, "finished",
2818 G_CALLBACK (ev_window_save_job_cb),
2820 /* The priority doesn't matter for this job */
2821 ev_job_scheduler_push_job (ev_window->priv->save_job, EV_JOB_PRIORITY_NONE);
2824 gtk_widget_destroy (fc);
2828 ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window)
2833 const gchar *default_uri;
2835 fc = gtk_file_chooser_dialog_new (
2837 GTK_WINDOW (ev_window), GTK_FILE_CHOOSER_ACTION_SAVE,
2838 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
2839 GTK_STOCK_SAVE, GTK_RESPONSE_OK,
2842 ev_document_factory_add_filters (fc, ev_window->priv->document);
2843 gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
2844 gtk_dialog_set_alternative_button_order (GTK_DIALOG (fc),
2846 GTK_RESPONSE_CANCEL,
2849 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (fc), FALSE);
2850 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
2851 file = g_file_new_for_uri (ev_window->priv->uri);
2852 base_name = g_file_get_basename (file);
2853 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc), base_name);
2855 default_uri = ev_application_get_filechooser_uri (EV_APP, GTK_FILE_CHOOSER_ACTION_SAVE);
2857 gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (fc), default_uri);
2859 const gchar *folder;
2861 folder = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
2862 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (fc),
2863 folder ? folder : g_get_home_dir ());
2866 g_object_unref (file);
2869 g_signal_connect (fc, "response",
2870 G_CALLBACK (file_save_dialog_response_cb),
2873 gtk_widget_show (fc);
2877 ev_window_cmd_open_containing_folder (GtkAction *action, EvWindow *ev_window)
2879 GtkWidget *ev_window_widget;
2883 ev_window_widget = GTK_WIDGET (ev_window);
2885 file = g_file_new_for_uri (ev_window->priv->uri);
2886 parent = g_file_get_parent (file);
2891 parent_uri = g_file_get_uri (parent);
2897 screen = gtk_widget_get_screen (ev_window_widget);
2898 timestamp = gtk_get_current_event_time ();
2901 if (!gtk_show_uri (screen, parent_uri, timestamp, &error)) {
2902 ev_window_error_message (ev_window, error, _("Could not open the containing folder"));
2903 g_error_free (error);
2906 g_free (parent_uri);
2911 g_object_unref (file);
2914 g_object_unref (parent);
2919 get_print_settings_file (void)
2921 GKeyFile *print_settings_file;
2923 GError *error = NULL;
2925 print_settings_file = g_key_file_new ();
2927 filename = g_build_filename (ev_application_get_dot_dir (EV_APP, FALSE),
2928 EV_PRINT_SETTINGS_FILE, NULL);
2929 if (!g_key_file_load_from_file (print_settings_file,
2931 G_KEY_FILE_KEEP_COMMENTS |
2932 G_KEY_FILE_KEEP_TRANSLATIONS,
2935 /* Don't warn if the file simply doesn't exist */
2936 if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
2937 g_warning ("%s", error->message);
2939 g_error_free (error);
2944 return print_settings_file;
2948 save_print_setting_file (GKeyFile *key_file)
2953 GError *error = NULL;
2955 filename = g_build_filename (ev_application_get_dot_dir (EV_APP, TRUE),
2956 EV_PRINT_SETTINGS_FILE, NULL);
2957 data = g_key_file_to_data (key_file, &data_length, NULL);
2958 g_file_set_contents (filename, data, data_length, &error);
2960 g_warning ("Failed to save print settings: %s", error->message);
2961 g_error_free (error);
2968 ev_window_save_print_settings (EvWindow *window,
2969 GtkPrintSettings *print_settings)
2974 key_file = get_print_settings_file ();
2975 gtk_print_settings_to_key_file (print_settings, key_file, EV_PRINT_SETTINGS_GROUP);
2977 /* Save print settings that are specific to the document */
2978 for (i = 0; i < G_N_ELEMENTS (document_print_settings); i++) {
2979 /* Remove it from global settings */
2980 g_key_file_remove_key (key_file, EV_PRINT_SETTINGS_GROUP,
2981 document_print_settings[i], NULL);
2983 if (window->priv->metadata) {
2986 value = gtk_print_settings_get (print_settings,
2987 document_print_settings[i]);
2988 ev_metadata_set_string (window->priv->metadata,
2989 document_print_settings[i], value);
2993 save_print_setting_file (key_file);
2994 g_key_file_free (key_file);
2998 ev_window_save_print_page_setup (EvWindow *window,
2999 GtkPageSetup *page_setup)
3003 key_file = get_print_settings_file ();
3004 gtk_page_setup_to_key_file (page_setup, key_file, EV_PAGE_SETUP_GROUP);
3006 /* Do not save document settings in global file */
3007 g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
3008 "page-setup-orientation", NULL);
3009 g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
3010 "page-setup-margin-top", NULL);
3011 g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
3012 "page-setup-margin-bottom", NULL);
3013 g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
3014 "page-setup-margin-left", NULL);
3015 g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
3016 "page-setup-margin-right", NULL);
3018 save_print_setting_file (key_file);
3019 g_key_file_free (key_file);
3021 if (!window->priv->metadata)
3024 /* Save page setup options that are specific to the document */
3025 ev_metadata_set_int (window->priv->metadata, "page-setup-orientation",
3026 gtk_page_setup_get_orientation (page_setup));
3027 ev_metadata_set_double (window->priv->metadata, "page-setup-margin-top",
3028 gtk_page_setup_get_top_margin (page_setup, GTK_UNIT_MM));
3029 ev_metadata_set_double (window->priv->metadata, "page-setup-margin-bottom",
3030 gtk_page_setup_get_bottom_margin (page_setup, GTK_UNIT_MM));
3031 ev_metadata_set_double (window->priv->metadata, "page-setup-margin-left",
3032 gtk_page_setup_get_left_margin (page_setup, GTK_UNIT_MM));
3033 ev_metadata_set_double (window->priv->metadata, "page-setup-margin-right",
3034 gtk_page_setup_get_right_margin (page_setup, GTK_UNIT_MM));
3038 ev_window_load_print_settings_from_metadata (EvWindow *window,
3039 GtkPrintSettings *print_settings)
3043 if (!window->priv->metadata)
3046 /* Load print setting that are specific to the document */
3047 for (i = 0; i < G_N_ELEMENTS (document_print_settings); i++) {
3048 gchar *value = NULL;
3050 ev_metadata_get_string (window->priv->metadata,
3051 document_print_settings[i], &value);
3052 gtk_print_settings_set (print_settings,
3053 document_print_settings[i], value);
3058 ev_window_load_print_page_setup_from_metadata (EvWindow *window,
3059 GtkPageSetup *page_setup)
3062 gdouble double_value;
3063 GtkPaperSize *paper_size = gtk_page_setup_get_paper_size (page_setup);
3065 /* Load page setup options that are specific to the document */
3066 if (window->priv->metadata &&
3067 ev_metadata_get_int (window->priv->metadata, "page-setup-orientation", &int_value)) {
3068 gtk_page_setup_set_orientation (page_setup, int_value);
3070 gtk_page_setup_set_orientation (page_setup, GTK_PAGE_ORIENTATION_PORTRAIT);
3073 if (window->priv->metadata &&
3074 ev_metadata_get_double (window->priv->metadata, "page-setup-margin-top", &double_value)) {
3075 gtk_page_setup_set_top_margin (page_setup, double_value, GTK_UNIT_MM);
3077 gtk_page_setup_set_top_margin (page_setup,
3078 gtk_paper_size_get_default_top_margin (paper_size, GTK_UNIT_MM),
3082 if (window->priv->metadata &&
3083 ev_metadata_get_double (window->priv->metadata, "page-setup-margin-bottom", &double_value)) {
3084 gtk_page_setup_set_bottom_margin (page_setup, double_value, GTK_UNIT_MM);
3086 gtk_page_setup_set_bottom_margin (page_setup,
3087 gtk_paper_size_get_default_bottom_margin (paper_size, GTK_UNIT_MM),
3091 if (window->priv->metadata &&
3092 ev_metadata_get_double (window->priv->metadata, "page-setup-margin-left", &double_value)) {
3093 gtk_page_setup_set_left_margin (page_setup, double_value, GTK_UNIT_MM);
3095 gtk_page_setup_set_left_margin (page_setup,
3096 gtk_paper_size_get_default_left_margin (paper_size, GTK_UNIT_MM),
3100 if (window->priv->metadata &&
3101 ev_metadata_get_double (window->priv->metadata, "page-setup-margin-right", &double_value)) {
3102 gtk_page_setup_set_right_margin (page_setup, double_value, GTK_UNIT_MM);
3104 gtk_page_setup_set_right_margin (page_setup,
3105 gtk_paper_size_get_default_right_margin (paper_size, GTK_UNIT_MM),
3110 static GtkPrintSettings *
3111 get_print_settings (GKeyFile *key_file)
3113 GtkPrintSettings *print_settings;
3115 print_settings = g_key_file_has_group (key_file, EV_PRINT_SETTINGS_GROUP) ?
3116 gtk_print_settings_new_from_key_file (key_file, EV_PRINT_SETTINGS_GROUP, NULL) :
3117 gtk_print_settings_new ();
3119 return print_settings ? print_settings : gtk_print_settings_new ();
3122 static GtkPageSetup *
3123 get_print_page_setup (GKeyFile *key_file)
3125 GtkPageSetup *page_setup;
3127 page_setup = g_key_file_has_group (key_file, EV_PAGE_SETUP_GROUP) ?
3128 gtk_page_setup_new_from_key_file (key_file, EV_PAGE_SETUP_GROUP, NULL) :
3129 gtk_page_setup_new ();
3131 return page_setup ? page_setup : gtk_page_setup_new ();
3135 ev_window_print_cancel (EvWindow *ev_window)
3137 EvPrintOperation *op;
3139 if (!ev_window->priv->print_queue)
3142 while ((op = g_queue_peek_tail (ev_window->priv->print_queue))) {
3143 ev_print_operation_cancel (op);
3148 ev_window_print_update_pending_jobs_message (EvWindow *ev_window,
3153 if (!EV_IS_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area) ||
3154 !ev_window->priv->print_queue)
3158 ev_window_set_message_area (ev_window, NULL);
3163 text = g_strdup_printf (ngettext ("%d pending job in queue",
3164 "%d pending jobs in queue",
3165 n_jobs - 1), n_jobs - 1);
3168 ev_message_area_set_secondary_text (EV_MESSAGE_AREA (ev_window->priv->message_area),
3174 destroy_window (GtkWidget *window)
3176 gtk_widget_destroy (window);
3182 ev_window_print_operation_done (EvPrintOperation *op,
3183 GtkPrintOperationResult result,
3184 EvWindow *ev_window)
3189 case GTK_PRINT_OPERATION_RESULT_APPLY: {
3190 GtkPrintSettings *print_settings;
3192 print_settings = ev_print_operation_get_print_settings (op);
3193 ev_window_save_print_settings (ev_window, print_settings);
3195 if (ev_print_operation_get_embed_page_setup (op)) {
3196 GtkPageSetup *page_setup;
3198 page_setup = ev_print_operation_get_default_page_setup (op);
3199 ev_window_save_print_page_setup (ev_window, page_setup);
3204 case GTK_PRINT_OPERATION_RESULT_ERROR: {
3206 GError *error = NULL;
3209 ev_print_operation_get_error (op, &error);
3211 /* The message area is already used by
3212 * the printing progress, so it's better to
3213 * use a popup dialog in this case
3215 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
3216 GTK_DIALOG_DESTROY_WITH_PARENT,
3219 "%s", _("Failed to print document"));
3220 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
3221 "%s", error->message);
3222 g_signal_connect (dialog, "response",
3223 G_CALLBACK (gtk_widget_destroy),
3225 gtk_widget_show (dialog);
3227 g_error_free (error);
3230 case GTK_PRINT_OPERATION_RESULT_CANCEL:
3235 g_queue_remove (ev_window->priv->print_queue, op);
3236 g_object_unref (op);
3237 n_jobs = g_queue_get_length (ev_window->priv->print_queue);
3238 ev_window_print_update_pending_jobs_message (ev_window, n_jobs);
3240 if (n_jobs == 0 && ev_window->priv->close_after_print)
3241 g_idle_add ((GSourceFunc)destroy_window,
3246 ev_window_print_progress_response_cb (EvProgressMessageArea *area,
3248 EvWindow *ev_window)
3250 if (response == GTK_RESPONSE_CANCEL) {
3251 EvPrintOperation *op;
3253 op = g_queue_peek_tail (ev_window->priv->print_queue);
3254 ev_print_operation_cancel (op);
3256 gtk_widget_hide (GTK_WIDGET (area));
3261 ev_window_print_operation_status_changed (EvPrintOperation *op,
3262 EvWindow *ev_window)
3264 const gchar *status;
3267 status = ev_print_operation_get_status (op);
3268 fraction = ev_print_operation_get_progress (op);
3270 if (!ev_window->priv->message_area) {
3272 const gchar *job_name;
3275 job_name = ev_print_operation_get_job_name (op);
3276 text = g_strdup_printf (_("Printing job “%s”"), job_name);
3278 area = ev_progress_message_area_new (GTK_STOCK_PRINT,
3283 GTK_RESPONSE_CANCEL,
3285 ev_window_print_update_pending_jobs_message (ev_window, 1);
3286 g_signal_connect (area, "response",
3287 G_CALLBACK (ev_window_print_progress_response_cb),
3289 gtk_widget_show (area);
3290 ev_window_set_message_area (ev_window, area);
3294 ev_progress_message_area_set_status (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
3296 ev_progress_message_area_set_fraction (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
3301 ev_window_print_operation_begin_print (EvPrintOperation *op,
3302 EvWindow *ev_window)
3304 if (!ev_window->priv->print_queue)
3305 ev_window->priv->print_queue = g_queue_new ();
3307 g_queue_push_head (ev_window->priv->print_queue, op);
3308 ev_window_print_update_pending_jobs_message (ev_window,
3309 g_queue_get_length (ev_window->priv->print_queue));
3313 ev_window_print_range (EvWindow *ev_window,
3317 EvPrintOperation *op;
3318 GKeyFile *print_settings_file;
3319 GtkPrintSettings *print_settings;
3320 GtkPageSetup *print_page_setup;
3322 gint document_last_page;
3323 gboolean embed_page_setup;
3325 g_return_if_fail (EV_IS_WINDOW (ev_window));
3326 g_return_if_fail (ev_window->priv->document != NULL);
3328 if (!ev_window->priv->print_queue)
3329 ev_window->priv->print_queue = g_queue_new ();
3331 op = ev_print_operation_new (ev_window->priv->document);
3333 g_warning ("%s", "Printing is not supported for document\n");
3337 g_signal_connect (op, "begin_print",
3338 G_CALLBACK (ev_window_print_operation_begin_print),
3339 (gpointer)ev_window);
3340 g_signal_connect (op, "status_changed",
3341 G_CALLBACK (ev_window_print_operation_status_changed),
3342 (gpointer)ev_window);
3343 g_signal_connect (op, "done",
3344 G_CALLBACK (ev_window_print_operation_done),
3345 (gpointer)ev_window);
3347 current_page = ev_document_model_get_page (ev_window->priv->model);
3348 document_last_page = ev_document_get_n_pages (ev_window->priv->document);
3350 print_settings_file = get_print_settings_file ();
3352 print_settings = get_print_settings (print_settings_file);
3353 ev_window_load_print_settings_from_metadata (ev_window, print_settings);
3355 print_page_setup = get_print_page_setup (print_settings_file);
3356 ev_window_load_print_page_setup_from_metadata (ev_window, print_page_setup);
3358 if (first_page != 1 || last_page != document_last_page) {
3361 /* Ranges in GtkPrint are 0 - N */
3362 range.start = first_page - 1;
3363 range.end = last_page - 1;
3365 gtk_print_settings_set_print_pages (print_settings,
3366 GTK_PRINT_PAGES_RANGES);
3367 gtk_print_settings_set_page_ranges (print_settings,
3371 ev_print_operation_set_job_name (op, gtk_window_get_title (GTK_WINDOW (ev_window)));
3372 ev_print_operation_set_current_page (op, current_page);
3373 ev_print_operation_set_print_settings (op, print_settings);
3374 ev_print_operation_set_default_page_setup (op, print_page_setup);
3375 embed_page_setup = ev_window->priv->lockdown_settings ?
3376 !g_settings_get_boolean (ev_window->priv->lockdown_settings,
3377 GS_LOCKDOWN_PRINT_SETUP) :
3379 ev_print_operation_set_embed_page_setup (op, embed_page_setup);
3381 g_object_unref (print_settings);
3382 g_object_unref (print_page_setup);
3383 g_key_file_free (print_settings_file);
3385 ev_print_operation_run (op, GTK_WINDOW (ev_window));
3389 ev_window_print (EvWindow *window)
3391 ev_window_print_range (window, 1,
3392 ev_document_get_n_pages (window->priv->document));
3396 ev_window_cmd_file_print (GtkAction *action, EvWindow *ev_window)
3398 ev_window_print (ev_window);
3402 ev_window_cmd_file_properties (GtkAction *action, EvWindow *ev_window)
3404 if (ev_window->priv->properties == NULL) {
3405 ev_window->priv->properties = ev_properties_dialog_new ();
3406 ev_properties_dialog_set_document (EV_PROPERTIES_DIALOG (ev_window->priv->properties),
3407 ev_window->priv->uri,
3408 ev_window->priv->document);
3409 g_object_add_weak_pointer (G_OBJECT (ev_window->priv->properties),
3410 (gpointer) &(ev_window->priv->properties));
3411 gtk_window_set_transient_for (GTK_WINDOW (ev_window->priv->properties),
3412 GTK_WINDOW (ev_window));
3415 ev_document_fc_mutex_lock ();
3416 gtk_widget_show (ev_window->priv->properties);
3417 ev_document_fc_mutex_unlock ();
3421 document_modified_confirmation_dialog_response (GtkDialog *dialog,
3423 EvWindow *ev_window)
3425 gtk_widget_destroy (GTK_WIDGET (dialog));
3428 case GTK_RESPONSE_YES:
3429 ev_window_cmd_save_as (NULL, ev_window);
3431 case GTK_RESPONSE_NO:
3432 gtk_widget_destroy (GTK_WIDGET (ev_window));
3434 case GTK_RESPONSE_CANCEL:
3441 ev_window_check_document_modified (EvWindow *ev_window)
3443 EvDocument *document = ev_window->priv->document;
3445 gchar *text, *markup;
3446 const gchar *secondary_text;
3451 if (EV_IS_DOCUMENT_FORMS (document) &&
3452 ev_document_forms_document_is_modified (EV_DOCUMENT_FORMS (document))) {
3453 secondary_text = _("Document contains form fields that have been filled out. "
3454 "If you don't save a copy, changes will be permanently lost.");
3455 } else if (EV_IS_DOCUMENT_ANNOTATIONS (document) &&
3456 ev_document_annotations_document_is_modified (EV_DOCUMENT_ANNOTATIONS (document))) {
3457 secondary_text = _("Document contains new or modified annotations. "
3458 "If you don't save a copy, changes will be permanently lost.");
3464 text = g_markup_printf_escaped (_("Save a copy of document “%s” before closing?"),
3465 gtk_window_get_title (GTK_WINDOW (ev_window)));
3467 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
3469 GTK_MESSAGE_QUESTION,
3473 markup = g_strdup_printf ("<b>%s</b>", text);
3476 gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), markup);
3479 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
3480 "%s", secondary_text);
3482 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
3483 _("Close _without Saving"),
3486 GTK_RESPONSE_CANCEL,
3490 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
3491 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
3494 GTK_RESPONSE_CANCEL,
3497 g_signal_connect (dialog, "response",
3498 G_CALLBACK (document_modified_confirmation_dialog_response),
3500 gtk_widget_show (dialog);
3506 print_jobs_confirmation_dialog_response (GtkDialog *dialog,
3508 EvWindow *ev_window)
3510 gtk_widget_destroy (GTK_WIDGET (dialog));
3513 case GTK_RESPONSE_YES:
3514 if (!ev_window->priv->print_queue ||
3515 g_queue_is_empty (ev_window->priv->print_queue))
3516 gtk_widget_destroy (GTK_WIDGET (ev_window));
3518 ev_window->priv->close_after_print = TRUE;
3520 case GTK_RESPONSE_NO:
3521 ev_window->priv->close_after_print = TRUE;
3522 if (ev_window->priv->print_queue &&
3523 !g_queue_is_empty (ev_window->priv->print_queue)) {
3524 gtk_widget_set_sensitive (GTK_WIDGET (ev_window), FALSE);
3525 ev_window_print_cancel (ev_window);
3527 gtk_widget_destroy (GTK_WIDGET (ev_window));
3530 case GTK_RESPONSE_CANCEL:
3532 ev_window->priv->close_after_print = FALSE;
3537 ev_window_check_print_queue (EvWindow *ev_window)
3540 gchar *text, *markup;
3543 n_print_jobs = ev_window->priv->print_queue ?
3544 g_queue_get_length (ev_window->priv->print_queue) : 0;
3546 if (n_print_jobs == 0)
3549 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
3551 GTK_MESSAGE_QUESTION,
3554 if (n_print_jobs == 1) {
3555 EvPrintOperation *op;
3556 const gchar *job_name;
3558 op = g_queue_peek_tail (ev_window->priv->print_queue);
3559 job_name = ev_print_operation_get_job_name (op);
3561 text = g_strdup_printf (_("Wait until print job “%s” finishes before closing?"),
3564 text = g_strdup_printf (_("There are %d print jobs active. "
3565 "Wait until print finishes before closing?"),
3569 markup = g_strdup_printf ("<b>%s</b>", text);
3572 gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), markup);
3575 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s",
3576 _("If you close the window, pending print "
3577 "jobs will not be printed."));
3579 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
3580 _("Cancel _print and Close"),
3583 GTK_RESPONSE_CANCEL,
3584 _("Close _after Printing"),
3587 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
3588 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
3591 GTK_RESPONSE_CANCEL,
3594 g_signal_connect (dialog, "response",
3595 G_CALLBACK (print_jobs_confirmation_dialog_response),
3597 gtk_widget_show (dialog);
3603 ev_window_close (EvWindow *ev_window)
3605 if (EV_WINDOW_IS_PRESENTATION (ev_window)) {
3608 /* Save current page */
3609 current_page = ev_view_presentation_get_current_page (
3610 EV_VIEW_PRESENTATION (ev_window->priv->presentation_view));
3611 ev_document_model_set_page (ev_window->priv->model, current_page);
3614 if (ev_window_check_document_modified (ev_window))
3617 if (ev_window_check_print_queue (ev_window))
3624 ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window)
3626 if (ev_window_close (ev_window))
3627 gtk_widget_destroy (GTK_WIDGET (ev_window));
3631 ev_window_cmd_focus_page_selector (GtkAction *act, EvWindow *window)
3635 update_chrome_flag (window, EV_CHROME_RAISE_TOOLBAR, TRUE);
3636 ev_window_set_action_sensitive (window, "ViewToolbar", FALSE);
3637 update_chrome_visibility (window);
3639 action = gtk_action_group_get_action (window->priv->action_group,
3640 PAGE_SELECTOR_ACTION);
3641 ev_page_action_grab_focus (EV_PAGE_ACTION (action));
3645 ev_window_cmd_scroll_forward (GtkAction *action, EvWindow *window)
3647 ev_view_scroll (EV_VIEW (window->priv->view), GTK_SCROLL_PAGE_FORWARD, FALSE);
3651 ev_window_cmd_scroll_backward (GtkAction *action, EvWindow *window)
3653 ev_view_scroll (EV_VIEW (window->priv->view), GTK_SCROLL_PAGE_BACKWARD, FALSE);
3657 ev_window_cmd_continuous (GtkAction *action, EvWindow *ev_window)
3659 gboolean continuous;
3661 ev_window_stop_presentation (ev_window, TRUE);
3662 continuous = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
3663 ev_document_model_set_continuous (ev_window->priv->model, continuous);
3667 ev_window_cmd_dual (GtkAction *action, EvWindow *ev_window)
3671 ev_window_stop_presentation (ev_window, TRUE);
3672 dual_page = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
3673 ev_document_model_set_dual_page (ev_window->priv->model, dual_page);
3677 ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window)
3679 ev_window_stop_presentation (ev_window, TRUE);
3681 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
3682 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_BEST_FIT);
3684 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FREE);
3686 ev_window_update_actions (ev_window);
3690 ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window)
3692 ev_window_stop_presentation (ev_window, TRUE);
3694 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
3695 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FIT_WIDTH);
3697 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FREE);
3699 ev_window_update_actions (ev_window);
3704 ev_window_cmd_edit_select_all (GtkAction *action, EvWindow *ev_window)
3706 g_return_if_fail (EV_IS_WINDOW (ev_window));
3708 ev_view_select_all (EV_VIEW (ev_window->priv->view));
3712 ev_window_cmd_edit_find (GtkAction *action, EvWindow *ev_window)
3714 g_return_if_fail (EV_IS_WINDOW (ev_window));
3716 if (ev_window->priv->document == NULL || !EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
3717 g_error ("Find action should be insensitive since document doesn't support find");
3721 update_chrome_flag (ev_window, EV_CHROME_FINDBAR, TRUE);
3722 update_chrome_visibility (ev_window);
3723 gtk_widget_grab_focus (ev_window->priv->find_bar);
3727 ev_window_cmd_edit_find_next (GtkAction *action, EvWindow *ev_window)
3729 g_return_if_fail (EV_IS_WINDOW (ev_window));
3731 update_chrome_flag (ev_window, EV_CHROME_FINDBAR, TRUE);
3732 update_chrome_visibility (ev_window);
3733 gtk_widget_grab_focus (ev_window->priv->find_bar);
3734 ev_view_find_next (EV_VIEW (ev_window->priv->view));
3738 ev_window_cmd_edit_find_previous (GtkAction *action, EvWindow *ev_window)
3740 g_return_if_fail (EV_IS_WINDOW (ev_window));
3742 update_chrome_flag (ev_window, EV_CHROME_FINDBAR, TRUE);
3743 update_chrome_visibility (ev_window);
3744 gtk_widget_grab_focus (ev_window->priv->find_bar);
3745 ev_view_find_previous (EV_VIEW (ev_window->priv->view));
3749 ev_window_cmd_edit_copy (GtkAction *action, EvWindow *ev_window)
3751 g_return_if_fail (EV_IS_WINDOW (ev_window));
3753 ev_view_copy (EV_VIEW (ev_window->priv->view));
3757 ev_window_sidebar_position_change_cb (GObject *object,
3759 EvWindow *ev_window)
3761 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window))
3762 ev_metadata_set_int (ev_window->priv->metadata, "sidebar_size",
3763 gtk_paned_get_position (GTK_PANED (object)));
3767 ev_window_update_fullscreen_action (EvWindow *window)
3771 action = gtk_action_group_get_action (window->priv->action_group, "ViewFullscreen");
3772 g_signal_handlers_block_by_func
3773 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
3774 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
3775 ev_document_model_get_fullscreen (window->priv->model));
3776 g_signal_handlers_unblock_by_func
3777 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
3781 fullscreen_toolbar_setup_item_properties (GtkUIManager *ui_manager)
3785 item = gtk_ui_manager_get_widget (ui_manager, "/FullscreenToolbar/GoPreviousPage");
3786 g_object_set (item, "is-important", FALSE, NULL);
3788 item = gtk_ui_manager_get_widget (ui_manager, "/FullscreenToolbar/GoNextPage");
3789 g_object_set (item, "is-important", FALSE, NULL);
3791 item = gtk_ui_manager_get_widget (ui_manager, "/FullscreenToolbar/StartPresentation");
3792 g_object_set (item, "is-important", TRUE, NULL);
3794 item = gtk_ui_manager_get_widget (ui_manager, "/FullscreenToolbar/LeaveFullscreen");
3795 g_object_set (item, "is-important", TRUE, NULL);
3799 fullscreen_toolbar_remove_shadow (GtkWidget *toolbar)
3801 static gboolean done = FALSE;
3804 gtk_rc_parse_string (
3806 " style \"fullscreen-toolbar-style\"\n"
3808 " GtkToolbar::shadow-type=GTK_SHADOW_NONE\n"
3811 " widget \"*.fullscreen-toolbar\" style \"fullscreen-toolbar-style\"\n"
3816 gtk_widget_set_name (toolbar, "fullscreen-toolbar");
3820 ev_window_run_fullscreen (EvWindow *window)
3822 gboolean fullscreen_window = TRUE;
3824 if (ev_document_model_get_fullscreen (window->priv->model))
3827 if (!window->priv->fullscreen_toolbar) {
3828 window->priv->fullscreen_toolbar =
3829 gtk_ui_manager_get_widget (window->priv->ui_manager,
3830 "/FullscreenToolbar");
3832 gtk_toolbar_set_style (GTK_TOOLBAR (window->priv->fullscreen_toolbar),
3833 GTK_TOOLBAR_BOTH_HORIZ);
3834 fullscreen_toolbar_remove_shadow (window->priv->fullscreen_toolbar);
3835 fullscreen_toolbar_setup_item_properties (window->priv->ui_manager);
3837 gtk_box_pack_start (GTK_BOX (window->priv->main_box),
3838 window->priv->fullscreen_toolbar,
3840 gtk_box_reorder_child (GTK_BOX (window->priv->main_box),
3841 window->priv->fullscreen_toolbar, 1);
3844 if (EV_WINDOW_IS_PRESENTATION (window)) {
3845 ev_window_stop_presentation (window, FALSE);
3846 fullscreen_window = FALSE;
3849 g_object_set (G_OBJECT (window->priv->scrolled_window),
3850 "shadow-type", GTK_SHADOW_NONE,
3853 ev_document_model_set_fullscreen (window->priv->model, TRUE);
3854 ev_window_update_fullscreen_action (window);
3856 /* If the user doesn't have the main toolbar he/she won't probably want
3857 * the toolbar in fullscreen mode. See bug #483048
3859 update_chrome_flag (window, EV_CHROME_FULLSCREEN_TOOLBAR,
3860 (window->priv->chrome & EV_CHROME_TOOLBAR) != 0);
3861 update_chrome_visibility (window);
3863 if (fullscreen_window)
3864 gtk_window_fullscreen (GTK_WINDOW (window));
3865 gtk_widget_grab_focus (window->priv->view);
3867 if (window->priv->metadata && !ev_window_is_empty (window))
3868 ev_metadata_set_boolean (window->priv->metadata, "fullscreen", TRUE);
3872 ev_window_stop_fullscreen (EvWindow *window,
3873 gboolean unfullscreen_window)
3875 if (!ev_document_model_get_fullscreen (window->priv->model))
3878 g_object_set (G_OBJECT (window->priv->scrolled_window),
3879 "shadow-type", GTK_SHADOW_IN,
3882 ev_document_model_set_fullscreen (window->priv->model, FALSE);
3883 ev_window_update_fullscreen_action (window);
3884 update_chrome_flag (window, EV_CHROME_FULLSCREEN_TOOLBAR, FALSE);
3885 update_chrome_visibility (window);
3886 if (unfullscreen_window)
3887 gtk_window_unfullscreen (GTK_WINDOW (window));
3889 if (window->priv->metadata && !ev_window_is_empty (window))
3890 ev_metadata_set_boolean (window->priv->metadata, "fullscreen", FALSE);
3894 ev_window_cmd_view_fullscreen (GtkAction *action, EvWindow *window)
3896 gboolean fullscreen;
3898 fullscreen = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
3900 ev_window_run_fullscreen (window);
3902 ev_window_stop_fullscreen (window, TRUE);
3907 ev_window_update_presentation_action (EvWindow *window)
3911 action = gtk_action_group_get_action (window->priv->action_group, "ViewPresentation");
3912 g_signal_handlers_block_by_func
3913 (action, G_CALLBACK (ev_window_cmd_view_presentation), window);
3914 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
3915 EV_WINDOW_IS_PRESENTATION (window));
3916 g_signal_handlers_unblock_by_func
3917 (action, G_CALLBACK (ev_window_cmd_view_presentation), window);
3921 ev_window_view_presentation_finished (EvWindow *window)
3923 ev_window_stop_presentation (window, TRUE);
3927 ev_window_run_presentation (EvWindow *window)
3929 gboolean fullscreen_window = TRUE;
3932 gboolean inverted_colors;
3934 if (EV_WINDOW_IS_PRESENTATION (window))
3937 if (ev_document_model_get_fullscreen (window->priv->model)) {
3938 ev_window_stop_fullscreen (window, FALSE);
3939 fullscreen_window = FALSE;
3942 current_page = ev_document_model_get_page (window->priv->model);
3943 rotation = ev_document_model_get_rotation (window->priv->model);
3944 inverted_colors = ev_document_model_get_inverted_colors (window->priv->model);
3945 window->priv->presentation_view = ev_view_presentation_new (window->priv->document,
3949 g_signal_connect_swapped (window->priv->presentation_view, "finished",
3950 G_CALLBACK (ev_window_view_presentation_finished),
3953 gtk_box_pack_start (GTK_BOX (window->priv->main_box),
3954 window->priv->presentation_view,
3957 gtk_widget_hide (window->priv->hpaned);
3958 ev_window_update_presentation_action (window);
3959 update_chrome_visibility (window);
3961 gtk_widget_grab_focus (window->priv->presentation_view);
3962 if (fullscreen_window)
3963 gtk_window_fullscreen (GTK_WINDOW (window));
3965 gtk_widget_show (window->priv->presentation_view);
3967 ev_application_screensaver_disable (EV_APP);
3969 if (window->priv->metadata && !ev_window_is_empty (window))
3970 ev_metadata_set_boolean (window->priv->metadata, "presentation", TRUE);
3974 ev_window_stop_presentation (EvWindow *window,
3975 gboolean unfullscreen_window)
3979 if (!EV_WINDOW_IS_PRESENTATION (window))
3982 current_page = ev_view_presentation_get_current_page (EV_VIEW_PRESENTATION (window->priv->presentation_view));
3983 ev_document_model_set_page (window->priv->model, current_page);
3985 gtk_container_remove (GTK_CONTAINER (window->priv->main_box),
3986 window->priv->presentation_view);
3987 window->priv->presentation_view = NULL;
3989 gtk_widget_show (window->priv->hpaned);
3990 ev_window_update_presentation_action (window);
3991 update_chrome_visibility (window);
3992 if (unfullscreen_window)
3993 gtk_window_unfullscreen (GTK_WINDOW (window));
3995 gtk_widget_grab_focus (window->priv->view);
3997 ev_application_screensaver_enable (EV_APP);
3999 if (window->priv->metadata && !ev_window_is_empty (window))
4000 ev_metadata_set_boolean (window->priv->metadata, "presentation", FALSE);
4004 ev_window_cmd_view_presentation (GtkAction *action, EvWindow *window)
4006 gboolean presentation;
4008 presentation = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
4010 ev_window_run_presentation (window);
4015 ev_window_setup_gtk_settings (EvWindow *window)
4017 GtkSettings *settings;
4019 gchar *menubar_accel_accel;
4021 screen = gtk_window_get_screen (GTK_WINDOW (window));
4022 settings = gtk_settings_get_for_screen (screen);
4024 g_object_get (settings,
4025 "gtk-menu-bar-accel", &menubar_accel_accel,
4027 if (menubar_accel_accel != NULL && menubar_accel_accel[0] != '\0') {
4028 gtk_accelerator_parse (menubar_accel_accel,
4029 &window->priv->menubar_accel_keyval,
4030 &window->priv->menubar_accel_modifier);
4031 if (window->priv->menubar_accel_keyval == 0) {
4032 g_warning ("Failed to parse menu bar accelerator '%s'\n",
4033 menubar_accel_accel);
4036 window->priv->menubar_accel_keyval = 0;
4037 window->priv->menubar_accel_modifier = 0;
4040 g_free (menubar_accel_accel);
4044 ev_window_update_max_min_scale (EvWindow *window)
4048 gdouble min_width, min_height;
4049 gdouble width, height;
4051 gint rotation = ev_document_model_get_rotation (window->priv->model);
4053 if (!window->priv->document)
4056 dpi = get_screen_dpi (window) / 72.0;
4058 ev_document_get_min_page_size (window->priv->document, &min_width, &min_height);
4059 width = (rotation == 0 || rotation == 180) ? min_width : min_height;
4060 height = (rotation == 0 || rotation == 180) ? min_height : min_width;
4061 max_scale = sqrt (PAGE_CACHE_SIZE / (width * dpi * 4 * height * dpi));
4063 action = gtk_action_group_get_action (window->priv->action_group,
4064 ZOOM_CONTROL_ACTION);
4065 ephy_zoom_action_set_max_zoom_level (EPHY_ZOOM_ACTION (action), max_scale * dpi);
4067 ev_document_model_set_min_scale (window->priv->model, MIN_SCALE * dpi);
4068 ev_document_model_set_max_scale (window->priv->model, max_scale * dpi);
4072 ev_window_screen_changed (GtkWidget *widget,
4073 GdkScreen *old_screen)
4075 EvWindow *window = EV_WINDOW (widget);
4078 screen = gtk_widget_get_screen (widget);
4079 if (screen == old_screen)
4082 ev_window_setup_gtk_settings (window);
4083 ev_window_update_max_min_scale (window);
4085 if (GTK_WIDGET_CLASS (ev_window_parent_class)->screen_changed) {
4086 GTK_WIDGET_CLASS (ev_window_parent_class)->screen_changed (widget, old_screen);
4091 ev_window_state_event (GtkWidget *widget,
4092 GdkEventWindowState *event)
4094 EvWindow *window = EV_WINDOW (widget);
4096 if (GTK_WIDGET_CLASS (ev_window_parent_class)->window_state_event) {
4097 GTK_WIDGET_CLASS (ev_window_parent_class)->window_state_event (widget, event);
4100 if ((event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN) == 0)
4103 if (event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN) {
4104 if (ev_document_model_get_fullscreen (window->priv->model) || EV_WINDOW_IS_PRESENTATION (window))
4107 ev_window_run_fullscreen (window);
4109 if (ev_document_model_get_fullscreen (window->priv->model))
4110 ev_window_stop_fullscreen (window, FALSE);
4111 else if (EV_WINDOW_IS_PRESENTATION (window))
4112 ev_window_stop_presentation (window, FALSE);
4119 ev_window_set_page_mode (EvWindow *window,
4120 EvWindowPageMode page_mode)
4122 GtkWidget *child = NULL;
4123 GtkWidget *real_child;
4125 if (window->priv->page_mode == page_mode)
4128 window->priv->page_mode = page_mode;
4130 switch (page_mode) {
4131 case PAGE_MODE_DOCUMENT:
4132 child = window->priv->view;
4134 case PAGE_MODE_PASSWORD:
4135 child = window->priv->password_view;
4138 g_assert_not_reached ();
4141 real_child = gtk_bin_get_child (GTK_BIN (window->priv->scrolled_window));
4142 if (child != real_child) {
4143 gtk_container_remove (GTK_CONTAINER (window->priv->scrolled_window),
4145 gtk_container_add (GTK_CONTAINER (window->priv->scrolled_window),
4148 ev_window_update_actions (window);
4153 ev_window_cmd_edit_rotate_left (GtkAction *action, EvWindow *ev_window)
4155 gint rotation = ev_document_model_get_rotation (ev_window->priv->model);
4157 ev_document_model_set_rotation (ev_window->priv->model, rotation - 90);
4161 ev_window_cmd_edit_rotate_right (GtkAction *action, EvWindow *ev_window)
4163 gint rotation = ev_document_model_get_rotation (ev_window->priv->model);
4165 ev_document_model_set_rotation (ev_window->priv->model, rotation + 90);
4169 ev_window_cmd_view_inverted_colors (GtkAction *action, EvWindow *ev_window)
4171 gboolean inverted_colors = ev_document_model_get_inverted_colors (ev_window->priv->model);
4173 ev_document_model_set_inverted_colors (ev_window->priv->model, !inverted_colors);
4177 ev_window_cmd_edit_toolbar_cb (GtkDialog *dialog,
4179 EvWindow *ev_window)
4181 EggEditableToolbar *toolbar;
4182 gchar *toolbars_file;
4184 toolbar = EGG_EDITABLE_TOOLBAR (ev_window->priv->toolbar);
4185 egg_editable_toolbar_set_edit_mode (toolbar, FALSE);
4187 toolbars_file = g_build_filename (ev_application_get_dot_dir (EV_APP, TRUE),
4188 "evince_toolbar.xml", NULL);
4189 egg_toolbars_model_save_toolbars (egg_editable_toolbar_get_model (toolbar),
4190 toolbars_file, "1.0");
4191 g_free (toolbars_file);
4193 gtk_widget_destroy (GTK_WIDGET (dialog));
4197 ev_window_cmd_edit_toolbar (GtkAction *action, EvWindow *ev_window)
4201 GtkWidget *content_area;
4202 EggEditableToolbar *toolbar;
4204 dialog = gtk_dialog_new_with_buttons (_("Toolbar Editor"),
4205 GTK_WINDOW (ev_window),
4206 GTK_DIALOG_DESTROY_WITH_PARENT,
4210 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
4211 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE);
4212 gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)), 5);
4213 gtk_box_set_spacing (GTK_BOX (content_area), 2);
4214 gtk_window_set_default_size (GTK_WINDOW (dialog), 500, 400);
4216 toolbar = EGG_EDITABLE_TOOLBAR (ev_window->priv->toolbar);
4217 editor = egg_toolbar_editor_new (ev_window->priv->ui_manager,
4218 egg_editable_toolbar_get_model (toolbar));
4220 gtk_container_set_border_width (GTK_CONTAINER (editor), 5);
4221 gtk_box_set_spacing (GTK_BOX (EGG_TOOLBAR_EDITOR (editor)), 5);
4223 gtk_container_add (GTK_CONTAINER (content_area), editor);
4225 egg_editable_toolbar_set_edit_mode (toolbar, TRUE);
4227 g_signal_connect (dialog, "response",
4228 G_CALLBACK (ev_window_cmd_edit_toolbar_cb),
4230 gtk_widget_show_all (dialog);
4234 ev_window_cmd_edit_save_settings (GtkAction *action, EvWindow *ev_window)
4236 EvWindowPrivate *priv = ev_window->priv;
4237 EvDocumentModel *model = priv->model;
4238 GSettings *settings = priv->default_settings;
4240 g_settings_set_boolean (settings, "continuous",
4241 ev_document_model_get_continuous (model));
4242 g_settings_set_boolean (settings, "dual-page",
4243 ev_document_model_get_dual_page (model));
4244 g_settings_set_boolean (settings, "fullscreen",
4245 ev_document_model_get_fullscreen (model));
4246 g_settings_set_boolean (settings, "inverted-colors",
4247 ev_document_model_get_inverted_colors (model));
4248 g_settings_set_enum (settings, "sizing-mode",
4249 ev_document_model_get_sizing_mode (model));
4250 g_settings_set_boolean (settings, "show-toolbar",
4251 gtk_widget_get_visible (priv->toolbar));
4252 g_settings_set_boolean (settings, "show-sidebar",
4253 gtk_widget_get_visible (priv->sidebar));
4254 g_settings_set_int (settings, "sidebar-size",
4255 gtk_paned_get_position (GTK_PANED (priv->hpaned)));
4256 g_settings_set_string (settings, "sidebar-page",
4257 ev_window_sidebar_get_current_page_id (ev_window));
4258 g_settings_apply (settings);
4262 ev_window_cmd_view_zoom_in (GtkAction *action, EvWindow *ev_window)
4264 g_return_if_fail (EV_IS_WINDOW (ev_window));
4266 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FREE);
4267 ev_view_zoom_in (EV_VIEW (ev_window->priv->view));
4271 ev_window_cmd_view_zoom_out (GtkAction *action, EvWindow *ev_window)
4273 g_return_if_fail (EV_IS_WINDOW (ev_window));
4275 ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FREE);
4276 ev_view_zoom_out (EV_VIEW (ev_window->priv->view));
4280 ev_window_cmd_go_previous_page (GtkAction *action, EvWindow *ev_window)
4282 g_return_if_fail (EV_IS_WINDOW (ev_window));
4284 ev_view_previous_page (EV_VIEW (ev_window->priv->view));
4288 ev_window_cmd_go_next_page (GtkAction *action, EvWindow *ev_window)
4290 g_return_if_fail (EV_IS_WINDOW (ev_window));
4292 ev_view_next_page (EV_VIEW (ev_window->priv->view));
4296 ev_window_cmd_go_first_page (GtkAction *action, EvWindow *ev_window)
4298 g_return_if_fail (EV_IS_WINDOW (ev_window));
4300 ev_document_model_set_page (ev_window->priv->model, 0);
4304 ev_window_cmd_go_last_page (GtkAction *action, EvWindow *ev_window)
4306 g_return_if_fail (EV_IS_WINDOW (ev_window));
4308 ev_document_model_set_page (ev_window->priv->model,
4309 ev_document_get_n_pages (ev_window->priv->document) - 1);
4313 ev_window_cmd_go_forward (GtkAction *action, EvWindow *ev_window)
4315 int n_pages, current_page;
4317 g_return_if_fail (EV_IS_WINDOW (ev_window));
4319 n_pages = ev_document_get_n_pages (ev_window->priv->document);
4320 current_page = ev_document_model_get_page (ev_window->priv->model);
4322 if (current_page + 10 < n_pages) {
4323 ev_document_model_set_page (ev_window->priv->model, current_page + 10);
4328 ev_window_cmd_go_backward (GtkAction *action, EvWindow *ev_window)
4332 g_return_if_fail (EV_IS_WINDOW (ev_window));
4334 current_page = ev_document_model_get_page (ev_window->priv->model);
4336 if (current_page - 10 >= 0) {
4337 ev_document_model_set_page (ev_window->priv->model, current_page - 10);
4342 ev_window_cmd_view_reload (GtkAction *action, EvWindow *ev_window)
4344 ev_window_reload_document (ev_window, NULL);
4348 ev_window_cmd_view_autoscroll (GtkAction *action, EvWindow *ev_window)
4350 ev_view_autoscroll_start (EV_VIEW (ev_window->priv->view));
4353 #if OFFLINE_HELP_ENABLED
4354 #define EV_HELP "ghelp:evince"
4356 #define EV_HELP "http://library.gnome.org/users/evince/stable/"
4360 ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
4362 GError *error = NULL;
4364 gtk_show_uri (gtk_window_get_screen (GTK_WINDOW (ev_window)),
4366 gtk_get_current_event_time (),
4369 ev_window_error_message (ev_window, error,
4370 "%s", _("There was an error displaying help"));
4371 g_error_free (error);
4376 ev_window_cmd_leave_fullscreen (GtkAction *action, EvWindow *window)
4378 ev_window_stop_fullscreen (window, TRUE);
4382 ev_window_cmd_start_presentation (GtkAction *action, EvWindow *window)
4384 ev_window_run_presentation (window);
4388 ev_window_cmd_escape (GtkAction *action, EvWindow *window)
4392 ev_view_autoscroll_stop (EV_VIEW (window->priv->view));
4394 widget = gtk_window_get_focus (GTK_WINDOW (window));
4395 if (widget && gtk_widget_get_ancestor (widget, EGG_TYPE_FIND_BAR)) {
4396 update_chrome_flag (window, EV_CHROME_FINDBAR, FALSE);
4397 update_chrome_visibility (window);
4398 gtk_widget_grab_focus (window->priv->view);
4400 gboolean fullscreen;
4402 fullscreen = ev_document_model_get_fullscreen (window->priv->model);
4405 ev_window_stop_fullscreen (window, TRUE);
4406 } else if (EV_WINDOW_IS_PRESENTATION (window)) {
4407 ev_window_stop_presentation (window, TRUE);
4408 gtk_widget_grab_focus (window->priv->view);
4410 gtk_widget_grab_focus (window->priv->view);
4413 if (fullscreen && EV_WINDOW_IS_PRESENTATION (window))
4414 g_warning ("Both fullscreen and presentation set somehow");
4419 save_sizing_mode (EvWindow *window)
4422 GEnumValue *enum_value;
4424 if (!window->priv->metadata || ev_window_is_empty (window))
4427 mode = ev_document_model_get_sizing_mode (window->priv->model);
4428 enum_value = g_enum_get_value (g_type_class_peek (EV_TYPE_SIZING_MODE), mode);
4429 ev_metadata_set_string (window->priv->metadata, "sizing_mode",
4430 enum_value->value_nick);
4434 ev_window_document_changed_cb (EvDocumentModel *model,
4436 EvWindow *ev_window)
4438 ev_window_set_document (ev_window,
4439 ev_document_model_get_document (model));
4443 ev_window_sizing_mode_changed_cb (EvDocumentModel *model,
4445 EvWindow *ev_window)
4447 EvSizingMode sizing_mode = ev_document_model_get_sizing_mode (model);
4449 g_object_set (ev_window->priv->scrolled_window,
4450 "hscrollbar-policy",
4451 sizing_mode == EV_SIZING_FREE ?
4452 GTK_POLICY_AUTOMATIC : GTK_POLICY_NEVER,
4453 "vscrollbar-policy", GTK_POLICY_AUTOMATIC,
4456 update_sizing_buttons (ev_window);
4457 save_sizing_mode (ev_window);
4461 ev_window_zoom_changed_cb (EvDocumentModel *model, GParamSpec *pspec, EvWindow *ev_window)
4463 ev_window_update_actions (ev_window);
4465 if (!ev_window->priv->metadata)
4468 if (ev_document_model_get_sizing_mode (model) == EV_SIZING_FREE && !ev_window_is_empty (ev_window)) {
4471 zoom = ev_document_model_get_scale (model);
4472 zoom *= 72.0 / get_screen_dpi (ev_window);
4473 ev_metadata_set_double (ev_window->priv->metadata, "zoom", zoom);
4478 ev_window_update_continuous_action (EvWindow *window)
4482 action = gtk_action_group_get_action (window->priv->action_group, "ViewContinuous");
4483 g_signal_handlers_block_by_func
4484 (action, G_CALLBACK (ev_window_cmd_continuous), window);
4485 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
4486 ev_document_model_get_continuous (window->priv->model));
4487 g_signal_handlers_unblock_by_func
4488 (action, G_CALLBACK (ev_window_cmd_continuous), window);
4492 ev_window_update_dual_page_action (EvWindow *window)
4496 action = gtk_action_group_get_action (window->priv->action_group, "ViewDual");
4497 g_signal_handlers_block_by_func
4498 (action, G_CALLBACK (ev_window_cmd_dual), window);
4499 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
4500 ev_document_model_get_dual_page (window->priv->model));
4501 g_signal_handlers_unblock_by_func
4502 (action, G_CALLBACK (ev_window_cmd_dual), window);
4506 ev_window_continuous_changed_cb (EvDocumentModel *model,
4508 EvWindow *ev_window)
4510 ev_window_update_continuous_action (ev_window);
4512 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window))
4513 ev_metadata_set_boolean (ev_window->priv->metadata, "continuous",
4514 ev_document_model_get_continuous (model));
4518 ev_window_rotation_changed_cb (EvDocumentModel *model,
4522 gint rotation = ev_document_model_get_rotation (model);
4524 if (window->priv->metadata && !ev_window_is_empty (window))
4525 ev_metadata_set_int (window->priv->metadata, "rotation",
4528 ev_window_update_max_min_scale (window);
4529 ev_window_refresh_window_thumbnail (window);
4533 ev_window_update_inverted_colors_action (EvWindow *window)
4537 action = gtk_action_group_get_action (window->priv->action_group, "ViewInvertedColors");
4538 g_signal_handlers_block_by_func
4539 (action, G_CALLBACK (ev_window_cmd_view_inverted_colors), window);
4540 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
4541 ev_document_model_get_inverted_colors (window->priv->model));
4542 g_signal_handlers_unblock_by_func
4543 (action, G_CALLBACK (ev_window_cmd_view_inverted_colors), window);
4547 ev_window_inverted_colors_changed_cb (EvDocumentModel *model,
4551 gboolean inverted_colors = ev_document_model_get_inverted_colors (model);
4553 ev_window_update_inverted_colors_action (window);
4555 if (window->priv->metadata && !ev_window_is_empty (window))
4556 ev_metadata_set_boolean (window->priv->metadata, "inverted-colors",
4559 ev_window_refresh_window_thumbnail (window);
4563 ev_window_dual_mode_changed_cb (EvDocumentModel *model,
4565 EvWindow *ev_window)
4567 ev_window_update_dual_page_action (ev_window);
4569 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window))
4570 ev_metadata_set_boolean (ev_window->priv->metadata, "dual-page",
4571 ev_document_model_get_dual_page (model));
4575 build_comments_string (EvDocument *document)
4577 gchar *comments = NULL;
4578 EvDocumentBackendInfo info;
4580 if (document && ev_document_get_backend_info (document, &info)) {
4581 comments = g_strdup_printf (
4582 _("Document Viewer\nUsing %s (%s)"),
4583 info.name, info.version);
4585 comments = g_strdup_printf (
4586 _("Document Viewer"));
4593 ev_window_cmd_help_about (GtkAction *action, EvWindow *ev_window)
4595 const char *authors[] = {
4596 "Martin Kretzschmar <m_kretzschmar@gmx.net>",
4597 "Jonathan Blandford <jrb@gnome.org>",
4598 "Marco Pesenti Gritti <marco@gnome.org>",
4599 "Nickolay V. Shmyrev <nshmyrev@yandex.ru>",
4600 "Bryan Clark <clarkbw@gnome.org>",
4601 "Carlos Garcia Campos <carlosgc@gnome.org>",
4602 "Wouter Bolsterlee <wbolster@gnome.org>",
4603 "Christian Persch <chpe" "\100" "gnome.org>",
4607 const char *documenters[] = {
4608 "Nickolay V. Shmyrev <nshmyrev@yandex.ru>",
4612 const char *license[] = {
4613 N_("Evince is free software; you can redistribute it and/or modify "
4614 "it under the terms of the GNU General Public License as published by "
4615 "the Free Software Foundation; either version 2 of the License, or "
4616 "(at your option) any later version.\n"),
4617 N_("Evince is distributed in the hope that it will be useful, "
4618 "but WITHOUT ANY WARRANTY; without even the implied warranty of "
4619 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
4620 "GNU General Public License for more details.\n"),
4621 N_("You should have received a copy of the GNU General Public License "
4622 "along with Evince; if not, write to the Free Software Foundation, Inc., "
4623 "51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n")
4626 char *license_trans;
4632 for (p = authors; *p; ++p)
4635 for (p = documenters; *p; ++p)
4639 license_trans = g_strconcat (_(license[0]), "\n", _(license[1]), "\n",
4640 _(license[2]), "\n", NULL);
4642 comments = build_comments_string (ev_window->priv->document);
4644 gtk_show_about_dialog (
4645 GTK_WINDOW (ev_window),
4646 "name", _("Evince"),
4649 _("© 1996–2009 The Evince authors"),
4650 "license", license_trans,
4651 "website", "http://www.gnome.org/projects/evince",
4652 "comments", comments,
4654 "documenters", documenters,
4655 "translator-credits", _("translator-credits"),
4656 "logo-icon-name", "evince",
4657 "wrap-license", TRUE,
4661 g_free (license_trans);
4665 ev_window_view_toolbar_cb (GtkAction *action, EvWindow *ev_window)
4669 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
4670 update_chrome_flag (ev_window, EV_CHROME_TOOLBAR, active);
4671 update_chrome_visibility (ev_window);
4672 if (ev_window->priv->metadata)
4673 ev_metadata_set_boolean (ev_window->priv->metadata, "show_toolbar", active);
4677 ev_window_view_sidebar_cb (GtkAction *action, EvWindow *ev_window)
4679 if (EV_WINDOW_IS_PRESENTATION (ev_window))
4682 update_chrome_flag (ev_window, EV_CHROME_SIDEBAR,
4683 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
4684 update_chrome_visibility (ev_window);
4688 ev_window_sidebar_current_page_changed_cb (EvSidebar *ev_sidebar,
4690 EvWindow *ev_window)
4692 if (ev_window->priv->metadata && !ev_window_is_empty (ev_window)) {
4693 ev_metadata_set_string (ev_window->priv->metadata,
4695 ev_window_sidebar_get_current_page_id (ev_window));
4700 ev_window_sidebar_visibility_changed_cb (EvSidebar *ev_sidebar,
4702 EvWindow *ev_window)
4706 action = gtk_action_group_get_action (ev_window->priv->action_group, "ViewSidebar");
4708 if (!EV_WINDOW_IS_PRESENTATION (ev_window)) {
4709 gboolean visible = gtk_widget_get_visible (GTK_WIDGET (ev_sidebar));
4711 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible);
4713 if (ev_window->priv->metadata)
4714 ev_metadata_set_boolean (ev_window->priv->metadata, "sidebar_visibility",
4720 view_menu_link_popup (EvWindow *ev_window,
4723 gboolean show_external = FALSE;
4724 gboolean show_internal = FALSE;
4727 if (ev_window->priv->link)
4728 g_object_unref (ev_window->priv->link);
4731 ev_window->priv->link = g_object_ref (link);
4733 ev_window->priv->link = NULL;
4735 if (ev_window->priv->link) {
4736 EvLinkAction *ev_action;
4738 ev_action = ev_link_get_action (link);
4740 switch (ev_link_action_get_action_type (ev_action)) {
4741 case EV_LINK_ACTION_TYPE_GOTO_DEST:
4742 case EV_LINK_ACTION_TYPE_GOTO_REMOTE:
4743 show_internal = TRUE;
4745 case EV_LINK_ACTION_TYPE_EXTERNAL_URI:
4746 case EV_LINK_ACTION_TYPE_LAUNCH:
4747 show_external = TRUE;
4755 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4757 gtk_action_set_visible (action, show_external);
4759 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4761 gtk_action_set_visible (action, show_external);
4763 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4765 gtk_action_set_visible (action, show_internal);
4767 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4768 "OpenLinkNewWindow");
4769 gtk_action_set_visible (action, show_internal);
4773 view_menu_image_popup (EvWindow *ev_window,
4777 gboolean show_image = FALSE;
4779 if (ev_window->priv->image)
4780 g_object_unref (ev_window->priv->image);
4783 ev_window->priv->image = g_object_ref (image);
4785 ev_window->priv->image = NULL;
4787 show_image = (ev_window->priv->image != NULL);
4789 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4791 gtk_action_set_visible (action, show_image);
4793 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4795 gtk_action_set_visible (action, show_image);
4799 view_menu_annot_popup (EvWindow *ev_window,
4800 EvAnnotation *annot)
4803 gboolean show_annot = FALSE;
4805 if (ev_window->priv->annot)
4806 g_object_unref (ev_window->priv->annot);
4807 ev_window->priv->annot = (annot) ? g_object_ref (annot) : NULL;
4809 action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
4811 gtk_action_set_visible (action, (annot != NULL && EV_IS_ANNOTATION_MARKUP (annot)));
4813 if (annot && EV_IS_ANNOTATION_ATTACHMENT (annot)) {
4814 EvAttachment *attachment;
4816 attachment = ev_annotation_attachment_get_attachment (EV_ANNOTATION_ATTACHMENT (annot));
4819 if (ev_window->priv->attach_list) {
4820 g_list_foreach (ev_window->priv->attach_list,
4821 (GFunc) g_object_unref, NULL);
4822 g_list_free (ev_window->priv->attach_list);
4823 ev_window->priv->attach_list = NULL;
4825 ev_window->priv->attach_list =
4826 g_list_prepend (ev_window->priv->attach_list,
4827 g_object_ref (attachment));
4831 action = gtk_action_group_get_action (ev_window->priv->attachment_popup_action_group,
4833 gtk_action_set_visible (action, show_annot);
4835 action = gtk_action_group_get_action (ev_window->priv->attachment_popup_action_group,
4836 "SaveAttachmentAs");
4837 gtk_action_set_visible (action, show_annot);
4841 view_menu_popup_cb (EvView *view,
4843 EvWindow *ev_window)
4846 gboolean has_link = FALSE;
4847 gboolean has_image = FALSE;
4848 gboolean has_annot = FALSE;
4850 for (l = items; l; l = g_list_next (l)) {
4851 if (EV_IS_LINK (l->data)) {
4852 view_menu_link_popup (ev_window, EV_LINK (l->data));
4854 } else if (EV_IS_IMAGE (l->data)) {
4855 view_menu_image_popup (ev_window, EV_IMAGE (l->data));
4857 } else if (EV_IS_ANNOTATION (l->data)) {
4858 view_menu_annot_popup (ev_window, EV_ANNOTATION (l->data));
4864 view_menu_link_popup (ev_window, NULL);
4866 view_menu_image_popup (ev_window, NULL);
4868 view_menu_annot_popup (ev_window, NULL);
4870 gtk_menu_popup (GTK_MENU (ev_window->priv->view_popup),
4871 NULL, NULL, NULL, NULL,
4872 3, gtk_get_current_event_time ());
4877 attachment_bar_menu_popup_cb (EvSidebarAttachments *attachbar,
4879 EvWindow *ev_window)
4883 g_assert (attach_list != NULL);
4885 if (ev_window->priv->attach_list) {
4886 g_list_foreach (ev_window->priv->attach_list,
4887 (GFunc) g_object_unref, NULL);
4888 g_list_free (ev_window->priv->attach_list);
4891 ev_window->priv->attach_list = attach_list;
4893 popup = ev_window->priv->attachment_popup;
4895 gtk_menu_popup (GTK_MENU (popup), NULL, NULL,
4897 3, gtk_get_current_event_time ());
4903 ev_window_update_find_status_message (EvWindow *ev_window)
4907 if (!ev_window->priv->find_job)
4910 if (ev_job_is_finished (ev_window->priv->find_job)) {
4911 EvJobFind *job_find = EV_JOB_FIND (ev_window->priv->find_job);
4913 if (ev_job_find_has_results (job_find)) {
4916 n_results = ev_job_find_get_n_results (job_find,
4917 ev_document_model_get_page (ev_window->priv->model));
4918 /* TRANS: Sometimes this could be better translated as
4919 "%d hit(s) on this page". Therefore this string
4920 contains plural cases. */
4921 message = g_strdup_printf (ngettext ("%d found on this page",
4922 "%d found on this page",
4926 message = g_strdup (_("Not found"));
4931 percent = ev_job_find_get_progress (EV_JOB_FIND (ev_window->priv->find_job));
4932 message = g_strdup_printf (_("%3d%% remaining to search"),
4933 (gint) ((1.0 - percent) * 100));
4936 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar), message);
4941 ev_window_find_job_finished_cb (EvJobFind *job,
4942 EvWindow *ev_window)
4944 ev_window_update_find_status_message (ev_window);
4948 ev_window_find_job_updated_cb (EvJobFind *job,
4950 EvWindow *ev_window)
4952 ev_window_update_actions (ev_window);
4954 ev_view_find_changed (EV_VIEW (ev_window->priv->view),
4955 ev_job_find_get_results (job),
4957 ev_window_update_find_status_message (ev_window);
4961 ev_window_clear_find_job (EvWindow *ev_window)
4963 if (ev_window->priv->find_job != NULL) {
4964 if (!ev_job_is_finished (ev_window->priv->find_job))
4965 ev_job_cancel (ev_window->priv->find_job);
4967 g_signal_handlers_disconnect_by_func (ev_window->priv->find_job,
4968 ev_window_find_job_finished_cb,
4970 g_signal_handlers_disconnect_by_func (ev_window->priv->find_job,
4971 ev_window_find_job_updated_cb,
4973 g_object_unref (ev_window->priv->find_job);
4974 ev_window->priv->find_job = NULL;
4979 find_bar_previous_cb (EggFindBar *find_bar,
4980 EvWindow *ev_window)
4982 ev_view_find_previous (EV_VIEW (ev_window->priv->view));
4986 find_bar_next_cb (EggFindBar *find_bar,
4987 EvWindow *ev_window)
4989 ev_view_find_next (EV_VIEW (ev_window->priv->view));
4993 find_bar_close_cb (EggFindBar *find_bar,
4994 EvWindow *ev_window)
4996 ev_view_find_cancel (EV_VIEW (ev_window->priv->view));
4997 ev_window_clear_find_job (ev_window);
4998 update_chrome_flag (ev_window, EV_CHROME_FINDBAR, FALSE);
4999 update_chrome_visibility (ev_window);
5003 find_bar_search_changed_cb (EggFindBar *find_bar,
5005 EvWindow *ev_window)
5007 gboolean case_sensitive;
5008 const char *search_string;
5010 if (!ev_window->priv->document || !EV_IS_DOCUMENT_FIND (ev_window->priv->document))
5013 /* Either the string or case sensitivity could have changed. */
5014 case_sensitive = egg_find_bar_get_case_sensitive (find_bar);
5015 search_string = egg_find_bar_get_search_string (find_bar);
5017 ev_view_find_search_changed (EV_VIEW (ev_window->priv->view));
5019 ev_window_clear_find_job (ev_window);
5021 if (search_string && search_string[0]) {
5022 ev_window->priv->find_job = ev_job_find_new (ev_window->priv->document,
5023 ev_document_model_get_page (ev_window->priv->model),
5024 ev_document_get_n_pages (ev_window->priv->document),
5027 g_signal_connect (ev_window->priv->find_job, "finished",
5028 G_CALLBACK (ev_window_find_job_finished_cb),
5030 g_signal_connect (ev_window->priv->find_job, "updated",
5031 G_CALLBACK (ev_window_find_job_updated_cb),
5033 ev_job_scheduler_push_job (ev_window->priv->find_job, EV_JOB_PRIORITY_NONE);
5035 ev_window_update_actions (ev_window);
5036 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar),
5038 gtk_widget_queue_draw (GTK_WIDGET (ev_window->priv->view));
5043 find_bar_visibility_changed_cb (EggFindBar *find_bar,
5045 EvWindow *ev_window)
5049 visible = gtk_widget_get_visible (GTK_WIDGET (find_bar));
5051 if (ev_window->priv->document &&
5052 EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
5053 ev_view_find_set_highlight_search (EV_VIEW (ev_window->priv->view), visible);
5054 ev_view_find_search_changed (EV_VIEW (ev_window->priv->view));
5055 ev_window_update_actions (ev_window);
5058 find_bar_search_changed_cb (find_bar, NULL, ev_window);
5060 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar), NULL);
5065 find_bar_scroll (EggFindBar *find_bar,
5066 GtkScrollType scroll,
5067 EvWindow *ev_window)
5069 ev_view_scroll (EV_VIEW (ev_window->priv->view), scroll, FALSE);
5073 zoom_control_changed_cb (EphyZoomAction *action,
5075 EvWindow *ev_window)
5079 if (zoom == EPHY_ZOOM_BEST_FIT) {
5080 mode = EV_SIZING_BEST_FIT;
5081 } else if (zoom == EPHY_ZOOM_FIT_WIDTH) {
5082 mode = EV_SIZING_FIT_WIDTH;
5084 mode = EV_SIZING_FREE;
5087 ev_document_model_set_sizing_mode (ev_window->priv->model, mode);
5089 if (mode == EV_SIZING_FREE) {
5090 ev_document_model_set_scale (ev_window->priv->model,
5091 zoom * get_screen_dpi (ev_window) / 72.0);
5096 ev_window_drag_data_received (GtkWidget *widget,
5097 GdkDragContext *context,
5100 GtkSelectionData *selection_data,
5105 EvWindow *window = EV_WINDOW (widget);
5108 GSList *uri_list = NULL;
5111 source = gtk_drag_get_source_widget (context);
5112 if (source && widget == gtk_widget_get_toplevel (source)) {
5113 gtk_drag_finish (context, FALSE, FALSE, time);
5117 uris = gtk_selection_data_get_uris (selection_data);
5119 gtk_drag_finish (context, FALSE, FALSE, time);
5123 for (i = 0; uris[i]; i++) {
5124 uri_list = g_slist_prepend (uri_list, (gpointer) uris[i]);
5127 ev_application_open_uri_list (EV_APP, uri_list,
5128 gtk_window_get_screen (GTK_WINDOW (window)),
5130 gtk_drag_finish (context, TRUE, FALSE, time);
5133 g_slist_free (uri_list);
5137 ev_window_finalize (GObject *object)
5139 G_OBJECT_CLASS (ev_window_parent_class)->finalize (object);
5141 if (ev_window_n_copies == 0) {
5142 ev_application_shutdown (EV_APP);
5144 ev_window_n_copies--;
5149 ev_window_dispose (GObject *object)
5151 EvWindow *window = EV_WINDOW (object);
5152 EvWindowPrivate *priv = window->priv;
5153 GObject *mpkeys = ev_application_get_media_keys (EV_APP);
5156 g_signal_handlers_disconnect_by_func (mpkeys,
5157 ev_window_media_player_key_pressed,
5162 if (priv->dbus_object_id > 0) {
5163 ev_window_emit_closed (window);
5164 g_dbus_connection_unregister_object (ev_application_get_dbus_connection (EV_APP),
5165 priv->dbus_object_id);
5166 priv->dbus_object_id = 0;
5169 if (priv->dbus_object_path) {
5170 g_free (priv->dbus_object_path);
5171 priv->dbus_object_path = NULL;
5173 #endif /* ENABLE_DBUS */
5175 if (priv->metadata) {
5176 g_object_unref (priv->metadata);
5177 priv->metadata = NULL;
5180 if (priv->setup_document_idle > 0) {
5181 g_source_remove (priv->setup_document_idle);
5182 priv->setup_document_idle = 0;
5185 if (priv->monitor) {
5186 g_object_unref (priv->monitor);
5187 priv->monitor = NULL;
5191 ev_window_title_free (priv->title);
5195 if (priv->ui_manager) {
5196 g_object_unref (priv->ui_manager);
5197 priv->ui_manager = NULL;
5200 if (priv->action_group) {
5201 g_object_unref (priv->action_group);
5202 priv->action_group = NULL;
5205 if (priv->view_popup_action_group) {
5206 g_object_unref (priv->view_popup_action_group);
5207 priv->view_popup_action_group = NULL;
5210 if (priv->attachment_popup_action_group) {
5211 g_object_unref (priv->attachment_popup_action_group);
5212 priv->attachment_popup_action_group = NULL;
5215 if (priv->recent_action_group) {
5216 g_object_unref (priv->recent_action_group);
5217 priv->recent_action_group = NULL;
5220 if (priv->recent_manager) {
5221 g_signal_handlers_disconnect_by_func (priv->recent_manager,
5222 ev_window_setup_recent,
5224 priv->recent_manager = NULL;
5227 if (priv->settings) {
5228 g_object_unref (priv->settings);
5229 priv->settings = NULL;
5232 if (priv->default_settings) {
5233 g_settings_apply (priv->default_settings);
5234 g_object_unref (priv->default_settings);
5235 priv->default_settings = NULL;
5238 if (priv->lockdown_settings) {
5239 g_object_unref (priv->lockdown_settings);
5240 priv->lockdown_settings = NULL;
5243 priv->recent_ui_id = 0;
5246 g_signal_handlers_disconnect_by_func (priv->model,
5247 ev_window_page_changed_cb,
5249 g_object_unref (priv->model);
5253 if (priv->document) {
5254 g_object_unref (priv->document);
5255 priv->document = NULL;
5259 g_object_unref (priv->view);
5263 if (priv->password_view) {
5264 g_object_unref (priv->password_view);
5265 priv->password_view = NULL;
5268 if (priv->load_job) {
5269 ev_window_clear_load_job (window);
5272 if (priv->reload_job) {
5273 ev_window_clear_reload_job (window);
5276 if (priv->save_job) {
5277 ev_window_clear_save_job (window);
5280 if (priv->thumbnail_job) {
5281 ev_window_clear_thumbnail_job (window);
5284 if (priv->find_job) {
5285 ev_window_clear_find_job (window);
5288 if (priv->local_uri) {
5289 ev_window_clear_local_uri (window);
5290 priv->local_uri = NULL;
5293 ev_window_clear_progress_idle (window);
5294 if (priv->progress_cancellable) {
5295 g_object_unref (priv->progress_cancellable);
5296 priv->progress_cancellable = NULL;
5299 ev_window_close_dialogs (window);
5302 g_object_unref (priv->link);
5307 g_object_unref (priv->image);
5312 g_object_unref (priv->annot);
5316 if (priv->attach_list) {
5317 g_list_foreach (priv->attach_list,
5318 (GFunc) g_object_unref,
5320 g_list_free (priv->attach_list);
5321 priv->attach_list = NULL;
5324 if (priv->find_bar) {
5325 g_signal_handlers_disconnect_by_func
5326 (window->priv->find_bar,
5327 G_CALLBACK (find_bar_close_cb),
5329 priv->find_bar = NULL;
5337 if (priv->search_string) {
5338 g_free (priv->search_string);
5339 priv->search_string = NULL;
5343 g_object_unref (priv->dest);
5347 if (priv->history) {
5348 g_object_unref (priv->history);
5349 priv->history = NULL;
5352 if (priv->print_queue) {
5353 g_queue_free (priv->print_queue);
5354 priv->print_queue = NULL;
5357 G_OBJECT_CLASS (ev_window_parent_class)->dispose (object);
5361 menubar_deactivate_cb (GtkWidget *menubar,
5364 g_signal_handlers_disconnect_by_func (menubar,
5365 G_CALLBACK (menubar_deactivate_cb),
5368 gtk_menu_shell_deselect (GTK_MENU_SHELL (menubar));
5370 update_chrome_visibility (window);
5374 ev_window_key_press_event (GtkWidget *widget,
5377 EvWindow *ev_window = EV_WINDOW (widget);
5378 EvWindowPrivate *priv = ev_window->priv;
5379 gboolean handled = FALSE;
5381 /* Propagate the event to the view first
5382 * It's needed to be able to type in
5383 * annot popups windows
5386 g_object_ref (priv->view);
5387 if (gtk_widget_is_sensitive (priv->view))
5388 handled = gtk_widget_event (priv->view, (GdkEvent*) event);
5389 g_object_unref (priv->view);
5392 if (!handled && !EV_WINDOW_IS_PRESENTATION (ev_window)) {
5393 guint modifier = event->state & gtk_accelerator_get_default_mod_mask ();
5395 if (priv->menubar_accel_keyval != 0 &&
5396 event->keyval == priv->menubar_accel_keyval &&
5397 modifier == priv->menubar_accel_modifier) {
5398 if (!gtk_widget_get_visible (priv->menubar)) {
5399 g_signal_connect (priv->menubar, "deactivate",
5400 G_CALLBACK (menubar_deactivate_cb),
5403 gtk_widget_show (priv->menubar);
5404 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menubar),
5413 handled = GTK_WIDGET_CLASS (ev_window_parent_class)->key_press_event (widget, event);
5419 ev_window_delete_event (GtkWidget *widget,
5422 return !ev_window_close (EV_WINDOW (widget));
5426 ev_window_class_init (EvWindowClass *ev_window_class)
5428 GObjectClass *g_object_class = G_OBJECT_CLASS (ev_window_class);
5429 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (ev_window_class);
5431 g_object_class->dispose = ev_window_dispose;
5432 g_object_class->finalize = ev_window_finalize;
5434 widget_class->delete_event = ev_window_delete_event;
5435 widget_class->key_press_event = ev_window_key_press_event;
5436 widget_class->screen_changed = ev_window_screen_changed;
5437 widget_class->window_state_event = ev_window_state_event;
5438 widget_class->drag_data_received = ev_window_drag_data_received;
5440 g_type_class_add_private (g_object_class, sizeof (EvWindowPrivate));
5444 static const GtkActionEntry entries[] = {
5445 { "File", NULL, N_("_File") },
5446 { "Edit", NULL, N_("_Edit") },
5447 { "View", NULL, N_("_View") },
5448 { "Go", NULL, N_("_Go") },
5449 { "Help", NULL, N_("_Help") },
5452 { "FileOpen", GTK_STOCK_OPEN, N_("_Open…"), "<control>O",
5453 N_("Open an existing document"),
5454 G_CALLBACK (ev_window_cmd_file_open) },
5455 { "FileOpenCopy", NULL, N_("Op_en a Copy"), "<control>N",
5456 N_("Open a copy of the current document in a new window"),
5457 G_CALLBACK (ev_window_cmd_file_open_copy) },
5458 { "FileSaveAs", GTK_STOCK_SAVE_AS, N_("_Save a Copy…"), "<control>S",
5459 N_("Save a copy of the current document"),
5460 G_CALLBACK (ev_window_cmd_save_as) },
5461 { "FileOpenContainingFolder", GTK_STOCK_DIRECTORY, N_("Open Containing _Folder"), NULL,
5462 N_("Show the folder which contains this file in the file manager"),
5463 G_CALLBACK (ev_window_cmd_open_containing_folder) },
5464 { "FilePrint", GTK_STOCK_PRINT, N_("_Print…"), "<control>P",
5465 N_("Print this document"),
5466 G_CALLBACK (ev_window_cmd_file_print) },
5467 { "FileProperties", GTK_STOCK_PROPERTIES, N_("P_roperties"), "<alt>Return", NULL,
5468 G_CALLBACK (ev_window_cmd_file_properties) },
5469 { "FileCloseWindow", GTK_STOCK_CLOSE, NULL, "<control>W", NULL,
5470 G_CALLBACK (ev_window_cmd_file_close_window) },
5473 { "EditCopy", GTK_STOCK_COPY, NULL, "<control>C", NULL,
5474 G_CALLBACK (ev_window_cmd_edit_copy) },
5475 { "EditSelectAll", GTK_STOCK_SELECT_ALL, N_("Select _All"), "<control>A", NULL,
5476 G_CALLBACK (ev_window_cmd_edit_select_all) },
5477 { "EditFind", GTK_STOCK_FIND, N_("_Find…"), "<control>F",
5478 N_("Find a word or phrase in the document"),
5479 G_CALLBACK (ev_window_cmd_edit_find) },
5480 { "EditFindNext", NULL, N_("Find Ne_xt"), "<control>G", NULL,
5481 G_CALLBACK (ev_window_cmd_edit_find_next) },
5482 { "EditFindPrevious", NULL, N_("Find Pre_vious"), "<shift><control>G", NULL,
5483 G_CALLBACK (ev_window_cmd_edit_find_previous) },
5484 { "EditToolbar", NULL, N_("T_oolbar"), NULL, NULL,
5485 G_CALLBACK (ev_window_cmd_edit_toolbar) },
5486 { "EditRotateLeft", EV_STOCK_ROTATE_LEFT, N_("Rotate _Left"), "<control>Left", NULL,
5487 G_CALLBACK (ev_window_cmd_edit_rotate_left) },
5488 { "EditRotateRight", EV_STOCK_ROTATE_RIGHT, N_("Rotate _Right"), "<control>Right", NULL,
5489 G_CALLBACK (ev_window_cmd_edit_rotate_right) },
5490 { "EditSaveSettings", NULL, N_("Save Current Settings as _Default"), "<control>T", NULL,
5491 G_CALLBACK (ev_window_cmd_edit_save_settings) },
5495 { "ViewZoomIn", GTK_STOCK_ZOOM_IN, NULL, "<control>plus",
5496 N_("Enlarge the document"),
5497 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5498 { "ViewZoomOut", GTK_STOCK_ZOOM_OUT, NULL, "<control>minus",
5499 N_("Shrink the document"),
5500 G_CALLBACK (ev_window_cmd_view_zoom_out) },
5501 { "ViewReload", GTK_STOCK_REFRESH, N_("_Reload"), "<control>R",
5502 N_("Reload the document"),
5503 G_CALLBACK (ev_window_cmd_view_reload) },
5505 { "ViewAutoscroll", GTK_STOCK_MEDIA_PLAY, N_("Auto_scroll"), NULL, NULL,
5506 G_CALLBACK (ev_window_cmd_view_autoscroll) },
5509 { "GoPreviousPage", GTK_STOCK_GO_UP, N_("_Previous Page"), "<control>Page_Up",
5510 N_("Go to the previous page"),
5511 G_CALLBACK (ev_window_cmd_go_previous_page) },
5512 { "GoNextPage", GTK_STOCK_GO_DOWN, N_("_Next Page"), "<control>Page_Down",
5513 N_("Go to the next page"),
5514 G_CALLBACK (ev_window_cmd_go_next_page) },
5515 { "GoFirstPage", GTK_STOCK_GOTO_TOP, N_("_First Page"), "<control>Home",
5516 N_("Go to the first page"),
5517 G_CALLBACK (ev_window_cmd_go_first_page) },
5518 { "GoLastPage", GTK_STOCK_GOTO_BOTTOM, N_("_Last Page"), "<control>End",
5519 N_("Go to the last page"),
5520 G_CALLBACK (ev_window_cmd_go_last_page) },
5523 { "HelpContents", GTK_STOCK_HELP, N_("_Contents"), "F1", NULL,
5524 G_CALLBACK (ev_window_cmd_help_contents) },
5526 { "HelpAbout", GTK_STOCK_ABOUT, N_("_About"), NULL, NULL,
5527 G_CALLBACK (ev_window_cmd_help_about) },
5530 { "LeaveFullscreen", GTK_STOCK_LEAVE_FULLSCREEN, N_("Leave Fullscreen"), NULL,
5531 N_("Leave fullscreen mode"),
5532 G_CALLBACK (ev_window_cmd_leave_fullscreen) },
5533 { "StartPresentation", EV_STOCK_RUN_PRESENTATION, N_("Start Presentation"), NULL,
5534 N_("Start a presentation"),
5535 G_CALLBACK (ev_window_cmd_start_presentation) },
5538 { "Escape", NULL, "", "Escape", "",
5539 G_CALLBACK (ev_window_cmd_escape) },
5540 { "Slash", GTK_STOCK_FIND, NULL, "slash", NULL,
5541 G_CALLBACK (ev_window_cmd_edit_find) },
5542 { "F3", NULL, "", "F3", NULL,
5543 G_CALLBACK (ev_window_cmd_edit_find_next) },
5544 { "PageDown", NULL, "", "Page_Down", NULL,
5545 G_CALLBACK (ev_window_cmd_scroll_forward) },
5546 { "PageUp", NULL, "", "Page_Up", NULL,
5547 G_CALLBACK (ev_window_cmd_scroll_backward) },
5548 { "Space", NULL, "", "space", NULL,
5549 G_CALLBACK (ev_window_cmd_scroll_forward) },
5550 { "ShiftSpace", NULL, "", "<shift>space", NULL,
5551 G_CALLBACK (ev_window_cmd_scroll_backward) },
5552 { "BackSpace", NULL, "", "BackSpace", NULL,
5553 G_CALLBACK (ev_window_cmd_scroll_backward) },
5554 { "ShiftBackSpace", NULL, "", "<shift>BackSpace", NULL,
5555 G_CALLBACK (ev_window_cmd_scroll_forward) },
5556 { "Return", NULL, "", "Return", NULL,
5557 G_CALLBACK (ev_window_cmd_scroll_forward) },
5558 { "ShiftReturn", NULL, "", "<shift>Return", NULL,
5559 G_CALLBACK (ev_window_cmd_scroll_backward) },
5560 { "p", GTK_STOCK_GO_UP, "", "p", NULL,
5561 G_CALLBACK (ev_window_cmd_go_previous_page) },
5562 { "n", GTK_STOCK_GO_DOWN, "", "n", NULL,
5563 G_CALLBACK (ev_window_cmd_go_next_page) },
5564 { "Plus", GTK_STOCK_ZOOM_IN, NULL, "plus", NULL,
5565 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5566 { "CtrlEqual", GTK_STOCK_ZOOM_IN, NULL, "<control>equal", NULL,
5567 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5568 { "Equal", GTK_STOCK_ZOOM_IN, NULL, "equal", NULL,
5569 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5570 { "Minus", GTK_STOCK_ZOOM_OUT, NULL, "minus", NULL,
5571 G_CALLBACK (ev_window_cmd_view_zoom_out) },
5572 { "FocusPageSelector", NULL, "", "<control>l", NULL,
5573 G_CALLBACK (ev_window_cmd_focus_page_selector) },
5574 { "GoBackwardFast", NULL, "", "<shift>Page_Up", NULL,
5575 G_CALLBACK (ev_window_cmd_go_backward) },
5576 { "GoForwardFast", NULL, "", "<shift>Page_Down", NULL,
5577 G_CALLBACK (ev_window_cmd_go_forward) },
5578 { "KpPlus", GTK_STOCK_ZOOM_IN, NULL, "KP_Add", NULL,
5579 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5580 { "KpMinus", GTK_STOCK_ZOOM_OUT, NULL, "KP_Subtract", NULL,
5581 G_CALLBACK (ev_window_cmd_view_zoom_out) },
5582 { "CtrlKpPlus", GTK_STOCK_ZOOM_IN, NULL, "<control>KP_Add", NULL,
5583 G_CALLBACK (ev_window_cmd_view_zoom_in) },
5584 { "CtrlKpMinus", GTK_STOCK_ZOOM_OUT, NULL, "<control>KP_Subtract", NULL,
5585 G_CALLBACK (ev_window_cmd_view_zoom_out) },
5586 { "CtrlInsert", GTK_STOCK_COPY, NULL, "<control>Insert", NULL,
5587 G_CALLBACK (ev_window_cmd_edit_copy) },
5591 static const GtkToggleActionEntry toggle_entries[] = {
5593 { "ViewToolbar", NULL, N_("_Toolbar"), NULL,
5594 N_("Show or hide the toolbar"),
5595 G_CALLBACK (ev_window_view_toolbar_cb), TRUE },
5596 { "ViewSidebar", GTK_STOCK_INDEX, N_("Side _Pane"), "F9",
5597 N_("Show or hide the side pane"),
5598 G_CALLBACK (ev_window_view_sidebar_cb), TRUE },
5599 { "ViewContinuous", EV_STOCK_VIEW_CONTINUOUS, N_("_Continuous"), NULL,
5600 N_("Show the entire document"),
5601 G_CALLBACK (ev_window_cmd_continuous), TRUE },
5602 { "ViewDual", EV_STOCK_VIEW_DUAL, N_("_Dual"), NULL,
5603 N_("Show two pages at once"),
5604 G_CALLBACK (ev_window_cmd_dual), FALSE },
5605 { "ViewFullscreen", GTK_STOCK_FULLSCREEN, N_("_Fullscreen"), "F11",
5606 N_("Expand the window to fill the screen"),
5607 G_CALLBACK (ev_window_cmd_view_fullscreen) },
5608 { "ViewPresentation", EV_STOCK_RUN_PRESENTATION, N_("Pre_sentation"), "F5",
5609 N_("Run document as a presentation"),
5610 G_CALLBACK (ev_window_cmd_view_presentation) },
5611 { "ViewBestFit", EV_STOCK_ZOOM_PAGE, N_("_Best Fit"), NULL,
5612 N_("Make the current document fill the window"),
5613 G_CALLBACK (ev_window_cmd_view_best_fit) },
5614 { "ViewPageWidth", EV_STOCK_ZOOM_WIDTH, N_("Fit Page _Width"), NULL,
5615 N_("Make the current document fill the window width"),
5616 G_CALLBACK (ev_window_cmd_view_page_width) },
5617 { "ViewInvertedColors", EV_STOCK_INVERTED_COLORS, N_("_Inverted Colors"), "<control>I",
5618 N_("Show page contents with the colors inverted"),
5619 G_CALLBACK (ev_window_cmd_view_inverted_colors) },
5623 /* Popups specific items */
5624 static const GtkActionEntry view_popup_entries [] = {
5626 { "OpenLink", GTK_STOCK_OPEN, N_("_Open Link"), NULL,
5627 NULL, G_CALLBACK (ev_view_popup_cmd_open_link) },
5628 { "GoLink", GTK_STOCK_GO_FORWARD, N_("_Go To"), NULL,
5629 NULL, G_CALLBACK (ev_view_popup_cmd_open_link) },
5630 { "OpenLinkNewWindow", NULL, N_("Open in New _Window"), NULL,
5631 NULL, G_CALLBACK (ev_view_popup_cmd_open_link_new_window) },
5632 { "CopyLinkAddress", NULL, N_("_Copy Link Address"), NULL,
5633 NULL, G_CALLBACK (ev_view_popup_cmd_copy_link_address) },
5634 { "SaveImageAs", NULL, N_("_Save Image As…"), NULL,
5635 NULL, G_CALLBACK (ev_view_popup_cmd_save_image_as) },
5636 { "CopyImage", NULL, N_("Copy _Image"), NULL,
5637 NULL, G_CALLBACK (ev_view_popup_cmd_copy_image) },
5638 { "AnnotProperties", NULL, N_("Annotation Properties…"), NULL,
5639 NULL, G_CALLBACK (ev_view_popup_cmd_annot_properties) }
5642 static const GtkActionEntry attachment_popup_entries [] = {
5643 { "OpenAttachment", GTK_STOCK_OPEN, N_("_Open Attachment"), NULL,
5644 NULL, G_CALLBACK (ev_attachment_popup_cmd_open_attachment) },
5645 { "SaveAttachmentAs", GTK_STOCK_SAVE_AS, N_("_Save Attachment As…"), NULL,
5646 NULL, G_CALLBACK (ev_attachment_popup_cmd_save_attachment_as) },
5650 sidebar_links_link_activated_cb (EvSidebarLinks *sidebar_links, EvLink *link, EvWindow *window)
5652 ev_view_handle_link (EV_VIEW (window->priv->view), link);
5656 activate_link_cb (EvPageAction *page_action, EvLink *link, EvWindow *window)
5658 ev_view_handle_link (EV_VIEW (window->priv->view), link);
5659 gtk_widget_grab_focus (window->priv->view);
5663 navigation_action_activate_link_cb (EvNavigationAction *action, EvLink *link, EvWindow *window)
5666 ev_view_handle_link (EV_VIEW (window->priv->view), link);
5667 gtk_widget_grab_focus (window->priv->view);
5671 sidebar_layers_visibility_changed (EvSidebarLayers *layers,
5674 ev_view_reload (EV_VIEW (window->priv->view));
5678 sidebar_annots_annot_activated_cb (EvSidebarAnnotations *sidebar_annots,
5679 EvMapping *annot_mapping,
5682 ev_view_focus_annotation (EV_VIEW (window->priv->view), annot_mapping);
5686 sidebar_annots_begin_annot_add (EvSidebarAnnotations *sidebar_annots,
5687 EvAnnotationType annot_type,
5690 ev_view_begin_add_annotation (EV_VIEW (window->priv->view), annot_type);
5694 view_annot_added (EvView *view,
5695 EvAnnotation *annot,
5698 ev_sidebar_annotations_annot_added (EV_SIDEBAR_ANNOTATIONS (window->priv->sidebar_annots),
5703 sidebar_annots_annot_add_cancelled (EvSidebarAnnotations *sidebar_annots,
5706 ev_view_cancel_add_annotation (EV_VIEW (window->priv->view));
5710 register_custom_actions (EvWindow *window, GtkActionGroup *group)
5714 action = g_object_new (EV_TYPE_PAGE_ACTION,
5715 "name", PAGE_SELECTOR_ACTION,
5717 "tooltip", _("Select Page"),
5718 "icon_name", "text-x-generic",
5719 "visible_overflown", FALSE,
5721 ev_page_action_set_model (EV_PAGE_ACTION (action),
5722 window->priv->model);
5723 g_signal_connect (action, "activate_link",
5724 G_CALLBACK (activate_link_cb), window);
5725 gtk_action_group_add_action (group, action);
5726 g_object_unref (action);
5728 action = g_object_new (EPHY_TYPE_ZOOM_ACTION,
5729 "name", ZOOM_CONTROL_ACTION,
5731 "stock_id", EV_STOCK_ZOOM,
5732 "tooltip", _("Adjust the zoom level"),
5735 g_signal_connect (action, "zoom_to_level",
5736 G_CALLBACK (zoom_control_changed_cb), window);
5737 gtk_action_group_add_action (group, action);
5738 g_object_unref (action);
5740 action = g_object_new (EV_TYPE_NAVIGATION_ACTION,
5741 "name", NAVIGATION_ACTION,
5742 "label", _("Navigation"),
5743 "is_important", TRUE,
5744 "short_label", _("Back"),
5745 "stock_id", GTK_STOCK_GO_DOWN,
5746 /*translators: this is the history action*/
5747 "tooltip", _("Move across visited pages"),
5749 g_signal_connect (action, "activate_link",
5750 G_CALLBACK (navigation_action_activate_link_cb), window);
5751 gtk_action_group_add_action (group, action);
5752 g_object_unref (action);
5754 action = g_object_new (EV_TYPE_OPEN_RECENT_ACTION,
5755 "name", "FileOpenRecent",
5756 "label", _("_Open…"),
5757 "tooltip", _("Open an existing document"),
5758 "stock_id", GTK_STOCK_OPEN,
5760 g_signal_connect (action, "activate",
5761 G_CALLBACK (ev_window_cmd_file_open), window);
5762 g_signal_connect (action, "item_activated",
5763 G_CALLBACK (ev_window_open_recent_action_item_activated),
5765 gtk_action_group_add_action (group, action);
5766 g_object_unref (action);
5770 set_action_properties (GtkActionGroup *action_group)
5774 action = gtk_action_group_get_action (action_group, "FileOpenContainingFolder");
5775 /*translators: this is the label for toolbar button*/
5776 g_object_set (action, "short_label", _("Open Folder"), NULL);
5778 action = gtk_action_group_get_action (action_group, "GoPreviousPage");
5779 g_object_set (action, "is-important", TRUE, NULL);
5780 /*translators: this is the label for toolbar button*/
5781 g_object_set (action, "short_label", _("Previous"), NULL);
5783 action = gtk_action_group_get_action (action_group, "GoNextPage");
5784 g_object_set (action, "is-important", TRUE, NULL);
5785 /*translators: this is the label for toolbar button*/
5786 g_object_set (action, "short_label", _("Next"), NULL);
5788 action = gtk_action_group_get_action (action_group, "ViewZoomIn");
5789 /*translators: this is the label for toolbar button*/
5790 g_object_set (action, "short_label", _("Zoom In"), NULL);
5792 action = gtk_action_group_get_action (action_group, "ViewZoomOut");
5793 /*translators: this is the label for toolbar button*/
5794 g_object_set (action, "short_label", _("Zoom Out"), NULL);
5796 action = gtk_action_group_get_action (action_group, "ViewBestFit");
5797 /*translators: this is the label for toolbar button*/
5798 g_object_set (action, "short_label", _("Best Fit"), NULL);
5800 action = gtk_action_group_get_action (action_group, "ViewPageWidth");
5801 /*translators: this is the label for toolbar button*/
5802 g_object_set (action, "short_label", _("Fit Width"), NULL);
5804 action = gtk_action_group_get_action (action_group, "LeaveFullscreen");
5805 g_object_set (action, "is-important", TRUE, NULL);
5809 sidebar_widget_model_set (EvSidebarLinks *ev_sidebar_links,
5811 EvWindow *ev_window)
5813 GtkTreeModel *model;
5816 g_object_get (G_OBJECT (ev_sidebar_links),
5820 action = gtk_action_group_get_action (ev_window->priv->action_group, PAGE_SELECTOR_ACTION);
5821 ev_page_action_set_links_model (EV_PAGE_ACTION (action), model);
5822 g_object_unref (model);
5826 view_actions_focus_in_cb (GtkWidget *widget, GdkEventFocus *event, EvWindow *window)
5831 keys = ev_application_get_media_keys (EV_APP);
5832 ev_media_player_keys_focused (EV_MEDIA_PLAYER_KEYS (keys));
5833 #endif /* ENABLE_DBUS */
5835 update_chrome_flag (window, EV_CHROME_RAISE_TOOLBAR, FALSE);
5836 ev_window_set_action_sensitive (window, "ViewToolbar", TRUE);
5838 ev_window_set_view_accels_sensitivity (window, TRUE);
5840 update_chrome_visibility (window);
5846 view_actions_focus_out_cb (GtkWidget *widget, GdkEventFocus *event, EvWindow *window)
5848 ev_window_set_view_accels_sensitivity (window, FALSE);
5854 sidebar_page_main_widget_update_cb (GObject *ev_sidebar_page,
5856 EvWindow *ev_window)
5860 g_object_get (ev_sidebar_page, "main_widget", &widget, NULL);
5862 if (widget != NULL) {
5863 g_signal_connect_object (widget, "focus_in_event",
5864 G_CALLBACK (view_actions_focus_in_cb),
5866 g_signal_connect_object (widget, "focus_out_event",
5867 G_CALLBACK (view_actions_focus_out_cb),
5869 g_object_unref (widget);
5874 window_state_event_cb (EvWindow *window, GdkEventWindowState *event, gpointer dummy)
5876 if (!(event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN)) {
5879 maximized = event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED;
5880 if (window->priv->metadata && !ev_window_is_empty (window))
5881 ev_metadata_set_boolean (window->priv->metadata, "window_maximized", maximized);
5888 window_configure_event_cb (EvWindow *window, GdkEventConfigure *event, gpointer dummy)
5890 GdkWindowState state;
5891 gdouble document_width, document_height;
5893 if (!window->priv->metadata)
5896 state = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (window)));
5898 if (!(state & GDK_WINDOW_STATE_FULLSCREEN)) {
5899 if (window->priv->document) {
5900 ev_document_get_max_page_size (window->priv->document,
5901 &document_width, &document_height);
5902 g_settings_set (window->priv->default_settings, "window-ratio", "(dd)",
5903 (double)event->width / document_width,
5904 (double)event->height / document_height);
5906 ev_metadata_set_int (window->priv->metadata, "window_x", event->x);
5907 ev_metadata_set_int (window->priv->metadata, "window_y", event->y);
5908 ev_metadata_set_int (window->priv->metadata, "window_width", event->width);
5909 ev_metadata_set_int (window->priv->metadata, "window_height", event->height);
5917 launch_action (EvWindow *window, EvLinkAction *action)
5919 const char *filename = ev_link_action_get_filename (action);
5922 GList file_list = {NULL};
5923 GAppLaunchContext *context;
5924 GError *error = NULL;
5926 if (filename == NULL)
5929 if (g_path_is_absolute (filename)) {
5930 file = g_file_new_for_path (filename);
5935 dir = g_path_get_dirname (window->priv->uri);
5936 base_file = g_file_new_for_uri (dir);
5939 file = g_file_resolve_relative_path (base_file, filename);
5940 g_object_unref (base_file);
5943 app_info = g_file_query_default_handler (file, NULL, &error);
5945 ev_window_error_message (window, error,
5947 _("Unable to launch external application."));
5948 g_object_unref (file);
5949 g_error_free (error);
5954 context = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
5955 gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (context),
5956 gtk_window_get_screen (GTK_WINDOW (window)));
5957 gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (context),
5958 gtk_get_current_event_time ());
5960 file_list.data = file;
5961 if (!g_app_info_launch (app_info, &file_list, context, &error)) {
5962 ev_window_error_message (window, error,
5964 _("Unable to launch external application."));
5965 g_error_free (error);
5968 g_object_unref (app_info);
5969 g_object_unref (file);
5970 /* FIXMEchpe: unref launch context? */
5972 /* According to the PDF spec filename can be an executable. I'm not sure
5973 allowing to launch executables is a good idea though. -- marco */
5977 launch_external_uri (EvWindow *window, EvLinkAction *action)
5979 const gchar *uri = ev_link_action_get_uri (action);
5980 GError *error = NULL;
5982 GAppLaunchContext *context;
5984 context = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
5985 gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (context),
5986 gtk_window_get_screen (GTK_WINDOW (window)));
5987 gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (context),
5988 gtk_get_current_event_time ());
5990 if (!g_strstr_len (uri, strlen (uri), "://") &&
5991 !g_str_has_prefix (uri, "mailto:")) {
5994 /* Not a valid uri, assume http if it starts with www */
5995 if (g_str_has_prefix (uri, "www.")) {
5996 new_uri = g_strdup_printf ("http://%s", uri);
5998 GFile *file, *parent;
6000 file = g_file_new_for_uri (window->priv->uri);
6001 parent = g_file_get_parent (file);
6002 g_object_unref (file);
6004 gchar *parent_uri = g_file_get_uri (parent);
6006 new_uri = g_build_filename (parent_uri, uri, NULL);
6007 g_free (parent_uri);
6008 g_object_unref (parent);
6010 new_uri = g_strdup_printf ("file:///%s", uri);
6013 ret = g_app_info_launch_default_for_uri (new_uri, context, &error);
6016 ret = g_app_info_launch_default_for_uri (uri, context, &error);
6020 ev_window_error_message (window, error,
6021 "%s", _("Unable to open external link"));
6022 g_error_free (error);
6025 /* FIXMEchpe: unref launch context? */
6029 open_remote_link (EvWindow *window, EvLinkAction *action)
6034 dir = g_path_get_dirname (window->priv->uri);
6036 uri = g_build_filename (dir, ev_link_action_get_filename (action),
6040 ev_application_open_uri_at_dest (EV_APP, uri,
6041 gtk_window_get_screen (GTK_WINDOW (window)),
6042 ev_link_action_get_dest (action),
6045 gtk_get_current_event_time ());
6051 do_action_named (EvWindow *window, EvLinkAction *action)
6053 const gchar *name = ev_link_action_get_name (action);
6055 if (g_ascii_strcasecmp (name, "FirstPage") == 0) {
6056 ev_window_cmd_go_first_page (NULL, window);
6057 } else if (g_ascii_strcasecmp (name, "PrevPage") == 0) {
6058 ev_window_cmd_go_previous_page (NULL, window);
6059 } else if (g_ascii_strcasecmp (name, "NextPage") == 0) {
6060 ev_window_cmd_go_next_page (NULL, window);
6061 } else if (g_ascii_strcasecmp (name, "LastPage") == 0) {
6062 ev_window_cmd_go_last_page (NULL, window);
6063 } else if (g_ascii_strcasecmp (name, "GoToPage") == 0) {
6064 ev_window_cmd_focus_page_selector (NULL, window);
6065 } else if (g_ascii_strcasecmp (name, "Find") == 0) {
6066 ev_window_cmd_edit_find (NULL, window);
6067 } else if (g_ascii_strcasecmp (name, "Close") == 0) {
6068 ev_window_cmd_file_close_window (NULL, window);
6069 } else if (g_ascii_strcasecmp (name, "Print") == 0) {
6070 ev_window_cmd_file_print (NULL, window);
6072 g_warning ("Unimplemented named action: %s, please post a "
6073 "bug report in Evince bugzilla "
6074 "(http://bugzilla.gnome.org) with a testcase.",
6080 view_external_link_cb (EvView *view, EvLinkAction *action, EvWindow *window)
6082 switch (ev_link_action_get_action_type (action)) {
6083 case EV_LINK_ACTION_TYPE_GOTO_DEST: {
6086 dest = ev_link_action_get_dest (action);
6090 ev_window_open_copy_at_dest (window, dest);
6093 case EV_LINK_ACTION_TYPE_EXTERNAL_URI:
6094 launch_external_uri (window, action);
6096 case EV_LINK_ACTION_TYPE_LAUNCH:
6097 launch_action (window, action);
6099 case EV_LINK_ACTION_TYPE_GOTO_REMOTE:
6100 open_remote_link (window, action);
6102 case EV_LINK_ACTION_TYPE_NAMED:
6103 do_action_named (window, action);
6106 g_assert_not_reached ();
6111 ev_view_popup_cmd_open_link (GtkAction *action, EvWindow *window)
6113 ev_view_handle_link (EV_VIEW (window->priv->view), window->priv->link);
6117 ev_view_popup_cmd_open_link_new_window (GtkAction *action, EvWindow *window)
6119 EvLinkAction *ev_action = NULL;
6122 ev_action = ev_link_get_action (window->priv->link);
6126 dest = ev_link_action_get_dest (ev_action);
6130 ev_window_open_copy_at_dest (window, dest);
6134 ev_view_popup_cmd_copy_link_address (GtkAction *action, EvWindow *window)
6136 EvLinkAction *ev_action;
6138 ev_action = ev_link_get_action (window->priv->link);
6142 ev_view_copy_link_address (EV_VIEW (window->priv->view),
6148 image_save_dialog_response_cb (GtkWidget *fc,
6150 EvWindow *ev_window)
6154 GError *error = NULL;
6160 GdkPixbufFormat *format;
6161 GtkFileFilter *filter;
6163 if (response_id != GTK_RESPONSE_OK) {
6164 gtk_widget_destroy (fc);
6168 uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
6169 filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (fc));
6170 format = g_object_get_data (G_OBJECT (filter), "pixbuf-format");
6172 if (format == NULL) {
6173 format = get_gdk_pixbuf_format_by_extension (uri);
6176 if (format == NULL && g_strrstr (uri, ".") == NULL) {
6177 /* no extension found and no extension provided within uri */
6178 format = get_gdk_pixbuf_format_by_extension (".png");
6179 if (format == NULL) {
6180 /* no .png support, try .jpeg */
6181 format = get_gdk_pixbuf_format_by_extension (".jpeg");
6185 if (format == NULL) {
6186 ev_window_error_message (ev_window, NULL,
6188 _("Couldn't find appropriate format to save image"));
6190 gtk_widget_destroy (fc);
6195 extensions = gdk_pixbuf_format_get_extensions (format);
6196 if (!g_str_has_suffix (uri, extensions[0])) {
6197 gchar *uri_extension;
6199 uri_extension = g_strconcat (uri, ".", extensions[0], NULL);
6200 target_file = g_file_new_for_uri (uri_extension);
6201 g_free (uri_extension);
6203 target_file = g_file_new_for_uri (uri);
6205 g_strfreev (extensions);
6208 is_native = g_file_is_native (target_file);
6210 filename = g_file_get_path (target_file);
6212 /* Create a temporary local file to save to */
6213 if (ev_mkstemp ("saveimage.XXXXXX", &filename, &error) == -1)
6217 ev_document_doc_mutex_lock ();
6218 pixbuf = ev_document_images_get_image (EV_DOCUMENT_IMAGES (ev_window->priv->document),
6219 ev_window->priv->image);
6220 ev_document_doc_mutex_unlock ();
6222 file_format = gdk_pixbuf_format_get_name (format);
6223 gdk_pixbuf_save (pixbuf, filename, file_format, &error, NULL);
6224 g_free (file_format);
6225 g_object_unref (pixbuf);
6229 ev_window_error_message (ev_window, error,
6230 "%s", _("The image could not be saved."));
6231 g_error_free (error);
6233 g_object_unref (target_file);
6234 gtk_widget_destroy (fc);
6242 source_file = g_file_new_for_path (filename);
6244 ev_window_save_remote (ev_window, EV_SAVE_IMAGE,
6245 source_file, target_file);
6246 g_object_unref (source_file);
6250 g_object_unref (target_file);
6251 gtk_widget_destroy (fc);
6255 ev_view_popup_cmd_save_image_as (GtkAction *action, EvWindow *window)
6259 if (!window->priv->image)
6262 fc = gtk_file_chooser_dialog_new (_("Save Image"),
6263 GTK_WINDOW (window),
6264 GTK_FILE_CHOOSER_ACTION_SAVE,
6266 GTK_RESPONSE_CANCEL,
6267 GTK_STOCK_SAVE, GTK_RESPONSE_OK,
6270 gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
6271 gtk_dialog_set_alternative_button_order (GTK_DIALOG (fc),
6273 GTK_RESPONSE_CANCEL,
6276 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (fc), FALSE);
6277 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
6279 file_chooser_dialog_add_writable_pixbuf_formats (GTK_FILE_CHOOSER (fc));
6281 g_signal_connect (fc, "response",
6282 G_CALLBACK (image_save_dialog_response_cb),
6285 gtk_widget_show (fc);
6289 ev_view_popup_cmd_copy_image (GtkAction *action, EvWindow *window)
6291 GtkClipboard *clipboard;
6294 if (!window->priv->image)
6297 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (window),
6298 GDK_SELECTION_CLIPBOARD);
6299 ev_document_doc_mutex_lock ();
6300 pixbuf = ev_document_images_get_image (EV_DOCUMENT_IMAGES (window->priv->document),
6301 window->priv->image);
6302 ev_document_doc_mutex_unlock ();
6304 gtk_clipboard_set_image (clipboard, pixbuf);
6305 g_object_unref (pixbuf);
6309 ev_view_popup_cmd_annot_properties (GtkAction *action,
6312 const gchar *author;
6315 gboolean popup_is_open;
6316 EvAnnotationPropertiesDialog *dialog;
6317 EvAnnotation *annot = window->priv->annot;
6318 EvAnnotationsSaveMask mask = EV_ANNOTATIONS_SAVE_NONE;
6323 dialog = EV_ANNOTATION_PROPERTIES_DIALOG (ev_annotation_properties_dialog_new_with_annotation (window->priv->annot));
6324 if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_APPLY) {
6325 gtk_widget_destroy (GTK_WIDGET (dialog));
6330 /* Set annotations changes */
6331 author = ev_annotation_properties_dialog_get_author (dialog);
6332 if (ev_annotation_markup_set_label (EV_ANNOTATION_MARKUP (annot), author))
6333 mask |= EV_ANNOTATIONS_SAVE_LABEL;
6335 ev_annotation_properties_dialog_get_color (dialog, &color);
6336 if (ev_annotation_set_color (annot, &color))
6337 mask |= EV_ANNOTATIONS_SAVE_COLOR;
6339 opacity = ev_annotation_properties_dialog_get_opacity (dialog);
6340 if (ev_annotation_markup_set_opacity (EV_ANNOTATION_MARKUP (annot), opacity))
6341 mask |= EV_ANNOTATIONS_SAVE_OPACITY;
6343 popup_is_open = ev_annotation_properties_dialog_get_popup_is_open (dialog);
6344 if (ev_annotation_markup_set_popup_is_open (EV_ANNOTATION_MARKUP (annot), popup_is_open))
6345 mask |= EV_ANNOTATIONS_SAVE_POPUP_IS_OPEN;
6347 if (EV_IS_ANNOTATION_TEXT (annot)) {
6348 EvAnnotationTextIcon icon;
6350 icon = ev_annotation_properties_dialog_get_text_icon (dialog);
6351 if (ev_annotation_text_set_icon (EV_ANNOTATION_TEXT (annot), icon))
6352 mask |= EV_ANNOTATIONS_SAVE_TEXT_ICON;
6355 if (mask != EV_ANNOTATIONS_SAVE_NONE) {
6356 ev_document_doc_mutex_lock ();
6357 ev_document_annotations_save_annotation (EV_DOCUMENT_ANNOTATIONS (window->priv->document),
6358 window->priv->annot,
6360 ev_document_doc_mutex_unlock ();
6362 /* FIXME: update annot region only */
6363 ev_view_reload (EV_VIEW (window->priv->view));
6366 gtk_widget_destroy (GTK_WIDGET (dialog));
6370 ev_attachment_popup_cmd_open_attachment (GtkAction *action, EvWindow *window)
6375 if (!window->priv->attach_list)
6378 screen = gtk_window_get_screen (GTK_WINDOW (window));
6380 for (l = window->priv->attach_list; l && l->data; l = g_list_next (l)) {
6381 EvAttachment *attachment;
6382 GError *error = NULL;
6384 attachment = (EvAttachment *) l->data;
6386 ev_attachment_open (attachment, screen, gtk_get_current_event_time (), &error);
6389 ev_window_error_message (window, error,
6390 "%s", _("Unable to open attachment"));
6391 g_error_free (error);
6397 attachment_save_dialog_response_cb (GtkWidget *fc,
6399 EvWindow *ev_window)
6404 GtkFileChooserAction fc_action;
6408 if (response_id != GTK_RESPONSE_OK) {
6409 gtk_widget_destroy (fc);
6413 uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
6414 target_file = g_file_new_for_uri (uri);
6415 g_object_get (G_OBJECT (fc), "action", &fc_action, NULL);
6416 is_dir = (fc_action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
6417 is_native = g_file_is_native (target_file);
6419 for (l = ev_window->priv->attach_list; l && l->data; l = g_list_next (l)) {
6420 EvAttachment *attachment;
6421 GFile *save_to = NULL;
6422 GError *error = NULL;
6424 attachment = (EvAttachment *) l->data;
6428 save_to = g_file_get_child (target_file,
6429 /* FIXMEchpe: file name encoding! */
6430 ev_attachment_get_name (attachment));
6432 save_to = g_object_ref (target_file);
6435 save_to = ev_mkstemp_file ("saveattachment.XXXXXX", &error);
6439 ev_attachment_save (attachment, save_to, &error);
6442 ev_window_error_message (ev_window, error,
6443 "%s", _("The attachment could not be saved."));
6444 g_error_free (error);
6445 g_object_unref (save_to);
6454 dest_file = g_file_get_child (target_file,
6455 ev_attachment_get_name (attachment));
6457 dest_file = g_object_ref (target_file);
6460 ev_window_save_remote (ev_window, EV_SAVE_ATTACHMENT,
6461 save_to, dest_file);
6463 g_object_unref (dest_file);
6466 g_object_unref (save_to);
6470 g_object_unref (target_file);
6472 gtk_widget_destroy (fc);
6476 ev_attachment_popup_cmd_save_attachment_as (GtkAction *action, EvWindow *window)
6479 EvAttachment *attachment = NULL;
6481 if (!window->priv->attach_list)
6484 if (g_list_length (window->priv->attach_list) == 1)
6485 attachment = (EvAttachment *) window->priv->attach_list->data;
6487 fc = gtk_file_chooser_dialog_new (
6488 _("Save Attachment"),
6489 GTK_WINDOW (window),
6490 attachment ? GTK_FILE_CHOOSER_ACTION_SAVE : GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
6492 GTK_RESPONSE_CANCEL,
6493 GTK_STOCK_SAVE, GTK_RESPONSE_OK,
6496 gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
6497 gtk_dialog_set_alternative_button_order (GTK_DIALOG (fc),
6499 GTK_RESPONSE_CANCEL,
6502 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
6503 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (fc), FALSE);
6506 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc),
6507 ev_attachment_get_name (attachment));
6509 g_signal_connect (fc, "response",
6510 G_CALLBACK (attachment_save_dialog_response_cb),
6513 gtk_widget_show (fc);
6517 ev_window_media_player_key_pressed (EvWindow *window,
6521 if (!gtk_window_is_active (GTK_WINDOW (window)))
6524 /* Note how Previous/Next only go to the
6525 * next/previous page despite their icon telling you
6526 * they should go to the beginning/end.
6528 * There's very few keyboards with FFW/RWD though,
6529 * so we stick the most useful keybinding on the most
6532 if (strcmp (key, "Play") == 0) {
6533 ev_window_run_presentation (window);
6534 } else if (strcmp (key, "Previous") == 0) {
6535 ev_window_cmd_go_previous_page (NULL, window);
6536 } else if (strcmp (key, "Next") == 0) {
6537 ev_window_cmd_go_next_page (NULL, window);
6538 } else if (strcmp (key, "FastForward") == 0) {
6539 ev_window_cmd_go_last_page (NULL, window);
6540 } else if (strcmp (key, "Rewind") == 0) {
6541 ev_window_cmd_go_first_page (NULL, window);
6545 static EggToolbarsModel *
6546 get_toolbars_model (void)
6548 EggToolbarsModel *toolbars_model;
6549 gchar *toolbars_file;
6550 gchar *toolbars_path;
6553 toolbars_model = egg_toolbars_model_new ();
6555 toolbars_file = g_build_filename (ev_application_get_dot_dir (EV_APP, FALSE),
6556 "evince_toolbar.xml", NULL);
6557 toolbars_path = g_build_filename (ev_application_get_data_dir (EV_APP),
6558 "evince-toolbar.xml", NULL);
6559 egg_toolbars_model_load_names (toolbars_model, toolbars_path);
6561 if (!egg_toolbars_model_load_toolbars (toolbars_model, toolbars_file)) {
6562 egg_toolbars_model_load_toolbars (toolbars_model, toolbars_path);
6563 goto skip_conversion;
6566 /* Open item doesn't exist anymore,
6567 * convert it to OpenRecent for compatibility
6569 for (i = 0; i < egg_toolbars_model_n_items (toolbars_model, 0); i++) {
6572 item = egg_toolbars_model_item_nth (toolbars_model, 0, i);
6573 if (g_ascii_strcasecmp (item, "FileOpen") == 0) {
6574 egg_toolbars_model_remove_item (toolbars_model, 0, i);
6575 egg_toolbars_model_add_item (toolbars_model, 0, i,
6577 egg_toolbars_model_save_toolbars (toolbars_model, toolbars_file, "1.0");
6583 g_free (toolbars_file);
6584 g_free (toolbars_path);
6586 egg_toolbars_model_set_flags (toolbars_model, 0, EGG_TB_MODEL_NOT_REMOVABLE);
6588 return toolbars_model;
6593 ev_window_sync_source (EvWindow *window,
6596 GDBusConnection *connection;
6597 GError *error = NULL;
6599 if (window->priv->dbus_object_id <= 0)
6602 connection = ev_application_get_dbus_connection (EV_APP);
6606 g_dbus_connection_emit_signal (connection,
6608 window->priv->dbus_object_path,
6609 EV_WINDOW_DBUS_INTERFACE,
6611 g_variant_new ("(s(ii))",
6617 g_printerr ("Failed to emit DBus signal SyncSource: %s\n",
6619 g_error_free (error);
6624 ev_window_emit_closed (EvWindow *window)
6626 GDBusConnection *connection;
6627 GError *error = NULL;
6629 if (window->priv->dbus_object_id <= 0)
6632 connection = ev_application_get_dbus_connection (EV_APP);
6636 g_dbus_connection_emit_signal (connection,
6638 window->priv->dbus_object_path,
6639 EV_WINDOW_DBUS_INTERFACE,
6644 g_printerr ("Failed to emit DBus signal Closed: %s\n",
6646 g_error_free (error);
6651 /* If this is the last window call g_dbus_connection_flush_sync()
6652 * to make sure the signal is emitted.
6654 if (ev_application_get_n_windows (EV_APP) == 1)
6655 g_dbus_connection_flush_sync (connection, NULL, NULL);
6659 ev_window_emit_doc_loaded (EvWindow *window)
6661 GDBusConnection *connection;
6662 GError *error = NULL;
6664 if (window->priv->dbus_object_id <= 0)
6667 connection = ev_application_get_dbus_connection (EV_APP);
6671 g_dbus_connection_emit_signal (connection,
6673 window->priv->dbus_object_path,
6674 EV_WINDOW_DBUS_INTERFACE,
6676 g_variant_new("(s)", window->priv->uri),
6679 g_printerr ("Failed to emit DBus signal DocumentLoaded: %s\n",
6681 g_error_free (error);
6688 method_call_cb (GDBusConnection *connection,
6689 const gchar *sender,
6690 const gchar *object_path,
6691 const gchar *interface_name,
6692 const gchar *method_name,
6693 GVariant *parameters,
6694 GDBusMethodInvocation *invocation,
6697 EvWindow *window = EV_WINDOW (user_data);
6699 if (g_strcmp0 (method_name, "SyncView") != 0)
6702 if (window->priv->document && ev_document_has_synctex (window->priv->document)) {
6706 g_variant_get (parameters, "(&s(ii)u)", &link.filename, &link.line, &link.col, ×tamp);
6707 ev_view_highlight_forward_search (EV_VIEW (window->priv->view), &link);
6708 gtk_window_present_with_time (GTK_WINDOW (window), timestamp);
6711 g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
6714 static const char introspection_xml[] =
6716 "<interface name='org.gnome.evince.Window'>"
6717 "<method name='SyncView'>"
6718 "<arg type='s' name='source_file' direction='in'/>"
6719 "<arg type='(ii)' name='source_point' direction='in'/>"
6720 "<arg type='u' name='timestamp' direction='in'/>"
6722 "<signal name='SyncSource'>"
6723 "<arg type='s' name='source_file' direction='out'/>"
6724 "<arg type='(ii)' name='source_point' direction='out'/>"
6726 "<signal name='Closed'/>"
6727 "<signal name='DocumentLoaded'>"
6728 "<arg type='s' name='uri' direction='out'/>"
6733 static const GDBusInterfaceVTable interface_vtable = {
6739 static GDBusNodeInfo *introspection_data;
6740 #endif /* ENABLE_DBUS */
6743 ev_window_init (EvWindow *ev_window)
6745 GtkActionGroup *action_group;
6746 GtkAccelGroup *accel_group;
6747 GError *error = NULL;
6748 GtkWidget *sidebar_widget;
6749 GtkWidget *menuitem;
6750 EggToolbarsModel *toolbars_model;
6754 GDBusConnection *connection;
6755 static gint window_id = 0;
6758 g_signal_connect (ev_window, "configure_event",
6759 G_CALLBACK (window_configure_event_cb), NULL);
6760 g_signal_connect (ev_window, "window_state_event",
6761 G_CALLBACK (window_state_event_cb), NULL);
6763 ev_window->priv = EV_WINDOW_GET_PRIVATE (ev_window);
6766 connection = ev_application_get_dbus_connection (EV_APP);
6768 if (!introspection_data) {
6769 introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, &error);
6770 if (error) g_warning ("%s\n", error->message);
6772 g_assert (introspection_data != NULL);
6774 ev_window->priv->dbus_object_path = g_strdup_printf (EV_WINDOW_DBUS_OBJECT_PATH, window_id++);
6775 ev_window->priv->dbus_object_id =
6776 g_dbus_connection_register_object (connection,
6777 ev_window->priv->dbus_object_path,
6778 introspection_data->interfaces[0],
6782 if (ev_window->priv->dbus_object_id == 0) {
6783 g_printerr ("Failed to register bus object %s: %s\n",
6784 ev_window->priv->dbus_object_path, error->message);
6785 g_error_free (error);
6786 g_free (ev_window->priv->dbus_object_path);
6787 ev_window->priv->dbus_object_path = NULL;
6792 #endif /* ENABLE_DBUS */
6794 ev_window->priv->model = ev_document_model_new ();
6796 ev_window->priv->page_mode = PAGE_MODE_DOCUMENT;
6797 ev_window->priv->title = ev_window_title_new (ev_window);
6799 ev_window->priv->main_box = gtk_vbox_new (FALSE, 0);
6800 gtk_container_add (GTK_CONTAINER (ev_window), ev_window->priv->main_box);
6801 gtk_widget_show (ev_window->priv->main_box);
6803 action_group = gtk_action_group_new ("MenuActions");
6804 ev_window->priv->action_group = action_group;
6805 gtk_action_group_set_translation_domain (action_group, NULL);
6806 gtk_action_group_add_actions (action_group, entries,
6807 G_N_ELEMENTS (entries), ev_window);
6808 gtk_action_group_add_toggle_actions (action_group, toggle_entries,
6809 G_N_ELEMENTS (toggle_entries),
6811 set_action_properties (action_group);
6812 register_custom_actions (ev_window, action_group);
6814 ev_window->priv->ui_manager = gtk_ui_manager_new ();
6815 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
6819 gtk_ui_manager_get_accel_group (ev_window->priv->ui_manager);
6820 gtk_window_add_accel_group (GTK_WINDOW (ev_window), accel_group);
6822 ev_window_set_view_accels_sensitivity (ev_window, FALSE);
6824 action_group = gtk_action_group_new ("ViewPopupActions");
6825 ev_window->priv->view_popup_action_group = action_group;
6826 gtk_action_group_set_translation_domain (action_group, NULL);
6827 gtk_action_group_add_actions (action_group, view_popup_entries,
6828 G_N_ELEMENTS (view_popup_entries),
6830 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
6833 action_group = gtk_action_group_new ("AttachmentPopupActions");
6834 ev_window->priv->attachment_popup_action_group = action_group;
6835 gtk_action_group_set_translation_domain (action_group, NULL);
6836 gtk_action_group_add_actions (action_group, attachment_popup_entries,
6837 G_N_ELEMENTS (attachment_popup_entries),
6839 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
6842 ui_path = g_build_filename (ev_application_get_data_dir (EV_APP),
6843 "evince-ui.xml", NULL);
6844 if (!gtk_ui_manager_add_ui_from_file (
6845 ev_window->priv->ui_manager, ui_path, &error))
6847 g_warning ("building menus failed: %s", error->message);
6848 g_error_free (error);
6852 ev_window->priv->recent_manager = gtk_recent_manager_get_default ();
6853 ev_window->priv->recent_action_group = NULL;
6854 ev_window->priv->recent_ui_id = 0;
6855 g_signal_connect_swapped (ev_window->priv->recent_manager,
6857 G_CALLBACK (ev_window_setup_recent),
6860 ev_window->priv->menubar =
6861 gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
6863 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box),
6864 ev_window->priv->menubar,
6866 menuitem = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
6867 "/MainMenu/EditMenu/EditRotateLeftMenu");
6868 gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menuitem), TRUE);
6869 menuitem = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
6870 "/MainMenu/EditMenu/EditRotateRightMenu");
6871 gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menuitem), TRUE);
6873 toolbars_model = get_toolbars_model ();
6874 ev_window->priv->toolbar = GTK_WIDGET
6875 (g_object_new (EGG_TYPE_EDITABLE_TOOLBAR,
6876 "ui-manager", ev_window->priv->ui_manager,
6877 "popup-path", "/ToolbarPopup",
6878 "model", toolbars_model,
6880 g_object_unref (toolbars_model);
6882 egg_editable_toolbar_show (EGG_EDITABLE_TOOLBAR (ev_window->priv->toolbar),
6884 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box),
6885 ev_window->priv->toolbar,
6887 gtk_widget_show (ev_window->priv->toolbar);
6889 /* Add the main area */
6890 ev_window->priv->hpaned = gtk_hpaned_new ();
6891 g_signal_connect (ev_window->priv->hpaned,
6893 G_CALLBACK (ev_window_sidebar_position_change_cb),
6896 gtk_paned_set_position (GTK_PANED (ev_window->priv->hpaned), SIDEBAR_DEFAULT_SIZE);
6897 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), ev_window->priv->hpaned,
6899 gtk_widget_show (ev_window->priv->hpaned);
6901 ev_window->priv->sidebar = ev_sidebar_new ();
6902 ev_sidebar_set_model (EV_SIDEBAR (ev_window->priv->sidebar),
6903 ev_window->priv->model);
6904 gtk_paned_pack1 (GTK_PANED (ev_window->priv->hpaned),
6905 ev_window->priv->sidebar, FALSE, FALSE);
6906 gtk_widget_show (ev_window->priv->sidebar);
6908 /* Stub sidebar, for now */
6910 sidebar_widget = ev_sidebar_thumbnails_new ();
6911 ev_window->priv->sidebar_thumbs = sidebar_widget;
6912 g_signal_connect (sidebar_widget,
6913 "notify::main-widget",
6914 G_CALLBACK (sidebar_page_main_widget_update_cb),
6916 sidebar_page_main_widget_update_cb (G_OBJECT (sidebar_widget), NULL, ev_window);
6917 gtk_widget_show (sidebar_widget);
6918 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
6921 sidebar_widget = ev_sidebar_links_new ();
6922 ev_window->priv->sidebar_links = sidebar_widget;
6923 g_signal_connect (sidebar_widget,
6925 G_CALLBACK (sidebar_widget_model_set),
6927 g_signal_connect (sidebar_widget,
6929 G_CALLBACK (sidebar_links_link_activated_cb),
6931 sidebar_page_main_widget_update_cb (G_OBJECT (sidebar_widget), NULL, ev_window);
6932 gtk_widget_show (sidebar_widget);
6933 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
6936 sidebar_widget = ev_sidebar_attachments_new ();
6937 ev_window->priv->sidebar_attachments = sidebar_widget;
6938 g_signal_connect_object (sidebar_widget,
6940 G_CALLBACK (attachment_bar_menu_popup_cb),
6942 gtk_widget_show (sidebar_widget);
6943 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
6946 sidebar_widget = ev_sidebar_layers_new ();
6947 ev_window->priv->sidebar_layers = sidebar_widget;
6948 g_signal_connect (sidebar_widget,
6949 "layers_visibility_changed",
6950 G_CALLBACK (sidebar_layers_visibility_changed),
6952 gtk_widget_show (sidebar_widget);
6953 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
6956 sidebar_widget = ev_sidebar_annotations_new ();
6957 ev_window->priv->sidebar_annots = sidebar_widget;
6958 g_signal_connect (sidebar_widget,
6960 G_CALLBACK (sidebar_annots_annot_activated_cb),
6962 g_signal_connect (sidebar_widget,
6964 G_CALLBACK (sidebar_annots_begin_annot_add),
6966 g_signal_connect (sidebar_widget,
6967 "annot_add_cancelled",
6968 G_CALLBACK (sidebar_annots_annot_add_cancelled),
6970 gtk_widget_show (sidebar_widget);
6971 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
6974 ev_window->priv->view_box = gtk_vbox_new (FALSE, 0);
6975 ev_window->priv->scrolled_window =
6976 GTK_WIDGET (g_object_new (GTK_TYPE_SCROLLED_WINDOW,
6977 "shadow-type", GTK_SHADOW_IN,
6979 gtk_box_pack_start (GTK_BOX (ev_window->priv->view_box),
6980 ev_window->priv->scrolled_window,
6982 gtk_widget_show (ev_window->priv->scrolled_window);
6984 gtk_paned_add2 (GTK_PANED (ev_window->priv->hpaned),
6985 ev_window->priv->view_box);
6986 gtk_widget_show (ev_window->priv->view_box);
6988 ev_window->priv->view = ev_view_new ();
6989 ev_view_set_page_cache_size (EV_VIEW (ev_window->priv->view), PAGE_CACHE_SIZE);
6990 ev_view_set_model (EV_VIEW (ev_window->priv->view), ev_window->priv->model);
6992 ev_window->priv->password_view = ev_password_view_new (GTK_WINDOW (ev_window));
6993 g_signal_connect_swapped (ev_window->priv->password_view,
6995 G_CALLBACK (ev_window_password_view_unlock),
6997 g_signal_connect_object (ev_window->priv->view, "focus_in_event",
6998 G_CALLBACK (view_actions_focus_in_cb),
7000 g_signal_connect_object (ev_window->priv->view, "focus_out_event",
7001 G_CALLBACK (view_actions_focus_out_cb),
7003 g_signal_connect_object (ev_window->priv->view, "external-link",
7004 G_CALLBACK (view_external_link_cb),
7006 g_signal_connect_object (ev_window->priv->view, "handle-link",
7007 G_CALLBACK (view_handle_link_cb),
7009 g_signal_connect_object (ev_window->priv->view, "popup",
7010 G_CALLBACK (view_menu_popup_cb),
7012 g_signal_connect_object (ev_window->priv->view, "selection-changed",
7013 G_CALLBACK (view_selection_changed_cb),
7015 g_signal_connect_object (ev_window->priv->view, "annot-added",
7016 G_CALLBACK (view_annot_added),
7018 g_signal_connect_object (ev_window->priv->view, "layers-changed",
7019 G_CALLBACK (view_layers_changed_cb),
7022 g_signal_connect_swapped (ev_window->priv->view, "sync-source",
7023 G_CALLBACK (ev_window_sync_source),
7026 gtk_widget_show (ev_window->priv->view);
7027 gtk_widget_show (ev_window->priv->password_view);
7030 ev_window->priv->find_bar = egg_find_bar_new ();
7031 gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
7032 ev_window->priv->find_bar,
7035 /* We own a ref on these widgets, as we can swap them in and out */
7036 g_object_ref (ev_window->priv->view);
7037 g_object_ref (ev_window->priv->password_view);
7039 gtk_container_add (GTK_CONTAINER (ev_window->priv->scrolled_window),
7040 ev_window->priv->view);
7042 /* Connect to model signals */
7043 g_signal_connect_swapped (ev_window->priv->model,
7045 G_CALLBACK (ev_window_page_changed_cb),
7047 g_signal_connect (ev_window->priv->model,
7049 G_CALLBACK (ev_window_document_changed_cb),
7051 g_signal_connect (ev_window->priv->model,
7053 G_CALLBACK (ev_window_zoom_changed_cb),
7055 g_signal_connect (ev_window->priv->model,
7056 "notify::sizing-mode",
7057 G_CALLBACK (ev_window_sizing_mode_changed_cb),
7059 g_signal_connect (ev_window->priv->model,
7061 G_CALLBACK (ev_window_rotation_changed_cb),
7063 g_signal_connect (ev_window->priv->model,
7064 "notify::continuous",
7065 G_CALLBACK (ev_window_continuous_changed_cb),
7067 g_signal_connect (ev_window->priv->model,
7068 "notify::dual-page",
7069 G_CALLBACK (ev_window_dual_mode_changed_cb),
7071 g_signal_connect (ev_window->priv->model,
7072 "notify::inverted-colors",
7073 G_CALLBACK (ev_window_inverted_colors_changed_cb),
7076 /* Connect sidebar signals */
7077 g_signal_connect (ev_window->priv->sidebar,
7079 G_CALLBACK (ev_window_sidebar_visibility_changed_cb),
7081 g_signal_connect (ev_window->priv->sidebar,
7082 "notify::current-page",
7083 G_CALLBACK (ev_window_sidebar_current_page_changed_cb),
7086 /* Connect to find bar signals */
7087 g_signal_connect (ev_window->priv->find_bar,
7089 G_CALLBACK (find_bar_previous_cb),
7091 g_signal_connect (ev_window->priv->find_bar,
7093 G_CALLBACK (find_bar_next_cb),
7095 g_signal_connect (ev_window->priv->find_bar,
7097 G_CALLBACK (find_bar_close_cb),
7099 g_signal_connect (ev_window->priv->find_bar,
7100 "notify::search-string",
7101 G_CALLBACK (find_bar_search_changed_cb),
7103 g_signal_connect (ev_window->priv->find_bar,
7104 "notify::case-sensitive",
7105 G_CALLBACK (find_bar_search_changed_cb),
7107 g_signal_connect (ev_window->priv->find_bar,
7109 G_CALLBACK (find_bar_visibility_changed_cb),
7111 g_signal_connect (ev_window->priv->find_bar,
7113 G_CALLBACK (find_bar_scroll),
7117 ev_window->priv->view_popup = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
7119 ev_window->priv->link = NULL;
7121 ev_window->priv->attachment_popup = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
7122 "/AttachmentPopup");
7123 ev_window->priv->attach_list = NULL;
7125 /* Media player keys */
7126 mpkeys = ev_application_get_media_keys (EV_APP);
7128 g_signal_connect_swapped (mpkeys, "key_pressed",
7129 G_CALLBACK (ev_window_media_player_key_pressed),
7133 /* Give focus to the document view */
7134 gtk_widget_grab_focus (ev_window->priv->view);
7136 ev_window->priv->default_settings = g_settings_new (GS_SCHEMA_NAME".Default");
7137 g_settings_delay (ev_window->priv->default_settings);
7139 /* Set it user interface params */
7140 ev_window_setup_recent (ev_window);
7142 ev_window_setup_gtk_settings (ev_window);
7144 setup_chrome_from_metadata (ev_window);
7145 update_chrome_actions (ev_window);
7146 update_chrome_visibility (ev_window);
7148 gtk_window_set_default_size (GTK_WINDOW (ev_window), 600, 600);
7150 setup_view_from_metadata (ev_window);
7151 setup_sidebar_from_metadata (ev_window);
7153 ev_window_sizing_mode_changed_cb (ev_window->priv->model, NULL, ev_window);
7154 ev_window_setup_action_sensitivity (ev_window);
7157 gtk_drag_dest_set (GTK_WIDGET (ev_window),
7158 GTK_DEST_DEFAULT_ALL,
7161 gtk_drag_dest_add_uri_targets (GTK_WIDGET (ev_window));
7167 * Creates a #GtkWidget that represents the window.
7169 * Returns: the #GtkWidget that represents the window.
7172 ev_window_new (void)
7174 GtkWidget *ev_window;
7176 ev_window = GTK_WIDGET (g_object_new (EV_TYPE_WINDOW,
7177 "type", GTK_WINDOW_TOPLEVEL,
7184 ev_window_get_dbus_object_path (EvWindow *ev_window)
7187 return ev_window->priv->dbus_object_path;