#include "ev-document-links.h"
#include "ev-document-fonts.h"
#include "ev-document-find.h"
+#include "ev-document-images.h"
#include "ev-document-security.h"
#include "ev-document-factory.h"
#include "ev-job-queue.h"
#include "ev-utils.h"
#include "ev-history.h"
#include "ev-image.h"
+#include "ev-message-area.h"
+#include "ev-mount-operation.h"
+#include "ev-file-monitor.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_PDF
#include <poppler.h>
#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 <gio/gio.h>
#include <gconf/gconf-client.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
-#include "ev-message-area.h"
-
-#include "eggfileformatchooser.h"
-
-#if !GLIB_CHECK_VERSION (2, 13, 3)
-char *xdg_user_dir_lookup (char *type);
-#endif
-
typedef enum {
PAGE_MODE_DOCUMENT,
PAGE_MODE_PASSWORD
/* Dialogs */
GtkWidget *properties;
-#ifdef WITH_PRINT
GtkWidget *print_dialog;
-#endif
GtkWidget *password_dialog;
/* UI Builders */
EvLinkDest *dest;
gboolean unlink_temp_file;
gboolean in_reload;
+ EvFileMonitor *monitor;
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;
+
+ /* 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 THUMBNAILS_SIDEBAR_ID "thumbnails"
#define ATTACHMENTS_SIDEBAR_ID "attachments"
-#ifdef WITH_GTK_PRINT
static const gchar *document_print_settings[] = {
GTK_PRINT_SETTINGS_N_COPIES,
GTK_PRINT_SETTINGS_COLLATE,
GTK_PRINT_SETTINGS_PAGE_RANGES,
GTK_PRINT_SETTINGS_PAGE_SET
};
-#endif /* WITH_GTK_PRINT */
static void ev_window_update_actions (EvWindow *ev_window);
static void ev_window_sidebar_visibility_changed_cb (EvSidebar *ev_sidebar,
EvWindowPageMode page_mode);
static void ev_window_load_job_cb (EvJobLoad *job,
gpointer data);
+static void ev_window_reload_document (EvWindow *window);
+static void ev_window_reload_job_cb (EvJobLoad *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,
EvWindow *window);
-#endif
static void ev_window_save_job_cb (EvJobSave *save,
EvWindow *window);
static void ev_window_sizing_mode_changed_cb (EvView *view,
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 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);
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);
}
static void
-ev_window_error_message_response_cb (EvMessageArea *area,
- gint response_id,
- EvWindow *window)
+ev_window_message_area_response_cb (EvMessageArea *area,
+ gint response_id,
+ EvWindow *window)
{
ev_window_set_message_area (window, NULL);
}
GTK_STOCK_CLOSE,
GTK_RESPONSE_CANCEL,
NULL);
- ev_message_area_set_secondary_text (EV_MESSAGE_AREA (area), error->message);
+ 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 (EV_WINDOW (window), area);
+}
+
+static void
+ev_window_warning_message (GtkWindow *window, const gchar *msg)
+{
+ GtkWidget *area;
+
+ if (EV_WINDOW (window)->priv->message_area)
+ return;
+
+ area = ev_message_area_new (GTK_MESSAGE_WARNING,
+ msg,
+ GTK_STOCK_CLOSE,
+ GTK_RESPONSE_CANCEL,
+ NULL);
+
g_signal_connect (area, "response",
- G_CALLBACK (ev_window_error_message_response_cb),
+ G_CALLBACK (ev_window_message_area_response_cb),
window);
gtk_widget_show (area);
ev_window_set_message_area (EV_WINDOW (window), area);
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);
}
static gboolean
if (ev_page_cache_get_n_pages (ev_window->priv->page_cache) > 0) {
ev_view_set_document (view, document);
+ } else {
+ ev_window_warning_message (GTK_WINDOW (ev_window),
+ _("The document contains no pages"));
}
g_idle_add ((GSourceFunc)ev_window_setup_document, ev_window);
}
+static void
+ev_window_document_changed (EvWindow *ev_window,
+ gpointer user_data)
+{
+ ev_window_reload_document (ev_window);
+}
+
static void
password_dialog_response (GtkWidget *password_dialog,
gint response_id,
}
}
+static void
+ev_window_clear_reload_job (EvWindow *ev_window)
+{
+ if (ev_window->priv->reload_job != NULL) {
+
+ if (!ev_window->priv->reload_job->finished)
+ ev_job_queue_remove_job (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);
-
- filename = g_filename_from_uri (ev_window->priv->uri, NULL, NULL);
- if (!filename)
- return;
+ file = g_file_new_for_uri (ev_window->priv->uri);
+ tempdir = g_file_new_for_path (g_get_tmp_dir ());
- tempdir = g_get_tmp_dir ();
- if (g_ascii_strncasecmp (filename, tempdir, strlen (tempdir)) == 0) {
- g_unlink (filename);
+ if (g_file_has_prefix (file, tempdir)) {
+ g_file_delete (file, NULL, NULL);
}
- g_free (filename);
+ g_object_unref (file);
+ g_object_unref (tempdir);
}
/* This callback will executed when load job will be finished.
EvDocument *document = EV_JOB (job)->document;
g_assert (job->uri);
-
+
ev_view_set_loading (EV_VIEW (ev_window->priv->view), FALSE);
/* Success! */
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);
- }
- } else if (job->search_string && EV_IS_DOCUMENT_FIND (document)) {
+ if (job->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->search_string);
}
+ /* Create a monitor for the document */
+ ev_window->priv->monitor = ev_file_monitor_new (job->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;
+ GFile *file;
+ gchar *base_name;
setup_view_from_metadata (ev_window);
- file_name = gnome_vfs_format_uri_for_display (job->uri);
- base_name = g_path_get_basename (file_name);
+ file = g_file_new_for_uri (job->uri);
+ base_name = g_file_get_basename (file);
ev_password_view_set_file_name (EV_PASSWORD_VIEW (ev_window->priv->password_view),
base_name);
- g_free (file_name);
+ g_object_unref (file);
g_free (base_name);
ev_window_set_page_mode (ev_window, PAGE_MODE_PASSWORD);
_("Unable to open document"),
job->error);
ev_window_clear_load_job (ev_window);
- ev_window->priv->in_reload = FALSE;
}
+}
- return;
+static void
+ev_window_reload_job_cb (EvJobLoad *job,
+ EvWindow *ev_window)
+{
+ GtkWidget *widget;
+
+ if (job->error) {
+ ev_window_clear_reload_job (ev_window);
+ ev_window->priv->in_reload = FALSE;
+ return;
+ }
+
+ ev_window_set_document (ev_window, EV_JOB (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;
}
/**
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 (GTK_WINDOW (ev_window),
+ _("Unable to open document"),
+ error);
+ g_free (ev_window->priv->local_uri);
+ ev_window->priv->local_uri = NULL;
+}
- 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
+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);
}
+}
- return 0;
+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_queue_add_job (ev_window->priv->load_job, EV_JOB_PRIORITY_HIGH);
+ g_object_unref (source);
+
+ 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
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);
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;
-
- /* 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 = 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;
+ 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_queue_add_job (ev_window->priv->load_job, EV_JOB_PRIORITY_HIGH);
}
+}
+
+static void
+ev_window_reload_document (EvWindow *ev_window)
+{
+ const gchar *uri;
- gnome_vfs_uri_unref (source_uri);
- ev_job_queue_add_job (ev_window->priv->load_job, EV_JOB_PRIORITY_HIGH);
+ ev_window_clear_reload_job (ev_window);
+ ev_window->priv->in_reload = TRUE;
+
+ 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_queue_add_job (ev_window->priv->reload_job, EV_JOB_PRIORITY_LOW);
}
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",
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;
+ GtkWidget *dialog;
+ gchar *name;
+ GError *error = NULL;
+
+ if (g_file_copy_finish (src, async_result, &error)) {
+ ev_tmp_file_unlink (src);
+ return;
}
- return 0;
+ window = g_object_get_data (G_OBJECT (dst), "ev-window");
+ name = g_file_get_basename (dst);
+ dialog = gtk_message_dialog_new (GTK_WINDOW (window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ _("The file could not be saved as ā%sā."),
+ name);
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ "%s", error->message);
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (gtk_widget_destroy),
+ NULL);
+ gtk_widget_show (dialog);
+ 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
{
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)
{
GTK_BUTTONS_OK,
_("Failed to print document"));
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- error->message);
+ "%s", error->message);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
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);
}
}
EvWindow *window)
{
if (job->error) {
- g_warning (job->error->message);
+ g_warning ("%s", job->error->message);
ev_window_clear_print_job (window);
return;
}
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_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);
-
- config = load_print_config_from_file ();
-
- if (ev_window->priv->print_job == NULL)
- ev_window->priv->print_job = gnome_print_job_new (config);
-
- if (ev_window->priv->print_dialog == NULL) {
- ev_window->priv->print_dialog =
- gnome_print_dialog_new (ev_window->priv->print_job,
- (guchar *) _("Print"),
- (GNOME_PRINT_DIALOG_RANGE |
- GNOME_PRINT_DIALOG_COPIES));
- }
-
- gtk_window_set_transient_for (GTK_WINDOW (ev_window->priv->print_dialog),
- GTK_WINDOW (ev_window));
- g_object_unref (config);
-
- pages_label = g_strconcat (_("Pages"), " ", NULL);
- gnome_print_dialog_construct_range_page (GNOME_PRINT_DIALOG (ev_window->priv->print_dialog),
- GNOME_PRINT_RANGE_ALL |
- GNOME_PRINT_RANGE_RANGE,
- first_page, last_page,
- NULL, (const guchar *)pages_label);
- g_free (pages_label);
-
- gtk_dialog_set_response_sensitive (GTK_DIALOG (ev_window->priv->print_dialog),
- GNOME_PRINT_DIALOG_RESPONSE_PREVIEW,
- FALSE);
-
- g_signal_connect (G_OBJECT (ev_window->priv->print_dialog), "response",
- G_CALLBACK (ev_window_print_dialog_response_cb),
- ev_window);
- gtk_widget_show (ev_window->priv->print_dialog);
-}
-#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
{
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);
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,
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);
+ ev_window_stop_presentation (window, TRUE);
}
}
static void
ev_window_cmd_view_reload (GtkAction *action, EvWindow *ev_window)
{
- gchar *uri;
-
- uri = g_strdup (ev_window->priv->uri);
- ev_window_open_uri (ev_window, uri, NULL, 0, NULL, FALSE, NULL);
- g_free (uri);
+ ev_window_reload_document (ev_window);
}
static void
ev_window_cmd_view_autoscroll (GtkAction *action, EvWindow *ev_window)
{
- ev_view_autoscroll (EV_VIEW (ev_window->priv->view));
+ ev_view_autoscroll_start (EV_VIEW (ev_window->priv->view));
}
static void
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);
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)
GTK_BUTTONS_OK,
_("Failed to print document"));
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- error->message);
+ "%s", error->message);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
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)
&error);
if (error) {
- g_warning (error->message);
+ g_warning ("%s", error->message);
g_error_free (error);
print_settings = NULL;
}
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);
find_bar_close_cb (EggFindBar *find_bar,
EvWindow *ev_window)
{
+ ev_view_find_cancel (EV_VIEW (ev_window->priv->view));
update_chrome_flag (ev_window, EV_CHROME_FINDBAR, FALSE);
update_chrome_visibility (ev_window);
}
EvWindow *window = EV_WINDOW (object);
EvWindowPrivate *priv = window->priv;
+ 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);
}
}
ev_window_close_dialogs (window);
-
-#ifdef WITH_GTK_PRINT
ev_window_clear_print_job (window);
if (window->priv->gtk_print_job) {
g_object_unref (window->priv->print_page_setup);
window->priv->print_page_setup = NULL;
}
-#endif
if (priv->link) {
g_object_unref (priv->link);
{ "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_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 */
"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",
launch_action (EvWindow *window, EvLinkAction *action)
{
const char *filename = ev_link_action_get_filename (action);
- char *uri = NULL;
+ const char *content_type;
+ GAppInfo *app_info;
+ GFileInfo *file_info;
+ GFile *file;
+ GList *file_list = 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;
+
+ base_file = g_file_new_for_uri (window->priv->uri);
+ 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);
+
+ file_info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+ 0, NULL, NULL);
+ if (file_info == NULL) {
+ g_object_unref (file);
+ return;
}
+
+ content_type = g_file_info_get_content_type (file_info);
+ app_info = g_app_info_get_default_for_type (content_type, TRUE);
+
+ file_list = g_list_append (file_list, file);
- g_free (uri);
+ /* FIXME: should we use a GAppLaunchContext? */
+ g_app_info_launch (app_info, file_list,
+ NULL, NULL);
+
+ g_list_free (file_list);
+ g_object_unref (app_info);
+ g_object_unref (file_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;
-
- 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) {
+ GError *error = NULL;
+ gboolean ret;
+
+ ret = g_app_info_launch_default_for_uri (uri, NULL, &error);
+ if (ret == FALSE) {
+ GtkWidget *dialog;
+
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);
+ error->message, uri);
g_signal_connect (dialog, "response",
G_CALLBACK (gtk_widget_destroy),
NULL);
gtk_widget_show (dialog);
-
+ g_error_free(error);
}
- return;
}
static void
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)
{
- GtkWidget *format_chooser;
- GnomeVFSURI *target_uri;
- gchar *uri;
- gchar *uri_extension;
- gchar *filename;
- gchar *file_format;
- gboolean is_local;
- GError *error = NULL;
- guint format;
+ 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);
return;
}
- format_chooser = gtk_file_chooser_get_extra_widget (GTK_FILE_CHOOSER (fc));
-
uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
- format = egg_file_format_chooser_get_format (EGG_FILE_FORMAT_CHOOSER (format_chooser), uri);
- uri_extension = egg_file_format_chooser_append_extension (EGG_FILE_FORMAT_CHOOSER (format_chooser),
- uri, format);
- file_format = (char *)egg_file_format_chooser_get_format_data (EGG_FILE_FORMAT_CHOOSER (format_chooser),
- format);
- target_uri = gnome_vfs_uri_new (uri_extension);
- is_local = gnome_vfs_uri_is_local (target_uri);
-
- if (is_local) {
- filename = g_filename_from_uri (uri_extension, NULL, NULL);
+ filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (fc));
+ format = g_object_get_data (G_OBJECT (filter), "pixbuf-format");
+
+ if (format == NULL) {
+ format = get_gdk_pixbuf_format_by_extension (uri);
+ }
+
+ if (format == NULL) {
+ ev_window_error_message (GTK_WINDOW (ev_window),
+ _("Couldn't find appropriate format to save image"),
+ NULL);
+ 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);
- g_free (uri_extension);
- gdk_pixbuf_save (ev_image_get_pixbuf (ev_window->priv->image),
- filename, file_format, &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_message (GTK_WINDOW (ev_window),
error);
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, *format_chooser;
- GtkFileFilter *filter;
+ GtkWidget *fc;
if (!window->priv->image)
return;
gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (fc), FALSE);
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
- format_chooser = egg_file_format_chooser_new ();
- egg_file_format_chooser_add_pixbuf_formats (EGG_FILE_FORMAT_CHOOSER (format_chooser),
- 0, NULL);
+ file_chooser_dialog_add_writable_pixbuf_formats (GTK_FILE_CHOOSER (fc));
- gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (fc), format_chooser);
-
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
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_message (GTK_WINDOW (ev_window),
_("The attachment could not be saved."),
error);
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);
}