[epiphany] ephy-download: Make EphyDownload:window a construct only property



commit 8ed26c6a506feec75e37cf285450a23ac7c8a689
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Fri Jan 4 10:54:26 2013 +0100

    ephy-download: Make EphyDownload:window a construct only property
    
    It's always set right after the download object is created and it
    doesn't have any effect when it's set after the download has been added
    to the embed shell. This way we can make sure that when the download is
    added to the embed shell the parent window has already been set if
    there's any.

 embed/ephy-download.c      |   57 ++++++++++++++-----------------------------
 embed/ephy-download.h      |   12 ++++----
 embed/ephy-embed.c         |   12 +++++----
 src/ephy-shell.c           |    4 +--
 src/popup-commands.c       |    8 ++----
 tests/ephy-download-test.c |    2 +-
 6 files changed, 37 insertions(+), 58 deletions(-)
---
diff --git a/embed/ephy-download.c b/embed/ephy-download.c
index 2713b75..988a0ab 100644
--- a/embed/ephy-download.c
+++ b/embed/ephy-download.c
@@ -52,7 +52,7 @@ struct _EphyDownloadPrivate
   EphyDownloadActionType action;
   guint32 start_time;
 
-  GtkWidget *window;
+  GtkWindow *window;
   GtkWidget *widget;
 };
 
@@ -125,7 +125,7 @@ ephy_download_set_property (GObject      *object,
       ephy_download_set_action (download, g_value_get_enum (value));
       break;
     case PROP_WINDOW:
-      ephy_download_set_window (download, g_value_get_object (value));
+      download->priv->window = g_value_dup_object (value);
       break;
     case PROP_WIDGET:
       ephy_download_set_widget (download, g_value_get_object (value));
@@ -427,31 +427,6 @@ ephy_download_set_action (EphyDownload *download,
 }
 
 /**
- * ephy_download_set_window:
- * @download: an #EphyDownload
- * @window: #GtkWidget that produced @download
- *
- * Sets @window to be @download's parent, this means that @download will be
- * shown on @window's #EphyWindow (where it is contained).
- **/
-void
-ephy_download_set_window (EphyDownload *download,
-                          GtkWidget *window)
-{
-  g_return_if_fail (EPHY_IS_DOWNLOAD (download));
-
-  if (download->priv->window != NULL)
-    g_object_unref (download->priv->window);
-
-  download->priv->window = NULL;
-
-  if (window != NULL)
-    download->priv->window = g_object_ref (window);
-
-  g_object_notify (G_OBJECT (download), "window");
-}
-
-/**
  * ephy_download_set_widget:
  * @download: an #EphyDownload
  * @widget: a #GtkWidget
@@ -511,12 +486,12 @@ 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
+ * Gets the window set as the parent of @download, this can be %NULL if no
  * specific window generated this download.
  *
- * Returns: (transfer none): a #GtkWidget
+ * Returns: (transfer none): a #GtkWindow
  **/
-GtkWidget *
+GtkWindow *
 ephy_download_get_window (EphyDownload *download)
 {
   g_return_val_if_fail (EPHY_IS_DOWNLOAD (download), NULL);
@@ -828,7 +803,7 @@ ephy_download_class_init (EphyDownloadClass *klass)
                                                       G_PARAM_STATIC_BLURB));
 
   /**
-   * EphyDownload::window:
+   * EphyDownload:window:
    *
    * Window that produced the download, the download will be shown in its
    * parent window.
@@ -837,8 +812,9 @@ ephy_download_class_init (EphyDownloadClass *klass)
                                    g_param_spec_object ("window",
                                                         "A GtkWindow",
                                                         "Window that produced this download.",
-                                                        GTK_TYPE_WIDGET,
+                                                        GTK_TYPE_WINDOW,
                                                         G_PARAM_READWRITE |
+                                                        G_PARAM_CONSTRUCT_ONLY |
                                                         G_PARAM_STATIC_NAME |
                                                         G_PARAM_STATIC_NICK |
                                                         G_PARAM_STATIC_BLURB));
@@ -1026,6 +1002,7 @@ download_error_cb (WebKitDownload *download,
 
 /**
  * ephy_download_new:
+ * @parent: the #GtkWindow parent of the download, or %NULL
  *
  * Creates a new #EphyDownload. You can use ephy_download_new_for_download and
  * ephy_download_new_for_uri as convenience functions to create #EphyDownload
@@ -1034,21 +1011,23 @@ download_error_cb (WebKitDownload *download,
  * Returns: an #EphyDownload.
  **/
 EphyDownload *
