Switch from GPLv2 to GPLv2+
[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; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 #include "aoview.h"
20
21
22 #define NUM_CHANNEL     10
23
24 static GtkRadioMenuItem *channel_item[NUM_CHANNEL];
25
26 int
27 aoview_channel_current(void)
28 {
29         int     c;
30
31         for (c = 0; c < NUM_CHANNEL; c++)
32                 if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(channel_item[c])))
33                         return c;
34         return -1;
35 }
36
37 static void
38 aoview_channel_notify(int channel)
39 {
40         if (0 <= channel && channel < NUM_CHANNEL)
41                 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(channel_item[channel]), TRUE);
42 }
43
44 #define ALTOS_CHANNEL_PATH      "/apps/aoview/channel"
45
46 static void
47 aoview_channel_change(GtkWidget *widget, gpointer data)
48 {
49         gboolean        enabled = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
50         int             c = (int) data;
51         GConfClient     *gconf_client;
52         GError          *error;
53
54         if (enabled) {
55                 aoview_monitor_set_channel(c);
56                 gconf_client = gconf_client_get_default();
57                 gconf_client_set_int(gconf_client, ALTOS_CHANNEL_PATH, c, &error);
58         }
59 }
60
61 void
62 aoview_channel_init(GladeXML *xml)
63 {
64         int     c;
65         GConfClient     *gconf_client;
66
67         for (c = 0; c < NUM_CHANNEL; c++) {
68                 char    name[32];
69
70                 sprintf(name, "channel_%d", c);
71                 channel_item[c] = GTK_RADIO_MENU_ITEM(glade_xml_get_widget(xml, name));
72                 assert(channel_item[c]);
73                 g_signal_connect(G_OBJECT(channel_item[c]), "toggled",
74                                  G_CALLBACK(aoview_channel_change),
75                                  (gpointer) c);
76         }
77         gconf_client = gconf_client_get_default();
78         c = 0;
79         if (gconf_client)
80         {
81                 GError  *error;
82
83                 error = NULL;
84                 c = gconf_client_get_int(gconf_client,
85                                          ALTOS_CHANNEL_PATH,
86                                          &error);
87                 if (error)
88                         c = 0;
89         }
90         aoview_channel_notify(c);
91 }