add ui update when 3rd party app setting update
authorMyoungJune Park <mj2004.park@samsung.com>
Fri, 14 Sep 2012 10:12:34 +0000 (19:12 +0900)
committerMyoungJune Park <mj2004.park@samsung.com>
Fri, 14 Sep 2012 10:12:34 +0000 (19:12 +0900)
include/setting-plugin.h
include/setting.h
src/setting-main.c
src/setting-plugin.c
src/setting.c

index 7606b9c..fd260c5 100755 (executable)
@@ -1,5 +1,13 @@
 #ifndef _SETTING_PLUGIN_H_
 #define _SETTING_PLUGIN_H_
+
+#include <setting.h>
+#include <Elementary.h>
+#include <Eina.h>
+
+#include <libxml/xmlmemory.h>
+#include <libxml/parser.h>
+
 #ifndef bool
 #define bool int
 #define TRUE 1
 #endif
 
 #if 1
-#define PLUGIN_INIT \
+#define PLUGIN_INIT( context ) \
 {\
        setting_drawer_list_init();\
-       setting_dbus_handler_init();\
+       setting_dbus_handler_init( context );\
 }
 #define PLUGIN_FINI \
 {\
 
 #endif
 
-extern int setting_dbus_handler_init(void);
+extern int setting_dbus_handler_init(void* data);
 extern int setting_dbus_handler_fini(void);
 extern void setting_drawer_list_init();
 extern void setting_drawer_list_fini();
-extern bool setting_plugin_load(const char *cfg_file);
+
+typedef void* (*drawer_fp)(void *data, xmlNode *xmlObj);
+
+// draw handler
+typedef struct
+{
+       const char* type;                       // ui type
+       drawer_fp draw;
+} Object_Drawer;
+
+// draw handler
+typedef struct
+{
+       xmlDocPtr doc;
+       xmlNode *root;
+
+       const char *cfg_file;
+       Evas_Object *win_get;
+       Evas_Object *ly_main;
+       Evas_Object *scroller;
+       Evas_Object *navi_bar;
+} Draw_Data;
+
+typedef struct PluginNode PluginNode;
+
+
+struct PluginNode
+{
+       char* plugin_path;
+       Draw_Data *pd;
+       Eina_Hash *ui_list;     // UI element to be udpated
+};
+
+extern PluginNode* setting_plugin_create();
+extern bool setting_plugin_load(PluginNode* context, const char *cfg_file);
+extern void setting_plugin_destroy(PluginNode* node);
+
 #endif //_SETTING_PLUGIN_H_
 
index 4399746..ad6118c 100755 (executable)
@@ -170,6 +170,10 @@ typedef struct _setting_main_appdata {
        const char *more_connective_menus[MAX_MORE_MENU_NUM];
        const char *more_system_menus[MAX_MORE_MENU_NUM];
        
+       // plugin xml path;
+       char* plugin_path;      
+//     PluginNode* plugin_node;
+       void* plugin_node;
 
 } setting_main_appdata;
 
index 827d08e..f865c66 100755 (executable)
@@ -996,11 +996,18 @@ static void draw_3rdapp(void* data, char* name, char* pkgname)
 
        if (ad)
        {
+               if (ad->plugin_path)
+               {
+                       free(ad->plugin_path);
+                       ad->plugin_path = NULL;
+               }
+               ad->plugin_path = strdup(fullpath);
+
                setting_create_Gendial_field_groupitem(ad->main_genlist,
                                                           &(ad->itc[GENDIAL_Type_1text_1icon_2]),
                                                           NULL,
                                                           setting_main_click_list_plugin_cb,
-                                                          strdup(fullpath),
+                                                          ad,
                                                           SWALLOW_Type_INVALID,
                                                           IMG_DefaultIcon, NULL,
                                                           0, name, NULL,
@@ -1846,6 +1853,14 @@ static int setting_main_destroy(void *cb)
                evas_object_del(ad->flight_popup);
                ad->flight_popup = NULL;
        }
+
+#if 0
+       if (ad->plugin_node)
+       {
+               setting_plugin_destroy(ad->plugin_node);
+       }
+#endif
+
        setting_view_main.is_create = 0;
        SETTING_TRACE_END;
        return SETTING_RETURN_SUCCESS;
@@ -2165,8 +2180,26 @@ setting_main_click_list_plugin_cb(void *data, Evas_Object *obj,
        retm_if(event_info == NULL, "Invalid argument: event info is NULL");
        Elm_Object_Item *item = (Elm_Object_Item *) event_info;
        elm_genlist_item_selected_set(item, EINA_FALSE);
+
+       setting_main_appdata *ad = data;
 #ifdef PLUGIN
-       setting_plugin_load((const char *)data);
+       if (ad->plugin_path)
+       {
+               PluginNode* plugin_node = setting_plugin_create();
+
+               plugin_node->plugin_path = strdup(ad->plugin_path);
+
+               setting_plugin_load(plugin_node, (const char *)ad->plugin_path);
+               ad->plugin_node = (void*)plugin_node;
+
+               #if 0
+               if(ad->plugin_path)
+               {
+                       free(ad->plugin_path);
+                       ad->plugin_path = NULL;
+               }
+               #endif
+       }
 #endif
 }
 
index 7acc839..776cfbb 100755 (executable)
@@ -23,8 +23,6 @@
 #include <eina_list.h>
 #include <glib.h>
 
-#include <libxml/xmlmemory.h>
-#include <libxml/parser.h>
 
 #include <setting-debug.h>
 #include <setting-common-general-func.h>
 
 #include <setting-plugin.h>
 
+
+
+static Setting_GenGroupItem_Data *g_list_item; /*TEST*/
+
+
+
 /*
  * UI draw handler table : _g_draw_list
  *  - contains Object_Drawer typed object.
  */
 Eina_List *_g_drawer_list = NULL;
 
-typedef void (*drawer_fp)(void *data, xmlNode *xmlObj);
-static void group_func(void *data, xmlNode *xmlObj);
-static void link_func(void *data, xmlNode *xmlObj);
-static void slider_func(void *data, xmlNode *xmlObj);
-static void label_func(void *data, xmlNode *xmlObj);
-static void navigationbar_func(void *data, xmlNode *xmlObj);
-static void checkbox_func(void *data, xmlNode *xmlObj);
-static void editbox_func(void *data, xmlNode *xmlObj);
-static void expanditem_func(void *data, xmlNode *xmlObj);
-static void expandlist_func(void *data, xmlNode *xmlObj);
-static void settings_func(void *data, xmlNode *xmlObj);
-static void setting_func(void *data, xmlNode *xmlObj);
-
-// draw handler
-typedef struct
-{
-       const char* type;                       // ui type
-       drawer_fp draw;
-} Object_Drawer;
+/**
+ * @return Evas_Object * obj
+ */
+static void* navigationbar_func(void *data, xmlNode *xmlObj);
+
+
+/*
+ * @return void
+ */ 
+static void* group_func(void *data, xmlNode *xmlObj);
+
+/*
+ * @return Setting_GenGroupItem_Data* ptr
+ */
+static void* link_func(void *data, xmlNode *xmlObj);
+
+/*
+ * @return Setting_GenGroupItem_Data* ptr
+ */
+static void* slider_func(void *data, xmlNode *xmlObj);
+
+/*
+ * @return Setting_GenGroupItem_Data* ptr
+ */
+static void* label_func(void *data, xmlNode *xmlObj);
+
+/*
+ * @return Setting_GenGroupItem_Data* ptr
+ */
+static void* checkbox_func(void *data, xmlNode *xmlObj);
+
+/*
+ * @return Setting_GenGroupItem_Data* ptr
+ */
+static void* editbox_func(void *data, xmlNode *xmlObj);
+
+/*
+ * @return Setting_GenGroupItem_Data* ptr
+ */
+static void* expandlist_func(void *data, xmlNode *xmlObj);
+
+/**
+ * @return nothing
+ */
+static void* expanditem_func(void *data, xmlNode *xmlObj);
+
+/**
+ * do nothing
+ */
+static void* settings_func(void *data, xmlNode *xmlObj);
+
+/**
+ * do nothing
+ */
+static void* setting_func(void *data, xmlNode *xmlObj);
+
+static int __node_walker(PluginNode* context, xmlNode* cur);
+
+static int __node_finder(PluginNode* context, xmlNode* cur, char* id_str, char* value);
+
 
 static void __drawer_add(const char *type, drawer_fp draw)
 {
@@ -96,7 +141,8 @@ static drawer_fp __drawer_find(char* type)
        return list_item ? list_item->draw : NULL;
 }
 void setting_drawer_list_init()
-{SETTING_TRACE_BEGIN;
+{
+       SETTING_TRACE_BEGIN;
        /* <navigationbar> */__drawer_add("navigationbar", navigationbar_func);
        /* <bool>          */__drawer_add("bool", checkbox_func);
        /* <string>        */__drawer_add("string", editbox_func);
@@ -140,6 +186,13 @@ void setting_drawer_list_fini()
 #define DBUS_SIGNAL_INTERFACE "org.tizen.setting.signal"
 #define DBUS_SIGNAL "test"
 
+static char* substring(const char* str, size_t begin, size_t len) 
+{ 
+  if (str == 0 || strlen(str) == 0 || strlen(str) < begin || strlen(str) < (begin+len)) 
+    return 0;  
+
+  return strndup(str + begin, len); 
+} 
 
 //------------------------------------------------------
 // for client - bus
@@ -155,6 +208,8 @@ static DBusHandlerResult __signal_filter(DBusConnection* conn, DBusMessage* mess
     DBusError error;
     dbus_error_init(&error);
 
+       setting_main_appdata *ad = user_data;
+
     if (dbus_message_is_signal(message, DBUS_SIGNAL_INTERFACE, DBUS_SIGNAL))
     {
         if (dbus_message_get_args(message, &error,
@@ -172,6 +227,43 @@ static DBusHandlerResult __signal_filter(DBusConnection* conn, DBusMessage* mess
     if (sender_pid != 0 && my_pid != sender_pid)
     {
         SETTING_TRACE("received key : %s , value : %s", key, value);
+               //-------------------------------------------------------------
+               // received key : checkbox1|N/A , value : INT|1 
+               //-------------------------------------------------------------
+               //char* key = "checkbox1|N/A";
+               char* ptr = strchr(key, '|');
+
+               xmlDocPtr doc = NULL;
+               if (ptr && key)
+               {   
+                       //parsing for : checkbox1|N/A  -> checkbox1
+                       char* key_name = substring(key, 0, strlen(key)-strlen(ptr));
+                       char* val_name = strchr(value, '|');
+                       val_name++;
+    
+                       // ad->plugin_path
+                       // access xml file
+                       doc = xmlParseFile(ad->plugin_path);
+                       // generate xml tree
+                       xmlNode *root = xmlDocGetRootElement(doc);
+                       // find a node
+                       __node_finder((PluginNode*)ad->plugin_node, root, key_name ,val_name);
+               }   
+               // update the node
+               GError *error = NULL;
+
+               /*
+               if(doc != NULL)
+               {
+                       xmlSaveFormatFile(ad->plugin_path, doc, 1);
+                       // TODO: make sure this is right
+                       xmlFreeDoc(doc);
+                       doc = NULL;
+                       SETTING_TRACE("__cfg_file_write successful");
+               }
+               */
+
+               // update UI
     }
 
     return DBUS_HANDLER_RESULT_HANDLED;
@@ -239,7 +331,7 @@ static void __send_string_msg(xmlNode* xmlObj, char *string)
 }
 
 
-int setting_dbus_handler_init(void)
+int setting_dbus_handler_init(void* user_data)
 {
        SETTING_TRACE_BEGIN;
     DBusError error;
@@ -265,7 +357,7 @@ int setting_dbus_handler_init(void)
         return -1;
     }
 
-    if (dbus_connection_add_filter(bus, __signal_filter, NULL, NULL) == FALSE)
+    if (dbus_connection_add_filter(bus, __signal_filter, user_data, NULL) == FALSE)
     {
         return -1;
     }
@@ -304,20 +396,6 @@ int setting_dbus_handler_fini(void)
 
 Elm_Genlist_Item_Class itc_layout;
 
-// draw handler
-typedef struct
-{
-       xmlDocPtr doc;
-       xmlNode *root;
-
-       const char *cfg_file;
-       Evas_Object *win_get;
-       Evas_Object *ly_main;
-       Evas_Object *scroller;
-       Evas_Object *navi_bar;
-} Draw_Data;
-
-
 // write -> update
 static int __cfg_file_write(Draw_Data *pd)
 {
@@ -342,25 +420,31 @@ static void ___click_softkey_back_cb(void *data, Evas_Object *obj,
 {
        SETTING_TRACE_BEGIN;
        ret_if(!data);
-       Draw_Data *pd = data;
+
+       PluginNode* node = (PluginNode*)data;
+       Draw_Data *pd = node->pd;
        if (pd->ly_main) {
                evas_object_del(pd->ly_main);
                pd->ly_main = NULL;
        }
 
-       pd->scroller = NULL;
-       pd->navi_bar = NULL;
-       pd->cfg_file = NULL;
+       setting_plugin_destroy(node);
+
+//     pd->scroller = NULL;
+//     pd->navi_bar = NULL;
+//     pd->cfg_file = NULL;
 
-       pd->root = NULL;
+//     pd->root = NULL;
 }
 
 
-static void group_func(void *data, xmlNode *xmlObj)
+static void* group_func(void *data, xmlNode *xmlObj)
 {
        SETTING_TRACE_BEGIN;
        ret_if(!data || !xmlObj);
-       Draw_Data *pd = data;
+
+       PluginNode* node = (PluginNode*)data;
+       Draw_Data *pd = node->pd;
 
        // original code is non-recursive
 #if 0
@@ -390,10 +474,12 @@ static void group_func(void *data, xmlNode *xmlObj)
        SETTING_TRACE (" >>> GROUP NAME : %s \n", title);
        (void)setting_create_Gendial_field_titleItem(pd->scroller, &(itc_group_item), title, NULL);
 #endif
+
+       return NULL;
 };
 
 
-static void __link_list_cb(void *data, Evas_Object *obj, void *event_info)
+static void* __link_list_cb(void *data, Evas_Object *obj, void *event_info)
 {
        ret_if(data == NULL);
        retm_if(event_info == NULL, "Invalid argument: event info is NULL");
@@ -415,34 +501,48 @@ static void __link_list_cb(void *data, Evas_Object *obj, void *event_info)
        snprintf(file, sizeof(file), "%s/%s", PLUGIN_CFG_DIR, link_file);
        SETTING_TRACE("file:%s", file);
 
-       setting_plugin_load(file);
+       PluginNode* plugin_node = setting_plugin_create();
+       setting_plugin_load(plugin_node, (const char *)file);
+
+       //setting_plugin_load(NULL, file);
+
+       return NULL;
 }
 
 
-static void label_func(void *data, xmlNode *xmlObj)
+static void* label_func(void *data, xmlNode *xmlObj)
 {
        SETTING_TRACE_BEGIN;
        ret_if(!data || !xmlObj);
-       Draw_Data *pd = data;
+       PluginNode* node = (PluginNode*)data;
+       Draw_Data *pd = node->pd;
+
        const char *title = (char*)xmlGetProp(xmlObj, "title");
 
-       setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
-                                        NULL,
-                                        xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
-                                        0, title, NULL, NULL);
+       Setting_GenGroupItem_Data *obj =
+               setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
+                                                NULL,
+                                                xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
+                                                0, title, NULL, NULL);
+
+       return obj;
 }
 
-static void link_func(void *data, xmlNode *xmlObj)
+static void* link_func(void *data, xmlNode *xmlObj)
 {
        SETTING_TRACE_BEGIN;
        ret_if(!data || !xmlObj);
-       Draw_Data *pd = data;
+       PluginNode* node = (PluginNode*)data;
+       Draw_Data *pd = node->pd;
+
        const char *key_str = (char*)xmlGetProp(xmlObj, "id");
+       Setting_GenGroupItem_Data * obj = 
+               setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
+                                                __link_list_cb,
+                                                xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
+                                                0, key_str, NULL, NULL);
 
-       setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
-                                        __link_list_cb,
-                                        xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
-                                        0, key_str, NULL, NULL);
+       return (void*)obj;
 };
 
 
@@ -475,11 +575,12 @@ static void __slider_stop_cb(void *data, Evas_Object *obj,
 }
 
 
-static void slider_func(void *data, xmlNode *xmlObj)
+static void* slider_func(void *data, xmlNode *xmlObj)
 {
        SETTING_TRACE_BEGIN;
        ret_if(!data || !xmlObj);
-       Draw_Data *pd = data;
+       PluginNode* node = (PluginNode*)data;
+       Draw_Data *pd = node->pd;
 
        // type casting
        const char *title = (char*)xmlGetProp(xmlObj, "title");
@@ -510,14 +611,24 @@ static void slider_func(void *data, xmlNode *xmlObj)
                list_item->stop_change_cb = __slider_stop_cb;
                list_item->belongs_to = (int)pd;
        }
-};
 
+       g_list_item = list_item;
+
+       return (void*)list_item;
+};
 
-static void navigationbar_func(void *data, xmlNode *xmlObj)
+/*
+  elm_object_item_data_set(item_to_update->item, item_to_update);
+  elm_genlist_item_update(item_to_update->item);
+*/
+static void* navigationbar_func(void *data, xmlNode *xmlObj)
 {
        SETTING_TRACE_BEGIN;
        ret_if(!data || !xmlObj);
-       Draw_Data *pd = data;
+
+       //Draw_Data *pd = node->pd;
+       PluginNode* node = (PluginNode*)data;
+       Draw_Data *pd = node->pd;
 
        //----------------------------------------------------------------
        // [DATA] title, btn[0], btn[1]
@@ -545,8 +656,11 @@ static void navigationbar_func(void *data, xmlNode *xmlObj)
                                                   _(title),
                                                   _(btn[1]), _(btn[0]),
                                                   ___click_softkey_back_cb,
-                                                  ___click_softkey_back_cb, pd, &pd->scroller,
+                                                  ___click_softkey_back_cb, data, &pd->scroller,
                                                   &(pd->navi_bar));
+
+       //return (void*)(pd->ly_main);
+       return NULL;
 };
 
 
@@ -608,11 +722,13 @@ static void __chk_btn_cb(void *data, Evas_Object *obj,
 }
 
 
-static void checkbox_func(void *data, xmlNode *xmlObj)
+static void* checkbox_func(void *data, xmlNode *xmlObj)
 {
        SETTING_TRACE_BEGIN;
        ret_if(!data || !xmlObj);
-       Draw_Data *pd = data;
+
+       PluginNode* node = (PluginNode*)data;
+       Draw_Data *pd = node->pd;
 
        // [DATA] title, value
        const char *title = (char*)xmlGetProp(xmlObj, "title");
@@ -647,7 +763,9 @@ static void checkbox_func(void *data, xmlNode *xmlObj)
                list_item->belongs_to = (int) pd;
                SETTING_TRACE("pd:%p,list_item->belongs_to:%d", pd, list_item->belongs_to);
        }
-};
+
+       return list_item;
+}
 
 
 static void __entry_unfocus_cb(void *data, Evas_Object *obj, void *event_info)
@@ -715,11 +833,13 @@ static void __editbox_changed_cb(void *data, Evas_Object *obj,
 }
 
 
-static void editbox_func(void *data, xmlNode *xmlObj)
+static void* editbox_func(void *data, xmlNode *xmlObj)
 {
        SETTING_TRACE_BEGIN;
        ret_if(!data || !xmlObj);
-       Draw_Data *pd = data;
+
+       PluginNode* node = (PluginNode*)data;
+       Draw_Data *pd = node->pd;
 
        const char *title = (char*)xmlGetProp(xmlObj, "title");
        const char *key_str= (char*)xmlGetProp(xmlObj, "value");
@@ -737,6 +857,8 @@ static void editbox_func(void *data, xmlNode *xmlObj)
                list_item->stop_change_cb = __entry_unfocus_cb;
                list_item->belongs_to = (int)pd;
        }
+
+       return list_item;
 };
 
 
