2 * Open Service Platform
3 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd
5 * Licensed under the Flora License, Version 1.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://floralicense.org/license/
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 #include <Elementary.h>
21 #include <location-appman.h>
23 #include "libug-setting-location-efl.h"
24 #include "libug-setting-location-efl-log.h"
26 static void _setting_location_app_cb(void *data, Evas_Object * obj, void *event_info)
28 location_appman_info *app_info = (location_appman_info *)data;
31 Eina_Bool state = elm_check_state_get(obj);
33 onoff = (state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
34 location_appman_set_on(app_info->package, onoff);
37 static char *_setting_location_gl_app_text_get(void *data, Evas_Object * obj, const char *part)
39 location_appman_info *app_info = (location_appman_info *)data;
42 if (location_appman_get_name(app_info->package, &name) != LOCATION_APPMAN_ERROR_NONE) {
43 LOC_LOG("Fail to [%s] location_appman_get_name", app_info->package);
46 LOC_LOG("package [%s], get_name [%s]", app_info->package, name);
50 static char *_setting_location_gl_app_msg_get(void *data, Evas_Object * obj, const char *part)
52 return strdup(_("IDS_LBS_BODY_APPLICATIONS_BELOW_MAY_USE_YOUR_LOCATION_DATA_IF_ALLOWED"));
55 static Evas_Object *_setting_location_gl_app_check_get(void *data, Evas_Object * obj, const char *part)
57 location_appman_info *app_info = (location_appman_info *)data;
61 app_info->tg = tg = elm_check_add(obj);
63 location_appman_is_enabled(app_info->package, &enabled);
65 if (enabled == KEY_ENABLED) {
66 elm_check_state_set(tg, EINA_TRUE);
68 elm_check_state_set(tg, EINA_FALSE);
71 elm_object_style_set(tg, "on&off");
72 evas_object_propagate_events_set(tg, EINA_FALSE);
73 evas_object_smart_callback_add(tg, "changed", _setting_location_app_cb, app_info);
78 static void setting_location_gl_app_sel(void *data, Evas_Object *obj, void *event_info)
80 location_appman_info *app_info = (location_appman_info *)data;
83 Eina_Bool state = elm_check_state_get(app_info->tg);
85 onoff = (!state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
86 location_appman_set_on(app_info->package, onoff);
87 elm_genlist_item_update(app_info->gi_app);
88 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
91 void setting_location_delete_app_list(Evas_Object *genlist, struct ug_data *ugd)
95 if (ugd->itc_bot_sep != NULL) {
96 elm_object_item_del(ugd->gi_bot_sep);
97 elm_genlist_item_class_free(ugd->itc_bot_sep);
100 if (ugd->itc_msg != NULL) {
101 elm_object_item_del(ugd->gi_msg);
102 elm_genlist_item_class_free(ugd->itc_msg);
105 if (ugd->app_info == NULL) {
109 for (i = 0; i < ugd->app_count; i++) {
110 if (ugd->app_info[i].gi_app != NULL) {
111 elm_object_item_del(ugd->app_info[i].gi_app);
113 if (ugd->app_info[i].itc_app != NULL) {
114 elm_genlist_item_class_free(ugd->app_info[i].itc_app);
121 void setting_location_appman_init(struct ug_data *ugd)
123 ugd->app_info = NULL;
128 int setting_location_get_location_app_list(Evas_Object *genlist, struct ug_data *ugd)
131 location_appman_s *app_list;
133 if (location_appman_get_app_list(LOCATION_APPMAN_COLUMN_INSTALLED_DATE, &ugd->app_count, &app_list) != LOCATION_APPMAN_ERROR_NONE) {
134 LOC_LOG("Fail to location_appman_get_app_list");
137 setting_location_appman_init(ugd);
138 LOC_LOG("app count : %d", ugd->app_count);
139 if (ugd->app_count <= 0) {
140 LOC_LOG("There is no location application in DB");
144 if (ugd->app_count == 1 && (strcmp(app_list[0].package, "org.tizen.setting") == 0)) {
145 LOC_LOG("Setting application is only one location application");
149 ugd->app_info = (location_appman_info *)malloc(sizeof(location_appman_info) * ugd->app_count);
150 if (ugd->app_info == NULL) {
151 LOC_LOG("Fail to alloc to app_info");
156 ugd->itc_msg = elm_genlist_item_class_new();
157 ugd->itc_msg->item_style = "multiline/1text";
158 ugd->itc_msg->func.text_get = _setting_location_gl_app_msg_get;
159 ugd->itc_msg->func.content_get = NULL;
160 ugd->itc_msg->func.state_get = NULL;
161 ugd->itc_msg->func.del = NULL;
163 ugd->gi_msg = elm_genlist_item_append(genlist, ugd->itc_msg, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
164 elm_genlist_item_select_mode_set(ugd->gi_msg, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
166 for (i = 0; i < ugd->app_count; i++) {
167 strcpy(ugd->app_info[i].package, app_list[i].package);
168 ugd->app_info[i].itc_app = elm_genlist_item_class_new();
169 ugd->app_info[i].itc_app->item_style = "dialogue/1text.1icon";
170 ugd->app_info[i].itc_app->func.text_get = _setting_location_gl_app_text_get;
171 ugd->app_info[i].itc_app->func.content_get = _setting_location_gl_app_check_get;
172 ugd->app_info[i].itc_app->func.state_get = NULL;
173 ugd->app_info[i].itc_app->func.del = NULL;
175 if (strcmp(app_list[i].package, "org.tizen.setting") == 0) {
176 ugd->app_info[i].gi_app = NULL;
178 ugd->app_info[i].gi_app = elm_genlist_item_append(genlist, ugd->app_info[i].itc_app, (void *)&ugd->app_info[i], NULL, ELM_GENLIST_ITEM_NONE, setting_location_gl_app_sel, (void *)&ugd->app_info[i]);
182 ugd->itc_bot_sep = elm_genlist_item_class_new();
183 ugd->itc_bot_sep->item_style = "dialogue/separator";
184 ugd->itc_bot_sep->func.text_get = NULL;
185 ugd->itc_bot_sep->func.content_get = NULL;
186 ugd->itc_bot_sep->func.state_get = NULL;
187 ugd->itc_bot_sep->func.del = NULL;
188 ugd->gi_bot_sep = elm_genlist_item_append(genlist, ugd->itc_bot_sep, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
189 elm_genlist_item_select_mode_set(ugd->gi_bot_sep, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);