Show a 'Delete all' button in the transferbar as needed

The button shows up as a new download starts and vanishes again
if no downloads are there.
This commit is contained in:
Christian Dywan 2009-04-19 19:05:05 +02:00
parent 19c57b4da7
commit 7ae35d62ab

View file

@ -66,6 +66,7 @@ struct _MidoriBrowser
GtkWidget* statusbar; GtkWidget* statusbar;
GtkWidget* transferbar; GtkWidget* transferbar;
GtkWidget* transferbar_clear;
GtkWidget* progressbar; GtkWidget* progressbar;
gchar* statusbar_text; gchar* statusbar_text;
@ -903,11 +904,16 @@ midori_browser_download_notify_status_cb (WebKitDownload* download,
gtk_button_set_image (GTK_BUTTON (button), icon); gtk_button_set_image (GTK_BUTTON (button), icon);
if (g_object_get_data (G_OBJECT (download), "open-download")) if (g_object_get_data (G_OBJECT (download), "open-download"))
gtk_button_clicked (GTK_BUTTON (button)); gtk_button_clicked (GTK_BUTTON (button));
else
g_object_set_data (G_OBJECT (gtk_widget_get_parent (button)),
"done", (void*)1);
break; break;
case WEBKIT_DOWNLOAD_STATUS_CANCELLED: case WEBKIT_DOWNLOAD_STATUS_CANCELLED:
case WEBKIT_DOWNLOAD_STATUS_ERROR: case WEBKIT_DOWNLOAD_STATUS_ERROR:
icon = gtk_image_new_from_stock (GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU); icon = gtk_image_new_from_stock (GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU);
gtk_button_set_image (GTK_BUTTON (button), icon); gtk_button_set_image (GTK_BUTTON (button), icon);
g_object_set_data (G_OBJECT (gtk_widget_get_parent (button)),
"done", (void*)1);
break; break;
default: default:
break; break;
@ -918,10 +924,17 @@ static void
midori_browser_download_button_clicked_cb (GtkWidget* button, midori_browser_download_button_clicked_cb (GtkWidget* button,
WebKitDownload* download) WebKitDownload* download)
{ {
MidoriBrowser* browser;
GList* buttons;
browser = MIDORI_BROWSER (gtk_widget_get_toplevel (button));
switch (webkit_download_get_status (download)) switch (webkit_download_get_status (download))
{ {
case WEBKIT_DOWNLOAD_STATUS_STARTED: case WEBKIT_DOWNLOAD_STATUS_STARTED:
webkit_download_cancel (download); webkit_download_cancel (download);
g_object_set_data (G_OBJECT (gtk_widget_get_parent (button)),
"done", (void*)1);
break; break;
case WEBKIT_DOWNLOAD_STATUS_FINISHED: case WEBKIT_DOWNLOAD_STATUS_FINISHED:
{ {
@ -943,6 +956,11 @@ midori_browser_download_button_clicked_cb (GtkWidget* button,
default: default:
break; break;
} }
buttons = gtk_container_get_children (GTK_CONTAINER (browser->transferbar));
if (g_list_length (buttons) == 1)
gtk_widget_hide (browser->transferbar_clear);
g_list_free (buttons);
} }
static void static void
@ -978,6 +996,7 @@ midori_browser_add_download_item (MidoriBrowser* browser,
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
gtk_widget_show_all (box); gtk_widget_show_all (box);
gtk_box_pack_start (GTK_BOX (browser->transferbar), box, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (browser->transferbar), box, FALSE, FALSE, 0);
gtk_widget_show (browser->transferbar_clear);
g_signal_connect (download, "notify::progress", g_signal_connect (download, "notify::progress",
G_CALLBACK (midori_browser_download_notify_progress_cb), progress); G_CALLBACK (midori_browser_download_notify_progress_cb), progress);
@ -1016,6 +1035,26 @@ midori_view_download_requested_cb (GtkWidget* view,
} }
#endif #endif
static void
midori_browser_transferbar_clear_clicked_cb (GtkWidget* button,
MidoriBrowser* browser)
{
GList* buttons;
guint i;
GtkWidget* item;
buttons = gtk_container_get_children (GTK_CONTAINER (browser->transferbar));
i = 0;
while ((item = g_list_nth_data (buttons, i++)))
if (g_object_get_data (G_OBJECT (item), "done"))
gtk_widget_destroy (item);
g_list_free (buttons);
buttons = gtk_container_get_children (GTK_CONTAINER (browser->transferbar));
if (g_list_length (buttons) == 1)
gtk_widget_hide (browser->transferbar_clear);
g_list_free (buttons);
}
static void static void
midori_view_search_text_cb (GtkWidget* view, midori_view_search_text_cb (GtkWidget* view,
gboolean found, gboolean found,
@ -3885,6 +3924,7 @@ midori_browser_init (MidoriBrowser* browser)
GtkToolItem* toolitem; GtkToolItem* toolitem;
GtkRcStyle* rcstyle; GtkRcStyle* rcstyle;
GtkWidget* scrolled; GtkWidget* scrolled;
GtkWidget* icon;
browser->net = katze_net_new (); browser->net = katze_net_new ();
@ -4290,6 +4330,13 @@ midori_browser_init (MidoriBrowser* browser)
gtk_box_pack_start (GTK_BOX (browser->statusbar), browser->transferbar, gtk_box_pack_start (GTK_BOX (browser->statusbar), browser->transferbar,
FALSE, FALSE, 3); FALSE, FALSE, 3);
gtk_widget_show (browser->transferbar); gtk_widget_show (browser->transferbar);
browser->transferbar_clear = gtk_button_new_with_label (_("Delete All"));
icon = gtk_image_new_from_stock (GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU);
gtk_button_set_image (GTK_BUTTON (browser->transferbar_clear), icon);
g_signal_connect (browser->transferbar_clear, "clicked",
G_CALLBACK (midori_browser_transferbar_clear_clicked_cb), browser);
gtk_box_pack_end (GTK_BOX (browser->transferbar), browser->transferbar_clear,
FALSE, FALSE, 0);
g_signal_connect (browser->statusbar, "button-press-event", g_signal_connect (browser->statusbar, "button-press-event",
G_CALLBACK (midori_browser_toolbar_item_button_press_event_cb), browser); G_CALLBACK (midori_browser_toolbar_item_button_press_event_cb), browser);