tizen 2.3 release
[apps/home/settings.git] / setting-font / src / setting-font.c
index cb22158..5b5b4a7 100755 (executable)
 /*
  * setting
- * Copyright (c) 2012 Samsung Electronics Co., Ltd.
  *
- * Licensed under the Flora License, Version 1.1 (the License);
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
+ *
+ * Contact: MyoungJune Park <mj2004.park@samsung.com>
+ *
+ * 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://floralicense.org/license/
+ * 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,
+ * 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 <setting-font.h>
 #include <system_settings.h>
+#include <setting-cfg.h>
+
 #ifndef UG_MODULE_API
 #define UG_MODULE_API __attribute__ ((visibility("default")))
 #endif
 
-setting_view *__get_font_view_to_load(void *data,service_h service)
+setting_view * __default_view_state(void* data, app_control_h service)
 {
        SETTING_TRACE_BEGIN;
        setting_retvm_if((!data), NULL, "data is NULL");
        SettingFontUG *fontUG = (SettingFontUG *)data;
 
-       setting_view_node_table_intialize();
-
+       // argument processing
        char *category = NULL;
-       service_get_extra_data(service, "category", &category);
+       app_control_get_extra_data(service, "category", &category);
 
        if (0 == safeStrCmp(category, "FontType")) {
                SETTING_TRACE("LAUNCHED BY APP-CONTROL MODE");
                fontUG->viewmode = FONT_SEL_VIEW_APPCONTROL;
-               // here
                setting_view_node_table_register(&setting_view_font_font_size, &setting_view_font_main);
                setting_view_node_table_register(&setting_view_font_main, NULL);
+               FREE(category);
                return &setting_view_font_main;
        } else if (0 == safeStrCmp(category, "FontSize")) {
                SETTING_TRACE("category = %s", category);
                fontUG->viewmode = FONT_SIZE_VIEW_APPCONTROL;
                setting_view_node_table_register(&setting_view_font_font_size, NULL);
+               FREE(category);
                return &setting_view_font_font_size;
        }else {
                SETTING_TRACE("HERE ?? <<<<< ");
+               char *viewtype = NULL;
+               app_control_get_extra_data(service, "viewtype", &viewtype);
+               if(!safeStrCmp(viewtype, "FontType_expand")){
+                       fontUG->font_expand_state = FONT_EXPAND_STATE_FONT_TYPE;
+               }else if(!safeStrCmp(viewtype, "FontSize_expand")){
+                       fontUG->font_expand_state = FONT_EXPAND_STATE_FONT_SIZE;
+               }else{
+                       fontUG->font_expand_state = FONT_EXPAND_STATE_NONE;
+               }
                fontUG->viewmode = FONT_SIZE_AND_FONT_SEL_UG;   // set default
                setting_view_node_table_register(&setting_view_font_font_size, &setting_view_font_main);
                setting_view_node_table_register(&setting_view_font_main, NULL);
+               FREE(category);
                return &setting_view_font_main;
        }
 }
 
+//-------------------------------------------------------------
+// http://tizen.org/appcontrol/operation/configure/font/type
+// http://tizen.org/appcontrol/operation/configure/font/size
+//-------------------------------------------------------------
+setting_view * __app_control_get_operation_handler(void* data,app_control_h service)
+{
+       SETTING_TRACE_BEGIN;
+       setting_retvm_if((!data), NULL, "data is NULL");
+       setting_retvm_if((!service), NULL, "service is NULL");
+       SettingFontUG *fontUG = (SettingFontUG *)data;
+       char *output_url = NULL;
+
+       int ret = app_control_get_operation(service, &output_url);
+
+       if(ret == APP_CONTROL_ERROR_NONE)
+       {
+               //SETTING_TRACE(" >>>>>>>>>>>>>>>>>>> (%s) ", output_url);
+               if (0 == safeStrCmp(output_url, "http://tizen.org/appcontrol/operation/configure/font/type")
+                       || 0 == safeStrCmp(output_url, "http://samsung.com/appcontrol/operation/configure/font/type"))
+               {
+                       fontUG->viewmode = FONT_SEL_VIEW_APPCONTROL;
+                       setting_view_node_table_register(&setting_view_font_font_size, &setting_view_font_main);
+                       setting_view_node_table_register(&setting_view_font_main, NULL);
+
+                       FREE(output_url);
+                       return &setting_view_font_main;
+               } else if (0 == safeStrCmp(output_url, "http://tizen.org/appcontrol/operation/configure/font/size")
+                       || 0 == safeStrCmp(output_url, "http://tizen.org/appcontrol/operation/configure/font/size")) {
+                       fontUG->viewmode = FONT_SIZE_VIEW_APPCONTROL;
+                       setting_view_node_table_register(&setting_view_font_font_size, NULL);
+
+                       FREE(output_url);
+                       return &setting_view_font_font_size;
+               } else {
+                       SETTING_TRACE("No URL, default action - argument parsing");
+                       FREE(output_url);
+                       return __default_view_state(fontUG, service);
+               }
+       }else{
+               SETTING_TRACE("failed to call app_control_get_operation with error code %d",ret);
+               if(output_url) {
+                       FREE(output_url);
+               }
+               return NULL;
+       }
+}
+
+setting_view *__get_font_view_to_load(void *data,app_control_h service)
+{
+       SETTING_TRACE_BEGIN;
+       setting_retvm_if((!data), NULL, "data is NULL");
+       SettingFontUG *fontUG = (SettingFontUG *)data;
+
+       //if ug is called by accessibility, view node table should not be initialized
+       char *caller = NULL;
+       app_control_get_extra_data(service, "caller", &caller);
+       if (0 != safeStrCmp(caller, "accessibility")) {
+               /*need to initialize the node table when UG is re-created and it is NOT loaded by another UG*/
+               setting_view_node_table_intialize();
+       }
+       FREE(caller);
+
+       // if argument is there, process it first
+       char *output_url = NULL;
+       int ret = app_control_get_operation(service, &output_url);
+
+       // service OK, but there's no argument
+       if((ret == APP_CONTROL_ERROR_NONE)
+               && (0 == safeStrCmp(output_url, "http://tizen.org/appcontrol/operation/default")
+               || 0 == safeStrCmp(output_url, "http://samsung.com/appcontrol/operation/default")))
+       {
+               FREE(output_url);
+               return __default_view_state(fontUG, service);
+
+       } else if(ret == APP_CONTROL_ERROR_NONE) {
+               FREE(output_url);
+               return __app_control_get_operation_handler(fontUG, service);
+
+       } else{
+               if(output_url) {
+                       FREE(output_url);
+               }
+               // service is not OK, but need to handle default action
+               return __default_view_state(fontUG, service);
+       }
+}
+
 static void setting_font_ug_cb_resize(void *data, Evas *e, Evas_Object *obj,
                                      void *event_info)
 {
@@ -60,7 +163,7 @@ static void setting_font_ug_cb_resize(void *data, Evas *e, Evas_Object *obj,
 }
 
 static void *setting_font_ug_on_create(ui_gadget_h ug, enum ug_mode mode,
-                                      service_h service, void *priv)
+                                      app_control_h service, void *priv)
 {
        setting_retvm_if((!priv), NULL, "!priv");
        SettingFontUG *fontUG = priv;
@@ -76,18 +179,12 @@ static void *setting_font_ug_on_create(ui_gadget_h ug, enum ug_mode mode,
        setting_retvm_if(fontUG->win_main_layout == NULL, NULL,
                         "cannot get main window ");
 
-       fontUG->itc_seperator.item_style = "dialogue/separator";
-       fontUG->itc_seperator.func.text_get = NULL;
-       fontUG->itc_seperator.func.content_get = NULL;
-       fontUG->itc_seperator.func.state_get = NULL;
-       fontUG->itc_seperator.func.del = NULL;
-
-       setting_create_Gendial_itc("dialogue/2text.3/expandable", &(fontUG->itc_2text_3_parent));
-       setting_create_Gendial_itc("dialogue/1text.1icon/expandable2", &(fontUG->itc_1icon_1text_sub));
-       setting_create_Gendial_itc("dialogue/2text.3", &(fontUG->itc_2text_2));
-       setting_create_Gendial_itc("dialogue/1text.1icon.3.tb", &(fontUG->itc_1text_1icon_2));
-       setting_create_Gendial_itc("dialogue/title", &(fontUG->itc_group_item));
-       setting_create_Gendial_itc("multiline/1text", &(fontUG->itc_bg_1icon));
+       setting_create_Gendial_itc("2line.top", &(fontUG->itc_2text_3_parent));
+       setting_create_Gendial_itc("2line.top", &(fontUG->itc_1icon_1text_sub));
+       //setting_create_Gendial_itc("dialogue/2text.3", &(fontUG->itc_2text_2));
+       setting_create_Gendial_itc("2line.top", &(fontUG->itc_2text_2));
+       setting_create_Gendial_itc("groupindex", &(fontUG->itc_group_item));
+       setting_create_Gendial_itc("multiline", &(fontUG->itc_bg_1icon));
 
        // view type checking
        fontUG->view_to_load = __get_font_view_to_load(fontUG, service);
@@ -102,22 +199,22 @@ static void *setting_font_ug_on_create(ui_gadget_h ug, enum ug_mode mode,
        return fontUG->ly_main;
 }
 
-static void setting_font_ug_on_start(ui_gadget_h ug, service_h service,
+static void setting_font_ug_on_start(ui_gadget_h ug, app_control_h service,
                                     void *priv)
 {
 }
 
-static void setting_font_ug_on_pause(ui_gadget_h ug, service_h service,
+static void setting_font_ug_on_pause(ui_gadget_h ug, app_control_h service,
                                     void *priv)
 {
 }
 
-static void setting_font_ug_on_resume(ui_gadget_h ug, service_h service,
+static void setting_font_ug_on_resume(ui_gadget_h ug, app_control_h service,
                                      void *priv)
 {
 }
 
-static void setting_font_ug_on_destroy(ui_gadget_h ug, service_h service,
+static void setting_font_ug_on_destroy(ui_gadget_h ug, app_control_h service,
                                       void *priv)
 {
        SETTING_TRACE_BEGIN;
@@ -127,18 +224,8 @@ static void setting_font_ug_on_destroy(ui_gadget_h ug, service_h service,
        evas_object_event_callback_del(fontUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_font_ug_cb_resize);       /* fix flash issue for gallery */
        fontUG->ug = ug;
 
-#if 0
-       /*  delete the allocated objects. */
-       if (fontUG->view_to_load == &setting_view_font_font_size) {
-               setting_view_destroy(&setting_view_font_font_size, fontUG);
-       } else {
-               setting_view_destroy(&setting_view_font_font_size, fontUG);
-               setting_view_destroy(&setting_view_font_main, fontUG);
-       }
-#else
        setting_view_destroy(&setting_view_font_font_size, fontUG);
        setting_view_destroy(&setting_view_font_main, fontUG);
-#endif
 
        if (NULL != ug_get_layout(fontUG->ug)) {
                evas_object_hide((Evas_Object *) ug_get_layout(fontUG->ug));
@@ -148,22 +235,26 @@ static void setting_font_ug_on_destroy(ui_gadget_h ug, service_h service,
        SETTING_TRACE_END;
 }
 
-static void setting_font_ug_on_message(ui_gadget_h ug, service_h msg,
-                                      service_h service, void *priv)
+static void setting_font_ug_on_message(ui_gadget_h ug, app_control_h msg,
+                                      app_control_h service, void *priv)
 {
        SETTING_TRACE_BEGIN;
 }
 
+
 static void setting_font_ug_on_event(ui_gadget_h ug, enum ug_event event,
-                                    service_h service, void *priv)
+                                    app_control_h service, void *priv)
 {
        SETTING_TRACE_BEGIN;
+       SettingFontUG *ad = (SettingFontUG *)priv;
+       setting_retm_if(NULL == ad, "ad is NULL");
        switch (event) {
        case UG_EVENT_LOW_MEMORY:
                break;
        case UG_EVENT_LOW_BATTERY:
                break;
        case UG_EVENT_LANG_CHANGE:
+               setting_navi_items_update(ad->navibar);
                break;
        case UG_EVENT_ROTATE_PORTRAIT:
                break;
@@ -181,12 +272,13 @@ static void setting_font_ug_on_event(ui_gadget_h ug, enum ug_event event,
 }
 
 static void setting_font_ug_on_key_event(ui_gadget_h ug,
-                                        enum ug_key_event event, service_h service,
+                                        enum ug_key_event event, app_control_h service,
                                         void *priv)
 {
        SETTING_TRACE_BEGIN;
-       if (!ug)
+       if (!ug) {
                return;
+       }
 
        switch (event) {
        case UG_KEY_EVENT_END:
@@ -214,6 +306,8 @@ UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
        ops->priv = fontUG;
        ops->opt = UG_OPT_INDICATOR_ENABLE;
 
+       memset(fontUG, 0x00, sizeof(SettingFontUG));
+
        return 0;
 }
 
@@ -235,96 +329,26 @@ UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
  *
  ***************************************************/
 
-int setting_font_update_vconf_key_int_type(void *data,
-                                          setting_int_slp_list slp_key)
-{
-       SETTING_TRACE_BEGIN;
-       /* error check */
-       if (data == NULL) {
-               return SETTING_GENERAL_ERR_NULL_DATA_PARAMETER;
-       }
-
-       int ret = SETTING_RETURN_FAIL;
-       int value;
-       int err;
-       /* SettingFontUG *ad = (SettingFontUG *)data; */
-
-       ret = setting_get_int_slp_key(slp_key, &value, &err);
-
-       switch (slp_key) {
-               /*
-                  case INT_SLP_SETTING_LCD_TIMEOUT_NORMAL:
-                  {
-                  if (ret == SETTING_RETURN_FAIL) value = SETTING_BACKLIGHT_TIME_15SEC;
-
-                  switch(value)
-                  {
-                  case SETTING_BACKLIGHT_TIME_8SEC:    edje_object_part_text_set(_EDJ(ad->eo_DC_backlight), DC_ITEM_SUB_STR_BACKLIGHT, _(STR_SETTING_8SEC)); break;
-                  case SETTING_BACKLIGHT_TIME_15SEC: edje_object_part_text_set(_EDJ(ad->eo_DC_backlight), DC_ITEM_SUB_STR_BACKLIGHT, _(STR_SETTING_15SEC)); break;
-                  case SETTING_BACKLIGHT_TIME_30SEC: edje_object_part_text_set(_EDJ(ad->eo_DC_backlight), DC_ITEM_SUB_STR_BACKLIGHT, _(STR_SETTING_30SEC)); break;
-                  case SETTING_BACKLIGHT_TIME_1MIN: edje_object_part_text_set(_EDJ(ad->eo_DC_backlight), DC_ITEM_SUB_STR_BACKLIGHT, _(STR_SETTING_1MIN)); break;
-                  case SETTING_BACKLIGHT_TIME_3MIN: edje_object_part_text_set(_EDJ(ad->eo_DC_backlight), DC_ITEM_SUB_STR_BACKLIGHT, _(STR_SETTING_3MIN)); break;
-                  case SETTING_BACKLIGHT_TIME_10MIN: edje_object_part_text_set(_EDJ(ad->eo_DC_backlight), DC_ITEM_SUB_STR_BACKLIGHT, _(STR_SETTING_10MIN)); break;
-                  default: ret = SETTING_GENERAL_ERR_NOT_FIND_VALUE_SWITCH;
-                  }
-                  }
-                  break;
-                */
+static Setting_Cfg_Node_T s_cfg_node_array[] = {
+       {"IDS_ST_BODY_FONT_TYPE", NULL, "viewtype:FontType_expand;tab:first;keyword:IDS_ST_BODY_FONT_TYPE", 0, 0, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
+       {"IDS_ST_MBODY_FONT_SIZE", NULL, "viewtype:FontSize_expand;tab:first;keyword:IDS_ST_MBODY_FONT_SIZE", 0, 0, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
+};
 
-       default:
-               ret = SETTING_GENERAL_ERR_NOT_FIND_VALUE_SWITCH;
-               break;
-       }
-
-       return ret;
-}
-
-int setting_font_update_vconf_key(void *data, setting_vconf_type type,
-                                 int slp_key)
+UG_MODULE_API int setting_plugin_search_init(app_control_h service, void *priv, char** applocale)
 {
        SETTING_TRACE_BEGIN;
-       /* error check */
-       if (data == NULL) {
-               return SETTING_GENERAL_ERR_NULL_DATA_PARAMETER;
-       }
+       SETTING_TRACE(">> setting-font-efl DB search code");
+       setting_retvm_if(!priv || !applocale,SETTING_GENERAL_ERR_NULL_DATA_PARAMETER, "pplist/applocale is NULL");
 
-       int ret = SETTING_RETURN_FAIL;
-       SettingFontUG *ad = (SettingFontUG *) data;
+       *applocale = strdup("setting:/usr/apps/org.tizen.setting/res/locale");
 
-       switch (type) {
-       case SETTING_VCONF_INT_TYPE:
-               ret = setting_font_update_vconf_key_int_type(ad, slp_key);
-               break;
-
-       case SETTING_VCONF_BOOL_TYPE:
-               break;
-
-       case SETTING_VCONF_STR_TYPE:
-               break;
-       default:
-               /* do nothing */
-               break;
+       Eina_List **pplist = (Eina_List**)priv;
+       int i;
+       int size = sizeof(s_cfg_node_array)/sizeof(s_cfg_node_array[0]);
+       for(i=0;i<size;i++) {
+               Setting_Cfg_Node_T * node = setting_plugin_search_item_subindex_add(s_cfg_node_array[i].key_name, s_cfg_node_array[i].ug_args, IMG_Font,s_cfg_node_array[i].item_type,  s_cfg_node_array[i].data, "Font");
+               *pplist = eina_list_append(*pplist, node);
        }
-
-       return ret;
-}
-/**
-* Reset function to 'reset' the settings of the UG, it will be invoked by 'Reset' UG
-*/
-UG_MODULE_API int setting_plugin_reset(service_h service, void *priv)
-{
-       SETTING_TRACE_BEGIN;
-       int ret = 0;
-       int value = SYSTEM_SETTINGS_FONT_SIZE_NORMAL;
-       vconf_get_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &value);
-       if (value != SYSTEM_SETTINGS_FONT_SIZE_NORMAL)
-       {
-               /* reset font type, default is HelveticaNeue */
-               font_config_set("HelveticaNeue");
-               ret += vconf_set_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, SYSTEM_SETTINGS_FONT_SIZE_NORMAL);
-               setting_retvm_if(ret == -1, ret, "Failed to set vconf");
-               font_size_set();
-       }
-       return ret;
+       return 0;
 }