Fix up the response signal handlers. Use returns of 0 for 'Ok' and

2003-01-07  Glynn Foster  <glynn.foster@sun.com>

	* src/calendar.c, src/entry.c, src/fileselection.c,
	src/main.c, src/msg.c, src/progress.c, src/text.c,
	src/tree.c, src/zenity.glade, src/zenity.h: Fix up
	the response signal handlers. Use returns of 0 for
	'Ok' and 'Close', 1 for 'Cancel' and 'Escape' and
	-1 for 'Uh Oh'. Get stuff printing to stderr. Fix up
	the error handling that I thought was improved,
	although still have issues with popt callback getting
	called numerous times because of more than one instance
	of the same kind is being used in poptOption.

	* TODO: Update accordingly.
This commit is contained in:
Glynn Foster 2003-01-07 13:22:57 +00:00 committed by Glynn Foster
parent 952fc14e7b
commit 6a65d75921
12 changed files with 189 additions and 148 deletions

View File

@ -1,3 +1,18 @@
2003-01-07 Glynn Foster <glynn.foster@sun.com>
* src/calendar.c, src/entry.c, src/fileselection.c,
src/main.c, src/msg.c, src/progress.c, src/text.c,
src/tree.c, src/zenity.glade, src/zenity.h: Fix up
the response signal handlers. Use returns of 0 for
'Ok' and 'Close', 1 for 'Cancel' and 'Escape' and
-1 for 'Uh Oh'. Get stuff printing to stderr. Fix up
the error handling that I thought was improved,
although still have issues with popt callback getting
called numerous times because of more than one instance
of the same kind is being used in poptOption.
* TODO: Update accordingly.
2003-01-07 Glynn Foster <glynn.foster@sun.com> 2003-01-07 Glynn Foster <glynn.foster@sun.com>
* src/main.c: Fix up the error returns. * src/main.c: Fix up the error returns.

1
TODO
View File

@ -1,5 +1,6 @@
* Finish off support for progress dialog * Finish off support for progress dialog
* Implement return values for all dialogs * Implement return values for all dialogs
* All done, except for list view
* Add some accessibility I guess * Add some accessibility I guess
* Find some nice default window icons * Find some nice default window icons
* Implement about box * Implement about box

View File

@ -25,23 +25,32 @@
#include "zenity.h" #include "zenity.h"
#include "util.h" #include "util.h"
void zenity_calendar_dialog_response (GtkWindow *window, int button, gpointer data);
int zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data) static GtkWidget *calendar;
static void zenity_calendar_dialog_response (GtkWidget *widget, int response, gpointer data);
void
zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data)
{ {
GladeXML *glade_dialog = NULL; GladeXML *glade_dialog = NULL;
GtkWidget *dialog; GtkWidget *dialog;
GtkWidget *calendar;
GtkWidget *text; GtkWidget *text;
glade_dialog = zenity_util_load_glade_file ("zenity_calendar_dialog"); glade_dialog = zenity_util_load_glade_file ("zenity_calendar_dialog");
if (glade_dialog == NULL) if (glade_dialog == NULL) {
return FALSE; data->exit_code = -1;
return;
}
glade_xml_signal_autoconnect (glade_dialog); glade_xml_signal_autoconnect (glade_dialog);
dialog = glade_xml_get_widget (glade_dialog, "zenity_calendar_dialog"); dialog = glade_xml_get_widget (glade_dialog, "zenity_calendar_dialog");
g_signal_connect (G_OBJECT (dialog), "response",
G_CALLBACK (zenity_calendar_dialog_response), data);
if (data->dialog_title) if (data->dialog_title)
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
@ -55,36 +64,41 @@ int zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data)
calendar = glade_xml_get_widget (glade_dialog, "zenity_calendar"); calendar = glade_xml_get_widget (glade_dialog, "zenity_calendar");
if (glade_dialog)
g_object_unref (glade_dialog);
if (cal_data->month > 0 && cal_data->year > 0) if (cal_data->month > 0 && cal_data->year > 0)
gtk_calendar_select_month (GTK_CALENDAR (calendar), cal_data->month, cal_data->year); gtk_calendar_select_month (GTK_CALENDAR (calendar), cal_data->month - 1, cal_data->year);
if (cal_data->day > 0) if (cal_data->day > 0)
gtk_calendar_select_day (GTK_CALENDAR (calendar), cal_data->day); gtk_calendar_select_day (GTK_CALENDAR (calendar), cal_data->day);
gtk_label_set_mnemonic_widget (GTK_LABEL (text), calendar); gtk_label_set_mnemonic_widget (GTK_LABEL (text), calendar);
gtk_widget_show (dialog); gtk_widget_show (dialog);
gtk_main (); gtk_main ();
if (glade_dialog)
g_object_unref (glade_dialog);
return TRUE;
} }
void static void
zenity_calendar_dialog_response (GtkWindow *window, int button, gpointer data) zenity_calendar_dialog_response (GtkWidget *widget, int response, gpointer data)
{ {
GError *error = NULL; ZenityData *zen_data = data;
guint day, month, year;
switch (button) { switch (response) {
case GTK_RESPONSE_OK: case GTK_RESPONSE_OK:
gtk_calendar_get_date (GTK_CALENDAR (calendar), &day, &month, &year);
g_printerr ("%02d/%02d/%02d\n", day, month + 1, year);
zen_data->exit_code = 0;
gtk_main_quit (); gtk_main_quit ();
break; break;
case GTK_RESPONSE_CANCEL: case GTK_RESPONSE_CANCEL:
zen_data->exit_code = 1;
gtk_main_quit (); gtk_main_quit ();
break; break;
default: default:
/* Esc dialog */
zen_data->exit_code = 1;
break; break;
} }
} }

