[epiphany] downloads: Do not add automatically the downloads to the UI when they are created



commit d7941bf07f72af1778cdcac66652d1e583620844
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Thu Jan 9 13:27:40 2014 +0100

    downloads: Do not add automatically the downloads to the UI when they are created
    
    This allows the creator to decide whether to add the download to the UI
    or not and when. The downloads are no longer handled by the
    EphyEmbedShell making clear who takes the ownership. Downloads are now
    explicitly added to a particular Ephywindow, instead of all the windows
    be notified by a download and deciding whether such download belongs to
    that particular window or not.

 embed/ephy-download.c    |    7 ---
 embed/ephy-embed-shell.c |   92 ----------------------------------------------
 embed/ephy-embed-shell.h |   10 -----
 embed/ephy-embed.c       |   10 -----
 embed/ephy-embed.h       |    2 -
 src/ephy-shell.c         |    6 ++-
 src/ephy-window.c        |   42 +++++++--------------
 src/ephy-window.h        |    4 ++
 src/popup-commands.c     |    4 ++
 9 files changed, 27 insertions(+), 150 deletions(-)
---
diff --git a/embed/ephy-download.c b/embed/ephy-download.c
index cddbf87..925bf11 100644
--- a/embed/ephy-download.c
+++ b/embed/ephy-download.c
@@ -595,8 +595,6 @@ ephy_download_dispose (GObject *object)
     priv->widget = NULL;
   }
 
-  ephy_embed_shell_remove_download (ephy_embed_shell_get_default (), download);
-
   G_OBJECT_CLASS (ephy_download_parent_class)->dispose (object);
 }
 
@@ -800,8 +798,6 @@ download_finished_cb (WebKitDownload *wk_download,
     ephy_download_do_download_action (download, EPHY_DOWNLOAD_ACTION_AUTO);
   else
     ephy_download_do_download_action (download, priv->action);
-
-  ephy_embed_shell_remove_download (ephy_embed_shell_get_default (), download);
 }
 
 static void
@@ -849,9 +845,6 @@ ephy_download_new (WebKitDownload *download,
   ephy_download->priv->download = g_object_ref (download);
   g_object_set_data (G_OBJECT (download), "ephy-download-set", GINT_TO_POINTER (TRUE));
 
-  /* In WebKit2 the download has already started */
-  ephy_embed_shell_add_download (ephy_embed_shell_get_default (), ephy_download);
-
   return ephy_download;
 }
 
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index ee57ff3..995b02b 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -24,7 +24,6 @@
 
 #include "ephy-about-handler.h"
 #include "ephy-debug.h"
-#include "ephy-download.h"
 #include "ephy-embed-prefs.h"
 #include "ephy-embed-private.h"
 #include "ephy-embed-type-builtins.h"
