]> www.fi.muni.cz Git - evince.git/blobdiff - shell/ev-window.c
Add seb128
[evince.git] / shell / ev-window.c
index 9eab28a3a40d7a2147e28f312665a5b3162e88a9..e95c921373ac365a3d78051a0d2c439bbd552847 100644 (file)
 #include "ev-jobs.h"
 #include "ev-sidebar-page.h"
 #include "eggfindbar.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-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-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 "egg-toolbars-model.h"
 #include "ephy-zoom.h"
 #include "ephy-zoom-action.h"
 #include <libgnomeprintui/gnome-print-dialog.h>
 #endif
 
 #include <libgnomeprintui/gnome-print-dialog.h>
 #endif
 
+#ifdef WITH_GTK_PRINT
+#include <gtk/gtkprintunixdialog.h>
+#endif
+
 #include <poppler.h>
 
 #include <glib/gi18n.h>
 #include <poppler.h>
 
 #include <glib/gi18n.h>
@@ -115,16 +123,21 @@ struct _EvWindowPrivate {
 
        /* Dialogs */
        GtkWidget *properties;
 
        /* Dialogs */
        GtkWidget *properties;
-#ifdef WITH_GNOME_PRINT
+#ifdef WITH_PRINT
        GtkWidget *print_dialog;
 #endif
        GtkWidget *password_dialog;
 
        /* UI Builders */
        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;
 
        /* Fullscreen mode */
        GtkWidget *fullscreen_toolbar;
@@ -149,12 +162,22 @@ struct _EvWindowPrivate {
        EvPageCache *page_cache;
        EvWindowPageMode page_mode;
        EvWindowTitle *title;
        EvPageCache *page_cache;
        EvWindowPageMode page_mode;
        EvWindowTitle *title;
+#ifndef HAVE_GTK_RECENT
        EggRecentViewUIManager *recent_view;
        EggRecentViewUIManager *recent_view;
+#endif
 
        EvJob *xfer_job;
 #ifdef WITH_GNOME_PRINT
        GnomePrintJob *print_job;
 #endif
 
        EvJob *xfer_job;
 #ifdef WITH_GNOME_PRINT
        GnomePrintJob *print_job;
 #endif
+
+#ifdef WITH_GTK_PRINT
+       EvJob            *print_job;
+       GtkPrintJob      *gtk_print_job;
+       GtkPrinter       *printer;
+       GtkPrintSettings *print_settings;
+       GtkPageSetup     *print_page_setup;
+#endif
 };
 
 static const GtkTargetEntry ev_drop_types[] = {
 };
 
 static const GtkTargetEntry ev_drop_types[] = {
@@ -186,8 +209,12 @@ static void     ev_window_sidebar_visibility_changed_cb (EvSidebar        *ev_si
                                                         EvWindow         *ev_window);
 static void     ev_window_set_page_mode                 (EvWindow         *window,
                                                         EvWindowPageMode  page_mode);
                                                         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_xfer_job_cb                   (EvJobXfer        *job,
+                                                        gpointer          data);
+#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_sizing_mode_changed_cb        (EvView           *view,
                                                         GParamSpec       *pspec,
                                                         EvWindow         *ev_window);
@@ -296,7 +323,7 @@ ev_window_setup_action_sensitivity (EvWindow *ev_window)
        if (gconf_client_get_bool (client, GCONF_LOCKDOWN_PRINT, NULL)) {
                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);
        ok_to_print = FALSE;
 #endif
        g_object_unref (client);
@@ -591,6 +618,7 @@ setup_document_from_metadata (EvWindow *window)
                new_page = CLAMP (g_value_get_int (&page), 0, ev_page_cache_get_n_pages (window->priv->page_cache) - 1);
                ev_page_cache_set_current_page (window->priv->page_cache,
                                                new_page);
                new_page = CLAMP (g_value_get_int (&page), 0, ev_page_cache_get_n_pages (window->priv->page_cache) - 1);
                ev_page_cache_set_current_page (window->priv->page_cache,
                                                new_page);
+               g_value_unset (&page);
        }
 }
 
        }
 }
 