@@ -773,7 +895,10 @@ static void __expanditem_func_exp_cb(void *data, Evas_Object *obj, void *event_i
 {
        ret_if(NULL == data || NULL == event_info);
        SETTING_TRACE_BEGIN;
-       Draw_Data *pd = data;
+
+       PluginNode* node = (PluginNode*)data;
+       Draw_Data *pd = node->pd;
+
        Elm_Object_Item *parentItem = event_info;       /* parent item */
        Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem);      /* parent data */
        Evas_Object *scroller = elm_object_item_widget_get(parentItem);
@@ -840,15 +965,15 @@ static void __expanditem_func_smart_cb(void *data, Evas_Object *obj, void *event
 }
 
 
-static void settings_func(void *data, xmlNode *xmlObj)
+static void* settings_func(void *data, xmlNode *xmlObj)
 {
-
+       return NULL;
 }
 
 // <setting>
-static void setting_func(void *data, xmlNode *xmlObj)
+static void* setting_func(void *data, xmlNode *xmlObj)
 {
-#if 0
+#if 0/*{{{*/
        // DO NOTHING
        //----------------------------------------------------------------
        // [DATA] title, btn[0], btn[1]
@@ -881,25 +1006,30 @@ static void setting_func(void *data, xmlNode *xmlObj)
                                                   ___click_softkey_back_cb,
                                                   ___click_softkey_back_cb, pd, &pd->scroller,
                                                   &(pd->navi_bar));
-#endif
+#endif/*}}}*/
+
+       return NULL;
 }
 
 
