summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGama Anderson <gamaanderson92@gmail.com>2015-02-28 20:06:09 +0100
committerArx Cruz <acruz@redhat.com>2015-04-21 13:00:44 +0200
commitba5ea0386de2a80a664fb28d3af7e8d395968314 (patch)
treef07081dd0d7b837c80716b4573dd563a2300f2ea /src
parentallow build if GDK_WINDOWING_X11 not set (diff)
downloadzenity-ba5ea0386de2a80a664fb28d3af7e8d395968314.tar.gz
zenity-ba5ea0386de2a80a664fb28d3af7e8d395968314.tar.bz2
zenity-ba5ea0386de2a80a664fb28d3af7e8d395968314.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/calendar.c13
-rw-r--r--src/color.c10
-rw-r--r--src/entry.c13
-rw-r--r--src/fileselection.c11
-rw-r--r--src/forms.c10
-rw-r--r--src/msg.c21
-rw-r--r--src/option.c40
-rw-r--r--src/password.c10
-rw-r--r--src/progress.c11
-rw-r--r--src/scale.c12
-rw-r--r--src/text.c11
-rw-r--r--src/tree.c11
-rw-r--r--src/util.c2
-rw-r--r--src/zenity.h2
14 files changed, 161 insertions, 16 deletions
diff --git a/src/calendar.c b/src/calendar.c
index e8967974..8e2f6950 100644
--- a/src/calendar.c
+++ b/src/calendar.c
@@ -91,7 +91,15 @@ zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data)
if (data->timeout_delay > 0) {
g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, dialog);
}
-
+
+ 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_calendar_ok_button"));
gtk_button_set_label (GTK_BUTTON (button), data->ok_label);
@@ -149,7 +157,8 @@ zenity_calendar_dialog_response (GtkWidget *widget, int response, gpointer 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;
}
diff --git a/src/color.c b/src/color.c
index e3b8a428..be63068b 100644
--- a/src/color.c
+++ b/src/color.c
@@ -57,6 +57,14 @@ void zenity_colorselection (ZenityData *data, ZenityColorData *color_data)
&color);
}
+ 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) {
g_object_get (G_OBJECT (dialog), "ok-button", &button, NULL);
gtk_button_set_label (GTK_BUTTON (button), data->ok_label);
@@ -109,6 +117,8 @@ zenity_colorselection_dialog_response (GtkWidget *widget, int response, gpointer
break;
default:
+ 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;
}
diff --git a/src/entry.c b/src/entry.c
index ca5e3752..5066f71e 100644
--- a/src/entry.c
+++ b/src/entry.c
@@ -83,7 +83,15 @@ zenity_entry (ZenityData *data, ZenityEntryData *entry_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_entry_ok_button"));
gtk_button_set_label (GTK_BUTTON (button), data->ok_label);
@@ -188,7 +196,8 @@ zenity_entry_dialog_response (GtkWidget *widget, int response, gpointer 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;
}
diff --git a/src/fileselection.c b/src/fileselection.c
index 9edbb6ae..fbf0e5de 100644
--- a/src/fileselection.c
+++ b/src/fileselection.c
@@ -62,6 +62,14 @@ void zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
g_signal_connect (G_OBJECT (dialog), "response",
G_CALLBACK (zenity_fileselection_dialog_response), file_data);
+ 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->dialog_title)
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
@@ -181,7 +189,8 @@ zenity_fileselection_dialog_response (GtkWidget *widget, int response, gpointer
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;
}
diff --git a/src/forms.c b/src/forms.c
index 59c6461f..1923790f 100644
--- a/src/forms.c
+++ b/src/forms.c
@@ -206,6 +206,14 @@ void zenity_forms_dialog (ZenityData *data, ZenityFormsData *forms_data)
if (data->width > -1 || data->height > -1)
gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height);
+ 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_forms_ok_button"));
gtk_button_set_label (GTK_BUTTON (button), data->ok_label);
@@ -439,6 +447,8 @@ zenity_forms_dialog_response (GtkWidget *widget, int response, gpointer data)
break;
default:
+ 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;
}
diff --git a/src/msg.c b/src/msg.c
index fb549421..6f077501 100644
--- a/src/msg.c
+++ b/src/msg.c
@@ -31,8 +31,10 @@ static void zenity_text_size_allocate (GtkWidget *widget, GtkAllocation *allocat
static void
zenity_msg_construct_question_dialog (GtkWidget *dialog, ZenityMsgData *msg_data, ZenityData *data)
{
+
+
GtkWidget *cancel_button, *ok_button;
-
+
cancel_button = gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_NO, GTK_RESPONSE_CANCEL);
ok_button = gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_YES, GTK_RESPONSE_OK);
@@ -49,6 +51,8 @@ zenity_msg_construct_question_dialog (GtkWidget *dialog, ZenityMsgData *msg_data
gtk_button_set_image (GTK_BUTTON (ok_button),
gtk_image_new_from_stock (GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON));
}
+
+
}
static void
@@ -95,6 +99,7 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
break;
case ZENITY_MSG_QUESTION:
+ case ZENITY_MSG_SWITCH:
builder = zenity_util_load_ui_file ("zenity_question_dialog", NULL);
dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_question_dialog"));
text = gtk_builder_get_object (builder, "zenity_question_text");
@@ -128,6 +133,14 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
break;
}
+ 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 (builder == NULL) {
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
return;
@@ -159,6 +172,10 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
zenity_msg_construct_question_dialog (dialog, msg_data, data);
break;
+ case ZENITY_MSG_SWITCH:
+ zenity_util_set_window_icon_from_stock (dialog, data->window_icon, GTK_STOCK_DIALOG_QUESTION);
+ break;
+
case ZENITY_MSG_ERROR:
zenity_util_set_window_icon_from_stock (dialog, data->window_icon, GTK_STOCK_DIALOG_ERROR);
break;
@@ -233,6 +250,8 @@ zenity_msg_dialog_response (GtkWidget *widget, int response, gpointer data)
break;
default:
+ 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;
}
diff --git a/src/option.c b/src/option.c
index eb0a03a3..7ec4b634 100644
--- a/src/option.c
+++ b/src/option.c
@@ -45,6 +45,7 @@ static gboolean zenity_general_dialog_no_markup;
static gint zenity_general_timeout_delay;
static gchar *zenity_general_ok_button;
static gchar *zenity_general_cancel_button;
+static gchar **zenity_general_extra_buttons;
static gboolean zenity_general_modal;
static gint zenity_general_attach;
static gboolean zenity_general_dialog_ellipsize;
@@ -104,6 +105,7 @@ static gboolean zenity_progress_time_remaining;
/* Question Dialog Options */
static gboolean zenity_question_active;
static gboolean zenity_question_default_cancel;
+static gboolean zenity_question_switch;
/* Text Dialog Options */
static gboolean zenity_text_active;
@@ -223,6 +225,15 @@ static GOptionEntry general_options[] = {
N_("TEXT")
},
{
+ "extra-button",
+ '\0',
+ 0,
+ G_OPTION_ARG_STRING_ARRAY,
+ &zenity_general_extra_buttons,
+ N_("Add extra-button"),
+ N_("TEXT")
+ },
+ {
"modal",
'\0',
G_OPTION_FLAG_NOALIAS,
@@ -855,6 +866,15 @@ static GOptionEntry question_options[] = {
&zenity_general_dialog_ellipsize,
N_("Enable ellipsizing in the dialog text. This fixes the high window size with long texts")
},
+ {
+ "switch",
+ '\0',
+ G_OPTION_FLAG_NOALIAS,
+ G_OPTION_ARG_NONE,
+ &zenity_question_switch,
+ N_("Supress ok and cancel buttons"),
+ NULL
+ },
{
NULL
}
@@ -1341,7 +1361,9 @@ zenity_option_free (void) {
g_free (zenity_general_ok_button);
if (zenity_general_cancel_button)
g_free (zenity_general_cancel_button);
-
+ if (zenity_general_extra_buttons)
+ g_strfreev (zenity_general_extra_buttons);
+
if (zenity_calendar_date_format)
g_free (zenity_calendar_date_format);
@@ -1463,6 +1485,7 @@ zenity_general_pre_callback (GOptionContext *context,
zenity_general_uri = NULL;
zenity_general_ok_button = NULL;
zenity_general_cancel_button = NULL;
+ zenity_general_extra_buttons = NULL;
zenity_general_dialog_no_wrap = FALSE;
zenity_general_dialog_no_markup = FALSE;
zenity_general_timeout_delay = -1;
@@ -1594,7 +1617,7 @@ zenity_question_pre_callback (GOptionContext *context,
{
zenity_question_active = FALSE;
zenity_question_default_cancel = FALSE;
-
+ zenity_question_switch = FALSE;
return TRUE;
}
@@ -1710,6 +1733,7 @@ zenity_general_post_callback (GOptionContext *context,
results->data->timeout_delay = zenity_general_timeout_delay;
results->data->ok_label = zenity_general_ok_button;
results->data->cancel_label = zenity_general_cancel_button;
+ results->data->extra_label = zenity_general_extra_buttons;
results->data->modal = zenity_general_modal;
results->data->attach = zenity_general_attach;
@@ -2012,13 +2036,18 @@ zenity_question_post_callback (GOptionContext *context,
if (results->mode == MODE_QUESTION) {
results->msg_data->dialog_text = zenity_general_dialog_text;
results->msg_data->dialog_icon = zenity_general_dialog_icon;
- results->msg_data->mode = ZENITY_MSG_QUESTION;
+ if(zenity_question_switch)
+ results->msg_data->mode = ZENITY_MSG_SWITCH;
+ else
+ results->msg_data->mode = ZENITY_MSG_QUESTION;
results->msg_data->no_wrap = zenity_general_dialog_no_wrap;
results->msg_data->no_markup = zenity_general_dialog_no_markup;
- results->msg_data->ellipsize = zenity_general_dialog_ellipsize;
+ results->msg_data->ellipsize = zenity_general_dialog_ellipsize;
results->msg_data->default_cancel = zenity_question_default_cancel;
}
-
+ if(zenity_question_switch && zenity_general_extra_buttons==NULL)
+ zenity_option_error (zenity_option_get_name (question_options, &zenity_question_switch), ERROR_SYNTAX);
+
return TRUE;
}
@@ -2495,5 +2524,6 @@ zenity_option_parse (gint argc, gchar **argv)
if (results->mode != MODE_INFO && results->mode != MODE_ERROR && results->mode != MODE_QUESTION && results->mode != MODE_WARNING)
zenity_option_error (zenity_option_get_name (text_options, &zenity_general_dialog_ellipsize), ERROR_SUPPORT);
+
return results;
}
diff --git a/src/password.c b/src/password.c
index ff254fde..23357467 100644
--- a/src/password.c
+++ b/src/password.c
@@ -44,6 +44,14 @@ void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data
dialog = gtk_dialog_new ();
+ 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++;
+ }
+ }
+
gtk_dialog_add_button(GTK_DIALOG(dialog),
data->cancel_label != NULL ? data->cancel_label : GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL);
@@ -177,6 +185,8 @@ zenity_password_dialog_response (GtkWidget *widget, int response, gpointer data)
break;
default:
+ 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;
}
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;
}
diff --git a/src/scale.c b/src/scale.c
index adcf67be..92c9818d 100644
--- a/src/scale.c
+++ b/src/scale.c
@@ -78,7 +78,15 @@ zenity_scale (ZenityData *data, ZenityScaleData *scale_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_scale_ok_button"));
gtk_button_set_label (GTK_BUTTON (button), data->ok_label);
@@ -145,6 +153,8 @@ zenity_scale_dialog_response (GtkWidget *widget, int response, gpointer data)
break;
default:
+ 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;
}
diff --git a/src/text.c b/src/text.c
index 8f383b9c..f9daa73f 100644
--- a/src/text.c
+++ b/src/text.c
@@ -276,6 +276,14 @@ zenity_text (ZenityData *data, ZenityTextData *text_data)
if (text_data->editable)
zen_text_data->buffer = text_buffer;
+ 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) {
gtk_button_set_label (GTK_BUTTON (ok_button), data->ok_label);
gtk_button_set_image (GTK_BUTTON (ok_button),
@@ -398,7 +406,8 @@ zenity_text_dialog_response (GtkWidget *widget, int response, gpointer data)
break;
default:
- /* Esc dialog */
+ if (response < g_strv_length(zen_data->extra_label))
+ printf("%s\n",zen_data->extra_label[response]);
zenity_util_exit_code_with_data(ZENITY_ESC, zen_data);
break;
}
diff --git a/src/tree.c b/src/tree.c
index 819f9a8e..0e2665c1 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -396,6 +396,14 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_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_tree_ok_button"));
gtk_button_set_label (GTK_BUTTON (button), data->ok_label);
@@ -708,7 +716,8 @@ zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer 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;
}
diff --git a/src/util.c b/src/util.c
index d63aecaf..730b7a93 100644
--- a/src/util.c
+++ b/src/util.c
@@ -76,7 +76,7 @@ zenity_util_load_ui_file (const gchar *root_widget, ...)
/* Enforce terminating NULL */
g_ptr_array_add (ptrarray, NULL);
objects = (gchar**) g_ptr_array_free (ptrarray, FALSE);
-
+
if (g_file_test (ZENITY_UI_FILE_RELATIVEPATH, G_FILE_TEST_EXISTS)) {
/* Try current dir, for debugging */
result = gtk_builder_add_objects_from_file (builder,
diff --git a/src/zenity.h b/src/zenity.h
index 6390b007..77f0c050 100644
--- a/src/zenity.h
+++ b/src/zenity.h
@@ -28,6 +28,7 @@ typedef struct {
gchar *window_icon;
gchar *ok_label;
gchar *cancel_label;
+ gchar **extra_label;
gint width;
gint height;
gint exit_code;
@@ -56,6 +57,7 @@ typedef struct {
typedef enum {
ZENITY_MSG_WARNING,
ZENITY_MSG_QUESTION,
+ ZENITY_MSG_SWITCH,
ZENITY_MSG_ERROR,
ZENITY_MSG_INFO
} MsgMode;
bgstack15