88b747abb52fd52b2e1731625da39811e44f000a
[fw/altos] / aoview / aoview_label.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 struct {
21         char            *name;
22         char            *initial_value;
23         GtkLabel        *widget;
24 } label_widgets[] = {
25         { "height_label", "Height", NULL },
26         { "state_label", "State", NULL },
27         { "rssi_label", "RSSI", NULL },
28         { "height_value", "0m", NULL },
29         { "state_value", "pad", NULL },
30         { "rssi_value", "-50dBm", NULL },
31 };
32
33 static void
34 aoview_label_assign(GtkLabel *widget, char *value)
35 {
36         char    *markup;
37
38         markup = g_markup_printf_escaped("<span font_weight=\"bold\" size=\"xx-large\">%s</span>", value);
39         gtk_label_set_markup(widget, markup);
40         g_free(markup);
41 }
42
43 void
44 aoview_label_show(struct aostate *state)
45 {
46         char    line[1024];
47         sprintf(line, "%dm", state->height);
48         aoview_label_assign(label_widgets[3].widget, line);
49
50         aoview_label_assign(label_widgets[4].widget, state->state);
51
52         sprintf(line, "%ddBm", state->rssi);
53         aoview_label_assign(label_widgets[5].widget, line);
54 }
55
56 void
57 aoview_label_init(GladeXML *xml)
58 {
59         int i;
60         for (i = 0; i < sizeof(label_widgets)/sizeof(label_widgets[0]); i++) {
61                 label_widgets[i].widget = GTK_LABEL(glade_xml_get_widget(xml, label_widgets[i].name));
62                 aoview_label_assign(label_widgets[i].widget, label_widgets[i].initial_value);
63                 assert(label_widgets[i].widget);
64         }
65 }