Language popup as separate view 26/59326/6
authorAgnieszka Janowicz <a.janowicz@samsung.com>
Fri, 12 Feb 2016 12:59:05 +0000 (13:59 +0100)
committerAgnieszka Janowicz <a.janowicz@samsung.com>
Mon, 15 Feb 2016 14:54:03 +0000 (15:54 +0100)
Change-Id: If67db733577069f4c50cfcca107b777b853727ee
Signed-off-by: Agnieszka Janowicz <a.janowicz@samsung.com>
13 files changed:
CMakeLists.txt
include/data/system/settings_language.h [new file with mode: 0644]
include/define.h
include/layout/system.h
include/view/system/view_language.h [new file with mode: 0644]
res/layout/system.edc
res/settings.edc
res/view/system/language.edc [new file with mode: 0644]
src/data/system/settings_language.c [new file with mode: 0644]
src/layout/layout_system.c
src/main.c
src/view/system/view_language.c [new file with mode: 0644]
src/view/system/view_sleep_timer.c

index 371719c..e89d1b5 100644 (file)
@@ -67,6 +67,7 @@ SET(SRCS
        src/view/system/view_sleep_timer.c
        src/view/system/view_wakeup_timer.c
        src/view/system/view_pincode.c
+       src/view/system/view_language.c
        src/view/system/view_location.c
        src/view/view_new_network.c
        src/common/utils.c
@@ -89,6 +90,7 @@ SET(SRCS
        src/data/system/settings_clock.c
        src/data/system/settings_wakeup_timer.c
        src/data/system/settings_pincode.c
+       src/data/system/settings_language.c
        src/data/system/data_wireless.c
        src/data/system/data_wired.c
    )
diff --git a/include/data/system/settings_language.h b/include/data/system/settings_language.h
new file mode 100644 (file)
index 0000000..e641a4c
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __AIR_SETTINGS_WAKEUP_TIMER_H__
+#define __AIR_SETTINGS_WAKEUP_TIMER_H__
+
+#include <stdbool.h>
+#include <time.h>
+
+typedef enum _language_type {
+       LANG_TYPE_ENG = 0,
+       LANG_TYPE_KOR,
+       LANG_TYPE_MAX
+} settings_language_type;
+
+/* Sets current language */
+void settings_language_set_language(settings_language_type lang_type);
+/* Gets current language ID */
+settings_language_type settings_language_get_language_id(void);
+/* Gets current locale language string.
+ * Note that the returned string needs to be freed after use. */
+char *settings_language_get_language_locale_str(void);
+/* Gets current display language string. */
+char *settings_language_get_language_display_str(void);
+
+#endif /* __AIR_SETTINGS_WAKEUP_TIMER_H__ */
index 7010bf2..8b45a33 100644 (file)
@@ -32,6 +32,7 @@
 #define VIEW_NEW_NETWORK "VIEW_NEW_NETWORK"
 #define VIEW_WAKEUP_TIMER "VIEW_WAKEUP_TIMER"
 #define VIEW_SLEEP_TIMER "VIEW_SLEEP_TIMER"
+#define VIEW_LANGUAGE "VIEW_LANGUAGE"
 
 /* Layout ID */
 #define LAYOUT_ID_PICTURE "LAYOUT_ID_PICTURE"
@@ -51,6 +52,7 @@
 #define GRP_VIEW_NEW_NETWORK "grp.view.new_network"
 #define GRP_VIEW_WAKEUP_TIMER "grp.view.wakeup_timer"
 #define GRP_VIEW_SLEEP_TIMER "grp.view.sleep_timer"
+#define GRP_VIEW_LANGUAGE "grp.view.language"
 
 /* Part for EDC */
 #define PART_TOP_TITLE "part.top.title"
index a5a077f..b919b9f 100644 (file)
 
 /* group */
 #define GRP_LAYOUT_SYSTEM "grp.layout.system"
-#define GRP_POPUP_LANGUAGE "grp.popup.language"
 
 /* part */
 #define PART_SYSTEM "part.system"
 
-#define POPUP_SLEEP_TIMER_BTN_COUNT 6
-#define POPUP_LANGUAGE_BTN_COUNT 2
-
 #define PART_LOCATION_TEXT  "part.location.text"
 #define PART_LOCATION_MENU1  "part.location.menu1"
 #define PART_LOCATION_MENU2  "part.location.menu2"
diff --git a/include/view/system/view_language.h b/include/view/system/view_language.h
new file mode 100644 (file)
index 0000000..aca333f
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __AIR_SETTINGS_VIEW_LANGUAGE_H__
+#define __AIR_SETTINGS_VIEW_LANGUAGE_H__
+
+view_class *view_language_get_vclass(void);
+
+#endif /* __AIR_SETTINGS_VIEW_LANGUAGE_H__ */
index 2b4351a..b425495 100644 (file)
@@ -84,134 +84,3 @@ group {
                }
        }
 }
