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;
47 * @return Evas_Object * obj
49 static void* navigationbar_func(void *data, xmlNode *xmlObj);
55 static void* group_func(void *data, xmlNode *xmlObj);
58 * @return Setting_GenGroupItem_Data* ptr
60 static void* link_func(void *data, xmlNode *xmlObj);
63 * @return Setting_GenGroupItem_Data* ptr
65 static void* slider_func(void *data, xmlNode *xmlObj);
68 * @return Setting_GenGroupItem_Data* ptr
70 static void* label_func(void *data, xmlNode *xmlObj);
73 * @return Setting_GenGroupItem_Data* ptr
75 static void* checkbox_func(void *data, xmlNode *xmlObj);
78 * @return Setting_GenGroupItem_Data* ptr
80 static void* editbox_func(void *data, xmlNode *xmlObj);
83 * @return Setting_GenGroupItem_Data* ptr
85 static void* expandlist_func(void *data, xmlNode *xmlObj);
90 static void* expanditem_func(void *data, xmlNode *xmlObj);
95 static void* settings_func(void *data, xmlNode *xmlObj);
98 static void* launch_func(void *data, xmlNode *xmlObj);
103 static void* setting_func(void *data, xmlNode *xmlObj);
105 static int __node_walker(PluginNode* context, xmlNode* cur);
107 static int __node_finder(PluginNode* context, xmlNode* cur, char* id_str, char* value, bool* is_end);
110 static void __drawer_add(const char *type, drawer_fp draw)
112 Object_Drawer *node = calloc(1, sizeof(Object_Drawer));
113 if (node && type && draw)
118 _g_drawer_list = eina_list_append(_g_drawer_list, node);
125 static drawer_fp __drawer_find(char* type)
128 SETTING_TRACE("node type:%s", type);
129 Eina_List *check_list = _g_drawer_list;
130 Object_Drawer *list_item = NULL;
133 list_item = (Object_Drawer *) eina_list_data_get(check_list);
134 if (NULL == list_item)
137 if (0 == safeStrCmp(list_item->type, type))
139 //SETTING_TRACE("list_item->type:%s", list_item->type);
142 //if not matched,to check next node.
143 check_list = eina_list_next(check_list);
146 //SETTING_TRACE("list_item:%p", list_item);
147 return list_item ? list_item->draw : NULL;
149 void setting_drawer_list_init()
153 /* <navigationbar> */__drawer_add("navigationbar", navigationbar_func);
155 /* <bool> */__drawer_add("bool", checkbox_func);
156 /* <string> */__drawer_add("string", editbox_func);
157 /* <group> */__drawer_add("group", group_func);
158 /* <integer> */__drawer_add("integer", slider_func);
159 /* <label> */__drawer_add("label", label_func);
160 /* <link> */__drawer_add("link", link_func);
161 /* <launch> */__drawer_add("launch", launch_func);
162 /* <extendlist> */__drawer_add("expandlist", expandlist_func);
163 /* <extenditem> */__drawer_add("expanditem", expanditem_func);
164 /* <settings> */__drawer_add("settings", settings_func);
165 /* <setting> */__drawer_add("setting", setting_func);
168 void setting_drawer_list_fini()
172 Object_Drawer *node = NULL;
173 Eina_List *li = _g_drawer_list;
175 node = (Object_Drawer *) eina_list_data_get(li);
178 //SETTING_TRACE("Deregister %s", node->type);
181 li = eina_list_next(li);
183 _g_drawer_list = eina_list_free(_g_drawer_list);
184 _g_drawer_list = NULL;
188 /////////////////////////
189 /////////////////////////
190 /////////////////////////
192 #define MAX_CONTENT_LEN 512
193 #define MAX_LOCAL_BUFSIZE 128
194 #define DBUS_PATH "/setting/dbus_handler"
195 #define DBUS_SIGNAL_INTERFACE "org.tizen.setting.signal"
197 #define APPID_LENGTH 10
198 #define APPID_POS_FROM_PATH 10
200 static char* s_pkg_name;
203 static char* substring(const char* str, size_t begin, size_t len)
205 if (str == 0 || strlen(str) == 0 || strlen(str) < begin || strlen(str) < (begin+len))
208 return strndup(str + begin, len);
215 * ncbyusjryr.AppSetting --> package ID is ncbyusjryr
216 * "Update_" "ncbyusjryr"
218 static char* get_app_string(char* path)
221 char* temp = substring(path, APPID_POS_FROM_PATH, APPID_LENGTH/*string size*/);
222 SETTING_TRACE("package ID : >>> %s ",temp );
226 //------------------------------------------------------
228 static DBusConnection *bus;
229 //------------------------------------------------------
230 static DBusHandlerResult __signal_filter(DBusConnection* conn, DBusMessage* message, void* user_data)
232 int my_pid = getpid();
238 dbus_error_init(&error);
240 setting_main_appdata *ad = user_data;
242 char* pkg_name = get_app_string(ad->plugin_path);
244 char str_buf[MAX_COMMON_BUFFER_LEN];
245 snprintf(str_buf, MAX_COMMON_BUFFER_LEN, "Update_%s", pkg_name);
246 s_pkg_name = strdup(str_buf);
254 if (s_pkg_name == NULL)
256 SETTING_TRACE("s_pkg_name is NULL - it's abnormal operation");
257 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
259 SETTING_TRACE("s_pkg_name : %s ", s_pkg_name);
260 if (dbus_message_is_signal(message, DBUS_SIGNAL_INTERFACE, s_pkg_name))
262 if (dbus_message_get_args(message, &error,
263 DBUS_TYPE_UINT32, &sender_pid,
264 DBUS_TYPE_STRING, &key,
265 DBUS_TYPE_STRING, &value,
266 DBUS_TYPE_INVALID) == FALSE)
268 SETTING_TRACE_ERROR("Fail to get data : %s", error.message);
269 dbus_error_free(&error);
270 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
274 if (sender_pid != 0 && my_pid != sender_pid)
276 SETTING_TRACE("received key : %s , value : %s", key, value);
277 //-------------------------------------------------------------
278 // received key : checkbox1|N/A , value : INT|1
279 //-------------------------------------------------------------
280 //char* key = "checkbox1|N/A";
284 ptr = strchr(key, '|');
287 xmlDocPtr doc = NULL;
290 //parsing for : checkbox1|N/A -> checkbox1
291 char* key_name = substring(key, 0, strlen(key)-strlen(ptr));
292 char* val_name = strchr(value, '|');
297 doc = xmlParseFile(ad->plugin_path);
299 xmlNode *root = xmlDocGetRootElement(doc);
302 __node_finder((PluginNode*)ad->plugin_node, root, key_name ,val_name, &is_end);
305 GError *error = NULL;
310 xmlSaveFormatFile(ad->plugin_path, doc, 1);
311 // TODO: make sure this is right
314 SETTING_TRACE("__cfg_file_write successful");
321 return DBUS_HANDLER_RESULT_HANDLED;
324 static int __send_msg(char* key, char* value)
326 DBusMessage* message;
328 int sender_pid = getpid();
333 if (s_pkg_name == NULL)
335 SETTING_TRACE("s_pkg_name is NULL - it's abnormal operation");
339 message = dbus_message_new_signal(DBUS_PATH, DBUS_SIGNAL_INTERFACE, s_pkg_name);
341 SETTING_TRACE("Sending message[%s:%s] via dbus", key ,value);
342 if (dbus_message_append_args(message,
343 DBUS_TYPE_UINT32, &sender_pid,
344 DBUS_TYPE_STRING, &key,
345 DBUS_TYPE_STRING, &value,
346 DBUS_TYPE_INVALID) == FALSE)
348 SETTING_TRACE("Fail to load data error");
352 if (dbus_connection_send(bus, message, NULL) == FALSE)
354 SETTING_TRACE("Fail to send message");
358 dbus_connection_flush(bus);
359 dbus_message_unref(message);
361 SETTING_TRACE("[CLIENT] send data signal done");
367 static void __send_int_msg(xmlNode* xmlObj, int val)
369 const char *id = (char*)xmlGetProp(xmlObj, "id");
370 const char *title = (char*)xmlGetProp(xmlObj, "title");
371 char key[MAX_CONTENT_LEN] = {0,};
372 snprintf(key, sizeof(key), "%s|%s", id, title);
374 char value[MAX_CONTENT_LEN] = {0,};
375 snprintf(value, sizeof(value), "INT|%d", val);
376 __send_msg(key, value);
380 static void __send_string_msg(xmlNode* xmlObj, char *string)
382 const char *id = (char*)xmlGetProp(xmlObj, "id");
383 const char *title = (char*)xmlGetProp(xmlObj, "title");
384 char key[MAX_CONTENT_LEN] = {0,};
385 snprintf(key, sizeof(key), "%s|%s", id, title);
387 char value[MAX_CONTENT_LEN] = {0,};
388 snprintf(value, sizeof(value), "STRING|%s", string);
389 __send_msg(key, value);
393 int setting_dbus_handler_init(void* user_data)
398 SETTING_TRACE("already get a bus, need release first.");
399 setting_dbus_handler_fini();
402 memset(&error, 0, sizeof(DBusError));
403 char rule[MAX_LOCAL_BUFSIZE + 1] = {0,};
404 dbus_error_init(&error);
405 bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
408 SETTING_TRACE("Fail to connect to the D-BUS daemon: %s", error.message);
409 dbus_error_free(&error);
413 dbus_connection_setup_with_g_main(bus, NULL);
414 snprintf(rule, MAX_LOCAL_BUFSIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH, DBUS_SIGNAL_INTERFACE);
416 dbus_bus_add_match(bus, rule, &error);
417 if (dbus_error_is_set(&error))
419 SETTING_TRACE("Fail to rule set; %s", error.message);
420 dbus_bus_remove_match(bus, rule, &error);
421 dbus_error_free(&error);
422 dbus_connection_close(bus);
427 if (dbus_connection_add_filter(bus, __signal_filter, user_data, NULL) == FALSE)
429 dbus_bus_remove_match(bus, rule, &error);
430 dbus_error_free(&error);
431 dbus_connection_close(bus);
436 SETTING_TRACE("app signal initialized");
440 int setting_dbus_handler_fini(void)
442 //do safty checking first.
443 setting_retvm_if(!bus, 0, "!bus");
445 memset(&error, 0, sizeof(DBusError));
446 char rule[MAX_LOCAL_BUFSIZE + 1] = {0, };
448 dbus_error_init(&error);
449 //dbus_connection_remove_filter(bus, __signal_filter, NULL);
450 snprintf(rule, MAX_LOCAL_BUFSIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH, DBUS_SIGNAL_INTERFACE);
451 dbus_bus_remove_match(bus, rule, &error);
453 if (dbus_error_is_set(&error))
455 SETTING_TRACE("Fail to rule unset: %s", error.message);
456 dbus_error_free(&error);
460 dbus_connection_close(bus);
462 SETTING_TRACE("app signal finalized");
466 /////////////////////////////
467 /////////////////////////////
468 /////////////////////////////
470 Elm_Genlist_Item_Class itc_layout;
473 static int __cfg_file_write(Draw_Data *pd)
477 GError *error = NULL;
480 xmlSaveFormatFile(pd->cfg_file, pd->doc, 1);
481 //xmlFreeDoc(pd->doc);
483 SETTING_TRACE("__cfg_file_write successful");
490 static void ___click_softkey_back_cb(void *data, Evas_Object *obj,
496 PluginNode* node = (PluginNode*)data;
497 Draw_Data *pd = node->pd;
499 evas_object_del(pd->ly_main);
503 setting_plugin_destroy(node);
516 static void* group_func(void *data, xmlNode *xmlObj)
519 retv_if(!data || !xmlObj, NULL);
521 PluginNode* node = (PluginNode*)data;
522 Draw_Data *pd = node->pd;
524 // original code is non-recursive
526 const char *title = (char*)json_object_get_string_member(jsonObj, "title");
527 (void)setting_create_Gendial_field_titleItem(pd->scroller,
531 // non recursive method
532 if (json_object_has_member(jsonObj, "elements"))
534 JsonNode* elements_node = json_object_get_member(jsonObj, "elements");
538 for (i=0; i < json_array_get_length(json_node_get_array(elements_node)); i++)
540 tempobj = json_array_get_object_element(json_node_get_array(elements_node), i);
541 type = (char*)json_object_get_string_member(tempobj, "type");
542 drawer_fp fp = __drawer_find(type);
543 if (fp) fp(pd, tempobj); // draw it
547 // new code is recursive
548 const char *title = (char*)xmlGetProp(xmlObj, "title");
549 SETTING_TRACE (" >>> GROUP NAME : %s \n", title);
550 (void)setting_create_Gendial_field_titleItem(pd->scroller, &(itc_group_item), title, NULL);
557 static void* __link_list_cb(void *data, Evas_Object *obj, void *event_info)
560 retv_if(data == NULL, NULL);
561 retvm_if(event_info == NULL, NULL, "Invalid argument: event info is NULL");
562 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
563 elm_genlist_item_selected_set(item, 0);
564 Setting_GenGroupItem_Data *list_item =
565 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
567 xmlNode* xmlObj = data;
568 retv_if(!xmlObj, NULL);
569 const char *link_file = (char*)xmlGetProp(xmlObj, "value");
573 SETTING_TRACE_ERROR("Invalidate liked file");
576 char file[1024] = {0,};
577 snprintf(file, sizeof(file), "%s/%s", PLUGIN_CFG_DIR, link_file);
578 SETTING_TRACE("file:%s", file);
580 PluginNode* plugin_node = setting_plugin_create();
581 setting_plugin_load(plugin_node, (const char *)file);
583 //setting_plugin_load(NULL, file);
588 static void* __launch_list_cb(void *data, Evas_Object *obj, void *event_info)
591 retv_if(data == NULL, NULL);
592 retvm_if(event_info == NULL, NULL, "Invalid argument: event info is NULL");
593 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
594 elm_genlist_item_selected_set(item, 0);
595 Setting_GenGroupItem_Data *list_item =
596 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
598 xmlNode* xmlObj = data;
599 retv_if(!xmlObj, NULL);
600 const char *key_str = (char*)xmlGetProp(xmlObj, "id");
601 const char *title_str = (char*)xmlGetProp(xmlObj, "title");
602 const char *appid_str = (char*)xmlGetProp(xmlObj, "appid");
603 const char *operation_str = (char*)xmlGetProp(xmlObj, "operation");
606 service_h svc = NULL;
607 service_create(&svc);
608 service_set_app_id(svc, appid_str); // xml property – appid
609 service_set_operation(svc, operation_str); // property : operation
610 service_send_launch_request(svc, NULL, NULL);
611 service_destroy(svc);
616 static void* label_func(void *data, xmlNode *xmlObj)
619 retv_if(!data || !xmlObj, NULL);
620 PluginNode* node = (PluginNode*)data;
621 Draw_Data *pd = node->pd;
623 const char *title = (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, NULL, NULL);
634 static void* link_func(void *data, xmlNode *xmlObj)
637 retv_if(!data || !xmlObj, NULL);
638 PluginNode* node = (PluginNode*)data;
639 Draw_Data *pd = node->pd;
641 const char *key_str = (char*)xmlGetProp(xmlObj, "id");
642 Setting_GenGroupItem_Data * obj =
643 setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
645 xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
646 0, key_str, NULL, NULL);
651 static void* launch_func(void *data, xmlNode *xmlObj)
654 retv_if(!data || !xmlObj, NULL);
655 PluginNode* node = (PluginNode*)data;
656 Draw_Data *pd = node->pd;
658 const char *title_str = (char*)xmlGetProp(xmlObj, "title");
660 Setting_GenGroupItem_Data * obj =
661 setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
663 xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
664 0, title_str, NULL, NULL);
669 static void __slider_stop_cb(void *data, Evas_Object *obj,
672 ret_if(data == NULL || obj == NULL);
673 double val = elm_slider_value_get(obj);
674 SETTING_TRACE("val = %f", val);
675 Setting_GenGroupItem_Data *list_item = data;
676 ret_if(list_item->userdata == NULL);
678 xmlNode* xmlObj = list_item->userdata;
681 //apply the vconf changes after stopping moving slider..
682 list_item->chk_status = (int)(val + 0.5);
683 elm_slider_value_set(obj, list_item->chk_status);
685 SETTING_TRACE(" slider after ---> val = %d", (int) list_item->chk_status);
687 // int -> double -> xmlChar*
690 sprintf(buf, "%d", (int) list_item->chk_status);
691 newattr = xmlSetProp(xmlObj, "value", buf);
693 __send_int_msg(xmlObj, list_item->chk_status);
694 __cfg_file_write((Draw_Data *)list_item->belongs_to);
698 static void* slider_func(void *data, xmlNode *xmlObj)
701 retv_if(!data || !xmlObj, NULL);
702 PluginNode* node = (PluginNode*)data;
703 Draw_Data *pd = node->pd;
706 const char *title = (char*)xmlGetProp(xmlObj, "title");
708 SETTING_TRACE (" >>> [slider input] min=%s max=%s value=%s ",(char*)xmlGetProp(xmlObj, "min"), (char*)xmlGetProp(xmlObj, "max"), (char*)xmlGetProp(xmlObj, "value"));
710 int value = atoi((char*)xmlGetProp(xmlObj, "value"));
711 int min = atoi((char*)xmlGetProp(xmlObj, "min"));
712 int max = atoi((char*)xmlGetProp(xmlObj, "max"));
714 SETTING_TRACE ("[slider input] min=%d max=%d value=%d ", min, max, value);
716 setting_create_Gendial_itc("dialogue/1text.1icon.5", &(itc_layout));
717 Setting_GenGroupItem_Data *list_item =
718 setting_create_Gendial_field_def(pd->scroller, &(itc_layout), NULL,
720 SWALLOW_Type_LAYOUT_SLIDER,
721 IMG_SENSITIVITY_ICON_01,
722 IMG_SENSITIVITY_ICON_02, value,
725 list_item->win_main = NULL;
726 list_item->evas = NULL;
727 list_item->isIndicatorVisible = true;
728 list_item->slider_min = min;
729 list_item->slider_max = max;
730 list_item->userdata = xmlObj;
731 list_item->stop_change_cb = __slider_stop_cb;
732 list_item->belongs_to = (int)pd;
735 g_list_item = list_item;
737 return (void*)list_item;
742 elm_object_item_data_set(item_to_update->item, item_to_update);
743 elm_genlist_item_update(item_to_update->item);
745 static void* navigationbar_func(void *data, xmlNode *xmlObj)
749 ret_if(!data || !xmlObj);
751 PluginNode* node = (PluginNode*)data;
752 Draw_Data *pd = node->pd;
754 //----------------------------------------------------------------
755 // [DATA] title, btn[0], btn[1]
756 const char *title = (char*)xmlGetProp(xmlObj, "title");
757 char *btn[2] = {0, };
759 // find child nodes named 'elements'
760 if (xmlObj->children) {
761 xmlNode* cur = xmlObj->children;
765 if (!xmlStrcmp(cur->name, (const xmlChar*)"button")) {
766 btn[i] = xmlGetProp(cur, "title");
767 SETTING_TRACE("------>>> node type : Element, name=%s id=%s / btn[%d] = %s ",
768 cur->name,xmlGetProp(cur, "id"),
776 //----------------------------------------------------------------
778 pd->ly_main = setting_create_layout_navi_bar_genlist(pd->win_get,
781 _(btn[1]), _(btn[0]),
782 ___click_softkey_back_cb,
783 ___click_softkey_back_cb, data, &pd->scroller,
791 static void __check_mouse_up_cb(void *data, Evas_Object *obj,
796 setting_retm_if(data == NULL, "Data parameter is NULL");
798 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
799 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
800 elm_genlist_item_selected_set(item, 0);
801 Setting_GenGroupItem_Data *list_item =
802 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
804 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
806 int old_status = elm_check_state_get(list_item->eo_check);
807 list_item->chk_status = !old_status;
808 elm_check_state_set(list_item->eo_check, list_item->chk_status);
810 xmlNode *xmlObj = data;
812 newattr = xmlSetProp(xmlObj, "state", xmlXPathCastNumberToString(list_item->chk_status));
814 __send_int_msg(xmlObj, list_item->chk_status);
815 __cfg_file_write((Draw_Data *)list_item->belongs_to);
819 static void __chk_btn_cb(void *data, Evas_Object *obj,
824 retm_if(data == NULL, "Data parameter is NULL");
825 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
827 xmlNode* xmlObj = list_item->userdata;
829 list_item->chk_status = elm_check_state_get(obj); /* for genlist update status */
832 if (list_item->chk_status == 1) {
833 newattr = xmlSetProp(xmlObj, "value", "true");
834 } else if (list_item->chk_status == 0) {
835 newattr = xmlSetProp(xmlObj, "value", "false");
837 newattr = xmlSetProp(xmlObj, "value", "false");
840 const char *id = (char*)xmlGetProp(xmlObj, "id");
841 const char *title = (char*)xmlGetProp(xmlObj, "title");
842 //SETTING_TRACE(" >>>> id:%s , title:%s", id, title);
843 __send_int_msg(xmlObj, list_item->chk_status);
844 __cfg_file_write((Draw_Data *)list_item->belongs_to);
849 static void* checkbox_func(void *data, xmlNode *xmlObj)
852 retv_if(!data || !xmlObj, NULL);
854 PluginNode* node = (PluginNode*)data;
855 Draw_Data *pd = node->pd;
857 // [DATA] title, value
858 const char *title = (char*)xmlGetProp(xmlObj, "title");
861 char* value = (char*)xmlGetProp(xmlObj, "value");
865 if ( 0 == safeStrCmp(value, "true")) {
867 } else if ( 0 == safeStrCmp(value, "false")) {
870 ival = 0; // default : false (0)
873 // title, value, xmlObj
874 Setting_GenGroupItem_Data *list_item =
875 setting_create_Gendial_field_def(pd->scroller,
879 SWALLOW_Type_1TOGGLE,
886 list_item->userdata = xmlObj;
887 list_item->belongs_to = (int) pd;
888 SETTING_TRACE("pd:%p,list_item->belongs_to:%d", pd, list_item->belongs_to);
895 static void __entry_unfocus_cb(void *data, Evas_Object *obj, void *event_info)
898 retm_if(!data || !obj, "Data parameter is NULL");
900 setting_hide_input_pannel_cb(obj);
901 const char *entry_str = elm_entry_entry_get(obj);
902 char *entry_str_utf8 = NULL;
903 entry_str_utf8 = elm_entry_markup_to_utf8(entry_str);
905 Setting_GenGroupItem_Data *list_item = data;
907 xmlNode* xmlObj = list_item->userdata;
909 FREE(entry_str_utf8);
914 const char *title = (char*)xmlSetProp(xmlObj, "value",entry_str_utf8);
916 __send_string_msg(xmlObj, entry_str_utf8);
917 __cfg_file_write((Draw_Data *)list_item->belongs_to);
919 FREE(entry_str_utf8);
923 static void __editbox_list_cb(void *data, Evas_Object *obj,
929 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
930 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
931 elm_genlist_item_selected_set(item, 0);
932 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
934 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
935 if (!elm_object_focus_get(list_item->eo_check)) {
936 elm_object_focus_set(list_item->eo_check, EINA_TRUE);
939 Ecore_IMF_Context *imf_context = (Ecore_IMF_Context *)elm_entry_imf_context_get(list_item->eo_check);
940 setting_retm_if(imf_context == NULL, "imf_context is NULL");
941 ecore_imf_context_input_panel_show(imf_context);
945 static void __editbox_changed_cb(void *data, Evas_Object *obj,
949 retm_if(!data || !obj, "Data parameter is NULL");
950 retm_if(!elm_object_focus_get(obj), "Entry is not focused");
952 Setting_GenGroupItem_Data *list_item =
953 (Setting_GenGroupItem_Data *) data;
955 const char *entry_str = elm_entry_entry_get(obj);
956 int entry_len = safeStrLen(entry_str);
957 SETTING_TRACE("entry_str:[%s], lenght:%d", entry_str, entry_len);
959 G_FREE(list_item->sub_desc);//release first
960 list_item->sub_desc = (char *)g_strdup(entry_str);
964 static void* editbox_func(void *data, xmlNode *xmlObj)
967 retv_if(!data || !xmlObj, NULL);
969 PluginNode* node = (PluginNode*)data;
970 Draw_Data *pd = node->pd;
972 const char *title = (char*)xmlGetProp(xmlObj, "title");
973 const char *key_str= (char*)xmlGetProp(xmlObj, "value");
975 const char *minlength= (char*)xmlGetProp(xmlObj, "minlength");
976 const char *maxlength= (char*)xmlGetProp(xmlObj, "maxlength");
981 max_len = atoi(maxlength);
982 SETTING_TRACE(" >> MAXLENGTH FILTER IS AVAILABLE !!!! maxlength = %d", max_len);
985 Setting_GenGroupItem_Data *list_item = NULL;
989 // without maxlength filter
990 list_item = setting_create_Gendial_field_def(pd->scroller, &(itc_1icon),
992 pd, SWALLOW_Type_LAYOUT_ENTRY,
993 NULL, NULL, 0, title, key_str,
994 __editbox_changed_cb);
997 // add max length filter
998 list_item = setting_create_Gendial_field_entry(
1003 SWALLOW_Type_LAYOUT_ENTRY,
1004 NULL, NULL, 0, title, key_str, __editbox_changed_cb,
1005 ELM_INPUT_PANEL_LAYOUT_NORMAL,
1014 list_item->userdata = xmlObj;
1015 list_item->stop_change_cb = __entry_unfocus_cb;
1016 list_item->belongs_to = (int)pd;
1023 static void __expanditem_func_sel_cb(void *data, Evas_Object *obj, void *event_info)
1025 SETTING_TRACE_BEGIN;
1027 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
1028 Elm_Object_Item *subitem = (Elm_Object_Item *) event_info;
1029 Elm_Object_Item *parentItem = elm_genlist_item_parent_get(subitem);
1030 elm_genlist_item_selected_set(subitem, 0);
1031 Setting_GenGroupItem_Data *data_subItem = elm_object_item_data_get(subitem);
1032 Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem); /* parent data */
1033 ret_if(NULL == data_subItem || NULL == data_parentItem);
1035 elm_radio_value_set(data_subItem->rgd, data_subItem->chk_status);
1037 data_parentItem->sub_desc = (char *)g_strdup(_(data_subItem->keyStr));
1038 elm_object_item_data_set(data_parentItem->item, data_parentItem);
1039 elm_genlist_item_update(data_parentItem->item);
1041 xmlNode* xmlObj = data_parentItem->userdata;
1045 //newattr = xmlSetProp(xmlObj, "string", data_parentItem->sub_desc);
1046 newattr = xmlSetProp(xmlObj, "value", data_parentItem->sub_desc);
1048 __send_string_msg(xmlObj, data_parentItem->sub_desc);
1049 __cfg_file_write((Draw_Data *)data_parentItem->belongs_to);
1053 static void __expanditem_func_exp_cb(void *data, Evas_Object *obj, void *event_info)
1055 ret_if(NULL == data || NULL == event_info);
1056 SETTING_TRACE_BEGIN;
1058 PluginNode* node = (PluginNode*)data;
1059 Draw_Data *pd = node->pd;
1061 Elm_Object_Item *parentItem = event_info; /* parent item */
1062 Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem); /* parent data */
1063 Evas_Object *scroller = elm_object_item_widget_get(parentItem);
1066 xmlNode *xmlObj = data_parentItem->userdata;
1067 //char *value = (char*)xmlGetProp(xmlObj, "string");
1068 char *value = (char*)xmlGetProp(xmlObj, "value");
1069 SETTING_TRACE(">>> value = %s", value);
1070 Evas_Object *rgd = NULL;
1072 if (xmlObj->children && !data_parentItem->rgd) {//to protect from entering repeatly
1073 xmlNode* cur = xmlObj->children;
1075 rgd = elm_radio_add(scroller);
1076 elm_radio_value_set(rgd, -1);
1079 char *subitem_title = NULL;
1080 int subitem_index = 0;
1083 while (cur != NULL) {
1084 if (!xmlStrcmp(cur->name, (const xmlChar*)"expanditem")) {
1085 type = (char*)xmlGetProp(cur, "type");
1086 if (0 == safeStrCmp(type, "radio")) {
1087 subitem_title = (char*)xmlGetProp(cur, "title");
1088 Setting_GenGroupItem_Data *list_item =
1089 setting_create_Gendial_exp_sub_field(scroller,
1090 &(itc_1icon_1text_sub),
1091 __expanditem_func_sel_cb, NULL, parentItem,
1092 SWALLOW_Type_1RADIO, rgd,
1094 subitem_title, NULL);
1096 // SETTING_TRACE(">>> value = %s, subitem_title = %s ", value, subitem_title);
1098 if (0 == safeStrCmp(value, subitem_title)) {
1099 sel_idx = subitem_index;
1100 SETTING_TRACE("%d is selected in Radio Group", sel_idx);
1102 data_parentItem->childs = eina_list_append(data_parentItem->childs, list_item);
1106 SETTING_TRACE("invalid type[:%s]", type);
1113 elm_radio_value_set(rgd, sel_idx);
1114 data_parentItem->rgd = rgd;//protecting condition
1119 static void __expanditem_func_smart_cb(void *data, Evas_Object *obj, void *event_info)
1121 ret_if(data == NULL || event_info == NULL);
1122 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
1123 Setting_GenGroupItem_Data *data_item = elm_object_item_data_get(item);
1124 char *cb_type = data;
1126 if (0 == safeStrCmp(cb_type, "contracted")) {
1127 data_item->rgd = NULL;
1128 elm_genlist_item_subitems_clear(item);
1133 static void* settings_func(void *data, xmlNode *xmlObj)
1139 static Evas_Object *setting_create_win_layout2(Evas_Object *win_layout, Evas_Object *win_obj)
1142 Evas_Object *layout = NULL;
1143 //Evas_Object *conform = elm_conformant_add(win_obj);
1144 //setting_main_appdata *ad = (setting_main_appdata *) data;
1147 layout = elm_layout_add(win_obj);
1148 //evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1149 setting_retvm_if(layout == NULL, FALSE, "layout == NULL");
1151 elm_layout_theme_set(layout, "layout", "application", "default");
1152 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1153 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
1154 //elm_win_resize_object_add(win_obj, conform);
1155 //elm_object_content_set(conform, layout);
1157 Evas_Object *bg = setting_create_bg(layout, win_obj, "group_list");
1158 elm_object_part_content_set(layout, "elm.swallow.bg", bg);
1159 evas_object_show(layout);
1160 //evas_object_show(conform);
1162 //ad->conformant = conform;
1167 Evas_Object *setting_create_layout_navi_bar2(Evas_Object *win_layout, Evas_Object *win_obj, char *title_str, char *lbutton_str, char *rbutton_str, char *mbutton_str, setting_call_back_func lbutton_click_cb, setting_call_back_func rbutton_click_cb, setting_call_back_func mbutton_click_cb, void *cb_data, Evas_Object *eo_view, /*any container obj constructed on any evas obj */
1168 Evas_Object **navi_bar,
1169 Evas_Object **titleobj)
1172 Evas_Object *layout = setting_create_win_layout2(win_layout, win_obj);
1173 *navi_bar = setting_create_navi_bar(layout);
1175 setting_create_navi_bar_buttons(title_str,
1176 lbutton_str, rbutton_str, mbutton_str,
1177 lbutton_click_cb, rbutton_click_cb,
1178 mbutton_click_cb, cb_data, eo_view /*content */ ,
1184 static void* setting_func(void *data, xmlNode *xmlObj)
1186 SETTING_TRACE_BEGIN;
1187 retv_if(!data || !xmlObj, NULL);
1190 PluginNode* node = (PluginNode*)data;
1191 Draw_Data *pd = node->pd;
1193 // [DATA] title, btn[0], btn[1]
1194 const char *title = (char*)xmlGetProp(xmlObj, "title");
1195 char *btn[2] = {/* 0 */"OK", /* 1 */"NO"};
1197 SETTING_TRACE("before setting_create_layout_navi_bar_genlist");
1200 pd->scroller = elm_genlist_add(pd->win_get);
1201 retvm_if(pd->scroller == NULL, NULL,
1202 "Cannot set scroller object as contento of layout");
1203 elm_object_style_set(pd->scroller, "dialogue");
1204 elm_genlist_clear(pd->scroller); /* first to clear list */
1207 SETTING_TRACE("_(title):%s", _(title));
1208 pd->ly_main = setting_create_layout_navi_bar2(pd->win_get, pd->win_get,
1210 _("IDS_COM_BODY_BACK"), NULL, NULL,
1211 ___click_softkey_back_cb,
1214 &(pd->navi_bar), NULL);
1215 SETTING_TRACE("after setting_create_layout_navi_bar_genlist");
1222 static void* expanditem_func(void *data, xmlNode *xmlObj)
1224 // DO NOTHING - expandlist draws this area
1228 static void* expandlist_func(void *data, xmlNode *xmlObj)
1230 SETTING_TRACE_BEGIN;
1231 retv_if(!data || !xmlObj, NULL);
1233 PluginNode* node = (PluginNode*)data;
1234 Draw_Data *pd = node->pd;
1236 const char *key_str = (char*)xmlGetProp(xmlObj, "title");
1237 const char *value = (char*)xmlGetProp(xmlObj, "value"); // string -> value
1239 setting_enable_expandable_genlist(pd->scroller, data, __expanditem_func_exp_cb, __expanditem_func_smart_cb);
1240 Setting_GenGroupItem_Data *list_item =
1241 setting_create_Gendial_exp_parent_field(pd->scroller,
1242 &(itc_2text_3_parent),
1244 SWALLOW_Type_INVALID,
1248 list_item->userdata = xmlObj;
1249 list_item->belongs_to = (int)pd;
1257 static int __node_walker(PluginNode* context, xmlNode* cur)
1259 //SETTING_TRACE_BEGIN;
1260 Draw_Data *pd = context->pd;
1263 xmlNode *cur_node = NULL;
1264 for (cur_node = cur; cur_node;cur_node = cur_node->next) {
1265 if (cur_node->type == XML_ELEMENT_NODE) {
1266 // SETTING_TRACE("node type : %s id= %s", cur_node->name,xmlGetProp(cur_node, "id"));
1267 drawer_fp fp = __drawer_find(cur_node->name);
1271 void* vret = fp(context, cur_node); // draw it
1275 Setting_GenGroupItem_Data* genlist_node = (Setting_GenGroupItem_Data* )vret;
1276 //SETTING_TRACE("add node to Eina List name : %s, id : ", cur_node->name, xmlGetProp(cur_node, "id"));
1277 // add it to the hash table create before.
1280 char* key_name = xmlGetProp(cur_node, "id");
1281 eina_hash_add(context->ui_list, strdup(key_name),(void*)genlist_node);
1285 __node_walker(context, cur_node->children); /* RECURSIVE */
1291 * @param id_str [in] "id"
1292 * @param value [in] value to be udpated
1293 * @see __expanditem_func_sel_cb
1295 static int __node_finder(PluginNode* context, xmlNode* cur, char* id_str, char* value, bool* is_end)
1297 SETTING_TRACE_BEGIN;
1298 xmlNode *cur_node = NULL;
1300 if (*is_end == true) return 0;
1302 for (cur_node = cur; cur_node;cur_node = cur_node->next) {
1303 if (cur_node->type == XML_ELEMENT_NODE) {
1305 char* id_name = (char*)xmlGetProp(cur_node, "id");
1306 if ( id_name && 0 == strcmp(id_str, id_name))
1308 SETTING_TRACE("FOUND >>>> %s", id_name);
1309 // cur_node - update xml code
1310 xmlAttrPtr newattr = xmlSetProp(cur_node, "value", value);
1312 //-----------------------------------------------------------
1315 if ( 0 == strcmp (cur_node->name, "integer"))
1317 SETTING_TRACE(">>>>> UPDATE SLIDER CONTROL %x --- %s ",context->ui_list, id_name);
1318 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1321 item_to_update->chk_status = atoi(value);
1322 SETTING_TRACE(">>> o-------------0 SLIDER VALUE = %d ", item_to_update->chk_status);
1324 elm_object_item_data_set(item_to_update->item, item_to_update);
1325 elm_genlist_item_update(item_to_update->item);
1327 SETTING_TRACE("item_to_update is NULL");
1331 if ( 0 == strcmp (cur_node->name, "bool"))
1333 SETTING_TRACE(">>>>> UPDATE TOGGLE CONTROL %x --- %s ",context->ui_list, id_name);
1334 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1337 item_to_update->chk_status = atoi(value);
1338 SETTING_TRACE(">>> o-------------0 TOGGLE VALUE = %d ", item_to_update->chk_status);
1340 elm_object_item_data_set(item_to_update->item, item_to_update);
1341 elm_genlist_item_update(item_to_update->item);
1343 SETTING_TRACE("item_to_update is NULL");
1346 // case : edit control
1347 if ( 0 == strcmp (cur_node->name, "string"))
1349 SETTING_TRACE(">>>>> UPDATE EDIT CONTROL CONTROL %x --- %s ",context->ui_list, id_name);
1350 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1353 char* old_string = item_to_update->sub_desc;
1354 item_to_update->sub_desc = strdup(value);
1355 SETTING_TRACE(">>> o-------------0 STRING VALUE = %s ", value);
1359 elm_object_item_data_set(item_to_update->item, item_to_update);
1360 elm_genlist_item_update(item_to_update->item);
1363 SETTING_TRACE("item_to_update is NULL");
1366 // case : expand list
1372 //-----------------------------------------------------------
1373 if ( 0 == strcmp (cur_node->name, "expandlist"))
1375 SETTING_TRACE(">>>>> UPDATE EXPAND LIST CONTROL %x --- %s ",context->ui_list, id_name);
1376 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1379 char* old_string = item_to_update->sub_desc;
1380 item_to_update->sub_desc = strdup(value);
1381 SETTING_TRACE(">>> o-------------0 EXPAND LIST VALUE = %s ", value);
1385 elm_object_item_data_set(item_to_update->item, item_to_update);
1386 elm_genlist_item_update(item_to_update->item);
1388 // TODO: need to update child elements
1389 // item_to_update->childs ---> expanded list
1390 if (item_to_update->childs)
1392 Eina_List *li = item_to_update->childs;
1393 int radio_index = 0;
1396 Setting_GenGroupItem_Data* node = eina_list_data_get(li);
1397 // do something more
1398 // SETTING_TRACE(">>> RADIO LIST STRING VALUE = %s ", node->keyStr);
1399 // set position of radio button
1400 if (strcmp(node->keyStr, value) == 0)
1402 elm_radio_value_set(node->rgd, radio_index);
1404 elm_object_item_data_set(item_to_update->item, item_to_update);
1405 elm_genlist_item_update(item_to_update->item);
1408 li = eina_list_next(li);
1414 SETTING_TRACE("item_to_update is NULL");
1421 __node_finder(context, cur_node->children, id_str, value, is_end); /* RECURSIVE */
1426 static unsigned int _plugin_string_key_length(const char*key)
1431 return (int)strlen(key) + 1;
1434 static int _plugin_string_key_cmp(const char* key1, int key1_length,
1435 const char* key2, int key2_length)
1437 return strcmp(key1, key2);
1440 static void _plugin_entry_free_cb(void* data)
1442 Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) data;
1445 eina_list_free(node->childs);
1446 node->childs = NULL;
1450 //static PluginNode* g_context;
1452 PluginNode* setting_plugin_create()
1454 PluginNode *node = calloc(1, sizeof(PluginNode));
1456 Draw_Data *pd = calloc(1, sizeof(Draw_Data));
1463 setting_retvm_if(!pd, -1, "Create Draw_Data obj failed");
1467 node->ui_list = eina_hash_new(EINA_KEY_LENGTH(_plugin_string_key_length),
1468 EINA_KEY_CMP(_plugin_string_key_cmp),
1469 EINA_KEY_HASH(eina_hash_superfast),
1470 _plugin_entry_free_cb,
1476 void setting_plugin_destroy(PluginNode* node)
1478 SETTING_TRACE_BEGIN;
1480 SETTING_TRACE("node is NOT NULL")
1482 SETTING_TRACE("node->pd is NOT NULL")
1483 if(node->pd->doc != NULL) {
1484 xmlSaveFormatFile(node->plugin_path, node->pd->doc, 1);
1485 xmlFreeDoc(node->pd->doc);
1486 node->pd->doc = NULL;
1487 SETTING_TRACE("__cfg_file_write successful");
1494 if (node->ui_list) {
1495 eina_hash_free(node->ui_list);
1496 node->ui_list = NULL;
1504 static Eina_Bool _plugin_foreach_cb(const Eina_Hash *hash, const void*key, void* data, void* fdata)
1506 Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) data;
1507 SETTING_TRACE("%s --- %s ", (char*)key, node->keyStr);
1512 void setting_plugin_debug(PluginNode* context)
1514 // SETTING_TRACE("HASH TABLE -------------------------------------");
1515 eina_hash_foreach(context->ui_list,_plugin_foreach_cb, NULL);
1516 // SETTING_TRACE("HASH TABLE -------------------------------------");
1520 void setting_plugin_update(PluginNode* context)
1522 Eina_List *li = context->ui_list;
1525 Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) eina_list_data_get(li);
1527 // SETTING_TRACE(" ---> keyStr : %s , swallow type : %d ", node->keyStr, node->swallow_type);
1528 Setting_GenGroupItem_Data* item_to_update = NULL;
1529 item_to_update = node;
1530 elm_object_item_data_set(item_to_update->item, item_to_update);
1531 elm_genlist_item_update(item_to_update->item);
1533 li = eina_list_next(li);
1541 bool setting_plugin_load(PluginNode* context, const char *cfg_file)
1543 SETTING_TRACE("cfg_file:%s", cfg_file)
1544 if (isEmptyStr(cfg_file) || 0 != access(cfg_file, R_OK|W_OK|F_OK ))
1546 SETTING_TRACE_ERROR(" error occured : access \n");
1549 context->pd->cfg_file = cfg_file;
1550 context->pd->win_get = (Evas_Object *) ug_get_window();
1552 GError *error = NULL;
1554 context->pd->doc = xmlParseFile(cfg_file);
1555 context->pd->root = xmlDocGetRootElement(context->pd->doc);
1557 // TODO: error handler here
1558 __node_walker(context, context->pd->root);
1561 setting_plugin_debug(context);