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 SETTING_TRACE("node type:%s", type);
126 Eina_List *check_list = _g_drawer_list;
127 Object_Drawer *list_item = NULL;
130 list_item = (Object_Drawer *) eina_list_data_get(check_list);
131 if (NULL == list_item)
134 if (0 == safeStrCmp(list_item->type, type))
136 //SETTING_TRACE("list_item->type:%s", list_item->type);
139 //if not matched,to check next node.
140 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"
194 static char* s_pkg_name;
196 static char* substring(const char* str, size_t begin, size_t len)
198 if (str == 0 || strlen(str) == 0 || strlen(str) < begin || strlen(str) < (begin+len))
201 return strndup(str + begin, len);
207 * ncbyusjryr.AppSetting --> package ID is ncbyusjryr
209 static char* get_app_string(char* path)
212 char* temp = substring(path, 10, 10/*string size*/);
213 SETTING_TRACE("package ID : >>> %s ",temp );
217 //------------------------------------------------------
219 static DBusConnection *bus;
220 //------------------------------------------------------
221 static DBusHandlerResult __signal_filter(DBusConnection* conn, DBusMessage* message, void* user_data)
223 int my_pid = getpid();
229 dbus_error_init(&error);
231 setting_main_appdata *ad = user_data;
233 char* pkg_name = get_app_string(ad->plugin_path);
234 s_pkg_name = pkg_name;
236 if (dbus_message_is_signal(message, DBUS_SIGNAL_INTERFACE, pkg_name))
238 if (dbus_message_get_args(message, &error,
239 DBUS_TYPE_UINT32, &sender_pid,
240 DBUS_TYPE_STRING, &key,
241 DBUS_TYPE_STRING, &value,
242 DBUS_TYPE_INVALID) == FALSE)
244 SETTING_TRACE_ERROR("Fail to get data : %s", error.message);
245 dbus_error_free(&error);
246 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
250 if (sender_pid != 0 && my_pid != sender_pid)
252 SETTING_TRACE("received key : %s , value : %s", key, value);
253 //-------------------------------------------------------------
254 // received key : checkbox1|N/A , value : INT|1
255 //-------------------------------------------------------------
256 //char* key = "checkbox1|N/A";
257 char* ptr = strchr(key, '|');
259 xmlDocPtr doc = NULL;
262 //parsing for : checkbox1|N/A -> checkbox1
263 char* key_name = substring(key, 0, strlen(key)-strlen(ptr));
264 char* val_name = strchr(value, '|');
269 doc = xmlParseFile(ad->plugin_path);
271 xmlNode *root = xmlDocGetRootElement(doc);
274 __node_finder((PluginNode*)ad->plugin_node, root, key_name ,val_name, &is_end);
277 GError *error = NULL;
282 xmlSaveFormatFile(ad->plugin_path, doc, 1);
283 // TODO: make sure this is right
286 SETTING_TRACE("__cfg_file_write successful");
293 return DBUS_HANDLER_RESULT_HANDLED;
296 static int __send_msg(char* key, char* value)
298 DBusMessage* message;
300 int sender_pid = getpid();
305 if (s_pkg_name == NULL) return -1;
307 message = dbus_message_new_signal(DBUS_PATH, DBUS_SIGNAL_INTERFACE, s_pkg_name);
309 SETTING_TRACE("Sending message[%s:%s] via dbus", key ,value);
310 if (dbus_message_append_args(message,
311 DBUS_TYPE_UINT32, &sender_pid,
312 DBUS_TYPE_STRING, &key,
313 DBUS_TYPE_STRING, &value,
314 DBUS_TYPE_INVALID) == FALSE)
316 SETTING_TRACE("Fail to load data error");
320 if (dbus_connection_send(bus, message, NULL) == FALSE)
322 SETTING_TRACE("Fail to send message");
326 dbus_connection_flush(bus);
327 dbus_message_unref(message);
329 SETTING_TRACE("[CLIENT] send data signal done");
335 static void __send_int_msg(xmlNode* xmlObj, int val)
337 const char *id = (char*)xmlGetProp(xmlObj, "id");
338 const char *title = (char*)xmlGetProp(xmlObj, "title");
339 char key[MAX_CONTENT_LEN] = {0,};
340 snprintf(key, sizeof(key), "%s|%s", id, title);
342 char value[MAX_CONTENT_LEN] = {0,};
343 snprintf(value, sizeof(value), "INT|%d", val);
344 __send_msg(key, value);
348 static void __send_string_msg(xmlNode* xmlObj, char *string)
350 const char *id = (char*)xmlGetProp(xmlObj, "id");
351 const char *title = (char*)xmlGetProp(xmlObj, "title");
352 char key[MAX_CONTENT_LEN] = {0,};
353 snprintf(key, sizeof(key), "%s|%s", id, title);
355 char value[MAX_CONTENT_LEN] = {0,};
356 snprintf(value, sizeof(value), "STRING|%s", string);
357 __send_msg(key, value);
361 int setting_dbus_handler_init(void* user_data)
366 SETTING_TRACE("already get a bus, need release first.");
367 setting_dbus_handler_fini();
370 memset(&error, 0, sizeof(DBusError));
371 char rule[MAX_LOCAL_BUFSIZE + 1] = {0,};
372 dbus_error_init(&error);
373 bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
376 SETTING_TRACE("Fail to connect to the D-BUS daemon: %s", error.message);
377 dbus_error_free(&error);
381 dbus_connection_setup_with_g_main(bus, NULL);
382 snprintf(rule, MAX_LOCAL_BUFSIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH, DBUS_SIGNAL_INTERFACE);
384 dbus_bus_add_match(bus, rule, &error);
385 if (dbus_error_is_set(&error))
387 SETTING_TRACE("Fail to rule set; %s", error.message);
388 dbus_bus_remove_match(bus, rule, &error);
389 dbus_error_free(&error);
390 dbus_connection_close(bus);
395 if (dbus_connection_add_filter(bus, __signal_filter, user_data, NULL) == FALSE)
397 dbus_bus_remove_match(bus, rule, &error);
398 dbus_error_free(&error);
399 dbus_connection_close(bus);
404 SETTING_TRACE("app signal initialized");
408 int setting_dbus_handler_fini(void)
410 //do safty checking first.
411 setting_retvm_if(!bus, 0, "!bus");
413 memset(&error, 0, sizeof(DBusError));
414 char rule[MAX_LOCAL_BUFSIZE + 1] = {0, };
416 dbus_error_init(&error);
417 //dbus_connection_remove_filter(bus, __signal_filter, NULL);
418 snprintf(rule, MAX_LOCAL_BUFSIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH, DBUS_SIGNAL_INTERFACE);
419 dbus_bus_remove_match(bus, rule, &error);
421 if (dbus_error_is_set(&error))
423 SETTING_TRACE("Fail to rule unset: %s", error.message);
424 dbus_error_free(&error);
428 dbus_connection_close(bus);
430 SETTING_TRACE("app signal finalized");
434 /////////////////////////////
435 /////////////////////////////
436 /////////////////////////////
438 Elm_Genlist_Item_Class itc_layout;
441 static int __cfg_file_write(Draw_Data *pd)
445 GError *error = NULL;
448 xmlSaveFormatFile(pd->cfg_file, pd->doc, 1);
449 //xmlFreeDoc(pd->doc);
451 SETTING_TRACE("__cfg_file_write successful");
458 static void ___click_softkey_back_cb(void *data, Evas_Object *obj,
464 PluginNode* node = (PluginNode*)data;
465 Draw_Data *pd = node->pd;
467 evas_object_del(pd->ly_main);
471 setting_plugin_destroy(node);
481 static void* group_func(void *data, xmlNode *xmlObj)
484 ret_if(!data || !xmlObj);
486 PluginNode* node = (PluginNode*)data;
487 Draw_Data *pd = node->pd;
489 // original code is non-recursive
491 const char *title = (char*)json_object_get_string_member(jsonObj, "title");
492 (void)setting_create_Gendial_field_titleItem(pd->scroller,
496 // non recursive method
497 if (json_object_has_member(jsonObj, "elements"))
499 JsonNode* elements_node = json_object_get_member(jsonObj, "elements");
503 for (i=0; i < json_array_get_length(json_node_get_array(elements_node)); i++)
505 tempobj = json_array_get_object_element(json_node_get_array(elements_node), i);
506 type = (char*)json_object_get_string_member(tempobj, "type");
507 drawer_fp fp = __drawer_find(type);
508 if (fp) fp(pd, tempobj); // draw it
512 // new code is recursive
513 const char *title = (char*)xmlGetProp(xmlObj, "title");
514 SETTING_TRACE (" >>> GROUP NAME : %s \n", title);
515 (void)setting_create_Gendial_field_titleItem(pd->scroller, &(itc_group_item), title, NULL);
522 static void* __link_list_cb(void *data, Evas_Object *obj, void *event_info)
525 ret_if(data == NULL);
526 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
527 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
528 elm_genlist_item_selected_set(item, 0);
529 Setting_GenGroupItem_Data *list_item =
530 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
532 xmlNode* xmlObj = data;
534 const char *link_file = (char*)xmlGetProp(xmlObj, "value");
538 SETTING_TRACE_ERROR("Invalidate liked file");
541 char file[1024] = {0,};
542 snprintf(file, sizeof(file), "%s/%s", PLUGIN_CFG_DIR, link_file);
543 SETTING_TRACE("file:%s", file);
545 PluginNode* plugin_node = setting_plugin_create();
546 setting_plugin_load(plugin_node, (const char *)file);
548 //setting_plugin_load(NULL, file);
553 static void* __launch_list_cb(void *data, Evas_Object *obj, void *event_info)
556 ret_if(data == NULL);
557 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
558 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
559 elm_genlist_item_selected_set(item, 0);
560 Setting_GenGroupItem_Data *list_item =
561 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
563 xmlNode* xmlObj = data;
565 const char *key_str = (char*)xmlGetProp(xmlObj, "id");
566 const char *title_str = (char*)xmlGetProp(xmlObj, "title");
567 const char *appid_str = (char*)xmlGetProp(xmlObj, "appid");
568 const char *operation_str = (char*)xmlGetProp(xmlObj, "operation");
571 service_h svc = NULL;
572 service_create(&svc);
573 service_set_app_id(svc, appid_str); // xml property – appid
574 service_set_operation(svc, operation_str); // property : operation
575 service_send_launch_request(svc, NULL, NULL);
576 service_destroy(svc);
581 static void* label_func(void *data, xmlNode *xmlObj)
584 ret_if(!data || !xmlObj);
585 PluginNode* node = (PluginNode*)data;
586 Draw_Data *pd = node->pd;
588 const char *title = (char*)xmlGetProp(xmlObj, "title");
590 Setting_GenGroupItem_Data *obj =
591 setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
593 xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
594 0, title, NULL, NULL);
599 static void* link_func(void *data, xmlNode *xmlObj)
602 ret_if(!data || !xmlObj);
603 PluginNode* node = (PluginNode*)data;
604 Draw_Data *pd = node->pd;
606 const char *key_str = (char*)xmlGetProp(xmlObj, "id");
607 Setting_GenGroupItem_Data * obj =
608 setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
610 xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
611 0, key_str, NULL, NULL);
616 static void* launch_func(void *data, xmlNode *xmlObj)
619 ret_if(!data || !xmlObj);
620 PluginNode* node = (PluginNode*)data;
621 Draw_Data *pd = node->pd;
623 const char *title_str = (char*)xmlGetProp(xmlObj, "title");
625 Setting_GenGroupItem_Data * obj =
626 setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
628 xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
629 0, title_str, NULL, NULL);
634 static void __slider_stop_cb(void *data, Evas_Object *obj,
637 ret_if(data == NULL || obj == NULL);
638 double val = elm_slider_value_get(obj);
639 SETTING_TRACE("val = %f", val);
640 Setting_GenGroupItem_Data *list_item = data;
641 ret_if(list_item->userdata == NULL);
643 xmlNode* xmlObj = list_item->userdata;
646 //apply the vconf changes after stopping moving slider..
647 list_item->chk_status = (int)(val + 0.5);
648 elm_slider_value_set(obj, list_item->chk_status);
650 SETTING_TRACE(" slider after ---> val = %d", (int) list_item->chk_status);
652 // int -> double -> xmlChar*
655 sprintf(buf, "%d", (int) list_item->chk_status);
656 newattr = xmlSetProp(xmlObj, "value", buf);
658 __send_int_msg(xmlObj, list_item->chk_status);
659 __cfg_file_write((Draw_Data *)list_item->belongs_to);
663 static void* slider_func(void *data, xmlNode *xmlObj)
666 ret_if(!data || !xmlObj);
667 PluginNode* node = (PluginNode*)data;
668 Draw_Data *pd = node->pd;
671 const char *title = (char*)xmlGetProp(xmlObj, "title");
673 SETTING_TRACE (" >>> [slider input] min=%s max=%s value=%s ",(char*)xmlGetProp(xmlObj, "min"), (char*)xmlGetProp(xmlObj, "max"), (char*)xmlGetProp(xmlObj, "value"));
675 int value = atoi((char*)xmlGetProp(xmlObj, "value"));
676 int min = atoi((char*)xmlGetProp(xmlObj, "min"));
677 int max = atoi((char*)xmlGetProp(xmlObj, "max"));
679 SETTING_TRACE ("[slider input] min=%d max=%d value=%d ", min, max, value);
681 setting_create_Gendial_itc("dialogue/1text.1icon.5", &(itc_layout));
682 Setting_GenGroupItem_Data *list_item =
683 setting_create_Gendial_field_def(pd->scroller, &(itc_layout), NULL,
685 SWALLOW_Type_LAYOUT_SLIDER,
686 IMG_SENSITIVITY_ICON_01,
687 IMG_SENSITIVITY_ICON_02, value,
690 list_item->win_main = NULL;
691 list_item->evas = NULL;
692 list_item->isIndicatorVisible = true;
693 list_item->slider_min = min;
694 list_item->slider_max = max;
695 list_item->userdata = xmlObj;
696 list_item->stop_change_cb = __slider_stop_cb;
697 list_item->belongs_to = (int)pd;
700 g_list_item = list_item;
702 return (void*)list_item;
706 elm_object_item_data_set(item_to_update->item, item_to_update);
707 elm_genlist_item_update(item_to_update->item);
709 static void* navigationbar_func(void *data, xmlNode *xmlObj)
713 ret_if(!data || !xmlObj);
715 PluginNode* node = (PluginNode*)data;
716 Draw_Data *pd = node->pd;
718 //----------------------------------------------------------------
719 // [DATA] title, btn[0], btn[1]
720 const char *title = (char*)xmlGetProp(xmlObj, "title");
721 char *btn[2] = {0, };
723 // find child nodes named 'elements'
724 if (xmlObj->children) {
725 xmlNode* cur = xmlObj->children;
729 if (!xmlStrcmp(cur->name, (const xmlChar*)"button")) {
730 btn[i] = xmlGetProp(cur, "title");
731 SETTING_TRACE("------>>> node type : Element, name=%s id=%s / btn[%d] = %s ",
732 cur->name,xmlGetProp(cur, "id"),
740 //----------------------------------------------------------------
742 pd->ly_main = setting_create_layout_navi_bar_genlist(pd->win_get,
745 _(btn[1]), _(btn[0]),
746 ___click_softkey_back_cb,
747 ___click_softkey_back_cb, data, &pd->scroller,
755 static void __check_mouse_up_cb(void *data, Evas_Object *obj,
760 setting_retm_if(data == NULL, "Data parameter is NULL");
762 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
763 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
764 elm_genlist_item_selected_set(item, 0);
765 Setting_GenGroupItem_Data *list_item =
766 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
768 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
770 int old_status = elm_check_state_get(list_item->eo_check);
771 list_item->chk_status = !old_status;
772 elm_check_state_set(list_item->eo_check, list_item->chk_status);
774 xmlNode *xmlObj = data;
776 newattr = xmlSetProp(xmlObj, "state", xmlXPathCastNumberToString(list_item->chk_status));
778 __send_int_msg(xmlObj, list_item->chk_status);
779 __cfg_file_write((Draw_Data *)list_item->belongs_to);
783 static void __chk_btn_cb(void *data, Evas_Object *obj,
788 retm_if(data == NULL, "Data parameter is NULL");
789 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
791 xmlNode* xmlObj = list_item->userdata;
793 list_item->chk_status = elm_check_state_get(obj); /* for genlist update status */
796 if (list_item->chk_status == 1) {
797 newattr = xmlSetProp(xmlObj, "value", "true");
798 } else if (list_item->chk_status == 0) {
799 newattr = xmlSetProp(xmlObj, "value", "false");
801 newattr = xmlSetProp(xmlObj, "value", "false");
804 const char *id = (char*)xmlGetProp(xmlObj, "id");
805 const char *title = (char*)xmlGetProp(xmlObj, "title");
806 //SETTING_TRACE(" >>>> id:%s , title:%s", id, title);
807 __send_int_msg(xmlObj, list_item->chk_status);
808 __cfg_file_write((Draw_Data *)list_item->belongs_to);
813 static void* checkbox_func(void *data, xmlNode *xmlObj)
816 ret_if(!data || !xmlObj);
818 PluginNode* node = (PluginNode*)data;
819 Draw_Data *pd = node->pd;
821 // [DATA] title, value
822 const char *title = (char*)xmlGetProp(xmlObj, "title");
825 char* value = (char*)xmlGetProp(xmlObj, "value");
829 if ( 0 == safeStrCmp(value, "true")) {
831 } else if ( 0 == safeStrCmp(value, "false")) {
834 ival = 0; // default : false (0)
837 // title, value, xmlObj
838 Setting_GenGroupItem_Data *list_item =
839 setting_create_Gendial_field_def(pd->scroller,
843 SWALLOW_Type_1TOGGLE,
850 list_item->userdata = xmlObj;
851 list_item->belongs_to = (int) pd;
852 SETTING_TRACE("pd:%p,list_item->belongs_to:%d", pd, list_item->belongs_to);
859 static void __entry_unfocus_cb(void *data, Evas_Object *obj, void *event_info)
862 retm_if(!data || !obj, "Data parameter is NULL");
864 setting_hide_input_pannel_cb(obj);
865 const char *entry_str = elm_entry_entry_get(obj);
866 char *entry_str_utf8 = NULL;
867 entry_str_utf8 = elm_entry_markup_to_utf8(entry_str);
869 Setting_GenGroupItem_Data *list_item = data;
871 xmlNode* xmlObj = list_item->userdata;
874 const char *title = (char*)xmlSetProp(xmlObj, "value",entry_str_utf8);
876 __send_string_msg(xmlObj, entry_str_utf8);
877 __cfg_file_write((Draw_Data *)list_item->belongs_to);
879 FREE(entry_str_utf8);
883 static void __editbox_list_cb(void *data, Evas_Object *obj,
889 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
890 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
891 elm_genlist_item_selected_set(item, 0);
892 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
894 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
895 if (!elm_object_focus_get(list_item->eo_check)) {
896 elm_object_focus_set(list_item->eo_check, EINA_TRUE);
899 Ecore_IMF_Context *imf_context = (Ecore_IMF_Context *)elm_entry_imf_context_get(list_item->eo_check);
900 setting_retm_if(imf_context == NULL, "imf_context is NULL");
901 ecore_imf_context_input_panel_show(imf_context);
905 static void __editbox_changed_cb(void *data, Evas_Object *obj,
909 retm_if(!data || !obj, "Data parameter is NULL");
910 retm_if(!elm_object_focus_get(obj), "Entry is not focused");
912 Setting_GenGroupItem_Data *list_item =
913 (Setting_GenGroupItem_Data *) data;
915 const char *entry_str = elm_entry_entry_get(obj);
916 int entry_len = safeStrLen(entry_str);
917 SETTING_TRACE("entry_str:[%s], lenght:%d", entry_str, entry_len);
919 G_FREE(list_item->sub_desc);//release first
920 list_item->sub_desc = (char *)g_strdup(entry_str);
924 static void* editbox_func(void *data, xmlNode *xmlObj)
927 ret_if(!data || !xmlObj);
929 PluginNode* node = (PluginNode*)data;
930 Draw_Data *pd = node->pd;
932 const char *title = (char*)xmlGetProp(xmlObj, "title");
933 const char *key_str= (char*)xmlGetProp(xmlObj, "value");
937 Setting_GenGroupItem_Data *list_item =
938 setting_create_Gendial_field_def(pd->scroller, &(itc_1icon),
940 pd, SWALLOW_Type_LAYOUT_ENTRY,
941 NULL, NULL, 0, title, key_str,
942 __editbox_changed_cb);
944 list_item->userdata = xmlObj;
945 list_item->stop_change_cb = __entry_unfocus_cb;
946 list_item->belongs_to = (int)pd;
953 static void __expanditem_func_sel_cb(void *data, Evas_Object *obj, void *event_info)
957 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
958 Elm_Object_Item *subitem = (Elm_Object_Item *) event_info;
959 Elm_Object_Item *parentItem = elm_genlist_item_parent_get(subitem);
960 elm_genlist_item_selected_set(subitem, 0);
961 Setting_GenGroupItem_Data *data_subItem = elm_object_item_data_get(subitem);
962 Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem); /* parent data */
963 ret_if(NULL == data_subItem || NULL == data_parentItem);
965 elm_radio_value_set(data_subItem->rgd, data_subItem->chk_status);
967 data_parentItem->sub_desc = (char *)g_strdup(_(data_subItem->keyStr));
968 elm_object_item_data_set(data_parentItem->item, data_parentItem);
969 elm_genlist_item_update(data_parentItem->item);
971 xmlNode* xmlObj = data_parentItem->userdata;
975 //newattr = xmlSetProp(xmlObj, "string", data_parentItem->sub_desc);
976 newattr = xmlSetProp(xmlObj, "value", data_parentItem->sub_desc);
978 __send_string_msg(xmlObj, data_parentItem->sub_desc);
979 __cfg_file_write((Draw_Data *)data_parentItem->belongs_to);
983 static void __expanditem_func_exp_cb(void *data, Evas_Object *obj, void *event_info)
985 ret_if(NULL == data || NULL == event_info);
988 PluginNode* node = (PluginNode*)data;
989 Draw_Data *pd = node->pd;
991 Elm_Object_Item *parentItem = event_info; /* parent item */
992 Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem); /* parent data */
993 Evas_Object *scroller = elm_object_item_widget_get(parentItem);
996 xmlNode *xmlObj = data_parentItem->userdata;
997 //char *value = (char*)xmlGetProp(xmlObj, "string");
998 char *value = (char*)xmlGetProp(xmlObj, "value");
999 SETTING_TRACE(">>> value = %s", value);
1001 Evas_Object *rgd = NULL;
1003 if (xmlObj->children && !data_parentItem->rgd) {//to protect from entering repeatly
1004 xmlNode* cur = xmlObj->children;
1006 rgd = elm_radio_add(scroller);
1007 elm_radio_value_set(rgd, -1);
1011 char *subitem_title = NULL;
1012 int subitem_index = 0;
1015 while (cur != NULL) {
1016 if (!xmlStrcmp(cur->name, (const xmlChar*)"expanditem")) {
1017 type = (char*)xmlGetProp(cur, "type");
1018 if (0 == safeStrCmp(type, "radio")) {
1019 subitem_title = (char*)xmlGetProp(cur, "title");
1020 Setting_GenGroupItem_Data *list_item =
1021 setting_create_Gendial_exp_sub_field(scroller,
1022 &(itc_1icon_1text_sub),
1023 __expanditem_func_sel_cb, NULL, parentItem,
1024 SWALLOW_Type_1RADIO, rgd,
1026 subitem_title, NULL);
1028 // SETTING_TRACE(">>> value = %s, subitem_title = %s ", value, subitem_title);
1030 if (0 == safeStrCmp(value, subitem_title)) {
1031 sel_idx = subitem_index;
1032 SETTING_TRACE("%d is selected in Radio Group", sel_idx);
1034 data_parentItem->childs = eina_list_append(data_parentItem->childs, list_item);
1038 SETTING_TRACE("invalid type[:%s]", type);
1047 elm_radio_value_set(rgd, sel_idx);
1048 data_parentItem->rgd = rgd;//protecting condition
1053 static void __expanditem_func_smart_cb(void *data, Evas_Object *obj, void *event_info)
1055 ret_if(data == NULL || event_info == NULL);
1056 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
1057 Setting_GenGroupItem_Data *data_item = elm_object_item_data_get(item);
1058 char *cb_type = data;
1060 if (0 == safeStrCmp(cb_type, "contracted")) {
1061 data_item->rgd = NULL;
1062 elm_genlist_item_subitems_clear(item);
1067 static void* settings_func(void *data, xmlNode *xmlObj)
1073 static void* setting_func(void *data, xmlNode *xmlObj)
1075 SETTING_TRACE_BEGIN;
1076 ret_if(!data || !xmlObj);
1079 //Draw_Data *pd = node->pd;
1080 PluginNode* node = (PluginNode*)data;
1081 Draw_Data *pd = node->pd;
1083 //----------------------------------------------------------------
1084 // [DATA] title, btn[0], btn[1]
1085 const char *title = (char*)xmlGetProp(xmlObj, "title");
1086 char *btn[2] = {/* 0 */"OK", /* 1 */"NO"};
1088 // find child nodes named 'elements'
1090 if (xmlObj->children) {
1091 xmlNode* cur = xmlObj->children;
1095 if (!xmlStrcmp(cur->name, (const xmlChar*)"button")) {
1096 btn[i] = xmlGetProp(cur, "title");
1097 SETTING_TRACE("------>>> node type : Element, name=%s id=%s / btn[%d] = %s ",
1098 cur->name,xmlGetProp(cur, "id"),
1107 //----------------------------------------------------------------
1108 SETTING_TRACE("before setting_create_layout_navi_bar_genlist");
1110 pd->scroller = elm_genlist_add(pd->win_get);
1111 retvm_if(pd->scroller == NULL, NULL,
1112 "Cannot set scroller object as contento of layout");
1113 elm_object_style_set(pd->scroller, "dialogue");
1114 elm_genlist_clear(pd->scroller); /* first to clear list */
1116 /* Enabling illume notification property for window */
1117 elm_win_conformant_set(pd->win_get, 1);
1118 Evas_Object *conformant = elm_conformant_add(pd->win_get);
1119 elm_object_style_set(conformant, "internal_layout"); /* By Kollus. 2011-01-04 */
1120 evas_object_show(conformant);
1121 elm_object_content_set(conformant, pd->scroller);
1123 SETTING_TRACE("_(title):%s", _(title));
1125 setting_create_layout_navi_bar(pd->win_get, pd->win_get,
1127 _("IDS_COM_BODY_BACK"), NULL, NULL,
1128 ___click_softkey_back_cb,
1131 &(pd->navi_bar), NULL);
1132 SETTING_TRACE("after setting_create_layout_navi_bar_genlist");
1139 static void* expanditem_func(void *data, xmlNode *xmlObj)
1141 // DO NOTHING - expandlist draws this area
1145 static void* expandlist_func(void *data, xmlNode *xmlObj)
1147 SETTING_TRACE_BEGIN;
1148 ret_if(!data || !xmlObj);
1150 PluginNode* node = (PluginNode*)data;
1151 Draw_Data *pd = node->pd;
1153 const char *key_str = (char*)xmlGetProp(xmlObj, "title");
1154 const char *value = (char*)xmlGetProp(xmlObj, "value"); // string -> value
1156 setting_enable_expandable_genlist(pd->scroller, data, __expanditem_func_exp_cb, __expanditem_func_smart_cb);
1157 Setting_GenGroupItem_Data *list_item =
1158 setting_create_Gendial_exp_parent_field(pd->scroller,
1159 &(itc_2text_3_parent),
1161 SWALLOW_Type_INVALID,
1165 list_item->userdata = xmlObj;
1166 list_item->belongs_to = (int)pd;
1174 static int __node_walker(PluginNode* context, xmlNode* cur)
1176 //SETTING_TRACE_BEGIN;
1177 Draw_Data *pd = context->pd;
1180 xmlNode *cur_node = NULL;
1181 for (cur_node = cur; cur_node;cur_node = cur_node->next) {
1182 if (cur_node->type == XML_ELEMENT_NODE) {
1183 SETTING_TRACE("node type : %s id= %s", cur_node->name,xmlGetProp(cur_node, "id"));
1185 drawer_fp fp = __drawer_find(cur_node->name);
1189 void* vret = fp(context, cur_node); // draw it
1193 Setting_GenGroupItem_Data* genlist_node = (Setting_GenGroupItem_Data* )vret;
1194 //SETTING_TRACE("add node to Eina List name : %s, id : ", cur_node->name, xmlGetProp(cur_node, "id"));
1195 // add it to the hash table create before.
1198 char* key_name = xmlGetProp(cur_node, "id");
1199 eina_hash_add(context->ui_list, strdup(key_name),(void*)genlist_node);
1203 __node_walker(context, cur_node->children); /* RECURSIVE */
1209 * @param id_str [in] "id"
1210 * @param value [in] value to be udpated
1211 * @see __expanditem_func_sel_cb
1213 static int __node_finder(PluginNode* context, xmlNode* cur, char* id_str, char* value, bool* is_end)
1215 SETTING_TRACE_BEGIN;
1216 xmlNode *cur_node = NULL;
1218 if (*is_end == true) return 0;
1220 for (cur_node = cur; cur_node;cur_node = cur_node->next) {
1221 if (cur_node->type == XML_ELEMENT_NODE) {
1223 char* id_name = (char*)xmlGetProp(cur_node, "id");
1224 if ( id_name && 0 == strcmp(id_str, id_name))
1226 SETTING_TRACE("FOUND >>>> %s", id_name);
1227 // cur_node - update xml code
1228 xmlAttrPtr newattr = xmlSetProp(cur_node, "value", value);
1230 //-----------------------------------------------------------
1233 if ( 0 == strcmp (cur_node->name, "integer"))
1235 SETTING_TRACE(">>>>> UPDATE SLIDER CONTROL %x --- %s ",context->ui_list, id_name);
1236 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1239 item_to_update->chk_status = atoi(value);
1240 SETTING_TRACE(">>> o-------------0 SLIDER VALUE = %d ", item_to_update->chk_status);
1242 elm_object_item_data_set(item_to_update->item, item_to_update);
1243 elm_genlist_item_update(item_to_update->item);
1245 SETTING_TRACE("item_to_update is NULL");
1249 if ( 0 == strcmp (cur_node->name, "bool"))
1251 SETTING_TRACE(">>>>> UPDATE TOGGLE CONTROL %x --- %s ",context->ui_list, id_name);
1252 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1255 item_to_update->chk_status = atoi(value);
1256 SETTING_TRACE(">>> o-------------0 TOGGLE VALUE = %d ", item_to_update->chk_status);
1258 elm_object_item_data_set(item_to_update->item, item_to_update);
1259 elm_genlist_item_update(item_to_update->item);
1261 SETTING_TRACE("item_to_update is NULL");
1264 // case : edit control
1265 if ( 0 == strcmp (cur_node->name, "string"))
1267 SETTING_TRACE(">>>>> UPDATE EDIT CONTROL CONTROL %x --- %s ",context->ui_list, id_name);
1268 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1271 char* old_string = item_to_update->sub_desc;
1272 item_to_update->sub_desc = strdup(value);
1273 SETTING_TRACE(">>> o-------------0 STRING VALUE = %s ", value);
1277 elm_object_item_data_set(item_to_update->item, item_to_update);
1278 elm_genlist_item_update(item_to_update->item);
1281 SETTING_TRACE("item_to_update is NULL");
1284 // case : expand list
1290 //-----------------------------------------------------------
1291 if ( 0 == strcmp (cur_node->name, "expandlist"))
1293 SETTING_TRACE(">>>>> UPDATE EXPAND LIST CONTROL %x --- %s ",context->ui_list, id_name);
1294 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1297 char* old_string = item_to_update->sub_desc;
1298 item_to_update->sub_desc = strdup(value);
1299 SETTING_TRACE(">>> o-------------0 EXPAND LIST VALUE = %s ", value);
1303 elm_object_item_data_set(item_to_update->item, item_to_update);
1304 elm_genlist_item_update(item_to_update->item);
1306 // TODO: need to update child elements
1307 // item_to_update->childs ---> expanded list
1308 if (item_to_update->childs)
1310 Eina_List *li = item_to_update->childs;
1311 int radio_index = 0;
1314 Setting_GenGroupItem_Data* node = eina_list_data_get(li);
1315 // do something more
1316 // SETTING_TRACE(">>> RADIO LIST STRING VALUE = %s ", node->keyStr);
1317 // set position of radio button
1318 if (strcmp(node->keyStr, value) == 0)
1320 elm_radio_value_set(node->rgd, radio_index);
1322 elm_object_item_data_set(item_to_update->item, item_to_update);
1323 elm_genlist_item_update(item_to_update->item);
1326 li = eina_list_next(li);
1332 SETTING_TRACE("item_to_update is NULL");
1339 __node_finder(context, cur_node->children, id_str, value, is_end); /* RECURSIVE */
1344 static unsigned int _plugin_string_key_length(const char*key)
1349 return (int)strlen(key) + 1;
1352 static int _plugin_string_key_cmp(const char* key1, int key1_length,
1353 const char* key2, int key2_length)
1355 return strcmp(key1, key2);
1358 static void _plugin_entry_free_cb(void* data)
1360 Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) data;
1363 eina_list_free(node->childs);
1364 node->childs = NULL;
1368 //static PluginNode* g_context;
1370 PluginNode* setting_plugin_create()
1372 PluginNode *node = calloc(1, sizeof(PluginNode));
1374 Draw_Data *pd = calloc(1, sizeof(Draw_Data));
1375 setting_retvm_if(!pd, -1, "Create Draw_Data obj failed");
1379 node->ui_list = eina_hash_new(EINA_KEY_LENGTH(_plugin_string_key_length),
1380 EINA_KEY_CMP(_plugin_string_key_cmp),
1381 EINA_KEY_HASH(eina_hash_superfast),
1382 _plugin_entry_free_cb,
1388 void setting_plugin_destroy(PluginNode* node)
1390 SETTING_TRACE_BEGIN;
1392 SETTING_TRACE("node is NOT NULL")
1394 SETTING_TRACE("node->pd is NOT NULL")
1395 if(node->pd->doc != NULL) {
1396 xmlSaveFormatFile(node->plugin_path, node->pd->doc, 1);
1397 xmlFreeDoc(node->pd->doc);
1398 node->pd->doc = NULL;
1399 SETTING_TRACE("__cfg_file_write successful");
1406 if (node->ui_list) {
1407 eina_hash_free(node->ui_list);
1408 node->ui_list = NULL;
1416 static Eina_Bool _plugin_foreach_cb(const Eina_Hash *hash, const void*key, void* data, void* fdata)
1418 Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) data;
1419 SETTING_TRACE("%s --- %s ", (char*)key, node->keyStr);
1424 void setting_plugin_debug(PluginNode* context)
1426 // SETTING_TRACE("HASH TABLE -------------------------------------");
1427 eina_hash_foreach(context->ui_list,_plugin_foreach_cb, NULL);
1428 // SETTING_TRACE("HASH TABLE -------------------------------------");
1432 void setting_plugin_update(PluginNode* context)
1434 Eina_List *li = context->ui_list;
1437 Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) eina_list_data_get(li);
1439 // SETTING_TRACE(" ---> keyStr : %s , swallow type : %d ", node->keyStr, node->swallow_type);
1440 Setting_GenGroupItem_Data* item_to_update = NULL;
1441 item_to_update = node;
1442 elm_object_item_data_set(item_to_update->item, item_to_update);
1443 elm_genlist_item_update(item_to_update->item);
1445 li = eina_list_next(li);
1450 bool setting_plugin_load(PluginNode* context, const char *cfg_file)
1452 SETTING_TRACE("cfg_file:%s", cfg_file)
1453 if (isEmptyStr(cfg_file) || 0 != access(cfg_file, R_OK|W_OK|F_OK ))
1455 SETTING_TRACE_ERROR(" error occured : access \n");
1458 context->pd->cfg_file = cfg_file;
1459 context->pd->win_get = (Evas_Object *) ug_get_window();
1461 GError *error = NULL;
1463 context->pd->doc = xmlParseFile(cfg_file);
1464 context->pd->root = xmlDocGetRootElement(context->pd->doc);
1466 // TODO: error handler here
1467 __node_walker(context, context->pd->root);
1470 setting_plugin_debug(context);