diff options
author | Diego Escalante Urrelo <descalante@igalia.com> | 2011-01-19 00:10:11 +0800 |
---|---|---|
committer | Diego Escalante Urrelo <descalante@igalia.com> | 2011-03-08 04:34:52 +0800 |
commit | b9f9bf1a0763492f8bf41b8856bbd1149c5871a9 (patch) | |
tree | 92ad55101bff9eabcbc17afdba4a398ce4c4b709 /embed/ephy-embed-shell.c | |
parent | 7f7826a163f31bb662247ac4486dca0d01df35f6 (diff) | |
download | gsoc2013-epiphany-b9f9bf1a0763492f8bf41b8856bbd1149c5871a9.tar gsoc2013-epiphany-b9f9bf1a0763492f8bf41b8856bbd1149c5871a9.tar.gz gsoc2013-epiphany-b9f9bf1a0763492f8bf41b8856bbd1149c5871a9.tar.bz2 gsoc2013-epiphany-b9f9bf1a0763492f8bf41b8856bbd1149c5871a9.tar.lz gsoc2013-epiphany-b9f9bf1a0763492f8bf41b8856bbd1149c5871a9.tar.xz gsoc2013-epiphany-b9f9bf1a0763492f8bf41b8856bbd1149c5871a9.tar.zst gsoc2013-epiphany-b9f9bf1a0763492f8bf41b8856bbd1149c5871a9.zip |
ephy-download: add the new EphyDownload object
EphyDownload is a wrapper object around WebKitDownload that handles common
behavior in downloads: auto-destination, default action for the MIME type.
It can be used to wrap a WebKitDownload coming from a WebKitView or to download
a url: ephy_download_new_for_uri and ephy_download_new_for_download are
provided.
Its lifetime is not automagic like EphyEmbedPersist, so you have to unref it
when you no longer need it.
This new object replaces EphyEmbedPersist and enables us to use a single
codepath for downloads in all Epiphany.
Bug #618443
Diffstat (limited to 'embed/ephy-embed-shell.c')
-rw-r--r-- | embed/ephy-embed-shell.c | 144 |
1 files changed, 93 insertions, 51 deletions
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c index 3fcf7ee82..a0d77cdc6 100644 --- a/embed/ephy-embed-shell.c +++ b/embed/ephy-embed-shell.c @@ -25,9 +25,9 @@ #include <glib/gstdio.h> #include <gtk/gtk.h> -#include "downloader-view.h" #include "ephy-adblock-manager.h" #include "ephy-debug.h" +#include "ephy-download.h" #include "ephy-embed-shell.h" #include "ephy-embed-single.h" #include "ephy-encodings.h" @@ -50,7 +50,7 @@ struct _EphyEmbedShellPrivate { EphyHistory *global_history; - DownloaderView *downloader_view; + GList *downloads; EphyFaviconCache *favicon_cache; EphyEmbedSingle *embed_single; EphyEncodings *encodings; @@ -63,6 +63,8 @@ struct _EphyEmbedShellPrivate enum { + DOWNLOAD_ADDED, + DOWNLOAD_REMOVED, PREPARE_CLOSE, QUIT, LAST_SIGNAL @@ -83,17 +85,6 @@ ephy_embed_shell_dispose (GObject *object) EphyEmbedShell *shell = EPHY_EMBED_SHELL (object); EphyEmbedShellPrivate *priv = shell->priv; - if (priv->downloader_view != NULL) - { - DownloaderView **downloader_view = &priv->downloader_view; - LOG ("Unref downloader"); - g_object_remove_weak_pointer - (G_OBJECT (priv->downloader_view), - (gpointer *) downloader_view); - g_object_unref (priv->downloader_view); - priv->downloader_view = NULL; - } - if (priv->favicon_cache != NULL) { LOG ("Unref favicon cache"); @@ -128,6 +119,14 @@ ephy_embed_shell_finalize (GObject *object) { EphyEmbedShell *shell = EPHY_EMBED_SHELL (object); + if (shell->priv->downloads != NULL) + { + LOG ("Destroying downloads list"); + g_list_foreach (shell->priv->downloads, (GFunc) g_object_unref, NULL); + g_list_free (shell->priv->downloads); + shell->priv->downloads = NULL; + } + if (shell->priv->global_history) { LOG ("Unref history"); @@ -190,44 +189,6 @@ ephy_embed_shell_get_global_history (EphyEmbedShell *shell) return G_OBJECT (shell->priv->global_history); } -/** - * ephy_embed_shell_get_downloader_view: - * @shell: the #EphyEmbedShell - * - * Return value: (transfer none): - **/ -GObject * -ephy_embed_shell_get_downloader_view (EphyEmbedShell *shell) -{ - g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), NULL); - - if (shell->priv->downloader_view == NULL) - { - DownloaderView **downloader_view; - shell->priv->downloader_view = downloader_view_new (); - downloader_view = &shell->priv->downloader_view; - g_object_add_weak_pointer - (G_OBJECT(shell->priv->downloader_view), - (gpointer *) downloader_view); - } - - return G_OBJECT (shell->priv->downloader_view); -} - -/** - * ephy_embed_shell_get_downloader_view_nocreate: - * @shell: the #EphyEmbedShell - * - * Return value: (transfer none): - **/ -GObject * -ephy_embed_shell_get_downloader_view_nocreate (EphyEmbedShell *shell) -{ - g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), NULL); - - return (GObject *) shell->priv->downloader_view; -} - static GObject * impl_get_embed_single (EphyEmbedShell *shell) { @@ -319,6 +280,8 @@ ephy_embed_shell_init (EphyEmbedShell *shell) /* globally accessible singleton */ g_assert (embed_shell == NULL); embed_shell = shell; + + shell->priv->downloads = NULL; } static void @@ -332,6 +295,40 @@ ephy_embed_shell_class_init (EphyEmbedShellClass *klass) klass->get_embed_single = impl_get_embed_single; /** + * 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: * @shell: the #EphyEmbedShell * @@ -563,6 +560,51 @@ ephy_embed_shell_get_print_settings (EphyEmbedShell *shell) return priv->print_settings; } +/** + * ephy_embed_shell_get_downloads: + * @shell: the #EphyEmbedShell + * + * Gets the global #GList object listing active downloads. + * + * Returns: (transfer none): 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); +} + static void object_notify_cb (EphyEmbedShell *shell, GObject *object) |