daemon: read settings from gconf
[espeaktime] / src / applet.c
index d98db82..2fd3a44 100644 (file)
@@ -2,8 +2,8 @@
 #include <gtk/gtk.h>
 #include <hildon/hildon.h>
 #include <hildon-cp-plugin/hildon-cp-plugin-interface.h>
-
-#define ESPEAK_BIN "espeak"
+#include <gconf/gconf-client.h>
+#include "config.h"
 
 /* TODO: read these from disk */
 
@@ -70,51 +70,6 @@ static const struct effect {
 };
 static const int num_effects = sizeof(effects) / sizeof(effects[0]);
 
-struct espeaktime_settings {
-       const gchar *voice;
-       const gchar *effect;
-       const gchar *text;
-       gint amplitude;
-       gint pitch;
-       gint speed;
-       gboolean ignore_silent;
-};
-
-static void do_test(struct espeaktime_settings *cfg)
-{
-       gchar astr[16], pstr[16], sstr[16];
-       gchar vstr[64];
-       gchar text[4096];
-       time_t t;
-       struct tm *tm;
-       int res;
-       pid_t pid;
-
-       time(&t);
-       tm = localtime(&t);
-
-       g_snprintf(astr, sizeof(astr), "%d", cfg->amplitude);
-       g_snprintf(pstr, sizeof(pstr), "%d", cfg->pitch);
-       g_snprintf(sstr, sizeof(sstr), "%d", cfg->speed);
-       g_snprintf(vstr, sizeof(vstr), "%s%s%s", cfg->voice,
-               (*cfg->effect) ? "+" : "", cfg->effect);
-       strftime(text, sizeof(text), cfg->text, tm);
-
-       pid = fork();
-       if (pid < 0) {
-               perror("fork");
-               return;
-       }
-       if (pid)
-               return;
-       g_print("execlp: -a '%s' -p '%s' -s '%s' -v '%s' '%s'\n",
-               astr, pstr, sstr, vstr, text);
-       res = execlp(ESPEAK_BIN, ESPEAK_BIN,
-               "-a", astr, "-p", pstr, "-s", sstr, "-v", vstr,
-               text, NULL);
-       g_print("execlp: %d\n", res);
-}
-
 
 static void add_scale(GtkVBox *vbox, GtkSizeGroup *size_group, const char *caption, GtkAdjustment *adjustment)
 {
@@ -136,6 +91,9 @@ osso_return_t execute(osso_context_t *osso, gpointer data, gboolean user_activat
                .ignore_silent = TRUE,
        };
 
+       GConfClient *client = gconf_client_get_default();
+       cfg_read(client, &cfg);
+
        GtkWidget *dialog;
        dialog = gtk_dialog_new_with_buttons(
                "eSpeakTime Settings",
@@ -211,26 +169,34 @@ osso_return_t execute(osso_context_t *osso, gpointer data, gboolean user_activat
        while (1) {
                int result = gtk_dialog_run(GTK_DIALOG(dialog));
 
+               g_free(cfg.voice);
+               g_free(cfg.effect);
+               g_free(cfg.text);
+               cfg.voice = g_strdup(voices[hildon_picker_button_get_active(voice)].id);
+               cfg.effect = g_strdup(effects[hildon_picker_button_get_active(effect)].id);
+               cfg.text = g_strdup(gtk_entry_get_text(GTK_ENTRY(text)));
+               cfg.amplitude = gtk_adjustment_get_value(amplitude_adj);
+               cfg.pitch = gtk_adjustment_get_value(pitch_adj);
+               cfg.speed = gtk_adjustment_get_value(speed_adj);
+               cfg.ignore_silent = hildon_check_button_get_active(ignore_silent);
+
                switch (result) {
                case 1:
                        g_print("Test button\n");
-                       cfg.voice = voices[hildon_picker_button_get_active(voice)].id;
-                       cfg.effect = effects[hildon_picker_button_get_active(effect)].id;
-                       cfg.text = gtk_entry_get_text(GTK_ENTRY(text));
-                       cfg.amplitude = gtk_adjustment_get_value(amplitude_adj);
-                       cfg.pitch = gtk_adjustment_get_value(pitch_adj);
-                       cfg.speed = gtk_adjustment_get_value(speed_adj);
-                       cfg.ignore_silent = hildon_check_button_get_active(ignore_silent);
-                       do_test(&cfg);
+                       cfg_speak(&cfg, TRUE);
                        continue;
                case GTK_RESPONSE_OK:
                        g_print("Save\n");
+                       cfg_write(client, &cfg);
                        break;
                }
                break;
        }
        gtk_widget_destroy(GTK_WIDGET(dialog));
 
+       cfg_free(&cfg);
+       g_object_unref(G_OBJECT(client));
+
        return OSSO_OK;
 }