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 for (i = 0; i < ugd->app_count; i++) {
104 if (ugd->app_info[i].gi_app != NULL) {
105 elm_object_item_del(ugd->app_info[i].gi_app);
107 if (ugd->app_info[i].itc_app != NULL) {
108 elm_genlist_item_class_free(ugd->app_info[i].itc_app);
112 if (ugd->app_info != NULL) {
117 int setting_location_get_location_app_list(Evas_Object *genlist, struct ug_data *ugd)
120 location_appman_s *app_list;
121 Elm_Object_Item *item;
123 if (location_appman_get_app_list(LOCATION_APPMAN_COLUMN_INSTALLED_DATE, &ugd->app_count, &app_list) != LOCATION_APPMAN_ERROR_NONE) {
124 LOC_LOG("Fail to location_appman_get_app_list");
128 LOC_LOG("app count : %d", ugd->app_count);
129 if (ugd->app_count <= 0) {
130 LOC_LOG("There is no location application in DB");
134 if (ugd->app_count == 1 && (strcmp(app_list[0].package, "org.tizen.setting") == 0)) {
135 LOC_LOG("Setting application is only one location application");
136 ugd->itc_line = NULL;
143 ugd->app_info = (location_appman_info *)malloc(sizeof(location_appman_info) * ugd->app_count);
145 ugd->itc_msg = elm_genlist_item_class_new();
146 ugd->itc_msg->item_style = "multiline/1text";
147 ugd->itc_msg->func.text_get = _setting_location_gl_app_msg_get;
148 ugd->itc_msg->func.content_get = NULL;
149 ugd->itc_msg->func.state_get = NULL;
150 ugd->itc_msg->func.del = NULL;
152 ugd->itc_line= elm_genlist_item_class_new();
153 ugd->itc_line->item_style = "dialogue/separator/1/with_line";
154 ugd->itc_line->func.text_get = NULL;
155 ugd->itc_line->func.content_get = NULL;
156 ugd->itc_line->func.state_get = NULL;
157 ugd->itc_line->func.del = NULL;
159 ugd->gi_msg = elm_genlist_item_append(genlist, ugd->itc_msg, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
160 elm_genlist_item_select_mode_set(ugd->gi_msg, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
162 ugd->gi_line = elm_genlist_item_append(genlist, ugd->itc_line, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
163 elm_genlist_item_select_mode_set(ugd->gi_line, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
165 for (i = 0; i < ugd->app_count; i++) {
166 strcpy(ugd->app_info[i].package, app_list[i].package);
167 ugd->app_info[i].itc_app = elm_genlist_item_class_new();
168 ugd->app_info[i].itc_app->item_style = "dialogue/1text.1icon";
169 ugd->app_info[i].itc_app->func.text_get = _setting_location_gl_app_text_get;
170 ugd->app_info[i].itc_app->func.content_get = _setting_location_gl_app_check_get;
171 ugd->app_info[i].itc_app->func.state_get = NULL;
172 ugd->app_info[i].itc_app->func.del = NULL;
174 if (strcmp(app_list[i].package, "org.tizen.setting") == 0) {
175 ugd->app_info[i].gi_app = NULL;
179 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]);