-static void expanditem_func(void *data, xmlNode *xmlObj)
+static void* expanditem_func(void *data, xmlNode *xmlObj)
 {
        // DO NOTHING - expandlist draws this area
-};
-
+       return NULL;
+}
 
-static void expandlist_func(void *data, xmlNode *xmlObj)
+static void* expandlist_func(void *data, xmlNode *xmlObj)
 {
        SETTING_TRACE_BEGIN;
        ret_if(!data || !xmlObj);
-       Draw_Data *pd = data;
+
+       PluginNode* node = (PluginNode*)data;
+       Draw_Data *pd = node->pd;
+
        const char *key_str = (char*)xmlGetProp(xmlObj, "title");
        const char *value = (char*)xmlGetProp(xmlObj, "value"); // string -> value
 
-       setting_enable_expandable_genlist(pd->scroller, pd, __expanditem_func_exp_cb, __expanditem_func_smart_cb);
+       setting_enable_expandable_genlist(pd->scroller, data, __expanditem_func_exp_cb, __expanditem_func_smart_cb);
        Setting_GenGroupItem_Data *list_item =
            setting_create_Gendial_exp_parent_field(pd->scroller,
                                                    &(itc_2text_3_parent),
@@ -911,13 +1041,17 @@ static void expandlist_func(void *data, xmlNode *xmlObj)
                list_item->userdata = xmlObj;
                list_item->belongs_to = (int)pd;
        }
-};
+
+       return list_item;
+}
 
 
 /////////////
