summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog13
-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
12 files changed, 120 insertions, 31 deletions
diff --git a/ChangeLog b/ChangeLog
index b6fca517..e0393de9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2003-06-07 Mike Newman <mikegtn@gnome.org>
+
+ * src/calendar.c: Allow user-defined return values via env vars
+ * src/entry.c: Prefer ZENITY_OK etc, but also check for DIALOG_OK
+ * src/fileselection.c: and fall through to original zenity behaviour.
+ * src/msg.c:
+ * src/progress.c:
+ * src/text.c:
+ * src/tree.c:
+ * src/util.c:
+ * src/util.h:
+ * src/zenity.h:
+
2003-06-07 Glynn Foster <glynn.foster@sun.com>
* src/zenity.glade: Untranslate silly strings pointed out by
diff --git a/src/about.c b/src/about.c
index ddc3325f..e00cbce7 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 460ab8d5..e2d94ffd 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 a46fd613..d3b6656e 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 ec46f0c1..69fc6583 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 22f50187..2b4083b5 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 0fa80882..e07039be 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 af655e50..0afe2694 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 f3e63779..903ef704 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 7c8805a1..5091f2ab 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 abfd2aed..0b518a1e 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 e96f5285..97ecee17 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;
bgstack15