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