From 48c1564ac5ef431e9111606e40488d04a96f3059 Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Fri, 3 Jan 2003 13:26:04 +0000 Subject: Initial revision --- src/progress.c | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 src/progress.c (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c new file mode 100644 index 00000000..21305917 --- /dev/null +++ b/src/progress.c @@ -0,0 +1,139 @@ +/* + * progress.c + * + * Copyright (C) 2002 Sun Microsystems, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Authors: Glynn Foster + */ + +#include +#include +#include "zenity.h" +#include "util.h" + +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); + +void zenity_progress_dialog_response (GtkWindow *window, int button, gpointer data); + +gint +zenity_progress_timeout (gpointer data) +{ + gtk_progress_bar_pulse (GTK_PROGRESS_BAR (data)); + return TRUE; +} + +int 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"); + + if (glade_dialog == NULL) + return FALSE; + + glade_xml_signal_autoconnect (glade_dialog); + + dialog = glade_xml_get_widget (glade_dialog, "zenity_progress_dialog"); + + if (data->dialog_title) + gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); + + if (data->window_icon) + zenity_util_set_window_icon (dialog, data->window_icon); + else { + zenity_util_set_window_icon (dialog, ZENITY_IMAGE_FULLPATH ("zenity-progress.png")); + } + + text = glade_xml_get_widget (glade_dialog, "zenity_progress_text"); + gtk_label_set_text (GTK_LABEL (text), progress_data->dialog_text); + + progress_bar = glade_xml_get_widget (glade_dialog, "zenity_progress_bar"); + + giochannel = g_io_channel_unix_new (0); + + if (progress_data->pulsate != TRUE) { + 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); + } + + g_io_channel_unref (giochannel); + gtk_widget_show (dialog); + gtk_main (); + + if (glade_dialog) + g_object_unref (glade_dialog); + + return TRUE; +} + +static gboolean +zenity_progress_pulsate_bar (GIOChannel *giochannel, GIOCondition condition, gpointer data) +{ + gchar buf[1024]; + + if (!feof (stdin)) { + 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); + return FALSE; + } + + fgets (buf, sizeof (buf)-1, stdin); + return TRUE; +} + +static gboolean +zenity_progress_increment_bar (GIOChannel *giochannel, GIOCondition condition, gpointer data) +{ + /* FIXME: Do nothing at the moment */ +} + +void +zenity_progress_dialog_response (GtkWindow *window, int button, gpointer data) +{ + GError *error = NULL; + + switch (button) { + case GTK_RESPONSE_OK: + gtk_main_quit (); + break; + + case GTK_RESPONSE_CANCEL: + gtk_main_quit (); + break; + + default: + break; + } +} -- cgit From a8c3006035a068069ed9199400472332db540bb5 Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Tue, 7 Jan 2003 00:01:00 +0000 Subject: Improve error handling... a lot. 2003-01-06 Glynn Foster * src/calendar.c, src/main.c, src/progress.c, src/tree.c, src/zenity.h: Improve error handling... a lot. --- src/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 21305917..a890059b 100644 --- a/src/progress.c +++ b/src/progress.c @@ -74,7 +74,7 @@ int zenity_progress (ZenityData *data, ZenityProgressData *progress_data) giochannel = g_io_channel_unix_new (0); - if (progress_data->pulsate != TRUE) { + 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 { -- cgit From 6a65d75921d352323277f770f357ca3065436133 Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Tue, 7 Jan 2003 13:22:57 +0000 Subject: Fix up the response signal handlers. Use returns of 0 for 'Ok' and 2003-01-07 Glynn Foster * src/calendar.c, src/entry.c, src/fileselection.c, src/main.c, src/msg.c, src/progress.c, src/text.c, src/tree.c, src/zenity.glade, src/zenity.h: Fix up the response signal handlers. Use returns of 0 for 'Ok' and 'Close', 1 for 'Cancel' and 'Escape' and -1 for 'Uh Oh'. Get stuff printing to stderr. Fix up the error handling that I thought was improved, although still have issues with popt callback getting called numerous times because of more than one instance of the same kind is being used in poptOption. * TODO: Update accordingly. --- src/progress.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index a890059b..349072a3 100644 --- a/src/progress.c +++ b/src/progress.c @@ -32,7 +32,7 @@ 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); -void zenity_progress_dialog_response (GtkWindow *window, int button, gpointer data); +static void zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data); gint zenity_progress_timeout (gpointer data) @@ -41,7 +41,8 @@ zenity_progress_timeout (gpointer data) return TRUE; } -int zenity_progress (ZenityData *data, ZenityProgressData *progress_data) +void +zenity_progress (ZenityData *data, ZenityProgressData *progress_data) { GtkWidget *dialog; GtkWidget *text; @@ -51,12 +52,17 @@ int zenity_progress (ZenityData *data, ZenityProgressData *progress_data) glade_dialog = zenity_util_load_glade_file ("zenity_progress_dialog"); - if (glade_dialog == NULL) - return FALSE; + if (glade_dialog == NULL) { + data->exit_code = -1; + return; + } glade_xml_signal_autoconnect (glade_dialog); dialog = glade_xml_get_widget (glade_dialog, "zenity_progress_dialog"); + + g_signal_connect (G_OBJECT (dialog), "response", + G_CALLBACK (zenity_progress_dialog_response), data); if (data->dialog_title) gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); @@ -72,6 +78,9 @@ int 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) { @@ -85,11 +94,6 @@ int zenity_progress (ZenityData *data, ZenityProgressData *progress_data) g_io_channel_unref (giochannel); gtk_widget_show (dialog); gtk_main (); - - if (glade_dialog) - g_object_unref (glade_dialog); - - return TRUE; } static gboolean @@ -119,21 +123,24 @@ zenity_progress_increment_bar (GIOChannel *giochannel, GIOCondition condition, g /* FIXME: Do nothing at the moment */ } -void -zenity_progress_dialog_response (GtkWindow *window, int button, gpointer data) +static void +zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data) { - GError *error = NULL; + ZenityData *zen_data = data; - switch (button) { + switch (response) { case GTK_RESPONSE_OK: + zen_data->exit_code = 0; gtk_main_quit (); break; case GTK_RESPONSE_CANCEL: + zen_data->exit_code = 1; gtk_main_quit (); break; default: + zen_data->exit_code = 1; break; } } -- cgit 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. --- src/progress.c | 102 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 67 insertions(+), 35 deletions(-) (limited to 'src/progress.c') 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 From 49f89795349a47ae4e061666d84a715bf24f5373 Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Mon, 10 Mar 2003 17:11:18 +0000 Subject: Mass indentation cleanup. Make sure the glade dialogs aren't initially 2003-03-10 Glynn Foster * src/about.c, src/calendar.c, src/entry.c, src/fileselection.c, src/main.c, src/msg.c, src/progress.c, src/text.c, src/tree.c, src/util.c, src/util.h, src/zenity.glade, src/zenity.h: Mass indentation cleanup. Make sure the glade dialogs aren't initially visible because this avoids a visibility jump. Apparently == TRUE is bad mojo. Fix up. --- src/progress.c | 194 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 97 insertions(+), 97 deletions(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index bf730bcd..41153bc4 100644 --- a/src/progress.c +++ b/src/progress.c @@ -37,142 +37,142 @@ static void zenity_progress_dialog_response (GtkWidget *widget, int response, gp void zenity_progress (ZenityData *data, ZenityProgressData *progress_data) { - GtkWidget *dialog; - GtkWidget *text; - GtkWidget *progress_bar; - guint input; + GtkWidget *dialog; + GtkWidget *text; + GtkWidget *progress_bar; + guint input; - glade_dialog = zenity_util_load_glade_file ("zenity_progress_dialog"); + glade_dialog = zenity_util_load_glade_file ("zenity_progress_dialog"); - if (glade_dialog == NULL) { - data->exit_code = -1; - return; - } + if (glade_dialog == NULL) { + data->exit_code = -1; + return; + } - glade_xml_signal_autoconnect (glade_dialog); - - dialog = glade_xml_get_widget (glade_dialog, "zenity_progress_dialog"); + glade_xml_signal_autoconnect (glade_dialog); + + dialog = glade_xml_get_widget (glade_dialog, "zenity_progress_dialog"); - g_signal_connect (G_OBJECT (dialog), "response", - G_CALLBACK (zenity_progress_dialog_response), data); + g_signal_connect (G_OBJECT (dialog), "response", + G_CALLBACK (zenity_progress_dialog_response), data); - if (data->dialog_title) - gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); + if (data->dialog_title) + gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); - if (data->window_icon) - zenity_util_set_window_icon (dialog, data->window_icon); - else { - zenity_util_set_window_icon (dialog, ZENITY_IMAGE_FULLPATH ("zenity-progress.png")); - } + if (data->window_icon) + zenity_util_set_window_icon (dialog, data->window_icon); + else { + zenity_util_set_window_icon (dialog, ZENITY_IMAGE_FULLPATH ("zenity-progress.png")); + } - text = glade_xml_get_widget (glade_dialog, "zenity_progress_text"); - gtk_label_set_text (GTK_LABEL (text), progress_data->dialog_text); + text = glade_xml_get_widget (glade_dialog, "zenity_progress_text"); + gtk_label_set_text (GTK_LABEL (text), progress_data->dialog_text); - progress_bar = glade_xml_get_widget (glade_dialog, "zenity_progress_bar"); + progress_bar = glade_xml_get_widget (glade_dialog, "zenity_progress_bar"); - if (progress_data->percentage > -1) - gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), - progress_data->percentage/100.0); + if (progress_data->percentage > -1) + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), + progress_data->percentage/100.0); - 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_widget_show (dialog); + if (!progress_data->pulsate) + timer = gtk_timeout_add (100, zenity_progress_timeout, progress_bar); + else + timer = gtk_timeout_add (100, zenity_progress_pulsate_timeout, progress_bar); - gtk_main (); + gtk_main (); } gint zenity_progress_timeout (gpointer data) { - gchar buffer[256]; - float percentage; - - while(gtk_events_pending()) { - gtk_main_iteration(); + gchar buffer[256]; + float percentage; - if (timer == 0) - return FALSE; - } + while(gtk_events_pending()) { + gtk_main_iteration(); - if (scanf ("%255s", buffer) == EOF) { - GtkWidget *button; + if (timer == 0) + return FALSE; + } - button = glade_xml_get_widget (glade_dialog, "zenity_progress_ok_button"); - gtk_widget_set_sensitive (button, TRUE); - gtk_widget_grab_focus (button); + if (scanf ("%255s", buffer) == EOF) { + GtkWidget *button; - button = glade_xml_get_widget (glade_dialog, "zenity_progress_cancel_button"); - gtk_widget_set_sensitive (button, FALSE); + button = glade_xml_get_widget (glade_dialog, "zenity_progress_ok_button"); + gtk_widget_set_sensitive (button, TRUE); + gtk_widget_grab_focus (button); - if (glade_dialog) - g_object_unref (glade_dialog); + 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); + 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); + 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; - } + return TRUE; + } } gint zenity_progress_pulsate_timeout (gpointer data) { - while(gtk_events_pending()) { - gtk_main_iteration(); - - if (timer == 0) - return FALSE; - } - - if (feof (stdin)) { - gtk_progress_bar_pulse (GTK_PROGRESS_BAR (data)); + while(gtk_events_pending()) { + gtk_main_iteration(); - return FALSE; - } else { - GtkWidget *button; + if (timer == 0) + return FALSE; + } - /* We stop the pulsating and switch the focus on the dialog buttons */ + if (feof (stdin)) { + gtk_progress_bar_pulse (GTK_PROGRESS_BAR (data)); + return FALSE; + } else { + GtkWidget *button; - gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (data), 1.0); + /* 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_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); + button = glade_xml_get_widget (glade_dialog, "zenity_progress_cancel_button"); + gtk_widget_set_sensitive (button, FALSE); - return TRUE; - } + return TRUE; + } } static void zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data) { - ZenityData *zen_data = data; - - switch (response) { - case GTK_RESPONSE_OK: - zen_data->exit_code = 0; - gtk_main_quit (); - break; - - case GTK_RESPONSE_CANCEL: - zen_data->exit_code = 1; - gtk_main_quit (); - break; - - default: - zen_data->exit_code = 1; - break; - } + ZenityData *zen_data = data; + + switch (response) { + case GTK_RESPONSE_OK: + zen_data->exit_code = 0; + gtk_main_quit (); + break; + + case GTK_RESPONSE_CANCEL: + zen_data->exit_code = 1; + gtk_main_quit (); + break; + + default: + /* Esc dialog */ + zen_data->exit_code = 1; + break; + } } -- cgit From 965c2a91497fcf96c88c0029b18a6a1e9f5d46bd Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Sun, 13 Apr 2003 15:42:41 +0000 Subject: Finish off the indentation cleanup. Add new '--width' and '--height' 2003-04-13 Glynn Foster * src/calendar.c, src/entry.c, src/fileselection.c, src/main.c, src/msg.c, src/progress.c, src/text.c, src/tree.c, src/zenity.h: Finish off the indentation cleanup. Add new '--width' and '--height' options to the general options. Fix up the radio list view, so that we can now act like a radio button group. * TODO: Update --- src/progress.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 41153bc4..d7ae35e3 100644 --- a/src/progress.c +++ b/src/progress.c @@ -61,9 +61,10 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) if (data->window_icon) zenity_util_set_window_icon (dialog, data->window_icon); - else { + else zenity_util_set_window_icon (dialog, ZENITY_IMAGE_FULLPATH ("zenity-progress.png")); - } + + gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height); text = glade_xml_get_widget (glade_dialog, "zenity_progress_text"); gtk_label_set_text (GTK_LABEL (text), progress_data->dialog_text); -- cgit From 70ea28f34c25cc21bac51286b7e2c767a2df5807 Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Mon, 19 May 2003 18:24:41 +0000 Subject: Make the progress dialog actually work and now uses g_io_channel. Woot! 2003-05-19 Glynn Foster * src/progress.c: Make the progress dialog actually work and now uses g_io_channel. Woot! Need to be able to cancel the dialog, which currently doesn't work too well. * TODO: Update. * help/C/zenity.xml: Update help documentation. --- src/progress.c | 197 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 122 insertions(+), 75 deletions(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index d7ae35e3..aad133a2 100644 --- a/src/progress.c +++ b/src/progress.c @@ -29,11 +29,130 @@ static guint timer; static GladeXML *glade_dialog; +static GIOChannel *channel; + 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); +static gboolean +zenity_progress_pulsate_progress_bar (gpointer user_data) +{ + gtk_progress_bar_pulse (GTK_PROGRESS_BAR (user_data)); + return TRUE; +} + +static gboolean +zenity_progress_handle_stdin (GIOChannel *channel, + GIOCondition condition, + gpointer data) +{ + static ZenityProgressData *progress_data; + static GtkWidget *progress_bar; + static GtkWidget *progress_label; + static gint pulsate_timeout = -1; + float percentage = 0.0; + + progress_data = (ZenityProgressData *) data; + progress_bar = glade_xml_get_widget (glade_dialog, "zenity_progress_bar"); + progress_label = glade_xml_get_widget (glade_dialog, "zenity_progress_text"); + + if ((condition == G_IO_IN) || (condition == G_IO_IN + G_IO_HUP)) { + GString *string; + GError *error = NULL; + + string = g_string_new (NULL); + + if (progress_data->pulsate) { + if (pulsate_timeout == -1) + pulsate_timeout = g_timeout_add (100, zenity_progress_pulsate_progress_bar, progress_bar); + } + + while (channel->is_readable != TRUE) + ; + do { + gint status; + + do { + status = g_io_channel_read_line_string (channel, string, NULL, &error); + + while (gtk_events_pending ()) + gtk_main_iteration (); + + } while (status == G_IO_STATUS_AGAIN); + + if (status != G_IO_STATUS_NORMAL) { + if (error) { + g_warning ("zenity_progress_handle_stdin () : %s", error->message); + g_error_free (error); + error = NULL; + } + continue; + } + + if (!g_ascii_strncasecmp (string->str, "#", 1)) { + gchar *match; + + /* We have a comment, so let's try to change the label */ + match = g_strstr_len (string->str, strlen (string->str), "#"); + match++; + gtk_label_set_text (GTK_LABEL (progress_label), g_strchomp (g_strchug (match))); + } else { + + if (!g_ascii_isdigit (*(string->str))) + continue; + + /* Now try to convert the thing to a number */ + percentage = atoi (string->str); + if (percentage > 100) + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), 1.0); + else + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), percentage / 100.0); + } + + } while (g_io_channel_get_buffer_condition (channel) == G_IO_IN); + g_string_free (string, TRUE); + } + + if (condition != G_IO_IN) { + /* We assume that we are done, so stop the pulsating and de-sensitize the buttons */ + GtkWidget *button; + GtkWidget *progress_bar; + + 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); + + progress_bar = glade_xml_get_widget (glade_dialog, "zenity_progress_bar"); + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), 1.0); + + if (progress_data->pulsate) { + g_source_remove (pulsate_timeout); + pulsate_timeout = -1; + } + + if (glade_dialog) + g_object_unref (glade_dialog); + + g_io_channel_shutdown (channel, TRUE, NULL); + return FALSE; + } + return TRUE; +} + +static void +zenity_progress_read_info (ZenityProgressData *progress_data) +{ + channel = g_io_channel_unix_new (0); + g_io_channel_set_encoding (channel, NULL, NULL); + g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL); + g_io_add_watch (channel, G_IO_IN | G_IO_HUP, zenity_progress_handle_stdin, progress_data); +} + void zenity_progress (ZenityData *data, ZenityProgressData *progress_data) { @@ -76,85 +195,11 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) progress_data->percentage/100.0); gtk_widget_show (dialog); - if (!progress_data->pulsate) - timer = gtk_timeout_add (100, zenity_progress_timeout, progress_bar); - else - timer = gtk_timeout_add (100, zenity_progress_pulsate_timeout, progress_bar); + zenity_progress_read_info (progress_data); gtk_main (); } -gint -zenity_progress_timeout (gpointer data) -{ - gchar buffer[256]; - float percentage; - - while(gtk_events_pending()) { - gtk_main_iteration(); - - if (timer == 0) - return FALSE; - } - - if (scanf ("%255s", buffer) == EOF) { - GtkWidget *button; - - 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; - } -} - -gint -zenity_progress_pulsate_timeout (gpointer data) -{ - - 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 zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data) { @@ -167,6 +212,8 @@ zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data) break; case GTK_RESPONSE_CANCEL: + /* FIXME: This should kill off the parent process - not entirely sure how to achieve this */ + kill (0); zen_data->exit_code = 1; gtk_main_quit (); break; -- cgit From 1acd9cfed892c8a277199912d099f7c5ff7a94ca Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Sat, 24 May 2003 01:36:24 +0000 Subject: Patch from Dagmar d'Surreal to correct help docs 2003-05-24 Glynn Foster * help/C/zenity.xml: Patch from Dagmar d'Surreal to correct help docs and script examples for the change from --dialog-title to --title. * THANKS, src/about.c: Add Dagmar. * src/progress.c: For now, just send a SIGHUP to the parent process - not entirely sure if this is the best thing to do right now. --- src/progress.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index aad133a2..f7444c42 100644 --- a/src/progress.c +++ b/src/progress.c @@ -212,8 +212,11 @@ zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data) break; case GTK_RESPONSE_CANCEL: - /* FIXME: This should kill off the parent process - not entirely sure how to achieve this */ - kill (0); + /* FIXME: This should kill off the parent process nicely and return an error code + * I'm pretty sure there is a nice way to do this, but I'm clueless about this + * stuff. Should be using SIGHUP instead of 1 though. + */ + kill (getpid (), 1); zen_data->exit_code = 1; gtk_main_quit (); break; -- cgit From 25d20adbd11319e7224ada5970c1a1b1ba6557df Mon Sep 17 00:00:00 2001 From: Mike Newman Date: Sat, 24 May 2003 09:15:50 +0000 Subject: Fix typo in gdialog wrapper. Sensitize OK button in progress when 100% reached. --- src/progress.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index f7444c42..aa06e7d4 100644 --- a/src/progress.c +++ b/src/progress.c @@ -105,9 +105,13 @@ zenity_progress_handle_stdin (GIOChannel *channel, /* Now try to convert the thing to a number */ percentage = atoi (string->str); - if (percentage > 100) + if (percentage >= 100) { + GtkWidget *button; + button = glade_xml_get_widget( glade_dialog,"zenity_progress_ok_button"); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), 1.0); - else + gtk_widget_set_sensitive(GTK_WIDGET (button), TRUE); + gtk_widget_grab_focus(GTK_WIDGET (button)); + } else gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), percentage / 100.0); } -- cgit From 626d95b752159fdcec1e7c08271f3eaca1113ab7 Mon Sep 17 00:00:00 2001 From: Mike Newman Date: Tue, 3 Jun 2003 21:52:16 +0000 Subject: Add --auto-close option to progress dialog. Closes dialog when 100% has been reached. Also update docs for new option. Fixes #114125. --- src/progress.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index aa06e7d4..dc0d74b3 100644 --- a/src/progress.c +++ b/src/progress.c @@ -28,7 +28,7 @@ static guint timer; static GladeXML *glade_dialog; - +static ZenityData *zen_data; static GIOChannel *channel; gint zenity_progress_timeout (gpointer data); @@ -111,6 +111,11 @@ zenity_progress_handle_stdin (GIOChannel *channel, gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), 1.0); gtk_widget_set_sensitive(GTK_WIDGET (button), TRUE); gtk_widget_grab_focus(GTK_WIDGET (button)); + if (progress_data->autoclose) { + zen_data->exit_code = 0; + gtk_main_quit(); + + } } else gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), percentage / 100.0); } @@ -165,6 +170,7 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) GtkWidget *progress_bar; guint input; + zen_data = data; glade_dialog = zenity_util_load_glade_file ("zenity_progress_dialog"); if (glade_dialog == NULL) { @@ -207,8 +213,6 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) static void zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data) { - ZenityData *zen_data = data; - switch (response) { case GTK_RESPONSE_OK: zen_data->exit_code = 0; -- cgit From 65cb873430d7bfcdf0452c76bf07f2ebbb4a21af Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Wed, 4 Jun 2003 12:53:46 +0000 Subject: Fix up some build warnings as reported by Ross Burton and his amazing gcc 2003-06-04 Glynn Foster * src/about.c, src/main.c, src/msg.c, src/progress.c, src/tree.c, src/util.c: Fix up some build warnings as reported by Ross Burton and his amazing gcc 3.3 techno machine. --- src/progress.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index dc0d74b3..0fa80882 100644 --- a/src/progress.c +++ b/src/progress.c @@ -22,6 +22,10 @@ */ #include +#include +#include +#include +#include #include #include "zenity.h" #include "util.h" @@ -168,7 +172,6 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) GtkWidget *dialog; GtkWidget *text; GtkWidget *progress_bar; - guint input; zen_data = data; glade_dialog = zenity_util_load_glade_file ("zenity_progress_dialog"); -- cgit From 5bade6fe6a14cce50508ee5d510a4560ebe3e421 Mon Sep 17 00:00:00 2001 From: Mike Newman Date: Sat, 7 Jun 2003 14:41:56 +0000 Subject: Support user-defined return values via env vars, like dialog did. --- src/progress.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 0fa80882..e07039be 100644 --- a/src/progress.c +++ b/src/progress.c @@ -116,7 +116,7 @@ zenity_progress_handle_stdin (GIOChannel *channel, gtk_widget_set_sensitive(GTK_WIDGET (button), TRUE); gtk_widget_grab_focus(GTK_WIDGET (button)); if (progress_data->autoclose) { - zen_data->exit_code = 0; + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); gtk_main_quit(); } @@ -177,7 +177,7 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) glade_dialog = zenity_util_load_glade_file ("zenity_progress_dialog"); if (glade_dialog == NULL) { - data->exit_code = -1; + data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); return; } @@ -218,7 +218,7 @@ zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data) { switch (response) { case GTK_RESPONSE_OK: - zen_data->exit_code = 0; + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); gtk_main_quit (); break; @@ -228,13 +228,13 @@ zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data) * stuff. Should be using SIGHUP instead of 1 though. */ kill (getpid (), 1); - zen_data->exit_code = 1; + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); gtk_main_quit (); break; default: /* Esc dialog */ - zen_data->exit_code = 1; + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); break; } } -- cgit From af594b60e97a43d8c60027971ed91029df5a7e67 Mon Sep 17 00:00:00 2001 From: Mike Newman Date: Fri, 13 Jun 2003 22:01:48 +0000 Subject: *** empty log message *** --- src/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index e07039be..c7ab5cf1 100644 --- a/src/progress.c +++ b/src/progress.c @@ -101,7 +101,7 @@ zenity_progress_handle_stdin (GIOChannel *channel, /* We have a comment, so let's try to change the label */ match = g_strstr_len (string->str, strlen (string->str), "#"); match++; - gtk_label_set_text (GTK_LABEL (progress_label), g_strchomp (g_strchug (match))); + gtk_label_set_text (GTK_LABEL (progress_label), g_strcompress(g_strchomp (g_strchug (match)))); } else { if (!g_ascii_isdigit (*(string->str))) -- cgit From b43bbda2e247e72782cf116003d308d21346935f Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Fri, 19 Mar 2004 02:28:30 +0000 Subject: Patch from Darren Adams to make sure the new 2004-03-19 Glynn Foster * src/calendar.c, src/entry.c, src/fileselection.c, src/msg.c, src/progress.c, src/text.c, src/tree.c: Patch from Darren Adams to make sure the new file chooser resizes nicely. Sanitize the default setting of the other widgets. * configure.in, src/util.c: Lose gconf dependancy since we don't currently use it, although arguably we should to detect which help browser we're supposed to run :/ * THANKS, src/about.c: Add Darren to the list. --- src/progress.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index c7ab5cf1..68c653d7 100644 --- a/src/progress.c +++ b/src/progress.c @@ -196,7 +196,8 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) else zenity_util_set_window_icon (dialog, ZENITY_IMAGE_FULLPATH ("zenity-progress.png")); - gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height); + if (data->width > -1 || data->height > -1) + gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height); text = glade_xml_get_widget (glade_dialog, "zenity_progress_text"); gtk_label_set_text (GTK_LABEL (text), progress_data->dialog_text); -- cgit From 62785ed80fb0b86847b4eaa3f4cf596f4c109324 Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Mon, 26 Apr 2004 04:41:25 +0000 Subject: Add from the 2 Sebastian's, and make email addresses more spam proof. 2004-04-26 Glynn Foster * THANKS, src/about.c: Add from the 2 Sebastian's, and make email addresses more spam proof. * src/calendar.c, src/entry.c, src/fileselection.c, src/msg.c, * src/progress.c, src/text.c, src/tree.c, src/util.c, * src/util.h: Patch from Sebastian Kapfer to make all zenity dialogs transients of the parent xterm. Fixes #136226. * src/zenity.glade: Patch from Sebastian Heinlein to improve things HIG wise. Fixes #140745. --- src/progress.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 68c653d7..3cc4bd9a 100644 --- a/src/progress.c +++ b/src/progress.c @@ -207,8 +207,8 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) if (progress_data->percentage > -1) gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), progress_data->percentage/100.0); - - gtk_widget_show (dialog); + + zenity_util_show_dialog (dialog); zenity_progress_read_info (progress_data); gtk_main (); -- cgit From 6c68b70ca3bb5ea719c5044a2e5d7959f87b1a06 Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Thu, 17 Jun 2004 23:38:39 +0000 Subject: Patch from Luke Suchocki to send HUP to parent instead of itself. Fixes 2004-06-18 Glynn Foster * THANKS, src/about.c, src/progress.c: Patch from Luke Suchocki to send HUP to parent instead of itself. Fixes #144542. --- src/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 3cc4bd9a..5804e88a 100644 --- a/src/progress.c +++ b/src/progress.c @@ -228,7 +228,7 @@ zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data) * I'm pretty sure there is a nice way to do this, but I'm clueless about this * stuff. Should be using SIGHUP instead of 1 though. */ - kill (getpid (), 1); + kill (getppid (), 1); zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); gtk_main_quit (); break; -- cgit From 63661a6ea0de0250b545d794f645a36ffeb88490 Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Mon, 19 Jul 2004 01:13:40 +0000 Subject: src/calendar.c, src/entry.c, src/fileselection.c, Cleanup fixes from Paul 2004-07-19 Glynn Foster * src/calendar.c, src/entry.c, src/fileselection.c, * src/msg.c, src/progress.c, src/text.c, src/tree.c: Cleanup fixes from Paul Bolle. --- src/progress.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 5804e88a..373c5b82 100644 --- a/src/progress.c +++ b/src/progress.c @@ -220,7 +220,6 @@ zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data) switch (response) { case GTK_RESPONSE_OK: zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); - gtk_main_quit (); break; case GTK_RESPONSE_CANCEL: @@ -230,7 +229,6 @@ zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data) */ kill (getppid (), 1); zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); - gtk_main_quit (); break; default: @@ -238,4 +236,5 @@ zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data) zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); break; } + gtk_main_quit (); } -- cgit From 3e05834b4c23a5d5951403719b8594ff3d9fe30b Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Mon, 13 Sep 2004 07:51:51 +0000 Subject: Add new notification icon. Update for new files. Restructure code a little 2004-09-13 Glynn Foster * data/Makefile.am, data/zenity-notification.png: Add new notification icon. * src/Makefile.am: Update for new files. * src/about.c, src/calendar.c, src/entry.c, src/fileselection.c, src/progress.c, src/text.c, src/tree.c, src/msg.c: Restructure code a little bit for new utility functions for setting window icons. * src/eggtrayicon.c, src/eggtrayicon.h: New files for notification area support. * src/main.c, src/notification.c, src/util.c, src/util.h, src/zenity.h: Add support for notification area. * data/zenity.1, help/*: Update docs for notification and new file selection changes. --- src/progress.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 373c5b82..ed727cae 100644 --- a/src/progress.c +++ b/src/progress.c @@ -191,10 +191,7 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) if (data->dialog_title) gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); - if (data->window_icon) - zenity_util_set_window_icon (dialog, data->window_icon); - else - zenity_util_set_window_icon (dialog, ZENITY_IMAGE_FULLPATH ("zenity-progress.png")); + zenity_util_set_window_icon (dialog, data->window_icon, ZENITY_IMAGE_FULLPATH ("zenity-progress.png")); if (data->width > -1 || data->height > -1) gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height); -- cgit From ca975e839996dbe1a85825b7f3472b170505540c Mon Sep 17 00:00:00 2001 From: Kjartan Maraas Date: Fri, 17 Sep 2004 08:57:21 +0000 Subject: Add missing header. Same ANSIfication. Closes bug #152851. 2004-09-17 Kjartan Maraas * src/progress.c: Add missing header. * src/tree.c: Same * src/util.c: (transient_get_xterm), (transient_get_xterm_toplevel): ANSIfication. Closes bug #152851. --- src/progress.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index ed727cae..734dd732 100644 --- a/src/progress.c +++ b/src/progress.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include "zenity.h" -- cgit From 6bac2fb94750123b9cbadc337d1434daf80c9889 Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Mon, 7 Feb 2005 01:56:02 +0000 Subject: If auto-close, close the dialog when the input stream finds an EOF. 2005-02-07 Glynn Foster * src/progress.c: If auto-close, close the dialog when the input stream finds an EOF. --- src/progress.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 734dd732..dfe9cef1 100644 --- a/src/progress.c +++ b/src/progress.c @@ -152,6 +152,11 @@ zenity_progress_handle_stdin (GIOChannel *channel, if (glade_dialog) g_object_unref (glade_dialog); + if (progress_data->autoclose) { + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); + gtk_main_quit(); + } + g_io_channel_shutdown (channel, TRUE, NULL); return FALSE; } -- cgit From 6abd93050f533752e47b75158e95431575c652ac Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Mon, 25 Apr 2005 03:20:45 +0000 Subject: COPYING, src/about.c, src/calendar.c, src/eggtrayicon.c, src/entry.c, 2005-04-25 Glynn Foster * COPYING, src/about.c, src/calendar.c, src/eggtrayicon.c, * src/entry.c, src/fileselection.c, src/main.c, src/msg.c, * src/notification.c, src/option.c, src/progress.c, * src/text.c, src/tree.c, src/util.c: Update the FSF address to point to 51 Franklin Street, Fifth Floor as per forwarded mail from Alvaro Lopez Ortega. --- src/progress.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index dfe9cef1..8d7b1dbe 100644 --- a/src/progress.c +++ b/src/progress.c @@ -15,8 +15,8 @@ * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. * * Authors: Glynn Foster */ -- cgit From 4c328078b6ff16a0ba648f53c3bee7a68fe4dbc5 Mon Sep 17 00:00:00 2001 From: Lucas Almeida Rocha Date: Wed, 6 Jul 2005 20:13:11 +0000 Subject: Include cleanups (config.h) --- src/progress.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 8d7b1dbe..d92d2e2d 100644 --- a/src/progress.c +++ b/src/progress.c @@ -21,6 +21,8 @@ * Authors: Glynn Foster */ +#include "config.h" + #include #include #include -- cgit From 21f7bc6a54636c749cf5514e091feb68cc88907b Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Fri, 8 Jul 2005 23:21:34 +0000 Subject: general code cleanups. Contribution from Benoît Dejean. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2005-07-08 Lucas Rocha * src/about.c, src/calendar.c, src/fileselection.c, src/option.c, src/progress.c, src/text.c, src/tree.c, src/util.c: general code cleanups. Contribution from Benoît Dejean. --- src/progress.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index d92d2e2d..34779c12 100644 --- a/src/progress.c +++ b/src/progress.c @@ -33,7 +33,6 @@ #include "zenity.h" #include "util.h" -static guint timer; static GladeXML *glade_dialog; static ZenityData *zen_data; static GIOChannel *channel; -- cgit From 5547de9384430dfccb9c3c8a68badfa120760b4a Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Tue, 15 Nov 2005 04:14:35 +0000 Subject: make it possible to add new lines and markup in the dialog text. 2005-11-15 Lucas Rocha * src/calendar.c, src/progress.c, src/tree.c: make it possible to add new lines and markup in the dialog text. --- src/progress.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 34779c12..68f34ac4 100644 --- a/src/progress.c +++ b/src/progress.c @@ -204,7 +204,9 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height); text = glade_xml_get_widget (glade_dialog, "zenity_progress_text"); - gtk_label_set_text (GTK_LABEL (text), progress_data->dialog_text); + + if (progress_data->dialog_text) + gtk_label_set_markup (GTK_LABEL (text), g_strcompress (progress_data->dialog_text)); progress_bar = glade_xml_get_widget (glade_dialog, "zenity_progress_bar"); -- cgit From 09c4a49800992d979845e3c7a05122b5aa1ceaed Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Sat, 2 Dec 2006 10:54:45 +0000 Subject: add "auto-kill" option to progress dialog. Now the user can choose whether 2006-12-02 Lucas Rocha * src/zenity.h, src/progress.c, src/option.c: add "auto-kill" option to progress dialog. Now the user can choose whether to kill parent process or not (Fixes bug #310824). Patch from Diego Escalante Urrelo . --- src/progress.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 68f34ac4..d14969b2 100644 --- a/src/progress.c +++ b/src/progress.c @@ -37,6 +37,8 @@ static GladeXML *glade_dialog; static ZenityData *zen_data; static GIOChannel *channel; +static gboolean autokill; + gint zenity_progress_timeout (gpointer data); gint zenity_progress_pulsate_timeout (gpointer data); @@ -214,6 +216,8 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), progress_data->percentage/100.0); + autokill = progress_data->autokill; + zenity_util_show_dialog (dialog); zenity_progress_read_info (progress_data); @@ -229,14 +233,19 @@ zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data) break; case GTK_RESPONSE_CANCEL: - /* FIXME: This should kill off the parent process nicely and return an error code - * I'm pretty sure there is a nice way to do this, but I'm clueless about this - * stuff. Should be using SIGHUP instead of 1 though. - */ - kill (getppid (), 1); + /* We do not want to kill the parent process, in order to give the user + the ability to choose the action to be taken. See bug #310824. + -- Monday 27, March 2006 + But we want to give people the option to choose this behavior. + */ + if (autokill) { + kill (getppid (), 1); + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); + break; + } zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); break; - + default: /* Esc dialog */ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); -- cgit From adee9db56646cc297fd226db983d40f3ba0d4793 Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Mon, 14 May 2007 21:26:08 +0000 Subject: general cleanups for build warnings (Fixes bug #416196). Patch from 2007-05-14 Lucas Rocha * src/progress.c (zenity_progress_handle_stdin), src/option.c (zenity_create_context), src/about.c, src/notification.c (zenity_notification_handle_stdin): general cleanups for build warnings (Fixes bug #416196). Patch from Kjartan Maraas . svn path=/trunk/; revision=1208 --- src/progress.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index d14969b2..b8ac1fc8 100644 --- a/src/progress.c +++ b/src/progress.c @@ -135,7 +135,6 @@ zenity_progress_handle_stdin (GIOChannel *channel, if (condition != G_IO_IN) { /* We assume that we are done, so stop the pulsating and de-sensitize the buttons */ GtkWidget *button; - GtkWidget *progress_bar; button = glade_xml_get_widget (glade_dialog, "zenity_progress_ok_button"); gtk_widget_set_sensitive (button, TRUE); @@ -144,7 +143,6 @@ zenity_progress_handle_stdin (GIOChannel *channel, button = glade_xml_get_widget (glade_dialog, "zenity_progress_cancel_button"); gtk_widget_set_sensitive (button, FALSE); - progress_bar = glade_xml_get_widget (glade_dialog, "zenity_progress_bar"); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), 1.0); if (progress_data->pulsate) { -- cgit From 8b16d4d4122e6337517ec16b9ca22dd27df0dafb Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Mon, 13 Aug 2007 20:36:29 +0000 Subject: added timeout option to all dialogs (Fixes bug #160654). Based on patch 2007-08-13 Lucas Rocha * src/*.c: added timeout option to all dialogs (Fixes bug #160654). Based on patch from Muthiah Annamalai . svn path=/trunk/; revision=1231 --- src/progress.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index b8ac1fc8..ffd87072 100644 --- a/src/progress.c +++ b/src/progress.c @@ -219,6 +219,10 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) zenity_util_show_dialog (dialog); zenity_progress_read_info (progress_data); + if(data->timeout_delay > 0) { + g_timeout_add (data->timeout_delay * 1000, (GSourceFunc) zenity_util_timeout_handle, NULL); + } + gtk_main (); } -- cgit From 3f33966167cf2216f813c091d47461c451837602 Mon Sep 17 00:00:00 2001 From: Felix Riemann Date: Mon, 20 Jul 2009 10:23:32 +0200 Subject: Bug 578393 – convert from libglade to GtkBuilder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/progress.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index ffd87072..a17a36ae 100644 --- a/src/progress.c +++ b/src/progress.c @@ -29,11 +29,10 @@ #include #include #include -#include #include "zenity.h" #include "util.h" -static GladeXML *glade_dialog; +static GtkBuilder *builder; static ZenityData *zen_data; static GIOChannel *channel; @@ -57,14 +56,14 @@ zenity_progress_handle_stdin (GIOChannel *channel, gpointer data) { static ZenityProgressData *progress_data; - static GtkWidget *progress_bar; - static GtkWidget *progress_label; + static GObject *progress_bar; + static GObject *progress_label; static gint pulsate_timeout = -1; float percentage = 0.0; progress_data = (ZenityProgressData *) data; - progress_bar = glade_xml_get_widget (glade_dialog, "zenity_progress_bar"); - progress_label = glade_xml_get_widget (glade_dialog, "zenity_progress_text"); + progress_bar = gtk_builder_get_object (builder, "zenity_progress_bar"); + progress_label = gtk_builder_get_object (builder, "zenity_progress_text"); if ((condition == G_IO_IN) || (condition == G_IO_IN + G_IO_HUP)) { GString *string; @@ -114,8 +113,8 @@ zenity_progress_handle_stdin (GIOChannel *channel, /* Now try to convert the thing to a number */ percentage = atoi (string->str); if (percentage >= 100) { - GtkWidget *button; - button = glade_xml_get_widget( glade_dialog,"zenity_progress_ok_button"); + GObject *button; + button = gtk_builder_get_object(builder, "zenity_progress_ok_button"); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), 1.0); gtk_widget_set_sensitive(GTK_WIDGET (button), TRUE); gtk_widget_grab_focus(GTK_WIDGET (button)); @@ -136,11 +135,13 @@ zenity_progress_handle_stdin (GIOChannel *channel, /* We assume that we are done, so stop the pulsating and de-sensitize the buttons */ GtkWidget *button; - button = glade_xml_get_widget (glade_dialog, "zenity_progress_ok_button"); + button = GTK_WIDGET (gtk_builder_get_object (builder, + "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"); + button = GTK_WIDGET (gtk_builder_get_object (builder, + "zenity_progress_cancel_button")); gtk_widget_set_sensitive (button, FALSE); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), 1.0); @@ -150,8 +151,7 @@ zenity_progress_handle_stdin (GIOChannel *channel, pulsate_timeout = -1; } - if (glade_dialog) - g_object_unref (glade_dialog); + g_object_unref (builder); if (progress_data->autoclose) { zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); @@ -177,20 +177,21 @@ void zenity_progress (ZenityData *data, ZenityProgressData *progress_data) { GtkWidget *dialog; - GtkWidget *text; - GtkWidget *progress_bar; + GObject *text; + GObject *progress_bar; zen_data = data; - glade_dialog = zenity_util_load_glade_file ("zenity_progress_dialog"); + builder = zenity_util_load_ui_file ("zenity_progress_dialog", NULL); - if (glade_dialog == NULL) { + if (builder == NULL) { data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); return; } - glade_xml_signal_autoconnect (glade_dialog); + gtk_builder_connect_signals (builder, NULL); - dialog = glade_xml_get_widget (glade_dialog, "zenity_progress_dialog"); + dialog = GTK_WIDGET (gtk_builder_get_object (builder, + "zenity_progress_dialog")); g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (zenity_progress_dialog_response), data); @@ -203,12 +204,12 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) if (data->width > -1 || data->height > -1) gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height); - text = glade_xml_get_widget (glade_dialog, "zenity_progress_text"); + text = gtk_builder_get_object (builder, "zenity_progress_text"); if (progress_data->dialog_text) gtk_label_set_markup (GTK_LABEL (text), g_strcompress (progress_data->dialog_text)); - progress_bar = glade_xml_get_widget (glade_dialog, "zenity_progress_bar"); + progress_bar = gtk_builder_get_object (builder, "zenity_progress_bar"); if (progress_data->percentage > -1) gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), -- cgit From 5c6a48f6843bbc133a2c9b48ecc67c7a271474f2 Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Sat, 8 Aug 2009 10:51:52 +0100 Subject: [progress] Cosmetic fix in code comment --- src/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index a17a36ae..485f4797 100644 --- a/src/progress.c +++ b/src/progress.c @@ -238,8 +238,8 @@ zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data) case GTK_RESPONSE_CANCEL: /* We do not want to kill the parent process, in order to give the user the ability to choose the action to be taken. See bug #310824. + But we want to give people the option to choose this behavior. -- Monday 27, March 2006 - But we want to give people the option to choose this behavior. */ if (autokill) { kill (getppid (), 1); -- cgit From 25ec1ed3bb17675c2e522e175676f5fa1551c0e7 Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Sat, 8 Aug 2009 11:21:24 +0100 Subject: [progress] Remove duplicate code when returning --- src/progress.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 485f4797..668f4277 100644 --- a/src/progress.c +++ b/src/progress.c @@ -243,8 +243,6 @@ zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data) */ if (autokill) { kill (getppid (), 1); - zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); - break; } zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); break; -- cgit From 54b171ff82c39fcc178c1366fdee94bb6555dead Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Sat, 8 Aug 2009 18:19:33 +0100 Subject: [progress] coding style fixes --- src/progress.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 668f4277..9d6e8bb3 100644 --- a/src/progress.c +++ b/src/progress.c @@ -113,17 +113,16 @@ zenity_progress_handle_stdin (GIOChannel *channel, /* Now try to convert the thing to a number */ percentage = atoi (string->str); if (percentage >= 100) { - GObject *button; - button = gtk_builder_get_object(builder, "zenity_progress_ok_button"); + GObject *button; + button = gtk_builder_get_object(builder, "zenity_progress_ok_button"); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), 1.0); - gtk_widget_set_sensitive(GTK_WIDGET (button), TRUE); - gtk_widget_grab_focus(GTK_WIDGET (button)); - if (progress_data->autoclose) { - zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); - gtk_main_quit(); - - } - } else + gtk_widget_set_sensitive(GTK_WIDGET (button), TRUE); + gtk_widget_grab_focus(GTK_WIDGET (button)); + if (progress_data->autoclose) { + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); + gtk_main_quit(); + } + } else gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), percentage / 100.0); } @@ -136,14 +135,15 @@ zenity_progress_handle_stdin (GIOChannel *channel, GtkWidget *button; button = GTK_WIDGET (gtk_builder_get_object (builder, - "zenity_progress_ok_button")); + "zenity_progress_ok_button")); gtk_widget_set_sensitive (button, TRUE); gtk_widget_grab_focus (button); button = GTK_WIDGET (gtk_builder_get_object (builder, - "zenity_progress_cancel_button")); + "zenity_progress_cancel_button")); + gtk_widget_set_sensitive (button, FALSE); - + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), 1.0); if (progress_data->pulsate) { @@ -157,7 +157,7 @@ zenity_progress_handle_stdin (GIOChannel *channel, zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); gtk_main_quit(); } - + g_io_channel_shutdown (channel, TRUE, NULL); return FALSE; } @@ -187,15 +187,15 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); return; } - + gtk_builder_connect_signals (builder, NULL); - + dialog = GTK_WIDGET (gtk_builder_get_object (builder, - "zenity_progress_dialog")); + "zenity_progress_dialog")); g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (zenity_progress_dialog_response), data); - + if (data->dialog_title) gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); @@ -234,12 +234,12 @@ zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data) case GTK_RESPONSE_OK: zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); break; - + case GTK_RESPONSE_CANCEL: /* We do not want to kill the parent process, in order to give the user the ability to choose the action to be taken. See bug #310824. - But we want to give people the option to choose this behavior. - -- Monday 27, March 2006 + But we want to give people the option to choose this behavior. + -- Monday 27, March 2006 */ if (autokill) { kill (getppid (), 1); -- cgit From fa0349545d65df0ce1c8b4de2cedc5824c7a5866 Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Sat, 8 Aug 2009 19:16:49 +0100 Subject: [progress] Factor out function to control pulsate --- src/progress.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 9d6e8bb3..8a6e10fc 100644 --- a/src/progress.c +++ b/src/progress.c @@ -36,6 +36,7 @@ static GtkBuilder *builder; static ZenityData *zen_data; static GIOChannel *channel; +static gint pulsate_timeout = -1; static gboolean autokill; gint zenity_progress_timeout (gpointer data); @@ -50,6 +51,25 @@ zenity_progress_pulsate_progress_bar (gpointer user_data) return TRUE; } +static void +zenity_progress_pulsate_stop () +{ + if (pulsate_timeout > 0) { + g_source_remove (pulsate_timeout); + pulsate_timeout = -1; + } +} + +static void +zenity_progress_pulsate_start (GObject *progress_bar) +{ + if (pulsate_timeout == -1) { + pulsate_timeout = g_timeout_add (100, + zenity_progress_pulsate_progress_bar, + progress_bar); + } +} + static gboolean zenity_progress_handle_stdin (GIOChannel *channel, GIOCondition condition, @@ -58,7 +78,6 @@ zenity_progress_handle_stdin (GIOChannel *channel, static ZenityProgressData *progress_data; static GObject *progress_bar; static GObject *progress_label; - static gint pulsate_timeout = -1; float percentage = 0.0; progress_data = (ZenityProgressData *) data; @@ -72,8 +91,7 @@ zenity_progress_handle_stdin (GIOChannel *channel, string = g_string_new (NULL); if (progress_data->pulsate) { - if (pulsate_timeout == -1) - pulsate_timeout = g_timeout_add (100, zenity_progress_pulsate_progress_bar, progress_bar); + zenity_progress_pulsate_start (progress_bar); } while (channel->is_readable != TRUE) @@ -146,10 +164,7 @@ zenity_progress_handle_stdin (GIOChannel *channel, gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), 1.0); - if (progress_data->pulsate) { - g_source_remove (pulsate_timeout); - pulsate_timeout = -1; - } + zenity_progress_pulsate_stop (); g_object_unref (builder); -- cgit From a66e4df5d1c0ebb485d5f3f8a24129366d2ff598 Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Sat, 8 Aug 2009 18:15:42 +0100 Subject: Bug 556198 – Support toggling pulsate in progressbar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/progress.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 8a6e10fc..a0868eaa 100644 --- a/src/progress.c +++ b/src/progress.c @@ -123,6 +123,33 @@ zenity_progress_handle_stdin (GIOChannel *channel, match = g_strstr_len (string->str, strlen (string->str), "#"); match++; gtk_label_set_text (GTK_LABEL (progress_label), g_strcompress(g_strchomp (g_strchug (match)))); + + } else if (g_str_has_prefix (string->str, "pulsate")) { + gchar *colon, *command, *value; + + zenity_util_strip_newline (string->str); + + colon = strchr(string->str, ':'); + if (colon == NULL) { + continue; + } + + /* split off the command and value */ + command = g_strstrip (g_strndup (string->str, colon - string->str)); + + value = colon + 1; + while (*value && g_ascii_isspace (*value)) value++; + + if (!g_ascii_strcasecmp (value, "false")) { + zenity_progress_pulsate_stop (); + + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), + progress_data->percentage / 100.0); + } else { + zenity_progress_pulsate_start (progress_bar); + } + + g_free (command); } else { if (!g_ascii_isdigit (*(string->str))) @@ -134,14 +161,17 @@ zenity_progress_handle_stdin (GIOChannel *channel, GObject *button; button = gtk_builder_get_object(builder, "zenity_progress_ok_button"); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), 1.0); + progress_data->percentage = 100; gtk_widget_set_sensitive(GTK_WIDGET (button), TRUE); gtk_widget_grab_focus(GTK_WIDGET (button)); if (progress_data->autoclose) { zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); gtk_main_quit(); } - } else + } else { gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), percentage / 100.0); + progress_data->percentage = percentage; + } } } while (g_io_channel_get_buffer_condition (channel) == G_IO_IN); -- cgit From f0dfc8a82038de334c545a4add70851051dabccc Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Mon, 10 Aug 2009 03:22:05 +0100 Subject: [progress] Improve code to update of percentage --- src/progress.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index a0868eaa..bc1c102d 100644 --- a/src/progress.c +++ b/src/progress.c @@ -156,21 +156,24 @@ zenity_progress_handle_stdin (GIOChannel *channel, continue; /* Now try to convert the thing to a number */ - percentage = atoi (string->str); - if (percentage >= 100) { + percentage = CLAMP(atoi (string->str), 0, 100); + + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), + percentage / 100.0); + + progress_data->percentage = percentage; + + if (percentage == 100) { GObject *button; + button = gtk_builder_get_object(builder, "zenity_progress_ok_button"); - gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), 1.0); - progress_data->percentage = 100; gtk_widget_set_sensitive(GTK_WIDGET (button), TRUE); gtk_widget_grab_focus(GTK_WIDGET (button)); + if (progress_data->autoclose) { zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); gtk_main_quit(); } - } else { - gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), percentage / 100.0); - progress_data->percentage = percentage; } } -- cgit From 3c17a5a8870422b9a9145ff805d6d3bb872dacea Mon Sep 17 00:00:00 2001 From: Huzaifa Sidhpurwala Date: Tue, 23 Feb 2010 18:07:08 +0000 Subject: Bug 593926 - --progress needs a --nocancel option --- src/progress.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index bc1c102d..40f91821 100644 --- a/src/progress.c +++ b/src/progress.c @@ -38,6 +38,8 @@ static GIOChannel *channel; static gint pulsate_timeout = -1; static gboolean autokill; +static gboolean no_cancel; +static gboolean auto_close; gint zenity_progress_timeout (gpointer data); gint zenity_progress_pulsate_timeout (gpointer data); @@ -227,6 +229,7 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) GtkWidget *dialog; GObject *text; GObject *progress_bar; + GObject *cancel_button,*ok_button; zen_data = data; builder = zenity_util_load_ui_file ("zenity_progress_dialog", NULL); @@ -265,6 +268,20 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) autokill = progress_data->autokill; + auto_close = progress_data->autoclose; + ok_button = gtk_builder_get_object (builder, "zenity_progress_ok_button"); + + no_cancel = progress_data->no_cancel; + cancel_button = gtk_builder_get_object (builder, "zenity_progress_cancel_button"); + + if (no_cancel) { + gtk_widget_hide (GTK_WIDGET(cancel_button)); + gtk_window_set_deletable (GTK_WINDOW (dialog), FALSE); + } + + if (no_cancel && auto_close) + gtk_widget_hide(GTK_WIDGET(ok_button)); + zenity_util_show_dialog (dialog); zenity_progress_read_info (progress_data); -- cgit From 1570a2bbf07627cb5f8d9828a95db67b7d00634c Mon Sep 17 00:00:00 2001 From: Philippe Gauthier Date: Fri, 30 Oct 2009 14:51:16 -0400 Subject: Use g_timeout_add_seconds instead g_timeout_add The calls to g_timeout_add are replaced with g_timeout_add_seconds to reduce the number or program wake ups. See the GNOME Goal description: http://live.gnome.org/GnomeGoals/UseTimeoutAddSeconds --- src/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 40f91821..4f1f55ef 100644 --- a/src/progress.c +++ b/src/progress.c @@ -286,7 +286,7 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) zenity_progress_read_info (progress_data); if(data->timeout_delay > 0) { - g_timeout_add (data->timeout_delay * 1000, (GSourceFunc) zenity_util_timeout_handle, NULL); + g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, NULL); } gtk_main (); -- cgit From ef3a33a142620fee850351d14f4a1c191fc6e273 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Sun, 2 Jan 2011 22:57:42 -0200 Subject: Fix for bug 540560. Patch by Victor Ananjevsky --- src/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 4f1f55ef..29814d91 100644 --- a/src/progress.c +++ b/src/progress.c @@ -183,7 +183,7 @@ zenity_progress_handle_stdin (GIOChannel *channel, g_string_free (string, TRUE); } - if (condition != G_IO_IN) { + if ((condition != G_IO_IN) && (condition != G_IO_IN + G_IO_HUP)) { /* We assume that we are done, so stop the pulsating and de-sensitize the buttons */ GtkWidget *button; -- cgit From b39ad33c35bb93c647e7f6f05d1310a0ce6895d5 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Thu, 16 Jun 2011 11:07:58 -0300 Subject: Bug 651948 - zenity list does not return default value when timeout is over --- src/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 29814d91..2533aa1c 100644 --- a/src/progress.c +++ b/src/progress.c @@ -286,7 +286,7 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) zenity_progress_read_info (progress_data); if(data->timeout_delay > 0) { - g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, NULL); + g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, dialog); } gtk_main (); -- cgit From d60e5eeeb379e5444ad218d7335b17eaa821b182 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Fri, 17 Jun 2011 10:47:07 -0300 Subject: Now if you use --timeout option, the return code will be properly handled The default behavior will be done (ie. user click on ok button) The return code will be 5 --- src/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 2533aa1c..6dc93f87 100644 --- a/src/progress.c +++ b/src/progress.c @@ -297,7 +297,7 @@ zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data) { switch (response) { case GTK_RESPONSE_OK: - zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); + zenity_util_exit_code_with_data(ZENITY_OK, zen_data); break; case GTK_RESPONSE_CANCEL: -- cgit From 6768a40e997697d05008aecdb41815e1dbae61c6 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Tue, 26 Jul 2011 14:00:28 -0300 Subject: Fix for bug #611297 Now Zenity have --ok-label and --cancel-label in all dialogs. This patch doesn't break old zenity scripts. --- src/progress.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 6dc93f87..b16e400d 100644 --- a/src/progress.c +++ b/src/progress.c @@ -227,6 +227,7 @@ void zenity_progress (ZenityData *data, ZenityProgressData *progress_data) { GtkWidget *dialog; + GtkWidget *button; GObject *text; GObject *progress_bar; GObject *cancel_button,*ok_button; @@ -255,6 +256,20 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) if (data->width > -1 || data->height > -1) gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height); + if (data->ok_label) { + button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_progress_ok_button")); + gtk_button_set_label (GTK_BUTTON (button), data->ok_label); + gtk_button_set_image (GTK_BUTTON (button), + gtk_image_new_from_stock (GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON)); + } + + if (data->cancel_label) { + button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_progress_cancel_button")); + gtk_button_set_label (GTK_BUTTON (button), data->cancel_label); + gtk_button_set_image (GTK_BUTTON (button), + gtk_image_new_from_stock (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON)); + } + text = gtk_builder_get_object (builder, "zenity_progress_text"); if (progress_data->dialog_text) -- cgit From 1e88554c3f18c5b92a8a2724bf36d875eb6bd8f0 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Thu, 19 Apr 2012 16:10:21 -0300 Subject: Fix for Bug 567663. Now the --pulsate option works properly --- src/progress.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index b16e400d..d17b3599 100644 --- a/src/progress.c +++ b/src/progress.c @@ -92,10 +92,6 @@ zenity_progress_handle_stdin (GIOChannel *channel, string = g_string_new (NULL); - if (progress_data->pulsate) { - zenity_progress_pulsate_start (progress_bar); - } - while (channel->is_readable != TRUE) ; do { @@ -221,6 +217,14 @@ zenity_progress_read_info (ZenityProgressData *progress_data) g_io_channel_set_encoding (channel, NULL, NULL); g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL); g_io_add_watch (channel, G_IO_IN | G_IO_HUP, zenity_progress_handle_stdin, progress_data); + /* We need to check the pulsate state here, because, the g_io_add_watch + doesn't call the zenity_progress_handle_stdin function if there's no + input. This fix the Bug 567663 */ + if (progress_data->pulsate) { + GObject *progress_bar = gtk_builder_get_object (builder, "zenity_progress_bar"); + zenity_progress_pulsate_start (progress_bar); + g_object_unref(progress_bar); + } } void -- cgit From cb5f17a2df9fd06520d7078c50b781fc320e47a5 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Thu, 19 Apr 2012 17:32:59 -0300 Subject: Wrong unref object --- src/progress.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index d17b3599..6763376d 100644 --- a/src/progress.c +++ b/src/progress.c @@ -223,7 +223,6 @@ zenity_progress_read_info (ZenityProgressData *progress_data) if (progress_data->pulsate) { GObject *progress_bar = gtk_builder_get_object (builder, "zenity_progress_bar"); zenity_progress_pulsate_start (progress_bar); - g_object_unref(progress_bar); } } -- cgit From 5dd7442bd5b544a99553b6e595419ed999ae6eab Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sun, 12 Aug 2012 12:20:07 -0400 Subject: Fix various compiler warnings (two serious) Missing sentinels can cause crashes. The others are just style. --- src/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 6763376d..3e6f5a2c 100644 --- a/src/progress.c +++ b/src/progress.c @@ -54,7 +54,7 @@ zenity_progress_pulsate_progress_bar (gpointer user_data) } static void -zenity_progress_pulsate_stop () +zenity_progress_pulsate_stop (void) { if (pulsate_timeout > 0) { g_source_remove (pulsate_timeout); -- cgit From 0628bd3291aad936b6b553366600590cca360bfa Mon Sep 17 00:00:00 2001 From: Florian Müllner Date: Tue, 18 Sep 2012 18:33:07 +0200 Subject: util: Add an option to request dialogs being modal As WMs cannot open windows themselves, Mutter uses zenity to open "Force Quit" dialogs for unresponsive windows; as those are strongly tied to the corresponding window, it makes sense to make them modal (in particular when attaching them to their parent). https://bugzilla.gnome.org/show_bug.cgi?id=684322 --- src/progress.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 3e6f5a2c..fca31c82 100644 --- a/src/progress.c +++ b/src/progress.c @@ -259,6 +259,9 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) if (data->width > -1 || data->height > -1) gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height); + if (data->modal) + gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); + if (data->ok_label) { button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_progress_ok_button")); gtk_button_set_label (GTK_BUTTON (button), data->ok_label); -- cgit From 1ac1da63f8de626ce10d350be7b29744a743ec95 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Tue, 5 Mar 2013 16:56:24 -0300 Subject: But #674881 - Timeout option overriding normal exit code --- src/progress.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index fca31c82..c382d74d 100644 --- a/src/progress.c +++ b/src/progress.c @@ -307,7 +307,7 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) zenity_progress_read_info (progress_data); if(data->timeout_delay > 0) { - g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, dialog); + g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, NULL); } gtk_main (); @@ -333,6 +333,9 @@ zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data) zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); break; + case ZENITY_TIMEOUT: + zenity_util_exit_code_with_data (ZENITY_TIMEOUT, zen_data); + break; default: /* Esc dialog */ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); -- cgit From c89ce9c3812fdc3a2637fd76b42a07385ad50684 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Tue, 4 Jun 2013 16:27:48 -0300 Subject: Bug #653468. Fixed by Kurt Miller . Fix the broken auto-close option in progress and list dialogs. --- src/progress.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index c382d74d..055699c0 100644 --- a/src/progress.c +++ b/src/progress.c @@ -81,12 +81,13 @@ zenity_progress_handle_stdin (GIOChannel *channel, static GObject *progress_bar; static GObject *progress_label; float percentage = 0.0; + GIOStatus status = G_IO_STATUS_NORMAL; progress_data = (ZenityProgressData *) data; progress_bar = gtk_builder_get_object (builder, "zenity_progress_bar"); progress_label = gtk_builder_get_object (builder, "zenity_progress_text"); - if ((condition == G_IO_IN) || (condition == G_IO_IN + G_IO_HUP)) { + if ((condition & G_IO_IN) != 0) { GString *string; GError *error = NULL; @@ -95,8 +96,6 @@ zenity_progress_handle_stdin (GIOChannel *channel, while (channel->is_readable != TRUE) ; do { - gint status; - do { status = g_io_channel_read_line_string (channel, string, NULL, &error); @@ -175,11 +174,11 @@ zenity_progress_handle_stdin (GIOChannel *channel, } } - } while (g_io_channel_get_buffer_condition (channel) == G_IO_IN); + } while ((g_io_channel_get_buffer_condition (channel) & G_IO_IN) == G_IO_IN && status != G_IO_STATUS_EOF); g_string_free (string, TRUE); } - if ((condition != G_IO_IN) && (condition != G_IO_IN + G_IO_HUP)) { + if ((condition & G_IO_IN) != G_IO_IN || status == G_IO_STATUS_EOF) { /* We assume that we are done, so stop the pulsating and de-sensitize the buttons */ GtkWidget *button; -- cgit From 009523d5da827392b027ac6da1a50f94314e3a35 Mon Sep 17 00:00:00 2001 From: Weitian Leung Date: Fri, 23 Aug 2013 09:15:07 +0800 Subject: added attach option for transient window --- src/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 055699c0..cbffe08e 100644 --- a/src/progress.c +++ b/src/progress.c @@ -302,7 +302,7 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) if (no_cancel && auto_close) gtk_widget_hide(GTK_WIDGET(ok_button)); - zenity_util_show_dialog (dialog); + zenity_util_show_dialog (dialog, data->attach); zenity_progress_read_info (progress_data); if(data->timeout_delay > 0) { -- cgit From 673550b6d326e111867fa78ba4d796045715202e Mon Sep 17 00:00:00 2001 From: Scott Pakin Date: Tue, 5 Aug 2014 15:22:12 -0600 Subject: Added time-remaining support to progress bars Introduced a --time-remaining command-line option that uses the time and percent complete to extrapolate the time remaining until progress reaches 100%. --- src/progress.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index cbffe08e..00544873 100644 --- a/src/progress.c +++ b/src/progress.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "zenity.h" #include "util.h" @@ -72,6 +73,39 @@ zenity_progress_pulsate_start (GObject *progress_bar) } } +static void +zenity_progress_update_time_remaining (ZenityProgressData *progress_data) +{ + static GObject *progress_time = NULL; + static time_t start_time = (time_t)(-1); + float percentage = progress_data->percentage; + + if (progress_time == NULL) + progress_time = gtk_builder_get_object (builder, "zenity_progress_time"); + if (start_time == (time_t)(-1) || percentage <= 0.0 || percentage >= 100.0) { + start_time = time(NULL); + gtk_label_set_text (GTK_LABEL (progress_time), ""); + } else { + time_t current_time = time (NULL); + time_t elapsed_time = current_time - start_time; + time_t total_time = (time_t) (100.0*elapsed_time/progress_data->percentage); + time_t remaining_time = total_time - elapsed_time; + gulong hours, minutes, seconds; + gchar *remaining_message; + + seconds = (gulong) (remaining_time%60); + remaining_time /= 60; + minutes = (gulong) (remaining_time%60); + remaining_time /= 60; + hours = (gulong) remaining_time; + + remaining_message = g_strdup_printf (_("Time remaining: %lu:%02lu:%02lu"), + hours, minutes, seconds); + gtk_label_set_text (GTK_LABEL (progress_time), remaining_message); + g_free (remaining_message); + } +} + static gboolean zenity_progress_handle_stdin (GIOChannel *channel, GIOCondition condition, @@ -160,6 +194,9 @@ zenity_progress_handle_stdin (GIOChannel *channel, progress_data->percentage = percentage; + if (progress_data->time_remaining == TRUE) + zenity_progress_update_time_remaining (progress_data); + if (percentage == 100) { GObject *button; -- cgit From 6ac663ea05f00aa42d2aa620968e26e525487201 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Tue, 21 Oct 2014 16:05:31 +0200 Subject: Fixing remain g_timeout_add Finish switch g_timeout_add for g_timeout_add_seconds --- src/progress.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 00544873..1963f16e 100644 --- a/src/progress.c +++ b/src/progress.c @@ -67,9 +67,9 @@ static void zenity_progress_pulsate_start (GObject *progress_bar) { if (pulsate_timeout == -1) { - pulsate_timeout = g_timeout_add (100, - zenity_progress_pulsate_progress_bar, - progress_bar); + pulsate_timeout = g_timeout_add_seconds (100, + zenity_progress_pulsate_progress_bar, + progress_bar); } } -- cgit From b44b2fb33dac0618e355f8cd5c46be0b3d13eadc Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Tue, 21 Oct 2014 16:32:14 +0200 Subject: Fixing g_timeout_add calls --- src/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 1963f16e..185da2f2 100644 --- a/src/progress.c +++ b/src/progress.c @@ -67,7 +67,7 @@ static void zenity_progress_pulsate_start (GObject *progress_bar) { if (pulsate_timeout == -1) { - pulsate_timeout = g_timeout_add_seconds (100, + pulsate_timeout = g_timeout_add (100, zenity_progress_pulsate_progress_bar, progress_bar); } -- cgit From b5460887fb2b37d1f7aa2edc5dc53b86152cfb2a Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Wed, 22 Oct 2014 15:35:22 +0200 Subject: Bug #700249 - Progress dialog does not wrap --- src/progress.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 185da2f2..3fd2c2ef 100644 --- a/src/progress.c +++ b/src/progress.c @@ -262,6 +262,12 @@ zenity_progress_read_info (ZenityProgressData *progress_data) } } +static void +zenity_text_size_allocate (GtkWidget *widget, GtkAllocation *allocation, gpointer data) +{ + gtk_widget_set_size_request (widget, allocation->width/2, -1); +} + void zenity_progress (ZenityData *data, ZenityProgressData *progress_data) { @@ -281,6 +287,8 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) gtk_builder_connect_signals (builder, NULL); + text = gtk_builder_get_object (builder, "zenity_progress_text"); + dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_progress_dialog")); @@ -295,6 +303,16 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) if (data->width > -1 || data->height > -1) gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height); + if (data->width > -1) { + gtk_widget_set_size_request (GTK_WIDGET (text), data->width, -1); + } + else { + g_signal_connect_after (G_OBJECT (text), "size-allocate", + G_CALLBACK (zenity_text_size_allocate), data); + g_signal_connect_after (G_OBJECT (progress_bar), "size-allocate", + G_CALLBACK (zenity_text_size_allocate), data); + } + if (data->modal) gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); @@ -312,8 +330,6 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) gtk_image_new_from_stock (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON)); } - text = gtk_builder_get_object (builder, "zenity_progress_text"); - if (progress_data->dialog_text) gtk_label_set_markup (GTK_LABEL (text), g_strcompress (progress_data->dialog_text)); -- cgit From 6fcbb80fd1b5268fbedcdb985ffa873a2e475840 Mon Sep 17 00:00:00 2001 From: Javier Jardón Date: Sun, 22 Mar 2015 04:57:05 +0000 Subject: Do not use an icon for Cancel/OK buttons GTK+ documentation recommends to not use an icons, but use "_OK"/"_Cancel" labels instead --- src/progress.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 3fd2c2ef..dfbdd8a9 100644 --- a/src/progress.c +++ b/src/progress.c @@ -319,15 +319,11 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) if (data->ok_label) { button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_progress_ok_button")); gtk_button_set_label (GTK_BUTTON (button), data->ok_label); - gtk_button_set_image (GTK_BUTTON (button), - gtk_image_new_from_stock (GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON)); } if (data->cancel_label) { button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_progress_cancel_button")); gtk_button_set_label (GTK_BUTTON (button), data->cancel_label); - gtk_button_set_image (GTK_BUTTON (button), - gtk_image_new_from_stock (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON)); } if (progress_data->dialog_text) -- cgit From ba5ea0386de2a80a664fb28d3af7e8d395968314 Mon Sep 17 00:00:00 2001 From: Gama Anderson Date: Sat, 28 Feb 2015 20:06:09 +0100 Subject: ADD gchar **extra_label TO struct ZenityData this is done to keep the name of the extra buttons ADD general option "extra-button" with string array as argument This will upon consecutive calls save the name of buttons in an array of strings To all MODES, except notification.c and about.c ADD if (data->extra_label) { gint i=0; while(data->extra_label[i]!=NULL){ gtk_dialog_add_button (GTK_DIALOG (dialog), data->extra_label[i], i); i++; } } This add the extra buttons to the dialog. The response is the number of the button To all MODES response, except notification.c and about.c ADD default: if (response < g_strv_length(zen_data->extra_label)) printf("%s\n",zen_data->extra_label[response]); This will print the button name to stdout when they are pressed ADD question option "switch" This will suppress the standard "ok" and "cancel" button in question. This just wort in combination with --extra-button, otherwise error is raised. https://bugzilla.gnome.org/show_bug.cgi?id=118016 --- src/progress.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 3fd2c2ef..409175fa 100644 --- a/src/progress.c +++ b/src/progress.c @@ -316,6 +316,14 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) if (data->modal) gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); + if (data->extra_label) { + gint i=0; + while(data->extra_label[i]!=NULL){ + gtk_dialog_add_button (GTK_DIALOG (dialog), data->extra_label[i], i); + i++; + } + } + if (data->ok_label) { button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_progress_ok_button")); gtk_button_set_label (GTK_BUTTON (button), data->ok_label); @@ -389,7 +397,8 @@ zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data) zenity_util_exit_code_with_data (ZENITY_TIMEOUT, zen_data); break; default: - /* Esc dialog */ + if (response < g_strv_length(zen_data->extra_label)) + printf("%s\n",zen_data->extra_label[response]); zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); break; } -- cgit From 8fcde2b8423526eb1f2ab8bbe8e07a0350283927 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Fri, 29 May 2015 13:53:25 +0200 Subject: Fix uninitialized progress_bar error --- src/progress.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index d8ecea52..8e458c66 100644 --- a/src/progress.c +++ b/src/progress.c @@ -292,6 +292,8 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_progress_dialog")); + progress_bar = gtk_builder_get_object (builder, "zenity_progress_bar"); + g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (zenity_progress_dialog_response), data); @@ -337,8 +339,6 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) if (progress_data->dialog_text) gtk_label_set_markup (GTK_LABEL (text), g_strcompress (progress_data->dialog_text)); - progress_bar = gtk_builder_get_object (builder, "zenity_progress_bar"); - if (progress_data->percentage > -1) gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), progress_data->percentage/100.0); -- cgit From d063797fdfa73e5bec96d9399ab1bf47173a62d4 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Fri, 2 Oct 2015 14:35:06 +0200 Subject: Fixing GLib-CRITICAL messages --- src/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 8e458c66..4995c5fd 100644 --- a/src/progress.c +++ b/src/progress.c @@ -393,7 +393,7 @@ zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data) zenity_util_exit_code_with_data (ZENITY_TIMEOUT, zen_data); break; default: - if (response < g_strv_length(zen_data->extra_label)) + if (zen_data->extra_label && response < g_strv_length(zen_data->extra_label)) printf("%s\n",zen_data->extra_label[response]); zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); break; -- cgit From 4eddb202cafdcabc254aa941ad1348ff09372627 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Fri, 7 Apr 2017 14:00:42 +0200 Subject: Fix style Fixing style in all zenity code, removing useless spaces, empty lines, all code in 80 columns, etc. --- src/progress.c | 673 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 350 insertions(+), 323 deletions(-) (limited to 'src/progress.c') diff --git a/src/progress.c b/src/progress.c index 4995c5fd..1a5a68fd 100644 --- a/src/progress.c +++ b/src/progress.c @@ -23,15 +23,15 @@ #include "config.h" +#include "util.h" +#include "zenity.h" +#include #include -#include #include +#include #include -#include -#include #include -#include "zenity.h" -#include "util.h" +#include static GtkBuilder *builder; static ZenityData *zen_data; @@ -45,358 +45,385 @@ static gboolean auto_close; 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); +static void zenity_progress_dialog_response ( + GtkWidget *widget, int response, gpointer data); static gboolean -zenity_progress_pulsate_progress_bar (gpointer user_data) -{ - gtk_progress_bar_pulse (GTK_PROGRESS_BAR (user_data)); - return TRUE; +zenity_progress_pulsate_progress_bar (gpointer user_data) { + gtk_progress_bar_pulse (GTK_PROGRESS_BAR (user_data)); + return TRUE; } static void -zenity_progress_pulsate_stop (void) -{ - if (pulsate_timeout > 0) { - g_source_remove (pulsate_timeout); - pulsate_timeout = -1; - } +zenity_progress_pulsate_stop (void) { + if (pulsate_timeout > 0) { + g_source_remove (pulsate_timeout); + pulsate_timeout = -1; + } } static void -zenity_progress_pulsate_start (GObject *progress_bar) -{ - if (pulsate_timeout == -1) { - pulsate_timeout = g_timeout_add (100, - zenity_progress_pulsate_progress_bar, - progress_bar); - } +zenity_progress_pulsate_start (GObject *progress_bar) { + if (pulsate_timeout == -1) { + pulsate_timeout = g_timeout_add ( + 100, zenity_progress_pulsate_progress_bar, progress_bar); + } } static void -zenity_progress_update_time_remaining (ZenityProgressData *progress_data) -{ - static GObject *progress_time = NULL; - static time_t start_time = (time_t)(-1); - float percentage = progress_data->percentage; - - if (progress_time == NULL) - progress_time = gtk_builder_get_object (builder, "zenity_progress_time"); - if (start_time == (time_t)(-1) || percentage <= 0.0 || percentage >= 100.0) { - start_time = time(NULL); - gtk_label_set_text (GTK_LABEL (progress_time), ""); - } else { - time_t current_time = time (NULL); - time_t elapsed_time = current_time - start_time; - time_t total_time = (time_t) (100.0*elapsed_time/progress_data->percentage); - time_t remaining_time = total_time - elapsed_time; - gulong hours, minutes, seconds; - gchar *remaining_message; - - seconds = (gulong) (remaining_time%60); - remaining_time /= 60; - minutes = (gulong) (remaining_time%60); - remaining_time /= 60; - hours = (gulong) remaining_time; - - remaining_message = g_strdup_printf (_("Time remaining: %lu:%02lu:%02lu"), - hours, minutes, seconds); - gtk_label_set_text (GTK_LABEL (progress_time), remaining_message); - g_free (remaining_message); - } +zenity_progress_update_time_remaining (ZenityProgressData *progress_data) { + static GObject *progress_time = NULL; + static time_t start_time = (time_t) (-1); + float percentage = progress_data->percentage; + + if (progress_time == NULL) + progress_time = + gtk_builder_get_object (builder, "zenity_progress_time"); + if (start_time == (time_t) (-1) || percentage <= 0.0 || + percentage >= 100.0) { + start_time = time (NULL); + gtk_label_set_text (GTK_LABEL (progress_time), ""); + } else { + time_t current_time = time (NULL); + time_t elapsed_time = current_time - start_time; + time_t total_time = + (time_t) (100.0 * elapsed_time / progress_data->percentage); + time_t remaining_time = total_time - elapsed_time; + gulong hours, minutes, seconds; + gchar *remaining_message; + + seconds = (gulong) (remaining_time % 60); + remaining_time /= 60; + minutes = (gulong) (remaining_time % 60); + remaining_time /= 60; + hours = (gulong) remaining_time; + + remaining_message = g_strdup_printf ( + _ ("Time remaining: %lu:%02lu:%02lu"), hours, minutes, seconds); + gtk_label_set_text (GTK_LABEL (progress_time), remaining_message); + g_free (remaining_message); + } } static gboolean -zenity_progress_handle_stdin (GIOChannel *channel, - GIOCondition condition, - gpointer data) -{ - static ZenityProgressData *progress_data; - static GObject *progress_bar; - static GObject *progress_label; - float percentage = 0.0; - GIOStatus status = G_IO_STATUS_NORMAL; - - progress_data = (ZenityProgressData *) data; - progress_bar = gtk_builder_get_object (builder, "zenity_progress_bar"); - progress_label = gtk_builder_get_object (builder, "zenity_progress_text"); - - if ((condition & G_IO_IN) != 0) { - GString *string; - GError *error = NULL; - - string = g_string_new (NULL); - - while (channel->is_readable != TRUE) - ; - do { - do { - status = g_io_channel_read_line_string (channel, string, NULL, &error); - - while (gtk_events_pending ()) - gtk_main_iteration (); - - } while (status == G_IO_STATUS_AGAIN); - - if (status != G_IO_STATUS_NORMAL) { - if (error) { - g_warning ("zenity_progress_handle_stdin () : %s", error->message); - g_error_free (error); - error = NULL; - } - continue; - } - - if (!g_ascii_strncasecmp (string->str, "#", 1)) { - gchar *match; - - /* We have a comment, so let's try to change the label */ - match = g_strstr_len (string->str, strlen (string->str), "#"); - match++; - gtk_label_set_text (GTK_LABEL (progress_label), g_strcompress(g_strchomp (g_strchug (match)))); - - } else if (g_str_has_prefix (string->str, "pulsate")) { - gchar *colon, *command, *value; - - zenity_util_strip_newline (string->str); - - colon = strchr(string->str, ':'); - if (colon == NULL) { - continue; - } - - /* split off the command and value */ - command = g_strstrip (g_strndup (string->str, colon - string->str)); - - value = colon + 1; - while (*value && g_ascii_isspace (*value)) value++; - - if (!g_ascii_strcasecmp (value, "false")) { - zenity_progress_pulsate_stop (); - - gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), - progress_data->percentage / 100.0); - } else { - zenity_progress_pulsate_start (progress_bar); - } - - g_free (command); - } else { - - if (!g_ascii_isdigit (*(string->str))) - continue; - - /* Now try to convert the thing to a number */ - percentage = CLAMP(atoi (string->str), 0, 100); - - gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), - percentage / 100.0); - - progress_data->percentage = percentage; - - if (progress_data->time_remaining == TRUE) - zenity_progress_update_time_remaining (progress_data); +zenity_progress_handle_stdin ( + GIOChannel *channel, GIOCondition condition, gpointer data) { + static ZenityProgressData *progress_data; + static GObject *progress_bar; + static GObject *progress_label; + float percentage = 0.0; + GIOStatus status = G_IO_STATUS_NORMAL; + + progress_data = (ZenityProgressData *) data; + progress_bar = gtk_builder_get_object (builder, "zenity_progress_bar"); + progress_label = gtk_builder_get_object (builder, "zenity_progress_text"); + + if ((condition & G_IO_IN) != 0) { + GString *string; + GError *error = NULL; + + string = g_string_new (NULL); + + while (channel->is_readable != TRUE) + ; + do { + do { + status = g_io_channel_read_line_string ( + channel, string, NULL, &error); + + while (gtk_events_pending ()) + gtk_main_iteration (); + + } while (status == G_IO_STATUS_AGAIN); + + if (status != G_IO_STATUS_NORMAL) { + if (error) { + g_warning ( + "zenity_progress_handle_stdin () : %s", error->message); + g_error_free (error); + error = NULL; + } + continue; + } + + if (!g_ascii_strncasecmp (string->str, "#", 1)) { + gchar *match; - if (percentage == 100) { - GObject *button; + /* We have a comment, so let's try to change the label */ + match = g_strstr_len (string->str, strlen (string->str), "#"); + match++; + gtk_label_set_text (GTK_LABEL (progress_label), + g_strcompress (g_strchomp (g_strchug (match)))); + + } else if (g_str_has_prefix (string->str, "pulsate")) { + gchar *colon, *command, *value; + + zenity_util_strip_newline (string->str); + + colon = strchr (string->str, ':'); + if (colon == NULL) { + continue; + } + + /* split off the command and value */ + command = + g_strstrip (g_strndup (string->str, colon - string->str)); + + value = colon + 1; + while (*value && g_ascii_isspace (*value)) + value++; + + if (!g_ascii_strcasecmp (value, "false")) { + zenity_progress_pulsate_stop (); + + gtk_progress_bar_set_fraction ( + GTK_PROGRESS_BAR (progress_bar), + progress_data->percentage / 100.0); + } else { + zenity_progress_pulsate_start (progress_bar); + } + + g_free (command); + } else { + + if (!g_ascii_isdigit (*(string->str))) + continue; + + /* Now try to convert the thing to a number */ + percentage = CLAMP (atoi (string->str), 0, 100); + + gtk_progress_bar_set_fraction ( + GTK_PROGRESS_BAR (progress_bar), percentage / 100.0); + + progress_data->percentage = percentage; + + if (progress_data->time_remaining == TRUE) + zenity_progress_update_time_remaining (progress_data); + + if (percentage == 100) { + GObject *button; + + button = gtk_builder_get_object ( + builder, "zenity_progress_ok_button"); + gtk_widget_set_sensitive (GTK_WIDGET (button), TRUE); + gtk_widget_grab_focus (GTK_WIDGET (button)); + + if (progress_data->autoclose) { + zen_data->exit_code = + zenity_util_return_exit_code (ZENITY_OK); + gtk_main_quit (); + } + } + } - button = gtk_builder_get_object(builder, "zenity_progress_ok_button"); - gtk_widget_set_sensitive(GTK_WIDGET (button), TRUE); - gtk_widget_grab_focus(GTK_WIDGET (button)); + } while ((g_io_channel_get_buffer_condition (channel) & G_IO_IN) == + G_IO_IN && + status != G_IO_STATUS_EOF); + g_string_free (string, TRUE); + } - if (progress_data->autoclose) { - zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); - gtk_main_quit(); - } - } - } + if ((condition & G_IO_IN) != G_IO_IN || status == G_IO_STATUS_EOF) { + /* We assume that we are done, so stop the pulsating and de-sensitize + * the buttons */ + GtkWidget *button; - } while ((g_io_channel_get_buffer_condition (channel) & G_IO_IN) == G_IO_IN && status != G_IO_STATUS_EOF); - g_string_free (string, TRUE); - } + button = GTK_WIDGET ( + gtk_builder_get_object (builder, "zenity_progress_ok_button")); + gtk_widget_set_sensitive (button, TRUE); + gtk_widget_grab_focus (button); - if ((condition & G_IO_IN) != G_IO_IN || status == G_IO_STATUS_EOF) { - /* We assume that we are done, so stop the pulsating and de-sensitize the buttons */ - GtkWidget *button; + button = GTK_WIDGET ( + gtk_builder_get_object (builder, "zenity_progress_cancel_button")); - button = GTK_WIDGET (gtk_builder_get_object (builder, - "zenity_progress_ok_button")); - gtk_widget_set_sensitive (button, TRUE); - gtk_widget_grab_focus (button); + gtk_widget_set_sensitive (button, FALSE); + + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), 1.0); - button = GTK_WIDGET (gtk_builder_get_object (builder, - "zenity_progress_cancel_button")); + zenity_progress_pulsate_stop (); - gtk_widget_set_sensitive (button, FALSE); + g_object_unref (builder); - gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), 1.0); + if (progress_data->autoclose) { + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); + gtk_main_quit (); + } - zenity_progress_pulsate_stop (); - - g_object_unref (builder); - - if (progress_data->autoclose) { - zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); - gtk_main_quit(); - } - - g_io_channel_shutdown (channel, TRUE, NULL); - return FALSE; - } - return TRUE; + g_io_channel_shutdown (channel, TRUE, NULL); + return FALSE; + } + return TRUE; } static void -zenity_progress_read_info (ZenityProgressData *progress_data) -{ - channel = g_io_channel_unix_new (0); - g_io_channel_set_encoding (channel, NULL, NULL); - g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL); - g_io_add_watch (channel, G_IO_IN | G_IO_HUP, zenity_progress_handle_stdin, progress_data); - /* We need to check the pulsate state here, because, the g_io_add_watch - doesn't call the zenity_progress_handle_stdin function if there's no - input. This fix the Bug 567663 */ - if (progress_data->pulsate) { - GObject *progress_bar = gtk_builder_get_object (builder, "zenity_progress_bar"); - zenity_progress_pulsate_start (progress_bar); - } +zenity_progress_read_info (ZenityProgressData *progress_data) { + channel = g_io_channel_unix_new (0); + g_io_channel_set_encoding (channel, NULL, NULL); + g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL); + g_io_add_watch (channel, + G_IO_IN | G_IO_HUP, + zenity_progress_handle_stdin, + progress_data); + /* We need to check the pulsate state here, because, the g_io_add_watch + doesn't call the zenity_progress_handle_stdin function if there's no + input. This fix the Bug 567663 */ + if (progress_data->pulsate) { + GObject *progress_bar = + gtk_builder_get_object (builder, "zenity_progress_bar"); + zenity_progress_pulsate_start (progress_bar); + } } static void -zenity_text_size_allocate (GtkWidget *widget, GtkAllocation *allocation, gpointer data) -{ - gtk_widget_set_size_request (widget, allocation->width/2, -1); +zenity_text_size_allocate ( + GtkWidget *widget, GtkAllocation *allocation, gpointer data) { + gtk_widget_set_size_request (widget, allocation->width / 2, -1); } void -zenity_progress (ZenityData *data, ZenityProgressData *progress_data) -{ - GtkWidget *dialog; - GtkWidget *button; - GObject *text; - GObject *progress_bar; - GObject *cancel_button,*ok_button; - - zen_data = data; - builder = zenity_util_load_ui_file ("zenity_progress_dialog", NULL); - - if (builder == NULL) { - data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); - return; - } - - gtk_builder_connect_signals (builder, NULL); - - text = gtk_builder_get_object (builder, "zenity_progress_text"); - - dialog = GTK_WIDGET (gtk_builder_get_object (builder, - "zenity_progress_dialog")); - - progress_bar = gtk_builder_get_object (builder, "zenity_progress_bar"); - - g_signal_connect (G_OBJECT (dialog), "response", - G_CALLBACK (zenity_progress_dialog_response), data); - - if (data->dialog_title) - gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); - - zenity_util_set_window_icon (dialog, data->window_icon, ZENITY_IMAGE_FULLPATH ("zenity-progress.png")); - - if (data->width > -1 || data->height > -1) - gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height); - - if (data->width > -1) { - gtk_widget_set_size_request (GTK_WIDGET (text), data->width, -1); - } - else { - g_signal_connect_after (G_OBJECT (text), "size-allocate", - G_CALLBACK (zenity_text_size_allocate), data); - g_signal_connect_after (G_OBJECT (progress_bar), "size-allocate", - G_CALLBACK (zenity_text_size_allocate), data); - } - - if (data->modal) - gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); - - if (data->extra_label) { - gint i=0; - while(data->extra_label[i]!=NULL){ - gtk_dialog_add_button (GTK_DIALOG (dialog), data->extra_label[i], i); - i++; - } - } - - if (data->ok_label) { - button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_progress_ok_button")); - gtk_button_set_label (GTK_BUTTON (button), data->ok_label); - } - - if (data->cancel_label) { - button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_progress_cancel_button")); - gtk_button_set_label (GTK_BUTTON (button), data->cancel_label); - } - - if (progress_data->dialog_text) - gtk_label_set_markup (GTK_LABEL (text), g_strcompress (progress_data->dialog_text)); - - if (progress_data->percentage > -1) - gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), - progress_data->percentage/100.0); - - autokill = progress_data->autokill; - - auto_close = progress_data->autoclose; - ok_button = gtk_builder_get_object (builder, "zenity_progress_ok_button"); - - no_cancel = progress_data->no_cancel; - cancel_button = gtk_builder_get_object (builder, "zenity_progress_cancel_button"); - - if (no_cancel) { - gtk_widget_hide (GTK_WIDGET(cancel_button)); - gtk_window_set_deletable (GTK_WINDOW (dialog), FALSE); - } - - if (no_cancel && auto_close) - gtk_widget_hide(GTK_WIDGET(ok_button)); - - zenity_util_show_dialog (dialog, data->attach); - zenity_progress_read_info (progress_data); - - if(data->timeout_delay > 0) { - g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, NULL); - } - - gtk_main (); +zenity_progress (ZenityData *data, ZenityProgressData *progress_data) { + GtkWidget *dialog; + GtkWidget *button; + GObject *text; + GObject *progress_bar; + GObject *cancel_button, *ok_button; + + zen_data = data; + builder = zenity_util_load_ui_file ("zenity_progress_dialog", NULL); + + if (builder == NULL) { + data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); + return; + } + + gtk_builder_connect_signals (builder, NULL); + + text = gtk_builder_get_object (builder, "zenity_progress_text"); + + dialog = + GTK_WIDGET (gtk_builder_get_object (builder, "zenity_progress_dialog")); + + progress_bar = gtk_builder_get_object (builder, "zenity_progress_bar"); + + g_signal_connect (G_OBJECT (dialog), + "response", + G_CALLBACK (zenity_progress_dialog_response), + data); + + if (data->dialog_title) + gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); + + zenity_util_set_window_icon (dialog, + data->window_icon, + ZENITY_IMAGE_FULLPATH ("zenity-progress.png")); + + if (data->width > -1 || data->height > -1) + gtk_window_set_default_size ( + GTK_WINDOW (dialog), data->width, data->height); + + if (data->width > -1) { + gtk_widget_set_size_request (GTK_WIDGET (text), data->width, -1); + } else { + g_signal_connect_after (G_OBJECT (text), + "size-allocate", + G_CALLBACK (zenity_text_size_allocate), + data); + g_signal_connect_after (G_OBJECT (progress_bar), + "size-allocate", + G_CALLBACK (zenity_text_size_allocate), + data); + } + + if (data->modal) + gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); + + if (data->extra_label) { + gint i = 0; + while (data->extra_label[i] != NULL) { + gtk_dialog_add_button ( + GTK_DIALOG (dialog), data->extra_label[i], i); + i++; + } + } + + if (data->ok_label) { + button = GTK_WIDGET ( + gtk_builder_get_object (builder, "zenity_progress_ok_button")); + gtk_button_set_label (GTK_BUTTON (button), data->ok_label); + } + + if (data->cancel_label) { + button = GTK_WIDGET ( + gtk_builder_get_object (builder, "zenity_progress_cancel_button")); + gtk_button_set_label (GTK_BUTTON (button), data->cancel_label); + } + + if (progress_data->dialog_text) + gtk_label_set_markup ( + GTK_LABEL (text), g_strcompress (progress_data->dialog_text)); + + if (progress_data->percentage > -1) + gtk_progress_bar_set_fraction ( + GTK_PROGRESS_BAR (progress_bar), progress_data->percentage / 100.0); + + autokill = progress_data->autokill; + + auto_close = progress_data->autoclose; + ok_button = gtk_builder_get_object (builder, "zenity_progress_ok_button"); + + no_cancel = progress_data->no_cancel; + cancel_button = + gtk_builder_get_object (builder, "zenity_progress_cancel_button"); + + if (no_cancel) { + gtk_widget_hide (GTK_WIDGET (cancel_button)); + gtk_window_set_deletable (GTK_WINDOW (dialog), FALSE); + } + + if (no_cancel && auto_close) + gtk_widget_hide (GTK_WIDGET (ok_button)); + + zenity_util_show_dialog (dialog, data->attach); + zenity_progress_read_info (progress_data); + + if (data->timeout_delay > 0) { + g_timeout_add_seconds (data->timeout_delay, + (GSourceFunc) zenity_util_timeout_handle, + NULL); + } + + gtk_main (); } static void -zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data) -{ - switch (response) { - case GTK_RESPONSE_OK: - zenity_util_exit_code_with_data(ZENITY_OK, zen_data); - break; - - case GTK_RESPONSE_CANCEL: - /* We do not want to kill the parent process, in order to give the user - the ability to choose the action to be taken. See bug #310824. - But we want to give people the option to choose this behavior. - -- Monday 27, March 2006 - */ - if (autokill) { - kill (getppid (), 1); - } - zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); - break; - - case ZENITY_TIMEOUT: - zenity_util_exit_code_with_data (ZENITY_TIMEOUT, zen_data); - break; - default: - if (zen_data->extra_label && response < g_strv_length(zen_data->extra_label)) - printf("%s\n",zen_data->extra_label[response]); - zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); - break; - } - gtk_main_quit (); +zenity_progress_dialog_response ( + GtkWidget *widget, int response, gpointer data) { + switch (response) { + case GTK_RESPONSE_OK: + zenity_util_exit_code_with_data (ZENITY_OK, zen_data); + break; + + case GTK_RESPONSE_CANCEL: + /* We do not want to kill the parent process, in order to give the + user + the ability to choose the action to be taken. See bug #310824. + But we want to give people the option to choose this behavior. + -- Monday 27, March 2006 + */ + if (autokill) { + kill (getppid (), 1); + } + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); + break; + + case ZENITY_TIMEOUT: + zenity_util_exit_code_with_data (ZENITY_TIMEOUT, zen_data); + break; + default: + if (zen_data->extra_label && + response < g_strv_length (zen_data->extra_label)) + printf ("%s\n", zen_data->extra_label[response]); + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); + break; + } + gtk_main_quit (); } -- cgit