aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2013-07-27 13:49:59 +0800
committerMatthew Barnes <mbarnes@redhat.com>2013-07-28 03:27:09 +0800
commit69837f33cc6701043c9bbef2005c3c8281d5980e (patch)
tree7027303ba875f204a526b4e87702e036b8272662 /e-util
parent51b74eee72ecf1323105f9c12942f2fe303ec7e1 (diff)
downloadgsoc2013-evolution-69837f33cc6701043c9bbef2005c3c8281d5980e.tar
gsoc2013-evolution-69837f33cc6701043c9bbef2005c3c8281d5980e.tar.gz
gsoc2013-evolution-69837f33cc6701043c9bbef2005c3c8281d5980e.tar.bz2
gsoc2013-evolution-69837f33cc6701043c9bbef2005c3c8281d5980e.tar.lz
gsoc2013-evolution-69837f33cc6701043c9bbef2005c3c8281d5980e.tar.xz
gsoc2013-evolution-69837f33cc6701043c9bbef2005c3c8281d5980e.tar.zst
gsoc2013-evolution-69837f33cc6701043c9bbef2005c3c8281d5980e.zip
Add e_web_view_suggest_filename().
Attempts to derive a suggested filename from the given URI for use in a "Save As" dialog. By default the suggested filename is the last path segment of the given URI (the unless the given URI looks like a query), but subclasses can use other mechanisms for custom URI schemes. For example, "cid:" URIs in an email message may refer to a MIME part with a suggested filename in its Content-Disposition header.
Diffstat (limited to 'e-util')
-rw-r--r--e-util/e-web-view.c61
-rw-r--r--e-util/e-web-view.h4
2 files changed, 65 insertions, 0 deletions
diff --git a/e-util/e-web-view.c b/e-util/e-web-view.c
index 68ca266ca1..936781a8c1 100644
--- a/e-util/e-web-view.c
+++ b/e-util/e-web-view.c
@@ -1087,6 +1087,25 @@ web_view_redirect_uri (EWebView *web_view,
return g_strdup (uri);
}
+static gchar *
+web_view_suggest_filename (EWebView *web_view,
+ const gchar *uri)
+{
+ const gchar *cp;
+
+ /* Try to derive a filename from the last path segment. */
+
+ cp = strrchr (uri, '/');
+ if (cp != NULL) {
+ if (strchr (cp, '?') == NULL)
+ cp++;
+ else
+ cp = NULL;
+ }
+
+ return g_strdup (cp);
+}
+
static gboolean
web_view_popup_event (EWebView *web_view,
const gchar *uri)
@@ -1375,6 +1394,7 @@ e_web_view_class_init (EWebViewClass *class)
class->load_string = web_view_load_string;
class->load_uri = web_view_load_uri;
class->redirect_uri = web_view_redirect_uri;
+ class->suggest_filename = web_view_suggest_filename;
class->popup_event = web_view_popup_event;
class->stop_loading = web_view_stop_loading;
class->update_actions = web_view_update_actions;
@@ -1850,6 +1870,47 @@ e_web_view_redirect_uri (EWebView *web_view,
return class->redirect_uri (web_view, uri);
}
+/**
+ * e_web_view_suggest_filename:
+ * @web_view: an #EWebView
+ * @uri: a URI string
+ *
+ * Attempts to derive a suggested filename from the @uri for use in a
+ * "Save As" dialog.
+ *
+ * By default the suggested filename is the last path segment of the @uri
+ * (unless @uri looks like a query), but subclasses can use other mechanisms
+ * for custom URI schemes. For example, "cid:" URIs in an email message may
+ * refer to a MIME part with a suggested filename in its Content-Disposition
+ * header.
+ *
+ * The returned string should be freed with g_free() when finished with it,
+ * but callers should also be prepared for the function to return %NULL if
+ * a filename cannot be determined.
+ *
+ * Returns: a suggested filename, or %NULL
+ **/
+gchar *
+e_web_view_suggest_filename (EWebView *web_view,
+ const gchar *uri)
+{
+ EWebViewClass *class;
+ gchar *filename;
+
+ g_return_val_if_fail (E_IS_WEB_VIEW (web_view), NULL);
+ g_return_val_if_fail (uri != NULL, NULL);
+
+ class = E_WEB_VIEW_GET_CLASS (web_view);
+ g_return_val_if_fail (class->suggest_filename != NULL, NULL);
+
+ filename = class->suggest_filename (web_view, uri);
+
+ if (filename != NULL)
+ e_filename_make_safe (filename);
+
+ return filename;
+}
+
void
e_web_view_reload (EWebView *web_view)
{
diff --git a/e-util/e-web-view.h b/e-util/e-web-view.h
index d4b1db650d..df338abd71 100644
--- a/e-util/e-web-view.h
+++ b/e-util/e-web-view.h
@@ -82,6 +82,8 @@ struct _EWebViewClass {
const gchar *load_uri);
gchar * (*redirect_uri) (EWebView *web_view,
const gchar *uri);
+ gchar * (*suggest_filename) (EWebView *web_view,
+ const gchar *uri);
void (*set_fonts) (EWebView *web_view,
PangoFontDescription **monospace,
PangoFontDescription **variable_width);
@@ -106,6 +108,8 @@ void e_web_view_load_uri (EWebView *web_view,
const gchar *uri);
gchar * e_web_view_redirect_uri (EWebView *web_view,
const gchar *uri);
+gchar * e_web_view_suggest_filename (EWebView *web_view,
+ const gchar *uri);
void e_web_view_reload (EWebView *web_view);
gchar * e_web_view_get_html (EWebView *web_view);
gboolean e_web_view_get_caret_mode (EWebView *web_view);