]> www.fi.muni.cz Git - evince.git/blobdiff - shell/ev-window.c
Updated Slovenian translation
[evince.git] / shell / ev-window.c
index dc96285d79429cb1cf5a42b3cf9ac1cadec61279..dd05d662d2b88ab2f871f6d8cd9c48594e8f028f 100644 (file)
@@ -66,6 +66,7 @@
 #include "ev-history.h"
 #include "ev-image.h"
 #include "ev-message-area.h"
+#include "ev-mount-operation.h"
 
 #include <gtk/gtkprintunixdialog.h>
 
@@ -231,11 +232,13 @@ static void     ev_window_zoom_changed_cb                 (EvView           *view,
 static void     ev_window_add_recent                    (EvWindow         *window,
                                                         const char       *filename);
 static void     ev_window_run_fullscreen                (EvWindow         *window);
-static void     ev_window_stop_fullscreen               (EvWindow         *window);
+static void     ev_window_stop_fullscreen               (EvWindow         *window,
+                                                        gboolean          unfullscreen_window);
 static void     ev_window_cmd_view_fullscreen           (GtkAction        *action,
                                                         EvWindow         *window);
 static void     ev_window_run_presentation              (EvWindow         *window);
-static void     ev_window_stop_presentation             (EvWindow         *window);
+static void     ev_window_stop_presentation             (EvWindow         *window,
+                                                        gboolean          unfullscreen_window);
 static void     ev_window_cmd_view_presentation         (GtkAction        *action,
                                                         EvWindow         *window);
 static void     ev_window_run_preview                   (EvWindow         *window);
@@ -266,6 +269,8 @@ static void     find_bar_search_changed_cb              (EggFindBar       *find_
                                                         GParamSpec       *param,
                                                         EvWindow         *ev_window);
 static void     ev_window_do_preview_print              (EvWindow         *window);
+static void     ev_window_load_file_remote              (EvWindow         *ev_window,
+                                                        GFile            *source_file);
 
 G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW)
 
@@ -1070,8 +1075,6 @@ ev_window_set_icon_from_thumbnail (EvJobThumbnail *job,
 static void
 ev_window_refresh_window_thumbnail (EvWindow *ev_window, int rotation)
 {
-       
-       EvRenderContext *rc;
        gint page_width, page_height;
        gdouble scale;
        EvDocument *document = ev_window->priv->document;
@@ -1087,14 +1090,11 @@ ev_window_refresh_window_thumbnail (EvWindow *ev_window, int rotation)
                                &page_width, &page_height);
        scale = (gdouble)128 / (gdouble)page_width;
        
-       rc = ev_render_context_new (rotation, 0, scale);
-       
-       ev_window->priv->thumbnail_job = ev_job_thumbnail_new (document, rc);
+       ev_window->priv->thumbnail_job = ev_job_thumbnail_new (document, 0, rotation, scale);
        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);
 }
 
 static gboolean
@@ -1424,14 +1424,102 @@ ev_window_close_dialogs (EvWindow *ev_window)
        ev_window->priv->properties = NULL;
 }
 
