Now if you use --timeout option, the return code will be properly handled

The default behavior will be done (ie. user click on ok button)
The return code will be 5
This commit is contained in:
Arx Cruz 2011-06-17 10:47:07 -03:00
parent f77a0199af
commit d60e5eeeb3
13 changed files with 31 additions and 13 deletions

View File

@ -112,8 +112,7 @@ zenity_calendar_dialog_response (GtkWidget *widget, int response, gpointer data)
if (date != NULL)
g_date_free (date);
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
zenity_util_exit_code_with_data (ZENITY_OK, zen_data);
break;
case GTK_RESPONSE_CANCEL:

View File

@ -78,7 +78,7 @@ zenity_colorselection_dialog_response (GtkWidget *widget, int response, gpointer
switch (response) {
case GTK_RESPONSE_OK:
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
zenity_util_exit_code_with_data(ZENITY_OK, zen_data);
colorsel = gtk_color_selection_dialog_get_color_selection (GTK_COLOR_SELECTION_DIALOG (widget));
gtk_color_selection_get_current_color (GTK_COLOR_SELECTION (colorsel), &color);
g_print ("%s\n", gdk_color_to_string (&color));

View File

@ -143,7 +143,7 @@ zenity_entry_dialog_response (GtkWidget *widget, int response, gpointer data)
switch (response) {
case GTK_RESPONSE_OK:
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
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));
}

View File

@ -150,7 +150,7 @@ zenity_fileselection_dialog_response (GtkWidget *widget, int response, gpointer
switch (response) {
case GTK_RESPONSE_OK:
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_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));

View File

@ -181,7 +181,7 @@ zenity_forms_dialog_response (GtkWidget *widget, int response, gpointer data)
switch (response) {
case GTK_RESPONSE_OK:
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_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) {

View File

@ -153,7 +153,7 @@ zenity_msg_dialog_response (GtkWidget *widget, int response, gpointer data)
switch (response) {
case GTK_RESPONSE_OK:
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
zenity_util_exit_code_with_data(ZENITY_OK, zen_data);
break;
case GTK_RESPONSE_CANCEL:

View File

@ -154,7 +154,7 @@ zenity_password_dialog_response (GtkWidget *widget, int response, gpointer data)
ZenityPasswordData *password_data = (ZenityPasswordData *) data;
switch (response) {
case GTK_RESPONSE_OK:
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
zenity_util_exit_code_with_data(ZENITY_OK, zen_data);
if (password_data->username)
g_print("%s|%s\n", gtk_entry_get_text (GTK_ENTRY(password_data->entry_username)), gtk_entry_get_text (GTK_ENTRY(password_data->entry_password)));
else

View File

@ -297,7 +297,7 @@ zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data)
{
switch (response) {
case GTK_RESPONSE_OK:
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
zenity_util_exit_code_with_data(ZENITY_OK, zen_data);
break;
case GTK_RESPONSE_CANCEL:

View File

@ -113,7 +113,7 @@ zenity_scale_dialog_response (GtkWidget *widget, int response, gpointer data)
switch (response) {
case GTK_RESPONSE_OK:
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
zenity_util_exit_code_with_data(ZENITY_OK, zen_data);
g_print ("%.0f\n", gtk_range_get_value (GTK_RANGE (scale)));
break;

View File

@ -187,7 +187,7 @@ zenity_text_dialog_response (GtkWidget *widget, int response, gpointer data)
default:
/* Esc dialog */
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
zenity_util_exit_code_with_data(ZENITY_ESC, zen_data);
break;
}
gtk_main_quit ();

View File

@ -613,7 +613,7 @@ zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data)
GTK_TREE_VIEW (tree_view));
}
zenity_tree_dialog_output ();
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
zenity_util_exit_code_with_data(ZENITY_OK, zen_data);
break;
case GTK_RESPONSE_CANCEL:

View File

@ -305,6 +305,14 @@ zenity_util_return_exit_code ( ZenityExitCode value )
retval = ZENITY_ERROR_DEFAULT;
break;
case ZENITY_TIMEOUT:
env_var = g_getenv("ZENITY_TIMEOUT");
if (! env_var)
env_var = g_getenv("DIALOG_TIMEOUT");
if (! env_var)
retval = ZENITY_TIMEOUT;
break;
default:
retval = 1;
}
@ -314,6 +322,15 @@ zenity_util_return_exit_code ( ZenityExitCode value )
return retval;
}
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);
}
#ifdef GDK_WINDOWING_X11

View File

@ -26,6 +26,8 @@ GdkPixbuf * zenity_util_pixbuf_new_from_file (GtkWidget *widget,
const gchar *filename);
void zenity_util_show_help (GError **error);
gint zenity_util_return_exit_code (ZenityExitCode value);
void zenity_util_exit_code_with_data (ZenityExitCode value,
ZenityData *data);
void zenity_util_show_dialog (GtkWidget *widget);
gboolean zenity_util_timeout_handle (gpointer data);