-static int __node_walker(Draw_Data *pd, xmlNode* cur)
+static int __node_walker(PluginNode* context, xmlNode* cur)
 {
        //SETTING_TRACE_BEGIN;
+       Draw_Data *pd = context->pd;
+
        retv_if(!pd, -1);
        xmlNode *cur_node = NULL;
        for (cur_node = cur; cur_node;cur_node = cur_node->next) {
@@ -926,15 +1060,244 @@ static int __node_walker(Draw_Data *pd, xmlNode* cur)
 
                        drawer_fp  fp = __drawer_find(cur_node->name);
                        if (fp)
-                               fp(pd, cur_node); // draw it
+                       {
+                               // type check 
+                               void* vret = fp(context, cur_node); // draw it
+
+                               if (vret) 
+                               {
+                                       Setting_GenGroupItem_Data* genlist_node = (Setting_GenGroupItem_Data* )vret;
+                                       //SETTING_TRACE("add node to Eina List name : %s, id : ", cur_node->name, xmlGetProp(cur_node, "id"));
+                                       // add it to the hash table create before.
+                                       // id, object
+                                       // add list
+                                       char* key_name = xmlGetProp(cur_node, "id");
+                                       eina_hash_add(context->ui_list, strdup(key_name),(void*)genlist_node); 
+                                       //context->ui_list= eina_list_append(context->ui_list, genlist_node);
+                               }
+                       }
+               }
+               __node_walker(context, cur_node->children);     /* RECURSIVE */
+       }
+       return 0;
+}
+
+/**
+ * @param id_str [in] "id"
+ * @param value [in] value to be udpated
+ */
+// refer to __expanditem_func_sel_cb
+static int __node_finder(PluginNode* context, xmlNode* cur, char* id_str, char* value)
+{
+       //SETTING_TRACE_BEGIN;
+       xmlNode *cur_node = NULL;
+       for (cur_node = cur; cur_node;cur_node = cur_node->next) {
+               if (cur_node->type == XML_ELEMENT_NODE) {
+
+                       //SETTING_TRACE("node type : Element, name=%s id=%s", cur_node->name,xmlGetProp(cur_node, "id"));
+                       char* id_name = (char*)xmlGetProp(cur_node, "id");
+                       if ( id_name && 0 == strcmp(id_str, id_name))
+                       {
+                               SETTING_TRACE("FOUND >>>> %s", id_name);
+                               // cur_node     - update xml code
+                               xmlAttrPtr newattr = xmlSetProp(cur_node, "value", value);
+
+                               //-----------------------------------------------------------
+                               // UI UPDATE
+                               // case : slider
+                               if ( 0 == strcmp (cur_node->name, "integer"))
+                               {
+                                       SETTING_TRACE(">>>>> UPDATE SLIDER CONTROL %x --- %s ",context->ui_list, id_name);
+                                       Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name); 
+                                       if      (item_to_update)
+                                       {
+                                               item_to_update->chk_status = atoi(value);
+                                               SETTING_TRACE(">>>   o-------------0 SLIDER VALUE = %d ", item_to_update->chk_status);
+
+                                               elm_object_item_data_set(item_to_update->item, item_to_update);
+                                               elm_genlist_item_update(item_to_update->item);
+                                       } else {
+                                               SETTING_TRACE("item_to_update is NULL");
+                                       }
+                               }                               
+                               // case : toggle
+                               if ( 0 == strcmp (cur_node->name, "bool"))
+                               {
+                                       SETTING_TRACE(">>>>> UPDATE TOGGLE CONTROL %x --- %s ",context->ui_list, id_name);
+                                       Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name); 
+                                       if      (item_to_update)
+                                       {
+                                               item_to_update->chk_status = atoi(value);
+                                               SETTING_TRACE(">>>   o-------------0 TOGGLE VALUE = %d ", item_to_update->chk_status);
+
+                                               elm_object_item_data_set(item_to_update->item, item_to_update);
+                                               elm_genlist_item_update(item_to_update->item);
+                                       } else {
+                                               SETTING_TRACE("item_to_update is NULL");
+                                       }
+                               }
+                               // case : edit control          
+                               if ( 0 == strcmp (cur_node->name, "string"))
+                               {
+                                       SETTING_TRACE(">>>>> UPDATE EDIT CONTROL CONTROL %x --- %s ",context->ui_list, id_name);
+                                       Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name); 
+                                       if      (item_to_update)
+                                       {
+                                               char* old_string = item_to_update->sub_desc;
+                                               item_to_update->sub_desc = strdup(value);
+                                               SETTING_TRACE(">>>   o-------------0 STRING VALUE = %s ", value);
+                                               
+                                               // free old string
+
+                                               elm_object_item_data_set(item_to_update->item, item_to_update);
+                                               elm_genlist_item_update(item_to_update->item);
+                                       } else {
+                                               SETTING_TRACE("item_to_update is NULL");
+                                       }
+                               }
+                               // case : expand list
+                               // parent
+                               //    child1
+                               //    child2
+                               //    child3
+                               //    child4
+                               //-----------------------------------------------------------
+                               if ( 0 == strcmp (cur_node->name, "expandlist"))
+                               {
+                                       SETTING_TRACE(">>>>> UPDATE EXPAND LIST CONTROL %x --- %s ",context->ui_list, id_name);
+                                       Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name); 
+                                       if      (item_to_update)
+                                       {
+                                               char* old_string = item_to_update->sub_desc;
+                                               item_to_update->sub_desc = strdup(value);
+                                               SETTING_TRACE(">>>   o-------------0 EXPAND LIST VALUE = %s ", value);
+
+                                               // free old string
+                                               elm_object_item_data_set(item_to_update->item, item_to_update);
+                                               elm_genlist_item_update(item_to_update->item);
+                                       } else {
+                                               SETTING_TRACE("item_to_update is NULL");
+                                       }
+                               }
+                       }
                }
