]> www.fi.muni.cz Git - evince.git/blobdiff - shell/ev-window.c
Updated Czech translation.
[evince.git] / shell / ev-window.c
index b9d6dfe0460d26a94889f5d2633b7a7e96ac19dd..532aa4e4aef3d40e99454b554ec3abe9c28210c3 100644 (file)
@@ -94,6 +94,8 @@
 
 #include <string.h>
 
 
 #include <string.h>
 
+char *xdg_user_dir_lookup (char *type);
+
 typedef enum {
        PAGE_MODE_DOCUMENT,
        PAGE_MODE_PASSWORD
 typedef enum {
        PAGE_MODE_DOCUMENT,
        PAGE_MODE_PASSWORD
@@ -431,13 +433,6 @@ ev_window_update_actions (EvWindow *ev_window)
                                        ev_view_can_zoom_out (view) &&
                                        !presentation_mode);
        
                                        ev_view_can_zoom_out (view) &&
                                        !presentation_mode);
        
-       ev_window_set_action_sensitive (ev_window, "Plus", !presentation_mode);
-       ev_window_set_action_sensitive (ev_window, "Minus", !presentation_mode);
-       ev_window_set_action_sensitive (ev_window, "KpPlus", !presentation_mode);
-       ev_window_set_action_sensitive (ev_window, "KpMinus", !presentation_mode);
-       ev_window_set_action_sensitive (ev_window, "CtrlKpPlus", !presentation_mode);
-       ev_window_set_action_sensitive (ev_window, "CtrlKpMinus", !presentation_mode);
-
         /* Go menu */
        if (has_pages) {
                ev_window_set_action_sensitive (ev_window, "GoPreviousPage", page > 0);
         /* Go menu */
        if (has_pages) {
                ev_window_set_action_sensitive (ev_window, "GoPreviousPage", page > 0);
@@ -611,6 +606,16 @@ update_sizing_buttons (EvWindow *window)
        }
 }
 
        }
 }
 
+/**
+ * ev_window_is_empty:
+ * @ev_window: The instance of the #EvWindow.
+ *
+ * It does look if there is any document loaded or if there is any job to load
+ * a document.
+ *
+ * Returns: %TRUE if there isn't any document loaded or any any documente to be
+ *          loaded, %FALSE in other case.
+ */
 gboolean
 ev_window_is_empty (const EvWindow *ev_window)
 {
 gboolean
 ev_window_is_empty (const EvWindow *ev_window)
 {
@@ -905,8 +910,14 @@ setup_size_from_metadata (EvWindow *window)
         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)) {
         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;
                gint document_width;
                gint document_height;
+               
+               GdkScreen *screen;
+               
+               gint request_width;
+               gint request_height;
 
                ev_page_cache_get_max_width (window->priv->page_cache, 
                                             0, 1.0,
 
                ev_page_cache_get_max_width (window->priv->page_cache, 
                                             0, 1.0,
@@ -915,9 +926,19 @@ setup_size_from_metadata (EvWindow *window)
                                             0, 1.0,
                                             &document_height);                 
                
                                             0, 1.0,
                                             &document_height);                 
                
+               request_width = g_value_get_double (&width_ratio) * document_width;
+               request_height = g_value_get_double (&height_ratio) * document_height;
+               
+               screen = gtk_window_get_screen (GTK_WINDOW (window));
+               
+               if (screen) {
+                       request_width = MIN (request_width, gdk_screen_get_width (screen));
+                       request_height = MIN (request_width, gdk_screen_get_height (screen));
+               }
+                               
                gtk_window_resize (GTK_WINDOW (window),
                gtk_window_resize (GTK_WINDOW (window),
-                                  g_value_get_double (&width_ratio) * document_width,
-                                  g_value_get_double (&height_ratio) * document_height);
+                                  request_width,
+                                  request_height);
                g_value_unset (&width_ratio);
                g_value_unset (&height_ratio);
        }
                g_value_unset (&width_ratio);
                g_value_unset (&height_ratio);
        }
@@ -1053,8 +1074,10 @@ ev_window_setup_document (EvWindow *ev_window)
 
        document = ev_window->priv->document;
        ev_window->priv->page_cache = ev_page_cache_get (ev_window->priv->document);
 
        document = ev_window->priv->document;
        ev_window->priv->page_cache = ev_page_cache_get (ev_window->priv->document);
