diff options
author | Dan Nicholson <dbn.lists@gmail.com> | 2013-02-23 23:34:04 -0800 |
---|---|---|
committer | Dan Nicholson <dbn.lists@gmail.com> | 2013-02-23 23:34:04 -0800 |
commit | 1b5a0d5f475f4ba34c6202ade182ece0aeff5587 (patch) | |
tree | 30f4ac291a36da50dfbd66e068948a3831935691 /src | |
parent | 2e70862c8257564d7e8d9f9f2b93059cdef4df38 (diff) |
Use the original URI of the file when setting a default for the saved
file. This is an improvement over using the document title or the
temporary file name from the browser. As a bonus, this avoids the
deprecated ev_backends_manager_get_document_type_info API from evince.
Diffstat (limited to 'src')
-rw-r--r-- | src/evbp-viewer.c | 43 | ||||
-rw-r--r-- | src/evbp-viewer.h | 3 | ||||
-rw-r--r-- | src/evbp.c | 8 |
3 files changed, 32 insertions, 22 deletions
diff --git a/src/evbp-viewer.c b/src/evbp-viewer.c index 1f19f6a..0a90de8 100644 --- a/src/evbp-viewer.c +++ b/src/evbp-viewer.c @@ -73,8 +73,9 @@ evbp_chooser_response_cb(GtkDialog *dialog, gint response, EvbpViewer *viewer) static void evbp_viewer_save_copy(GtkAction *action, EvbpViewer *viewer) { - const gchar *title; const gchar *download_dir; + const gchar *uri; + gchar *path; gchar *filename = NULL; GtkWindow *parent; GtkWidget *chooser; @@ -101,28 +102,16 @@ evbp_viewer_save_copy(GtkAction *action, EvbpViewer *viewer) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser), download_dir); - /* Try to determine an appropriate initial filename. What we get from - * mozilla is likely a garbage temporary name, so try the document title - * first. */ - title = ev_document_get_title(viewer->document); - if (title) { - EvTypeInfo *typeinfo; - const gchar *suffix; - - typeinfo = ev_backends_manager_get_document_type_info(viewer->document); - suffix = evbp_mime_get_suffix(*typeinfo->mime_types); - filename = g_strdup_printf("%s.%s", title, suffix); - g_free(typeinfo); - } else { - const gchar *uri; - gchar *path; - + /* Try to determine an appropriate initial filename. If we have the + * original uri, use that. Otherwise, use the actual file's uri. */ + if (viewer->orig_uri) + uri = viewer->orig_uri; + else uri = ev_document_get_uri(viewer->document); - path = g_filename_from_uri(uri, NULL, NULL); - if (path) { - filename = g_path_get_basename(path); - g_free(path); - } + path = g_filename_from_uri(uri, NULL, NULL); + if (path) { + filename = g_path_get_basename(path); + g_free(path); } if (filename) { gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(chooser), @@ -344,6 +333,10 @@ evbp_viewer_dispose(GObject *object) g_object_unref(viewer->ui_manager); viewer->ui_manager = NULL; } + if (viewer->orig_uri) { + g_free(viewer->orig_uri); + viewer->orig_uri = NULL; + } G_OBJECT_CLASS(evbp_viewer_parent_class)->dispose(object); } @@ -544,3 +537,9 @@ evbp_viewer_load_uri(EvbpViewer *viewer, const gchar *uri, GError **error) return TRUE; } + +void +evbp_viewer_set_original_uri(EvbpViewer *viewer, const char *uri) +{ + viewer->orig_uri = g_strdup(uri); +} diff --git a/src/evbp-viewer.h b/src/evbp-viewer.h index 08b3503..5c7cbeb 100644 --- a/src/evbp-viewer.h +++ b/src/evbp-viewer.h @@ -55,6 +55,8 @@ struct _EvbpViewer { GtkWidget *scroll; GtkWidget *view; + + gchar *orig_uri; }; struct _EvbpViewerClass { @@ -65,6 +67,7 @@ GType evbp_viewer_get_type(void) G_GNUC_CONST; GtkWidget *evbp_viewer_new(void); gboolean evbp_viewer_load_uri(EvbpViewer *viewer, const char *uri, GError **error); +void evbp_viewer_set_original_uri(EvbpViewer *viewer, const gchar *uri); G_END_DECLS @@ -237,8 +237,16 @@ static NPError evbp_new_stream(NPP instance, NPMIMEType type, NPStream *stream, NPBool seekable, uint16_t *stype) { + evbp_priv_t *priv = instance->pdata; + g_debug("%s", __func__); + /* keep track of the url if possible */ + if (stream->url) { + g_debug("Streaming url \"%s\"", stream->url); + evbp_viewer_set_original_uri(EVBP_VIEWER(priv->viewer), stream->url); + } + /* fetch the url to a local file only */ *stype = NP_ASFILEONLY; |