]> www.fi.muni.cz Git - evince.git/blobdiff - shell/ev-window.c
Use stock icon for Select All action. Fixes bug #382652.
[evince.git] / shell / ev-window.c
index e95c921373ac365a3d78051a0d2c439bbd552847..b3ad4ee7dbd01d7dc2939ed1bab1b38594a31640 100644 (file)
@@ -30,6 +30,7 @@
 
 #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"
@@ -39,7 +40,7 @@
 #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"
@@ -68,6 +69,7 @@
 #include "ev-file-helpers.h"
 #include "ev-utils.h"
 #include "ev-debug.h"
+#include "ev-history.h"
 
 #ifdef WITH_GNOME_PRINT
 #include "ev-print-job.h"
 #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>
@@ -100,6 +105,7 @@ typedef enum {
        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;
 
@@ -120,6 +126,7 @@ struct _EvWindowPrivate {
        GtkWidget *sidebar_thumbs;
        GtkWidget *sidebar_links;
        GtkWidget *sidebar_attachments;
+       GtkWidget *preview_toolbar;
 
        /* Dialogs */
        GtkWidget *properties;
@@ -143,7 +150,7 @@ struct _EvWindowPrivate {
        GtkWidget *fullscreen_toolbar;
        GtkWidget *fullscreen_popup;
        guint      fullscreen_timeout_id;
-       
+
        /* Popup link */
        GtkWidget *view_popup;
        EvLink    *link;
@@ -156,9 +163,10 @@ struct _EvWindowPrivate {
        char *uri;
        char *local_uri;
        EvLinkDest *dest;
+       gboolean unlink_temp_file;
        
        EvDocument *document;
-
+       EvHistory *history;
        EvPageCache *page_cache;
        EvWindowPageMode page_mode;
        EvWindowTitle *title;
@@ -190,6 +198,7 @@ static const GtkTargetEntry ev_drop_types[] = {
 
 #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"
@@ -234,6 +243,8 @@ static void     ev_window_cmd_view_presentation         (GtkAction        *actio
 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_attachment_popup_cmd_open_attachment (GtkAction        *action,
@@ -299,7 +310,7 @@ ev_window_setup_action_sensitivity (EvWindow *ev_window)
                can_get_text = TRUE;
        }
        
-       if (has_document && EV_IS_DOCUMENT_FIND (document)) {
+       if (has_pages && EV_IS_DOCUMENT_FIND (document)) {
                can_find = TRUE;
        }
 
@@ -312,7 +323,7 @@ ev_window_setup_action_sensitivity (EvWindow *ev_window)
                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;
 
        
@@ -330,16 +341,24 @@ ev_window_setup_action_sensitivity (EvWindow *ev_window)
 
 
        /* 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);
 
@@ -353,6 +372,7 @@ ev_window_setup_action_sensitivity (EvWindow *ev_window)
        /* 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);
 }
@@ -414,6 +434,11 @@ ev_window_update_actions (EvWindow *ev_window)
 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);
@@ -423,12 +448,13 @@ ev_window_set_view_accels_sensitivity (EvWindow *window, gboolean 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);
        }
 }
 
@@ -449,6 +475,7 @@ update_chrome_visibility (EvWindow *window)
        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));
@@ -461,11 +488,13 @@ update_chrome_visibility (EvWindow *window)
                              (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);
@@ -590,7 +619,15 @@ page_changed_cb (EvPageCache *page_cache,
                 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);
@@ -676,48 +713,28 @@ setup_sidebar_from_metadata (EvWindow *window, EvDocument *document)
 }
 
 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, };
-       GValue sizing_mode = { 0, };
-       GValue zoom = { 0, };
-       GValue continuous = { 0, };
-       GValue dual_page = { 0, };
-       GValue presentation = { 0, };
-       GValue fullscreen = { 0, };
-       GValue rotation = { 0, };
-       gboolean restore_size = TRUE;
-
-       /* Window size */
 
        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;
+                       return;
                } else {
                        gtk_window_unmaximize (GTK_WINDOW (window));
                }
                g_value_unset (&maximized);
        }
 
-       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));
-               g_value_unset (&width);
-               g_value_unset (&height);                
-       }
-       if (restore_size &&
-           ev_metadata_manager_get (uri, "window_x", &x, TRUE) &&
+       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));
@@ -725,6 +742,63 @@ setup_view_from_metadata (EvWindow *window)
                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;
+
+               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);                 
+               
+               gtk_window_resize (GTK_WINDOW (window),
+                                  g_value_get_double (&width_ratio) * document_width,
+                                  g_value_get_double (&height_ratio) * document_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 dual_page = { 0, };
+       GValue presentation = { 0, };
+       GValue fullscreen = { 0, };
+       GValue rotation = { 0, };
+       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));
+               } else {
+                       gtk_window_unmaximize (GTK_WINDOW (window));
+               }
+               g_value_unset (&maximized);
+       }
+
        /* Sizing mode */
        if (ev_metadata_manager_get (uri, "sizing_mode", &sizing_mode, FALSE)) {
                enum_value = g_enum_get_value_by_nick
@@ -823,11 +897,19 @@ ev_window_setup_document (EvWindow *ev_window)
        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);