-       g_signal_connect (ev_window->priv->page_cache, "page-changed", G_CALLBACK (page_changed_cb), ev_window);
-       g_signal_connect (ev_window->priv->page_cache, "history-changed", G_CALLBACK (history_changed_cb), ev_window);
+       g_signal_connect (ev_window->priv->page_cache, "page-changed",
+                         G_CALLBACK (page_changed_cb), ev_window);
+       g_signal_connect (ev_window->priv->page_cache, "history-changed",
+                         G_CALLBACK (history_changed_cb), ev_window);
 
        if (EV_IS_DOCUMENT_FIND (document)) {
                g_signal_connect_object (G_OBJECT (document),
 
        if (EV_IS_DOCUMENT_FIND (document)) {
                g_signal_connect_object (G_OBJECT (document),
@@ -1064,12 +1087,24 @@ ev_window_setup_document (EvWindow *ev_window)
        }
 
        if (EV_IS_DOCUMENT_THUMBNAILS (document)) {
        }
 
        if (EV_IS_DOCUMENT_THUMBNAILS (document)) {
+               EvRenderContext *rc;
+               gint page_width, page_height;
+               gdouble scale;
+
                ev_window_clear_thumbnail_job (ev_window);
                ev_window_clear_thumbnail_job (ev_window);
-               ev_window->priv->thumbnail_job = ev_job_thumbnail_new (document, 0, 0, 100);
+               
+               ev_page_cache_get_size (ev_window->priv->page_cache,
+                                       0, 0, 1.0,
+                                       &page_width, &page_height);
+               scale = (gdouble)128 / (gdouble)page_width;
+               
+               rc = ev_render_context_new (0, 0, scale);
+               ev_window->priv->thumbnail_job = ev_job_thumbnail_new (document, rc);
                g_signal_connect (ev_window->priv->thumbnail_job, "finished",
                                  G_CALLBACK (ev_window_set_icon_from_thumbnail),
                                  ev_window);
                ev_job_queue_add_job (EV_JOB (ev_window->priv->thumbnail_job), EV_JOB_PRIORITY_LOW);
                g_signal_connect (ev_window->priv->thumbnail_job, "finished",
                                  G_CALLBACK (ev_window_set_icon_from_thumbnail),
                                  ev_window);
                ev_job_queue_add_job (EV_JOB (ev_window->priv->thumbnail_job), EV_JOB_PRIORITY_LOW);
+               g_object_unref (rc);
        }
 
        ev_sidebar_set_document (sidebar, document);
        }
 
        ev_sidebar_set_document (sidebar, document);
@@ -1252,8 +1287,11 @@ ev_window_load_job_cb  (EvJobLoad *job,
                        g_object_unref (ev_window->priv->document);
                ev_window->priv->document = g_object_ref (document);
 
                        g_object_unref (ev_window->priv->document);
                ev_window->priv->document = g_object_ref (document);
 
-               if (!ev_window->priv->unlink_temp_file) {
+               if (job->mode != EV_WINDOW_MODE_PREVIEW) {
                        setup_view_from_metadata (ev_window);
                        setup_view_from_metadata (ev_window);
+               }
+
+               if (!ev_window->priv->unlink_temp_file) {
                        ev_window_add_recent (ev_window, ev_window->priv->uri);
                }
 
                        ev_window_add_recent (ev_window, ev_window->priv->uri);
                }
 
@@ -1312,12 +1350,27 @@ ev_window_load_job_cb  (EvJobLoad *job,
        return;
 }
 
        return;
 }
 
+/**
+ * ev_window_get_uri:
+ * @ev_window: The instance of the #EvWindow.
+ *
+ * It returns the uri of the document showed in the #EvWindow.
+ *
+ * Returns: the uri of the document showed in the #EvWindow.
+ */
 const char *
 ev_window_get_uri (EvWindow *ev_window)
 {
        return ev_window->priv->uri;
 }
 
 const char *
 ev_window_get_uri (EvWindow *ev_window)
 {
        return ev_window->priv->uri;
 }
 
+/**
+ * ev_window_close_dialogs:
+ * @ev_window: The window where dialogs will be closed.
+ *
+ * It looks for password, print and properties dialogs and closes them and
+ * frees them from memory. If there is any print job it does free it too.
+ */
 static void
 ev_window_close_dialogs (EvWindow *ev_window)
 {
 static void
 ev_window_close_dialogs (EvWindow *ev_window)
 {
@@ -1484,6 +1537,13 @@ ev_window_cmd_file_open (GtkAction *action, EvWindow *window)
                gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (chooser),
                                          window->priv->uri);
        }
                gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (chooser),
                                          window->priv->uri);
        }
