But #674881 - Timeout option overriding normal exit code

This commit is contained in:
Arx Cruz 2013-03-05 16:56:24 -03:00
parent 3af1e444e6
commit 1ac1da63f8
9 changed files with 170 additions and 110 deletions

View File

@ -110,33 +110,44 @@ zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data)
gtk_main (); 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 static void
zenity_calendar_dialog_response (GtkWidget *widget, int response, gpointer data) zenity_calendar_dialog_response (GtkWidget *widget, int response, gpointer data)
{ {
ZenityData *zen_data; ZenityData *zen_data;
guint day, month, year;
gchar time_string[128];
GDate *date = NULL;
zen_data = data; zen_data = data;
switch (response) { switch (response) {
case GTK_RESPONSE_OK: case GTK_RESPONSE_OK:
gtk_calendar_get_date (GTK_CALENDAR (calendar), &day, &month, &year); zenity_calendar_dialog_output ();
date = g_date_new_dmy (year, month + 1, day); zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
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);
break; break;
case GTK_RESPONSE_CANCEL: case GTK_RESPONSE_CANCEL:
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
break; break;
case ZENITY_TIMEOUT:
zenity_calendar_dialog_output ();
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_TIMEOUT);
break;
default: default:
/* Esc dialog */ /* Esc dialog */
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);

View File

@ -153,31 +153,40 @@ zenity_entry (ZenityData *data, ZenityEntryData *entry_data)
gtk_main (); gtk_main ();
} }
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 static void
zenity_entry_dialog_response (GtkWidget *widget, int response, gpointer data) zenity_entry_dialog_response (GtkWidget *widget, int response, gpointer data)
{ {
ZenityData *zen_data = data; ZenityData *zen_data = data;
const gchar *text;
switch (response) { switch (response) {
case GTK_RESPONSE_OK: case GTK_RESPONSE_OK:
zenity_entry_dialog_output ();
zenity_util_exit_code_with_data(ZENITY_OK, zen_data); 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; break;
case GTK_RESPONSE_CANCEL: case GTK_RESPONSE_CANCEL:
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
break; break;
case ZENITY_TIMEOUT:
zenity_entry_dialog_output ();
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_TIMEOUT);
break;
default: default:
/* Esc dialog */ /* Esc dialog */
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);

View File

@ -145,30 +145,41 @@ void zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
gtk_main (); gtk_main ();
} }
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 static void
zenity_fileselection_dialog_response (GtkWidget *widget, int response, gpointer data) zenity_fileselection_dialog_response (GtkWidget *widget, int response, gpointer data)
{ {
ZenityFileData *file_data = data; ZenityFileData *file_data = data;
GSList *selections, *iter;
switch (response) { switch (response) {
case GTK_RESPONSE_OK: case GTK_RESPONSE_OK:
zenity_fileselection_dialog_output (widget, file_data);
zenity_util_exit_code_with_data(ZENITY_OK, zen_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; break;
case GTK_RESPONSE_CANCEL: case GTK_RESPONSE_CANCEL:
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
break; break;
case ZENITY_TIMEOUT:
zenity_fileselection_dialog_output (widget, file_data);
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_TIMEOUT);
break;
default: default:
/* Esc dialog */ /* Esc dialog */
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);

View File

@ -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 * static GtkWidget *
zenity_forms_create_and_fill_list (ZenityFormsData *forms_data, zenity_forms_create_and_fill_list (ZenityFormsData *forms_data,
int list_number, gchar *header) int list_number, gchar *header)
@ -317,49 +301,72 @@ void zenity_forms_dialog (ZenityData *data, ZenityFormsData *forms_data)
} }
static void 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, *tmp2;
GSList *tmp;
guint day, year, month; guint day, year, month;
GDate *date = NULL; GDate *date = NULL;
gchar time_string[128]; gchar time_string[128];
GtkTreeSelection *selection; 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) { switch (response) {
case GTK_RESPONSE_OK: case GTK_RESPONSE_OK:
zenity_forms_dialog_output (forms_data);
zenity_util_exit_code_with_data(ZENITY_OK, zen_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; break;
case GTK_RESPONSE_CANCEL: case GTK_RESPONSE_CANCEL:
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
break; break;
case ZENITY_TIMEOUT:
zenity_forms_dialog_output (forms_data);
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_TIMEOUT);
break;
default: default:
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
break; break;

View File

@ -307,7 +307,7 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data)
zenity_progress_read_info (progress_data); zenity_progress_read_info (progress_data);
if(data->timeout_delay > 0) { 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 (); 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); zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
break; break;
case ZENITY_TIMEOUT:
zenity_util_exit_code_with_data (ZENITY_TIMEOUT, zen_data);
break;
default: default:
/* Esc dialog */ /* Esc dialog */
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);