@@ -603,6 +631,7 @@ setup_chrome_from_metadata (EvWindow *window)
        if (ev_metadata_manager_get (NULL, "show_toolbar", &show_toolbar, FALSE)) {
                if (!g_value_get_boolean (&show_toolbar))
                        chrome &= ~EV_CHROME_TOOLBAR;
        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;
 }
        }
        window->priv->chrome = chrome;
 }
@@ -622,11 +651,12 @@ setup_sidebar_from_metadata (EvWindow *window, EvDocument *document)
        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));
        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 (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)) {
                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)) {
@@ -634,12 +664,14 @@ setup_sidebar_from_metadata (EvWindow *window, EvDocument *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);
                }
                } 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));
        } 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);
        }
 }
 
        }
 }
 
@@ -672,6 +704,7 @@ setup_view_from_metadata (EvWindow *window)
                } else {
                        gtk_window_unmaximize (GTK_WINDOW (window));
                }
                } else {
                        gtk_window_unmaximize (GTK_WINDOW (window));
                }
+               g_value_unset (&maximized);
        }
 
        if (restore_size &&
        }
 
        if (restore_size &&
@@ -680,12 +713,16 @@ setup_view_from_metadata (EvWindow *window)
                gtk_window_resize (GTK_WINDOW (window),
                                   g_value_get_int (&width),
                                   g_value_get_int (&height));
                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) &&
            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));
        }
        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 (&x);
+               g_value_unset (&y);
        }
 
        /* Sizing mode */
        }
 
        /* Sizing mode */
@@ -700,16 +737,19 @@ setup_view_from_metadata (EvWindow *window)
        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);
        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);
+               g_value_unset (&zoom);
        }
 
        /* Continuous */
        if (ev_metadata_manager_get (uri, "continuous", &continuous, FALSE)) {
                ev_view_set_continuous (view, g_value_get_boolean (&continuous));
        }
 
        /* 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));
        }
 
        /* 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 */
        }
 
        /* Presentation */
@@ -717,6 +757,7 @@ setup_view_from_metadata (EvWindow *window)
                if (g_value_get_boolean (&presentation) && uri) {
                        ev_window_run_presentation (window);
                }
                if (g_value_get_boolean (&presentation) && uri) {
                        ev_window_run_presentation (window);
                }
+               g_value_unset (&presentation);
        }
 
        /* Fullscreen */
        }
 
        /* Fullscreen */
@@ -724,6 +765,7 @@ setup_view_from_metadata (EvWindow *window)
                if (g_value_get_boolean (&fullscreen) && uri) {
                        ev_window_run_fullscreen (window);
                }
                if (g_value_get_boolean (&fullscreen) && uri) {
                        ev_window_run_fullscreen (window);
                }
+               g_value_unset (&fullscreen);
        }
 
        /* Rotation */
        }
 
        /* Rotation */
@@ -743,6 +785,7 @@ setup_view_from_metadata (EvWindow *window)
                                        break;
                        }
                }
                                        break;
                        }
                }
+               g_value_unset (&rotation);
        }
 }
 
        }
 }
 
@@ -985,16 +1028,19 @@ ev_window_close_dialogs (EvWindow *ev_window)
        if (ev_window->priv->password_dialog)
                gtk_widget_destroy (ev_window->priv->password_dialog);
        ev_window->priv->password_dialog = NULL;
        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
 
 #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);
                g_object_unref (ev_window->priv->print_job);
-       }
-       ev_window->priv->print_dialog = NULL;
        ev_window->priv->print_job = NULL;
 #endif
        ev_window->priv->print_job = NULL;
 #endif
-
+       
        if (ev_window->priv->properties)
                gtk_widget_destroy (ev_window->priv->properties);
        ev_window->priv->properties = NULL;
        if (ev_window->priv->properties)
                gtk_widget_destroy (ev_window->priv->properties);
        ev_window->priv->properties = NULL;
