Add code for checking profile to support TV profile
[platform/core/uifw/inputdelegator.git] / src / w-input-selector.cpp
index f08b774..4576c70 100755 (executable)
 #include <dlog.h>
 #include <Eina.h>
 #include <string>
-#include <efl_assist.h>
 #include <vconf.h>
 #include <vconf-keys.h>
+#include <stdint.h>
+#include <system_info.h>
 
-//#include "ui_extension.h"
 #include "w-input-selector.h"
+#include "w-input-template.h"
 #include "w-input-keyboard.h"
 #include "w-input-stt-ise.h"
 #include "w-input-emoticon.h"
@@ -44,32 +45,68 @@ InputTypeData g_input_type_data;
 static Elm_Object_Item *it_empty;
 static Elm_Object_Item *it_title;
 
+static unsigned int g_template_item_size = 0;          /* Current Template item size */
+
 Evas_Coord last_step; // 0 ~ 9 for gesture, 10~11 for rotary
 
+tizen_profile_t _get_tizen_profile()
+{
+   static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
+   if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
+     return profile;
+
+   char *profileName;
+   system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
+   switch (*profileName)
+     {
+      case 'm':
+      case 'M':
+         profile = TIZEN_PROFILE_MOBILE;
+         break;
+      case 'w':
+      case 'W':
+         profile = TIZEN_PROFILE_WEARABLE;
+         break;
+      case 't':
+      case 'T':
+         profile = TIZEN_PROFILE_TV;
+         break;
+      case 'i':
+      case 'I':
+         profile = TIZEN_PROFILE_IVI;
+         break;
+      default: // common or unknown ==> ALL ARE COMMON.
+         profile = TIZEN_PROFILE_COMMON;
+     }
+   free(profileName);
+
+   return profile;
+}
+
+
 void _init_app_data(App_Data* app_data);
 static void _app_language_changed(app_event_info_h event_info, void *user_data);
 
 Evas_Object* _create_genlist(Evas_Object* parent);
 void _create_genlist_items(void* user_data);
+void _create_header_items(void *user_data);
+void _update_genlist_items(void *user_data);
+unsigned int _update_template_items(void *user_data);
 static void _popup_close_cb(void *data, Evas_Object *obj, void *event_info);
 static void _popup_back_cb(void *data, Evas_Object *obj, void *event_info);
 static void input_type_deinit(void);
 
-
-
 void _init_app_data(App_Data* app_data)
 {
-    app_data->win_main = NULL;
-    app_data->layout_main = NULL;
-    app_data->conform = NULL;
-    app_data->naviframe = NULL;
-    app_data->genlist = NULL;
+       app_data->win_main = NULL;
+       app_data->layout_main = NULL;
+       app_data->conform = NULL;
+       app_data->naviframe = NULL;
+       app_data->genlist = NULL;
 
-    app_data->res_path = NULL;
+       app_data->res_path = NULL;
 }
 
-
-
 Evas_Object* load_edj(Evas_Object* parent, const char* file, const char* group)
 {
        Evas_Object* window;
@@ -90,7 +127,6 @@ Evas_Object* load_edj(Evas_Object* parent, const char* file, const char* group)
 
                evas_object_size_hint_weight_set(window, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        }
-
        return window;
 }
 
@@ -109,9 +145,9 @@ void init_customizing_theme(void)
 
 static Eina_Bool back_cb(void *data, Elm_Object_Item *it)
 {
-    reply_to_sender_by_callback_for_back();
-    elm_exit();
-    return EINA_FALSE;
+       reply_to_sender_by_callback_for_back();
+       elm_exit();
+       return EINA_FALSE;
 }
 
 static void _stt_clicked_cb(void *data, Evas_Object * obj, void *event_info)
@@ -139,6 +175,11 @@ static void _stt_clicked_cb(void *data, Evas_Object * obj, void *event_info)
        }
 }
 
