Fix N_SE-12125,N_SE-10514 and N_SE-9938
[apps/home/settings.git] / src / setting-plugin.c
1 /*
2  * setting
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
5  *
6  * Contact: MyoungJune Park <mj2004.park@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include <unistd.h>
23 #include <eina_list.h>
24 #include <glib.h>
25
26
27 #include <setting-debug.h>
28 #include <setting-common-general-func.h>
29 #include <setting-common-draw-widget.h>
30
31 #include <setting-plugin.h>
32
33
34
35 static Setting_GenGroupItem_Data *g_list_item;  /*TEST*/
36
37
38
39 /*
40  * UI draw handler table : _g_draw_list
41  *  - contains Object_Drawer typed object.
42  */
43 Eina_List *_g_drawer_list = NULL;
44
45 /**
46  * @return Evas_Object * obj
47  */
48 static void* navigationbar_func(void *data, xmlNode *xmlObj);
49
50
51 /*
52  * @return void
53  */
54 static void* group_func(void *data, xmlNode *xmlObj);
55
56 /*
57  * @return Setting_GenGroupItem_Data* ptr
58  */
59 static void* link_func(void *data, xmlNode *xmlObj);
60
61 /*
62  * @return Setting_GenGroupItem_Data* ptr
63  */
64 static void* slider_func(void *data, xmlNode *xmlObj);
65
66 /*
67  * @return Setting_GenGroupItem_Data* ptr
68  */
69 static void* label_func(void *data, xmlNode *xmlObj);
70
71 /*
72  * @return Setting_GenGroupItem_Data* ptr
73  */
74 static void* checkbox_func(void *data, xmlNode *xmlObj);
75
76 /*
77  * @return Setting_GenGroupItem_Data* ptr
78  */
79 static void* editbox_func(void *data, xmlNode *xmlObj);
80
81 /*
82  * @return Setting_GenGroupItem_Data* ptr
83  */
84 static void* expandlist_func(void *data, xmlNode *xmlObj);
85
86 /**
87  * @return nothing
88  */
89 static void* expanditem_func(void *data, xmlNode *xmlObj);
90
91 /**
92  * do nothing
93  */
94 static void* settings_func(void *data, xmlNode *xmlObj);
95
96
97 static void* launch_func(void *data, xmlNode *xmlObj);
98
99 /**
100  * do nothing
101  */
102 static void* setting_func(void *data, xmlNode *xmlObj);
103
104 static int __node_walker(PluginNode* context, xmlNode* cur);
105
106 static int __node_finder(PluginNode* context, xmlNode* cur, char* id_str, char* value, bool* is_end);
107
108
109 static void __drawer_add(const char *type, drawer_fp draw)
110 {
111         Object_Drawer *node = calloc(1, sizeof(Object_Drawer));
112         if (node && type && draw)
113         {
114                 node->type = type;
115                 node->draw = draw;
116
117                 _g_drawer_list = eina_list_append(_g_drawer_list, node);
118         }
119 }
120
121
122 static drawer_fp __drawer_find(char* type)
123 {
124         SETTING_TRACE_BEGIN;
125         SETTING_TRACE("node type:%s", type);
126         Eina_List *check_list = _g_drawer_list;
127         Object_Drawer *list_item = NULL;
128
129         while (check_list) {
130                 list_item = (Object_Drawer *) eina_list_data_get(check_list);
131                 if (NULL == list_item)
132                         continue;
133
134                 if (0 == safeStrCmp(list_item->type, type))
135                 {
136                         //SETTING_TRACE("list_item->type:%s", list_item->type);
137                         break;
138                 }
139                 //if not matched,to check next node.
140                 check_list = eina_list_next(check_list);
141                 list_item = NULL;
142         }
143         //SETTING_TRACE("list_item:%p", list_item);
144         return list_item ? list_item->draw : NULL;
145 }
146 void setting_drawer_list_init()
147 {
148         SETTING_TRACE_BEGIN;
149 #if 0
150         /* <navigationbar> */__drawer_add("navigationbar", navigationbar_func);
151 #endif
152         /* <bool>          */__drawer_add("bool", checkbox_func);
153         /* <string>        */__drawer_add("string", editbox_func);
154         /* <group>         */__drawer_add("group", group_func);
155         /* <integer>       */__drawer_add("integer", slider_func);
156         /* <label>         */__drawer_add("label", label_func);
157         /* <link>          */__drawer_add("link", link_func);
158         /* <launch>        */__drawer_add("launch", launch_func);
159         /* <extendlist>    */__drawer_add("expandlist", expandlist_func);
160         /* <extenditem>    */__drawer_add("expanditem", expanditem_func);
161         /* <settings>      */__drawer_add("settings", settings_func);
162         /* <setting>       */__drawer_add("setting", setting_func);
163 }
164
165 void setting_drawer_list_fini()
166 {
167         if (_g_drawer_list)
168         {
169                 Object_Drawer *node = NULL;
170                 Eina_List *li = _g_drawer_list;
171                 while (li) {
172                         node = (Object_Drawer *) eina_list_data_get(li);
173                         if (node)
174                         {
175                                 //SETTING_TRACE("Deregister %s", node->type);
176                                 FREE(node);
177                         }
178                         li = eina_list_next(li);
179                 }
180                 _g_drawer_list = eina_list_free(_g_drawer_list);
181                 _g_drawer_list = NULL;
182         }
183 }
184
185 /////////////////////////
186 /////////////////////////
187 /////////////////////////
188
189 #define MAX_CONTENT_LEN 512
190 #define MAX_LOCAL_BUFSIZE 128
191 #define DBUS_PATH "/setting/dbus_handler"
192 #define DBUS_SIGNAL_INTERFACE "org.tizen.setting.signal"
193 #define DBUS_SIGNAL "test"
194
195 static char* substring(const char* str, size_t begin, size_t len)
196 {
197   if (str == 0 || strlen(str) == 0 || strlen(str) < begin || strlen(str) < (begin+len))
198     return 0;
199
200   return strndup(str + begin, len);
201 }
202
203 //------------------------------------------------------
204 // for client - bus
205 static DBusConnection *bus;
206 //------------------------------------------------------
207 static DBusHandlerResult __signal_filter(DBusConnection* conn, DBusMessage* message, void* user_data)
208 {
209     int my_pid = getpid();
210     int sender_pid = 0;
211     char* key = NULL;
212     char* value = NULL;
213
214     DBusError error;
215     dbus_error_init(&error);
216
217         setting_main_appdata *ad = user_data;
218
219     if (dbus_message_is_signal(message, DBUS_SIGNAL_INTERFACE, DBUS_SIGNAL))
220     {
221         if (dbus_message_get_args(message, &error,
222                 DBUS_TYPE_UINT32, &sender_pid,
223                 DBUS_TYPE_STRING, &key,
224                 DBUS_TYPE_STRING, &value,
225                 DBUS_TYPE_INVALID) == FALSE)
226         {
227             SETTING_TRACE_ERROR("Fail to get data : %s", error.message);
228             dbus_error_free(&error);
229             return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
230         }
231     }
232
233     if (sender_pid != 0 && my_pid != sender_pid)
234     {
235         SETTING_TRACE("received key : %s , value : %s", key, value);
236                 //-------------------------------------------------------------
237                 // received key : checkbox1|N/A , value : INT|1
238                 //-------------------------------------------------------------
239                 //char* key = "checkbox1|N/A";
240                 char* ptr = strchr(key, '|');
241
242                 xmlDocPtr doc = NULL;
243                 if (ptr && key)
244                 {
245                         //parsing for : checkbox1|N/A  -> checkbox1
246                         char* key_name = substring(key, 0, strlen(key)-strlen(ptr));
247                         char* val_name = strchr(value, '|');
248                         val_name++;
249
250                         // ad->plugin_path
251                         // access xml file
252                         doc = xmlParseFile(ad->plugin_path);
253                         // generate xml tree
254                         xmlNode *root = xmlDocGetRootElement(doc);
255                         // find a node
256                         bool is_end = false;
257                         __node_finder((PluginNode*)ad->plugin_node, root, key_name ,val_name, &is_end);
258                 }
259                 // update the node
260                 GError *error = NULL;
261
262 #if 0
263                 if(doc != NULL)
264                 {
265                         xmlSaveFormatFile(ad->plugin_path, doc, 1);
266                         // TODO: make sure this is right
267                         xmlFreeDoc(doc);
268                         doc = NULL;
269                         SETTING_TRACE("__cfg_file_write successful");
270                 }
271 #endif
272
273                 // update UI
274     }
275
276     return DBUS_HANDLER_RESULT_HANDLED;
277 }
278
279 static int __send_msg(char* key, char* value)
280 {
281         DBusMessage* message;
282         int sender_pid = getpid();
283
284         if (bus == NULL)
285                 return -1;
286
287         message = dbus_message_new_signal(DBUS_PATH, DBUS_SIGNAL_INTERFACE, DBUS_SIGNAL);
288
289         SETTING_TRACE("Sending message[%s:%s] via dbus", key ,value);
290         if (dbus_message_append_args(message,
291                                 DBUS_TYPE_UINT32, &sender_pid,
292                                 DBUS_TYPE_STRING, &key,
293                                 DBUS_TYPE_STRING, &value,
294                                 DBUS_TYPE_INVALID) == FALSE)
295         {
296                 SETTING_TRACE("Fail to load data error");
297                 return -1;
298         }
299
300         if (dbus_connection_send(bus, message, NULL) == FALSE)
301         {
302                 SETTING_TRACE("Fail to send message");
303                 return -1;
304         }
305
306         dbus_connection_flush(bus);
307         dbus_message_unref(message);
308
309         SETTING_TRACE("[CLIENT] send data signal done");
310
311     return 0;
312 }
313
314
315 static void __send_int_msg(xmlNode* xmlObj, int val)
316 {
317         const char *id = (char*)xmlGetProp(xmlObj, "id");
318         const char *title = (char*)xmlGetProp(xmlObj, "title");
319         char key[MAX_CONTENT_LEN] = {0,};
320         snprintf(key, sizeof(key), "%s|%s", id, title);
321
322         char value[MAX_CONTENT_LEN] = {0,};
323         snprintf(value, sizeof(value), "INT|%d", val);
324         __send_msg(key, value);
325 }
326
327
328 static void __send_string_msg(xmlNode* xmlObj, char *string)
329 {
330         const char *id = (char*)xmlGetProp(xmlObj, "id");
331         const char *title = (char*)xmlGetProp(xmlObj, "title");
332         char key[MAX_CONTENT_LEN] = {0,};
333         snprintf(key, sizeof(key), "%s|%s", id, title);
334
335         char value[MAX_CONTENT_LEN] = {0,};
336         snprintf(value, sizeof(value), "STRING|%s", string);
337         __send_msg(key, value);
338 }
339
340
341 int setting_dbus_handler_init(void* user_data)
342 {
343         SETTING_TRACE_BEGIN;
344         if (bus)
345         {
346                 SETTING_TRACE("already get a bus, need release first.");
347                 setting_dbus_handler_fini();
348         }
349         DBusError error;
350         memset(&error, 0, sizeof(DBusError));
351         char rule[MAX_LOCAL_BUFSIZE + 1] = {0,};
352         dbus_error_init(&error);
353         bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
354         if (!bus)
355         {
356                 SETTING_TRACE("Fail to connect to the D-BUS daemon: %s", error.message);
357                 dbus_error_free(&error);
358                 return -1;
359         }
360
361         dbus_connection_setup_with_g_main(bus, NULL);
362         snprintf(rule, MAX_LOCAL_BUFSIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH, DBUS_SIGNAL_INTERFACE);
363
364         dbus_bus_add_match(bus, rule, &error);
365         if (dbus_error_is_set(&error))
366         {
367                 SETTING_TRACE("Fail to rule set; %s", error.message);
368                 dbus_bus_remove_match(bus, rule, &error);
369                 dbus_error_free(&error);
370                 dbus_connection_close(bus);
371                 bus = NULL;
372                 return -1;
373         }
374
375         if (dbus_connection_add_filter(bus, __signal_filter, user_data, NULL) == FALSE)
376         {
377                 dbus_bus_remove_match(bus, rule, &error);
378                 dbus_error_free(&error);
379                 dbus_connection_close(bus);
380                 bus = NULL;
381                 return -1;
382         }
383
384         SETTING_TRACE("app signal initialized");
385         return 0;
386 }
387
388 int setting_dbus_handler_fini(void)
389 {
390         //do safty checking first.
391         setting_retvm_if(!bus, 0, "!bus");
392         DBusError error;
393         memset(&error, 0, sizeof(DBusError));
394         char rule[MAX_LOCAL_BUFSIZE + 1] = {0, };
395
396         dbus_error_init(&error);
397         //dbus_connection_remove_filter(bus, __signal_filter, NULL);
398         snprintf(rule, MAX_LOCAL_BUFSIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH, DBUS_SIGNAL_INTERFACE);
399         dbus_bus_remove_match(bus, rule, &error);
400
401         if (dbus_error_is_set(&error))
402         {
403                 SETTING_TRACE("Fail to rule unset: %s", error.message);
404                 dbus_error_free(&error);
405                 //return -1;
406         }
407
408         dbus_connection_close(bus);
409         bus = NULL;
410         SETTING_TRACE("app signal finalized");
411         return 0;
412 }
413
414 /////////////////////////////
415 /////////////////////////////
416 /////////////////////////////
417
418 Elm_Genlist_Item_Class itc_layout;
419
420 // write -> update
421 static int __cfg_file_write(Draw_Data *pd)
422 {
423         SETTING_TRACE_BEGIN;
424
425         GError *error = NULL;
426         if(pd->doc != NULL)
427         {
428                 xmlSaveFormatFile(pd->cfg_file, pd->doc, 1);
429                 //xmlFreeDoc(pd->doc);
430                 //pd->doc = NULL;
431                 SETTING_TRACE("__cfg_file_write successful");
432         }
433
434         return TRUE;
435 }
436
437
438 static void ___click_softkey_back_cb(void *data, Evas_Object *obj,
439                                           void *event_info)
440 {
441         SETTING_TRACE_BEGIN;
442         ret_if(!data);
443
444         PluginNode* node = (PluginNode*)data;
445         Draw_Data *pd = node->pd;
446         if (pd->ly_main) {
447                 evas_object_del(pd->ly_main);
448                 pd->ly_main = NULL;
449         }
450
451         setting_plugin_destroy(node);
452
453         pd->scroller = NULL;
454         pd->navi_bar = NULL;
455         pd->cfg_file = NULL;
456
457         pd->root = NULL;
458 }
459
460
461 static void* group_func(void *data, xmlNode *xmlObj)
462 {
463         SETTING_TRACE_BEGIN;
464         ret_if(!data || !xmlObj);
465
466         PluginNode* node = (PluginNode*)data;
467         Draw_Data *pd = node->pd;
468
469         // original code is non-recursive
470 #if 0
471         const char *title = (char*)json_object_get_string_member(jsonObj, "title");
472         (void)setting_create_Gendial_field_titleItem(pd->scroller,
473                                                      &(itc_group_item),
474                                                      title, NULL);
475
476         // non recursive method
477         if (json_object_has_member(jsonObj, "elements"))
478         {
479                 JsonNode* elements_node = json_object_get_member(jsonObj, "elements");
480                 int i;
481                 JsonObject* tempobj;
482                 char* type;
483                 for (i=0; i < json_array_get_length(json_node_get_array(elements_node)); i++)
484                 {
485                         tempobj  = json_array_get_object_element(json_node_get_array(elements_node), i);
486                         type = (char*)json_object_get_string_member(tempobj, "type");
487                         drawer_fp  fp = __drawer_find(type);
488                         if (fp) fp(pd, tempobj); // draw it
489                 }
490         }
491 #else
492         // new code is recursive
493         const char *title = (char*)xmlGetProp(xmlObj, "title");
494         SETTING_TRACE (" >>> GROUP NAME : %s \n", title);
495         (void)setting_create_Gendial_field_titleItem(pd->scroller, &(itc_group_item), title, NULL);
496 #endif
497
498         return NULL;
499 };
500
501
502 static void* __link_list_cb(void *data, Evas_Object *obj, void *event_info)
503 {
504         SETTING_TRACE_BEGIN;
505         ret_if(data == NULL);
506         retm_if(event_info == NULL, "Invalid argument: event info is NULL");
507         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
508         elm_genlist_item_selected_set(item, 0);
509         Setting_GenGroupItem_Data *list_item =
510             (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
511
512         xmlNode* xmlObj = data;
513         ret_if(!xmlObj);
514         const char *link_file = (char*)xmlGetProp(xmlObj, "value");
515
516         if(!link_file)
517         {
518                 SETTING_TRACE_ERROR("Invalidate liked file");
519                 return;
520         }
521         char file[1024] = {0,};
522         snprintf(file, sizeof(file), "%s/%s", PLUGIN_CFG_DIR, link_file);
523         SETTING_TRACE("file:%s", file);
524
525         PluginNode* plugin_node = setting_plugin_create();
526         setting_plugin_load(plugin_node, (const char *)file);
527
528         //setting_plugin_load(NULL, file);
529
530         return NULL;
531 }
532
533 static void* __launch_list_cb(void *data, Evas_Object *obj, void *event_info)
534 {
535         SETTING_TRACE_BEGIN;
536         ret_if(data == NULL);
537         retm_if(event_info == NULL, "Invalid argument: event info is NULL");
538         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
539         elm_genlist_item_selected_set(item, 0);
540         Setting_GenGroupItem_Data *list_item =
541             (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
542
543         xmlNode* xmlObj = data;
544         ret_if(!xmlObj);
545         const char *key_str = (char*)xmlGetProp(xmlObj, "id");
546         const char *title_str = (char*)xmlGetProp(xmlObj, "title");
547         const char *appid_str = (char*)xmlGetProp(xmlObj, "appid");
548         const char *operation_str = (char*)xmlGetProp(xmlObj, "operation");
549
550
551         service_h svc = NULL;
552         service_create(&svc);
553         service_set_app_id(svc, appid_str);                                                     // xml property â€“ appid
554         service_set_operation(svc, operation_str);                                              // property : operation
555         service_send_launch_request(svc, NULL, NULL);
556         service_destroy(svc);
557
558         return NULL;
559 }
560
561 static void* label_func(void *data, xmlNode *xmlObj)
562 {
563         SETTING_TRACE_BEGIN;
564         ret_if(!data || !xmlObj);
565         PluginNode* node = (PluginNode*)data;
566         Draw_Data *pd = node->pd;
567
568         const char *title = (char*)xmlGetProp(xmlObj, "title");
569
570         Setting_GenGroupItem_Data *obj =
571                 setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
572                                                  NULL,
573                                                  xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
574                                                  0, title, NULL, NULL);
575
576         return obj;
577 }
578
579 static void* link_func(void *data, xmlNode *xmlObj)
580 {
581         SETTING_TRACE_BEGIN;
582         ret_if(!data || !xmlObj);
583         PluginNode* node = (PluginNode*)data;
584         Draw_Data *pd = node->pd;
585
586         const char *key_str = (char*)xmlGetProp(xmlObj, "id");
587         Setting_GenGroupItem_Data * obj =
588                 setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
589                                                  __link_list_cb,
590                                                  xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
591                                                  0, key_str, NULL, NULL);
592
593         return (void*)obj;
594 };
595
596 static void* launch_func(void *data, xmlNode *xmlObj)
597 {
598         SETTING_TRACE_BEGIN;
599         ret_if(!data || !xmlObj);
600         PluginNode* node = (PluginNode*)data;
601         Draw_Data *pd = node->pd;
602
603         const char *title_str = (char*)xmlGetProp(xmlObj, "title");
604
605         Setting_GenGroupItem_Data * obj =
606                 setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
607                                                  __launch_list_cb,
608                                                  xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
609                                                  0, title_str, NULL, NULL);
610
611         return (void*)obj;
612 };
613
614 static void __slider_stop_cb(void *data, Evas_Object *obj,
615                                     void *event_info)
616 {
617         ret_if(data == NULL || obj == NULL);
618         double val = elm_slider_value_get(obj);
619         SETTING_TRACE("val = %f", val);
620         Setting_GenGroupItem_Data *list_item = data;
621         ret_if(list_item->userdata == NULL);
622
623         xmlNode* xmlObj = list_item->userdata;
624         ret_if(!xmlObj);
625
626         //apply the vconf changes after stopping moving slider..
627         list_item->chk_status = (int)(val + 0.5);
628         elm_slider_value_set(obj, list_item->chk_status);
629
630         SETTING_TRACE(" slider after ---> val = %d", (int) list_item->chk_status);
631
632         // int -> double -> xmlChar*
633         xmlAttrPtr newattr;
634         char buf[10];
635         sprintf(buf, "%d", (int) list_item->chk_status);
636         newattr = xmlSetProp(xmlObj, "value", buf);
637
638         __send_int_msg(xmlObj, list_item->chk_status);
639         __cfg_file_write((Draw_Data *)list_item->belongs_to);
640 }
641
642
643 static void* slider_func(void *data, xmlNode *xmlObj)
644 {
645         SETTING_TRACE_BEGIN;
646         ret_if(!data || !xmlObj);
647         PluginNode* node = (PluginNode*)data;
648         Draw_Data *pd = node->pd;
649
650         // type casting
651         const char *title = (char*)xmlGetProp(xmlObj, "title");
652
653         SETTING_TRACE (" >>> [slider input] min=%s max=%s value=%s ",(char*)xmlGetProp(xmlObj, "min"), (char*)xmlGetProp(xmlObj, "max"), (char*)xmlGetProp(xmlObj, "value"));
654
655         int value = atoi((char*)xmlGetProp(xmlObj, "value"));
656         int min = atoi((char*)xmlGetProp(xmlObj, "min"));
657         int max = atoi((char*)xmlGetProp(xmlObj, "max"));
658
659         SETTING_TRACE ("[slider input] min=%d max=%d value=%d ", min, max, value);
660
661         setting_create_Gendial_itc("dialogue/1text.1icon.5", &(itc_layout));
662         Setting_GenGroupItem_Data *list_item =
663             setting_create_Gendial_field_def(pd->scroller, &(itc_layout), NULL,
664                                              NULL,
665                                              SWALLOW_Type_LAYOUT_SLIDER,
666                                              IMG_SENSITIVITY_ICON_01,
667                                              IMG_SENSITIVITY_ICON_02, value,
668                                              title, NULL, NULL);
669         if (list_item) {
670                 list_item->win_main = NULL;
671                 list_item->evas = NULL;
672                 list_item->isIndicatorVisible = true;
673                 list_item->slider_min = min;
674                 list_item->slider_max = max;
675                 list_item->userdata = xmlObj;
676                 list_item->stop_change_cb = __slider_stop_cb;
677                 list_item->belongs_to = (int)pd;
678         }
679
680         g_list_item = list_item;
681
682         return (void*)list_item;
683 };
684
685 /*
686   elm_object_item_data_set(item_to_update->item, item_to_update);
687   elm_genlist_item_update(item_to_update->item);
688 */
689 static void* navigationbar_func(void *data, xmlNode *xmlObj)
690 {
691 #if 1
692         SETTING_TRACE_BEGIN;
693         ret_if(!data || !xmlObj);
694
695         PluginNode* node = (PluginNode*)data;
696         Draw_Data *pd = node->pd;
697
698         //----------------------------------------------------------------
699         // [DATA] title, btn[0], btn[1]
700         const char *title = (char*)xmlGetProp(xmlObj, "title");
701         char *btn[2] = {0, };
702
703         // find child nodes named 'elements'
704         if (xmlObj->children) {
705                 xmlNode* cur = xmlObj->children;
706                 int i =0;
707                 while (cur != NULL)
708                 {
709                         if (!xmlStrcmp(cur->name, (const xmlChar*)"button")) {
710                                 btn[i] = xmlGetProp(cur, "title");
711                                 SETTING_TRACE("------>>> node type : Element, name=%s id=%s / btn[%d] = %s ",
712                                                                 cur->name,xmlGetProp(cur, "id"),
713                                                                 i,
714                                                                 btn[i]);
715                                 i++;
716                         }
717                         cur = cur->next;
718                 }
719         }
720         //----------------------------------------------------------------
721         // [UI] with DATA
722         pd->ly_main = setting_create_layout_navi_bar_genlist(pd->win_get,
723                                                    pd->win_get,
724                                                    _(title),
725                                                    _(btn[1]), _(btn[0]),
726                                                    ___click_softkey_back_cb,
727                                                    ___click_softkey_back_cb, data, &pd->scroller,
728                                                    &(pd->navi_bar));
729
730 #endif
731         return NULL;
732 };
733
734
735 static void __check_mouse_up_cb(void *data, Evas_Object *obj,
736                                              void *event_info)
737 {
738         /* error check */
739         SETTING_TRACE_BEGIN;
740         setting_retm_if(data == NULL, "Data parameter is NULL");
741
742         retm_if(event_info == NULL, "Invalid argument: event info is NULL");
743         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
744         elm_genlist_item_selected_set(item, 0);
745         Setting_GenGroupItem_Data *list_item =
746             (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
747
748         SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
749
750         int old_status = elm_check_state_get(list_item->eo_check);
751         list_item->chk_status = !old_status;
752         elm_check_state_set(list_item->eo_check, list_item->chk_status);
753
754         xmlNode *xmlObj = data;
755         xmlAttrPtr newattr;
756         newattr = xmlSetProp(xmlObj, "state", xmlXPathCastNumberToString(list_item->chk_status));
757
758         __send_int_msg(xmlObj, list_item->chk_status);
759         __cfg_file_write((Draw_Data *)list_item->belongs_to);
760 }
761
762
763 static void __chk_btn_cb(void *data, Evas_Object *obj,
764                                              void *event_info)
765 {
766         SETTING_TRACE_BEGIN;
767         /* error check */
768         retm_if(data == NULL, "Data parameter is NULL");
769         Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
770
771         xmlNode* xmlObj = list_item->userdata;
772         ret_if(!xmlObj);
773         list_item->chk_status = elm_check_state_get(obj);       /*  for genlist update status */
774
775         xmlAttrPtr newattr;
776         if (list_item->chk_status == 1) {
777                 newattr = xmlSetProp(xmlObj, "value", "true");
778         } else if (list_item->chk_status == 0) {
779                 newattr = xmlSetProp(xmlObj, "value", "false");
780         } else {
781                 newattr = xmlSetProp(xmlObj, "value", "false");
782         }
783
784         const char *id = (char*)xmlGetProp(xmlObj, "id");
785         const char *title = (char*)xmlGetProp(xmlObj, "title");
786         //SETTING_TRACE(" >>>> id:%s , title:%s", id, title);
787         __send_int_msg(xmlObj, list_item->chk_status);
788         __cfg_file_write((Draw_Data *)list_item->belongs_to);
789         return;
790 }
791
792
793 static void* checkbox_func(void *data, xmlNode *xmlObj)
794 {
795         SETTING_TRACE_BEGIN;
796         ret_if(!data || !xmlObj);
797
798         PluginNode* node = (PluginNode*)data;
799         Draw_Data *pd = node->pd;
800
801         // [DATA] title, value
802         const char *title = (char*)xmlGetProp(xmlObj, "title");
803
804         // true / false
805         char* value = (char*)xmlGetProp(xmlObj, "value");
806
807         int ival = -1;
808
809         if ( 0 == safeStrCmp(value, "true")) {
810                 ival = 1;
811         } else if ( 0 == safeStrCmp(value, "false"))  {
812                 ival = 0;
813         } else {
814                 ival = 0;       // default : false (0)
815         }
816
817         // title, value, xmlObj
818         Setting_GenGroupItem_Data *list_item =
819                 setting_create_Gendial_field_def(pd->scroller,
820                                           &(itc_1text_1icon),
821                                           __check_mouse_up_cb,
822                                           xmlObj,
823                                           SWALLOW_Type_1TOGGLE,
824                                           NULL, NULL,
825                                           ival,
826                                           title,
827                                           NULL,
828                                           __chk_btn_cb);
829         if(list_item) {
830                 list_item->userdata = xmlObj;
831                 list_item->belongs_to = (int) pd;
832                 SETTING_TRACE("pd:%p,list_item->belongs_to:%d", pd, list_item->belongs_to);
833         }
834
835         return list_item;
836 }
837
838
839 static void __entry_unfocus_cb(void *data, Evas_Object *obj, void *event_info)
840 {
841         SETTING_TRACE_BEGIN;
842         retm_if(!data || !obj, "Data parameter is NULL");
843
844         setting_hide_input_pannel_cb(obj);
845         const char *entry_str = elm_entry_entry_get(obj);
846         char *entry_str_utf8 = NULL;
847         entry_str_utf8 = elm_entry_markup_to_utf8(entry_str);
848
849         Setting_GenGroupItem_Data *list_item = data;
850
851         xmlNode* xmlObj = list_item->userdata;
852         ret_if(!xmlObj);
853         xmlAttrPtr newattr;
854         const char *title = (char*)xmlSetProp(xmlObj, "value",entry_str_utf8);
855
856         __send_string_msg(xmlObj, entry_str_utf8);
857         __cfg_file_write((Draw_Data *)list_item->belongs_to);
858
859         FREE(entry_str_utf8);
860 }
861
862
863 static void __editbox_list_cb(void *data, Evas_Object *obj,
864                                             void *event_info)
865 {
866         SETTING_TRACE_BEGIN;
867         /* error check */
868
869         retm_if(event_info == NULL, "Invalid argument: event info is NULL");
870         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
871         elm_genlist_item_selected_set(item, 0);
872         Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
873
874         SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
875         if (!elm_object_focus_get(list_item->eo_check)) {
876                 elm_object_focus_set(list_item->eo_check, EINA_TRUE);
877         }
878
879         Ecore_IMF_Context *imf_context = (Ecore_IMF_Context *)elm_entry_imf_context_get(list_item->eo_check);
880         setting_retm_if(imf_context == NULL, "imf_context is NULL");
881         ecore_imf_context_input_panel_show(imf_context);
882 }
883
884
885 static void __editbox_changed_cb(void *data, Evas_Object *obj,
886                                        void *event_info)
887 {
888         SETTING_TRACE_BEGIN;
889         retm_if(!data || !obj, "Data parameter is NULL");
890         retm_if(!elm_object_focus_get(obj), "Entry is not focused");
891
892         Setting_GenGroupItem_Data *list_item =
893             (Setting_GenGroupItem_Data *) data;
894
895         const char *entry_str = elm_entry_entry_get(obj);
896         int entry_len = safeStrLen(entry_str);
897         SETTING_TRACE("entry_str:[%s], lenght:%d", entry_str, entry_len);
898
899         G_FREE(list_item->sub_desc);//release first
900         list_item->sub_desc = (char *)g_strdup(entry_str);
901 }
902
903
904 static void* editbox_func(void *data, xmlNode *xmlObj)
905 {
906         SETTING_TRACE_BEGIN;
907         ret_if(!data || !xmlObj);
908
909         PluginNode* node = (PluginNode*)data;
910         Draw_Data *pd = node->pd;
911
912         const char *title = (char*)xmlGetProp(xmlObj, "title");
913         const char *key_str= (char*)xmlGetProp(xmlObj, "value");
914
915         // TODO: minlength
916         // TODO: maxlength
917         Setting_GenGroupItem_Data *list_item =
918             setting_create_Gendial_field_def(pd->scroller, &(itc_1icon),
919                                              __editbox_list_cb,
920                                              pd, SWALLOW_Type_LAYOUT_ENTRY,
921                                              NULL, NULL, 0, title, key_str,
922                                              __editbox_changed_cb);
923         if (list_item) {
924                 list_item->userdata = xmlObj;
925                 list_item->stop_change_cb = __entry_unfocus_cb;
926                 list_item->belongs_to = (int)pd;
927         }
928
929         return list_item;
930 };
931
932
933 static void __expanditem_func_sel_cb(void *data, Evas_Object *obj, void *event_info)
934 {
935         SETTING_TRACE_BEGIN;
936         /* error check */
937         retm_if(event_info == NULL, "Invalid argument: event info is NULL");
938         Elm_Object_Item *subitem = (Elm_Object_Item *) event_info;
939         Elm_Object_Item *parentItem = elm_genlist_item_parent_get(subitem);
940         elm_genlist_item_selected_set(subitem, 0);
941         Setting_GenGroupItem_Data *data_subItem = elm_object_item_data_get(subitem);
942         Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem);      /* parent data */
943         ret_if(NULL == data_subItem || NULL == data_parentItem);
944
945         elm_radio_value_set(data_subItem->rgd, data_subItem->chk_status);
946
947         data_parentItem->sub_desc = (char *)g_strdup(_(data_subItem->keyStr));
948         elm_object_item_data_set(data_parentItem->item, data_parentItem);
949         elm_genlist_item_update(data_parentItem->item);
950
951         xmlNode* xmlObj = data_parentItem->userdata;
952         ret_if(!xmlObj);
953
954         xmlAttrPtr newattr;
955         //newattr = xmlSetProp(xmlObj, "string", data_parentItem->sub_desc);
956         newattr = xmlSetProp(xmlObj, "value", data_parentItem->sub_desc);
957
958         __send_string_msg(xmlObj, data_parentItem->sub_desc);
959         __cfg_file_write((Draw_Data *)data_parentItem->belongs_to);
960 }
961
962
963 static void __expanditem_func_exp_cb(void *data, Evas_Object *obj, void *event_info)
964 {
965         ret_if(NULL == data || NULL == event_info);
966         SETTING_TRACE_BEGIN;
967
968         PluginNode* node = (PluginNode*)data;
969         Draw_Data *pd = node->pd;
970
971         Elm_Object_Item *parentItem = event_info;       /* parent item */
972         Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem);      /* parent data */
973         Evas_Object *scroller = elm_object_item_widget_get(parentItem);
974
975
976         xmlNode *xmlObj = data_parentItem->userdata;
977         //char *value = (char*)xmlGetProp(xmlObj, "string");
978         char *value = (char*)xmlGetProp(xmlObj, "value");
979         SETTING_TRACE(">>> value = %s", value);
980         int i=0;
981         Evas_Object *rgd = NULL;
982
983         if (xmlObj->children && !data_parentItem->rgd) {//to protect from entering repeatly
984                 xmlNode* cur = xmlObj->children;
985
986                 rgd = elm_radio_add(scroller);
987                 elm_radio_value_set(rgd, -1);
988
989                 int i;
990                 char *type;
991                 char *subitem_title = NULL;
992                 int subitem_index = 0;
993                 int sel_idx = -1;
994
995                 while (cur != NULL) {
996                         if (!xmlStrcmp(cur->name, (const xmlChar*)"expanditem")) {
997                                 type = (char*)xmlGetProp(cur, "type");
998                                 if (0 == safeStrCmp(type, "radio")) {
999                                         subitem_title = (char*)xmlGetProp(cur, "title");
1000                                         Setting_GenGroupItem_Data *list_item =
1001                                                                                         setting_create_Gendial_exp_sub_field(scroller,
1002                                                                                                         &(itc_1icon_1text_sub),
1003                                                                                                         __expanditem_func_sel_cb, NULL, parentItem,
1004                                                                                                         SWALLOW_Type_1RADIO, rgd,
1005                                                                                                         subitem_index,
1006                                                                                                         subitem_title, NULL);
1007
1008                                         // SETTING_TRACE(">>> value = %s, subitem_title = %s ", value, subitem_title);
1009
1010                                         if (0 == safeStrCmp(value, subitem_title)) {
1011                                                 sel_idx = subitem_index;
1012                                                 SETTING_TRACE("%d is selected in Radio Group", sel_idx);
1013                                         }
1014                                         data_parentItem->childs = eina_list_append(data_parentItem->childs, list_item);
1015                                         subitem_index++;
1016
1017                                 } else {
1018                                         SETTING_TRACE("invalid type[:%s]", type);
1019                                 }
1020
1021                                 i++;
1022                         }
1023                         cur = cur->next;
1024                 }
1025
1026                 // value set
1027                 elm_radio_value_set(rgd, sel_idx);
1028                 data_parentItem->rgd = rgd;//protecting condition
1029         }
1030 }
1031
1032
1033 static void __expanditem_func_smart_cb(void *data, Evas_Object *obj, void *event_info)
1034 {
1035         ret_if(data == NULL || event_info == NULL);
1036         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
1037         Setting_GenGroupItem_Data *data_item = elm_object_item_data_get(item);
1038         char *cb_type = data;
1039
1040         if (0 == safeStrCmp(cb_type, "contracted")) {
1041                 data_item->rgd = NULL;
1042                 elm_genlist_item_subitems_clear(item);
1043         }
1044 }
1045
1046
1047 static void* settings_func(void *data, xmlNode *xmlObj)
1048 {
1049         return NULL;
1050 }
1051
1052 // <setting>
1053 static void* setting_func(void *data, xmlNode *xmlObj)
1054 {
1055         SETTING_TRACE_BEGIN;
1056         ret_if(!data || !xmlObj);
1057
1058 #if 1/*{{{*/
1059         //Draw_Data *pd = node->pd;
1060         PluginNode* node = (PluginNode*)data;
1061         Draw_Data *pd = node->pd;
1062
1063         //----------------------------------------------------------------
1064         // [DATA] title, btn[0], btn[1]
1065         const char *title = (char*)xmlGetProp(xmlObj, "title");
1066         char *btn[2] = {/* 0 */"OK", /* 1 */"NO"};
1067
1068         // find child nodes named 'elements'
1069         #if 0
1070         if (xmlObj->children) {
1071                 xmlNode* cur = xmlObj->children;
1072                 int i =0;
1073                 while (cur != NULL)
1074                 {
1075                         if (!xmlStrcmp(cur->name, (const xmlChar*)"button")) {
1076                                 btn[i] = xmlGetProp(cur, "title");
1077                                 SETTING_TRACE("------>>> node type : Element, name=%s id=%s / btn[%d] = %s ",
1078                                                                 cur->name,xmlGetProp(cur, "id"),
1079                                                                 i,
1080                                                                 btn[i]);
1081                                 i++;
1082                         }
1083                         cur = cur->next;
1084                 }
1085         }
1086         #endif
1087         //----------------------------------------------------------------
1088         SETTING_TRACE("before setting_create_layout_navi_bar_genlist");
1089         // [UI] with DATA
1090         pd->scroller = elm_genlist_add(pd->win_get);
1091         retvm_if(pd->scroller == NULL, NULL,
1092                  "Cannot set scroller object  as contento of layout");
1093         elm_object_style_set(pd->scroller, "dialogue");
1094         elm_genlist_clear(pd->scroller);        /* first to clear list */
1095
1096         /*  Enabling illume notification property for window */
1097         elm_win_conformant_set(pd->win_get, 1);
1098         Evas_Object *conformant = elm_conformant_add(pd->win_get);
1099         elm_object_style_set(conformant, "internal_layout");    /*  By Kollus. 2011-01-04 */
1100         evas_object_show(conformant);
1101         elm_object_content_set(conformant, pd->scroller);
1102
1103         SETTING_TRACE("_(title):%s", _(title));
1104         pd->ly_main =
1105             setting_create_layout_navi_bar(pd->win_get, pd->win_get,
1106                                            _(title),
1107                                            _("IDS_COM_BODY_BACK"), NULL, NULL,
1108                                            ___click_softkey_back_cb,
1109                                            NULL, NULL,
1110                                            data, conformant,
1111                                            &(pd->navi_bar), NULL);
1112         SETTING_TRACE("after setting_create_layout_navi_bar_genlist");
1113
1114 #endif/*}}}*/
1115         return NULL;
1116 }
1117
1118
1119 static void* expanditem_func(void *data, xmlNode *xmlObj)
1120 {
1121         // DO NOTHING - expandlist draws this area
1122         return NULL;
1123 }
1124
1125 static void* expandlist_func(void *data, xmlNode *xmlObj)
1126 {
1127         SETTING_TRACE_BEGIN;
1128         ret_if(!data || !xmlObj);
1129
1130         PluginNode* node = (PluginNode*)data;
1131         Draw_Data *pd = node->pd;
1132
1133         const char *key_str = (char*)xmlGetProp(xmlObj, "title");
1134         const char *value = (char*)xmlGetProp(xmlObj, "value"); // string -> value
1135
1136         setting_enable_expandable_genlist(pd->scroller, data, __expanditem_func_exp_cb, __expanditem_func_smart_cb);
1137         Setting_GenGroupItem_Data *list_item =
1138             setting_create_Gendial_exp_parent_field(pd->scroller,
1139                                                     &(itc_2text_3_parent),
1140                                                     NULL, NULL,
1141                                                     SWALLOW_Type_INVALID,
1142                                                     key_str,
1143                                                     value);
1144         if (list_item) {
1145                 list_item->userdata = xmlObj;
1146                 list_item->belongs_to = (int)pd;
1147         }
1148
1149         return list_item;
1150 }
1151
1152
1153
1154 static int __node_walker(PluginNode* context, xmlNode* cur)
1155 {
1156         //SETTING_TRACE_BEGIN;
1157         Draw_Data *pd = context->pd;
1158
1159         retv_if(!pd, -1);
1160         xmlNode *cur_node = NULL;
1161         for (cur_node = cur; cur_node;cur_node = cur_node->next) {
1162                 if (cur_node->type == XML_ELEMENT_NODE) {
1163                         SETTING_TRACE("node type : %s id= %s", cur_node->name,xmlGetProp(cur_node, "id"));
1164
1165                         drawer_fp  fp = __drawer_find(cur_node->name);
1166                         if (fp)
1167                         {
1168                                 // type check
1169                                 void* vret = fp(context, cur_node); // draw it
1170
1171                                 if (vret)
1172                                 {
1173                                         Setting_GenGroupItem_Data* genlist_node = (Setting_GenGroupItem_Data* )vret;
1174                                         //SETTING_TRACE("add node to Eina List name : %s, id : ", cur_node->name, xmlGetProp(cur_node, "id"));
1175                                         // add it to the hash table create before.
1176                                         // id, object
1177                                         // add list
1178                                         char* key_name = xmlGetProp(cur_node, "id");
1179                                         eina_hash_add(context->ui_list, strdup(key_name),(void*)genlist_node);
1180                                 }
1181                         }
1182                 }
1183                 __node_walker(context, cur_node->children);     /* RECURSIVE */
1184         }
1185         return 0;
1186 }
1187
1188 /**
1189  * @param id_str [in] "id"
1190  * @param value [in] value to be udpated
1191  * @see __expanditem_func_sel_cb
1192  */
1193 static int __node_finder(PluginNode* context, xmlNode* cur, char* id_str, char* value, bool* is_end)
1194 {
1195         SETTING_TRACE_BEGIN;
1196         xmlNode *cur_node = NULL;
1197
1198         if (*is_end == true) return 0;
1199
1200         for (cur_node = cur; cur_node;cur_node = cur_node->next) {
1201                 if (cur_node->type == XML_ELEMENT_NODE) {
1202
1203                         char* id_name = (char*)xmlGetProp(cur_node, "id");
1204                         if ( id_name && 0 == strcmp(id_str, id_name))
1205                         {
1206                                 SETTING_TRACE("FOUND >>>> %s", id_name);
1207                                 // cur_node     - update xml code
1208                                 xmlAttrPtr newattr = xmlSetProp(cur_node, "value", value);
1209
1210                                 //-----------------------------------------------------------
1211                                 // UI UPDATE
1212                                 // case : slider
1213                                 if ( 0 == strcmp (cur_node->name, "integer"))
1214                                 {
1215                                         SETTING_TRACE(">>>>> UPDATE SLIDER CONTROL %x --- %s ",context->ui_list, id_name);
1216                                         Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1217                                         if      (item_to_update)
1218                                         {
1219                                                 item_to_update->chk_status = atoi(value);
1220                                                 SETTING_TRACE(">>>   o-------------0 SLIDER VALUE = %d ", item_to_update->chk_status);
1221
1222                                                 elm_object_item_data_set(item_to_update->item, item_to_update);
1223                                                 elm_genlist_item_update(item_to_update->item);
1224                                         } else {
1225                                                 SETTING_TRACE("item_to_update is NULL");
1226                                         }
1227                                 }
1228                                 // case : toggle
1229                                 if ( 0 == strcmp (cur_node->name, "bool"))
1230                                 {
1231                                         SETTING_TRACE(">>>>> UPDATE TOGGLE CONTROL %x --- %s ",context->ui_list, id_name);
1232                                         Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1233                                         if      (item_to_update)
1234                                         {
1235                                                 item_to_update->chk_status = atoi(value);
1236                                                 SETTING_TRACE(">>>   o-------------0 TOGGLE VALUE = %d ", item_to_update->chk_status);
1237
1238                                                 elm_object_item_data_set(item_to_update->item, item_to_update);
1239                                                 elm_genlist_item_update(item_to_update->item);
1240                                         } else {
1241                                                 SETTING_TRACE("item_to_update is NULL");
1242                                         }
1243                                 }
1244                                 // case : edit control
1245                                 if ( 0 == strcmp (cur_node->name, "string"))
1246                                 {
1247                                         SETTING_TRACE(">>>>> UPDATE EDIT CONTROL CONTROL %x --- %s ",context->ui_list, id_name);
1248                                         Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1249                                         if      (item_to_update)
1250                                         {
1251                                                 char* old_string = item_to_update->sub_desc;
1252                                                 item_to_update->sub_desc = strdup(value);
1253                                                 SETTING_TRACE(">>>   o-------------0 STRING VALUE = %s ", value);
1254
1255                                                 // free old string
1256
1257                                                 elm_object_item_data_set(item_to_update->item, item_to_update);
1258                                                 elm_genlist_item_update(item_to_update->item);
1259
1260                                         } else {
1261                                                 SETTING_TRACE("item_to_update is NULL");
1262                                         }
1263                                 }
1264                                 // case : expand list
1265                                 // parent
1266                                 //    child1
1267                                 //    child2
1268                                 //    child3
1269                                 //    child4
1270                                 //-----------------------------------------------------------
1271                                 if ( 0 == strcmp (cur_node->name, "expandlist"))
1272                                 {
1273                                         SETTING_TRACE(">>>>> UPDATE EXPAND LIST CONTROL %x --- %s ",context->ui_list, id_name);
1274                                         Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1275                                         if      (item_to_update)
1276                                         {
1277                                                 char* old_string = item_to_update->sub_desc;
1278                                                 item_to_update->sub_desc = strdup(value);
1279                                                 SETTING_TRACE(">>>   o-------------0 EXPAND LIST VALUE = %s ", value);
1280
1281                                                 // free old string
1282                                                 // string update
1283                                                 elm_object_item_data_set(item_to_update->item, item_to_update);
1284                                                 elm_genlist_item_update(item_to_update->item);
1285
1286                                                 // TODO: need to update child elements
1287                                                 // item_to_update->childs ---> expanded list
1288                                                 if (item_to_update->childs)
1289                                                 {
1290                                                         Eina_List *li = item_to_update->childs;
1291                                                         int radio_index = 0;
1292                                                         while(li)
1293                                                         {
1294                                                                 Setting_GenGroupItem_Data* node = eina_list_data_get(li);
1295                                                                 // do something more
1296                                                                 // SETTING_TRACE(">>> RADIO LIST STRING VALUE = %s ", node->keyStr);
1297                                                                 // set position of radio button
1298                                                                 if (strcmp(node->keyStr, value) == 0)
1299                                                                 {
1300                                                                         elm_radio_value_set(node->rgd, radio_index);
1301                                                                 }
1302                                                                 elm_object_item_data_set(item_to_update->item, item_to_update);
1303                                                                 elm_genlist_item_update(item_to_update->item);
1304
1305                                                                 // go next
1306                                                                 li = eina_list_next(li);
1307                                                                 radio_index++;
1308                                                         }
1309
1310                                                 }
1311                                         } else {
1312                                                 SETTING_TRACE("item_to_update is NULL");
1313                                         }
1314                                 }
1315
1316                                 *is_end = true;
1317                         }
1318                 }
1319                 __node_finder(context, cur_node->children, id_str, value, is_end);      /* RECURSIVE */
1320         }
1321         return 0;
1322 }
1323
1324 static unsigned int _plugin_string_key_length(const char*key)
1325 {
1326         if (!key)
1327                 return 0;
1328
1329         return (int)strlen(key) + 1;
1330 }
1331
1332 static int _plugin_string_key_cmp(const char* key1, int key1_length,
1333                                                                         const char* key2, int key2_length)
1334 {
1335         return strcmp(key1, key2);
1336 }
1337
1338 static void _plugin_entry_free_cb(void* data)
1339 {
1340     Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) data;
1341         if (node->childs)
1342         {
1343                 eina_list_free(node->childs);
1344                 node->childs = NULL;
1345         }
1346 }
1347
1348 //static PluginNode* g_context;
1349
1350 PluginNode* setting_plugin_create()
1351 {
1352         PluginNode *node = calloc(1, sizeof(PluginNode));
1353
1354         Draw_Data *pd = calloc(1, sizeof(Draw_Data));
1355         setting_retvm_if(!pd, -1, "Create Draw_Data obj failed");
1356         //eina_init();
1357
1358         node->pd = pd;
1359         node->ui_list = eina_hash_new(EINA_KEY_LENGTH(_plugin_string_key_length),
1360                                                                   EINA_KEY_CMP(_plugin_string_key_cmp),
1361                                                                   EINA_KEY_HASH(eina_hash_superfast),
1362                                                                   _plugin_entry_free_cb,
1363                                                                   5); // 2^5
1364
1365         return node;
1366 }
1367
1368 void setting_plugin_destroy(PluginNode* node)
1369 {
1370         SETTING_TRACE_BEGIN;
1371         if (node) {
1372                 SETTING_TRACE("node is NOT NULL")
1373                 if (node->pd) {
1374                         SETTING_TRACE("node->pd is NOT NULL")
1375                         if(node->pd->doc != NULL) {
1376                                 xmlSaveFormatFile(node->plugin_path, node->pd->doc, 1);
1377                                 xmlFreeDoc(node->pd->doc);
1378                                 node->pd->doc = NULL;
1379                                 SETTING_TRACE("__cfg_file_write successful");
1380                         }
1381
1382                         free(node->pd);
1383                         node->pd = NULL;
1384                 }
1385
1386                 if (node->ui_list) {
1387                         eina_hash_free(node->ui_list);
1388                         node->ui_list = NULL;
1389                 }
1390                 free(node);
1391                 node = NULL;
1392         }
1393 }
1394
1395
1396 static Eina_Bool _plugin_foreach_cb(const Eina_Hash *hash, const void*key, void* data, void* fdata)
1397 {
1398     Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) data;
1399         SETTING_TRACE("%s --- %s ", (char*)key, node->keyStr);
1400         return EINA_TRUE;
1401 }
1402
1403
1404 void setting_plugin_debug(PluginNode* context)
1405 {
1406 //      SETTING_TRACE("HASH TABLE -------------------------------------");
1407         eina_hash_foreach(context->ui_list,_plugin_foreach_cb, NULL);
1408 //      SETTING_TRACE("HASH TABLE -------------------------------------");
1409
1410 }
1411
1412 void setting_plugin_update(PluginNode* context)
1413 {
1414     Eina_List *li = context->ui_list;
1415
1416     while (li) {
1417         Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) eina_list_data_get(li);
1418         if (node) {
1419             // SETTING_TRACE(" ---> keyStr : %s , swallow type : %d  ", node->keyStr, node->swallow_type);
1420                         Setting_GenGroupItem_Data* item_to_update = NULL;
1421                         item_to_update = node;
1422                         elm_object_item_data_set(item_to_update->item, item_to_update);
1423                         elm_genlist_item_update(item_to_update->item);
1424         }
1425         li = eina_list_next(li);
1426         }
1427 }
1428
1429
1430 bool setting_plugin_load(PluginNode* context, const char *cfg_file)
1431 {
1432         SETTING_TRACE("cfg_file:%s", cfg_file)
1433         if (isEmptyStr(cfg_file) || 0 != access(cfg_file, R_OK|W_OK|F_OK ))
1434         {
1435                 SETTING_TRACE_ERROR(" error occured : access \n");
1436                 return FALSE;
1437         }
1438         context->pd->cfg_file = cfg_file;
1439         context->pd->win_get = (Evas_Object *) ug_get_window();
1440
1441         GError *error = NULL;
1442
1443         context->pd->doc = xmlParseFile(cfg_file);
1444         context->pd->root = xmlDocGetRootElement(context->pd->doc);
1445
1446         // TODO: error handler here
1447         __node_walker(context, context->pd->root);
1448
1449         // debug message
1450         setting_plugin_debug(context);
1451         return true;
1452 }
1453
1454