summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--TODO2
-rw-r--r--src/main.c17
-rw-r--r--src/tree.c65
4 files changed, 79 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index 0721404..0439581 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2003-01-13 Glynn Foster <glynn.foster@sun.com>
+
+ * src/main.c: Improve error handling.
+ * src/tree.c: Make --list actually return something
+ useful, although I still need to actually seperate
+ things out so it's actually decipherable.
+
+ * TODO: Update accordingly.
+
2003-01-09 Glynn Foster <glynn.foster@sun.com>
* src/calendar.c: Fix up the date string, although I guess
diff --git a/TODO b/TODO
index 0d3a96d..cf51c43 100644
--- a/TODO
+++ b/TODO
@@ -1,5 +1,3 @@
-* Implement return values for all dialogs
- * All done, except for list view
* Add some accessibility I guess
* Find some nice default window icons
* Implement about box
diff --git a/src/main.c b/src/main.c
index 53cfc99..03f6d4c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -842,6 +842,9 @@ void zenity_parse_options_callback (poptContext ctx,
const char *arg,
void *data)
{
+ static gboolean parse_option_text = FALSE;
+ static gboolean parse_option_file = FALSE;
+
if (reason == POPT_CALLBACK_REASON_POST) {
return;
}
@@ -956,6 +959,12 @@ void zenity_parse_options_callback (poptContext ctx,
case OPTION_QUESTIONTEXT:
case OPTION_PROGRESSTEXT:
case OPTION_WARNINGTEXT:
+ if (parse_option_text == TRUE) {
+ g_printerr (_("--text given twice for the same dialog\n"));
+ zenity_free_parsing_options ();
+ exit (-1);
+ }
+
switch (results->mode) {
case MODE_CALENDAR:
results->calendar_data->dialog_text = g_strdup (arg);
@@ -977,6 +986,7 @@ void zenity_parse_options_callback (poptContext ctx,
zenity_free_parsing_options ();
exit (-1);
}
+ parse_option_text = TRUE;
break;
case OPTION_DAY:
if (results->mode != MODE_CALENDAR) {
@@ -1045,6 +1055,12 @@ void zenity_parse_options_callback (poptContext ctx,
break;
case OPTION_FILENAME:
case OPTION_TEXTFILE:
+ if (parse_option_file == TRUE) {
+ g_printerr (_("--filename given twice for the same dialog\n"));
+ zenity_free_parsing_options ();
+ exit (-1);
+ }
+
switch (results->mode) {
case MODE_FILE:
results->file_data->uri = g_strdup (arg);
@@ -1057,6 +1073,7 @@ void zenity_parse_options_callback (poptContext ctx,
zenity_free_parsing_options ();
exit (-1);
}
+ parse_option_file = TRUE;
break;
case OPTION_COLUMN:
if (results->mode != MODE_LIST) {
diff --git a/src/tree.c b/src/tree.c
index 401fbe0..2b31002 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -53,15 +53,6 @@ zenity_tree_toggled_callback (GtkCellRendererToggle *cell, gchar *path_string, g
gtk_tree_path_free (path);
}
-static gboolean
-count_rows_foreach (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
-{
- gint *rows = data;
-
- (*rows)++;
- return FALSE;
-}
-
static void
zenity_tree_fill_entries (GtkTreeView *tree_view, const gchar **args, gint n_columns, gboolean toggles)
{
@@ -70,7 +61,6 @@ zenity_tree_fill_entries (GtkTreeView *tree_view, const gchar **args, gint n_col
gint i = 0;
model = gtk_tree_view_get_model (tree_view);
- /* gtk_tree_model_foreach (model, count_rows_foreach, &i); */
while (args[i] != NULL) {
gint j;
@@ -123,6 +113,14 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
return;
}
+ n_columns = g_slist_length (tree_data->columns);
+
+ if (n_columns == 0) {
+ g_printerr (_("No column titles specified for --list\n"));
+ data->exit_code = -1;
+ return;
+ }
+
glade_xml_signal_autoconnect (glade_dialog);
dialog = glade_xml_get_widget (glade_dialog, "zenity_tree_dialog");
@@ -140,8 +138,6 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
tree_view = glade_xml_get_widget (glade_dialog, "zenity_tree_view");
- n_columns = g_slist_length (tree_data->columns);
-
/* Create an empty list store */
model = g_object_new (GTK_TYPE_LIST_STORE, NULL);
@@ -216,13 +212,58 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
g_object_unref (glade_dialog);
}
+static void
+zenity_tree_dialog_output (GtkTreeModel *model, GtkTreePath *path_buf, GtkTreeIter *iter, GtkTreeView *tree_view)
+{
+ GValue value = {0, };
+
+ gtk_tree_model_get_value (model, iter, 0, &value);
+
+ g_printerr ("%s", g_value_get_string (&value));
+ g_value_unset (&value);
+}
+
+static gboolean
+zenity_tree_dialog_toggle_output (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
+{
+ GValue toggle_value = {0, };
+
+ gtk_tree_model_get_value (model, iter, 0, &toggle_value);
+
+ if (g_value_get_boolean (&toggle_value) == TRUE) {
+ GValue value = {0, };
+ gtk_tree_model_get_value (model, iter, 1, &value);
+ g_printerr ("%s", g_value_get_string (&value));
+ g_value_unset (&value);
+ }
+ g_value_unset (&toggle_value);
+ return FALSE;
+}
+
static void
zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data)
{
ZenityData *zen_data = data;
+ GtkWidget *tree_view;
+ GtkTreeSelection *selection;
+ GtkTreeModel *model;
switch (response) {
case GTK_RESPONSE_OK:
+ tree_view = glade_xml_get_widget (glade_dialog, "zenity_tree_view");
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));
+
+ if (gtk_tree_model_get_column_type (model, 0) == G_TYPE_BOOLEAN) {
+ gtk_tree_model_foreach (model,
+ (GtkTreeModelForeachFunc) zenity_tree_dialog_toggle_output,
+ NULL);
+ }
+ else {
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
+ gtk_tree_selection_selected_foreach (selection,
+ (GtkTreeSelectionForeachFunc) zenity_tree_dialog_output,
+ GTK_TREE_VIEW (tree_view));
+ }
zen_data->exit_code = 0;
gtk_main_quit ();
break;