@@ -1010,7 +1056,7 @@ ev_window_open_uri (EvWindow       *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_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->xfer_job = ev_job_xfer_new (uri, dest, mode);
        g_signal_connect (ev_window->priv->xfer_job,
                          "finished",
        ev_window->priv->xfer_job = ev_job_xfer_new (uri, dest, mode);
        g_signal_connect (ev_window->priv->xfer_job,
                          "finished",
@@ -1073,6 +1119,18 @@ ev_window_cmd_file_open (GtkAction *action, EvWindow *window)
        gtk_widget_show (chooser);
 }
 
        gtk_widget_show (chooser);
 }
 
+#ifdef HAVE_GTK_RECENT
+static void
+ev_window_cmd_recent_file_activate (GtkAction     *action,
+                                   GtkRecentInfo *info)
+{
+       const gchar *uri;
+
+       uri = gtk_recent_info_get_uri (info);
+       
+       ev_application_open_uri (EV_APP, uri, NULL, GDK_CURRENT_TIME, NULL);
+}
+#else
 static void
 ev_window_cmd_recent_file_activate (GtkAction *action,
                                    EvWindow *ev_window)
 static void
 ev_window_cmd_recent_file_activate (GtkAction *action,
                                    EvWindow *ev_window)
@@ -1089,21 +1147,126 @@ ev_window_cmd_recent_file_activate (GtkAction *action,
        
        g_free (uri);
 }
        
        g_free (uri);
 }
+#endif /* HAVE_GTK_RECENT */
 
 static void
 ev_window_add_recent (EvWindow *window, const char *filename)
 {
 
 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);
        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 */
+
 static void
 ev_window_setup_recent (EvWindow *ev_window)
 {
 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))
+                       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));
+               
+               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_signal_connect (G_OBJECT (action), "activate",
+                                 G_CALLBACK (ev_window_cmd_recent_file_activate),
+                                 (gpointer) info);
+
+               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), 
        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), 
@@ -1118,6 +1281,7 @@ ev_window_setup_recent (EvWindow *ev_window)
        
        g_signal_connect (ev_window->priv->recent_view, "activate",
                        G_CALLBACK (ev_window_cmd_recent_file_activate), ev_window);
        
        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
 }
 
 static void
@@ -1181,85 +1345,357 @@ ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window)
        gtk_widget_show (fc);
 }
 
        gtk_widget_show (fc);
 }
 
+#ifdef WITH_GTK_PRINT
 static void
 static void
-ev_window_print (EvWindow *window)
+ev_window_clear_print_job (EvWindow *window)
 {
 {
-       EvPageCache *page_cache;
-       int last_page;
+       if (window->priv->print_job) {
+               if (!window->priv->print_job->finished)
+                       ev_job_queue_remove_job (window->priv->print_job);
 
 
-       page_cache = ev_page_cache_get (window->priv->document);
-       last_page = ev_page_cache_get_n_pages (page_cache);
+               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;
+       }
+}
 
 
-#ifdef WITH_GNOME_PRINT
-       ev_window_print_range (window, 1, last_page);
-#endif
+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;
+       GError      *error = NULL;
+       
+       if (window->priv->gtk_print_job)
+               g_object_unref (window->priv->gtk_print_job);
+       
+       job = gtk_print_job_new ("evince-print",
+                                window->priv->printer,
+                                window->priv->print_settings,
+                                window->priv->print_page_setup);
+       
+       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)
+{
+       EvBackend     document_type;
+       gboolean      export_to_ps = TRUE;
+       GtkPrintPages print_pages;
+       
+       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)));
+
+       document_type = ev_document_factory_get_backend (window->priv->document);
+       print_pages = gtk_print_settings_get_print_pages (window->priv->print_settings);
+       
+       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)) {
+               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;
+       }
+
+       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);
+       
+               window->priv->print_job =
+                       ev_job_print_new (window->priv->document,
+                                         ranges, n_ranges,
+                                         (gdouble)width,
+                                         (gdouble)height);
+               
+               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;
+
+               filename = g_filename_from_uri (window->priv->uri, NULL, NULL);
+               ev_window_print_send (window, filename);
+               g_free (filename);
+       }
+       
+       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;
+
+       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;
+       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);
+       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
 
 #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
 }
 
 void
