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"
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)
346 SETTING_TRACE("already get a bus, need release first.");
347 setting_dbus_handler_fini();
350 memset(&error, 0, sizeof(DBusError));
351 char rule[MAX_LOCAL_BUFSIZE + 1] = {0,};
352 dbus_error_init(&error);
353 bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
356 SETTING_TRACE("Fail to connect to the D-BUS daemon: %s", error.message);
357 dbus_error_free(&error);
361 dbus_connection_setup_with_g_main(bus, NULL);
362 snprintf(rule, MAX_LOCAL_BUFSIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH, DBUS_SIGNAL_INTERFACE);
364 dbus_bus_add_match(bus, rule, &error);
365 if (dbus_error_is_set(&error))
367 SETTING_TRACE("Fail to rule set; %s", error.message);
368 dbus_bus_remove_match(bus, rule, &error);
369 dbus_error_free(&error);
370 dbus_connection_close(bus);
375 if (dbus_connection_add_filter(bus, __signal_filter, user_data, NULL) == FALSE)
377 dbus_bus_remove_match(bus, rule, &error);
378 dbus_error_free(&error);
379 dbus_connection_close(bus);
384 SETTING_TRACE("app signal initialized");
388 int setting_dbus_handler_fini(void)
390 //do safty checking first.
391 setting_retvm_if(!bus, 0, "!bus");
393 memset(&error, 0, sizeof(DBusError));
394 char rule[MAX_LOCAL_BUFSIZE + 1] = {0, };
396 dbus_error_init(&error);
397 //dbus_connection_remove_filter(bus, __signal_filter, NULL);
398 snprintf(rule, MAX_LOCAL_BUFSIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH, DBUS_SIGNAL_INTERFACE);
399 dbus_bus_remove_match(bus, rule, &error);
401 if (dbus_error_is_set(&error))
403 SETTING_TRACE("Fail to rule unset: %s", error.message);
404 dbus_error_free(&error);
408 dbus_connection_close(bus);
410 SETTING_TRACE("app signal finalized");
414 /////////////////////////////
415 /////////////////////////////
416 /////////////////////////////
418 Elm_Genlist_Item_Class itc_layout;
421 static int __cfg_file_write(Draw_Data *pd)
425 GError *error = NULL;
428 xmlSaveFormatFile(pd->cfg_file, pd->doc, 1);
429 //xmlFreeDoc(pd->doc);
431 SETTING_TRACE("__cfg_file_write successful");
438 static void ___click_softkey_back_cb(void *data, Evas_Object *obj,
444 PluginNode* node = (PluginNode*)data;
445 Draw_Data *pd = node->pd;
447 evas_object_del(pd->ly_main);
451 setting_plugin_destroy(node);
461 static void* group_func(void *data, xmlNode *xmlObj)
464 ret_if(!data || !xmlObj);
466 PluginNode* node = (PluginNode*)data;
467 Draw_Data *pd = node->pd;
469 // original code is non-recursive
471 const char *title = (char*)json_object_get_string_member(jsonObj, "title");
472 (void)setting_create_Gendial_field_titleItem(pd->scroller,
476 // non recursive method
477 if (json_object_has_member(jsonObj, "elements"))
479 JsonNode* elements_node = json_object_get_member(jsonObj, "elements");
483 for (i=0; i < json_array_get_length(json_node_get_array(elements_node)); i++)
485 tempobj = json_array_get_object_element(json_node_get_array(elements_node), i);
486 type = (char*)json_object_get_string_member(tempobj, "type");
487 drawer_fp fp = __drawer_find(type);
488 if (fp) fp(pd, tempobj); // draw it
492 // new code is recursive
493 const char *title = (char*)xmlGetProp(xmlObj, "title");
494 SETTING_TRACE (" >>> GROUP NAME : %s \n", title);
495 (void)setting_create_Gendial_field_titleItem(pd->scroller, &(itc_group_item), title, NULL);
502 static void* __link_list_cb(void *data, Evas_Object *obj, void *event_info)
505 ret_if(data == NULL);
506 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
507 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
508 elm_genlist_item_selected_set(item, 0);
509 Setting_GenGroupItem_Data *list_item =
510 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
512 xmlNode* xmlObj = data;
514 const char *link_file = (char*)xmlGetProp(xmlObj, "value");
518 SETTING_TRACE_ERROR("Invalidate liked file");
521 char file[1024] = {0,};
522 snprintf(file, sizeof(file), "%s/%s", PLUGIN_CFG_DIR, link_file);
523 SETTING_TRACE("file:%s", file);
525 PluginNode* plugin_node = setting_plugin_create();
526 setting_plugin_load(plugin_node, (const char *)file);
528 //setting_plugin_load(NULL, file);
533 static void* __launch_list_cb(void *data, Evas_Object *obj, void *event_info)
536 ret_if(data == NULL);
537 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
538 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
539 elm_genlist_item_selected_set(item, 0);
540 Setting_GenGroupItem_Data *list_item =
541 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
543 xmlNode* xmlObj = data;
545 const char *key_str = (char*)xmlGetProp(xmlObj, "id");
546 const char *title_str = (char*)xmlGetProp(xmlObj, "title");
547 const char *appid_str = (char*)xmlGetProp(xmlObj, "appid");
548 const char *operation_str = (char*)xmlGetProp(xmlObj, "operation");
551 service_h svc = NULL;
552 service_create(&svc);
553 service_set_app_id(svc, appid_str); // xml property – appid
554 service_set_operation(svc, operation_str); // property : operation
555 service_send_launch_request(svc, NULL, NULL);
556 service_destroy(svc);
561 static void* label_func(void *data, xmlNode *xmlObj)
564 ret_if(!data || !xmlObj);
565 PluginNode* node = (PluginNode*)data;
566 Draw_Data *pd = node->pd;
568 const char *title = (char*)xmlGetProp(xmlObj, "title");
570 Setting_GenGroupItem_Data *obj =
571 setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
573 xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
574 0, title, NULL, NULL);
579 static void* link_func(void *data, xmlNode *xmlObj)
582 ret_if(!data || !xmlObj);
583 PluginNode* node = (PluginNode*)data;
584 Draw_Data *pd = node->pd;
586 const char *key_str = (char*)xmlGetProp(xmlObj, "id");
587 Setting_GenGroupItem_Data * obj =
588 setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
590 xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
591 0, key_str, NULL, NULL);
596 static void* launch_func(void *data, xmlNode *xmlObj)
599 ret_if(!data || !xmlObj);
600 PluginNode* node = (PluginNode*)data;
601 Draw_Data *pd = node->pd;
603 const char *title_str = (char*)xmlGetProp(xmlObj, "title");
605 Setting_GenGroupItem_Data * obj =
606 setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
608 xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
609 0, title_str, NULL, NULL);
614 static void __slider_stop_cb(void *data, Evas_Object *obj,
617 ret_if(data == NULL || obj == NULL);
618 double val = elm_slider_value_get(obj);
619 SETTING_TRACE("val = %f", val);
620 Setting_GenGroupItem_Data *list_item = data;
621 ret_if(list_item->userdata == NULL);
623 xmlNode* xmlObj = list_item->userdata;
626 //apply the vconf changes after stopping moving slider..
627 list_item->chk_status = (int)(val + 0.5);
628 elm_slider_value_set(obj, list_item->chk_status);
630 SETTING_TRACE(" slider after ---> val = %d", (int) list_item->chk_status);
632 // int -> double -> xmlChar*
635 sprintf(buf, "%d", (int) list_item->chk_status);
636 newattr = xmlSetProp(xmlObj, "value", buf);
638 __send_int_msg(xmlObj, list_item->chk_status);
639 __cfg_file_write((Draw_Data *)list_item->belongs_to);
643 static void* slider_func(void *data, xmlNode *xmlObj)
646 ret_if(!data || !xmlObj);
647 PluginNode* node = (PluginNode*)data;
648 Draw_Data *pd = node->pd;
651 const char *title = (char*)xmlGetProp(xmlObj, "title");
653 SETTING_TRACE (" >>> [slider input] min=%s max=%s value=%s ",(char*)xmlGetProp(xmlObj, "min"), (char*)xmlGetProp(xmlObj, "max"), (char*)xmlGetProp(xmlObj, "value"));
655 int value = atoi((char*)xmlGetProp(xmlObj, "value"));
656 int min = atoi((char*)xmlGetProp(xmlObj, "min"));
657 int max = atoi((char*)xmlGetProp(xmlObj, "max"));
659 SETTING_TRACE ("[slider input] min=%d max=%d value=%d ", min, max, value);
661 setting_create_Gendial_itc("dialogue/1text.1icon.5", &(itc_layout));
662 Setting_GenGroupItem_Data *list_item =
663 setting_create_Gendial_field_def(pd->scroller, &(itc_layout), NULL,
665 SWALLOW_Type_LAYOUT_SLIDER,
666 IMG_SENSITIVITY_ICON_01,
667 IMG_SENSITIVITY_ICON_02, value,
670 list_item->win_main = NULL;
671 list_item->evas = NULL;
672 list_item->isIndicatorVisible = true;
673 list_item->slider_min = min;
674 list_item->slider_max = max;
675 list_item->userdata = xmlObj;
676 list_item->stop_change_cb = __slider_stop_cb;
677 list_item->belongs_to = (int)pd;
680 g_list_item = list_item;
682 return (void*)list_item;
686 elm_object_item_data_set(item_to_update->item, item_to_update);
687 elm_genlist_item_update(item_to_update->item);
689 static void* navigationbar_func(void *data, xmlNode *xmlObj)
693 ret_if(!data || !xmlObj);
695 PluginNode* node = (PluginNode*)data;
696 Draw_Data *pd = node->pd;
698 //----------------------------------------------------------------
699 // [DATA] title, btn[0], btn[1]
700 const char *title = (char*)xmlGetProp(xmlObj, "title");
701 char *btn[2] = {0, };
703 // find child nodes named 'elements'
704 if (xmlObj->children) {
705 xmlNode* cur = xmlObj->children;
709 if (!xmlStrcmp(cur->name, (const xmlChar*)"button")) {
710 btn[i] = xmlGetProp(cur, "title");
711 SETTING_TRACE("------>>> node type : Element, name=%s id=%s / btn[%d] = %s ",
712 cur->name,xmlGetProp(cur, "id"),
720 //----------------------------------------------------------------
722 pd->ly_main = setting_create_layout_navi_bar_genlist(pd->win_get,
725 _(btn[1]), _(btn[0]),
726 ___click_softkey_back_cb,
727 ___click_softkey_back_cb, data, &pd->scroller,
735 static void __check_mouse_up_cb(void *data, Evas_Object *obj,
740 setting_retm_if(data == NULL, "Data parameter is NULL");
742 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
743 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
744 elm_genlist_item_selected_set(item, 0);
745 Setting_GenGroupItem_Data *list_item =
746 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
748 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
750 int old_status = elm_check_state_get(list_item->eo_check);
751 list_item->chk_status = !old_status;
752 elm_check_state_set(list_item->eo_check, list_item->chk_status);
754 xmlNode *xmlObj = data;
756 newattr = xmlSetProp(xmlObj, "state", xmlXPathCastNumberToString(list_item->chk_status));
758 __send_int_msg(xmlObj, list_item->chk_status);
759 __cfg_file_write((Draw_Data *)list_item->belongs_to);
763 static void __chk_btn_cb(void *data, Evas_Object *obj,
768 retm_if(data == NULL, "Data parameter is NULL");
769 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
771 xmlNode* xmlObj = list_item->userdata;
773 list_item->chk_status = elm_check_state_get(obj); /* for genlist update status */
776 if (list_item->chk_status == 1) {
777 newattr = xmlSetProp(xmlObj, "value", "true");
778 } else if (list_item->chk_status == 0) {
779 newattr = xmlSetProp(xmlObj, "value", "false");
781 newattr = xmlSetProp(xmlObj, "value", "false");
784 const char *id = (char*)xmlGetProp(xmlObj, "id");
785 const char *title = (char*)xmlGetProp(xmlObj, "title");
786 //SETTING_TRACE(" >>>> id:%s , title:%s", id, title);
787 __send_int_msg(xmlObj, list_item->chk_status);
788 __cfg_file_write((Draw_Data *)list_item->belongs_to);
793 static void* checkbox_func(void *data, xmlNode *xmlObj)
796 ret_if(!data || !xmlObj);
798 PluginNode* node = (PluginNode*)data;
799 Draw_Data *pd = node->pd;
801 // [DATA] title, value
802 const char *title = (char*)xmlGetProp(xmlObj, "title");
805 char* value = (char*)xmlGetProp(xmlObj, "value");
809 if ( 0 == safeStrCmp(value, "true")) {
811 } else if ( 0 == safeStrCmp(value, "false")) {
814 ival = 0; // default : false (0)
817 // title, value, xmlObj
818 Setting_GenGroupItem_Data *list_item =
819 setting_create_Gendial_field_def(pd->scroller,
823 SWALLOW_Type_1TOGGLE,
830 list_item->userdata = xmlObj;
831 list_item->belongs_to = (int) pd;
832 SETTING_TRACE("pd:%p,list_item->belongs_to:%d", pd, list_item->belongs_to);
839 static void __entry_unfocus_cb(void *data, Evas_Object *obj, void *event_info)
842 retm_if(!data || !obj, "Data parameter is NULL");
844 setting_hide_input_pannel_cb(obj);
845 const char *entry_str = elm_entry_entry_get(obj);
846 char *entry_str_utf8 = NULL;
847 entry_str_utf8 = elm_entry_markup_to_utf8(entry_str);
849 Setting_GenGroupItem_Data *list_item = data;
851 xmlNode* xmlObj = list_item->userdata;
854 const char *title = (char*)xmlSetProp(xmlObj, "value",entry_str_utf8);
856 __send_string_msg(xmlObj, entry_str_utf8);
857 __cfg_file_write((Draw_Data *)list_item->belongs_to);
859 FREE(entry_str_utf8);
863 static void __editbox_list_cb(void *data, Evas_Object *obj,
869 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
870 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
871 elm_genlist_item_selected_set(item, 0);
872 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
874 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
875 if (!elm_object_focus_get(list_item->eo_check)) {
876 elm_object_focus_set(list_item->eo_check, EINA_TRUE);
879 Ecore_IMF_Context *imf_context = (Ecore_IMF_Context *)elm_entry_imf_context_get(list_item->eo_check);
880 setting_retm_if(imf_context == NULL, "imf_context is NULL");
881 ecore_imf_context_input_panel_show(imf_context);
885 static void __editbox_changed_cb(void *data, Evas_Object *obj,
889 retm_if(!data || !obj, "Data parameter is NULL");
890 retm_if(!elm_object_focus_get(obj), "Entry is not focused");
892 Setting_GenGroupItem_Data *list_item =
893 (Setting_GenGroupItem_Data *) data;
895 const char *entry_str = elm_entry_entry_get(obj);
896 int entry_len = safeStrLen(entry_str);
897 SETTING_TRACE("entry_str:[%s], lenght:%d", entry_str, entry_len);
899 G_FREE(list_item->sub_desc);//release first
900 list_item->sub_desc = (char *)g_strdup(entry_str);
904 static void* editbox_func(void *data, xmlNode *xmlObj)
907 ret_if(!data || !xmlObj);
909 PluginNode* node = (PluginNode*)data;
910 Draw_Data *pd = node->pd;
912 const char *title = (char*)xmlGetProp(xmlObj, "title");
913 const char *key_str= (char*)xmlGetProp(xmlObj, "value");
917 Setting_GenGroupItem_Data *list_item =
918 setting_create_Gendial_field_def(pd->scroller, &(itc_1icon),
920 pd, SWALLOW_Type_LAYOUT_ENTRY,
921 NULL, NULL, 0, title, key_str,
922 __editbox_changed_cb);
924 list_item->userdata = xmlObj;
925 list_item->stop_change_cb = __entry_unfocus_cb;
926 list_item->belongs_to = (int)pd;
933 static void __expanditem_func_sel_cb(void *data, Evas_Object *obj, void *event_info)
937 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
938 Elm_Object_Item *subitem = (Elm_Object_Item *) event_info;
939 Elm_Object_Item *parentItem = elm_genlist_item_parent_get(subitem);
940 elm_genlist_item_selected_set(subitem, 0);
941 Setting_GenGroupItem_Data *data_subItem = elm_object_item_data_get(subitem);
942 Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem); /* parent data */
943 ret_if(NULL == data_subItem || NULL == data_parentItem);
945 elm_radio_value_set(data_subItem->rgd, data_subItem->chk_status);
947 data_parentItem->sub_desc = (char *)g_strdup(_(data_subItem->keyStr));
948 elm_object_item_data_set(data_parentItem->item, data_parentItem);
949 elm_genlist_item_update(data_parentItem->item);
951 xmlNode* xmlObj = data_parentItem->userdata;
955 //newattr = xmlSetProp(xmlObj, "string", data_parentItem->sub_desc);
956 newattr = xmlSetProp(xmlObj, "value", data_parentItem->sub_desc);
958 __send_string_msg(xmlObj, data_parentItem->sub_desc);
959 __cfg_file_write((Draw_Data *)data_parentItem->belongs_to);
963 static void __expanditem_func_exp_cb(void *data, Evas_Object *obj, void *event_info)
965 ret_if(NULL == data || NULL == event_info);
968 PluginNode* node = (PluginNode*)data;
969 Draw_Data *pd = node->pd;
971 Elm_Object_Item *parentItem = event_info; /* parent item */
972 Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem); /* parent data */
973 Evas_Object *scroller = elm_object_item_widget_get(parentItem);
976 xmlNode *xmlObj = data_parentItem->userdata;
977 //char *value = (char*)xmlGetProp(xmlObj, "string");
978 char *value = (char*)xmlGetProp(xmlObj, "value");
979 SETTING_TRACE(">>> value = %s", value);
981 Evas_Object *rgd = NULL;
983 if (xmlObj->children && !data_parentItem->rgd) {//to protect from entering repeatly
984 xmlNode* cur = xmlObj->children;
986 rgd = elm_radio_add(scroller);
987 elm_radio_value_set(rgd, -1);
991 char *subitem_title = NULL;
992 int subitem_index = 0;
995 while (cur != NULL) {
996 if (!xmlStrcmp(cur->name, (const xmlChar*)"expanditem")) {
997 type = (char*)xmlGetProp(cur, "type");
998 if (0 == safeStrCmp(type, "radio")) {
999 subitem_title = (char*)xmlGetProp(cur, "title");
1000 Setting_GenGroupItem_Data *list_item =
1001 setting_create_Gendial_exp_sub_field(scroller,
1002 &(itc_1icon_1text_sub),
1003 __expanditem_func_sel_cb, NULL, parentItem,
1004 SWALLOW_Type_1RADIO, rgd,
1006 subitem_title, NULL);
1008 // SETTING_TRACE(">>> value = %s, subitem_title = %s ", value, subitem_title);
1010 if (0 == safeStrCmp(value, subitem_title)) {
1011 sel_idx = subitem_index;
1012 SETTING_TRACE("%d is selected in Radio Group", sel_idx);
1014 data_parentItem->childs = eina_list_append(data_parentItem->childs, list_item);
1018 SETTING_TRACE("invalid type[:%s]", type);
1027 elm_radio_value_set(rgd, sel_idx);
1028 data_parentItem->rgd = rgd;//protecting condition
1033 static void __expanditem_func_smart_cb(void *data, Evas_Object *obj, void *event_info)
1035 ret_if(data == NULL || event_info == NULL);
1036 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
1037 Setting_GenGroupItem_Data *data_item = elm_object_item_data_get(item);
1038 char *cb_type = data;
1040 if (0 == safeStrCmp(cb_type, "contracted")) {
1041 data_item->rgd = NULL;
1042 elm_genlist_item_subitems_clear(item);
1047 static void* settings_func(void *data, xmlNode *xmlObj)
1053 static void* setting_func(void *data, xmlNode *xmlObj)
1055 SETTING_TRACE_BEGIN;
1056 ret_if(!data || !xmlObj);
1059 //Draw_Data *pd = node->pd;
1060 PluginNode* node = (PluginNode*)data;
1061 Draw_Data *pd = node->pd;
1063 //----------------------------------------------------------------
1064 // [DATA] title, btn[0], btn[1]
1065 const char *title = (char*)xmlGetProp(xmlObj, "title");
1066 char *btn[2] = {/* 0 */"OK", /* 1 */"NO"};
1068 // find child nodes named 'elements'
1070 if (xmlObj->children) {
1071 xmlNode* cur = xmlObj->children;
1075 if (!xmlStrcmp(cur->name, (const xmlChar*)"button")) {
1076 btn[i] = xmlGetProp(cur, "title");
1077 SETTING_TRACE("------>>> node type : Element, name=%s id=%s / btn[%d] = %s ",
1078 cur->name,xmlGetProp(cur, "id"),
1087 //----------------------------------------------------------------
1088 SETTING_TRACE("before setting_create_layout_navi_bar_genlist");
1090 pd->scroller = elm_genlist_add(pd->win_get);
1091 retvm_if(pd->scroller == NULL, NULL,
1092 "Cannot set scroller object as contento of layout");
1093 elm_object_style_set(pd->scroller, "dialogue");
1094 elm_genlist_clear(pd->scroller); /* first to clear list */
1096 /* Enabling illume notification property for window */
1097 elm_win_conformant_set(pd->win_get, 1);
1098 Evas_Object *conformant = elm_conformant_add(pd->win_get);
1099 elm_object_style_set(conformant, "internal_layout"); /* By Kollus. 2011-01-04 */
1100 evas_object_show(conformant);
1101 elm_object_content_set(conformant, pd->scroller);
1103 SETTING_TRACE("_(title):%s", _(title));
1105 setting_create_layout_navi_bar(pd->win_get, pd->win_get,
1107 _("IDS_COM_BODY_BACK"), NULL, NULL,
1108 ___click_softkey_back_cb,
1111 &(pd->navi_bar), NULL);
1112 SETTING_TRACE("after setting_create_layout_navi_bar_genlist");
1119 static void* expanditem_func(void *data, xmlNode *xmlObj)
1121 // DO NOTHING - expandlist draws this area
1125 static void* expandlist_func(void *data, xmlNode *xmlObj)
1127 SETTING_TRACE_BEGIN;
1128 ret_if(!data || !xmlObj);
1130 PluginNode* node = (PluginNode*)data;
1131 Draw_Data *pd = node->pd;
1133 const char *key_str = (char*)xmlGetProp(xmlObj, "title");
1134 const char *value = (char*)xmlGetProp(xmlObj, "value"); // string -> value
1136 setting_enable_expandable_genlist(pd->scroller, data, __expanditem_func_exp_cb, __expanditem_func_smart_cb);
1137 Setting_GenGroupItem_Data *list_item =
1138 setting_create_Gendial_exp_parent_field(pd->scroller,
1139 &(itc_2text_3_parent),
1141 SWALLOW_Type_INVALID,
1145 list_item->userdata = xmlObj;
1146 list_item->belongs_to = (int)pd;
1154 static int __node_walker(PluginNode* context, xmlNode* cur)
1156 //SETTING_TRACE_BEGIN;
1157 Draw_Data *pd = context->pd;
1160 xmlNode *cur_node = NULL;
1161 for (cur_node = cur; cur_node;cur_node = cur_node->next) {
1162 if (cur_node->type == XML_ELEMENT_NODE) {
1163 SETTING_TRACE("node type : %s id= %s", cur_node->name,xmlGetProp(cur_node, "id"));
1165 drawer_fp fp = __drawer_find(cur_node->name);
1169 void* vret = fp(context, cur_node); // draw it
1173 Setting_GenGroupItem_Data* genlist_node = (Setting_GenGroupItem_Data* )vret;
1174 //SETTING_TRACE("add node to Eina List name : %s, id : ", cur_node->name, xmlGetProp(cur_node, "id"));
1175 // add it to the hash table create before.
1178 char* key_name = xmlGetProp(cur_node, "id");
1179 eina_hash_add(context->ui_list, strdup(key_name),(void*)genlist_node);
1183 __node_walker(context, cur_node->children); /* RECURSIVE */
1189 * @param id_str [in] "id"
1190 * @param value [in] value to be udpated
1191 * @see __expanditem_func_sel_cb
1193 static int __node_finder(PluginNode* context, xmlNode* cur, char* id_str, char* value, bool* is_end)
1195 SETTING_TRACE_BEGIN;
1196 xmlNode *cur_node = NULL;
1198 if (*is_end == true) return 0;
1200 for (cur_node = cur; cur_node;cur_node = cur_node->next) {
1201 if (cur_node->type == XML_ELEMENT_NODE) {
1203 char* id_name = (char*)xmlGetProp(cur_node, "id");
1204 if ( id_name && 0 == strcmp(id_str, id_name))
1206 SETTING_TRACE("FOUND >>>> %s", id_name);
1207 // cur_node - update xml code
1208 xmlAttrPtr newattr = xmlSetProp(cur_node, "value", value);
1210 //-----------------------------------------------------------
1213 if ( 0 == strcmp (cur_node->name, "integer"))
1215 SETTING_TRACE(">>>>> UPDATE SLIDER CONTROL %x --- %s ",context->ui_list, id_name);
1216 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1219 item_to_update->chk_status = atoi(value);
1220 SETTING_TRACE(">>> o-------------0 SLIDER VALUE = %d ", item_to_update->chk_status);
1222 elm_object_item_data_set(item_to_update->item, item_to_update);
1223 elm_genlist_item_update(item_to_update->item);
1225 SETTING_TRACE("item_to_update is NULL");
1229 if ( 0 == strcmp (cur_node->name, "bool"))
1231 SETTING_TRACE(">>>>> UPDATE TOGGLE CONTROL %x --- %s ",context->ui_list, id_name);
1232 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1235 item_to_update->chk_status = atoi(value);
1236 SETTING_TRACE(">>> o-------------0 TOGGLE VALUE = %d ", item_to_update->chk_status);
1238 elm_object_item_data_set(item_to_update->item, item_to_update);
1239 elm_genlist_item_update(item_to_update->item);
1241 SETTING_TRACE("item_to_update is NULL");
1244 // case : edit control
1245 if ( 0 == strcmp (cur_node->name, "string"))
1247 SETTING_TRACE(">>>>> UPDATE EDIT CONTROL CONTROL %x --- %s ",context->ui_list, id_name);
1248 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1251 char* old_string = item_to_update->sub_desc;
1252 item_to_update->sub_desc = strdup(value);
1253 SETTING_TRACE(">>> o-------------0 STRING VALUE = %s ", value);
1257 elm_object_item_data_set(item_to_update->item, item_to_update);
1258 elm_genlist_item_update(item_to_update->item);
1261 SETTING_TRACE("item_to_update is NULL");
1264 // case : expand list
1270 //-----------------------------------------------------------
1271 if ( 0 == strcmp (cur_node->name, "expandlist"))
1273 SETTING_TRACE(">>>>> UPDATE EXPAND LIST CONTROL %x --- %s ",context->ui_list, id_name);
1274 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1277 char* old_string = item_to_update->sub_desc;
1278 item_to_update->sub_desc = strdup(value);
1279 SETTING_TRACE(">>> o-------------0 EXPAND LIST VALUE = %s ", value);
1283 elm_object_item_data_set(item_to_update->item, item_to_update);
1284 elm_genlist_item_update(item_to_update->item);
1286 // TODO: need to update child elements
1287 // item_to_update->childs ---> expanded list
1288 if (item_to_update->childs)
1290 Eina_List *li = item_to_update->childs;
1291 int radio_index = 0;
1294 Setting_GenGroupItem_Data* node = eina_list_data_get(li);
1295 // do something more
1296 // SETTING_TRACE(">>> RADIO LIST STRING VALUE = %s ", node->keyStr);
1297 // set position of radio button
1298 if (strcmp(node->keyStr, value) == 0)
1300 elm_radio_value_set(node->rgd, radio_index);
1302 elm_object_item_data_set(item_to_update->item, item_to_update);
1303 elm_genlist_item_update(item_to_update->item);
1306 li = eina_list_next(li);
1312 SETTING_TRACE("item_to_update is NULL");
1319 __node_finder(context, cur_node->children, id_str, value, is_end); /* RECURSIVE */
1324 static unsigned int _plugin_string_key_length(const char*key)
1329 return (int)strlen(key) + 1;
1332 static int _plugin_string_key_cmp(const char* key1, int key1_length,
1333 const char* key2, int key2_length)
1335 return strcmp(key1, key2);
1338 static void _plugin_entry_free_cb(void* data)
1340 Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) data;
1343 eina_list_free(node->childs);
1344 node->childs = NULL;
1348 //static PluginNode* g_context;
1350 PluginNode* setting_plugin_create()
1352 PluginNode *node = calloc(1, sizeof(PluginNode));
1354 Draw_Data *pd = calloc(1, sizeof(Draw_Data));
1355 setting_retvm_if(!pd, -1, "Create Draw_Data obj failed");
1359 node->ui_list = eina_hash_new(EINA_KEY_LENGTH(_plugin_string_key_length),
1360 EINA_KEY_CMP(_plugin_string_key_cmp),
1361 EINA_KEY_HASH(eina_hash_superfast),
1362 _plugin_entry_free_cb,
1368 void setting_plugin_destroy(PluginNode* node)
1370 SETTING_TRACE_BEGIN;
1372 SETTING_TRACE("node is NOT NULL")
1374 SETTING_TRACE("node->pd is NOT NULL")
1375 if(node->pd->doc != NULL) {
1376 xmlSaveFormatFile(node->plugin_path, node->pd->doc, 1);
1377 xmlFreeDoc(node->pd->doc);
1378 node->pd->doc = NULL;
1379 SETTING_TRACE("__cfg_file_write successful");
1386 if (node->ui_list) {
1387 eina_hash_free(node->ui_list);
1388 node->ui_list = NULL;
1396 static Eina_Bool _plugin_foreach_cb(const Eina_Hash *hash, const void*key, void* data, void* fdata)
1398 Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) data;
1399 SETTING_TRACE("%s --- %s ", (char*)key, node->keyStr);
1404 void setting_plugin_debug(PluginNode* context)
1406 // SETTING_TRACE("HASH TABLE -------------------------------------");
1407 eina_hash_foreach(context->ui_list,_plugin_foreach_cb, NULL);
1408 // SETTING_TRACE("HASH TABLE -------------------------------------");
1412 void setting_plugin_update(PluginNode* context)
1414 Eina_List *li = context->ui_list;
1417 Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) eina_list_data_get(li);
1419 // SETTING_TRACE(" ---> keyStr : %s , swallow type : %d ", node->keyStr, node->swallow_type);
1420 Setting_GenGroupItem_Data* item_to_update = NULL;
1421 item_to_update = node;
1422 elm_object_item_data_set(item_to_update->item, item_to_update);
1423 elm_genlist_item_update(item_to_update->item);
1425 li = eina_list_next(li);
1430 bool setting_plugin_load(PluginNode* context, const char *cfg_file)
1432 SETTING_TRACE("cfg_file:%s", cfg_file)
1433 if (isEmptyStr(cfg_file) || 0 != access(cfg_file, R_OK|W_OK|F_OK ))
1435 SETTING_TRACE_ERROR(" error occured : access \n");
1438 context->pd->cfg_file = cfg_file;
1439 context->pd->win_get = (Evas_Object *) ug_get_window();
1441 GError *error = NULL;
1443 context->pd->doc = xmlParseFile(cfg_file);
1444 context->pd->root = xmlDocGetRootElement(context->pd->doc);
1446 // TODO: error handler here
1447 __node_walker(context, context->pd->root);
1450 setting_plugin_debug(context);