#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 "egg-toolbar-editor.h"
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.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-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"
-#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
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;
/* Dialogs */
GtkWidget *properties;
-#ifdef WITH_PRINT
GtkWidget *print_dialog;
-#endif
- GtkWidget *password_dialog;
/* UI Builders */
GtkActionGroup *action_group;
/* 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;
EvWindowPageMode page_mode;
EvWindowTitle *title;
- EvJob *load_job;
- EvJob *thumbnail_job;
- EvJob *save_job;
-#ifdef WITH_GNOME_PRINT
- GnomePrintJob *print_job;
-#endif
-
-#ifdef WITH_GTK_PRINT
+ EvJob *load_job;
+ EvJob *reload_job;
+ EvJob *thumbnail_job;
+ EvJob *save_job;
EvJob *print_job;
+ EvJob *find_job;
+
+ /* Printing */
gboolean print_preview;
GtkPrintJob *gtk_print_job;
GtkPrinter *printer;
GtkPrintSettings *print_settings;
GtkPageSetup *print_page_setup;
-#endif
+
};
#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
+};
static void ev_window_update_actions (EvWindow *ev_window);
static void ev_window_sidebar_visibility_changed_cb (EvSidebar *ev_sidebar,
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_print_job_cb (EvJob *job,
EvWindow *window);
-#endif
-static void ev_window_save_job_cb (EvJobSave *save,
+static void ev_window_save_job_cb (EvJob *save,
EvWindow *window);
static void ev_window_sizing_mode_changed_cb (EvView *view,
GParamSpec *pspec,
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 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);
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);
}
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)
{
- gtk_widget_destroy (dialog);
+ 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_error_dialog (GtkWindow *window, const gchar *msg, GError *error)
+ev_window_message_area_response_cb (EvMessageArea *area,
+ gint response_id,
+ EvWindow *window)
{
- GtkWidget *dialog;
+ ev_window_set_message_area (window, 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);
+static void
+ev_window_error_message (EvWindow *window,
+ GError *error,
+ const gchar *format,
+ ...)
+{
+ 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_ERROR,
+ msg,
+ GTK_STOCK_CLOSE,
+ GTK_RESPONSE_CANCEL,
+ 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_CANCEL,
+ 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);
}
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)) {
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);
static void
ev_window_refresh_window_thumbnail (EvWindow *ev_window, int rotation)
{
-
- EvRenderContext *rc;
gint page_width, page_height;
gdouble scale;
EvDocument *document = ev_window->priv->document;
- if (!EV_IS_DOCUMENT_THUMBNAILS (document)) {
+ if (!EV_IS_DOCUMENT_THUMBNAILS (document) ||
+ ev_page_cache_get_n_pages (ev_window->priv->page_cache) <= 0) {
return;
}
&page_width, &page_height);
scale = (gdouble)128 / (gdouble)page_width;
- rc = ev_render_context_new (rotation, 0, scale);
-
- ev_window->priv->thumbnail_job = ev_job_thumbnail_new (document, rc);
+ 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_queue_add_job (EV_JOB (ev_window->priv->thumbnail_job), EV_JOB_PRIORITY_LOW);
- g_object_unref (rc);
+ ev_job_scheduler_push_job (ev_window->priv->thumbnail_job, EV_JOB_PRIORITY_NONE);
}
static gboolean
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);
- }
+
+ ev_window->priv->setup_document_idle = 0;
ev_window_refresh_window_thumbnail (ev_window, 0);
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_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);
}
}
+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)
{
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);
+ file = g_file_new_for_uri (ev_window->priv->uri);
+ tempdir = g_file_new_for_path (g_get_tmp_dir ());
- filename = g_filename_from_uri (ev_window->priv->uri, NULL, NULL);
- if (!filename)
- return;
-
- 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 (job_load->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 (job_load->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 (g_object_ref (job_load->dest));
link = ev_link_new (NULL, link_action);
ev_view_handle_link (EV_VIEW (ev_window->priv->view), link);
g_object_unref (link);
}
- switch (job->mode) {
+ switch (job_load->mode) {
case EV_WINDOW_MODE_FULLSCREEN:
ev_window_run_fullscreen (ev_window);
break;
break;
}
- /* Restart the search after reloading */
- if (ev_window->priv->in_reload) {
- GtkWidget *widget;
-
- 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);
- }
+ if (job_load->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),
+ job_load->search_string);
}
+ /* Create a monitor for the document */
+ ev_window->priv->monitor = ev_file_monitor_new (ev_window->priv->uri);
+ g_signal_connect_swapped (G_OBJECT (ev_window->priv->monitor), "changed",
+ G_CALLBACK (ev_window_document_changed),
+ ev_window);
+
ev_window_clear_load_job (ev_window);
- ev_window->priv->in_reload = FALSE;
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);
- ev_window->priv->in_reload = FALSE;
}
+}
- 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_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;
+}
- 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
+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);
}
- return 0;
+ 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;
+
+ 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 {
+ ev_window_load_remote_failed (ev_window, error);
+ g_object_unref (source);
+ }
+
+ g_error_free (error);
+}
+
+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);
+ }
+
+ target_file = g_file_new_for_uri (ev_window->priv->local_uri);
+ g_file_copy_async (source_file, target_file,
+ 0, G_PRIORITY_DEFAULT, NULL,
+ NULL, NULL, /* no progress callback */
+ (GAsyncReadyCallback) window_open_file_copy_ready_cb,
+ ev_window);
+ g_object_unref (target_file);
}
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->priv->in_reload = TRUE;
+ 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);
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, dest, mode, search_string);
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, NULL, 0, NULL);
+ 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);
+}
+
+static void
+reload_remote_copy_ready_cb (GFile *remote,
+ GAsyncResult *async_result,
+ EvWindow *ev_window)
+{
+ g_file_copy_finish (remote, async_result, NULL);
+ ev_window_reload_local (ev_window);
+ g_object_unref (remote);
+}
+
+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);
- 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);
-
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;
+ 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, NULL,
+ NULL, NULL, /* no progress callback */
+ (GAsyncReadyCallback) reload_remote_copy_ready_cb,
+ ev_window);
+ g_object_unref (target_file);
+ } 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);
}
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);
+}
+
+static void
+ev_window_open_recent_action_item_activated (EvOpenRecentAction *action,
+ const gchar *uri,
+ EvWindow *window)
+{
+ ev_application_open_uri_at_dest (EV_APP, uri,
+ gtk_window_get_screen (GTK_WINDOW (window)),
+ NULL, 0, NULL, FALSE, NULL,
GDK_CURRENT_TIME);
}
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;
g_list_free (items);
}
-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 ();
+static void
+window_save_file_copy_ready_cb (GFile *src,
+ GAsyncResult *async_result,
+ GFile *dst)
+{
+ EvWindow *window;
+ gchar *name;
+ GError *error = NULL;
+
+ if (g_file_copy_finish (src, async_result, &error)) {
+ ev_tmp_file_unlink (src);
+ return;
}
- return 0;
+ window = EV_WINDOW (g_object_get_data (G_OBJECT (dst), "ev-window"));
+ name = g_file_get_basename (dst);
+ ev_window_error_message (window, error,
+ _("The file could not be saved as “%s”."),
+ name);
+ ev_tmp_file_unlink (src);
+ g_free (name);
+ g_error_free (error);
}
static void
-ev_window_save_remote (EvWindow *ev_window,
- GnomeVFSURI *src,
- GnomeVFSURI *dst)
+ev_window_save_remote (EvWindow *ev_window,
+ GFile *src,
+ GFile *dst)
{
- GnomeVFSAsyncHandle *handle;
- GList *slist = NULL;
- GList *tlist = NULL;
-
- 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);
+ g_object_set_data (G_OBJECT (dst), "ev-window", ev_window);
+ g_file_copy_async (src, dst,
+ G_FILE_COPY_OVERWRITE,
+ G_PRIORITY_DEFAULT, NULL,
+ NULL, NULL, /* no progress callback */
+ (GAsyncReadyCallback) window_save_file_copy_ready_cb,
+ dst);
}
static void
ev_window_clear_save_job (EvWindow *ev_window)
{
if (ev_window->priv->save_job != NULL) {
- if (!ev_window->priv->save_job->finished)
- ev_job_queue_remove_job (ev_window->priv->save_job);
+ if (!ev_job_is_finished (ev_window->priv->save_job))
+ ev_job_cancel (ev_window->priv->save_job);
g_signal_handlers_disconnect_by_func (ev_window->priv->save_job,
ev_window_save_job_cb,
}
static void
-ev_window_save_job_cb (EvJobSave *job,
+ev_window_save_job_cb (EvJob *job,
EvWindow *window)
{
- if (job->error) {
- gchar *msg;
-
- msg = g_strdup_printf (_("The file could not be saved as “%s”."), job->uri);
- ev_window_error_dialog (GTK_WINDOW (window), msg, job->error);
- g_free (msg);
+ 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);
}
ev_window_clear_save_job (window);
G_CALLBACK (ev_window_save_job_cb),
ev_window);
/* The priority doesn't matter for this job */
- ev_job_queue_add_job (ev_window->priv->save_job, EV_JOB_PRIORITY_LOW);
+ 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_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_name = gnome_vfs_format_uri_for_display (ev_window->priv->uri);
- base_name = g_path_get_basename (file_name);
+ 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);
-#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
- g_free (file_name);
+ g_object_unref (file);
g_free (base_name);
g_signal_connect (fc, "response",
gtk_widget_show (fc);
}
-#ifdef WITH_GTK_PRINT
static void
ev_window_print_page_setup_done_cb (GtkPageSetup *page_setup,
EvWindow *window)
g_object_unref (window->priv->print_page_setup);
window->priv->print_page_setup = g_object_ref (page_setup);
}
-#endif /* WITH_GTK_PRINT */
static void
ev_window_cmd_file_print_setup (GtkAction *action, EvWindow *ev_window)
{
-#ifdef WITH_GTK_PRINT
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)
{
if (window->priv->print_job) {
- if (!window->priv->print_job->finished)
- ev_job_queue_remove_job (window->priv->print_job);
+ if (!ev_job_is_finished (window->priv->print_job))
+ ev_job_cancel (window->priv->print_job);
g_signal_handlers_disconnect_by_func (window->priv->print_job,
ev_window_print_job_cb,
}
}
+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);
+ }
+}
+
+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_print_finished (GtkPrintJob *print_job,
EvWindow *window,
ev_window_clear_print_job (window);
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"));
} else {
/* If printed successfully, save print settings */
ev_application_set_print_settings (EV_APP,
window->priv->print_settings);
+ ev_window_save_print_settings (window);
}
}
ev_application_set_print_settings (EV_APP,
window->priv->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,
+ NULL,
TRUE,
print_settings_file,
GDK_CURRENT_TIME);
GtkPrintJob *job;
GError *error = NULL;
- job = gtk_print_job_new ("evince-print",
+ job = gtk_print_job_new (gtk_window_get_title (GTK_WINDOW (window)),
window->priv->printer,
settings,
window->priv->print_page_setup);
window, NULL);
} else {
ev_window_clear_print_job (window);
- g_warning (error->message);
+ g_warning ("%s", error->message);
g_error_free (error);
}
}
}
static void
-ev_window_print_job_cb (EvJobPrint *job,
- EvWindow *window)
+ev_window_print_job_cb (EvJob *job,
+ EvWindow *window)
{
- if (job->error) {
- g_warning (job->error->message);
+ if (ev_job_is_failed (job)) {
+ g_warning ("%s", job->error->message);
ev_window_clear_print_job (window);
return;
}
- g_assert (job->temp_file != NULL);
+ g_assert (EV_JOB_PRINT (job)->temp_file != NULL);
- ev_window_print_send (window, job->temp_file);
+ ev_window_print_send (window, EV_JOB_PRINT (job)->temp_file);
}
static gboolean
GtkPrintPages print_pages;
const gchar *file_format;
- if (response == GTK_RESPONSE_CANCEL) {
+ if (response != GTK_RESPONSE_OK &&
+ response != GTK_RESPONSE_APPLY) {
gtk_widget_destroy (GTK_WIDGET (dialog));
window->priv->print_dialog = NULL;
GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT);
if (!gtk_printer_accepts_ps (window->priv->printer)) {
- GtkWidget *msgdialog;
-
- 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);
-
+ ev_window_error_message (window, NULL, "%s",
+ _("Printing is not supported on this printer."));
return FALSE;
}
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);
+ ev_job_scheduler_push_job (window->priv->print_job, EV_JOB_PRIORITY_NONE);
gtk_widget_destroy (GTK_WIDGET (dialog));
window->priv->print_dialog = NULL;
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.start = first_page - 1;
range.end = last_page - 1;
- gtk_print_settings_set_print_pages (ev_window->priv->print_settings,
- GTK_PRINT_PAGES_RANGES);
- gtk_print_settings_set_page_ranges (ev_window->priv->print_settings,
- &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);
-
- 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;
-
- 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);
+ gtk_print_settings_set_print_pages (ev_window->priv->print_settings,
+ GTK_PRINT_PAGES_RANGES);
+ gtk_print_settings_set_page_ranges (ev_window->priv->print_settings,
+ &range, 1);
+ }
- config = load_print_config_from_file ();
+ 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);
- if (ev_window->priv->print_job == NULL)
- ev_window->priv->print_job = gnome_print_job_new (config);
+ gtk_print_unix_dialog_set_current_page (GTK_PRINT_UNIX_DIALOG (dialog),
+ current_page);
- 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_print_unix_dialog_set_settings (GTK_PRINT_UNIX_DIALOG (dialog),
+ ev_window->priv->print_settings);
- 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",
+ 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 (ev_window->priv->print_dialog);
+
+ gtk_widget_show (dialog);
}
-#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));
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);
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);
/* If the user doesn't have the main toolbar he/she won't probably want
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)
{
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);
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);
(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)
const gchar *print_settings_file = priv->print_settings_file;
if (print_settings_file) {
&error);
if (error) {
- g_warning (error->message);
+ g_warning ("%s", error->message);
g_error_free (error);
print_settings = NULL;
}
}
}
-#endif /* GTK 2.11.0 */
if (!print_settings)
print_settings = gtk_print_settings_new ();
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);
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);
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);
}
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
{
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;
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_close_dialogs (window);
ev_window_clear_print_job (window);
if (window->priv->gtk_print_job) {
g_object_unref (window->priv->print_page_setup);
window->priv->print_page_setup = NULL;
}
-#endif
if (priv->link) {
g_object_unref (priv->link);
g_object_class->finalize = ev_window_finalize;
widget_class->screen_changed = ev_window_screen_changed;
+ widget_class->window_state_event = ev_window_state_event;
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",
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 */
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);
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 == NULL)
+ return;
- if (filename && g_path_is_absolute (filename)) {
- uri = gnome_vfs_get_uri_from_local_path (filename);
+ if (g_path_is_absolute (filename)) {
+ file = g_file_new_for_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);
- }
+ 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);
}
- if (uri) {
- gnome_vfs_url_show (uri);
- } else {
- gnome_vfs_url_show (filename);
+ 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);
+
+ return;
}
- g_free (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
+
+ 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);
+ }
+
+ g_object_unref (app_info);
+ g_object_unref (file);
/* According to the PDF spec filename can be an executable. I'm not sure
allowing to launch executables is a good idea though. -- marco */
launch_external_uri (EvWindow *window, EvLinkAction *action)
{
const gchar *uri = ev_link_action_get_uri (action);
- GnomeVFSResult result = gnome_vfs_url_show (uri);
- GtkWidget *dialog;
- gchar* message = NULL;
+ GError *error = NULL;
+ gboolean ret;
+#if GTK_CHECK_VERSION (2, 14, 0)
+ GAppLaunchContext *context = NULL;
+#endif
- switch(result) {
- case GNOME_VFS_OK:
- break;
- case GNOME_VFS_ERROR_BAD_PARAMETERS:
- message = _("Invalid URI: “%s”");
- break;
- case GNOME_VFS_ERROR_NOT_SUPPORTED:
- message = _("Unsupported URI: “%s”");
- break;
- default:
- message = _("Unknown error");
- }
- if(message) {
- 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),
- message, 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
+ 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);
+ }
+
+ if (ret == FALSE) {
+ ev_window_error_message (window, error,
+ "%s", _("Unable to open external link"));
+ g_error_free (error);
}
- return;
}
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_uri (filename);
+
+ ev_window_save_remote (ev_window, 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, 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);
}
-#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);
-
+
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);