[epiphany/downloads: 7/9] ephy-window: add new downloads UI



commit b6b61602b89e5b31621b14b3bbb07a48dbfc4529
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 |  145 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 145 insertions(+), 0 deletions(-)
---
diff --git a/src/ephy-window.c b/src/ephy-window.c
index a88afb8..e0d9e2b 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,108 @@ 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;
+	EphyDownload *download = NULL;
+	GList *children = NULL;
+
+	gtk_tree_model_get (tree_model, iter, 0, &download, -1);
+
+	LOG ("%p] inserted (%p)", window, download);
+
+	embed = ephy_download_get_embed (download);
+	children = impl_get_children (EPHY_EMBED_CONTAINER (window));
+
+	if (g_list_find (children, embed))
+	{
+		GtkWidget *widget;
+
+		LOG ("first pack !!!!");
+		widget = ephy_download_get_widget (download);
+		gtk_box_pack_start (GTK_BOX (window->priv->downloads_box),
+				    widget, FALSE, FALSE, 0);
+		gtk_widget_show_all (window->priv->downloads_box);
+	}
+	g_list_free (children);
+}
+
+static void
+download_changed_cb (GtkTreeModel *tree_model,
+		GtkTreePath *path,
+		GtkTreeIter *iter,
+		gpointer data)
+{
+	EphyWindow *window = EPHY_WINDOW (data);
+	GtkWidget *widget;
+	EphyEmbed *embed;
+	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);
+	GList *children = NULL;
+
+	children = gtk_container_get_children (GTK_CONTAINER (window->priv->downloads_box));
+
+	if (g_list_length (children) == 1)
+		gtk_widget_hide (window->priv->downloads_box);
+
+	g_list_free (children);
+}
+
+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, 0);
+	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);
@@ -3065,6 +3169,7 @@ ephy_window_dispose (GObject *object)
 	if (window->priv->closing == FALSE)
 	{
 		EphyExtension *manager;
+		GList *l;
 
 		window->priv->closing = TRUE;
 
@@ -3073,6 +3178,30 @@ 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);
+
+		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);
@@ -3377,6 +3506,7 @@ cancel_handler (gpointer idptr)
 	g_source_remove (id);
 }
 
+
 static void
 ephy_window_init (EphyWindow *window)
 {
@@ -3385,6 +3515,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 *
@@ -3451,8 +3591,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]