+        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),
                                                   ev_window->priv->document);
        }
        
+       setup_size_from_metadata (ev_window);
        setup_document_from_metadata (ev_window);
        setup_sidebar_from_metadata (ev_window, document);
 
@@ -858,7 +940,7 @@ password_dialog_response (GtkWidget *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);
                
-               gtk_widget_destroy (password_dialog);
+               gtk_widget_destroy (password_dialog);
                        
                return;
        }
@@ -920,7 +1002,7 @@ ev_window_clear_local_uri (EvWindow *ev_window)
     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);
@@ -928,6 +1010,35 @@ ev_window_clear_local_uri (EvWindow *ev_window)
     }
 }
 
+static void
+ev_window_clear_temp_file (EvWindow *ev_window)
+{
+       GnomeVFSURI *uri;
+       gchar       *filename;
+       const gchar *tempdir;
+
+       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
@@ -950,22 +1061,25 @@ ev_window_xfer_job_cb  (EvJobXfer *job,
        /* Success! */
        if (job->error == NULL) {
 
-               g_free (ev_window->priv->uri);
+               if (ev_window->priv->uri)
+                       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->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) {
+                       setup_view_from_metadata (ev_window);
+                       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);         
 
                if (job->dest)
                        ev_window_goto_dest (ev_window, job->dest);
@@ -996,7 +1110,6 @@ ev_window_xfer_job_cb  (EvJobXfer *job,
                ev_window->priv->uri = g_strdup (job->uri);
                setup_view_from_metadata (ev_window);
 
-
                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),
@@ -1004,7 +1117,7 @@ ev_window_xfer_job_cb  (EvJobXfer *job,
                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), 
@@ -1050,13 +1163,16 @@ void
 ev_window_open_uri (EvWindow       *ev_window,
                    const char     *uri,
                    EvLinkDest     *dest,
-                   EvWindowRunMode mode)
+                   EvWindowRunMode mode,
+                   gboolean        unlink_temp_file)
 {
        ev_window_close_dialogs (ev_window);
        ev_window_clear_xfer_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;
+       
        ev_window->priv->xfer_job = ev_job_xfer_new (uri, dest, mode);
        g_signal_connect (ev_window->priv->xfer_job,
                          "finished",
@@ -1081,7 +1197,9 @@ file_open_dialog_response_cb (GtkWidget *chooser,
 
                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);
@@ -1108,9 +1226,13 @@ ev_window_cmd_file_open (GtkAction *action, EvWindow *window)
        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);
+       }
        
        g_signal_connect (chooser, "response",
                          G_CALLBACK (file_open_dialog_response_cb),
@@ -1119,16 +1241,117 @@ ev_window_cmd_file_open (GtkAction *action, EvWindow *window)
        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;
+
+       old_filename = g_filename_from_uri (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,
-                                   GtkRecentInfo *info)
+                                   EvWindow      *window)
 {
-       const gchar *uri;
+       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 (EV_APP, uri, NULL, GDK_CURRENT_TIME, NULL);
+       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
@@ -1143,7 +1366,8 @@ ev_window_cmd_recent_file_activate (GtkAction *action,
 
        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);
 }
@@ -1190,6 +1414,47 @@ compare_recent_items (GtkRecentInfo *a, GtkRecentInfo *b)
 }
 #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)
 {
@@ -1230,21 +1495,22 @@ ev_window_setup_recent (EvWindow *ev_window)
                        continue;
 
                action_name = g_strdup_printf ("RecentFile%u", i++);
-               label = g_strdup_printf ("_%d.  %s",
-                                        n_items + 1,
-                                        gtk_recent_info_get_display_name (info));
+               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_weak_ref (G_OBJECT (action),
-                                  (GWeakNotify) gtk_recent_info_unref,
-                                  gtk_recent_info_ref (info));
+               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) info);
+                                 (gpointer) ev_window);
 
                gtk_action_group_add_action (ev_window->priv->recent_action_group,
                                             action);
