Improve error handling... a lot.
2003-01-06 Glynn Foster <glynn.foster@sun.com> * src/calendar.c, src/main.c, src/progress.c, src/tree.c, src/zenity.h: Improve error handling... a lot.
This commit is contained in:
parent
d88a32f1f5
commit
a8c3006035
@ -1,3 +1,9 @@
|
|||||||
|
2003-01-06 Glynn Foster <glynn.foster@sun.com>
|
||||||
|
|
||||||
|
* src/calendar.c, src/main.c, src/progress.c,
|
||||||
|
src/tree.c, src/zenity.h: Improve error handling...
|
||||||
|
a lot.
|
||||||
|
|
||||||
2003-01-06 Glynn Foster <glynn.foster@sun.com>
|
2003-01-06 Glynn Foster <glynn.foster@sun.com>
|
||||||
|
|
||||||
* src/main.c, src/tree.c, src/zenity.h: Finish off
|
* src/main.c, src/tree.c, src/zenity.h: Finish off
|
||||||
|
@ -55,9 +55,9 @@ 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 (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, cal_data->year);
|
||||||
if (cal_data->day)
|
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);
|
||||||
|
170
src/main.c
170
src/main.c
@ -680,6 +680,7 @@ zenity_init_parsing_options (void) {
|
|||||||
results = g_new0 (ZenityParsingOptions, 1);
|
results = g_new0 (ZenityParsingOptions, 1);
|
||||||
|
|
||||||
/* Initialize the various dialog structures */
|
/* Initialize the various dialog structures */
|
||||||
|
results->mode = MODE_LAST;
|
||||||
results->data = g_new0 (ZenityData, 1);
|
results->data = g_new0 (ZenityData, 1);
|
||||||
results->calendar_data = g_new0 (ZenityCalendarData, 1);
|
results->calendar_data = g_new0 (ZenityCalendarData, 1);
|
||||||
results->msg_data = g_new0 (ZenityMsgData, 1);
|
results->msg_data = g_new0 (ZenityMsgData, 1);
|
||||||
@ -690,6 +691,10 @@ zenity_init_parsing_options (void) {
|
|||||||
results->tree_data = g_new0 (ZenityTreeData, 1);
|
results->tree_data = g_new0 (ZenityTreeData, 1);
|
||||||
|
|
||||||
/* Give some sensible defaults */
|
/* Give some sensible defaults */
|
||||||
|
results->calendar_data->day = 0;
|
||||||
|
results->calendar_data->month = 0;
|
||||||
|
results->calendar_data->year = 0;
|
||||||
|
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;
|
||||||
results->tree_data->radiobox = FALSE;
|
results->tree_data->radiobox = FALSE;
|
||||||
@ -760,6 +765,11 @@ main (gint argc, gchar **argv) {
|
|||||||
while((nextopt = poptGetNextOpt(ctx)) > 0)
|
while((nextopt = poptGetNextOpt(ctx)) > 0)
|
||||||
/*nothing*/;
|
/*nothing*/;
|
||||||
|
|
||||||
|
if (nextopt != -1) {
|
||||||
|
g_printerr (_("%s in an invalid option for this dialog\n"), poptBadOption (ctx, 0));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
gtk_init (&argc, &argv);
|
gtk_init (&argc, &argv);
|
||||||
|
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
@ -807,7 +817,6 @@ void zenity_parse_options_callback (poptContext ctx,
|
|||||||
const char *arg,
|
const char *arg,
|
||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
gint i = 0;
|
|
||||||
if (reason == POPT_CALLBACK_REASON_POST) {
|
if (reason == POPT_CALLBACK_REASON_POST) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -817,43 +826,91 @@ void zenity_parse_options_callback (poptContext ctx,
|
|||||||
switch (opt->val & POPT_ARG_MASK) {
|
switch (opt->val & POPT_ARG_MASK) {
|
||||||
|
|
||||||
case OPTION_CALENDAR:
|
case OPTION_CALENDAR:
|
||||||
|
if (results->mode != MODE_LAST) {
|
||||||
|
g_printerr (_("Two or more dialog options specified\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
results->mode = MODE_CALENDAR;
|
results->mode = MODE_CALENDAR;
|
||||||
break;
|
break;
|
||||||
case OPTION_ENTRY:
|
case OPTION_ENTRY:
|
||||||
|
if (results->mode != MODE_LAST) {
|
||||||
|
g_printerr (_("Two or more dialog options specified\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
results->mode = MODE_ENTRY;
|
results->mode = MODE_ENTRY;
|
||||||
break;
|
break;
|
||||||
case OPTION_ERROR:
|
case OPTION_ERROR:
|
||||||
|
if (results->mode != MODE_LAST) {
|
||||||
|
g_printerr (_("Two or more dialog options specified\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
results->mode = MODE_ERROR;
|
results->mode = MODE_ERROR;
|
||||||
results->msg_data->mode = ZENITY_MSG_ERROR;
|
results->msg_data->mode = ZENITY_MSG_ERROR;
|
||||||
break;
|
break;
|
||||||
case OPTION_INFO:
|
case OPTION_INFO:
|
||||||
|
if (results->mode != MODE_LAST) {
|
||||||
|
g_printerr (_("Two or more dialog options specified\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
results->mode = MODE_INFO;
|
results->mode = MODE_INFO;
|
||||||
results->msg_data->mode = ZENITY_MSG_INFO;
|
results->msg_data->mode = ZENITY_MSG_INFO;
|
||||||
break;
|
break;
|
||||||
case OPTION_FILE:
|
case OPTION_FILE:
|
||||||
|
if (results->mode != MODE_LAST) {
|
||||||
|
g_printerr (_("Two or more dialog options specified\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
results->mode = MODE_FILE;
|
results->mode = MODE_FILE;
|
||||||
break;
|
break;
|
||||||
case OPTION_LIST:
|
case OPTION_LIST:
|
||||||
|
if (results->mode != MODE_LAST) {
|
||||||
|
g_printerr (_("Two or more dialog options specified\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
results->mode = MODE_LIST;
|
results->mode = MODE_LIST;
|
||||||
break;
|
break;
|
||||||
case OPTION_PROGRESS:
|
case OPTION_PROGRESS:
|
||||||
|
if (results->mode != MODE_LAST) {
|
||||||
|
g_printerr (_("Two or more dialog options specified\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
results->mode = MODE_PROGRESS;
|
results->mode = MODE_PROGRESS;
|
||||||
break;
|
break;
|
||||||
case OPTION_QUESTION:
|
case OPTION_QUESTION:
|
||||||
|
if (results->mode != MODE_LAST) {
|
||||||
|
g_printerr (_("Two or more dialog options specified\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
results->mode = MODE_QUESTION;
|
results->mode = MODE_QUESTION;
|
||||||
results->msg_data->mode = ZENITY_MSG_QUESTION;
|
results->msg_data->mode = ZENITY_MSG_QUESTION;
|
||||||
break;
|
break;
|
||||||
case OPTION_TEXTINFO:
|
case OPTION_TEXTINFO:
|
||||||
|
if (results->mode != MODE_LAST) {
|
||||||
|
g_printerr (_("Two or more dialog options specified\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
results->mode = MODE_TEXTINFO;
|
results->mode = MODE_TEXTINFO;
|
||||||
break;
|
break;
|
||||||
case OPTION_WARNING:
|
case OPTION_WARNING:
|
||||||
|
if (results->mode != MODE_LAST) {
|
||||||
|
g_printerr (_("Two or more dialog options specified\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
results->mode = MODE_WARNING;
|
results->mode = MODE_WARNING;
|
||||||
results->msg_data->mode = ZENITY_MSG_WARNING;
|
results->msg_data->mode = ZENITY_MSG_WARNING;
|
||||||
break;
|
break;
|
||||||
case OPTION_TITLE:
|
case OPTION_TITLE:
|
||||||
|
if (results->data->dialog_title != NULL) {
|
||||||
|
g_printerr (_("--title given twice for the same dialog\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
results->data->dialog_title = g_strdup (arg);
|
results->data->dialog_title = g_strdup (arg);
|
||||||
break;
|
break;
|
||||||
case OPTION_ICON:
|
case OPTION_ICON:
|
||||||
|
if (results->data->window_icon != NULL) {
|
||||||
|
g_printerr (_("--window-icon given twice for the same dialog\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
results->data->window_icon = g_strdup (arg);
|
results->data->window_icon = g_strdup (arg);
|
||||||
break;
|
break;
|
||||||
case OPTION_CALENDARTEXT:
|
case OPTION_CALENDARTEXT:
|
||||||
@ -864,72 +921,173 @@ 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"));
|
||||||
|
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"));
|
||||||
|
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"));
|
||||||
|
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"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
results->progress_data->dialog_text = g_strdup (arg);
|
results->progress_data->dialog_text = g_strdup (arg);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
g_printerr (_("--text is not supported for this dialog\n"));
|
||||||
|
exit (1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case OPTION_DAY:
|
case OPTION_DAY:
|
||||||
|
if (results->mode != MODE_CALENDAR) {
|
||||||
|
g_printerr (_("--day is not supported for this dialog\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
if (results->calendar_data->day > 0) {
|
||||||
|
g_printerr (_("--day given twice for the same dialog\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
results->calendar_data->day = atoi (arg);
|
results->calendar_data->day = atoi (arg);
|
||||||
break;
|
break;
|
||||||
case OPTION_MONTH:
|
case OPTION_MONTH:
|
||||||
|
if (results->mode != MODE_CALENDAR) {
|
||||||
|
g_printerr (_("--month is not supported for this dialog\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
if (results->calendar_data->month > 0) {
|
||||||
|
g_printerr (_("--month given twice for the same dialog\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
results->calendar_data->month = atoi (arg);
|
results->calendar_data->month = atoi (arg);
|
||||||
break;
|
break;
|
||||||
case OPTION_YEAR:
|
case OPTION_YEAR:
|
||||||
|
if (results->mode != MODE_CALENDAR) {
|
||||||
|
g_printerr (_("--year is not supported for this dialog\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
if (results->calendar_data->year > 0) {
|
||||||
|
g_printerr (_("--year given twice for the same dialog\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
results->calendar_data->year = atoi (arg);
|
results->calendar_data->year = atoi (arg);
|
||||||
break;
|
break;
|
||||||
case OPTION_INPUTTEXT:
|
case OPTION_INPUTTEXT:
|
||||||
|
if (results->mode != MODE_ENTRY) {
|
||||||
|
g_printerr (_("--entry-text is not supported for this dialog\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
if (results->entry_data->entry_text != NULL) {
|
||||||
|
g_printerr (_("--entry-text given twice for the same dialog\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
results->entry_data->entry_text = g_strdup (arg);
|
results->entry_data->entry_text = g_strdup (arg);
|
||||||
break;
|
break;
|
||||||
case OPTION_HIDETEXT:
|
case OPTION_HIDETEXT:
|
||||||
|
if (results->mode != MODE_ENTRY) {
|
||||||
|
g_printerr (_("--hide-text is not supported for this dialog\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
if (results->entry_data->visible == FALSE) {
|
||||||
|
g_printerr (_("--hide-text given twice for the same dialog\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
results->entry_data->visible = FALSE;
|
results->entry_data->visible = FALSE;
|
||||||
break;
|
break;
|
||||||
case OPTION_FILENAME:
|
case OPTION_FILENAME:
|
||||||
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"));
|
||||||
|
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"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
results->text_data->uri = g_strdup (arg);
|
results->text_data->uri = g_strdup (arg);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
g_printerr (_("--filename is not supported for this dialog\n"));
|
||||||
|
exit (1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case OPTION_COLUMN:
|
case OPTION_COLUMN:
|
||||||
|
if (results->mode != MODE_LIST) {
|
||||||
|
g_printerr (_("--column is not supported for this dialog\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
results->tree_data->columns = g_slist_append (results->tree_data->columns, g_strdup (arg));
|
results->tree_data->columns = g_slist_append (results->tree_data->columns, g_strdup (arg));
|
||||||
break;
|
break;
|
||||||
case OPTION_CHECKLIST:
|
case OPTION_CHECKLIST:
|
||||||
|
if (results->mode != MODE_LIST) {
|
||||||
|
g_printerr (_("--checkbox is not supported for this dialog\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
if (results->tree_data->checkbox == TRUE) {
|
||||||
|
g_printerr (_("--checkbox given twice for the same dialog\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
results->tree_data->checkbox = TRUE;
|
results->tree_data->checkbox = TRUE;
|
||||||
break;
|
break;
|
||||||
case OPTION_RADIOLIST:
|
case OPTION_RADIOLIST:
|
||||||
|
if (results->mode != MODE_LIST) {
|
||||||
|
g_printerr (_("--radiobox is not supported for this dialog\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
if (results->tree_data->radiobox == TRUE) {
|
||||||
|
g_printerr (_("--radiobox given twice for the same dialog\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
results->tree_data->radiobox = TRUE;
|
results->tree_data->radiobox = TRUE;
|
||||||
break;
|
break;
|
||||||
case OPTION_PERCENTAGE:
|
case OPTION_PERCENTAGE:
|
||||||
|
if (results->mode != MODE_PROGRESS) {
|
||||||
|
g_printerr (_("--percentage is not supported for this dialog\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
if (results->progress_data->percentage > -1) {
|
||||||
|
g_printerr (_("--percentage given twice for the same dialog\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
results->progress_data->percentage = atoi (arg);
|
results->progress_data->percentage = atoi (arg);
|
||||||
break;
|
break;
|
||||||
case OPTION_ABOUT:
|
case OPTION_ABOUT:
|
||||||
results->mode = MODE_LAST;
|
if (results->mode != MODE_LAST) {
|
||||||
|
g_printerr (_("Two or more dialog options specified\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case OPTION_VERSION:
|
case OPTION_VERSION:
|
||||||
results->mode = MODE_LAST;
|
if (results->mode != MODE_LAST) {
|
||||||
|
g_printerr (_("Two or more dialog options specified\n"));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
g_print ("%s\n", VERSION);
|
g_print ("%s\n", VERSION);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
g_warning ("Invalid option %s", arg);
|
||||||
|
exit (1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ int zenity_progress (ZenityData *data, ZenityProgressData *progress_data)
|
|||||||
|
|
||||||
giochannel = g_io_channel_unix_new (0);
|
giochannel = g_io_channel_unix_new (0);
|
||||||
|
|
||||||
if (progress_data->pulsate != TRUE) {
|
if (progress_data->pulsate != TRUE && progress_data->percentage > -1) {
|
||||||
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), progress_data->percentage/100.0);
|
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), progress_data->percentage/100.0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -63,7 +63,7 @@ count_rows_foreach (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, g
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_tree_fill_entries (GtkTreeView *tree_view, gchar **args, gint n_columns, gboolean toggles)
|
zenity_tree_fill_entries (GtkTreeView *tree_view, const gchar **args, gint n_columns, gboolean toggles)
|
||||||
{
|
{
|
||||||
GtkTreeModel *model;
|
GtkTreeModel *model;
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
|
@ -73,7 +73,7 @@ typedef struct {
|
|||||||
GSList *columns;
|
GSList *columns;
|
||||||
gboolean checkbox;
|
gboolean checkbox;
|
||||||
gboolean radiobox;
|
gboolean radiobox;
|
||||||
gchar **data;
|
const gchar **data;
|
||||||
} ZenityTreeData;
|
} ZenityTreeData;
|
||||||
|
|
||||||
int zenity_calendar (ZenityData *data,
|
int zenity_calendar (ZenityData *data,
|
||||||
|
Reference in New Issue
Block a user