+       else {
+               char *folder;
+               folder = xdg_user_dir_lookup ("DOCUMENTS");
+               gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser),
+                                                    folder);
+               free (folder);
+       }
        
        g_signal_connect (chooser, "response",
                          G_CALLBACK (file_open_dialog_response_cb),
        
        g_signal_connect (chooser, "response",
                          G_CALLBACK (file_open_dialog_response_cb),
@@ -1536,11 +1596,11 @@ ev_window_create_tmp_symlink (const gchar *filename, GError **error)
 static void
 ev_window_cmd_file_open_copy_at_dest (EvWindow *window, EvLinkDest *dest)
 {
 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;
-       gchar *uri_unc;
+       GError      *error = NULL;
+       gchar       *symlink_uri;
+       gchar       *old_filename;
+       gchar       *new_filename;
+       const gchar *uri_unc;
 
        uri_unc = g_object_get_data (G_OBJECT (window->priv->document),
                                     "uri-uncompressed");
 
        uri_unc = g_object_get_data (G_OBJECT (window->priv->document),
                                     "uri-uncompressed");
@@ -1689,13 +1749,11 @@ ev_window_get_recent_file_label (gint index, const gchar *filename)
        p = filename;
        end = filename + length;
  
        p = filename;
        end = filename + length;
  
-       while (p != end)
-       {
+       while (p != end) {
                const gchar *next;
                next = g_utf8_next_char (p);
  
                const gchar *next;
                next = g_utf8_next_char (p);
  
-               switch (*p)
-               {
+               switch (*p) {
                        case '_':
                                g_string_append (str, "__");
                                break;
                        case '_':
                                g_string_append (str, "__");
                                break;
@@ -1811,63 +1869,100 @@ file_save_dialog_response_cb (GtkWidget *fc,
                              gint       response_id,
                              EvWindow  *ev_window)
 {
                              gint       response_id,
                              EvWindow  *ev_window)
 {
-       gboolean success;
+       const gchar *uri_unc;
+       gint         fd;
+       gchar       *filename;
+       gchar       *tmp_filename;
+       GError      *error = NULL;
 
 
-       if (response_id == GTK_RESPONSE_OK) {
-               gint    fd;
-               gchar  *filename;
-               gchar  *tmp_filename;
-               GError *error = NULL;
+       if (response_id != GTK_RESPONSE_OK) {
+               gtk_widget_destroy (fc);
+               return;
+       }
+       
 
 
-               filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fc));
-               tmp_filename = g_strdup_printf ("%s.XXXXXX", filename);
+       filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fc));
+       tmp_filename = g_strdup_printf ("%s.XXXXXX", filename);
+       
+       fd = g_mkstemp (tmp_filename);
+       if (fd == -1) {
+               gchar *display_name;
+               gint   save_errno = errno;
                
                
-               fd = g_mkstemp (tmp_filename);
-               if (fd == -1) {
-                       gchar *display_name;
-                       gint   save_errno = errno;
-                       
-                       display_name = g_filename_display_name (tmp_filename);
-                       g_set_error (&error,
-                                    G_FILE_ERROR,
-                                    g_file_error_from_errno (save_errno),
-                                    _("Failed to create file “%s”: %s"),
-                                    display_name, g_strerror (save_errno));
-                       g_free (display_name);
-               } else {
-                       gchar *uri;
+               display_name = g_filename_display_name (tmp_filename);
+               g_set_error (&error,
+                            G_FILE_ERROR,
+                            g_file_error_from_errno (save_errno),
+                            _("Failed to create file “%s”: %s"),
+                            display_name, g_strerror (save_errno));
+               g_free (display_name);
+       } else {
+               gchar *uri;
+               
+               uri = g_filename_to_uri (tmp_filename, NULL, NULL);
+               
+               ev_document_doc_mutex_lock ();
+               ev_document_save (ev_window->priv->document, uri, &error);
+               ev_document_doc_mutex_unlock ();
+               
+               g_free (uri);
+               close (fd);
+       }
 
 
-                       uri = g_filename_to_uri (tmp_filename, NULL, NULL);
-                       
-                       ev_document_doc_mutex_lock ();
-                       success = ev_document_save (ev_window->priv->document,
-                                                   uri,
-                                                   &error);
-                       ev_document_doc_mutex_unlock ();
+       if (!error) {
+               uri_unc = g_object_get_data (G_OBJECT (ev_window->priv->document),
+                                            "uri-uncompressed");
+               if (uri_unc) {
+                       EvCompressionType ctype;
+                       gchar            *uri_comp;
+                       gchar            *uri;
+                       const gchar      *ext;
 
 
+                       ctype = EV_COMPRESSION_NONE;
+                       
+                       ext = g_strrstr (ev_window->priv->uri, ".gz");
+                       if (ext && g_ascii_strcasecmp (ext, ".gz") == 0)
+                               ctype = EV_COMPRESSION_GZIP;
+                       
+                       ext = g_strrstr (ev_window->priv->uri, ".bz2");
+                       if (ext && g_ascii_strcasecmp (ext, ".bz2") == 0)
+                               ctype = EV_COMPRESSION_BZIP2;
+                       
+                       uri = g_filename_to_uri (tmp_filename, NULL, NULL);
+                       uri_comp = ev_file_compress (uri, ctype, &error);
                        g_free (uri);
                        g_free (uri);
-                       close (fd);
-               }
+                       g_unlink (tmp_filename);
+                       g_free (tmp_filename);
 
 
-               if (!error) {
-                       if (g_rename (tmp_filename, filename) == -1) {
-                               g_unlink (tmp_filename);
+                       if (!uri_comp || error) {
+                               tmp_filename = NULL;
+                       } else {
+                               tmp_filename = g_filename_from_uri (uri_comp,
+                                                                   NULL, NULL);
                        }
                        }
-               } else {
-                       gchar *msg;
-                       gchar *uri;
-
-                       uri = g_filename_to_uri (filename, NULL, NULL);
-                       msg = g_strdup_printf (_("The file could not be saved as “%s”."), uri);
-                       ev_window_error_dialog (GTK_WINDOW (ev_window), msg, error);
-                       g_free (msg);
-                       g_free (uri);
-                       g_error_free (error);
+                       
+                       g_free (uri_comp);
                }
                }
+       }
+
+       if (tmp_filename && g_rename (tmp_filename, filename) == -1) {
+               g_unlink (tmp_filename);
+       }
+       
+       if (error) {
+               gchar *msg;
+               gchar *uri;
                
                
-               g_free (tmp_filename);
-               g_free (filename);
+               uri = g_filename_to_uri (filename, NULL, NULL);
+               msg = g_strdup_printf (_("The file could not be saved as “%s”."), uri);
+               ev_window_error_dialog (GTK_WINDOW (ev_window), msg, error);
+               g_free (msg);
+               g_free (uri);
+               g_error_free (error);
        }
        }
+       
+       g_free (tmp_filename);
+       g_free (filename);
 
        gtk_widget_destroy (fc);
 }
 
        gtk_widget_destroy (fc);
 }
@@ -1878,6 +1973,7 @@ ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window)
        GtkWidget *fc;
        gchar *base_name;
        gchar *file_name;
        GtkWidget *fc;
        gchar *base_name;
        gchar *file_name;
+       gchar *folder;
 
        fc = gtk_file_chooser_dialog_new (
                _("Save a Copy"),
 
        fc = gtk_file_chooser_dialog_new (
                _("Save a Copy"),
@@ -1892,10 +1988,13 @@ ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window)
        gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER (fc), TRUE);    
        file_name = gnome_vfs_format_uri_for_display (ev_window->priv->uri);
        base_name = g_path_get_basename (file_name);
        gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER (fc), TRUE);    
        file_name = gnome_vfs_format_uri_for_display (ev_window->priv->uri);
        base_name = g_path_get_basename (file_name);
