[epiphany/wip/downloads: 8/10] downloads: Remove the window property of EphyDownload
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/downloads: 8/10] downloads: Remove the window property of EphyDownload
- Date: Wed, 7 Oct 2015 15:25:57 +0000 (UTC)
commit 07b0a2649a94569aa43e274da9def58433a79f1d
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Wed Oct 7 12:47:16 2015 +0200
downloads: Remove the window property of EphyDownload
Downloads are global now, we no longer need to associate them to a window.
embed/ephy-download.c | 71 ++++----------------------------------------
embed/ephy-download.h | 8 +----
src/ephy-shell.c | 15 +--------
src/ephy-window.c | 2 +-
src/popup-commands.c | 28 +++++++++++------
tests/ephy-download-test.c | 2 +-
6 files changed, 29 insertions(+), 97 deletions(-)
---
diff --git a/embed/ephy-download.c b/embed/ephy-download.c
index 603a966..e1cc90e 100644
--- a/embed/ephy-download.c
+++ b/embed/ephy-download.c
@@ -53,8 +53,6 @@ struct _EphyDownloadPrivate
guint32 start_time;
gboolean finished;
GError *error;
-
- GtkWindow *window;
};
enum
@@ -63,8 +61,7 @@ enum
PROP_DOWNLOAD,
PROP_DESTINATION,
PROP_ACTION,
- PROP_START_TIME,
- PROP_WINDOW
+ PROP_START_TIME
};
enum
@@ -84,16 +81,9 @@ ephy_download_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- EphyDownload *download;
- EphyDownloadPrivate *priv;
-
- download = EPHY_DOWNLOAD (object);
- priv = download->priv;
+ EphyDownload *download = EPHY_DOWNLOAD (object);
switch (property_id) {
- case PROP_WINDOW:
- g_value_set_object (value, priv->window);
- break;
case PROP_DOWNLOAD:
g_value_set_object (value, ephy_download_get_webkit_download (download));
break;
@@ -128,9 +118,6 @@ ephy_download_set_property (GObject *object,
case PROP_ACTION:
ephy_download_set_action (download, g_value_get_enum (value));
break;
- case PROP_WINDOW:
- download->priv->window = g_value_dup_object (value);
- break;
case PROP_DOWNLOAD:
case PROP_START_TIME:
default:
@@ -397,23 +384,6 @@ ephy_download_get_webkit_download (EphyDownload *download)
}
/**
- * ephy_download_get_window:
- * @download: an #EphyDownload
- *
- * Gets the window set as the parent of @download, this can be %NULL if no
- * specific window generated this download.
- *
- * Returns: (transfer none): a #GtkWindow
- **/
-GtkWindow *
-ephy_download_get_window (EphyDownload *download)
-{
- g_return_val_if_fail (EPHY_IS_DOWNLOAD (download), NULL);
-
- return download->priv->window;
-}
-
-/**
* ephy_download_get_destination_uri:
* @download: an #EphyDownload
*
@@ -584,11 +554,6 @@ ephy_download_dispose (GObject *object)
priv->download = NULL;
}
- if (priv->window) {
- g_object_unref (priv->window);
- priv->window = NULL;
- }
-
g_clear_error(&priv->error);
G_OBJECT_CLASS (ephy_download_parent_class)->dispose (object);
@@ -670,23 +635,6 @@ ephy_download_class_init (EphyDownloadClass *klass)
G_PARAM_STATIC_BLURB));
/**
- * EphyDownload:window:
- *
- * Window that produced the download, the download will be shown in its
- * parent window.
- */
- g_object_class_install_property (object_class, PROP_WINDOW,
- g_param_spec_object ("window",
- "A GtkWindow",
- "Window that produced this download.",
- GTK_TYPE_WINDOW,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_NAME |
- G_PARAM_STATIC_NICK |
- G_PARAM_STATIC_BLURB));
-
- /**
* EphyDownload::filename-suggested:
*
* The ::filename-suggested signal is emitted when we have received the
@@ -742,8 +690,6 @@ ephy_download_init (EphyDownload *download)
download->priv->action = EPHY_DOWNLOAD_ACTION_NONE;
download->priv->start_time = gtk_get_current_event_time ();
-
- download->priv->window = NULL;
}
static gboolean
@@ -796,21 +742,19 @@ download_failed_cb (WebKitDownload *wk_download,
/**
* ephy_download_new:
* @download: a #WebKitDownload to wrap
- * @parent: the #GtkWindow parent of the download, or %NULL
*
* Wraps @download in an #EphyDownload.
*
* Returns: an #EphyDownload.
**/
EphyDownload *
-ephy_download_new (WebKitDownload *download,
- GtkWindow *parent)
+ephy_download_new (WebKitDownload *download)
{
EphyDownload *ephy_download;
g_return_val_if_fail (WEBKIT_IS_DOWNLOAD (download), NULL);
- ephy_download = g_object_new (EPHY_TYPE_DOWNLOAD, "window", parent, NULL);
+ ephy_download = g_object_new (EPHY_TYPE_DOWNLOAD, NULL);
g_signal_connect (download, "decide-destination",
G_CALLBACK (download_decide_destination_cb),
@@ -831,15 +775,13 @@ ephy_download_new (WebKitDownload *download,
/**
* ephy_download_new_for_uri:
* @uri: a source URI from where to download
- * @parent: the #GtkWindow parent of the download, or %NULL
*
* Creates an #EphyDownload to download @uri.
*
* Returns: an #EphyDownload.
**/
EphyDownload *
-ephy_download_new_for_uri (const char *uri,
- GtkWindow *parent)
+ephy_download_new_for_uri (const char *uri)
{
EphyDownload *ephy_download;
WebKitDownload *download;
@@ -848,8 +790,7 @@ ephy_download_new_for_uri (const char *uri,
g_return_val_if_fail (uri != NULL, NULL);
download = webkit_web_context_download_uri (ephy_embed_shell_get_web_context (shell), uri);
-
- ephy_download = ephy_download_new (download, parent);
+ ephy_download = ephy_download_new (download);
g_object_unref (download);
return ephy_download;
diff --git a/embed/ephy-download.h b/embed/ephy-download.h
index 0f6053a..d95190c 100644
--- a/embed/ephy-download.h
+++ b/embed/ephy-download.h
@@ -68,10 +68,8 @@ typedef enum
GType ephy_download_get_type (void) G_GNUC_CONST;
-EphyDownload *ephy_download_new (WebKitDownload *download,
- GtkWindow *parent);
-EphyDownload *ephy_download_new_for_uri (const char *uri,
- GtkWindow *parent);
+EphyDownload *ephy_download_new (WebKitDownload *download);
+EphyDownload *ephy_download_new_for_uri (const char *uri);
void ephy_download_cancel (EphyDownload *download);
gboolean ephy_download_is_active (EphyDownload *download);
@@ -89,8 +87,6 @@ char *ephy_download_get_content_type (EphyDownload *download);
guint32 ephy_download_get_start_time (EphyDownload *download);
-GtkWindow *ephy_download_get_window (EphyDownload *download);
-
EphyDownloadActionType ephy_download_get_action (EphyDownload *download);
void ephy_download_set_action (EphyDownload *download,
EphyDownloadActionType action);
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index 28f2df7..e1f6797 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -260,7 +260,6 @@ download_started_cb (WebKitWebContext *web_context,
WebKitDownload *download,
EphyShell *shell)
{
- GtkWindow *window = NULL;
WebKitWebView *web_view;
EphyDownload *ephy_download;
gboolean ephy_download_set;
@@ -281,19 +280,7 @@ download_started_cb (WebKitWebContext *web_context,
if (ephy_download_set)
return;
- web_view = webkit_download_get_web_view (download);
- if (web_view) {
- GtkWidget *toplevel;
-
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (web_view));
- if (GTK_IS_WINDOW (toplevel))
- window = GTK_WINDOW (toplevel);
- }
-
- if (!window)
- window = gtk_application_get_active_window (GTK_APPLICATION (shell));
-
- ephy_download = ephy_download_new (download, window);
+ ephy_download = ephy_download_new (download);
ephy_downloads_manager_add_download (ephy_embed_shell_get_downloads_manager (EPHY_EMBED_SHELL (shell)),
ephy_download);
g_object_unref (ephy_download);
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 4c2cde6..eca73c1 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -1969,7 +1969,7 @@ save_target_uri (EphyWindow *window,
{
EphyDownload *download;
- download = ephy_download_new_for_uri (location, GTK_WINDOW (window));
+ download = ephy_download_new_for_uri (location);
ephy_download_set_action (download, EPHY_DOWNLOAD_ACTION_OPEN);
ephy_downloads_manager_add_download (ephy_embed_shell_get_downloads_manager
(EPHY_EMBED_SHELL (ephy_shell_get_default ())),
download);
diff --git a/src/popup-commands.c b/src/popup-commands.c
index d4541d4..e3d2287 100644
--- a/src/popup-commands.c
+++ b/src/popup-commands.c
@@ -149,19 +149,21 @@ cancel_download_idle_cb (EphyDownload *download)
return FALSE;
}
+typedef struct {
+ char *title;
+ EphyWindow *window;
+} SavePropertyURLData;
+
static void
filename_suggested_cb (EphyDownload *download,
const char *suggested_filename,
- char *title)
+ SavePropertyURLData *data)
{
- EphyWindow *window;
EphyFileChooser *dialog;
char *sanitized_filename;
- window = EPHY_WINDOW (ephy_download_get_window (download));
-
- dialog = ephy_file_chooser_new (title,
- GTK_WIDGET (window),
+ dialog = ephy_file_chooser_new (data->title,
+ GTK_WIDGET (data->window),
GTK_FILE_CHOOSER_ACTION_SAVE,
EPHY_FILE_FILTER_NONE);
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
@@ -195,7 +197,9 @@ filename_suggested_cb (EphyDownload *download,
}
gtk_widget_destroy (GTK_WIDGET (dialog));
- g_free (title);
+ g_free (data->title);
+ g_object_unref (data->window);
+ g_free (data);
g_object_unref (download);
}
@@ -208,6 +212,7 @@ save_property_url (const char *title,
EphyEmbedEvent *event;
const char *location;
EphyDownload *download;
+ SavePropertyURLData *data;
GValue value = { 0, };
event = ephy_window_get_context_event (window);
@@ -215,10 +220,13 @@ save_property_url (const char *title,
ephy_embed_event_get_property (event, property, &value);
location = g_value_get_string (&value);
- download = ephy_download_new_for_uri (location, GTK_WINDOW (window));
+ download = ephy_download_new_for_uri (location);
+ data = g_new (SavePropertyURLData, 1);
+ data->title = g_strdup (title);
+ data->window = g_object_ref (window);
g_signal_connect (download, "filename-suggested",
G_CALLBACK (filename_suggested_cb),
- g_strdup (title));
+ data);
g_value_unset (&value);
}
@@ -272,7 +280,7 @@ popup_cmd_set_image_as_background (GtkAction *action,
ephy_embed_event_get_property (event, "image-uri", &value);
location = g_value_get_string (&value);
- download = ephy_download_new_for_uri (location, GTK_WINDOW (window));
+ download = ephy_download_new_for_uri (location);
base = g_path_get_basename (location);
base_converted = g_filename_from_utf8 (base, -1, NULL, NULL, NULL);
diff --git a/tests/ephy-download-test.c b/tests/ephy-download-test.c
index f3838e3..237de92 100644
--- a/tests/ephy-download-test.c
+++ b/tests/ephy-download-test.c
@@ -88,7 +88,7 @@ fixture_setup (Fixture *fixture, gconstpointer data)
dest_file = g_build_filename (ephy_file_tmp_dir (), tmp_filename, NULL);
fixture->source = get_uri_for_path ("/default");
- fixture->download = ephy_download_new_for_uri (fixture->source, NULL);
+ fixture->download = ephy_download_new_for_uri (fixture->source);
fixture->destination = g_filename_to_uri (dest_file, NULL, NULL);
fixture->loop = g_main_loop_new (NULL, TRUE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]