-ephy_download_new (void)
+ephy_download_new (GtkWindow *parent)
 {
-  return g_object_new (EPHY_TYPE_DOWNLOAD, NULL);
+  return g_object_new (EPHY_TYPE_DOWNLOAD, "window", parent, NULL);
 }
 
 /**
  * ephy_download_new_for_download:
  * @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_for_download (WebKitDownload *download)
+ephy_download_new_for_download (WebKitDownload *download,
+                                GtkWindow *parent)
 {
   EphyDownload *ephy_download;
 #ifdef HAVE_WEBKIT2
@@ -1057,7 +1036,7 @@ ephy_download_new_for_download (WebKitDownload *download)
 
   g_return_val_if_fail (WEBKIT_IS_DOWNLOAD (download), NULL);
 
-  ephy_download = ephy_download_new ();
+  ephy_download = ephy_download_new (parent);
 
 #ifdef HAVE_WEBKIT2
   g_signal_connect (download, "decide-destination",
@@ -1100,13 +1079,15 @@ ephy_download_new_for_download (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)
+ephy_download_new_for_uri (const char *uri,
+                           GtkWindow *parent)
 {
   EphyDownload *ephy_download;
   WebKitDownload *download;
@@ -1126,7 +1107,7 @@ ephy_download_new_for_uri (const char *uri)
   g_object_unref (request);
 #endif
 
-  ephy_download = ephy_download_new_for_download (download);
+  ephy_download = ephy_download_new_for_download (download, parent);
   g_object_unref (download);
 
   return ephy_download;
diff --git a/embed/ephy-download.h b/embed/ephy-download.h
index e4efeb3..902ae57 100644
--- a/embed/ephy-download.h
+++ b/embed/ephy-download.h
@@ -78,9 +78,11 @@ typedef enum
 
 GType         ephy_download_get_type              (void) G_GNUC_CONST;
 
-EphyDownload *ephy_download_new                   (void);
-EphyDownload *ephy_download_new_for_uri           (const char *uri);
-EphyDownload *ephy_download_new_for_download      (WebKitDownload *download);
+EphyDownload *ephy_download_new                   (GtkWindow *parent);
+EphyDownload *ephy_download_new_for_uri           (const char *uri,
+                                                   GtkWindow *parent);
+EphyDownload *ephy_download_new_for_download      (WebKitDownload *download,
+                                                   GtkWindow *parent);
 
 
 void          ephy_download_start                 (EphyDownload *download);
@@ -99,9 +101,7 @@ char         *ephy_download_get_content_type      (EphyDownload *download);
 
 guint32       ephy_download_get_start_time        (EphyDownload *download);
 
-GtkWidget    *ephy_download_get_window            (EphyDownload *download);
-void          ephy_download_set_window            (EphyDownload *download,
-                                                   GtkWidget *window);
+GtkWindow    *ephy_download_get_window            (EphyDownload *download);
 
 EphyDownloadActionType ephy_download_get_action   (EphyDownload *download);
 void          ephy_download_set_action            (EphyDownload *download,
diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c
index c66dad3..dca8642 100644
--- a/embed/ephy-embed.c
+++ b/embed/ephy-embed.c
@@ -635,7 +635,7 @@ ephy_embed_auto_download_url (EphyEmbed *embed, const char *url)
 {
   EphyDownload *download;
 
-  download = ephy_download_new_for_uri (url);
+  download = ephy_download_new_for_uri (url, NULL);
   ephy_download_set_auto_destination (download);
   ephy_download_set_action (download, EPHY_DOWNLOAD_ACTION_OPEN);
 }
@@ -647,17 +647,19 @@ download_requested_cb (WebKitWebView *web_view,
                        EphyEmbed *embed)
 {
   EphyDownload *ed;
-  GtkWidget *window;
+  GtkWidget *toplevel;
+  GtkWindow *window = NULL;
 
   /* Is download locked down? */
   if (g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN,
                               EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK))
     return FALSE;
 
-  window = gtk_widget_get_toplevel (GTK_WIDGET (embed));
+  toplevel = gtk_widget_get_toplevel (GTK_WIDGET (embed));
+  if (GTK_IS_WINDOW (toplevel))
+    window = GTK_WINDOW (toplevel);
 
-  ed = ephy_download_new_for_download (download);
-  ephy_download_set_window (ed, window);
+  ed = ephy_download_new_for_download (download, window);
   ephy_download_set_auto_destination (ed);
 
   return TRUE;
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index a44c923..6afb298 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -606,9 +606,7 @@ download_started_cb (WebKitWebContext *web_context,
   }
 
   window = gtk_application_get_active_window (GTK_APPLICATION (shell));
-
-  ed = ephy_download_new_for_download (download);
-  ephy_download_set_window (ed, GTK_WIDGET (window));
+  ed = ephy_download_new_for_download (download, GTK_WINDOW (window));
 }
 #endif
 
diff --git a/src/popup-commands.c b/src/popup-commands.c
index e010c26..c917788 100644
--- a/src/popup-commands.c
+++ b/src/popup-commands.c
@@ -245,8 +245,7 @@ save_property_url (GtkAction *action,
 	ephy_embed_event_get_property (event, property, &value);
 	location = g_value_get_string (&value);
 
-	download = ephy_download_new_for_uri (location);
-	ephy_download_set_window (download, GTK_WIDGET (window));
+	download = ephy_download_new_for_uri (location, GTK_WINDOW (window));
 
 	if (ask_dest)
 	{
@@ -348,8 +347,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);
-	ephy_download_set_window (download, GTK_WIDGET (window));
+	download = ephy_download_new_for_uri (location, GTK_WINDOW (window));
 
 	base = g_path_get_basename (location);
 	base_converted = g_filename_from_utf8 (base, -1, NULL, NULL, NULL);
@@ -459,7 +457,7 @@ save_temp_source (const char *address)
 	if (dest == NULL) return;
 
 	dest_uri = g_filename_to_uri (dest, NULL, NULL);
-	download = ephy_download_new_for_uri (address);
+	download = ephy_download_new_for_uri (address, NULL);
 	ephy_download_set_destination_uri (download, dest_uri);
 
 	g_signal_connect (download, "completed",
diff --git a/tests/ephy-download-test.c b/tests/ephy-download-test.c
index 475aa03..d2b9863 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);
+  fixture->download = ephy_download_new_for_uri (fixture->source, NULL);
   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]