@@ -1345,6 +1611,34 @@ ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window)
        gtk_widget_show (fc);
 }
 
+#ifdef WITH_GTK_PRINT
+static void
+ev_window_print_page_setup_done_cb (GtkPageSetup *page_setup,
+                                   EvWindow     *window)
+{
+       /* Dialog was canceled */
+       if (!page_setup)
+               return;
+
+       if (window->priv->print_page_setup)
+               g_object_unref (window->priv->print_page_setup);
+       window->priv->print_page_setup = g_object_ref (page_setup);
+}
+#endif /* WITH_GTK_PRINT */
+
+static void
+ev_window_cmd_file_print_setup (GtkAction *action, EvWindow *ev_window)
+{
+#ifdef WITH_GTK_PRINT
+       gtk_print_run_page_setup_dialog_async (
+               GTK_WINDOW (ev_window),
+               ev_window->priv->print_page_setup,
+               ev_window->priv->print_settings,
+               (GtkPageSetupDoneFunc) ev_window_print_page_setup_done_cb,
+               ev_window);
+#endif /* WITH_GTK_PRINT */
+}
+
 #ifdef WITH_GTK_PRINT
 static void
 ev_window_clear_print_job (EvWindow *window)
@@ -1432,9 +1726,18 @@ ev_window_print_dialog_response_cb (GtkDialog *dialog,
                                    gint       response,
                                    EvWindow  *window)
 {
-       EvBackend     document_type;
-       gboolean      export_to_ps = TRUE;
-       GtkPrintPages print_pages;
+       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));
@@ -1457,32 +1760,10 @@ ev_window_print_dialog_response_cb (GtkDialog *dialog,
        window->priv->print_page_setup = g_object_ref (
                gtk_print_unix_dialog_get_page_setup (GTK_PRINT_UNIX_DIALOG (dialog)));
 
-       document_type = ev_document_factory_get_backend (window->priv->document);
-       print_pages = gtk_print_settings_get_print_pages (window->priv->print_settings);
+       file_format = gtk_print_settings_get (window->priv->print_settings,
+                                             GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT);
        
-       if (print_pages == GTK_PRINT_PAGES_ALL) {
-               switch (document_type) {
-                       case EV_BACKEND_PDF:
-                               /* Export to ps when printing to file */
-                               if (gtk_print_settings_has_key (window->priv->print_settings,
-                                                               GTK_PRINT_SETTINGS_OUTPUT_URI)) {
-                                       export_to_ps = TRUE;
-                               } else {
-                                       export_to_ps = !gtk_printer_accepts_pdf (window->priv->printer);
-                               }
-
-                               break;
-                       case EV_BACKEND_PS:
-                               export_to_ps = FALSE;
-                               break;
-                       default:
-                               export_to_ps = TRUE;
-                               break;
-               }
-       }
-
-       if ((export_to_ps || document_type == EV_BACKEND_PS) &&
-           !gtk_printer_accepts_ps (window->priv->printer)) {
+       if (!gtk_printer_accepts_ps (window->priv->printer)) {
                GtkWidget *msgdialog;
 
                msgdialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
@@ -1497,65 +1778,64 @@ ev_window_print_dialog_response_cb (GtkDialog *dialog,
                return FALSE;
        }
 
-       if (export_to_ps) {
-               EvPrintRange *ranges = NULL;
-               EvPageCache  *page_cache;
-               gint          n_ranges = 0;
-               gint          current_page;
-               gint          width;
-               gint          height;
-
-               ev_window_clear_print_job (window);
-
-               current_page =
-                       gtk_print_unix_dialog_get_current_page (GTK_PRINT_UNIX_DIALOG (dialog));
-
-               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_cache = ev_page_cache_get (window->priv->document);
-               ev_page_cache_get_size (page_cache,
-                                       current_page,
-                                       0, 1.0,
-                                       &width, &height);
+       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);
        
-               window->priv->print_job =
-                       ev_job_print_new (window->priv->document,
-                                         ranges, n_ranges,
-                                         (gdouble)width,
-                                         (gdouble)height);
+       switch (print_pages) {
+       case GTK_PRINT_PAGES_CURRENT:
+               ranges = g_new0 (EvPrintRange, 1);
                
-               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);
-       } else {
-               gchar *filename;
+               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;
+       }
 
-               filename = g_filename_from_uri (window->priv->uri, NULL, NULL);
-               ev_window_print_send (window, filename);
-               g_free (filename);
+       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;
@@ -1566,10 +1846,11 @@ ev_window_print_dialog_response_cb (GtkDialog *dialog,
 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;
+       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);
@@ -1601,13 +1882,23 @@ ev_window_print_range (EvWindow *ev_window, int first_page, int last_page)
 
        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),
-                                                      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);
+                                                      capabilities);
+
        gtk_print_unix_dialog_set_current_page (GTK_PRINT_UNIX_DIALOG (dialog),
                                                current_page);
        
