Remove unused cctools code paths for old libusb and cp2103 ioctls.
[fw/altos] / aoview / aoview_voice.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 #if HAVE_FLITE
21 #include <stdarg.h>
22
23 FILE    *aoview_flite;
24
25 void aoview_voice_open(void)
26 {
27         int     err;
28
29         if (!aoview_flite)
30                 aoview_flite = aoview_flite_start();
31 }
32
33 void aoview_voice_close(void)
34 {
35         if (aoview_flite) {
36                 aoview_flite_stop();
37                 aoview_flite = NULL;
38         }
39 }
40
41 void aoview_voice_speak(char *format, ...)
42 {
43         va_list ap;
44
45         if (aoview_flite) {
46                 va_start(ap, format);
47                 vfprintf(aoview_flite, format, ap);
48                 fflush(aoview_flite);
49                 va_end(ap);
50         }
51 }
52
53 #else
54 void aoview_voice_open(void)
55 {
56 }
57
58 void aoview_voice_close(void)
59 {
60 }
61
62 void aoview_voice_speak(char *format, ...)
63 {
64 }
65 #endif
66
67
68 static GtkCheckMenuItem *voice_enable;
69
70 #define ALTOS_VOICE_PATH        "/apps/aoview/voice"
71
72 static void
73 aoview_voice_enable(GtkWidget *widget, gpointer data)
74 {
75         gboolean        enabled = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
76         GError          *error;
77         GConfClient     *gconf_client;
78
79         if (enabled) {
80                 aoview_voice_open();
81                 aoview_voice_speak("enable voice\n");
82         } else {
83                 aoview_voice_speak("disable voice\n");
84                 aoview_voice_close();
85         }
86         gconf_client = gconf_client_get_default();
87         gconf_client_set_bool(gconf_client,
88                               ALTOS_VOICE_PATH,
89                               enabled,
90                               &error);
91 }
92
93 void
94 aoview_voice_init(GladeXML *xml)
95 {
96         gboolean        enabled;
97         GConfClient     *gconf_client;
98
99         voice_enable = GTK_CHECK_MENU_ITEM(glade_xml_get_widget(xml, "voice_enable"));
100         assert(voice_enable);
101
102         gconf_client = gconf_client_get_default();
103         enabled = TRUE;
104         if (gconf_client)
105         {
106                 GError  *error;
107
108                 error = NULL;
109                 enabled = gconf_client_get_bool(gconf_client,
110                                                 ALTOS_VOICE_PATH,
111                                                 &error);
112                 if (error)
113                         enabled = TRUE;
114         }
115         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(voice_enable), enabled);
116         if (enabled)
117                 aoview_voice_open();
118
119         g_signal_connect(G_OBJECT(voice_enable), "toggled",
120                          G_CALLBACK(aoview_voice_enable),
121                          voice_enable);
122 }