@@ -48,7 +47,6 @@
 struct _EphyEmbedShellPrivate
 {
   EphyHistoryService *global_history_service;
-  GList *downloads;
   EphyEncodings *encodings;
   GtkPageSetup *page_setup;
   GtkPrintSettings *print_settings;
@@ -62,8 +60,6 @@ struct _EphyEmbedShellPrivate
 
 enum
 {
-  DOWNLOAD_ADDED,
-  DOWNLOAD_REMOVED,
   PREPARE_CLOSE,
   RESTORED_WINDOW,
   WEB_VIEW_CREATED,
@@ -97,13 +93,6 @@ ephy_embed_shell_dispose (GObject *object)
   g_clear_object (&priv->print_settings);
   g_clear_object (&priv->frecent_store);
   g_clear_object (&priv->global_history_service);
-
-  if (priv->downloads != NULL) {
-    LOG ("Destroying downloads list");
-    g_list_free_full (priv->downloads, (GDestroyNotify)g_object_unref);
-    priv->downloads = NULL;
-  }
-
   g_clear_object (&priv->about_handler);
 
   G_OBJECT_CLASS (ephy_embed_shell_parent_class)->dispose (object);
@@ -440,8 +429,6 @@ ephy_embed_shell_init (EphyEmbedShell *shell)
   /* globally accessible singleton */
   g_assert (embed_shell == NULL);
   embed_shell = shell;
-
-  shell->priv->downloads = NULL;
 }
 
 static void
@@ -469,40 +456,6 @@ ephy_embed_shell_class_init (EphyEmbedShellClass *klass)
   g_object_class_install_properties (object_class,
                                      N_PROPERTIES,
                                      object_properties);
-  
-/**
- * EphyEmbed::download-added:
- * @shell: the #EphyEmbedShell
- * @download: the #EphyDownload added
- *
- * Emitted when a #EphyDownload has been added to the global watch list of
- * @shell, via ephy_embed_shell_add_download.
- **/
-  signals[DOWNLOAD_ADDED] =
-    g_signal_new ("download-added",
-                  EPHY_TYPE_EMBED_SHELL,
-                  G_SIGNAL_RUN_LAST,
-                  G_STRUCT_OFFSET (EphyEmbedShellClass, download_added),
-                  NULL, NULL,
-                  g_cclosure_marshal_VOID__OBJECT,
-                  G_TYPE_NONE, 1, EPHY_TYPE_DOWNLOAD);
-  
-/**
- * EphyEmbed::download-removed:
- * @shell: the #EphyEmbedShell
- * @download: the #EphyDownload being removed
- *
- * Emitted when a #EphyDownload has been removed from the global watch list of
- * @shell, via ephy_embed_shell_remove_download.
- **/
-  signals[DOWNLOAD_REMOVED] =
-    g_signal_new ("download-removed",
-                  EPHY_TYPE_EMBED_SHELL,
-                  G_SIGNAL_RUN_LAST,
-                  G_STRUCT_OFFSET (EphyEmbedShellClass, download_removed),
-                  NULL, NULL,
-                  g_cclosure_marshal_VOID__OBJECT,
-                  G_TYPE_NONE, 1, EPHY_TYPE_DOWNLOAD);
 
 /**
  * EphyEmbed::prepare-close:
@@ -720,51 +673,6 @@ ephy_embed_shell_get_print_settings (EphyEmbedShell *shell)
 }
 
 /**
- * ephy_embed_shell_get_downloads:
- * @shell: the #EphyEmbedShell
- *
- * Gets the global #GList object listing active downloads.
- *
- * Returns: (transfer none) (element-type EphyDownload): a #GList object
- **/
-GList *
-ephy_embed_shell_get_downloads (EphyEmbedShell *shell)
-{
-  EphyEmbedShellPrivate *priv;
-
-  g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), NULL);
-  priv = shell->priv;
-
-  return priv->downloads;
-}
-
-void
-ephy_embed_shell_add_download (EphyEmbedShell *shell, EphyDownload *download)
-{
-  EphyEmbedShellPrivate *priv;
-
-  g_return_if_fail (EPHY_IS_EMBED_SHELL (shell));
-
-  priv = shell->priv;
-  priv->downloads = g_list_prepend (priv->downloads, download);
-
-  g_signal_emit_by_name (shell, "download-added", download, NULL);
-}
-
-void
-ephy_embed_shell_remove_download (EphyEmbedShell *shell, EphyDownload *download)
-{
-  EphyEmbedShellPrivate *priv;
-
-  g_return_if_fail (EPHY_IS_EMBED_SHELL (shell));
-
-  priv = shell->priv;
-  priv->downloads = g_list_remove (priv->downloads, download);
-
-  g_signal_emit_by_name (shell, "download-removed", download, NULL);
-}
-
-/**
  * ephy_embed_shell_get_mode:
  * @shell: an #EphyEmbedShell
  * 
diff --git a/embed/ephy-embed-shell.h b/embed/ephy-embed-shell.h
index e73d3f1..02016c8 100644
--- a/embed/ephy-embed-shell.h
+++ b/embed/ephy-embed-shell.h
@@ -28,8 +28,6 @@
 
 #include <gtk/gtk.h>
 
-#include "ephy-download.h"
-
 G_BEGIN_DECLS
 
 #define EPHY_TYPE_EMBED_SHELL   (ephy_embed_shell_get_type ())
@@ -68,9 +66,6 @@ struct _EphyEmbedShellClass
 {
   GtkApplicationClass parent_class;
 
-  void    (* download_added)   (EphyEmbedShell *shell, EphyDownload *download);
-  void    (* download_removed) (EphyEmbedShell *shell, EphyDownload *download);
-
   void    (* prepare_close)    (EphyEmbedShell *shell);
 
   void    (* restored_window)  (EphyEmbedShell *shell);
@@ -88,11 +83,6 @@ GtkPageSetup      *ephy_embed_shell_get_page_setup             (EphyEmbedShell
 void               ephy_embed_shell_set_print_settings         (EphyEmbedShell   *shell,
                                                                 GtkPrintSettings *settings);
 GtkPrintSettings  *ephy_embed_shell_get_print_settings         (EphyEmbedShell   *shell);
-GList             *ephy_embed_shell_get_downloads              (EphyEmbedShell   *shell);
-void               ephy_embed_shell_add_download               (EphyEmbedShell   *shell,
-                                                                EphyDownload     *download);
-void               ephy_embed_shell_remove_download            (EphyEmbedShell   *shell,
-                                                                EphyDownload     *download);
 EphyEmbedShellMode ephy_embed_shell_get_mode                   (EphyEmbedShell   *shell);
 gboolean           ephy_embed_shell_launch_handler             (EphyEmbedShell   *shell,
                                                                 GFile            *file,
diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c
index 5121c90..34bb0c6 100644
--- a/embed/ephy-embed.c
+++ b/embed/ephy-embed.c
@@ -27,7 +27,6 @@
 #include "ephy-embed.h"
 
 #include "ephy-debug.h"
-#include "ephy-download.h"
 #include "ephy-embed-prefs.h"
 #include "ephy-embed-shell.h"
 #include "ephy-find-toolbar.h"
@@ -481,15 +480,6 @@ ephy_embed_attach_inspector_cb (WebKitWebInspector *inspector,
   return TRUE;
 }
 
-void
-ephy_embed_auto_download_url (EphyEmbed *embed, const char *url)
-{
-  EphyDownload *download;
-
-  download = ephy_download_new_for_uri (url, NULL);
-  ephy_download_set_action (download, EPHY_DOWNLOAD_ACTION_OPEN);
-}
-
 static void
 ephy_embed_set_fullscreen_message (EphyEmbed *embed,
                                    gboolean is_html5_fullscreen)
diff --git a/embed/ephy-embed.h b/embed/ephy-embed.h
index d599ab3..8aaa9a3 100644
--- a/embed/ephy-embed.h
+++ b/embed/ephy-embed.h
@@ -60,8 +60,6 @@ void             ephy_embed_add_top_widget           (EphyEmbed  *embed,
                                                       gboolean    destroy_on_transition);
 void             ephy_embed_remove_top_widget        (EphyEmbed  *embed,
                                                       GtkWidget  *widget);
-void             ephy_embed_auto_download_url        (EphyEmbed  *embed,
-                                                      const char *url);
 void             ephy_embed_entering_fullscreen      (EphyEmbed *embed);
 void             ephy_embed_leaving_fullscreen       (EphyEmbed *embed);
 void             ephy_embed_set_delayed_load_request (EphyEmbed *embed,
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index c6e3a55..a84a7ac 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -26,6 +26,7 @@
 #include "ephy-bookmarks-editor.h"
 #include "ephy-bookmarks-import.h"
 #include "ephy-debug.h"
+#include "ephy-download.h"
 #include "ephy-embed-container.h"
 #include "ephy-embed-utils.h"
 #include "ephy-file-helpers.h"
@@ -521,6 +522,7 @@ download_started_cb (WebKitWebContext *web_context,
 {
   GtkWindow *window = NULL;
   WebKitWebView *web_view;
+  EphyDownload *ephy_download;
   gboolean ephy_download_set;
 
   /* Is download locked down? */