@@ -1276,11 +1712,16 @@ ev_window_print_range (EvWindow *ev_window, int first_page, int last_page)
        if (ev_window->priv->print_job == NULL)
                ev_window->priv->print_job = gnome_print_job_new (config);
        
        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);
        g_object_unref (config);                                                                
 
        pages_label = g_strconcat (_("Pages"), " ", NULL);
@@ -1295,12 +1736,27 @@ ev_window_print_range (EvWindow *ev_window, int first_page, int last_page)
                                           GNOME_PRINT_DIALOG_RESPONSE_PREVIEW,
                                           FALSE);
 
                                           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);
+       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);
        gtk_widget_show (ev_window->priv->print_dialog);
-       return;
 }
 #endif /* WITH_GNOME_PRINT */
 }
 #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
+}
+
 static void
 ev_window_cmd_file_print (GtkAction *action, EvWindow *ev_window)
 {
 static void
 ev_window_cmd_file_print (GtkAction *action, EvWindow *ev_window)
 {
@@ -2152,10 +2608,14 @@ ev_window_cmd_escape (GtkAction *action, EvWindow *window)
                              "presentation", &presentation,
                              NULL);
 
                              "presentation", &presentation,
                              NULL);
 
-               if (fullscreen)
+               if (fullscreen) {
                        ev_window_stop_fullscreen (window);
                        ev_window_stop_fullscreen (window);
-               if (presentation)
+               } else if (presentation) {
                        ev_window_stop_presentation (window);
                        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");
 
                if (fullscreen && presentation)
                        g_warning ("Both fullscreen and presentation set somehow");
@@ -2715,11 +3175,6 @@ ev_window_dispose (GObject *object)
                priv->title = NULL;
        }
 
                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;
        if (priv->ui_manager) {
                g_object_unref (priv->ui_manager);
                priv->ui_manager = NULL;
@@ -2740,6 +3195,27 @@ ev_window_dispose (GObject *object)
                priv->attachment_popup_action_group = 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;
        if (priv->page_cache) {
                g_signal_handlers_disconnect_by_func (priv->page_cache, page_changed_cb, window);
                priv->page_cache = NULL;
@@ -2765,6 +3241,30 @@ ev_window_dispose (GObject *object)
        
        ev_window_close_dialogs (window);
 
        
        ev_window_close_dialogs (window);
 
+#ifdef WITH_GTK_PRINT
+       ev_window_clear_print_job (window);
+
+       if (window->priv->gtk_print_job) {
+               g_object_unref (window->priv->gtk_print_job);
+               window->priv->gtk_print_job = NULL;
+       }
+       
+       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->link) {
                g_object_unref (priv->link);
                priv->link = NULL;
@@ -2948,7 +3448,7 @@ static const GtkActionEntry entries[] = {
 /* Toggle items */
 static const GtkToggleActionEntry toggle_entries[] = {
        /* 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",
          N_("Show or hide the toolbar"),
          G_CALLBACK (ev_window_view_toolbar_cb), TRUE },
         { "ViewSidebar", GTK_STOCK_INDEX, N_("Side _Pane"), "F9",
@@ -3308,7 +3808,9 @@ do_action_named (EvWindow *window, EvLinkAction *action)
        } else if (g_ascii_strcasecmp (name, "Find") == 0) {
                ev_window_cmd_edit_find (NULL, window);
        } else {
        } else if (g_ascii_strcasecmp (name, "Find") == 0) {
                ev_window_cmd_edit_find (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);
        }
 }
                           name);
        }
 }
@@ -3536,7 +4038,17 @@ ev_window_init (EvWindow *ev_window)
                g_warning ("building menus failed: %s", error->message);
                g_error_free (error);
        }
                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_default ();
+       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");
        ev_window->priv->menubar =
                 gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
                                            "/MainMenu");