From: Nickolay V. Shmyrev Date: Fri, 10 Jun 2005 14:49:25 +0000 (+0000) Subject: Transfer remote documents to tmp directory to display them later X-Git-Tag: EVINCE_0_3_3~262 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=270571fe9d9ab085696c5b2af5a484dfc272b7a0;p=evince.git Transfer remote documents to tmp directory to display them later --- diff --git a/ChangeLog b/ChangeLog index 90f053bb..0e8ee660 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2005-06-10 Nickolay V. Shmyrev + + * shell/ev-application.c: (ev_application_open): + * shell/ev-document-types.c: (ev_document_type_from_from_mime), + (ev_document_type_get_type), (ev_document_type_lookup): + * shell/ev-document-types.h: + * shell/ev-job-xfer.c: (ev_job_xfer_dispose), (ev_job_xfer_run): + * shell/ev-job-xfer.h: + * shell/ev-window.c: (ev_window_clear_local_uri), + (ev_window_load_job_cb), (ev_window_xfer_job_cb), + (ev_window_open_uri), (ev_window_add_recent), (ev_window_dispose): + * thumbnailer/evince-thumbnailer.c: (evince_thumbnail_pngenc_get): + + Transfer remote documents to tmp directory to display them later. + 2005-06-10 Marco Pesenti Gritti * backend/ev-document-info.h: diff --git a/shell/ev-application.c b/shell/ev-application.c index d10914b3..3b162ce0 100644 --- a/shell/ev-application.c +++ b/shell/ev-application.c @@ -195,11 +195,12 @@ ev_application_open (EvApplication *application, GError *err) all_filter = gtk_file_filter_new (); gtk_file_filter_set_name (all_filter, _("All Files")); gtk_file_filter_add_pattern (all_filter, "*"); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), all_filter); - gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (chooser), documents_filter); gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (chooser), TRUE); + gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser), FALSE); if (gtk_dialog_run (GTK_DIALOG (chooser)) == GTK_RESPONSE_OK) { GSList *uris; diff --git a/shell/ev-document-types.c b/shell/ev-document-types.c index 6ce546b9..71332952 100644 --- a/shell/ev-document-types.c +++ b/shell/ev-document-types.c @@ -37,6 +37,7 @@ #endif #include +#include #include #include #include @@ -111,32 +112,13 @@ mime_type_supported_by_gdk_pixbuf (const gchar *mime_type) return retval; } -static char * -get_slow_mime_type (const char *uri) -{ - GnomeVFSFileInfo *info; - char *mime_type; - GnomeVFSResult result; - - info = gnome_vfs_file_info_new (); - result = gnome_vfs_get_file_info (uri, info, - GNOME_VFS_FILE_INFO_GET_MIME_TYPE | - GNOME_VFS_FILE_INFO_FORCE_SLOW_MIME_TYPE | - GNOME_VFS_FILE_INFO_FOLLOW_LINKS); - if (info->mime_type == NULL || result != GNOME_VFS_OK) { - mime_type = NULL; - } else { - mime_type = g_strdup (info->mime_type); - } - gnome_vfs_file_info_unref (info); - - return mime_type; -} static GType -get_document_type_from_mime (const char *mime_type) +ev_document_type_from_from_mime (const char *mime_type) { int i; + + g_return_val_if_fail (mime_type, G_TYPE_INVALID); for (i = 0; i < G_N_ELEMENTS (document_types); i++) { if (strcmp (mime_type, document_types[i].mime_type) == 0) { @@ -152,32 +134,82 @@ get_document_type_from_mime (const char *mime_type) return G_TYPE_INVALID; } -GType -ev_document_type_lookup (const char *uri, char **mime_type) +/** + * ev_document_type_get_type: + * @uri: String with uri + * @slow: Do we need to check slow gnome-vfs mime type + * @mime_type: If we've found handled type, the mime_type string is returned here. + * @error: Information about error occured + * + * Return value: G_TYPE_INVALID on error, G_TYPE_NONE when we are not sure about + * mime type, and type of EvDocument implementation when we've found document. + **/ +static GType +ev_document_type_get_type (const char *uri, gboolean slow, gchar **mime_type, GError **error) { - GType type = G_TYPE_INVALID; - char *mime; - - g_return_val_if_fail (uri, G_TYPE_INVALID); + GnomeVFSFileInfo *info; + GnomeVFSResult result; - mime = gnome_vfs_get_mime_type (uri); - if (mime) { - type = get_document_type_from_mime (mime); + GType type = G_TYPE_INVALID; + + info = gnome_vfs_file_info_new (); + result = gnome_vfs_get_file_info (uri, info, + GNOME_VFS_FILE_INFO_GET_MIME_TYPE | + GNOME_VFS_FILE_INFO_FOLLOW_LINKS | + (slow ? GNOME_VFS_FILE_INFO_FORCE_SLOW_MIME_TYPE : 0)); + if (result != GNOME_VFS_OK) { + g_set_error (error, + EV_DOCUMENT_ERROR, + 0, + gnome_vfs_result_to_string (result)); + gnome_vfs_file_info_unref (info); + return G_TYPE_INVALID; + } + + if (info->mime_type == NULL) { + g_set_error (error, + EV_DOCUMENT_ERROR, + 0, + _("Unknown MIME Type")); + gnome_vfs_file_info_unref (info); + return slow ? G_TYPE_INVALID : G_TYPE_NONE; } - + + type = ev_document_type_from_from_mime (info->mime_type); + if (type == G_TYPE_INVALID) { - g_free (mime); - mime = get_slow_mime_type (uri); - if (mime) { - type = get_document_type_from_mime (mime); - } + g_set_error (error, + EV_DOCUMENT_ERROR, + 0, + _("Unhandled MIME type: '%s'"), info->mime_type); + gnome_vfs_file_info_unref (info); + return slow ? G_TYPE_INVALID : G_TYPE_NONE; + } + + if (mime_type != NULL) { + *mime_type = g_strdup (info->mime_type); } + gnome_vfs_file_info_unref (info); + + return type; +} - if (mime_type) { - *mime_type = mime; - } else { - g_free (mime); +GType +ev_document_type_lookup (const char *uri, gchar **mime_type, GError **error) +{ + GType type = G_TYPE_INVALID; + + type = ev_document_type_get_type (uri, FALSE, mime_type, error); + + if (type != G_TYPE_NONE) + return type; + + if (error) { + g_error_free (*error); + *error = NULL; } + type = ev_document_type_get_type (uri, TRUE, mime_type, error); + return type; } diff --git a/shell/ev-document-types.h b/shell/ev-document-types.h index e3e8fa03..86eb100e 100644 --- a/shell/ev-document-types.h +++ b/shell/ev-document-types.h @@ -26,7 +26,8 @@ G_BEGIN_DECLS GType ev_document_type_lookup (const char *uri, - char **mime_type); + gchar **mime_type, + GError **error); G_END_DECLS diff --git a/shell/ev-job-xfer.c b/shell/ev-job-xfer.c index b75e9d1c..49f674e5 100644 --- a/shell/ev-job-xfer.c +++ b/shell/ev-job-xfer.c @@ -24,6 +24,7 @@ #include "ev-job-xfer.h" #include "ev-document-types.h" +#include "ev-file-helpers.h" #include #include @@ -31,6 +32,7 @@ #include #include #include +#include static void ev_job_xfer_init (EvJobXfer *job); static void ev_job_xfer_class_init (EvJobXferClass *class); @@ -49,6 +51,11 @@ ev_job_xfer_dispose (GObject *object) job->uri = NULL; } + if (job->local_uri) { + g_free (job->local_uri); + job->local_uri = NULL; + } + if (job->error) { g_error_free (job->error); job->error = NULL; @@ -83,9 +90,10 @@ ev_job_xfer_new (const gchar *uri) void ev_job_xfer_run (EvJobXfer *job) { - GnomeVFSURI *vfs_uri; - char *mime_type; GType document_type; + GError *error = NULL; + GnomeVFSURI *source_uri; + GnomeVFSURI *target_uri; g_return_if_fail (EV_IS_JOB_XFER (job)); @@ -94,34 +102,35 @@ ev_job_xfer_run (EvJobXfer *job) job->error = NULL; } - vfs_uri = gnome_vfs_uri_new (job->uri); - if (vfs_uri) { - if (!gnome_vfs_uri_exists (vfs_uri)) { - g_set_error (&job->error, - EV_DOCUMENT_ERROR, - 0, - _("The file %s does not exist."), - job->uri); - - EV_JOB (job)->finished = TRUE; - return; - } - } - gnome_vfs_uri_unref (vfs_uri); - - document_type = ev_document_type_lookup (job->uri, &mime_type); + document_type = ev_document_type_lookup (job->uri, NULL, &error); if (document_type != G_TYPE_INVALID) { EV_JOB (job)->document = g_object_new (document_type, NULL); } else { - g_set_error (&job->error, - EV_DOCUMENT_ERROR, - 0, - _("Unhandled MIME type: '%s'"), - mime_type ? mime_type : ""); + job->error = error; EV_JOB (job)->finished = TRUE; return; } + + source_uri = gnome_vfs_uri_new (job->uri); + if (!gnome_vfs_uri_is_local (source_uri)) { + char *tmp_name; + + tmp_name = ev_tmp_filename (); + job->local_uri = g_strconcat ("file:", tmp_name, NULL); + g_free (tmp_name); + + target_uri = gnome_vfs_uri_new (job->local_uri); + + gnome_vfs_xfer_uri (source_uri, target_uri, + GNOME_VFS_XFER_DEFAULT | GNOME_VFS_XFER_FOLLOW_LINKS, + GNOME_VFS_XFER_ERROR_MODE_ABORT, + GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE, + NULL, + job); + gnome_vfs_uri_unref (target_uri); + } + gnome_vfs_uri_unref (source_uri); EV_JOB (job)->finished = TRUE; return; diff --git a/shell/ev-job-xfer.h b/shell/ev-job-xfer.h index dba99017..256a60ed 100644 --- a/shell/ev-job-xfer.h +++ b/shell/ev-job-xfer.h @@ -38,7 +38,8 @@ struct _EvJobXfer { EvJob parent; GError *error; - gchar *uri; + char *uri; + char *local_uri; }; struct _EvJobXferClass diff --git a/shell/ev-window.c b/shell/ev-window.c index f3c7a46e..28921f03 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -114,6 +114,7 @@ struct _EvWindowPrivate { /* Document */ char *uri; + char *local_uri; EvDocument *document; EvPageCache *page_cache; @@ -747,6 +748,22 @@ ev_window_clear_jobs (EvWindow *ev_window) } } +static void +ev_window_clear_local_uri (EvWindow *ev_window) +{ + char *filename; + + if (ev_window->priv->local_uri) { + filename = g_filename_from_uri (ev_window->priv->local_uri, NULL, NULL); + if (filename != NULL) { + unlink (filename); + g_free (filename); + } + g_free (ev_window->priv->local_uri); + ev_window->priv->local_uri = NULL; + } +} + /* This callback will executed when load job will be finished. * * Since the flow of the error dialog is very confusing, we assume that both @@ -788,7 +805,7 @@ ev_window_load_job_cb (EvJobLoad *job, ev_window->priv->document = g_object_ref (document); ev_window_setup_document (ev_window); - ev_window_add_recent (ev_window, job->uri); + ev_window_add_recent (ev_window, ev_window->priv->uri); ev_window_clear_jobs (ev_window); return; @@ -824,33 +841,37 @@ ev_window_xfer_job_cb (EvJobXfer *job, { EvWindow *ev_window = EV_WINDOW (data); - ev_statusbar_pop (EV_STATUSBAR (ev_window->priv->statusbar), - EV_CONTEXT_PROGRESS); - ev_statusbar_set_progress (EV_STATUSBAR (ev_window->priv->statusbar), - FALSE); if (job->error != NULL) { + ev_statusbar_pop (EV_STATUSBAR (ev_window->priv->statusbar), + EV_CONTEXT_PROGRESS); + ev_statusbar_set_progress (EV_STATUSBAR (ev_window->priv->statusbar), + FALSE); + unable_to_load (ev_window, job->error->message); ev_window_clear_jobs (ev_window); } else { + char *uri; + EvDocument *document = g_object_ref (EV_JOB (job)->document); - + + if (job->local_uri) { + ev_window->priv->local_uri = g_strdup (job->local_uri); + uri = ev_window->priv->local_uri; + } else { + ev_window->priv->local_uri = NULL; + uri = ev_window->priv->uri; + } + ev_window_clear_jobs (ev_window); - ev_window->priv->load_job = ev_job_load_new (document, ev_window->priv->uri); + ev_window->priv->load_job = ev_job_load_new (document, uri); g_signal_connect (ev_window->priv->load_job, "finished", G_CALLBACK (ev_window_load_job_cb), ev_window); ev_job_queue_add_job (ev_window->priv->load_job, EV_JOB_PRIORITY_HIGH); - - ev_statusbar_push (EV_STATUSBAR (ev_window->priv->statusbar), - EV_CONTEXT_PROGRESS, - _("Loading document. Please wait")); - ev_statusbar_set_progress (EV_STATUSBAR (ev_window->priv->statusbar), - TRUE); - } } @@ -864,6 +885,7 @@ ev_window_open_uri (EvWindow *ev_window, const char *uri) ev_window->priv->uri = g_strdup (uri); ev_window_clear_jobs (ev_window); + ev_window_clear_local_uri (ev_window); ev_window->priv->xfer_job = ev_job_xfer_new (uri); g_signal_connect (ev_window->priv->xfer_job, @@ -938,9 +960,6 @@ ev_window_add_recent (EvWindow *window, const char *filename) { EggRecentItem *item; - if (strstr (filename, "file:///") == NULL) - return; - item = egg_recent_item_new_from_uri (filename); egg_recent_item_add_group (item, "Evince"); egg_recent_model_add_full (window->priv->recent_model, item); @@ -2370,6 +2389,10 @@ ev_window_dispose (GObject *object) if (priv->load_job || priv->xfer_job) { ev_window_clear_jobs (window); } + + if (priv->local_uri) { + ev_window_clear_local_uri (window); + } if (priv->password_document) { g_object_unref (priv->password_document); diff --git a/thumbnailer/evince-thumbnailer.c b/thumbnailer/evince-thumbnailer.c index dfa521be..c4a02cb6 100644 --- a/thumbnailer/evince-thumbnailer.c +++ b/thumbnailer/evince-thumbnailer.c @@ -38,8 +38,8 @@ evince_thumbnail_pngenc_get (const char *uri, const char *thumbnail, int size) GType document_type; char *mime_type = NULL; - document_type = ev_document_type_lookup (uri, &mime_type); - if (document_type == G_TYPE_INVALID) + document_type = ev_document_type_lookup (uri, &mime_type, &error); + if (document_type == G_TYPE_INVALID || error != NULL) return FALSE; document = g_object_new (document_type, NULL);