/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
/* this file is part of evince, a gnome document viewer
*
+ * Copyright (C) 2008 Carlos Garcia Campos
* Copyright (C) 2004 Martin Kretzschmar
* Copyright (C) 2004 Red Hat, Inc.
* Copyright (C) 2000, 2001, 2002, 2003, 2004 Marco Pesenti Gritti
#include "config.h"
#endif
-#include "ev-window.h"
-#include "ev-window-title.h"
-#include "ev-navigation-action.h"
-#include "ev-page-action.h"
-#include "ev-sidebar.h"
-#include "ev-sidebar-links.h"
-#include "ev-sidebar-attachments.h"
-#include "ev-sidebar-thumbnails.h"
-#include "ev-view.h"
-#include "ev-password.h"
-#include "ev-password-view.h"
-#include "ev-properties-dialog.h"
-#include "ev-file-exporter.h"
-#include "ev-document-thumbnails.h"
-#include "ev-document-links.h"
-#include "ev-document-fonts.h"
-#include "ev-document-find.h"
-#include "ev-document-security.h"
-#include "ev-document-factory.h"
-#include "ev-job-queue.h"
-#include "ev-jobs.h"
-#include "ev-sidebar-page.h"
-#include "eggfindbar.h"
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
-#ifndef HAVE_GTK_RECENT
-#include "egg-recent-view-uimanager.h"
-#include "egg-recent-view.h"
-#include "egg-recent-model.h"
+#include <glib/gstdio.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+#include <gtk/gtk.h>
+#if GTK_CHECK_VERSION (2, 14, 0)
+#include <gtk/gtkunixprint.h>
+#else
+#include <gtk/gtkprintunixdialog.h>
#endif
+#include <gconf/gconf-client.h>
-#include "egg-toolbar-editor.h"
#include "egg-editable-toolbar.h"
+#include "egg-toolbar-editor.h"
#include "egg-toolbars-model.h"
-#include "ephy-zoom.h"
+
+#include "eggfindbar.h"
+
#include "ephy-zoom-action.h"
+#include "ephy-zoom.h"
+
#include "ev-application.h"
-#include "ev-stock-icons.h"
-#include "ev-metadata-manager.h"
+#include "ev-document-factory.h"
+#include "ev-document-find.h"
+#include "ev-document-fonts.h"
+#include "ev-document-images.h"
+#include "ev-document-links.h"
+#include "ev-document-thumbnails.h"
+#include "ev-file-exporter.h"
#include "ev-file-helpers.h"
-#include "ev-utils.h"
+#include "ev-file-monitor.h"
#include "ev-history.h"
#include "ev-image.h"
+#include "ev-job-scheduler.h"
+#include "ev-jobs.h"
+#include "ev-message-area.h"
+#include "ev-metadata-manager.h"
+#include "ev-mount-operation.h"
+#include "ev-navigation-action.h"
+#include "ev-open-recent-action.h"
+#include "ev-page-action.h"
+#include "ev-password-view.h"
+#include "ev-properties-dialog.h"
+#include "ev-sidebar-attachments.h"
+#include "ev-sidebar.h"
+#include "ev-sidebar-links.h"
+#include "ev-sidebar-page.h"
+#include "ev-sidebar-thumbnails.h"
+#include "ev-sidebar-layers.h"
+#include "ev-stock-icons.h"
+#include "ev-utils.h"
+#include "ev-keyring.h"
+#include "ev-view.h"
+#include "ev-window.h"
+#include "ev-window-title.h"
+#include "ev-print-operation.h"
+#include "ev-progress-message-area.h"
-#ifdef WITH_GNOME_PRINT
-#include "ev-print-job.h"
-#include <libgnomeprintui/gnome-print-dialog.h>
-#endif
-
-#ifdef WITH_GTK_PRINT
-#include <gtk/gtkprintunixdialog.h>
-#endif
+#ifdef ENABLE_DBUS
+#include "ev-media-player-keys.h"
+#endif /* ENABLE_DBUS */
#ifdef ENABLE_PDF
#include <poppler.h>
#endif
-#include <glib/gstdio.h>
-#include <glib/gi18n.h>
-#include <gtk/gtk.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
-#include <libgnomevfs/gnome-vfs-async-ops.h>
-#include <libgnomevfs/gnome-vfs-ops.h>
-#include <gconf/gconf-client.h>
-
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#if !GLIB_CHECK_VERSION (2, 13, 3)
-char *xdg_user_dir_lookup (char *type);
-#endif
-
typedef enum {
PAGE_MODE_DOCUMENT,
PAGE_MODE_PASSWORD
EV_CHROME_NORMAL = EV_CHROME_MENUBAR | EV_CHROME_TOOLBAR | EV_CHROME_SIDEBAR
} EvChrome;
+typedef enum {
+ EV_SAVE_DOCUMENT,
+ EV_SAVE_ATTACHMENT,
+ EV_SAVE_IMAGE
+} EvSaveType;
+
struct _EvWindowPrivate {
/* UI */
EvChrome chrome;
GtkWidget *menubar;
GtkWidget *toolbar;
GtkWidget *hpaned;
+ GtkWidget *view_box;
GtkWidget *sidebar;
GtkWidget *find_bar;
GtkWidget *scrolled_window;
GtkWidget *view;
+ GtkWidget *message_area;
GtkWidget *password_view;
GtkWidget *sidebar_thumbs;
GtkWidget *sidebar_links;
GtkWidget *sidebar_attachments;
+ GtkWidget *sidebar_layers;
+
+ /* Progress Messages */
+ guint progress_idle;
+ GCancellable *progress_cancellable;
/* Dialogs */
GtkWidget *properties;
-#ifdef WITH_PRINT
GtkWidget *print_dialog;
-#endif
- GtkWidget *password_dialog;
/* UI Builders */
GtkActionGroup *action_group;
GtkActionGroup *view_popup_action_group;
GtkActionGroup *attachment_popup_action_group;
-#ifdef HAVE_GTK_RECENT
GtkRecentManager *recent_manager;
GtkActionGroup *recent_action_group;
guint recent_ui_id;
-#endif
GtkUIManager *ui_manager;
/* Fullscreen mode */
/* Document */
char *uri;
+ glong uri_mtime;
char *local_uri;
- EvLinkDest *dest;
gboolean unlink_temp_file;
+ gboolean in_reload;
+ EvFileMonitor *monitor;
+ guint setup_document_idle;
EvDocument *document;
EvHistory *history;
EvPageCache *page_cache;
EvWindowPageMode page_mode;
EvWindowTitle *title;
-#ifndef HAVE_GTK_RECENT
- EggRecentViewUIManager *recent_view;
-#endif
- EvJob *load_job;
- EvJob *thumbnail_job;
-#ifdef WITH_GNOME_PRINT
- GnomePrintJob *print_job;
-#endif
+ /* Load params */
+ EvLinkDest *dest;
+ gchar *search_string;
+ EvWindowRunMode window_mode;
+
+ EvJob *load_job;
+ EvJob *reload_job;
+ EvJob *thumbnail_job;
+ EvJob *save_job;
+ EvJob *find_job;
-#ifdef WITH_GTK_PRINT
- EvJob *print_job;
- gboolean print_preview;
- GtkPrintJob *gtk_print_job;
+ /* Printing */
+ GQueue *print_queue;
GtkPrinter *printer;
GtkPrintSettings *print_settings;
GtkPageSetup *print_page_setup;
-#endif
+ gboolean close_after_print;
};
#define EV_WINDOW_GET_PRIVATE(object) \
#define LINKS_SIDEBAR_ID "links"
#define THUMBNAILS_SIDEBAR_ID "thumbnails"
#define ATTACHMENTS_SIDEBAR_ID "attachments"
+#define LAYERS_SIDEBAR_ID "layers"
+
+static const gchar *document_print_settings[] = {
+ GTK_PRINT_SETTINGS_N_COPIES,
+ GTK_PRINT_SETTINGS_COLLATE,
+ GTK_PRINT_SETTINGS_REVERSE,
+ GTK_PRINT_SETTINGS_NUMBER_UP,
+ GTK_PRINT_SETTINGS_SCALE,
+ GTK_PRINT_SETTINGS_PRINT_PAGES,
+ GTK_PRINT_SETTINGS_PAGE_RANGES,
+ GTK_PRINT_SETTINGS_PAGE_SET,
+ GTK_PRINT_SETTINGS_OUTPUT_URI
+};
-static void ev_window_update_actions (EvWindow *ev_window);
+static void ev_window_update_actions (EvWindow *ev_window);
static void ev_window_sidebar_visibility_changed_cb (EvSidebar *ev_sidebar,
GParamSpec *pspec,
EvWindow *ev_window);
static void ev_window_set_page_mode (EvWindow *window,
EvWindowPageMode page_mode);
-static void ev_window_load_job_cb (EvJobLoad *job,
+static void ev_window_load_job_cb (EvJob *job,
gpointer data);
+static void ev_window_reload_document (EvWindow *window);
+static void ev_window_reload_job_cb (EvJob *job,
+ EvWindow *window);
static void ev_window_set_icon_from_thumbnail (EvJobThumbnail *job,
EvWindow *ev_window);
-#ifdef WITH_GTK_PRINT
-static void ev_window_print_job_cb (EvJobPrint *job,
+static void ev_window_save_job_cb (EvJob *save,
EvWindow *window);
-#endif
static void ev_window_sizing_mode_changed_cb (EvView *view,
GParamSpec *pspec,
EvWindow *ev_window);
static void ev_window_add_recent (EvWindow *window,
const char *filename);
static void ev_window_run_fullscreen (EvWindow *window);
-static void ev_window_stop_fullscreen (EvWindow *window);
+static void ev_window_stop_fullscreen (EvWindow *window,
+ gboolean unfullscreen_window);
static void ev_window_cmd_view_fullscreen (GtkAction *action,
EvWindow *window);
static void ev_window_run_presentation (EvWindow *window);
-static void ev_window_stop_presentation (EvWindow *window);
+static void ev_window_stop_presentation (EvWindow *window,
+ gboolean unfullscreen_window);
static void ev_window_cmd_view_presentation (GtkAction *action,
EvWindow *window);
static void ev_window_run_preview (EvWindow *window);
static void ev_view_popup_cmd_copy_image (GtkAction *action,
EvWindow *window);
static void ev_attachment_popup_cmd_open_attachment (GtkAction *action,
- EvWindow *window);
-static void ev_attachment_popup_cmd_save_attachment_as (GtkAction *action,
- EvWindow *window);
+ EvWindow *window);
+static void ev_attachment_popup_cmd_save_attachment_as (GtkAction *action,
+ EvWindow *window);
static void ev_window_cmd_view_best_fit (GtkAction *action,
EvWindow *ev_window);
static void ev_window_cmd_view_page_width (GtkAction *action,
EvWindow *ev_window);
-static void view_handle_link_cb (EvView *view,
- EvLink *link,
- EvWindow *window);
+static void view_handle_link_cb (EvView *view,
+ EvLink *link,
+ EvWindow *window);
+static void ev_window_update_find_status_message (EvWindow *ev_window);
+static void ev_window_cmd_edit_find (GtkAction *action,
+ EvWindow *ev_window);
+static void find_bar_search_changed_cb (EggFindBar *find_bar,
+ GParamSpec *param,
+ EvWindow *ev_window);
+static void ev_window_do_preview_print (EvWindow *window);
+static void ev_window_load_file_remote (EvWindow *ev_window,
+ GFile *source_file);
+static void ev_window_media_player_key_pressed (EvWindow *window,
+ const gchar *key,
+ gpointer user_data);
+static void ev_window_save_print_page_setup (EvWindow *window);
G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW)
gboolean ok_to_print = TRUE;
gboolean ok_to_copy = TRUE;
gboolean has_properties = TRUE;
- gboolean override_restrictions = FALSE;
+ gboolean override_restrictions = TRUE;
gboolean can_get_text = FALSE;
gboolean has_pages = FALSE;
gboolean can_find = FALSE;
if (gconf_client_get_bool (client, GCONF_LOCKDOWN_PRINT, NULL)) {
ok_to_print = FALSE;
}
-#ifndef WITH_PRINT
- ok_to_print = FALSE;
-#endif
- g_object_unref (client);
+ g_object_unref (client);
/* File menu */
ev_window_set_action_sensitive (ev_window, "FileOpenCopy", has_document);
ev_window_set_action_sensitive (ev_window, "FileSaveAs", has_document && ok_to_copy);
-
-#ifdef WITH_GTK_PRINT
ev_window_set_action_sensitive (ev_window, "FilePrintSetup", has_pages && ok_to_print);
-#endif
-
-#ifdef WITH_GNOME_PRINT
- ev_window_set_action_sensitive (ev_window, "FilePrintSetup", FALSE);
-#endif
-
ev_window_set_action_sensitive (ev_window, "FilePrint", has_pages && ok_to_print);
ev_window_set_action_sensitive (ev_window, "FileProperties", has_document && has_properties);
ev_window_set_action_sensitive (ev_window, "ViewBestFit", has_pages);
ev_window_set_action_sensitive (ev_window, "ViewPageWidth", has_pages);
ev_window_set_action_sensitive (ev_window, "ViewReload", has_pages);
+ ev_window_set_action_sensitive (ev_window, "ViewAutoscroll", has_pages);
/* Toolbar-specific actions: */
ev_window_set_action_sensitive (ev_window, PAGE_SELECTOR_ACTION, has_pages);
int n_pages = 0, page = -1;
gboolean has_pages = FALSE;
gboolean presentation_mode;
+ gboolean can_find_in_page = FALSE;
if (ev_window->priv->document && ev_window->priv->page_cache) {
page = ev_page_cache_get_current_page (ev_window->priv->page_cache);
has_pages = n_pages > 0;
}
+ can_find_in_page = (ev_window->priv->find_job &&
+ ev_job_find_has_results (EV_JOB_FIND (ev_window->priv->find_job)));
+
ev_window_set_action_sensitive (ev_window, "EditCopy",
has_pages &&
ev_view_get_has_selection (view));
ev_window_set_action_sensitive (ev_window, "EditFindNext",
- ev_view_can_find_next (view));
+ has_pages && can_find_in_page);
ev_window_set_action_sensitive (ev_window, "EditFindPrevious",
- ev_view_can_find_previous (view));
+ has_pages && can_find_in_page);
presentation_mode = ev_view_get_presentation (view);
} else {
priv->chrome &= ~flag;
}
-
- update_chrome_visibility (window);
}
static void
}
static void
-ev_window_error_dialog_response_cb (GtkWidget *dialog,
- gint response_id,
- EvWindow *ev_window)
+ev_window_set_message_area (EvWindow *window,
+ GtkWidget *area)
+{
+ if (window->priv->message_area == area)
+ return;
+
+ if (window->priv->message_area)
+ gtk_widget_destroy (window->priv->message_area);
+ window->priv->message_area = area;
+
+ if (!area)
+ return;
+
+ gtk_box_pack_start (GTK_BOX (window->priv->view_box),
+ window->priv->message_area,
+ FALSE, FALSE, 0);
+ gtk_box_reorder_child (GTK_BOX (window->priv->view_box),
+ window->priv->message_area, 0);
+ g_object_add_weak_pointer (G_OBJECT (window->priv->message_area),
+ (gpointer) &(window->priv->message_area));
+}
+
+static void
+ev_window_message_area_response_cb (EvMessageArea *area,
+ gint response_id,
+ EvWindow *window)
{
- gtk_widget_destroy (dialog);
+ ev_window_set_message_area (window, NULL);
}
static void
-ev_window_error_dialog (GtkWindow *window, const gchar *msg, GError *error)
+ev_window_error_message (EvWindow *window,
+ GError *error,
+ const gchar *format,
+ ...)
{
- GtkWidget *dialog;
+ GtkWidget *area;
+ va_list args;
+ gchar *msg = NULL;
- dialog = gtk_message_dialog_new (GTK_WINDOW (window),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_CLOSE,
- msg);
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- "%s", error->message);
- g_signal_connect (dialog, "response",
- G_CALLBACK (ev_window_error_dialog_response_cb),
- window);
- gtk_widget_show (dialog);
+ if (window->priv->message_area)
+ return;
+
+ va_start (args, format);
+ msg = g_strdup_vprintf (format, args);
+ va_end (args);
+
+ area = ev_message_area_new (GTK_MESSAGE_ERROR,
+ msg,
+ GTK_STOCK_CLOSE,
+ GTK_RESPONSE_CLOSE,
+ NULL);
+ g_free (msg);
+
+ if (error)
+ ev_message_area_set_secondary_text (EV_MESSAGE_AREA (area), error->message);
+ g_signal_connect (area, "response",
+ G_CALLBACK (ev_window_message_area_response_cb),
+ window);
+ gtk_widget_show (area);
+ ev_window_set_message_area (window, area);
}
static void
-find_changed_cb (EvDocument *document, int page, EvWindow *ev_window)
+ev_window_warning_message (EvWindow *window,
+ const gchar *format,
+ ...)
{
- ev_window_update_actions (ev_window);
+ GtkWidget *area;
+ va_list args;
+ gchar *msg = NULL;
+
+ if (window->priv->message_area)
+ return;
+
+ va_start (args, format);
+ msg = g_strdup_vprintf (format, args);
+ va_end (args);
+
+ area = ev_message_area_new (GTK_MESSAGE_WARNING,
+ msg,
+ GTK_STOCK_CLOSE,
+ GTK_RESPONSE_CLOSE,
+ NULL);
+ g_free (msg);
+
+ g_signal_connect (area, "response",
+ G_CALLBACK (ev_window_message_area_response_cb),
+ window);
+ gtk_widget_show (area);
+ ev_window_set_message_area (window, area);
}
static void
EvWindow *ev_window)
{
ev_window_update_actions (ev_window);
-
+
+ ev_window_update_find_status_message (ev_window);
+
if (!ev_window_is_empty (ev_window))
ev_metadata_manager_set_int (ev_window->priv->uri, "page", page);
}
if (window->priv->history == NULL)
return;
+
+ if (!EV_IS_DOCUMENT_LINKS (window->priv->document))
+ return;
if (link) {
action = g_object_ref (ev_link_get_action (link));
find_task.page_label = page_label;
find_task.chapter = NULL;
- if (EV_IS_DOCUMENT_LINKS (window->priv->document) &&
- ev_document_links_has_document_links (EV_DOCUMENT_LINKS (window->priv->document))) {
+ if (ev_document_links_has_document_links (EV_DOCUMENT_LINKS (window->priv->document))) {
GtkTreeModel *model;
g_object_get (G_OBJECT (window->priv->sidebar_links), "model", &model, NULL);
if (uri && ev_metadata_manager_get (uri, "page", &page, TRUE)) {
n_pages = ev_page_cache_get_n_pages (window->priv->page_cache);
new_page = CLAMP (g_value_get_int (&page), 0, n_pages - 1);
- if (new_page == n_pages - 1)
+ if (!window->priv->in_reload && new_page == n_pages - 1)
new_page = 0;
ev_page_cache_set_current_page (window->priv->page_cache,
new_page);
GtkWidget *links = window->priv->sidebar_links;
GtkWidget *thumbs = window->priv->sidebar_thumbs;
GtkWidget *attachments = window->priv->sidebar_attachments;
+ GtkWidget *layers = window->priv->sidebar_layers;
GValue sidebar_size = { 0, };
GValue sidebar_page = { 0, };
GValue sidebar_visibility = { 0, };
g_value_unset(&sidebar_size);
}
- if (document && ev_metadata_manager_get (uri, "sidebar_page", &sidebar_page, FALSE)) {
+ if (document && ev_metadata_manager_get (uri, "sidebar_page", &sidebar_page, TRUE)) {
const char *page_id = g_value_get_string (&sidebar_page);
-
+
if (strcmp (page_id, LINKS_SIDEBAR_ID) == 0 && ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (links), document)) {
ev_sidebar_set_page (EV_SIDEBAR (sidebar), links);
- } else if (strcmp (page_id, THUMBNAILS_SIDEBAR_ID) && ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (thumbs), document)) {
+ } else if (strcmp (page_id, THUMBNAILS_SIDEBAR_ID) == 0 && ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (thumbs), document)) {
ev_sidebar_set_page (EV_SIDEBAR (sidebar), thumbs);
- } else if (strcmp (page_id, ATTACHMENTS_SIDEBAR_ID) && ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (attachments), document)) {
+ } else if (strcmp (page_id, ATTACHMENTS_SIDEBAR_ID) == 0 && ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (attachments), document)) {
ev_sidebar_set_page (EV_SIDEBAR (sidebar), attachments);
+ } else if (strcmp (page_id, LAYERS_SIDEBAR_ID) == 0 && ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (layers), document)) {
+ ev_sidebar_set_page (EV_SIDEBAR (sidebar), layers);
}
g_value_unset (&sidebar_page);
- } else if (document && ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (links), document)) {
- ev_sidebar_set_page (EV_SIDEBAR (sidebar), links);
+ } else if (document) {
+ if (ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (links), document)) {
+ ev_sidebar_set_page (EV_SIDEBAR (sidebar), links);
+ } else if (ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (thumbs), document)) {
+ ev_sidebar_set_page (EV_SIDEBAR (sidebar), thumbs);
+ } else if (ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (attachments), document)) {
+ ev_sidebar_set_page (EV_SIDEBAR (sidebar), attachments);
+ } else if (ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (layers), document)) {
+ ev_sidebar_set_page (EV_SIDEBAR (sidebar), layers);
+ }
}
if (ev_metadata_manager_get (uri, "sidebar_visibility", &sidebar_visibility, FALSE)) {
update_chrome_flag (window, EV_CHROME_SIDEBAR, g_value_get_boolean (&sidebar_visibility));
g_value_unset (&sidebar_visibility);
+ update_chrome_visibility (window);
}
}
if (ev_metadata_manager_get (uri, "window_maximized", &maximized, FALSE)) {
if (g_value_get_boolean (&maximized)) {
gtk_window_maximize (GTK_WINDOW (window));
+ g_value_unset (&maximized);
return;
} else {
gtk_window_unmaximize (GTK_WINDOW (window));
ev_window_clear_thumbnail_job (EvWindow *ev_window)
{
if (ev_window->priv->thumbnail_job != NULL) {
- ev_job_queue_remove_job (ev_window->priv->thumbnail_job);
-
+ if (!ev_job_is_finished (ev_window->priv->thumbnail_job))
+ ev_job_cancel (ev_window->priv->thumbnail_job);
+
g_signal_handlers_disconnect_by_func (ev_window->priv->thumbnail_job,
ev_window_set_icon_from_thumbnail,
ev_window);
ev_window_clear_thumbnail_job (ev_window);
}
+static void
+ev_window_refresh_window_thumbnail (EvWindow *ev_window, int rotation)
+{
+ gint page_width, page_height;
+ gdouble scale;
+ EvDocument *document = ev_window->priv->document;
+
+ if (!EV_IS_DOCUMENT_THUMBNAILS (document) ||
+ ev_page_cache_get_n_pages (ev_window->priv->page_cache) <= 0) {
+ return;
+ }
+
+ ev_window_clear_thumbnail_job (ev_window);
+
+ ev_page_cache_get_size (ev_window->priv->page_cache,
+ 0, 0, 1.0,
+ &page_width, &page_height);
+ scale = (gdouble)128 / (gdouble)page_width;
+
+ ev_window->priv->thumbnail_job = ev_job_thumbnail_new (document, 0, rotation, scale);
+ g_signal_connect (ev_window->priv->thumbnail_job, "finished",
+ G_CALLBACK (ev_window_set_icon_from_thumbnail),
+ ev_window);
+ ev_job_scheduler_push_job (ev_window->priv->thumbnail_job, EV_JOB_PRIORITY_NONE);
+}
+
static gboolean
ev_window_setup_document (EvWindow *ev_window)
{
EvDocument *document = ev_window->priv->document;
EvSidebar *sidebar = EV_SIDEBAR (ev_window->priv->sidebar);
GtkAction *action;
-
- if (EV_IS_DOCUMENT_FIND (document)) {
- g_signal_connect_object (G_OBJECT (document),
- "find_changed",
- G_CALLBACK (find_changed_cb),
- ev_window, 0);
- }
- if (EV_IS_DOCUMENT_THUMBNAILS (document)) {
- EvRenderContext *rc;
- gint page_width, page_height;
- gdouble scale;
-
- ev_window_clear_thumbnail_job (ev_window);
-
- ev_page_cache_get_size (ev_window->priv->page_cache,
- 0, 0, 1.0,
- &page_width, &page_height);
- scale = (gdouble)128 / (gdouble)page_width;
-
- rc = ev_render_context_new (0, 0, scale);
- ev_window->priv->thumbnail_job = ev_job_thumbnail_new (document, rc);
- g_signal_connect (ev_window->priv->thumbnail_job, "finished",
- G_CALLBACK (ev_window_set_icon_from_thumbnail),
- ev_window);
- ev_job_queue_add_job (EV_JOB (ev_window->priv->thumbnail_job), EV_JOB_PRIORITY_LOW);
- g_object_unref (rc);
- }
+ ev_window->priv->setup_document_idle = 0;
+
+ ev_window_refresh_window_thumbnail (ev_window, 0);
ev_window_set_page_mode (ev_window, PAGE_MODE_DOCUMENT);
ev_window_title_set_document (ev_window->priv->title, document);
if (ev_window->priv->properties) {
ev_properties_dialog_set_document (EV_PROPERTIES_DIALOG (ev_window->priv->properties),
+ ev_window->priv->uri,
ev_window->priv->document);
}
if (ev_window->priv->document)
g_object_unref (ev_window->priv->document);
ev_window->priv->document = g_object_ref (document);
+
+ ev_window_set_message_area (ev_window, NULL);
ev_window->priv->page_cache = ev_page_cache_get (ev_window->priv->document);
g_signal_connect (ev_window->priv->page_cache, "page-changed",
if (ev_page_cache_get_n_pages (ev_window->priv->page_cache) > 0) {
ev_view_set_document (view, document);
+ } else {
+ ev_window_warning_message (ev_window, "%s",
+ _("The document contains no pages"));
}
- g_idle_add ((GSourceFunc)ev_window_setup_document, ev_window);
+ if (ev_window->priv->setup_document_idle > 0)
+ g_source_remove (ev_window->priv->setup_document_idle);
+ ev_window->priv->setup_document_idle = g_idle_add ((GSourceFunc)ev_window_setup_document, ev_window);
}
static void
-password_dialog_response (GtkWidget *password_dialog,
- gint response_id,
- EvWindow *ev_window)
+ev_window_document_changed (EvWindow *ev_window,
+ gpointer user_data)
{
- char *password;
-
- if (response_id == GTK_RESPONSE_OK) {
-
- password = ev_password_dialog_get_password (EV_PASSWORD_DIALOG (password_dialog));
- if (password) {
- ev_document_doc_mutex_lock ();
- ev_document_security_set_password (EV_DOCUMENT_SECURITY (ev_window->priv->load_job->document),
- password);
- ev_document_doc_mutex_unlock ();
- }
- g_free (password);
-
- ev_password_dialog_save_password (EV_PASSWORD_DIALOG (password_dialog));
-
- ev_window_title_set_type (ev_window->priv->title, EV_WINDOW_TITLE_DOCUMENT);
- ev_job_queue_add_job (ev_window->priv->load_job, EV_JOB_PRIORITY_HIGH);
-
- gtk_widget_destroy (password_dialog);
-
- return;
- }
-
- gtk_widget_set_sensitive (ev_window->priv->password_view, TRUE);
- gtk_widget_destroy (password_dialog);
+ ev_window_reload_document (ev_window);
}
-/* Called either by ev_window_load_job_cb or by the "unlock" callback on the
- * password_view page. It assumes that ev_window->priv->password_* has been set
- * correctly. These are cleared by password_dialog_response() */
-
static void
-ev_window_popup_password_dialog (EvWindow *ev_window)
+ev_window_password_view_unlock (EvWindow *ev_window)
{
+ const gchar *password;
+
g_assert (ev_window->priv->load_job);
- gtk_widget_set_sensitive (ev_window->priv->password_view, FALSE);
-
- ev_window_title_set_uri (ev_window->priv->title, ev_window->priv->uri);
- ev_window_title_set_type (ev_window->priv->title, EV_WINDOW_TITLE_PASSWORD);
-
- if (ev_window->priv->password_dialog == NULL) {
- ev_window->priv->password_dialog =
- g_object_new (EV_TYPE_PASSWORD_DIALOG, "uri", ev_window->priv->uri, NULL);
- gtk_window_set_transient_for (GTK_WINDOW (ev_window->priv->password_dialog), GTK_WINDOW (ev_window));
-
- g_object_add_weak_pointer (G_OBJECT (ev_window->priv->password_dialog),
- (gpointer) &(ev_window->priv->password_dialog));
- g_signal_connect (ev_window->priv->password_dialog,
- "response",
- G_CALLBACK (password_dialog_response),
- ev_window);
- gtk_widget_show (ev_window->priv->password_dialog);
- } else {
- ev_password_dialog_set_bad_pass (EV_PASSWORD_DIALOG (ev_window->priv->password_dialog));
- }
+ password = ev_password_view_get_password (EV_PASSWORD_VIEW (ev_window->priv->password_view));
+ ev_job_load_set_password (EV_JOB_LOAD (ev_window->priv->load_job), password);
+ ev_job_scheduler_push_job (ev_window->priv->load_job, EV_JOB_PRIORITY_NONE);
}
static void
ev_window_clear_load_job (EvWindow *ev_window)
{
- if (ev_window->priv->load_job != NULL) {
-
- if (!ev_window->priv->load_job->finished)
- ev_job_queue_remove_job (ev_window->priv->load_job);
+ if (ev_window->priv->load_job != NULL) {
+ if (!ev_job_is_finished (ev_window->priv->load_job))
+ ev_job_cancel (ev_window->priv->load_job);
+
+ g_signal_handlers_disconnect_by_func (ev_window->priv->load_job, ev_window_load_job_cb, ev_window);
+ g_object_unref (ev_window->priv->load_job);
+ ev_window->priv->load_job = NULL;
+ }
+}
- g_signal_handlers_disconnect_by_func (ev_window->priv->load_job, ev_window_load_job_cb, ev_window);
- g_object_unref (ev_window->priv->load_job);
- ev_window->priv->load_job = NULL;
- }
+static void
+ev_window_clear_reload_job (EvWindow *ev_window)
+{
+ if (ev_window->priv->reload_job != NULL) {
+ if (!ev_job_is_finished (ev_window->priv->reload_job))
+ ev_job_cancel (ev_window->priv->reload_job);
+
+ g_signal_handlers_disconnect_by_func (ev_window->priv->reload_job, ev_window_reload_job_cb, ev_window);
+ g_object_unref (ev_window->priv->reload_job);
+ ev_window->priv->reload_job = NULL;
+ }
}
static void
ev_window_clear_local_uri (EvWindow *ev_window)
{
- if (ev_window->priv->local_uri) {
- ev_tmp_uri_unlink (ev_window->priv->local_uri);
- g_free (ev_window->priv->local_uri);
- ev_window->priv->local_uri = NULL;
- }
+ if (ev_window->priv->local_uri) {
+ ev_tmp_uri_unlink (ev_window->priv->local_uri);
+ g_free (ev_window->priv->local_uri);
+ ev_window->priv->local_uri = NULL;
+ }
}
static void
static void
ev_window_clear_temp_file (EvWindow *ev_window)
{
- GnomeVFSURI *uri;
- gchar *filename;
- const gchar *tempdir;
+ GFile *file, *tempdir;
if (!ev_window->priv->uri)
return;
- uri = gnome_vfs_uri_new (ev_window->priv->uri);
- if (!gnome_vfs_uri_is_local (uri)) {
- gnome_vfs_uri_unref (uri);
- return;
- }
- gnome_vfs_uri_unref (uri);
-
- filename = g_filename_from_uri (ev_window->priv->uri, NULL, NULL);
- if (!filename)
- return;
+ file = g_file_new_for_uri (ev_window->priv->uri);
+ tempdir = g_file_new_for_path (g_get_tmp_dir ());
- tempdir = g_get_tmp_dir ();
- if (g_ascii_strncasecmp (filename, tempdir, strlen (tempdir)) == 0) {
- g_unlink (filename);
+ if (g_file_has_prefix (file, tempdir)) {
+ g_file_delete (file, NULL, NULL);
}
- g_free (filename);
+ g_object_unref (file);
+ g_object_unref (tempdir);
}
/* This callback will executed when load job will be finished.
* function should _not_ necessarily expect those to exist after being
* called. */
static void
-ev_window_load_job_cb (EvJobLoad *job,
- gpointer data)
+ev_window_load_job_cb (EvJob *job,
+ gpointer data)
{
EvWindow *ev_window = EV_WINDOW (data);
EvDocument *document = EV_JOB (job)->document;
+ EvJobLoad *job_load = EV_JOB_LOAD (job);
+
+ g_assert (job_load->uri);
- g_assert (job->uri);
-
ev_view_set_loading (EV_VIEW (ev_window->priv->view), FALSE);
/* Success! */
- if (job->error == NULL) {
+ if (!ev_job_is_failed (job)) {
ev_window_set_document (ev_window, document);
- if (job->mode != EV_WINDOW_MODE_PREVIEW) {
+ if (ev_window->priv->window_mode != EV_WINDOW_MODE_PREVIEW) {
setup_view_from_metadata (ev_window);
}
ev_window_add_recent (ev_window, ev_window->priv->uri);
}
- if (job->dest) {
+ ev_window_title_set_type (ev_window->priv->title,
+ EV_WINDOW_TITLE_DOCUMENT);
+ if (job_load->password) {
+ GPasswordSave flags;
+
+ flags = ev_password_view_get_password_save_flags (
+ EV_PASSWORD_VIEW (ev_window->priv->password_view));
+ ev_keyring_save_password (ev_window->priv->uri,
+ job_load->password,
+ flags);
+ }
+
+ if (ev_window->priv->dest) {
EvLink *link;
EvLinkAction *link_action;
- link_action = ev_link_action_new_dest (g_object_ref (job->dest));
+ link_action = ev_link_action_new_dest (ev_window->priv->dest);
link = ev_link_new (NULL, link_action);
ev_view_handle_link (EV_VIEW (ev_window->priv->view), link);
g_object_unref (link);
+
+ /* Already unrefed by ev_link_action
+ * FIXME: link action should inc dest ref counting
+ * or not unref it at all
+ */
+ ev_window->priv->dest = NULL;
}
- switch (job->mode) {
+ switch (ev_window->priv->window_mode) {
case EV_WINDOW_MODE_FULLSCREEN:
ev_window_run_fullscreen (ev_window);
break;
break;
}
- ev_window_clear_load_job (ev_window);
+ if (ev_window->priv->search_string && EV_IS_DOCUMENT_FIND (document)) {
+ ev_window_cmd_edit_find (NULL, ev_window);
+ egg_find_bar_set_search_string (EGG_FIND_BAR (ev_window->priv->find_bar),
+ ev_window->priv->search_string);
+ }
+
+ g_free (ev_window->priv->search_string);
+ ev_window->priv->search_string = NULL;
+
+ /* Create a monitor for the document */
+ ev_window->priv->monitor = ev_file_monitor_new (ev_window->priv->uri);
+ g_signal_connect_swapped (ev_window->priv->monitor, "changed",
+ G_CALLBACK (ev_window_document_changed),
+ ev_window);
+
+ ev_window_clear_load_job (ev_window);
return;
}
if (job->error->domain == EV_DOCUMENT_ERROR &&
job->error->code == EV_DOCUMENT_ERROR_ENCRYPTED) {
- gchar *base_name, *file_name;
-
+ gchar *password;
+
setup_view_from_metadata (ev_window);
+
+ /* First look whether password is in keyring */
+ password = ev_keyring_lookup_password (ev_window->priv->uri);
+ if (password) {
+ if (job_load->password && strcmp (password, job_load->password) == 0) {
+ /* Password in kering is wrong */
+ ev_job_load_set_password (job_load, NULL);
+ /* FIXME: delete password from keyring? */
+ } else {
+ ev_job_load_set_password (job_load, password);
+ ev_job_scheduler_push_job (job, EV_JOB_PRIORITY_NONE);
+ g_free (password);
+ return;
+ }
+
+ g_free (password);
+ }
+
+ /* We need to ask the user for a password */
+ ev_window_title_set_uri (ev_window->priv->title,
+ ev_window->priv->uri);
+ ev_window_title_set_type (ev_window->priv->title,
+ EV_WINDOW_TITLE_PASSWORD);
+
+ ev_password_view_set_uri (EV_PASSWORD_VIEW (ev_window->priv->password_view),
+ job_load->uri);
- file_name = gnome_vfs_format_uri_for_display (job->uri);
- base_name = g_path_get_basename (file_name);
- ev_password_view_set_file_name (EV_PASSWORD_VIEW (ev_window->priv->password_view),
- base_name);
- g_free (file_name);
- g_free (base_name);
ev_window_set_page_mode (ev_window, PAGE_MODE_PASSWORD);
-
- ev_window_popup_password_dialog (ev_window);
+
+ ev_job_load_set_password (job_load, NULL);
+ ev_password_view_ask_password (EV_PASSWORD_VIEW (ev_window->priv->password_view));
} else {
- ev_window_error_dialog (GTK_WINDOW (ev_window),
- _("Unable to open document"),
- job->error);
+ ev_window_error_message (ev_window, job->error,
+ "%s", _("Unable to open document"));
ev_window_clear_load_job (ev_window);
}
+}
- return;
+static void
+ev_window_reload_job_cb (EvJob *job,
+ EvWindow *ev_window)
+{
+ GtkWidget *widget;
+
+ if (ev_job_is_failed (job)) {
+ ev_window_clear_reload_job (ev_window);
+ ev_window->priv->in_reload = FALSE;
+ return;
+ }
+
+ ev_window_set_document (ev_window, job->document);
+
+ /* Restart the search after reloading */
+ widget = gtk_window_get_focus (GTK_WINDOW (ev_window));
+ if (widget && gtk_widget_get_ancestor (widget, EGG_TYPE_FIND_BAR)) {
+ find_bar_search_changed_cb (EGG_FIND_BAR (ev_window->priv->find_bar),
+ NULL, ev_window);
+ }
+
+ ev_window_clear_reload_job (ev_window);
+ ev_window->priv->in_reload = FALSE;
}
/**
static void
ev_window_close_dialogs (EvWindow *ev_window)
{
- if (ev_window->priv->password_dialog)
- gtk_widget_destroy (ev_window->priv->password_dialog);
- ev_window->priv->password_dialog = NULL;
-
-#ifdef WITH_PRINT
if (ev_window->priv->print_dialog)
gtk_widget_destroy (ev_window->priv->print_dialog);
ev_window->priv->print_dialog = NULL;
-#endif
-
-#ifdef WITH_GNOME_PRINT
- if (ev_window->priv->print_job)
- g_object_unref (ev_window->priv->print_job);
- ev_window->priv->print_job = NULL;
-#endif
if (ev_window->priv->properties)
gtk_widget_destroy (ev_window->priv->properties);
ev_window->priv->properties = NULL;
}
-static gint
-open_xfer_update_progress_callback (GnomeVFSAsyncHandle *handle,
- GnomeVFSXferProgressInfo *info,
- EvWindow *ev_window)
-{
- switch (info->status) {
- case GNOME_VFS_XFER_PROGRESS_STATUS_OK:
- if (info->phase == GNOME_VFS_XFER_PHASE_COMPLETED) {
- ev_job_queue_add_job (ev_window->priv->load_job, EV_JOB_PRIORITY_HIGH);
- }
+static void
+ev_window_clear_progress_idle (EvWindow *ev_window)
+{
+ if (ev_window->priv->progress_idle > 0)
+ g_source_remove (ev_window->priv->progress_idle);
+ ev_window->priv->progress_idle = 0;
+}
- return 1;
- case GNOME_VFS_XFER_PROGRESS_STATUS_VFSERROR:
- case GNOME_VFS_XFER_PROGRESS_STATUS_OVERWRITE:
- case GNOME_VFS_XFER_PROGRESS_STATUS_DUPLICATE:
- return 1;
- default:
- g_assert_not_reached ();
- }
+static void
+reset_progress_idle (EvWindow *ev_window)
+{
+ ev_window->priv->progress_idle = 0;
+}
- return 0;
+static void
+ev_window_show_progress_message (EvWindow *ev_window,
+ guint interval,
+ GSourceFunc function)
+{
+ if (ev_window->priv->progress_idle > 0)
+ g_source_remove (ev_window->priv->progress_idle);
+ ev_window->priv->progress_idle =
+ g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
+ interval, function,
+ ev_window,
+ (GDestroyNotify)reset_progress_idle);
+}
+
+static void
+ev_window_reset_progress_cancellable (EvWindow *ev_window)
+{
+ if (ev_window->priv->progress_cancellable)
+ g_cancellable_reset (ev_window->priv->progress_cancellable);
+ else
+ ev_window->priv->progress_cancellable = g_cancellable_new ();
+}
+
+static void
+ev_window_progress_response_cb (EvProgressMessageArea *area,
+ gint response,
+ EvWindow *ev_window)
+{
+ if (response == GTK_RESPONSE_CANCEL)
+ g_cancellable_cancel (ev_window->priv->progress_cancellable);
+ ev_window_set_message_area (ev_window, NULL);
+}
+
+static gboolean
+show_loading_progress (EvWindow *ev_window)
+{
+ GtkWidget *area;
+ gchar *text;
+
+ if (ev_window->priv->message_area)
+ return FALSE;
+
+ text = g_strdup_printf (_("Loading document from %s"),
+ ev_window->priv->uri);
+ area = ev_progress_message_area_new (GTK_STOCK_OPEN,
+ text,
+ GTK_STOCK_CLOSE,
+ GTK_RESPONSE_CLOSE,
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_CANCEL,
+ NULL);
+ g_signal_connect (area, "response",
+ G_CALLBACK (ev_window_progress_response_cb),
+ ev_window);
+ gtk_widget_show (area);
+ ev_window_set_message_area (ev_window, area);
+ g_free (text);
+
+ return FALSE;
+}
+
+static void
+ev_window_load_remote_failed (EvWindow *ev_window,
+ GError *error)
+{
+ ev_view_set_loading (EV_VIEW (ev_window->priv->view), FALSE);
+ ev_window->priv->in_reload = FALSE;
+ ev_window_error_message (ev_window, error,
+ "%s", _("Unable to open document"));
+ g_free (ev_window->priv->local_uri);
+ ev_window->priv->local_uri = NULL;
+ ev_window->priv->uri_mtime = 0;
+}
+
+static void
+set_uri_mtime (GFile *source,
+ GAsyncResult *async_result,
+ EvWindow *ev_window)
+{
+ GFileInfo *info;
+ GError *error = NULL;
+
+ info = g_file_query_info_finish (source, async_result, &error);
+
+ if (error) {
+ ev_window->priv->uri_mtime = 0;
+ g_error_free (error);
+ } else {
+ GTimeVal mtime;
+
+ g_file_info_get_modification_time (info, &mtime);
+ ev_window->priv->uri_mtime = mtime.tv_sec;
+ g_object_unref (info);
+ }
+
+ g_object_unref (source);
+}
+
+static void
+mount_volume_ready_cb (GFile *source,
+ GAsyncResult *async_result,
+ EvWindow *ev_window)
+{
+ GError *error = NULL;
+
+ g_file_mount_enclosing_volume_finish (source, async_result, &error);
+
+ if (error) {
+ ev_window_load_remote_failed (ev_window, error);
+ g_object_unref (source);
+ g_error_free (error);
+ } else {
+ /* Volume successfully mounted,
+ try opening the file again */
+ ev_window_load_file_remote (ev_window, source);
+ }
+}
+
+static void
+window_open_file_copy_ready_cb (GFile *source,
+ GAsyncResult *async_result,
+ EvWindow *ev_window)
+{
+ GError *error = NULL;
+
+ ev_window_clear_progress_idle (ev_window);
+
+ g_file_copy_finish (source, async_result, &error);
+ if (!error) {
+ ev_job_scheduler_push_job (ev_window->priv->load_job, EV_JOB_PRIORITY_NONE);
+ g_file_query_info_async (source,
+ G_FILE_ATTRIBUTE_TIME_MODIFIED,
+ 0, G_PRIORITY_DEFAULT,
+ NULL,
+ (GAsyncReadyCallback)set_uri_mtime,
+ ev_window);
+ return;
+ }
+
+ if (error->domain == G_IO_ERROR &&
+ error->code == G_IO_ERROR_NOT_MOUNTED) {
+ GMountOperation *operation;
+
+ operation = ev_mount_operation_new (GTK_WINDOW (ev_window));
+ g_file_mount_enclosing_volume (source,
+ G_MOUNT_MOUNT_NONE,
+ operation, NULL,
+ (GAsyncReadyCallback)mount_volume_ready_cb,
+ ev_window);
+ g_object_unref (operation);
+ } else if (error->domain == G_IO_ERROR &&
+ error->code == G_IO_ERROR_CANCELLED) {
+ ev_window_clear_load_job (ev_window);
+ ev_window_clear_local_uri (ev_window);
+ ev_window_clear_print_settings_file (ev_window);
+ g_free (ev_window->priv->uri);
+ ev_window->priv->uri = NULL;
+ g_object_unref (source);
+
+ ev_view_set_loading (EV_VIEW (ev_window->priv->view), FALSE);
+ } else {
+ ev_window_load_remote_failed (ev_window, error);
+ g_object_unref (source);
+ }
+
+ g_error_free (error);
+}
+
+static void
+window_open_file_copy_progress_cb (goffset n_bytes,
+ goffset total_bytes,
+ EvWindow *ev_window)
+{
+ gchar *status;
+ gdouble fraction;
+
+ if (!ev_window->priv->message_area)
+ return;
+
+ fraction = n_bytes / (gdouble)total_bytes;
+ status = g_strdup_printf (_("Downloading document (%d%%)"),
+ (gint)(fraction * 100));
+
+ ev_progress_message_area_set_status (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
+ status);
+ ev_progress_message_area_set_fraction (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
+ fraction);
+
+ g_free (status);
+}
+
+static void
+ev_window_load_file_remote (EvWindow *ev_window,
+ GFile *source_file)
+{
+ GFile *target_file;
+
+ if (!ev_window->priv->local_uri) {
+ gchar *tmp_name;
+ gchar *base_name;
+
+ /* We'd like to keep extension of source uri since
+ * it helps to resolve some mime types, say cbz */
+ tmp_name = ev_tmp_filename (NULL);
+ base_name = g_file_get_basename (source_file);
+ ev_window->priv->local_uri = g_strconcat ("file:", tmp_name, "-",
+ base_name, NULL);
+ ev_job_load_set_uri (EV_JOB_LOAD (ev_window->priv->load_job),
+ ev_window->priv->local_uri);
+ g_free (base_name);
+ g_free (tmp_name);
+ }
+
+ ev_window_reset_progress_cancellable (ev_window);
+
+ target_file = g_file_new_for_uri (ev_window->priv->local_uri);
+ g_file_copy_async (source_file, target_file,
+ 0, G_PRIORITY_DEFAULT,
+ ev_window->priv->progress_cancellable,
+ (GFileProgressCallback)window_open_file_copy_progress_cb,
+ ev_window,
+ (GAsyncReadyCallback)window_open_file_copy_ready_cb,
+ ev_window);
+ g_object_unref (target_file);
+
+ ev_window_show_progress_message (ev_window, 1,
+ (GSourceFunc)show_loading_progress);
}
void
const char *uri,
EvLinkDest *dest,
EvWindowRunMode mode,
+ const gchar *search_string,
gboolean unlink_temp_file,
const gchar *print_settings)
{
- GnomeVFSURI *source_uri;
- GnomeVFSURI *target_uri;
+ GFile *source_file;
+
+ ev_window->priv->in_reload = FALSE;
+
+ if (ev_window->priv->uri &&
+ g_ascii_strcasecmp (ev_window->priv->uri, uri) == 0) {
+ ev_window_reload_document (ev_window);
+ return;
+ }
+
+ if (ev_window->priv->monitor) {
+ g_object_unref (ev_window->priv->monitor);
+ ev_window->priv->monitor = NULL;
+ }
ev_window_close_dialogs (ev_window);
ev_window_clear_load_job (ev_window);
ev_view_set_loading (EV_VIEW (ev_window->priv->view), TRUE);
ev_window->priv->unlink_temp_file = unlink_temp_file;
+ ev_window->priv->window_mode = mode;
if (mode == EV_WINDOW_MODE_PREVIEW) {
ev_window->priv->print_settings_file = print_settings ?
g_free (ev_window->priv->uri);
ev_window->priv->uri = g_strdup (uri);
+ if (ev_window->priv->search_string)
+ g_free (ev_window->priv->search_string);
+ ev_window->priv->search_string = search_string ?
+ g_strdup (search_string) : NULL;
+
+ if (ev_window->priv->dest)
+ g_object_unref (ev_window->priv->dest);
+ ev_window->priv->dest = dest ? g_object_ref (dest) : NULL;
+
setup_size_from_metadata (ev_window);
- ev_window->priv->load_job = ev_job_load_new (uri, dest, mode);
+ ev_window->priv->load_job = ev_job_load_new (uri);
g_signal_connect (ev_window->priv->load_job,
"finished",
G_CALLBACK (ev_window_load_job_cb),
ev_window);
- source_uri = gnome_vfs_uri_new (uri);
- if (!gnome_vfs_uri_is_local (source_uri) && !ev_window->priv->local_uri) {
- GnomeVFSAsyncHandle *handle;
- GList *slist = NULL;
- GList *tlist = NULL;
- char *tmp_name;
- char *base_name;
+ source_file = g_file_new_for_uri (uri);
+ if (!g_file_is_native (source_file) && !ev_window->priv->local_uri) {
+ ev_window_load_file_remote (ev_window, source_file);
+ } else {
+ g_object_unref (source_file);
+ ev_job_scheduler_push_job (ev_window->priv->load_job, EV_JOB_PRIORITY_NONE);
+ }
+}
- /* We'd like to keep extension of source uri since
- * it helps to resolve some mime types, say cbz */
+static void
+ev_window_reload_local (EvWindow *ev_window)
+{
+ const gchar *uri;
+
+ uri = ev_window->priv->local_uri ? ev_window->priv->local_uri : ev_window->priv->uri;
+ ev_window->priv->reload_job = ev_job_load_new (uri);
+ g_signal_connect (ev_window->priv->reload_job, "finished",
+ G_CALLBACK (ev_window_reload_job_cb),
+ ev_window);
+ ev_job_scheduler_push_job (ev_window->priv->reload_job, EV_JOB_PRIORITY_NONE);
+}
- tmp_name = ev_tmp_filename (NULL);
- base_name = gnome_vfs_uri_extract_short_name (source_uri);
- ev_window->priv->local_uri = g_strconcat ("file:", tmp_name, "-", base_name, NULL);
- ev_job_load_set_uri (EV_JOB_LOAD (ev_window->priv->load_job),
- ev_window->priv->local_uri);
- g_free (base_name);
- g_free (tmp_name);
-
- target_uri = gnome_vfs_uri_new (ev_window->priv->local_uri);
-
- slist = g_list_prepend (slist, source_uri);
- tlist = g_list_prepend (tlist, target_uri);
- gnome_vfs_async_xfer (&handle, slist, tlist,
- GNOME_VFS_XFER_DEFAULT | GNOME_VFS_XFER_FOLLOW_LINKS,
- GNOME_VFS_XFER_ERROR_MODE_ABORT,
- GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
- GNOME_VFS_PRIORITY_DEFAULT,
- (GnomeVFSAsyncXferProgressCallback)
- open_xfer_update_progress_callback,
- ev_window,
- NULL, NULL);
-
- g_list_free (slist);
- g_list_free (tlist);
- gnome_vfs_uri_unref (target_uri);
- gnome_vfs_uri_unref (source_uri);
+static gboolean
+show_reloading_progress (EvWindow *ev_window)
+{
+ GtkWidget *area;
+ gchar *text;
+
+ if (ev_window->priv->message_area)
+ return FALSE;
+
+ text = g_strdup_printf (_("Reloading document from %s"),
+ ev_window->priv->uri);
+ area = ev_progress_message_area_new (GTK_STOCK_REFRESH,
+ text,
+ GTK_STOCK_CLOSE,
+ GTK_RESPONSE_CLOSE,
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_CANCEL,
+ NULL);
+ g_signal_connect (area, "response",
+ G_CALLBACK (ev_window_progress_response_cb),
+ ev_window);
+ gtk_widget_show (area);
+ ev_window_set_message_area (ev_window, area);
+ g_free (text);
+
+ return FALSE;
+}
+
+static void
+reload_remote_copy_ready_cb (GFile *remote,
+ GAsyncResult *async_result,
+ EvWindow *ev_window)
+{
+ GError *error = NULL;
+
+ ev_window_clear_progress_idle (ev_window);
+
+ g_file_copy_finish (remote, async_result, &error);
+ if (error) {
+ if (error->domain != G_IO_ERROR ||
+ error->code != G_IO_ERROR_CANCELLED)
+ ev_window_error_message (ev_window, error,
+ "%s", _("Failed to reload document."));
+ g_error_free (error);
+ } else {
+ ev_window_reload_local (ev_window);
+ }
+ g_object_unref (remote);
+}
+
+static void
+reload_remote_copy_progress_cb (goffset n_bytes,
+ goffset total_bytes,
+ EvWindow *ev_window)
+{
+ gchar *status;
+ gdouble fraction;
+
+ if (!ev_window->priv->message_area)
return;
+
+ fraction = n_bytes / (gdouble)total_bytes;
+ status = g_strdup_printf (_("Downloading document (%d%%)"),
+ (gint)(fraction * 100));
+
+ ev_progress_message_area_set_status (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
+ status);
+ ev_progress_message_area_set_fraction (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
+ fraction);
+
+ g_free (status);
+}
+
+static void
+query_remote_uri_mtime_cb (GFile *remote,
+ GAsyncResult *async_result,
+ EvWindow *ev_window)
+{
+ GFileInfo *info;
+ GTimeVal mtime;
+ GError *error = NULL;
+
+ info = g_file_query_info_finish (remote, async_result, &error);
+ if (error) {
+ g_error_free (error);
+ g_object_unref (remote);
+ ev_window_reload_local (ev_window);
+
+ return;
+ }
+
+ g_file_info_get_modification_time (info, &mtime);
+ if (ev_window->priv->uri_mtime != mtime.tv_sec) {
+ GFile *target_file;
+
+ /* Remote file has changed */
+ ev_window->priv->uri_mtime = mtime.tv_sec;
+
+ ev_window_reset_progress_cancellable (ev_window);
+
+ target_file = g_file_new_for_uri (ev_window->priv->local_uri);
+ g_file_copy_async (remote, target_file,
+ G_FILE_COPY_OVERWRITE,
+ G_PRIORITY_DEFAULT,
+ ev_window->priv->progress_cancellable,
+ (GFileProgressCallback)reload_remote_copy_progress_cb,
+ ev_window,
+ (GAsyncReadyCallback)reload_remote_copy_ready_cb,
+ ev_window);
+ g_object_unref (target_file);
+ ev_window_show_progress_message (ev_window, 1,
+ (GSourceFunc)show_reloading_progress);
+ } else {
+ g_object_unref (remote);
+ ev_window_reload_local (ev_window);
}
+
+ g_object_unref (info);
+}
- gnome_vfs_uri_unref (source_uri);
- ev_job_queue_add_job (ev_window->priv->load_job, EV_JOB_PRIORITY_HIGH);
+static void
+ev_window_reload_remote (EvWindow *ev_window)
+{
+ GFile *remote;
+
+ remote = g_file_new_for_uri (ev_window->priv->uri);
+ /* Reload the remote uri only if it has changed */
+ g_file_query_info_async (remote,
+ G_FILE_ATTRIBUTE_TIME_MODIFIED,
+ 0, G_PRIORITY_DEFAULT,
+ NULL,
+ (GAsyncReadyCallback)query_remote_uri_mtime_cb,
+ ev_window);
+}
+
+static void
+ev_window_reload_document (EvWindow *ev_window)
+{
+ ev_window_clear_reload_job (ev_window);
+ ev_window->priv->in_reload = TRUE;
+
+ if (ev_window->priv->local_uri) {
+ ev_window_reload_remote (ev_window);
+ } else {
+ ev_window_reload_local (ev_window);
+ }
}
static void
gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (chooser),
window->priv->uri);
} else {
-#if GLIB_CHECK_VERSION (2, 13, 3)
const gchar *folder;
folder = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser),
folder ? folder : g_get_home_dir ());
-#else
- char *folder;
-
- folder = xdg_user_dir_lookup ("DOCUMENTS");
- gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser),
- folder);
- free (folder);
-#endif
}
g_signal_connect (chooser, "response",
new_filename = ev_window_create_tmp_symlink (old_filename, &error);
if (error) {
- ev_window_error_dialog (GTK_WINDOW (window),
- _("Cannot open a copy."),
- error);
-
+ ev_window_error_message (window, error,
+ "%s", _("Cannot open a copy."));
g_error_free (error);
g_free (old_filename);
g_free (new_filename);
gtk_window_get_screen (GTK_WINDOW (window)),
dest,
0,
+ NULL,
TRUE,
NULL,
GDK_CURRENT_TIME);
g_object_unref (dest);
}
-#ifdef HAVE_GTK_RECENT
static void
-ev_window_cmd_recent_file_activate (GtkAction *action,
- EvWindow *window)
+ev_window_cmd_recent_file_activate (GtkAction *action,
+ EvWindow *window)
{
GtkRecentInfo *info;
const gchar *uri;
ev_application_open_uri_at_dest (EV_APP, uri,
gtk_window_get_screen (GTK_WINDOW (window)),
- NULL, 0, FALSE, NULL,
+ NULL, 0, NULL, FALSE, NULL,
GDK_CURRENT_TIME);
}
-#else
+
static void
-ev_window_cmd_recent_file_activate (GtkAction *action,
- EvWindow *ev_window)
+ev_window_open_recent_action_item_activated (EvOpenRecentAction *action,
+ const gchar *uri,
+ EvWindow *window)
{
- char *uri;
- EggRecentItem *item;
-
- item = egg_recent_view_uimanager_get_item (ev_window->priv->recent_view,
- action);
-
- uri = egg_recent_item_get_uri (item);
-
ev_application_open_uri_at_dest (EV_APP, uri,
- gtk_window_get_screen (GTK_WINDOW (ev_window)),
- NULL, 0, FALSE, NULL,
+ gtk_window_get_screen (GTK_WINDOW (window)),
+ NULL, 0, NULL, FALSE, NULL,
GDK_CURRENT_TIME);
-
- g_free (uri);
}
-#endif /* HAVE_GTK_RECENT */
static void
ev_window_add_recent (EvWindow *window, const char *filename)
{
-#ifdef HAVE_GTK_RECENT
gtk_recent_manager_add_item (window->priv->recent_manager, filename);
-#else
- EggRecentItem *item;
-
- item = egg_recent_item_new_from_uri (filename);
- egg_recent_item_add_group (item, "Evince");
- egg_recent_model_add_full (ev_application_get_recent_model (EV_APP), item);
-#endif /* HAVE_GTK_RECENT */
}
-#ifdef HAVE_GTK_RECENT
static gint
compare_recent_items (GtkRecentInfo *a, GtkRecentInfo *b)
{
return 0;
}
-#endif /* HAVE_GTK_RECENT */
/*
* Doubles underscore to avoid spurious menu accels.
gint length;
const gchar *p;
const gchar *end;
-
+ gboolean is_rtl;
+
+ is_rtl = (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL);
+
g_return_val_if_fail (filename != NULL, NULL);
length = strlen (filename);
str = g_string_sized_new (length + 10);
- g_string_printf (str, "_%d. ", index);
+ g_string_printf (str, "%s_%d. ", is_rtl ? "\xE2\x80\x8F" : "", index);
p = filename;
end = filename + length;
static void
ev_window_setup_recent (EvWindow *ev_window)
{
-#ifdef HAVE_GTK_RECENT
GList *items, *l;
guint n_items = 0;
const gchar *evince = g_get_application_name ();
gtk_recent_info_ref (info),
(GDestroyNotify) gtk_recent_info_unref);
- g_signal_connect (G_OBJECT (action), "activate",
+ g_signal_connect (action, "activate",
G_CALLBACK (ev_window_cmd_recent_file_activate),
(gpointer) ev_window);
g_list_foreach (items, (GFunc) gtk_recent_info_unref, NULL);
g_list_free (items);
-#else /* HAVE_GTK_RECENT */
- ev_window->priv->recent_view = egg_recent_view_uimanager_new (ev_window->priv->ui_manager,
- "/MainMenu/FileMenu/RecentFilesMenu",
- G_CALLBACK (ev_window_cmd_recent_file_activate),
- ev_window);
-
- egg_recent_view_uimanager_show_icons (EGG_RECENT_VIEW_UIMANAGER (ev_window->priv->recent_view), FALSE);
+}
- egg_recent_view_set_model (EGG_RECENT_VIEW (ev_window->priv->recent_view),
- ev_application_get_recent_model (EV_APP));
+static gboolean
+show_saving_progress (GFile *dst)
+{
+ EvWindow *ev_window;
+ GtkWidget *area;
+ gchar *text;
+ gchar *uri;
+ EvSaveType save_type;
- egg_recent_view_uimanager_set_trailing_sep (ev_window->priv->recent_view, TRUE);
+ ev_window = EV_WINDOW (g_object_get_data (G_OBJECT (dst), "ev-window"));
+ ev_window->priv->progress_idle = 0;
- g_signal_connect (ev_window->priv->recent_view, "activate",
- G_CALLBACK (ev_window_cmd_recent_file_activate), ev_window);
-#endif /* HAVE_GTK_RECENT */
-}
+ if (ev_window->priv->message_area)
+ return FALSE;
-static gint
-save_xfer_update_progress_callback (GnomeVFSAsyncHandle *handle,
- GnomeVFSXferProgressInfo *info,
- GnomeVFSURI *tmp_uri)
-{
- switch (info->status) {
- case GNOME_VFS_XFER_PROGRESS_STATUS_OK:
- if (info->phase == GNOME_VFS_XFER_PHASE_COMPLETED) {
- gchar *uri;
-
- uri = gnome_vfs_uri_to_string (tmp_uri, 0);
- ev_tmp_uri_unlink (uri);
- g_free (uri);
- gnome_vfs_uri_unref (tmp_uri);
- }
- return 1;
- case GNOME_VFS_XFER_PROGRESS_STATUS_VFSERROR:
- if (info->vfs_status != GNOME_VFS_OK) {
- GtkWidget *dialog;
- gchar *uri;
-
- dialog = gtk_message_dialog_new (NULL,
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_CLOSE,
- _("The file could not be saved as “%s”."),
- info->target_name);
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- gnome_vfs_result_to_string (info->vfs_status));
-
- g_signal_connect (dialog, "response",
- G_CALLBACK (gtk_widget_destroy),
- NULL);
- gtk_widget_show (dialog);
-
- uri = gnome_vfs_uri_to_string (tmp_uri, 0);
- ev_tmp_uri_unlink (uri);
- g_free (uri);
- gnome_vfs_uri_unref (tmp_uri);
- }
- return 1;
- case GNOME_VFS_XFER_PROGRESS_STATUS_OVERWRITE:
- case GNOME_VFS_XFER_PROGRESS_STATUS_DUPLICATE:
- return 1;
- default:
- g_assert_not_reached ();
+ save_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dst), "save-type"));
+ uri = g_file_get_uri (dst);
+ switch (save_type) {
+ case EV_SAVE_DOCUMENT:
+ text = g_strdup_printf (_("Saving document to %s"), uri);
+ break;
+ case EV_SAVE_ATTACHMENT:
+ text = g_strdup_printf (_("Saving attachment to %s"), uri);
+ break;
+ case EV_SAVE_IMAGE:
+ text = g_strdup_printf (_("Saving image to %s"), uri);
+ break;
+ default:
+ g_assert_not_reached ();
}
+ g_free (uri);
+ area = ev_progress_message_area_new (GTK_STOCK_SAVE,
+ text,
+ GTK_STOCK_CLOSE,
+ GTK_RESPONSE_CLOSE,
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_CANCEL,
+ NULL);
+ g_signal_connect (area, "response",
+ G_CALLBACK (ev_window_progress_response_cb),
+ ev_window);
+ gtk_widget_show (area);
+ ev_window_set_message_area (ev_window, area);
+ g_free (text);
- return 0;
+ return FALSE;
}
static void
-ev_window_save_remote (EvWindow *ev_window,
- GnomeVFSURI *src,
- GnomeVFSURI *dst)
+window_save_file_copy_ready_cb (GFile *src,
+ GAsyncResult *async_result,
+ GFile *dst)
{
- GnomeVFSAsyncHandle *handle;
- GList *slist = NULL;
- GList *tlist = NULL;
+ EvWindow *ev_window;
+ GError *error = NULL;
+
+ ev_window = EV_WINDOW (g_object_get_data (G_OBJECT (dst), "ev-window"));
+ ev_window_clear_progress_idle (ev_window);
- slist = g_list_prepend (slist, src);
- tlist = g_list_prepend (tlist, dst);
- gnome_vfs_async_xfer (&handle, slist, tlist,
- GNOME_VFS_XFER_DEFAULT | GNOME_VFS_XFER_FOLLOW_LINKS,
- GNOME_VFS_XFER_ERROR_MODE_ABORT,
- GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
- GNOME_VFS_PRIORITY_DEFAULT,
- (GnomeVFSAsyncXferProgressCallback)
- save_xfer_update_progress_callback,
- gnome_vfs_uri_ref (src),
- NULL, NULL);
- g_list_free (slist);
- g_list_free (tlist);
+ if (g_file_copy_finish (src, async_result, &error)) {
+ ev_tmp_file_unlink (src);
+ return;
+ }
+
+ if (error->domain != G_IO_ERROR ||
+ error->code != G_IO_ERROR_CANCELLED) {
+ gchar *name;
+
+ name = g_file_get_basename (dst);
+ ev_window_error_message (ev_window, error,
+ _("The file could not be saved as “%s”."),
+ name);
+ g_free (name);
+ }
+ ev_tmp_file_unlink (src);
+ g_error_free (error);
}
static void
-file_save_dialog_response_cb (GtkWidget *fc,
- gint response_id,
- EvWindow *ev_window)
+window_save_file_copy_progress_cb (goffset n_bytes,
+ goffset total_bytes,
+ GFile *dst)
{
- gchar *uri;
- gchar *local_uri;
- gint fd;
- gchar *filename;
- gchar *tmp_filename;
- GError *error = NULL;
+ EvWindow *ev_window;
+ EvSaveType save_type;
+ gchar *status;
+ gdouble fraction;
- if (response_id != GTK_RESPONSE_OK) {
- gtk_widget_destroy (fc);
+ ev_window = EV_WINDOW (g_object_get_data (G_OBJECT (dst), "ev-window"));
+
+ if (!ev_window->priv->message_area)
return;
- }
-
- uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
+
+ fraction = n_bytes / (gdouble)total_bytes;
+ save_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dst), "save-type"));
- filename = ev_tmp_filename ("saveacopy");
- tmp_filename = g_strdup_printf ("%s.XXXXXX", filename);
- g_free (filename);
+ switch (save_type) {
+ case EV_SAVE_DOCUMENT:
+ status = g_strdup_printf (_("Uploading document (%d%%)"),
+ (gint)(fraction * 100));
+ break;
+ case EV_SAVE_ATTACHMENT:
+ status = g_strdup_printf (_("Uploading attachment (%d%%)"),
+ (gint)(fraction * 100));
+ break;
+ case EV_SAVE_IMAGE:
+ status = g_strdup_printf (_("Uploading image (%d%%)"),
+ (gint)(fraction * 100));
+ break;
+ default:
+ g_assert_not_reached ();
+ }
- fd = g_mkstemp (tmp_filename);
- if (fd == -1) {
- gchar *msg;
- gchar *display_name;
- gint save_errno = errno;
-
- display_name = g_filename_display_name (tmp_filename);
- g_set_error (&error,
- G_FILE_ERROR,
- g_file_error_from_errno (save_errno),
- _("Failed to create file “%s”: %s"),
- display_name, g_strerror (save_errno));
- g_free (display_name);
+ ev_progress_message_area_set_status (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
+ status);
+ ev_progress_message_area_set_fraction (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
+ fraction);
- msg = g_strdup_printf (_("The file could not be saved as “%s”."), uri);
- ev_window_error_dialog (GTK_WINDOW (ev_window), msg, error);
+ g_free (status);
+}
- g_free (tmp_filename);
- g_free (uri);
- g_free (msg);
- g_error_free (error);
- gtk_widget_destroy (fc);
+static void
+ev_window_save_remote (EvWindow *ev_window,
+ EvSaveType save_type,
+ GFile *src,
+ GFile *dst)
+{
+ ev_window_reset_progress_cancellable (ev_window);
+ g_object_set_data (G_OBJECT (dst), "ev-window", ev_window);
+ g_object_set_data (G_OBJECT (dst), "save-type", GINT_TO_POINTER (save_type));
+ g_file_copy_async (src, dst,
+ G_FILE_COPY_OVERWRITE,
+ G_PRIORITY_DEFAULT,
+ ev_window->priv->progress_cancellable,
+ (GFileProgressCallback)window_save_file_copy_progress_cb,
+ dst,
+ (GAsyncReadyCallback)window_save_file_copy_ready_cb,
+ dst);
+ ev_window->priv->progress_idle =
+ g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
+ 1,
+ (GSourceFunc)show_saving_progress,
+ dst,
+ NULL);
+}
+
+static void
+ev_window_clear_save_job (EvWindow *ev_window)
+{
+ if (ev_window->priv->save_job != NULL) {
+ if (!ev_job_is_finished (ev_window->priv->save_job))
+ ev_job_cancel (ev_window->priv->save_job);
- return;
+ g_signal_handlers_disconnect_by_func (ev_window->priv->save_job,
+ ev_window_save_job_cb,
+ ev_window);
+ g_object_unref (ev_window->priv->save_job);
+ ev_window->priv->save_job = NULL;
}
+}
- /* Save document to temp filename */
- local_uri = g_filename_to_uri (tmp_filename, NULL, NULL);
-
- ev_document_doc_mutex_lock ();
- ev_document_save (ev_window->priv->document, local_uri, &error);
- ev_document_doc_mutex_unlock ();
-
- close (fd);
-
- if (!error) {
- /* If original document was compressed,
- * compress it again before saving
- */
- if (g_object_get_data (G_OBJECT (ev_window->priv->document),
- "uri-uncompressed")) {
- EvCompressionType ctype = EV_COMPRESSION_NONE;
- const gchar *ext;
- gchar *uri_comp;
-
- ext = g_strrstr (ev_window->priv->uri, ".gz");
- if (ext && g_ascii_strcasecmp (ext, ".gz") == 0)
- ctype = EV_COMPRESSION_GZIP;
-
- ext = g_strrstr (ev_window->priv->uri, ".bz2");
- if (ext && g_ascii_strcasecmp (ext, ".bz2") == 0)
- ctype = EV_COMPRESSION_BZIP2;
-
- uri_comp = ev_file_compress (local_uri, ctype, &error);
- g_free (local_uri);
- ev_tmp_filename_unlink (tmp_filename);
-
- if (!uri_comp || error) {
- local_uri = NULL;
- } else {
- local_uri = uri_comp;
- }
- }
+static void
+ev_window_save_job_cb (EvJob *job,
+ EvWindow *window)
+{
+ if (ev_job_is_failed (job)) {
+ ev_window_error_message (window, job->error,
+ _("The file could not be saved as “%s”."),
+ EV_JOB_SAVE (job)->uri);
}
- g_free (tmp_filename);
-
- if (error) {
- gchar *msg;
+ ev_window_clear_save_job (window);
+}
- msg = g_strdup_printf (_("The file could not be saved as “%s”."), uri);
- ev_window_error_dialog (GTK_WINDOW (ev_window), msg, error);
- g_free (uri);
- g_free (msg);
- g_error_free (error);
- g_free (local_uri);
+static void
+file_save_dialog_response_cb (GtkWidget *fc,
+ gint response_id,
+ EvWindow *ev_window)
+{
+ gchar *uri;
+
+ if (response_id != GTK_RESPONSE_OK) {
gtk_widget_destroy (fc);
-
return;
}
-
- if (local_uri) {
- GnomeVFSURI *target_uri;
-
- target_uri = gnome_vfs_uri_new (uri);
- if (gnome_vfs_uri_is_local (target_uri)) {
- /* If target uri is local, just rename local_uri */
- if (gnome_vfs_move (local_uri, uri, TRUE) != GNOME_VFS_OK)
- ev_tmp_uri_unlink (local_uri);
- } else {
- GnomeVFSURI *source_uri;
-
- source_uri = gnome_vfs_uri_new (local_uri);
- ev_window_save_remote (ev_window, source_uri, target_uri);
- gnome_vfs_uri_unref (source_uri);
- }
-
- gnome_vfs_uri_unref (target_uri);
- g_free (local_uri);
- }
+
+ uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
+ /* FIXME: remote copy should be done here rather than in the save job,
+ * so that we can track progress and cancel the operation
+ */
+
+ ev_window_clear_save_job (ev_window);
+ ev_window->priv->save_job = ev_job_save_new (ev_window->priv->document,
+ uri, ev_window->priv->uri);
+ g_signal_connect (ev_window->priv->save_job, "finished",
+ G_CALLBACK (ev_window_save_job_cb),
+ ev_window);
+ /* The priority doesn't matter for this job */
+ ev_job_scheduler_push_job (ev_window->priv->save_job, EV_JOB_PRIORITY_NONE);
g_free (uri);
gtk_widget_destroy (fc);
{
GtkWidget *fc;
gchar *base_name;
- gchar *file_name;
-#if GLIB_CHECK_VERSION (2, 13, 3)
+ GFile *file;
const gchar *folder;
-#else
- gchar *folder;
-#endif
fc = gtk_file_chooser_dialog_new (
_("Save a Copy"),
GTK_STOCK_SAVE, GTK_RESPONSE_OK,
NULL);
- ev_document_factory_add_filters (fc, ev_window->priv->document);
- gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
+ ev_document_factory_add_filters (fc, ev_window->priv->document);
+ gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
+
+ gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (fc), FALSE);
+ gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
+ file = g_file_new_for_uri (ev_window->priv->uri);
+ base_name = g_file_get_basename (file);
+ gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc), base_name);
+
+ folder = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (fc),
+ folder ? folder : g_get_home_dir ());
+
+ g_object_unref (file);
+ g_free (base_name);
+
+ g_signal_connect (fc, "response",
+ G_CALLBACK (file_save_dialog_response_cb),
+ ev_window);
+
+ gtk_widget_show (fc);
+}
+
+static void
+ev_window_load_print_settings_from_metadata (EvWindow *window)
+{
+ gchar *uri = window->priv->uri;
+ gint i;
+
+ /* Load print setting that are specific to the document */
+ for (i = 0; i < G_N_ELEMENTS (document_print_settings); i++) {
+ GValue value = { 0, };
+ gboolean success;
+
+ success = ev_metadata_manager_get (uri, document_print_settings[i], &value, TRUE);
+ gtk_print_settings_set (window->priv->print_settings,
+ document_print_settings[i],
+ success ? g_value_get_string (&value) : NULL);
+ if (success)
+ g_value_unset (&value);
+ }
+}
+
+static void
+ev_window_save_print_settings (EvWindow *window)
+{
+ gchar *uri = window->priv->uri;
+ gint i;
+
+ /* Save print settings that are specific to the document */
+ for (i = 0; i < G_N_ELEMENTS (document_print_settings); i++) {
+ const gchar *value;
+
+ value = gtk_print_settings_get (window->priv->print_settings,
+ document_print_settings[i]);
+ ev_metadata_manager_set_string (uri, document_print_settings[i], value);
+ }
+}
+
+static void
+ev_window_save_print_page_setup (EvWindow *window)
+{
+ gchar *uri = window->priv->uri;
+ GtkPageSetup *page_setup = window->priv->print_page_setup;
+
+ /* Save page setup options that are specific to the document */
+ ev_metadata_manager_set_int (uri, "page-setup-orientation",
+ gtk_page_setup_get_orientation (page_setup));
+ ev_metadata_manager_set_double (uri, "page-setup-margin-top",
+ gtk_page_setup_get_top_margin (page_setup, GTK_UNIT_MM));
+ ev_metadata_manager_set_double (uri, "page-setup-margin-bottom",
+ gtk_page_setup_get_bottom_margin (page_setup, GTK_UNIT_MM));
+ ev_metadata_manager_set_double (uri, "page-setup-margin-left",
+ gtk_page_setup_get_left_margin (page_setup, GTK_UNIT_MM));
+ ev_metadata_manager_set_double (uri, "page-setup-margin-right",
+ gtk_page_setup_get_right_margin (page_setup, GTK_UNIT_MM));
+}
- gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (fc), FALSE);
- gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
- file_name = gnome_vfs_format_uri_for_display (ev_window->priv->uri);
- base_name = g_path_get_basename (file_name);
- gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc), base_name);
+static void
+ev_window_load_print_page_setup_from_metadata (EvWindow *window)
+{
+ gchar *uri = window->priv->uri;
+ GtkPageSetup *page_setup = window->priv->print_page_setup;
+ GtkPaperSize *paper_size;
+ GValue value = { 0, };
+
+ paper_size = gtk_page_setup_get_paper_size (page_setup);
-#if GLIB_CHECK_VERSION (2, 13, 3)
- folder = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
- gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (fc),
- folder ? folder : g_get_home_dir ());
-#else
- folder = xdg_user_dir_lookup ("DOCUMENTS");
- gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (fc), folder);
- free (folder);
-#endif
+ /* Load page setup options that are specific to the document */
+ if (ev_metadata_manager_get (uri, "page-setup-orientation", &value, TRUE)) {
+ gtk_page_setup_set_orientation (page_setup, g_value_get_int (&value));
+ g_value_unset (&value);
+ } else {
+ gtk_page_setup_set_orientation (page_setup, GTK_PAGE_ORIENTATION_PORTRAIT);
+ }
- g_free (file_name);
- g_free (base_name);
-
- g_signal_connect (fc, "response",
- G_CALLBACK (file_save_dialog_response_cb),
- ev_window);
+ if (ev_metadata_manager_get (uri, "page-setup-margin-top", &value, TRUE)) {
+ gtk_page_setup_set_top_margin (page_setup, g_value_get_double (&value), GTK_UNIT_MM);
+ g_value_unset (&value);
+ } else {
+ gtk_page_setup_set_top_margin (page_setup,
+ gtk_paper_size_get_default_top_margin (paper_size, GTK_UNIT_MM),
+ GTK_UNIT_MM);
+ }
- gtk_widget_show (fc);
+ if (ev_metadata_manager_get (uri, "page-setup-margin-bottom", &value, TRUE)) {
+ gtk_page_setup_set_bottom_margin (page_setup, g_value_get_double (&value), GTK_UNIT_MM);
+ g_value_unset (&value);
+ } else {
+ gtk_page_setup_set_bottom_margin (page_setup,
+ gtk_paper_size_get_default_bottom_margin (paper_size, GTK_UNIT_MM),
+ GTK_UNIT_MM);
+ }
+
+ if (ev_metadata_manager_get (uri, "page-setup-margin-left", &value, TRUE)) {
+ gtk_page_setup_set_left_margin (page_setup, g_value_get_double (&value), GTK_UNIT_MM);
+ g_value_unset (&value);
+ } else {
+ gtk_page_setup_set_left_margin (page_setup,
+ gtk_paper_size_get_default_left_margin (paper_size, GTK_UNIT_MM),
+ GTK_UNIT_MM);
+ }
+
+ if (ev_metadata_manager_get (uri, "page-setup-margin-right", &value, TRUE)) {
+ gtk_page_setup_set_right_margin (page_setup, g_value_get_double (&value), GTK_UNIT_MM);
+ g_value_unset (&value);
+ } else {
+ gtk_page_setup_set_right_margin (page_setup,
+ gtk_paper_size_get_default_right_margin (paper_size, GTK_UNIT_MM),
+ GTK_UNIT_MM);
+ }
}
-#ifdef WITH_GTK_PRINT
static void
ev_window_print_page_setup_done_cb (GtkPageSetup *page_setup,
EvWindow *window)
if (!page_setup)
return;
- if (window->priv->print_page_setup)
- g_object_unref (window->priv->print_page_setup);
- window->priv->print_page_setup = g_object_ref (page_setup);
+ if (window->priv->print_page_setup != page_setup) {
+ if (window->priv->print_page_setup)
+ g_object_unref (window->priv->print_page_setup);
+ window->priv->print_page_setup = g_object_ref (page_setup);
+ }
+
+ ev_application_set_page_setup (EV_APP, page_setup);
+ ev_window_save_print_page_setup (window);
}
-#endif /* WITH_GTK_PRINT */
static void
ev_window_cmd_file_print_setup (GtkAction *action, EvWindow *ev_window)
{
-#ifdef WITH_GTK_PRINT
+ if (!ev_window->priv->print_page_setup) {
+ ev_window->priv->print_page_setup = gtk_page_setup_copy (
+ ev_application_get_page_setup (EV_APP));
+ ev_window_load_print_page_setup_from_metadata (ev_window);
+ }
+
gtk_print_run_page_setup_dialog_async (
GTK_WINDOW (ev_window),
ev_window->priv->print_page_setup,
ev_window->priv->print_settings,
(GtkPageSetupDoneFunc) ev_window_print_page_setup_done_cb,
ev_window);
-#endif /* WITH_GTK_PRINT */
}
-#ifdef WITH_GTK_PRINT
static void
-ev_window_clear_print_job (EvWindow *window)
+ev_window_print_cancel (EvWindow *ev_window)
{
- if (window->priv->print_job) {
- if (!window->priv->print_job->finished)
- ev_job_queue_remove_job (window->priv->print_job);
-
- g_signal_handlers_disconnect_by_func (window->priv->print_job,
- ev_window_print_job_cb,
- window);
- g_object_unref (window->priv->print_job);
- window->priv->print_job = NULL;
- }
+ EvPrintOperation *op;
+
+ if (!ev_window->priv->print_queue)
+ return;
- if (window->priv->gtk_print_job) {
- g_object_unref (window->priv->gtk_print_job);
- window->priv->gtk_print_job = NULL;
+ while ((op = g_queue_peek_tail (ev_window->priv->print_queue))) {
+ ev_print_operation_cancel (op);
}
}
static void
-ev_window_print_finished (GtkPrintJob *print_job,
- EvWindow *window,
- GError *error)
+ev_window_print_update_pending_jobs_message (EvWindow *ev_window,
+ gint n_jobs)
{
- ev_window_clear_print_job (window);
+ gchar *text = NULL;
- if (error) {
- GtkWidget *dialog;
-
- dialog = gtk_message_dialog_new (GTK_WINDOW (window),
- GTK_DIALOG_MODAL,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- _("Failed to print document"));
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- error->message);
+ if (!EV_IS_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area) ||
+ !ev_window->priv->print_queue)
+ return;
- gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
- } else {
- /* If printed successfully, save print settings */
- ev_application_set_print_settings (EV_APP,
- window->priv->print_settings);
+ if (n_jobs == 0) {
+ ev_window_set_message_area (ev_window, NULL);
+ return;
+ }
+
+ if (n_jobs > 1) {
+ text = g_strdup_printf (ngettext ("%d pending job in queue",
+ "%d pending jobs in queue",
+ n_jobs - 1), n_jobs - 1);
}
+
+ ev_message_area_set_secondary_text (EV_MESSAGE_AREA (ev_window->priv->message_area),
+ text);
+ g_free (text);
+}
+
+static gboolean
+destroy_window (GtkWidget *window)
+{
+ gtk_widget_destroy (window);
+
+ return FALSE;
}
static void
-ev_window_print_send (EvWindow *window,
- const gchar *filename)
+ev_window_print_operation_done (EvPrintOperation *op,
+ GtkPrintOperationResult result,
+ EvWindow *ev_window)
{
- GtkPrintSettings *settings;
- EvFileExporterCapabilities capabilities;
+ gint n_jobs;
- /* Some printers take into account some print settings,
- * and others don't. However we have exported the document
- * to a ps or pdf file according to such print settings. So,
- * we want to send the exported file to printer with those
- * settings set to default values.
- */
- settings = gtk_print_settings_copy (window->priv->print_settings);
- capabilities = ev_file_exporter_get_capabilities (EV_FILE_EXPORTER (window->priv->document));
-
- gtk_print_settings_set_page_ranges (settings, NULL, 0);
- gtk_print_settings_set_print_pages (settings, GTK_PRINT_PAGES_ALL);
- if (capabilities & EV_FILE_EXPORTER_CAN_COPIES)
- gtk_print_settings_set_n_copies (settings, 1);
- if (capabilities & EV_FILE_EXPORTER_CAN_PAGE_SET)
- gtk_print_settings_set_page_set (settings, GTK_PAGE_SET_ALL);
- if (capabilities & EV_FILE_EXPORTER_CAN_SCALE)
- gtk_print_settings_set_scale (settings, 1.0);
- if (capabilities & EV_FILE_EXPORTER_CAN_COLLATE)
- gtk_print_settings_set_collate (settings, FALSE);
- if (capabilities & EV_FILE_EXPORTER_CAN_REVERSE)
- gtk_print_settings_set_reverse (settings, FALSE);
- if (capabilities & EV_FILE_EXPORTER_CAN_NUMBER_UP) {
- gtk_print_settings_set_number_up (settings, 1);
- gtk_print_settings_set_int (settings, "cups-"GTK_PRINT_SETTINGS_NUMBER_UP, 1);
- }
-
- if (window->priv->print_preview) {
- gchar *uri;
- gchar *print_settings_file = NULL;
-
- ev_application_set_print_settings (EV_APP,
- window->priv->print_settings);
+ switch (result) {
+ case GTK_PRINT_OPERATION_RESULT_APPLY: {
+ GtkPrintSettings *print_settings;
-#if GTK_CHECK_VERSION (2, 11, 0)
- print_settings_file = ev_tmp_filename ("print-settings");
- gtk_print_settings_to_file (settings, print_settings_file, NULL);
-#endif
- uri = g_filename_to_uri (filename, NULL, NULL);
- ev_application_open_uri_at_dest (EV_APP,
- uri,
- gtk_window_get_screen (GTK_WINDOW (window)),
- NULL,
- EV_WINDOW_MODE_PREVIEW,
- TRUE,
- print_settings_file,
- GDK_CURRENT_TIME);
- g_free (print_settings_file);
- g_free (uri);
- } else {
- GtkPrintJob *job;
- GError *error = NULL;
-
- job = gtk_print_job_new ("evince-print",
- window->priv->printer,
- settings,
- window->priv->print_page_setup);
-
- if (window->priv->gtk_print_job)
- g_object_unref (window->priv->gtk_print_job);
- window->priv->gtk_print_job = job;
-
- if (gtk_print_job_set_source_file (job, filename, &error)) {
- gtk_print_job_send (job,
- (GtkPrintJobCompleteFunc)ev_window_print_finished,
- window, NULL);
- } else {
- ev_window_clear_print_job (window);
- g_warning (error->message);
- g_error_free (error);
+ print_settings = ev_print_operation_get_print_settings (op);
+ if (ev_window->priv->print_settings != print_settings) {
+ if (ev_window->priv->print_settings)
+ g_object_unref (ev_window->priv->print_settings);
+ ev_window->priv->print_settings = g_object_ref (print_settings);
}
+
+ ev_application_set_print_settings (EV_APP, print_settings);
+ ev_window_save_print_settings (ev_window);
}
- g_object_unref (settings);
-}
+ break;
+ case GTK_PRINT_OPERATION_RESULT_ERROR: {
+ GtkWidget *dialog;
+ GError *error = NULL;
-static void
-ev_window_print_job_cb (EvJobPrint *job,
- EvWindow *window)
-{
- if (job->error) {
- g_warning (job->error->message);
- ev_window_clear_print_job (window);
- return;
+
+ ev_print_operation_get_error (op, &error);
+
+ /* The message area is already used by
+ * the printing progress, so it's better to
+ * use a popup dialog in this case
+ */
+ dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "%s", _("Failed to print document"));
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ "%s", error->message);
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (gtk_widget_destroy),
+ NULL);
+ gtk_widget_show (dialog);
+
+ g_error_free (error);
+ }
+ break;
+ case GTK_PRINT_OPERATION_RESULT_CANCEL:
+ default:
+ break;
}
- g_assert (job->temp_file != NULL);
+ g_queue_remove (ev_window->priv->print_queue, op);
+ g_object_unref (op);
+ n_jobs = g_queue_get_length (ev_window->priv->print_queue);
+ ev_window_print_update_pending_jobs_message (ev_window, n_jobs);
- ev_window_print_send (window, job->temp_file);
+ if (n_jobs == 0 && ev_window->priv->close_after_print)
+ g_idle_add ((GSourceFunc)destroy_window,
+ ev_window);
}
-static gboolean
-ev_window_print_dialog_response_cb (GtkDialog *dialog,
- gint response,
- EvWindow *window)
+static void
+ev_window_print_progress_response_cb (EvProgressMessageArea *area,
+ gint response,
+ EvWindow *ev_window)
{
- EvPrintRange *ranges = NULL;
- EvPrintPageSet page_set;
- gint n_ranges = 0;
- gint copies;
- gint pages_per_sheet;
- gboolean collate;
- gboolean reverse;
- gdouble scale;
- gint current_page;
- gdouble width;
- gdouble height;
- GtkPrintPages print_pages;
- const gchar *file_format;
-
if (response == GTK_RESPONSE_CANCEL) {
- gtk_widget_destroy (GTK_WIDGET (dialog));
- window->priv->print_dialog = NULL;
+ EvPrintOperation *op;
- return FALSE;
+ op = g_queue_peek_tail (ev_window->priv->print_queue);
+ ev_print_operation_cancel (op);
+ } else {
+ gtk_widget_hide (GTK_WIDGET (area));
}
+}
- window->priv->print_preview = (response == GTK_RESPONSE_APPLY);
-
- if (window->priv->printer)
- g_object_unref (window->priv->printer);
- if (window->priv->print_settings)
- g_object_unref (window->priv->print_settings);
- if (window->priv->print_page_setup)
- g_object_unref (window->priv->print_page_setup);
-
- window->priv->printer = g_object_ref (
- gtk_print_unix_dialog_get_selected_printer (GTK_PRINT_UNIX_DIALOG (dialog)));
- window->priv->print_settings = g_object_ref (
- gtk_print_unix_dialog_get_settings (GTK_PRINT_UNIX_DIALOG (dialog)));
- window->priv->print_page_setup = g_object_ref (
- gtk_print_unix_dialog_get_page_setup (GTK_PRINT_UNIX_DIALOG (dialog)));
+static void
+ev_window_print_operation_status_changed (EvPrintOperation *op,
+ EvWindow *ev_window)
+{
+ const gchar *status;
+ gdouble fraction;
- file_format = gtk_print_settings_get (window->priv->print_settings,
- GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT);
+ status = ev_print_operation_get_status (op);
+ fraction = ev_print_operation_get_progress (op);
- if (!gtk_printer_accepts_ps (window->priv->printer)) {
- GtkWidget *msgdialog;
+ if (!ev_window->priv->message_area) {
+ GtkWidget *area;
+ const gchar *job_name;
+ gchar *text;
- msgdialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
- GTK_DIALOG_MODAL,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- _("Printing is not supported on this printer."));
-
- gtk_dialog_run (GTK_DIALOG (msgdialog));
- gtk_widget_destroy (msgdialog);
-
- return FALSE;
- }
+ job_name = ev_print_operation_get_job_name (op);
+ text = g_strdup_printf (_("Printing job “%s”"), job_name);
- ev_window_clear_print_job (window);
-
- current_page = gtk_print_unix_dialog_get_current_page (GTK_PRINT_UNIX_DIALOG (dialog));
- print_pages = gtk_print_settings_get_print_pages (window->priv->print_settings);
-
- switch (print_pages) {
- case GTK_PRINT_PAGES_CURRENT:
- ranges = g_new0 (EvPrintRange, 1);
-
- ranges->start = current_page;
- ranges->end = current_page;
- n_ranges = 1;
-
- break;
- case GTK_PRINT_PAGES_RANGES: {
- GtkPageRange *page_range;
-
- page_range = gtk_print_settings_get_page_ranges (window->priv->print_settings,
- &n_ranges);
- if (n_ranges > 0)
- ranges = g_memdup (page_range, n_ranges * sizeof (GtkPageRange));
- }
- break;
- default:
- break;
+ area = ev_progress_message_area_new (GTK_STOCK_PRINT,
+ text,
+ GTK_STOCK_CLOSE,
+ GTK_RESPONSE_CLOSE,
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_CANCEL,
+ NULL);
+ ev_window_print_update_pending_jobs_message (ev_window, 1);
+ g_signal_connect (area, "response",
+ G_CALLBACK (ev_window_print_progress_response_cb),
+ ev_window);
+ gtk_widget_show (area);
+ ev_window_set_message_area (ev_window, area);
+ g_free (text);
}
- page_set = (EvPrintPageSet)gtk_print_settings_get_page_set (window->priv->print_settings);
+ ev_progress_message_area_set_status (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
+ status);
+ ev_progress_message_area_set_fraction (EV_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area),
+ fraction);
+}
- scale = gtk_print_settings_get_scale (window->priv->print_settings) * 0.01;
-
- width = gtk_page_setup_get_paper_width (window->priv->print_page_setup,
- GTK_UNIT_POINTS);
- height = gtk_page_setup_get_paper_height (window->priv->print_page_setup,
- GTK_UNIT_POINTS);
+static void
+ev_window_print_operation_begin_print (EvPrintOperation *op,
+ EvWindow *ev_window)
+{
+ GtkPrintSettings *print_settings;
- if (scale != 1.0) {
- width *= scale;
- height *= scale;
- }
+ if (!ev_window->priv->print_queue)
+ ev_window->priv->print_queue = g_queue_new ();
- pages_per_sheet = gtk_print_settings_get_number_up (window->priv->print_settings);
-
- copies = gtk_print_settings_get_n_copies (window->priv->print_settings);
- collate = gtk_print_settings_get_collate (window->priv->print_settings);
- reverse = gtk_print_settings_get_reverse (window->priv->print_settings);
-
- window->priv->print_job = ev_job_print_new (window->priv->document,
- file_format ? file_format : "ps",
- width, height,
- ranges, n_ranges,
- page_set,
- pages_per_sheet,
- copies, collate,
- reverse);
-
- g_signal_connect (window->priv->print_job, "finished",
- G_CALLBACK (ev_window_print_job_cb),
- window);
- /* The priority doesn't matter for this job */
- ev_job_queue_add_job (window->priv->print_job, EV_JOB_PRIORITY_LOW);
+ g_queue_push_head (ev_window->priv->print_queue, op);
+ ev_window_print_update_pending_jobs_message (ev_window,
+ g_queue_get_length (ev_window->priv->print_queue));
- gtk_widget_destroy (GTK_WIDGET (dialog));
- window->priv->print_dialog = NULL;
-
- return TRUE;
+ if (ev_window->priv->print_settings)
+ g_object_unref (ev_window->priv->print_settings);
+ print_settings = ev_print_operation_get_print_settings (op);
+ ev_window->priv->print_settings = g_object_ref (print_settings);
}
void
-ev_window_print_range (EvWindow *ev_window, int first_page, int last_page)
+ev_window_print_range (EvWindow *ev_window,
+ gint first_page,
+ gint last_page)
{
- GtkWidget *dialog;
- EvPageCache *page_cache;
- gint current_page;
- gint document_last_page;
- GtkPrintCapabilities capabilities;
+ EvPrintOperation *op;
+ EvPageCache *page_cache;
+ gint current_page;
+ gint document_last_page;
g_return_if_fail (EV_IS_WINDOW (ev_window));
g_return_if_fail (ev_window->priv->document != NULL);
- if (ev_window->priv->print_dialog) {
- gtk_window_present (GTK_WINDOW (ev_window->priv->print_dialog));
- return;
- }
-
+ if (!ev_window->priv->print_queue)
+ ev_window->priv->print_queue = g_queue_new ();
+
+ op = ev_print_operation_new (ev_window->priv->document);
+ g_signal_connect (op, "begin_print",
+ G_CALLBACK (ev_window_print_operation_begin_print),
+ (gpointer)ev_window);
+ g_signal_connect (op, "status_changed",
+ G_CALLBACK (ev_window_print_operation_status_changed),
+ (gpointer)ev_window);
+ g_signal_connect (op, "done",
+ G_CALLBACK (ev_window_print_operation_done),
+ (gpointer)ev_window);
+
page_cache = ev_page_cache_get (ev_window->priv->document);
current_page = ev_page_cache_get_current_page (page_cache);
document_last_page = ev_page_cache_get_n_pages (page_cache);
if (!ev_window->priv->print_settings) {
- ev_window->priv->print_settings = g_object_ref (
+ ev_window->priv->print_settings = gtk_print_settings_copy (
ev_application_get_print_settings (EV_APP));
+ ev_window_load_print_settings_from_metadata (ev_window);
}
if (first_page != 1 || last_page != document_last_page) {
&range, 1);
}
- dialog = gtk_print_unix_dialog_new (_("Print"), GTK_WINDOW (ev_window));
- ev_window->priv->print_dialog = dialog;
-
- capabilities = GTK_PRINT_CAPABILITY_PREVIEW |
- ev_file_exporter_get_capabilities (EV_FILE_EXPORTER (ev_window->priv->document));
- gtk_print_unix_dialog_set_manual_capabilities (GTK_PRINT_UNIX_DIALOG (dialog),
- capabilities);
-
- gtk_print_unix_dialog_set_current_page (GTK_PRINT_UNIX_DIALOG (dialog),
- current_page);
-
- gtk_print_unix_dialog_set_settings (GTK_PRINT_UNIX_DIALOG (dialog),
- ev_window->priv->print_settings);
-
+ ev_print_operation_set_job_name (op, gtk_window_get_title (GTK_WINDOW (ev_window)));
+ ev_print_operation_set_current_page (op, current_page);
+ ev_print_operation_set_print_settings (op, ev_window->priv->print_settings);
if (ev_window->priv->print_page_setup)
- gtk_print_unix_dialog_set_page_setup (GTK_PRINT_UNIX_DIALOG (dialog),
- ev_window->priv->print_page_setup);
-
- g_signal_connect (G_OBJECT (dialog), "response",
- G_CALLBACK (ev_window_print_dialog_response_cb),
- ev_window);
-
- gtk_widget_show (dialog);
-}
-#endif /* WITH_GTK_PRINT */
-
-#ifdef WITH_GNOME_PRINT
-static gboolean
-ev_window_print_dialog_response_cb (GtkDialog *print_dialog,
- gint response,
- EvWindow *ev_window)
-{
- EvPrintJob *print_job;
- GnomePrintConfig *config;
-
- if (response != GNOME_PRINT_DIALOG_RESPONSE_PRINT) {
- gtk_widget_destroy (GTK_WIDGET (print_dialog));
- ev_window->priv->print_dialog = NULL;
- g_object_unref (ev_window->priv->print_job);
- ev_window->priv->print_job = NULL;
-
- return FALSE;
- }
-
- config = gnome_print_dialog_get_config (GNOME_PRINT_DIALOG (print_dialog));
-
- /* FIXME: Change this when we have the first backend
- * that can print more than postscript
- */
- if (using_pdf_printer (config)) {
- GtkWidget *dialog;
-
- dialog = gtk_message_dialog_new (GTK_WINDOW (print_dialog), GTK_DIALOG_MODAL,
- GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
- _("Generating PDF is not supported"));
- gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
-
- return FALSE;
- } else if (!using_postscript_printer (config)) {
- GtkWidget *dialog;
+ ev_print_operation_set_default_page_setup (op, ev_window->priv->print_page_setup);
- dialog = gtk_message_dialog_new (GTK_WINDOW (print_dialog), GTK_DIALOG_MODAL,
- GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
- _("Printing is not supported on this printer."));
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- _("You were trying to print to a printer using the “%s” driver. "
- "This program requires a PostScript printer driver."),
- gnome_print_config_get (config, (guchar *)"Settings.Engine.Backend.Driver"));
- gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
-
- return FALSE;
- }
-
- save_print_config_to_file (config);
-
- print_job = g_object_new (EV_TYPE_PRINT_JOB,
- "gnome_print_job", ev_window->priv->print_job,
- "document", ev_window->priv->document,
- "print_dialog", print_dialog,
- NULL);
-
- if (print_job != NULL) {
- ev_print_job_print (print_job, GTK_WINDOW (ev_window));
- g_object_unref (print_job);
- }
-
- g_object_unref (config);
-
- gtk_widget_destroy (GTK_WIDGET (print_dialog));
- ev_window->priv->print_dialog = NULL;
- g_object_unref (ev_window->priv->print_job);
- ev_window->priv->print_job = NULL;
-
- return FALSE;
-}
-
-void
-ev_window_print_range (EvWindow *ev_window, int first_page, int last_page)
-{
- GnomePrintConfig *config;
- gchar *pages_label;
-
- g_return_if_fail (EV_IS_WINDOW (ev_window));
- g_return_if_fail (ev_window->priv->document != NULL);
-
- config = load_print_config_from_file ();
-
- if (ev_window->priv->print_job == NULL)
- ev_window->priv->print_job = gnome_print_job_new (config);
-
- if (ev_window->priv->print_dialog == NULL) {
- ev_window->priv->print_dialog =
- gnome_print_dialog_new (ev_window->priv->print_job,
- (guchar *) _("Print"),
- (GNOME_PRINT_DIALOG_RANGE |
- GNOME_PRINT_DIALOG_COPIES));
- }
-
- gtk_window_set_transient_for (GTK_WINDOW (ev_window->priv->print_dialog),
- GTK_WINDOW (ev_window));
- g_object_unref (config);
-
- pages_label = g_strconcat (_("Pages"), " ", NULL);
- gnome_print_dialog_construct_range_page (GNOME_PRINT_DIALOG (ev_window->priv->print_dialog),
- GNOME_PRINT_RANGE_ALL |
- GNOME_PRINT_RANGE_RANGE,
- first_page, last_page,
- NULL, (const guchar *)pages_label);
- g_free (pages_label);
-
- gtk_dialog_set_response_sensitive (GTK_DIALOG (ev_window->priv->print_dialog),
- GNOME_PRINT_DIALOG_RESPONSE_PREVIEW,
- FALSE);
-
- g_signal_connect (G_OBJECT (ev_window->priv->print_dialog), "response",
- G_CALLBACK (ev_window_print_dialog_response_cb),
- ev_window);
- gtk_widget_show (ev_window->priv->print_dialog);
+ ev_print_operation_run (op, GTK_WINDOW (ev_window));
}
-#endif /* WITH_GNOME_PRINT */
static void
ev_window_print (EvWindow *window)
page_cache = ev_page_cache_get (window->priv->document);
last_page = ev_page_cache_get_n_pages (page_cache);
-#ifdef WITH_PRINT
ev_window_print_range (window, 1, last_page);
-#endif
}
static void
if (ev_window->priv->properties == NULL) {
ev_window->priv->properties = ev_properties_dialog_new ();
ev_properties_dialog_set_document (EV_PROPERTIES_DIALOG (ev_window->priv->properties),
+ ev_window->priv->uri,
ev_window->priv->document);
g_object_add_weak_pointer (G_OBJECT (ev_window->priv->properties),
(gpointer) &(ev_window->priv->properties));
gtk_widget_show (ev_window->priv->properties);
ev_document_fc_mutex_unlock ();
}
-
+
+static void
+print_jobs_confirmation_dialog_response (GtkDialog *dialog,
+ gint response,
+ EvWindow *ev_window)
+{
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+
+ switch (response) {
+ case GTK_RESPONSE_YES:
+ if (!ev_window->priv->print_queue ||
+ g_queue_is_empty (ev_window->priv->print_queue))
+ gtk_widget_destroy (GTK_WIDGET (ev_window));
+ else
+ ev_window->priv->close_after_print = TRUE;
+ break;
+ case GTK_RESPONSE_NO:
+ ev_window->priv->close_after_print = TRUE;
+ if (ev_window->priv->print_queue &&
+ !g_queue_is_empty (ev_window->priv->print_queue)) {
+ gtk_widget_set_sensitive (GTK_WIDGET (ev_window), FALSE);
+ ev_window_print_cancel (ev_window);
+ } else {
+ gtk_widget_destroy (GTK_WIDGET (ev_window));
+ }
+ break;
+ case GTK_RESPONSE_CANCEL:
+ default:
+ ev_window->priv->close_after_print = FALSE;
+ }
+}
+
static void
ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window)
{
- g_return_if_fail (EV_IS_WINDOW (ev_window));
+ GtkWidget *dialog;
+ gchar *text, *markup;
+ gint n_print_jobs;
+
+ n_print_jobs = ev_window->priv->print_queue ?
+ g_queue_get_length (ev_window->priv->print_queue) : 0;
+
+ if (n_print_jobs == 0) {
+ gtk_widget_destroy (GTK_WIDGET (ev_window));
+ return;
+ }
+
+ dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_NONE,
+ NULL);
+ if (n_print_jobs == 1) {
+ EvPrintOperation *op;
+ const gchar *job_name;
+
+ op = g_queue_peek_tail (ev_window->priv->print_queue);
+ job_name = ev_print_operation_get_job_name (op);
+
+ text = g_strdup_printf (_("Wait until print job “%s” finishes before closing?"),
+ job_name);
+ } else {
+ text = g_strdup_printf (_("There are %d print jobs active. "
+ "Wait until print finishes before closing?"),
+ n_print_jobs);
+ }
+
+ markup = g_strdup_printf ("<b>%s</b>", text);
+ g_free (text);
- gtk_widget_destroy (GTK_WIDGET (ev_window));
+ gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), markup);
+ g_free (markup);
+
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s",
+ _("If you close the window, pending print "
+ "jobs will not be printed."));
+
+ gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+ _("Cancel _print and Close"),
+ GTK_RESPONSE_NO,
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_CANCEL,
+ _("Close _after Printing"),
+ GTK_RESPONSE_YES,
+ NULL);
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
+
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (print_jobs_confirmation_dialog_response),
+ ev_window);
+ gtk_widget_show (dialog);
}
static void
update_chrome_flag (window, EV_CHROME_RAISE_TOOLBAR, TRUE);
ev_window_set_action_sensitive (window, "ViewToolbar", FALSE);
+ update_chrome_visibility (window);
action = gtk_action_group_get_action (window->priv->action_group,
PAGE_SELECTOR_ACTION);
static void
ev_window_cmd_scroll_forward (GtkAction *action, EvWindow *window)
{
- ev_view_scroll (EV_VIEW (window->priv->view), EV_SCROLL_PAGE_FORWARD, FALSE);
+ ev_view_scroll (EV_VIEW (window->priv->view), GTK_SCROLL_PAGE_FORWARD, FALSE);
}
static void
ev_window_cmd_scroll_backward (GtkAction *action, EvWindow *window)
{
- ev_view_scroll (EV_VIEW (window->priv->view), EV_SCROLL_PAGE_BACKWARD, FALSE);
+ ev_view_scroll (EV_VIEW (window->priv->view), GTK_SCROLL_PAGE_BACKWARD, FALSE);
}
static void
{
gboolean continuous;
- ev_window_stop_presentation (ev_window);
+ ev_window_stop_presentation (ev_window, TRUE);
continuous = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
g_object_set (G_OBJECT (ev_window->priv->view),
"continuous", continuous,
{
gboolean dual_page;
- ev_window_stop_presentation (ev_window);
+ ev_window_stop_presentation (ev_window, TRUE);
dual_page = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
g_object_set (G_OBJECT (ev_window->priv->view),
"dual-page", dual_page,
static void
ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window)
{
- ev_window_stop_presentation (ev_window);
+ ev_window_stop_presentation (ev_window, TRUE);
if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
ev_view_set_sizing_mode (EV_VIEW (ev_window->priv->view), EV_SIZING_BEST_FIT);
static void
ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window)
{
- ev_window_stop_presentation (ev_window);
+ ev_window_stop_presentation (ev_window, TRUE);
if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
ev_view_set_sizing_mode (EV_VIEW (ev_window->priv->view), EV_SIZING_FIT_WIDTH);
}
update_chrome_flag (ev_window, EV_CHROME_FINDBAR, TRUE);
+ update_chrome_visibility (ev_window);
gtk_widget_grab_focus (ev_window->priv->find_bar);
}
g_return_if_fail (EV_IS_WINDOW (ev_window));
update_chrome_flag (ev_window, EV_CHROME_FINDBAR, TRUE);
+ update_chrome_visibility (ev_window);
gtk_widget_grab_focus (ev_window->priv->find_bar);
ev_view_find_next (EV_VIEW (ev_window->priv->view));
}
g_return_if_fail (EV_IS_WINDOW (ev_window));
update_chrome_flag (ev_window, EV_CHROME_FINDBAR, TRUE);
+ update_chrome_visibility (ev_window);
gtk_widget_grab_focus (ev_window->priv->find_bar);
ev_view_find_previous (EV_VIEW (ev_window->priv->view));
}
g_object_set (item, "is-important", TRUE, NULL);
}
+static void
+fullscreen_toolbar_remove_shadow (GtkWidget *toolbar)
+{
+ static gboolean done = FALSE;
+
+ if (!done) {
+ gtk_rc_parse_string (
+ "\n"
+ " style \"fullscreen-toolbar-style\"\n"
+ " {\n"
+ " GtkToolbar::shadow-type=GTK_SHADOW_NONE\n"
+ " }\n"
+ "\n"
+ " widget \"*.fullscreen-toolbar\" style \"fullscreen-toolbar-style\"\n"
+ "\n");
+ done = TRUE;
+ }
+
+ gtk_widget_set_name (toolbar, "fullscreen-toolbar");
+}
+
static void
ev_window_run_fullscreen (EvWindow *window)
{
+ EvView *view = EV_VIEW (window->priv->view);
+ gboolean fullscreen_window = TRUE;
+
+ if (ev_view_get_fullscreen (view))
+ return;
+
if (!window->priv->fullscreen_toolbar) {
window->priv->fullscreen_toolbar =
gtk_ui_manager_get_widget (window->priv->ui_manager,
gtk_toolbar_set_style (GTK_TOOLBAR (window->priv->fullscreen_toolbar),
GTK_TOOLBAR_BOTH_HORIZ);
+ fullscreen_toolbar_remove_shadow (window->priv->fullscreen_toolbar);
fullscreen_toolbar_setup_item_properties (window->priv->ui_manager);
gtk_box_pack_start (GTK_BOX (window->priv->main_box),
window->priv->fullscreen_toolbar, 1);
}
+ if (ev_view_get_presentation (view)) {
+ ev_window_stop_presentation (window, FALSE);
+ fullscreen_window = FALSE;
+ }
+
g_object_set (G_OBJECT (window->priv->scrolled_window),
"shadow-type", GTK_SHADOW_NONE,
NULL);
- ev_view_set_fullscreen (EV_VIEW (window->priv->view), TRUE);
+ ev_view_set_fullscreen (view, TRUE);
ev_window_update_fullscreen_action (window);
- update_chrome_flag (window, EV_CHROME_FULLSCREEN_TOOLBAR, TRUE);
+ /* If the user doesn't have the main toolbar he/she won't probably want
+ * the toolbar in fullscreen mode. See bug #483048
+ */
+ update_chrome_flag (window, EV_CHROME_FULLSCREEN_TOOLBAR,
+ (window->priv->chrome & EV_CHROME_TOOLBAR) != 0);
update_chrome_visibility (window);
-
- gtk_window_fullscreen (GTK_WINDOW (window));
+
+ if (fullscreen_window)
+ gtk_window_fullscreen (GTK_WINDOW (window));
gtk_widget_grab_focus (window->priv->view);
if (!ev_window_is_empty (window))
}
static void
-ev_window_stop_fullscreen (EvWindow *window)
+ev_window_stop_fullscreen (EvWindow *window,
+ gboolean unfullscreen_window)
{
EvView *view = EV_VIEW (window->priv->view);
- if (!ev_view_get_fullscreen (EV_VIEW (view)))
+ if (!ev_view_get_fullscreen (view))
return;
g_object_set (G_OBJECT (window->priv->scrolled_window),
ev_window_update_fullscreen_action (window);
update_chrome_flag (window, EV_CHROME_FULLSCREEN_TOOLBAR, FALSE);
update_chrome_visibility (window);
- gtk_window_unfullscreen (GTK_WINDOW (window));
+ if (unfullscreen_window)
+ gtk_window_unfullscreen (GTK_WINDOW (window));
if (!ev_window_is_empty (window))
ev_metadata_manager_set_boolean (window->priv->uri, "fullscreen", FALSE);
{
gboolean fullscreen;
- g_return_if_fail (EV_IS_WINDOW (window));
- ev_window_stop_presentation (window);
-
fullscreen = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
if (fullscreen) {
ev_window_run_fullscreen (window);
} else {
- ev_window_stop_fullscreen (window);
+ ev_window_stop_fullscreen (window, TRUE);
}
}
g_source_remove (window->priv->presentation_timeout_id);
}
-#if GLIB_CHECK_VERSION (2, 13, 0)
window->priv->presentation_timeout_id =
g_timeout_add_seconds (PRESENTATION_TIMEOUT,
(GSourceFunc)presentation_timeout_cb, window);
-#else
- window->priv->presentation_timeout_id =
- g_timeout_add (PRESENTATION_TIMEOUT * 1000,
- (GSourceFunc)presentation_timeout_cb, window);
-#endif
ev_view_show_cursor (EV_VIEW (window->priv->view));
}
static void
ev_window_run_presentation (EvWindow *window)
{
+ EvView *view = EV_VIEW (window->priv->view);
+ gboolean fullscreen_window = TRUE;
+
+ if (ev_view_get_presentation (view))
+ return;
+
+ if (ev_view_get_fullscreen (view)) {
+ ev_window_stop_fullscreen (window, FALSE);
+ fullscreen_window = FALSE;
+ }
+
g_object_set (G_OBJECT (window->priv->scrolled_window),
"shadow-type", GTK_SHADOW_NONE,
NULL);
- ev_view_set_presentation (EV_VIEW (window->priv->view), TRUE);
+ ev_view_set_presentation (view, TRUE);
ev_window_update_presentation_action (window);
update_chrome_visibility (window);
gtk_widget_grab_focus (window->priv->view);
- gtk_window_fullscreen (GTK_WINDOW (window));
+ if (fullscreen_window)
+ gtk_window_fullscreen (GTK_WINDOW (window));
g_signal_connect (window->priv->view,
"motion-notify-event",
}
static void
-ev_window_stop_presentation (EvWindow *window)
+ev_window_stop_presentation (EvWindow *window,
+ gboolean unfullscreen_window)
{
- if (!ev_view_get_presentation (EV_VIEW (window->priv->view)))
+ EvView *view = EV_VIEW (window->priv->view);
+
+ if (!ev_view_get_presentation (view))
return;
g_object_set (G_OBJECT (window->priv->scrolled_window),
ev_view_set_presentation (EV_VIEW (window->priv->view), FALSE);
ev_window_update_presentation_action (window);
update_chrome_visibility (window);
- gtk_window_unfullscreen (GTK_WINDOW (window));
+ if (unfullscreen_window)
+ gtk_window_unfullscreen (GTK_WINDOW (window));
g_signal_handlers_disconnect_by_func (window->priv->view,
(gpointer) presentation_motion_notify_cb,
{
gboolean presentation;
- g_return_if_fail (EV_IS_WINDOW (window));
- ev_window_stop_fullscreen (window);
-
presentation = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
if (presentation) {
ev_window_run_presentation (window);
- } else {
- ev_window_stop_presentation (window);
}
}
action = gtk_action_group_get_action (window->priv->action_group,
"PreviewPrint");
-#if GTK_CHECK_VERSION (2, 11, 0)
gtk_action_set_visible (action, TRUE);
-#else
- gtk_action_set_visible (action, FALSE);
-#endif
update_chrome_visibility (window);
}
}
}
+static gboolean
+ev_window_state_event (GtkWidget *widget,
+ GdkEventWindowState *event)
+{
+ EvWindow *window = EV_WINDOW (widget);
+ EvView *view = EV_VIEW (window->priv->view);
+
+ if (GTK_WIDGET_CLASS (ev_window_parent_class)->window_state_event) {
+ GTK_WIDGET_CLASS (ev_window_parent_class)->window_state_event (widget, event);
+ }
+
+ if ((event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN) == 0)
+ return FALSE;
+
+ if (event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN) {
+ if (ev_view_get_fullscreen (view) || ev_view_get_presentation (view))
+ return FALSE;
+
+ ev_window_run_fullscreen (window);
+ } else {
+ if (ev_view_get_fullscreen (view))
+ ev_window_stop_fullscreen (window, FALSE);
+ else if (ev_view_get_presentation (view))
+ ev_window_stop_presentation (window, FALSE);
+ }
+
+ return FALSE;
+}
+
static void
ev_window_set_page_mode (EvWindow *window,
EvWindowPageMode page_mode)
static void
ev_window_cmd_view_reload (GtkAction *action, EvWindow *ev_window)
{
- gchar *uri;
+ ev_window_reload_document (ev_window);
+}
- uri = g_strdup (ev_window->priv->uri);
- ev_window_open_uri (ev_window, uri, NULL, 0, FALSE, NULL);
- g_free (uri);
+static void
+ev_window_cmd_view_autoscroll (GtkAction *action, EvWindow *ev_window)
+{
+ ev_view_autoscroll_start (EV_VIEW (ev_window->priv->view));
}
+#if GTK_CHECK_VERSION (2, 14, 0)
+static void
+ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
+{
+ GError *error = NULL;
+
+ gtk_show_uri (gtk_window_get_screen (GTK_WINDOW (ev_window)),
+ "ghelp:evince",
+ GDK_CURRENT_TIME,
+ &error);
+ if (error) {
+ ev_window_error_message (ev_window, error,
+ "%s", _("There was an error displaying help"));
+ g_error_free (error);
+ }
+}
+#else /* !GTK_CHECK_VERSION (2, 14, 0) */
static void
ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
{
if (g_file_test (uri, G_FILE_TEST_EXISTS)) {
break;
}
+ g_free (uri);
+ uri = NULL;
}
if (uri == NULL) {
screen = gtk_widget_get_screen (GTK_WIDGET (ev_window));
gdk_spawn_command_line_on_screen (screen, command, &error);
if (error != NULL) {
- g_warning (error->message);
+ g_warning ("%s", error->message);
g_error_free (error);
}
g_free (command);
}
+#endif /* GTK_CHECK_VERSION (2, 14, 0) */
static void
ev_window_cmd_leave_fullscreen (GtkAction *action, EvWindow *window)
{
- ev_window_stop_fullscreen (window);
+ ev_window_stop_fullscreen (window, TRUE);
}
static void
ev_window_cmd_start_presentation (GtkAction *action, EvWindow *window)
{
- ev_window_stop_fullscreen (window);
ev_window_run_presentation (window);
}
-#ifdef WITH_GTK_PRINT
-static void ev_window_do_preview_print (EvWindow *window);
-
static gboolean
ev_window_enumerate_printer_cb (GtkPrinter *printer,
EvWindow *window)
GError *error)
{
if (error) {
- GtkWidget *dialog;
-
- dialog = gtk_message_dialog_new (GTK_WINDOW (window),
- GTK_DIALOG_MODAL,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- _("Failed to print document"));
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- error->message);
-
- gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
+ ev_window_error_message (window, error,
+ "%s", _("Failed to print document"));
}
g_object_unref (print_job);
ev_window_do_preview_print (EvWindow *window)
{
EvWindowPrivate *priv = window->priv;
- GtkPageSetup *page_setup;
GtkPrintJob *job;
gchar *filename;
GError *error = NULL;
g_assert (priv->print_settings != NULL);
g_assert (priv->printer != NULL);
- page_setup = gtk_page_setup_new ();
-
- job = gtk_print_job_new ("evince-print",
+ job = gtk_print_job_new (gtk_window_get_title (GTK_WINDOW (window)),
priv->printer,
priv->print_settings,
- page_setup);
+ priv->print_page_setup);
g_object_unref (priv->print_settings);
priv->print_settings = NULL;
+ g_object_unref (priv->print_page_setup);
+ priv->print_page_setup = NULL;
g_object_unref (priv->printer);
priv->printer = NULL;
- g_object_unref (page_setup);
filename = g_filename_from_uri (priv->local_uri ?
priv->local_uri : priv->uri,
(GtkPrintJobCompleteFunc)ev_window_preview_print_finished,
window, NULL);
} else {
- g_warning (error->message);
+ g_warning ("%s", error->message);
g_error_free (error);
}
gtk_widget_hide (GTK_WIDGET (window));
}
-#endif /* WITH_GTK_PRINT */
-
static void
ev_window_cmd_preview_print (GtkAction *action, EvWindow *window)
{
-#ifdef WITH_GTK_PRINT
- EvWindowPrivate *priv = window->priv;
- GtkPrintSettings *print_settings = NULL;
-#if GTK_CHECK_VERSION (2, 11, 0)
+ EvWindowPrivate *priv = window->priv;
+ GtkPrintSettings *print_settings;
+ GtkPageSetup *page_setup;
const gchar *print_settings_file = priv->print_settings_file;
- if (print_settings_file) {
- if (g_file_test (print_settings_file, G_FILE_TEST_IS_REGULAR)) {
- GError *error = NULL;
-
- print_settings = gtk_print_settings_new_from_file (print_settings_file,
- &error);
+ if (print_settings_file && g_file_test (print_settings_file, G_FILE_TEST_IS_REGULAR)) {
+ GKeyFile *key_file;
+ GError *error = NULL;
+
+ key_file = g_key_file_new ();
+ g_key_file_load_from_file (key_file,
+ print_settings_file,
+ G_KEY_FILE_KEEP_COMMENTS |
+ G_KEY_FILE_KEEP_TRANSLATIONS,
+ &error);
+ if (!error) {
+ print_settings =
+ gtk_print_settings_new_from_key_file (key_file,
+ "Print Settings",
+ NULL);
+ print_settings = print_settings ? print_settings : gtk_print_settings_new ();
- if (error) {
- g_warning (error->message);
- g_error_free (error);
- print_settings = NULL;
- }
+ page_setup = gtk_page_setup_new_from_key_file (key_file,
+ "Page Setup",
+ NULL);
+ page_setup = page_setup ? page_setup : gtk_page_setup_new ();
+ } else {
+ print_settings = gtk_print_settings_new ();
+ page_setup = gtk_page_setup_new ();
+ g_error_free (error);
}
+
+ g_key_file_free (key_file);
+ } else {
+ print_settings = gtk_print_settings_new ();
+ page_setup = gtk_page_setup_new ();
}
-#endif /* GTK 2.11.0 */
- if (!print_settings)
- print_settings = gtk_print_settings_new ();
-
if (priv->print_settings)
g_object_unref (priv->print_settings);
priv->print_settings = print_settings;
+ if (priv->print_page_setup)
+ g_object_unref (priv->print_page_setup);
+ priv->print_page_setup = page_setup;
gtk_enumerate_printers ((GtkPrinterFunc) ev_window_enumerate_printer_cb,
window, NULL, FALSE);
-#endif /* WITH_GTK_PRINT */
}
static void
{
GtkWidget *widget;
+ ev_view_autoscroll_stop (EV_VIEW (window->priv->view));
+
widget = gtk_window_get_focus (GTK_WINDOW (window));
if (widget && gtk_widget_get_ancestor (widget, EGG_TYPE_FIND_BAR)) {
update_chrome_flag (window, EV_CHROME_FINDBAR, FALSE);
+ update_chrome_visibility (window);
gtk_widget_grab_focus (window->priv->view);
} else {
gboolean fullscreen;
NULL);
if (fullscreen) {
- ev_window_stop_fullscreen (window);
+ ev_window_stop_fullscreen (window, TRUE);
} else if (presentation) {
- ev_window_stop_presentation (window);
+ ev_window_stop_presentation (window, TRUE);
gtk_widget_grab_focus (window->priv->view);
} else {
gtk_widget_grab_focus (window->priv->view);
ev_sidebar_thumbnails_refresh (EV_SIDEBAR_THUMBNAILS (window->priv->sidebar_thumbs),
rotation);
+ ev_window_refresh_window_thumbnail (window, rotation);
}
static void
active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
update_chrome_flag (ev_window, EV_CHROME_TOOLBAR, active);
+ update_chrome_visibility (ev_window);
ev_metadata_manager_set_boolean (NULL, "show_toolbar", active);
}
update_chrome_flag (ev_window, EV_CHROME_SIDEBAR,
gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
+ update_chrome_visibility (ev_window);
}
static void
id = THUMBNAILS_SIDEBAR_ID;
} else if (current_page == ev_window->priv->sidebar_attachments) {
id = ATTACHMENTS_SIDEBAR_ID;
+ } else if (current_page == ev_window->priv->sidebar_layers) {
+ id = LAYERS_SIDEBAR_ID;
} else {
g_assert_not_reached();
}
}
static void
-view_find_status_changed_cb (EvView *view,
- GParamSpec *pspec,
- EvWindow *ev_window)
+ev_window_update_find_status_message (EvWindow *ev_window)
+{
+ gchar *message;
+
+ if (!ev_window->priv->find_job)
+ return;
+
+ if (ev_job_is_finished (ev_window->priv->find_job)) {
+ gint n_results;
+
+ n_results = ev_job_find_get_n_results (EV_JOB_FIND (ev_window->priv->find_job),
+ ev_page_cache_get_current_page (ev_window->priv->page_cache));
+ /* TRANS: Sometimes this could be better translated as
+ "%d hit(s) on this page". Therefore this string
+ contains plural cases. */
+ message = g_strdup_printf (ngettext ("%d found on this page",
+ "%d found on this page",
+ n_results),
+ n_results);
+ } else {
+ gdouble percent;
+
+ percent = ev_job_find_get_progress (EV_JOB_FIND (ev_window->priv->find_job));
+ message = g_strdup_printf (_("%3d%% remaining to search"),
+ (gint) ((1.0 - percent) * 100));
+ }
+
+ egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar), message);
+ g_free (message);
+}
+
+static void
+ev_window_find_job_finished_cb (EvJobFind *job,
+ EvWindow *ev_window)
+{
+ ev_window_update_find_status_message (ev_window);
+}
+
+static void
+ev_window_find_job_updated_cb (EvJobFind *job,
+ gint page,
+ EvWindow *ev_window)
+{
+ ev_window_update_actions (ev_window);
+
+ ev_view_find_changed (EV_VIEW (ev_window->priv->view),
+ ev_job_find_get_results (job),
+ page);
+ ev_window_update_find_status_message (ev_window);
+}
+
+static void
+ev_window_clear_find_job (EvWindow *ev_window)
{
- const char *text;
+ if (ev_window->priv->find_job != NULL) {
+ if (!ev_job_is_finished (ev_window->priv->find_job))
+ ev_job_cancel (ev_window->priv->find_job);
- text = ev_view_get_find_status (view);
- egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar),
- text);
+ g_signal_handlers_disconnect_by_func (ev_window->priv->find_job,
+ ev_window_find_job_finished_cb,
+ ev_window);
+ g_signal_handlers_disconnect_by_func (ev_window->priv->find_job,
+ ev_window_find_job_updated_cb,
+ ev_window);
+ g_object_unref (ev_window->priv->find_job);
+ ev_window->priv->find_job = NULL;
+ }
}
static void
find_bar_close_cb (EggFindBar *find_bar,
EvWindow *ev_window)
{
+ ev_view_find_cancel (EV_VIEW (ev_window->priv->view));
+ ev_window_clear_find_job (ev_window);
update_chrome_flag (ev_window, EV_CHROME_FINDBAR, FALSE);
+ update_chrome_visibility (ev_window);
}
static void
gboolean case_sensitive;
const char *search_string;
+ if (!ev_window->priv->document || !EV_IS_DOCUMENT_FIND (ev_window->priv->document))
+ return;
+
/* Either the string or case sensitivity could have changed. */
-
case_sensitive = egg_find_bar_get_case_sensitive (find_bar);
search_string = egg_find_bar_get_search_string (find_bar);
- ev_view_search_changed (EV_VIEW(ev_window->priv->view));
+ ev_view_find_search_changed (EV_VIEW (ev_window->priv->view));
- if (ev_window->priv->document &&
- EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
- if (search_string && search_string[0]) {
- ev_document_doc_mutex_lock ();
- ev_document_find_begin (EV_DOCUMENT_FIND (ev_window->priv->document),
- ev_page_cache_get_current_page (ev_window->priv->page_cache),
- search_string,
- case_sensitive);
- ev_document_doc_mutex_unlock ();
- } else {
- ev_document_doc_mutex_lock ();
- ev_document_find_cancel (EV_DOCUMENT_FIND (ev_window->priv->document));
- ev_document_doc_mutex_unlock ();
-
- ev_window_update_actions (ev_window);
- egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar),
- NULL);
- gtk_widget_queue_draw (GTK_WIDGET (ev_window->priv->view));
- }
+ ev_window_clear_find_job (ev_window);
+
+ if (search_string && search_string[0]) {
+ ev_window->priv->find_job = ev_job_find_new (ev_window->priv->document,
+ ev_page_cache_get_current_page (ev_window->priv->page_cache),
+ ev_page_cache_get_n_pages (ev_window->priv->page_cache),
+ search_string,
+ case_sensitive);
+ g_signal_connect (ev_window->priv->find_job, "finished",
+ G_CALLBACK (ev_window_find_job_finished_cb),
+ ev_window);
+ g_signal_connect (ev_window->priv->find_job, "updated",
+ G_CALLBACK (ev_window_find_job_updated_cb),
+ ev_window);
+ ev_job_scheduler_push_job (ev_window->priv->find_job, EV_JOB_PRIORITY_NONE);
+ } else {
+ ev_window_update_actions (ev_window);
+ egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar),
+ NULL);
+ gtk_widget_queue_draw (GTK_WIDGET (ev_window->priv->view));
}
}
static void
find_bar_visibility_changed_cb (EggFindBar *find_bar,
- GParamSpec *param,
- EvWindow *ev_window)
+ GParamSpec *param,
+ EvWindow *ev_window)
{
gboolean visible;
if (ev_window->priv->document &&
EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
- ev_view_set_highlight_search (EV_VIEW(ev_window->priv->view), visible);
- ev_view_search_changed (EV_VIEW(ev_window->priv->view));
+ ev_view_find_set_highlight_search (EV_VIEW (ev_window->priv->view), visible);
+ ev_view_find_search_changed (EV_VIEW (ev_window->priv->view));
ev_window_update_actions (ev_window);
- if (!visible)
+ if (visible)
+ find_bar_search_changed_cb (find_bar, NULL, ev_window);
+ else
egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar), NULL);
}
}
static void
-find_bar_scroll(EggFindBar *find_bar, GtkScrollType scroll, EvWindow* ev_window)
+find_bar_scroll (EggFindBar *find_bar,
+ GtkScrollType scroll,
+ EvWindow *ev_window)
{
- ev_view_scroll(EV_VIEW(ev_window->priv->view), scroll, FALSE);
+ ev_view_scroll (EV_VIEW (ev_window->priv->view), scroll, FALSE);
}
static void
}
}
+static void
+ev_window_drag_data_received (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time)
+
+{
+ EvWindow *window = EV_WINDOW (widget);
+ gchar **uris;
+ gint i = 0;
+ GSList *uri_list = NULL;
+
+ uris = gtk_selection_data_get_uris (selection_data);
+ if (!uris) {
+ gtk_drag_finish (context, FALSE, FALSE, time);
+ return;
+ }
+
+ for (i = 0; uris[i]; i++) {
+ uri_list = g_slist_prepend (uri_list, (gpointer) uris[i]);
+ }
+
+ ev_application_open_uri_list (EV_APP, uri_list,
+ gtk_window_get_screen (GTK_WINDOW (window)),
+ 0);
+ gtk_drag_finish (context, TRUE, FALSE, time);
+
+ g_strfreev (uris);
+ g_slist_free (uri_list);
+}
+
static void
ev_window_finalize (GObject *object)
{
{
EvWindow *window = EV_WINDOW (object);
EvWindowPrivate *priv = window->priv;
+ GObject *mpkeys = ev_application_get_media_keys (EV_APP);
+ if (mpkeys) {
+ g_signal_handlers_disconnect_by_func (mpkeys,
+ ev_window_media_player_key_pressed,
+ window);
+ }
+
+ if (priv->setup_document_idle > 0) {
+ g_source_remove (priv->setup_document_idle);
+ priv->setup_document_idle = 0;
+ }
+
+ if (priv->monitor) {
+ g_object_unref (priv->monitor);
+ priv->monitor = NULL;
+ }
+
if (priv->title) {
ev_window_title_free (priv->title);
priv->title = NULL;
priv->attachment_popup_action_group = NULL;
}
-#ifdef HAVE_GTK_RECENT
if (priv->recent_action_group) {
g_object_unref (priv->recent_action_group);
priv->recent_action_group = NULL;
}
priv->recent_ui_id = 0;
-#else
- if (priv->recent_view) {
- g_object_unref (priv->recent_view);
- priv->recent_view = NULL;
- }
-#endif /* HAVE_GTK_RECENT */
if (priv->page_cache) {
g_signal_handlers_disconnect_by_func (priv->page_cache, page_changed_cb, window);
ev_window_clear_load_job (window);
}
+ if (priv->reload_job) {
+ ev_window_clear_reload_job (window);
+ }
+
+ if (priv->save_job) {
+ ev_window_clear_save_job (window);
+ }
+
if (priv->thumbnail_job) {
ev_window_clear_thumbnail_job (window);
}
+
+ if (priv->find_job) {
+ ev_window_clear_find_job (window);
+ }
if (priv->local_uri) {
ev_window_clear_local_uri (window);
priv->local_uri = NULL;
}
-
- ev_window_close_dialogs (window);
-
-#ifdef WITH_GTK_PRINT
- ev_window_clear_print_job (window);
- if (window->priv->gtk_print_job) {
- g_object_unref (window->priv->gtk_print_job);
- window->priv->gtk_print_job = NULL;
+ ev_window_clear_progress_idle (window);
+ if (priv->progress_cancellable) {
+ g_object_unref (priv->progress_cancellable);
+ priv->progress_cancellable = NULL;
}
+ ev_window_close_dialogs (window);
+
if (window->priv->printer) {
g_object_unref (window->priv->printer);
window->priv->printer = NULL;
g_object_unref (window->priv->print_page_setup);
window->priv->print_page_setup = NULL;
}
-#endif
if (priv->link) {
g_object_unref (priv->link);
priv->uri = NULL;
}
+ if (priv->search_string) {
+ g_free (priv->search_string);
+ priv->search_string = NULL;
+ }
+
if (priv->dest) {
g_object_unref (priv->dest);
priv->dest = NULL;
priv->presentation_timeout_id = 0;
}
+ if (priv->print_queue) {
+ g_queue_free (priv->print_queue);
+ priv->print_queue = NULL;
+ }
+
G_OBJECT_CLASS (ev_window_parent_class)->dispose (object);
}
g_object_class->finalize = ev_window_finalize;
widget_class->screen_changed = ev_window_screen_changed;
+ widget_class->window_state_event = ev_window_state_event;
+ widget_class->drag_data_received = ev_window_drag_data_received;
g_type_class_add_private (g_object_class, sizeof (EvWindowPrivate));
}
{ "FileOpen", GTK_STOCK_OPEN, N_("_Open..."), "<control>O",
N_("Open an existing document"),
G_CALLBACK (ev_window_cmd_file_open) },
- { "FileOpenCopy", NULL, N_("Op_en a Copy"), NULL,
+ { "FileOpenCopy", NULL, N_("Op_en a Copy"), "<control>N",
N_("Open a copy of the current document in a new window"),
G_CALLBACK (ev_window_cmd_file_open_copy) },
{ "FileSaveAs", GTK_STOCK_SAVE_AS, N_("_Save a Copy..."), "<control>S",
/* Edit menu */
{ "EditCopy", GTK_STOCK_COPY, NULL, "<control>C", NULL,
G_CALLBACK (ev_window_cmd_edit_copy) },
-#ifdef HAVE_GTK_RECENT
{ "EditSelectAll", GTK_STOCK_SELECT_ALL, N_("Select _All"), "<control>A", NULL,
-#else
- { "EditSelectAll", NULL, N_("Select _All"), "<control>A", NULL,
-#endif /* HAVE_GTK_RECENT */
G_CALLBACK (ev_window_cmd_edit_select_all) },
{ "EditFind", GTK_STOCK_FIND, N_("_Find..."), "<control>F",
N_("Find a word or phrase in the document"),
G_CALLBACK (ev_window_cmd_edit_find_previous) },
{ "EditToolbar", NULL, N_("T_oolbar"), NULL, NULL,
G_CALLBACK (ev_window_cmd_edit_toolbar) },
- { "EditRotateLeft", EV_STOCK_ROTATE_LEFT, N_("Rotate _Left"), NULL, NULL,
+ { "EditRotateLeft", EV_STOCK_ROTATE_LEFT, N_("Rotate _Left"), "<alt>Left", NULL,
G_CALLBACK (ev_window_cmd_edit_rotate_left) },
- { "EditRotateRight", EV_STOCK_ROTATE_RIGHT, N_("Rotate _Right"), NULL, NULL,
+ { "EditRotateRight", EV_STOCK_ROTATE_RIGHT, N_("Rotate _Right"), "<alt>Right", NULL,
G_CALLBACK (ev_window_cmd_edit_rotate_right) },
/* View menu */
N_("Reload the document"),
G_CALLBACK (ev_window_cmd_view_reload) },
+ { "ViewAutoscroll", GTK_STOCK_MEDIA_PLAY, N_("Auto_scroll"), NULL, NULL,
+ G_CALLBACK (ev_window_cmd_view_autoscroll) },
+
/* Go menu */
- { "GoPreviousPage", GTK_STOCK_GO_BACK, N_("_Previous Page"), "<control>Page_Up",
+ { "GoPreviousPage", GTK_STOCK_GO_UP, N_("_Previous Page"), "<control>Page_Up",
N_("Go to the previous page"),
G_CALLBACK (ev_window_cmd_go_previous_page) },
- { "GoNextPage", GTK_STOCK_GO_FORWARD, N_("_Next Page"), "<control>Page_Down",
+ { "GoNextPage", GTK_STOCK_GO_DOWN, N_("_Next Page"), "<control>Page_Down",
N_("Go to the next page"),
G_CALLBACK (ev_window_cmd_go_next_page) },
- { "GoFirstPage", GTK_STOCK_GOTO_FIRST, N_("_First Page"), "<control>Home",
+ { "GoFirstPage", GTK_STOCK_GOTO_TOP, N_("_First Page"), "<control>Home",
N_("Go to the first page"),
G_CALLBACK (ev_window_cmd_go_first_page) },
- { "GoLastPage", GTK_STOCK_GOTO_LAST, N_("_Last Page"), "<control>End",
+ { "GoLastPage", GTK_STOCK_GOTO_BOTTOM, N_("_Last Page"), "<control>End",
N_("Go to the last page"),
G_CALLBACK (ev_window_cmd_go_last_page) },
G_CALLBACK (ev_window_cmd_view_zoom_in) },
{ "CtrlKpMinus", GTK_STOCK_ZOOM_OUT, NULL, "<control>KP_Subtract", NULL,
G_CALLBACK (ev_window_cmd_view_zoom_out) },
+ { "CtrlInsert", GTK_STOCK_COPY, NULL, "<control>Insert", NULL,
+ G_CALLBACK (ev_window_cmd_edit_copy) },
};
/* Toggle items */
{ "ViewFullscreen", GTK_STOCK_FULLSCREEN, N_("_Fullscreen"), "F11",
N_("Expand the window to fill the screen"),
G_CALLBACK (ev_window_cmd_view_fullscreen) },
- { "ViewPresentation", EV_STOCK_RUN_PRESENTATION, N_("_Presentation"), "F5",
+ { "ViewPresentation", EV_STOCK_RUN_PRESENTATION, N_("Pre_sentation"), "F5",
N_("Run document as a presentation"),
G_CALLBACK (ev_window_cmd_view_presentation) },
{ "ViewBestFit", EV_STOCK_ZOOM_PAGE, N_("_Best Fit"), NULL,
gtk_widget_grab_focus (window->priv->view);
}
+static void
+sidebar_layers_visibility_changed (EvSidebarLayers *layers,
+ EvWindow *window)
+{
+ ev_view_reload (EV_VIEW (window->priv->view));
+}
+
static void
register_custom_actions (EvWindow *window, GtkActionGroup *group)
{
"is_important", TRUE,
"short_label", _("Back"),
"stock_id", GTK_STOCK_GO_DOWN,
+ /*translators: this is the history action*/
"tooltip", _("Move across visited pages"),
NULL);
g_signal_connect (action, "activate_link",
G_CALLBACK (navigation_action_activate_link_cb), window);
gtk_action_group_add_action (group, action);
g_object_unref (action);
+
+ action = g_object_new (EV_TYPE_OPEN_RECENT_ACTION,
+ "name", "FileOpenRecent",
+ "label", _("_Open..."),
+ "tooltip", _("Open an existing document"),
+ "stock_id", GTK_STOCK_OPEN,
+ NULL);
+ g_signal_connect (action, "activate",
+ G_CALLBACK (ev_window_cmd_file_open), window);
+ g_signal_connect (action, "item_activated",
+ G_CALLBACK (ev_window_open_recent_action_item_activated),
+ window);
+ gtk_action_group_add_action (group, action);
+ g_object_unref (action);
}
static void
static gboolean
view_actions_focus_in_cb (GtkWidget *widget, GdkEventFocus *event, EvWindow *window)
{
+#ifdef ENABLE_DBUS
+ GObject *keys;
+
+ keys = ev_application_get_media_keys (EV_APP);
+ ev_media_player_keys_focused (EV_MEDIA_PLAYER_KEYS (keys));
+#endif /* ENABLE_DBUS */
+
update_chrome_flag (window, EV_CHROME_RAISE_TOOLBAR, FALSE);
ev_window_set_action_sensitive (window, "ViewToolbar", TRUE);
ev_window_set_view_accels_sensitivity (window, TRUE);
+ update_chrome_visibility (window);
+
return FALSE;
}
launch_action (EvWindow *window, EvLinkAction *action)
{
const char *filename = ev_link_action_get_filename (action);
- char *uri = NULL;
+ GAppInfo *app_info;
+ GFile *file;
+ GList file_list = {NULL};
+ GAppLaunchContext *context = NULL;
+ GError *error = NULL;
- if (filename && g_path_is_absolute (filename)) {
- uri = gnome_vfs_get_uri_from_local_path (filename);
- } else {
- GnomeVFSURI *base_uri, *resolved_uri;
-
- base_uri = gnome_vfs_uri_new (window->priv->uri);
- if (base_uri && filename) {
- resolved_uri = gnome_vfs_uri_resolve_relative (base_uri, filename);
- if (resolved_uri) {
- uri = gnome_vfs_uri_to_string (resolved_uri, GNOME_VFS_URI_HIDE_NONE);
- gnome_vfs_uri_unref (resolved_uri);
- }
- gnome_vfs_uri_unref (base_uri);
- }
- }
+ if (filename == NULL)
+ return;
- if (uri) {
- gnome_vfs_url_show (uri);
+ if (g_path_is_absolute (filename)) {
+ file = g_file_new_for_path (filename);
} else {
- gnome_vfs_url_show (filename);
+ GFile *base_file;
+ gchar *dir;
+
+ dir = g_path_get_dirname (window->priv->uri);
+ base_file = g_file_new_for_uri (dir);
+ g_free (dir);
+
+ file = g_file_resolve_relative_path (base_file, filename);
+ g_object_unref (base_file);
}
- g_free (uri);
+ app_info = g_file_query_default_handler (file, NULL, &error);
+ if (!app_info) {
+ ev_window_error_message (window, error,
+ "%s",
+ _("Unable to launch external application."));
+ g_object_unref (file);
+ g_error_free (error);
- /* According to the PDF spec filename can be an executable. I'm not sure
- allowing to launch executables is a good idea though. -- marco */
-}
+ return;
+ }
-static gboolean
-uri_is_valid (const gchar *uri)
-{
- gchar *p = (gchar *) uri;
+#if GTK_CHECK_VERSION (2, 14, 0)
+ context = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
+ gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (context),
+ gtk_window_get_screen (GTK_WINDOW (window)));
+ gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (context), GDK_CURRENT_TIME);
+#endif
- if (!p || !g_ascii_isalpha (*p))
- return FALSE;
+ file_list.data = file;
+ if (!g_app_info_launch (app_info, &file_list, context, &error)) {
+ ev_window_error_message (window, error,
+ "%s",
+ _("Unable to launch external application."));
+ g_error_free (error);
+ }
- p++;
- while (g_ascii_isalnum (*p))
- p++;
+ g_object_unref (app_info);
+ g_object_unref (file);
- return (g_ascii_strncasecmp (p, "://", strlen ("://")) == 0);
+ /* According to the PDF spec filename can be an executable. I'm not sure
+ allowing to launch executables is a good idea though. -- marco */
}
static void
launch_external_uri (EvWindow *window, EvLinkAction *action)
{
const gchar *uri = ev_link_action_get_uri (action);
-
- if (!uri_is_valid (uri)) {
- GtkWidget *dialog;
+ GError *error = NULL;
+ gboolean ret;
+#if GTK_CHECK_VERSION (2, 14, 0)
+ GAppLaunchContext *context = NULL;
+#endif
- dialog = gtk_message_dialog_new (GTK_WINDOW (window),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_CLOSE,
- _("Unable to open external link"));
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- _("Invalid URI: “%s”"), uri);
- g_signal_connect (dialog, "response",
- G_CALLBACK (gtk_widget_destroy),
- NULL);
- gtk_widget_show (dialog);
+#if GTK_CHECK_VERSION (2, 14, 0)
+ context = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
+ gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (context),
+ gtk_window_get_screen (GTK_WINDOW (window)));
+ gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (context),
+ GDK_CURRENT_TIME);
+#endif
- return;
+ if (!g_strstr_len (uri, strlen (uri), "://") &&
+ !g_str_has_prefix (uri, "mailto:")) {
+ gchar *http;
+
+ /* Not a valid uri, assuming it's http */
+ http = g_strdup_printf ("http://%s", uri);
+ ret = g_app_info_launch_default_for_uri (http, NULL, &error);
+ g_free (http);
+ } else {
+ ret = g_app_info_launch_default_for_uri (uri, NULL, &error);
}
- gnome_vfs_url_show (uri);
+ if (ret == FALSE) {
+ ev_window_error_message (window, error,
+ "%s", _("Unable to open external link"));
+ g_error_free (error);
+ }
}
static void
gtk_window_get_screen (GTK_WINDOW (window)),
ev_link_action_get_dest (action),
0,
+ NULL,
FALSE,
NULL,
GDK_CURRENT_TIME);
static void
ev_view_popup_cmd_copy_link_address (GtkAction *action, EvWindow *window)
{
- GtkClipboard *clipboard;
EvLinkAction *ev_action;
- const gchar *uri;
ev_action = ev_link_get_action (window->priv->link);
if (!ev_action)
return;
- uri = ev_link_action_get_uri (ev_action);
-
- clipboard = gtk_widget_get_clipboard (GTK_WIDGET (window),
- GDK_SELECTION_CLIPBOARD);
- gtk_clipboard_set_text (clipboard, uri, -1);
+ ev_view_copy_link_address (EV_VIEW (window->priv->view),
+ ev_action);
}
+
static void
image_save_dialog_response_cb (GtkWidget *fc,
gint response_id,
EvWindow *ev_window)
{
- GnomeVFSURI *target_uri;
- gchar *uri;
- gchar *filename;
- gboolean is_local;
- GError *error = NULL;
+ GFile *target_file;
+ gboolean is_native;
+ GError *error = NULL;
+ GdkPixbuf *pixbuf;
+ gchar *uri;
+ gchar **extensions;
+ gchar *filename;
+ gchar *file_format;
+ GdkPixbufFormat *format;
+ GtkFileFilter *filter;
if (response_id != GTK_RESPONSE_OK) {
gtk_widget_destroy (fc);
}
uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
- target_uri = gnome_vfs_uri_new (uri);
- is_local = gnome_vfs_uri_is_local (target_uri);
+ filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (fc));
+ format = g_object_get_data (G_OBJECT (filter), "pixbuf-format");
- if (is_local) {
- filename = g_filename_from_uri (uri, NULL, NULL);
+ if (format == NULL) {
+ format = get_gdk_pixbuf_format_by_extension (uri);
+ }
+
+ if (format == NULL) {
+ ev_window_error_message (ev_window, NULL,
+ "%s",
+ _("Couldn't find appropriate format to save image"));
+ g_free (uri);
+ gtk_widget_destroy (fc);
+
+ return;
+ }
+
+ extensions = gdk_pixbuf_format_get_extensions (format);
+ if (!g_str_has_suffix (uri, extensions[0])) {
+ gchar *uri_extension;
+
+ uri_extension = g_strconcat (uri, ".", extensions[0], NULL);
+ target_file = g_file_new_for_uri (uri_extension);
+ g_free (uri_extension);
} else {
- filename = ev_tmp_filename ("saveimage");
+ target_file = g_file_new_for_uri (uri);
}
-
+ g_strfreev (extensions);
g_free (uri);
- /* FIXME: allow saving in other image formats than png */
- gdk_pixbuf_save (ev_image_get_pixbuf (ev_window->priv->image),
- filename, "png", &error, NULL);
+ is_native = g_file_is_native (target_file);
+ if (is_native) {
+ filename = g_file_get_path (target_file);
+ } else {
+ filename = ev_tmp_filename ("saveimage");
+ }
+
+ ev_document_doc_mutex_lock ();
+ pixbuf = ev_document_images_get_image (EV_DOCUMENT_IMAGES (ev_window->priv->document),
+ ev_window->priv->image);
+ ev_document_doc_mutex_unlock ();
+
+ file_format = gdk_pixbuf_format_get_name (format);
+ gdk_pixbuf_save (pixbuf, filename, file_format, &error, NULL);
+ g_free (file_format);
+ g_object_unref (pixbuf);
if (error) {
- ev_window_error_dialog (GTK_WINDOW (ev_window),
- _("The image could not be saved."),
- error);
+ ev_window_error_message (ev_window, error,
+ "%s", _("The image could not be saved."));
g_error_free (error);
g_free (filename);
- gnome_vfs_uri_unref (target_uri);
+ g_object_unref (target_file);
gtk_widget_destroy (fc);
return;
}
- if (!is_local) {
- GnomeVFSURI *source_uri;
- gchar *local_uri;
-
- local_uri = g_filename_to_uri (filename, NULL, NULL);
- source_uri = gnome_vfs_uri_new (local_uri);
- g_free (local_uri);
- ev_window_save_remote (ev_window, source_uri, target_uri);
- gnome_vfs_uri_unref (source_uri);
+ if (!is_native) {
+ GFile *source_file;
+
+ source_file = g_file_new_for_path (filename);
+
+ ev_window_save_remote (ev_window, EV_SAVE_IMAGE,
+ source_file, target_file);
+ g_object_unref (source_file);
}
g_free (filename);
- gnome_vfs_uri_unref (target_uri);
+ g_object_unref (target_file);
gtk_widget_destroy (fc);
}
static void
ev_view_popup_cmd_save_image_as (GtkAction *action, EvWindow *window)
{
- GtkWidget *fc;
- GtkFileFilter *filter;
+ GtkWidget *fc;
if (!window->priv->image)
return;
gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (fc), FALSE);
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
-
- filter = gtk_file_filter_new ();
- gtk_file_filter_set_name (filter, _("Images"));
- gtk_file_filter_add_pixbuf_formats (filter);
- gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (fc), filter);
-
+
+ file_chooser_dialog_add_writable_pixbuf_formats (GTK_FILE_CHOOSER (fc));
+
g_signal_connect (fc, "response",
G_CALLBACK (image_save_dialog_response_cb),
window);
ev_view_popup_cmd_copy_image (GtkAction *action, EvWindow *window)
{
GtkClipboard *clipboard;
+ GdkPixbuf *pixbuf;
if (!window->priv->image)
return;
clipboard = gtk_widget_get_clipboard (GTK_WIDGET (window),
GDK_SELECTION_CLIPBOARD);
- gtk_clipboard_set_image (clipboard,
- ev_image_get_pixbuf (window->priv->image));
+ ev_document_doc_mutex_lock ();
+ pixbuf = ev_document_images_get_image (EV_DOCUMENT_IMAGES (window->priv->document),
+ window->priv->image);
+ ev_document_doc_mutex_unlock ();
+
+ gtk_clipboard_set_image (clipboard, pixbuf);
+ g_object_unref (pixbuf);
}
static void
ev_attachment_popup_cmd_open_attachment (GtkAction *action, EvWindow *window)
{
- GList *l;
+ GList *l;
+ GdkScreen *screen;
if (!window->priv->attach_list)
return;
+ screen = gtk_window_get_screen (GTK_WINDOW (window));
+
for (l = window->priv->attach_list; l && l->data; l = g_list_next (l)) {
EvAttachment *attachment;
GError *error = NULL;
attachment = (EvAttachment *) l->data;
- ev_attachment_open (attachment, &error);
+ ev_attachment_open (attachment, screen, GDK_CURRENT_TIME, &error);
if (error) {
- ev_window_error_dialog (GTK_WINDOW (window),
- _("Unable to open attachment"),
- error);
+ ev_window_error_message (window, error,
+ "%s", _("Unable to open attachment"));
g_error_free (error);
}
}
gint response_id,
EvWindow *ev_window)
{
- GnomeVFSURI *target_uri;
+ GFile *target_file;
gchar *uri;
GList *l;
GtkFileChooserAction fc_action;
gboolean is_dir;
- gboolean is_local;
+ gboolean is_native;
if (response_id != GTK_RESPONSE_OK) {
gtk_widget_destroy (fc);
}
uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
- target_uri = gnome_vfs_uri_new (uri);
+ target_file = g_file_new_for_uri (uri);
g_object_get (G_OBJECT (fc), "action", &fc_action, NULL);
is_dir = (fc_action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
- is_local = gnome_vfs_uri_is_local (target_uri);
+ is_native = g_file_is_native (target_file);
for (l = ev_window->priv->attach_list; l && l->data; l = g_list_next (l)) {
EvAttachment *attachment;
- gchar *filename;
+ GFile *save_to;
GError *error = NULL;
attachment = (EvAttachment *) l->data;
- if (is_local) {
+ if (is_native) {
if (is_dir) {
- filename = g_strjoin ("/", uri,
- ev_attachment_get_name (attachment),
- NULL);
+ save_to = g_file_get_child (target_file,
+ ev_attachment_get_name (attachment));
} else {
- filename = g_strdup (uri);
+ save_to = g_object_ref (target_file);
}
} else {
- filename = ev_tmp_filename ("saveattachment");
+ save_to = ev_tmp_file_get ("saveattachment");
}
- ev_attachment_save (attachment, filename, &error);
+ ev_attachment_save (attachment, save_to, &error);
if (error) {
- ev_window_error_dialog (GTK_WINDOW (ev_window),
- _("The attachment could not be saved."),
- error);
+ ev_window_error_message (ev_window, error,
+ "%s", _("The attachment could not be saved."));
g_error_free (error);
- g_free (filename);
+ g_object_unref (save_to);
continue;
}
- if (!is_local) {
- GnomeVFSURI *src_uri;
- GnomeVFSURI *dest_uri;
- gchar *local_uri;
+ if (!is_native) {
+ GFile *dest_file;
if (is_dir) {
- const gchar *name = ev_attachment_get_name (attachment);
-
- dest_uri = gnome_vfs_uri_append_file_name (target_uri,
- name);
+ dest_file = g_file_get_child (target_file,
+ ev_attachment_get_name (attachment));
} else {
- dest_uri = gnome_vfs_uri_ref (target_uri);
+ dest_file = g_object_ref (target_file);
}
-
- local_uri = g_filename_to_uri (filename, NULL, NULL);
- src_uri = gnome_vfs_uri_new (local_uri);
- g_free (local_uri);
- ev_window_save_remote (ev_window, src_uri, dest_uri);
- gnome_vfs_uri_unref (src_uri);
- gnome_vfs_uri_unref (dest_uri);
+
+ ev_window_save_remote (ev_window, EV_SAVE_ATTACHMENT,
+ save_to, dest_file);
+
+ g_object_unref (dest_file);
}
- g_free (filename);
+ g_object_unref (save_to);
}
g_free (uri);
- gnome_vfs_uri_unref (target_uri);
+ g_object_unref (target_file);
gtk_widget_destroy (fc);
}
gtk_widget_show (fc);
}
+static void
+ev_window_media_player_key_pressed (EvWindow *window,
+ const gchar *key,
+ gpointer user_data)
+{
+ if (!gtk_window_is_active (GTK_WINDOW (window)))
+ return;
+
+ /* Note how Previous/Next only go to the
+ * next/previous page despite their icon telling you
+ * they should go to the beginning/end.
+ *
+ * There's very few keyboards with FFW/RWD though,
+ * so we stick the most useful keybinding on the most
+ * often seen keys
+ */
+ if (strcmp (key, "Play") == 0) {
+ ev_window_run_presentation (window);
+ } else if (strcmp (key, "Previous") == 0) {
+ ev_window_cmd_go_previous_page (NULL, window);
+ } else if (strcmp (key, "Next") == 0) {
+ ev_window_cmd_go_next_page (NULL, window);
+ } else if (strcmp (key, "FastForward") == 0) {
+ ev_window_cmd_go_last_page (NULL, window);
+ } else if (strcmp (key, "Rewind") == 0) {
+ ev_window_cmd_go_first_page (NULL, window);
+ }
+}
+
static void
ev_window_init (EvWindow *ev_window)
{
GtkAccelGroup *accel_group;
GError *error = NULL;
GtkWidget *sidebar_widget;
+ GObject *mpkeys;
g_signal_connect (ev_window, "configure_event",
G_CALLBACK (window_configure_event_cb), NULL);
g_error_free (error);
}
-#ifdef HAVE_GTK_RECENT
-#if GTK_CHECK_VERSION(2,11,4)
ev_window->priv->recent_manager = gtk_recent_manager_get_default ();
-#else
- /* It's fine to just use the one of the default screen here */
- ev_window->priv->recent_manager = gtk_recent_manager_get_for_screen (
- gdk_screen_get_default ());
-#endif
ev_window->priv->recent_action_group = NULL;
ev_window->priv->recent_ui_id = 0;
g_signal_connect_swapped (ev_window->priv->recent_manager,
"changed",
G_CALLBACK (ev_window_setup_recent),
ev_window);
-#endif /* HAVE_GTK_RECENT */
-
+
ev_window->priv->menubar =
gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
"/MainMenu");
ev_window->priv->menubar,
FALSE, FALSE, 0);
-
ev_window->priv->toolbar = GTK_WIDGET
(g_object_new (EGG_TYPE_EDITABLE_TOOLBAR,
"ui-manager", ev_window->priv->ui_manager,
ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
sidebar_widget);
+ sidebar_widget = ev_sidebar_layers_new ();
+ ev_window->priv->sidebar_layers = sidebar_widget;
+ g_signal_connect (sidebar_widget,
+ "layers_visibility_changed",
+ G_CALLBACK (sidebar_layers_visibility_changed),
+ ev_window);
+ gtk_widget_show (sidebar_widget);
+ ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
+ sidebar_widget);
+
+ ev_window->priv->view_box = gtk_vbox_new (FALSE, 0);
ev_window->priv->scrolled_window =
GTK_WIDGET (g_object_new (GTK_TYPE_SCROLLED_WINDOW,
"shadow-type", GTK_SHADOW_IN,
NULL));
+ gtk_box_pack_start (GTK_BOX (ev_window->priv->view_box),
+ ev_window->priv->scrolled_window,
+ TRUE, TRUE, 0);
gtk_widget_show (ev_window->priv->scrolled_window);
gtk_paned_add2 (GTK_PANED (ev_window->priv->hpaned),
- ev_window->priv->scrolled_window);
+ ev_window->priv->view_box);
+ gtk_widget_show (ev_window->priv->view_box);
ev_window->priv->view = ev_view_new ();
ev_view_set_screen_dpi (EV_VIEW (ev_window->priv->view),
get_screen_dpi (GTK_WINDOW (ev_window)));
- ev_window->priv->password_view = ev_password_view_new ();
+ ev_window->priv->password_view = ev_password_view_new (GTK_WINDOW (ev_window));
g_signal_connect_swapped (ev_window->priv->password_view,
"unlock",
- G_CALLBACK (ev_window_popup_password_dialog),
+ G_CALLBACK (ev_window_password_view_unlock),
ev_window);
g_signal_connect_object (ev_window->priv->view, "focus_in_event",
G_CALLBACK (view_actions_focus_in_cb),
gtk_container_add (GTK_CONTAINER (ev_window->priv->scrolled_window),
ev_window->priv->view);
- g_signal_connect (ev_window->priv->view,
- "notify::find-status",
- G_CALLBACK (view_find_status_changed_cb),
- ev_window);
g_signal_connect (ev_window->priv->view,
"notify::sizing-mode",
G_CALLBACK (ev_window_sizing_mode_changed_cb),
"/AttachmentPopup");
ev_window->priv->attach_list = NULL;
+ /* Media player keys */
+ mpkeys = ev_application_get_media_keys (EV_APP);
+ if (mpkeys) {
+ g_signal_connect_swapped (mpkeys, "key_pressed",
+ G_CALLBACK (ev_window_media_player_key_pressed),
+ ev_window);
+ }
+
/* Give focus to the document view */
gtk_widget_grab_focus (ev_window->priv->view);
ev_window_sizing_mode_changed_cb (EV_VIEW (ev_window->priv->view), NULL, ev_window);
ev_window_setup_action_sensitivity (ev_window);
+
+ /* Drag and Drop */
+ gtk_drag_dest_set (GTK_WIDGET (ev_window),
+ GTK_DEST_DEFAULT_ALL,
+ NULL, 0,
+ GDK_ACTION_COPY);
+ gtk_drag_dest_add_uri_targets (GTK_WIDGET (ev_window));
}
/**