Add channel menu to ao-view.
authorKeith Packard <keithp@keithp.com>
Sat, 10 Oct 2009 18:43:31 +0000 (11:43 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 10 Oct 2009 18:43:31 +0000 (11:43 -0700)
Sets radio channel when TD is connected, saves selected channel in
gconf database.

Signed-off-by: Keith Packard <keithp@keithp.com>
ao-tools/ao-view/Makefile.am
ao-tools/ao-view/aoview.glade
ao-tools/ao-view/aoview.h
ao-tools/ao-view/aoview_channel.c [new file with mode: 0644]
ao-tools/ao-view/aoview_main.c
ao-tools/ao-view/aoview_monitor.c

index 7b274a40484e6e94f51624ef7a4c6a93273bc7cc..7a288417b10f161d874a607fc2764191e40c25a7 100644 (file)
@@ -25,6 +25,7 @@ ao_view_SOURCES = \
        aoview_replay.c \
        aoview_label.c \
        aoview_flite.c \
+       aoview_channel.c \
        aoview.h
 
 BUILT_SOURCES = aoview_glade.h
index 9a7461108af227c299ed86860d017ce00521e328..c302ad0db1be69a3a34b4cd86720324a2c0ef2c8 100644 (file)
                 </child>
               </widget>
             </child>
+            <child>
+              <widget class="GtkMenuItem" id="channel_menu_item">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">_Channel</property>
+                <property name="use_underline">True</property>
+                <child>
+                  <widget class="GtkMenu" id="menu7">
+                    <property name="visible">True</property>
+                    <child>
+                      <widget class="GtkRadioMenuItem" id="channel_0">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">Channel 0 (434.550MHz)</property>
+                        <property name="use_underline">True</property>
+                        <property name="draw_as_radio">True</property>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkRadioMenuItem" id="channel_1">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">Channel 1 (434.650MHz)</property>
+                        <property name="use_underline">True</property>
+                        <property name="draw_as_radio">True</property>
+                        <property name="group">channel_0</property>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkRadioMenuItem" id="channel_2">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">Channel 2 (434.750MHz)</property>
+                        <property name="use_underline">True</property>
+                        <property name="draw_as_radio">True</property>
+                        <property name="group">channel_0</property>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkRadioMenuItem" id="channel_3">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">Channel 3 (434.850MHz)</property>
+                        <property name="use_underline">True</property>
+                        <property name="draw_as_radio">True</property>
+                        <property name="group">channel_0</property>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkRadioMenuItem" id="channel_4">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">Channel 4 (434.950MHz)</property>
+                        <property name="use_underline">True</property>
+                        <property name="draw_as_radio">True</property>
+                        <property name="group">channel_0</property>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkRadioMenuItem" id="channel_5">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">Channel 5 (435.050MHz)</property>
+                        <property name="use_underline">True</property>
+                        <property name="draw_as_radio">True</property>
+                        <property name="group">channel_0</property>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkRadioMenuItem" id="channel_6">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">Channel 6 (435.150MHz)</property>
+                        <property name="use_underline">True</property>
+                        <property name="draw_as_radio">True</property>
+                        <property name="group">channel_0</property>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkRadioMenuItem" id="channel_7">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">Channel 7 (435.250MHz)</property>
+                        <property name="use_underline">True</property>
+                        <property name="draw_as_radio">True</property>
+                        <property name="group">channel_0</property>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkRadioMenuItem" id="channel_8">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">Channel 8 (435.350MHz)</property>
+                        <property name="use_underline">True</property>
+                        <property name="draw_as_radio">True</property>
+                        <property name="group">channel_0</property>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkRadioMenuItem" id="channel_9">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">Channel 9 (435.450MHz)</property>
+                        <property name="use_underline">True</property>
+                        <property name="draw_as_radio">True</property>
+                        <property name="group">channel_0</property>
+                      </widget>
+                    </child>
+                  </widget>
+                </child>
+              </widget>
+            </child>
             <child>
               <widget class="GtkMenuItem" id="menuitem4">
                 <property name="visible">True</property>
index 6a4753acb761a8590fdb87c0b1cee5bbeefb1725..c582159c86001c9a016cd169b29b3685ce46476a 100644 (file)
@@ -168,6 +168,9 @@ aoview_monitor_connect(char *tty);
 gboolean
 aoview_monitor_parse(const char *line);
 
+void
+aoview_monitor_set_channel(int channel);
+
 void
 aoview_monitor_reset(void);
 
@@ -320,4 +323,12 @@ aoview_flite_stop(void);
 
 extern char *aoview_tty;
 
+/* aoview_channel.c */
+
+int
+aoview_channel_current(void);
+
+void
+aoview_channel_init(GladeXML *xml);
+
 #endif /* _AOVIEW_H_ */
diff --git a/ao-tools/ao-view/aoview_channel.c b/ao-tools/ao-view/aoview_channel.c
new file mode 100644 (file)
index 0000000..959173c
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * Copyright © 2009 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#include "aoview.h"
+
+
+#define NUM_CHANNEL    10
+
+static GtkRadioMenuItem *channel_item[NUM_CHANNEL];
+
+int
+aoview_channel_current(void)
+{
+       int     c;
+
+       for (c = 0; c < NUM_CHANNEL; c++)
+               if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(channel_item[c])))
+                       return c;
+       return -1;
+}
+
+static void
+aoview_channel_notify(int channel)
+{
+       if (0 <= channel && channel < NUM_CHANNEL)
+               gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(channel_item[channel]), TRUE);
+}
+
+#define ALTOS_CHANNEL_PATH     "/apps/aoview/channel"
+
+static void
+aoview_channel_change(GtkWidget *widget, gpointer data)
+{
+       gboolean        enabled = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
+       int             c = (int) data;
+       GConfClient     *gconf_client;
+       GError          *error;
+
+       if (enabled) {
+               aoview_monitor_set_channel(c);
+               gconf_client = gconf_client_get_default();
+               gconf_client_set_int(gconf_client, ALTOS_CHANNEL_PATH, c, &error);
+       }
+}
+
+void
+aoview_channel_init(GladeXML *xml)
+{
+       int     c;
+       GConfClient     *gconf_client;
+
+       for (c = 0; c < NUM_CHANNEL; c++) {
+               char    name[32];
+
+               sprintf(name, "channel_%d", c);
+               channel_item[c] = GTK_RADIO_MENU_ITEM(glade_xml_get_widget(xml, name));
+               assert(channel_item[c]);
+               g_signal_connect(G_OBJECT(channel_item[c]), "toggled",
+                                G_CALLBACK(aoview_channel_change),
+                                (gpointer) c);
+       }
+       gconf_client = gconf_client_get_default();
+       c = 0;
+       if (gconf_client)
+       {
+               GError  *error;
+
+               error = NULL;
+               c = gconf_client_get_int(gconf_client,
+                                        ALTOS_CHANNEL_PATH,
+                                        &error);
+               if (error)
+                       c = 0;
+       }
+       aoview_channel_notify(c);
+}
index 64c1c0273a90c2c5e857af4b53d5fa07077a41db..714bee9a2677924c8369cf79540b3bcea9c81edd 100644 (file)
@@ -86,6 +86,8 @@ int main(int argc, char **argv)
 
        aoview_voice_init(xml);
 
