4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
6 * Contact: MyoungJune Park <mj2004.park@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 #include <eina_list.h>
27 #include <setting-debug.h>
28 #include <setting-common-general-func.h>
29 #include <setting-common-draw-widget.h>
31 #include <setting-plugin.h>
35 static Setting_GenGroupItem_Data *g_list_item; /*TEST*/
40 * UI draw handler table : _g_draw_list
41 * - contains Object_Drawer typed object.
43 Eina_List *_g_drawer_list = NULL;
46 * @return Evas_Object * obj
48 static void* navigationbar_func(void *data, xmlNode *xmlObj);
54 static void* group_func(void *data, xmlNode *xmlObj);
57 * @return Setting_GenGroupItem_Data* ptr
59 static void* link_func(void *data, xmlNode *xmlObj);
62 * @return Setting_GenGroupItem_Data* ptr
64 static void* slider_func(void *data, xmlNode *xmlObj);
67 * @return Setting_GenGroupItem_Data* ptr
69 static void* label_func(void *data, xmlNode *xmlObj);
72 * @return Setting_GenGroupItem_Data* ptr
74 static void* checkbox_func(void *data, xmlNode *xmlObj);
77 * @return Setting_GenGroupItem_Data* ptr
79 static void* editbox_func(void *data, xmlNode *xmlObj);
82 * @return Setting_GenGroupItem_Data* ptr
84 static void* expandlist_func(void *data, xmlNode *xmlObj);
89 static void* expanditem_func(void *data, xmlNode *xmlObj);
94 static void* settings_func(void *data, xmlNode *xmlObj);
97 static void* launch_func(void *data, xmlNode *xmlObj);
102 static void* setting_func(void *data, xmlNode *xmlObj);
104 static int __node_walker(PluginNode* context, xmlNode* cur);
106 static int __node_finder(PluginNode* context, xmlNode* cur, char* id_str, char* value, bool* is_end);
109 static void __drawer_add(const char *type, drawer_fp draw)
111 Object_Drawer *node = calloc(1, sizeof(Object_Drawer));
112 if (node && type && draw)
117 _g_drawer_list = eina_list_append(_g_drawer_list, node);
122 static drawer_fp __drawer_find(char* type)
125 Eina_List *check_list = _g_drawer_list;
126 Object_Drawer *list_item = NULL;
131 list_item = (Object_Drawer *) eina_list_data_get(check_list);
132 if (NULL == list_item)
135 if (0 == safeStrCmp(list_item->type, type))
137 //SETTING_TRACE("list_item->type:%s", list_item->type);
141 check_list = eina_list_next(check_list);
143 //SETTING_TRACE("list_item:%p", list_item);
144 return list_item ? list_item->draw : NULL;
146 void setting_drawer_list_init()
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);
163 void setting_drawer_list_fini()
167 Object_Drawer *node = NULL;
168 Eina_List *li = _g_drawer_list;
170 node = (Object_Drawer *) eina_list_data_get(li);
173 //SETTING_TRACE("Deregister %s", node->type);
176 li = eina_list_next(li);
178 _g_drawer_list = eina_list_free(_g_drawer_list);
179 _g_drawer_list = NULL;
183 /////////////////////////
184 /////////////////////////
185 /////////////////////////
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"
193 static char* substring(const char* str, size_t begin, size_t len)
195 if (str == 0 || strlen(str) == 0 || strlen(str) < begin || strlen(str) < (begin+len))
198 return strndup(str + begin, len);
201 //------------------------------------------------------
203 static DBusConnection *bus;
204 //------------------------------------------------------
205 static DBusHandlerResult __signal_filter(DBusConnection* conn, DBusMessage* message, void* user_data)
207 int my_pid = getpid();
213 dbus_error_init(&error);
215 setting_main_appdata *ad = user_data;
217 if (dbus_message_is_signal(message, DBUS_SIGNAL_INTERFACE, DBUS_SIGNAL))
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)
225 SETTING_TRACE_ERROR("Fail to get data : %s", error.message);
226 dbus_error_free(&error);
227 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
231 if (sender_pid != 0 && my_pid != sender_pid)
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, '|');
240 xmlDocPtr doc = NULL;
243 //parsing for : checkbox1|N/A -> checkbox1
244 char* key_name = substring(key, 0, strlen(key)-strlen(ptr));
245 char* val_name = strchr(value, '|');
250 doc = xmlParseFile(ad->plugin_path);
252 xmlNode *root = xmlDocGetRootElement(doc);
255 __node_finder((PluginNode*)ad->plugin_node, root, key_name ,val_name, &is_end);
258 GError *error = NULL;
263 xmlSaveFormatFile(ad->plugin_path, doc, 1);
264 // TODO: make sure this is right
267 SETTING_TRACE("__cfg_file_write successful");
274 return DBUS_HANDLER_RESULT_HANDLED;
277 static int __send_msg(char* key, char* value)
279 DBusMessage* message;
280 int sender_pid = getpid();
285 message = dbus_message_new_signal(DBUS_PATH, DBUS_SIGNAL_INTERFACE, DBUS_SIGNAL);
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)
294 SETTING_TRACE("Fail to load data error");
298 if (dbus_connection_send(bus, message, NULL) == FALSE)
300 SETTING_TRACE("Fail to send message");
304 dbus_connection_flush(bus);
305 dbus_message_unref(message);
307 SETTING_TRACE("[CLIENT] send data signal done");
313 static void __send_int_msg(xmlNode* xmlObj, int val)
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);
320 char value[MAX_CONTENT_LEN] = {0,};
321 snprintf(value, sizeof(value), "INT|%d", val);
322 __send_msg(key, value);
326 static void __send_string_msg(xmlNode* xmlObj, char *string)
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);
333 char value[MAX_CONTENT_LEN] = {0,};
334 snprintf(value, sizeof(value), "STRING|%s", string);
335 __send_msg(key, value);
339 int setting_dbus_handler_init(void* user_data)
343 char rule[MAX_LOCAL_BUFSIZE];
345 dbus_error_init(&error);
346 bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
349 SETTING_TRACE("Fail to connect to the D-BUS daemon: %s", error.message);
350 dbus_error_free(&error);
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);
357 dbus_bus_add_match(bus, rule, &error);
358 if (dbus_error_is_set(&error))
360 SETTING_TRACE("Fail to rule set; %s", error.message);
361 dbus_error_free(&error);
365 if (dbus_connection_add_filter(bus, __signal_filter, user_data, NULL) == FALSE)
370 SETTING_TRACE("app signal initialized");
376 int setting_dbus_handler_fini(void)
379 char rule[MAX_LOCAL_BUFSIZE];
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);
386 if (dbus_error_is_set(&error))
388 SETTING_TRACE("Fail to rule unset: %s", error.message);
389 dbus_error_free(&error);
393 dbus_connection_close(bus);
394 SETTING_TRACE("app signal finalized");
398 /////////////////////////////
399 /////////////////////////////
400 /////////////////////////////
402 Elm_Genlist_Item_Class itc_layout;
405 static int __cfg_file_write(Draw_Data *pd)
409 GError *error = NULL;
412 xmlSaveFormatFile(pd->cfg_file, pd->doc, 1);
413 //xmlFreeDoc(pd->doc);
415 SETTING_TRACE("__cfg_file_write successful");
422 static void ___click_softkey_back_cb(void *data, Evas_Object *obj,
428 PluginNode* node = (PluginNode*)data;
429 Draw_Data *pd = node->pd;
431 evas_object_del(pd->ly_main);
435 setting_plugin_destroy(node);
437 // pd->scroller = NULL;
438 // pd->navi_bar = NULL;
439 // pd->cfg_file = NULL;
445 static void* group_func(void *data, xmlNode *xmlObj)
448 ret_if(!data || !xmlObj);
450 PluginNode* node = (PluginNode*)data;
451 Draw_Data *pd = node->pd;
453 // original code is non-recursive
455 const char *title = (char*)json_object_get_string_member(jsonObj, "title");
456 (void)setting_create_Gendial_field_titleItem(pd->scroller,
460 // non recursive method
461 if (json_object_has_member(jsonObj, "elements"))
463 JsonNode* elements_node = json_object_get_member(jsonObj, "elements");
467 for (i=0; i < json_array_get_length(json_node_get_array(elements_node)); i++)
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
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);
486 static void* __link_list_cb(void *data, Evas_Object *obj, void *event_info)
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);
496 xmlNode* xmlObj = data;
498 const char *link_file = (char*)xmlGetProp(xmlObj, "value");
502 SETTING_TRACE_ERROR("Invalidate liked file");
505 char file[1024] = {0,};
506 snprintf(file, sizeof(file), "%s/%s", PLUGIN_CFG_DIR, link_file);
507 SETTING_TRACE("file:%s", file);
509 PluginNode* plugin_node = setting_plugin_create();
510 setting_plugin_load(plugin_node, (const char *)file);
512 //setting_plugin_load(NULL, file);
517 static void* __launch_list_cb(void *data, Evas_Object *obj, void *event_info)
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);
527 xmlNode* xmlObj = data;
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");
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);
545 static void* label_func(void *data, xmlNode *xmlObj)
548 ret_if(!data || !xmlObj);
549 PluginNode* node = (PluginNode*)data;
550 Draw_Data *pd = node->pd;
552 const char *title = (char*)xmlGetProp(xmlObj, "title");
554 Setting_GenGroupItem_Data *obj =
555 setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
557 xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
558 0, title, NULL, NULL);
563 static void* link_func(void *data, xmlNode *xmlObj)
566 ret_if(!data || !xmlObj);
567 PluginNode* node = (PluginNode*)data;
568 Draw_Data *pd = node->pd;
570 const char *key_str = (char*)xmlGetProp(xmlObj, "id");
571 Setting_GenGroupItem_Data * obj =
572 setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
574 xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
575 0, key_str, NULL, NULL);
580 static void* launch_func(void *data, xmlNode *xmlObj)
583 ret_if(!data || !xmlObj);
584 PluginNode* node = (PluginNode*)data;
585 Draw_Data *pd = node->pd;
587 const char *title_str = (char*)xmlGetProp(xmlObj, "title");
589 Setting_GenGroupItem_Data * obj =
590 setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
592 xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
593 0, title_str, NULL, NULL);
598 static void __slider_stop_cb(void *data, Evas_Object *obj,
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);
607 xmlNode* xmlObj = list_item->userdata;
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);
614 SETTING_TRACE(" slider after ---> val = %d", (int) list_item->chk_status);
616 // int -> double -> xmlChar*
619 sprintf(buf, "%d", (int) list_item->chk_status);
620 newattr = xmlSetProp(xmlObj, "value", buf);
622 __send_int_msg(xmlObj, list_item->chk_status);
623 __cfg_file_write((Draw_Data *)list_item->belongs_to);
627 static void* slider_func(void *data, xmlNode *xmlObj)
630 ret_if(!data || !xmlObj);
631 PluginNode* node = (PluginNode*)data;
632 Draw_Data *pd = node->pd;
635 const char *title = (char*)xmlGetProp(xmlObj, "title");
637 SETTING_TRACE (" >>> [slider input] min=%s max=%s value=%s ",(char*)xmlGetProp(xmlObj, "min"), (char*)xmlGetProp(xmlObj, "max"), (char*)xmlGetProp(xmlObj, "value"));
639 int value = atoi((char*)xmlGetProp(xmlObj, "value"));
640 int min = atoi((char*)xmlGetProp(xmlObj, "min"));
641 int max = atoi((char*)xmlGetProp(xmlObj, "max"));
643 SETTING_TRACE ("[slider input] min=%d max=%d value=%d ", min, max, value);
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,
649 SWALLOW_Type_LAYOUT_SLIDER,
650 IMG_SENSITIVITY_ICON_01,
651 IMG_SENSITIVITY_ICON_02, value,
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;
664 g_list_item = list_item;
666 return (void*)list_item;
670 elm_object_item_data_set(item_to_update->item, item_to_update);
671 elm_genlist_item_update(item_to_update->item);
673 static void* navigationbar_func(void *data, xmlNode *xmlObj)
676 ret_if(!data || !xmlObj);
678 //Draw_Data *pd = node->pd;
679 PluginNode* node = (PluginNode*)data;
680 Draw_Data *pd = node->pd;
682 //----------------------------------------------------------------
683 // [DATA] title, btn[0], btn[1]
684 const char *title = (char*)xmlGetProp(xmlObj, "title");
685 char *btn[2] = {0, };
687 // find child nodes named 'elements'
688 if (xmlObj->children) {
689 xmlNode* cur = xmlObj->children;
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]);
701 //----------------------------------------------------------------
703 pd->ly_main = setting_create_layout_navi_bar_genlist(pd->win_get,
706 _(btn[1]), _(btn[0]),
707 ___click_softkey_back_cb,
708 ___click_softkey_back_cb, data, &pd->scroller,
715 static void __check_mouse_up_cb(void *data, Evas_Object *obj,
720 setting_retm_if(data == NULL, "Data parameter is NULL");
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);
728 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
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);
734 xmlNode *xmlObj = data;
736 newattr = xmlSetProp(xmlObj, "state", xmlXPathCastNumberToString(list_item->chk_status));
738 __send_int_msg(xmlObj, list_item->chk_status);
739 __cfg_file_write((Draw_Data *)list_item->belongs_to);
743 static void __chk_btn_cb(void *data, Evas_Object *obj,
748 retm_if(data == NULL, "Data parameter is NULL");
749 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
751 xmlNode* xmlObj = list_item->userdata;
753 list_item->chk_status = elm_check_state_get(obj); /* for genlist update status */
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");
761 newattr = xmlSetProp(xmlObj, "value", "false");
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);
773 static void* checkbox_func(void *data, xmlNode *xmlObj)
776 ret_if(!data || !xmlObj);
778 PluginNode* node = (PluginNode*)data;
779 Draw_Data *pd = node->pd;
781 // [DATA] title, value
782 const char *title = (char*)xmlGetProp(xmlObj, "title");
785 char* value = (char*)xmlGetProp(xmlObj, "value");
789 if ( 0 == safeStrCmp(value, "true")) {
791 } else if ( 0 == safeStrCmp(value, "false")) {
794 ival = 0; // default : false (0)
797 // title, value, xmlObj
798 Setting_GenGroupItem_Data *list_item =
799 setting_create_Gendial_field_def(pd->scroller,
803 SWALLOW_Type_1TOGGLE,
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);
819 static void __entry_unfocus_cb(void *data, Evas_Object *obj, void *event_info)
822 retm_if(!data || !obj, "Data parameter is NULL");
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);
829 Setting_GenGroupItem_Data *list_item = data;
831 xmlNode* xmlObj = list_item->userdata;
834 const char *title = (char*)xmlSetProp(xmlObj, "value",entry_str_utf8);
836 __send_string_msg(xmlObj, entry_str_utf8);
837 __cfg_file_write((Draw_Data *)list_item->belongs_to);
839 FREE(entry_str_utf8);
843 static void __editbox_list_cb(void *data, Evas_Object *obj,
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);
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);
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);
865 static void __editbox_changed_cb(void *data, Evas_Object *obj,
869 retm_if(!data || !obj, "Data parameter is NULL");
870 retm_if(!elm_object_focus_get(obj), "Entry is not focused");
872 Setting_GenGroupItem_Data *list_item =
873 (Setting_GenGroupItem_Data *) data;
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);
879 G_FREE(list_item->sub_desc);//release first
880 list_item->sub_desc = (char *)g_strdup(entry_str);
884 static void* editbox_func(void *data, xmlNode *xmlObj)
887 ret_if(!data || !xmlObj);
889 PluginNode* node = (PluginNode*)data;
890 Draw_Data *pd = node->pd;
892 const char *title = (char*)xmlGetProp(xmlObj, "title");
893 const char *key_str= (char*)xmlGetProp(xmlObj, "value");
897 Setting_GenGroupItem_Data *list_item =
898 setting_create_Gendial_field_def(pd->scroller, &(itc_1icon),
900 pd, SWALLOW_Type_LAYOUT_ENTRY,
901 NULL, NULL, 0, title, key_str,
902 __editbox_changed_cb);
904 list_item->userdata = xmlObj;
905 list_item->stop_change_cb = __entry_unfocus_cb;
906 list_item->belongs_to = (int)pd;
913 static void __expanditem_func_sel_cb(void *data, Evas_Object *obj, void *event_info)
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);
925 elm_radio_value_set(data_subItem->rgd, data_subItem->chk_status);
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);
931 xmlNode* xmlObj = data_parentItem->userdata;
935 //newattr = xmlSetProp(xmlObj, "string", data_parentItem->sub_desc);
936 newattr = xmlSetProp(xmlObj, "value", data_parentItem->sub_desc);
938 __send_string_msg(xmlObj, data_parentItem->sub_desc);
939 __cfg_file_write((Draw_Data *)data_parentItem->belongs_to);
943 static void __expanditem_func_exp_cb(void *data, Evas_Object *obj, void *event_info)
945 ret_if(NULL == data || NULL == event_info);
948 PluginNode* node = (PluginNode*)data;
949 Draw_Data *pd = node->pd;
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);
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);
961 Evas_Object *rgd = NULL;
963 if (xmlObj->children && !data_parentItem->rgd) {//to protect from entering repeatly
964 xmlNode* cur = xmlObj->children;
966 rgd = elm_radio_add(scroller);
967 elm_radio_value_set(rgd, -1);
971 char *subitem_title = NULL;
972 int subitem_index = 0;
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,
986 subitem_title, NULL);
988 // SETTING_TRACE(">>> value = %s, subitem_title = %s ", value, subitem_title);
990 if (0 == safeStrCmp(value, subitem_title)) {
991 sel_idx = subitem_index;
992 SETTING_TRACE("%d is selected in Radio Group", sel_idx);
994 data_parentItem->childs = eina_list_append(data_parentItem->childs, list_item);
998 SETTING_TRACE("invalid type[:%s]", type);
1007 elm_radio_value_set(rgd, sel_idx);
1008 data_parentItem->rgd = rgd;//protecting condition
1013 static void __expanditem_func_smart_cb(void *data, Evas_Object *obj, void *event_info)
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;
1020 if (0 == safeStrCmp(cb_type, "contracted")) {
1021 data_item->rgd = NULL;
1022 elm_genlist_item_subitems_clear(item);
1027 static void* settings_func(void *data, xmlNode *xmlObj)
1033 static void* setting_func(void *data, xmlNode *xmlObj)
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, };
1043 // find child nodes named 'elements'
1045 if (xmlObj->children) {
1046 xmlNode* cur = xmlObj->children;
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]);
1059 //----------------------------------------------------------------
1061 pd->ly_main = setting_create_layout_navi_bar_genlist(pd->win_get,
1065 ___click_softkey_back_cb,
1066 ___click_softkey_back_cb, pd, &pd->scroller,
1074 static void* expanditem_func(void *data, xmlNode *xmlObj)
1076 // DO NOTHING - expandlist draws this area
1080 static void* expandlist_func(void *data, xmlNode *xmlObj)
1082 SETTING_TRACE_BEGIN;
1083 ret_if(!data || !xmlObj);
1085 PluginNode* node = (PluginNode*)data;
1086 Draw_Data *pd = node->pd;
1088 const char *key_str = (char*)xmlGetProp(xmlObj, "title");
1089 const char *value = (char*)xmlGetProp(xmlObj, "value"); // string -> value
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),
1096 SWALLOW_Type_INVALID,
1100 list_item->userdata = xmlObj;
1101 list_item->belongs_to = (int)pd;
1109 static int __node_walker(PluginNode* context, xmlNode* cur)
1111 //SETTING_TRACE_BEGIN;
1112 Draw_Data *pd = context->pd;
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"));
1120 drawer_fp fp = __drawer_find(cur_node->name);
1124 void* vret = fp(context, cur_node); // draw it
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.
1133 char* key_name = xmlGetProp(cur_node, "id");
1134 eina_hash_add(context->ui_list, strdup(key_name),(void*)genlist_node);
1138 __node_walker(context, cur_node->children); /* RECURSIVE */
1144 * @param id_str [in] "id"
1145 * @param value [in] value to be udpated
1146 * @see __expanditem_func_sel_cb
1148 static int __node_finder(PluginNode* context, xmlNode* cur, char* id_str, char* value, bool* is_end)
1150 SETTING_TRACE_BEGIN;
1151 xmlNode *cur_node = NULL;
1153 if (*is_end == true) return 0;
1155 for (cur_node = cur; cur_node;cur_node = cur_node->next) {
1156 if (cur_node->type == XML_ELEMENT_NODE) {
1158 char* id_name = (char*)xmlGetProp(cur_node, "id");
1159 if ( id_name && 0 == strcmp(id_str, id_name))
1161 SETTING_TRACE("FOUND >>>> %s", id_name);
1162 // cur_node - update xml code
1163 xmlAttrPtr newattr = xmlSetProp(cur_node, "value", value);
1165 //-----------------------------------------------------------
1168 if ( 0 == strcmp (cur_node->name, "integer"))
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);
1174 item_to_update->chk_status = atoi(value);
1175 SETTING_TRACE(">>> o-------------0 SLIDER VALUE = %d ", item_to_update->chk_status);
1177 elm_object_item_data_set(item_to_update->item, item_to_update);
1178 elm_genlist_item_update(item_to_update->item);
1180 SETTING_TRACE("item_to_update is NULL");
1184 if ( 0 == strcmp (cur_node->name, "bool"))
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);
1190 item_to_update->chk_status = atoi(value);
1191 SETTING_TRACE(">>> o-------------0 TOGGLE VALUE = %d ", item_to_update->chk_status);
1193 elm_object_item_data_set(item_to_update->item, item_to_update);
1194 elm_genlist_item_update(item_to_update->item);
1196 SETTING_TRACE("item_to_update is NULL");
1199 // case : edit control
1200 if ( 0 == strcmp (cur_node->name, "string"))
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);
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);
1212 elm_object_item_data_set(item_to_update->item, item_to_update);
1213 elm_genlist_item_update(item_to_update->item);
1216 SETTING_TRACE("item_to_update is NULL");
1219 // case : expand list
1225 //-----------------------------------------------------------
1226 if ( 0 == strcmp (cur_node->name, "expandlist"))
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);
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);
1238 elm_object_item_data_set(item_to_update->item, item_to_update);
1239 elm_genlist_item_update(item_to_update->item);
1241 // TODO: need to update child elements
1242 // item_to_update->childs ---> expanded list
1243 if (item_to_update->childs)
1245 Eina_List *li = item_to_update->childs;
1246 int radio_index = 0;
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)
1255 elm_radio_value_set(node->rgd, radio_index);
1257 elm_object_item_data_set(item_to_update->item, item_to_update);
1258 elm_genlist_item_update(item_to_update->item);
1261 li = eina_list_next(li);
1267 SETTING_TRACE("item_to_update is NULL");
1274 __node_finder(context, cur_node->children, id_str, value, is_end); /* RECURSIVE */
1279 static unsigned int _plugin_string_key_length(const char*key)
1284 return (int)strlen(key) + 1;
1287 static int _plugin_string_key_cmp(const char* key1, int key1_length,
1288 const char* key2, int key2_length)
1290 return strcmp(key1, key2);
1293 static void _plugin_entry_free_cb(void* data)
1295 Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) data;
1298 eina_list_free(node->childs);
1299 node->childs = NULL;
1303 //static PluginNode* g_context;
1305 PluginNode* setting_plugin_create()
1307 PluginNode *node = calloc(1, sizeof(PluginNode));
1309 Draw_Data *pd = calloc(1, sizeof(Draw_Data));
1310 setting_retvm_if(!pd, -1, "Create Draw_Data obj failed");
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,
1323 void setting_plugin_destroy(PluginNode* node)
1325 SETTING_TRACE_BEGIN;
1327 SETTING_TRACE("node is NOT NULL")
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");
1341 if (node->ui_list) {
1342 eina_hash_free(node->ui_list);
1343 node->ui_list = NULL;
1351 static Eina_Bool _plugin_foreach_cb(const Eina_Hash *hash, const void*key, void* data, void* fdata)
1353 Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) data;
1354 SETTING_TRACE("%s --- %s ", (char*)key, node->keyStr);
1359 void setting_plugin_debug(PluginNode* context)
1361 // SETTING_TRACE("HASH TABLE -------------------------------------");
1362 eina_hash_foreach(context->ui_list,_plugin_foreach_cb, NULL);
1363 // SETTING_TRACE("HASH TABLE -------------------------------------");
1367 void setting_plugin_update(PluginNode* context)
1369 Eina_List *li = context->ui_list;
1372 Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) eina_list_data_get(li);
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);
1380 li = eina_list_next(li);
1385 bool setting_plugin_load(PluginNode* context, const char *cfg_file)
1387 SETTING_TRACE("cfg_file:%s", cfg_file)
1388 if (isEmptyStr(cfg_file) || 0 != access(cfg_file, R_OK|W_OK|F_OK ))
1390 SETTING_TRACE_ERROR(" error occured : access \n");
1393 context->pd->cfg_file = cfg_file;
1394 context->pd->win_get = (Evas_Object *) ug_get_window();
1396 GError *error = NULL;
1398 context->pd->doc = xmlParseFile(cfg_file);
1399 context->pd->root = xmlDocGetRootElement(context->pd->doc);
1401 // TODO: error handler here
1402 __node_walker(context, context->pd->root);
1405 setting_plugin_debug(context);