applet: add Test button
[espeaktime] / src / applet.c
index 82170de..f9426df 100644 (file)
@@ -1,6 +1,137 @@
 #include <gtk/gtk.h>
+#include <hildon/hildon.h>
 #include <hildon-cp-plugin/hildon-cp-plugin-interface.h>
 
+/* TODO: read these from disk */
+
+static const struct voice {
+       const char *id;
+       const char *name;
+} voices[] = {
+       { "",           "Default" },
+       { "en",         "English" },
+       { "en-us",      "English (American)" },
+       { "en-sc",      "English (Scottish)" },
+       { "af",         "Afrikaans" },
+       { "bs",         "Bosnian" },
+       { "ca",         "Catalan" },
+       { "cs",         "Czech" },
+       { "de",         "German" },
+       { "el",         "Greek" },
+       { "eo",         "Esperanto" },
+       { "es",         "Spanish" },
+       { "es-la",      "Spanish (Latin America)" },
+       { "fi",         "Finnish" },
+       { "fr",         "French" },
+       { "hr",         "Croatian" },
+       { "hu",         "Hungarian" },
+       { "it",         "Italian" },
+       { "ku",         "Kurdish" },
+       { "lv",         "Latvian" },
+       { "pl",         "Polish" },
+       { "pt",         "Portuguese (Brazil)" },
+       { "pt-pt",      "Portuguese (European)" },
+       { "ro",         "Romanian" },
+       { "sk",         "Slovak" },
+       { "sr",         "Serbian" },
+       { "sv",         "Swedish" },
+       { "sw",         "Swahihi" },
+       { "ta",         "Tamil" },
+       { "tr",         "Turkish" },
+       { "zh",         "Mandarin Chinese" },
+};
+static const int num_voices = sizeof(voices) / sizeof(voices[0]);
+
+static const struct effect {
+       const char *id;
+       const char *name;
+} effects[] = {
+       { "",           "(none)" },
+       { "f1",         "Female 1" },
+       { "f2",         "Female 2" },
+       { "f3",         "Female 3" },
+       { "f4",         "Female 4" },
+       { "m1",         "Male 1" },
+       { "m2",         "Male 2" },
+       { "m3",         "Male 3" },
+       { "m4",         "Male 4" },
+       { "m5",         "Male 5" },
+       { "m6",         "Male 6" },
+       { "m7",         "Male 7" },
+       { "croak",      "Croak" },
+       { "fast",       "Fast" },
+       { "klatt",      "Klatt" },
+       { "klatt2",     "Klatt 2" },
+       { "klatt3",     "Klatt 3" },
+       { "whisper",    "Whisper" },
+};
+static const int num_effects = sizeof(effects) / sizeof(effects[0]);
+
+static void add_scale(GtkVBox *vbox, GtkSizeGroup *size_group, const char *caption, GtkAdjustment *adjustment)
+{
+       GtkWidget *scale = gtk_hscale_new(adjustment);
+       gtk_scale_set_digits(GTK_SCALE(scale), 0);
+       gtk_box_pack_start(GTK_BOX(vbox),
+               hildon_caption_new(size_group, caption, scale, NULL, HILDON_CAPTION_MANDATORY),
+               FALSE, FALSE, 0);
+}
+
+static GtkWidget *build_ui(void)
+{
+       int k;
+       GtkVBox *vbox = GTK_VBOX(gtk_vbox_new(FALSE, 0));
+       GtkSizeGroup *title_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+       GtkSizeGroup *value_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+
+       /* selectors */
+       HildonTouchSelector *voice_selector = HILDON_TOUCH_SELECTOR(hildon_touch_selector_new_text());
+       for (k = 0; k < num_voices; k++)
+               hildon_touch_selector_append_text(voice_selector, voices[k].name);
+
+       HildonTouchSelector *effect_selector = HILDON_TOUCH_SELECTOR(hildon_touch_selector_new_text());
+       for (k = 0; k < num_effects; k++)
+               hildon_touch_selector_append_text(effect_selector, effects[k].name);
+
+       HildonPickerButton *voice = HILDON_PICKER_BUTTON(hildon_picker_button_new(HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
+       hildon_button_set_title(HILDON_BUTTON(voice), "Voice");
+       hildon_picker_button_set_selector(voice, voice_selector);
+       hildon_picker_button_set_active(voice, 0);
+       hildon_button_add_size_groups(HILDON_BUTTON(voice), title_group, value_group, NULL);
+       gtk_button_set_alignment(GTK_BUTTON(voice), 0.0, 0.5);
+       gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(voice), FALSE, FALSE, 0);
+
+       HildonPickerButton *effect = HILDON_PICKER_BUTTON(hildon_picker_button_new(HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
+       hildon_button_set_title(HILDON_BUTTON(effect), "Effect");
+       hildon_picker_button_set_selector(effect, effect_selector);
+       hildon_picker_button_set_active(effect, 0);
+       hildon_button_add_size_groups(HILDON_BUTTON(effect), title_group, value_group, NULL);
+       gtk_button_set_alignment(GTK_BUTTON(effect), 0.0, 0.5);
+       gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(effect), FALSE, FALSE, 0);
+
+       HildonEntry *text = HILDON_ENTRY(hildon_entry_new(HILDON_SIZE_AUTO));
+       gtk_box_pack_start(GTK_BOX(vbox),
+               hildon_caption_new(title_group, "Speech string", GTK_WIDGET(text), NULL, HILDON_CAPTION_MANDATORY),
+               FALSE, FALSE, 0);
+
+       GtkAdjustment *amplitude_adj = GTK_ADJUSTMENT(gtk_adjustment_new(100, 0, 200, 1, 10, 0));
+       add_scale(vbox, title_group, "Amplitude", amplitude_adj);
+
+       GtkAdjustment *pitch_adj = GTK_ADJUSTMENT(gtk_adjustment_new(50, 00, 99, 1, 10, 0));
+       add_scale(vbox, title_group, "Pitch", pitch_adj);
+
+       GtkAdjustment *speed_adj = GTK_ADJUSTMENT(gtk_adjustment_new(170, 80, 390, 1, 10, 0));
+       add_scale(vbox, title_group, "Words per minute", speed_adj);
+
+       GtkWidget *ignore_silent = hildon_check_button_new(HILDON_SIZE_FINGER_HEIGHT);
+       gtk_button_set_label(GTK_BUTTON(ignore_silent), "Ignore silent profile");
+       gtk_box_pack_start(GTK_BOX(vbox), ignore_silent, FALSE, FALSE, 0);
+
+       GtkWidget *panarea = hildon_pannable_area_new();
+       gtk_widget_set_size_request(panarea, -1, 800);
+       hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA(panarea), GTK_WIDGET(vbox));
+       return panarea;
+}
+
 osso_return_t execute(osso_context_t *osso, gpointer data, gboolean user_activated)
 {
        GtkWidget *dialog;
@@ -9,14 +140,25 @@ osso_return_t execute(osso_context_t *osso, gpointer data, gboolean user_activat
                "eSpeakTime Settings",
                GTK_WINDOW(data),
                GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR,
-               GTK_STOCK_SAVE,
-               GTK_RESPONSE_OK,
-               GTK_STOCK_CANCEL,
-               GTK_RESPONSE_CANCEL,
+               "Test", 1,
+               GTK_STOCK_SAVE, GTK_RESPONSE_OK,
+               GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                NULL);
 
+       gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), build_ui());
        gtk_widget_show_all(dialog);
-       gtk_dialog_run(GTK_DIALOG(dialog));
+       while (1) {
+               int result = gtk_dialog_run(GTK_DIALOG(dialog));
+               switch (result) {
+               case 1:
+                       g_print("Test button\n");
+                       continue;
+               case GTK_RESPONSE_OK:
+                       g_print("Save\n");
+                       break;
+               }
+               break;
+       }
        gtk_widget_destroy(GTK_WIDGET(dialog));
 
        return OSSO_OK;
@@ -24,6 +166,7 @@ osso_return_t execute(osso_context_t *osso, gpointer data, gboolean user_activat
 
 osso_return_t save_state(osso_context_t *osso, gpointer data)
 {
+       g_print("save_state called\n");
        return OSSO_OK;
 }