From 2b7c35a699635baec5b3581dc97a00d1dd98e77b Mon Sep 17 00:00:00 2001 From: Chris Lahey Date: Wed, 11 Feb 2004 21:43:10 +0000 Subject: Added timeout so that dialog won't disappear before 5 seconds is over. 2004-02-11 Chris Lahey * embed/downloader-view.c: Added timeout so that dialog won't disappear before 5 seconds is over. Made Pause/Resume button update label properly. --- embed/downloader-view.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 2 deletions(-) (limited to 'embed') diff --git a/embed/downloader-view.c b/embed/downloader-view.c index 62549f09d..d19213881 100644 --- a/embed/downloader-view.c +++ b/embed/downloader-view.c @@ -40,6 +40,7 @@ #include #define CONF_DOWNLOADING_SHOW_DETAILS "/apps/epiphany/dialogs/downloader_show_details" +#define DIALOG_MINIMUM_DISPLAY_TIMEOUT 5000 enum { @@ -236,6 +237,50 @@ get_row_from_download (DownloaderView *dv, EphyDownload *download) return g_hash_table_lookup (dv->priv->downloads_hash, download); } +static void +update_buttons (DownloaderView *dv) +{ + GtkTreeSelection *selection; + GtkTreeModel *model; + GtkTreeIter iter; + GValue val = {0, }; + EphyDownload *download; + EphyDownloadState state; + gboolean pause_enabled = FALSE; + gboolean abort_enabled = FALSE; + gboolean label_pause = TRUE; + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(dv->priv->treeview)); + + if (gtk_tree_selection_get_selected (selection, &model, &iter)) + { + gtk_tree_model_get_value (model, &iter, COL_DOWNLOAD_OBJECT, &val); + download = g_value_get_object (&val); + g_value_unset (&val); + + state = ephy_download_get_state (download); + + switch (state) + { + case EPHY_DOWNLOAD_DOWNLOADING: + pause_enabled = TRUE; + abort_enabled = TRUE; + break; + case EPHY_DOWNLOAD_PAUSED: + pause_enabled = TRUE; + abort_enabled = TRUE; + label_pause = FALSE; + break; + default: + abort_enabled = TRUE; + break; + } + } + gtk_widget_set_sensitive (dv->priv->pause_button, pause_enabled); + gtk_widget_set_sensitive (dv->priv->abort_button, abort_enabled); + gtk_button_set_label (GTK_BUTTON (dv->priv->pause_button), label_pause ? _("_Pause") : _("_Resume")); +} + static void update_download_row (DownloaderView *dv, EphyDownload *download) { @@ -317,6 +362,8 @@ update_download_row (DownloaderView *dv, EphyDownload *download) g_free (cur_progress); g_free (file); g_free (remaining); + + update_buttons (dv); } static void @@ -418,6 +465,18 @@ downloader_view_add_download (DownloaderView *dv, ephy_dialog_show (EPHY_DIALOG (dv)); } +static void +selection_changed (GtkTreeSelection *selection, DownloaderView *dv) +{ + update_buttons (dv); +} + +static gboolean unref_return_false (void *data) +{ + g_object_unref (data); + return FALSE; +} + static void downloader_view_build_ui (DownloaderView *dv) { @@ -427,6 +486,7 @@ downloader_view_build_ui (DownloaderView *dv) GtkCellRenderer *renderer; GdkPixbuf *icon; EphyDialog *d = EPHY_DIALOG (dv); + GtkTreeSelection *selection; ephy_dialog_construct (d, properties, @@ -499,6 +559,12 @@ downloader_view_build_ui (DownloaderView *dv) GTK_ICON_SIZE_MENU, NULL); gtk_window_set_icon (GTK_WINDOW(priv->window), icon); + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)); + g_signal_connect (selection, "changed", G_CALLBACK (selection_changed), dv); + + g_object_ref (dv); + g_timeout_add (DIALOG_MINIMUM_DISPLAY_TIMEOUT, unref_return_false, dv); } void @@ -524,13 +590,12 @@ download_dialog_pause_cb (GtkButton *button, DownloaderView *dv) if (state == EPHY_DOWNLOAD_DOWNLOADING) { ephy_download_pause (download); - gtk_button_set_label (GTK_BUTTON (dv->priv->pause_button), _("_Resume")); } else if (state == EPHY_DOWNLOAD_PAUSED) { ephy_download_resume (download); - gtk_button_set_label (GTK_BUTTON (dv->priv->pause_button), _("_Pause")); } + update_buttons (dv); } void -- cgit