+        folder = xdg_user_dir_lookup ("DOCUMENTS");
        gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc), base_name);
        gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc), base_name);
+        gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (fc), folder);
        g_free (file_name);
        g_free (base_name);
        g_free (file_name);
        g_free (base_name);
-
+        free (folder);
+        
        g_signal_connect (fc, "response",
                          G_CALLBACK (file_save_dialog_response_cb),
                          ev_window);
        g_signal_connect (fc, "response",
                          G_CALLBACK (file_save_dialog_response_cb),
                          ev_window);
@@ -3743,8 +3842,6 @@ find_bar_search_changed_cb (EggFindBar *find_bar,
        gboolean visible;
        const char *search_string;
 
        gboolean visible;
        const char *search_string;
 
-       g_return_if_fail (EV_IS_WINDOW (ev_window));
-
        /* Either the string or case sensitivity could have changed,
         * we connect this callback to both. We also connect it
         * to ::visible so when the find bar is hidden, we should
        /* Either the string or case sensitivity could have changed,
         * we connect this callback to both. We also connect it
         * to ::visible so when the find bar is hidden, we should
@@ -4016,7 +4113,7 @@ static const GtkActionEntry entries[] = {
        { "FileOpen", GTK_STOCK_OPEN, N_("_Open..."), "<control>O",
          N_("Open an existing document"),
          G_CALLBACK (ev_window_cmd_file_open) },
        { "FileOpen", GTK_STOCK_OPEN, N_("_Open..."), "<control>O",
          N_("Open an existing document"),
          G_CALLBACK (ev_window_cmd_file_open) },
-       { "FileOpenCopy", NULL, N_("Open a _Copy"), NULL,
+       { "FileOpenCopy", NULL, N_("Op_en a Copy"), NULL,
          N_("Open a copy of the current document in a new window"),
          G_CALLBACK (ev_window_cmd_file_open_copy) },
                { "FileSaveAs", GTK_STOCK_SAVE_AS, N_("_Save a Copy..."), "<control>S",
          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",
@@ -4444,10 +4541,45 @@ launch_action (EvWindow *window, EvLinkAction *action)
           allowing to launch executables is a good idea though. -- marco */
 }
 
           allowing to launch executables is a good idea though. -- marco */
 }
 
