[epiphany/downloads: 8/12] ephy-window: add new downloads UI



commit 813e5de4e6fe10fbaab88472d30f2a0f12c86e0a
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.

 data/ui/epiphany-ui.xml |    1 +
 src/ephy-session.c      |    9 ++++
 src/ephy-window.c       |  111 +++++++++++++++++++++++++++++++++++++++++++++++
 src/ephy-window.h       |    3 +
 4 files changed, 124 insertions(+), 0 deletions(-)
---
diff --git a/data/ui/epiphany-ui.xml b/data/ui/epiphany-ui.xml
index c2a9b44..5d1ffbf 100644
--- a/data/ui/epiphany-ui.xml
+++ b/data/ui/epiphany-ui.xml
@@ -47,6 +47,7 @@
 					<separator/>
 				</menu>
 			</placeholder>
+			<menuitem name="ViewDownloadsBar" action="ViewDownloadsBar"/>
 			<separator name="ViewSep1"/>
 			<menuitem name="ViewPopupsMenu" action="ViewPopupWindows"/>
 			<menuitem name="ViewFullscreenMenu" action="ViewFullscreen"/>
diff --git a/src/ephy-session.c b/src/ephy-session.c
index 72acea0..08bdfd4 100644
--- a/src/ephy-session.c
+++ b/src/ephy-session.c
@@ -202,12 +202,14 @@ client_quit_requested_cb (EggSMClient *sm_client,
 	GtkWidget *dialog, *box;
 	InteractData *data;
 	GtkTreeModel *downloads;
+	GList *windows;
 
 	/* If we're shutting down, check if there are downloads
 	 * remaining, since they can't be restarted.
 	 */
 
 	downloads = GTK_TREE_MODEL (ephy_embed_shell_get_downloads (embed_shell));
+
 	if (ephy_shell_get_default () == NULL ||
 	    gtk_tree_model_iter_n_children (downloads, NULL) == 0)
 	{
@@ -215,6 +217,13 @@ client_quit_requested_cb (EggSMClient *sm_client,
 		return;
 	}
 
+	windows	= ephy_session_get_windows (session);
+	if (windows->data)
+	{
+		ephy_window_show_downloads_box (EPHY_WINDOW (windows->data), TRUE);
+	}
+	g_list_free (windows);
+
 	dialog = gtk_message_dialog_new
 		(NULL,
 		 GTK_DIALOG_MODAL,
diff --git a/src/ephy-window.c b/src/ephy-window.c
index acd0eaa..468a76a 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -37,6 +37,8 @@
 #include "ephy-embed-utils.h"
 #include "ephy-zoom.h"
 #include "ephy-debug.h"
+#include "ephy-download.h"
+#include "ephy-download-widget.h"
 #include "ephy-file-helpers.h"
 #include "egg-editable-toolbar.h"
 #include "ephy-toolbar.h"
@@ -278,6 +280,9 @@ static const GtkToggleActionEntry ephy_menu_toggle_entries [] =
 	{ "ViewToolbar", NULL, N_("_Hide Toolbars"), NULL,
 	  N_("Show or hide toolbar"),
 	  G_CALLBACK (ephy_window_view_toolbar_cb), FALSE },
+	{ "ViewDownloadsBar", NULL, N_("View _downloads bar"), NULL,
+	  N_("Show the active downloads for this window"),
+	  NULL, FALSE },
 	{ "ViewFullscreen", GTK_STOCK_FULLSCREEN, N_("_Fullscreen"), "F11",
 	  N_("Browse at full screen"),
 	  G_CALLBACK (window_cmd_view_fullscreen), FALSE },
@@ -442,6 +447,7 @@ struct _EphyWindowPrivate
 	EphyEmbedEvent *context_event;
 	guint idle_worker;
 	GtkWidget *entry;
+	GtkWidget *downloads_box;
 
 	guint clear_progress_timeout_id;
 
@@ -3052,6 +3058,87 @@ ephy_window_set_chrome (EphyWindow *window, EphyWebViewChrome mask)
 }
 
 static void
+download_added_cb (EphyEmbedShell *shell,
+		   EphyDownload *download,
+		   gpointer data)
+{
+	EphyWindow *window = EPHY_WINDOW (data);
+	EphyEmbed *embed;
+	GList *children = NULL;
+	GtkWidget *widget;
+
+	embed = ephy_download_get_embed (download);
+	children = impl_get_children (EPHY_EMBED_CONTAINER (window));
+	widget = ephy_download_get_widget (download);
+
+	if (widget == NULL && (embed == NULL || g_list_find (children, embed)))
+	{
+		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_show_downloads_box (window, TRUE);
+	}
+
+	g_list_free (children);
+}
+
+static void
+download_removed_cb (EphyEmbedShell *shell,
+		     EphyDownload *download,
+		     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)
+		ephy_window_show_downloads_box (window, FALSE);
+
+	g_list_free (children);
+}
+
+static void
+downloads_close_cb (GtkButton *button, EphyWindow *window)
+{
+	ephy_window_show_downloads_box (window, FALSE);
+}
+
+static GtkWidget *
+setup_downloads_box (EphyWindow *window)
+{
+	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), window);
+
+	gtk_widget_show_all (close_button);
+
+	return widget;
+}
+
+void
+ephy_window_show_downloads_box (EphyWindow *window,
+				gboolean show)
+{
+	if (show)
+		gtk_widget_show (window->priv->downloads_box);
+	else
+		gtk_widget_hide (window->priv->downloads_box);
+}
+
+static void
 ephy_window_dispose (GObject *object)
 {
 	EphyWindow *window = EPHY_WINDOW (object);
@@ -3073,6 +3160,11 @@ ephy_window_dispose (GObject *object)
 		ephy_extension_detach_window (manager, window);
 		ephy_bookmarks_ui_detach_window (window);
 
+		g_signal_handlers_disconnect_by_func
+			(embed_shell, download_added_cb, window);
+		g_signal_handlers_disconnect_by_func
+			(embed_shell, download_removed_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);
@@ -3377,6 +3469,7 @@ cancel_handler (gpointer idptr)
 	g_source_remove (id);
 }
 
