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);
99 static void* setting_func(void *data, xmlNode *xmlObj);
101 static int __node_walker(PluginNode* context, xmlNode* cur);
103 static int __node_finder(PluginNode* context, xmlNode* cur, char* id_str, char* value, bool* is_end);
106 static void __drawer_add(const char *type, drawer_fp draw)
108 Object_Drawer *node = calloc(1, sizeof(Object_Drawer));
109 if (node && type && draw)
114 _g_drawer_list = eina_list_append(_g_drawer_list, node);
119 static drawer_fp __drawer_find(char* type)
122 Eina_List *check_list = _g_drawer_list;
123 Object_Drawer *list_item = NULL;
128 list_item = (Object_Drawer *) eina_list_data_get(check_list);
129 if (NULL == list_item)
132 if (0 == safeStrCmp(list_item->type, type))
134 //SETTING_TRACE("list_item->type:%s", list_item->type);
138 check_list = eina_list_next(check_list);
140 //SETTING_TRACE("list_item:%p", list_item);
141 return list_item ? list_item->draw : NULL;
143 void setting_drawer_list_init()
146 /* <navigationbar> */__drawer_add("navigationbar", navigationbar_func);
147 /* <bool> */__drawer_add("bool", checkbox_func);
148 /* <string> */__drawer_add("string", editbox_func);
149 /* <group> */__drawer_add("group", group_func);
150 /* <integer> */__drawer_add("integer", slider_func);
151 /* <label> */__drawer_add("label", label_func);
152 /* <link> */__drawer_add("link", link_func);
153 /* <extendlist> */__drawer_add("expandlist", expandlist_func);
154 /* <extenditem> */__drawer_add("expanditem", expanditem_func);
155 /* <settings> */__drawer_add("settings", settings_func);
156 /* <setting> */__drawer_add("setting", setting_func);
159 void setting_drawer_list_fini()
163 Object_Drawer *node = NULL;
164 Eina_List *li = _g_drawer_list;
166 node = (Object_Drawer *) eina_list_data_get(li);
169 //SETTING_TRACE("Deregister %s", node->type);
172 li = eina_list_next(li);
174 _g_drawer_list = eina_list_free(_g_drawer_list);
175 _g_drawer_list = NULL;
179 /////////////////////////
180 /////////////////////////
181 /////////////////////////
183 #define MAX_CONTENT_LEN 512
184 #define MAX_LOCAL_BUFSIZE 128
185 #define DBUS_PATH "/setting/dbus_handler"
186 #define DBUS_SIGNAL_INTERFACE "org.tizen.setting.signal"
187 #define DBUS_SIGNAL "test"
189 static char* substring(const char* str, size_t begin, size_t len)
191 if (str == 0 || strlen(str) == 0 || strlen(str) < begin || strlen(str) < (begin+len))
194 return strndup(str + begin, len);
197 //------------------------------------------------------
199 static DBusConnection *bus;
200 //------------------------------------------------------
201 static DBusHandlerResult __signal_filter(DBusConnection* conn, DBusMessage* message, void* user_data)
203 int my_pid = getpid();
209 dbus_error_init(&error);
211 setting_main_appdata *ad = user_data;
213 if (dbus_message_is_signal(message, DBUS_SIGNAL_INTERFACE, DBUS_SIGNAL))
215 if (dbus_message_get_args(message, &error,
216 DBUS_TYPE_UINT32, &sender_pid,
217 DBUS_TYPE_STRING, &key,
218 DBUS_TYPE_STRING, &value,
219 DBUS_TYPE_INVALID) == FALSE)
221 SETTING_TRACE_ERROR("Fail to get data : %s", error.message);
222 dbus_error_free(&error);
223 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
227 if (sender_pid != 0 && my_pid != sender_pid)
229 SETTING_TRACE("received key : %s , value : %s", key, value);
230 //-------------------------------------------------------------
231 // received key : checkbox1|N/A , value : INT|1
232 //-------------------------------------------------------------
233 //char* key = "checkbox1|N/A";
234 char* ptr = strchr(key, '|');
236 xmlDocPtr doc = NULL;
239 //parsing for : checkbox1|N/A -> checkbox1
240 char* key_name = substring(key, 0, strlen(key)-strlen(ptr));
241 char* val_name = strchr(value, '|');
246 doc = xmlParseFile(ad->plugin_path);
248 xmlNode *root = xmlDocGetRootElement(doc);
251 __node_finder((PluginNode*)ad->plugin_node, root, key_name ,val_name, &is_end);
254 GError *error = NULL;
259 xmlSaveFormatFile(ad->plugin_path, doc, 1);
260 // TODO: make sure this is right
263 SETTING_TRACE("__cfg_file_write successful");
270 return DBUS_HANDLER_RESULT_HANDLED;
273 static int __send_msg(char* key, char* value)
275 DBusMessage* message;
276 int sender_pid = getpid();
281 message = dbus_message_new_signal(DBUS_PATH, DBUS_SIGNAL_INTERFACE, DBUS_SIGNAL);
283 SETTING_TRACE("Sending message[%s:%s] via dbus", key ,value);
284 if (dbus_message_append_args(message,
285 DBUS_TYPE_UINT32, &sender_pid,
286 DBUS_TYPE_STRING, &key,
287 DBUS_TYPE_STRING, &value,
288 DBUS_TYPE_INVALID) == FALSE)
290 SETTING_TRACE("Fail to load data error");
294 if (dbus_connection_send(bus, message, NULL) == FALSE)
296 SETTING_TRACE("Fail to send message");
300 dbus_connection_flush(bus);
301 dbus_message_unref(message);
303 SETTING_TRACE("[CLIENT] send data signal done");
309 static void __send_int_msg(xmlNode* xmlObj, int val)
311 const char *id = (char*)xmlGetProp(xmlObj, "id");
312 const char *title = (char*)xmlGetProp(xmlObj, "title");
313 char key[MAX_CONTENT_LEN] = {0,};
314 snprintf(key, sizeof(key), "%s|%s", id, title);
316 char value[MAX_CONTENT_LEN] = {0,};
317 snprintf(value, sizeof(value), "INT|%d", val);
318 __send_msg(key, value);
322 static void __send_string_msg(xmlNode* xmlObj, char *string)
324 const char *id = (char*)xmlGetProp(xmlObj, "id");
325 const char *title = (char*)xmlGetProp(xmlObj, "title");
326 char key[MAX_CONTENT_LEN] = {0,};
327 snprintf(key, sizeof(key), "%s|%s", id, title);
329 char value[MAX_CONTENT_LEN] = {0,};
330 snprintf(value, sizeof(value), "STRING|%s", string);
331 __send_msg(key, value);
335 int setting_dbus_handler_init(void* user_data)
339 char rule[MAX_LOCAL_BUFSIZE];
341 dbus_error_init(&error);
342 bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
345 SETTING_TRACE("Fail to connect to the D-BUS daemon: %s", error.message);
346 dbus_error_free(&error);
350 dbus_connection_setup_with_g_main(bus, NULL);
351 snprintf(rule, MAX_LOCAL_BUFSIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH, DBUS_SIGNAL_INTERFACE);
353 dbus_bus_add_match(bus, rule, &error);
354 if (dbus_error_is_set(&error))
356 SETTING_TRACE("Fail to rule set; %s", error.message);
357 dbus_error_free(&error);
361 if (dbus_connection_add_filter(bus, __signal_filter, user_data, NULL) == FALSE)
366 SETTING_TRACE("app signal initialized");
372 int setting_dbus_handler_fini(void)
375 char rule[MAX_LOCAL_BUFSIZE];
377 dbus_error_init(&error);
378 dbus_connection_remove_filter(bus, __signal_filter, NULL);
379 snprintf(rule, MAX_LOCAL_BUFSIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH, DBUS_SIGNAL_INTERFACE);
380 dbus_bus_remove_match(bus, rule, &error);
382 if (dbus_error_is_set(&error))
384 SETTING_TRACE("Fail to rule unset: %s", error.message);
385 dbus_error_free(&error);
389 dbus_connection_close(bus);
390 SETTING_TRACE("app signal finalized");
394 /////////////////////////////
395 /////////////////////////////
396 /////////////////////////////
398 Elm_Genlist_Item_Class itc_layout;
401 static int __cfg_file_write(Draw_Data *pd)
405 GError *error = NULL;
408 xmlSaveFormatFile(pd->cfg_file, pd->doc, 1);
409 //xmlFreeDoc(pd->doc);
411 SETTING_TRACE("__cfg_file_write successful");
418 static void ___click_softkey_back_cb(void *data, Evas_Object *obj,
424 PluginNode* node = (PluginNode*)data;
425 Draw_Data *pd = node->pd;
427 evas_object_del(pd->ly_main);
431 setting_plugin_destroy(node);
433 // pd->scroller = NULL;
434 // pd->navi_bar = NULL;
435 // pd->cfg_file = NULL;
441 static void* group_func(void *data, xmlNode *xmlObj)
444 ret_if(!data || !xmlObj);
446 PluginNode* node = (PluginNode*)data;
447 Draw_Data *pd = node->pd;
449 // original code is non-recursive
451 const char *title = (char*)json_object_get_string_member(jsonObj, "title");
452 (void)setting_create_Gendial_field_titleItem(pd->scroller,
456 // non recursive method
457 if (json_object_has_member(jsonObj, "elements"))
459 JsonNode* elements_node = json_object_get_member(jsonObj, "elements");
463 for (i=0; i < json_array_get_length(json_node_get_array(elements_node)); i++)
465 tempobj = json_array_get_object_element(json_node_get_array(elements_node), i);
466 type = (char*)json_object_get_string_member(tempobj, "type");
467 drawer_fp fp = __drawer_find(type);
468 if (fp) fp(pd, tempobj); // draw it
472 // new code is recursive
473 const char *title = (char*)xmlGetProp(xmlObj, "title");
474 SETTING_TRACE (" >>> GROUP NAME : %s \n", title);
475 (void)setting_create_Gendial_field_titleItem(pd->scroller, &(itc_group_item), title, NULL);
482 static void* __link_list_cb(void *data, Evas_Object *obj, void *event_info)
484 ret_if(data == NULL);
485 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
486 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
487 elm_genlist_item_selected_set(item, 0);
488 Setting_GenGroupItem_Data *list_item =
489 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
491 xmlNode* xmlObj = data;
493 const char *link_file = (char*)xmlGetProp(xmlObj, "value");
497 SETTING_TRACE_ERROR("Invalidate liked file");
500 char file[1024] = {0,};
501 snprintf(file, sizeof(file), "%s/%s", PLUGIN_CFG_DIR, link_file);
502 SETTING_TRACE("file:%s", file);
504 PluginNode* plugin_node = setting_plugin_create();
505 setting_plugin_load(plugin_node, (const char *)file);
507 //setting_plugin_load(NULL, file);
513 static void* label_func(void *data, xmlNode *xmlObj)
516 ret_if(!data || !xmlObj);
517 PluginNode* node = (PluginNode*)data;
518 Draw_Data *pd = node->pd;
520 const char *title = (char*)xmlGetProp(xmlObj, "title");
522 Setting_GenGroupItem_Data *obj =
523 setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
525 xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
526 0, title, NULL, NULL);
531 static void* link_func(void *data, xmlNode *xmlObj)
534 ret_if(!data || !xmlObj);
535 PluginNode* node = (PluginNode*)data;
536 Draw_Data *pd = node->pd;
538 const char *key_str = (char*)xmlGetProp(xmlObj, "id");
539 Setting_GenGroupItem_Data * obj =
540 setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
542 xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
543 0, key_str, NULL, NULL);
549 static void __slider_stop_cb(void *data, Evas_Object *obj,
552 ret_if(data == NULL || obj == NULL);
553 double val = elm_slider_value_get(obj);
554 SETTING_TRACE("val = %f", val);
555 Setting_GenGroupItem_Data *list_item = data;
556 ret_if(list_item->userdata == NULL);
558 xmlNode* xmlObj = list_item->userdata;
561 //apply the vconf changes after stopping moving slider..
562 list_item->chk_status = (int)(val + 0.5);
563 elm_slider_value_set(obj, list_item->chk_status);
565 SETTING_TRACE(" slider after ---> val = %d", (int) list_item->chk_status);
567 // int -> double -> xmlChar*
570 sprintf(buf, "%d", (int) list_item->chk_status);
571 newattr = xmlSetProp(xmlObj, "value", buf);
573 __send_int_msg(xmlObj, list_item->chk_status);
574 __cfg_file_write((Draw_Data *)list_item->belongs_to);
578 static void* slider_func(void *data, xmlNode *xmlObj)
581 ret_if(!data || !xmlObj);
582 PluginNode* node = (PluginNode*)data;
583 Draw_Data *pd = node->pd;
586 const char *title = (char*)xmlGetProp(xmlObj, "title");
588 SETTING_TRACE (" >>> [slider input] min=%s max=%s value=%s ",(char*)xmlGetProp(xmlObj, "min"), (char*)xmlGetProp(xmlObj, "max"), (char*)xmlGetProp(xmlObj, "value"));
590 int value = atoi((char*)xmlGetProp(xmlObj, "value"));
591 int min = atoi((char*)xmlGetProp(xmlObj, "min"));
592 int max = atoi((char*)xmlGetProp(xmlObj, "max"));
594 SETTING_TRACE ("[slider input] min=%d max=%d value=%d ", min, max, value);
596 setting_create_Gendial_itc("dialogue/1text.1icon.5", &(itc_layout));
597 Setting_GenGroupItem_Data *list_item =
598 setting_create_Gendial_field_def(pd->scroller, &(itc_layout), NULL,
600 SWALLOW_Type_LAYOUT_SLIDER,
601 IMG_SENSITIVITY_ICON_01,
602 IMG_SENSITIVITY_ICON_02, value,
605 list_item->win_main = NULL;
606 list_item->evas = NULL;
607 list_item->isIndicatorVisible = true;
608 list_item->slider_min = min;
609 list_item->slider_max = max;
610 list_item->userdata = xmlObj;
611 list_item->stop_change_cb = __slider_stop_cb;
612 list_item->belongs_to = (int)pd;
615 g_list_item = list_item;
617 return (void*)list_item;
621 elm_object_item_data_set(item_to_update->item, item_to_update);
622 elm_genlist_item_update(item_to_update->item);
624 static void* navigationbar_func(void *data, xmlNode *xmlObj)
627 ret_if(!data || !xmlObj);
629 //Draw_Data *pd = node->pd;
630 PluginNode* node = (PluginNode*)data;
631 Draw_Data *pd = node->pd;
633 //----------------------------------------------------------------
634 // [DATA] title, btn[0], btn[1]
635 const char *title = (char*)xmlGetProp(xmlObj, "title");
636 char *btn[2] = {0, };
638 // find child nodes named 'elements'
639 if (xmlObj->children) {
640 xmlNode* cur = xmlObj->children;
644 if (!xmlStrcmp(cur->name, (const xmlChar*)"button")) {
645 btn[i] = xmlGetProp(cur, "title");
646 SETTING_TRACE("------>>> node type : Element, name=%s id=%s / btn[%d] = %s ", cur->name,xmlGetProp(cur, "id"), i, btn[i]);
652 //----------------------------------------------------------------
654 pd->ly_main = setting_create_layout_navi_bar_genlist(pd->win_get,
657 _(btn[1]), _(btn[0]),
658 ___click_softkey_back_cb,
659 ___click_softkey_back_cb, data, &pd->scroller,
666 static void __check_mouse_up_cb(void *data, Evas_Object *obj,
671 setting_retm_if(data == NULL, "Data parameter is NULL");
673 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
674 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
675 elm_genlist_item_selected_set(item, 0);
676 Setting_GenGroupItem_Data *list_item =
677 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
679 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
681 int old_status = elm_check_state_get(list_item->eo_check);
682 list_item->chk_status = !old_status;
683 elm_check_state_set(list_item->eo_check, list_item->chk_status);
685 xmlNode *xmlObj = data;
687 newattr = xmlSetProp(xmlObj, "state", xmlXPathCastNumberToString(list_item->chk_status));
689 __send_int_msg(xmlObj, list_item->chk_status);
690 __cfg_file_write((Draw_Data *)list_item->belongs_to);
694 static void __chk_btn_cb(void *data, Evas_Object *obj,
699 retm_if(data == NULL, "Data parameter is NULL");
700 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
702 xmlNode* xmlObj = list_item->userdata;
704 list_item->chk_status = elm_check_state_get(obj); /* for genlist update status */
707 if (list_item->chk_status == 1) {
708 newattr = xmlSetProp(xmlObj, "value", "true");
709 } else if (list_item->chk_status == 0) {
710 newattr = xmlSetProp(xmlObj, "value", "false");
712 newattr = xmlSetProp(xmlObj, "value", "false");
715 const char *id = (char*)xmlGetProp(xmlObj, "id");
716 const char *title = (char*)xmlGetProp(xmlObj, "title");
717 //SETTING_TRACE(" >>>> id:%s , title:%s", id, title);
718 __send_int_msg(xmlObj, list_item->chk_status);
719 __cfg_file_write((Draw_Data *)list_item->belongs_to);
724 static void* checkbox_func(void *data, xmlNode *xmlObj)
727 ret_if(!data || !xmlObj);
729 PluginNode* node = (PluginNode*)data;
730 Draw_Data *pd = node->pd;
732 // [DATA] title, value
733 const char *title = (char*)xmlGetProp(xmlObj, "title");
736 char* value = (char*)xmlGetProp(xmlObj, "value");
740 if ( 0 == safeStrCmp(value, "true")) {
742 } else if ( 0 == safeStrCmp(value, "false")) {
745 ival = 0; // default : false (0)
748 // title, value, xmlObj
749 Setting_GenGroupItem_Data *list_item =
750 setting_create_Gendial_field_def(pd->scroller,
754 SWALLOW_Type_1TOGGLE,
761 list_item->userdata = xmlObj;
762 list_item->belongs_to = (int) pd;
763 SETTING_TRACE("pd:%p,list_item->belongs_to:%d", pd, list_item->belongs_to);
770 static void __entry_unfocus_cb(void *data, Evas_Object *obj, void *event_info)
773 retm_if(!data || !obj, "Data parameter is NULL");
775 setting_hide_input_pannel_cb(obj);
776 const char *entry_str = elm_entry_entry_get(obj);
777 char *entry_str_utf8 = NULL;
778 entry_str_utf8 = elm_entry_markup_to_utf8(entry_str);
780 Setting_GenGroupItem_Data *list_item = data;
782 xmlNode* xmlObj = list_item->userdata;
785 const char *title = (char*)xmlSetProp(xmlObj, "value",entry_str_utf8);
787 __send_string_msg(xmlObj, entry_str_utf8);
788 __cfg_file_write((Draw_Data *)list_item->belongs_to);
790 FREE(entry_str_utf8);
794 static void __editbox_list_cb(void *data, Evas_Object *obj,
800 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
801 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
802 elm_genlist_item_selected_set(item, 0);
803 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
805 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
806 if (!elm_object_focus_get(list_item->eo_check)) {
807 elm_object_focus_set(list_item->eo_check, EINA_TRUE);
810 Ecore_IMF_Context *imf_context = (Ecore_IMF_Context *)elm_entry_imf_context_get(list_item->eo_check);
811 setting_retm_if(imf_context == NULL, "imf_context is NULL");
812 ecore_imf_context_input_panel_show(imf_context);
816 static void __editbox_changed_cb(void *data, Evas_Object *obj,
820 retm_if(!data || !obj, "Data parameter is NULL");
821 retm_if(!elm_object_focus_get(obj), "Entry is not focused");
823 Setting_GenGroupItem_Data *list_item =
824 (Setting_GenGroupItem_Data *) data;
826 const char *entry_str = elm_entry_entry_get(obj);
827 int entry_len = safeStrLen(entry_str);
828 SETTING_TRACE("entry_str:[%s], lenght:%d", entry_str, entry_len);
830 G_FREE(list_item->sub_desc);//release first
831 list_item->sub_desc = (char *)g_strdup(entry_str);
835 static void* editbox_func(void *data, xmlNode *xmlObj)
838 ret_if(!data || !xmlObj);
840 PluginNode* node = (PluginNode*)data;
841 Draw_Data *pd = node->pd;
843 const char *title = (char*)xmlGetProp(xmlObj, "title");
844 const char *key_str= (char*)xmlGetProp(xmlObj, "value");
848 Setting_GenGroupItem_Data *list_item =
849 setting_create_Gendial_field_def(pd->scroller, &(itc_1icon),
851 pd, SWALLOW_Type_LAYOUT_ENTRY,
852 NULL, NULL, 0, title, key_str,
853 __editbox_changed_cb);
855 list_item->userdata = xmlObj;
856 list_item->stop_change_cb = __entry_unfocus_cb;
857 list_item->belongs_to = (int)pd;
864 static void __expanditem_func_sel_cb(void *data, Evas_Object *obj, void *event_info)
868 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
869 Elm_Object_Item *subitem = (Elm_Object_Item *) event_info;
870 Elm_Object_Item *parentItem = elm_genlist_item_parent_get(subitem);
871 elm_genlist_item_selected_set(subitem, 0);
872 Setting_GenGroupItem_Data *data_subItem = elm_object_item_data_get(subitem);
873 Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem); /* parent data */
874 ret_if(NULL == data_subItem || NULL == data_parentItem);
876 elm_radio_value_set(data_subItem->rgd, data_subItem->chk_status);
878 data_parentItem->sub_desc = (char *)g_strdup(_(data_subItem->keyStr));
879 elm_object_item_data_set(data_parentItem->item, data_parentItem);
880 elm_genlist_item_update(data_parentItem->item);
882 xmlNode* xmlObj = data_parentItem->userdata;
886 //newattr = xmlSetProp(xmlObj, "string", data_parentItem->sub_desc);
887 newattr = xmlSetProp(xmlObj, "value", data_parentItem->sub_desc);
889 __send_string_msg(xmlObj, data_parentItem->sub_desc);
890 __cfg_file_write((Draw_Data *)data_parentItem->belongs_to);
894 static void __expanditem_func_exp_cb(void *data, Evas_Object *obj, void *event_info)
896 ret_if(NULL == data || NULL == event_info);
899 PluginNode* node = (PluginNode*)data;
900 Draw_Data *pd = node->pd;
902 Elm_Object_Item *parentItem = event_info; /* parent item */
903 Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem); /* parent data */
904 Evas_Object *scroller = elm_object_item_widget_get(parentItem);
907 xmlNode *xmlObj = data_parentItem->userdata;
908 //char *value = (char*)xmlGetProp(xmlObj, "string");
909 char *value = (char*)xmlGetProp(xmlObj, "value");
910 SETTING_TRACE(">>> value = %s", value);
912 Evas_Object *rgd = NULL;
914 if (xmlObj->children && !data_parentItem->rgd) {//to protect from entering repeatly
915 xmlNode* cur = xmlObj->children;
917 rgd = elm_radio_add(scroller);
918 elm_radio_value_set(rgd, -1);
922 char *subitem_title = NULL;
923 int subitem_index = 0;
926 while (cur != NULL) {
927 if (!xmlStrcmp(cur->name, (const xmlChar*)"expanditem")) {
928 type = (char*)xmlGetProp(cur, "type");
929 if (0 == safeStrCmp(type, "radio")) {
930 subitem_title = (char*)xmlGetProp(cur, "title");
931 Setting_GenGroupItem_Data *list_item =
932 setting_create_Gendial_exp_sub_field(scroller,
933 &(itc_1icon_1text_sub),
934 __expanditem_func_sel_cb, NULL, parentItem,
935 SWALLOW_Type_1RADIO, rgd,
937 subitem_title, NULL);
939 // SETTING_TRACE(">>> value = %s, subitem_title = %s ", value, subitem_title);
941 if (0 == safeStrCmp(value, subitem_title)) {
942 sel_idx = subitem_index;
943 SETTING_TRACE("%d is selected in Radio Group", sel_idx);
945 data_parentItem->childs = eina_list_append(data_parentItem->childs, list_item);
949 SETTING_TRACE("invalid type[:%s]", type);
958 elm_radio_value_set(rgd, sel_idx);
959 data_parentItem->rgd = rgd;//protecting condition
964 static void __expanditem_func_smart_cb(void *data, Evas_Object *obj, void *event_info)
966 ret_if(data == NULL || event_info == NULL);
967 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
968 Setting_GenGroupItem_Data *data_item = elm_object_item_data_get(item);
969 char *cb_type = data;
971 if (0 == safeStrCmp(cb_type, "contracted")) {
972 data_item->rgd = NULL;
973 elm_genlist_item_subitems_clear(item);
978 static void* settings_func(void *data, xmlNode *xmlObj)
984 static void* setting_func(void *data, xmlNode *xmlObj)
988 //----------------------------------------------------------------
989 // [DATA] title, btn[0], btn[1]
990 Draw_Data *pd = data;
991 const char *title = (char*)xmlGetProp(xmlObj, "title");
992 char *btn[2] = {0, };
994 // find child nodes named 'elements'
996 if (xmlObj->children) {
997 xmlNode* cur = xmlObj->children;
1001 if (!xmlStrcmp(cur->name, (const xmlChar*)"button")) {
1002 btn[i] = xmlGetProp(cur, "title");
1003 SETTING_TRACE("------>>> node type : Element, name=%s id=%s / btn[%d] = %s ", cur->name,xmlGetProp(cur, "id"), i, btn[i]);
1010 //----------------------------------------------------------------
1012 pd->ly_main = setting_create_layout_navi_bar_genlist(pd->win_get,
1016 ___click_softkey_back_cb,
1017 ___click_softkey_back_cb, pd, &pd->scroller,
1025 static void* expanditem_func(void *data, xmlNode *xmlObj)
1027 // DO NOTHING - expandlist draws this area
1031 static void* expandlist_func(void *data, xmlNode *xmlObj)
1033 SETTING_TRACE_BEGIN;
1034 ret_if(!data || !xmlObj);
1036 PluginNode* node = (PluginNode*)data;
1037 Draw_Data *pd = node->pd;
1039 const char *key_str = (char*)xmlGetProp(xmlObj, "title");
1040 const char *value = (char*)xmlGetProp(xmlObj, "value"); // string -> value
1042 setting_enable_expandable_genlist(pd->scroller, data, __expanditem_func_exp_cb, __expanditem_func_smart_cb);
1043 Setting_GenGroupItem_Data *list_item =
1044 setting_create_Gendial_exp_parent_field(pd->scroller,
1045 &(itc_2text_3_parent),
1047 SWALLOW_Type_INVALID,
1051 list_item->userdata = xmlObj;
1052 list_item->belongs_to = (int)pd;
1060 static int __node_walker(PluginNode* context, xmlNode* cur)
1062 //SETTING_TRACE_BEGIN;
1063 Draw_Data *pd = context->pd;
1066 xmlNode *cur_node = NULL;
1067 for (cur_node = cur; cur_node;cur_node = cur_node->next) {
1068 if (cur_node->type == XML_ELEMENT_NODE) {
1069 SETTING_TRACE("node type : Element, name=%s id=%s", cur_node->name,xmlGetProp(cur_node, "id"));
1071 drawer_fp fp = __drawer_find(cur_node->name);
1075 void* vret = fp(context, cur_node); // draw it
1079 Setting_GenGroupItem_Data* genlist_node = (Setting_GenGroupItem_Data* )vret;
1080 //SETTING_TRACE("add node to Eina List name : %s, id : ", cur_node->name, xmlGetProp(cur_node, "id"));
1081 // add it to the hash table create before.
1084 char* key_name = xmlGetProp(cur_node, "id");
1085 eina_hash_add(context->ui_list, strdup(key_name),(void*)genlist_node);
1089 __node_walker(context, cur_node->children); /* RECURSIVE */
1095 * @param id_str [in] "id"
1096 * @param value [in] value to be udpated
1097 * @see __expanditem_func_sel_cb
1099 static int __node_finder(PluginNode* context, xmlNode* cur, char* id_str, char* value, bool* is_end)
1101 SETTING_TRACE_BEGIN;
1102 xmlNode *cur_node = NULL;
1104 if (*is_end == true) return 0;
1106 for (cur_node = cur; cur_node;cur_node = cur_node->next) {
1107 if (cur_node->type == XML_ELEMENT_NODE) {
1109 char* id_name = (char*)xmlGetProp(cur_node, "id");
1110 if ( id_name && 0 == strcmp(id_str, id_name))
1112 SETTING_TRACE("FOUND >>>> %s", id_name);
1113 // cur_node - update xml code
1114 xmlAttrPtr newattr = xmlSetProp(cur_node, "value", value);
1116 //-----------------------------------------------------------
1119 if ( 0 == strcmp (cur_node->name, "integer"))
1121 SETTING_TRACE(">>>>> UPDATE SLIDER CONTROL %x --- %s ",context->ui_list, id_name);
1122 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1125 item_to_update->chk_status = atoi(value);
1126 SETTING_TRACE(">>> o-------------0 SLIDER VALUE = %d ", item_to_update->chk_status);
1128 elm_object_item_data_set(item_to_update->item, item_to_update);
1129 elm_genlist_item_update(item_to_update->item);
1131 SETTING_TRACE("item_to_update is NULL");
1135 if ( 0 == strcmp (cur_node->name, "bool"))
1137 SETTING_TRACE(">>>>> UPDATE TOGGLE CONTROL %x --- %s ",context->ui_list, id_name);
1138 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1141 item_to_update->chk_status = atoi(value);
1142 SETTING_TRACE(">>> o-------------0 TOGGLE VALUE = %d ", item_to_update->chk_status);
1144 elm_object_item_data_set(item_to_update->item, item_to_update);
1145 elm_genlist_item_update(item_to_update->item);
1147 SETTING_TRACE("item_to_update is NULL");
1150 // case : edit control
1151 if ( 0 == strcmp (cur_node->name, "string"))
1153 SETTING_TRACE(">>>>> UPDATE EDIT CONTROL CONTROL %x --- %s ",context->ui_list, id_name);
1154 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1157 char* old_string = item_to_update->sub_desc;
1158 item_to_update->sub_desc = strdup(value);
1159 SETTING_TRACE(">>> o-------------0 STRING VALUE = %s ", value);
1163 elm_object_item_data_set(item_to_update->item, item_to_update);
1164 elm_genlist_item_update(item_to_update->item);
1167 SETTING_TRACE("item_to_update is NULL");
1170 // case : expand list
1176 //-----------------------------------------------------------
1177 if ( 0 == strcmp (cur_node->name, "expandlist"))
1179 SETTING_TRACE(">>>>> UPDATE EXPAND LIST CONTROL %x --- %s ",context->ui_list, id_name);
1180 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1183 char* old_string = item_to_update->sub_desc;
1184 item_to_update->sub_desc = strdup(value);
1185 SETTING_TRACE(">>> o-------------0 EXPAND LIST VALUE = %s ", value);
1189 elm_object_item_data_set(item_to_update->item, item_to_update);
1190 elm_genlist_item_update(item_to_update->item);
1192 // TODO: need to update child elements
1193 // item_to_update->childs ---> expanded list
1194 if (item_to_update->childs)
1196 Eina_List *li = item_to_update->childs;
1197 int radio_index = 0;
1200 Setting_GenGroupItem_Data* node = eina_list_data_get(li);
1201 // do something more
1202 // SETTING_TRACE(">>> RADIO LIST STRING VALUE = %s ", node->keyStr);
1203 // set position of radio button
1204 if (strcmp(node->keyStr, value) == 0)
1206 elm_radio_value_set(node->rgd, radio_index);
1208 elm_object_item_data_set(item_to_update->item, item_to_update);
1209 elm_genlist_item_update(item_to_update->item);
1212 li = eina_list_next(li);
1218 SETTING_TRACE("item_to_update is NULL");
1225 __node_finder(context, cur_node->children, id_str, value, is_end); /* RECURSIVE */
1230 static unsigned int _plugin_string_key_length(const char*key)
1235 return (int)strlen(key) + 1;
1238 static int _plugin_string_key_cmp(const char* key1, int key1_length,
1239 const char* key2, int key2_length)
1241 return strcmp(key1, key2);
1244 static void _plugin_entry_free_cb(void* data)
1246 Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) data;
1249 eina_list_free(node->childs);
1250 node->childs = NULL;
1254 //static PluginNode* g_context;
1256 PluginNode* setting_plugin_create()
1258 PluginNode *node = calloc(1, sizeof(PluginNode));
1260 Draw_Data *pd = calloc(1, sizeof(Draw_Data));
1261 setting_retvm_if(!pd, -1, "Create Draw_Data obj failed");
1265 node->ui_list = eina_hash_new(EINA_KEY_LENGTH(_plugin_string_key_length),
1266 EINA_KEY_CMP(_plugin_string_key_cmp),
1267 EINA_KEY_HASH(eina_hash_superfast),
1268 _plugin_entry_free_cb,
1274 void setting_plugin_destroy(PluginNode* node)
1276 SETTING_TRACE_BEGIN;
1278 SETTING_TRACE("node is NOT NULL")
1280 SETTING_TRACE("node->pd is NOT NULL")
1281 if(node->pd->doc != NULL) {
1282 xmlSaveFormatFile(node->plugin_path, node->pd->doc, 1);
1283 xmlFreeDoc(node->pd->doc);
1284 node->pd->doc = NULL;
1285 SETTING_TRACE("__cfg_file_write successful");
1292 if (node->ui_list) {
1293 eina_hash_free(node->ui_list);
1294 node->ui_list = NULL;
1302 static Eina_Bool _plugin_foreach_cb(const Eina_Hash *hash, const void*key, void* data, void* fdata)
1304 Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) data;
1305 SETTING_TRACE("%s --- %s ", (char*)key, node->keyStr);
1310 void setting_plugin_debug(PluginNode* context)
1312 // SETTING_TRACE("HASH TABLE -------------------------------------");
1313 eina_hash_foreach(context->ui_list,_plugin_foreach_cb, NULL);
1314 // SETTING_TRACE("HASH TABLE -------------------------------------");
1318 void setting_plugin_update(PluginNode* context)
1320 Eina_List *li = context->ui_list;
1323 Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) eina_list_data_get(li);
1325 // SETTING_TRACE(" ---> keyStr : %s , swallow type : %d ", node->keyStr, node->swallow_type);
1326 Setting_GenGroupItem_Data* item_to_update = NULL;
1327 item_to_update = node;
1328 elm_object_item_data_set(item_to_update->item, item_to_update);
1329 elm_genlist_item_update(item_to_update->item);
1331 li = eina_list_next(li);
1336 bool setting_plugin_load(PluginNode* context, const char *cfg_file)
1338 SETTING_TRACE("cfg_file:%s", cfg_file)
1339 if (isEmptyStr(cfg_file) || 0 != access(cfg_file, R_OK|W_OK|F_OK ))
1341 SETTING_TRACE_ERROR(" error occured : access \n");
1344 context->pd->cfg_file = cfg_file;
1345 context->pd->win_get = (Evas_Object *) ug_get_window();
1347 GError *error = NULL;
1349 context->pd->doc = xmlParseFile(cfg_file);
1350 context->pd->root = xmlDocGetRootElement(context->pd->doc);
1352 // TODO: error handler here
1353 __node_walker(context, context->pd->root);
1356 setting_plugin_debug(context);