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()
150 /* <navigationbar> */__drawer_add("navigationbar", navigationbar_func);
152 /* <bool> */__drawer_add("bool", checkbox_func);
153 /* <string> */__drawer_add("string", editbox_func);
154 /* <group> */__drawer_add("group", group_func);
155 /* <integer> */__drawer_add("integer", slider_func);
156 /* <label> */__drawer_add("label", label_func);
157 /* <link> */__drawer_add("link", link_func);
158 /* <launch> */__drawer_add("launch", launch_func);
159 /* <extendlist> */__drawer_add("expandlist", expandlist_func);
160 /* <extenditem> */__drawer_add("expanditem", expanditem_func);
161 /* <settings> */__drawer_add("settings", settings_func);
162 /* <setting> */__drawer_add("setting", setting_func);
165 void setting_drawer_list_fini()
169 Object_Drawer *node = NULL;
170 Eina_List *li = _g_drawer_list;
172 node = (Object_Drawer *) eina_list_data_get(li);
175 //SETTING_TRACE("Deregister %s", node->type);
178 li = eina_list_next(li);
180 _g_drawer_list = eina_list_free(_g_drawer_list);
181 _g_drawer_list = NULL;
185 /////////////////////////
186 /////////////////////////
187 /////////////////////////
189 #define MAX_CONTENT_LEN 512
190 #define MAX_LOCAL_BUFSIZE 128
191 #define DBUS_PATH "/setting/dbus_handler"
192 #define DBUS_SIGNAL_INTERFACE "org.tizen.setting.signal"
193 #define DBUS_SIGNAL "test"
195 static char* substring(const char* str, size_t begin, size_t len)
197 if (str == 0 || strlen(str) == 0 || strlen(str) < begin || strlen(str) < (begin+len))
200 return strndup(str + begin, len);
203 //------------------------------------------------------
205 static DBusConnection *bus;
206 //------------------------------------------------------
207 static DBusHandlerResult __signal_filter(DBusConnection* conn, DBusMessage* message, void* user_data)
209 int my_pid = getpid();
215 dbus_error_init(&error);
217 setting_main_appdata *ad = user_data;
219 if (dbus_message_is_signal(message, DBUS_SIGNAL_INTERFACE, DBUS_SIGNAL))
221 if (dbus_message_get_args(message, &error,
222 DBUS_TYPE_UINT32, &sender_pid,
223 DBUS_TYPE_STRING, &key,
224 DBUS_TYPE_STRING, &value,
225 DBUS_TYPE_INVALID) == FALSE)
227 SETTING_TRACE_ERROR("Fail to get data : %s", error.message);
228 dbus_error_free(&error);
229 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
233 if (sender_pid != 0 && my_pid != sender_pid)
235 SETTING_TRACE("received key : %s , value : %s", key, value);
236 //-------------------------------------------------------------
237 // received key : checkbox1|N/A , value : INT|1
238 //-------------------------------------------------------------
239 //char* key = "checkbox1|N/A";
240 char* ptr = strchr(key, '|');
242 xmlDocPtr doc = NULL;
245 //parsing for : checkbox1|N/A -> checkbox1
246 char* key_name = substring(key, 0, strlen(key)-strlen(ptr));
247 char* val_name = strchr(value, '|');
252 doc = xmlParseFile(ad->plugin_path);
254 xmlNode *root = xmlDocGetRootElement(doc);
257 __node_finder((PluginNode*)ad->plugin_node, root, key_name ,val_name, &is_end);
260 GError *error = NULL;
265 xmlSaveFormatFile(ad->plugin_path, doc, 1);
266 // TODO: make sure this is right
269 SETTING_TRACE("__cfg_file_write successful");
276 return DBUS_HANDLER_RESULT_HANDLED;
279 static int __send_msg(char* key, char* value)
281 DBusMessage* message;
282 int sender_pid = getpid();
287 message = dbus_message_new_signal(DBUS_PATH, DBUS_SIGNAL_INTERFACE, DBUS_SIGNAL);
289 SETTING_TRACE("Sending message[%s:%s] via dbus", key ,value);
290 if (dbus_message_append_args(message,
291 DBUS_TYPE_UINT32, &sender_pid,
292 DBUS_TYPE_STRING, &key,
293 DBUS_TYPE_STRING, &value,
294 DBUS_TYPE_INVALID) == FALSE)
296 SETTING_TRACE("Fail to load data error");
300 if (dbus_connection_send(bus, message, NULL) == FALSE)
302 SETTING_TRACE("Fail to send message");
306 dbus_connection_flush(bus);
307 dbus_message_unref(message);
309 SETTING_TRACE("[CLIENT] send data signal done");
315 static void __send_int_msg(xmlNode* xmlObj, int val)
317 const char *id = (char*)xmlGetProp(xmlObj, "id");
318 const char *title = (char*)xmlGetProp(xmlObj, "title");
319 char key[MAX_CONTENT_LEN] = {0,};
320 snprintf(key, sizeof(key), "%s|%s", id, title);
322 char value[MAX_CONTENT_LEN] = {0,};
323 snprintf(value, sizeof(value), "INT|%d", val);
324 __send_msg(key, value);
328 static void __send_string_msg(xmlNode* xmlObj, char *string)
330 const char *id = (char*)xmlGetProp(xmlObj, "id");
331 const char *title = (char*)xmlGetProp(xmlObj, "title");
332 char key[MAX_CONTENT_LEN] = {0,};
333 snprintf(key, sizeof(key), "%s|%s", id, title);
335 char value[MAX_CONTENT_LEN] = {0,};
336 snprintf(value, sizeof(value), "STRING|%s", string);
337 __send_msg(key, value);
341 int setting_dbus_handler_init(void* user_data)
345 char rule[MAX_LOCAL_BUFSIZE];
347 dbus_error_init(&error);
348 bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
351 SETTING_TRACE("Fail to connect to the D-BUS daemon: %s", error.message);
352 dbus_error_free(&error);
356 dbus_connection_setup_with_g_main(bus, NULL);
357 snprintf(rule, MAX_LOCAL_BUFSIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH, DBUS_SIGNAL_INTERFACE);
359 dbus_bus_add_match(bus, rule, &error);
360 if (dbus_error_is_set(&error))
362 SETTING_TRACE("Fail to rule set; %s", error.message);
363 dbus_error_free(&error);
367 if (dbus_connection_add_filter(bus, __signal_filter, user_data, NULL) == FALSE)
372 SETTING_TRACE("app signal initialized");
378 int setting_dbus_handler_fini(void)
381 char rule[MAX_LOCAL_BUFSIZE];
383 dbus_error_init(&error);
384 dbus_connection_remove_filter(bus, __signal_filter, NULL);
385 snprintf(rule, MAX_LOCAL_BUFSIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH, DBUS_SIGNAL_INTERFACE);
386 dbus_bus_remove_match(bus, rule, &error);
388 if (dbus_error_is_set(&error))
390 SETTING_TRACE("Fail to rule unset: %s", error.message);
391 dbus_error_free(&error);
395 dbus_connection_close(bus);
396 SETTING_TRACE("app signal finalized");
400 /////////////////////////////
401 /////////////////////////////
402 /////////////////////////////
404 Elm_Genlist_Item_Class itc_layout;
407 static int __cfg_file_write(Draw_Data *pd)
411 GError *error = NULL;
414 xmlSaveFormatFile(pd->cfg_file, pd->doc, 1);
415 //xmlFreeDoc(pd->doc);
417 SETTING_TRACE("__cfg_file_write successful");
424 static void ___click_softkey_back_cb(void *data, Evas_Object *obj,
430 PluginNode* node = (PluginNode*)data;
431 Draw_Data *pd = node->pd;
433 evas_object_del(pd->ly_main);
437 setting_plugin_destroy(node);
447 static void* group_func(void *data, xmlNode *xmlObj)
450 ret_if(!data || !xmlObj);
452 PluginNode* node = (PluginNode*)data;
453 Draw_Data *pd = node->pd;
455 // original code is non-recursive
457 const char *title = (char*)json_object_get_string_member(jsonObj, "title");
458 (void)setting_create_Gendial_field_titleItem(pd->scroller,
462 // non recursive method
463 if (json_object_has_member(jsonObj, "elements"))
465 JsonNode* elements_node = json_object_get_member(jsonObj, "elements");
469 for (i=0; i < json_array_get_length(json_node_get_array(elements_node)); i++)
471 tempobj = json_array_get_object_element(json_node_get_array(elements_node), i);
472 type = (char*)json_object_get_string_member(tempobj, "type");
473 drawer_fp fp = __drawer_find(type);
474 if (fp) fp(pd, tempobj); // draw it
478 // new code is recursive
479 const char *title = (char*)xmlGetProp(xmlObj, "title");
480 SETTING_TRACE (" >>> GROUP NAME : %s \n", title);
481 (void)setting_create_Gendial_field_titleItem(pd->scroller, &(itc_group_item), title, NULL);
488 static void* __link_list_cb(void *data, Evas_Object *obj, void *event_info)
491 ret_if(data == NULL);
492 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
493 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
494 elm_genlist_item_selected_set(item, 0);
495 Setting_GenGroupItem_Data *list_item =
496 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
498 xmlNode* xmlObj = data;
500 const char *link_file = (char*)xmlGetProp(xmlObj, "value");
504 SETTING_TRACE_ERROR("Invalidate liked file");
507 char file[1024] = {0,};
508 snprintf(file, sizeof(file), "%s/%s", PLUGIN_CFG_DIR, link_file);
509 SETTING_TRACE("file:%s", file);
511 PluginNode* plugin_node = setting_plugin_create();
512 setting_plugin_load(plugin_node, (const char *)file);
514 //setting_plugin_load(NULL, file);
519 static void* __launch_list_cb(void *data, Evas_Object *obj, void *event_info)
522 ret_if(data == NULL);
523 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
524 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
525 elm_genlist_item_selected_set(item, 0);
526 Setting_GenGroupItem_Data *list_item =
527 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
529 xmlNode* xmlObj = data;
531 const char *key_str = (char*)xmlGetProp(xmlObj, "id");
532 const char *title_str = (char*)xmlGetProp(xmlObj, "title");
533 const char *appid_str = (char*)xmlGetProp(xmlObj, "appid");
534 const char *operation_str = (char*)xmlGetProp(xmlObj, "operation");
537 service_h svc = NULL;
538 service_create(&svc);
539 service_set_app_id(svc, appid_str); // xml property – appid
540 service_set_operation(svc, operation_str); // property : operation
541 service_send_launch_request(svc, NULL, NULL);
542 service_destroy(svc);
547 static void* label_func(void *data, xmlNode *xmlObj)
550 ret_if(!data || !xmlObj);
551 PluginNode* node = (PluginNode*)data;
552 Draw_Data *pd = node->pd;
554 const char *title = (char*)xmlGetProp(xmlObj, "title");
556 Setting_GenGroupItem_Data *obj =
557 setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
559 xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
560 0, title, NULL, NULL);
565 static void* link_func(void *data, xmlNode *xmlObj)
568 ret_if(!data || !xmlObj);
569 PluginNode* node = (PluginNode*)data;
570 Draw_Data *pd = node->pd;
572 const char *key_str = (char*)xmlGetProp(xmlObj, "id");
573 Setting_GenGroupItem_Data * obj =
574 setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
576 xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
577 0, key_str, NULL, NULL);
582 static void* launch_func(void *data, xmlNode *xmlObj)
585 ret_if(!data || !xmlObj);
586 PluginNode* node = (PluginNode*)data;
587 Draw_Data *pd = node->pd;
589 const char *title_str = (char*)xmlGetProp(xmlObj, "title");
591 Setting_GenGroupItem_Data * obj =
592 setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
594 xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
595 0, title_str, NULL, NULL);
600 static void __slider_stop_cb(void *data, Evas_Object *obj,
603 ret_if(data == NULL || obj == NULL);
604 double val = elm_slider_value_get(obj);
605 SETTING_TRACE("val = %f", val);
606 Setting_GenGroupItem_Data *list_item = data;
607 ret_if(list_item->userdata == NULL);
609 xmlNode* xmlObj = list_item->userdata;
612 //apply the vconf changes after stopping moving slider..
613 list_item->chk_status = (int)(val + 0.5);
614 elm_slider_value_set(obj, list_item->chk_status);
616 SETTING_TRACE(" slider after ---> val = %d", (int) list_item->chk_status);
618 // int -> double -> xmlChar*
621 sprintf(buf, "%d", (int) list_item->chk_status);
622 newattr = xmlSetProp(xmlObj, "value", buf);
624 __send_int_msg(xmlObj, list_item->chk_status);
625 __cfg_file_write((Draw_Data *)list_item->belongs_to);
629 static void* slider_func(void *data, xmlNode *xmlObj)
632 ret_if(!data || !xmlObj);
633 PluginNode* node = (PluginNode*)data;
634 Draw_Data *pd = node->pd;
637 const char *title = (char*)xmlGetProp(xmlObj, "title");
639 SETTING_TRACE (" >>> [slider input] min=%s max=%s value=%s ",(char*)xmlGetProp(xmlObj, "min"), (char*)xmlGetProp(xmlObj, "max"), (char*)xmlGetProp(xmlObj, "value"));
641 int value = atoi((char*)xmlGetProp(xmlObj, "value"));
642 int min = atoi((char*)xmlGetProp(xmlObj, "min"));
643 int max = atoi((char*)xmlGetProp(xmlObj, "max"));
645 SETTING_TRACE ("[slider input] min=%d max=%d value=%d ", min, max, value);
647 setting_create_Gendial_itc("dialogue/1text.1icon.5", &(itc_layout));
648 Setting_GenGroupItem_Data *list_item =
649 setting_create_Gendial_field_def(pd->scroller, &(itc_layout), NULL,
651 SWALLOW_Type_LAYOUT_SLIDER,
652 IMG_SENSITIVITY_ICON_01,
653 IMG_SENSITIVITY_ICON_02, value,
656 list_item->win_main = NULL;
657 list_item->evas = NULL;
658 list_item->isIndicatorVisible = true;
659 list_item->slider_min = min;
660 list_item->slider_max = max;
661 list_item->userdata = xmlObj;
662 list_item->stop_change_cb = __slider_stop_cb;
663 list_item->belongs_to = (int)pd;
666 g_list_item = list_item;
668 return (void*)list_item;
672 elm_object_item_data_set(item_to_update->item, item_to_update);
673 elm_genlist_item_update(item_to_update->item);
675 static void* navigationbar_func(void *data, xmlNode *xmlObj)
679 ret_if(!data || !xmlObj);
681 PluginNode* node = (PluginNode*)data;
682 Draw_Data *pd = node->pd;
684 //----------------------------------------------------------------
685 // [DATA] title, btn[0], btn[1]
686 const char *title = (char*)xmlGetProp(xmlObj, "title");
687 char *btn[2] = {0, };
689 // find child nodes named 'elements'
690 if (xmlObj->children) {
691 xmlNode* cur = xmlObj->children;
695 if (!xmlStrcmp(cur->name, (const xmlChar*)"button")) {
696 btn[i] = xmlGetProp(cur, "title");
697 SETTING_TRACE("------>>> node type : Element, name=%s id=%s / btn[%d] = %s ",
698 cur->name,xmlGetProp(cur, "id"),
706 //----------------------------------------------------------------
708 pd->ly_main = setting_create_layout_navi_bar_genlist(pd->win_get,
711 _(btn[1]), _(btn[0]),
712 ___click_softkey_back_cb,
713 ___click_softkey_back_cb, data, &pd->scroller,
721 static void __check_mouse_up_cb(void *data, Evas_Object *obj,
726 setting_retm_if(data == NULL, "Data parameter is NULL");
728 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
729 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
730 elm_genlist_item_selected_set(item, 0);
731 Setting_GenGroupItem_Data *list_item =
732 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
734 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
736 int old_status = elm_check_state_get(list_item->eo_check);
737 list_item->chk_status = !old_status;
738 elm_check_state_set(list_item->eo_check, list_item->chk_status);
740 xmlNode *xmlObj = data;
742 newattr = xmlSetProp(xmlObj, "state", xmlXPathCastNumberToString(list_item->chk_status));
744 __send_int_msg(xmlObj, list_item->chk_status);
745 __cfg_file_write((Draw_Data *)list_item->belongs_to);
749 static void __chk_btn_cb(void *data, Evas_Object *obj,
754 retm_if(data == NULL, "Data parameter is NULL");
755 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
757 xmlNode* xmlObj = list_item->userdata;
759 list_item->chk_status = elm_check_state_get(obj); /* for genlist update status */
762 if (list_item->chk_status == 1) {
763 newattr = xmlSetProp(xmlObj, "value", "true");
764 } else if (list_item->chk_status == 0) {
765 newattr = xmlSetProp(xmlObj, "value", "false");
767 newattr = xmlSetProp(xmlObj, "value", "false");
770 const char *id = (char*)xmlGetProp(xmlObj, "id");
771 const char *title = (char*)xmlGetProp(xmlObj, "title");
772 //SETTING_TRACE(" >>>> id:%s , title:%s", id, title);
773 __send_int_msg(xmlObj, list_item->chk_status);
774 __cfg_file_write((Draw_Data *)list_item->belongs_to);
779 static void* checkbox_func(void *data, xmlNode *xmlObj)
782 ret_if(!data || !xmlObj);
784 PluginNode* node = (PluginNode*)data;
785 Draw_Data *pd = node->pd;
787 // [DATA] title, value
788 const char *title = (char*)xmlGetProp(xmlObj, "title");
791 char* value = (char*)xmlGetProp(xmlObj, "value");
795 if ( 0 == safeStrCmp(value, "true")) {
797 } else if ( 0 == safeStrCmp(value, "false")) {
800 ival = 0; // default : false (0)
803 // title, value, xmlObj
804 Setting_GenGroupItem_Data *list_item =
805 setting_create_Gendial_field_def(pd->scroller,
809 SWALLOW_Type_1TOGGLE,
816 list_item->userdata = xmlObj;
817 list_item->belongs_to = (int) pd;
818 SETTING_TRACE("pd:%p,list_item->belongs_to:%d", pd, list_item->belongs_to);
825 static void __entry_unfocus_cb(void *data, Evas_Object *obj, void *event_info)
828 retm_if(!data || !obj, "Data parameter is NULL");
830 setting_hide_input_pannel_cb(obj);
831 const char *entry_str = elm_entry_entry_get(obj);
832 char *entry_str_utf8 = NULL;
833 entry_str_utf8 = elm_entry_markup_to_utf8(entry_str);
835 Setting_GenGroupItem_Data *list_item = data;
837 xmlNode* xmlObj = list_item->userdata;
840 const char *title = (char*)xmlSetProp(xmlObj, "value",entry_str_utf8);
842 __send_string_msg(xmlObj, entry_str_utf8);
843 __cfg_file_write((Draw_Data *)list_item->belongs_to);
845 FREE(entry_str_utf8);
849 static void __editbox_list_cb(void *data, Evas_Object *obj,
855 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
856 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
857 elm_genlist_item_selected_set(item, 0);
858 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
860 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
861 if (!elm_object_focus_get(list_item->eo_check)) {
862 elm_object_focus_set(list_item->eo_check, EINA_TRUE);
865 Ecore_IMF_Context *imf_context = (Ecore_IMF_Context *)elm_entry_imf_context_get(list_item->eo_check);
866 setting_retm_if(imf_context == NULL, "imf_context is NULL");
867 ecore_imf_context_input_panel_show(imf_context);
871 static void __editbox_changed_cb(void *data, Evas_Object *obj,
875 retm_if(!data || !obj, "Data parameter is NULL");
876 retm_if(!elm_object_focus_get(obj), "Entry is not focused");
878 Setting_GenGroupItem_Data *list_item =
879 (Setting_GenGroupItem_Data *) data;
881 const char *entry_str = elm_entry_entry_get(obj);
882 int entry_len = safeStrLen(entry_str);
883 SETTING_TRACE("entry_str:[%s], lenght:%d", entry_str, entry_len);
885 G_FREE(list_item->sub_desc);//release first
886 list_item->sub_desc = (char *)g_strdup(entry_str);
890 static void* editbox_func(void *data, xmlNode *xmlObj)
893 ret_if(!data || !xmlObj);
895 PluginNode* node = (PluginNode*)data;
896 Draw_Data *pd = node->pd;
898 const char *title = (char*)xmlGetProp(xmlObj, "title");
899 const char *key_str= (char*)xmlGetProp(xmlObj, "value");
903 Setting_GenGroupItem_Data *list_item =
904 setting_create_Gendial_field_def(pd->scroller, &(itc_1icon),
906 pd, SWALLOW_Type_LAYOUT_ENTRY,
907 NULL, NULL, 0, title, key_str,
908 __editbox_changed_cb);
910 list_item->userdata = xmlObj;
911 list_item->stop_change_cb = __entry_unfocus_cb;
912 list_item->belongs_to = (int)pd;
919 static void __expanditem_func_sel_cb(void *data, Evas_Object *obj, void *event_info)
923 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
924 Elm_Object_Item *subitem = (Elm_Object_Item *) event_info;
925 Elm_Object_Item *parentItem = elm_genlist_item_parent_get(subitem);
926 elm_genlist_item_selected_set(subitem, 0);
927 Setting_GenGroupItem_Data *data_subItem = elm_object_item_data_get(subitem);
928 Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem); /* parent data */
929 ret_if(NULL == data_subItem || NULL == data_parentItem);
931 elm_radio_value_set(data_subItem->rgd, data_subItem->chk_status);
933 data_parentItem->sub_desc = (char *)g_strdup(_(data_subItem->keyStr));
934 elm_object_item_data_set(data_parentItem->item, data_parentItem);
935 elm_genlist_item_update(data_parentItem->item);
937 xmlNode* xmlObj = data_parentItem->userdata;
941 //newattr = xmlSetProp(xmlObj, "string", data_parentItem->sub_desc);
942 newattr = xmlSetProp(xmlObj, "value", data_parentItem->sub_desc);
944 __send_string_msg(xmlObj, data_parentItem->sub_desc);
945 __cfg_file_write((Draw_Data *)data_parentItem->belongs_to);
949 static void __expanditem_func_exp_cb(void *data, Evas_Object *obj, void *event_info)
951 ret_if(NULL == data || NULL == event_info);
954 PluginNode* node = (PluginNode*)data;
955 Draw_Data *pd = node->pd;
957 Elm_Object_Item *parentItem = event_info; /* parent item */
958 Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem); /* parent data */
959 Evas_Object *scroller = elm_object_item_widget_get(parentItem);
962 xmlNode *xmlObj = data_parentItem->userdata;
963 //char *value = (char*)xmlGetProp(xmlObj, "string");
964 char *value = (char*)xmlGetProp(xmlObj, "value");
965 SETTING_TRACE(">>> value = %s", value);
967 Evas_Object *rgd = NULL;
969 if (xmlObj->children && !data_parentItem->rgd) {//to protect from entering repeatly
970 xmlNode* cur = xmlObj->children;
972 rgd = elm_radio_add(scroller);
973 elm_radio_value_set(rgd, -1);
977 char *subitem_title = NULL;
978 int subitem_index = 0;
981 while (cur != NULL) {
982 if (!xmlStrcmp(cur->name, (const xmlChar*)"expanditem")) {
983 type = (char*)xmlGetProp(cur, "type");
984 if (0 == safeStrCmp(type, "radio")) {
985 subitem_title = (char*)xmlGetProp(cur, "title");
986 Setting_GenGroupItem_Data *list_item =
987 setting_create_Gendial_exp_sub_field(scroller,
988 &(itc_1icon_1text_sub),
989 __expanditem_func_sel_cb, NULL, parentItem,
990 SWALLOW_Type_1RADIO, rgd,
992 subitem_title, NULL);
994 // SETTING_TRACE(">>> value = %s, subitem_title = %s ", value, subitem_title);
996 if (0 == safeStrCmp(value, subitem_title)) {
997 sel_idx = subitem_index;
998 SETTING_TRACE("%d is selected in Radio Group", sel_idx);
1000 data_parentItem->childs = eina_list_append(data_parentItem->childs, list_item);
1004 SETTING_TRACE("invalid type[:%s]", type);
1013 elm_radio_value_set(rgd, sel_idx);
1014 data_parentItem->rgd = rgd;//protecting condition
1019 static void __expanditem_func_smart_cb(void *data, Evas_Object *obj, void *event_info)
1021 ret_if(data == NULL || event_info == NULL);
1022 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
1023 Setting_GenGroupItem_Data *data_item = elm_object_item_data_get(item);
1024 char *cb_type = data;
1026 if (0 == safeStrCmp(cb_type, "contracted")) {
1027 data_item->rgd = NULL;
1028 elm_genlist_item_subitems_clear(item);
1033 static void* settings_func(void *data, xmlNode *xmlObj)
1039 static void* setting_func(void *data, xmlNode *xmlObj)
1041 SETTING_TRACE_BEGIN;
1042 ret_if(!data || !xmlObj);
1045 //Draw_Data *pd = node->pd;
1046 PluginNode* node = (PluginNode*)data;
1047 Draw_Data *pd = node->pd;
1049 //----------------------------------------------------------------
1050 // [DATA] title, btn[0], btn[1]
1051 const char *title = (char*)xmlGetProp(xmlObj, "title");
1052 char *btn[2] = {/* 0 */"OK", /* 1 */"NO"};
1054 // find child nodes named 'elements'
1056 if (xmlObj->children) {
1057 xmlNode* cur = xmlObj->children;
1061 if (!xmlStrcmp(cur->name, (const xmlChar*)"button")) {
1062 btn[i] = xmlGetProp(cur, "title");
1063 SETTING_TRACE("------>>> node type : Element, name=%s id=%s / btn[%d] = %s ",
1064 cur->name,xmlGetProp(cur, "id"),
1073 //----------------------------------------------------------------
1074 SETTING_TRACE("before setting_create_layout_navi_bar_genlist");
1076 pd->ly_main = setting_create_layout_navi_bar_genlist(pd->win_get,
1079 _(btn[1]), _(btn[0]),
1080 ___click_softkey_back_cb,
1081 ___click_softkey_back_cb, data, &pd->scroller,
1083 SETTING_TRACE("after setting_create_layout_navi_bar_genlist");
1090 static void* expanditem_func(void *data, xmlNode *xmlObj)
1092 // DO NOTHING - expandlist draws this area
1096 static void* expandlist_func(void *data, xmlNode *xmlObj)
1098 SETTING_TRACE_BEGIN;
1099 ret_if(!data || !xmlObj);
1101 PluginNode* node = (PluginNode*)data;
1102 Draw_Data *pd = node->pd;
1104 const char *key_str = (char*)xmlGetProp(xmlObj, "title");
1105 const char *value = (char*)xmlGetProp(xmlObj, "value"); // string -> value
1107 setting_enable_expandable_genlist(pd->scroller, data, __expanditem_func_exp_cb, __expanditem_func_smart_cb);
1108 Setting_GenGroupItem_Data *list_item =
1109 setting_create_Gendial_exp_parent_field(pd->scroller,
1110 &(itc_2text_3_parent),
1112 SWALLOW_Type_INVALID,
1116 list_item->userdata = xmlObj;
1117 list_item->belongs_to = (int)pd;
1125 static int __node_walker(PluginNode* context, xmlNode* cur)
1127 //SETTING_TRACE_BEGIN;
1128 Draw_Data *pd = context->pd;
1131 xmlNode *cur_node = NULL;
1132 for (cur_node = cur; cur_node;cur_node = cur_node->next) {
1133 if (cur_node->type == XML_ELEMENT_NODE) {
1134 SETTING_TRACE("node type : Element, name=%s id=%s", cur_node->name,xmlGetProp(cur_node, "id"));
1136 drawer_fp fp = __drawer_find(cur_node->name);
1140 void* vret = fp(context, cur_node); // draw it
1144 Setting_GenGroupItem_Data* genlist_node = (Setting_GenGroupItem_Data* )vret;
1145 //SETTING_TRACE("add node to Eina List name : %s, id : ", cur_node->name, xmlGetProp(cur_node, "id"));
1146 // add it to the hash table create before.
1149 char* key_name = xmlGetProp(cur_node, "id");
1150 eina_hash_add(context->ui_list, strdup(key_name),(void*)genlist_node);
1154 __node_walker(context, cur_node->children); /* RECURSIVE */
1160 * @param id_str [in] "id"
1161 * @param value [in] value to be udpated
1162 * @see __expanditem_func_sel_cb
1164 static int __node_finder(PluginNode* context, xmlNode* cur, char* id_str, char* value, bool* is_end)
1166 SETTING_TRACE_BEGIN;
1167 xmlNode *cur_node = NULL;
1169 if (*is_end == true) return 0;
1171 for (cur_node = cur; cur_node;cur_node = cur_node->next) {
1172 if (cur_node->type == XML_ELEMENT_NODE) {
1174 char* id_name = (char*)xmlGetProp(cur_node, "id");
1175 if ( id_name && 0 == strcmp(id_str, id_name))
1177 SETTING_TRACE("FOUND >>>> %s", id_name);
1178 // cur_node - update xml code
1179 xmlAttrPtr newattr = xmlSetProp(cur_node, "value", value);
1181 //-----------------------------------------------------------
1184 if ( 0 == strcmp (cur_node->name, "integer"))
1186 SETTING_TRACE(">>>>> UPDATE SLIDER 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 SLIDER 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");
1200 if ( 0 == strcmp (cur_node->name, "bool"))
1202 SETTING_TRACE(">>>>> UPDATE TOGGLE 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 item_to_update->chk_status = atoi(value);
1207 SETTING_TRACE(">>> o-------------0 TOGGLE VALUE = %d ", item_to_update->chk_status);
1209 elm_object_item_data_set(item_to_update->item, item_to_update);
1210 elm_genlist_item_update(item_to_update->item);
1212 SETTING_TRACE("item_to_update is NULL");
1215 // case : edit control
1216 if ( 0 == strcmp (cur_node->name, "string"))
1218 SETTING_TRACE(">>>>> UPDATE EDIT CONTROL CONTROL %x --- %s ",context->ui_list, id_name);
1219 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1222 char* old_string = item_to_update->sub_desc;
1223 item_to_update->sub_desc = strdup(value);
1224 SETTING_TRACE(">>> o-------------0 STRING VALUE = %s ", value);
1228 elm_object_item_data_set(item_to_update->item, item_to_update);
1229 elm_genlist_item_update(item_to_update->item);
1232 SETTING_TRACE("item_to_update is NULL");
1235 // case : expand list
1241 //-----------------------------------------------------------
1242 if ( 0 == strcmp (cur_node->name, "expandlist"))
1244 SETTING_TRACE(">>>>> UPDATE EXPAND LIST CONTROL %x --- %s ",context->ui_list, id_name);
1245 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1248 char* old_string = item_to_update->sub_desc;
1249 item_to_update->sub_desc = strdup(value);
1250 SETTING_TRACE(">>> o-------------0 EXPAND LIST VALUE = %s ", value);
1254 elm_object_item_data_set(item_to_update->item, item_to_update);
1255 elm_genlist_item_update(item_to_update->item);
1257 // TODO: need to update child elements
1258 // item_to_update->childs ---> expanded list
1259 if (item_to_update->childs)
1261 Eina_List *li = item_to_update->childs;
1262 int radio_index = 0;
1265 Setting_GenGroupItem_Data* node = eina_list_data_get(li);
1266 // do something more
1267 // SETTING_TRACE(">>> RADIO LIST STRING VALUE = %s ", node->keyStr);
1268 // set position of radio button
1269 if (strcmp(node->keyStr, value) == 0)
1271 elm_radio_value_set(node->rgd, radio_index);
1273 elm_object_item_data_set(item_to_update->item, item_to_update);
1274 elm_genlist_item_update(item_to_update->item);
1277 li = eina_list_next(li);
1283 SETTING_TRACE("item_to_update is NULL");
1290 __node_finder(context, cur_node->children, id_str, value, is_end); /* RECURSIVE */
1295 static unsigned int _plugin_string_key_length(const char*key)
1300 return (int)strlen(key) + 1;
1303 static int _plugin_string_key_cmp(const char* key1, int key1_length,
1304 const char* key2, int key2_length)
1306 return strcmp(key1, key2);
1309 static void _plugin_entry_free_cb(void* data)
1311 Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) data;
1314 eina_list_free(node->childs);
1315 node->childs = NULL;
1319 //static PluginNode* g_context;
1321 PluginNode* setting_plugin_create()
1323 PluginNode *node = calloc(1, sizeof(PluginNode));
1325 Draw_Data *pd = calloc(1, sizeof(Draw_Data));
1326 setting_retvm_if(!pd, -1, "Create Draw_Data obj failed");
1330 node->ui_list = eina_hash_new(EINA_KEY_LENGTH(_plugin_string_key_length),
1331 EINA_KEY_CMP(_plugin_string_key_cmp),
1332 EINA_KEY_HASH(eina_hash_superfast),
1333 _plugin_entry_free_cb,
1339 void setting_plugin_destroy(PluginNode* node)
1341 SETTING_TRACE_BEGIN;
1343 SETTING_TRACE("node is NOT NULL")
1345 SETTING_TRACE("node->pd is NOT NULL")
1346 if(node->pd->doc != NULL) {
1347 xmlSaveFormatFile(node->plugin_path, node->pd->doc, 1);
1348 xmlFreeDoc(node->pd->doc);
1349 node->pd->doc = NULL;
1350 SETTING_TRACE("__cfg_file_write successful");
1357 if (node->ui_list) {
1358 eina_hash_free(node->ui_list);
1359 node->ui_list = NULL;
1367 static Eina_Bool _plugin_foreach_cb(const Eina_Hash *hash, const void*key, void* data, void* fdata)
1369 Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) data;
1370 SETTING_TRACE("%s --- %s ", (char*)key, node->keyStr);
1375 void setting_plugin_debug(PluginNode* context)
1377 // SETTING_TRACE("HASH TABLE -------------------------------------");
1378 eina_hash_foreach(context->ui_list,_plugin_foreach_cb, NULL);
1379 // SETTING_TRACE("HASH TABLE -------------------------------------");
1383 void setting_plugin_update(PluginNode* context)
1385 Eina_List *li = context->ui_list;
1388 Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) eina_list_data_get(li);
1390 // SETTING_TRACE(" ---> keyStr : %s , swallow type : %d ", node->keyStr, node->swallow_type);
1391 Setting_GenGroupItem_Data* item_to_update = NULL;
1392 item_to_update = node;
1393 elm_object_item_data_set(item_to_update->item, item_to_update);
1394 elm_genlist_item_update(item_to_update->item);
1396 li = eina_list_next(li);
1401 bool setting_plugin_load(PluginNode* context, const char *cfg_file)
1403 SETTING_TRACE("cfg_file:%s", cfg_file)
1404 if (isEmptyStr(cfg_file) || 0 != access(cfg_file, R_OK|W_OK|F_OK ))
1406 SETTING_TRACE_ERROR(" error occured : access \n");
1409 context->pd->cfg_file = cfg_file;
1410 context->pd->win_get = (Evas_Object *) ug_get_window();
1412 GError *error = NULL;
1414 context->pd->doc = xmlParseFile(cfg_file);
1415 context->pd->root = xmlDocGetRootElement(context->pd->doc);
1417 // TODO: error handler here
1418 __node_walker(context, context->pd->root);
1421 setting_plugin_debug(context);