View File

@ -25,23 +25,31 @@
#include "zenity.h" #include "zenity.h"
#include "util.h" #include "util.h"
void zenity_entry_dialog_response (GtkWindow *window, int button, gpointer data); static void zenity_entry_dialog_response (GtkWidget *widget, int response, gpointer data);
int zenity_entry (ZenityData *data, ZenityEntryData *entry_data) static GtkWidget *entry;
void
zenity_entry (ZenityData *data, ZenityEntryData *entry_data)
{ {
GladeXML *glade_dialog = NULL; GladeXML *glade_dialog = NULL;
GtkWidget *dialog; GtkWidget *dialog;
GtkWidget *text; GtkWidget *text;
GtkWidget *entry;
glade_dialog = zenity_util_load_glade_file ("zenity_entry_dialog"); glade_dialog = zenity_util_load_glade_file ("zenity_entry_dialog");
if (glade_dialog == NULL) if (glade_dialog == NULL) {
return FALSE; data->exit_code = -1;
return;
}
glade_xml_signal_autoconnect (glade_dialog); glade_xml_signal_autoconnect (glade_dialog);
dialog = glade_xml_get_widget (glade_dialog, "zenity_entry_dialog"); dialog = glade_xml_get_widget (glade_dialog, "zenity_entry_dialog");
g_signal_connect (G_OBJECT (dialog), "response",
G_CALLBACK (zenity_entry_dialog_response), data);
if (data->dialog_title) if (data->dialog_title)
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
@ -57,6 +65,9 @@ int zenity_entry (ZenityData *data, ZenityEntryData *entry_data)
entry = glade_xml_get_widget (glade_dialog, "zenity_entry_input"); entry = glade_xml_get_widget (glade_dialog, "zenity_entry_input");
if (glade_dialog)
g_object_unref (glade_dialog);
if (entry_data->entry_text) if (entry_data->entry_text)
gtk_entry_set_text (GTK_ENTRY (entry), entry_data->entry_text); gtk_entry_set_text (GTK_ENTRY (entry), entry_data->entry_text);
@ -67,28 +78,28 @@ int zenity_entry (ZenityData *data, ZenityEntryData *entry_data)
gtk_widget_show (dialog); gtk_widget_show (dialog);
gtk_main (); gtk_main ();
if (glade_dialog)
g_object_unref (glade_dialog);
return TRUE;
} }
void static void
zenity_entry_dialog_response (GtkWindow *window, int button, gpointer data) zenity_entry_dialog_response (GtkWidget *widget, int response, gpointer data)
{ {
GError *error = NULL; ZenityData *zen_data = data;
switch (button) { switch (response) {
case GTK_RESPONSE_OK: case GTK_RESPONSE_OK:
zen_data->exit_code = 0;
g_printerr ("%s\n", gtk_entry_get_text (GTK_ENTRY (entry)));
gtk_main_quit (); gtk_main_quit ();
break; break;
case GTK_RESPONSE_CANCEL: case GTK_RESPONSE_CANCEL:
zen_data->exit_code = 1;
gtk_main_quit (); gtk_main_quit ();
break; break;
default: default:
/* Esc dialog */
zen_data->exit_code = 1;
break; break;
} }
} }

View File

