#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-password.h"
#include "ev-password-view.h"
#include "ev-properties-dialog.h"
-#include "ev-ps-exporter.h"
+#include "ev-file-exporter.h"
#include "ev-document-thumbnails.h"
#include "ev-document-links.h"
#include "ev-document-fonts.h"
#include "ev-jobs.h"
#include "ev-sidebar-page.h"
#include "eggfindbar.h"
+
+#ifndef HAVE_GTK_RECENT
#include "egg-recent-view-uimanager.h"
#include "egg-recent-view.h"
+#include "egg-recent-model.h"
+#endif
+
#include "egg-toolbar-editor.h"
#include "egg-editable-toolbar.h"
-#include "egg-recent-model.h"
#include "egg-toolbars-model.h"
#include "ephy-zoom.h"
#include "ephy-zoom-action.h"
#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"
#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>
+#endif
+#include <glib/gstdio.h>
#include <glib/gi18n.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
EV_CHROME_RAISE_TOOLBAR = 1 << 3,
EV_CHROME_FULLSCREEN_TOOLBAR = 1 << 4,
EV_CHROME_SIDEBAR = 1 << 5,
+ EV_CHROME_PREVIEW_TOOLBAR = 1 << 6,
EV_CHROME_NORMAL = EV_CHROME_MENUBAR | EV_CHROME_TOOLBAR | EV_CHROME_SIDEBAR
} EvChrome;
GtkWidget *sidebar_thumbs;
GtkWidget *sidebar_links;
GtkWidget *sidebar_attachments;
+ GtkWidget *preview_toolbar;
/* Dialogs */
GtkWidget *properties;
-#ifdef WITH_GNOME_PRINT
+#ifdef WITH_PRINT
GtkWidget *print_dialog;
#endif
GtkWidget *password_dialog;
/* UI Builders */
- GtkActionGroup *action_group;
- GtkActionGroup *view_popup_action_group;
- GtkActionGroup *attachment_popup_action_group;
- GtkUIManager *ui_manager;
+ GtkActionGroup *action_group;
+ GtkActionGroup *view_popup_action_group;
+ GtkActionGroup *attachment_popup_action_group;
+#ifdef HAVE_GTK_RECENT
+ GtkRecentManager *recent_manager;
+ GtkActionGroup *recent_action_group;
+ guint recent_ui_id;
+#endif
+ GtkUIManager *ui_manager;
/* Fullscreen mode */
GtkWidget *fullscreen_toolbar;
GtkWidget *fullscreen_popup;
guint fullscreen_timeout_id;
-
- /* Popup link */
+
+ /* Popup view */
GtkWidget *view_popup;
EvLink *link;
+ EvImage *image;
/* Popup attachment */
GtkWidget *attachment_popup;
char *uri;
char *local_uri;
EvLinkDest *dest;
+ gboolean unlink_temp_file;
EvDocument *document;
- EvDocument *password_document;
+ EvHistory *history;
EvPageCache *page_cache;
EvWindowPageMode page_mode;
EvWindowTitle *title;
+#ifndef HAVE_GTK_RECENT
EggRecentViewUIManager *recent_view;
+#endif
- EvJob *xfer_job;
+ EvJob *load_job;
+ EvJob *thumbnail_job;
#ifdef WITH_GNOME_PRINT
GnomePrintJob *print_job;
#endif
-};
-static const GtkTargetEntry ev_drop_types[] = {
- { "text/uri-list", 0, 0 }
+#ifdef WITH_GTK_PRINT
+ EvJob *print_job;
+ GtkPrintJob *gtk_print_job;
+ GtkPrinter *printer;
+ GtkPrintSettings *print_settings;
+ GtkPageSetup *print_page_setup;
+#endif
};
-
#define EV_WINDOW_GET_PRIVATE(object) \
(G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_WINDOW, EvWindowPrivate))
#define PAGE_SELECTOR_ACTION "PageSelector"
#define ZOOM_CONTROL_ACTION "ViewZoom"
+#define NAVIGATION_ACTION "Navigation"
#define GCONF_OVERRIDE_RESTRICTIONS "/apps/evince/override_restrictions"
#define GCONF_LOCKDOWN_SAVE "/desktop/gnome/lockdown/disable_save_to_disk"
EvWindow *ev_window);
static void ev_window_set_page_mode (EvWindow *window,
EvWindowPageMode page_mode);
-static void ev_window_xfer_job_cb (EvJobXfer *job,
- gpointer data);
+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);
+#endif
static void ev_window_sizing_mode_changed_cb (EvView *view,
GParamSpec *pspec,
EvWindow *ev_window);
static void ev_window_stop_presentation (EvWindow *window);
static void ev_window_cmd_view_presentation (GtkAction *action,
EvWindow *window);
+static void ev_window_run_preview (EvWindow *window);
static void ev_view_popup_cmd_open_link (GtkAction *action,
EvWindow *window);
+static void ev_view_popup_cmd_open_link_new_window (GtkAction *action,
+ EvWindow *window);
static void ev_view_popup_cmd_copy_link_address (GtkAction *action,
EvWindow *window);
+static void ev_view_popup_cmd_save_image_as (GtkAction *action,
+ EvWindow *window);
+static void ev_view_popup_cmd_copy_image (GtkAction *action,
+ EvWindow *window);
static void ev_attachment_popup_cmd_open_attachment (GtkAction *action,
EvWindow *window);
static void ev_attachment_popup_cmd_save_attachment_as (GtkAction *action,
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)
+static gdouble
+ev_window_get_screen_dpi (EvWindow *ev_window)
+{
+ GdkScreen *screen;
+ gdouble xdpi, ydpi;
+
+ screen = gtk_window_get_screen (GTK_WINDOW (ev_window));
+
+ xdpi = 25.4 * gdk_screen_get_width (screen) / gdk_screen_get_width_mm (screen);
+ ydpi = 25.4 * gdk_screen_get_height (screen) / gdk_screen_get_height_mm (screen);
+
+ return (xdpi + ydpi) / 2.0;
+}
+
static void
ev_window_set_action_sensitive (EvWindow *ev_window,
const char *name,
can_get_text = TRUE;
}
- if (has_document && EV_IS_DOCUMENT_FIND (document)) {
+ if (has_pages && EV_IS_DOCUMENT_FIND (document)) {
can_find = TRUE;
}
ok_to_copy = (info->permissions & EV_DOCUMENT_PERMISSIONS_OK_TO_COPY);
}
- if (has_document && !EV_IS_PS_EXPORTER(document))
+ if (has_document && !EV_IS_FILE_EXPORTER(document))
ok_to_print = FALSE;
if (gconf_client_get_bool (client, GCONF_LOCKDOWN_PRINT, NULL)) {
ok_to_print = FALSE;
}
-#ifndef WITH_GNOME_PRINT
+#ifndef WITH_PRINT
ok_to_print = FALSE;
#endif
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);
/* Edit menu */
ev_window_set_action_sensitive (ev_window, "EditSelectAll", has_pages && can_get_text);
- ev_window_set_action_sensitive (ev_window, "EditFind",
- has_pages && EV_IS_DOCUMENT_FIND (document));
- ev_window_set_action_sensitive (ev_window, "Slash",
- has_pages && EV_IS_DOCUMENT_FIND (document));
+ ev_window_set_action_sensitive (ev_window, "EditFind", can_find);
+ ev_window_set_action_sensitive (ev_window, "Slash", can_find);
ev_window_set_action_sensitive (ev_window, "EditRotateLeft", has_pages);
ev_window_set_action_sensitive (ev_window, "EditRotateRight", has_pages);
/* Toolbar-specific actions: */
ev_window_set_action_sensitive (ev_window, PAGE_SELECTOR_ACTION, has_pages);
ev_window_set_action_sensitive (ev_window, ZOOM_CONTROL_ACTION, has_pages);
+ ev_window_set_action_sensitive (ev_window, NAVIGATION_ACTION, has_pages);
ev_window_update_actions (ev_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);
ZOOM_CONTROL_ACTION);
real_zoom = ev_view_get_zoom (EV_VIEW (ev_window->priv->view));
+ real_zoom *= 72.0 / ev_window_get_screen_dpi (ev_window);
zoom = ephy_zoom_get_nearest_zoom_level (real_zoom);
ephy_zoom_action_set_zoom_level (EPHY_ZOOM_ACTION (action), zoom);
static void
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);
+
if (window->priv->action_group) {
ev_window_set_action_sensitive (window, "PageDown", sensitive);
ev_window_set_action_sensitive (window, "PageUp", sensitive);
ev_window_set_action_sensitive (window, "ShiftBackSpace", sensitive);
ev_window_set_action_sensitive (window, "Return", sensitive);
ev_window_set_action_sensitive (window, "ShiftReturn", sensitive);
- ev_window_set_action_sensitive (window, "Slash", sensitive);
ev_window_set_action_sensitive (window, "Plus", sensitive);
ev_window_set_action_sensitive (window, "Minus", sensitive);
ev_window_set_action_sensitive (window, "KpPlus", sensitive);
ev_window_set_action_sensitive (window, "KpMinus", sensitive);
ev_window_set_action_sensitive (window, "Equal", sensitive);
+
+ ev_window_set_action_sensitive (window, "Slash", sensitive && can_find);
}
}
EvWindowPrivate *priv = window->priv;
gboolean menubar, toolbar, findbar, fullscreen_toolbar, sidebar;
gboolean fullscreen_mode, presentation, fullscreen;
+ gboolean preview_toolbar;
presentation = ev_view_get_presentation (EV_VIEW (priv->view));
fullscreen = ev_view_get_fullscreen (EV_VIEW (priv->view));
(priv->chrome & EV_CHROME_RAISE_TOOLBAR) != 0) && fullscreen;
findbar = (priv->chrome & EV_CHROME_FINDBAR) != 0;
sidebar = (priv->chrome & EV_CHROME_SIDEBAR) != 0 && !fullscreen_mode;
+ preview_toolbar = (priv->chrome& EV_CHROME_PREVIEW_TOOLBAR);
set_widget_visibility (priv->menubar, menubar);
set_widget_visibility (priv->toolbar_dock, toolbar);
set_widget_visibility (priv->find_bar, findbar);
set_widget_visibility (priv->sidebar, sidebar);
+ set_widget_visibility (priv->preview_toolbar, preview_toolbar);
ev_window_set_action_sensitive (window, "EditToolbar", toolbar);
gtk_widget_set_sensitive (priv->menubar, menubar);
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
EvWindow *ev_window)
{
ev_window_update_actions (ev_window);
-
+
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)
{
{
char *uri = window->priv->uri;
GValue page = { 0, };
+ gint n_pages;
gint new_page;
+ /* View the previously shown page, but make sure to not open a document on
+ * the last page, since closing it on the last page most likely means the
+ * user was finished reading the document. In that case, reopening should
+ * show the first page. */
if (uri && ev_metadata_manager_get (uri, "page", &page, TRUE)) {
- new_page = CLAMP (g_value_get_int (&page), 0, ev_page_cache_get_n_pages (window->priv->page_cache) - 1);
+ n_pages = ev_page_cache_get_n_pages (window->priv->page_cache);
+ new_page = CLAMP (g_value_get_int (&page), 0, n_pages - 1);
+ if (new_page == n_pages - 1)
+ new_page = 0;
ev_page_cache_set_current_page (window->priv->page_cache,
new_page);
+ g_value_unset (&page);
}
}
if (ev_metadata_manager_get (NULL, "show_toolbar", &show_toolbar, FALSE)) {
if (!g_value_get_boolean (&show_toolbar))
chrome &= ~EV_CHROME_TOOLBAR;
+ g_value_unset (&show_toolbar);
}
window->priv->chrome = chrome;
}
if (ev_metadata_manager_get (uri, "sidebar_size", &sidebar_size, FALSE)) {
gtk_paned_set_position (GTK_PANED (window->priv->hpaned),
g_value_get_int (&sidebar_size));
+ g_value_unset(&sidebar_size);
}
if (document && ev_metadata_manager_get (uri, "sidebar_page", &sidebar_page, FALSE)) {
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, ATTACHMENTS_SIDEBAR_ID) && ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (attachments), document)) {
ev_sidebar_set_page (EV_SIDEBAR (sidebar), thumbs);
}
+ 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);
}
if (ev_metadata_manager_get (uri, "sidebar_visibility", &sidebar_visibility, FALSE)) {
update_chrome_flag (window, EV_CHROME_SIDEBAR, g_value_get_boolean (&sidebar_visibility));
+ g_value_unset (&sidebar_visibility);
}
}
static void
-setup_view_from_metadata (EvWindow *window)
+setup_size_from_metadata (EvWindow *window)
{
- EvView *view = EV_VIEW (window->priv->view);
char *uri = window->priv->uri;
- GEnumValue *enum_value;
GValue width = { 0, };
GValue height = { 0, };
+ GValue width_ratio = { 0, };
+ GValue height_ratio = { 0, };
GValue maximized = { 0, };
GValue x = { 0, };
GValue y = { 0, };
+
+ if (ev_metadata_manager_get (uri, "window_maximized", &maximized, FALSE)) {
+ if (g_value_get_boolean (&maximized)) {
+ gtk_window_maximize (GTK_WINDOW (window));
+ return;
+ } else {
+ gtk_window_unmaximize (GTK_WINDOW (window));
+ }
+ g_value_unset (&maximized);
+ }
+
+ if (ev_metadata_manager_get (uri, "window_x", &x, TRUE) &&
+ ev_metadata_manager_get (uri, "window_y", &y, TRUE)) {
+ gtk_window_move (GTK_WINDOW (window), g_value_get_int (&x),
+ g_value_get_int (&y));
+ g_value_unset (&x);
+ g_value_unset (&y);
+ }
+
+ if (ev_metadata_manager_get (uri, "window_width", &width, TRUE) &&
+ ev_metadata_manager_get (uri, "window_height", &height, TRUE)) {
+ gtk_window_resize (GTK_WINDOW (window),
+ g_value_get_int (&width),
+ g_value_get_int (&height));
+ g_value_unset (&width);
+ g_value_unset (&height);
+ return;
+ }
+
+ 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,
+ &document_width);
+ ev_page_cache_get_max_height (window->priv->page_cache,
+ 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),
+ request_width,
+ request_height);
+ g_value_unset (&width_ratio);
+ g_value_unset (&height_ratio);
+ }
+}
+
+static void
+setup_view_from_metadata (EvWindow *window)
+{
+ EvView *view = EV_VIEW (window->priv->view);
+ char *uri = window->priv->uri;
+ GEnumValue *enum_value;
GValue sizing_mode = { 0, };
GValue zoom = { 0, };
GValue continuous = { 0, };
GValue presentation = { 0, };
GValue fullscreen = { 0, };
GValue rotation = { 0, };
- gboolean restore_size = TRUE;
-
- /* Window size */
+ GValue maximized = { 0, };
+ /* Maximized */
if (ev_metadata_manager_get (uri, "window_maximized", &maximized, FALSE)) {
if (g_value_get_boolean (&maximized)) {
gtk_window_maximize (GTK_WINDOW (window));
- restore_size = FALSE;
} else {
gtk_window_unmaximize (GTK_WINDOW (window));
}
- }
-
- if (restore_size &&
- ev_metadata_manager_get (uri, "window_width", &width, TRUE) &&
- ev_metadata_manager_get (uri, "window_height", &height, TRUE)) {
- gtk_window_resize (GTK_WINDOW (window),
- g_value_get_int (&width),
- g_value_get_int (&height));
- }
- if (restore_size &&
- ev_metadata_manager_get (uri, "window_x", &x, TRUE) &&
- ev_metadata_manager_get (uri, "window_y", &y, TRUE)) {
- gtk_window_move (GTK_WINDOW (window), g_value_get_int (&x),
- g_value_get_int (&y));
+ g_value_unset (&maximized);
}
/* Sizing mode */
/* Zoom */
if (ev_metadata_manager_get (uri, "zoom", &zoom, FALSE) &&
ev_view_get_sizing_mode (view) == EV_SIZING_FREE) {
- ev_view_set_zoom (view, g_value_get_double (&zoom), FALSE);
+ gdouble zoom_value;
+
+ zoom_value = g_value_get_double (&zoom);
+ zoom_value *= ev_window_get_screen_dpi (window) / 72.0;
+ ev_view_set_zoom (view, zoom_value, FALSE);
+ g_value_unset (&zoom);
}
/* Continuous */
if (ev_metadata_manager_get (uri, "continuous", &continuous, FALSE)) {
ev_view_set_continuous (view, g_value_get_boolean (&continuous));
+ g_value_unset (&continuous);
}
/* Dual page */
if (ev_metadata_manager_get (uri, "dual-page", &dual_page, FALSE)) {
ev_view_set_dual_page (view, g_value_get_boolean (&dual_page));
+ g_value_unset (&dual_page);
}
/* Presentation */
if (g_value_get_boolean (&presentation) && uri) {
ev_window_run_presentation (window);
}
+ g_value_unset (&presentation);
}
/* Fullscreen */
if (g_value_get_boolean (&fullscreen) && uri) {
ev_window_run_fullscreen (window);
}
+ g_value_unset (&fullscreen);
}
/* Rotation */
break;
}
}
+ g_value_unset (&rotation);
+ }
+}
+
+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
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_page_action_set_document (EV_PAGE_ACTION (action), document);
ev_window_setup_action_sensitivity (ev_window);
+ if (ev_window->priv->history)
+ g_object_unref (ev_window->priv->history);
+ 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);
+
if (ev_window->priv->properties) {
ev_properties_dialog_set_document (EV_PROPERTIES_DIALOG (ev_window->priv->properties),
ev_window->priv->document);
}
+ setup_size_from_metadata (ev_window);
setup_document_from_metadata (ev_window);
setup_sidebar_from_metadata (ev_window, document);
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->password_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));
- g_object_unref (ev_window->priv->password_document);
- ev_window->priv->password_document = NULL;
-
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);
return;
}
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->password_document);
+ 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;
}
}
if (ev_window->priv->local_uri) {
filename = g_filename_from_uri (ev_window->priv->local_uri, NULL, NULL);
if (filename != NULL) {
- unlink (filename);
+ g_unlink (filename);
g_free (filename);
}
g_free (ev_window->priv->local_uri);
}
}
+static void
+ev_window_clear_temp_file (EvWindow *ev_window)
+{
+ GnomeVFSURI *uri;
+ gchar *filename;
+ const gchar *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;
+
+ tempdir = g_get_tmp_dir ();
+ if (g_ascii_strncasecmp (filename, tempdir, strlen (tempdir)) == 0) {
+ g_unlink (filename);
+ }
+
+ g_free (filename);
+}
+
/* This callback will executed when load job will be finished.
*
* Since the flow of the error dialog is very confusing, we assume that both
* 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);
ev_view_set_loading (EV_VIEW (ev_window->priv->view), FALSE);
- if (ev_window->priv->password_document) {
- g_object_unref (ev_window->priv->password_document);
- ev_window->priv->password_document = NULL;
- }
-
/* Success! */
if (job->error == NULL) {
-
- g_free (ev_window->priv->uri);
- ev_window->priv->uri = g_strdup (job->uri);
- setup_view_from_metadata (ev_window);
-
- if (job->local_uri) {
- ev_window->priv->local_uri = g_strdup (job->local_uri);
- } else {
- ev_window->priv->local_uri = NULL;
- }
-
if (ev_window->priv->document)
g_object_unref (ev_window->priv->document);
ev_window->priv->document = g_object_ref (document);
-
+
+ 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);
- ev_window_add_recent (ev_window, ev_window->priv->uri);
- ev_window_clear_xfer_job (ev_window);
- if (ev_window->priv->dest)
- ev_window_goto_dest (ev_window, ev_window->priv->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:
+ ev_window_run_fullscreen (ev_window);
+ break;
+ case EV_WINDOW_MODE_PRESENTATION:
+ ev_window_run_presentation (ev_window);
+ break;
+ case EV_WINDOW_MODE_PREVIEW:
+ ev_window_run_preview (ev_window);
+ break;
+ default:
+ break;
+ }
+
+ 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);
- ev_window->priv->password_document = g_object_ref (document);
-
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),
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);
} else {
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;
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_dialog) {
- gtk_widget_destroy (ev_window->priv->print_dialog);
+ if (ev_window->priv->print_job)
g_object_unref (ev_window->priv->print_job);
- }
- ev_window->priv->print_dialog = NULL;
ev_window->priv->print_job = NULL;
#endif
-
+
if (ev_window->priv->properties)
gtk_widget_destroy (ev_window->priv->properties);
ev_window->priv->properties = NULL;
}
-void
-ev_window_open_uri (EvWindow *ev_window, const char *uri, EvLinkDest *dest)
+static gint
+xfer_update_progress_callback (GnomeVFSAsyncHandle *handle,
+ GnomeVFSXferProgressInfo *info,
+ EvWindow *ev_window)
{
- g_free (ev_window->priv->uri);
- ev_window->priv->uri = NULL;
+ 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 ();
+ }
- if (ev_window->priv->dest)
- g_object_unref (ev_window->priv->dest);
- ev_window->priv->dest = dest ? g_object_ref (dest) : NULL;
+ return 0;
+}
+
+void
+ev_window_open_uri (EvWindow *ev_window,
+ const char *uri,
+ EvLinkDest *dest,
+ 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);
- 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
uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (chooser));
- ev_application_open_uri_list (EV_APP, uris, GDK_CURRENT_TIME);
+ ev_application_open_uri_list (EV_APP, uris,
+ gtk_window_get_screen (GTK_WINDOW (ev_window)),
+ GDK_CURRENT_TIME);
g_slist_foreach (uris, (GFunc)g_free, NULL);
g_slist_free (uris);
ev_document_factory_add_filters (chooser, NULL);
gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (chooser), TRUE);
gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser), FALSE);
- if (ev_application_get_chooser_uri (EV_APP) != NULL)
+ if (ev_application_get_chooser_uri (EV_APP) != NULL) {
gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (chooser),
ev_application_get_chooser_uri (EV_APP));
+ } else if (window->priv->uri != NULL) {
+ 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),
gtk_widget_show (chooser);
}
+static gchar *
+ev_window_create_tmp_symlink (const gchar *filename, GError **error)
+{
+ gchar *tmp_filename = NULL;
+ gchar *name;
+ gint res;
+ guint i = 0;
+
+ name = g_path_get_basename (filename);
+
+ do {
+ gchar *basename;
+
+ if (tmp_filename)
+ g_free (tmp_filename);
+
+ basename = g_strdup_printf ("%s-%d", name, i++);
+ tmp_filename = g_build_filename (ev_tmp_dir (),
+ basename, NULL);
+
+ g_free (basename);
+ } while ((res = symlink (filename, tmp_filename)) != 0 && errno == EEXIST);
+
+ g_free (name);
+
+ if (res != 0 && errno != EEXIST) {
+ if (error) {
+ *error = g_error_new (G_FILE_ERROR,
+ g_file_error_from_errno (errno),
+ _("Couldn't create symlink ā%sā: %s"),
+ tmp_filename, strerror (errno));
+ }
+
+ g_free (tmp_filename);
+
+ return NULL;
+ }
+
+ return tmp_filename;
+}
+
+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;
+ 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) {
+ ev_window_error_dialog (GTK_WINDOW (window),
+ _("Cannot open a copy."),
+ error);
+
+ g_error_free (error);
+ g_free (old_filename);
+ g_free (new_filename);
+
+ return;
+ }
+
+ g_free (old_filename);
+
+ symlink_uri = g_filename_to_uri (new_filename, NULL, NULL);
+ g_free (new_filename);
+
+ ev_application_open_uri_at_dest (EV_APP,
+ symlink_uri,
+ gtk_window_get_screen (GTK_WINDOW (window)),
+ dest,
+ 0,
+ TRUE,
+ GDK_CURRENT_TIME);
+ g_free (symlink_uri);
+}
+
+static void
+ev_window_cmd_file_open_copy (GtkAction *action, EvWindow *window)
+{
+ EvPageCache *page_cache;
+ EvLinkDest *dest;
+ gint current_page;
+
+ page_cache = ev_page_cache_get (window->priv->document);
+ current_page = ev_page_cache_get_current_page (page_cache);
+
+ dest = ev_link_dest_new_page (current_page);
+ ev_window_cmd_file_open_copy_at_dest (window, dest);
+ g_object_unref (dest);
+}
+
+#ifdef HAVE_GTK_RECENT
+static void
+ev_window_cmd_recent_file_activate (GtkAction *action,
+ EvWindow *window)
+{
+ GtkRecentInfo *info;
+ const gchar *uri;
+
+ info = g_object_get_data (G_OBJECT (action), "gtk-recent-info");
+ g_assert (info != NULL);
+
+ uri = gtk_recent_info_get_uri (info);
+
+ ev_application_open_uri_at_dest (EV_APP, uri,
+ gtk_window_get_screen (GTK_WINDOW (window)),
+ NULL, 0, FALSE,
+ GDK_CURRENT_TIME);
+}
+#else
static void
ev_window_cmd_recent_file_activate (GtkAction *action,
EvWindow *ev_window)
uri = egg_recent_item_get_uri (item);
- ev_application_open_uri (EV_APP, uri, NULL, GDK_CURRENT_TIME, NULL);
+ ev_application_open_uri (EV_APP, uri, NULL,
+ GDK_CURRENT_TIME, NULL);
g_free (uri);
}
+#endif /* HAVE_GTK_RECENT */
static void
ev_window_add_recent (EvWindow *window, const char *filename)
{
+#ifdef HAVE_GTK_RECENT
+ gtk_recent_manager_add_item (window->priv->recent_manager, filename);
+#else
EggRecentItem *item;
item = egg_recent_item_new_from_uri (filename);
egg_recent_item_add_group (item, "Evince");
egg_recent_model_add_full (ev_application_get_recent_model (EV_APP), item);
+#endif /* HAVE_GTK_RECENT */
+}
+
+#ifdef HAVE_GTK_RECENT
+static gint
+compare_recent_items (GtkRecentInfo *a, GtkRecentInfo *b)
+{
+ gboolean has_ev_a, has_ev_b;
+ const gchar *evince = g_get_application_name ();
+
+ has_ev_a = gtk_recent_info_has_application (a, evince);
+ has_ev_b = gtk_recent_info_has_application (b, evince);
+
+ if (has_ev_a && has_ev_b) {
+ time_t time_a, time_b;
+
+ time_a = gtk_recent_info_get_modified (a);
+ time_b = gtk_recent_info_get_modified (b);
+
+ return (time_b - time_a);
+ } else if (has_ev_a) {
+ return -1;
+ } else if (has_ev_b) {
+ return 1;
+ }
+
+ return 0;
+}
+#endif /* HAVE_GTK_RECENT */
+
+/*
+ * Doubles underscore to avoid spurious menu accels.
+ */
+static gchar *
+ev_window_get_recent_file_label (gint index, const gchar *filename)
+{
+ GString *str;
+ gint length;
+ const gchar *p;
+ const gchar *end;
+
+ g_return_val_if_fail (filename != NULL, NULL);
+
+ length = strlen (filename);
+ str = g_string_sized_new (length + 10);
+ g_string_printf (str, "_%d. ", index);
+
+ p = filename;
+ end = filename + length;
+
+ while (p != end) {
+ const gchar *next;
+ next = g_utf8_next_char (p);
+
+ switch (*p) {
+ case '_':
+ g_string_append (str, "__");
+ break;
+ default:
+ g_string_append_len (str, p, next - p);
+ break;
+ }
+
+ p = next;
+ }
+
+ return g_string_free (str, FALSE);
}
static void
ev_window_setup_recent (EvWindow *ev_window)
{
+#ifdef HAVE_GTK_RECENT
+ GList *items, *l;
+ guint n_items = 0;
+ const gchar *evince = g_get_application_name ();
+ static guint i = 0;
+ if (ev_window->priv->recent_ui_id > 0) {
+ gtk_ui_manager_remove_ui (ev_window->priv->ui_manager,
+ ev_window->priv->recent_ui_id);
+ gtk_ui_manager_ensure_update (ev_window->priv->ui_manager);
+ }
+ ev_window->priv->recent_ui_id = gtk_ui_manager_new_merge_id (ev_window->priv->ui_manager);
+
+ if (ev_window->priv->recent_action_group) {
+ gtk_ui_manager_remove_action_group (ev_window->priv->ui_manager,
+ ev_window->priv->recent_action_group);
+ g_object_unref (ev_window->priv->recent_action_group);
+ }
+ ev_window->priv->recent_action_group = gtk_action_group_new ("RecentFilesActions");
+ gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
+ ev_window->priv->recent_action_group, 0);
+
+ items = gtk_recent_manager_get_items (ev_window->priv->recent_manager);
+ items = g_list_sort (items, (GCompareFunc) compare_recent_items);
+
+ for (l = items; l && l->data; l = g_list_next (l)) {
+ GtkRecentInfo *info;
+ GtkAction *action;
+ gchar *action_name;
+ gchar *label;
+
+ info = (GtkRecentInfo *) l->data;
+
+ 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++);
+ label = ev_window_get_recent_file_label (
+ n_items + 1, gtk_recent_info_get_display_name (info));
+
+ action = g_object_new (GTK_TYPE_ACTION,
+ "name", action_name,
+ "label", label,
+ NULL);
+
+ g_object_set_data_full (G_OBJECT (action),
+ "gtk-recent-info",
+ gtk_recent_info_ref (info),
+ (GDestroyNotify) gtk_recent_info_unref);
+
+ g_signal_connect (G_OBJECT (action), "activate",
+ G_CALLBACK (ev_window_cmd_recent_file_activate),
+ (gpointer) ev_window);
+
+ gtk_action_group_add_action (ev_window->priv->recent_action_group,
+ action);
+ g_object_unref (action);
+
+ gtk_ui_manager_add_ui (ev_window->priv->ui_manager,
+ ev_window->priv->recent_ui_id,
+ "/MainMenu/FileMenu/RecentFilesMenu",
+ label,
+ action_name,
+ GTK_UI_MANAGER_MENUITEM,
+ FALSE);
+ g_free (action_name);
+ g_free (label);
+
+ if (++n_items == 5)
+ break;
+ }
+
+ g_list_foreach (items, (GFunc) gtk_recent_info_unref, NULL);
+ g_list_free (items);
+#else /* HAVE_GTK_RECENT */
ev_window->priv->recent_view = egg_recent_view_uimanager_new (ev_window->priv->ui_manager,
"/MainMenu/FileMenu/RecentFilesMenu",
G_CALLBACK (ev_window_cmd_recent_file_activate),
g_signal_connect (ev_window->priv->recent_view, "activate",
G_CALLBACK (ev_window_cmd_recent_file_activate), ev_window);
+#endif /* HAVE_GTK_RECENT */
}
static void
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;
- 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);
+ 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 (!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);
gtk_widget_show (fc);
}
+#ifdef WITH_GTK_PRINT
static void
-ev_window_print (EvWindow *window)
+ev_window_print_page_setup_done_cb (GtkPageSetup *page_setup,
+ EvWindow *window)
{
- EvPageCache *page_cache;
- int last_page;
+ /* Dialog was canceled */
+ if (!page_setup)
+ return;
- page_cache = ev_page_cache_get (window->priv->document);
- last_page = ev_page_cache_get_n_pages (page_cache);
+ if (window->priv->print_page_setup)
+ g_object_unref (window->priv->print_page_setup);
+ window->priv->print_page_setup = g_object_ref (page_setup);
+}
+#endif /* WITH_GTK_PRINT */
-#ifdef WITH_GNOME_PRINT
- ev_window_print_range (window, 1, last_page);
-#endif
+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);
+
+ g_signal_handlers_disconnect_by_func (window->priv->print_job,
+ ev_window_print_job_cb,
+ window);
+ g_object_unref (window->priv->print_job);
+ window->priv->print_job = NULL;
+ }
+}
+
+static void
+ev_window_print_finished (GtkPrintJob *print_job,
+ EvWindow *window,
+ GError *error)
+{
+ 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);
+ }
+}
+
+static void
+ev_window_print_send (EvWindow *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,
+ settings,
+ window->priv->print_page_setup);
+
+ g_object_unref (settings);
+
+ window->priv->gtk_print_job = job;
+
+ if (gtk_print_job_set_source_file (job, filename, &error)) {
+ gtk_print_job_send (job,
+ (GtkPrintJobCompleteFunc)ev_window_print_finished,
+ window, NULL);
+ } else {
+ ev_window_clear_print_job (window);
+ g_warning (error->message);
+ g_error_free (error);
+ }
+}
+
+static void
+ev_window_print_job_cb (EvJobPrint *job,
+ EvWindow *window)
+{
+ if (job->error) {
+ g_warning (job->error->message);
+ ev_window_clear_print_job (window);
+ return;
+ }
+
+ g_assert (job->temp_file != NULL);
+
+ ev_window_print_send (window, job->temp_file);
+}
+
+static gboolean
+ev_window_print_dialog_response_cb (GtkDialog *dialog,
+ gint response,
+ EvWindow *window)
+{
+ EvPrintRange *ranges = NULL;
+ EvPrintPageSet page_set;
+ gint n_ranges = 0;
+ gint copies;
+ gboolean collate;
+ gboolean reverse;
+ gdouble scale;
+ gint current_page;
+ gdouble width;
+ gdouble height;
+ GtkPrintPages print_pages;
+ const gchar *file_format;
+
+ if (response != GTK_RESPONSE_OK) {
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ window->priv->print_dialog = NULL;
+
+ return FALSE;
+ }
+
+ if (window->priv->printer)
+ g_object_unref (window->priv->printer);
+ if (window->priv->print_settings)
+ g_object_unref (window->priv->print_settings);
+ if (window->priv->print_page_setup)
+ g_object_unref (window->priv->print_page_setup);
+
+ window->priv->printer = g_object_ref (
+ gtk_print_unix_dialog_get_selected_printer (GTK_PRINT_UNIX_DIALOG (dialog)));
+ window->priv->print_settings = g_object_ref (
+ gtk_print_unix_dialog_get_settings (GTK_PRINT_UNIX_DIALOG (dialog)));
+ window->priv->print_page_setup = g_object_ref (
+ gtk_print_unix_dialog_get_page_setup (GTK_PRINT_UNIX_DIALOG (dialog)));
+
+ file_format = gtk_print_settings_get (window->priv->print_settings,
+ 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);
+
+ return FALSE;
+ }
+
+ ev_window_clear_print_job (window);
+
+ current_page = gtk_print_unix_dialog_get_current_page (GTK_PRINT_UNIX_DIALOG (dialog));
+ print_pages = gtk_print_settings_get_print_pages (window->priv->print_settings);
+
+ switch (print_pages) {
+ case GTK_PRINT_PAGES_CURRENT:
+ ranges = g_new0 (EvPrintRange, 1);
+
+ ranges->start = current_page;
+ ranges->end = current_page;
+ n_ranges = 1;
+
+ break;
+ case GTK_PRINT_PAGES_RANGES: {
+ GtkPageRange *page_range;
+
+ page_range = gtk_print_settings_get_page_ranges (window->priv->print_settings,
+ &n_ranges);
+ if (n_ranges > 0)
+ ranges = g_memdup (page_range, n_ranges * sizeof (GtkPageRange));
+ }
+ break;
+ default:
+ break;
+ }
+
+ page_set = (EvPrintPageSet)gtk_print_settings_get_page_set (window->priv->print_settings);
+
+ scale = gtk_print_settings_get_scale (window->priv->print_settings) * 0.01;
+
+ width = gtk_page_setup_get_paper_width (window->priv->print_page_setup,
+ GTK_UNIT_PIXEL);
+ height = gtk_page_setup_get_paper_height (window->priv->print_page_setup,
+ GTK_UNIT_PIXEL);
+
+ if (scale != 1.0) {
+ width *= scale;
+ height *= scale;
+ }
+
+ copies = gtk_print_settings_get_n_copies (window->priv->print_settings);
+ collate = gtk_print_settings_get_collate (window->priv->print_settings);
+ reverse = gtk_print_settings_get_reverse (window->priv->print_settings);
+
+ window->priv->print_job = ev_job_print_new (window->priv->document,
+ file_format ? file_format : "ps",
+ width, height,
+ ranges, n_ranges,
+ page_set,
+ copies, collate,
+ reverse);
+
+ g_signal_connect (window->priv->print_job, "finished",
+ G_CALLBACK (ev_window_print_job_cb),
+ window);
+ /* The priority doesn't matter for this job */
+ ev_job_queue_add_job (window->priv->print_job, EV_JOB_PRIORITY_LOW);
+
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ window->priv->print_dialog = NULL;
+
+ return TRUE;
+}
+
+void
+ev_window_print_range (EvWindow *ev_window, int first_page, int last_page)
+{
+ GtkWidget *dialog;
+ EvPageCache *page_cache;
+ gint current_page;
+ gint document_last_page;
+ GtkPrintCapabilities capabilities;
+
+ g_return_if_fail (EV_IS_WINDOW (ev_window));
+ g_return_if_fail (ev_window->priv->document != NULL);
+
+ if (ev_window->priv->print_dialog) {
+ gtk_window_present (GTK_WINDOW (ev_window->priv->print_dialog));
+ return;
+ }
+
+ page_cache = ev_page_cache_get (ev_window->priv->document);
+ current_page = ev_page_cache_get_current_page (page_cache);
+ document_last_page = ev_page_cache_get_n_pages (page_cache);
+
+ if (!ev_window->priv->print_settings)
+ ev_window->priv->print_settings = gtk_print_settings_new ();
+
+ if (first_page != 1 || last_page != document_last_page) {
+ GtkPageRange range;
+
+ /* Ranges in GtkPrint are 0 - N */
+ 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_PAGE_SET |
+ GTK_PRINT_CAPABILITY_COPIES |
+ GTK_PRINT_CAPABILITY_COLLATE |
+ GTK_PRINT_CAPABILITY_REVERSE |
+ GTK_PRINT_CAPABILITY_SCALE |
+ GTK_PRINT_CAPABILITY_GENERATE_PS;
+
+ if (EV_IS_FILE_EXPORTER (ev_window->priv->document) &&
+ ev_file_exporter_format_supported (EV_FILE_EXPORTER (ev_window->priv->document),
+ EV_FILE_FORMAT_PDF)) {
+ capabilities |= GTK_PRINT_CAPABILITY_GENERATE_PDF;
+ }
+
+ 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, gpointer data)
+ev_window_print_dialog_response_cb (GtkDialog *print_dialog,
+ gint response,
+ EvWindow *ev_window)
{
- EvWindow *ev_window = EV_WINDOW (data);
- EvPrintJob *print_job;
- GnomePrintConfig *config;
+ 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;
- }
+ 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;
- }
+ config = gnome_print_dialog_get_config (GNOME_PRINT_DIALOG (print_dialog));
- 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);
+ /* 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;
+ }
- if (print_job != NULL) {
- ev_print_job_print (print_job, GTK_WINDOW (ev_window));
- g_object_unref (print_job);
- }
+ 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);
+ 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;
+ 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;
+ return FALSE;
}
void
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));
+ 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_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);
- return;
+ 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)
+{
+ EvPageCache *page_cache;
+ gint last_page;
+
+ 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
}
-#endif /* WITH_GNOME_PRINT */
-
+
static void
ev_window_cmd_file_print (GtkAction *action, EvWindow *ev_window)
{
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));
}
+ ev_document_fc_mutex_lock ();
gtk_widget_show (ev_window->priv->properties);
+ ev_document_fc_mutex_unlock ();
}
static void
}
static gboolean
-fullscreen_timeout_cb (gpointer data)
+fullscreen_timeout_cb (EvWindow *window)
{
- EvWindow *window = EV_WINDOW (data);
-
+ EvView *view = EV_VIEW (window->priv->view);
+
+ if (!view ||
+ (!ev_view_get_fullscreen (EV_VIEW (view)) &&
+ !ev_view_get_presentation (EV_VIEW (view))))
+ return FALSE;
+
update_chrome_flag (window, EV_CHROME_FULLSCREEN_TOOLBAR, FALSE);
ev_view_hide_cursor (EV_VIEW (window->priv->view));
window->priv->fullscreen_timeout_id = 0;
}
window->priv->fullscreen_timeout_id =
- g_timeout_add (FULLSCREEN_TIMEOUT, fullscreen_timeout_cb, window);
+ g_timeout_add (FULLSCREEN_TIMEOUT, (GSourceFunc)fullscreen_timeout_cb, window);
update_chrome_flag (window, EV_CHROME_FULLSCREEN_TOOLBAR, TRUE);
update_chrome_visibility (window);
GdkScreen *screen;
window->priv->fullscreen_toolbar = egg_editable_toolbar_new_with_model
- (window->priv->ui_manager, ev_application_get_toolbars_model (EV_APP), NULL);
+ (window->priv->ui_manager, ev_application_get_toolbars_model (EV_APP, FALSE), NULL);
popup = gtk_window_new (GTK_WINDOW_POPUP);
hbox = gtk_hbox_new (FALSE, 0);
window);
fullscreen_set_timeout (window);
+ ev_application_screensaver_disable (EV_APP);
+
if (!ev_window_is_empty (window))
ev_metadata_manager_set_boolean (window->priv->uri, "presentation", TRUE);
}
window);
fullscreen_clear_timeout (window);
+ ev_application_screensaver_enable (EV_APP);
+
if (!ev_window_is_empty (window))
ev_metadata_manager_set_boolean (window->priv->uri, "presentation", FALSE);
}
}
}
+static void
+ev_window_run_preview (EvWindow *window)
+{
+ ev_view_set_continuous (EV_VIEW (window->priv->view), FALSE);
+
+ update_chrome_flag (window, EV_CHROME_TOOLBAR, FALSE);
+ update_chrome_flag (window, EV_CHROME_MENUBAR, FALSE);
+ update_chrome_flag (window, EV_CHROME_SIDEBAR, FALSE);
+
+ update_chrome_flag (window, EV_CHROME_PREVIEW_TOOLBAR, TRUE);
+
+ update_chrome_visibility (window);
+}
+
static gboolean
ev_window_focus_in_event (GtkWidget *widget, GdkEventFocus *event)
{
EvWindowPrivate *priv = window->priv;
GdkScreen *screen;
+ screen = gtk_widget_get_screen (widget);
+ if (screen == old_screen)
+ return;
+
+#ifdef HAVE_GTK_RECENT
+ if (old_screen) {
+ g_signal_handlers_disconnect_by_func (
+ gtk_recent_manager_get_for_screen (old_screen),
+ G_CALLBACK (ev_window_setup_recent), window);
+ }
+
+ priv->recent_manager = gtk_recent_manager_get_for_screen (screen);
+ g_signal_connect_swapped (priv->recent_manager,
+ "changed",
+ G_CALLBACK (ev_window_setup_recent),
+ 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);
}
g_signal_handlers_disconnect_by_func
(old_screen, G_CALLBACK (screen_size_changed_cb), window);
- screen = gtk_widget_get_screen (widget);
g_signal_connect_object (screen, "size-changed",
G_CALLBACK (screen_size_changed_cb),
window, 0);
gtk_window_set_default_size (GTK_WINDOW (dialog), 500, 400);
editor = egg_toolbar_editor_new (ev_window->priv->ui_manager,
- ev_application_get_toolbars_model (EV_APP));
+ ev_application_get_toolbars_model (EV_APP, FALSE));
gtk_container_set_border_width (GTK_CONTAINER (editor), 5);
gtk_box_set_spacing (GTK_BOX (EGG_TOOLBAR_EDITOR (editor)), 5);
static void
ev_window_cmd_view_reload (GtkAction *action, EvWindow *ev_window)
{
- char *uri;
- int page;
-
- g_return_if_fail (EV_IS_WINDOW (ev_window));
+ gchar *uri;
- page = ev_page_cache_get_current_page (ev_window->priv->page_cache);
uri = g_strdup (ev_window->priv->uri);
-
- ev_window_open_uri (ev_window, uri, NULL);
-
- /* In case the number of pages in the document has changed. */
- page = CLAMP (page, 0, ev_page_cache_get_n_pages (ev_window->priv->page_cache) - 1);
-
- ev_page_cache_set_current_page (ev_window->priv->page_cache, page);
-
+ ev_window_open_uri (ev_window, uri, NULL, 0, FALSE);
g_free (uri);
}
"presentation", &presentation,
NULL);
- if (fullscreen)
+ if (fullscreen) {
ev_window_stop_fullscreen (window);
- if (presentation)
+ } else if (presentation) {
ev_window_stop_presentation (window);
+ gtk_widget_grab_focus (window->priv->view);
+ } else {
+ gtk_widget_grab_focus (window->priv->view);
+ }
if (fullscreen && presentation)
g_warning ("Both fullscreen and presentation set somehow");
ev_window_update_actions (ev_window);
if (ev_view_get_sizing_mode (view) == EV_SIZING_FREE && !ev_window_is_empty (ev_window)) {
- ev_metadata_manager_set_double (ev_window->priv->uri, "zoom",
- ev_view_get_zoom (view));
+ gdouble zoom;
+
+ zoom = ev_view_get_zoom (view);
+ zoom *= 72.0 / ev_window_get_screen_dpi (ev_window);
+ ev_metadata_manager_set_double (ev_window->priv->uri, "zoom", zoom);
}
}
static char *
build_comments_string (void)
{
+#ifdef ENABLE_PDF
PopplerBackend backend;
const char *backend_name;
const char *version;
break;
}
- return g_strdup_printf (_("PostScript and PDF File Viewer.\n"
+ return g_strdup_printf (_("Document Viewer.\n"
"Using poppler %s (%s)"),
version, backend_name);
+#else
+ return g_strdup_printf (_("Document Viewer"));
+#endif
}
static void
"Marco Pesenti Gritti <marco@gnome.org>",
"Nickolay V. Shmyrev <nshmyrev@yandex.ru>",
"Bryan Clark <clarkbw@gnome.org>",
- "Carlos Garcia Campos <carlosgc@gnome.org>",
+ "Carlos Garcia Campos <carlosgc@gnome.org>",
+ "Wouter Bolsterlee <wbolster@gnome.org>",
NULL
};
"name", _("Evince"),
"version", VERSION,
"copyright",
- _("\xc2\xa9 1996-2005 The Evince authors"),
+ _("\xc2\xa9 1996-2007 The Evince authors"),
"license", license_trans,
"website", "http://www.gnome.org/projects/evince",
"comments", comments,
GtkAction *action;
action = gtk_action_group_get_action (ev_window->priv->action_group, "ViewSidebar");
- gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
- GTK_WIDGET_VISIBLE (ev_sidebar));
if (!ev_view_get_presentation (view) &&
!ev_view_get_fullscreen (view)) {
+
+ gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
+ GTK_WIDGET_VISIBLE (ev_sidebar));
+
ev_metadata_manager_set_boolean (ev_window->priv->uri, "sidebar_visibility",
GTK_WIDGET_VISIBLE (ev_sidebar));
}
}
-static gboolean
-view_menu_popup_cb (EvView *view,
- EvLink *link,
- EvWindow *ev_window)
+static void
+view_menu_link_popup (EvWindow *ev_window,
+ EvLink *link)
{
- GtkWidget *popup;
gboolean show_external = FALSE;
gboolean show_internal = FALSE;
GtkAction *action;
-
- if (ev_view_get_presentation (EV_VIEW (ev_window->priv->view)))
- return FALSE;
if (ev_window->priv->link)
g_object_unref (ev_window->priv->link);
else
ev_window->priv->link = NULL;
- popup = ev_window->priv->view_popup;
-
if (ev_window->priv->link) {
EvLinkAction *ev_action;
ev_action = ev_link_get_action (link);
- if (!ev_action)
- return FALSE;
-
- switch (ev_link_action_get_action_type (ev_action)) {
- case EV_LINK_ACTION_TYPE_GOTO_DEST:
- case EV_LINK_ACTION_TYPE_GOTO_REMOTE:
- show_internal = TRUE;
- break;
- case EV_LINK_ACTION_TYPE_EXTERNAL_URI:
- case EV_LINK_ACTION_TYPE_LAUNCH:
- show_external = TRUE;
- break;
- default:
- break;
+ if (ev_action) {
+ switch (ev_link_action_get_action_type (ev_action)) {
+ case EV_LINK_ACTION_TYPE_GOTO_DEST:
+ case EV_LINK_ACTION_TYPE_GOTO_REMOTE:
+ show_internal = TRUE;
+ break;
+ case EV_LINK_ACTION_TYPE_EXTERNAL_URI:
+ case EV_LINK_ACTION_TYPE_LAUNCH:
+ show_external = TRUE;
+ break;
+ default:
+ break;
+ }
}
}
"GoLink");
gtk_action_set_visible (action, show_internal);
- gtk_menu_popup (GTK_MENU (popup), NULL, NULL,
- NULL, NULL,
+ action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
+ "OpenLinkNewWindow");
+ gtk_action_set_visible (action, show_internal);
+}
+
+static void
+view_menu_image_popup (EvWindow *ev_window,
+ EvImage *image)
+{
+ GtkAction *action;
+ gboolean show_image = FALSE;
+
+ if (ev_window->priv->image)
+ g_object_unref (ev_window->priv->image);
+
+ if (image)
+ ev_window->priv->image = g_object_ref (image);
+ else
+ ev_window->priv->image = NULL;
+
+ show_image = (ev_window->priv->image != NULL);
+
+ action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
+ "SaveImageAs");
+ gtk_action_set_visible (action, show_image);
+
+ action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
+ "CopyImage");
+ gtk_action_set_visible (action, show_image);
+}
+
+static gboolean
+view_menu_popup_cb (EvView *view,
+ GObject *object,
+ EvWindow *ev_window)
+{
+ if (ev_view_get_presentation (EV_VIEW (ev_window->priv->view)))
+ return FALSE;
+
+ view_menu_link_popup (ev_window,
+ EV_IS_LINK (object) ? EV_LINK (object) : NULL);
+ view_menu_image_popup (ev_window,
+ EV_IS_IMAGE (object) ? EV_IMAGE (object) : NULL);
+
+ gtk_menu_popup (GTK_MENU (ev_window->priv->view_popup),
+ NULL, NULL, NULL, NULL,
3, gtk_get_current_event_time ());
return TRUE;
}
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
ev_view_set_sizing_mode (EV_VIEW (ev_window->priv->view), mode);
if (mode == EV_SIZING_FREE) {
- ev_view_set_zoom (EV_VIEW (ev_window->priv->view), zoom, FALSE);
+ ev_view_set_zoom (EV_VIEW (ev_window->priv->view),
+ zoom * ev_window_get_screen_dpi (ev_window) / 72.0,
+ FALSE);
}
}
priv->title = NULL;
}
- if (priv->recent_view) {
- g_object_unref (priv->recent_view);
- priv->recent_view = NULL;
- }
-
if (priv->ui_manager) {
g_object_unref (priv->ui_manager);
priv->ui_manager = NULL;
priv->attachment_popup_action_group = NULL;
}
+#ifdef HAVE_GTK_RECENT
+ if (priv->recent_action_group) {
+ g_object_unref (priv->recent_action_group);
+ priv->recent_action_group = NULL;
+ }
+
+ if (priv->recent_manager) {
+ g_signal_handlers_disconnect_by_func (priv->recent_manager,
+ ev_window_setup_recent,
+ window);
+ priv->recent_manager = NULL;
+ }
+
+ priv->recent_ui_id = 0;
+#else
+ if (priv->recent_view) {
+ g_object_unref (priv->recent_view);
+ priv->recent_view = NULL;
+ }
+#endif /* HAVE_GTK_RECENT */
+
if (priv->page_cache) {
g_signal_handlers_disconnect_by_func (priv->page_cache, page_changed_cb, window);
priv->page_cache = NULL;
priv->view = NULL;
}
- if (priv->xfer_job) {
- ev_window_clear_xfer_job (window);
+ if (priv->password_view) {
+ g_object_unref (priv->password_view);
+ priv->password_view = NULL;
+ }
+
+ 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);
+
+#ifdef WITH_GTK_PRINT
+ ev_window_clear_print_job (window);
- if (priv->password_document) {
- g_object_unref (priv->password_document);
- priv->password_document = NULL;
+ if (window->priv->gtk_print_job) {
+ g_object_unref (window->priv->gtk_print_job);
+ window->priv->gtk_print_job = NULL;
}
- ev_window_close_dialogs (window);
+ if (window->priv->printer) {
+ g_object_unref (window->priv->printer);
+ window->priv->printer = NULL;
+ }
+
+ if (window->priv->print_settings) {
+ g_object_unref (window->priv->print_settings);
+ window->priv->print_settings = NULL;
+ }
+
+ if (window->priv->print_page_setup) {
+ g_object_unref (window->priv->print_page_setup);
+ window->priv->print_page_setup = NULL;
+ }
+#endif
if (priv->link) {
g_object_unref (priv->link);
priv->link = NULL;
}
+ if (priv->image) {
+ g_object_unref (priv->image);
+ priv->image = NULL;
+ }
+
if (priv->attach_list) {
g_list_foreach (priv->attach_list,
(GFunc) g_object_unref,
}
if (priv->uri) {
+ if (priv->unlink_temp_file)
+ ev_window_clear_temp_file (window);
g_free (priv->uri);
priv->uri = NULL;
}
priv->dest = NULL;
}
+ if (priv->history) {
+ g_object_unref (priv->history);
+ priv->history = NULL;
+ }
+
if (priv->fullscreen_timeout_id) {
g_source_remove (priv->fullscreen_timeout_id);
priv->fullscreen_timeout_id = 0;
{ "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,
+ 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",
N_("Save a copy of the current document"),
G_CALLBACK (ev_window_cmd_save_as) },
+ { "FilePrintSetup", NULL, N_("Print Set_up..."), NULL,
+ N_("Setup the page settings for printing"),
+ G_CALLBACK (ev_window_cmd_file_print_setup) },
{ "FilePrint", GTK_STOCK_PRINT, N_("_Print..."), "<control>P",
N_("Print this document"),
G_CALLBACK (ev_window_cmd_file_print) },
/* Edit menu */
{ "EditCopy", GTK_STOCK_COPY, NULL, "<control>C", NULL,
G_CALLBACK (ev_window_cmd_edit_copy) },
- { "EditSelectAll", NULL, N_("Select _All"), "<control>A", NULL,
+#ifdef HAVE_GTK_RECENT
+ { "EditSelectAll", GTK_STOCK_SELECT_ALL, N_("Select _All"), "<control>A", NULL,
+#else
+ { "EditSelectAll", NULL, N_("Select _All"), "<control>A", NULL,
+#endif /* HAVE_GTK_RECENT */
G_CALLBACK (ev_window_cmd_edit_select_all) },
{ "EditFind", GTK_STOCK_FIND, N_("_Find..."), "<control>F",
N_("Find a word or phrase in the document"),
G_CALLBACK (ev_window_cmd_edit_find_previous) },
{ "EditToolbar", NULL, N_("T_oolbar"), NULL, NULL,
G_CALLBACK (ev_window_cmd_edit_toolbar) },
- { "EditRotateLeft", NULL, N_("Rotate _Left"), NULL, NULL,
+ { "EditRotateLeft", EV_STOCK_ROTATE_LEFT, N_("Rotate _Left"), NULL, NULL,
G_CALLBACK (ev_window_cmd_edit_rotate_left) },
- { "EditRotateRight", NULL, N_("Rotate _Right"), NULL, NULL,
+ { "EditRotateRight", EV_STOCK_ROTATE_RIGHT, N_("Rotate _Right"), NULL, NULL,
G_CALLBACK (ev_window_cmd_edit_rotate_right) },
/* View menu */
/* Toggle items */
static const GtkToggleActionEntry toggle_entries[] = {
/* View Menu */
- { "ViewToolbar", NULL, N_("_Toolbar"), "<shift><control>T",
+ { "ViewToolbar", NULL, N_("_Toolbar"), NULL,
N_("Show or hide the toolbar"),
G_CALLBACK (ev_window_view_toolbar_cb), TRUE },
{ "ViewSidebar", GTK_STOCK_INDEX, N_("Side _Pane"), "F9",
NULL, G_CALLBACK (ev_view_popup_cmd_open_link) },
{ "GoLink", GTK_STOCK_GO_FORWARD, N_("_Go To"), NULL,
NULL, G_CALLBACK (ev_view_popup_cmd_open_link) },
+ { "OpenLinkNewWindow", NULL, N_("Open in New _Window"), NULL,
+ NULL, G_CALLBACK (ev_view_popup_cmd_open_link_new_window) },
{ "CopyLinkAddress", NULL, N_("_Copy Link Address"), NULL,
- NULL,
- G_CALLBACK (ev_view_popup_cmd_copy_link_address) },
+ NULL, G_CALLBACK (ev_view_popup_cmd_copy_link_address) },
+ { "SaveImageAs", NULL, N_("_Save Image As..."), NULL,
+ NULL, G_CALLBACK (ev_view_popup_cmd_save_image_as) },
+ { "CopyImage", NULL, N_("Copy _Image"), NULL,
+ NULL, G_CALLBACK (ev_view_popup_cmd_copy_image) },
};
static const GtkActionEntry attachment_popup_entries [] = {
};
static void
-drag_data_received_cb (GtkWidget *widget, GdkDragContext *context,
- gint x, gint y, GtkSelectionData *selection_data,
- guint info, guint time, gpointer gdata)
+sidebar_links_link_activated_cb (EvSidebarLinks *sidebar_links, EvLink *link, EvWindow *window)
{
- GList *uri_list = NULL;
- GSList *uris = NULL;
- gchar *uri;
-
- uri_list = gnome_vfs_uri_list_parse ((gchar *) selection_data->data);
-
- if (uri_list) {
- while (uri_list) {
- uri = gnome_vfs_uri_to_string (uri_list->data, GNOME_VFS_URI_HIDE_NONE);
- uris = g_slist_append (uris, (gpointer) uri);
-
- uri_list = g_list_next (uri_list);
- }
-
- gnome_vfs_uri_list_free (uri_list);
-
- ev_application_open_uri_list (EV_APP, uris, 0);
-
- g_slist_free (uris);
- }
+ ev_view_handle_link (EV_VIEW (window->priv->view), link);
}
static void
gtk_widget_grab_focus (window->priv->view);
}
-static gboolean
-activate_label_cb (EvPageAction *page_action, char *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);
G_CALLBACK (zoom_control_changed_cb), window);
gtk_action_group_add_action (group, action);
g_object_unref (action);
+
+ action = g_object_new (EV_TYPE_NAVIGATION_ACTION,
+ "name", NAVIGATION_ACTION,
+ "label", _("Navigation"),
+ "is_important", TRUE,
+ "short_label", _("Back"),
+ "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);
}
static void
GtkAction *action;
action = gtk_action_group_get_action (action_group, "GoPreviousPage");
+ g_object_set (action, "is-important", TRUE, NULL);
/*translators: this is the label for toolbar button*/
g_object_set (action, "short_label", _("Previous"), NULL);
- g_object_set (action, "is-important", TRUE, NULL);
action = gtk_action_group_get_action (action_group, "GoNextPage");
g_object_set (action, "is-important", TRUE, NULL);
action = gtk_action_group_get_action (action_group, "ViewZoomIn");
/*translators: this is the label for toolbar button*/
g_object_set (action, "short_label", _("Zoom In"), NULL);
- action = gtk_action_group_get_action (action_group, "ViewZoomIn");
action = gtk_action_group_get_action (action_group, "ViewZoomOut");
/*translators: this is the label for toolbar button*/
g_object_set (action, "short_label", _("Zoom Out"), NULL);
- action = gtk_action_group_get_action (action_group, "ViewZoomIn");
action = gtk_action_group_get_action (action_group, "ViewBestFit");
/*translators: this is the label for toolbar button*/
g_object_set (action, "short_label", _("Best Fit"), NULL);
- action = gtk_action_group_get_action (action_group, "ViewZoomIn");
action = gtk_action_group_get_action (action_group, "ViewPageWidth");
/*translators: this is the label for toolbar button*/
g_object_set (action, "short_label", _("Fit Width"), NULL);
- action = gtk_action_group_get_action (action_group, "ViewZoomIn");
action = gtk_action_group_get_action (action_group, "LeaveFullscreen");
g_object_set (action, "is-important", TRUE, NULL);
{
char *uri = window->priv->uri;
GdkWindowState state;
- int x, y, width, height;
+ int x, y, width, height, document_width, document_height;
state = gdk_window_get_state (GTK_WIDGET (window)->window);
gtk_window_get_position (GTK_WINDOW (window), &x, &y);
gtk_window_get_size (GTK_WINDOW (window), &width, &height);
- if (!ev_window_is_empty (window)) {
+ if (!ev_window_is_empty (window) && window->priv->page_cache) {
+ ev_page_cache_get_max_width (window->priv->page_cache,
+ 0, 1.0,
+ &document_width);
+ ev_page_cache_get_max_height (window->priv->page_cache,
+ 0, 1.0,
+ &document_height);
+ ev_metadata_manager_set_double (uri, "window_width_ratio",
+ (double)width / document_width);
+ ev_metadata_manager_set_double (uri, "window_height_ratio",
+ (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);
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)
{
- const char *uri;
- char *escaped;
-
- uri = ev_link_action_get_uri (action);
- escaped = gnome_vfs_escape_host_and_path_string (uri);
+ 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);
- gnome_vfs_url_show (escaped);
- g_free (escaped);
+ return;
+ }
+
+ gnome_vfs_url_show (uri);
}
static void
uri = g_build_filename (dir, ev_link_action_get_filename (action),
NULL);
g_free (dir);
-
+
ev_application_open_uri_at_dest (EV_APP, uri,
+ gtk_window_get_screen (GTK_WINDOW (window)),
ev_link_action_get_dest (action),
+ 0,
+ FALSE,
GDK_CURRENT_TIME);
g_free (uri);
ev_window_cmd_focus_page_selector (NULL, window);
} else if (g_ascii_strcasecmp (name, "Find") == 0) {
ev_window_cmd_edit_find (NULL, window);
+ } else if (g_ascii_strcasecmp (name, "Close") == 0) {
+ ev_window_cmd_file_close_window (NULL, window);
} else {
- g_warning ("Unimplemented named action: %s, please post a bug report with a testcase.",
+ g_warning ("Unimplemented named action: %s, please post a "
+ "bug report in Evince bugzilla "
+ "(http://bugzilla.gnome.org) with a testcase.",
name);
}
}
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;
ev_view_handle_link (EV_VIEW (window->priv->view), window->priv->link);
}
+static void
+ev_view_popup_cmd_open_link_new_window (GtkAction *action, EvWindow *window)
+{
+ EvLinkAction *ev_action = NULL;
+ EvLinkDest *dest;
+
+ ev_action = ev_link_get_action (window->priv->link);
+ if (!ev_action)
+ return;
+
+ dest = ev_link_action_get_dest (ev_action);
+ if (!dest)
+ return;
+
+ ev_window_cmd_file_open_copy_at_dest (window, dest);
+}
+
static void
ev_view_popup_cmd_copy_link_address (GtkAction *action, EvWindow *window)
{
gtk_clipboard_set_text (clipboard, uri, -1);
}
+static void
+image_save_dialog_response_cb (GtkWidget *fc,
+ gint response_id,
+ EvWindow *ev_window)
+{
+ gchar *uri;
+ gchar *filename;
+ GError *error = NULL;
+
+ if (response_id != GTK_RESPONSE_OK) {
+ gtk_widget_destroy (fc);
+ return;
+ }
+
+ uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
+ filename = g_filename_from_uri (uri, NULL, NULL);
+ 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);
+
+ if (error) {
+ ev_window_error_dialog (GTK_WINDOW (ev_window),
+ _("The image could not be saved."),
+ error);
+ g_error_free (error);
+ }
+
+ g_free (filename);
+
+ gtk_widget_destroy (fc);
+}
+
+static void
+ev_view_popup_cmd_save_image_as (GtkAction *action, EvWindow *window)
+{
+ GtkWidget *fc;
+ GtkFileFilter *filter;
+
+ if (!window->priv->image)
+ return;
+
+ fc = gtk_file_chooser_dialog_new (_("Save Image"),
+ GTK_WINDOW (window),
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, GTK_RESPONSE_OK,
+ NULL);
+
+ gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
+ 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);
+
+ g_signal_connect (fc, "response",
+ G_CALLBACK (image_save_dialog_response_cb),
+ window);
+
+ gtk_widget_show (fc);
+}
+
+static void
+ev_view_popup_cmd_copy_image (GtkAction *action, EvWindow *window)
+{
+ GtkClipboard *clipboard;
+
+ 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));
+}
+
static void
ev_attachment_popup_cmd_open_attachment (GtkAction *action, EvWindow *window)
{
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);
attachment = (EvAttachment *) window->priv->attach_list->data;
fc = gtk_file_chooser_dialog_new (
- _("Save a Copy"),
+ _("Save Attachment"),
GTK_WINDOW (window),
attachment ? GTK_FILE_CHOOSER_ACTION_SAVE : GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
GTK_STOCK_CANCEL,
G_CALLBACK (window_configure_event_cb), NULL);
g_signal_connect (ev_window, "window_state_event",
G_CALLBACK (window_state_event_cb), NULL);
+ g_signal_connect (ev_window, "notify",
+ G_CALLBACK (fullscreen_timeout_cb), NULL);
ev_window->priv = EV_WINDOW_GET_PRIVATE (ev_window);
- ev_window->priv->dest = NULL;
-
ev_window->priv->page_mode = PAGE_MODE_DOCUMENT;
ev_window->priv->title = ev_window_title_new (ev_window);
g_warning ("building menus failed: %s", error->message);
g_error_free (error);
}
-
+
+#ifdef HAVE_GTK_RECENT
+ ev_window->priv->recent_manager = gtk_recent_manager_get_for_screen (
+ gtk_widget_get_screen (GTK_WIDGET (ev_window)));
+ ev_window->priv->recent_action_group = NULL;
+ ev_window->priv->recent_ui_id = 0;
+ g_signal_connect_swapped (ev_window->priv->recent_manager,
+ "changed",
+ G_CALLBACK (ev_window_setup_recent),
+ ev_window);
+#endif /* HAVE_GTK_RECENT */
+
ev_window->priv->menubar =
gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
"/MainMenu");
FALSE, FALSE, 0);
gtk_widget_show (toolbar_dock);
- ev_window->priv->toolbar = egg_editable_toolbar_new_with_model
- (ev_window->priv->ui_manager, ev_application_get_toolbars_model (EV_APP), NULL);
+ ev_window->priv->toolbar = GTK_WIDGET
+ (g_object_new (EGG_TYPE_EDITABLE_TOOLBAR,
+ "ui-manager", ev_window->priv->ui_manager,
+ "popup-path", "/ToolbarPopup",
+ "model", ev_application_get_toolbars_model (EV_APP, FALSE),
+ NULL));
+
egg_editable_toolbar_show (EGG_EDITABLE_TOOLBAR (ev_window->priv->toolbar),
"DefaultToolBar");
gtk_box_pack_start (GTK_BOX (toolbar_dock), ev_window->priv->toolbar,
TRUE, TRUE, 0);
gtk_widget_show (ev_window->priv->toolbar);
+ /* Preview toolbar */
+ ev_window->priv->preview_toolbar = egg_editable_toolbar_new_with_model
+ (ev_window->priv->ui_manager, ev_application_get_toolbars_model (EV_APP, TRUE), NULL);
+ gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), ev_window->priv->preview_toolbar,
+ FALSE, FALSE, 0);
+
/* Add the main area */
ev_window->priv->hpaned = gtk_hpaned_new ();
g_signal_connect (ev_window->priv->hpaned,
"popup",
G_CALLBACK (attachment_bar_menu_popup_cb),
ev_window, 0);
+ gtk_widget_show (sidebar_widget);
ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
sidebar_widget);
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),
/* Give focus to the document view */
gtk_widget_grab_focus (ev_window->priv->view);
- /* Drag and Drop */
- gtk_drag_dest_unset (GTK_WIDGET (ev_window->priv->view));
- gtk_drag_dest_set (GTK_WIDGET (ev_window->priv->view),
- GTK_DEST_DEFAULT_ALL,
- ev_drop_types,
- sizeof (ev_drop_types) / sizeof (ev_drop_types[0]),
- GDK_ACTION_COPY);
- g_signal_connect_swapped (G_OBJECT (ev_window->priv->view), "drag-data-received",
- G_CALLBACK (drag_data_received_cb),
- ev_window);
-
/* Set it user interface params */
-
ev_window_setup_recent (ev_window);
setup_chrome_from_metadata (ev_window);
update_chrome_visibility (ev_window);
gtk_window_set_default_size (GTK_WINDOW (ev_window), 600, 600);
+
setup_view_from_metadata (ev_window);
setup_sidebar_from_metadata (ev_window, NULL);