]> 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 c80314090e12bf6cbe33eefbb1fb604e983757c2..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"
@@ -78,7 +80,9 @@
 #include <gtk/gtkprintunixdialog.h>
 #endif
 
+#ifdef ENABLE_PDF
 #include <poppler.h>
+#endif
 
 #include <glib/gstdio.h>
 #include <glib/gi18n.h>
@@ -146,7 +150,7 @@ struct _EvWindowPrivate {
        GtkWidget *fullscreen_toolbar;
        GtkWidget *fullscreen_popup;
        guint      fullscreen_timeout_id;
-       
+
        /* Popup link */
        GtkWidget *view_popup;
        EvLink    *link;
@@ -162,7 +166,7 @@ struct _EvWindowPrivate {
        gboolean unlink_temp_file;
        
        EvDocument *document;
-
+       EvHistory *history;
        EvPageCache *page_cache;
        EvWindowPageMode page_mode;
        EvWindowTitle *title;
@@ -194,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"
@@ -318,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;
 
        
@@ -367,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);
 }
@@ -613,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);
@@ -883,6 +897,13 @@ 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);
@@ -994,7 +1015,7 @@ ev_window_clear_temp_file (EvWindow *ev_window)
 {
        GnomeVFSURI *uri;
        gchar       *filename;
-       gchar       *dir;
+       const gchar *tempdir;
 
        if (!ev_window->priv->uri)
                return;
@@ -1010,12 +1031,11 @@ ev_window_clear_temp_file (EvWindow *ev_window)
        if (!filename)
                return;
 
-       dir = g_path_get_dirname (filename);
-       if (g_ascii_strcasecmp (dir, g_get_tmp_dir ()) == 0) {
+       tempdir = g_get_tmp_dir ();
+       if (g_ascii_strncasecmp (filename, tempdir, strlen (tempdir)) == 0) {
                g_unlink (filename);
        }
 
-       g_free (dir);
        g_free (filename);
 }
 
@@ -1222,10 +1242,11 @@ ev_window_cmd_file_open (GtkAction *action, EvWindow *window)
 }
 
 static gchar *
-ev_window_get_copy_tmp_name (const gchar *filename)
+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);
@@ -1233,40 +1254,51 @@ ev_window_get_copy_tmp_name (const gchar *filename)
        do {
                gchar *basename;
 
-               basename = g_strdup_printf ("%s-%d", name, i);
-               tmp_filename = g_build_filename (g_get_tmp_dir (),
+               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 (g_file_test (tmp_filename, G_FILE_TEST_EXISTS));
+       } 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_get_copy_tmp_name (old_filename);
-       
-       if (symlink (old_filename, new_filename) != 0) {
-               gchar  *msg;
-               GError *error;
-
-               msg = g_strdup_printf (_("Cannot open a copy."));
-               error = g_error_new (G_FILE_ERROR,
-                                    g_file_error_from_errno (errno),
-                                    _("Couldn't create symlink ā€œ%sā€: %s"),
-                                    new_filename, strerror (errno));
-               ev_window_error_dialog (GTK_WINDOW (window), msg, error);
-               g_free (msg);
-               g_error_free (error);
+       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);
 
@@ -1705,6 +1737,7 @@ ev_window_print_dialog_response_cb (GtkDialog *dialog,
        gdouble        width;
        gdouble        height;
        GtkPrintPages  print_pages;
+       const gchar   *file_format;
        
        if (response != GTK_RESPONSE_OK) {
                gtk_widget_destroy (GTK_WIDGET (dialog));
@@ -1727,6 +1760,9 @@ 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)));
 
+       file_format = gtk_print_settings_get (window->priv->print_settings,
+                                             GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT);
+       
        if (!gtk_printer_accepts_ps (window->priv->printer)) {
                GtkWidget *msgdialog;
 
@@ -1788,6 +1824,7 @@ ev_window_print_dialog_response_cb (GtkDialog *dialog,
        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,
@@ -1809,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);
@@ -1844,13 +1882,22 @@ 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);
@@ -2250,9 +2297,11 @@ fullscreen_timeout_cb (EvWindow *window)
 {
        EvView *view = EV_VIEW (window->priv->view);
 
-       if (!view || !ev_view_get_fullscreen (EV_VIEW (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;
@@ -2505,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);
 }
@@ -2531,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);
 }
@@ -3049,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;
@@ -3067,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
@@ -3127,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,
@@ -3559,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;
@@ -3616,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"),
@@ -3627,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", "object-rotate-left", N_("Rotate _Left"), NULL, NULL,
+       { "EditRotateLeft", EV_STOCK_ROTATE_LEFT, N_("Rotate _Left"), NULL, NULL,
          G_CALLBACK (ev_window_cmd_edit_rotate_left) },
-       { "EditRotateRight", "object-rotate-right", 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 */
@@ -3839,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
@@ -4575,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);