2 * Copyright 2012 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://www.tizenopensource.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.
19 #include <Elementary.h>
20 #include <location-appman.h>
22 #include "libug-setting-location-efl.h"
23 #include "libug-setting-location-efl-log.h"
25 static void _setting_location_app_cb(void *data, Evas_Object * obj, void *event_info)
27 location_appman_info *app_info = (location_appman_info *)data;
30 Eina_Bool state = elm_check_state_get(obj);
32 onoff = (state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
33 location_appman_set_on(app_info->package, onoff);
36 static char *_setting_location_gl_app_text_get(void *data, Evas_Object * obj, const char *part)
38 location_appman_info *app_info = (location_appman_info *)data;
41 if (location_appman_get_name(app_info->package, &name) != LOCATION_APPMAN_ERROR_NONE) {
42 LOC_LOG("Fail to [%s] location_appman_get_name", app_info->package);
45 LOC_LOG("package [%s], get_name [%s]", app_info->package, name);
49 static char *_setting_location_gl_app_msg_get(void *data, Evas_Object * obj, const char *part)
51 return strdup(_("IDS_LBS_BODY_APPLICATIONS_BELOW_MAY_USE_YOUR_LOCATION_DATA_IF_ALLOWED"));
54 static Evas_Object *_setting_location_gl_app_check_get(void *data, Evas_Object * obj, const char *part)
56 location_appman_info *app_info = (location_appman_info *)data;
60 app_info->tg = tg = elm_check_add(obj);
62 location_appman_is_enabled(app_info->package, &enabled);
64 if (enabled == KEY_ENABLED) {
65 elm_check_state_set(tg, EINA_TRUE);
67 elm_check_state_set(tg, EINA_FALSE);
70 elm_object_style_set(tg, "on&off");
71 evas_object_propagate_events_set(tg, EINA_FALSE);
72 evas_object_smart_callback_add(tg, "changed", _setting_location_app_cb, app_info);
77 static void setting_location_gl_app_sel(void *data, Evas_Object *obj, void *event_info)
79 location_appman_info *app_info = (location_appman_info *)data;
82 Eina_Bool state = elm_check_state_get(app_info->tg);
84 elm_check_state_set(app_info->tg, !state);
85 onoff = (!state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
86 location_appman_set_on(app_info->package, onoff);
87 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
90 void setting_location_delete_app_list(Evas_Object *genlist, struct ug_data *ugd)
94 if (ugd->itc_msg != NULL) {
95 elm_object_item_del(ugd->gi_msg);
96 elm_genlist_item_class_free(ugd->itc_msg);
98 if (ugd->itc_line != NULL) {
99 elm_object_item_del(ugd->gi_line);
100 elm_genlist_item_class_free(ugd->itc_line);
103 if (ugd->app_info == NULL) {
107 for (i = 0; i < ugd->app_count; i++) {
108 if (ugd->app_info[i].gi_app != NULL) {
109 elm_object_item_del(ugd->app_info[i].gi_app);
111 if (ugd->app_info[i].itc_app != NULL) {
112 elm_genlist_item_class_free(ugd->app_info[i].itc_app);
119 void setting_location_appman_init(struct ug_data *ugd)
121 ugd->app_info = NULL;
122 ugd->itc_line = NULL;
128 int setting_location_get_location_app_list(Evas_Object *genlist, struct ug_data *ugd)
131 location_appman_s *app_list;
132 Elm_Object_Item *item;
134 if (location_appman_get_app_list(LOCATION_APPMAN_COLUMN_INSTALLED_DATE, &ugd->app_count, &app_list) != LOCATION_APPMAN_ERROR_NONE) {
135 LOC_LOG("Fail to location_appman_get_app_list");
138 setting_location_appman_init(ugd);
139 LOC_LOG("app count : %d", ugd->app_count);
140 if (ugd->app_count <= 0) {
141 LOC_LOG("There is no location application in DB");
145 if (ugd->app_count == 1 && (strcmp(app_list[0].package, "org.tizen.setting") == 0)) {
146 LOC_LOG("Setting application is only one location application");
150 ugd->app_info = (location_appman_info *)malloc(sizeof(location_appman_info) * ugd->app_count);
152 ugd->itc_msg = elm_genlist_item_class_new();
153 ugd->itc_msg->item_style = "multiline/1text";
154 ugd->itc_msg->func.text_get = _setting_location_gl_app_msg_get;
155 ugd->itc_msg->func.content_get = NULL;
156 ugd->itc_msg->func.state_get = NULL;
157 ugd->itc_msg->func.del = NULL;
159 ugd->itc_line= elm_genlist_item_class_new();
160 ugd->itc_line->item_style = "dialogue/separator/1/with_line";
161 ugd->itc_line->func.text_get = NULL;
162 ugd->itc_line->func.content_get = NULL;
163 ugd->itc_line->func.state_get = NULL;
164 ugd->itc_line->func.del = NULL;
166 ugd->gi_msg = elm_genlist_item_append(genlist, ugd->itc_msg, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
167 elm_genlist_item_select_mode_set(ugd->gi_msg, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
169 ugd->gi_line = elm_genlist_item_append(genlist, ugd->itc_line, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
170 elm_genlist_item_select_mode_set(ugd->gi_line, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
172 for (i = 0; i < ugd->app_count; i++) {
173 strcpy(ugd->app_info[i].package, app_list[i].package);
174 ugd->app_info[i].itc_app = elm_genlist_item_class_new();
175 ugd->app_info[i].itc_app->item_style = "dialogue/1text.1icon";
176 ugd->app_info[i].itc_app->func.text_get = _setting_location_gl_app_text_get;
177 ugd->app_info[i].itc_app->func.content_get = _setting_location_gl_app_check_get;
178 ugd->app_info[i].itc_app->func.state_get = NULL;
179 ugd->app_info[i].itc_app->func.del = NULL;
181 if (strcmp(app_list[i].package, "org.tizen.setting") == 0) {
182 ugd->app_info[i].gi_app = NULL;
186 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]);