View File

@ -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); zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
break; 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: default:
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
break; break;

View File

@ -344,6 +344,19 @@ zenity_text_toggle_button (GtkToggleButton *button, gpointer data)
gtk_widget_set_sensitive (GTK_WIDGET(ok_button), gtk_toggle_button_get_active(button)); gtk_widget_set_sensitive (GTK_WIDGET(ok_button), gtk_toggle_button_get_active(button));
} }
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 static void
zenity_text_dialog_response (GtkWidget *widget, int response, gpointer data) zenity_text_dialog_response (GtkWidget *widget, int response, gpointer data)
{ {
@ -351,17 +364,15 @@ zenity_text_dialog_response (GtkWidget *widget, int response, gpointer data)
switch (response) { switch (response) {
case GTK_RESPONSE_CLOSE: case GTK_RESPONSE_CLOSE:
if (zen_text_data->editable) { zenity_text_dialog_output (zen_data);
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);
}
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
break; break;
case ZENITY_TIMEOUT:
zenity_text_dialog_output (zen_data);
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_TIMEOUT);
break;
default: default:
/* Esc dialog */ /* Esc dialog */
zenity_util_exit_code_with_data(ZENITY_ESC, zen_data); zenity_util_exit_code_with_data(ZENITY_ESC, zen_data);

View File

@ -640,6 +640,23 @@ zenity_tree_dialog_toggle_get_selected (GtkTreeModel *model, GtkTreePath *path,
static void static void
zenity_tree_dialog_output (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; GSList *tmp;
for (tmp = selected; tmp; tmp = tmp->next) { for (tmp = selected; tmp; tmp = tmp->next) {
@ -661,24 +678,9 @@ static void
zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data) zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data)
{ {
ZenityData *zen_data = data; ZenityData *zen_data = data;
GObject *tree_view;
GtkTreeSelection *selection;
GtkTreeModel *model;
switch (response) { switch (response) {
case GTK_RESPONSE_OK: 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_tree_dialog_output ();
zenity_util_exit_code_with_data(ZENITY_OK, zen_data); zenity_util_exit_code_with_data(ZENITY_OK, zen_data);
break; 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); zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
break; break;
case ZENITY_TIMEOUT:
zenity_tree_dialog_output ();
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_TIMEOUT);
break;
default: default:
/* Esc dialog */ /* Esc dialog */
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);

View File

@ -325,10 +325,6 @@ zenity_util_return_exit_code ( ZenityExitCode value )
void void
zenity_util_exit_code_with_data(ZenityExitCode value, ZenityData *zen_data) 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); 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); GtkDialog *dialog = GTK_DIALOG(data);
if(dialog != NULL) if(dialog != NULL)
gtk_dialog_response(dialog, GTK_RESPONSE_OK); gtk_dialog_response(dialog, ZENITY_TIMEOUT);
else { else {
gtk_main_quit(); gtk_main_quit();
exit(ZENITY_TIMEOUT); exit(ZENITY_TIMEOUT);