2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include "ug-nfc-setting-main.h"
21 #include "ug-nfc-setting-db.h"
33 static int pd_item_cnt;
34 static GArray *pd_item_l;
36 static Elm_Genlist_Item_Class itc_sep;
37 static Elm_Genlist_Item_Class itc_1text2icon;
39 static void __nfc_vconf_changed_cb(keynode_t *key, void *data)
41 ugdata_t *ug_data = (ugdata_t *)data;
42 Elm_Object_Item *it, *next;
45 if (!ug_data || !key->keyname)
48 LOGD("key->keyname [%s]", key->keyname);
50 if (strncmp(key->keyname, VCONFKEY_NFC_STATE,
51 strlen(VCONFKEY_NFC_STATE)) != 0) {
55 if (!vconf_get_bool(key->keyname, &boolval) && !boolval) {
56 if (vconf_set_bool(VCONFKEY_NFC_PREDEFINED_ITEM_STATE,
57 VCONFKEY_NFC_PREDEFINED_ITEM_OFF)) {
58 LOGE("vconf_set_bool failed");
60 elm_check_state_set(ug_data->pd_on_off, EINA_FALSE);
63 if (!vconf_get_bool(VCONFKEY_NFC_PREDEFINED_ITEM_STATE, &boolval)) {
64 it = elm_genlist_first_item_get(ug_data->pd_genlist);
66 next = elm_genlist_item_next_get(it);
69 elm_object_item_disabled_set(it, EINA_FALSE);
71 elm_object_item_disabled_set(it, EINA_TRUE);
78 static void __title_pd_on_off_clicked_cb(void *data, Evas_Object *obj,
81 ugdata_t *ug_data = (ugdata_t *)data;
82 Elm_Object_Item *it, *next;
85 if (ug_data == NULL) {
90 __change_predefined_item_onoff_setting(ug_data);
92 if (!vconf_get_bool(VCONFKEY_NFC_PREDEFINED_ITEM_STATE, &boolval)) {
93 it = elm_genlist_first_item_get(ug_data->pd_genlist);
95 next = elm_genlist_item_next_get(it);
98 elm_object_item_disabled_set(it, EINA_FALSE);
100 elm_object_item_disabled_set(it, EINA_TRUE);
107 static char *__gl_text_get(void *data, Evas_Object *obj, const char *part)
109 int index = (int) data;
110 pd_data *item = NULL;
113 //LOGD("index : %d", index);
114 //LOGD("[Genlist] part : %s", part);
116 if (!strcmp(part, "elm.text") || !strcmp(part, "elm.text.1")) {
117 item = g_array_index(pd_item_l, pd_data *, index);
118 if ((item != NULL) && (item->msgDes != NULL)) {
119 text = strdup(item->msgDes);
120 //LOGD("msgDes : %s", item->msgDes);
128 static Evas_Object *__gl_content_get(void *data, Evas_Object *obj,
131 int index = (int) data;
132 pd_data *item = NULL;
133 Evas_Object *content = NULL;
134 Evas_Object *radio_group;
136 //LOGD("[Genlist] index : %d", index);
137 //LOGD("[Genlist] part : %s", part);
139 if (!strcmp(part, "elm.icon") || !strcmp(part, "elm.icon.1")) {
140 item = g_array_index(pd_item_l, pd_data *, index);
142 radio_group = evas_object_data_get(obj, "radio");
143 content = elm_radio_add(obj);
144 elm_radio_state_value_set(content, index);
145 elm_radio_group_add(content, radio_group);
147 if ((item != NULL) && (item->app_id != NULL)) {
150 app_id = vconf_get_str(VCONFKEY_NFC_PREDEFINED_ITEM);
151 if (app_id != NULL) {
152 if (!strcmp(app_id, item->app_id)) {
153 elm_radio_value_set(content, index);
159 evas_object_size_hint_weight_set(content, EVAS_HINT_EXPAND,
161 evas_object_size_hint_align_set(content, EVAS_HINT_FILL,
165 item = g_array_index(pd_item_l, pd_data *, index);
167 if ((item != NULL) && (item->iconPath != NULL)) {
168 content = elm_image_add(obj);
169 elm_image_file_set(content, item->iconPath, NULL);
170 elm_image_resizable_set(content, EINA_TRUE, EINA_TRUE);
177 static Eina_Bool __gl_state_get(void *data, Evas_Object *obj,
183 static void __gl_sel(void *data, Evas_Object *obj, void *event_info)
185 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
187 pd_data *pd_item = NULL;
193 elm_genlist_item_selected_set(item, 0);
195 index = (int) elm_object_item_data_get(item);
197 pd_item = g_array_index(pd_item_l, pd_data *, index);
199 if ((pd_item != NULL) && (pd_item->app_id != NULL)) {
200 if (vconf_set_str(VCONFKEY_NFC_PREDEFINED_ITEM,
202 LOGE("vconf_set_str failed");
205 elm_genlist_item_update(item);
208 static void __create_pd_data(void)
210 pd_data *item = NULL;
213 if (_ug_nfc_setting_db_open_table(&dbtable_h)) {
214 LOGE("_ug_nfc_setting_db_open_table is failed!!!!!");
219 _ug_nfc_setting_db_get_count(&pd_item_cnt);
220 LOGD("pd_item_cnt [%d]", pd_item_cnt);
222 /* create item list */
223 pd_item_l = g_array_new(FALSE, FALSE,
226 for (index = 0; index < pd_item_cnt; index++) {
227 item = (pd_data *) malloc(sizeof(pd_data));
229 LOGE("failed to allocation");
233 if (!_ug_nfc_setting_db_get_next_record(dbtable_h,
239 //LOGD("app_id:%s, pkgName:%s, iconPath:%s, msgDes:%s", item->app_id, item->pkgName, item->iconPath, item->msgDes);
241 g_array_append_val(pd_item_l, item);
247 _ug_nfc_setting_db_close_table(dbtable_h);
250 static void __destroy_pd_data(void)
252 if (pd_item_l != NULL) {
253 pd_data *old_info = NULL;
256 for (index = 0; index < pd_item_cnt; index++) {
257 old_info = g_array_index(pd_item_l, pd_data *, index);
259 if (old_info != NULL) {
260 free(old_info->app_id);
261 free(old_info->pkgName);
262 free(old_info->iconPath);
263 free(old_info->msgDes);
268 g_array_free(pd_item_l, FALSE);
272 static void __genlist_free_cb(void *data, Evas *e, Evas_Object *obj,
275 Evas_Object *radio_group = evas_object_data_get(obj, "radio");
278 evas_object_del(radio_group);
281 Evas_Object *__create_predefined_item_list(void *data)
283 ugdata_t *ug_data = (ugdata_t *)data;
284 Evas_Object *genlist, *radio_group;
285 Elm_Object_Item* separator;
288 /* create item data */
292 genlist = elm_genlist_add(ug_data->base_naviframe);
294 LOGE("genlist is null");
298 elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
299 evas_object_event_callback_add(genlist, EVAS_CALLBACK_FREE,
300 __genlist_free_cb, NULL);
303 radio_group = elm_radio_add(genlist);
304 elm_radio_state_value_set(radio_group, 0);
305 elm_radio_value_set(radio_group, 0);
306 evas_object_data_set(genlist, "radio", radio_group);
308 itc_sep.item_style = "dialogue/separator";
309 itc_sep.func.text_get = NULL;
310 itc_sep.func.content_get = NULL;
311 itc_sep.func.state_get = NULL;
312 itc_sep.func.del = NULL;
314 itc_1text2icon.item_style = "1text.2icon.2";
315 itc_1text2icon.func.text_get = __gl_text_get;
316 itc_1text2icon.func.content_get = __gl_content_get;
317 itc_1text2icon.func.state_get = __gl_state_get;
318 itc_1text2icon.func.del = NULL;
321 separator = elm_genlist_item_append(genlist, &itc_sep, NULL, NULL,
322 ELM_GENLIST_ITEM_NONE, NULL, NULL);
323 elm_genlist_item_select_mode_set(separator,
324 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
325 elm_object_item_access_unregister(separator);
328 if (!vconf_get_bool(VCONFKEY_NFC_PREDEFINED_ITEM_STATE, &boolval)) {
329 for (index = 0; index < pd_item_cnt; index++) {
332 it = elm_genlist_item_append(genlist,
333 &itc_1text2icon, (void *)index,
334 NULL, ELM_GENLIST_ITEM_NONE,
337 elm_object_item_disabled_set(it, EINA_FALSE);
339 elm_object_item_disabled_set(it, EINA_TRUE);
342 separator = elm_genlist_item_append(genlist, &itc_sep,
343 NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
344 elm_genlist_item_select_mode_set(separator,
345 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
346 elm_object_item_access_unregister(separator);
350 evas_object_show(genlist);
352 vconf_notify_key_changed(VCONFKEY_NFC_STATE ,
353 __nfc_vconf_changed_cb, ug_data);
358 static Eina_Bool __destroy_predefined_item_list(void *data,
361 ugdata_t *ug_data = (ugdata_t *)data;
367 if (ug_data && ug_data->ns_genlist) {
368 elm_genlist_realized_items_update(ug_data->ns_genlist);
371 vconf_ignore_key_changed(VCONFKEY_NFC_STATE,
372 __nfc_vconf_changed_cb);
377 bool _ug_nfc_check_predefined_item_available(void)
379 if (!_ug_nfc_setting_db_open_table(&dbtable_h)) {
380 _ug_nfc_setting_db_close_table(dbtable_h);
387 void _ug_nfc_predefined_item_create(void *data)
389 ugdata_t *ug_data = (ugdata_t *)data;
390 Evas_Object *genlist;
394 LOGE("invalid paramater");
398 /* create setting view */
399 ug_data->pd_genlist = genlist = __create_predefined_item_list(ug_data);
404 ug_data->base_navi_it = elm_naviframe_item_push(ug_data->base_naviframe,
405 IDS_USE_NFC_IN_HOME, NULL, NULL, genlist, NULL);
406 elm_naviframe_item_pop_cb_set(ug_data->base_navi_it,
407 __destroy_predefined_item_list, ug_data);
409 ug_data->pd_on_off = elm_check_add(ug_data->base_naviframe);
410 elm_object_style_set(ug_data->pd_on_off, "naviframe/title_on&off");
411 elm_object_item_part_content_set(ug_data->base_navi_it,
412 "title_right_btn", ug_data->pd_on_off);
413 evas_object_smart_callback_add(ug_data->pd_on_off, "changed",
414 __title_pd_on_off_clicked_cb, ug_data);
416 if (!vconf_get_bool(VCONFKEY_NFC_PREDEFINED_ITEM_STATE, &boolval) &&
418 elm_check_state_set(ug_data->pd_on_off, EINA_TRUE);
420 elm_check_state_set(ug_data->pd_on_off, EINA_FALSE);