2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
7 * Unless required by applicable law or agreed to in writing, software
8 * distributed under the License is distributed on an "AS IS" BASIS,
9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 * See the License for the specific language governing permissions and
11 * limitations under the License.
18 #include <voice_control_setting.h>
20 #include "voice_control_panel_main.h"
21 #include "voice_control_panel_view.h"
22 #include "voice_control_panel_vc.h"
24 static void __vc_enabled_changed_cb(bool enabled, void* user_data)
26 LOGD("Voice control enabled changed to (%d)", enabled);
28 if (false == enabled) {
33 static bool app_create(void *data)
37 appdata *ad = (appdata *)data;
39 /* Check voice control enabled */
40 if (0 != vc_setting_initialize()) {
45 if (0 != vc_setting_get_enabled(&enabled)) {
46 LOGE("Fail to get enabled");
47 vc_setting_deinitialize();
50 if (false == enabled) {
51 LOGE("Voice control is disabled");
52 vc_setting_deinitialize();
56 if (0 != vc_setting_set_enabled_changed_cb(__vc_enabled_changed_cb, NULL)) {
57 LOGE("Fail to set enabled cb");
61 if (0 != vc_setting_get_language(&lang)) {
62 LOGE("Fail to get language");
66 char loc[64] = {'\0',};
67 snprintf(loc, 64, "%s.UTF-8", lang);
69 setlocale(LC_ALL, loc);
71 bindtextdomain("org.tizen.voice-control-panel", "/usr/apps/org.tizen.voice-control-panel/res/locale");
72 textdomain("org.tizen.voice-control-panel");
80 if (0 != vc_panel_view_create(ad)) {
81 LOGE( "[ERROR] Fail to create view");
85 /* Initialize Voice Control */
86 if (0 != vc_panel_vc_init(ad)) {
87 LOGE( "[ERROR] Fail to vc init");
94 static void app_control(app_control_h app_control, void *data)
98 appdata *ad = (appdata *)data;
99 LOGD("state - %d", ad->app_state);
101 if (0 != ad->app_state) {
107 elm_win_activate(ad->win);
109 ad->app_state = APP_STATE_INIT;
112 static void app_pause(void *data)
116 appdata *ad = (appdata *)data;
117 ad->app_state = APP_STATE_PAUSE;
121 static void app_resume(void *data)
125 appdata *ad = (appdata *)data;
126 if(ad->app_state == APP_STATE_PAUSE) {
128 elm_win_activate(ad->win);
131 ad->app_state = APP_STATE_SERVICE;
133 vc_panel_vc_start(ad);
136 static void app_terminate(void *data)
140 appdata *ad = (appdata *)data;
141 ad->app_state = APP_STATE_TERMINATE;
143 vc_panel_vc_cancel(ad);
145 vc_panel_view_destroy(ad);
147 vc_setting_deinitialize();
149 if (0 != vc_panel_vc_deinit(data)) {
150 LOGE( "[ERROR] Fail to vc deinit");
155 static void ui_app_lang_changed(app_event_info_h event_info, void *user_data)
160 static void ui_app_orient_changed(app_event_info_h event_info, void *user_data)
165 static void ui_app_region_changed(app_event_info_h event_info, void *user_data)
170 static void ui_app_low_battery(app_event_info_h event_info, void *user_data)
175 static void ui_app_low_memory(app_event_info_h event_info, void *user_data)
180 int main (int argc, char *argv[])
185 ui_app_lifecycle_callback_s event_callback = {0,};
186 app_event_handler_h handlers[5] = {NULL, };
188 event_callback.create = app_create;
189 event_callback.terminate = app_terminate;
190 event_callback.pause = app_pause;
191 event_callback.resume = app_resume;
192 event_callback.app_control = app_control;
194 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, ui_app_low_battery, &ad);
195 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, ui_app_low_memory, &ad);
196 ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, &ad);
197 ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, &ad);
198 ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, &ad);
200 ret = ui_app_main(argc, argv, &event_callback, &ad);
201 if (ret != APP_ERROR_NONE) {
202 LOGW("ui_app_main failed, Err=%d\n", ret);
209 vi:ts=4:ai:nowrap:expandtab