@ -25,21 +25,30 @@
#include "zenity.h" #include "zenity.h"
#include "util.h" #include "util.h"
void zenity_fileselection_dialog_response (GtkWindow *window, int button, gpointer data); static void zenity_fileselection_dialog_response (GtkWidget *widget, int response, gpointer data);
int zenity_fileselection (ZenityData *data, ZenityFileData *file_data) void zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
{ {
GladeXML *glade_dialog; GladeXML *glade_dialog;
GtkWidget *dialog; GtkWidget *dialog;
glade_dialog = zenity_util_load_glade_file ("zenity_fileselection_dialog"); glade_dialog = zenity_util_load_glade_file ("zenity_fileselection_dialog");
if (glade_dialog == NULL) if (glade_dialog == NULL) {
return FALSE; data->exit_code = -1;
return;
}
glade_xml_signal_autoconnect (glade_dialog); glade_xml_signal_autoconnect (glade_dialog);
dialog = glade_xml_get_widget (glade_dialog, "zenity_fileselection_dialog"); dialog = glade_xml_get_widget (glade_dialog, "zenity_fileselection_dialog");
if (glade_dialog)
g_object_unref (glade_dialog);
g_signal_connect (G_OBJECT (dialog), "response",
G_CALLBACK (zenity_fileselection_dialog_response), data);
if (data->dialog_title) if (data->dialog_title)
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
@ -53,28 +62,27 @@ int zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
gtk_widget_show (dialog); gtk_widget_show (dialog);
gtk_main (); gtk_main ();
if (glade_dialog)
g_object_unref (glade_dialog);
return TRUE;
} }
void static void
zenity_fileselection_dialog_response (GtkWindow *window, int button, gpointer data) zenity_fileselection_dialog_response (GtkWidget *widget, int response, gpointer data)
{ {
GError *error = NULL; ZenityData *zen_data = data;
switch (button) { switch (response) {
case GTK_RESPONSE_OK: case GTK_RESPONSE_OK:
zen_data->exit_code = 0;
g_printerr ("%s\n", gtk_file_selection_get_filename (GTK_FILE_SELECTION (widget)));
gtk_main_quit (); gtk_main_quit ();
break; break;
case GTK_RESPONSE_CANCEL: case GTK_RESPONSE_CANCEL:
zen_data->exit_code = 1;
gtk_main_quit (); gtk_main_quit ();
break; break;
default: default:
zen_data->exit_code = 1;
break; break;
} }
} }

View File

