summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/calendar.c33
-rw-r--r--src/entry.c31
-rw-r--r--src/fileselection.c33
-rw-r--r--src/forms.c99
-rw-r--r--src/progress.c5
-rw-r--r--src/scale.c5
-rw-r--r--src/text.c27
-rw-r--r--src/tree.c37
-rw-r--r--src/util.c8
9 files changed, 169 insertions, 109 deletions
diff --git a/src/calendar.c b/src/calendar.c
index c0f7af13..f2820014 100644
--- a/src/calendar.c
+++ b/src/calendar.c
@@ -110,33 +110,44 @@ zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data)
gtk_main ();
}
+static void
+zenity_calendar_dialog_output (void)
+{
+ guint day, month, year;
+ gchar time_string[128];
+ GDate *date = NULL;
+
+ gtk_calendar_get_date (GTK_CALENDAR (calendar), &day, &month, &year);
+ date = g_date_new_dmy (year, month + 1, day);
+ g_date_strftime (time_string, 127, zen_cal_data->date_format, date);
+ g_print ("%s\n", time_string);
+
+ if (date != NULL)
+ g_date_free (date);
+}
static void
zenity_calendar_dialog_response (GtkWidget *widget, int response, gpointer data)
{
ZenityData *zen_data;
- guint day, month, year;
- gchar time_string[128];
- GDate *date = NULL;
zen_data = data;
switch (response) {
case GTK_RESPONSE_OK:
- gtk_calendar_get_date (GTK_CALENDAR (calendar), &day, &month, &year);
- date = g_date_new_dmy (year, month + 1, day);
- g_date_strftime (time_string, 127, zen_cal_data->date_format, date);
- g_print ("%s\n", time_string);
-
- if (date != NULL)
- g_date_free (date);
- zenity_util_exit_code_with_data (ZENITY_OK, zen_data);
+ zenity_calendar_dialog_output ();
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
break;
case GTK_RESPONSE_CANCEL:
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
break;
+ case ZENITY_TIMEOUT:
+ zenity_calendar_dialog_output ();
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_TIMEOUT);
+ break;
+
default:
/* Esc dialog */
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
diff --git a/src/entry.c b/src/entry.c
index 72f73b5c..da708e22 100644
--- a/src/entry.c
+++ b/src/entry.c
@@ -154,30 +154,39 @@ zenity_entry (ZenityData *data, ZenityEntryData *entry_data)
}
static void
+zenity_entry_dialog_output (void)
+{
+ const gchar *text;
+ if (n_entries > 1)
+ text = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (entry));
+ else
+ text = gtk_entry_get_text (GTK_ENTRY (entry));
+
+ if (text != NULL)
+ g_print ("%s\n", text);
+
+}
+
+static void
zenity_entry_dialog_response (GtkWidget *widget, int response, gpointer data)
{
ZenityData *zen_data = data;
- const gchar *text;
switch (response) {
case GTK_RESPONSE_OK:
+ zenity_entry_dialog_output ();
zenity_util_exit_code_with_data(ZENITY_OK, zen_data);
- if (n_entries > 1) {
- text = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (entry));
- }
- else {
- text = gtk_entry_get_text (GTK_ENTRY (entry));
- }
-
- if (text != NULL)
- g_print ("%s\n", text);
-
break;
case GTK_RESPONSE_CANCEL:
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
break;
+ case ZENITY_TIMEOUT:
+ zenity_entry_dialog_output ();
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_TIMEOUT);
+ break;
+
default:
/* Esc dialog */
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
diff --git a/src/fileselection.c b/src/fileselection.c
index cf82f028..b4b0a65e 100644
--- a/src/fileselection.c
+++ b/src/fileselection.c
@@ -146,29 +146,40 @@ void zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
}
static void
+zenity_fileselection_dialog_output (GtkWidget *widget, ZenityFileData *file_data)
+{
+ GSList *selections, *iter;
+ selections = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER (widget));
+ for (iter = selections;iter != NULL; iter = iter->next) {
+ g_print ("%s", g_filename_to_utf8 ((gchar*)iter->data, -1, NULL, NULL, NULL));
+ g_free (iter->data);
+ if (iter->next != NULL)
+ g_print ("%s",file_data->separator);
+ }
+ g_print("\n");
+ g_slist_free(selections);
+}
+
+static void
zenity_fileselection_dialog_response (GtkWidget *widget, int response, gpointer data)
{
ZenityFileData *file_data = data;
- GSList *selections, *iter;
-
+
switch (response) {
case GTK_RESPONSE_OK:
+ zenity_fileselection_dialog_output (widget, file_data);
zenity_util_exit_code_with_data(ZENITY_OK, zen_data);
- selections = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER (widget));
- for (iter = selections;iter != NULL; iter = iter->next) {
- g_print ("%s", g_filename_to_utf8 ((gchar*)iter->data, -1, NULL, NULL, NULL));
- g_free (iter->data);
- if (iter->next != NULL)
- g_print ("%s",file_data->separator);
- }
- g_print("\n");
- g_slist_free(selections);
break;
case GTK_RESPONSE_CANCEL:
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
break;
+ case ZENITY_TIMEOUT:
+ zenity_fileselection_dialog_output (widget, file_data);
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_TIMEOUT);
+ break;
+
default:
/* Esc dialog */
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
diff --git a/src/forms.c b/src/forms.c
index 6a5b08f8..0bac6679 100644
--- a/src/forms.c
+++ b/src/forms.c
@@ -44,22 +44,6 @@ static void zenity_forms_dialog_get_selected (GtkTreeModel *model, GtkTreePath *
}
}
-static void zenity_forms_dialog_output (void)
-{
- GSList *tmp;
-
- for (tmp = selected; tmp; tmp = tmp->next) {
- if (tmp->next != NULL) {
- g_print ("%s,", (gchar *) tmp->data);
- }
- else
- g_print ("%s", (gchar *) tmp->data);
- }
-
- g_slist_foreach (selected, (GFunc) g_free, NULL);
- selected = NULL;
-}
-
static GtkWidget *
zenity_forms_create_and_fill_list (ZenityFormsData *forms_data,
int list_number, gchar *header)
@@ -317,49 +301,72 @@ void zenity_forms_dialog (ZenityData *data, ZenityFormsData *forms_data)
}
static void
-zenity_forms_dialog_response (GtkWidget *widget, int response, gpointer data)
+zenity_forms_dialog_output (ZenityFormsData *forms_data)
{
- ZenityFormsData *forms_data = (ZenityFormsData *) data;
- GSList *tmp;
+ GSList *tmp, *tmp2;
guint day, year, month;
GDate *date = NULL;
- gchar time_string[128];
+ gchar time_string[128];
GtkTreeSelection *selection;
+ for (tmp = forms_data->list; tmp; tmp = tmp->next) {
+ ZenityFormsValue *zenity_value = (ZenityFormsValue *) tmp->data;
+ switch (zenity_value->type) {
+ case ZENITY_FORMS_PASSWORD:
+ case ZENITY_FORMS_ENTRY:
+ g_print("%s", gtk_entry_get_text (GTK_ENTRY (zenity_value->forms_widget)));
+ break;
+ case ZENITY_FORMS_LIST:
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (gtk_bin_get_child (GTK_BIN (zenity_value->forms_widget))));
+ gtk_tree_selection_selected_foreach (selection,
+ (GtkTreeSelectionForeachFunc) zenity_forms_dialog_get_selected,
+ GTK_TREE_VIEW (gtk_bin_get_child (GTK_BIN (zenity_value->forms_widget))));
+
+ for (tmp2 = selected; tmp2; tmp2 = tmp2->next) {
+ if (tmp->next != NULL) {
+ g_print ("%s,", (gchar *) tmp2->data);
+ }
+ else
+ g_print ("%s", (gchar *) tmp2->data);
+ }
+
+ g_slist_foreach (selected, (GFunc) g_free, NULL);
+ selected = NULL;
+
+ break;
+ case ZENITY_FORMS_CALENDAR:
+ gtk_calendar_get_date (GTK_CALENDAR (zenity_value->forms_widget), &day, &month, &year);
+ date = g_date_new_dmy (year, month + 1, day);
+ g_date_strftime (time_string, 127, forms_data->date_format, date);
+ g_print ("%s", time_string);
+ break;
+ }
+ if (tmp->next != NULL)
+ g_print("%s", forms_data->separator);
+ }
+ g_print("\n");
+}
+
+static void
+zenity_forms_dialog_response (GtkWidget *widget, int response, gpointer data)
+{
+ ZenityFormsData *forms_data = (ZenityFormsData *) data;
+
switch (response) {
case GTK_RESPONSE_OK:
+ zenity_forms_dialog_output (forms_data);
zenity_util_exit_code_with_data(ZENITY_OK, zen_data);
- for (tmp = forms_data->list; tmp; tmp = tmp->next) {
- ZenityFormsValue *zenity_value = (ZenityFormsValue *) tmp->data;
- switch (zenity_value->type) {
- case ZENITY_FORMS_PASSWORD:
- case ZENITY_FORMS_ENTRY:
- g_print("%s", gtk_entry_get_text (GTK_ENTRY (zenity_value->forms_widget)));
- break;
- case ZENITY_FORMS_LIST:
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (gtk_bin_get_child (GTK_BIN (zenity_value->forms_widget))));
- gtk_tree_selection_selected_foreach (selection,
- (GtkTreeSelectionForeachFunc) zenity_forms_dialog_get_selected,
- GTK_TREE_VIEW (gtk_bin_get_child (GTK_BIN (zenity_value->forms_widget))));
- zenity_forms_dialog_output ();
- break;
- case ZENITY_FORMS_CALENDAR:
- gtk_calendar_get_date (GTK_CALENDAR (zenity_value->forms_widget), &day, &month, &year);
- date = g_date_new_dmy (year, month + 1, day);
- g_date_strftime (time_string, 127, forms_data->date_format, date);
- g_print ("%s", time_string);
- break;
- }
- if (tmp->next != NULL)
- g_print("%s", forms_data->separator);
- }
- g_print("\n");
-
break;
+
case GTK_RESPONSE_CANCEL:
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
break;
+ case ZENITY_TIMEOUT:
+ zenity_forms_dialog_output (forms_data);
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_TIMEOUT);
+ break;
+
default:
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
break;
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);
diff --git a/src/scale.c b/src/scale.c
index 21f820eb..a7f6d718 100644
--- a/src/scale.c
+++ b/src/scale.c
@@ -139,6 +139,11 @@ zenity_scale_dialog_response (GtkWidget *widget, int response, gpointer data)
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
break;
+ case ZENITY_TIMEOUT:
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_TIMEOUT);
+ g_print ("%.0f\n", gtk_range_get_value (GTK_RANGE (scale)));
+ break;
+
default:
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
break;
diff --git a/src/text.c b/src/text.c
index 0163c3c0..05ada53d 100644
--- a/src/text.c
+++ b/src/text.c
@@ -345,23 +345,34 @@ zenity_text_toggle_button (GtkToggleButton *button, gpointer data)
}
static void
+zenity_text_dialog_output (ZenityData *zen_data)
+{
+ if (zen_text_data->editable) {
+ GtkTextIter start, end;
+ gchar *text;
+ gtk_text_buffer_get_bounds (zen_text_data->buffer, &start, &end);
+ text = gtk_text_buffer_get_text (zen_text_data->buffer, &start, &end, 0);
+ g_print ("%s", text);
+ g_free (text);
+ }
+}
+
+static void
zenity_text_dialog_response (GtkWidget *widget, int response, gpointer data)
{
ZenityData *zen_data = data;
switch (response) {
case GTK_RESPONSE_CLOSE:
- if (zen_text_data->editable) {
- GtkTextIter start, end;
- gchar *text;
- gtk_text_buffer_get_bounds (zen_text_data->buffer, &start, &end);
- text = gtk_text_buffer_get_text (zen_text_data->buffer, &start, &end, 0);
- g_print ("%s", text);
- g_free (text);
- }
+ zenity_text_dialog_output (zen_data);
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
break;
+ case ZENITY_TIMEOUT:
+ zenity_text_dialog_output (zen_data);
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_TIMEOUT);
+ break;
+
default:
/* Esc dialog */
zenity_util_exit_code_with_data(ZENITY_ESC, zen_data);
diff --git a/src/tree.c b/src/tree.c
index c1a20d0f..cf902391 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -640,6 +640,23 @@ zenity_tree_dialog_toggle_get_selected (GtkTreeModel *model, GtkTreePath *path,
static void
zenity_tree_dialog_output (void)
{
+GObject *tree_view;
+ GtkTreeSelection *selection;
+ GtkTreeModel *model;
+
+ tree_view = gtk_builder_get_object (builder, "zenity_tree_view");
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));
+
+ if (gtk_tree_model_get_column_type (model, 0) == G_TYPE_BOOLEAN)
+ gtk_tree_model_foreach (model, (GtkTreeModelForeachFunc) zenity_tree_dialog_toggle_get_selected,
+ GTK_TREE_VIEW (tree_view));
+ else {
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
+ gtk_tree_selection_selected_foreach (selection,
+ (GtkTreeSelectionForeachFunc) zenity_tree_dialog_get_selected,
+ GTK_TREE_VIEW (tree_view));
+ }
+
GSList *tmp;
for (tmp = selected; tmp; tmp = tmp->next) {
@@ -661,24 +678,9 @@ static void
zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data)
{
ZenityData *zen_data = data;
- GObject *tree_view;
- GtkTreeSelection *selection;
- GtkTreeModel *model;
switch (response) {
case GTK_RESPONSE_OK:
- tree_view = gtk_builder_get_object (builder, "zenity_tree_view");
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));
-
- if (gtk_tree_model_get_column_type (model, 0) == G_TYPE_BOOLEAN)
- gtk_tree_model_foreach (model, (GtkTreeModelForeachFunc) zenity_tree_dialog_toggle_get_selected,
- GTK_TREE_VIEW (tree_view));
- else {
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
- gtk_tree_selection_selected_foreach (selection,
- (GtkTreeSelectionForeachFunc) zenity_tree_dialog_get_selected,
- GTK_TREE_VIEW (tree_view));
- }
zenity_tree_dialog_output ();
zenity_util_exit_code_with_data(ZENITY_OK, zen_data);
break;
@@ -687,6 +689,11 @@ zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data)
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
break;
+ case ZENITY_TIMEOUT:
+ zenity_tree_dialog_output ();
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_TIMEOUT);
+ break;
+
default:
/* Esc dialog */
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
diff --git a/src/util.c b/src/util.c
index 1fb8e327..df7317a9 100644
--- a/src/util.c
+++ b/src/util.c
@@ -312,7 +312,7 @@ zenity_util_return_exit_code ( ZenityExitCode value )
if (! env_var)
retval = ZENITY_TIMEOUT;
break;
-
+
default:
retval = 1;
}
@@ -325,10 +325,6 @@ zenity_util_return_exit_code ( ZenityExitCode value )
void
zenity_util_exit_code_with_data(ZenityExitCode value, ZenityData *zen_data)
{
- /* We assume it's being called with --timeout option and should return 5) */
- if(zen_data->timeout_delay > 0)
- zen_data->exit_code = zenity_util_return_exit_code (ZENITY_TIMEOUT);
- else
zen_data->exit_code = zenity_util_return_exit_code (value);
}
@@ -432,7 +428,7 @@ zenity_util_timeout_handle (gpointer data)
{
GtkDialog *dialog = GTK_DIALOG(data);
if(dialog != NULL)
- gtk_dialog_response(dialog, GTK_RESPONSE_OK);
+ gtk_dialog_response(dialog, ZENITY_TIMEOUT);
else {
gtk_main_quit();
exit(ZENITY_TIMEOUT);
bgstack15