]> www.fi.muni.cz Git - evince.git/commitdiff
Handle errors when opening remote files.
authorCarlos Garcia Campos <carlosgc@gnome.org>
Mon, 31 Mar 2008 18:42:17 +0000 (18:42 +0000)
committerCarlos Garcia Campos <carlosgc@src.gnome.org>
Mon, 31 Mar 2008 18:42:17 +0000 (18:42 +0000)
2008-03-31  Carlos Garcia Campos  <carlosgc@gnome.org>

* shell/ev-window.c: (window_open_file_copy_ready_cb),
(ev_window_load_file_remote), (ev_window_open_uri):

Handle errors when opening remote files.

svn path=/trunk/; revision=2985

ChangeLog
shell/ev-window.c

index 9c45ab507a23153aaf8e5cd2974bcc84b2924de9..1cb15f4b845d65be8bf6003e4c9274ca5dc5d4a3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-03-31  Carlos Garcia Campos  <carlosgc@gnome.org>
+
+       * shell/ev-window.c: (window_open_file_copy_ready_cb),
+       (ev_window_load_file_remote), (ev_window_open_uri):
+
+       Handle errors when opening remote files.
+       
 2008-03-31  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * shell/ev-page-action.c: (ev_page_action_grab_focus):
index 4cd205a0226933aa5113e60dbfdb08422285ab59..9ca965b223833d14feea648897a4a0c09660fdf2 100644 (file)
@@ -1429,11 +1429,64 @@ 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);
+       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) {
+               /* TODO: try to mount */
+       }
+
+       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
+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
 ev_window_open_uri (EvWindow       *ev_window,
                    const char     *uri,
@@ -1444,7 +1497,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 +1530,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