Add channel menu to ao-view.
[fw/altos] / ao-tools / ao-view / aoview_channel.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
21 #define NUM_CHANNEL     10
22
23 static GtkRadioMenuItem *channel_item[NUM_CHANNEL];
24
25 int
26 aoview_channel_current(void)
27 {
28         int     c;
29
30         for (c = 0; c < NUM_CHANNEL; c++)
31                 if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(channel_item[c])))
32                         return c;
33         return -1;
34 }
35
36 static void
37 aoview_channel_notify(int channel)
38 {
39         if (0 <= channel && channel < NUM_CHANNEL)
40                 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(channel_item[channel]), TRUE);
41 }
42
43 #define ALTOS_CHANNEL_PATH      "/apps/aoview/channel"
44
45 static void
46 aoview_channel_change(GtkWidget *widget, gpointer data)
47 {
48         gboolean        enabled = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
49         int             c = (int) data;
50         GConfClient     *gconf_client;
51         GError          *error;
52
53         if (enabled) {
54                 aoview_monitor_set_channel(c);
55                 gconf_client = gconf_client_get_default();
56                 gconf_client_set_int(gconf_client, ALTOS_CHANNEL_PATH, c, &error);
57         }
58 }
59
60 void
61 aoview_channel_init(GladeXML *xml)
62 {
63         int     c;
64         GConfClient     *gconf_client;
65
66         for (c = 0; c < NUM_CHANNEL; c++) {
67                 char    name[32];
68
69                 sprintf(name, "channel_%d", c);
70                 channel_item[c] = GTK_RADIO_MENU_ITEM(glade_xml_get_widget(xml, name));
71                 assert(channel_item[c]);
72                 g_signal_connect(G_OBJECT(channel_item[c]), "toggled",
73                                  G_CALLBACK(aoview_channel_change),
74                                  (gpointer) c);
75         }
76         gconf_client = gconf_client_get_default();
77         c = 0;
78         if (gconf_client)
79         {
80                 GError  *error;
81
82                 error = NULL;
83                 c = gconf_client_get_int(gconf_client,
84                                          ALTOS_CHANNEL_PATH,
85                                          &error);
86                 if (error)
87                         c = 0;
88         }
89         aoview_channel_notify(c);
90 }