#include "ev-metadata-manager.h"
#include "ev-file-helpers.h"
#include "ev-utils.h"
-#include "ev-debug.h"
#include "ev-history.h"
#include "ev-image.h"
#include <gtk/gtk.h>
#include <gnome.h>
#include <libgnomevfs/gnome-vfs-utils.h>
+#include <libgnomevfs/gnome-vfs-async-ops.h>
#include <gconf/gconf-client.h>
#include <string.h>
+char *xdg_user_dir_lookup (char *type);
+
typedef enum {
PAGE_MODE_DOCUMENT,
PAGE_MODE_PASSWORD
EggRecentViewUIManager *recent_view;
#endif
- EvJob *xfer_job;
+ EvJob *load_job;
+ EvJob *thumbnail_job;
#ifdef WITH_GNOME_PRINT
GnomePrintJob *print_job;
#endif
EvWindow *ev_window);
static void ev_window_set_page_mode (EvWindow *window,
EvWindowPageMode page_mode);
-static void ev_window_xfer_job_cb (EvJobXfer *job,
+static void ev_window_load_job_cb (EvJobLoad *job,
gpointer data);
+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);
static gboolean fullscreen_leave_notify_cb (GtkWidget *widget,
GdkEventCrossing *event,
gpointer user_data);
+static void view_handle_link_cb (EvView *view,
+ EvLink *link,
+ EvWindow *window);
G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW)
EvView *view = EV_VIEW (ev_window->priv->view);
int n_pages = 0, page = -1;
gboolean has_pages = FALSE;
+ gboolean presentation_mode;
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;
}
- ev_window_set_action_sensitive (ev_window, "EditCopy", has_pages && ev_view_get_has_selection (view));
+ 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));
+ ev_view_can_find_next (view));
ev_window_set_action_sensitive (ev_window, "EditFindPrevious",
- ev_view_can_find_previous (view));
+ ev_view_can_find_previous (view));
+ presentation_mode = ev_view_get_presentation (view);
+
ev_window_set_action_sensitive (ev_window, "ViewZoomIn",
- has_pages && ev_view_can_zoom_in (view));
+ has_pages &&
+ ev_view_can_zoom_in (view) &&
+ !presentation_mode);
ev_window_set_action_sensitive (ev_window, "ViewZoomOut",
- has_pages && ev_view_can_zoom_out (view));
-
+ has_pages &&
+ ev_view_can_zoom_out (view) &&
+ !presentation_mode);
+
/* Go menu */
if (has_pages) {
ev_window_set_action_sensitive (ev_window, "GoPreviousPage", page > 0);
ev_window_set_view_accels_sensitivity (EvWindow *window, gboolean sensitive)
{
gboolean can_find;
-
+
can_find = window->priv->document &&
EV_IS_DOCUMENT_FIND (window->priv->document);
g_return_val_if_fail (EV_IS_WINDOW (ev_window), FALSE);
return (ev_window->priv->document == NULL) &&
- (ev_window->priv->xfer_job == NULL);
+ (ev_window->priv->load_job == NULL);
}
static void
gint page,
EvWindow *ev_window)
{
- gchar *label;
-
ev_window_update_actions (ev_window);
- if (ev_window->priv->history) {
- label = ev_page_cache_get_page_label (ev_window->priv->page_cache, page);
- ev_history_add_page (ev_window->priv->history, page, label);
- g_free (label);
- }
-
if (!ev_window_is_empty (ev_window))
ev_metadata_manager_set_int (ev_window->priv->uri, "page", page);
}
+typedef struct _FindTask {
+ const gchar *page_label;
+ gchar *chapter;
+} FindTask;
+
+static gboolean
+ev_window_find_chapter (GtkTreeModel *tree_model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ FindTask *task = (FindTask *)data;
+ gchar *page_string;
+
+ gtk_tree_model_get (tree_model, iter,
+ EV_DOCUMENT_LINKS_COLUMN_PAGE_LABEL, &page_string,
+ -1);
+
+ if (!page_string)
+ return FALSE;
+
+ if (!strcmp (page_string, task->page_label)) {
+ gtk_tree_model_get (tree_model, iter,
+ EV_DOCUMENT_LINKS_COLUMN_MARKUP, &task->chapter,
+ -1);
+ g_free (page_string);
+ return TRUE;
+ }
+
+ g_free (page_string);
+ return FALSE;
+}
+
+static void
+ev_window_add_history (EvWindow *window, gint page, EvLink *link)
+{
+ gchar *page_label = NULL;
+ gchar *link_title;
+ FindTask find_task;
+ EvLink *real_link;
+ EvLinkAction *action;
+ EvLinkDest *dest;
+
+ if (link) {
+ action = g_object_ref (ev_link_get_action (link));
+ dest = ev_link_action_get_dest (action);
+ page = ev_link_dest_get_page (dest);
+ page_label = ev_view_page_label_from_dest (EV_VIEW (window->priv->view), dest);
+ } else {
+ dest = ev_link_dest_new_page (page);
+ action = ev_link_action_new_dest (dest);
+ page_label = ev_page_cache_get_page_label (window->priv->page_cache, page);
+ }
+
+ if (!page_label)
+ return;
+
+ find_task.page_label = page_label;
+ find_task.chapter = NULL;
+
+ if (EV_IS_DOCUMENT_LINKS (window->priv->document) &&
+ ev_document_links_has_document_links (EV_DOCUMENT_LINKS (window->priv->document))) {
+ GtkTreeModel *model;
+
+ g_object_get (G_OBJECT (window->priv->sidebar_links), "model", &model, NULL);
+
+ if (model) {
+ gtk_tree_model_foreach (model,
+ ev_window_find_chapter,
+ &find_task);
+
+ g_object_unref (model);
+ }
+ }
+
+ if (find_task.chapter)
+ link_title = g_strdup_printf (_("Page %s - %s"), page_label, find_task.chapter);
+ else
+ link_title = g_strdup_printf (_("Page %s"), page_label);
+
+ real_link = ev_link_new (link_title, action);
+
+ ev_history_add_link (window->priv->history, real_link);
+
+ g_free (find_task.chapter);
+ g_free (link_title);
+ g_free (page_label);
+ g_object_unref (real_link);
+}
+
+static void
+view_handle_link_cb (EvView *view, EvLink *link, EvWindow *window)
+{
+ int current_page = ev_page_cache_get_current_page (window->priv->page_cache);
+
+ ev_window_add_history (window, 0, link);
+ ev_window_add_history (window, current_page, NULL);
+}
+
+static void
+history_changed_cb (EvPageCache *page_cache,
+ gint page,
+ EvWindow *window)
+{
+ int current_page = ev_page_cache_get_current_page (window->priv->page_cache);
+
+ ev_window_add_history (window, page, NULL);
+ ev_window_add_history (window, current_page, NULL);
+
+ return;
+}
+
static void
update_document_mode (EvWindow *window, EvDocumentMode mode)
{
if (window->priv->page_cache &&
ev_metadata_manager_get (uri, "window_width_ratio", &width_ratio, FALSE) &&
ev_metadata_manager_get (uri, "window_height_ratio", &height_ratio, FALSE)) {
+
gint document_width;
gint document_height;
+
+ GdkScreen *screen;
+
+ gint request_width;
+ gint request_height;
ev_page_cache_get_max_width (window->priv->page_cache,
0, 1.0,
0, 1.0,
&document_height);
+ request_width = g_value_get_double (&width_ratio) * document_width;
+ request_height = g_value_get_double (&height_ratio) * document_height;
+
+ screen = gtk_window_get_screen (GTK_WINDOW (window));
+
+ if (screen) {
+ request_width = MIN (request_width, gdk_screen_get_width (screen));
+ request_height = MIN (request_width, gdk_screen_get_height (screen));
+ }
+
gtk_window_resize (GTK_WINDOW (window),
- g_value_get_double (&width_ratio) * document_width,
- g_value_get_double (&height_ratio) * document_height);
+ request_width,
+ request_height);
g_value_unset (&width_ratio);
g_value_unset (&height_ratio);
}
-
}
static void
}
}
+static void
+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);
+
+ g_signal_handlers_disconnect_by_func (ev_window->priv->thumbnail_job,
+ ev_window_set_icon_from_thumbnail,
+ ev_window);
+ g_object_unref (ev_window->priv->thumbnail_job);
+ ev_window->priv->thumbnail_job = NULL;
+ }
+}
+
+static void
+ev_window_set_icon_from_thumbnail (EvJobThumbnail *job,
+ EvWindow *ev_window)
+{
+ if (job->thumbnail) {
+ gtk_window_set_icon (GTK_WINDOW (ev_window),
+ job->thumbnail);
+ }
+
+ ev_window_clear_thumbnail_job (ev_window);
+}
+
static void
ev_window_setup_document (EvWindow *ev_window)
{
document = ev_window->priv->document;
ev_window->priv->page_cache = ev_page_cache_get (ev_window->priv->document);
- g_signal_connect (ev_window->priv->page_cache, "page-changed", G_CALLBACK (page_changed_cb), ev_window);
+ g_signal_connect (ev_window->priv->page_cache, "page-changed",
+ G_CALLBACK (page_changed_cb), ev_window);
+ g_signal_connect (ev_window->priv->page_cache, "history-changed",
+ G_CALLBACK (history_changed_cb), ev_window);
if (EV_IS_DOCUMENT_FIND (document)) {
g_signal_connect_object (G_OBJECT (document),
ev_window, 0);
}
+ if (EV_IS_DOCUMENT_THUMBNAILS (document)) {
+ EvRenderContext *rc;
+ gint page_width, page_height;
+ gdouble scale;
+
+ ev_window_clear_thumbnail_job (ev_window);
+
+ ev_page_cache_get_size (ev_window->priv->page_cache,
+ 0, 0, 1.0,
+ &page_width, &page_height);
+ scale = (gdouble)128 / (gdouble)page_width;
+
+ rc = ev_render_context_new (0, 0, scale);
+ ev_window->priv->thumbnail_job = ev_job_thumbnail_new (document, rc);
+ g_signal_connect (ev_window->priv->thumbnail_job, "finished",
+ G_CALLBACK (ev_window_set_icon_from_thumbnail),
+ ev_window);
+ ev_job_queue_add_job (EV_JOB (ev_window->priv->thumbnail_job), EV_JOB_PRIORITY_LOW);
+ g_object_unref (rc);
+ }
+
ev_sidebar_set_document (sidebar, document);
if (ev_page_cache_get_n_pages (ev_window->priv->page_cache) > 0) {
ev_window->priv->history = ev_history_new ();
action = gtk_action_group_get_action (ev_window->priv->action_group, NAVIGATION_ACTION);
ev_navigation_action_set_history (EV_NAVIGATION_ACTION (action), ev_window->priv->history);
- ev_navigation_action_set_window (EV_NAVIGATION_ACTION (action), ev_window);
if (ev_window->priv->properties) {
ev_properties_dialog_set_document (EV_PROPERTIES_DIALOG (ev_window->priv->properties),
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->xfer_job->document),
+ ev_document_security_set_password (EV_DOCUMENT_SECURITY (ev_window->priv->load_job->document),
password);
ev_document_doc_mutex_unlock ();
}
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->xfer_job, EV_JOB_PRIORITY_HIGH);
+ ev_job_queue_add_job (ev_window->priv->load_job, EV_JOB_PRIORITY_HIGH);
gtk_widget_destroy (password_dialog);
gtk_widget_destroy (password_dialog);
}
-/* Called either by ev_window_xfer_job_cb or by the "unlock" callback on the
+/* 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)
{
- g_assert (ev_window->priv->xfer_job);
+ g_assert (ev_window->priv->load_job);
gtk_widget_set_sensitive (ev_window->priv->password_view, FALSE);
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));
+ (gpointer) &(ev_window->priv->password_dialog));
g_signal_connect (ev_window->priv->password_dialog,
"response",
G_CALLBACK (password_dialog_response),
}
static void
-ev_window_clear_xfer_job (EvWindow *ev_window)
+ev_window_clear_load_job (EvWindow *ev_window)
{
- if (ev_window->priv->xfer_job != NULL) {
+ if (ev_window->priv->load_job != NULL) {
- if (!ev_window->priv->xfer_job->finished)
- ev_job_queue_remove_job (ev_window->priv->xfer_job);
+ if (!ev_window->priv->load_job->finished)
+ ev_job_queue_remove_job (ev_window->priv->load_job);
- g_signal_handlers_disconnect_by_func (ev_window->priv->xfer_job, ev_window_xfer_job_cb, ev_window);
- g_object_unref (ev_window->priv->xfer_job);
- ev_window->priv->xfer_job = NULL;
+ g_signal_handlers_disconnect_by_func (ev_window->priv->load_job, ev_window_load_job_cb, ev_window);
+ g_object_unref (ev_window->priv->load_job);
+ ev_window->priv->load_job = NULL;
}
}
* function should _not_ necessarily expect those to exist after being
* called. */
static void
-ev_window_xfer_job_cb (EvJobXfer *job,
+ev_window_load_job_cb (EvJobLoad *job,
gpointer data)
{
EvWindow *ev_window = EV_WINDOW (data);
/* Success! */
if (job->error == NULL) {
-
- if (ev_window->priv->uri)
- g_free (ev_window->priv->uri);
- ev_window->priv->uri = g_strdup (job->uri);
-
- if (ev_window->priv->local_uri)
- g_free (ev_window->priv->local_uri);
- ev_window->priv->local_uri =
- job->local_uri ? g_strdup (job->local_uri) : NULL;
-
if (ev_window->priv->document)
g_object_unref (ev_window->priv->document);
ev_window->priv->document = g_object_ref (document);
- if (!ev_window->priv->unlink_temp_file) {
+ if (job->mode != EV_WINDOW_MODE_PREVIEW) {
setup_view_from_metadata (ev_window);
+ }
+
+ if (!ev_window->priv->unlink_temp_file) {
ev_window_add_recent (ev_window, ev_window->priv->uri);
}
ev_window_setup_document (ev_window);
- if (job->dest)
- ev_window_goto_dest (ev_window, job->dest);
+ if (job->dest) {
+ EvLink *link;
+ EvLinkAction *link_action;
+
+ link_action = ev_link_action_new_dest (g_object_ref (job->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) {
case EV_WINDOW_MODE_FULLSCREEN:
break;
}
- ev_window_clear_xfer_job (ev_window);
+ ev_window_clear_load_job (ev_window);
return;
}
job->error->code == EV_DOCUMENT_ERROR_ENCRYPTED) {
gchar *base_name, *file_name;
- g_free (ev_window->priv->uri);
- ev_window->priv->uri = g_strdup (job->uri);
setup_view_from_metadata (ev_window);
file_name = gnome_vfs_format_uri_for_display (job->uri);
ev_window_error_dialog (GTK_WINDOW (ev_window),
_("Unable to open document"),
job->error);
- ev_window_clear_xfer_job (ev_window);
+ ev_window_clear_load_job (ev_window);
}
return;
ev_window->priv->properties = NULL;
}
+static gint
+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);
+ }
+
+ 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 ();
+ }
+
+ return 0;
+}
+
void
ev_window_open_uri (EvWindow *ev_window,
const char *uri,
EvWindowRunMode mode,
gboolean unlink_temp_file)
{
+ GnomeVFSURI *source_uri;
+ GnomeVFSURI *target_uri;
+
ev_window_close_dialogs (ev_window);
- ev_window_clear_xfer_job (ev_window);
+ ev_window_clear_load_job (ev_window);
ev_window_clear_local_uri (ev_window);
ev_view_set_loading (EV_VIEW (ev_window->priv->view), TRUE);
ev_window->priv->unlink_temp_file = unlink_temp_file;
+
+ if (ev_window->priv->uri)
+ g_free (ev_window->priv->uri);
+ ev_window->priv->uri = g_strdup (uri);
+
+ setup_size_from_metadata (ev_window);
- ev_window->priv->xfer_job = ev_job_xfer_new (uri, dest, mode);
- g_signal_connect (ev_window->priv->xfer_job,
+ ev_window->priv->load_job = ev_job_load_new (uri, dest, mode);
+ g_signal_connect (ev_window->priv->load_job,
"finished",
- G_CALLBACK (ev_window_xfer_job_cb),
+ G_CALLBACK (ev_window_load_job_cb),
ev_window);
- ev_job_queue_add_job (ev_window->priv->xfer_job, EV_JOB_PRIORITY_HIGH);
-}
-void
-ev_window_goto_dest (EvWindow *ev_window, EvLinkDest *dest)
-{
- ev_view_goto_dest (EV_VIEW (ev_window->priv->view), dest);
+ 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)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;
+ }
+
+ gnome_vfs_uri_unref (source_uri);
+ ev_job_queue_add_job (ev_window->priv->load_job, EV_JOB_PRIORITY_HIGH);
}
static void
gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (chooser),
window->priv->uri);
}
+ else {
+ char *folder;
+ folder = xdg_user_dir_lookup ("DOCUMENTS");
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser),
+ folder);
+ free (folder);
+ }
g_signal_connect (chooser, "response",
G_CALLBACK (file_open_dialog_response_cb),
static void
ev_window_cmd_file_open_copy_at_dest (EvWindow *window, EvLinkDest *dest)
{
- GError *error = NULL;
- gchar *symlink_uri;
- gchar *old_filename;
- gchar *new_filename;
-
- old_filename = g_filename_from_uri (window->priv->uri, NULL, NULL);
+ GError *error = NULL;
+ gchar *symlink_uri;
+ gchar *old_filename;
+ gchar *new_filename;
+ const gchar *uri_unc;
+
+ uri_unc = g_object_get_data (G_OBJECT (window->priv->document),
+ "uri-uncompressed");
+ old_filename = g_filename_from_uri (uri_unc ? uri_unc : window->priv->uri,
+ NULL, NULL);
new_filename = ev_window_create_tmp_symlink (old_filename, &error);
if (error) {
p = filename;
end = filename + length;
- while (p != end)
- {
+ while (p != end) {
const gchar *next;
next = g_utf8_next_char (p);
- switch (*p)
- {
+ switch (*p) {
case '_':
g_string_append (str, "__");
break;
info = (GtkRecentInfo *) l->data;
- if (!gtk_recent_info_has_application (info, evince))
+ if (!gtk_recent_info_has_application (info, evince) ||
+ (gtk_recent_info_is_local (info) && !gtk_recent_info_exists (info)))
continue;
action_name = g_strdup_printf ("RecentFile%u", i++);
gint response_id,
EvWindow *ev_window)
{
- gboolean success;
-
- if (response_id == GTK_RESPONSE_OK) {
- gchar *uri;
- GError *err = NULL;
+ const gchar *uri_unc;
+ gint fd;
+ gchar *filename;
+ gchar *tmp_filename;
+ GError *error = NULL;
- uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
+ if (response_id != GTK_RESPONSE_OK) {
+ gtk_widget_destroy (fc);
+ return;
+ }
+
+ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fc));
+ tmp_filename = g_strdup_printf ("%s.XXXXXX", filename);
+
+ fd = g_mkstemp (tmp_filename);
+ if (fd == -1) {
+ gchar *display_name;
+ gint save_errno = errno;
+
+ display_name = g_filename_display_name (tmp_filename);
+ g_set_error (&error,
+ G_FILE_ERROR,
+ g_file_error_from_errno (save_errno),
+ _("Failed to create file “%s”: %s"),
+ display_name, g_strerror (save_errno));
+ g_free (display_name);
+ } else {
+ gchar *uri;
+
+ uri = g_filename_to_uri (tmp_filename, NULL, NULL);
+
ev_document_doc_mutex_lock ();
- success = ev_document_save (ev_window->priv->document, uri, &err);
+ ev_document_save (ev_window->priv->document, uri, &error);
ev_document_doc_mutex_unlock ();
+
+ g_free (uri);
+ close (fd);
+ }
+
+ if (!error) {
+ uri_unc = g_object_get_data (G_OBJECT (ev_window->priv->document),
+ "uri-uncompressed");
+ if (uri_unc) {
+ EvCompressionType ctype;
+ gchar *uri_comp;
+ gchar *uri;
+ const gchar *ext;
+
+ ctype = EV_COMPRESSION_NONE;
+
+ ext = g_strrstr (ev_window->priv->uri, ".gz");
+ if (ext && g_ascii_strcasecmp (ext, ".gz") == 0)
+ ctype = EV_COMPRESSION_GZIP;
+
+ ext = g_strrstr (ev_window->priv->uri, ".bz2");
+ if (ext && g_ascii_strcasecmp (ext, ".bz2") == 0)
+ ctype = EV_COMPRESSION_BZIP2;
+
+ uri = g_filename_to_uri (tmp_filename, NULL, NULL);
+ uri_comp = ev_file_compress (uri, ctype, &error);
+ g_free (uri);
+ g_unlink (tmp_filename);
+ g_free (tmp_filename);
- if (err) {
- gchar *msg;
- msg = g_strdup_printf (_("The file could not be saved as “%s”."), uri);
- ev_window_error_dialog (GTK_WINDOW (fc), msg, err);
- g_free (msg);
+ if (!uri_comp || error) {
+ tmp_filename = NULL;
+ } else {
+ tmp_filename = g_filename_from_uri (uri_comp,
+ NULL, NULL);
+ }
+
+ g_free (uri_comp);
}
+ }
+ if (tmp_filename && g_rename (tmp_filename, filename) == -1) {
+ g_unlink (tmp_filename);
+ }
+
+ if (error) {
+ gchar *msg;
+ gchar *uri;
+
+ uri = g_filename_to_uri (filename, NULL, NULL);
+ msg = g_strdup_printf (_("The file could not be saved as “%s”."), uri);
+ ev_window_error_dialog (GTK_WINDOW (ev_window), msg, error);
+ g_free (msg);
g_free (uri);
+ g_error_free (error);
}
+
+ g_free (tmp_filename);
+ g_free (filename);
gtk_widget_destroy (fc);
}
GtkWidget *fc;
gchar *base_name;
gchar *file_name;
+ gchar *folder;
fc = gtk_file_chooser_dialog_new (
_("Save a Copy"),
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);
+ folder = xdg_user_dir_lookup ("DOCUMENTS");
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc), base_name);
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (fc), folder);
g_free (file_name);
g_free (base_name);
-
+ free (folder);
+
g_signal_connect (fc, "response",
G_CALLBACK (file_save_dialog_response_cb),
ev_window);
const gchar *filename)
{
GtkPrintJob *job;
+ GtkPrintSettings *settings;
GError *error = NULL;
if (window->priv->gtk_print_job)
g_object_unref (window->priv->gtk_print_job);
+
+ /* Some printers take into account some print settings,
+ * and others don't. However we have exported the document
+ * to a ps or pdf file according to such print settings. So,
+ * we want to send the exported file to printer with those
+ * settings set to default values.
+ */
+ settings = gtk_print_settings_copy (window->priv->print_settings);
+ gtk_print_settings_set_n_copies (settings, 1);
+ gtk_print_settings_set_page_ranges (settings, NULL, 0);
+ gtk_print_settings_set_page_set (settings, GTK_PAGE_SET_ALL);
+ gtk_print_settings_set_print_pages (settings, GTK_PRINT_PAGES_ALL);
+ gtk_print_settings_set_scale (settings, 1.0);
+ gtk_print_settings_set_collate (settings, FALSE);
+ gtk_print_settings_set_reverse (settings, FALSE);
job = gtk_print_job_new ("evince-print",
window->priv->printer,
- window->priv->print_settings,
+ settings,
window->priv->print_page_setup);
+
+ g_object_unref (settings);
window->priv->gtk_print_job = job;
ev_properties_dialog_set_document (EV_PROPERTIES_DIALOG (ev_window->priv->properties),
ev_window->priv->document);
g_object_add_weak_pointer (G_OBJECT (ev_window->priv->properties),
- (gpointer *) &(ev_window->priv->properties));
+ (gpointer) &(ev_window->priv->properties));
gtk_window_set_transient_for (GTK_WINDOW (ev_window->priv->properties),
GTK_WINDOW (ev_window));
}
window);
#endif
+ ev_view_set_screen_dpi (EV_VIEW (window->priv->view),
+ ev_window_get_screen_dpi (window));
+
if (GTK_WIDGET_CLASS (ev_window_parent_class)->screen_changed) {
GTK_WIDGET_CLASS (ev_window_parent_class)->screen_changed (widget, old_screen);
}
static void
ev_window_cmd_view_reload (GtkAction *action, EvWindow *ev_window)
{
- char *uri;
-
- g_return_if_fail (EV_IS_WINDOW (ev_window));
+ gchar *uri;
uri = g_strdup (ev_window->priv->uri);
-
ev_window_open_uri (ev_window, uri, NULL, 0, FALSE);
-
g_free (uri);
}
gboolean visible;
const char *search_string;
- g_return_if_fail (EV_IS_WINDOW (ev_window));
-
/* Either the string or case sensitivity could have changed,
* we connect this callback to both. We also connect it
* to ::visible so when the find bar is hidden, we should
priv->password_view = NULL;
}
- if (priv->xfer_job) {
- ev_window_clear_xfer_job (window);
+ if (priv->load_job) {
+ ev_window_clear_load_job (window);
+ }
+
+ if (priv->thumbnail_job) {
+ ev_window_clear_thumbnail_job (window);
}
if (priv->local_uri) {
ev_window_clear_local_uri (window);
+ priv->local_uri = NULL;
}
ev_window_close_dialogs (window);
{ "FileOpen", GTK_STOCK_OPEN, N_("_Open..."), "<control>O",
N_("Open an existing document"),
G_CALLBACK (ev_window_cmd_file_open) },
- { "FileOpenCopy", NULL, N_("Open a _Copy"), NULL,
+ { "FileOpenCopy", NULL, N_("Op_en a Copy"), NULL,
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",
NULL, G_CALLBACK (ev_attachment_popup_cmd_save_attachment_as) },
};
+static void
+sidebar_links_link_activated_cb (EvSidebarLinks *sidebar_links, EvLink *link, EvWindow *window)
+{
+ ev_view_handle_link (EV_VIEW (window->priv->view), link);
+}
+
static void
activate_link_cb (EvPageAction *page_action, EvLink *link, EvWindow *window)
{
gtk_widget_grab_focus (window->priv->view);
}
-static gboolean
-activate_label_cb (EvPageAction *page_action, const gchar *label, EvWindow *window)
+static void
+navigation_action_activate_link_cb (EvNavigationAction *action, EvLink *link, EvWindow *window)
{
- g_return_val_if_fail (EV_IS_WINDOW (window), FALSE);
-
+
+ ev_view_handle_link (EV_VIEW (window->priv->view), link);
gtk_widget_grab_focus (window->priv->view);
-
- return ev_page_cache_set_page_label (window->priv->page_cache, label);
}
static void
NULL);
g_signal_connect (action, "activate_link",
G_CALLBACK (activate_link_cb), window);
- g_signal_connect (action, "activate_label",
- G_CALLBACK (activate_label_cb), window);
gtk_action_group_add_action (group, action);
g_object_unref (action);
"stock_id", GTK_STOCK_GO_DOWN,
"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);
}
ev_page_cache_get_max_height (window->priv->page_cache,
0, 1.0,
&document_height);
- ev_metadata_manager_set_int (uri, "window_x", x);
- ev_metadata_manager_set_int (uri, "window_y", y);
ev_metadata_manager_set_double (uri, "window_width_ratio",
- (double)width/document_width);
+ (double)width / document_width);
ev_metadata_manager_set_double (uri, "window_height_ratio",
- (double)height/document_height);
+ (double)height / document_height);
+
+ ev_metadata_manager_set_int (uri, "window_x", x);
+ ev_metadata_manager_set_int (uri, "window_y", y);
+ ev_metadata_manager_set_int (uri, "window_width", width);
+ ev_metadata_manager_set_int (uri, "window_height", height);
}
}
return FALSE;
}
-static void
-sidebar_links_link_activated_cb (EvSidebarLinks *sidebar_links, EvLink *link, EvWindow *window)
-{
- ev_view_handle_link (EV_VIEW (window->priv->view), link);
-}
-
static void
launch_action (EvWindow *window, EvLinkAction *action)
{
allowing to launch executables is a good idea though. -- marco */
}
+static gboolean
+uri_is_valid (const gchar *uri)
+{
+ gchar *p = (gchar *) uri;
+
+ if (!p || !g_ascii_isalpha (*p))
+ return FALSE;
+
+ p++;
+ while (g_ascii_isalnum (*p))
+ p++;
+
+ return (g_ascii_strncasecmp (p, "://", strlen ("://")) == 0);
+}
+
static void
launch_external_uri (EvWindow *window, EvLinkAction *action)
{
- gnome_vfs_url_show (ev_link_action_get_uri (action));
+ const gchar *uri = ev_link_action_get_uri (action);
+
+ if (!uri_is_valid (uri)) {
+ 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),
+ _("Invalid URI: “%s”"), uri);
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (gtk_widget_destroy),
+ NULL);
+ gtk_widget_show (dialog);
+
+ return;
+ }
+
+ gnome_vfs_url_show (uri);
}
static void
view_external_link_cb (EvView *view, EvLinkAction *action, EvWindow *window)
{
switch (ev_link_action_get_action_type (action)) {
+ case EV_LINK_ACTION_TYPE_GOTO_DEST: {
+ EvLinkDest *dest;
+
+ dest = ev_link_action_get_dest (action);
+ if (!dest)
+ return;
+
+ ev_window_cmd_file_open_copy_at_dest (window, dest);
+ }
+ break;
case EV_LINK_ACTION_TYPE_EXTERNAL_URI:
launch_external_uri (window, action);
break;
filename, "png", &error, NULL);
if (error) {
- ev_window_error_dialog (GTK_WINDOW (fc),
+ ev_window_error_dialog (GTK_WINDOW (ev_window),
_("The image could not be saved."),
error);
g_error_free (error);
g_free (filename);
if (error) {
- ev_window_error_dialog (GTK_WINDOW (fc),
+ ev_window_error_dialog (GTK_WINDOW (ev_window),
_("The attachment could not be saved."),
error);
g_error_free (error);
ev_window->priv->scrolled_window);
ev_window->priv->view = ev_view_new ();
+ ev_view_set_screen_dpi (EV_VIEW (ev_window->priv->view),
+ ev_window_get_screen_dpi (ev_window));
ev_window->priv->password_view = ev_password_view_new ();
g_signal_connect_swapped (ev_window->priv->password_view,
"unlock",
g_signal_connect_object (ev_window->priv->view, "external-link",
G_CALLBACK (view_external_link_cb),
ev_window, 0);
+ g_signal_connect_object (ev_window->priv->view, "handle-link",
+ G_CALLBACK (view_handle_link_cb),
+ ev_window, 0);
+
g_signal_connect_object (ev_window->priv->view,
"popup",
G_CALLBACK (view_menu_popup_cb),