-
-
-
-group {
-       name, GRP_POPUP_LANGUAGE;
-       parts {
-               part {
-                       name, "area";
-                       type, RECT;
-                       scale, 1;
-                       description {
-                               state, "default" 0.0;
-                               visible, 0;
-                       }
-               }
-
-               part {
-                       name, "padding.title";
-                       type, SPACER;
-                       scale, 1;
-                       description {
-                               state, "default" 0.0;
-                               min, 0 24;
-                               rel1.to, "area";
-                               rel2 {
-                                       to, "area";
-                                       relative, 1.0 0.0;
-                               }
-                               align, 0.5 0.0;
-                               fixed, 0 1;
-                       }
-               }
-
-               part {
-                       name, PART_POPUP_NAME;
-                       type, TEXT;
-                       scale, 1;
-                       description {
-                               state, "default" 0.0;
-                               min, 0 32;
-                               rel1 {
-                                       to, "padding.title";
-                                       relative, 0.0 1.0;
-                               }
-                               rel2.to, "padding.title";
-                               align, 0.5 0.0;
-                               fixed, 0 1;
-                               color, COLOR_TEXT_POPUP;
-                               text {
-                                       font, FONT_LIGHT;
-                                       size, 32;
-                               }
-                       }
-               }
-
-               part {
-                       name, "padding.lang1";
-                       type, SPACER;
-                       scale, 1;
-                       description {
-                               state, "default" 0.0;
-                               min, 0 32;
-                               rel1 {
-                                       to, PART_POPUP_NAME;
-                                       relative, 0.0 1.0;
-                               }
-                               rel2.to, PART_POPUP_NAME;
-                               align, 0.5 0.0;
-                               fixed, 0 1;
-                       }
-               }
-
-               part {
-                       name, PART_POPUP_BUTTON1;
-                       type, SWALLOW;
-                       scale, 1;
-                       description {
-                               state, "default" 0.0;
-                               min, 488 68;
-                               rel1 {
-                                       to, "padding.lang1";
-                                       relative, 0.5 1.0;
-                               }
-                               rel2 {
-                                       to, "padding.lang1";
-                                       relative, 0.5 1.0;
-                               }
-                               align, 0.5 0.0;
-                               fixed, 0 1;
-                               color, 0 0 0 255;
-                       }
-               }
-
-               part {
-                       name, "padding.lang2";
-                       type, SPACER;
-                       scale, 1;
-                       description {
-                               state, "default" 0.0;
-                               min, 0 32;
-                               rel1 {
-                                       to, PART_POPUP_BUTTON1;
-                                       relative, 0.0 1.0;
-                               }
-                               rel2.to, PART_POPUP_BUTTON1;
-                               align, 0.5 0.0;
-                               fixed, 0 1;
-                       }
-               }
-
-               part {
-                       name, PART_POPUP_BUTTON2;
-                       type, SWALLOW;
-                       scale, 1;
-                       description {
-                               state, "default" 0.0;
-                               min, 488 68;
-
-                               rel1 {
-                                       to, "padding.lang2";
-                                       relative, 0.0 1.0;
-                               }
-                               rel2.to, "padding.lang2";
-
-                               align, 0.5 0.0;
-                               fixed, 0 1;
-                               color, 0 0 0 255;
-                       }
-               }
-  }
-}
index aaabb07..eeaf103 100644 (file)
@@ -23,6 +23,7 @@ collections {
        #include "view/system/sleep_timer.edc"
        #include "view/system/wakeup_timer.edc"
        #include "view/system/pin.edc"
+       #include "view/system/language.edc"
        #include "view/system/location.edc"
        #include "layout/picture.edc"
        #include "layout/channel.edc"
diff --git a/res/view/system/language.edc b/res/view/system/language.edc
new file mode 100644 (file)
index 0000000..8824b3b
--- /dev/null
@@ -0,0 +1,105 @@
+group {
+       name, GRP_VIEW_LANGUAGE;
+       parts {
+               part {
+                       name, "area";
+                       type, RECT;
+                       scale, 1;
+                       description {
+                               state, "default" 0.0;
+                               visible, 0;
+                       }
+               }
+
+               part {
+                       name, "padding.title";
+                       type, SPACER;
+                       scale, 1;
+                       description {
+                               state, "default" 0.0;
+                               min, 0 24;
+                               rel1.to, "area";
+                               rel2 { to, "area"; relative, 1.0 0.0; }
+                               align, 0.5 0.0;
+                               fixed, 0 1;
+                       }
+               }
+
+               part {
+                       name, PART_POPUP_NAME;
+                       type, TEXT;
+                       scale, 1;
+                       description {
+                               state, "default" 0.0;
+                               min, 0 32;
+                               rel1 { to, "padding.title"; relative, 0.0 1.0; }
+                               rel2.to, "padding.title";
+                               align, 0.5 0.0;
+                               fixed, 0 1;
+                               color, COLOR_TEXT_POPUP;
+                               text {
+                                       font, FONT_LIGHT;
+                                       size, 32;
+                               }
+                       }
+               }
+
+               part {
+                       name, "padding.lang1";
+                       type, SPACER;
+                       scale, 1;
+                       description {
+                               state, "default" 0.0;
+                               min, 0 32;
+                               rel1 { to, PART_POPUP_NAME; relative, 0.0 1.0; }
+                               rel2.to, PART_POPUP_NAME;
+                               align, 0.5 0.0;
+                               fixed, 0 1;
+                       }
+               }
+
+               part {
+                       name, PART_POPUP_BUTTON1;
+                       type, SWALLOW;
+                       scale, 1;
+                       description {
+                               state, "default" 0.0;
+                               min, 488 68;
+                               rel1 { to, "padding.lang1"; relative, 0.5 1.0; }
+                               rel2 { to, "padding.lang1"; relative, 0.5 1.0; }
+                               align, 0.5 0.0;
+                               fixed, 0 1;
+                               color, 0 0 0 255;
+                       }
+               }
+
+               part {
+                       name, "padding.lang2";
+                       type, SPACER;
+                       scale, 1;
+                       description {
+                               state, "default" 0.0;
+                               min, 0 32;
+                               rel1 { to, PART_POPUP_BUTTON1; relative, 0.0 1.0; }
+                               rel2.to, PART_POPUP_BUTTON1;
+                               align, 0.5 0.0;
+                               fixed, 0 1;
+                       }
+               }
+
+               part {
+                       name, PART_POPUP_BUTTON2;
+                       type, SWALLOW;
+                       scale, 1;
+                       description {
+                               state, "default" 0.0;
+                               min, 488 68;
+                               rel1 { to, "padding.lang2"; relative, 0.0 1.0; }
+                               rel2.to, "padding.lang2";
+                               align, 0.5 0.0;
+                               fixed, 0 1;
+                               color, 0 0 0 255;
+                       }
+               }
+  }
+}
diff --git a/src/data/system/settings_language.c b/src/data/system/settings_language.c
new file mode 100644 (file)
index 0000000..babce9e
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+#include <system_settings.h>
+#include <utils_i18n.h>
+#include "app_debug.h"
+#include "data/system/settings_language.h"
+
+#define LANG_LOCALE_STR_L 6
+#define LANG_DISPLAY_STR_L 64
+
+#define LOCALE_UNKNOWN "Unknown"
+
+static char *lang_str[LANG_TYPE_MAX] = { "en_US", "ko_KR" };
+
+void settings_language_set_language(settings_language_type lang_type)
+{
+       int ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, lang_str[lang_type]);
+       if (ret != SYSTEM_SETTINGS_ERROR_NONE)
+               _ERR("Failed to set language: %s", lang_str[lang_type]);
+}
+
+settings_language_type settings_language_get_language_id(void)
+{
+       char *lang = NULL;
+       int r = 0;
+       int i = 0;
+
+       r = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &lang);
+       if (r != SYSTEM_SETTINGS_ERROR_NONE)
+               return LANG_TYPE_MAX;
+
+       for (i = 0; i < LANG_TYPE_MAX; i++) {
+               if (!strncmp(lang, lang_str[i], LANG_LOCALE_STR_L)) {
+                       free(lang);
+                       return i;
+               }
+       }
+
+       free(lang);
+
+       return LANG_TYPE_MAX;
+}
+
+char *settings_language_get_language_locale_str(void)
+{
+       char *lang = NULL;
+
+       system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &lang);
+
+       return lang;
+}
+
+char *settings_language_get_language_display_str(void)
+{
+       char *lang = NULL;
+       char name[LANG_DISPLAY_STR_L] = {0, };
+       i18n_uchar res[LANG_DISPLAY_STR_L] = {0, };
+       int r = 0;
+
+       lang = settings_language_get_language_locale_str();
+       if (!lang) {
+               _ERR("Failed to get language.");
+               return strdup(LOCALE_UNKNOWN);
+       }
+
+       r = i18n_ulocale_get_display_language(lang, lang, res, sizeof(res));
+       if (r < 0) {
+               _ERR("Failed to get display language: %s.", get_last_result());
+               free(lang);
+               return strdup(LOCALE_UNKNOWN);
+       }
+
+       i18n_ustring_copy_au_n(name, res, LANG_DISPLAY_STR_L-1);
+
+       free(lang);
+
+       return strdup(name);
+}
index 359b800..ed0b87c 100644 (file)
@@ -29,6 +29,7 @@
 #include "view/system/view_clock.h"
 #include "view/system/view_location.h"
 #include "data/system/settings_clock.h"