+static gboolean
+uri_is_valid (const gchar *uri)
+{
+       gchar *p = (gchar *) uri;
+       
+       if (!p || !g_ascii_isalpha (*p))
+               return FALSE;
+       
+       p++;
+       while (g_ascii_isalnum (*p))
+               p++;
+
+       return (g_ascii_strncasecmp (p, "://", strlen ("://")) == 0);
+}
+
 static void
 launch_external_uri (EvWindow *window, EvLinkAction *action)
 {
 static void
 launch_external_uri (EvWindow *window, EvLinkAction *action)
 {
-       gnome_vfs_url_show (ev_link_action_get_uri (action));
+       const gchar *uri = ev_link_action_get_uri (action);
+       
+       if (!uri_is_valid (uri)) {
+               GtkWidget *dialog;
+
+               dialog = gtk_message_dialog_new (GTK_WINDOW (window),
+                                                GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                GTK_MESSAGE_ERROR,
+                                                GTK_BUTTONS_CLOSE,
+                                                _("Unable to open external link"));
+               gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+                                                         _("Invalid URI: “%s”"), uri);
+               g_signal_connect (dialog, "response",
+                                 G_CALLBACK (gtk_widget_destroy),
+                                 NULL);
+               gtk_widget_show (dialog);
+
+               return;
+       }
+       
+       gnome_vfs_url_show (uri);
 }
 
 static void
 }
 
 static void
@@ -5080,6 +5212,13 @@ ev_window_init (EvWindow *ev_window)
        ev_window_setup_action_sensitivity (ev_window);
 }
 
        ev_window_setup_action_sensitivity (ev_window);
 }
 
+/**
+ * ev_window_new:
+ *
+ * Creates a #GtkWidget that represents the window.
+ *
+ * Returns: the #GtkWidget that represents the window.
+ */
 GtkWidget *
 ev_window_new (void)
 {
 GtkWidget *
 ev_window_new (void)
 {