@ -694,6 +694,7 @@ zenity_init_parsing_options (void) {
results->calendar_data->day = 0; results->calendar_data->day = 0;
results->calendar_data->month = 0; results->calendar_data->month = 0;
results->calendar_data->year = 0; results->calendar_data->year = 0;
results->calendar_data->dialog_text = NULL;
results->progress_data->percentage = -1; results->progress_data->percentage = -1;
results->entry_data->visible = TRUE; results->entry_data->visible = TRUE;
results->tree_data->checkbox = FALSE; results->tree_data->checkbox = FALSE;
@ -750,8 +751,8 @@ main (gint argc, gchar **argv) {
ZenityData *general; ZenityData *general;
ZenityCalendarData *cal_data; ZenityCalendarData *cal_data;
poptContext ctx; poptContext ctx;
char **args; gchar **args;
int nextopt, retval; gint nextopt, retval;
bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR); bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
@ -787,29 +788,29 @@ main (gint argc, gchar **argv) {
switch (results->mode) { switch (results->mode) {
case MODE_CALENDAR: case MODE_CALENDAR:
retval = zenity_calendar (results->data, results->calendar_data); zenity_calendar (results->data, results->calendar_data);
break; break;
case MODE_ENTRY: case MODE_ENTRY:
retval = zenity_entry (results->data, results->entry_data); zenity_entry (results->data, results->entry_data);
break; break;
case MODE_ERROR: case MODE_ERROR:
case MODE_QUESTION: case MODE_QUESTION:
case MODE_WARNING: case MODE_WARNING:
case MODE_INFO: case MODE_INFO:
retval = zenity_msg (results->data, results->msg_data); zenity_msg (results->data, results->msg_data);
break; break;
case MODE_FILE: case MODE_FILE:
retval = zenity_fileselection (results->data, results->file_data); zenity_fileselection (results->data, results->file_data);
break; break;
case MODE_LIST: case MODE_LIST:
results->tree_data->data = poptGetArgs (ctx); results->tree_data->data = poptGetArgs (ctx);
retval = zenity_tree (results->data, results->tree_data); zenity_tree (results->data, results->tree_data);
break; break;
case MODE_PROGRESS: case MODE_PROGRESS:
retval = zenity_progress (results->data, results->progress_data); zenity_progress (results->data, results->progress_data);
break; break;
case MODE_TEXTINFO: case MODE_TEXTINFO:
retval = zenity_text (results->data, results->text_data); zenity_text (results->data, results->text_data);
break; break;
default: default:
g_assert_not_reached (); g_assert_not_reached ();
@ -817,9 +818,10 @@ main (gint argc, gchar **argv) {
exit (-1); exit (-1);
} }
retval = results->data->exit_code;
poptFreeContext(ctx); poptFreeContext(ctx);
zenity_free_parsing_options (); zenity_free_parsing_options ();
exit (0); exit (retval);
} }
static static
@ -945,38 +947,18 @@ void zenity_parse_options_callback (poptContext ctx,
case OPTION_WARNINGTEXT: case OPTION_WARNINGTEXT:
switch (results->mode) { switch (results->mode) {
case MODE_CALENDAR: case MODE_CALENDAR:
if (results->calendar_data->dialog_text != NULL) {
g_printerr (_("--text given twice for the same dialog\n"));
zenity_free_parsing_options ();
exit (-1);
}
results->calendar_data->dialog_text = g_strdup (arg); results->calendar_data->dialog_text = g_strdup (arg);
break; break;
case MODE_ENTRY: case MODE_ENTRY:
if (results->entry_data->dialog_text != NULL) {
g_printerr (_("--text given twice for the same dialog\n"));
zenity_free_parsing_options ();
exit (-1);
}
results->entry_data->dialog_text = g_strdup (arg); results->entry_data->dialog_text = g_strdup (arg);
break; break;
case MODE_ERROR: case MODE_ERROR:
case MODE_QUESTION: case MODE_QUESTION:
case MODE_WARNING: case MODE_WARNING:
case MODE_INFO: case MODE_INFO:
if (results->msg_data->dialog_text != NULL) {
g_printerr (_("--text given twice for the same dialog\n"));
zenity_free_parsing_options ();
exit (-1);
}
results->msg_data->dialog_text = g_strdup (arg); results->msg_data->dialog_text = g_strdup (arg);
break; break;
case MODE_PROGRESS: case MODE_PROGRESS:
if (results->progress_data->dialog_text != NULL) {
g_printerr (_("--text given twice for the same dialog\n"));
zenity_free_parsing_options ();
exit (-1);
}
results->progress_data->dialog_text = g_strdup (arg); results->progress_data->dialog_text = g_strdup (arg);
break; break;
default: default:
@ -1054,19 +1036,9 @@ void zenity_parse_options_callback (poptContext ctx,
case OPTION_TEXTFILE: case OPTION_TEXTFILE:
switch (results->mode) { switch (results->mode) {
case MODE_FILE: case MODE_FILE:
if (results->file_data->uri != NULL) {
g_printerr (_("--filename given twice for the same dialog\n"));
zenity_free_parsing_options ();
exit (-1);
}
results->file_data->uri = g_strdup (arg); results->file_data->uri = g_strdup (arg);
break; break;
case MODE_TEXTINFO: case MODE_TEXTINFO:
if (results->text_data->uri != NULL) {
g_printerr (_("--filename given twice for the same dialog\n"));
zenity_free_parsing_options ();
exit (-1);
}
results->text_data->uri = g_strdup (arg); results->text_data->uri = g_strdup (arg);
break; break;
default: default:
@ -1128,6 +1100,8 @@ void zenity_parse_options_callback (poptContext ctx,
zenity_free_parsing_options (); zenity_free_parsing_options ();
exit (-1); exit (-1);
} }
g_print ("This does nothing at the moment\n");
exit (0);
break; break;
case OPTION_VERSION: case OPTION_VERSION:
if (results->mode != MODE_LAST) { if (results->mode != MODE_LAST) {
@ -1136,6 +1110,7 @@ void zenity_parse_options_callback (poptContext ctx,
exit (-1); exit (-1);
} }
g_print ("%s\n", VERSION); g_print ("%s\n", VERSION);
exit (0);
break; break;
default: default:
g_warning ("Invalid option %s", arg); g_warning ("Invalid option %s", arg);

View File

@ -25,9 +25,10 @@
#include "zenity.h" #include "zenity.h"
#include "util.h" #include "util.h"
void zenity_msg_dialog_response (GtkWindow *window, int button, gpointer data); static void zenity_msg_dialog_response (GtkWidget *widget, int response, gpointer data);
int zenity_msg (ZenityData *data, ZenityMsgData *msg_data) void
zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
{ {
GladeXML *glade_dialog; GladeXML *glade_dialog;
GtkWidget *dialog; GtkWidget *dialog;
@ -64,8 +65,16 @@ int zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
break; break;
} }
if (glade_dialog == NULL) if (glade_dialog)
return FALSE; g_object_unref (glade_dialog);
g_signal_connect (G_OBJECT (dialog), "response",
G_CALLBACK (zenity_msg_dialog_response), data);
if (glade_dialog == NULL) {
data->exit_code = -1;
return;
}
glade_xml_signal_autoconnect (glade_dialog); glade_xml_signal_autoconnect (glade_dialog);
@ -99,28 +108,26 @@ int zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
gtk_widget_show (dialog); gtk_widget_show (dialog);
gtk_main (); gtk_main ();
if (glade_dialog)
g_object_unref (glade_dialog);
return TRUE;
} }
void static void
zenity_msg_dialog_response (GtkWindow *window, int button, gpointer data) zenity_msg_dialog_response (GtkWidget *widget, int response, gpointer data)
{ {
GError *error = NULL; ZenityData *zen_data = data;
switch (button) { switch (response) {
case GTK_RESPONSE_OK: case GTK_RESPONSE_OK:
zen_data->exit_code = 0;
gtk_main_quit (); gtk_main_quit ();
break; break;
case GTK_RESPONSE_CANCEL: case GTK_RESPONSE_CANCEL:
zen_data->exit_code = 1;
gtk_main_quit (); gtk_main_quit ();
break; break;
default: default:
zen_data->exit_code = 1;
break; break;
} }
} }

View File

@ -32,7 +32,7 @@ static GladeXML *glade_dialog;
static gboolean zenity_progress_pulsate_bar (GIOChannel *giochannel, GIOCondition condition, gpointer data); static gboolean zenity_progress_pulsate_bar (GIOChannel *giochannel, GIOCondition condition, gpointer data);
static gboolean zenity_progress_increment_bar (GIOChannel *giochannel, GIOCondition condition, gpointer data); static gboolean zenity_progress_increment_bar (GIOChannel *giochannel, GIOCondition condition, gpointer data);
void zenity_progress_dialog_response (GtkWindow *window, int button, gpointer data); static void zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data);
gint gint
zenity_progress_timeout (gpointer data) zenity_progress_timeout (gpointer data)
@ -41,7 +41,8 @@ zenity_progress_timeout (gpointer data)
return TRUE; return TRUE;
} }
int zenity_progress (ZenityData *data, ZenityProgressData *progress_data) void
zenity_progress (ZenityData *data, ZenityProgressData *progress_data)
{ {
GtkWidget *dialog; GtkWidget *dialog;
GtkWidget *text; GtkWidget *text;
@ -51,12 +52,17 @@ int zenity_progress (ZenityData *data, ZenityProgressData *progress_data)
glade_dialog = zenity_util_load_glade_file ("zenity_progress_dialog"); glade_dialog = zenity_util_load_glade_file ("zenity_progress_dialog");
if (glade_dialog == NULL) if (glade_dialog == NULL) {
return FALSE; data->exit_code = -1;
return;
}
glade_xml_signal_autoconnect (glade_dialog); glade_xml_signal_autoconnect (glade_dialog);
dialog = glade_xml_get_widget (glade_dialog, "zenity_progress_dialog"); dialog = glade_xml_get_widget (glade_dialog, "zenity_progress_dialog");
g_signal_connect (G_OBJECT (dialog), "response",
G_CALLBACK (zenity_progress_dialog_response), data);
if (data->dialog_title) if (data->dialog_title)
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
@ -72,6 +78,9 @@ int zenity_progress (ZenityData *data, ZenityProgressData *progress_data)
progress_bar = glade_xml_get_widget (glade_dialog, "zenity_progress_bar"); progress_bar = glade_xml_get_widget (glade_dialog, "zenity_progress_bar");
if (glade_dialog)
g_object_unref (glade_dialog);
giochannel = g_io_channel_unix_new (0); giochannel = g_io_channel_unix_new (0);
if (progress_data->pulsate != TRUE && progress_data->percentage > -1) { if (progress_data->pulsate != TRUE && progress_data->percentage > -1) {
@ -85,11 +94,6 @@ int zenity_progress (ZenityData *data, ZenityProgressData *progress_data)
g_io_channel_unref (giochannel); g_io_channel_unref (giochannel);
gtk_widget_show (dialog); gtk_widget_show (dialog);
gtk_main (); gtk_main ();
if (glade_dialog)
g_object_unref (glade_dialog);
return TRUE;
} }
static gboolean static gboolean
@ -119,21 +123,24 @@ zenity_progress_increment_bar (GIOChannel *giochannel, GIOCondition condition, g
/* FIXME: Do nothing at the moment */ /* FIXME: Do nothing at the moment */
} }
void static void
zenity_progress_dialog_response (GtkWindow *window, int button, gpointer data) zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data)
{ {
GError *error = NULL; ZenityData *zen_data = data;
switch (button) { switch (response) {
case GTK_RESPONSE_OK: case GTK_RESPONSE_OK:
zen_data->exit_code = 0;
gtk_main_quit (); gtk_main_quit ();
break; break;
case GTK_RESPONSE_CANCEL: case GTK_RESPONSE_CANCEL:
zen_data->exit_code = 1;
gtk_main_quit (); gtk_main_quit ();
break; break;
default: default:
zen_data->exit_code = 1;
break; break;
} }
} }

View File

@ -25,9 +25,10 @@
#include "zenity.h" #include "zenity.h"
#include "util.h" #include "util.h"
void zenity_text_dialog_response (GtkWindow *window, int button, gpointer data); static void zenity_text_dialog_response (GtkWidget *widget, int response, gpointer data);
int zenity_text (ZenityData *data, ZenityTextData *text_data) void
zenity_text (ZenityData *data, ZenityTextData *text_data)
{ {
GladeXML *glade_dialog = NULL; GladeXML *glade_dialog = NULL;
GtkWidget *dialog; GtkWidget *dialog;
@ -36,13 +37,21 @@ int zenity_text (ZenityData *data, ZenityTextData *text_data)
glade_dialog = zenity_util_load_glade_file ("zenity_text_dialog"); glade_dialog = zenity_util_load_glade_file ("zenity_text_dialog");
if (glade_dialog == NULL) if (glade_dialog == NULL) {
return FALSE; data->exit_code = -1;
return;
}
glade_xml_signal_autoconnect (glade_dialog); glade_xml_signal_autoconnect (glade_dialog);
dialog = glade_xml_get_widget (glade_dialog, "zenity_text_dialog"); dialog = glade_xml_get_widget (glade_dialog, "zenity_text_dialog");
if (glade_dialog)
g_object_unref (glade_dialog);
g_signal_connect (G_OBJECT (dialog), "response",
G_CALLBACK (zenity_text_dialog_response), data);
if (data->dialog_title) if (data->dialog_title)
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
@ -60,24 +69,21 @@ int zenity_text (ZenityData *data, ZenityTextData *text_data)
gtk_widget_show (dialog); gtk_widget_show (dialog);
gtk_main (); gtk_main ();
if (glade_dialog)
g_object_unref (glade_dialog);
return TRUE;
} }
void static void
zenity_text_dialog_response (GtkWindow *window, int button, gpointer data) zenity_text_dialog_response (GtkWidget *widget, int response, gpointer data)
{ {
GError *error = NULL; ZenityData *zen_data = data;
switch (button) { switch (response) {
case GTK_RESPONSE_CLOSE: case GTK_RESPONSE_CLOSE:
zen_data->exit_code = 0;
gtk_main_quit (); gtk_main_quit ();
break; break;
default: default:
zen_data->exit_code = 1;
break; break;
} }
} }

View File

@ -31,7 +31,7 @@
static GladeXML *glade_dialog; static GladeXML *glade_dialog;
void zenity_tree_dialog_response (GtkWindow *window, int button, gpointer data); static void zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data);
static void static void
zenity_tree_toggled_callback (GtkCellRendererToggle *cell, gchar *path_string, gpointer data) zenity_tree_toggled_callback (GtkCellRendererToggle *cell, gchar *path_string, gpointer data)
@ -104,7 +104,7 @@ zenity_tree_fill_entries (GtkTreeView *tree_view, const gchar **args, gint n_col
} }
} }
int void
zenity_tree (ZenityData *data, ZenityTreeData *tree_data) zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
{ {
GtkWidget *dialog; GtkWidget *dialog;
@ -118,13 +118,18 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
glade_dialog = zenity_util_load_glade_file ("zenity_tree_dialog"); glade_dialog = zenity_util_load_glade_file ("zenity_tree_dialog");
if (glade_dialog == NULL) if (glade_dialog == NULL) {
return FALSE; data->exit_code = -1;
return;
}
glade_xml_signal_autoconnect (glade_dialog); glade_xml_signal_autoconnect (glade_dialog);
dialog = glade_xml_get_widget (glade_dialog, "zenity_tree_dialog"); dialog = glade_xml_get_widget (glade_dialog, "zenity_tree_dialog");
g_signal_connect (G_OBJECT (dialog), "response",
G_CALLBACK (zenity_tree_dialog_response), data);
if (data->dialog_title) if (data->dialog_title)
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
@ -209,25 +214,26 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
if (glade_dialog) if (glade_dialog)
g_object_unref (glade_dialog); g_object_unref (glade_dialog);
return TRUE;
} }
void static void
zenity_tree_dialog_response (GtkWindow *window, int button, gpointer data) zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data)
{ {
GError *error = NULL; ZenityData *zen_data = data;
switch (button) { switch (response) {
case GTK_RESPONSE_OK: case GTK_RESPONSE_OK:
zen_data->exit_code = 0;
gtk_main_quit (); gtk_main_quit ();
break; break;
case GTK_RESPONSE_CANCEL: case GTK_RESPONSE_CANCEL:
zen_data->exit_code = 1;
gtk_main_quit (); gtk_main_quit ();
break; break;
default: default:
zen_data->exit_code = 1;
break; break;
} }
} }