-               __node_walker(pd, cur_node->children);  /* RECURSIVE */
+               __node_finder(context, cur_node->children, id_str, value);      /* RECURSIVE */
        }
        return 0;
 }
 
+static unsigned int _plugin_string_key_length(const char*key)
+{
+       if (!key)
+               return 0;
+
+       return (int)strlen(key) + 1;
+}
+
+static int _plugin_string_key_cmp(const char* key1, int key1_length, 
+                                                                       const char* key2, int key2_length)
+{
+       return strcmp(key1, key2);
+}
+
+static void _plugin_entry_free_cb(void* data)
+{
+//     free(data);
+//     data = NULL;
+}
+
+//static PluginNode* g_context;
+
+PluginNode* setting_plugin_create()
+{
+       PluginNode *node = calloc(1, sizeof(PluginNode));
+
+       Draw_Data *pd = calloc(1, sizeof(Draw_Data));
+       setting_retvm_if(!pd, -1, "Create Draw_Data obj failed");
+       //eina_init();
+
+       node->pd = pd;
+       node->ui_list = eina_hash_new(EINA_KEY_LENGTH(_plugin_string_key_length),
+                                                                 EINA_KEY_CMP(_plugin_string_key_cmp),
+                                                                 EINA_KEY_HASH(eina_hash_superfast),
+                                                                 _plugin_entry_free_cb,
+                                                                 5); // 2^5
+
+       return node;
+}
+
+void setting_plugin_destroy(PluginNode* node)
+{
+       SETTING_TRACE_BEGIN;
+       if (node) {
+               SETTING_TRACE("node is NOT NULL")
+               if (node->pd) {
+                       SETTING_TRACE("node->pd is NOT NULL")
+                       if(node->pd->doc != NULL) {
+                               xmlSaveFormatFile(node->plugin_path, node->pd->doc, 1);
+                               // TODO: make sure this is right
+                               xmlFreeDoc(node->pd->doc);
+                               node->pd->doc = NULL;
+                               SETTING_TRACE("__cfg_file_write successful");
+                       }
+
+                       SETTING_TRACE("before freeing node->pd");
+                       free(node->pd);
+                       node->pd = NULL;
+                       SETTING_TRACE("after freeing node->pd");
+               }
+
+               SETTING_TRACE("before freeing ui_list");
+               if (node->ui_list) {
+                       eina_hash_free(node->ui_list);
+                       node->ui_list = NULL;
+               }
+               SETTING_TRACE("after freeing ui_list");
+
+               SETTING_TRACE("before freeing node");
+               free(node);
+               node = NULL;
+               SETTING_TRACE("after freeing node");
+       }
+}
+
+
+static Eina_Bool _plugin_foreach_cb(const Eina_Hash *hash, const void*key, void* data, void* fdata)
+{
+    Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) data;
+       SETTING_TRACE("%s --- %s ", (char*)key, node->keyStr);
+
+       return EINA_TRUE;
+}
+
 
