aboutsummaryrefslogtreecommitdiffstats
path: root/src/window-commands.c
diff options
context:
space:
mode:
authorCarlos Garcia Campos <cgarcia@igalia.com>2012-06-22 17:03:36 +0800
committerCarlos Garcia Campos <carlosgc@gnome.org>2012-06-27 20:16:00 +0800
commit7e1964acdacd4bdf4e23e85ec733fe9e92688ca6 (patch)
tree6acf7bf26c7b8ddf0e4a5161122fccc3c2cd46c2 /src/window-commands.c
parent39931fc51a3a668d04f938fa555bdf9a4abf3056 (diff)
downloadgsoc2013-epiphany-7e1964acdacd4bdf4e23e85ec733fe9e92688ca6.tar
gsoc2013-epiphany-7e1964acdacd4bdf4e23e85ec733fe9e92688ca6.tar.gz
gsoc2013-epiphany-7e1964acdacd4bdf4e23e85ec733fe9e92688ca6.tar.bz2
gsoc2013-epiphany-7e1964acdacd4bdf4e23e85ec733fe9e92688ca6.tar.lz
gsoc2013-epiphany-7e1964acdacd4bdf4e23e85ec733fe9e92688ca6.tar.xz
gsoc2013-epiphany-7e1964acdacd4bdf4e23e85ec733fe9e92688ca6.tar.zst
gsoc2013-epiphany-7e1964acdacd4bdf4e23e85ec733fe9e92688ca6.zip
Port downloads to WebKit2
https://bugzilla.gnome.org/show_bug.cgi?id=678612
Diffstat (limited to 'src/window-commands.c')
-rw-r--r--src/window-commands.c41
1 files changed, 37 insertions, 4 deletions
diff --git a/src/window-commands.c b/src/window-commands.c
index 39432bd18..3a0c43b6f 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -380,7 +380,26 @@ take_page_snapshot_and_set_image (EphyApplicationDialogData *data)
}
#ifdef HAVE_WEBKIT2
-/* TODO: Downloads */
+static void
+download_finished_cb (WebKitDownload *download,
+ EphyApplicationDialogData *data)
+{
+ char *filename;
+
+ filename = g_filename_from_uri (webkit_download_get_destination (download), NULL, NULL);
+ gtk_image_set_from_file (GTK_IMAGE (data->image), filename);
+ g_free (filename);
+}
+
+static void
+download_failed_cb (WebKitDownload *download,
+ GError *error,
+ EphyApplicationDialogData *data)
+{
+ g_signal_handlers_disconnect_by_func (download, download_finished_cb, data);
+ /* Something happened, default to a page snapshot. */
+ take_page_snapshot_and_set_image (data);
+}
#else
static void
download_status_changed_cb (WebKitDownload *download,
@@ -412,25 +431,39 @@ download_status_changed_cb (WebKitDownload *download,
static void
download_icon_and_set_image (EphyApplicationDialogData *data)
{
-#ifdef HAVE_WEBKIT2
- /* TODO: Downloads */
-#else
+#ifndef HAVE_WEBKIT2
WebKitNetworkRequest *request;
+#endif
WebKitDownload *download;
char *destination, *destination_uri, *tmp_filename;
+#ifdef HAVE_WEBKIT2
+ download = webkit_web_context_download_uri (webkit_web_context_get_default (),
+ data->icon_href);
+#else
request = webkit_network_request_new (data->icon_href);
download = webkit_download_new (request);
g_object_unref (request);
+#endif
tmp_filename = ephy_file_tmp_filename ("ephy-download-XXXXXX", NULL);
destination = g_build_filename (ephy_file_tmp_dir (), tmp_filename, NULL);
destination_uri = g_filename_to_uri (destination, NULL, NULL);
+#ifdef HAVE_WEBKIT2
+ webkit_download_set_destination (download, destination_uri);
+#else
webkit_download_set_destination_uri (download, destination_uri);
+#endif
g_free (destination);
g_free (destination_uri);
g_free (tmp_filename);
+#ifdef HAVE_WEBKIT2
+ g_signal_connect (download, "finished",
+ G_CALLBACK (download_finished_cb), data);
+ g_signal_connect (download, "failed",
+ G_CALLBACK (download_failed_cb), data);
+#else
g_signal_connect (download, "notify::status",
G_CALLBACK (download_status_changed_cb), data);