From cd4e438bfb3ebfd3cc872e203e343a50acc02a15 Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Thu, 9 Jan 2003 18:07:04 +0000 Subject: Fix up the date string, although I guess this should be localized. 2003-01-09 Glynn Foster * src/calendar.c: Fix up the date string, although I guess this should be localized. * src/main.c: Add a new --pulsate option, which reads from stdin and pulsates the progress bar until we reach EOF. * src/progress.c: Rewrite to actually work. Don't really need GIOChannels here. * TODO: Updated accordingly. --- ChangeLog | 12 +++++++ TODO | 1 - src/calendar.c | 2 +- src/main.c | 19 +++++++++++ src/progress.c | 102 +++++++++++++++++++++++++++++++++++++-------------------- 5 files changed, 99 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index 25c88af2..07214045 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2003-01-09 Glynn Foster + + * src/calendar.c: Fix up the date string, although I guess + this should be localized. + + * src/main.c: Add a new --pulsate option, which reads from + stdin and pulsates the progress bar until we reach EOF. + * src/progress.c: Rewrite to actually work. Don't really need + GIOChannels here. + + * TODO: Updated accordingly. + 2003-01-07 Glynn Foster * src/calendar.c, src/entry.c, src/fileselection.c, diff --git a/TODO b/TODO index 4c1070ea..0d3a96d5 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,3 @@ -* Finish off support for progress dialog * Implement return values for all dialogs * All done, except for list view * Add some accessibility I guess diff --git a/src/calendar.c b/src/calendar.c index df5d35c1..4d521be2 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -86,7 +86,7 @@ zenity_calendar_dialog_response (GtkWidget *widget, int response, gpointer data) switch (response) { case GTK_RESPONSE_OK: gtk_calendar_get_date (GTK_CALENDAR (calendar), &day, &month, &year); - g_printerr ("%02d/%02d/%02d\n", day, month + 1, year); + g_printerr ("%02d/%02d/%02d\n", year, month + 1, day); zen_data->exit_code = 0; gtk_main_quit (); break; diff --git a/src/main.c b/src/main.c index f60eb7f0..53cfc992 100644 --- a/src/main.c +++ b/src/main.c @@ -80,6 +80,7 @@ enum { OPTION_RADIOLIST, OPTION_PROGRESSTEXT, OPTION_PERCENTAGE, + OPTION_PULSATE, OPTION_QUESTIONTEXT, OPTION_TEXTFILE, OPTION_WARNINGTEXT, @@ -451,6 +452,15 @@ struct poptOption progress_options[] = { N_("Set initial percentage"), NULL }, + { + "pulsate", + '\0', + POPT_ARG_NONE, + NULL, + OPTION_PULSATE, + N_("Pulsate progress bar"), + NULL + }, POPT_TABLEEND }; @@ -696,6 +706,7 @@ zenity_init_parsing_options (void) { results->calendar_data->year = 0; results->calendar_data->dialog_text = NULL; results->progress_data->percentage = -1; + results->progress_data->pulsate = FALSE; results->entry_data->visible = TRUE; results->tree_data->checkbox = FALSE; results->tree_data->radiobox = FALSE; @@ -1094,6 +1105,14 @@ void zenity_parse_options_callback (poptContext ctx, } results->progress_data->percentage = atoi (arg); break; + case OPTION_PULSATE: + if (results->mode != MODE_PROGRESS) { + g_printerr (_("--pulsate is not supported for this dialog\n")); + zenity_free_parsing_options (); + exit (-1); + } + results->progress_data->pulsate = TRUE; + break; case OPTION_ABOUT: if (results->mode != MODE_LAST) { g_printerr (_("Two or more dialog options specified\n")); diff --git a/src/progress.c b/src/progress.c index 349072a3..bf730bcd 100644 --- a/src/progress.c +++ b/src/progress.c @@ -29,25 +29,17 @@ static guint timer; static GladeXML *glade_dialog; -static gboolean zenity_progress_pulsate_bar (GIOChannel *giochannel, GIOCondition condition, gpointer data); -static gboolean zenity_progress_increment_bar (GIOChannel *giochannel, GIOCondition condition, gpointer data); +gint zenity_progress_timeout (gpointer data); +gint zenity_progress_pulsate_timeout (gpointer data); static void zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data); -gint -zenity_progress_timeout (gpointer data) -{ - gtk_progress_bar_pulse (GTK_PROGRESS_BAR (data)); - return TRUE; -} - void zenity_progress (ZenityData *data, ZenityProgressData *progress_data) { GtkWidget *dialog; GtkWidget *text; GtkWidget *progress_bar; - GIOChannel *giochannel; guint input; glade_dialog = zenity_util_load_glade_file ("zenity_progress_dialog"); @@ -78,49 +70,89 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) progress_bar = glade_xml_get_widget (glade_dialog, "zenity_progress_bar"); - if (glade_dialog) - g_object_unref (glade_dialog); - - giochannel = g_io_channel_unix_new (0); - - if (progress_data->pulsate != TRUE && progress_data->percentage > -1) { - gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), progress_data->percentage/100.0); - } - else { - input = g_io_add_watch (giochannel, G_IO_IN | G_IO_HUP, zenity_progress_pulsate_bar, NULL); - timer = gtk_timeout_add (100, zenity_progress_timeout, progress_bar); - } + if (progress_data->percentage > -1) + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), + progress_data->percentage/100.0); - g_io_channel_unref (giochannel); gtk_widget_show (dialog); + if (progress_data->pulsate != TRUE) + timer = gtk_timeout_add (100, zenity_progress_timeout, progress_bar); + else + timer = gtk_timeout_add (100, zenity_progress_pulsate_timeout, progress_bar); + gtk_main (); } -static gboolean -zenity_progress_pulsate_bar (GIOChannel *giochannel, GIOCondition condition, gpointer data) +gint +zenity_progress_timeout (gpointer data) { - gchar buf[1024]; + gchar buffer[256]; + float percentage; + + while(gtk_events_pending()) { + gtk_main_iteration(); - if (!feof (stdin)) { + if (timer == 0) + return FALSE; + } + + if (scanf ("%255s", buffer) == EOF) { GtkWidget *button; - gtk_timeout_remove (timer); - g_io_channel_shutdown (giochannel, 0, NULL); + button = glade_xml_get_widget (glade_dialog, "zenity_progress_ok_button"); gtk_widget_set_sensitive (button, TRUE); gtk_widget_grab_focus (button); + button = glade_xml_get_widget (glade_dialog, "zenity_progress_cancel_button"); gtk_widget_set_sensitive (button, FALSE); + + if (glade_dialog) + g_object_unref (glade_dialog); + return FALSE; + } else { + percentage = atoi (buffer); + + if (percentage > 100) + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (data), 1.0); + else + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (data), percentage / 100.0); + + return TRUE; } - - fgets (buf, sizeof (buf)-1, stdin); - return TRUE; } -static gboolean -zenity_progress_increment_bar (GIOChannel *giochannel, GIOCondition condition, gpointer data) +gint +zenity_progress_pulsate_timeout (gpointer data) { - /* FIXME: Do nothing at the moment */ + + while(gtk_events_pending()) { + gtk_main_iteration(); + + if (timer == 0) + return FALSE; + } + + if (feof (stdin)) { + gtk_progress_bar_pulse (GTK_PROGRESS_BAR (data)); + + return FALSE; + } else { + GtkWidget *button; + + /* We stop the pulsating and switch the focus on the dialog buttons */ + + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (data), 1.0); + + button = glade_xml_get_widget (glade_dialog, "zenity_progress_ok_button"); + gtk_widget_set_sensitive (button, TRUE); + gtk_widget_grab_focus (button); + + button = glade_xml_get_widget (glade_dialog, "zenity_progress_cancel_button"); + gtk_widget_set_sensitive (button, FALSE); + + return TRUE; + } } static void -- cgit