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;
200 static char* substring(const char* str, size_t begin, size_t len)
202 if (str == 0 || strlen(str) == 0 || strlen(str) < begin || strlen(str) < (begin+len))
205 return strndup(str + begin, len);
211 * ncbyusjryr.AppSetting --> package ID is ncbyusjryr
212 * "Update_" "ncbyusjryr"
214 static char* get_app_string(char* path)
217 char* temp = substring(path, APPID_POS_FROM_PATH, APPID_LENGTH/*string size*/);
218 SETTING_TRACE("package ID : >>> %s ",temp );
222 //------------------------------------------------------
224 static DBusConnection *bus;
225 //------------------------------------------------------
226 static DBusHandlerResult __signal_filter(DBusConnection* conn, DBusMessage* message, void* user_data)
228 int my_pid = getpid();
234 dbus_error_init(&error);
236 setting_main_appdata *ad = user_data;
238 char* pkg_name = get_app_string(ad->plugin_path);
240 char str_buf[MAX_COMMON_BUFFER_LEN];
241 snprintf(str_buf, MAX_COMMON_BUFFER_LEN, "Update_%s", pkg_name);
242 s_pkg_name = strdup(str_buf);
250 if (s_pkg_name == NULL)
252 SETTING_TRACE("s_pkg_name is NULL - it's abnormal operation");
253 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
255 SETTING_TRACE("s_pkg_name : %s ", s_pkg_name);
256 if (dbus_message_is_signal(message, DBUS_SIGNAL_INTERFACE, s_pkg_name))
258 if (dbus_message_get_args(message, &error,
259 DBUS_TYPE_UINT32, &sender_pid,
260 DBUS_TYPE_STRING, &key,
261 DBUS_TYPE_STRING, &value,
262 DBUS_TYPE_INVALID) == FALSE)
264 SETTING_TRACE_ERROR("Fail to get data : %s", error.message);
265 dbus_error_free(&error);
266 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
270 if (sender_pid != 0 && my_pid != sender_pid)
272 SETTING_TRACE("received key : %s , value : %s", key, value);
273 //-------------------------------------------------------------
274 // received key : checkbox1|N/A , value : INT|1
275 //-------------------------------------------------------------
276 //char* key = "checkbox1|N/A";
277 char* ptr = strchr(key, '|');
279 xmlDocPtr doc = NULL;
282 //parsing for : checkbox1|N/A -> checkbox1
283 char* key_name = substring(key, 0, strlen(key)-strlen(ptr));
284 char* val_name = strchr(value, '|');
289 doc = xmlParseFile(ad->plugin_path);
291 xmlNode *root = xmlDocGetRootElement(doc);
294 __node_finder((PluginNode*)ad->plugin_node, root, key_name ,val_name, &is_end);
297 GError *error = NULL;
302 xmlSaveFormatFile(ad->plugin_path, doc, 1);
303 // TODO: make sure this is right
306 SETTING_TRACE("__cfg_file_write successful");
313 return DBUS_HANDLER_RESULT_HANDLED;
316 static int __send_msg(char* key, char* value)
318 DBusMessage* message;
320 int sender_pid = getpid();
325 if (s_pkg_name == NULL)
327 SETTING_TRACE("s_pkg_name is NULL - it's abnormal operation");
331 message = dbus_message_new_signal(DBUS_PATH, DBUS_SIGNAL_INTERFACE, s_pkg_name);
333 SETTING_TRACE("Sending message[%s:%s] via dbus", key ,value);
334 if (dbus_message_append_args(message,
335 DBUS_TYPE_UINT32, &sender_pid,
336 DBUS_TYPE_STRING, &key,
337 DBUS_TYPE_STRING, &value,
338 DBUS_TYPE_INVALID) == FALSE)
340 SETTING_TRACE("Fail to load data error");
344 if (dbus_connection_send(bus, message, NULL) == FALSE)
346 SETTING_TRACE("Fail to send message");
350 dbus_connection_flush(bus);
351 dbus_message_unref(message);
353 SETTING_TRACE("[CLIENT] send data signal done");
359 static void __send_int_msg(xmlNode* xmlObj, int val)
361 const char *id = (char*)xmlGetProp(xmlObj, "id");
362 const char *title = (char*)xmlGetProp(xmlObj, "title");
363 char key[MAX_CONTENT_LEN] = {0,};
364 snprintf(key, sizeof(key), "%s|%s", id, title);
366 char value[MAX_CONTENT_LEN] = {0,};
367 snprintf(value, sizeof(value), "INT|%d", val);
368 __send_msg(key, value);
372 static void __send_string_msg(xmlNode* xmlObj, char *string)
374 const char *id = (char*)xmlGetProp(xmlObj, "id");
375 const char *title = (char*)xmlGetProp(xmlObj, "title");
376 char key[MAX_CONTENT_LEN] = {0,};
377 snprintf(key, sizeof(key), "%s|%s", id, title);
379 char value[MAX_CONTENT_LEN] = {0,};
380 snprintf(value, sizeof(value), "STRING|%s", string);
381 __send_msg(key, value);
385 int setting_dbus_handler_init(void* user_data)
390 SETTING_TRACE("already get a bus, need release first.");
391 setting_dbus_handler_fini();
394 memset(&error, 0, sizeof(DBusError));
395 char rule[MAX_LOCAL_BUFSIZE + 1] = {0,};
396 dbus_error_init(&error);
397 bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
400 SETTING_TRACE("Fail to connect to the D-BUS daemon: %s", error.message);
401 dbus_error_free(&error);
405 dbus_connection_setup_with_g_main(bus, NULL);
406 snprintf(rule, MAX_LOCAL_BUFSIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH, DBUS_SIGNAL_INTERFACE);
408 dbus_bus_add_match(bus, rule, &error);
409 if (dbus_error_is_set(&error))
411 SETTING_TRACE("Fail to rule set; %s", error.message);
412 dbus_bus_remove_match(bus, rule, &error);
413 dbus_error_free(&error);
414 dbus_connection_close(bus);
419 if (dbus_connection_add_filter(bus, __signal_filter, user_data, NULL) == FALSE)
421 dbus_bus_remove_match(bus, rule, &error);
422 dbus_error_free(&error);
423 dbus_connection_close(bus);
428 SETTING_TRACE("app signal initialized");
432 int setting_dbus_handler_fini(void)
434 //do safty checking first.
435 setting_retvm_if(!bus, 0, "!bus");
437 memset(&error, 0, sizeof(DBusError));
438 char rule[MAX_LOCAL_BUFSIZE + 1] = {0, };
440 dbus_error_init(&error);
441 //dbus_connection_remove_filter(bus, __signal_filter, NULL);
442 snprintf(rule, MAX_LOCAL_BUFSIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH, DBUS_SIGNAL_INTERFACE);
443 dbus_bus_remove_match(bus, rule, &error);
445 if (dbus_error_is_set(&error))
447 SETTING_TRACE("Fail to rule unset: %s", error.message);
448 dbus_error_free(&error);
452 dbus_connection_close(bus);
454 SETTING_TRACE("app signal finalized");
458 /////////////////////////////
459 /////////////////////////////
460 /////////////////////////////
462 Elm_Genlist_Item_Class itc_layout;
465 static int __cfg_file_write(Draw_Data *pd)
469 GError *error = NULL;
472 xmlSaveFormatFile(pd->cfg_file, pd->doc, 1);
473 //xmlFreeDoc(pd->doc);
475 SETTING_TRACE("__cfg_file_write successful");
482 static void ___click_softkey_back_cb(void *data, Evas_Object *obj,
488 PluginNode* node = (PluginNode*)data;
489 Draw_Data *pd = node->pd;
491 evas_object_del(pd->ly_main);
495 setting_plugin_destroy(node);
508 static void* group_func(void *data, xmlNode *xmlObj)
511 ret_if(!data || !xmlObj);
513 PluginNode* node = (PluginNode*)data;
514 Draw_Data *pd = node->pd;
516 // original code is non-recursive
518 const char *title = (char*)json_object_get_string_member(jsonObj, "title");
519 (void)setting_create_Gendial_field_titleItem(pd->scroller,
523 // non recursive method
524 if (json_object_has_member(jsonObj, "elements"))
526 JsonNode* elements_node = json_object_get_member(jsonObj, "elements");
530 for (i=0; i < json_array_get_length(json_node_get_array(elements_node)); i++)
532 tempobj = json_array_get_object_element(json_node_get_array(elements_node), i);
533 type = (char*)json_object_get_string_member(tempobj, "type");
534 drawer_fp fp = __drawer_find(type);
535 if (fp) fp(pd, tempobj); // draw it
539 // new code is recursive
540 const char *title = (char*)xmlGetProp(xmlObj, "title");
541 SETTING_TRACE (" >>> GROUP NAME : %s \n", title);
542 (void)setting_create_Gendial_field_titleItem(pd->scroller, &(itc_group_item), title, NULL);
549 static void* __link_list_cb(void *data, Evas_Object *obj, void *event_info)
552 ret_if(data == NULL);
553 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
554 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
555 elm_genlist_item_selected_set(item, 0);
556 Setting_GenGroupItem_Data *list_item =
557 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
559 xmlNode* xmlObj = data;
561 const char *link_file = (char*)xmlGetProp(xmlObj, "value");
565 SETTING_TRACE_ERROR("Invalidate liked file");
568 char file[1024] = {0,};
569 snprintf(file, sizeof(file), "%s/%s", PLUGIN_CFG_DIR, link_file);
570 SETTING_TRACE("file:%s", file);
572 PluginNode* plugin_node = setting_plugin_create();
573 setting_plugin_load(plugin_node, (const char *)file);
575 //setting_plugin_load(NULL, file);
580 static void* __launch_list_cb(void *data, Evas_Object *obj, void *event_info)
583 ret_if(data == NULL);
584 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
585 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
586 elm_genlist_item_selected_set(item, 0);
587 Setting_GenGroupItem_Data *list_item =
588 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
590 xmlNode* xmlObj = data;
592 const char *key_str = (char*)xmlGetProp(xmlObj, "id");
593 const char *title_str = (char*)xmlGetProp(xmlObj, "title");
594 const char *appid_str = (char*)xmlGetProp(xmlObj, "appid");
595 const char *operation_str = (char*)xmlGetProp(xmlObj, "operation");
598 service_h svc = NULL;
599 service_create(&svc);
600 service_set_app_id(svc, appid_str); // xml property – appid
601 service_set_operation(svc, operation_str); // property : operation
602 service_send_launch_request(svc, NULL, NULL);
603 service_destroy(svc);
608 static void* label_func(void *data, xmlNode *xmlObj)
611 ret_if(!data || !xmlObj);
612 PluginNode* node = (PluginNode*)data;
613 Draw_Data *pd = node->pd;
615 const char *title = (char*)xmlGetProp(xmlObj, "title");
617 Setting_GenGroupItem_Data *obj =
618 setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
620 xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
621 0, title, NULL, NULL);
626 static void* link_func(void *data, xmlNode *xmlObj)
629 ret_if(!data || !xmlObj);
630 PluginNode* node = (PluginNode*)data;
631 Draw_Data *pd = node->pd;
633 const char *key_str = (char*)xmlGetProp(xmlObj, "id");
634 Setting_GenGroupItem_Data * obj =
635 setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
637 xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
638 0, key_str, NULL, NULL);
643 static void* launch_func(void *data, xmlNode *xmlObj)
646 ret_if(!data || !xmlObj);
647 PluginNode* node = (PluginNode*)data;
648 Draw_Data *pd = node->pd;
650 const char *title_str = (char*)xmlGetProp(xmlObj, "title");
652 Setting_GenGroupItem_Data * obj =
653 setting_create_Gendial_field_def(pd->scroller, &(itc_1text),
655 xmlObj, SWALLOW_Type_INVALID, NULL, NULL,
656 0, title_str, NULL, NULL);
661 static void __slider_stop_cb(void *data, Evas_Object *obj,
664 ret_if(data == NULL || obj == NULL);
665 double val = elm_slider_value_get(obj);
666 SETTING_TRACE("val = %f", val);
667 Setting_GenGroupItem_Data *list_item = data;
668 ret_if(list_item->userdata == NULL);
670 xmlNode* xmlObj = list_item->userdata;
673 //apply the vconf changes after stopping moving slider..
674 list_item->chk_status = (int)(val + 0.5);
675 elm_slider_value_set(obj, list_item->chk_status);
677 SETTING_TRACE(" slider after ---> val = %d", (int) list_item->chk_status);
679 // int -> double -> xmlChar*
682 sprintf(buf, "%d", (int) list_item->chk_status);
683 newattr = xmlSetProp(xmlObj, "value", buf);
685 __send_int_msg(xmlObj, list_item->chk_status);
686 __cfg_file_write((Draw_Data *)list_item->belongs_to);
690 static void* slider_func(void *data, xmlNode *xmlObj)
693 ret_if(!data || !xmlObj);
694 PluginNode* node = (PluginNode*)data;
695 Draw_Data *pd = node->pd;
698 const char *title = (char*)xmlGetProp(xmlObj, "title");
700 SETTING_TRACE (" >>> [slider input] min=%s max=%s value=%s ",(char*)xmlGetProp(xmlObj, "min"), (char*)xmlGetProp(xmlObj, "max"), (char*)xmlGetProp(xmlObj, "value"));
702 int value = atoi((char*)xmlGetProp(xmlObj, "value"));
703 int min = atoi((char*)xmlGetProp(xmlObj, "min"));
704 int max = atoi((char*)xmlGetProp(xmlObj, "max"));
706 SETTING_TRACE ("[slider input] min=%d max=%d value=%d ", min, max, value);
708 setting_create_Gendial_itc("dialogue/1text.1icon.5", &(itc_layout));
709 Setting_GenGroupItem_Data *list_item =
710 setting_create_Gendial_field_def(pd->scroller, &(itc_layout), NULL,
712 SWALLOW_Type_LAYOUT_SLIDER,
713 IMG_SENSITIVITY_ICON_01,
714 IMG_SENSITIVITY_ICON_02, value,
717 list_item->win_main = NULL;
718 list_item->evas = NULL;
719 list_item->isIndicatorVisible = true;
720 list_item->slider_min = min;
721 list_item->slider_max = max;
722 list_item->userdata = xmlObj;
723 list_item->stop_change_cb = __slider_stop_cb;
724 list_item->belongs_to = (int)pd;
727 g_list_item = list_item;
729 return (void*)list_item;
734 elm_object_item_data_set(item_to_update->item, item_to_update);
735 elm_genlist_item_update(item_to_update->item);
737 static void* navigationbar_func(void *data, xmlNode *xmlObj)
741 ret_if(!data || !xmlObj);
743 PluginNode* node = (PluginNode*)data;
744 Draw_Data *pd = node->pd;
746 //----------------------------------------------------------------
747 // [DATA] title, btn[0], btn[1]
748 const char *title = (char*)xmlGetProp(xmlObj, "title");
749 char *btn[2] = {0, };
751 // find child nodes named 'elements'
752 if (xmlObj->children) {
753 xmlNode* cur = xmlObj->children;
757 if (!xmlStrcmp(cur->name, (const xmlChar*)"button")) {
758 btn[i] = xmlGetProp(cur, "title");
759 SETTING_TRACE("------>>> node type : Element, name=%s id=%s / btn[%d] = %s ",
760 cur->name,xmlGetProp(cur, "id"),
768 //----------------------------------------------------------------
770 pd->ly_main = setting_create_layout_navi_bar_genlist(pd->win_get,
773 _(btn[1]), _(btn[0]),
774 ___click_softkey_back_cb,
775 ___click_softkey_back_cb, data, &pd->scroller,
783 static void __check_mouse_up_cb(void *data, Evas_Object *obj,
788 setting_retm_if(data == NULL, "Data parameter is NULL");
790 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
791 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
792 elm_genlist_item_selected_set(item, 0);
793 Setting_GenGroupItem_Data *list_item =
794 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
796 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
798 int old_status = elm_check_state_get(list_item->eo_check);
799 list_item->chk_status = !old_status;
800 elm_check_state_set(list_item->eo_check, list_item->chk_status);
802 xmlNode *xmlObj = data;
804 newattr = xmlSetProp(xmlObj, "state", xmlXPathCastNumberToString(list_item->chk_status));
806 __send_int_msg(xmlObj, list_item->chk_status);
807 __cfg_file_write((Draw_Data *)list_item->belongs_to);
811 static void __chk_btn_cb(void *data, Evas_Object *obj,
816 retm_if(data == NULL, "Data parameter is NULL");
817 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
819 xmlNode* xmlObj = list_item->userdata;
821 list_item->chk_status = elm_check_state_get(obj); /* for genlist update status */
824 if (list_item->chk_status == 1) {
825 newattr = xmlSetProp(xmlObj, "value", "true");
826 } else if (list_item->chk_status == 0) {
827 newattr = xmlSetProp(xmlObj, "value", "false");
829 newattr = xmlSetProp(xmlObj, "value", "false");
832 const char *id = (char*)xmlGetProp(xmlObj, "id");
833 const char *title = (char*)xmlGetProp(xmlObj, "title");
834 //SETTING_TRACE(" >>>> id:%s , title:%s", id, title);
835 __send_int_msg(xmlObj, list_item->chk_status);
836 __cfg_file_write((Draw_Data *)list_item->belongs_to);
841 static void* checkbox_func(void *data, xmlNode *xmlObj)
844 ret_if(!data || !xmlObj);
846 PluginNode* node = (PluginNode*)data;
847 Draw_Data *pd = node->pd;
849 // [DATA] title, value
850 const char *title = (char*)xmlGetProp(xmlObj, "title");
853 char* value = (char*)xmlGetProp(xmlObj, "value");
857 if ( 0 == safeStrCmp(value, "true")) {
859 } else if ( 0 == safeStrCmp(value, "false")) {
862 ival = 0; // default : false (0)
865 // title, value, xmlObj
866 Setting_GenGroupItem_Data *list_item =
867 setting_create_Gendial_field_def(pd->scroller,
871 SWALLOW_Type_1TOGGLE,
878 list_item->userdata = xmlObj;
879 list_item->belongs_to = (int) pd;
880 SETTING_TRACE("pd:%p,list_item->belongs_to:%d", pd, list_item->belongs_to);
887 static void __entry_unfocus_cb(void *data, Evas_Object *obj, void *event_info)
890 retm_if(!data || !obj, "Data parameter is NULL");
892 setting_hide_input_pannel_cb(obj);
893 const char *entry_str = elm_entry_entry_get(obj);
894 char *entry_str_utf8 = NULL;
895 entry_str_utf8 = elm_entry_markup_to_utf8(entry_str);
897 Setting_GenGroupItem_Data *list_item = data;
899 xmlNode* xmlObj = list_item->userdata;
902 const char *title = (char*)xmlSetProp(xmlObj, "value",entry_str_utf8);
904 __send_string_msg(xmlObj, entry_str_utf8);
905 __cfg_file_write((Draw_Data *)list_item->belongs_to);
907 FREE(entry_str_utf8);
911 static void __editbox_list_cb(void *data, Evas_Object *obj,
917 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
918 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
919 elm_genlist_item_selected_set(item, 0);
920 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
922 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
923 if (!elm_object_focus_get(list_item->eo_check)) {
924 elm_object_focus_set(list_item->eo_check, EINA_TRUE);
927 Ecore_IMF_Context *imf_context = (Ecore_IMF_Context *)elm_entry_imf_context_get(list_item->eo_check);
928 setting_retm_if(imf_context == NULL, "imf_context is NULL");
929 ecore_imf_context_input_panel_show(imf_context);
933 static void __editbox_changed_cb(void *data, Evas_Object *obj,
937 retm_if(!data || !obj, "Data parameter is NULL");
938 retm_if(!elm_object_focus_get(obj), "Entry is not focused");
940 Setting_GenGroupItem_Data *list_item =
941 (Setting_GenGroupItem_Data *) data;
943 const char *entry_str = elm_entry_entry_get(obj);
944 int entry_len = safeStrLen(entry_str);
945 SETTING_TRACE("entry_str:[%s], lenght:%d", entry_str, entry_len);
947 G_FREE(list_item->sub_desc);//release first
948 list_item->sub_desc = (char *)g_strdup(entry_str);
952 static void* editbox_func(void *data, xmlNode *xmlObj)
955 ret_if(!data || !xmlObj);
957 PluginNode* node = (PluginNode*)data;
958 Draw_Data *pd = node->pd;
960 const char *title = (char*)xmlGetProp(xmlObj, "title");
961 const char *key_str= (char*)xmlGetProp(xmlObj, "value");
963 const char *minlength= (char*)xmlGetProp(xmlObj, "minlength");
964 const char *maxlength= (char*)xmlGetProp(xmlObj, "maxlength");
969 max_len = atoi(maxlength);
970 SETTING_TRACE(" >> MAXLENGTH FILTER IS AVAILABLE !!!! maxlength = %d", max_len);
973 Setting_GenGroupItem_Data *list_item = NULL;
977 // without maxlength filter
978 list_item = setting_create_Gendial_field_def(pd->scroller, &(itc_1icon),
980 pd, SWALLOW_Type_LAYOUT_ENTRY,
981 NULL, NULL, 0, title, key_str,
982 __editbox_changed_cb);
985 // add max length filter
986 list_item = setting_create_Gendial_field_entry(
991 SWALLOW_Type_LAYOUT_ENTRY,
992 NULL, NULL, 0, title, key_str, __editbox_changed_cb,
993 ELM_INPUT_PANEL_LAYOUT_NORMAL,
1002 list_item->userdata = xmlObj;
1003 list_item->stop_change_cb = __entry_unfocus_cb;
1004 list_item->belongs_to = (int)pd;
1011 static void __expanditem_func_sel_cb(void *data, Evas_Object *obj, void *event_info)
1013 SETTING_TRACE_BEGIN;
1015 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
1016 Elm_Object_Item *subitem = (Elm_Object_Item *) event_info;
1017 Elm_Object_Item *parentItem = elm_genlist_item_parent_get(subitem);
1018 elm_genlist_item_selected_set(subitem, 0);
1019 Setting_GenGroupItem_Data *data_subItem = elm_object_item_data_get(subitem);
1020 Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem); /* parent data */
1021 ret_if(NULL == data_subItem || NULL == data_parentItem);
1023 elm_radio_value_set(data_subItem->rgd, data_subItem->chk_status);
1025 data_parentItem->sub_desc = (char *)g_strdup(_(data_subItem->keyStr));
1026 elm_object_item_data_set(data_parentItem->item, data_parentItem);
1027 elm_genlist_item_update(data_parentItem->item);
1029 xmlNode* xmlObj = data_parentItem->userdata;
1033 //newattr = xmlSetProp(xmlObj, "string", data_parentItem->sub_desc);
1034 newattr = xmlSetProp(xmlObj, "value", data_parentItem->sub_desc);
1036 __send_string_msg(xmlObj, data_parentItem->sub_desc);
1037 __cfg_file_write((Draw_Data *)data_parentItem->belongs_to);
1041 static void __expanditem_func_exp_cb(void *data, Evas_Object *obj, void *event_info)
1043 ret_if(NULL == data || NULL == event_info);
1044 SETTING_TRACE_BEGIN;
1046 PluginNode* node = (PluginNode*)data;
1047 Draw_Data *pd = node->pd;
1049 Elm_Object_Item *parentItem = event_info; /* parent item */
1050 Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem); /* parent data */
1051 Evas_Object *scroller = elm_object_item_widget_get(parentItem);
1054 xmlNode *xmlObj = data_parentItem->userdata;
1055 //char *value = (char*)xmlGetProp(xmlObj, "string");
1056 char *value = (char*)xmlGetProp(xmlObj, "value");
1057 SETTING_TRACE(">>> value = %s", value);
1059 Evas_Object *rgd = NULL;
1061 if (xmlObj->children && !data_parentItem->rgd) {//to protect from entering repeatly
1062 xmlNode* cur = xmlObj->children;
1064 rgd = elm_radio_add(scroller);
1065 elm_radio_value_set(rgd, -1);
1069 char *subitem_title = NULL;
1070 int subitem_index = 0;
1073 while (cur != NULL) {
1074 if (!xmlStrcmp(cur->name, (const xmlChar*)"expanditem")) {
1075 type = (char*)xmlGetProp(cur, "type");
1076 if (0 == safeStrCmp(type, "radio")) {
1077 subitem_title = (char*)xmlGetProp(cur, "title");
1078 Setting_GenGroupItem_Data *list_item =
1079 setting_create_Gendial_exp_sub_field(scroller,
1080 &(itc_1icon_1text_sub),
1081 __expanditem_func_sel_cb, NULL, parentItem,
1082 SWALLOW_Type_1RADIO, rgd,
1084 subitem_title, NULL);
1086 // SETTING_TRACE(">>> value = %s, subitem_title = %s ", value, subitem_title);
1088 if (0 == safeStrCmp(value, subitem_title)) {
1089 sel_idx = subitem_index;
1090 SETTING_TRACE("%d is selected in Radio Group", sel_idx);
1092 data_parentItem->childs = eina_list_append(data_parentItem->childs, list_item);
1096 SETTING_TRACE("invalid type[:%s]", type);
1105 elm_radio_value_set(rgd, sel_idx);
1106 data_parentItem->rgd = rgd;//protecting condition
1111 static void __expanditem_func_smart_cb(void *data, Evas_Object *obj, void *event_info)
1113 ret_if(data == NULL || event_info == NULL);
1114 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
1115 Setting_GenGroupItem_Data *data_item = elm_object_item_data_get(item);
1116 char *cb_type = data;
1118 if (0 == safeStrCmp(cb_type, "contracted")) {
1119 data_item->rgd = NULL;
1120 elm_genlist_item_subitems_clear(item);
1125 static void* settings_func(void *data, xmlNode *xmlObj)
1131 static Evas_Object *setting_create_win_layout2(Evas_Object *win_layout, Evas_Object *win_obj)
1134 Evas_Object *layout = NULL;
1135 Evas_Object *conform = elm_conformant_add(win_obj);
1136 //setting_main_appdata *ad = (setting_main_appdata *) data;
1139 layout = elm_layout_add(conform);
1140 evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1141 setting_retvm_if(layout == NULL, FALSE, "layout == NULL");
1143 elm_layout_theme_set(layout, "layout", "application", "default");
1144 evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1145 evas_object_size_hint_align_set(conform, EVAS_HINT_FILL, EVAS_HINT_FILL);
1146 elm_win_resize_object_add(win_obj, conform);
1147 elm_object_content_set(conform, layout);
1149 Evas_Object *bg = setting_create_bg(layout, win_obj, "group_list");
1150 elm_object_part_content_set(layout, "elm.swallow.bg", bg);
1151 evas_object_show(layout);
1152 evas_object_show(conform);
1154 //ad->conformant = conform;
1159 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 */
1160 Evas_Object **navi_bar,
1161 Evas_Object **titleobj)
1164 Evas_Object *layout = setting_create_win_layout2(win_layout, win_obj);
1165 *navi_bar = setting_create_navi_bar(layout);
1167 setting_create_navi_bar_buttons(title_str,
1168 lbutton_str, rbutton_str, mbutton_str,
1169 lbutton_click_cb, rbutton_click_cb,
1170 mbutton_click_cb, cb_data, eo_view /*content */ ,
1176 static void* setting_func(void *data, xmlNode *xmlObj)
1178 SETTING_TRACE_BEGIN;
1179 ret_if(!data || !xmlObj);
1182 PluginNode* node = (PluginNode*)data;
1183 Draw_Data *pd = node->pd;
1185 // [DATA] title, btn[0], btn[1]
1186 const char *title = (char*)xmlGetProp(xmlObj, "title");
1187 char *btn[2] = {/* 0 */"OK", /* 1 */"NO"};
1189 SETTING_TRACE("before setting_create_layout_navi_bar_genlist");
1192 pd->scroller = elm_genlist_add(pd->win_get);
1193 retvm_if(pd->scroller == NULL, NULL,
1194 "Cannot set scroller object as contento of layout");
1195 elm_object_style_set(pd->scroller, "dialogue");
1196 elm_genlist_clear(pd->scroller); /* first to clear list */
1199 SETTING_TRACE("_(title):%s", _(title));
1200 pd->ly_main = setting_create_layout_navi_bar2(pd->win_get, pd->win_get,
1202 _("IDS_COM_BODY_BACK"), NULL, NULL,
1203 ___click_softkey_back_cb,
1206 &(pd->navi_bar), NULL);
1207 SETTING_TRACE("after setting_create_layout_navi_bar_genlist");
1214 static void* expanditem_func(void *data, xmlNode *xmlObj)
1216 // DO NOTHING - expandlist draws this area
1220 static void* expandlist_func(void *data, xmlNode *xmlObj)
1222 SETTING_TRACE_BEGIN;
1223 ret_if(!data || !xmlObj);
1225 PluginNode* node = (PluginNode*)data;
1226 Draw_Data *pd = node->pd;
1228 const char *key_str = (char*)xmlGetProp(xmlObj, "title");
1229 const char *value = (char*)xmlGetProp(xmlObj, "value"); // string -> value
1231 setting_enable_expandable_genlist(pd->scroller, data, __expanditem_func_exp_cb, __expanditem_func_smart_cb);
1232 Setting_GenGroupItem_Data *list_item =
1233 setting_create_Gendial_exp_parent_field(pd->scroller,
1234 &(itc_2text_3_parent),
1236 SWALLOW_Type_INVALID,
1240 list_item->userdata = xmlObj;
1241 list_item->belongs_to = (int)pd;
1249 static int __node_walker(PluginNode* context, xmlNode* cur)
1251 //SETTING_TRACE_BEGIN;
1252 Draw_Data *pd = context->pd;
1255 xmlNode *cur_node = NULL;
1256 for (cur_node = cur; cur_node;cur_node = cur_node->next) {
1257 if (cur_node->type == XML_ELEMENT_NODE) {
1258 // SETTING_TRACE("node type : %s id= %s", cur_node->name,xmlGetProp(cur_node, "id"));
1259 drawer_fp fp = __drawer_find(cur_node->name);
1263 void* vret = fp(context, cur_node); // draw it
1267 Setting_GenGroupItem_Data* genlist_node = (Setting_GenGroupItem_Data* )vret;
1268 //SETTING_TRACE("add node to Eina List name : %s, id : ", cur_node->name, xmlGetProp(cur_node, "id"));
1269 // add it to the hash table create before.
1272 char* key_name = xmlGetProp(cur_node, "id");
1273 eina_hash_add(context->ui_list, strdup(key_name),(void*)genlist_node);
1277 __node_walker(context, cur_node->children); /* RECURSIVE */
1283 * @param id_str [in] "id"
1284 * @param value [in] value to be udpated
1285 * @see __expanditem_func_sel_cb
1287 static int __node_finder(PluginNode* context, xmlNode* cur, char* id_str, char* value, bool* is_end)
1289 SETTING_TRACE_BEGIN;
1290 xmlNode *cur_node = NULL;
1292 if (*is_end == true) return 0;
1294 for (cur_node = cur; cur_node;cur_node = cur_node->next) {
1295 if (cur_node->type == XML_ELEMENT_NODE) {
1297 char* id_name = (char*)xmlGetProp(cur_node, "id");
1298 if ( id_name && 0 == strcmp(id_str, id_name))
1300 SETTING_TRACE("FOUND >>>> %s", id_name);
1301 // cur_node - update xml code
1302 xmlAttrPtr newattr = xmlSetProp(cur_node, "value", value);
1304 //-----------------------------------------------------------
1307 if ( 0 == strcmp (cur_node->name, "integer"))
1309 SETTING_TRACE(">>>>> UPDATE SLIDER CONTROL %x --- %s ",context->ui_list, id_name);
1310 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1313 item_to_update->chk_status = atoi(value);
1314 SETTING_TRACE(">>> o-------------0 SLIDER VALUE = %d ", item_to_update->chk_status);
1316 elm_object_item_data_set(item_to_update->item, item_to_update);
1317 elm_genlist_item_update(item_to_update->item);
1319 SETTING_TRACE("item_to_update is NULL");
1323 if ( 0 == strcmp (cur_node->name, "bool"))
1325 SETTING_TRACE(">>>>> UPDATE TOGGLE CONTROL %x --- %s ",context->ui_list, id_name);
1326 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1329 item_to_update->chk_status = atoi(value);
1330 SETTING_TRACE(">>> o-------------0 TOGGLE VALUE = %d ", item_to_update->chk_status);
1332 elm_object_item_data_set(item_to_update->item, item_to_update);
1333 elm_genlist_item_update(item_to_update->item);
1335 SETTING_TRACE("item_to_update is NULL");
1338 // case : edit control
1339 if ( 0 == strcmp (cur_node->name, "string"))
1341 SETTING_TRACE(">>>>> UPDATE EDIT CONTROL CONTROL %x --- %s ",context->ui_list, id_name);
1342 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1345 char* old_string = item_to_update->sub_desc;
1346 item_to_update->sub_desc = strdup(value);
1347 SETTING_TRACE(">>> o-------------0 STRING VALUE = %s ", value);
1351 elm_object_item_data_set(item_to_update->item, item_to_update);
1352 elm_genlist_item_update(item_to_update->item);
1355 SETTING_TRACE("item_to_update is NULL");
1358 // case : expand list
1364 //-----------------------------------------------------------
1365 if ( 0 == strcmp (cur_node->name, "expandlist"))
1367 SETTING_TRACE(">>>>> UPDATE EXPAND LIST CONTROL %x --- %s ",context->ui_list, id_name);
1368 Setting_GenGroupItem_Data* item_to_update = (Setting_GenGroupItem_Data*)eina_hash_find(context->ui_list, id_name);
1371 char* old_string = item_to_update->sub_desc;
1372 item_to_update->sub_desc = strdup(value);
1373 SETTING_TRACE(">>> o-------------0 EXPAND LIST VALUE = %s ", value);
1377 elm_object_item_data_set(item_to_update->item, item_to_update);
1378 elm_genlist_item_update(item_to_update->item);
1380 // TODO: need to update child elements
1381 // item_to_update->childs ---> expanded list
1382 if (item_to_update->childs)
1384 Eina_List *li = item_to_update->childs;
1385 int radio_index = 0;
1388 Setting_GenGroupItem_Data* node = eina_list_data_get(li);
1389 // do something more
1390 // SETTING_TRACE(">>> RADIO LIST STRING VALUE = %s ", node->keyStr);
1391 // set position of radio button
1392 if (strcmp(node->keyStr, value) == 0)
1394 elm_radio_value_set(node->rgd, radio_index);
1396 elm_object_item_data_set(item_to_update->item, item_to_update);
1397 elm_genlist_item_update(item_to_update->item);
1400 li = eina_list_next(li);
1406 SETTING_TRACE("item_to_update is NULL");
1413 __node_finder(context, cur_node->children, id_str, value, is_end); /* RECURSIVE */
1418 static unsigned int _plugin_string_key_length(const char*key)
1423 return (int)strlen(key) + 1;
1426 static int _plugin_string_key_cmp(const char* key1, int key1_length,
1427 const char* key2, int key2_length)
1429 return strcmp(key1, key2);
1432 static void _plugin_entry_free_cb(void* data)
1434 Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) data;
1437 eina_list_free(node->childs);
1438 node->childs = NULL;
1442 //static PluginNode* g_context;
1444 PluginNode* setting_plugin_create()
1446 PluginNode *node = calloc(1, sizeof(PluginNode));
1448 Draw_Data *pd = calloc(1, sizeof(Draw_Data));
1449 setting_retvm_if(!pd, -1, "Create Draw_Data obj failed");
1453 node->ui_list = eina_hash_new(EINA_KEY_LENGTH(_plugin_string_key_length),
1454 EINA_KEY_CMP(_plugin_string_key_cmp),
1455 EINA_KEY_HASH(eina_hash_superfast),
1456 _plugin_entry_free_cb,
1462 void setting_plugin_destroy(PluginNode* node)
1464 SETTING_TRACE_BEGIN;
1466 SETTING_TRACE("node is NOT NULL")
1468 SETTING_TRACE("node->pd is NOT NULL")
1469 if(node->pd->doc != NULL) {
1470 xmlSaveFormatFile(node->plugin_path, node->pd->doc, 1);
1471 xmlFreeDoc(node->pd->doc);
1472 node->pd->doc = NULL;
1473 SETTING_TRACE("__cfg_file_write successful");
1480 if (node->ui_list) {
1481 eina_hash_free(node->ui_list);
1482 node->ui_list = NULL;
1490 static Eina_Bool _plugin_foreach_cb(const Eina_Hash *hash, const void*key, void* data, void* fdata)
1492 Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) data;
1493 SETTING_TRACE("%s --- %s ", (char*)key, node->keyStr);
1498 void setting_plugin_debug(PluginNode* context)
1500 // SETTING_TRACE("HASH TABLE -------------------------------------");
1501 eina_hash_foreach(context->ui_list,_plugin_foreach_cb, NULL);
1502 // SETTING_TRACE("HASH TABLE -------------------------------------");
1506 void setting_plugin_update(PluginNode* context)
1508 Eina_List *li = context->ui_list;
1511 Setting_GenGroupItem_Data* node = (Setting_GenGroupItem_Data*) eina_list_data_get(li);
1513 // SETTING_TRACE(" ---> keyStr : %s , swallow type : %d ", node->keyStr, node->swallow_type);
1514 Setting_GenGroupItem_Data* item_to_update = NULL;
1515 item_to_update = node;
1516 elm_object_item_data_set(item_to_update->item, item_to_update);
1517 elm_genlist_item_update(item_to_update->item);
1519 li = eina_list_next(li);
1527 bool setting_plugin_load(PluginNode* context, const char *cfg_file)
1529 SETTING_TRACE("cfg_file:%s", cfg_file)
1530 if (isEmptyStr(cfg_file) || 0 != access(cfg_file, R_OK|W_OK|F_OK ))
1532 SETTING_TRACE_ERROR(" error occured : access \n");
1535 context->pd->cfg_file = cfg_file;
1536 context->pd->win_get = (Evas_Object *) ug_get_window();
1538 GError *error = NULL;
1540 context->pd->doc = xmlParseFile(cfg_file);
1541 context->pd->root = xmlDocGetRootElement(context->pd->doc);
1543 // TODO: error handler here
1544 __node_walker(context, context->pd->root);
1547 setting_plugin_debug(context);