-bool setting_plugin_load(const char *cfg_file)
+void setting_plugin_debug(PluginNode* context)
+{
+       SETTING_TRACE("HASH TABLE -------------------------------------");
+       eina_hash_foreach(context->ui_list,_plugin_foreach_cb, NULL);
+       SETTING_TRACE("HASH TABLE -------------------------------------");
+
+}
+
+void setting_plugin_update(PluginNode* context)
+{
+    Eina_List *li = context->ui_list;
+
+    while (li) {
+        Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) eina_list_data_get(li);
+        if (node) {
+            // SETTING_TRACE(" ---> keyStr : %s , swallow type : %d  ", node->keyStr, node->swallow_type);
+                       Setting_GenGroupItem_Data* item_to_update = NULL;
+                       item_to_update = node;
+                       elm_object_item_data_set(item_to_update->item, item_to_update);
+                       elm_genlist_item_update(item_to_update->item);
+        }
+        li = eina_list_next(li);
+       }
+}
+
+
+bool setting_plugin_load(PluginNode* context, const char *cfg_file)
 {
        SETTING_TRACE("cfg_file:%s", cfg_file)
        if (isEmptyStr(cfg_file) || 0 != access(cfg_file, R_OK|W_OK|F_OK ))
@@ -942,20 +1305,20 @@ bool setting_plugin_load(const char *cfg_file)
                SETTING_TRACE_ERROR(" error occured : access \n");
                return FALSE;
        }
