From 3311a3252a30953d79b813775e3c553f1cb4c8cc Mon Sep 17 00:00:00 2001 From: Radek Kintop Date: Mon, 3 Apr 2017 17:32:38 +0200 Subject: [PATCH] Voice Control view and model binding Change-Id: I249d18bc2f8c68f1258e5f62e02d8bf0233a54c0 Signed-off-by: Radek Kintop Signed-off-by: Kiseok Chang --- include/data/system/settings_voice_control.h | 1 + include/view/system/view_voice_control.h | 1 - po/en.po | 3 + po/ko_KR.po | 3 + src/common/datamgr.c | 4 +- src/data/system/settings_voice_control.c | 59 ++++++++++- src/layout/layout_system.c | 52 ++-------- src/main.c | 6 ++ src/view/system/view_voice_control.c | 148 ++++++++++++++++++++++++++- 9 files changed, 228 insertions(+), 49 deletions(-) mode change 100644 => 100755 src/data/system/settings_voice_control.c diff --git a/include/data/system/settings_voice_control.h b/include/data/system/settings_voice_control.h index c3e5255..8781e9f 100644 --- a/include/data/system/settings_voice_control.h +++ b/include/data/system/settings_voice_control.h @@ -20,5 +20,6 @@ #include "common/datamgr.h" struct data_class *get_voice_control_data_class(void); +char *settings_voice_control_status_str(void); #endif /* INCLUDE_DATA_SYSTEM_SETTINGS_VOICE_CONTROL_H_ */ diff --git a/include/view/system/view_voice_control.h b/include/view/system/view_voice_control.h index 7391c33..147b637 100644 --- a/include/view/system/view_voice_control.h +++ b/include/view/system/view_voice_control.h @@ -21,5 +21,4 @@ view_class *view_voice_control_get_vclass(void); - #endif /* INCLUDE_VIEW_SYSTEM_VIEW_VOICE_CONTROL_H_ */ diff --git a/po/en.po b/po/en.po index 8cd0637..a0400d5 100644 --- a/po/en.po +++ b/po/en.po @@ -2269,6 +2269,9 @@ msgstr "4 processes at most" msgid "IDS_ST_HEADER_ENTER_PIN_ABB3" msgstr "Enter PIN" +msgid "IDS_ST_HEADER_VOICE_CONTROL" +msgstr "Voice Control" + msgid "IDS_ST_OPT_2G_ONLY" msgstr "2G only" diff --git a/po/ko_KR.po b/po/ko_KR.po index dc750cb..38acbe2 100644 --- a/po/ko_KR.po +++ b/po/ko_KR.po @@ -2242,6 +2242,9 @@ msgstr "프로세스 최대 4개" msgid "IDS_ST_HEADER_ENTER_PIN_ABB3" msgstr "PIN 입력" +msgid "IDS_ST_HEADER_VOICE_CONTROL" +msgstr "목소리 통제" + msgid "IDS_ST_OPT_2G_ONLY" msgstr "2G 전용" diff --git a/src/common/datamgr.c b/src/common/datamgr.c index 3bf757e..d184e97 100644 --- a/src/common/datamgr.c +++ b/src/common/datamgr.c @@ -77,8 +77,8 @@ bool datamgr_update(struct datamgr *dmgr) bool datamgr_select(struct datamgr *dmgr, Elm_Object_Item *it, void *data) { - if (!dmgr || !it) { - _ERR("Invalid argument."); + if (!dmgr) { + _ERR("Invalid argument"); return false; } diff --git a/src/data/system/settings_voice_control.c b/src/data/system/settings_voice_control.c old mode 100644 new mode 100755 index 4f0037e..c1a7ad5 --- a/src/data/system/settings_voice_control.c +++ b/src/data/system/settings_voice_control.c @@ -17,6 +17,7 @@ #include #include #include "app_debug.h" +#include "app_string.h" #include "data/system/settings_voice_control.h" static void *_create(void (*event_cb)(enum event_type type, void *data), @@ -34,6 +35,8 @@ static struct data_class vc_class = { .get_data = _get_data }; +static bool vc_initialised = false; + typedef struct { void (*event_cb)(enum event_type type, void *data); void *cb_data; @@ -45,6 +48,35 @@ struct data_class *get_voice_control_data_class(void) return &vc_class; } +char *settings_voice_control_status_str(void) +{ + int ret = VC_ERROR_NONE; + bool on_off = false; + + if (!vc_initialised) + { + ret = vc_setting_initialize(); + if (VC_ERROR_NONE != ret) { + _ERR("VC init error: %s", get_error_message(ret)); + return strdup(""); + } + vc_initialised = true; + } + + ret = vc_setting_get_enabled(&on_off); + + if (VC_ERROR_NONE != ret) { + _ERR("VC get enabled error: %s", get_error_message(ret)); + return strdup(""); + } + + if (on_off) { + return strdup(_("IDS_ST_BODY_ON")); + } else { + return strdup(_("IDS_ST_BODY_OFF")); + } +} + static void _voice_control_changed_cb(bool enabled, void *data) { private_data *priv = data; @@ -78,9 +110,27 @@ static void *_create(void (*event_cb)(enum event_type type, void *data), priv->event_cb = event_cb; priv->cb_data = cb_data; + if (!vc_initialised) + { + ret = vc_setting_initialize(); + if (VC_ERROR_NONE != ret) { + free(priv); + _ERR("VC init error: %s", get_error_message(ret)); + return NULL; + } + vc_initialised = true; + } + + ret = vc_setting_set_auto_language(true); + if (VC_ERROR_NONE != ret) { + _DBG("VC set auto language error: %s", get_error_message(ret)); + } + ret = vc_setting_set_enabled_changed_cb(_voice_control_changed_cb , priv); if (VC_ERROR_NONE != ret) { free(priv); + vc_initialised = false; + vc_setting_deinitialize(); _ERR("VC callback set error: %s", get_error_message(ret)); return NULL; } @@ -90,6 +140,8 @@ static void *_create(void (*event_cb)(enum event_type type, void *data), if (VC_ERROR_NONE != ret) { free(priv); _ERR("VC get enabled error: %s", get_error_message(ret)); + vc_initialised = false; + vc_setting_deinitialize(); return NULL; } @@ -102,13 +154,18 @@ static bool _destroy(void *data) if (VC_ERROR_NONE != ret) { _ERR("VC unset callback error: %s", get_error_message(ret)); } + free(data); + + (void)vc_setting_deinitialize(); + vc_initialised = false; + return (VC_ERROR_NONE == ret); } static bool _update(void *data) { int ret = VC_ERROR_NONE; - private_data *priv = NULL; + private_data *priv = data; ret = vc_setting_get_enabled(&(priv->voice_control_is_on)); if (VC_ERROR_NONE != ret) { diff --git a/src/layout/layout_system.c b/src/layout/layout_system.c index cbb76c7..f3d8558 100755 --- a/src/layout/layout_system.c +++ b/src/layout/layout_system.c @@ -26,6 +26,7 @@ #include "common/viewmgr.h" #include "data/system/settings_clock.h" #include "data/system/settings_language.h" +#include "data/system/settings_voice_control.h" #include "define.h" #include "layout.h" #include "layout/system.h" @@ -92,7 +93,7 @@ static struct menumgr_info menu_info[] = { .style = STYLE_STATUS_BTN, .disabled = EINA_FALSE, .status = _get_voice_control_status, - .selected = NULL, + .selected = _selected, .focused = _focused, .selected_menu = _selected_menu, .progress_value = NULL, @@ -110,7 +111,7 @@ static struct menumgr_info menu_info[] = { .progress_value = NULL, .progress_evas = NULL, .update_cb = NULL - }, + } }; static char *_get_clock_mode(void *data, int id) @@ -125,50 +126,9 @@ static char *_get_language(void *data, int id) static char *_get_voice_control_status(void *data, int id) { - return strdup("OFF"); + return settings_voice_control_status_str(); } -/* -static char *_get_location(void *data, int id) -{ - char *country = NULL; - char *lang = NULL; - char name[64] = {'\0'}; - i18n_uchar res[64] = {0,}; - int r = SYSTEM_SETTINGS_ERROR_NONE; - - r = system_settings_get_value_string( - SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &lang); - if (r != SYSTEM_SETTINGS_ERROR_NONE) { - _ERR("failed to get language"); - return strdup(STR_UNKNOWN); - } - - r = system_settings_get_value_string( - SYSTEM_SETTINGS_KEY_LOCALE_COUNTRY, &country); - if (r != SYSTEM_SETTINGS_ERROR_NONE) { - _ERR("failed to get country"); - free(lang); - return strdup(STR_UNKNOWN); - } - - r = i18n_ulocale_get_display_country(country, lang, res, sizeof(res)); - if (r < 0) { - _ERR("failed to get display country: %s", get_last_result()); - free(lang); - free(country); - return strdup(STR_UNKNOWN); - } - - i18n_ustring_copy_au(name, res); - - free(lang); - free(country); - - return strdup(name); -} -*/ - void set_callback_for_system_location_change(void *data) { if (data) { @@ -189,6 +149,10 @@ static void _selected(void *data, int id) if (!viewmgr_show_view(VIEW_LANGUAGE)) _ERR("Show Language view failed."); break; + case MENU_VOICE_CONTROL: + if (!viewmgr_show_view(VIEW_VOICE_CONTROL)) + _ERR("Show Language view failed."); + break; case MENU_RESET: if (!viewmgr_show_view(VIEW_RESET)) _ERR("Show reset view failed."); diff --git a/src/main.c b/src/main.c index b916247..31d80ee 100644 --- a/src/main.c +++ b/src/main.c @@ -27,6 +27,7 @@ #include "view/picture/view_picture_tint.h" #include "view/system/view_clock.h" #include "view/system/view_language.h" +#include "view/system/view_voice_control.h" #include "view/system/view_reset.h" #include "data/system/settings_language.h" @@ -215,6 +216,11 @@ static bool _create_system_ui(void) return false; } + if (!viewmgr_add_view(view_voice_control_get_vclass(), NULL)) { + _ERR("Add voice control view failed."); + return false; + } + if (!viewmgr_add_view(view_reset_get_vclass(), NULL)) { _ERR("Adding reset view failed."); return false; diff --git a/src/view/system/view_voice_control.c b/src/view/system/view_voice_control.c index 1c69527..e98b35e 100644 --- a/src/view/system/view_voice_control.c +++ b/src/view/system/view_voice_control.c @@ -16,11 +16,22 @@ #include #include "app_debug.h" +#include "app_string.h" +#include "common/datamgr.h" +#include "common/inputmgr.h" +#include "common/utils.h" #include "define.h" #include "view/system/view_voice_control.h" +#include "data/system/settings_voice_control.h" + +#define BUTTON_ID_ON 0 +#define BUTTON_ID_OFF 1 typedef struct { Evas_Object *base; + Evas_Object *on_button; + Evas_Object *off_button; + struct datamgr *data_mgr; } private_data; static Evas_Object *_create(Evas_Object *win, void *data); @@ -28,6 +39,11 @@ static void _show(void *data); static void _hide(void *data); static void _destroy(void *data); +static void _clicked_cb(int id, void *data, Evas_Object *obj); +static void _key_down_cb(int id, void *data, Evas *e, Evas_Object *obj, + Evas_Event_Key_Down *ev); +static void _vc_data_changed_cb(enum event_type type, void *data); + static view_class _vclass = { .view_id = VIEW_VOICE_CONTROL, .create = _create, @@ -36,6 +52,11 @@ static view_class _vclass = { .destroy = _destroy }; +static input_handler handler = { + .key_down = _key_down_cb, + .clicked = _clicked_cb +}; + view_class *view_voice_control_get_vclass(void) { return &_vclass; @@ -44,6 +65,13 @@ view_class *view_voice_control_get_vclass(void) static Evas_Object *_create(Evas_Object *win, void *data) { private_data *priv = NULL; + Evas_Object *ly = NULL; + char part_name[PART_POPUP_BUTTON_STR_MAX_L] = {0, }; + + if (!win) { + _ERR("Win is NULL"); + return NULL; + } priv = calloc(1, sizeof(private_data)); if (!priv) { @@ -52,8 +80,65 @@ static Evas_Object *_create(Evas_Object *win, void *data) return NULL; } + priv->base = utils_add_popup(win, NULL, STR_LANGUAGE, NULL); + if (!priv->base) { + _ERR("Adding popup failed"); + free(priv); + return NULL; + } + + ly = utils_add_layout(priv->base, GRP_VIEW_POPUP_2BTNS, EINA_FALSE); + if (!ly) { + _ERR("Adding layout failed"); + evas_object_del(priv->base); + free(priv); + return NULL; + } + + elm_object_translatable_part_text_set(ly, PART_POPUP_NAME, + _("IDS_ST_HEADER_VOICE_CONTROL")); + + snprintf(part_name, sizeof(part_name), PART_POPUP_BUTTON_X, BUTTON_ID_ON); + priv->on_button = utils_add_button(ly, part_name, NULL, + "IDS_ST_BODY_ON"); + if (!priv->on_button) { + _ERR("Adding on_button failed"); + evas_object_del(priv->base); + free(priv); + return NULL; + } + inputmgr_add_callback(priv->on_button, BUTTON_ID_ON, &handler, priv); + + snprintf(part_name, sizeof(part_name), PART_POPUP_BUTTON_X, BUTTON_ID_OFF); + priv->off_button = utils_add_button(ly, part_name, NULL, + "IDS_ST_BODY_OFF"); + if (!priv->off_button) { + _ERR("Adding off_button failed"); + inputmgr_remove_callback(priv->on_button, &handler); + evas_object_del(priv->base); + free(priv); + return NULL; + } + inputmgr_add_callback(priv->off_button, BUTTON_ID_OFF, &handler, priv); + + priv->data_mgr = datamgr_create(get_voice_control_data_class(), + _vc_data_changed_cb, priv); + if (!priv->data_mgr) { + _ERR("Creating datamgr unsuccessfull"); + inputmgr_remove_callback(priv->on_button, &handler); + inputmgr_remove_callback(priv->off_button, &handler); + evas_object_del(priv->base); + free(priv); + return NULL; + } + + elm_object_content_set(priv->base, ly); + if (!viewmgr_set_view_data(VIEW_VOICE_CONTROL, priv)) { _ERR("Set view data failed."); + datamgr_destroy(priv->data_mgr); + inputmgr_remove_callback(priv->on_button, &handler); + inputmgr_remove_callback(priv->off_button, &handler); evas_object_del(priv->base); free(priv); return NULL; @@ -65,10 +150,20 @@ static Evas_Object *_create(Evas_Object *win, void *data) static void _show(void *data) { private_data *priv = data; + bool on_off; if (!priv) { _ERR("!priv"); return; } + + on_off = (Eina_Bool)datamgr_get_data(priv->data_mgr); + + if (on_off) { + elm_object_focus_set(priv->on_button, EINA_TRUE); + } else { + elm_object_focus_set(priv->off_button, EINA_TRUE); + } + evas_object_show(priv->base); } static void _hide(void *data) @@ -79,7 +174,7 @@ static void _hide(void *data) _ERR("!priv"); return; } - + evas_object_hide(priv->base); } static void _destroy(void *data) @@ -90,4 +185,55 @@ static void _destroy(void *data) _ERR("!priv"); return; } + evas_object_del(priv->base); + datamgr_destroy(priv->data_mgr); + free(priv); +} + +static void _clicked_cb(int id, void *data, Evas_Object *obj) +{ + private_data *priv = data; + if (!priv) { + _ERR("!priv"); + return; + } + + if (BUTTON_ID_ON == id) + datamgr_select(priv->data_mgr, NULL, (void *)true); + if (BUTTON_ID_OFF == id) + datamgr_select(priv->data_mgr, NULL, (void *)false); + + viewmgr_pop_view(); +} + +static void _key_down_cb(int id, void *data, Evas *e, Evas_Object *obj, + Evas_Event_Key_Down *ev) +{ + private_data *priv = data; + if (!ev || !priv) { + _ERR("Invalid argument."); + return; + } + + if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_WAY)) + viewmgr_pop_view(); +} + +static void _vc_data_changed_cb(enum event_type type, void *data) +{ + private_data *priv = data; + bool on_off; + if (!priv) { + _ERR("!priv"); + return; + } + + on_off = (Eina_Bool)datamgr_get_data(priv->data_mgr); + + if (on_off) { + elm_object_focus_set(priv->on_button, EINA_TRUE); + } else { + elm_object_focus_set(priv->off_button, EINA_TRUE); + } + evas_object_show(priv->base); } -- 2.7.4