From 285cb79bafd2616f2d2dd7eb2ae82527942ef4cc Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Tue, 13 Dec 2005 04:18:58 +0000 Subject: new scale dialog for selecting a value from a range (Fixes #322399). 2005-12-13 Lucas Rocha * data/Makefile.am, data/zenity-scale.png, src/Makefile.am, src/main.c, src/option.c, src/option.h, src/scale.c, src/zenity.glade, src/zenity.h: new scale dialog for selecting a value from a range (Fixes #322399). --- ChangeLog | 8 ++ data/Makefile.am | 1 + data/zenity-scale.png | Bin 0 -> 240 bytes src/Makefile.am | 1 + src/main.c | 3 + src/option.c | 125 +++++++++++++++++++++++++++++ src/option.h | 2 + src/scale.c | 122 +++++++++++++++++++++++++++++ src/zenity.glade | 213 ++++++++++++++++++++++++++++++++++++++++++++++++-- src/zenity.h | 9 +++ 10 files changed, 477 insertions(+), 7 deletions(-) create mode 100644 data/zenity-scale.png create mode 100644 src/scale.c diff --git a/ChangeLog b/ChangeLog index fb6c98da..42c77689 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-12-13 Lucas Rocha + + * data/Makefile.am, data/zenity-scale.png, + src/Makefile.am, src/main.c, src/option.c, + src/option.h, src/scale.c, src/zenity.glade, + src/zenity.h: new scale dialog for selecting a + value from a range (Fixes #322399). + 2005-12-12 Lucas Rocha * configure.in: post release version bump. diff --git a/data/Makefile.am b/data/Makefile.am index fd71b4e3..5ee58f29 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -14,6 +14,7 @@ images_DATA = \ zenity-file.png \ zenity-progress.png \ zenity-text.png \ + zenity-scale.png \ zenity-entry.png \ zenity-notification.png diff --git a/data/zenity-scale.png b/data/zenity-scale.png new file mode 100644 index 00000000..8526c317 Binary files /dev/null and b/data/zenity-scale.png differ diff --git a/src/Makefile.am b/src/Makefile.am index 6b43b3e1..e3c62d53 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -9,6 +9,7 @@ zenity_SOURCES = \ zenity.h \ calendar.c \ msg.c \ + scale.c \ fileselection.c \ entry.c \ text.c \ diff --git a/src/main.c b/src/main.c index 09330d55..7077af8a 100644 --- a/src/main.c +++ b/src/main.c @@ -64,6 +64,9 @@ main (gint argc, gchar **argv) { case MODE_INFO: zenity_msg (results->data, results->msg_data); break; + case MODE_SCALE: + zenity_scale (results->data, results->scale_data); + break; case MODE_FILE: zenity_fileselection (results->data, results->file_data); break; diff --git a/src/option.c b/src/option.c index 19089305..f3f26b3a 100644 --- a/src/option.c +++ b/src/option.c @@ -91,6 +91,14 @@ static gboolean zenity_text_active; /* Warning Dialog Options */ static gboolean zenity_warning_active; +/* Scale Dialog Options */ +static gboolean zenity_scale_active; +static gint zenity_scale_value; +static gint zenity_scale_min_value; +static gint zenity_scale_max_value; +static gint zenity_scale_step; +static gboolean zenity_scale_print_partial; + /* Miscelaneus Options */ static gboolean zenity_misc_about; static gboolean zenity_misc_version; @@ -646,6 +654,75 @@ static GOptionEntry warning_options[] = { } }; +static GOptionEntry scale_options[] = { + { + "scale", + '\0', + G_OPTION_FLAG_IN_MAIN, + G_OPTION_ARG_NONE, + &zenity_scale_active, + N_("Display scale dialog"), + NULL + }, + { + "text", + '\0', + G_OPTION_FLAG_NOALIAS, + G_OPTION_ARG_STRING, + &zenity_general_dialog_text, + N_("Set the dialog text"), + NULL + }, + { + "value", + '\0', + 0, + G_OPTION_ARG_INT, + &zenity_scale_value, + N_("Set initial value"), + NULL + }, + { + "min-value", + '\0', + 0, + G_OPTION_ARG_INT, + &zenity_scale_min_value, + N_("Set minimum value"), + NULL + }, + { + "max-value", + '\0', + 0, + G_OPTION_ARG_INT, + &zenity_scale_max_value, + N_("Set maximum value"), + NULL + }, + { + "step", + '\0', + 0, + G_OPTION_ARG_INT, + &zenity_scale_step, + N_("Set step size"), + NULL + }, + { + "print-partial", + '\0', + 0, + G_OPTION_ARG_NONE, + &zenity_scale_print_partial, + N_("Print partial values"), + NULL + }, + { + NULL + } +}; + static GOptionEntry miscellaneous_options[] = { { "about", @@ -683,6 +760,7 @@ zenity_option_init (void) { results->data = g_new0 (ZenityData, 1); results->calendar_data = g_new0 (ZenityCalendarData, 1); results->msg_data = g_new0 (ZenityMsgData, 1); + results->scale_data = g_new0 (ZenityScaleData, 1); results->file_data = g_new0 (ZenityFileData, 1); results->entry_data = g_new0 (ZenityEntryData, 1); results->progress_data = g_new0 (ZenityProgressData, 1); @@ -912,6 +990,22 @@ zenity_warning_pre_callback (GOptionContext *context, return TRUE; } +static gboolean +zenity_scale_pre_callback (GOptionContext *context, + GOptionGroup *group, + gpointer data, + GError **error) +{ + zenity_scale_active = FALSE; + zenity_scale_value = 0; + zenity_scale_min_value = 0; + zenity_scale_max_value = 100; + zenity_scale_step = 1; + zenity_scale_print_partial = FALSE; + + return TRUE; +} + static gboolean zenity_misc_pre_callback (GOptionContext *context, GOptionGroup *group, @@ -1234,6 +1328,26 @@ zenity_warning_post_callback (GOptionContext *context, return TRUE; } +static gboolean +zenity_scale_post_callback (GOptionContext *context, + GOptionGroup *group, + gpointer data, + GError **error) +{ + zenity_option_set_dialog_mode (zenity_scale_active, MODE_SCALE); + + if (results->mode == MODE_SCALE) { + results->scale_data->dialog_text = zenity_general_dialog_text; + results->scale_data->value = zenity_scale_value; + results->scale_data->min_value = zenity_scale_min_value; + results->scale_data->max_value = zenity_scale_max_value; + results->scale_data->step = zenity_scale_step; + results->scale_data->print_partial = zenity_scale_print_partial; + } + + return TRUE; +} + static gboolean zenity_misc_post_callback (GOptionContext *context, GOptionGroup *group, @@ -1375,6 +1489,17 @@ zenity_create_context (void) g_option_group_set_translation_domain (a_group, GETTEXT_PACKAGE); g_option_context_add_group(tmp_ctx, a_group); + /* Adds scale option entries */ + a_group = g_option_group_new("scale", + N_("Scale options"), + N_("Show scale options"), NULL, 0); + g_option_group_add_entries(a_group, scale_options); + g_option_group_set_parse_hooks (a_group, + zenity_scale_pre_callback, zenity_scale_post_callback); + g_option_group_set_error_hook (a_group, zenity_option_error_callback); + g_option_group_set_translation_domain (a_group, GETTEXT_PACKAGE); + g_option_context_add_group(tmp_ctx, a_group); + /* Adds text option entries */ a_group = g_option_group_new("text-info", N_("Text information options"), diff --git a/src/option.h b/src/option.h index 63b28243..cce0553d 100644 --- a/src/option.h +++ b/src/option.h @@ -42,6 +42,7 @@ typedef enum { MODE_QUESTION, MODE_TEXTINFO, MODE_WARNING, + MODE_SCALE, MODE_INFO, MODE_NOTIFICATION, MODE_ABOUT, @@ -62,6 +63,7 @@ typedef struct { ZenityCalendarData *calendar_data; ZenityMsgData *msg_data; + ZenityScaleData *scale_data; ZenityFileData *file_data; ZenityEntryData *entry_data; ZenityProgressData *progress_data; diff --git a/src/scale.c b/src/scale.c new file mode 100644 index 00000000..228995e6 --- /dev/null +++ b/src/scale.c @@ -0,0 +1,122 @@ +/* + * scale.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., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * Authors: Lucas Rocha + */ + +#include "config.h" + +#include +#include "zenity.h" +#include "util.h" + +static GtkWidget *scale; + +static void zenity_scale_value_changed (GtkWidget *widget, gpointer data); +static void zenity_scale_dialog_response (GtkWidget *widget, int response, gpointer data); + +void +zenity_scale (ZenityData *data, ZenityScaleData *scale_data) +{ + GladeXML *glade_dialog; + GtkWidget *dialog; + GtkWidget *text; + + glade_dialog = zenity_util_load_glade_file ("zenity_scale_dialog"); + dialog = glade_xml_get_widget (glade_dialog, "zenity_scale_dialog"); + scale = glade_xml_get_widget (glade_dialog, "zenity_scale_hscale"); + text = glade_xml_get_widget (glade_dialog, "zenity_scale_text"); + + g_signal_connect (G_OBJECT (dialog), "response", + G_CALLBACK (zenity_scale_dialog_response), data); + + if (glade_dialog == NULL) { + data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); + return; + } + + if (scale_data->min_value >= scale_data->max_value) { + g_printerr (_("Maximum value must be greater than minimum value.\n")); + data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); + return; + } + + if (scale_data->value < scale_data->min_value || + scale_data->value > scale_data->max_value) { + g_printerr (_("Value out of range.\n")); + data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); + return; + } + + glade_xml_signal_autoconnect (glade_dialog); + + if (glade_dialog) + g_object_unref (glade_dialog); + + 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-scale.png")); + + if (data->width > -1 || data->height > -1) + gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height); + + if (scale_data->dialog_text) + gtk_label_set_markup (GTK_LABEL (text), g_strcompress (scale_data->dialog_text)); + + gtk_range_set_value (GTK_RANGE (scale), scale_data->value); + gtk_range_set_range (GTK_RANGE (scale), scale_data->min_value, scale_data->max_value); + gtk_range_set_increments (GTK_RANGE (scale), scale_data->step, 0); + + if (scale_data->print_partial) + g_signal_connect (G_OBJECT (scale), "value-changed", + G_CALLBACK (zenity_scale_value_changed), data); + + zenity_util_show_dialog (dialog); + gtk_main (); +} + +static void +zenity_scale_value_changed (GtkWidget *widget, gpointer data) +{ + g_print ("%.0f\n", gtk_range_get_value (GTK_RANGE (widget))); +} + +static void +zenity_scale_dialog_response (GtkWidget *widget, int response, gpointer data) +{ + ZenityData *zen_data = data; + + switch (response) { + case GTK_RESPONSE_OK: + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); + g_print ("%.0f\n", gtk_range_get_value (GTK_RANGE (scale))); + break; + + case GTK_RESPONSE_CANCEL: + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); + break; + + default: + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); + break; + } + gtk_main_quit (); +} diff --git a/src/zenity.glade b/src/zenity.glade index 22049ba9..66dc3cce 100644 --- a/src/zenity.glade +++ b/src/zenity.glade @@ -15,6 +15,8 @@ False GDK_WINDOW_TYPE_HINT_DIALOG GDK_GRAVITY_NORTH_WEST + True + False True @@ -90,6 +92,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -119,6 +125,10 @@ 0 0 zenity_calendar + PANGO_ELLIPSIZE_NONE + -1 + False + 0 @@ -166,6 +176,8 @@ False GDK_WINDOW_TYPE_HINT_DIALOG GDK_GRAVITY_NORTH_WEST + True + False False @@ -252,6 +264,10 @@ 0 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -283,6 +299,8 @@ False GDK_WINDOW_TYPE_HINT_DIALOG GDK_GRAVITY_NORTH_WEST + True + False True @@ -321,6 +339,8 @@ False GDK_WINDOW_TYPE_HINT_DIALOG GDK_GRAVITY_NORTH_WEST + True + False False @@ -407,6 +427,10 @@ 0 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -437,6 +461,8 @@ False GDK_WINDOW_TYPE_HINT_DIALOG GDK_GRAVITY_NORTH_WEST + True + False True @@ -513,6 +539,10 @@ 0 0 zenity_entry_input + PANGO_ELLIPSIZE_NONE + -1 + False + 0 @@ -533,7 +563,7 @@ 0 True - * + * True @@ -575,6 +605,8 @@ False GDK_WINDOW_TYPE_HINT_DIALOG GDK_GRAVITY_NORTH_WEST + True + False False @@ -675,6 +707,8 @@ False GDK_WINDOW_TYPE_HINT_DIALOG GDK_GRAVITY_NORTH_WEST + True + False True @@ -751,6 +785,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -764,8 +802,9 @@ True GTK_PROGRESS_LEFT_TO_RIGHT 0 - 0.1 + 0.10000000149 + PANGO_ELLIPSIZE_NONE 0 @@ -804,6 +843,8 @@ False GDK_WINDOW_TYPE_HINT_DIALOG GDK_GRAVITY_NORTH_WEST + True + False False @@ -883,6 +924,10 @@ 0 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -914,7 +959,7 @@ GTK_WIN_POS_CENTER False 300 - 200 + 196 True False True @@ -922,6 +967,8 @@ False GDK_WINDOW_TYPE_HINT_DIALOG GDK_GRAVITY_NORTH_WEST + True + False True @@ -996,6 +1043,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -1017,11 +1068,14 @@ True True - True + True True False False True + False + False + False @@ -1062,6 +1116,8 @@ False GDK_WINDOW_TYPE_HINT_DIALOG GDK_GRAVITY_NORTH_WEST + True + False False @@ -1140,6 +1196,10 @@ 0 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -1177,6 +1237,8 @@ False GDK_WINDOW_TYPE_HINT_DIALOG GDK_GRAVITY_NORTH_WEST + True + False True @@ -1265,7 +1327,7 @@ True True - zenity_about_version + zenity_about_version False True GTK_JUSTIFY_CENTER @@ -1275,6 +1337,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -1287,7 +1353,7 @@ True True - zenity_about_description + zenity_about_description False True GTK_JUSTIFY_CENTER @@ -1297,6 +1363,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -1309,7 +1379,7 @@ True True - zenity_about_copyright + zenity_about_copyright False True GTK_JUSTIFY_CENTER @@ -1319,6 +1389,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -1337,4 +1411,129 @@ + + True + Adjust the scale value + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + 300 + 100 + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + False + True + + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + -6 + + + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + 3 + True + False + 0 + + + + True + Adjust the scale value. + False + True + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 4 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + True + True + True + GTK_POS_RIGHT + 0 + GTK_UPDATE_DELAYED + False + 0 0 100 1 1 0 + + + 0 + True + True + + + + + 0 + True + True + + + + + + diff --git a/src/zenity.h b/src/zenity.h index b224abd9..6b8cd294 100644 --- a/src/zenity.h +++ b/src/zenity.h @@ -60,6 +60,15 @@ typedef struct { gboolean no_wrap; } ZenityMsgData; +typedef struct { + gchar *dialog_text; + gint value; + gint min_value; + gint max_value; + gint step; + gboolean print_partial; +} ZenityScaleData; + typedef struct { gchar *uri; gboolean multi; -- cgit