#include <unistd.h>
-#include <errno.h>
+#include <string.h>
#include <gtk/gtk.h>
#include <hildon/hildon.h>
#include <hildon-cp-plugin/hildon-cp-plugin-interface.h>
-#include <gconf/gconf.h>
#include <gconf/gconf-client.h>
-
-#define ESPEAK_BIN "espeak"
-#define GCONF_KEY "/apps/Maemo/espeaktime"
+#include "config.h"
/* TODO: read these from disk */
{ "pt", "Portuguese (Brazil)" },
{ "pt-pt", "Portuguese (European)" },
{ "ro", "Romanian" },
+ { "ru", "Russian [extra]" },
{ "sk", "Slovak" },
{ "sr", "Serbian" },
{ "sv", "Swedish" },
{ "sw", "Swahihi" },
{ "ta", "Tamil" },
{ "tr", "Turkish" },
- { "zh", "Mandarin Chinese" },
+ { "zh", "Chinese (Mandarin) [extra]" },
+ { "zh-yue", "Chinese (Cantonese) [extra]" },
};
static const int num_voices = sizeof(voices) / sizeof(voices[0]);
};
static const int num_effects = sizeof(effects) / sizeof(effects[0]);
-struct espeaktime_settings {
- gchar *voice;
- gchar *effect;
- gchar *text;
- gint amplitude;
- gint pitch;
- gint speed;
- gboolean ignore_silent;
-};
-
-static void cfg_read(GConfClient *client, struct espeaktime_settings *cfg)
+static const gchar help_message[] =
+ "The Speech string can be any string accepted by strftime(3). "
+ "The default is \"%H:%M\". An excerpt from the strftime man page is "
+ "provided below:\n"
+ "\n\n"
+ "Ordinary characters placed in the format string are copied to the output "
+ "without conversion. Conversion specifications are introduced by a '%' "
+ "character, and terminated by a conversion specifier character, and are "
+ "replaced in the output as follows:\n"
+ "\n"
+ "%a - The abbreviated weekday name according to the current locale. \n"
+ "\n"
+ "%A - The full weekday name according to the current locale. \n"
+ "\n"
+ "%b - The abbreviated month name according to the current locale. \n"
+ "\n"
+ "%B - The full month name according to the current locale. \n"
+ "\n"
+ "%c - The preferred date and time representation for the current locale. \n"
+ "\n"
+ "%C - The century number (year/100) as a 2-digit integer. (SU) \n"
+ "\n"
+ "%d - The day of the month as a decimal number (range 01 to 31). \n"
+ "\n"
+ "%D - Equivalent to %m/%d/%y. (Yecch -- for Americans only. Americans "
+ "should note that in other countries %d/%m/%y is rather common. This "
+ "means that in international context this format is ambiguous and should "
+ "not be used.) (SU) \n"
+ "\n"
+ "%e - Like %d, the day of the month as a decimal number, but a leading "
+ "zero is replaced by a space. (SU) \n"
+ "\n"
+ "%E - Modifier: use alternative format, see below. (SU) \n"
+ "\n"
+ "%F - Equivalent to %Y-%m-%d (the ISO 8601 date format). (C99) \n"
+ "\n"
+ "%G - The ISO 8601 year with century as a decimal number. The 4-digit "
+ "year corresponding to the ISO week number (see %V). This has the same "
+ "format and value as %y, except that if the ISO week number belongs to "
+ "the previous or next year, that year is used instead. (TZ) \n"
+ "\n"
+ "%g - Like %G, but without century, i.e., with a 2-digit year (00-99).\n"
+ "(TZ) \n"
+ "\n"
+ "%h - Equivalent to %b. (SU) \n"
+ "\n"
+ "%H - The hour as a decimal number using a 24-hour clock (range 00 to 23). \n"
+ "\n"
+ "%I - The hour as a decimal number using a 12-hour clock (range 01 to 12). \n"
+ "\n"
+ "%j - The day of the year as a decimal number (range 001 to 366). \n"
+ "\n"
+ "%k - The hour (24-hour clock) as a decimal number (range 0 to 23); "
+ "single digits are preceded by a blank. (See also %H.) (TZ) \n"
+ "\n"
+ "%l - The hour (12-hour clock) as a decimal number (range 1 to 12); "
+ "single digits are preceded by a blank. (See also %I.) (TZ) \n"
+ "\n"
+ "%m - The month as a decimal number (range 01 to 12). \n"
+ "\n"
+ "%M - The minute as a decimal number (range 00 to 59). \n"
+ "\n"
+ "%n - A newline character. (SU) \n"
+ "\n"
+ "%O - Modifier: use alternative format, see below. (SU) \n"
+ "\n"
+ "%p - Either 'AM' or 'PM' according to the given time value, or the "
+ "corresponding strings for the current locale. Noon is treated as 'pm' "
+ "and midnight as 'am'. \n"
+ "\n"
+ "%P - Like %p but in lowercase: 'am' or 'pm' or a corresponding string "
+ "for the current locale. (GNU) \n"
+ "\n"
+ "%r - The time in a.m. or p.m. notation. In the POSIX locale this is "
+ "equivalent to '%I:%M:%S %p'. (SU) \n"
+ "\n"
+ "%R - The time in 24-hour notation (%H:%M). (SU) For a version including "
+ "the seconds, see %T below. \n"
+ "\n"
+ "%s - The number of seconds since the Epoch, i.e., since 1970-01-01 "
+ "00:00:00 UTC. (TZ) \n"
+ "\n"
+ "%S - The second as a decimal number (range 00 to 60). (The range is up "
+ "to 60 to allow for occasional leap seconds.) \n"
+ "\n"
+ "%t - A tab character. (SU) \n"
+ "\n"
+ "%T - The time in 24-hour notation (%H:%M:%S). (SU) \n"
+ "\n"
+ "%u - The day of the week as a decimal, range 1 to 7, Monday being 1. See "
+ "also %w. (SU) \n"
+ "\n"
+ "%U - The week number of the current year as a decimal number, range 00 "
+ "to 53, starting with the first Sunday as the first day of week 01. See "
+ "also %V and %W. \n"
+ "\n"
+ "%V - The ISO 8601:1988 week number of the current year as a decimal "
+ "number, range 01 to 53, where week 1 is the first week that has at least "
+ "4 days in the current year, and with Monday as the first day of the "
+ "week. See also %U and %W. (SU) \n"
+ "\n"
+ "%w - The day of the week as a decimal, range 0 to 6, Sunday being 0. See "
+ "also %u. \n"
+ "\n"
+ "%W - The week number of the current year as a decimal number, range 00 "
+ "to 53, starting with the first Monday as the first day of week 01. \n"
+ "\n"
+ "%x - The preferred date representation for the current locale without "
+ "the time. \n"
+ "\n"
+ "%X - The preferred time representation for the current locale without "
+ "the date. \n"
+ "\n"
+ "%y - The year as a decimal number without a century (range 00 to 99). \n"
+ "\n"
+ "%Y - The year as a decimal number including the century. \n"
+ "\n"
+ "%z - The time-zone as hour offset from GMT. Required to emit RFC "
+ "822-conformant dates (using \"%a, %d %b %Y %H:%M:%S %z\"). (GNU) \n"
+ "\n"
+ "%Z - The time zone or name or abbreviation. \n"
+ "\n"
+ "%+ - The date and time in date(1) format. (TZ) (Not supported in "
+ "glibc2.) \n"
+ "\n"
+ "%% - A literal '%' character.\n"
+ "\n"
+ "\n"
+ "Some conversion specifications can be modified by preceding the "
+ "conversion specifier character by the E or O modifier to indicate that "
+ "an alternative format should be used. If the alternative format or "
+ "specification does not exist for the current locale, the behaviour will "
+ "be as if the unmodified conversion specification were used. (SU) The "
+ "Single Unix Specification mentions %Ec, %EC, %Ex, %EX, %Ey, %EY, %Od, "
+ "%Oe, %OH, %OI, %Om, %OM, %OS, %Ou, %OU, %OV, %Ow, %OW, %Oy, where the "
+ "effect of the O modifier is to use alternative numeric symbols (say, "
+ "roman numerals), and that of the E modifier is to use a locale-dependent "
+ "alternative representation.\n";
+
+
+
+static void show_help(GtkButton *button, GtkWidget *parent)
{
- cfg->voice = gconf_client_get_string(client, GCONF_KEY "/voice", NULL);
- cfg->effect = gconf_client_get_string(client, GCONF_KEY "/effect", NULL);
- cfg->text = gconf_client_get_string(client, GCONF_KEY "/text", NULL);
- cfg->amplitude = gconf_client_get_int(client, GCONF_KEY "/amplitude", NULL);
- cfg->pitch = gconf_client_get_int(client, GCONF_KEY "/pitch", NULL);
- cfg->speed = gconf_client_get_int(client, GCONF_KEY "/speed", NULL);
- cfg->ignore_silent = gconf_client_get_bool(client, GCONF_KEY "/ignore_silent", NULL);
- if (!cfg->voice)
- cfg->voice = g_strdup("en-us");
- if (!cfg->effect)
- cfg->effect = g_strdup("");
- if (!cfg->text)
- cfg->text = g_strdup("%H:%M");
- if (!cfg->amplitude)
- cfg->amplitude = 100;
- if (!cfg->pitch)
- cfg->pitch = 50;
- if (!cfg->speed)
- cfg->speed = 170;
- /* TODO: default ignore_silent to TRUE */
-}
+ GtkWidget *dialog, *label, *panarea;
-static void cfg_write(GConfClient *client, struct espeaktime_settings *cfg)
-{
- gconf_client_add_dir(client, GCONF_KEY, GCONF_CLIENT_PRELOAD_NONE, NULL);
- gconf_client_set_string(client, GCONF_KEY "/voice", cfg->voice, NULL);
- gconf_client_set_string(client, GCONF_KEY "/effect", cfg->effect, NULL);
- gconf_client_set_string(client, GCONF_KEY "/text", cfg->text, NULL);
- gconf_client_set_int(client, GCONF_KEY "/amplitude", cfg->amplitude, NULL);
- gconf_client_set_int(client, GCONF_KEY "/pitch", cfg->pitch, NULL);
- gconf_client_set_int(client, GCONF_KEY "/speed", cfg->speed, NULL);
- gconf_client_set_bool(client, GCONF_KEY "/ignore_silent", cfg->ignore_silent, NULL);
-}
+ dialog = gtk_dialog_new_with_buttons(
+ "eSpeakTime Help",
+ GTK_WINDOW(parent),
+ GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR,
+ GTK_STOCK_OK, GTK_RESPONSE_OK,
+ NULL);
-static void cfg_free(struct espeaktime_settings *cfg)
-{
- g_free(cfg->voice);
- g_free(cfg->effect);
- g_free(cfg->text);
-}
+ label = gtk_label_new(help_message);
+ gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
+ gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
-static void cfg_speak(struct espeaktime_settings *cfg, gboolean test_mode)
-{
- 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 (%s)\n", res, g_strerror(errno));
- exit(res);
-}
+ panarea = hildon_pannable_area_new();
+ gtk_widget_set_size_request(panarea, -1, 800);
+ hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA(panarea), label);
+ gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), panarea);
+ g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog);
+ gtk_widget_show_all(dialog);
+}
static void add_scale(GtkVBox *vbox, GtkSizeGroup *size_group, const char *caption, GtkAdjustment *adjustment)
{
gtk_button_set_alignment(GTK_BUTTON(effect), 0.0, 0.5);
gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(effect), FALSE, FALSE, 0);
+ GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(vbox), hbox, 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),
+ gtk_box_pack_start(GTK_BOX(hbox),
hildon_caption_new(title_group, "Speech string", GTK_WIDGET(text), NULL, HILDON_CAPTION_MANDATORY),
- FALSE, FALSE, 0);
+ TRUE, TRUE, 0);
+
+ GtkWidget *help_btn = hildon_button_new_with_text(HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT,
+ HILDON_BUTTON_ARRANGEMENT_HORIZONTAL, " ? ", NULL);
+ g_signal_connect(help_btn, "clicked", G_CALLBACK(show_help), dialog);
+ gtk_box_pack_start(GTK_BOX(hbox), help_btn, FALSE, FALSE, 0);
GtkAdjustment *amplitude_adj = GTK_ADJUSTMENT(gtk_adjustment_new(cfg.amplitude, 0, 200, 1, 10, 0));
add_scale(vbox, title_group, "Amplitude", amplitude_adj);
add_scale(vbox, title_group, "Pitch", pitch_adj);
GtkAdjustment *speed_adj = GTK_ADJUSTMENT(gtk_adjustment_new(cfg.speed, 80, 390, 1, 10, 0));
- add_scale(vbox, title_group, "Words per minute", speed_adj);
+ add_scale(vbox, title_group, "Speed (wpm)", speed_adj);
HildonCheckButton *ignore_silent = HILDON_CHECK_BUTTON(hildon_check_button_new(HILDON_SIZE_FINGER_HEIGHT));
hildon_check_button_set_active(ignore_silent, cfg.ignore_silent);