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);
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);
250 __node_finder((PluginNode*)ad->plugin_node, root, key_name ,val_name);
253 GError *error = NULL;
258 xmlSaveFormatFile(ad->plugin_path, doc, 1);
259 // TODO: make sure this is right
262 SETTING_TRACE("__cfg_file_write successful");
269 return DBUS_HANDLER_RESULT_HANDLED;
272 static int __send_msg(char* key, char* value)
274 DBusMessage* message;
275 int sender_pid = getpid();
280 message = dbus_message_new_signal(DBUS_PATH, DBUS_SIGNAL_INTERFACE, DBUS_SIGNAL);
282 SETTING_TRACE("Sending message[%s:%s] via dbus", key ,value);
283 if (dbus_message_append_args(message,
284 DBUS_TYPE_UINT32, &sender_pid,
285 DBUS_TYPE_STRING, &key,
286 DBUS_TYPE_STRING, &value,
287 DBUS_TYPE_INVALID) == FALSE)
289 SETTING_TRACE("Fail to load data error");
293 if (dbus_connection_send(bus, message, NULL) == FALSE)
295 SETTING_TRACE("Fail to send message");
299 dbus_connection_flush(bus);
300 dbus_message_unref(message);
302 SETTING_TRACE("[CLIENT] send data signal done");
308 static void __send_int_msg(xmlNode* xmlObj, int val)
310 const char *id = (char*)xmlGetProp(xmlObj, "id");
311 const char *title = (char*)xmlGetProp(xmlObj, "title");
312 char key[MAX_CONTENT_LEN] = {0,};
313 snprintf(key, sizeof(key), "%s|%s", id, title);
315 char value[MAX_CONTENT_LEN] = {0,};
316 snprintf(value, sizeof(value), "INT|%d", val);
317 __send_msg(key, value);
321 static void __send_string_msg(xmlNode* xmlObj, char *string)
323 const char *id = (char*)xmlGetProp(xmlObj, "id");
324 const char *title = (char*)xmlGetProp(xmlObj, "title");
325 char key[MAX_CONTENT_LEN] = {0,};
326 snprintf(key, sizeof(key), "%s|%s", id, title);
328 char value[MAX_CONTENT_LEN] = {0,};
329 snprintf(value, sizeof(value), "STRING|%s", string);
330 __send_msg(key, value);
334 int setting_dbus_handler_init(void* user_data)
338 char rule[MAX_LOCAL_BUFSIZE];
340 dbus_error_init(&error);
341 bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
344 SETTING_TRACE("Fail to connect to the D-BUS daemon: %s", error.message);
345 dbus_error_free(&error);
349 dbus_connection_setup_with_g_main(bus, NULL);
350 snprintf(rule, MAX_LOCAL_BUFSIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH, DBUS_SIGNAL_INTERFACE);
352 dbus_bus_add_match(bus, rule, &error);
353 if (dbus_error_is_set(&error))
355 SETTING_TRACE("Fail to rule set; %s", error.message);
356 dbus_error_free(&error);
360 if (dbus_connection_add_filter(bus, __signal_filter, user_data, NULL) == FALSE)
365 SETTING_TRACE("app signal initialized");
371 int setting_dbus_handler_fini(void)
374 char rule[MAX_LOCAL_BUFSIZE];
376 dbus_error_init(&error);
377 dbus_connection_remove_filter(bus, __signal_filter, NULL);
378 snprintf(rule, MAX_LOCAL_BUFSIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH, DBUS_SIGNAL_INTERFACE);
379 dbus_bus_remove_match(bus, rule, &error);
381 if (dbus_error_is_set(&error))
383 SETTING_TRACE("Fail to rule unset: %s", error.message);
384 dbus_error_free(&error);
388 dbus_connection_close(bus);
389 SETTING_TRACE("app signal finalized");
393 /////////////////////////////
394 /////////////////////////////
395 /////////////////////////////
397 Elm_Genlist_Item_Class itc_layout;
400 static int __cfg_file_write(Draw_Data *pd)
404 GError *error = NULL;
407 xmlSaveFormatFile(pd->cfg_file, pd->doc, 1);
408 // TODO: make sure this is right
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,
662 //return (void*)(pd->ly_main);
667 static void __check_mouse_up_cb(void *data, Evas_Object *obj,
672 setting_retm_if(data == NULL, "Data parameter is NULL");
674 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
675 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
676 elm_genlist_item_selected_set(item, 0);
677 Setting_GenGroupItem_Data *list_item =
678 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
680 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
682 int old_status = elm_check_state_get(list_item->eo_check);
683 list_item->chk_status = !old_status;
684 elm_check_state_set(list_item->eo_check, list_item->chk_status);
686 xmlNode *xmlObj = data;
688 newattr = xmlSetProp(xmlObj, "state", xmlXPathCastNumberToString(list_item->chk_status));
690 __send_int_msg(xmlObj, list_item->chk_status);
691 __cfg_file_write((Draw_Data *)list_item->belongs_to);
695 static void __chk_btn_cb(void *data, Evas_Object *obj,
700 retm_if(data == NULL, "Data parameter is NULL");
701 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
703 xmlNode* xmlObj = list_item->userdata;
705 list_item->chk_status = elm_check_state_get(obj); /* for genlist update status */
708 if (list_item->chk_status == 1) {
709 newattr = xmlSetProp(xmlObj, "value", "true");
710 } else if (list_item->chk_status == 0) {
711 newattr = xmlSetProp(xmlObj, "value", "false");
713 newattr = xmlSetProp(xmlObj, "value", "false");
716 const char *id = (char*)xmlGetProp(xmlObj, "id");
717 const char *title = (char*)xmlGetProp(xmlObj, "title");
718 SETTING_TRACE(" >>>> id:%s , title:%s", id, title);
719 __send_int_msg(xmlObj, list_item->chk_status);
720 __cfg_file_write((Draw_Data *)list_item->belongs_to);
725 static void* checkbox_func(void *data, xmlNode *xmlObj)
728 ret_if(!data || !xmlObj);
730 PluginNode* node = (PluginNode*)data;
731 Draw_Data *pd = node->pd;
733 // [DATA] title, value
734 const char *title = (char*)xmlGetProp(xmlObj, "title");
737 char* value = (char*)xmlGetProp(xmlObj, "value");
741 if ( 0 == safeStrCmp(value, "true")) {
743 } else if ( 0 == safeStrCmp(value, "false")) {
746 ival = 0; // default : false (0)
749 // title, value, xmlObj
750 Setting_GenGroupItem_Data *list_item =
751 setting_create_Gendial_field_def(pd->scroller,
755 SWALLOW_Type_1TOGGLE,
762 list_item->userdata = xmlObj;
763 list_item->belongs_to = (int) pd;
764 SETTING_TRACE("pd:%p,list_item->belongs_to:%d", pd, list_item->belongs_to);
771 static void __entry_unfocus_cb(void *data, Evas_Object *obj, void *event_info)
774 retm_if(!data || !obj, "Data parameter is NULL");
776 setting_hide_input_pannel_cb(obj);
777 const char *entry_str = elm_entry_entry_get(obj);
778 char *entry_str_utf8 = NULL;
779 entry_str_utf8 = elm_entry_markup_to_utf8(entry_str);
781 Setting_GenGroupItem_Data *list_item = data;
783 xmlNode* xmlObj = list_item->userdata;
786 const char *title = (char*)xmlSetProp(xmlObj, "value",entry_str_utf8);
788 __send_string_msg(xmlObj, entry_str_utf8);
789 __cfg_file_write((Draw_Data *)list_item->belongs_to);
791 FREE(entry_str_utf8);
795 static void __editbox_list_cb(void *data, Evas_Object *obj,
801 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
802 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
803 elm_genlist_item_selected_set(item, 0);
804 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
806 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
807 if (!elm_object_focus_get(list_item->eo_check)) {
808 elm_object_focus_set(list_item->eo_check, EINA_TRUE);
811 Ecore_IMF_Context *imf_context = (Ecore_IMF_Context *)elm_entry_imf_context_get(list_item->eo_check);
812 setting_retm_if(imf_context == NULL, "imf_context is NULL");
813 ecore_imf_context_input_panel_show(imf_context);
817 static void __editbox_changed_cb(void *data, Evas_Object *obj,
821 retm_if(!data || !obj, "Data parameter is NULL");
822 retm_if(!elm_object_focus_get(obj), "Entry is not focused");
824 Setting_GenGroupItem_Data *list_item =
825 (Setting_GenGroupItem_Data *) data;
827 const char *entry_str = elm_entry_entry_get(obj);
828 int entry_len = safeStrLen(entry_str);
829 SETTING_TRACE("entry_str:[%s], lenght:%d", entry_str, entry_len);
831 G_FREE(list_item->sub_desc);//release first
832 list_item->sub_desc = (char *)g_strdup(entry_str);
836 static void* editbox_func(void *data, xmlNode *xmlObj)
839 ret_if(!data || !xmlObj);
841 PluginNode* node = (PluginNode*)data;
842 Draw_Data *pd = node->pd;
844 const char *title = (char*)xmlGetProp(xmlObj, "title");
845 const char *key_str= (char*)xmlGetProp(xmlObj, "value");
849 Setting_GenGroupItem_Data *list_item =
850 setting_create_Gendial_field_def(pd->scroller, &(itc_1icon),
852 pd, SWALLOW_Type_LAYOUT_ENTRY,
853 NULL, NULL, 0, title, key_str,
854 __editbox_changed_cb);
856 list_item->userdata = xmlObj;
857 list_item->stop_change_cb = __entry_unfocus_cb;
858 list_item->belongs_to = (int)pd;
865 static void __expanditem_func_sel_cb(void *data, Evas_Object *obj, void *event_info)
869 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
870 Elm_Object_Item *subitem = (Elm_Object_Item *) event_info;
871 Elm_Object_Item *parentItem = elm_genlist_item_parent_get(subitem);
872 elm_genlist_item_selected_set(subitem, 0);
873 Setting_GenGroupItem_Data *data_subItem = elm_object_item_data_get(subitem);
874 Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem); /* parent data */
875 ret_if(NULL == data_subItem || NULL == data_parentItem);
877 elm_radio_value_set(data_subItem->rgd, data_subItem->chk_status);
879 data_parentItem->sub_desc = (char *)g_strdup(_(data_subItem->keyStr));
880 elm_object_item_data_set(data_parentItem->item, data_parentItem);
881 elm_genlist_item_update(data_parentItem->item);
883 xmlNode* xmlObj = data_parentItem->userdata;
887 newattr = xmlSetProp(xmlObj, "string", 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);
906 xmlNode *xmlObj = data_parentItem->userdata;
907 char *value = (char*)xmlGetProp(xmlObj, "string");
909 Evas_Object *rgd = NULL;
911 if (xmlObj->children && !data_parentItem->rgd) {//to protect from entering repeatly
912 xmlNode* cur = xmlObj->children;
914 rgd = elm_radio_add(scroller);
915 elm_radio_value_set(rgd, -1);
919 char *subitem_title = NULL;
920 int subitem_index = 0;
923 while (cur != NULL) {
924 if (!xmlStrcmp(cur->name, (const xmlChar*)"expanditem")) {
925 type = (char*)xmlGetProp(cur, "type");
926 if (0 == safeStrCmp(type, "radio")) {
927 subitem_title = (char*)xmlGetProp(cur, "title");
928 setting_create_Gendial_exp_sub_field(scroller,
929 &(itc_1icon_1text_sub),
930 __expanditem_func_sel_cb, NULL, parentItem,
931 SWALLOW_Type_1RADIO, rgd,
933 subitem_title, NULL);
934 if (0 == safeStrCmp(value, subitem_title)) {
935 sel_idx = subitem_index;
939 SETTING_TRACE("invalid type[:%s]", type);
948 elm_radio_value_set(rgd, sel_idx);
949 data_parentItem->rgd = rgd;//protecting condition
954 static void __expanditem_func_smart_cb(void *data, Evas_Object *obj, void *event_info)
956 ret_if(data == NULL || event_info == NULL);
957 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
958 Setting_GenGroupItem_Data *data_item = elm_object_item_data_get(item);
959 char *cb_type = data;
961 if (0 == safeStrCmp(cb_type, "contracted")) {
962 data_item->rgd = NULL;
963 elm_genlist_item_subitems_clear(item);
968 static void* settings_func(void *data, xmlNode *xmlObj)
974 static void* setting_func(void *data, xmlNode *xmlObj)
978 //----------------------------------------------------------------
979 // [DATA] title, btn[0], btn[1]
980 Draw_Data *pd = data;
981 const char *title = (char*)xmlGetProp(xmlObj, "title");
982 char *btn[2] = {0, };
984 // find child nodes named 'elements'
986 if (xmlObj->children) {
987 xmlNode* cur = xmlObj->children;
991 if (!xmlStrcmp(cur->name, (const xmlChar*)"button")) {
992 btn[i] = xmlGetProp(cur, "title");
993 SETTING_TRACE("------>>> node type : Element, name=%s id=%s / btn[%d] = %s ", cur->name,xmlGetProp(cur, "id"), i, btn[i]);
1000 //----------------------------------------------------------------
1002 pd->ly_main = setting_create_layout_navi_bar_genlist(pd->win_get,
1006 ___click_softkey_back_cb,
1007 ___click_softkey_back_cb, pd, &pd->scroller,
1015 static void* expanditem_func(void *data, xmlNode *xmlObj)
1017 // DO NOTHING - expandlist draws this area
1021 static void* expandlist_func(void *data, xmlNode *xmlObj)
1023 SETTING_TRACE_BEGIN;
1024 ret_if(!data || !xmlObj);
1026 PluginNode* node = (PluginNode*)data;
1027 Draw_Data *pd = node->pd;
1029 const char *key_str = (char*)xmlGetProp(xmlObj, "title");
1030 const char *value = (char*)xmlGetProp(xmlObj, "value"); // string -> value
1032 setting_enable_expandable_genlist(pd->scroller, data, __expanditem_func_exp_cb, __expanditem_func_smart_cb);
1033 Setting_GenGroupItem_Data *list_item =
1034 setting_create_Gendial_exp_parent_field(pd->scroller,
1035 &(itc_2text_3_parent),
1037 SWALLOW_Type_INVALID,
1041 list_item->userdata = xmlObj;
1042 list_item->belongs_to = (int)pd;
1050 static int __node_walker(PluginNode* context, xmlNode* cur)
1052 //SETTING_TRACE_BEGIN;
1053 Draw_Data *pd = context->pd;
1056 xmlNode *cur_node = NULL;
1057 for (cur_node = cur; cur_node;cur_node = cur_node->next) {
1058 if (cur_node->type == XML_ELEMENT_NODE) {
1059 SETTING_TRACE("node type : Element, name=%s id=%s", cur_node->name,xmlGetProp(cur_node, "id"));
1061 drawer_fp fp = __drawer_find(cur_node->name);
1065 void* vret = fp(context, cur_node); // draw it
1069 Setting_GenGroupItem_Data* genlist_node = (Setting_GenGroupItem_Data* )vret;
1070 //SETTING_TRACE("add node to Eina List name : %s, id : ", cur_node->name, xmlGetProp(cur_node, "id"));
1071 // add it to the hash table create before.
1074 char* key_name = xmlGetProp(cur_node, "id");
1075 eina_hash_add(context->ui_list, strdup(key_name),(void*)genlist_node);
1076 //context->ui_list= eina_list_append(context->ui_list, genlist_node);
1080 __node_walker(context, cur_node->children); /* RECURSIVE */
1086 * @param id_str [in] "id"
1087 * @param value [in] value to be udpated
1089 // refer to __expanditem_func_sel_cb
1090 static int __node_finder(PluginNode* context, xmlNode* cur, char* id_str, char* value)
1092 //SETTING_TRACE_BEGIN;
1093 xmlNode *cur_node = NULL;
1094 for (cur_node = cur; cur_node;cur_node = cur_node->next) {
1095 if (cur_node->type == XML_ELEMENT_NODE) {
1097 //SETTING_TRACE("node type : Element, name=%s id=%s", cur_node->name,xmlGetProp(cur_node, "id"));
1098 char* id_name = (char*)xmlGetProp(cur_node, "id");
1099 if ( id_name && 0 == strcmp(id_str, id_name))
1101 SETTING_TRACE("FOUND >>>> %s", id_name);
1102 // cur_node - update xml code
1103 xmlAttrPtr newattr = xmlSetProp(cur_node, "value", value);
1105 //-----------------------------------------------------------
1108 if ( 0 == strcmp (cur_node->name, "integer"))
1110 SETTING_TRACE(">>>>> UPDATE SLIDER CONTROL %x --- %s ",context->ui_list, id_name);
1111 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1114 item_to_update->chk_status = atoi(value);
1115 SETTING_TRACE(">>> o-------------0 SLIDER VALUE = %d ", item_to_update->chk_status);
1117 elm_object_item_data_set(item_to_update->item, item_to_update);
1118 elm_genlist_item_update(item_to_update->item);
1120 SETTING_TRACE("item_to_update is NULL");
1124 if ( 0 == strcmp (cur_node->name, "bool"))
1126 SETTING_TRACE(">>>>> UPDATE TOGGLE CONTROL %x --- %s ",context->ui_list, id_name);
1127 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1130 item_to_update->chk_status = atoi(value);
1131 SETTING_TRACE(">>> o-------------0 TOGGLE VALUE = %d ", item_to_update->chk_status);
1133 elm_object_item_data_set(item_to_update->item, item_to_update);
1134 elm_genlist_item_update(item_to_update->item);
1136 SETTING_TRACE("item_to_update is NULL");
1139 // case : edit control
1140 if ( 0 == strcmp (cur_node->name, "string"))
1142 SETTING_TRACE(">>>>> UPDATE EDIT CONTROL CONTROL %x --- %s ",context->ui_list, id_name);
1143 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1146 char* old_string = item_to_update->sub_desc;
1147 item_to_update->sub_desc = strdup(value);
1148 SETTING_TRACE(">>> o-------------0 STRING VALUE = %s ", value);
1152 elm_object_item_data_set(item_to_update->item, item_to_update);
1153 elm_genlist_item_update(item_to_update->item);
1155 SETTING_TRACE("item_to_update is NULL");
1158 // case : expand list
1164 //-----------------------------------------------------------
1165 if ( 0 == strcmp (cur_node->name, "expandlist"))
1167 SETTING_TRACE(">>>>> UPDATE EXPAND LIST CONTROL %x --- %s ",context->ui_list, id_name);
1168 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1171 char* old_string = item_to_update->sub_desc;
1172 item_to_update->sub_desc = strdup(value);
1173 SETTING_TRACE(">>> o-------------0 EXPAND LIST VALUE = %s ", value);
1176 elm_object_item_data_set(item_to_update->item, item_to_update);
1177 elm_genlist_item_update(item_to_update->item);
1179 SETTING_TRACE("item_to_update is NULL");
1184 __node_finder(context, cur_node->children, id_str, value); /* RECURSIVE */
1189 static unsigned int _plugin_string_key_length(const char*key)
1194 return (int)strlen(key) + 1;
1197 static int _plugin_string_key_cmp(const char* key1, int key1_length,
1198 const char* key2, int key2_length)
1200 return strcmp(key1, key2);
1203 static void _plugin_entry_free_cb(void* data)
1209 //static PluginNode* g_context;
1211 PluginNode* setting_plugin_create()
1213 PluginNode *node = calloc(1, sizeof(PluginNode));
1215 Draw_Data *pd = calloc(1, sizeof(Draw_Data));
1216 setting_retvm_if(!pd, -1, "Create Draw_Data obj failed");
1220 node->ui_list = eina_hash_new(EINA_KEY_LENGTH(_plugin_string_key_length),
1221 EINA_KEY_CMP(_plugin_string_key_cmp),
1222 EINA_KEY_HASH(eina_hash_superfast),
1223 _plugin_entry_free_cb,
1229 void setting_plugin_destroy(PluginNode* node)
1231 SETTING_TRACE_BEGIN;
1233 SETTING_TRACE("node is NOT NULL")
1235 SETTING_TRACE("node->pd is NOT NULL")
1236 if(node->pd->doc != NULL) {
1237 xmlSaveFormatFile(node->plugin_path, node->pd->doc, 1);
1238 // TODO: make sure this is right
1239 xmlFreeDoc(node->pd->doc);
1240 node->pd->doc = NULL;
1241 SETTING_TRACE("__cfg_file_write successful");
1244 SETTING_TRACE("before freeing node->pd");
1247 SETTING_TRACE("after freeing node->pd");
1250 SETTING_TRACE("before freeing ui_list");
1251 if (node->ui_list) {
1252 eina_hash_free(node->ui_list);
1253 node->ui_list = NULL;
1255 SETTING_TRACE("after freeing ui_list");
1257 SETTING_TRACE("before freeing node");
1260 SETTING_TRACE("after freeing node");
1265 static Eina_Bool _plugin_foreach_cb(const Eina_Hash *hash, const void*key, void* data, void* fdata)
1267 Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) data;
1268 SETTING_TRACE("%s --- %s ", (char*)key, node->keyStr);
1274 void setting_plugin_debug(PluginNode* context)
1276 SETTING_TRACE("HASH TABLE -------------------------------------");
1277 eina_hash_foreach(context->ui_list,_plugin_foreach_cb, NULL);
1278 SETTING_TRACE("HASH TABLE -------------------------------------");
1282 void setting_plugin_update(PluginNode* context)
1284 Eina_List *li = context->ui_list;
1287 Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) eina_list_data_get(li);
1289 // SETTING_TRACE(" ---> keyStr : %s , swallow type : %d ", node->keyStr, node->swallow_type);
1290 Setting_GenGroupItem_Data* item_to_update = NULL;
1291 item_to_update = node;
1292 elm_object_item_data_set(item_to_update->item, item_to_update);
1293 elm_genlist_item_update(item_to_update->item);
1295 li = eina_list_next(li);
1300 bool setting_plugin_load(PluginNode* context, const char *cfg_file)
1302 SETTING_TRACE("cfg_file:%s", cfg_file)
1303 if (isEmptyStr(cfg_file) || 0 != access(cfg_file, R_OK|W_OK|F_OK ))
1305 SETTING_TRACE_ERROR(" error occured : access \n");
1308 context->pd->cfg_file = cfg_file;
1309 context->pd->win_get = (Evas_Object *) ug_get_window();
1311 GError *error = NULL;
1313 context->pd->doc = xmlParseFile(cfg_file);
1314 context->pd->root = xmlDocGetRootElement(context->pd->doc);
1316 // TODO: error handler here
1317 __node_walker(context, context->pd->root);
1320 setting_plugin_debug(context);