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);
123 static drawer_fp __drawer_find(char* type)
126 SETTING_TRACE("node type:%s", type);
127 Eina_List *check_list = _g_drawer_list;
128 Object_Drawer *list_item = NULL;
131 list_item = (Object_Drawer *) eina_list_data_get(check_list);
132 if (NULL == list_item)
135 if (0 == safeStrCmp(list_item->type, type))
137 //SETTING_TRACE("list_item->type:%s", list_item->type);
140 //if not matched,to check next node.
141 check_list = eina_list_next(check_list);
144 //SETTING_TRACE("list_item:%p", list_item);
145 return list_item ? list_item->draw : NULL;
147 void setting_drawer_list_init()
151 /* <navigationbar> */__drawer_add("navigationbar", navigationbar_func);
153 /* <bool> */__drawer_add("bool", checkbox_func);
154 /* <string> */__drawer_add("string", editbox_func);
155 /* <group> */__drawer_add("group", group_func);
156 /* <integer> */__drawer_add("integer", slider_func);
157 /* <label> */__drawer_add("label", label_func);
158 /* <link> */__drawer_add("link", link_func);
159 /* <launch> */__drawer_add("launch", launch_func);
160 /* <extendlist> */__drawer_add("expandlist", expandlist_func);
161 /* <extenditem> */__drawer_add("expanditem", expanditem_func);
162 /* <settings> */__drawer_add("settings", settings_func);
163 /* <setting> */__drawer_add("setting", setting_func);
166 void setting_drawer_list_fini()
170 Object_Drawer *node = NULL;
171 Eina_List *li = _g_drawer_list;
173 node = (Object_Drawer *) eina_list_data_get(li);
176 //SETTING_TRACE("Deregister %s", node->type);
179 li = eina_list_next(li);
181 _g_drawer_list = eina_list_free(_g_drawer_list);
182 _g_drawer_list = NULL;
186 /////////////////////////
187 /////////////////////////
188 /////////////////////////
190 #define MAX_CONTENT_LEN 512
191 #define MAX_LOCAL_BUFSIZE 128
192 #define DBUS_PATH "/setting/dbus_handler"
193 #define DBUS_SIGNAL_INTERFACE "org.tizen.setting.signal"
195 #define APPID_LENGTH 10
196 #define APPID_POS_FROM_PATH 10
198 static char* s_pkg_name;
201 static char* substring(const char* str, size_t begin, size_t len)
203 if (str == 0 || strlen(str) == 0 || strlen(str) < begin || strlen(str) < (begin+len))
206 return strndup(str + begin, len);
213 * ncbyusjryr.AppSetting --> package ID is ncbyusjryr
214 * "Update_" "ncbyusjryr"
216 static char* get_app_string(char* path)
219 char* temp = substring(path, APPID_POS_FROM_PATH, APPID_LENGTH/*string size*/);
220 SETTING_TRACE("package ID : >>> %s ",temp );
224 //------------------------------------------------------
226 static DBusConnection *bus;
227 //------------------------------------------------------
228 static DBusHandlerResult __signal_filter(DBusConnection* conn, DBusMessage* message, void* user_data)
230 int my_pid = getpid();
236 dbus_error_init(&error);
238 setting_main_appdata *ad = user_data;
240 char* pkg_name = get_app_string(ad->plugin_path);
242 char str_buf[MAX_COMMON_BUFFER_LEN];
243 snprintf(str_buf, MAX_COMMON_BUFFER_LEN, "Update_%s", pkg_name);
244 s_pkg_name = strdup(str_buf);
252 if (s_pkg_name == NULL)
254 SETTING_TRACE("s_pkg_name is NULL - it's abnormal operation");
255 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
257 SETTING_TRACE("s_pkg_name : %s ", s_pkg_name);
258 if (dbus_message_is_signal(message, DBUS_SIGNAL_INTERFACE, s_pkg_name))
260 if (dbus_message_get_args(message, &error,
261 DBUS_TYPE_UINT32, &sender_pid,
262 DBUS_TYPE_STRING, &key,
263 DBUS_TYPE_STRING, &value,
264 DBUS_TYPE_INVALID) == FALSE)
266 SETTING_TRACE_ERROR("Fail to get data : %s", error.message);
267 dbus_error_free(&error);
268 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
272 if (sender_pid != 0 && my_pid != sender_pid)
274 SETTING_TRACE("received key : %s , value : %s", key, value);
275 //-------------------------------------------------------------
276 // received key : checkbox1|N/A , value : INT|1
277 //-------------------------------------------------------------
278 //char* key = "checkbox1|N/A";
279 char* ptr = strchr(key, '|');
281 xmlDocPtr doc = NULL;
284 //parsing for : checkbox1|N/A -> checkbox1
285 char* key_name = substring(key, 0, strlen(key)-strlen(ptr));
286 char* val_name = strchr(value, '|');
291 doc = xmlParseFile(ad->plugin_path);
293 xmlNode *root = xmlDocGetRootElement(doc);
296 __node_finder((PluginNode*)ad->plugin_node, root, key_name ,val_name, &is_end);
299 GError *error = NULL;
304 xmlSaveFormatFile(ad->plugin_path, doc, 1);
305 // TODO: make sure this is right
308 SETTING_TRACE("__cfg_file_write successful");
315 return DBUS_HANDLER_RESULT_HANDLED;
318 static int __send_msg(char* key, char* value)
320 DBusMessage* message;
322 int sender_pid = getpid();
327 if (s_pkg_name == NULL)
329 SETTING_TRACE("s_pkg_name is NULL - it's abnormal operation");
333 message = dbus_message_new_signal(DBUS_PATH, DBUS_SIGNAL_INTERFACE, s_pkg_name);
335 SETTING_TRACE("Sending message[%s:%s] via dbus", key ,value);
336 if (dbus_message_append_args(message,
337 DBUS_TYPE_UINT32, &sender_pid,
338 DBUS_TYPE_STRING, &key,
339 DBUS_TYPE_STRING, &value,
340 DBUS_TYPE_INVALID) == FALSE)
342 SETTING_TRACE("Fail to load data error");
346 if (dbus_connection_send(bus, message, NULL) == FALSE)
348 SETTING_TRACE("Fail to send message");
352 dbus_connection_flush(bus);
353 dbus_message_unref(message);
355 SETTING_TRACE("[CLIENT] send data signal done");
361 static void __send_int_msg(xmlNode* xmlObj, int val)
363 const char *id = (char*)xmlGetProp(xmlObj, "id");
364 const char *title = (char*)xmlGetProp(xmlObj, "title");
365 char key[MAX_CONTENT_LEN] = {0,};
366 snprintf(key, sizeof(key), "%s|%s", id, title);
368 char value[MAX_CONTENT_LEN] = {0,};
369 snprintf(value, sizeof(value), "INT|%d", val);
370 __send_msg(key, value);
374 static void __send_string_msg(xmlNode* xmlObj, char *string)
376 const char *id = (char*)xmlGetProp(xmlObj, "id");
377 const char *title = (char*)xmlGetProp(xmlObj, "title");
378 char key[MAX_CONTENT_LEN] = {0,};
379 snprintf(key, sizeof(key), "%s|%s", id, title);
381 char value[MAX_CONTENT_LEN] = {0,};
382 snprintf(value, sizeof(value), "STRING|%s", string);
383 __send_msg(key, value);
387 int setting_dbus_handler_init(void* user_data)
392 SETTING_TRACE("already get a bus, need release first.");
393 setting_dbus_handler_fini();
396 memset(&error, 0, sizeof(DBusError));
397 char rule[MAX_LOCAL_BUFSIZE + 1] = {0,};
398 dbus_error_init(&error);
399 bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
402 SETTING_TRACE("Fail to connect to the D-BUS daemon: %s", error.message);
403 dbus_error_free(&error);
407 dbus_connection_setup_with_g_main(bus, NULL);
408 snprintf(rule, MAX_LOCAL_BUFSIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH, DBUS_SIGNAL_INTERFACE);
410 dbus_bus_add_match(bus, rule, &error);
411 if (dbus_error_is_set(&error))
413 SETTING_TRACE("Fail to rule set; %s", error.message);
414 dbus_bus_remove_match(bus, rule, &error);
415 dbus_error_free(&error);
416 dbus_connection_close(bus);
421 if (dbus_connection_add_filter(bus, __signal_filter, user_data, NULL) == FALSE)
423 dbus_bus_remove_match(bus, rule, &error);
424 dbus_error_free(&error);
425 dbus_connection_close(bus);
430 SETTING_TRACE("app signal initialized");
434 int setting_dbus_handler_fini(void)
436 //do safty checking first.
437 setting_retvm_if(!bus, 0, "!bus");
439 memset(&error, 0, sizeof(DBusError));
440 char rule[MAX_LOCAL_BUFSIZE + 1] = {0, };
442 dbus_error_init(&error);
443 //dbus_connection_remove_filter(bus, __signal_filter, NULL);
444 snprintf(rule, MAX_LOCAL_BUFSIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH, DBUS_SIGNAL_INTERFACE);
445 dbus_bus_remove_match(bus, rule, &error);
447 if (dbus_error_is_set(&error))
449 SETTING_TRACE("Fail to rule unset: %s", error.message);
450 dbus_error_free(&error);
454 dbus_connection_close(bus);
456 SETTING_TRACE("app signal finalized");
460 /////////////////////////////
461 /////////////////////////////
462 /////////////////////////////
464 Elm_Genlist_Item_Class itc_layout;
467 static int __cfg_file_write(Draw_Data *pd)
471 GError *error = NULL;
474 xmlSaveFormatFile(pd->cfg_file, pd->doc, 1);
475 //xmlFreeDoc(pd->doc);
477 SETTING_TRACE("__cfg_file_write successful");
484 static void ___click_softkey_back_cb(void *data, Evas_Object *obj,
490 PluginNode* node = (PluginNode*)data;
491 Draw_Data *pd = node->pd;
493 evas_object_del(pd->ly_main);
497 setting_plugin_destroy(node);
510 static void* group_func(void *data, xmlNode *xmlObj)
513 ret_if(!data || !xmlObj);
515 PluginNode* node = (PluginNode*)data;
516 Draw_Data *pd = node->pd;
518 // original code is non-recursive
520 const char *title = (char*)json_object_get_string_member(jsonObj, "title");
521 (void)setting_create_Gendial_field_titleItem(pd->scroller,
525 // non recursive method
526 if (json_object_has_member(jsonObj, "elements"))
528 JsonNode* elements_node = json_object_get_member(jsonObj, "elements");
532 for (i=0; i < json_array_get_length(json_node_get_array(elements_node)); i++)
534 tempobj = json_array_get_object_element(json_node_get_array(elements_node), i);
535 type = (char*)json_object_get_string_member(tempobj, "type");
536 drawer_fp fp = __drawer_find(type);
537 if (fp) fp(pd, tempobj); // draw it
541 // new code is recursive
542 const char *title = (char*)xmlGetProp(xmlObj, "title");
543 SETTING_TRACE (" >>> GROUP NAME : %s \n", title);
544 (void)setting_create_Gendial_field_titleItem(pd->scroller, &(itc_group_item), title, NULL);
551 static void* __link_list_cb(void *data, Evas_Object *obj, void *event_info)
554 ret_if(data == NULL);
555 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
556 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
557 elm_genlist_item_selected_set(item, 0);
558 Setting_GenGroupItem_Data *list_item =
559 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
561 xmlNode* xmlObj = data;
563 const char *link_file = (char*)xmlGetProp(xmlObj, "value");
567 SETTING_TRACE_ERROR("Invalidate liked file");
570 char file[1024] = {0,};
571 snprintf(file, sizeof(file), "%s/%s", PLUGIN_CFG_DIR, link_file);
572 SETTING_TRACE("file:%s", file);
574 PluginNode* plugin_node = setting_plugin_create();
575 setting_plugin_load(plugin_node, (const char *)file);
577 //setting_plugin_load(NULL, file);
582 static void* __launch_list_cb(void *data, Evas_Object *obj, void *event_info)
585 ret_if(data == NULL);
586 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
587 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
588 elm_genlist_item_selected_set(item, 0);
589 Setting_GenGroupItem_Data *list_item =
590 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
592 xmlNode* xmlObj = data;
594 const char *key_str = (char*)xmlGetProp(xmlObj, "id");
595 const char *title_str = (char*)xmlGetProp(xmlObj, "title");
596 const char *appid_str = (char*)xmlGetProp(xmlObj, "appid");
597 const char *operation_str = (char*)xmlGetProp(xmlObj, "operation");
600 service_h svc = NULL;
601 service_create(&svc);
602 service_set_app_id(svc, appid_str); // xml property – appid
603 service_set_operation(svc, operation_str); // property : operation
604 service_send_launch_request(svc, NULL, NULL);
605 service_destroy(svc);
610 static void* label_func(void *data, xmlNode *xmlObj)
613 ret_if(!data || !xmlObj);
614 PluginNode* node = (PluginNode*)data;
615 Draw_Data *pd = node->pd;
617 const char *title = (char*)xmlGetProp(xmlObj, "title");
619 Setting_GenGroupItem_Data *obj =
620 setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
622 xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
623 0, title, NULL, NULL);
628 static void* link_func(void *data, xmlNode *xmlObj)
631 ret_if(!data || !xmlObj);
632 PluginNode* node = (PluginNode*)data;
633 Draw_Data *pd = node->pd;
635 const char *key_str = (char*)xmlGetProp(xmlObj, "id");
636 Setting_GenGroupItem_Data * obj =
637 setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
639 xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
640 0, key_str, NULL, NULL);
645 static void* launch_func(void *data, xmlNode *xmlObj)
648 ret_if(!data || !xmlObj);
649 PluginNode* node = (PluginNode*)data;
650 Draw_Data *pd = node->pd;
652 const char *title_str = (char*)xmlGetProp(xmlObj, "title");
654 Setting_GenGroupItem_Data * obj =
655 setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
657 xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
658 0, title_str, NULL, NULL);
663 static void __slider_stop_cb(void *data, Evas_Object *obj,
666 ret_if(data == NULL || obj == NULL);
667 double val = elm_slider_value_get(obj);
668 SETTING_TRACE("val = %f", val);
669 Setting_GenGroupItem_Data *list_item = data;
670 ret_if(list_item->userdata == NULL);
672 xmlNode* xmlObj = list_item->userdata;
675 //apply the vconf changes after stopping moving slider..
676 list_item->chk_status = (int)(val + 0.5);
677 elm_slider_value_set(obj, list_item->chk_status);
679 SETTING_TRACE(" slider after ---> val = %d", (int) list_item->chk_status);
681 // int -> double -> xmlChar*
684 sprintf(buf, "%d", (int) list_item->chk_status);
685 newattr = xmlSetProp(xmlObj, "value", buf);
687 __send_int_msg(xmlObj, list_item->chk_status);
688 __cfg_file_write((Draw_Data *)list_item->belongs_to);
692 static void* slider_func(void *data, xmlNode *xmlObj)
695 ret_if(!data || !xmlObj);
696 PluginNode* node = (PluginNode*)data;
697 Draw_Data *pd = node->pd;
700 const char *title = (char*)xmlGetProp(xmlObj, "title");
702 SETTING_TRACE (" >>> [slider input] min=%s max=%s value=%s ",(char*)xmlGetProp(xmlObj, "min"), (char*)xmlGetProp(xmlObj, "max"), (char*)xmlGetProp(xmlObj, "value"));
704 int value = atoi((char*)xmlGetProp(xmlObj, "value"));
705 int min = atoi((char*)xmlGetProp(xmlObj, "min"));
706 int max = atoi((char*)xmlGetProp(xmlObj, "max"));
708 SETTING_TRACE ("[slider input] min=%d max=%d value=%d ", min, max, value);
710 setting_create_Gendial_itc("dialogue/1text.1icon.5", &(itc_layout));
711 Setting_GenGroupItem_Data *list_item =
712 setting_create_Gendial_field_def(pd->scroller, &(itc_layout), NULL,
714 SWALLOW_Type_LAYOUT_SLIDER,
715 IMG_SENSITIVITY_ICON_01,
716 IMG_SENSITIVITY_ICON_02, value,
719 list_item->win_main = NULL;
720 list_item->evas = NULL;
721 list_item->isIndicatorVisible = true;
722 list_item->slider_min = min;
723 list_item->slider_max = max;
724 list_item->userdata = xmlObj;
725 list_item->stop_change_cb = __slider_stop_cb;
726 list_item->belongs_to = (int)pd;
729 g_list_item = list_item;
731 return (void*)list_item;
736 elm_object_item_data_set(item_to_update->item, item_to_update);
737 elm_genlist_item_update(item_to_update->item);
739 static void* navigationbar_func(void *data, xmlNode *xmlObj)
743 ret_if(!data || !xmlObj);
745 PluginNode* node = (PluginNode*)data;
746 Draw_Data *pd = node->pd;
748 //----------------------------------------------------------------
749 // [DATA] title, btn[0], btn[1]
750 const char *title = (char*)xmlGetProp(xmlObj, "title");
751 char *btn[2] = {0, };
753 // find child nodes named 'elements'
754 if (xmlObj->children) {
755 xmlNode* cur = xmlObj->children;
759 if (!xmlStrcmp(cur->name, (const xmlChar*)"button")) {
760 btn[i] = xmlGetProp(cur, "title");
761 SETTING_TRACE("------>>> node type : Element, name=%s id=%s / btn[%d] = %s ",
762 cur->name,xmlGetProp(cur, "id"),
770 //----------------------------------------------------------------
772 pd->ly_main = setting_create_layout_navi_bar_genlist(pd->win_get,
775 _(btn[1]), _(btn[0]),
776 ___click_softkey_back_cb,
777 ___click_softkey_back_cb, data, &pd->scroller,
785 static void __check_mouse_up_cb(void *data, Evas_Object *obj,
790 setting_retm_if(data == NULL, "Data parameter is NULL");
792 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
793 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
794 elm_genlist_item_selected_set(item, 0);
795 Setting_GenGroupItem_Data *list_item =
796 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
798 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
800 int old_status = elm_check_state_get(list_item->eo_check);
801 list_item->chk_status = !old_status;
802 elm_check_state_set(list_item->eo_check, list_item->chk_status);
804 xmlNode *xmlObj = data;
806 newattr = xmlSetProp(xmlObj, "state", xmlXPathCastNumberToString(list_item->chk_status));
808 __send_int_msg(xmlObj, list_item->chk_status);
809 __cfg_file_write((Draw_Data *)list_item->belongs_to);
813 static void __chk_btn_cb(void *data, Evas_Object *obj,
818 retm_if(data == NULL, "Data parameter is NULL");
819 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
821 xmlNode* xmlObj = list_item->userdata;
823 list_item->chk_status = elm_check_state_get(obj); /* for genlist update status */
826 if (list_item->chk_status == 1) {
827 newattr = xmlSetProp(xmlObj, "value", "true");
828 } else if (list_item->chk_status == 0) {
829 newattr = xmlSetProp(xmlObj, "value", "false");
831 newattr = xmlSetProp(xmlObj, "value", "false");
834 const char *id = (char*)xmlGetProp(xmlObj, "id");
835 const char *title = (char*)xmlGetProp(xmlObj, "title");
836 //SETTING_TRACE(" >>>> id:%s , title:%s", id, title);
837 __send_int_msg(xmlObj, list_item->chk_status);
838 __cfg_file_write((Draw_Data *)list_item->belongs_to);
843 static void* checkbox_func(void *data, xmlNode *xmlObj)
846 ret_if(!data || !xmlObj);
848 PluginNode* node = (PluginNode*)data;
849 Draw_Data *pd = node->pd;
851 // [DATA] title, value
852 const char *title = (char*)xmlGetProp(xmlObj, "title");
855 char* value = (char*)xmlGetProp(xmlObj, "value");
859 if ( 0 == safeStrCmp(value, "true")) {
861 } else if ( 0 == safeStrCmp(value, "false")) {
864 ival = 0; // default : false (0)
867 // title, value, xmlObj
868 Setting_GenGroupItem_Data *list_item =
869 setting_create_Gendial_field_def(pd->scroller,
873 SWALLOW_Type_1TOGGLE,
880 list_item->userdata = xmlObj;
881 list_item->belongs_to = (int) pd;
882 SETTING_TRACE("pd:%p,list_item->belongs_to:%d", pd, list_item->belongs_to);
889 static void __entry_unfocus_cb(void *data, Evas_Object *obj, void *event_info)
892 retm_if(!data || !obj, "Data parameter is NULL");
894 setting_hide_input_pannel_cb(obj);
895 const char *entry_str = elm_entry_entry_get(obj);
896 char *entry_str_utf8 = NULL;
897 entry_str_utf8 = elm_entry_markup_to_utf8(entry_str);
899 Setting_GenGroupItem_Data *list_item = data;
901 xmlNode* xmlObj = list_item->userdata;
904 const char *title = (char*)xmlSetProp(xmlObj, "value",entry_str_utf8);
906 __send_string_msg(xmlObj, entry_str_utf8);
907 __cfg_file_write((Draw_Data *)list_item->belongs_to);
909 FREE(entry_str_utf8);
913 static void __editbox_list_cb(void *data, Evas_Object *obj,
919 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
920 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
921 elm_genlist_item_selected_set(item, 0);
922 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
924 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
925 if (!elm_object_focus_get(list_item->eo_check)) {
926 elm_object_focus_set(list_item->eo_check, EINA_TRUE);
929 Ecore_IMF_Context *imf_context = (Ecore_IMF_Context *)elm_entry_imf_context_get(list_item->eo_check);
930 setting_retm_if(imf_context == NULL, "imf_context is NULL");
931 ecore_imf_context_input_panel_show(imf_context);
935 static void __editbox_changed_cb(void *data, Evas_Object *obj,
939 retm_if(!data || !obj, "Data parameter is NULL");
940 retm_if(!elm_object_focus_get(obj), "Entry is not focused");
942 Setting_GenGroupItem_Data *list_item =
943 (Setting_GenGroupItem_Data *) data;
945 const char *entry_str = elm_entry_entry_get(obj);
946 int entry_len = safeStrLen(entry_str);
947 SETTING_TRACE("entry_str:[%s], lenght:%d", entry_str, entry_len);
949 G_FREE(list_item->sub_desc);//release first
950 list_item->sub_desc = (char *)g_strdup(entry_str);
954 static void* editbox_func(void *data, xmlNode *xmlObj)
957 ret_if(!data || !xmlObj);
959 PluginNode* node = (PluginNode*)data;
960 Draw_Data *pd = node->pd;
962 const char *title = (char*)xmlGetProp(xmlObj, "title");
963 const char *key_str= (char*)xmlGetProp(xmlObj, "value");
965 const char *minlength= (char*)xmlGetProp(xmlObj, "minlength");
966 const char *maxlength= (char*)xmlGetProp(xmlObj, "maxlength");
971 max_len = atoi(maxlength);
972 SETTING_TRACE(" >> MAXLENGTH FILTER IS AVAILABLE !!!! maxlength = %d", max_len);
975 Setting_GenGroupItem_Data *list_item = NULL;
979 // without maxlength filter
980 list_item = setting_create_Gendial_field_def(pd->scroller, &(itc_1icon),
982 pd, SWALLOW_Type_LAYOUT_ENTRY,
983 NULL, NULL, 0, title, key_str,
984 __editbox_changed_cb);
987 // add max length filter
988 list_item = setting_create_Gendial_field_entry(
993 SWALLOW_Type_LAYOUT_ENTRY,
994 NULL, NULL, 0, title, key_str, __editbox_changed_cb,
995 ELM_INPUT_PANEL_LAYOUT_NORMAL,
1004 list_item->userdata = xmlObj;
1005 list_item->stop_change_cb = __entry_unfocus_cb;
1006 list_item->belongs_to = (int)pd;
1013 static void __expanditem_func_sel_cb(void *data, Evas_Object *obj, void *event_info)
1015 SETTING_TRACE_BEGIN;
1017 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
1018 Elm_Object_Item *subitem = (Elm_Object_Item *) event_info;
1019 Elm_Object_Item *parentItem = elm_genlist_item_parent_get(subitem);
1020 elm_genlist_item_selected_set(subitem, 0);
1021 Setting_GenGroupItem_Data *data_subItem = elm_object_item_data_get(subitem);
1022 Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem); /* parent data */
1023 ret_if(NULL == data_subItem || NULL == data_parentItem);
1025 elm_radio_value_set(data_subItem->rgd, data_subItem->chk_status);
1027 data_parentItem->sub_desc = (char *)g_strdup(_(data_subItem->keyStr));
1028 elm_object_item_data_set(data_parentItem->item, data_parentItem);
1029 elm_genlist_item_update(data_parentItem->item);
1031 xmlNode* xmlObj = data_parentItem->userdata;
1035 //newattr = xmlSetProp(xmlObj, "string", data_parentItem->sub_desc);
1036 newattr = xmlSetProp(xmlObj, "value", data_parentItem->sub_desc);
1038 __send_string_msg(xmlObj, data_parentItem->sub_desc);
1039 __cfg_file_write((Draw_Data *)data_parentItem->belongs_to);
1043 static void __expanditem_func_exp_cb(void *data, Evas_Object *obj, void *event_info)
1045 ret_if(NULL == data || NULL == event_info);
1046 SETTING_TRACE_BEGIN;
1048 PluginNode* node = (PluginNode*)data;
1049 Draw_Data *pd = node->pd;
1051 Elm_Object_Item *parentItem = event_info; /* parent item */
1052 Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem); /* parent data */
1053 Evas_Object *scroller = elm_object_item_widget_get(parentItem);
1056 xmlNode *xmlObj = data_parentItem->userdata;
1057 //char *value = (char*)xmlGetProp(xmlObj, "string");
1058 char *value = (char*)xmlGetProp(xmlObj, "value");
1059 SETTING_TRACE(">>> value = %s", value);
1061 Evas_Object *rgd = NULL;
1063 if (xmlObj->children && !data_parentItem->rgd) {//to protect from entering repeatly
1064 xmlNode* cur = xmlObj->children;
1066 rgd = elm_radio_add(scroller);
1067 elm_radio_value_set(rgd, -1);
1071 char *subitem_title = NULL;
1072 int subitem_index = 0;
1075 while (cur != NULL) {
1076 if (!xmlStrcmp(cur->name, (const xmlChar*)"expanditem")) {
1077 type = (char*)xmlGetProp(cur, "type");
1078 if (0 == safeStrCmp(type, "radio")) {
1079 subitem_title = (char*)xmlGetProp(cur, "title");
1080 Setting_GenGroupItem_Data *list_item =
1081 setting_create_Gendial_exp_sub_field(scroller,
1082 &(itc_1icon_1text_sub),
1083 __expanditem_func_sel_cb, NULL, parentItem,
1084 SWALLOW_Type_1RADIO, rgd,
1086 subitem_title, NULL);
1088 // SETTING_TRACE(">>> value = %s, subitem_title = %s ", value, subitem_title);
1090 if (0 == safeStrCmp(value, subitem_title)) {
1091 sel_idx = subitem_index;
1092 SETTING_TRACE("%d is selected in Radio Group", sel_idx);
1094 data_parentItem->childs = eina_list_append(data_parentItem->childs, list_item);
1098 SETTING_TRACE("invalid type[:%s]", type);
1107 elm_radio_value_set(rgd, sel_idx);
1108 data_parentItem->rgd = rgd;//protecting condition
1113 static void __expanditem_func_smart_cb(void *data, Evas_Object *obj, void *event_info)
1115 ret_if(data == NULL || event_info == NULL);
1116 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
1117 Setting_GenGroupItem_Data *data_item = elm_object_item_data_get(item);
1118 char *cb_type = data;
1120 if (0 == safeStrCmp(cb_type, "contracted")) {
1121 data_item->rgd = NULL;
1122 elm_genlist_item_subitems_clear(item);
1127 static void* settings_func(void *data, xmlNode *xmlObj)
1133 static Evas_Object *setting_create_win_layout2(Evas_Object *win_layout, Evas_Object *win_obj)
1136 Evas_Object *layout = NULL;
1137 Evas_Object *conform = elm_conformant_add(win_obj);
1138 //setting_main_appdata *ad = (setting_main_appdata *) data;
1141 layout = elm_layout_add(conform);
1142 evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1143 setting_retvm_if(layout == NULL, FALSE, "layout == NULL");
1145 elm_layout_theme_set(layout, "layout", "application", "default");
1146 evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1147 evas_object_size_hint_align_set(conform, EVAS_HINT_FILL, EVAS_HINT_FILL);
1148 elm_win_resize_object_add(win_obj, conform);
1149 elm_object_content_set(conform, layout);
1151 Evas_Object *bg = setting_create_bg(layout, win_obj, "group_list");
1152 elm_object_part_content_set(layout, "elm.swallow.bg", bg);
1153 evas_object_show(layout);
1154 evas_object_show(conform);
1156 //ad->conformant = conform;
1161 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 */
1162 Evas_Object **navi_bar,
1163 Evas_Object **titleobj)
1166 Evas_Object *layout = setting_create_win_layout2(win_layout, win_obj);
1167 *navi_bar = setting_create_navi_bar(layout);
1169 setting_create_navi_bar_buttons(title_str,
1170 lbutton_str, rbutton_str, mbutton_str,
1171 lbutton_click_cb, rbutton_click_cb,
1172 mbutton_click_cb, cb_data, eo_view /*content */ ,
1178 static void* setting_func(void *data, xmlNode *xmlObj)
1180 SETTING_TRACE_BEGIN;
1181 ret_if(!data || !xmlObj);
1184 PluginNode* node = (PluginNode*)data;
1185 Draw_Data *pd = node->pd;
1187 // [DATA] title, btn[0], btn[1]
1188 const char *title = (char*)xmlGetProp(xmlObj, "title");
1189 char *btn[2] = {/* 0 */"OK", /* 1 */"NO"};
1191 SETTING_TRACE("before setting_create_layout_navi_bar_genlist");
1194 pd->scroller = elm_genlist_add(pd->win_get);
1195 retvm_if(pd->scroller == NULL, NULL,
1196 "Cannot set scroller object as contento of layout");
1197 elm_object_style_set(pd->scroller, "dialogue");
1198 elm_genlist_clear(pd->scroller); /* first to clear list */
1201 SETTING_TRACE("_(title):%s", _(title));
1202 pd->ly_main = setting_create_layout_navi_bar2(pd->win_get, pd->win_get,
1204 _("IDS_COM_BODY_BACK"), NULL, NULL,
1205 ___click_softkey_back_cb,
1208 &(pd->navi_bar), NULL);
1209 SETTING_TRACE("after setting_create_layout_navi_bar_genlist");
1216 static void* expanditem_func(void *data, xmlNode *xmlObj)
1218 // DO NOTHING - expandlist draws this area
1222 static void* expandlist_func(void *data, xmlNode *xmlObj)
1224 SETTING_TRACE_BEGIN;
1225 ret_if(!data || !xmlObj);
1227 PluginNode* node = (PluginNode*)data;
1228 Draw_Data *pd = node->pd;
1230 const char *key_str = (char*)xmlGetProp(xmlObj, "title");
1231 const char *value = (char*)xmlGetProp(xmlObj, "value"); // string -> value
1233 setting_enable_expandable_genlist(pd->scroller, data, __expanditem_func_exp_cb, __expanditem_func_smart_cb);
1234 Setting_GenGroupItem_Data *list_item =
1235 setting_create_Gendial_exp_parent_field(pd->scroller,
1236 &(itc_2text_3_parent),
1238 SWALLOW_Type_INVALID,
1242 list_item->userdata = xmlObj;
1243 list_item->belongs_to = (int)pd;
1251 static int __node_walker(PluginNode* context, xmlNode* cur)
1253 //SETTING_TRACE_BEGIN;
1254 Draw_Data *pd = context->pd;
1257 xmlNode *cur_node = NULL;
1258 for (cur_node = cur; cur_node;cur_node = cur_node->next) {
1259 if (cur_node->type == XML_ELEMENT_NODE) {
1260 // SETTING_TRACE("node type : %s id= %s", cur_node->name,xmlGetProp(cur_node, "id"));
1261 drawer_fp fp = __drawer_find(cur_node->name);
1265 void* vret = fp(context, cur_node); // draw it
1269 Setting_GenGroupItem_Data* genlist_node = (Setting_GenGroupItem_Data* )vret;
1270 //SETTING_TRACE("add node to Eina List name : %s, id : ", cur_node->name, xmlGetProp(cur_node, "id"));
1271 // add it to the hash table create before.
1274 char* key_name = xmlGetProp(cur_node, "id");
1275 eina_hash_add(context->ui_list, strdup(key_name),(void*)genlist_node);
1279 __node_walker(context, cur_node->children); /* RECURSIVE */
1285 * @param id_str [in] "id"
1286 * @param value [in] value to be udpated
1287 * @see __expanditem_func_sel_cb
1289 static int __node_finder(PluginNode* context, xmlNode* cur, char* id_str, char* value, bool* is_end)
1291 SETTING_TRACE_BEGIN;
1292 xmlNode *cur_node = NULL;
1294 if (*is_end == true) return 0;
1296 for (cur_node = cur; cur_node;cur_node = cur_node->next) {
1297 if (cur_node->type == XML_ELEMENT_NODE) {
1299 char* id_name = (char*)xmlGetProp(cur_node, "id");
1300 if ( id_name && 0 == strcmp(id_str, id_name))
1302 SETTING_TRACE("FOUND >>>> %s", id_name);
1303 // cur_node - update xml code
1304 xmlAttrPtr newattr = xmlSetProp(cur_node, "value", value);
1306 //-----------------------------------------------------------
1309 if ( 0 == strcmp (cur_node->name, "integer"))
1311 SETTING_TRACE(">>>>> UPDATE SLIDER CONTROL %x --- %s ",context->ui_list, id_name);
1312 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1315 item_to_update->chk_status = atoi(value);
1316 SETTING_TRACE(">>> o-------------0 SLIDER VALUE = %d ", item_to_update->chk_status);
1318 elm_object_item_data_set(item_to_update->item, item_to_update);
1319 elm_genlist_item_update(item_to_update->item);
1321 SETTING_TRACE("item_to_update is NULL");
1325 if ( 0 == strcmp (cur_node->name, "bool"))
1327 SETTING_TRACE(">>>>> UPDATE TOGGLE CONTROL %x --- %s ",context->ui_list, id_name);
1328 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1331 item_to_update->chk_status = atoi(value);
1332 SETTING_TRACE(">>> o-------------0 TOGGLE VALUE = %d ", item_to_update->chk_status);
1334 elm_object_item_data_set(item_to_update->item, item_to_update);
1335 elm_genlist_item_update(item_to_update->item);
1337 SETTING_TRACE("item_to_update is NULL");
1340 // case : edit control
1341 if ( 0 == strcmp (cur_node->name, "string"))
1343 SETTING_TRACE(">>>>> UPDATE EDIT CONTROL CONTROL %x --- %s ",context->ui_list, id_name);
1344 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1347 char* old_string = item_to_update->sub_desc;
1348 item_to_update->sub_desc = strdup(value);
1349 SETTING_TRACE(">>> o-------------0 STRING VALUE = %s ", value);
1353 elm_object_item_data_set(item_to_update->item, item_to_update);
1354 elm_genlist_item_update(item_to_update->item);
1357 SETTING_TRACE("item_to_update is NULL");
1360 // case : expand list
1366 //-----------------------------------------------------------
1367 if ( 0 == strcmp (cur_node->name, "expandlist"))
1369 SETTING_TRACE(">>>>> UPDATE EXPAND LIST CONTROL %x --- %s ",context->ui_list, id_name);
1370 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1373 char* old_string = item_to_update->sub_desc;
1374 item_to_update->sub_desc = strdup(value);
1375 SETTING_TRACE(">>> o-------------0 EXPAND LIST VALUE = %s ", value);
1379 elm_object_item_data_set(item_to_update->item, item_to_update);
1380 elm_genlist_item_update(item_to_update->item);
1382 // TODO: need to update child elements
1383 // item_to_update->childs ---> expanded list
1384 if (item_to_update->childs)
1386 Eina_List *li = item_to_update->childs;
1387 int radio_index = 0;
1390 Setting_GenGroupItem_Data* node = eina_list_data_get(li);
1391 // do something more
1392 // SETTING_TRACE(">>> RADIO LIST STRING VALUE = %s ", node->keyStr);
1393 // set position of radio button
1394 if (strcmp(node->keyStr, value) == 0)
1396 elm_radio_value_set(node->rgd, radio_index);
1398 elm_object_item_data_set(item_to_update->item, item_to_update);
1399 elm_genlist_item_update(item_to_update->item);
1402 li = eina_list_next(li);
1408 SETTING_TRACE("item_to_update is NULL");
1415 __node_finder(context, cur_node->children, id_str, value, is_end); /* RECURSIVE */
1420 static unsigned int _plugin_string_key_length(const char*key)
1425 return (int)strlen(key) + 1;
1428 static int _plugin_string_key_cmp(const char* key1, int key1_length,
1429 const char* key2, int key2_length)
1431 return strcmp(key1, key2);
1434 static void _plugin_entry_free_cb(void* data)
1436 Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) data;
1439 eina_list_free(node->childs);
1440 node->childs = NULL;
1444 //static PluginNode* g_context;
1446 PluginNode* setting_plugin_create()
1448 PluginNode *node = calloc(1, sizeof(PluginNode));
1450 Draw_Data *pd = calloc(1, sizeof(Draw_Data));
1451 setting_retvm_if(!pd, -1, "Create Draw_Data obj failed");
1455 node->ui_list = eina_hash_new(EINA_KEY_LENGTH(_plugin_string_key_length),
1456 EINA_KEY_CMP(_plugin_string_key_cmp),
1457 EINA_KEY_HASH(eina_hash_superfast),
1458 _plugin_entry_free_cb,
1464 void setting_plugin_destroy(PluginNode* node)
1466 SETTING_TRACE_BEGIN;
1468 SETTING_TRACE("node is NOT NULL")
1470 SETTING_TRACE("node->pd is NOT NULL")
1471 if(node->pd->doc != NULL) {
1472 xmlSaveFormatFile(node->plugin_path, node->pd->doc, 1);
1473 xmlFreeDoc(node->pd->doc);
1474 node->pd->doc = NULL;
1475 SETTING_TRACE("__cfg_file_write successful");
1482 if (node->ui_list) {
1483 eina_hash_free(node->ui_list);
1484 node->ui_list = NULL;
1492 static Eina_Bool _plugin_foreach_cb(const Eina_Hash *hash, const void*key, void* data, void* fdata)
1494 Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) data;
1495 SETTING_TRACE("%s --- %s ", (char*)key, node->keyStr);
1500 void setting_plugin_debug(PluginNode* context)
1502 // SETTING_TRACE("HASH TABLE -------------------------------------");
1503 eina_hash_foreach(context->ui_list,_plugin_foreach_cb, NULL);
1504 // SETTING_TRACE("HASH TABLE -------------------------------------");
1508 void setting_plugin_update(PluginNode* context)
1510 Eina_List *li = context->ui_list;
1513 Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) eina_list_data_get(li);
1515 // SETTING_TRACE(" ---> keyStr : %s , swallow type : %d ", node->keyStr, node->swallow_type);
1516 Setting_GenGroupItem_Data* item_to_update = NULL;
1517 item_to_update = node;
1518 elm_object_item_data_set(item_to_update->item, item_to_update);
1519 elm_genlist_item_update(item_to_update->item);
1521 li = eina_list_next(li);
1529 bool setting_plugin_load(PluginNode* context, const char *cfg_file)
1531 SETTING_TRACE("cfg_file:%s", cfg_file)
1532 if (isEmptyStr(cfg_file) || 0 != access(cfg_file, R_OK|W_OK|F_OK ))
1534 SETTING_TRACE_ERROR(" error occured : access \n");
1537 context->pd->cfg_file = cfg_file;
1538 context->pd->win_get = (Evas_Object *) ug_get_window();
1540 GError *error = NULL;
1542 context->pd->doc = xmlParseFile(cfg_file);
1543 context->pd->root = xmlDocGetRootElement(context->pd->doc);
1545 // TODO: error handler here
1546 __node_walker(context, context->pd->root);
1549 setting_plugin_debug(context);