+static void
+ev_window_load_remote_failed (EvWindow *ev_window,
+                             GError   *error)
+{
+       ev_view_set_loading (EV_VIEW (ev_window->priv->view), FALSE);
+       ev_window->priv->in_reload = FALSE;
+       ev_window_error_message (GTK_WINDOW (ev_window),
+                                _("Unable to open document"),
+                                error);
+       g_free (ev_window->priv->local_uri);
+       ev_window->priv->local_uri = NULL;
+}
+
+static void
+mount_volume_ready_cb (GFile        *source,
+                      GAsyncResult *async_result,
+                      EvWindow     *ev_window)
+{
+       GError *error = NULL;
+
+       g_file_mount_enclosing_volume_finish (source, async_result, &error);
+
+       if (error) {
+               ev_window_load_remote_failed (ev_window, error);
+               g_object_unref (source);
+               g_error_free (error);
+       } else {
+               /* Volume successfully mounted,
+                  try opening the file again */
+               ev_window_load_file_remote (ev_window, source);
+       }
+}
+
 static void
 window_open_file_copy_ready_cb (GFile        *source,
                                GAsyncResult *async_result,
                                EvWindow     *ev_window)
 {
-       g_file_copy_finish (source, async_result, NULL);
-       ev_job_queue_add_job (ev_window->priv->load_job, EV_JOB_PRIORITY_HIGH);
-       g_object_unref (source);
+       GError *error = NULL;
+       
+       g_file_copy_finish (source, async_result, &error);
+       if (!error) {
+               ev_job_queue_add_job (ev_window->priv->load_job, EV_JOB_PRIORITY_HIGH);
+               g_object_unref (source);
+               
+               return;
+       }
+
+       if (error->domain == G_IO_ERROR &&
+           error->code == G_IO_ERROR_NOT_MOUNTED) {
+               GMountOperation *operation;
+
+               operation = ev_mount_operation_new (GTK_WINDOW (ev_window));
+               g_file_mount_enclosing_volume (source,
+                                              G_MOUNT_MOUNT_NONE,
+                                              operation, NULL,
+                                              (GAsyncReadyCallback)mount_volume_ready_cb,
+                                              ev_window);
+               g_object_unref (operation);
+       } else {
+               ev_window_load_remote_failed (ev_window, error);
+               g_object_unref (source);
+       }
+       
+       g_error_free (error);
+}
+
+static void
+ev_window_load_file_remote (EvWindow  *ev_window,
+                           GFile     *source_file)
+{
+       GFile *target_file;
+       
+       if (!ev_window->priv->local_uri) {
+               gchar *tmp_name;
+               gchar *base_name;
+
+               /* We'd like to keep extension of source uri since
+                * it helps to resolve some mime types, say cbz */
+               tmp_name = ev_tmp_filename (NULL);
+               base_name = g_file_get_basename (source_file);
+               ev_window->priv->local_uri = g_strconcat ("file:", tmp_name, "-",
+                                                         base_name, NULL);
+               ev_job_load_set_uri (EV_JOB_LOAD (ev_window->priv->load_job),
+                                    ev_window->priv->local_uri);
+               g_free (base_name);
+               g_free (tmp_name);
+       }
+       
+       target_file = g_file_new_for_uri (ev_window->priv->local_uri);
+       g_file_copy_async (source_file, target_file,
+                          0, G_PRIORITY_DEFAULT, NULL,
+                          NULL, NULL, /* no progress callback */
+                          (GAsyncReadyCallback) window_open_file_copy_ready_cb,
+                          ev_window);
+       g_object_unref (target_file);
 }
 
 void