+
 static void
 ephy_window_init (EphyWindow *window)
 {
@@ -3385,6 +3478,13 @@ 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 (embed_shell,
+			 "download-added", G_CALLBACK (download_added_cb),
+			 window);
+	g_signal_connect (embed_shell,
+			 "download-removed", G_CALLBACK (download_removed_cb),
+			 window);
 }
 
 static GObject *
@@ -3451,8 +3551,19 @@ 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);
+
 	gtk_box_pack_start (GTK_BOX (priv->main_vbox),
 			    GTK_WIDGET (priv->find_toolbar), FALSE, FALSE, 0);
+
+	priv->downloads_box = setup_downloads_box (window);
+	gtk_box_pack_start (GTK_BOX (priv->main_vbox),
+			    GTK_WIDGET (priv->downloads_box), FALSE, FALSE, 0);
+	action = gtk_action_group_get_action (window->priv->action_group,
+					      "ViewDownloadsBar");
+
+	g_object_bind_property (action, "active",
+				priv->downloads_box, "visible",
+				G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
 	/* don't show the find toolbar here! */
 	
 	/* get the toolbars model *before* getting the bookmarksbar model
diff --git a/src/ephy-window.h b/src/ephy-window.h
index 4daa96c..edad9fa 100644
--- a/src/ephy-window.h
+++ b/src/ephy-window.h
@@ -82,6 +82,9 @@ void		  ephy_window_activate_location	  (EphyWindow *window);
 
 EphyEmbedEvent	 *ephy_window_get_context_event	  (EphyWindow *window);
 
+void		  ephy_window_show_downloads_box (EphyWindow *window,
+						  gboolean show);
+
 G_END_DECLS
 
 #endif



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