[epiphany/downloads: 6/7] ephy-window: add new downloads UI
- From: Diego Escalante Urrelo <diegoe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/downloads: 6/7] ephy-window: add new downloads UI
- Date: Thu, 20 Jan 2011 07:03:31 +0000 (UTC)
commit 621fb328a7052f58be287c4d1ef8c19dc9ef2f36
Author: Diego Escalante Urrelo <descalante igalia com>
Date: Tue Jan 18 13:48:28 2011 -0500
ephy-window: add new downloads UI
Downloads are now shown per-window, imitating Chromium's bottom bar.
If a window with ongoing downloads is closed, their downloads will go to
another window. TBD: it might prove better to just ask if you want to cancel
them or not.
src/ephy-window.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 131 insertions(+), 0 deletions(-)
---
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 09a3c66..fa1a340 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -37,6 +37,7 @@
#include "ephy-embed-utils.h"
#include "ephy-zoom.h"
#include "ephy-debug.h"
+#include "ephy-download.h"
#include "ephy-file-helpers.h"
#include "egg-editable-toolbar.h"
#include "ephy-toolbar.h"
@@ -442,6 +443,7 @@ struct _EphyWindowPrivate
EphyEmbedEvent *context_event;
guint idle_worker;
GtkWidget *entry;
+ GtkWidget *downloads_box;
guint clear_progress_timeout_id;
@@ -3052,6 +3054,97 @@ ephy_window_set_chrome (EphyWindow *window, EphyWebViewChrome mask)
}
static void
+download_inserted_cb (GtkTreeModel *tree_model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ EphyWindow *window = EPHY_WINDOW (data);
+ EphyEmbed *embed = NULL;
+ EphyDownload *download = NULL;
+
+ gtk_tree_model_get (tree_model, iter, 0, &download, -1);
+
+ LOG ("%p] inserted (%p)", window, download);
+
+ embed = ephy_download_get_embed (download);
+ if (g_list_find (impl_get_children (EPHY_EMBED_CONTAINER (window)), embed) == NULL)
+ return;
+
+ LOG ("first pack !!!!");
+
+ gtk_box_pack_start (GTK_BOX (window->priv->downloads_box),
+ ephy_download_get_widget (download), FALSE, FALSE, 4);
+ gtk_widget_show_all (window->priv->downloads_box);
+}
+
+static void
+download_changed_cb (GtkTreeModel *tree_model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ EphyWindow *window = EPHY_WINDOW (data);
+ GtkWidget *widget = NULL;
+ EphyEmbed *embed = NULL;
+ EphyDownload *download = NULL;
+
+ gtk_tree_model_get (tree_model, iter, 0, &download, -1);
+
+ embed = ephy_download_get_embed (download);
+ widget = ephy_download_get_widget (download);
+
+ LOG ("%p] changed (%p)", window, embed);
+ if (embed || gtk_widget_get_parent (widget))
+ return;
+
+ LOG ("repacking !!!!");
+
+ gtk_box_pack_start (GTK_BOX (window->priv->downloads_box), widget, FALSE, FALSE, 4);
+ gtk_widget_show_all (window->priv->downloads_box);
+}
+
+static void
+download_deleted_cb (GtkTreeModel *tree_model,
+ GtkTreePath *path,
+ gpointer data)
+{
+ EphyWindow *window = EPHY_WINDOW (data);
+
+ if (g_list_length (gtk_container_get_children (GTK_CONTAINER (window->priv->downloads_box))) == 1)
+ gtk_widget_hide (window->priv->downloads_box);
+}
+
+static void
+downloads_close_cb (GtkButton *button, GtkWidget *box)
+{
+ gtk_widget_hide (box);
+}
+
+static GtkWidget *
+setup_downloads_box ()
+{
+ GtkWidget *widget;
+ GtkWidget *close_button;
+ GtkWidget *image;
+
+ widget = gtk_hbox_new (FALSE, 8);
+ close_button = gtk_button_new ();
+ image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON);
+
+ gtk_button_set_relief (GTK_BUTTON (close_button), GTK_RELIEF_NONE);
+
+ gtk_container_add (GTK_CONTAINER (close_button), image);
+ gtk_box_pack_end (GTK_BOX (widget), close_button, FALSE, FALSE, 4);
+
+ g_signal_connect (close_button, "clicked", G_CALLBACK (downloads_close_cb), widget);
+
+ gtk_widget_show_all (close_button);
+
+ return widget;
+}
+
+static void
ephy_window_dispose (GObject *object)
{
EphyWindow *window = EPHY_WINDOW (object);
@@ -3073,6 +3166,28 @@ ephy_window_dispose (GObject *object)
ephy_extension_detach_window (manager, window);
ephy_bookmarks_ui_detach_window (window);
+ g_signal_handlers_disconnect_by_func (ephy_embed_shell_get_downloads (embed_shell),
+ download_inserted_cb, window);
+ g_signal_handlers_disconnect_by_func (ephy_embed_shell_get_downloads (embed_shell),
+ download_changed_cb, window);
+ g_signal_handlers_disconnect_by_func (ephy_embed_shell_get_downloads (embed_shell),
+ download_deleted_cb, window);
+
+ GList *l;
+ l = gtk_container_get_children (GTK_CONTAINER (window->priv->downloads_box));
+
+ for (; l; l = l->next)
+ {
+ EphyDownload *download = g_object_get_data (G_OBJECT (l->data), "download");
+
+ if (download != NULL)
+ {
+ gtk_container_remove (GTK_CONTAINER (window->priv->downloads_box),
+ GTK_WIDGET (l->data));
+ ephy_download_set_embed (download, NULL);
+ }
+ }
+
/* 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);
@@ -3376,6 +3491,7 @@ cancel_handler (gpointer idptr)
g_source_remove (id);
}
+
static void
ephy_window_init (EphyWindow *window)
{
@@ -3384,6 +3500,16 @@ ephy_window_init (EphyWindow *window)
_ephy_embed_shell_track_object (EPHY_EMBED_SHELL (ephy_shell), G_OBJECT (window));
window->priv = EPHY_WINDOW_GET_PRIVATE (window);
+
+ g_signal_connect (ephy_embed_shell_get_downloads (embed_shell),
+ "row-inserted", G_CALLBACK (download_inserted_cb),
+ window);
+ g_signal_connect (ephy_embed_shell_get_downloads (embed_shell),
+ "row-changed", G_CALLBACK (download_changed_cb),
+ window);
+ g_signal_connect (ephy_embed_shell_get_downloads (embed_shell),
+ "row-deleted", G_CALLBACK (download_deleted_cb),
+ window);
}
static GObject *
@@ -3450,8 +3576,13 @@ ephy_window_constructor (GType type,
priv->find_toolbar = ephy_find_toolbar_new (window);
g_signal_connect (priv->find_toolbar, "close",
G_CALLBACK (find_toolbar_close_cb), window);
+
+ priv->downloads_box = setup_downloads_box ();
+
gtk_box_pack_start (GTK_BOX (priv->main_vbox),
GTK_WIDGET (priv->find_toolbar), FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (priv->main_vbox),
+ GTK_WIDGET (priv->downloads_box), FALSE, FALSE, 0);
/* don't show the find toolbar here! */
/* get the toolbars model *before* getting the bookmarksbar model
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]