From dbcf11f6024be3b18369d7e92888e1f899b080a1 Mon Sep 17 00:00:00 2001 From: Alex Badea Date: Sat, 19 Jun 2010 23:54:54 +0300 Subject: [PATCH 1/1] applet: fetch config values and construct commandline --- src/applet.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/applet.c b/src/applet.c index 6f74490..86762a4 100644 --- a/src/applet.c +++ b/src/applet.c @@ -1,7 +1,10 @@ +#include #include #include #include +#define ESPEAK_BIN "espeak" + /* TODO: read these from disk */ static const struct voice { @@ -67,6 +70,50 @@ 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; +}; + +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; + + pid = fork(); + if (pid < 0) { + perror("fork"); + return; + } + if (pid) + return; + 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); + g_print("execlp: -a '%s' -p '%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) { GtkWidget *scale = gtk_hscale_new(adjustment); @@ -120,6 +167,7 @@ osso_return_t execute(osso_context_t *osso, gpointer data, gboolean user_activat gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(effect), FALSE, FALSE, 0); HildonEntry *text = HILDON_ENTRY(hildon_entry_new(HILDON_SIZE_AUTO)); + gtk_entry_set_text(GTK_ENTRY(text), "%H:%M"); gtk_box_pack_start(GTK_BOX(vbox), hildon_caption_new(title_group, "Speech string", GTK_WIDGET(text), NULL, HILDON_CAPTION_MANDATORY), FALSE, FALSE, 0); @@ -144,10 +192,19 @@ osso_return_t execute(osso_context_t *osso, gpointer data, gboolean user_activat gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), panarea); gtk_widget_show_all(dialog); while (1) { + struct espeaktime_settings cfg; int result = gtk_dialog_run(GTK_DIALOG(dialog)); + 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); + do_test(&cfg); continue; case GTK_RESPONSE_OK: g_print("Save\n"); -- 1.7.9.5