+       aoview_channel_init(xml);
+
        aoview_dev_dialog_init(xml);
 
        aoview_state_init(xml);
index 8564014b31c7a9f7e4703891d526aab721f7450d..48e203209f51db2ec4c79e57bfe98fc2f48b309b 100644 (file)
@@ -82,6 +82,7 @@ aoview_monitor_parse(const char *input_line)
        char line_buf[8192], *line;
        struct aodata   data;
        int     tracking_pos;
+       int channel;
 
        /* avoid smashing our input parameter */
        strncpy (line_buf, input_line, sizeof (line_buf)-1);
@@ -214,15 +215,26 @@ aoview_monitor_callback(gpointer user_data,
        }
 }
 
+void
+aoview_monitor_set_channel(int channel)
+{
+       if (monitor_serial)
+               aoview_serial_printf(monitor_serial, "c r %d\n", channel);
+}
+
 gboolean
 aoview_monitor_connect(char *tty)
 {
+       int     channel;
        aoview_monitor_disconnect();
        monitor_serial = aoview_serial_open(tty);
        if (!monitor_serial)
                return FALSE;
        aoview_table_clear();
        aoview_state_reset();
+       channel = aoview_channel_current();
+       if (channel >= 0)
+               aoview_monitor_set_channel(channel);
        aoview_serial_set_callback(monitor_serial,
                                   aoview_monitor_callback);
        return TRUE;