diff options
author | Glynn Foster <glynn.foster@sun.com> | 2003-01-06 15:06:17 +0000 |
---|---|---|
committer | Glynn Foster <gman@src.gnome.org> | 2003-01-06 15:06:17 +0000 |
commit | 344345d9aa262940fedfb8beed9dc0c9bb163a10 (patch) | |
tree | 5c987624efb5352bb3ff4496af798943a3cc62c1 /src | |
parent | Zenity - the art of Zen. Clearly. Um. (diff) | |
download | zenity-344345d9aa262940fedfb8beed9dc0c9bb163a10.tar.gz zenity-344345d9aa262940fedfb8beed9dc0c9bb163a10.tar.bz2 zenity-344345d9aa262940fedfb8beed9dc0c9bb163a10.zip |
Add functions to init and free the parsing options. Still not terribly
2003-01-06 Glynn Foster <glynn.foster@sun.com>
* src/main.c: Add functions to init and free the
parsing options. Still not terribly pretty though.
* src/tree.c, src/zenity.h: Handle --column
argument.
* TODO: Update accordingly.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 71 | ||||
-rw-r--r-- | src/tree.c | 143 | ||||
-rw-r--r-- | src/zenity.h | 3 |
3 files changed, 138 insertions, 79 deletions
@@ -631,29 +631,76 @@ struct poptOption application_options[] = { ZenityParsingOptions *results; -gint -main (gint argc, gchar **argv) { - poptContext ctx; - int nextopt; - ZenityData *general; - ZenityCalendarData *cal_data; - - bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR); - bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); - textdomain(GETTEXT_PACKAGE); +static void +zenity_init_parsing_options (void) { results = g_new0 (ZenityParsingOptions, 1); + + /* Initialize the various dialog structures */ results->data = g_new0 (ZenityData, 1); results->calendar_data = g_new0 (ZenityCalendarData, 1); results->msg_data = g_new0 (ZenityMsgData, 1); results->file_data = g_new0 (ZenityFileData, 1); results->entry_data = g_new0 (ZenityEntryData, 1); - results->entry_data->visible = TRUE; results->progress_data = g_new0 (ZenityProgressData, 1); results->text_data = g_new0 (ZenityTextData, 1); results->tree_data = g_new0 (ZenityTreeData, 1); + + /* Give some sensible defaults */ + results->entry_data->visible = TRUE; results->tree_data->checkbox = FALSE; results->tree_data->radiobox = FALSE; +} + +static void +zenity_free_parsing_options (void) { + + /* General options */ + if (results->data->dialog_title) + g_free (results->data->dialog_title); + if (results->data->window_icon) + g_free (results->data->window_icon); + + /* Dialog options */ + switch (results->mode) { + case MODE_CALENDAR: + g_free (results->calendar_data->dialog_text); + break; + case MODE_ENTRY: + g_free (results->entry_data->dialog_text); + g_free (results->entry_data->entry_text); + break; + case MODE_ERROR: + case MODE_QUESTION: + case MODE_WARNING: + g_free (results->msg_data->dialog_text); + break; + case MODE_FILE: + g_free (results->file_data->uri); + break; + case MODE_TEXTINFO: + g_free (results->text_data->uri); + break; + case MODE_LIST: + g_slist_foreach (results->tree_data->columns, (GFunc) g_free, NULL); + break; + default: + break; + } +} + +gint +main (gint argc, gchar **argv) { + poptContext ctx; + int nextopt; + ZenityData *general; + ZenityCalendarData *cal_data; + + bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR); + bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); + textdomain(GETTEXT_PACKAGE); + + zenity_init_parsing_options (); /* FIXME: popt doesn't like passing stuff through data * but it doesn't seem to cope with the data that I try @@ -702,6 +749,7 @@ main (gint argc, gchar **argv) { } poptFreeContext(ctx); + zenity_free_parsing_options (); exit (0); } @@ -811,6 +859,7 @@ void zenity_parse_options_callback (poptContext ctx, } break; case OPTION_COLUMN: + results->tree_data->columns = g_slist_append (results->tree_data->columns, g_strdup (arg)); break; case OPTION_CHECKLIST: results->tree_data->checkbox = TRUE; @@ -31,13 +31,6 @@ static GladeXML *glade_dialog; -enum -{ - NAME_COLUMN, - DESCRIPTION_COLUMN, - N_COLUMNS -}; - void zenity_tree_dialog_response (GtkWindow *window, int button, gpointer data); static void @@ -52,10 +45,10 @@ zenity_tree_toggled_callback (GtkCellRendererToggle *cell, gchar *path_string, g path = gtk_tree_path_new_from_string (path_string); gtk_tree_model_get_iter (model, &iter, path); - gtk_tree_model_get (model, &iter, NAME_COLUMN, &value, -1); + gtk_tree_model_get (model, &iter, 0, &value, -1); value = !value; - gtk_list_store_set (GTK_LIST_STORE (model), &iter, NAME_COLUMN, value, -1); + gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, value, -1); gtk_tree_path_free (path); } @@ -80,23 +73,23 @@ zenity_tree_fill_entries (GtkTreeView *tree_view, const **argv) gtk_tree_model_foreach (model, count_rows_foreach, &i); while (i<10) { - gtk_list_store_append (GTK_LIST_STORE (model), &iter); - gtk_list_store_set (GTK_LIST_STORE (model), &iter, - NAME_COLUMN, "TRUE", - DESCRIPTION_COLUMN, "This is the bar above foobar", - -1); - - if (i == MAX_ELEMENTS_BEFORE_SCROLLING) { - GtkWidget *scrolled_window; - GtkRequisition rectangle; - - gtk_widget_size_request (GTK_WIDGET (tree_view), &rectangle); - scrolled_window = glade_xml_get_widget (glade_dialog, "zenity_tree_window"); - gtk_widget_set_size_request (scrolled_window, -1, rectangle.height); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), - GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); - } - i++; + gtk_list_store_append (GTK_LIST_STORE (model), &iter); + gtk_list_store_set (GTK_LIST_STORE (model), &iter, + 0, "TRUE", + 1, "This is the bar above foobar", -1); + + if (i == MAX_ELEMENTS_BEFORE_SCROLLING) { + GtkWidget *scrolled_window; + GtkRequisition rectangle; + + gtk_widget_size_request (GTK_WIDGET (tree_view), &rectangle); + scrolled_window = glade_xml_get_widget (glade_dialog, "zenity_tree_window"); + gtk_widget_set_size_request (scrolled_window, -1, rectangle.height); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), + GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); + } + + i++; } } @@ -107,6 +100,10 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) GtkWidget *tree_view; GtkTreeViewColumn *column; GtkListStore *model; + GType *column_types; + GSList *tmp; + gboolean first_column = FALSE; + gint i, column_index, column_n; glade_dialog = zenity_util_load_glade_file ("zenity_tree_dialog"); @@ -127,57 +124,71 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) tree_view = glade_xml_get_widget (glade_dialog, "zenity_tree_view"); - if (tree_data->checkbox || tree_data->radiobox) - model = gtk_list_store_new (N_COLUMNS, G_TYPE_BOOLEAN, G_TYPE_STRING); - else - model = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING); - - gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), GTK_TREE_MODEL (model)); + column_n = g_slist_length (tree_data->columns); - if (tree_data->checkbox) { - GtkCellRenderer *cell_renderer; + /* Create an empty list store */ + model = g_object_new (GTK_TYPE_LIST_STORE, NULL); - cell_renderer = gtk_cell_renderer_toggle_new (); - g_signal_connect (cell_renderer, "toggled", - G_CALLBACK (zenity_tree_toggled_callback), model); + column_types = g_new (GType, column_n); - column = gtk_tree_view_column_new_with_attributes (NULL, - cell_renderer, - "active", NAME_COLUMN, NULL); + for (i = 0; i < column_n; i++) { + /* Have the limitation that the radioboxes and checkboxes are in the first column */ + if (i == 0 && (tree_data->checkbox || tree_data->radiobox)) + column_types[i] = G_TYPE_BOOLEAN; + else + column_types[i] = G_TYPE_STRING; } - else if (tree_data->radiobox) { - GtkCellRenderer *cell_renderer; - cell_renderer = gtk_cell_renderer_toggle_new (); - g_object_set (G_OBJECT (cell_renderer), "radio", TRUE, NULL); - g_signal_connect (cell_renderer, "toggled", - G_CALLBACK (zenity_tree_toggled_callback), model); + gtk_list_store_set_column_types (model, column_n, column_types); - column = gtk_tree_view_column_new_with_attributes (NULL, - cell_renderer, - "active", NAME_COLUMN, NULL); - - } - else { - column = gtk_tree_view_column_new_with_attributes (tree_data->column_one_header, - gtk_cell_renderer_text_new (), - "text", NAME_COLUMN, NULL); - gtk_tree_view_column_set_sort_column_id (column, NAME_COLUMN); - } + gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), GTK_TREE_MODEL (model)); - gtk_tree_view_column_set_resizable (column, TRUE); - gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column); + column_index = 0; + + for (tmp = tree_data->columns; tmp; tmp = tmp->next) { + if (first_column == FALSE) { + if (tree_data->checkbox || tree_data->radiobox) { + GtkCellRenderer *cell_renderer; + + cell_renderer = gtk_cell_renderer_toggle_new (); + + if (tree_data->radiobox) + g_object_set (G_OBJECT (cell_renderer), "radio", TRUE, NULL); + + g_signal_connect (cell_renderer, "toggled", + G_CALLBACK (zenity_tree_toggled_callback), model); + + column = gtk_tree_view_column_new_with_attributes (tmp->data, + cell_renderer, + "active", column_index, NULL); + } + + else { + column = gtk_tree_view_column_new_with_attributes (tmp->data, + gtk_cell_renderer_text_new (), + "text", column_index, NULL); + gtk_tree_view_column_set_sort_column_id (column, column_index); + gtk_tree_view_column_set_resizable (column, TRUE); + } + + first_column = TRUE; + } + else { + column = gtk_tree_view_column_new_with_attributes (tmp->data, + gtk_cell_renderer_text_new (), + "text", column_index, NULL); + gtk_tree_view_column_set_sort_column_id (column, column_index); + gtk_tree_view_column_set_resizable (column, TRUE); + + } - column = gtk_tree_view_column_new_with_attributes (tree_data->column_two_header, - gtk_cell_renderer_text_new (), - "text", DESCRIPTION_COLUMN, NULL); - gtk_tree_view_column_set_sort_column_id (column, DESCRIPTION_COLUMN); - gtk_tree_view_column_set_resizable (column, TRUE); - gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column); + gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column); + column_index++; + } gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE); - zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), NULL); + /* zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), NULL); */ gtk_widget_show (dialog); gtk_main (); diff --git a/src/zenity.h b/src/zenity.h index 1543436b..ea04b026 100644 --- a/src/zenity.h +++ b/src/zenity.h @@ -69,8 +69,7 @@ typedef struct { typedef struct { gchar *dialog_text; - gchar *column_one_header; - gchar *column_two_header; + GSList *columns; gboolean checkbox; gboolean radiobox; } ZenityTreeData; |