+static void _input_template_notify_cb(void *user_data)
+{
+       _update_genlist_items((void *)app_data);
+}
+
 static void _emoticon_clicked_cb(void *data, Evas_Object * obj, void *event_info)
 {
        App_Data* ad = (App_Data*)data;
@@ -148,8 +189,7 @@ static void _emoticon_clicked_cb(void *data, Evas_Object * obj, void *event_info
        if(!ad)
                return;
 
-//     ise_show_emoticon_popup(ad);
-       ise_show_emoticon_popup_rotary(ad);
+       ise_show_emoticon_list(ad);
 }
 
 static void _keyboard_clicked_cb(void *data, Evas_Object * obj, void *event_info)
@@ -164,24 +204,56 @@ static void _keyboard_clicked_cb(void *data, Evas_Object * obj, void *event_info
        input_keyboard_launch(ad->win_main, data);
 }
 
-static void __bt_connection_result_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *user_data)
+static void __ise_template_gl_sel(void *data, Evas_Object *obj, void *event_info)
 {
-       char *val = NULL;
+       Elm_Object_Item *item = (Elm_Object_Item *) event_info;
+       int index = 0;
 
-       if (reply == NULL) {
-               PRINTFUNC(DLOG_ERROR, "service_h is NULL");
-               return;
+       if (item) {
+               elm_genlist_item_selected_set(item, EINA_FALSE);
+
+               index = (uintptr_t) elm_object_item_data_get(item);
+               const std::vector<TemplateData>  template_list = input_template_get_list();
+
+               if (index < (int)template_list.size()) {
+                       reply_to_sender_by_callback(gettext(template_list[index].text.c_str()), "template");
+                       elm_exit();
+               }
        }
+}
 
-       app_control_get_extra_data(reply, "__BT_CONNECTION__", &val);
-       if (val) {
-               if ( strcmp(val, "Connected") == 0 ) {
-                       PRINTFUNC(DLOG_ERROR, "BT Connected");
-               } else {
-                       PRINTFUNC(DLOG_ERROR, "BT Not Connected");
+static char * __ise_template_gl_text_get(void *data, Evas_Object *obj, const char *part)
+{
+       if(!strcmp(part, "elm.text")) {
+               unsigned int index = (uintptr_t)data;
+               const std::vector<TemplateData>  template_list = input_template_get_list();
+
+               if(index < template_list.size()) {
+                       if(template_list[index].use_gettext) {
+                               return strdup(gettext(template_list[index].text.c_str()));
+                       } else {
+                               Eina_Strbuf *buf = NULL;
+                               const char *str = NULL;
+                               char *markup = NULL;
+
+                               buf = eina_strbuf_new();
+                               if(buf) {
+                                       eina_strbuf_append(buf, template_list[index].text.c_str());
+                                       eina_strbuf_replace_all(buf, "\n", "");
+                                       eina_strbuf_replace_all(buf, "\r", "");
+
+                                       str = eina_strbuf_string_get(buf);
+
+                                       if (str) {
+                                               markup = elm_entry_utf8_to_markup(str);
+                                       }
+                                       eina_strbuf_free(buf);
+                               }
+                               return markup;
+                       }
                }
-               free(val);
        }
+       return NULL;
 }
 
 static Evas_Object * __ise_gl_2button_content_get(void *data, Evas_Object *obj, const char *part)
@@ -198,13 +270,15 @@ static Evas_Object * __ise_gl_2button_content_get(void *data, Evas_Object *obj,
                elm_image_resizable_set(ic, EINA_TRUE, EINA_TRUE);
                string path = get_resource_path();
                if (!strcmp(part, "elm.icon.1")) {
-                       elm_object_style_set(btn, "anchor");
                        string path_ic;
                        if(!strcmp(first_input_type, "input_voice")) {
+                               elm_object_style_set(btn, "ime_button_stt");
                                path_ic = path + "images/w_mode_stt_ic.png";
                        } else if (!strcmp(first_input_type, "input_emoticon")) {
+                               elm_object_style_set(btn, "ime_button_emoticon");
                                path_ic = path + "images/Delta_w_mode_emoticon_ic.png";
                        } else if (!strcmp(first_input_type, "input_keyboard")) {
+                               elm_object_style_set(btn, "ime_button_keyboard");
                                path_ic = path + "images/w_mode_keyboard_ic.png";
                                evas_object_propagate_events_set(btn, EINA_FALSE);
                        }
@@ -212,13 +286,15 @@ static Evas_Object * __ise_gl_2button_content_get(void *data, Evas_Object *obj,
                        elm_object_content_set(btn, ic);
                        evas_object_layer_set(btn, 32000);
                } else if (!strcmp(part, "elm.icon.2")){
-                       elm_object_style_set(btn, "anchor");
                        string path_ic;
                        if(!strcmp(second_input_type, "input_voice")) {
+                               elm_object_style_set(btn, "ime_button_stt");
                                path_ic = path + "images/w_mode_stt_ic.png";
                        } else if (!strcmp(second_input_type, "input_emoticon")) {
+                               elm_object_style_set(btn, "ime_button_emoticon");
                                path_ic = path + "images/Delta_w_mode_emoticon_ic.png";
                        } else if (!strcmp(second_input_type, "input_keyboard")) {
+                               elm_object_style_set(btn, "ime_button_keyboard");
                                path_ic = path + "images/w_mode_keyboard_ic.png";
                                evas_object_propagate_events_set(btn, EINA_FALSE);
                        }
@@ -273,21 +349,21 @@ static Evas_Object * __ise_gl_3button_content_get(void *data, Evas_Object *obj,
                elm_image_resizable_set(ic, EINA_TRUE, EINA_TRUE);
                string path = get_resource_path();
                if (!strcmp(part, "elm.icon.1")) {
-                       elm_object_style_set(btn, "anchor");
+                       elm_object_style_set(btn, "ime_button_stt");
                        string path_ic = path + "images/w_mode_stt_ic.png";
                        elm_image_file_set(ic, path_ic.c_str(), NULL);
                        elm_object_content_set(btn, ic);
                        evas_object_layer_set(btn, 32000);
 
                } else if (!strcmp(part, "elm.icon.2")){
-                       elm_object_style_set(btn, "anchor");
+                       elm_object_style_set(btn, "ime_button_emoticon");
                        string path_ic = path + "images/Delta_w_mode_emoticon_ic.png";
                        elm_image_file_set(ic, path_ic.c_str(), NULL);
                        elm_object_content_set(btn, ic);
                        evas_object_layer_set(btn, 32000);
 
                } else if (!strcmp(part, "elm.icon.3")){
-                       elm_object_style_set(btn, "anchor");
+                       elm_object_style_set(btn, "ime_button_keyboard");
                        string path_ic = path + "images/w_mode_keyboard_ic.png";
                        elm_image_file_set(ic, path_ic.c_str(), NULL);
                        elm_object_content_set(btn, ic);
@@ -485,10 +561,10 @@ void _back_to_genlist_for_selector()
                reply_to_sender_by_callback(NULL, NULL);
                elm_exit();
        }
-
+#ifdef _WEARABLE
        Evas_Object *circle_genlist = (Evas_Object *) evas_object_data_get(app_data->genlist, "circle");
-
        eext_rotary_object_event_activated_set(circle_genlist, EINA_TRUE);
+#endif
 }
 
 static void _item_realized(void *data, Evas_Object *obj, void *event_info) //called when list scrolled
@@ -503,12 +579,12 @@ Evas_Object* _create_genlist(Evas_Object* navi)
                return NULL;
 
        elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
-
+#ifdef _WEARABLE
        Evas_Object* circle_object_genlist = eext_circle_object_genlist_add(genlist, app_data->circle_surface);
        eext_circle_object_genlist_scroller_policy_set(circle_object_genlist, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
        evas_object_data_set(genlist, "circle", (void *) circle_object_genlist);
        eext_rotary_object_event_activated_set(circle_object_genlist, EINA_TRUE);
-
+#endif
        evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
 
@@ -574,8 +650,6 @@ _main_menu_title_text_get(void *data, Evas_Object *obj, const char *part)
 
 void _create_genlist_items(void* user_data)
 {
-       LOGD("[psw] _create_genlist_items");
-
        App_Data* app_data = (App_Data*) user_data;
 
        if(NULL == app_data->genlist) {
@@ -595,13 +669,13 @@ void _create_genlist_items(void* user_data)
 
        Elm_Genlist_Item_Class * itc1 = elm_genlist_item_class_new();
        if(g_input_type_data.input_type_array_len == 2){
-               itc1->item_style = "2button";
+               itc1->item_style = "2button_flat";
                itc1->func.text_get = NULL;
                itc1->func.content_get = __ise_gl_2button_content_get;
                itc1->func.state_get = NULL;
                itc1->func.del = NULL;
        } else {
-               itc1->item_style = "3button";
+               itc1->item_style = "3button_flat";
                itc1->func.text_get = NULL;
                itc1->func.content_get = __ise_gl_3button_content_get;
                itc1->func.state_get = NULL;
@@ -622,6 +696,8 @@ void _create_genlist_items(void* user_data)
 
        elm_genlist_item_select_mode_set(it_title, ELM_OBJECT_SELECT_MODE_NONE);
 
+       g_template_item_size = _update_template_items(app_data);
+
        Elm_Object_Item *item = elm_genlist_item_next_get(it_title);
        elm_genlist_item_show(item, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
 
@@ -631,6 +707,118 @@ void _create_genlist_items(void* user_data)
        elm_genlist_item_class_free(itc1);
 }
 
+void _create_header_items(void *user_data)
+{
+       Elm_Genlist_Item_Class * itc0 = elm_genlist_item_class_new();
+       itc0->item_style = "title";
+       itc0->func.text_get = NULL;
+       itc0->func.content_get = NULL;
+       itc0->func.state_get = NULL;
+       itc0->func.del = NULL;
+
+       Elm_Genlist_Item_Class * itc1 = elm_genlist_item_class_new();
+       if (g_input_type_data.input_type_array_len == 2) {
+               itc1->item_style = "2button_flat";
+               itc1->func.text_get = NULL;
+               itc1->func.content_get = __ise_gl_2button_content_get;
+               itc1->func.state_get = NULL;
+               itc1->func.del = NULL;
+       } else {
+               itc1->item_style = "3button_flat";
+               itc1->func.text_get = NULL;
+               itc1->func.content_get = __ise_gl_3button_content_get;
+               itc1->func.state_get = NULL;
+               itc1->func.del = NULL;
+       }
+
+       // dummy title for empty space
+       it_empty = elm_genlist_item_append(app_data->genlist, itc0,
+                               NULL, NULL,
+                               ELM_GENLIST_ITEM_NONE,
+                               NULL, NULL);
+
+       // 3 Buttons
+       it_title = elm_genlist_item_append(app_data->genlist, itc1,
+                                                       NULL, NULL,
+                                                       ELM_GENLIST_ITEM_NONE,
+                                                       NULL, NULL);
+
+       elm_genlist_item_select_mode_set(it_title, ELM_OBJECT_SELECT_MODE_NONE);
+
+       elm_genlist_item_class_free(itc0);
+       elm_genlist_item_class_free(itc1);
+}
+
+void _update_genlist_items(void *user_data)
+{
+       elm_genlist_clear(app_data->genlist);
+
+       _create_header_items(user_data);
+
+       g_template_item_size = _update_template_items(user_data);
+
+       /* Update genlist item position */
+       Elm_Object_Item *item = elm_genlist_item_next_get(it_title);
+       elm_genlist_item_show(item, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
+}
+
+unsigned int _update_template_items(void *user_data)
+{
+       App_Data* app_data;
+
+       Elm_Object_Item *first;
+
+       unsigned int i = 0;
+       unsigned int item_size = 0;
+
+       app_data = (App_Data *)user_data;
+
+       if (app_data == NULL) {
+               PRINTFUNC(DLOG_ERROR, "Can not get app_data");
+               return item_size;
+       }
+
+       if (app_data->genlist == NULL) {
+               /* smartreply will update when genlist is exist only */
+               PRINTFUNC(DLOG_ERROR, "Can not get getlist");
+               return item_size;
+       }
+
+       first = elm_genlist_first_item_get(app_data->genlist);
+       if (first == NULL)
+               return 0;
+       elm_genlist_item_next_get(first);
+
+       /* Append New Template list */
+       const std::vector<TemplateData> template_list = input_template_get_list();
+
+       if (template_list.size() > 0) {
+               Elm_Genlist_Item_Class *itc;
+
+               itc = elm_genlist_item_class_new();
+
+               itc->item_style = "1text";
+               itc->func.text_get = __ise_template_gl_text_get;
+               itc->func.content_get = NULL;
+               itc->func.state_get = NULL;
+               itc->func.del = NULL;
+
+               for (i = 0; i < template_list.size(); i++) {
+                       elm_genlist_item_append(app_data->genlist,
+                                       itc,
+                                       (void *)(uintptr_t)i,
+                                       NULL,
+                                       ELM_GENLIST_ITEM_NONE,
+                                       __ise_template_gl_sel,
+                                       app_data);
+                       item_size++;
+               }
+               elm_genlist_item_class_free(itc);
+       }
+
+       return item_size;
+}
+
 bool _app_create(void* user_data)
 {
        int width = 1000, height = 1000;
@@ -639,8 +827,9 @@ bool _app_create(void* user_data)
        Evas_Object* conform = NULL;
        Evas_Object* bg = NULL;
        Evas_Object* window = NULL;
+#ifdef _WEARABLE
        Eext_Circle_Surface *surface;
-
+#endif
        if (!user_data) {
                return false;
        }
@@ -675,7 +864,9 @@ bool _app_create(void* user_data)
        evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
 
        conform = elm_conformant_add(window);
+#ifdef _WEARABLE
        surface = eext_circle_surface_conformant_add(conform);
+#endif
        evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
 
 
@@ -688,7 +879,9 @@ bool _app_create(void* user_data)
        app_data->win_main = window;
        app_data->conform = conform;
        app_data->layout_main = layout;
+#ifdef _WEARABLE
        app_data->circle_surface = surface;
+#endif
        app_data->app_type = APP_TYPE_SELECT_MODE;
 
        Evas_Object *naviframe = elm_naviframe_add(layout);
@@ -745,6 +938,9 @@ void _app_service(app_control_h service, void* user_data)
 
        input_keyboard_init(service);
 
+       input_template_init(service);
+       input_template_set_notify(_input_template_notify_cb,  NULL);
+
        _create_genlist_items(app_data);
 
 ACTIVATE :
@@ -782,6 +978,10 @@ void _app_terminate(void* user_data)
                free(app_data->shared_res_path);
 
        input_keyboard_deinit();
+
+       input_template_unset_notify();
+       input_template_deinit();
+
        input_type_deinit();
 }
 
@@ -842,7 +1042,7 @@ void input_type_deinit(void)
        g_input_type_data.input_type_array_len = 0;
 }
 
-int main(int argc, char* argv[])
+EXPORTED int main(int argc, char* argv[])
 {
        App_Data app_data = {0, };
        ui_app_lifecycle_callback_s event_callback = {0, };