+       context->pd->cfg_file = cfg_file;
+       context->pd->win_get = (Evas_Object *) ug_get_window();
 
-       Draw_Data *pd = calloc(1, sizeof(Draw_Data));
-       setting_retvm_if(!pd, -1, "Create Draw_Data obj failed");
-
-       pd->cfg_file = cfg_file;
-       pd->win_get = (Evas_Object *) ug_get_window();
        GError *error = NULL;
 
-       pd->doc = xmlParseFile(cfg_file);
-       pd->root = xmlDocGetRootElement(pd->doc);
+       context->pd->doc = xmlParseFile(cfg_file);
+       context->pd->root = xmlDocGetRootElement(context->pd->doc);
+
        // TODO: error handler here
-       __node_walker(pd, pd->root);
+       __node_walker(context, context->pd->root);
 
-       return TRUE;
+       // debug message
+       setting_plugin_debug(context);
+       return true;
 }
 
 
index cf70ecd..9060738 100755 (executable)
@@ -658,7 +658,7 @@ static int setting_main_app_create(void *data)
 
        /* load config file */
        int cfg_operation_ret = setting_cfg_init();
-       PLUGIN_INIT;
+       PLUGIN_INIT(ad);
 
        elm_theme_extension_add(NULL, SETTING_THEME_EDJ_NAME);
 #if SUPPORT_LCD_TIMEOUT_KEEPING