@@ -1444,7 +1532,6 @@ ev_window_open_uri (EvWindow       *ev_window,
                    const gchar    *print_settings)
 {
        GFile *source_file;
-       GFile *target_file;
 
        if (ev_window->priv->uri &&
            g_ascii_strcasecmp (ev_window->priv->uri, uri) == 0) {
@@ -1478,33 +1565,11 @@ ev_window_open_uri (EvWindow       *ev_window,
 
        source_file = g_file_new_for_uri (uri);
        if (!g_file_is_native (source_file) && !ev_window->priv->local_uri) {
-               char *tmp_name;
-               char *base_name;
-
-               /* We'd like to keep extension of source uri since
-                * it helps to resolve some mime types, say cbz */
-
-               tmp_name = ev_tmp_filename (NULL);
-               base_name = g_file_get_basename (source_file);
-               ev_window->priv->local_uri = g_strconcat ("file:", tmp_name, "-", base_name, NULL);
-               ev_job_load_set_uri (EV_JOB_LOAD (ev_window->priv->load_job),
-                                    ev_window->priv->local_uri);
-               g_free (base_name);
-               g_free (tmp_name);
-               
-               target_file = g_file_new_for_uri (ev_window->priv->local_uri);
-
-               g_file_copy_async (source_file, target_file,
-                                  0, G_PRIORITY_DEFAULT, NULL,
-                                  NULL, NULL, /* no progress callback */
-                                  (GAsyncReadyCallback) window_open_file_copy_ready_cb,
-                                  ev_window);
-               g_object_unref (target_file);
-               return;
+               ev_window_load_file_remote (ev_window, source_file);
+       } else {
+               g_object_unref (source_file);
+               ev_job_queue_add_job (ev_window->priv->load_job, EV_JOB_PRIORITY_HIGH);
        }
-
-       g_object_unref (source_file);
-       ev_job_queue_add_job (ev_window->priv->load_job, EV_JOB_PRIORITY_HIGH);
 }
 
 static void
@@ -2220,7 +2285,7 @@ ev_window_print_dialog_response_cb (GtkDialog *dialog,
        GtkPrintPages  print_pages;
        const gchar   *file_format;
        
-       if (response != GTK_RESPONSE_ACCEPT &&
+       if (response != GTK_RESPONSE_OK &&
            response != GTK_RESPONSE_APPLY) {
                gtk_widget_destroy (GTK_WIDGET (dialog));
                window->priv->print_dialog = NULL;
@@ -2480,7 +2545,7 @@ ev_window_cmd_continuous (GtkAction *action, EvWindow *ev_window)
 {
        gboolean continuous;
 
-       ev_window_stop_presentation (ev_window);
+       ev_window_stop_presentation (ev_window, TRUE);
        continuous = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
        g_object_set (G_OBJECT (ev_window->priv->view),
                      "continuous", continuous,
@@ -2493,7 +2558,7 @@ ev_window_cmd_dual (GtkAction *action, EvWindow *ev_window)
 {
        gboolean dual_page;
 
-       ev_window_stop_presentation (ev_window);
+       ev_window_stop_presentation (ev_window, TRUE);
        dual_page = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
        g_object_set (G_OBJECT (ev_window->priv->view),
                      "dual-page", dual_page,
@@ -2504,7 +2569,7 @@ ev_window_cmd_dual (GtkAction *action, EvWindow *ev_window)
 static void
 ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window)
 {
-       ev_window_stop_presentation (ev_window);
+       ev_window_stop_presentation (ev_window, TRUE);
 
        if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
                ev_view_set_sizing_mode (EV_VIEW (ev_window->priv->view), EV_SIZING_BEST_FIT);
@@ -2517,7 +2582,7 @@ ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window)
 static void
 ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window)
 {
-       ev_window_stop_presentation (ev_window);
+       ev_window_stop_presentation (ev_window, TRUE);
 
        if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
                ev_view_set_sizing_mode (EV_VIEW (ev_window->priv->view), EV_SIZING_FIT_WIDTH);
@@ -2646,6 +2711,12 @@ fullscreen_toolbar_remove_shadow (GtkWidget *toolbar)
 static void
 ev_window_run_fullscreen (EvWindow *window)
 {
+       EvView  *view = EV_VIEW (window->priv->view);
+       gboolean fullscreen_window = TRUE;
+
+       if (ev_view_get_fullscreen (view))
+               return;
+       
        if (!window->priv->fullscreen_toolbar) {
                window->priv->fullscreen_toolbar =
                        gtk_ui_manager_get_widget (window->priv->ui_manager,
@@ -2663,11 +2734,16 @@ ev_window_run_fullscreen (EvWindow *window)
                                       window->priv->fullscreen_toolbar, 1);
        }
 
+       if (ev_view_get_presentation (view)) {
+               ev_window_stop_presentation (window, FALSE);
+               fullscreen_window = FALSE;
+       }
+
        g_object_set (G_OBJECT (window->priv->scrolled_window),
                      "shadow-type", GTK_SHADOW_NONE,
                      NULL);
 
-       ev_view_set_fullscreen (EV_VIEW (window->priv->view), TRUE);
+       ev_view_set_fullscreen (view, TRUE);
        ev_window_update_fullscreen_action (window);
 
        /* If the user doesn't have the main toolbar he/she won't probably want
@@ -2676,8 +2752,9 @@ ev_window_run_fullscreen (EvWindow *window)
        update_chrome_flag (window, EV_CHROME_FULLSCREEN_TOOLBAR,
                            (window->priv->chrome & EV_CHROME_TOOLBAR) != 0);
        update_chrome_visibility (window);
-       
-       gtk_window_fullscreen (GTK_WINDOW (window));
+
+       if (fullscreen_window)
+               gtk_window_fullscreen (GTK_WINDOW (window));
        gtk_widget_grab_focus (window->priv->view);
 
        if (!ev_window_is_empty (window))
@@ -2685,11 +2762,12 @@ ev_window_run_fullscreen (EvWindow *window)
 }
 
 static void
-ev_window_stop_fullscreen (EvWindow *window)
+ev_window_stop_fullscreen (EvWindow *window,
+                          gboolean  unfullscreen_window)
 {
        EvView *view = EV_VIEW (window->priv->view);
 
-       if (!ev_view_get_fullscreen (EV_VIEW (view)))
+       if (!ev_view_get_fullscreen (view))
                return;
 
        g_object_set (G_OBJECT (window->priv->scrolled_window),
@@ -2700,7 +2778,8 @@ ev_window_stop_fullscreen (EvWindow *window)
        ev_window_update_fullscreen_action (window);
        update_chrome_flag (window, EV_CHROME_FULLSCREEN_TOOLBAR, FALSE);
        update_chrome_visibility (window);
-       gtk_window_unfullscreen (GTK_WINDOW (window));
+       if (unfullscreen_window)
+               gtk_window_unfullscreen (GTK_WINDOW (window));
 
        if (!ev_window_is_empty (window))
                ev_metadata_manager_set_boolean (window->priv->uri, "fullscreen", FALSE);
@@ -2711,14 +2790,11 @@ ev_window_cmd_view_fullscreen (GtkAction *action, EvWindow *window)
 {
        gboolean fullscreen;
 
-        g_return_if_fail (EV_IS_WINDOW (window));
-       ev_window_stop_presentation (window);
-
        fullscreen = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
        if (fullscreen) {
                ev_window_run_fullscreen (window);
        } else {
-               ev_window_stop_fullscreen (window);
+               ev_window_stop_fullscreen (window, TRUE);
        }
 }
 
@@ -2803,17 +2879,29 @@ ev_window_update_presentation_action (EvWindow *window)
 static void
 ev_window_run_presentation (EvWindow *window)
 {
+       EvView  *view = EV_VIEW (window->priv->view);
+       gboolean fullscreen_window = TRUE;
+
+       if (ev_view_get_presentation (view))
+               return;
+
+       if (ev_view_get_fullscreen (view)) {
+               ev_window_stop_fullscreen (window, FALSE);
+               fullscreen_window = FALSE;
+       }
+       
        g_object_set (G_OBJECT (window->priv->scrolled_window),
                      "shadow-type", GTK_SHADOW_NONE,
                      NULL);
 
-       ev_view_set_presentation (EV_VIEW (window->priv->view), TRUE);
+       ev_view_set_presentation (view, TRUE);
        ev_window_update_presentation_action (window);
 
        update_chrome_visibility (window);
        
        gtk_widget_grab_focus (window->priv->view);
-       gtk_window_fullscreen (GTK_WINDOW (window));
+       if (fullscreen_window)
+               gtk_window_fullscreen (GTK_WINDOW (window));
 
        g_signal_connect (window->priv->view,
                          "motion-notify-event",
@@ -2832,9 +2920,12 @@ ev_window_run_presentation (EvWindow *window)
 }
 
 static void
-ev_window_stop_presentation (EvWindow *window)
+ev_window_stop_presentation (EvWindow *window,
+                            gboolean  unfullscreen_window)
 {
-       if (!ev_view_get_presentation (EV_VIEW (window->priv->view)))
+       EvView *view = EV_VIEW (window->priv->view);
+       
+       if (!ev_view_get_presentation (view))
                return;
 
        g_object_set (G_OBJECT (window->priv->scrolled_window),
@@ -2844,7 +2935,8 @@ ev_window_stop_presentation (EvWindow *window)
        ev_view_set_presentation (EV_VIEW (window->priv->view), FALSE);
        ev_window_update_presentation_action (window);
        update_chrome_visibility (window);
-       gtk_window_unfullscreen (GTK_WINDOW (window));
+       if (unfullscreen_window)
+               gtk_window_unfullscreen (GTK_WINDOW (window));
 
        g_signal_handlers_disconnect_by_func (window->priv->view,
                                              (gpointer) presentation_motion_notify_cb,
@@ -2865,14 +2957,11 @@ ev_window_cmd_view_presentation (GtkAction *action, EvWindow *window)
 {
        gboolean presentation;
 
-       g_return_if_fail (EV_IS_WINDOW (window));
-       ev_window_stop_fullscreen (window);
-
        presentation = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
        if (presentation) {
                ev_window_run_presentation (window);
        } else {
-               ev_window_stop_presentation (window);
+               ev_window_stop_presentation (window, TRUE);
        }
 }
 
@@ -3170,13 +3259,12 @@ ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
 static void
 ev_window_cmd_leave_fullscreen (GtkAction *action, EvWindow *window)
 {
-       ev_window_stop_fullscreen (window);
+       ev_window_stop_fullscreen (window, TRUE);
 }
 
 static void
 ev_window_cmd_start_presentation (GtkAction *action, EvWindow *window)
 {
-       ev_window_stop_fullscreen (window);
        ev_window_run_presentation (window);
 }
 
@@ -3328,9 +3416,9 @@ ev_window_cmd_escape (GtkAction *action, EvWindow *window)
                              NULL);
 
                if (fullscreen) {
-                       ev_window_stop_fullscreen (window);
+                       ev_window_stop_fullscreen (window, TRUE);
                } else if (presentation) {
-                       ev_window_stop_presentation (window);
+                       ev_window_stop_presentation (window, TRUE);
                        gtk_widget_grab_focus (window->priv->view);
                } else {
                        gtk_widget_grab_focus (window->priv->view);
@@ -3810,6 +3898,7 @@ static void
 find_bar_close_cb (EggFindBar *find_bar,
                   EvWindow   *ev_window)
 {
+       ev_view_find_cancel (EV_VIEW (ev_window->priv->view));
        update_chrome_flag (ev_window, EV_CHROME_FINDBAR, FALSE);
        update_chrome_visibility (ev_window);
 }
@@ -4229,6 +4318,8 @@ static const GtkActionEntry entries[] = {
           G_CALLBACK (ev_window_cmd_view_zoom_in) },
         { "CtrlKpMinus", GTK_STOCK_ZOOM_OUT, NULL, "<control>KP_Subtract", NULL,
           G_CALLBACK (ev_window_cmd_view_zoom_out) },
+       { "CtrlInsert", GTK_STOCK_COPY, NULL, "<control>Insert", NULL,
+         G_CALLBACK (ev_window_cmd_edit_copy) },
 };
 
 /* Toggle items */
@@ -4576,29 +4667,11 @@ static void
 launch_external_uri (EvWindow *window, EvLinkAction *action)
 {
        const gchar *uri = ev_link_action_get_uri (action);
-       const char *content_type;
-       GFile *file;
-       GFileInfo *file_info;
-       GAppInfo *app;
-       GList *file_list = NULL;
        GError *error = NULL;
+       gboolean ret;
        
-       file = g_file_new_for_uri (uri);
-       file_info = g_file_query_info (file,
-                                      G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
-                                      0, NULL, NULL);
-       if (file_info == NULL) {
-               g_object_unref (file);
-               return;
-       }
-       
-       content_type = g_file_info_get_content_type (file_info);
-       app = g_app_info_get_default_for_type (content_type, TRUE);
-       g_object_unref (file_info);
-       
-       file_list = g_list_append (file_list, file);
-       
-       if (!g_app_info_launch (app, file_list, NULL, &error)) {
+       ret = g_app_info_launch_default_for_uri (uri, NULL, &error);
+       if (ret == FALSE) {
                GtkWidget *dialog;
        
                dialog = gtk_message_dialog_new (GTK_WINDOW (window),
@@ -4612,11 +4685,8 @@ launch_external_uri (EvWindow *window, EvLinkAction *action)
                                  G_CALLBACK (gtk_widget_destroy),
                                  NULL);
                gtk_widget_show (dialog);
+               g_error_free(error);
        }
-
-       g_object_unref (app);
-       g_object_unref (file);
-       g_list_free (file_list);
 }
 
 static void
@@ -4727,19 +4797,14 @@ 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)
 {
-       GtkClipboard *clipboard;
        EvLinkAction *ev_action;
-       const gchar *uri;
 
        ev_action = ev_link_get_action (window->priv->link);
        if (!ev_action)
                return;
 
-       uri = ev_link_action_get_uri (ev_action);
-
-       clipboard = gtk_widget_get_clipboard (GTK_WIDGET (window),
-                                             GDK_SELECTION_CLIPBOARD);
-       gtk_clipboard_set_text (clipboard, uri, -1);
+       ev_view_copy_link_address (EV_VIEW (window->priv->view),
+                                  ev_action);
 }
 
 
@@ -4753,7 +4818,6 @@ image_save_dialog_response_cb (GtkWidget *fc,
        GError          *error = NULL;
        GdkPixbuf       *pixbuf;
        gchar           *uri;
-       gchar           *uri_extension;
        gchar          **extensions;
        gchar           *filename;
        gchar           *file_format;
@@ -4784,27 +4848,31 @@ image_save_dialog_response_cb (GtkWidget *fc,
        }
 
        extensions = gdk_pixbuf_format_get_extensions (format);
-       uri_extension = g_strconcat (uri, ".", extensions[0], NULL);
+       if (g_str_has_suffix(uri, extensions[0])) {
+               gchar *uri_extension;
+               
+               uri_extension = g_strconcat (uri, ".", extensions[0], NULL);
+               target_file = g_file_new_for_uri (uri_extension);
+               g_free (uri_extension);
+       } else {
+               target_file = g_file_new_for_uri (uri);
+       }
        g_strfreev(extensions);
-       file_format = gdk_pixbuf_format_get_name (format);
+       g_free (uri);
        
-       target_file = g_file_new_for_uri (uri_extension);
        is_native = g_file_is_native (target_file);
-       
        if (is_native) {
                filename = g_file_get_path (target_file);
        } else {
                filename = ev_tmp_filename ("saveimage");
        }
-       
-       g_free (uri);
-       g_free (uri_extension);
 
        ev_document_doc_mutex_lock ();
        pixbuf = ev_document_images_get_image (EV_DOCUMENT_IMAGES (ev_window->priv->document),
                                               ev_window->priv->image);
        ev_document_doc_mutex_unlock ();
-       
+
+       file_format = gdk_pixbuf_format_get_name (format);
        gdk_pixbuf_save (pixbuf, filename, file_format, &error, NULL);
        g_free (file_format);
        g_object_unref (pixbuf);