X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=test%2Fsimple-at.c;h=16c16f1a0ebab886c9e37eec1a5e89b17db0c8cd;hb=10693361faaa0aed1c8b887ddaa2fbda774351e4;hp=a0438f2305b4e4a38edd4ae5860ddd3d73f912be;hpb=fdf87471b3d56d7a66d31f33c1ef3d631e9ef51c;p=platform%2Fcore%2Fuifw%2Fat-spi2-atk.git diff --git a/test/simple-at.c b/test/simple-at.c index a0438f2..16c16f1 100644 --- a/test/simple-at.c +++ b/test/simple-at.c @@ -21,11 +21,28 @@ */ #include +#include +#include #include "spi.h" -void report_focus_event (void *fp); +static void report_focus_event (void *fp); +static void report_button_press (void *fp); +static boolean report_key_event (void *fp); +static void check_property_change (void *fp); +static void get_environment_vars (void); -void report_button_press (void *fp); +static int _festival_init (); +static void _festival_say (const char *text, const char *voice, boolean shutup); +static void _festival_write (const char *buff, int fd); + +static boolean use_magnifier = FALSE; +static boolean use_festival = FALSE; +static boolean festival_chatty = FALSE; + +static AccessibleEventListener *focus_listener; +static AccessibleEventListener *property_listener; +static AccessibleEventListener *button_listener; +static KeystrokeListener *key_listener; int main(int argc, char **argv) @@ -35,18 +52,23 @@ main(int argc, char **argv) int n_apps; Accessible *desktop; Accessible *application; - AccessibleEventListener *focus_listener; - AccessibleEventListener *button_listener; - - SPI_init(); - focus_listener = CreateEventListener (report_focus_event); - button_listener = CreateEventListener (report_button_press); + if ((argc > 1) && (!strncmp(argv[1],"-h",2))) + { + printf ("Usage: simple-at\n"); + printf ("\tEnvironment variables used:\n\t\tFESTIVAL\n\t\tMAGNIFIER\n\t\tFESTIVAL_CHATTY\n"); + exit(0); + } - RegisterGlobalEventListener (focus_listener, "focus:"); - RegisterGlobalEventListener (button_listener, "Gtk:GtkWidget:button-press-event"); + SPI_init(); - n_desktops = GetDesktopCount (); + focus_listener = createEventListener (report_focus_event); + property_listener = createEventListener (check_property_change); + button_listener = createEventListener (report_button_press); + registerGlobalEventListener (focus_listener, "focus:"); + registerGlobalEventListener (property_listener, "object:property-change:accessible-selection"); + registerGlobalEventListener (button_listener, "Gtk:GtkWidget:button-press-event"); + n_desktops = getDesktopCount (); for (i=0; itype, + Accessible_getName (&ev->source)); + report_focussed_accessible (&ev->source, TRUE); } void -report_focus_event (void *fp) +report_button_press (void *p) { - fprintf (stderr, "focus\n"); + AccessibleEvent *ev = (AccessibleEvent *) p; + fprintf (stderr, "%s event from %s\n", ev->type, + Accessible_getName (&ev->source)); } + void -report_button_press (void *fp) +check_property_change (void *p) +{ + AccessibleEvent *ev = (AccessibleEvent *) p; + AccessibleSelection *selection = Accessible_getSelection (&ev->source); + int n_selections; + int i; + if (selection) + { + n_selections = (int) AccessibleSelection_getNSelectedChildren (selection); + fprintf (stderr, "(Property) %s event from %s, %d selected children\n", ev->type, + Accessible_getName (&ev->source), n_selections); + /* for now, speak entire selection set */ + for (i=0; ikeyID) + { + case 'Q': + case 'q': + simple_at_exit(); + return TRUE; /* not reached */ + case 'M': + case 'm': + use_magnifier = ! use_magnifier; + return TRUE; + case 'F': + case 'f': + use_festival = ! use_festival; + return TRUE; + default: + return FALSE; + } +} + +static boolean +report_key_event (void *p) +{ + KeyStroke *key = (KeyStroke *) p; + fprintf(stderr, "KeyEvent %s%c (keycode %d)\n", + (key->modifiers & KEYMASK_ALT)?"Alt-":"", + ((key->modifiers & KEYMASK_SHIFT)^(key->modifiers & KEYMASK_SHIFTLOCK))? + (char) toupper((int) key->keyID) : (char) tolower((int) key->keyID), + (int) key->keycode); + return is_command_key (key); +} + +static int _festival_init () +{ + int fd; + struct sockaddr_in name; + int tries = 2; + + name.sin_family = AF_INET; + name.sin_port = htons (1314); + name.sin_addr.s_addr = htonl(INADDR_ANY); + fd = socket (PF_INET, SOCK_STREAM, 0); + + while (connect(fd, (struct sockaddr *) &name, sizeof (name)) < 0) { + if (!tries--) { + perror ("connect"); + return -1; + } + } + + _festival_write ("(audio_mode'async)\n", fd); + _festival_write ("(Parameter.set 'Duration_Model 'Tree_ZScore)\n", fd); + _festival_write ("(Parameter.set 'Duration_Stretch 0.75)\n", fd); + return fd; +} + +static void _festival_say (const char *text, const char *voice, boolean shutup) +{ + static int fd = 0; + gchar *quoted; + gchar *p; + gchar prefix[50]; + static gchar voice_spec[32]; + + if (!fd) + { + fd = _festival_init (); + } + + fprintf (stderr, "saying text: %s\n", text); + + quoted = g_malloc(64+strlen(text)*2); + + sprintf (prefix, "(SayText \""); + + strncpy(quoted, prefix, 10); + p = quoted+strlen(prefix); + while (*text) { + if ( *text == '\\' || *text == '"' ) + *p = '\\'; + *p++ = *text++; + } + *p++ = '"'; + *p++ = ')'; + *p++ = '\n'; + *p = 0; + + if (shutup) _festival_write ("(audio_mode'shutup)\n", fd); + if (voice && (strncmp (voice, (char *) (voice_spec+1), strlen(voice)))) + { + snprintf (voice_spec, 32, "(%s)\n", voice); + _festival_write (voice_spec, fd); + _festival_write ("(Parameter.set 'Duration_Model 'Tree_ZScore)\n", fd); + _festival_write ("(Parameter.set 'Duration_Stretch 0.75)\n", fd); + } + + _festival_write (quoted, fd); + + g_free(quoted); +} + +static void _festival_write (const gchar *command_string, int fd) +{ + fprintf(stderr, command_string); + if (fd < 0) { + perror("socket"); + return; + } + write(fd, command_string, strlen(command_string)); +} +