summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/about.c6
-rw-r--r--src/calendar.c8
-rw-r--r--src/entry.c8
-rw-r--r--src/fileselection.c9
-rw-r--r--src/msg.c6
-rw-r--r--src/progress.c10
-rw-r--r--src/text.c6
-rw-r--r--src/tree.c10
-rw-r--r--src/util.c64
-rw-r--r--src/util.h3
-rw-r--r--src/zenity.h8
11 files changed, 107 insertions, 31 deletions
diff --git a/src/about.c b/src/about.c
index ddc3325..e00cbce 100644
--- a/src/about.c
+++ b/src/about.c
@@ -257,7 +257,7 @@ zenity_about (ZenityData *data)
glade_dialog = zenity_util_load_glade_file ("zenity_about_dialog");
if (glade_dialog == NULL) {
- data->exit_code = -1;
+ data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
return;
}
@@ -434,7 +434,7 @@ zenity_about_dialog_response (GtkWidget *widget, int response, gpointer data)
switch (response) {
case GTK_RESPONSE_OK:
- zen_data->exit_code = 0;
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
gtk_main_quit ();
break;
@@ -448,7 +448,7 @@ zenity_about_dialog_response (GtkWidget *widget, int response, gpointer data)
default:
/* Esc dialog */
- zen_data->exit_code = 1;
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
break;
}
}
diff --git a/src/calendar.c b/src/calendar.c
index 460ab8d..e2d94ff 100644
--- a/src/calendar.c
+++ b/src/calendar.c
@@ -44,7 +44,7 @@ zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data)
glade_dialog = zenity_util_load_glade_file ("zenity_calendar_dialog");
if (glade_dialog == NULL) {
- data->exit_code = -1;
+ data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
return;
}
@@ -105,18 +105,18 @@ zenity_calendar_dialog_response (GtkWidget *widget, int response, gpointer data)
if (date != NULL)
g_date_free (date);
- zen_data->exit_code = 0;
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
gtk_main_quit ();
break;
case GTK_RESPONSE_CANCEL:
- zen_data->exit_code = 1;
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
gtk_main_quit ();
break;
default:
/* Esc dialog */
- zen_data->exit_code = 1;
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
break;
}
}
diff --git a/src/entry.c b/src/entry.c
index a46fd61..d3b6656 100644
--- a/src/entry.c
+++ b/src/entry.c
@@ -39,7 +39,7 @@ zenity_entry (ZenityData *data, ZenityEntryData *entry_data)
glade_dialog = zenity_util_load_glade_file ("zenity_entry_dialog");
if (glade_dialog == NULL) {
- data->exit_code = -1;
+ data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
return;
}
@@ -91,7 +91,7 @@ zenity_entry_dialog_response (GtkWidget *widget, int response, gpointer data)
switch (response) {
case GTK_RESPONSE_OK:
- zen_data->exit_code = 0;
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
text = gtk_entry_get_text (GTK_ENTRY (entry));
if (text != NULL)
@@ -101,13 +101,13 @@ zenity_entry_dialog_response (GtkWidget *widget, int response, gpointer data)
break;
case GTK_RESPONSE_CANCEL:
- zen_data->exit_code = 1;
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
gtk_main_quit ();
break;
default:
/* Esc dialog */
- zen_data->exit_code = 1;
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
break;
}
}
diff --git a/src/fileselection.c b/src/fileselection.c
index ec46f0c..69fc658 100644
--- a/src/fileselection.c
+++ b/src/fileselection.c
@@ -35,7 +35,7 @@ void zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
glade_dialog = zenity_util_load_glade_file ("zenity_fileselection_dialog");
if (glade_dialog == NULL) {
- data->exit_code = -1;
+ data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
return;
}
@@ -73,19 +73,20 @@ zenity_fileselection_dialog_response (GtkWidget *widget, int response, gpointer
switch (response) {
case GTK_RESPONSE_OK:
- zen_data->exit_code = 0;
+ zen_data->exit_code = zenity_util_return_exit_code
+ (ZENITY_OK);
g_printerr ("%s\n", gtk_file_selection_get_filename (GTK_FILE_SELECTION (widget)));
gtk_main_quit ();
break;
case GTK_RESPONSE_CANCEL:
- zen_data->exit_code = 1;
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
gtk_main_quit ();
break;
default:
/* Esc dialog */
- zen_data->exit_code = 1;
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
break;
}
}
diff --git a/src/msg.c b/src/msg.c
index 22f5018..2b4083b 100644
--- a/src/msg.c
+++ b/src/msg.c
@@ -71,7 +71,7 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
G_CALLBACK (zenity_msg_dialog_response), data);
if (glade_dialog == NULL) {
- data->exit_code = -1;
+ data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
return;
}
@@ -124,12 +124,12 @@ zenity_msg_dialog_response (GtkWidget *widget, int response, gpointer data)
switch (response) {
case GTK_RESPONSE_OK:
- zen_data->exit_code = 0;
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
gtk_main_quit ();
break;
case GTK_RESPONSE_CANCEL:
- zen_data->exit_code = 1;
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
gtk_main_quit ();
break;
diff --git a/src/progress.c b/src/progress.c
index 0fa8088..e07039b 100644
--- a/src/progress.c
+++ b/src/progress.c
@@ -116,7 +116,7 @@ zenity_progress_handle_stdin (GIOChannel *channel,
gtk_widget_set_sensitive(GTK_WIDGET (button), TRUE);
gtk_widget_grab_focus(GTK_WIDGET (button));
if (progress_data->autoclose) {
- zen_data->exit_code = 0;
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
gtk_main_quit();
}
@@ -177,7 +177,7 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data)
glade_dialog = zenity_util_load_glade_file ("zenity_progress_dialog");
if (glade_dialog == NULL) {
- data->exit_code = -1;
+ data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
return;
}
@@ -218,7 +218,7 @@ zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data)
{
switch (response) {
case GTK_RESPONSE_OK:
- zen_data->exit_code = 0;
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
gtk_main_quit ();
break;
@@ -228,13 +228,13 @@ zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data)
* stuff. Should be using SIGHUP instead of 1 though.
*/
kill (getpid (), 1);
- zen_data->exit_code = 1;
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
gtk_main_quit ();
break;
default:
/* Esc dialog */
- zen_data->exit_code = 1;
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
break;
}
}
diff --git a/src/text.c b/src/text.c
index af655e5..0afe269 100644
--- a/src/text.c
+++ b/src/text.c
@@ -41,7 +41,7 @@ zenity_text (ZenityData *data, ZenityTextData *text_data)
glade_dialog = zenity_util_load_glade_file ("zenity_text_dialog");
if (glade_dialog == NULL) {
- data->exit_code = -1;
+ data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
return;
}
@@ -95,13 +95,13 @@ zenity_text_dialog_response (GtkWidget *widget, int response, gpointer data)
gtk_text_buffer_get_bounds (zen_text_data->buffer, &start, &end);
g_printerr (gtk_text_buffer_get_text (zen_text_data->buffer, &start, &end, 0));
}
- zen_data->exit_code = 0;
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
gtk_main_quit ();
break;
default:
/* Esc dialog */
- zen_data->exit_code = 1;
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
break;
}
}
diff --git a/src/tree.c b/src/tree.c
index f3e6377..903ef70 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -279,7 +279,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
glade_dialog = zenity_util_load_glade_file ("zenity_tree_dialog");
if (glade_dialog == NULL) {
- data->exit_code = -1;
+ data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
return;
}
@@ -289,7 +289,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
if (n_columns == 0) {
g_printerr (_("No column titles specified for List dialog.\n"));
- data->exit_code = -1;
+ data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
return;
}
@@ -517,18 +517,18 @@ zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data)
GTK_TREE_VIEW (tree_view));
}
zenity_tree_dialog_output ();
- zen_data->exit_code = 0;
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
gtk_main_quit ();
break;
case GTK_RESPONSE_CANCEL:
- zen_data->exit_code = 1;
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
gtk_main_quit ();
break;
default:
/* Esc dialog */
- zen_data->exit_code = 1;
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
break;
}
}
diff --git a/src/util.c b/src/util.c
index 7c8805a..5091f2a 100644
--- a/src/util.c
+++ b/src/util.c
@@ -39,6 +39,12 @@
#define URL_HANDLER_DIR "/desktop/gnome/url-handlers/"
#define DEFAULT_HANDLER_PATH "/desktop/gnome/url-handlers/unknown/command"
+#define ZENITY_OK_DEFAULT 0
+#define ZENITY_CANCEL_DEFAULT 1
+#define ZENITY_ESC_DEFAULT 1
+#define ZENITY_ERROR_DEFAULT -1
+#define ZENITY_EXTRA_DEFAULT 127
+
GladeXML*
zenity_util_load_glade_file (const gchar *widget_root)
{
@@ -592,3 +598,61 @@ zenity_util_show_help (const gchar *path, const gchar *document, GError **error)
return ret;
}
+
+gint
+zenity_util_return_exit_code ( ZenityExitCode value )
+{
+
+ const gchar *env_var = NULL;
+ gint retval;
+
+ switch (value) {
+
+ case ZENITY_OK:
+ env_var = g_getenv("ZENITY_OK");
+ if (! env_var)
+ env_var = g_getenv("DIALOG_OK");
+ if (! env_var)
+ retval = ZENITY_OK_DEFAULT;
+ break;
+
+ case ZENITY_CANCEL:
+ env_var = g_getenv("ZENITY_CANCEL");
+ if (! env_var)
+ env_var = g_getenv("DIALOG_CANCEL");
+ if (! env_var)
+ retval = ZENITY_CANCEL_DEFAULT;
+ break;
+
+ case ZENITY_ESC:
+ env_var = g_getenv("ZENITY_ESC");
+ if (! env_var)
+ env_var = g_getenv("DIALOG_ESC");
+ if (! env_var)
+ retval = ZENITY_ESC_DEFAULT;
+ break;
+
+ case ZENITY_EXTRA:
+ env_var = g_getenv("ZENITY_EXTRA");
+ if (! env_var)
+ env_var = g_getenv("DIALOG_EXTRA");
+ if (! env_var)
+ retval = ZENITY_EXTRA_DEFAULT;
+ break;
+
+ case ZENITY_ERROR:
+ env_var = g_getenv("ZENITY_ERROR");
+ if (! env_var)
+ env_var = g_getenv("DIALOG_ERROR");
+ if (! env_var)
+ retval = ZENITY_ERROR_DEFAULT;
+ break;
+
+ default:
+ retval = 1;
+ }
+
+ if (env_var)
+ retval = atoi (env_var);
+ return retval;
+}
diff --git a/src/util.h b/src/util.h
index abfd2ae..0b518a1 100644
--- a/src/util.h
+++ b/src/util.h
@@ -3,6 +3,7 @@
#include <gtk/gtk.h>
#include <glade/glade.h>
+#include "zenity.h"
G_BEGIN_DECLS
@@ -21,6 +22,8 @@ void zenity_util_set_window_icon_from_stock (GtkWidget *widge
gboolean zenity_util_show_help (const gchar *path,
const gchar *document,
GError **error);
+gint zenity_util_return_exit_code (ZenityExitCode value);
+
G_END_DECLS
#endif /* UTIL_H */
diff --git a/src/zenity.h b/src/zenity.h
index e96f528..97ecee1 100644
--- a/src/zenity.h
+++ b/src/zenity.h
@@ -31,6 +31,14 @@ typedef struct {
gint exit_code;
} ZenityData;
+typedef enum {
+ ZENITY_OK,
+ ZENITY_CANCEL,
+ ZENITY_ESC,
+ ZENITY_ERROR,
+ ZENITY_EXTRA
+} ZenityExitCode;
+
typedef struct {
gchar *dialog_text;
gint day;