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,19 +110,13 @@ zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data)
gtk_main ();
}
static void
zenity_calendar_dialog_response (GtkWidget *widget, int response, gpointer data)
zenity_calendar_dialog_output (void)
{
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);
@ -130,13 +124,30 @@ zenity_calendar_dialog_response (GtkWidget *widget, int response, gpointer data)
if (date != NULL)
g_date_free (date);
zenity_util_exit_code_with_data (ZENITY_OK, zen_data);
}
static void
zenity_calendar_dialog_response (GtkWidget *widget, int response, gpointer data)
{
ZenityData *zen_data;
zen_data = data;
switch (response) {
case GTK_RESPONSE_OK:
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);

View File

@ -154,30 +154,39 @@ zenity_entry (ZenityData *data, ZenityEntryData *entry_data)
}
static void
zenity_entry_dialog_response (GtkWidget *widget, int response, gpointer data)
zenity_entry_dialog_output (void)
{
ZenityData *zen_data = data;
const gchar *text;
switch (response) {
case GTK_RESPONSE_OK:
zenity_util_exit_code_with_data(ZENITY_OK, zen_data);
if (n_entries > 1) {
if (n_entries > 1)
text = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (entry));
}
else {
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;
switch (response) {
case GTK_RESPONSE_OK:
zenity_entry_dialog_output ();
zenity_util_exit_code_with_data(ZENITY_OK, zen_data);
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);

View File

@ -146,14 +146,9 @@ void zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
}
static void
zenity_fileselection_dialog_response (GtkWidget *widget, int response, gpointer data)
zenity_fileselection_dialog_output (GtkWidget *widget, ZenityFileData *file_data)
{
ZenityFileData *file_data = data;
GSList *selections, *iter;
switch (response) {
case GTK_RESPONSE_OK:
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));
@ -163,12 +158,28 @@ zenity_fileselection_dialog_response (GtkWidget *widget, int response, gpointer
}
g_print("\n");
g_slist_free(selections);
}
static void
zenity_fileselection_dialog_response (GtkWidget *widget, int response, gpointer data)
{
ZenityFileData *file_data = data;
switch (response) {
case GTK_RESPONSE_OK:
zenity_fileselection_dialog_output (widget, file_data);
zenity_util_exit_code_with_data(ZENITY_OK, zen_data);
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);

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 *
zenity_forms_create_and_fill_list (ZenityFormsData *forms_data,
int list_number, gchar *header)
@ -317,18 +301,14 @@ 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];
GtkTreeSelection *selection;
switch (response) {
case GTK_RESPONSE_OK:
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) {
@ -341,7 +321,18 @@ zenity_forms_dialog_response (GtkWidget *widget, int response, gpointer data)
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 ();
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);
@ -354,12 +345,28 @@ zenity_forms_dialog_response (GtkWidget *widget, int response, gpointer data)
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);
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;

View File

@ -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);

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);
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;

View File

@ -345,12 +345,8 @@ zenity_text_toggle_button (GtkToggleButton *button, gpointer data)
}
static void
zenity_text_dialog_response (GtkWidget *widget, int response, gpointer data)
zenity_text_dialog_output (ZenityData *zen_data)
{
ZenityData *zen_data = data;
switch (response) {
case GTK_RESPONSE_CLOSE:
if (zen_text_data->editable) {
GtkTextIter start, end;
gchar *text;
@ -359,9 +355,24 @@ zenity_text_dialog_response (GtkWidget *widget, int response, gpointer data)
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:
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);

View File

@ -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);

View File

@ -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);