View File

@ -12,7 +12,6 @@
<property name="resizable">False</property> <property name="resizable">False</property>
<property name="destroy_with_parent">False</property> <property name="destroy_with_parent">False</property>
<property name="has_separator">True</property> <property name="has_separator">True</property>
<signal name="response" handler="zenity_calendar_dialog_response" last_modification_time="Fri, 27 Dec 2002 19:07:38 GMT"/>
<signal name="destroy" handler="gtk_main_quit" last_modification_time="Fri, 27 Dec 2002 19:08:11 GMT"/> <signal name="destroy" handler="gtk_main_quit" last_modification_time="Fri, 27 Dec 2002 19:08:11 GMT"/>
<child internal-child="vbox"> <child internal-child="vbox">
@ -157,7 +156,6 @@
<property name="resizable">False</property> <property name="resizable">False</property>
<property name="destroy_with_parent">False</property> <property name="destroy_with_parent">False</property>
<property name="has_separator">True</property> <property name="has_separator">True</property>
<signal name="response" handler="zenity_msg_dialog_response" last_modification_time="Fri, 27 Dec 2002 23:23:57 GMT"/>
<signal name="destroy" handler="gtk_main_quit" last_modification_time="Fri, 27 Dec 2002 23:24:20 GMT"/> <signal name="destroy" handler="gtk_main_quit" last_modification_time="Fri, 27 Dec 2002 23:24:20 GMT"/>
<child internal-child="vbox"> <child internal-child="vbox">
@ -269,7 +267,6 @@
<property name="resizable">False</property> <property name="resizable">False</property>
<property name="destroy_with_parent">False</property> <property name="destroy_with_parent">False</property>
<property name="show_fileops">True</property> <property name="show_fileops">True</property>
<signal name="response" handler="zenity_fileselection_dialog_response" last_modification_time="Sat, 28 Dec 2002 11:48:14 GMT"/>
<signal name="destroy" handler="gtk_main_quit" last_modification_time="Sat, 28 Dec 2002 11:48:27 GMT"/> <signal name="destroy" handler="gtk_main_quit" last_modification_time="Sat, 28 Dec 2002 11:48:27 GMT"/>
<child internal-child="cancel_button"> <child internal-child="cancel_button">
@ -301,7 +298,6 @@
<property name="resizable">False</property> <property name="resizable">False</property>
<property name="destroy_with_parent">False</property> <property name="destroy_with_parent">False</property>
<property name="has_separator">True</property> <property name="has_separator">True</property>
<signal name="response" handler="zenity_msg_dialog_response" last_modification_time="Sat, 28 Dec 2002 12:03:43 GMT"/>
<signal name="destroy" handler="gtk_main_quit" last_modification_time="Sat, 28 Dec 2002 12:03:54 GMT"/> <signal name="destroy" handler="gtk_main_quit" last_modification_time="Sat, 28 Dec 2002 12:03:54 GMT"/>
<child internal-child="vbox"> <child internal-child="vbox">
@ -412,7 +408,6 @@
<property name="resizable">False</property> <property name="resizable">False</property>
<property name="destroy_with_parent">False</property> <property name="destroy_with_parent">False</property>
<property name="has_separator">True</property> <property name="has_separator">True</property>
<signal name="response" handler="zenity_entry_dialog_response" last_modification_time="Sat, 28 Dec 2002 12:15:25 GMT"/>
<signal name="destroy" handler="gtk_main_quit" last_modification_time="Sat, 28 Dec 2002 12:15:37 GMT"/> <signal name="destroy" handler="gtk_main_quit" last_modification_time="Sat, 28 Dec 2002 12:15:37 GMT"/>
<child internal-child="vbox"> <child internal-child="vbox">
@ -543,7 +538,6 @@
<property name="resizable">True</property> <property name="resizable">True</property>
<property name="destroy_with_parent">False</property> <property name="destroy_with_parent">False</property>
<property name="has_separator">True</property> <property name="has_separator">True</property>
<signal name="response" handler="zenity_text_dialog_response" last_modification_time="Sat, 28 Dec 2002 12:34:28 GMT"/>
<signal name="destroy" handler="gtk_main_quit" last_modification_time="Sat, 28 Dec 2002 12:34:38 GMT"/> <signal name="destroy" handler="gtk_main_quit" last_modification_time="Sat, 28 Dec 2002 12:34:38 GMT"/>
<child internal-child="vbox"> <child internal-child="vbox">
@ -637,7 +631,6 @@
<property name="resizable">False</property> <property name="resizable">False</property>
<property name="destroy_with_parent">False</property> <property name="destroy_with_parent">False</property>
<property name="has_separator">True</property> <property name="has_separator">True</property>
<signal name="response" handler="zenity_progress_dialog_response" last_modification_time="Sat, 28 Dec 2002 14:46:19 GMT"/>
<signal name="destroy" handler="gtk_main_quit" last_modification_time="Sat, 28 Dec 2002 14:46:29 GMT"/> <signal name="destroy" handler="gtk_main_quit" last_modification_time="Sat, 28 Dec 2002 14:46:29 GMT"/>
<child internal-child="vbox"> <child internal-child="vbox">
@ -760,7 +753,6 @@
<property name="resizable">False</property> <property name="resizable">False</property>
<property name="destroy_with_parent">False</property> <property name="destroy_with_parent">False</property>
<property name="has_separator">True</property> <property name="has_separator">True</property>
<signal name="response" handler="zenity_msg_dialog_response" last_modification_time="Sat, 28 Dec 2002 15:05:31 GMT"/>
<signal name="destroy" handler="gtk_main_quit" last_modification_time="Sat, 28 Dec 2002 15:05:42 GMT"/> <signal name="destroy" handler="gtk_main_quit" last_modification_time="Sat, 28 Dec 2002 15:05:42 GMT"/>
<child internal-child="vbox"> <child internal-child="vbox">
@ -873,7 +865,6 @@
<property name="resizable">True</property> <property name="resizable">True</property>
<property name="destroy_with_parent">False</property> <property name="destroy_with_parent">False</property>
<property name="has_separator">True</property> <property name="has_separator">True</property>
<signal name="response" handler="zenity_tree_dialog_response" last_modification_time="Sat, 28 Dec 2002 22:18:54 GMT"/>
<signal name="destroy" handler="gtk_main_quit" last_modification_time="Sat, 28 Dec 2002 22:19:04 GMT"/> <signal name="destroy" handler="gtk_main_quit" last_modification_time="Sat, 28 Dec 2002 22:19:04 GMT"/>
<child internal-child="vbox"> <child internal-child="vbox">
@ -1007,7 +998,6 @@
<property name="resizable">False</property> <property name="resizable">False</property>
<property name="destroy_with_parent">False</property> <property name="destroy_with_parent">False</property>
<property name="has_separator">True</property> <property name="has_separator">True</property>
<signal name="response" handler="zenity_msg_dialog_response" last_modification_time="Sat, 28 Dec 2002 15:05:31 GMT"/>
<signal name="destroy" handler="gtk_main_quit" last_modification_time="Sat, 28 Dec 2002 15:05:42 GMT"/> <signal name="destroy" handler="gtk_main_quit" last_modification_time="Sat, 28 Dec 2002 15:05:42 GMT"/>
<child internal-child="vbox"> <child internal-child="vbox">