+#include "data/system/settings_language.h"
 
 #define PADDING_X 26
 #define PADDING_Y 26
 #define TIMER_ON "On"
 #define LOCALE_UNKNOWN "Unknown"
 
-#define PART_POPUP_BUTTON_X "part.popup.btn%d"
-
 struct _priv {
        Evas_Object *base;
        Evas_Object *ly;
        Evas_Object *table;
        layoutmgr *lmgr;
        struct menumgr *menu;
-
-       Evas_Object *popup;
-       Evas_Object *popup_btn[POPUP_SLEEP_TIMER_BTN_COUNT];
 };
 
 enum {
@@ -63,12 +59,6 @@ enum {
        MENU_RESET
 };
 
-
-enum object_type {
-       EO_BTN_LANG_ENG = 0,
-       EO_BTN_LANG_KOR
-};
-
 static char *_get_status(void *data, int id);
 static char *_get_clock_mode(void *data, int id);
 static char *_get_sleep_timer(void *data, int id);
@@ -76,16 +66,8 @@ static char *_get_language(void *data, int id);
 static char *_get_location(void *data, int id);
 
 static void _selected(void *data, int id);
-static void _language_selected(void *data, int id);
 static void _location_selected(void *data, int id);
 
-// popup handler
-static void _remove_popup(struct _priv *priv);
-static void _popup_clicked_cb(int id, void *data, Evas_Object *obj);
-static void _popup_key_down_cb(int id, void *data, Evas *e, Evas_Object *obj,  Evas_Event_Key_Down *ev);
-
-static char *language_option[POPUP_LANGUAGE_BTN_COUNT] = { "English", "Korean"};
-
 static struct menumgr_info menu_info[] = {
        {
                .id = MENU_CLOCK,
@@ -124,7 +106,7 @@ static struct menumgr_info menu_info[] = {
                .style = STYLE_STATUS_BTN,
                .disabled = EINA_FALSE,
                .status = _get_language,
-               .selected = _language_selected,
+               .selected = _selected,
        },
        {
                .id = MENU_SUBTITLE,
@@ -177,30 +159,7 @@ static char *_get_sleep_timer(void *data, int id)
 
 static char *_get_language(void *data, int id)
 {
-       char *lang = NULL;
-       char name[64] = {'\0',};
-       i18n_uchar res[64] = {0};
-       int r;
-
-       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(LOCALE_UNKNOWN);
-       }
-
-       r = i18n_ulocale_get_display_language(lang, lang, res, sizeof(res));
-       if (r < 0) {
-               _ERR("failed to get display language: %s", get_last_result());
-               free(lang);
-               return strdup(LOCALE_UNKNOWN);
-       }
-
-       i18n_ustring_copy_au(name, res);
-
-       free(lang);
-
-       return strdup(name);
+       return settings_language_get_language_display_str();
 }
 
 static char *_get_location(void *data, int id)
@@ -261,182 +220,15 @@ static void _selected(void *data, int id)
                        if (!viewmgr_show_view(VIEW_CHANGE_PINCODE))
                                _ERR("Push Clock view failed.");
                        break;
+               case MENU_LANGUAGE:
+                       if (!viewmgr_show_view(VIEW_LANGUAGE))
+                               _ERR("Push Language view failed.");
+                               break;
                default:
                        _ERR("Invalid menu.");
        }
 }
 
-static input_handler _popup_input_handler = {
-       .mouse_move = NULL,
-       .clicked = _popup_clicked_cb,
-       .key_down = _popup_key_down_cb
-};
-
-
-static void _remove_popup(struct _priv *priv)
-{
-       int i = 0;
-
-       if (!priv) {
-               _ERR("Invalid popup data !");
-               return;
-       }
-
-       for(i = 0; i < POPUP_SLEEP_TIMER_BTN_COUNT; i++) {
-               if (priv->popup_btn[i]) {
-                       inputmgr_remove_callback(priv->popup_btn[i], &_popup_input_handler);
-                       evas_object_del(priv->popup_btn[i]);
-                       priv->popup_btn[i] = NULL;
-               }
-       }
-
-       evas_object_hide(priv->popup);
-       evas_object_del(priv->popup);
-       priv->popup = NULL;
-}
-
-
-
-static void _popup_clicked_cb(int id, void *data, Evas_Object *obj)
-{
-       struct _priv *priv = NULL;
-
-       if (!data || !obj) {
-               _ERR("Invalid argument.");
-               return;
-       }
-
-       priv = data;
-
-       switch (id) {
-       case EO_BTN_LANG_ENG:
-               system_settings_set_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, "en_US");
-               menumgr_update(priv->menu);
-
-               _remove_popup(priv);
-               break;
-
-       case EO_BTN_LANG_KOR:
-               system_settings_set_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, "ko_KR");
-               menumgr_update(priv->menu);
-
-               _remove_popup(priv);
-               break;
-       default:
-               _ERR("Unhandled object type.");
-               return;
-       }
-}
-
-static void _popup_key_down_cb(int id, void *data, Evas *e, Evas_Object *obj,
-               Evas_Event_Key_Down *ev)
-{
-       struct _priv *priv = NULL;
-
-       if (!ev || !data) {
-               _ERR("Invalid argument.");
-               return;
-       }
-
-       priv = data;
-
-       if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_ESC)) {
-               _remove_popup(priv);
-       }
-}
-
-static bool _fill_popup_btns(struct _priv *priv, Evas_Object *layout, int btn_count, char *btn_part_x, char **btn_text, int first_btn_eo)
-{
-       Evas_Object *btn = NULL;
-       int i = 0;
-
-       for(i = 0; i < btn_count; i++) {
-               char part_name[24] = {0, };
-               snprintf(part_name, sizeof(part_name), btn_part_x, i+1);
-               btn = utils_add_button(layout, part_name, NULL, btn_text[i]);
-               if (!btn) {
-                       _ERR("Add button failed.");
-                       return false;
-               }
-
-               priv->popup_btn[i] = btn;
-
-               inputmgr_add_callback(btn, first_btn_eo+i, &_popup_input_handler, priv);
-       }
-
-       return true;
-}
-
-static bool _draw_language_select_popup(struct _priv *priv)
-{
-       Evas_Object *popup = NULL;
-       Evas_Object *ly = NULL;
-
-       popup = utils_add_popup(priv->base, NULL, STR_LANGUAGE, NULL);
-       if (!popup) {
-               _ERR("Add popup failed");
-               return false;
-       }
-       evas_object_show(popup);
-
-       ly = utils_add_layout(popup, GRP_POPUP_LANGUAGE, EINA_FALSE);
-       if (!ly) {
-               _ERR("Add layout failed.");
-               evas_object_del(popup);
-               return false;
-       }
-
-       elm_object_part_text_set(ly, PART_POPUP_NAME, "Select language.");
-       evas_object_show(ly);
-
-       if (!_fill_popup_btns(priv, ly, POPUP_LANGUAGE_BTN_COUNT, PART_POPUP_BUTTON_X, language_option, EO_BTN_LANG_ENG)) {
-               evas_object_del(popup);
-               return false;
-       }
-
-       if (priv->popup)
-               evas_object_del(priv->popup);
-
-       priv->popup = popup;
-
-       elm_object_content_set(popup, ly);
-
-       // Set Focus
-
-       {
-               char *lang;
-               int r;
-
-               r = system_settings_get_value_string(   SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &lang);
-               if (r != SYSTEM_SETTINGS_ERROR_NONE) {
-                       return false;
-               }
-
-               if (!strncmp(lang, "en_US",4)) {
-                       elm_object_focus_set(priv->popup_btn[0], EINA_TRUE);
-               }
-               else {
-                       elm_object_focus_set(priv->popup_btn[1], EINA_TRUE);
-               }
-
-               free(lang);
-       }
-       return true;
-}
-
-static void _language_selected(void *data, int id)
-{
-       SETTING_TRACE_BEGIN;
-       struct _priv *priv = (struct _priv *)data;
-
-
-       if (!_draw_language_select_popup(priv)) {
-               _ERR("Draw language select popup failed.");
-               return;
-       }
-
-}
-
 static void _location_selected(void *data, int id)
 {
        SETTING_TRACE_BEGIN;
@@ -516,10 +308,6 @@ static bool _create(layoutmgr *lmgr, void *data)
 
        priv->table = NULL;
        priv->menu = NULL;
-       priv->popup = NULL;
-
-       memset(priv->popup_btn, 0, POPUP_SLEEP_TIMER_BTN_COUNT * sizeof(Evas_Object *));
-
        priv->lmgr = lmgr;
        priv->base = base;
        priv->ly = ly;
index a7e8503..cfb8a4d 100644 (file)
@@ -26,8 +26,8 @@
 #include "view/system/view_sleep_timer.h"
 #include "view/system/view_wakeup_timer.h"
 #include "view/system/view_pincode.h"
-
-#include <system_settings.h>
+#include "view/system/view_language.h"
+#include "data/system/settings_language.h"
 
 struct _appdata {
        Evas_Object *win;
@@ -82,12 +82,6 @@ static bool _create(void *data)
                return false;
        }
 
-       if (!viewmgr_add_view(view_wakeup_timer_get_vclass(), NULL)) {
-               _ERR("Add view failed.");
-               evas_object_del(win);
-               return false;
-       }
-
        ad->win = win;
 
        return true;
@@ -108,9 +102,6 @@ static void _terminate(void *data)
 
        _destroy_system_ui();
 
-       if (!viewmgr_remove_view(VIEW_WAKEUP_TIMER))
-               _ERR("Remove view failed.");
-
        if (!viewmgr_destroy())
                _ERR("Destroy viewmgr failed.");
 
@@ -141,8 +132,7 @@ static void setting_lang_changed_cb(app_event_info_h event_info, void *data)
 {
        SETTING_TRACE_BEGIN;
 
-       char* localeLanguage = NULL;
-       system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &localeLanguage);
+       char* localeLanguage = settings_language_get_language_locale_str();
        elm_language_set(localeLanguage);
        free(localeLanguage);
 
@@ -153,14 +143,6 @@ static void setting_lang_changed_cb(app_event_info_h event_info, void *data)
 static void setting_region_changed_cb(app_event_info_h event_info, void *data)
 {
        SETTING_TRACE_BEGIN;
-#if 0
-       char* localeLanguage = NULL;
-       system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &localeLanguage);
-       elm_language_set(localeLanguage);
-       free(localeLanguage);
-
-       // add more here
-#endif
 }
 
 int main(int argc, char *argv[])
