]> www.fi.muni.cz Git - evince.git/blobdiff - shell/ev-window.c
Fix some build warnings under GCC 4.3.0. (#537535).
[evince.git] / shell / ev-window.c
index 9ca965b223833d14feea648897a4a0c09660fdf2..f6a525426730edf3bc855305525d18c2302511a4 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,6 +1424,39 @@ 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,
@@ -1441,19 +1474,21 @@ window_open_file_copy_ready_cb (GFile        *source,
 
        if (error->domain == G_IO_ERROR &&
            error->code == G_IO_ERROR_NOT_MOUNTED) {
-               /* TODO: try to mount */
+               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);
        }
-
-       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;
        
        g_error_free (error);
-       g_object_unref (source);
 }
 
 static void
@@ -1906,7 +1941,7 @@ window_save_file_copy_ready_cb (GFile        *src,
                                         _("The file could not be saved as ā€œ%sā€."),
                                         name);
        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
-                                                 error->message);
+                                                 "%s", error->message);
        g_signal_connect (dialog, "response",
                          G_CALLBACK (gtk_widget_destroy),
                          NULL);
@@ -2121,7 +2156,7 @@ ev_window_print_finished (GtkPrintJob *print_job,
                                                 GTK_BUTTONS_OK,
                                                 _("Failed to print document"));
                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
-                                                         error->message);
+                                                         "%s", error->message);
 
                gtk_dialog_run (GTK_DIALOG (dialog));
                gtk_widget_destroy (dialog);
@@ -2193,7 +2228,7 @@ ev_window_print_send (EvWindow    *window,
                GtkPrintJob *job;
                GError      *error = NULL;
        
-               job = gtk_print_job_new ("evince-print",
+               job = gtk_print_job_new (gtk_window_get_title (GTK_WINDOW (window)),
                                         window->priv->printer,
                                         settings,
                                         window->priv->print_page_setup);
@@ -2208,7 +2243,7 @@ ev_window_print_send (EvWindow    *window,
                                            window, NULL);
                } else {
                        ev_window_clear_print_job (window);
-                       g_warning (error->message);
+                       g_warning ("%s", error->message);
                        g_error_free (error);
                }
        }
@@ -2221,7 +2256,7 @@ ev_window_print_job_cb (EvJobPrint *job,
                        EvWindow   *window)
 {
        if (job->error) {
-               g_warning (job->error->message);
+               g_warning ("%s", job->error->message);
                ev_window_clear_print_job (window);
                return;
        }
@@ -2510,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,
@@ -2523,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,
@@ -2534,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);
@@ -2547,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);
@@ -2676,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,
@@ -2693,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
@@ -2706,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))
@@ -2715,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),
@@ -2730,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);
@@ -2741,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);
        }
 }
 
@@ -2833,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",
@@ -2862,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),
@@ -2874,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,
@@ -2895,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);
        }
 }
 
@@ -3191,7 +3250,7 @@ ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
        screen = gtk_widget_get_screen (GTK_WIDGET (ev_window));
        gdk_spawn_command_line_on_screen (screen, command, &error);
        if (error != NULL) {
-               g_warning (error->message);
+               g_warning ("%s", error->message);
                g_error_free (error);
        }
        g_free (command);
@@ -3200,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);
 }
 
@@ -3248,7 +3306,7 @@ ev_window_preview_print_finished (GtkPrintJob *print_job,
                                                 GTK_BUTTONS_OK,
                                                 _("Failed to print document"));
                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
-                                                         error->message);
+                                                         "%s", error->message);
 
                gtk_dialog_run (GTK_DIALOG (dialog));
                gtk_widget_destroy (dialog);
@@ -3272,7 +3330,7 @@ ev_window_do_preview_print (EvWindow *window)
 
        page_setup = gtk_page_setup_new ();
 
-       job = gtk_print_job_new ("evince-print",
+       job = gtk_print_job_new (gtk_window_get_title (GTK_WINDOW (window)),
                                 priv->printer,
                                 priv->print_settings,
                                 page_setup);
@@ -3292,7 +3350,7 @@ ev_window_do_preview_print (EvWindow *window)
                                    (GtkPrintJobCompleteFunc)ev_window_preview_print_finished,
                                    window, NULL);
        } else {
-               g_warning (error->message);
+               g_warning ("%s", error->message);
                g_error_free (error);
        }
 
@@ -3317,7 +3375,7 @@ ev_window_cmd_preview_print (GtkAction *action, EvWindow *window)
                                                                           &error);
                        
                        if (error) {
-                               g_warning (error->message);
+                               g_warning ("%s", error->message);
                                g_error_free (error);
                                print_settings = NULL;
                        }
@@ -3358,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);
@@ -4135,7 +4193,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) },
-       { "FileOpenCopy", NULL, N_("Op_en a Copy"), NULL,
+       { "FileOpenCopy", NULL, N_("Op_en a Copy"), "<control>N",
          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",
@@ -4260,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 */
@@ -4737,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);
 }