Handle GPS satellite tracking data
[fw/altos] / ao-view / 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 #define NCOL    2
21
22 static GtkTreeView      *dataview[NCOL];
23 static GtkListStore     *datalist[NCOL];
24
25 void
26 aoview_table_start(void)
27 {
28         int col;
29         for (col = 0; col < NCOL; col++)
30                 datalist[col] = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
31 }
32
33 void
34 aoview_table_add_row(int col, char *label, char *format, ...)
35 {
36         char            buf[1024];
37         va_list         ap;
38         GtkTreeIter     iter;
39
40         va_start(ap, format);
41         vsnprintf(buf, sizeof (buf), format, ap);
42         va_end(ap);
43         gtk_list_store_append(datalist[col], &iter);
44         gtk_list_store_set(datalist[col], &iter,
45                            0, label,
46                            1, buf,
47                            -1);
48 }
49
50 void
51 aoview_table_finish(void)
52 {
53         int     col;
54         for (col = 0; col < NCOL; col++) {
55                 gtk_tree_view_set_model(dataview[col], GTK_TREE_MODEL(datalist[col]));
56                 g_object_unref(G_OBJECT(datalist[col]));
57                 gtk_tree_view_columns_autosize(dataview[col]);
58         }
59 }
60
61 void
62 aoview_table_clear(void)
63 {
64         int     col;
65         for (col = 0; col < NCOL; col++)
66                 gtk_tree_view_set_model(dataview[col], NULL);
67 }
68
69 void
70 aoview_table_init(GladeXML *xml)
71 {
72         int     col;
73
74         for (col = 0; col < NCOL; col++) {
75                 char    name[32];
76                 sprintf(name, "dataview_%d", col);
77                 dataview[col] = GTK_TREE_VIEW(glade_xml_get_widget(xml, name));
78                 assert(dataview[col]);
79
80                 aoview_add_plain_text_column(dataview[col], "Field", 0, 20);
81                 aoview_add_plain_text_column(dataview[col], "Value", 1, 32);
82         }
83 }