View File

@ -26,6 +26,7 @@ G_BEGIN_DECLS
typedef struct { typedef struct {
gchar *dialog_title; gchar *dialog_title;
gchar *window_icon; gchar *window_icon;
gint exit_code;
} ZenityData; } ZenityData;
typedef struct { typedef struct {
@ -76,19 +77,19 @@ typedef struct {
const gchar **data; const gchar **data;
} ZenityTreeData; } ZenityTreeData;
int zenity_calendar (ZenityData *data, void zenity_calendar (ZenityData *data,
ZenityCalendarData *calendar_data); ZenityCalendarData *calendar_data);
int zenity_msg (ZenityData *data, void zenity_msg (ZenityData *data,
ZenityMsgData *msg_data); ZenityMsgData *msg_data);
int zenity_fileselection (ZenityData *data, void zenity_fileselection (ZenityData *data,
ZenityFileData *file_data); ZenityFileData *file_data);
int zenity_entry (ZenityData *data, void zenity_entry (ZenityData *data,
ZenityEntryData *entry_data); ZenityEntryData *entry_data);
int zenity_progress (ZenityData *data, void zenity_progress (ZenityData *data,
ZenityProgressData *progress_data); ZenityProgressData *progress_data);
int zenity_text (ZenityData *data, void zenity_text (ZenityData *data,
ZenityTextData *text_data); ZenityTextData *text_data);
int zenity_tree (ZenityData *data, void zenity_tree (ZenityData *data,
ZenityTreeData *tree_data); ZenityTreeData *tree_data);
G_END_DECLS G_END_DECLS