@@ -2002,10 +2293,15 @@ fullscreen_popup_size_request_cb (GtkWidget *popup, GtkRequisition *req, EvWindo
 }
 
 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;
@@ -2021,7 +2317,7 @@ fullscreen_set_timeout (EvWindow *window)
        }
        
        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);
@@ -2100,7 +2396,7 @@ ev_window_create_fullscreen_popup (EvWindow *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);
@@ -2258,6 +2554,8 @@ ev_window_run_presentation (EvWindow *window)
                          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);
 }
@@ -2284,6 +2582,8 @@ ev_window_stop_presentation (EvWindow *window)
                                              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);
 }
@@ -2307,29 +2607,14 @@ ev_window_cmd_view_presentation (GtkAction *action, EvWindow *window)
 static void
 ev_window_run_preview (EvWindow *window)
 {
-       EggToolbarsModel *model;
-       EggTbModelFlags   flags;
-
-       model = egg_toolbars_model_new ();
-
-       egg_toolbars_model_load_toolbars (model,
-                                         DATADIR"/evince-toolbar.xml");
-       
-       flags = egg_toolbars_model_get_flags (model, 1);
-       egg_toolbars_model_set_flags (model, 1, flags &= ~(EGG_TB_MODEL_HIDDEN));
-
-       egg_editable_toolbar_set_model (EGG_EDITABLE_TOOLBAR (window->priv->toolbar),
-                                       model);
-       
-       egg_editable_toolbar_hide (EGG_EDITABLE_TOOLBAR (window->priv->toolbar),
-                                  "DefaultToolBar");
-       egg_editable_toolbar_show (EGG_EDITABLE_TOOLBAR (window->priv->toolbar),
-                                  "PreviewToolBar");
-
        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);
 }
 
@@ -2367,6 +2652,24 @@ ev_window_screen_changed (GtkWidget *widget,
        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
+       
        if (GTK_WIDGET_CLASS (ev_window_parent_class)->screen_changed) {
                GTK_WIDGET_CLASS (ev_window_parent_class)->screen_changed (widget, old_screen);
        }
@@ -2375,7 +2678,6 @@ ev_window_screen_changed (GtkWidget *widget,
                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);
@@ -2460,7 +2762,7 @@ ev_window_cmd_edit_toolbar (GtkAction *action, EvWindow *ev_window)
        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);
              
@@ -2564,7 +2866,7 @@ ev_window_cmd_view_reload (GtkAction *action, EvWindow *ev_window)
 
        uri = g_strdup (ev_window->priv->uri);
 
-       ev_window_open_uri (ev_window, uri, NULL, 0);
+       ev_window_open_uri (ev_window, uri, NULL, 0, FALSE);
 
        g_free (uri);
 }
@@ -2800,6 +3102,7 @@ ev_window_dual_mode_changed_cb (EvView *view, GParamSpec *pspec, EvWindow *ev_wi
 static char *
 build_comments_string (void)
 {
+#ifdef ENABLE_PDF
        PopplerBackend backend;
        const char *backend_name;
        const char *version;
@@ -2818,9 +3121,12 @@ build_comments_string (void)
                        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
@@ -2832,7 +3138,8 @@ ev_window_cmd_help_about (GtkAction *action, EvWindow *ev_window)
                "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
        };
 
@@ -2877,7 +3184,7 @@ ev_window_cmd_help_about (GtkAction *action, EvWindow *ev_window)
                "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,
@@ -2944,11 +3251,13 @@ ev_window_sidebar_visibility_changed_cb (EvSidebar  *ev_sidebar,
        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));
        }
