2 * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
4 * This file is a modified version of BSD licensed file and
5 * licensed under the Flora License, Version 1.1 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://floralicense.org/license/
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an AS IS BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * Please, see the LICENSE file for the original copyright owner and
22 #include <Ecore_Evas.h>
24 #include <atspi/atspi.h>
25 #include <tone_player.h>
27 #include "screen_reader_tts.h"
28 #include "screen_reader_haptic.h"
29 #include "smart_notification.h"
31 #define RED "\x1B[31m"
32 #define RESET "\033[0m"
34 static Eina_Bool status = EINA_FALSE;
36 static void _smart_notification_focus_chain_end(void);
37 static void _smart_notification_realized_items(int start_idx, int end_idx);
40 * @brief Smart Notifications event handler
42 * @param nt Notification event type
43 * @param start_index int first visible items index smart_notification_realized_items
44 * @param end_index int last visible items index used for smart_notification_realized_items
46 void smart_notification(Notification_Type nt, int start_index, int end_index)
54 case FOCUS_CHAIN_END_NOTIFICATION_EVENT:
55 _smart_notification_focus_chain_end();
57 case REALIZED_ITEMS_NOTIFICATION_EVENT:
58 _smart_notification_realized_items(start_index, end_index);
61 DEBUG("Gesture type %d not handled in switch", nt);
66 * @brief Used for getting first and last index of visible items
68 * @param scrollable_object AtspiAccessible object on which scroll was triggered
69 * @param start_index int first visible items index smart_notification_realized_items
70 * @param end_index int last visible items index used for smart_notification_realized_items
72 void get_realized_items_count(AtspiAccessible *scrollable_object, int *start_idx, int *end_idx)
76 AtspiAccessible *child_iter;
77 AtspiStateType state = ATSPI_STATE_SHOWING;
79 if(!scrollable_object)
81 DEBUG("No scrollable object");
85 count_child = atspi_accessible_get_child_count(scrollable_object, NULL);
87 for(jdx = 0; jdx < count_child; jdx++)
89 child_iter = atspi_accessible_get_child_at_index(scrollable_object, jdx, NULL);
90 if (!child_iter) continue;
92 AtspiStateSet* state_set = atspi_accessible_get_state_set(child_iter);
94 gboolean is_visible = atspi_state_set_contains(state_set, state);
98 DEBUG("Item with index %d is visible", jdx);
101 DEBUG("Item with index %d is NOT visible", jdx);
103 *end_idx = *start_idx + 8;
107 * @brief Scroll-start/Scroll-end event callback
109 * @param event AtspiEvent
110 * @param user_data UNUSED
114 _scroll_event_cb(AtspiEvent *event, gpointer user_data)
119 int start_index, end_index;
123 gchar *role_name = atspi_accessible_get_role_name(event->source, NULL);
124 fprintf(stderr, "Event: %s: %d, obj: %p: role: %s\n",
125 event->type, event->detail1, event->source,
129 if (!strcmp(event->type, "object:scroll-start"))
131 DEBUG("Scrolling started");
132 tts_speak("Scrolling started", EINA_TRUE);
134 else if (!strcmp(event->type, "object:scroll-end"))
136 DEBUG("Scrolling finished");
137 tts_speak("Scrolling finished", EINA_FALSE);
138 get_realized_items_count((AtspiAccessible *)event->source, &start_index, &end_index);
139 _smart_notification_realized_items(start_index, end_index);
144 * @brief Initializer for smart notifications
148 void smart_notification_init(void)
150 DEBUG("Smart Notification init!");
152 AtspiEventListener *listener;
154 listener = atspi_event_listener_new(_scroll_event_cb, NULL, NULL);
155 atspi_event_listener_register(listener, "object:scroll-start", NULL);
156 atspi_event_listener_register(listener, "object:scroll-end", NULL);
158 haptic_module_init();
164 * @brief Smart notifications shutdown
167 void smart_notification_shutdown(void)
173 * @brief Smart notifications focus chain event handler
176 static void _smart_notification_focus_chain_end(void)
181 DEBUG(RED"Smart notification - FOCUS CHAIN END"RESET);
184 tone_player_start(TONE_TYPE_SUP_CONFIRM, SOUND_TYPE_MEDIA, 200, NULL);
188 * @brief Smart notifications realized items event handler
191 static void _smart_notification_realized_items(int start_idx, int end_idx)
196 if(start_idx == end_idx)
199 DEBUG(RED"Smart notification - Visible items notification"RESET);
203 snprintf(buf, sizeof(buf), _("IDS_REACHED_ITEMS_NOTIFICATION"), start_idx, end_idx);
205 tts_speak(strdup(buf), EINA_FALSE);