newer INSTALL file pulled in by autogen.sh
[fw/altos] / aoview / aoview_table.c
1 /*
2  * Copyright © 2009 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 #include "aoview.h"
19
20 static GtkTreeView      *dataview;
21 static GtkListStore     *datalist;
22
23 void
24 aoview_table_start(void)
25 {
26         datalist = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
27 }
28
29 void
30 aoview_table_add_row(char *label, char *format, ...)
31 {
32         char            buf[1024];
33         va_list         ap;
34         GtkTreeIter     iter;
35
36         va_start(ap, format);
37         vsnprintf(buf, sizeof (buf), format, ap);
38         va_end(ap);
39         gtk_list_store_append(datalist, &iter);
40         gtk_list_store_set(datalist, &iter,
41                            0, label,
42                            1, buf,
43                            -1);
44 }
45
46 void
47 aoview_table_finish(void)
48 {
49         gtk_tree_view_set_model(dataview, GTK_TREE_MODEL(datalist));
50         g_object_unref(G_OBJECT(datalist));
51         gtk_tree_view_columns_autosize(dataview);
52 }
53
54 void
55 aoview_table_clear(void)
56 {
57         gtk_tree_view_set_model(dataview, NULL);
58 }
59
60 void
61 aoview_table_init(GladeXML *xml)
62 {
63         dataview = GTK_TREE_VIEW(glade_xml_get_widget(xml, "dataview"));
64         assert(dataview);
65
66         aoview_add_plain_text_column(dataview, "Field", 0, 20);
67         aoview_add_plain_text_column(dataview, "Value", 1, 32);
68 }