summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/evbp-viewer.c43
-rw-r--r--src/evbp-viewer.h3
-rw-r--r--src/evbp.c8
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
diff --git a/src/evbp.c b/src/evbp.c
index 933e3e1..54c5851 100644
--- a/src/evbp.c
+++ b/src/evbp.c
@@ -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;