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.
18 #define UG_MODULE_API __attribute__ ((visibility("default")))
21 #include <Elementary.h>
22 #include <ui-gadget-module.h>
24 #include <vconf-internal-location-keys.h>
25 #include <location-appman.h>
27 #include "libug-setting-location-efl.h"
28 #include "libug-setting-location-efl-mypos.h"
29 #include "libug-setting-location-efl-help.h"
30 #include "libug-setting-location-efl-appman.h"
31 #include "libug-setting-location-efl-log.h"
33 #define END_KEY_EVENT FALSE
35 static char *menu[] = {
36 N_("IDS_LBS_BODY_GPS"),
37 N_("IDS_LBS_BODY_ADVANCED_GPS"),
38 N_("IDS_LBS_BODY_NETWORK_POSITION"),
39 N_("IDS_LBS_BODY_MY_POSITION")
42 #define LOCATION_MENU_ENABLE 0
43 #define LOCATION_MENU_AGPS 1
44 #define LOCATION_MENU_NET 2
45 #define LOCATION_MENU_MYPOS 3
47 int setting_location_set_int(const char *path, int val)
49 int ret = vconf_set_int(path, val);
56 void setting_location_check_di(void *data)
58 LOC_LOG("setting_location_check_di");
59 struct ug_data *ugd = (struct ug_data *)data;
62 elm_check_state_set(ugd->tg_gps, ugd->is_gps);
63 elm_object_item_disabled_set(ugd->gi_agps, !ugd->is_gps);
65 elm_check_state_set(ugd->tg_net, ugd->is_net);
67 elm_object_item_disabled_set(ugd->gi_mypos, !(ugd->is_gps || ugd->is_net));
68 for (i = 0; i < ugd->app_count; i++) {
69 elm_object_item_disabled_set(ugd->app_info[i].gi_app, !(ugd->is_gps || ugd->is_net));
73 static void setting_location_free_itc(Elm_Genlist_Item_Class *itc)
78 elm_genlist_item_class_free(itc);
82 static void setting_location_back_cb(void *data, Evas_Object * obj, void *event_info)
84 struct ug_data *ugd = (struct ug_data *)data;
87 setting_location_free_itc(ugd->itc_sep);
88 setting_location_free_itc(ugd->itc_line);
89 setting_location_free_itc(ugd->itc_gps);
90 setting_location_free_itc(ugd->itc_msg);
91 setting_location_free_itc(ugd->itc_agps);
92 setting_location_free_itc(ugd->itc_net);
93 setting_location_free_itc(ugd->itc_mypos);
94 for (i = 0; i < ugd->app_count; i++) {
95 setting_location_free_itc(ugd->app_info[i].itc_app);
97 if (ugd->app_info != NULL) {
100 ug_destroy_me(ugd->ug);
103 static void setting_location_help_cb(void *data, Evas_Object * obj, void *event_info)
105 struct ug_data *ugd = (struct ug_data *)data;
107 setting_location_help_view(ugd);
110 static void _setting_location_gps_cb(void *data, Evas_Object * obj, void *event_info)
112 struct ug_data *ugd = (struct ug_data *)data;
114 Eina_Bool state = elm_check_state_get(obj);
116 ugd->is_gps = (state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
117 setting_location_set_int(VCONFKEY_LOCATION_ENABLED, ugd->is_gps);
118 setting_location_check_di(ugd);
121 static void _setting_location_agps_cb(void *data, Evas_Object * obj, void *event_info)
123 struct ug_data *ugd = (struct ug_data *)data;
125 Eina_Bool state = elm_check_state_get(obj);
127 if (ugd->is_gps == KEY_DISABLED) {
128 elm_check_state_set(obj, !state);
131 ugd->is_agps = (state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
132 setting_location_set_int(VCONFKEY_LOCATION_AGPS_ENABLED, ugd->is_agps);
135 static void _setting_location_net_cb(void *data, Evas_Object * obj, void *event_info)
137 struct ug_data *ugd = (struct ug_data *)data;
139 Eina_Bool state = elm_check_state_get(obj);
141 ugd->is_net = (state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
142 setting_location_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, ugd->is_net);
143 setting_location_check_di(ugd);
146 static char *_setting_location_gl_gps_text_get(void *data, Evas_Object * obj, const char *part)
148 return strdup(_(menu[LOCATION_MENU_ENABLE]));
151 static Evas_Object *_setting_location_gl_gps_check_get(void *data, Evas_Object * obj, const char *part)
153 struct ug_data *ugd = (struct ug_data *)data;
157 ugd->tg_gps = tg = elm_check_add(obj);
159 if (ugd->is_gps == KEY_ENABLED) {
160 elm_check_state_set(tg, EINA_TRUE);
162 elm_check_state_set(tg, EINA_FALSE);
165 elm_object_style_set(tg, "on&off");
166 evas_object_propagate_events_set(tg, EINA_FALSE);
167 evas_object_smart_callback_add(tg, "changed", _setting_location_gps_cb, ugd);
172 static char *_setting_location_gl_loc_msg_get(void *data, Evas_Object * obj, const char *part)
174 return strdup(_("IDS_POP_APPLICATIONS_WILL_BE_PERMITTED_TO_USE_YOUR_LOCATION"));
177 static char *_setting_location_gl_agps_text_get(void *data, Evas_Object * obj, const char *part)
179 return strdup(_(menu[LOCATION_MENU_AGPS]));
182 static Evas_Object *_setting_location_gl_agps_check_get(void *data, Evas_Object * obj, const char *part)
184 struct ug_data *ugd = (struct ug_data *)data;
188 ugd->tg_agps = tg = elm_check_add(obj);
190 if (ugd->is_agps == KEY_ENABLED) {
191 elm_check_state_set(tg, EINA_TRUE);
193 elm_check_state_set(tg, EINA_FALSE);
196 elm_object_style_set(tg, "on&off");
197 evas_object_propagate_events_set(tg, EINA_FALSE);
198 evas_object_smart_callback_add(tg, "changed", _setting_location_agps_cb, ugd);
203 static char *_setting_location_gl_net_text_get(void *data, Evas_Object * obj, const char *part)
205 return strdup(_(menu[LOCATION_MENU_NET]));
208 static Evas_Object *_setting_location_gl_net_check_get(void *data, Evas_Object * obj, const char *part)
210 struct ug_data *ugd = (struct ug_data *)data;
214 ugd->tg_net = tg = elm_check_add(obj);
216 if (ugd->is_net == KEY_ENABLED) {
217 elm_check_state_set(tg, EINA_TRUE);
219 elm_check_state_set(tg, EINA_FALSE);
222 elm_object_style_set(tg, "on&off");
223 evas_object_propagate_events_set(tg, EINA_FALSE);
224 evas_object_smart_callback_add(tg, "changed", _setting_location_net_cb, ugd);
229 static char *_setting_location_gl_mypos_text_get(void *data, Evas_Object * obj, const char *part)
231 return strdup(_(menu[LOCATION_MENU_MYPOS]));
234 static Evas_Object *setting_location_create_layout(Evas_Object * parent)
239 layout = elm_layout_add(parent);
240 elm_layout_theme_set(layout, "layout", "application", "default");
241 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
242 elm_win_resize_object_add(parent, layout);
244 bg = elm_bg_add(layout);
245 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
246 elm_object_part_content_set(layout, "elm.swallow.bg", bg);
247 elm_object_style_set(bg, "group_list");
249 evas_object_show(layout);
254 Evas_Object *setting_location_create_navibar(Evas_Object * parent)
256 Evas_Object *naviframe;
258 naviframe = elm_naviframe_add(parent);
259 //elm_object_style_set(navi_bar, "extended_fnbtn_top_style");
260 elm_object_part_content_set(parent, "elm.swallow.content", naviframe);
262 evas_object_show(naviframe);
267 static void setting_location_gl_gps_sel(void *data, Evas_Object *obj, void *event_info)
269 LOC_LOG("setting_location_gl_gps_sel");
270 struct ug_data *ugd = (struct ug_data *)data;
271 Eina_Bool state = elm_check_state_get(ugd->tg_gps);
273 elm_check_state_set(ugd->tg_gps, !state);
274 ugd->is_gps = (!state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
275 setting_location_set_int(VCONFKEY_LOCATION_ENABLED, ugd->is_gps);
276 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
279 static void setting_location_gl_agps_sel(void *data, Evas_Object *obj, void *event_info)
281 LOC_LOG("setting_location_gl_agps_sel");
282 struct ug_data *ugd = (struct ug_data *)data;
283 Eina_Bool state = elm_check_state_get(ugd->tg_agps);
285 elm_check_state_set(ugd->tg_agps, !state);
286 ugd->is_agps = (!state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
287 setting_location_set_int(VCONFKEY_LOCATION_AGPS_ENABLED, ugd->is_agps);
288 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
291 static void setting_location_gl_net_sel(void *data, Evas_Object *obj, void *event_info)
293 LOC_LOG("setting_location_gl_net_sel");
294 struct ug_data *ugd = (struct ug_data *)data;
295 Eina_Bool state = elm_check_state_get(ugd->tg_net);
297 elm_check_state_set(ugd->tg_net, !state);
298 ugd->is_net = (!state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
299 setting_location_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, ugd->is_net);
300 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
303 static void setting_location_mypos_sel(void *data, Evas_Object *obj, void *event_info)
305 struct ug_data *ugd = (struct ug_data *)data;
307 elm_genlist_select_mode_set(ugd->genlist, ELM_OBJECT_SELECT_MODE_NONE);
309 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
310 setting_location_mypos_view(data);
314 Evas_Object *setting_location_create_gl(Evas_Object * parent, void *data)
316 LOC_LOG("setting_location_create_gl");
317 struct ug_data *ugd = (struct ug_data *)data;
319 Evas_Object *genlist;
320 Elm_Object_Item *item;
322 genlist = elm_genlist_add(parent);
323 elm_object_style_set(genlist, "dialogue");
324 elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
326 ugd->itc_sep = elm_genlist_item_class_new();
327 ugd->itc_sep->item_style = "dialogue/separator/21/with_line";
328 ugd->itc_sep->func.text_get = NULL;
329 ugd->itc_sep->func.content_get = NULL;
330 ugd->itc_sep->func.state_get = NULL;
331 ugd->itc_sep->func.del = NULL;
333 item = elm_genlist_item_append(genlist, ugd->itc_sep, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
334 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
336 ugd->itc_gps = elm_genlist_item_class_new();
337 ugd->itc_gps->item_style = "dialogue/1text.1icon";
338 ugd->itc_gps->func.text_get = _setting_location_gl_gps_text_get;
339 ugd->itc_gps->func.content_get = _setting_location_gl_gps_check_get;
340 ugd->itc_gps->func.state_get = NULL;
341 ugd->itc_gps->func.del = NULL;
343 ugd->gi_gps = elm_genlist_item_append(genlist, ugd->itc_gps, (void *)ugd, NULL, ELM_GENLIST_ITEM_NONE, setting_location_gl_gps_sel, ugd);
345 ugd->itc_msg = elm_genlist_item_class_new();
346 ugd->itc_msg->item_style = "multiline/1text";
347 ugd->itc_msg->func.text_get = _setting_location_gl_loc_msg_get;
348 ugd->itc_msg->func.content_get = NULL;
349 ugd->itc_msg->func.state_get = NULL;
350 ugd->itc_msg->func.del = NULL;
352 item = elm_genlist_item_append(genlist, ugd->itc_msg, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
353 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
355 ugd->itc_line= elm_genlist_item_class_new();
356 ugd->itc_line->item_style = "dialogue/separator/1/with_line";
357 ugd->itc_line->func.text_get = NULL;
358 ugd->itc_line->func.content_get = NULL;
359 ugd->itc_line->func.state_get = NULL;
360 ugd->itc_line->func.del = NULL;
362 item = elm_genlist_item_append(genlist, ugd->itc_line, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
363 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
365 ugd->itc_agps = elm_genlist_item_class_new();
366 ugd->itc_agps->item_style = "dialogue/1text.1icon";
367 ugd->itc_agps->func.text_get = _setting_location_gl_agps_text_get;
368 ugd->itc_agps->func.content_get = _setting_location_gl_agps_check_get;
369 ugd->itc_agps->func.state_get = NULL;
370 ugd->itc_agps->func.del = NULL;
372 ugd->gi_agps = elm_genlist_item_append(genlist, ugd->itc_agps, (void *)ugd, NULL, ELM_GENLIST_ITEM_NONE, setting_location_gl_agps_sel, ugd);
374 ugd->itc_net = elm_genlist_item_class_new();
375 ugd->itc_net->item_style = "dialogue/1text.1icon";
376 ugd->itc_net->func.text_get = _setting_location_gl_net_text_get;
377 ugd->itc_net->func.content_get = _setting_location_gl_net_check_get;
378 ugd->itc_net->func.state_get = NULL;
379 ugd->itc_net->func.del = NULL;
381 ugd->gi_net = elm_genlist_item_append(genlist, ugd->itc_net, (void *)ugd, NULL, ELM_GENLIST_ITEM_NONE, setting_location_gl_net_sel, ugd);
383 ugd->itc_mypos = elm_genlist_item_class_new();
384 ugd->itc_mypos->item_style = "dialogue/1text.1icon";
385 ugd->itc_mypos->func.text_get = _setting_location_gl_mypos_text_get;
386 ugd->itc_mypos->func.content_get = NULL;
387 ugd->itc_mypos->func.state_get = NULL;
388 ugd->itc_mypos->func.del = NULL;
390 ugd->gi_mypos = elm_genlist_item_append(genlist, ugd->itc_mypos, (void *)ugd, NULL, ELM_GENLIST_ITEM_NONE, setting_location_mypos_sel, ugd);
395 static Evas_Object *setting_location_create_view(Evas_Object * parent, struct ug_data *ugd)
397 Evas_Object *layout_main;
398 Elm_Object_Item* navi_it;
399 Evas_Object *l_button;
400 Evas_Object *help_button;
401 Evas_Object *toolbar;
403 layout_main = setting_location_create_layout(parent);
405 ugd->naviframe = setting_location_create_navibar(layout_main);
407 l_button = elm_button_add(ugd->naviframe);
408 elm_object_style_set(l_button, "naviframe/back_btn/default");
409 evas_object_smart_callback_add(l_button, "clicked", setting_location_back_cb, ugd);
411 ugd->genlist = setting_location_create_gl(ugd->naviframe, ugd);
413 setting_location_get_location_app_list(ugd->genlist, ugd);
415 evas_object_show(ugd->genlist);
417 navi_it = elm_naviframe_item_push(ugd->naviframe, _("IDS_LBS_BODY_LOCATION"), l_button, NULL, ugd->genlist, NULL);
419 toolbar = elm_toolbar_add(ugd->naviframe);
420 elm_toolbar_shrink_mode_set(toolbar, ELM_TOOLBAR_SHRINK_EXPAND);
422 help_button = (Evas_Object *)elm_toolbar_item_append(toolbar, NULL, _("IDS_COM_BODY_HELP"), setting_location_help_cb, ugd);
423 elm_object_item_disabled_set(elm_toolbar_item_append(toolbar, NULL, "", NULL, NULL), EINA_TRUE);
424 elm_object_item_part_content_set(navi_it, "controlbar", toolbar);
425 elm_object_item_part_content_set(navi_it, "title_right_btn", help_button);
430 void gps_enabled_cb(keynode_t * key, void *data)
432 struct ug_data *ugd = (struct ug_data *)data;
433 vconf_get_int(VCONFKEY_LOCATION_ENABLED, &ugd->is_gps);
434 setting_location_check_di(ugd);
437 void net_enabled_cb(keynode_t * key, void *data)
439 struct ug_data *ugd = (struct ug_data *)data;
440 vconf_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED, &ugd->is_net);
441 setting_location_check_di(ugd);
444 int setting_location_init(struct ug_data *ugd)
446 LOC_LOG("setting_location_init");
449 ret &= vconf_get_int(VCONFKEY_LOCATION_ENABLED, &ugd->is_gps);
450 ret &= vconf_get_int(VCONFKEY_LOCATION_AGPS_ENABLED, &ugd->is_agps);
451 ret &= vconf_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED, &ugd->is_net);
452 ret &= vconf_notify_key_changed(VCONFKEY_LOCATION_ENABLED, gps_enabled_cb, (void *)ugd);
453 ret &= vconf_notify_key_changed(VCONFKEY_LOCATION_NETWORK_ENABLED, net_enabled_cb, (void *)ugd);
455 setting_location_check_di(ugd);
460 int setting_location_deinit(struct ug_data *ugd)
464 ret = vconf_ignore_key_changed(VCONFKEY_LOCATION_ENABLED, gps_enabled_cb);
465 ret = vconf_ignore_key_changed(VCONFKEY_LOCATION_NETWORK_ENABLED, net_enabled_cb);
470 UG_MODULE_API int setting_plugin_reset(service_h service, void *priv)
472 if (vconf_set_int(VCONFKEY_LOCATION_ENABLED, KEY_ENABLED) != 0) {
475 if (vconf_set_int(VCONFKEY_LOCATION_AGPS_ENABLED, KEY_DISABLED) != 0) {
478 if (vconf_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, KEY_DISABLED) != 0) {
485 static void *on_create(ui_gadget_h ug, enum ug_mode mode, service_h service, void *priv)
493 bindtextdomain("ug-setting-location-efl", "/opt/ug/res/locale");
498 parent = ug_get_parent_layout(ug);
503 if (mode == UG_MODE_FULLVIEW) {
504 ugd->base = setting_location_create_view(parent, ugd);
505 setting_location_init(ugd);
513 static void on_start(ui_gadget_h ug, service_h service, void *priv)
515 LOC_LOG("on_start is called");
518 static void on_pause(ui_gadget_h ug, service_h service, void *priv)
520 LOC_LOG("on_pause is called");
523 static void on_resume(ui_gadget_h ug, service_h service, void *priv)
525 LOC_LOG("on_resume is called");
526 struct ug_data *ugd = (struct ug_data *)priv;
527 setting_location_delete_app_list(ugd->genlist, ugd);
528 setting_location_get_location_app_list(ugd->genlist, ugd);
529 setting_location_check_di(ugd);
532 static void on_destroy(ui_gadget_h ug, service_h service, void *priv)
534 struct ug_data *ugd = (struct ug_data *)priv;
541 char value[32] = {0,};
543 service_create(&result);
544 if (ugd->is_gps && ugd->is_net) strncpy(value, "GPSEnabled|WPSEnabled", sizeof(value));
545 else if (ugd->is_gps && !ugd->is_net) strncpy(value, "GPSEnabled|WPSDisabled", sizeof(value));
546 else if (!ugd->is_gps && ugd->is_net) strncpy(value, "GPSDisabled|WPSEnabled", sizeof(value));
547 else if (!ugd->is_gps && !ugd->is_net) strncpy(value, "GPSDisabled|WPSDisabled", sizeof(value));
548 service_add_extra_data(result, "State", value);
550 ug_send_result(ug, result);
552 setting_location_deinit(ugd);
554 if (ugd->base != NULL) {
555 evas_object_del(ugd->base);
561 static void on_message(ui_gadget_h ug, service_h msg, service_h data, void *priv)
565 static void on_event(ui_gadget_h ug, enum ug_event event, service_h data, void *priv)
568 case UG_EVENT_LOW_MEMORY:
570 case UG_EVENT_LOW_BATTERY:
572 case UG_EVENT_LANG_CHANGE:
574 case UG_EVENT_ROTATE_PORTRAIT:
576 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
578 case UG_EVENT_ROTATE_LANDSCAPE:
580 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
587 static void on_key_event(ui_gadget_h ug, enum ug_key_event event, service_h data, void *priv)
594 case UG_KEY_EVENT_END:
602 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
610 ugd = calloc(1, sizeof(struct ug_data));
615 ops->create = on_create;
616 ops->start = on_start;
617 ops->pause = on_pause;
618 ops->resume = on_resume;
619 ops->destroy = on_destroy;
620 ops->message = on_message;
621 ops->event = on_event;
622 ops->key_event = on_key_event;
624 ops->opt = UG_OPT_INDICATOR_ENABLE;
629 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)