@@ -3010,6 +3319,10 @@ view_menu_popup_cb (EvView   *view,
                                              "GoLink");
        gtk_action_set_visible (action, show_internal);
 
+       action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
+                                             "OpenLinkNewWindow");
+       gtk_action_set_visible (action, show_internal);
+
        gtk_menu_popup (GTK_MENU (popup), NULL, NULL,
                        NULL, NULL,
                        3, gtk_get_current_event_time ());
@@ -3231,6 +3544,11 @@ ev_window_dispose (GObject *object)
                priv->view = NULL;
        }
 
+       if (priv->password_view) {
+               g_object_unref (priv->password_view);
+               priv->password_view = NULL;
+       }
+
        if (priv->xfer_job) {
                ev_window_clear_xfer_job (window);
        }
@@ -3287,6 +3605,8 @@ ev_window_dispose (GObject *object)
        }
 
        if (priv->uri) {
+               if (priv->unlink_temp_file)
+                       ev_window_clear_temp_file (window);
                g_free (priv->uri);
                priv->uri = NULL;
        }
@@ -3296,6 +3616,11 @@ ev_window_dispose (GObject *object)
                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;
@@ -3333,9 +3658,15 @@ static const GtkActionEntry entries[] = {
        { "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,
+         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) },
@@ -3347,7 +3678,7 @@ static const GtkActionEntry entries[] = {
         /* 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,
+       { "EditSelectAll", GTK_STOCK_SELECT_ALL, N_("Select _All"), "<control>A", NULL,
          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"),
@@ -3358,9 +3689,9 @@ static const GtkActionEntry entries[] = {
          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 */
@@ -3481,6 +3812,8 @@ static const GtkActionEntry view_popup_entries [] = {
          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) },
@@ -3514,7 +3847,9 @@ drag_data_received_cb (GtkWidget *widget, GdkDragContext *context,
 
                gnome_vfs_uri_list_free (uri_list);
                
-               ev_application_open_uri_list (EV_APP, uris, 0);
+               ev_application_open_uri_list (EV_APP, uris,
+                                             gtk_widget_get_screen (widget),
+                                             0);
                
                g_slist_free (uris);
        }
@@ -3566,6 +3901,17 @@ register_custom_actions (EvWindow *window, GtkActionGroup *group)
                          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);
+       gtk_action_group_add_action (group, action);
+       g_object_unref (action);
 }
 
 static void
@@ -3574,9 +3920,9 @@ set_action_properties (GtkActionGroup *action_group)
        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);
@@ -3586,22 +3932,18 @@ set_action_properties (GtkActionGroup *action_group)
        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);
@@ -3698,7 +4040,7 @@ window_configure_event_cb (EvWindow *window, GdkEventConfigure *event, gpointer
 {
        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);
 
@@ -3706,11 +4048,19 @@ window_configure_event_cb (EvWindow *window, GdkEventConfigure *event, gpointer
                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_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);
+                       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);
                }
        }
 
@@ -3781,10 +4131,12 @@ open_remote_link (EvWindow *window, EvLinkAction *action)
        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);
@@ -3807,6 +4159,8 @@ do_action_named (EvWindow *window, EvLinkAction *action)
                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 in Evince bugzilla "
@@ -3842,6 +4196,23 @@ ev_view_popup_cmd_open_link (GtkAction *action, EvWindow *window)
        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)
 {
@@ -3983,6 +4354,8 @@ ev_window_init (EvWindow *ev_window)
                          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);
 
@@ -4040,7 +4413,8 @@ ev_window_init (EvWindow *ev_window)
        }
        
 #ifdef HAVE_GTK_RECENT
-       ev_window->priv->recent_manager = gtk_recent_manager_get_default ();
+       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,
@@ -4065,14 +4439,25 @@ ev_window_init (EvWindow *ev_window)
                            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,
@@ -4263,7 +4648,7 @@ ev_window_init (EvWindow *ev_window)
        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);