2 * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <Elementary.h>
21 #include <voice_control_setting.h>
22 #include <app_control_internal.h>
24 #include <tzsh_quickpanel_service.h>
28 #include "common_uic.h"
29 #include "voice_control.h"
30 #include "quickpanel-ui.h"
31 #include "list_util.h"
34 static int _init(void *data);
35 static int _fini(void *data);
36 Evas_Object* _voice_control_view_create(void *data);
37 static void _voice_control_register_event(void *data);
38 static bool _check_voice_control_enabled(void);
40 QP_Module voice_control = {
41 .name = "voice_control",
55 static Evas_Object *g_layout = NULL;
57 static void _voice_control_view_destroy(void *data)
59 DBG("_voice_control_view_destroy");
60 struct appdata *ad = data;
70 ERR("g_layout is not exist");
74 quickpanel_list_util_item_unpack_by_object(ad->list, g_layout, 0, 0);
75 quickpanel_list_util_item_del_tag(g_layout);
76 elm_object_signal_emit(ad->ly, "voice_icon.hide", "quickpanel.prog");
78 if (g_layout != NULL) {
79 evas_object_del(g_layout);
84 static int _init(void *data)
86 struct appdata *ad = (struct appdata *)data;
88 if (0 != vc_setting_initialize()) {
93 _voice_control_register_event(data);
95 if (_check_voice_control_enabled()) { //when module restart
96 _voice_control_view_create(ad);
102 static int _fini(void *data)
104 struct appdata *ad = (struct appdata *)data;
106 if (0 != vc_setting_deinitialize()) {
107 ERR("Fail to vc_setting_deinitialize");
110 _voice_control_view_destroy(ad);
115 static void _vc_enabled_changed_cb(bool enabled, void* user_data)
117 DBG("_vc_enabled_changed_cb");
118 struct appdata *ad = user_data;
120 if( !enabled ) { //deactivated voice controller
121 _voice_control_view_destroy(ad);
123 _voice_control_view_create(ad);
127 static void _voice_control_register_event(void *data)
129 DBG("_voice_control_register_event");
130 if (0 != vc_setting_set_enabled_changed_cb(_vc_enabled_changed_cb, data)) {
131 ERR("Fail to set enabled cb");
136 static bool _check_voice_control_enabled(void)
138 bool enabled = false;
140 if (0 != vc_setting_get_enabled(&enabled)) {
141 ERR("Fail to get enabled");
143 DBG("_check_voice_control_enabled enabled %d",enabled);
148 static void _button_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
150 DBG("_button_clicked_cb");
152 quickpanel_uic_launch_ug_by_appcontrol(VOICE_CONTOL_REF_APP, NULL);
153 quickpanel_uic_launch_app_inform_result(VOICE_CONTOL_REF_APP, ret);
154 quickpanel_uic_close_quickpanel(true, 1);
158 Evas_Object* _voice_control_view_create(void *data)
160 DBG("_voice_control_view_create");
161 struct appdata *ad = data;
162 Evas_Object *layout = NULL;
163 Eina_Bool ret = EINA_FALSE;
165 if (!_check_voice_control_enabled()) {
166 ERR("voice control is not enabled.");
171 ERR("invalid parent");
177 ERR("voice control view is already created.");
181 layout = elm_layout_add(ad->win);
184 ERR("Failed to create voice control layout");
190 ret = elm_layout_file_set(layout, VOICE_CONTOL_EDJ, "quickpanel/voice_control/default");
191 if (ret == EINA_FALSE)
193 ERR("Failed to set layout file[%d]", ret);
194 evas_object_del(layout);
198 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
199 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
200 evas_object_show(layout);
202 elm_object_signal_callback_add(layout, "button_clicked" , "", _button_clicked_cb, ad);
203 elm_object_signal_emit(ad->ly, "voice_icon.show", "quickpanel.prog");
206 qp_item_data *qid = quickpanel_list_util_item_new(QP_ITEM_TYPE_VOICE_CONTOL, layout);
207 quickpanel_list_util_item_set_tag(layout, qid);
208 quickpanel_list_util_sort_insert(ad->list, layout);
209 quickpanel_uic_initial_resize(layout, QP_VOICE_CONTOL_HEIGHT);