aboutsummaryrefslogtreecommitdiffstats
path: root/embed
diff options
context:
space:
mode:
authorGustavo Noronha Silva <gns@src.gnome.org>2009-03-05 07:59:35 +0800
committerGustavo Noronha Silva <gns@src.gnome.org>2009-03-05 07:59:35 +0800
commit42a654901e1cdc2abf20feff9eb1d7128246d6a1 (patch)
treefce1285f78c056de771bc4420ad040c8ec440720 /embed
parent8f403c6207687e3ecdec6a40bbe16e02a6815bc1 (diff)
downloadgsoc2013-epiphany-42a654901e1cdc2abf20feff9eb1d7128246d6a1.tar
gsoc2013-epiphany-42a654901e1cdc2abf20feff9eb1d7128246d6a1.tar.gz
gsoc2013-epiphany-42a654901e1cdc2abf20feff9eb1d7128246d6a1.tar.bz2
gsoc2013-epiphany-42a654901e1cdc2abf20feff9eb1d7128246d6a1.tar.lz
gsoc2013-epiphany-42a654901e1cdc2abf20feff9eb1d7128246d6a1.tar.xz
gsoc2013-epiphany-42a654901e1cdc2abf20feff9eb1d7128246d6a1.tar.zst
gsoc2013-epiphany-42a654901e1cdc2abf20feff9eb1d7128246d6a1.zip
Basic download functionality for ephy/webkit. This update also removes
the EphyDownload wrapper, which should be no longer needed with the advent of WebKitDownload. http://bugzilla.gnome.org/show_bug.cgi?id=570735 svn path=/trunk/; revision=8848
Diffstat (limited to 'embed')
-rw-r--r--embed/Makefile.am2
-rw-r--r--embed/downloader-view.c179
-rw-r--r--embed/downloader-view.h6
-rw-r--r--embed/ephy-download.c215
-rw-r--r--embed/ephy-download.h114
-rw-r--r--embed/webkit/webkit-embed.c57
6 files changed, 173 insertions, 400 deletions
diff --git a/embed/Makefile.am b/embed/Makefile.am
index e0c8b516f..03b33333d 100644
--- a/embed/Makefile.am
+++ b/embed/Makefile.am
@@ -11,7 +11,6 @@ header_DATA = \
NOINST_H_FILES = \
downloader-view.h \
- ephy-download.h \
ephy-embed-dialog.h \
ephy-encodings.h \
ephy-favicon-cache.h
@@ -44,7 +43,6 @@ libephyembed_la_SOURCES = \
ephy-base-embed.c \
downloader-view.c \
ephy-command-manager.c \
- ephy-download.c \
ephy-embed.c \
ephy-embed-container.c \
ephy-embed-dialog.c \
diff --git a/embed/downloader-view.c b/embed/downloader-view.c
index 1b5f49a77..b0380cfb7 100644
--- a/embed/downloader-view.c
+++ b/embed/downloader-view.c
@@ -193,14 +193,19 @@ show_status_icon (DownloaderView *dv)
}
static gboolean
-remove_download (EphyDownload *download,
+remove_download (WebKitDownload *download,
gpointer rowref,
DownloaderView *view)
{
+ WebKitDownloadState state;
+
g_signal_handlers_disconnect_matched
(download, G_SIGNAL_MATCH_DATA ,
0, 0, NULL, NULL, view);
- ephy_download_cancel (download);
+
+ state = webkit_download_get_state (download);
+ if (state == WEBKIT_DOWNLOAD_STATE_STARTED)
+ webkit_download_cancel (download);
g_object_unref (download);
return TRUE;
@@ -298,13 +303,13 @@ downloader_view_new (void)
}
static char *
-format_interval (gint64 interval)
+format_interval (gdouble interval)
{
int hours, mins, secs;
- hours = (int) interval / 3600;
+ hours = (int) (interval / 3600);
interval -= hours * 3600;
- mins = (int) interval / 60;
+ mins = (int) (interval / 60);
interval -= mins * 60;
secs = (int) interval;
@@ -319,7 +324,7 @@ format_interval (gint64 interval)
}
static GtkTreeRowReference *
-get_row_from_download (DownloaderView *dv, EphyDownload *download)
+get_row_from_download (DownloaderView *dv, WebKitDownload *download)
{
return g_hash_table_lookup (dv->priv->downloads_hash, download);
}
@@ -330,8 +335,8 @@ update_buttons (DownloaderView *dv)
GtkTreeSelection *selection;
GtkTreeModel *model;
GtkTreeIter iter;
- EphyDownloadState state;
- EphyDownload *download;
+ WebKitDownloadState state;
+ WebKitDownload *download;
gboolean pause_enabled = FALSE;
gboolean abort_enabled = FALSE;
gboolean label_pause = TRUE;
@@ -346,23 +351,12 @@ update_buttons (DownloaderView *dv)
return;
gtk_tree_model_get (model, &iter, COL_DOWNLOAD_OBJECT, &download, -1);
- state = ephy_download_get_state (download);
+ state = webkit_download_get_state (download);
- switch (state)
- {
- case EPHY_DOWNLOAD_DOWNLOADING:
- pause_enabled = TRUE;
- abort_enabled = TRUE;
- break;
- case EPHY_DOWNLOAD_PAUSED:
- pause_enabled = TRUE;
- abort_enabled = TRUE;
- label_pause = FALSE;
- break;
- default:
- abort_enabled = TRUE;
- break;
- }
+ /* Pausing is not supported yet */
+ pause_enabled = FALSE;
+ label_pause = TRUE;
+ abort_enabled = TRUE;
}
else
{
@@ -378,14 +372,58 @@ update_buttons (DownloaderView *dv)
label_pause ? _("_Pause") : _("_Resume"));
}
+static char *
+ephy_download_get_name (WebKitDownload *download)
+{
+ const char *target;
+ char *result;
+
+ target = webkit_download_get_destination_uri (download);
+
+ if (target)
+ {
+ result = g_path_get_basename (target);
+ }
+ else
+ {
+ result = g_strdup (_("Unknown"));
+ }
+
+ return result;
+}
+
+static gdouble
+ephy_download_get_remaining_time (WebKitDownload *download)
+{
+ gint64 total, cur;
+ gdouble elapsed_time;
+ gdouble remaining_time;
+
+ total = webkit_download_get_total_size (download);
+ cur = webkit_download_get_current_size (download);
+ elapsed_time = webkit_download_get_elapsed_time (download);
+
+ if (cur <= 0)
+ {
+ return -1.0;
+ }
+
+ gdouble per_byte_time;
+ per_byte_time = elapsed_time / cur;
+ remaining_time = per_byte_time * (total - cur);
+
+ return remaining_time;
+}
+
static void
-update_download_row (DownloaderView *dv, EphyDownload *download)
+update_download_row (DownloaderView *dv, WebKitDownload *download)
{
GtkTreeRowReference *row_ref;
GtkTreePath *path;
GtkTreeIter iter;
- EphyDownloadState state;
- gint64 remaining_secs = 0, total, current;
+ WebKitDownloadState state;
+ gint64 total, current;
+ gdouble remaining_seconds = 0.0;
char *remaining, *file, *cur_progress, *name;
struct tm;
int percent = 0;
@@ -398,10 +436,10 @@ update_download_row (DownloaderView *dv, EphyDownload *download)
g_return_if_fail (row_ref != NULL);
/* State special casing */
- state = ephy_download_get_state (download);
+ state = webkit_download_get_state (download);
- total = ephy_download_get_total_progress (download);
- current = ephy_download_get_current_progress (download);
+ total = webkit_download_get_total_size (download);
+ current = webkit_download_get_current_size (download);
cur_progress = g_format_size_for_display (current);
@@ -409,9 +447,11 @@ update_download_row (DownloaderView *dv, EphyDownload *download)
switch (state)
{
- case EPHY_DOWNLOAD_COMPLETED:
+ case WEBKIT_DOWNLOAD_STATE_CANCELLED:
+ downloader_view_remove_download (dv, download);
+ return;
+ case WEBKIT_DOWNLOAD_STATE_FINISHED:
downloader_view_remove_download (dv, download);
-
#ifdef HAVE_LIBNOTIFY
downloaded = g_strdup_printf (_("The file “%s” has been downloaded."),
name);
@@ -426,10 +466,9 @@ update_download_row (DownloaderView *dv, EphyDownload *download)
#endif
return;
- case EPHY_DOWNLOAD_PAUSED:
- case EPHY_DOWNLOAD_DOWNLOADING:
- percent = ephy_download_get_percent (download);
- remaining_secs = ephy_download_get_remaining_time (download);
+ case WEBKIT_DOWNLOAD_STATE_STARTED:
+ percent = (int) (webkit_download_get_progress (download) * 100);
+ remaining_seconds = ephy_download_get_remaining_time (download);
break;
default:
break;
@@ -454,13 +493,13 @@ update_download_row (DownloaderView *dv, EphyDownload *download)
file = g_strdup_printf ("%s\n%s", name, _("Unknown"));
}
- if (remaining_secs < 0)
+ if (remaining_seconds < 0)
{
remaining = g_strdup (_("Unknown"));
}
else
{
- remaining = format_interval (remaining_secs);
+ remaining = format_interval (remaining_seconds);
}
path = gtk_tree_row_reference_get_path (row_ref);
@@ -498,7 +537,18 @@ update_status_icon (DownloaderView *dv)
}
static void
-download_changed_cb (EphyDownload *download, DownloaderView *dv)
+download_progress_cb (WebKitDownload *download, GParamSpec *pspec, DownloaderView *dv)
+{
+ WebKitDownloadState state = webkit_download_get_state (download);
+ if ((state != WEBKIT_DOWNLOAD_STATE_STARTED) && (state != WEBKIT_DOWNLOAD_STATE_FINISHED))
+ return;
+ if ((state == WEBKIT_DOWNLOAD_STATE_FINISHED) && (webkit_download_get_progress (download) < 1.0))
+ return;
+ update_download_row (dv, download);
+}
+
+static void
+download_error_cb (WebKitDownload *download, gint error_code, gint error_detail, const gchar *reason, DownloaderView *dv)
{
update_download_row (dv, download);
}
@@ -542,7 +592,7 @@ show_notification_window (DownloaderView *dv)
void
downloader_view_add_download (DownloaderView *dv,
- EphyDownload *download)
+ WebKitDownload *download)
{
GtkTreeRowReference *row_ref;
GtkTreeIter iter;
@@ -584,8 +634,11 @@ downloader_view_add_download (DownloaderView *dv,
gtk_tree_selection_unselect_all (selection);
gtk_tree_selection_select_iter (selection, &iter);
- g_signal_connect_object (download, "changed",
- G_CALLBACK (download_changed_cb), dv, 0);
+ g_signal_connect_object (download, "notify::progress",
+ G_CALLBACK (download_progress_cb), dv, 0);
+
+ g_signal_connect_object (download, "error",
+ G_CALLBACK (download_error_cb), dv, 0);
/* Show it already */
g_value_init (&visible, G_TYPE_BOOLEAN);
@@ -595,8 +648,10 @@ downloader_view_add_download (DownloaderView *dv,
{
#ifdef HAVE_LIBNOTIFY
+ char *name = ephy_download_get_name (download);
downloading = g_strdup_printf(_("The file “%s” has been added to the downloads queue."),
- ephy_download_get_name (download));
+ name);
+ g_free (name);
notify_notification_update (dv->priv->notification,
_("Download started"),
downloading,
@@ -661,7 +716,7 @@ progress_cell_data_func (GtkTreeViewColumn *col,
GtkTreeIter *iter,
gpointer user_data)
{
- EphyDownloadState state;
+ WebKitDownloadState state;
const char *text = NULL;
int percent;
@@ -672,14 +727,15 @@ progress_cell_data_func (GtkTreeViewColumn *col,
switch (state)
{
- case EPHY_DOWNLOAD_INITIALISING:
+ case WEBKIT_DOWNLOAD_STATE_CREATED:
text = C_("download status", "Unknown");
break;
- case EPHY_DOWNLOAD_FAILED:
+ case WEBKIT_DOWNLOAD_STATE_ERROR:
text = C_("download status", "Failed");
break;
- case EPHY_DOWNLOAD_DOWNLOADING:
- case EPHY_DOWNLOAD_PAUSED:
+ case WEBKIT_DOWNLOAD_STATE_CANCELLED:
+ text = C_("download status", "Cancelled");
+ case WEBKIT_DOWNLOAD_STATE_STARTED:
if (percent == -1)
{
text = C_("download status", "Unknown");
@@ -809,8 +865,8 @@ download_dialog_pause (DownloaderView *dv)
GtkTreeModel *model;
GtkTreeIter iter;
GValue val = {0, };
- EphyDownload *download;
- EphyDownloadState state;
+ WebKitDownload *download;
+ WebKitDownloadState state;
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(dv->priv->treeview));
@@ -819,16 +875,9 @@ download_dialog_pause (DownloaderView *dv)
gtk_tree_model_get_value (model, &iter, COL_DOWNLOAD_OBJECT, &val);
download = g_value_get_object (&val);
- state = ephy_download_get_state (download);
+ state = webkit_download_get_state (download);
- if (state == EPHY_DOWNLOAD_DOWNLOADING)
- {
- ephy_download_pause (download);
- }
- else if (state == EPHY_DOWNLOAD_PAUSED)
- {
- ephy_download_resume (download);
- }
+ g_warning ("Pause/resume not implemented");
g_value_unset (&val);
@@ -836,7 +885,7 @@ download_dialog_pause (DownloaderView *dv)
}
void
-downloader_view_remove_download (DownloaderView *dv, EphyDownload *download)
+downloader_view_remove_download (DownloaderView *dv, WebKitDownload *download)
{
GtkTreeRowReference *row_ref;
GtkTreePath *path = NULL;
@@ -873,9 +922,8 @@ downloader_view_remove_download (DownloaderView *dv, EphyDownload *download)
/* Removal */
gtk_list_store_remove (GTK_LIST_STORE (dv->priv->model), &iter2);
- g_hash_table_remove (dv->priv->downloads_hash,
- download);
- g_object_unref (download);
+ g_hash_table_remove (dv->priv->downloads_hash, download);
+ remove_download (download, NULL, dv);
/* Actual selection */
@@ -910,7 +958,7 @@ download_dialog_stop (DownloaderView *dv)
GList *selected = NULL;
GList *downloads = NULL;
GList *l = NULL;
- EphyDownload *download;
+ WebKitDownload *download;
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(dv->priv->treeview));
model = gtk_tree_view_get_model (GTK_TREE_VIEW(dv->priv->treeview));
@@ -931,8 +979,7 @@ download_dialog_stop (DownloaderView *dv)
for (l = downloads; l; l = l->next)
{
if (!l->data) continue;
- ephy_download_cancel ((EphyDownload*) l->data);
- downloader_view_remove_download (dv, l->data);
+ webkit_download_cancel ((WebKitDownload*) l->data);
g_object_unref (l->data);
}
diff --git a/embed/downloader-view.h b/embed/downloader-view.h
index 52f5023df..82cb101f0 100644
--- a/embed/downloader-view.h
+++ b/embed/downloader-view.h
@@ -21,8 +21,8 @@
#define DOWNLOADER_VIEW_H
#include "ephy-dialog.h"
-#include "ephy-download.h"
+#include <webkit/webkit.h>
#include <glib-object.h>
#include <glib.h>
@@ -57,10 +57,10 @@ GType downloader_view_get_type (void);
DownloaderView *downloader_view_new (void);
void downloader_view_add_download (DownloaderView *dv,
- EphyDownload *download);
+ WebKitDownload *download);
void downloader_view_remove_download (DownloaderView *dv,
- EphyDownload *download);
+ WebKitDownload *download);
G_END_DECLS
diff --git a/embed/ephy-download.c b/embed/ephy-download.c
deleted file mode 100644
index 868d82975..000000000
--- a/embed/ephy-download.c
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
- * Copyright © 2000, 2001, 2002 Marco Pesenti Gritti
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "config.h"
-
-#include "ephy-download.h"
-
-#include <glib/gi18n.h>
-
-#define EPHY_DOWNLOAD_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_DOWNLOAD, EphyDownloadPrivate))
-
-#define REMAINING_TIME_UPDATE_SECS 2
-
-static void
-ephy_download_class_init (EphyDownloadClass *klass);
-static void
-ephy_download_init (EphyDownload *dv);
-
-enum
-{
- CHANGED,
- LAST_SIGNAL
-};
-
-struct _EphyDownloadPrivate
-{
- gint64 remaining_time_last_update;
- gint64 remaining_time;
-};
-
-static guint ephy_download_signals[LAST_SIGNAL];
-
-G_DEFINE_TYPE (EphyDownload, ephy_download, G_TYPE_OBJECT)
-
-static void
-ephy_download_class_init (EphyDownloadClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- ephy_download_signals[CHANGED] =
- g_signal_new ("changed",
- EPHY_TYPE_DOWNLOAD,
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (EphyDownloadClass, changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE,
- 0);
-
- g_type_class_add_private (object_class, sizeof(EphyDownloadPrivate));
-}
-
-static void
-ephy_download_init (EphyDownload *download)
-{
- download->priv = EPHY_DOWNLOAD_GET_PRIVATE (download);
-
- download->priv->remaining_time = 0;
- download->priv->remaining_time_last_update = 0;
-}
-
-EphyDownload *
-ephy_download_new (void)
-{
- return EPHY_DOWNLOAD (g_object_new (EPHY_TYPE_DOWNLOAD, NULL));
-}
-
-char *
-ephy_download_get_name (EphyDownload *download)
-{
- char *target;
- char *result;
-
- target = ephy_download_get_target (download);
-
- if (target)
- {
- result = g_path_get_basename (target);
- }
- else
- {
- result = g_strdup (_("Unknown"));
- }
-
- g_free (target);
-
- return result;
-}
-
-static void
-update_remaining_time (EphyDownload *download)
-{
- gint64 elapsed_time, total, cur;
-
- total = ephy_download_get_total_progress (download);
- cur = ephy_download_get_current_progress (download);
- elapsed_time = ephy_download_get_elapsed_time (download);
-
- if (cur > 0)
- {
- float per_byte_time;
-
- per_byte_time = (float)elapsed_time / (float)cur;
- download->priv->remaining_time = per_byte_time * (total - cur);
- }
-}
-
-gint64
-ephy_download_get_remaining_time (EphyDownload *download)
-{
- gint64 elapsed_time;
-
- elapsed_time = ephy_download_get_elapsed_time (download);
- if (elapsed_time - download->priv->remaining_time_last_update >=
- REMAINING_TIME_UPDATE_SECS)
- {
- update_remaining_time (download);
- download->priv->remaining_time_last_update = elapsed_time;
- }
-
- return download->priv->remaining_time;
-}
-
-char *
-ephy_download_get_source (EphyDownload *download)
-{
- EphyDownloadClass *klass = EPHY_DOWNLOAD_GET_CLASS (download);
- return klass->get_source (download);
-}
-
-char *
-ephy_download_get_target (EphyDownload *download)
-{
- EphyDownloadClass *klass = EPHY_DOWNLOAD_GET_CLASS (download);
- return klass->get_target (download);
-}
-
-gint64
-ephy_download_get_current_progress (EphyDownload *download)
-{
- EphyDownloadClass *klass = EPHY_DOWNLOAD_GET_CLASS (download);
- return klass->get_current_progress (download);
-}
-
-gint64
-ephy_download_get_total_progress (EphyDownload *download)
-{
- EphyDownloadClass *klass = EPHY_DOWNLOAD_GET_CLASS (download);
- return klass->get_total_progress (download);
-}
-
-int
-ephy_download_get_percent (EphyDownload *download)
-{
- EphyDownloadClass *klass = EPHY_DOWNLOAD_GET_CLASS (download);
- return klass->get_percent (download);
-}
-
-gint64
-ephy_download_get_elapsed_time (EphyDownload *download)
-{
- EphyDownloadClass *klass = EPHY_DOWNLOAD_GET_CLASS (download);
- return klass->get_elapsed_time (download);
-}
-
-EphyDownloadState
-ephy_download_get_state (EphyDownload *download)
-{
- EphyDownloadClass *klass = EPHY_DOWNLOAD_GET_CLASS (download);
- return klass->get_state (download);
-}
-
-char *
-ephy_download_get_mime (EphyDownload *download)
-{
- EphyDownloadClass *klass = EPHY_DOWNLOAD_GET_CLASS (download);
- return klass->get_mime (download);
-}
-
-void
-ephy_download_cancel (EphyDownload *download)
-{
- EphyDownloadClass *klass = EPHY_DOWNLOAD_GET_CLASS (download);
- klass->cancel (download);
-}
-
-void
-ephy_download_pause (EphyDownload *download)
-{
- EphyDownloadClass *klass = EPHY_DOWNLOAD_GET_CLASS (download);
- klass->pause (download);
-}
-
-void
-ephy_download_resume (EphyDownload *download)
-{
- EphyDownloadClass *klass = EPHY_DOWNLOAD_GET_CLASS (download);
- klass->resume (download);
-}
diff --git a/embed/ephy-download.h b/embed/ephy-download.h
deleted file mode 100644
index 6741f776b..000000000
--- a/embed/ephy-download.h
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright © 2000-2003 Marco Pesenti Gritti
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#if !defined (__EPHY_EPIPHANY_H_INSIDE__) && !defined (EPIPHANY_COMPILATION)
-#error "Only <epiphany/epiphany.h> can be included directly."
-#endif
-
-#ifndef EPHY_DOWNLOAD_H
-#define EPHY_DOWNLOAD_H
-
-#include <glib-object.h>
-#include <glib.h>
-
-G_BEGIN_DECLS
-
-#define EPHY_TYPE_DOWNLOAD (ephy_download_get_type ())
-#define EPHY_DOWNLOAD(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EPHY_TYPE_DOWNLOAD, EphyDownload))
-#define EPHY_DOWNLOAD_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), EPHY_TYPE_DOWNLOAD, EphyDownloadClass))
-#define EPHY_IS_DOWNLOAD(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EPHY_TYPE_DOWNLOAD))
-#define EPHY_IS_DOWNLOAD_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EPHY_TYPE_DOWNLOAD))
-#define EPHY_DOWNLOAD_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EPHY_TYPE_DOWNLOAD, EphyDownloadClass))
-
-typedef struct _EphyDownload EphyDownload;
-typedef struct _EphyDownloadClass EphyDownloadClass;
-typedef struct _EphyDownloadPrivate EphyDownloadPrivate;
-
-typedef enum
-{
- EPHY_DOWNLOAD_INITIALISING,
- EPHY_DOWNLOAD_DOWNLOADING,
- EPHY_DOWNLOAD_PAUSED,
- EPHY_DOWNLOAD_COMPLETED,
- EPHY_DOWNLOAD_FAILED
-} EphyDownloadState;
-
-struct _EphyDownload
-{
- GObject parent;
-
- /*< private >*/
- EphyDownloadPrivate *priv;
-};
-
-struct _EphyDownloadClass
-{
- GObjectClass parent_class;
-
- char * (* get_source) (EphyDownload *download);
- char * (* get_target) (EphyDownload *download);
- char * (* get_mime) (EphyDownload *download);
- int (* get_percent) (EphyDownload *download);
- gint64 (* get_current_progress) (EphyDownload *download);
- gint64 (* get_total_progress) (EphyDownload *download);
- gint64 (* get_elapsed_time) (EphyDownload *download);
- void (* cancel) (EphyDownload *download);
- void (* pause) (EphyDownload *download);
- void (* resume) (EphyDownload *download);
- EphyDownloadState (* get_state) (EphyDownload *download);
-
- /* Signals */
- void (* changed) (EphyDownload *download);
-};
-
-/* Time is expressed in seconds, file sizes in bytes */
-
-GType ephy_download_get_type (void);
-
-EphyDownload *ephy_download_new (void);
-
-char *ephy_download_get_name (EphyDownload *download);
-
-char *ephy_download_get_source (EphyDownload *download);
-
-char *ephy_download_get_target (EphyDownload *download);
-
-char *ephy_download_get_mime (EphyDownload *download);
-
-int ephy_download_get_percent (EphyDownload *download);
-
-EphyDownloadState ephy_download_get_state (EphyDownload *download);
-
-gint64 ephy_download_get_current_progress (EphyDownload *download);
-
-gint64 ephy_download_get_total_progress (EphyDownload *download);
-
-gint64 ephy_download_get_elapsed_time (EphyDownload *download);
-
-gint64 ephy_download_get_remaining_time (EphyDownload *download);
-
-void ephy_download_cancel (EphyDownload *download);
-
-void ephy_download_pause (EphyDownload *download);
-
-void ephy_download_resume (EphyDownload *download);
-
-G_END_DECLS
-
-#endif
diff --git a/embed/webkit/webkit-embed.c b/embed/webkit/webkit-embed.c
index 31d272cf2..2202ad3f3 100644
--- a/embed/webkit/webkit-embed.c
+++ b/embed/webkit/webkit-embed.c
@@ -22,14 +22,19 @@
#include "config.h"
+#include "downloader-view.h"
#include "ephy-command-manager.h"
#include "ephy-debug.h"
+#include "ephy-file-chooser.h"
#include "ephy-history.h"
+#include "ephy-embed-factory.h"
#include "ephy-embed-shell.h"
#include "ephy-embed-single.h"
+#include "ephy-embed-persist.h"
#include "ephy-string.h"
#include "ephy-embed-event.h"
#include "ephy-embed-utils.h"
+#include "ephy-prefs.h"
#include <webkit/webkit.h>
#include <string.h>
@@ -377,6 +382,57 @@ mime_type_policy_decision_requested_cb (WebKitWebView *web_view,
return FALSE;
}
+
+static gboolean
+download_requested_cb (WebKitWebView *web_view,
+ WebKitDownload *download,
+ WebKitEmbed *embed)
+{
+ EphyFileChooser *dialog;
+
+ GtkWindow *window;
+
+ gint dialog_result;
+ gboolean handled = FALSE;
+
+ /* Try to get the toplevel window related to the WebView that caused the
+ * download, and use NULL otherwise; we don't want to pass the WebView
+ * or other widget as a parent window.
+ */
+ window = gtk_widget_get_toplevel (GTK_WIDGET(web_view));
+ if (!GTK_WIDGET_TOPLEVEL (window))
+ window = NULL;
+
+ dialog = ephy_file_chooser_new (_("Save"),
+ window ? GTK_WIDGET (window) : NULL,
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ CONF_STATE_SAVE_DIR,
+ EPHY_FILE_FILTER_ALL_SUPPORTED);
+ gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
+
+ gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog),
+ webkit_download_get_suggested_filename (download));
+
+ dialog_result = gtk_dialog_run (GTK_DIALOG (dialog));
+
+ if (dialog_result == GTK_RESPONSE_ACCEPT)
+ {
+ DownloaderView *dview;
+ char *uri;
+
+ uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER(dialog));
+ webkit_download_set_destination_uri (download, uri);
+
+ dview = EPHY_DOWNLOADER_VIEW (ephy_embed_shell_get_downloader_view (embed_shell));
+ downloader_view_add_download (dview, download);
+
+ handled = TRUE;
+ }
+
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+
+ return handled;
+}
static void
webkit_embed_init (WebKitEmbed *embed)
@@ -409,6 +465,7 @@ webkit_embed_init (WebKitEmbed *embed)
"signal::load-progress-changed", G_CALLBACK (load_progress_changed_cb), embed,
"signal::hovering-over-link", G_CALLBACK (hovering_over_link_cb), embed,
"signal::mime-type-policy-decision-requested", G_CALLBACK (mime_type_policy_decision_requested_cb), embed,
+ "signal::download-requested", G_CALLBACK (download_requested_cb), embed,
NULL);
g_signal_connect (web_view, "notify::zoom-level",