@@ -194,11 +176,21 @@ static bool _create_system_ui(void)
                return false;
        }
 
+       if (!viewmgr_add_view(view_wakeup_timer_get_vclass(), NULL)) {
+               _ERR("Add wake up view failed.");
+               return false;
+       }
+
        if (!viewmgr_add_view(view_pincode_get_vclass(), NULL)) {
                _ERR("Adding change pin view failed.");
                return false;
        }
 
+       if (!viewmgr_add_view(view_language_get_vclass(), NULL)) {
+               _ERR("Add language view failed.");
+               return false;
+       }
+
        if (!viewmgr_add_view(view_location_get_vclass(), NULL)) {
                _ERR("Adding location view failed.");
                return false;
@@ -215,9 +207,15 @@ static void _destroy_system_ui(void)
        if (!viewmgr_remove_view(VIEW_SLEEP_TIMER))
                _ERR("Remove sleep timer view failed.");
 
+       if (!viewmgr_remove_view(VIEW_WAKEUP_TIMER))
+               _ERR("Remove wake up view failed.");
+
        if (!viewmgr_remove_view(VIEW_CHANGE_PINCODE))
                _ERR("Remove change pin view failed.");
 
+       if (!viewmgr_remove_view(VIEW_LANGUAGE))
+               _ERR("Remove language view failed.");
+
        if (!viewmgr_remove_view(VIEW_LOCATION))
                _ERR("Remove location view failed.");
 }