@@ -551,7 +553,9 @@ download_started_cb (WebKitWebContext *web_context,
   if (!window)
     window = gtk_application_get_active_window (GTK_APPLICATION (shell));
 
-  ephy_download_new (download, window);
+  ephy_download = ephy_download_new (download, window);
+  ephy_window_add_download (EPHY_WINDOW (window), ephy_download);
+  g_object_unref (ephy_download);
 }
 
 static void
diff --git a/src/ephy-window.c b/src/ephy-window.c
index d6331d9..0122c40 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -29,7 +29,6 @@
 #include "ephy-combined-stop-reload-action.h"
 #include "ephy-debug.h"
 #include "ephy-download-widget.h"
-#include "ephy-download.h"
 #include "ephy-embed-container.h"
 #include "ephy-embed-prefs.h"
 #include "ephy-embed-shell.h"
@@ -1904,7 +1903,12 @@ save_target_uri (EphyWindow *window,
                retval = ephy_embed_utils_address_has_web_scheme (location);
                if (retval)
                {
-                       ephy_embed_auto_download_url (EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW (view), location);
+                       EphyDownload *download;
+
+                       download = ephy_download_new_for_uri (location, GTK_WINDOW (window));
+                       ephy_download_set_action (download, EPHY_DOWNLOAD_ACTION_OPEN);
+                       ephy_window_add_download (window, download);
+                       g_object_unref (download);
                }
 
                g_free (location);
@@ -2863,27 +2867,17 @@ ephy_window_set_downloads_box_visibility (EphyWindow *window,
        }
 }
 
