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