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