diff --git a/src/view/system/view_language.c b/src/view/system/view_language.c
new file mode 100644 (file)
index 0000000..2ecf0aa
--- /dev/null
@@ -0,0 +1,225 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <app.h>
+#include <Elementary.h>
+#include <system_settings.h>
+#include <utils_i18n.h>
+#include <vconf.h>
+
+#include "app_debug.h"
+#include "define.h"
+#include "common/viewmgr.h"
+#include "common/inputmgr.h"
+#include "common/utils.h"
+#include "data/system/settings_language.h"
+#include "view/system/view_language.h"
+
+#define STR_LANGUAGE_DES "Select language."
+#define PART_POPUP_BUTTON_X "part.popup.btn%d"
+#define PART_POPUP_BUTTON_MAX_L 24
+
+struct _priv {
+       Evas_Object *base;
+       Evas_Object *popup_btn[LANG_TYPE_MAX];
+};
+
+enum language_eo_type {
+       EO_BTN_LANG_ENG = 0,
+       EO_BTN_LANG_KOR
+};
+
+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 char *language_option[LANG_TYPE_MAX] = { "English", "Korean"};
+
+static input_handler handler = {
+       .key_down = _key_down_cb,
+       .clicked = _clicked_cb
+};
+
+static bool _fill_popup_btns(struct _priv *priv, Evas_Object *layout,
+       int btn_count, char *btn_part_x, char **btn_text, int first_btn_eo)
+{
+       Evas_Object *btn = NULL;
+       int i;
+
+       for(i = 0; i < btn_count; i++) {
+               char part_name[PART_POPUP_BUTTON_MAX_L] = {0, };
+               snprintf(part_name, sizeof(part_name), btn_part_x, i+1);
+
+               btn = utils_add_button(layout, part_name, NULL, btn_text[i]);
+               if (!btn) {
+                       _ERR("Add button failed.");
+                       return false;
+               }
+
+               priv->popup_btn[i] = btn;
+
+               inputmgr_add_callback(btn, first_btn_eo+i, &handler, priv);
+       }
+
+       return true;
+}
+
+static Evas_Object *_create(Evas_Object *win, void *data)
+{
+       struct _priv *priv = NULL;
+       Evas_Object *ly = NULL;
+
+       if (!win) {
+               _ERR("Get window object failed.");
+               return NULL;
+       }
+
+       priv = calloc(1, sizeof(struct _priv *));
+       if (!priv) {
+               _ERR("Calloc failed.");
+               return NULL;
+       }
+
+       priv->base = utils_add_popup(win, NULL, STR_LANGUAGE, NULL);
+       if (!priv->base) {
+               _ERR("Add popup failed");
+               free(priv);
+               return NULL;
+       }
+
+       ly = utils_add_layout(priv->base, GRP_VIEW_LANGUAGE, EINA_FALSE);
+       if (!ly) {
+               _ERR("Add layout failed.");
+               evas_object_del(priv->base);
+               free(priv);
+               return NULL;
+       }
+
+       elm_object_part_text_set(ly, PART_POPUP_NAME, STR_LANGUAGE_DES);
+
+       if (!_fill_popup_btns(priv, ly, LANG_TYPE_MAX, PART_POPUP_BUTTON_X,
+                       language_option, EO_BTN_LANG_ENG)) {
+               evas_object_del(priv->base);
+               return NULL;
+       }
+
+       elm_object_content_set(priv->base, ly);
+
+
+       if (!viewmgr_set_view_data(VIEW_LANGUAGE, priv)) {
+               _ERR("Set view data failed.");
+               evas_object_del(priv->base);
+               free(priv);
+               return NULL;
+       }
+
+       return priv->base;
+}
+
+static void _show(void *data)
+{
+       struct _priv *priv = (struct _priv *)data;
+       int lang_id = 0;
+
+       if (!priv) {
+               _ERR("Invalid parameter.");
+               return;
+       }
+
+       evas_object_show(priv->base);
+
+       /* Set Focus */
+       lang_id = settings_language_get_language_id();
+
+       if(lang_id != LANG_TYPE_MAX)
+               elm_object_focus_set(priv->popup_btn[lang_id], EINA_TRUE);
+}
+
+static void _hide(void *data)
+{
+       struct _priv *priv = (struct _priv *)data;
+
+       if (!priv) {
+               _ERR("Invalid parameter.");
+               return;
+       }
+
+       evas_object_hide(priv->base);
+}
+
+static void _destroy(void *data)
+{
+       struct _priv *priv = (struct _priv *)data;
+
+       if (!priv) {
+               _ERR("Invalid parameter.");
+               return;
+       }
+
+       evas_object_del(priv->base);
+
+       free(priv);
+}
+
+static view_class _vclass = {
+       .view_id = VIEW_LANGUAGE,
+       .create = _create,
+       .show = _show,
+       .hide = _hide,
+       .destroy = _destroy
+};
+
+view_class *view_language_get_vclass(void)
+{
+       return &_vclass;
+}
+
+static void _key_down_cb(int id, void *data, Evas *e, Evas_Object *obj,
+               Evas_Event_Key_Down *ev)
+{
+       struct _priv *priv = (struct _priv *)data;
+
+       if (!ev || !priv) {
+               _ERR("Invalid argument.");
+               return;
+       }
+
+       if (!strcmp(ev->keyname, KEY_BACK))
+               viewmgr_pop_view();
+}
+
+static void _clicked_cb(int id, void *data, Evas_Object *obj)
+{
+       struct _priv *priv = (struct _priv *)data;
+
+       if (!priv || !obj) {
+               _ERR("Invalid argument.");
+               return;
+       }
+
+       switch (id) {
+       case EO_BTN_LANG_ENG:
+               settings_language_set_language(LANG_TYPE_ENG);
+               break;
+       case EO_BTN_LANG_KOR:
+               settings_language_set_language(LANG_TYPE_KOR);
+               break;
+       default:
+               _ERR("Unhandled object type.");
+       }
+
+       viewmgr_pop_view();
+}
index a9c2b78..b714c1f 100644 (file)
@@ -219,7 +219,6 @@ static void _clicked_cb(int id, void *data, Evas_Object *obj)
                        break;
                default:
                        _ERR("Unhandled object type.");
-                       return;
        }
 
        viewmgr_pop_view();