-static void
-download_added_cb (EphyEmbedShell *shell,
-                  EphyDownload *download,
-                  gpointer data)
+void
+ephy_window_add_download (EphyWindow *window,
+                         EphyDownload *download)
 {
-       EphyWindow *window = EPHY_WINDOW (data);
-       GtkWindow *download_window;
        GtkWidget *widget;
 
-       download_window = ephy_download_get_window (download);
-       widget = ephy_download_get_widget (download);
-
-       if (widget == NULL &&
-           (download_window == NULL || download_window == GTK_WINDOW (window)))
-       {
-               widget = ephy_download_widget_new (download);
-               gtk_box_pack_start (GTK_BOX (window->priv->downloads_box),
-                                   widget, FALSE, FALSE, 0);
-               gtk_widget_show (widget);
-               ephy_window_set_downloads_box_visibility (window, TRUE);
-       }
+       widget = ephy_download_widget_new (download);
+       gtk_box_pack_start (GTK_BOX (window->priv->downloads_box),
+                           widget, FALSE, FALSE, 0);
+       gtk_widget_show (widget);
+       ephy_window_set_downloads_box_visibility (window, TRUE);
 }
 
 static void
@@ -2971,10 +2965,6 @@ ephy_window_dispose (GObject *object)
 
                ephy_bookmarks_ui_detach_window (window);
 
-               g_signal_handlers_disconnect_by_func
-                       (ephy_embed_shell_get_default (),
-                        download_added_cb, window);
-
                /* Deactivate menus */
                popups = gtk_ui_manager_get_toplevels (window->priv->manager, GTK_UI_MANAGER_POPUP);
                g_slist_foreach (popups, (GFunc) gtk_menu_shell_deactivate, NULL);
@@ -3605,10 +3595,6 @@ ephy_window_init (EphyWindow *window)
        LOG ("EphyWindow initialising %p", window);
 
        window->priv = EPHY_WINDOW_GET_PRIVATE (window);
-
-       g_signal_connect (ephy_embed_shell_get_default (),
-                        "download-added", G_CALLBACK (download_added_cb),
-                        window);
 }
 
 /**
diff --git a/src/ephy-window.h b/src/ephy-window.h
index e284111..b1ac400 100644
--- a/src/ephy-window.h
+++ b/src/ephy-window.h
@@ -24,6 +24,7 @@
 #ifndef EPHY_WINDOW_H
 #define EPHY_WINDOW_H
 
+#include "ephy-download.h"
 #include "ephy-web-view.h"
 
 #include <gtk/gtk.h>
@@ -76,6 +77,9 @@ const char       *ephy_window_get_location        (EphyWindow *window);
 
 gboolean          ephy_window_close               (EphyWindow *window);
 
+void              ephy_window_add_download        (EphyWindow *window,
+                                                   EphyDownload *download);
+
 gboolean      ephy_window_is_on_current_workspace (EphyWindow *window);
 
 G_END_DECLS
diff --git a/src/popup-commands.c b/src/popup-commands.c
index 0e5ac0d..5146b25 100644
--- a/src/popup-commands.c
+++ b/src/popup-commands.c
@@ -161,6 +161,8 @@ save_property_url_to_destination (EphyWindow *window,
 
        if (destination)
                ephy_download_set_destination_uri (download, destination);
+       ephy_window_add_download (window, download);
+       g_object_unref (download);
 }
 
 static void
@@ -304,6 +306,8 @@ popup_cmd_set_image_as_background (GtkAction *action,
 
        ephy_download_set_destination_uri (download, dest_uri);
        ephy_download_set_action (download, EPHY_DOWNLOAD_ACTION_DO_NOTHING);
+       ephy_window_add_download (window, download);
+       g_object_unref (download);
 
        g_signal_connect (download, "completed",
                          G_CALLBACK (background_download_completed), window);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]