X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=test%2Fsimple-at.c;h=3fbf9fe2c24725bd897ae84ac50d09aa2cb170f9;hb=9bfdc127f8ae926e84a848740d98785ea3807f20;hp=d24344743614f6e8357ecc3c822e43fc50a05aa5;hpb=11518985294fd3a6847eac04c2dbde88f8e0d8b1;p=platform%2Fcore%2Fuifw%2Fat-spi2-atk.git diff --git a/test/simple-at.c b/test/simple-at.c index d243447..3fbf9fe 100644 --- a/test/simple-at.c +++ b/test/simple-at.c @@ -21,69 +21,419 @@ */ #include -#include "spi.h" +#include +#include +#include +#include +#include +#include "../util/mag_client.h" +#include "../cspi/spi-private.h" /* A hack for now */ -void report_focus_event (void *fp); +static void report_focus_event (AccessibleEvent *event, void *user_data); +static void report_generic_event (AccessibleEvent *event, void *user_data); +static void report_button_press (AccessibleEvent *event, void *user_data); +static void check_property_change (AccessibleEvent *event, void *user_data); +static SPIBoolean report_command_key_event (AccessibleKeystroke *stroke, void *user_data); +static SPIBoolean report_ordinary_key_event (AccessibleKeystroke *stroke, void *user_data); +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, SPIBoolean shutup); +static void _festival_write (const char *buff, int fd); + +static SPIBoolean use_magnifier = FALSE; +static SPIBoolean use_festival = FALSE; +static SPIBoolean festival_chatty = FALSE; + +static AccessibleEventListener *focus_listener; +static AccessibleEventListener *property_listener; +static AccessibleEventListener *generic_listener; +static AccessibleEventListener *button_listener; +static AccessibleKeystrokeListener *command_key_listener; +static AccessibleKeystrokeListener *ordinary_key_listener; int -main(int argc, char **argv) +main (int argc, char **argv) { int i, j; int n_desktops; int n_apps; Accessible *desktop; Accessible *application; - AccessibleEventListener *focus_listener; - AccessibleEventListener *button_listener; + char *s; - SPI_init(); + 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); + } - focus_listener = createEventListener (report_focus_event); - button_listener = createEventListener (report_button_press); + SPI_init (); + focus_listener = createAccessibleEventListener (report_focus_event, NULL); + property_listener = createAccessibleEventListener (check_property_change, NULL); + generic_listener = createAccessibleEventListener (report_generic_event, NULL); + button_listener = createAccessibleEventListener (report_button_press, NULL); registerGlobalEventListener (focus_listener, "focus:"); + registerGlobalEventListener (property_listener, "object:property-change:accessible-selection"); + registerGlobalEventListener (generic_listener, "object:selection-changed"); + registerGlobalEventListener (generic_listener, "object:children-changed"); + registerGlobalEventListener (generic_listener, "object:visible-data-changed"); + registerGlobalEventListener (generic_listener, "object:text-selection-changed"); + registerGlobalEventListener (generic_listener, "object:text-caret-moved"); + registerGlobalEventListener (generic_listener, "object:text-changed"); registerGlobalEventListener (button_listener, "Gtk:GtkWidget:button-press-event"); - n_desktops = getDesktopCount (); for (i=0; itype, - Accessible_getName (&ev->source)); - if (Accessible_isComponent (&ev->source)) + char *s; + int len; + + if (use_festival) + { + if (festival_chatty) + { + _festival_say (Accessible_getRole (obj), "voice_don_diphone", shutup_previous_speech); + } + fprintf (stderr, "getting Name\n"); + s = Accessible_getName (obj); + _festival_say (s, "voice_kal_diphone", + shutup_previous_speech || festival_chatty); + SPI_freeString (s); + } + + if (Accessible_isComponent (obj)) { long x, y, width, height; - AccessibleComponent *component = Accessible_getComponent (&ev->source); - fprintf (stderr, "Source implements IDL:Accessibility/Component:1.0\n"); + AccessibleComponent *component = Accessible_getComponent (obj); AccessibleComponent_getExtents (component, &x, &y, &width, &height, - COORD_TYPE_SCREEN); + SPI_COORD_TYPE_SCREEN); fprintf (stderr, "Bounding box: (%ld, %ld) ; (%ld, %ld)\n", x, y, x+width, y+height); + if (use_magnifier) { + magnifier_set_roi ((short) 0, x, y, width, height); + } + } + + if (Accessible_isValue (obj)) + { + AccessibleValue *value = Accessible_getValue (obj); + fprintf (stderr, "Current value = %f, min = %f; max = %f\n", + AccessibleValue_getCurrentValue (value), + AccessibleValue_getMinimumValue (value), + AccessibleValue_getMaximumValue (value)); } + /* if this is a text object, speak the first sentence. */ + + if (Accessible_isText(obj)) + + { + AccessibleText *text_interface; + long start_offset, end_offset; + char *first_sentence = "empty"; + text_interface = Accessible_getText (obj); + first_sentence = AccessibleText_getTextAtOffset ( + text_interface, (long) 0, SPI_TEXT_BOUNDARY_SENTENCE_START, &start_offset, &end_offset); + if (first_sentence) + { + _festival_say(first_sentence, "voice_don_diphone", FALSE); + SPI_freeString (first_sentence); + } + len = AccessibleText_getCharacterCount (text_interface); + s = AccessibleText_getText (text_interface, 0, len); + fprintf (stderr, "done reporting on focussed object, text=%s\n", s); + } +} + +void +report_focus_event (AccessibleEvent *event, void *user_data) +{ + char *s; + + g_return_if_fail (event->source != NULL); + + s = Accessible_getName (event->source); + if (cspi_warn_ev (cspi_ev (), "Report focus event")) + { + fprintf (stderr, "%s event from %s\n", event->type, s); + SPI_freeString (s); + report_focussed_accessible (event->source, TRUE); + } + Accessible_getParent (event->source); +} + +void +report_generic_event (AccessibleEvent *event, void *user_data) +{ + fprintf (stderr, "%s event received\n", event->type); } void -report_button_press (void *p) +report_button_press (AccessibleEvent *event, void *user_data) { - AccessibleEvent *ev = (AccessibleEvent *) p; - fprintf (stderr, "%s event from %s\n", ev->type, - Accessible_getName (&ev->source)); + char *s; + + g_return_if_fail (event->source != NULL); + + s = Accessible_getName (event->source); + + fprintf (stderr, "%s event from %s\n", event->type, s); + SPI_freeString (s); + s = Accessible_getDescription (event->source); + fprintf (stderr, "Object description %s\n", s); + SPI_freeString (s); +} + +void +check_property_change (AccessibleEvent *event, void *user_data) +{ + AccessibleSelection *selection = Accessible_getSelection (event->source); + int n_selections; + int i; + char *s; + if (selection) + { + n_selections = (int) AccessibleSelection_getNSelectedChildren (selection); + s = Accessible_getName (event->source); + fprintf (stderr, "(Property) %s event from %s, %d selected children\n", + event->type, s, n_selections); + SPI_freeString (s); + /* 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 SPIBoolean +report_command_key_event (AccessibleKeystroke *key, void *user_data) +{ + fprintf (stderr, "Command KeyEvent %s%c (keycode %d)\n", + (key->modifiers & SPI_KEYMASK_ALT)?"Alt-":"", + ((key->modifiers & SPI_KEYMASK_SHIFT)^(key->modifiers & SPI_KEYMASK_SHIFTLOCK))? + (char) toupper((int) key->keyID) : (char) tolower((int) key->keyID), + (int) key->keycode); + return is_command_key (key); +} + + +static SPIBoolean +report_ordinary_key_event (AccessibleKeystroke *key, void *user_data) +{ + fprintf (stderr, "Received key event:\tsym %ld\n\tmods %x\n\tcode %d\n\ttime %ld\n", + (long) key->keyID, + (unsigned int) key->modifiers, + (int) key->keycode, + (long int) key->timestamp); + return FALSE; +} + +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, SPIBoolean 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)); +} +