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.
19 #define UG_MODULE_API __attribute__ ((visibility("default")))
22 #include <Elementary.h>
23 #include <ui-gadget-module.h>
25 #include <vconf-internal-location-keys.h>
26 #include <location-appman.h>
28 #include "libug-setting-location-efl.h"
29 #include "libug-setting-location-efl-mypos.h"
30 #include "libug-setting-location-efl-help.h"
31 #include "libug-setting-location-efl-appman.h"
32 #include "libug-setting-location-efl-log.h"
34 #define END_KEY_EVENT FALSE
36 static char *menu[] = {
37 N_("IDS_LBS_BODY_GPS"),
38 N_("IDS_LBS_BODY_ADVANCED_GPS"),
39 N_("IDS_LBS_BODY_NETWORK_POSITION"),
40 N_("IDS_LBS_BODY_MY_POSITION")
43 #define LOCATION_MENU_ENABLE 0
44 #define LOCATION_MENU_AGPS 1
45 #define LOCATION_MENU_NET 2
46 #define LOCATION_MENU_MYPOS 3
48 #define GL_GPS_INDEX 2
50 int setting_location_set_int(const char *path, int val)
52 int ret = vconf_set_int(path, val);
59 void setting_location_check_di(void *data)
61 LOC_LOG("setting_location_check_di");
62 struct ug_data *ugd = (struct ug_data *)data;
65 elm_check_state_set(ugd->tg_gps, ugd->is_gps);
66 elm_object_item_disabled_set(ugd->gi_agps, !ugd->is_gps);
68 elm_check_state_set(ugd->tg_net, ugd->is_net);
70 elm_object_item_disabled_set(ugd->gi_mypos, !(ugd->is_gps || ugd->is_net));
72 if (ugd->app_info == NULL) {
76 for (i = 0; i < ugd->app_count; i++) {
77 if (ugd->app_info[i].gi_app != NULL) {
78 elm_object_item_disabled_set(ugd->app_info[i].gi_app, !(ugd->is_gps || ugd->is_net));
83 static void setting_location_free_itc(Elm_Genlist_Item_Class *itc)
88 elm_genlist_item_class_free(itc);
91 static void setting_location_back_cb(void *data, Evas_Object * obj, void *event_info)
93 LOC_LOG("setting_location_back_cb");
94 struct ug_data *ugd = (struct ug_data *)data;
97 setting_location_free_itc(ugd->itc_top_sep);
98 setting_location_free_itc(ugd->itc_mid_sep);
99 setting_location_free_itc(ugd->itc_gps);
100 setting_location_free_itc(ugd->itc_agps);
101 setting_location_free_itc(ugd->itc_net);
102 setting_location_free_itc(ugd->itc_mypos);
103 if (ugd->app_info != NULL) {
104 setting_location_free_itc(ugd->itc_msg);
105 for (i = 0; i < ugd->app_count; i++) {
106 setting_location_free_itc(ugd->app_info[i].itc_app);
111 ug_destroy_me(ugd->ug);
114 static void setting_location_help_cb(void *data, Evas_Object * obj, void *event_info)
116 struct ug_data *ugd = (struct ug_data *)data;
118 setting_location_help_view(ugd);
121 static void _setting_location_gps_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 ugd->is_gps = (state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
128 setting_location_set_int(VCONFKEY_LOCATION_ENABLED, ugd->is_gps);
129 setting_location_check_di(ugd);
132 static void _setting_location_agps_cb(void *data, Evas_Object * obj, void *event_info)
134 struct ug_data *ugd = (struct ug_data *)data;
136 Eina_Bool state = elm_check_state_get(obj);
138 if (ugd->is_gps == KEY_DISABLED) {
139 elm_check_state_set(obj, !state);
142 ugd->is_agps = (state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
143 setting_location_set_int(VCONFKEY_LOCATION_AGPS_ENABLED, ugd->is_agps);
146 static void _setting_location_net_cb(void *data, Evas_Object * obj, void *event_info)
148 struct ug_data *ugd = (struct ug_data *)data;
150 Eina_Bool state = elm_check_state_get(obj);
152 ugd->is_net = (state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
153 setting_location_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, ugd->is_net);
154 setting_location_check_di(ugd);
157 static char *_setting_location_gl_gps_text_get(void *data, Evas_Object * obj, const char *part)
159 return strdup(_(menu[LOCATION_MENU_ENABLE]));
162 static Evas_Object *_setting_location_gl_gps_check_get(void *data, Evas_Object * obj, const char *part)
164 struct ug_data *ugd = (struct ug_data *)data;
168 ugd->tg_gps = tg = elm_check_add(obj);
170 if (ugd->is_gps == KEY_ENABLED) {
171 elm_check_state_set(tg, EINA_TRUE);
173 elm_check_state_set(tg, EINA_FALSE);
176 elm_object_style_set(tg, "on&off");
177 evas_object_propagate_events_set(tg, EINA_FALSE);
178 evas_object_smart_callback_add(tg, "changed", _setting_location_gps_cb, ugd);
183 static char *_setting_location_gl_agps_text_get(void *data, Evas_Object * obj, const char *part)
185 return strdup(_(menu[LOCATION_MENU_AGPS]));
188 static Evas_Object *_setting_location_gl_agps_check_get(void *data, Evas_Object * obj, const char *part)
190 struct ug_data *ugd = (struct ug_data *)data;
194 ugd->tg_agps = tg = elm_check_add(obj);
196 if (ugd->is_agps == KEY_ENABLED) {
197 elm_check_state_set(tg, EINA_TRUE);
199 elm_check_state_set(tg, EINA_FALSE);
202 elm_object_style_set(tg, "on&off");
203 evas_object_propagate_events_set(tg, EINA_FALSE);
204 evas_object_smart_callback_add(tg, "changed", _setting_location_agps_cb, ugd);
209 static char *_setting_location_gl_net_text_get(void *data, Evas_Object * obj, const char *part)
211 return strdup(_(menu[LOCATION_MENU_NET]));
214 static Evas_Object *_setting_location_gl_net_check_get(void *data, Evas_Object * obj, const char *part)
216 struct ug_data *ugd = (struct ug_data *)data;
220 ugd->tg_net = tg = elm_check_add(obj);
222 if (ugd->is_net == KEY_ENABLED) {
223 elm_check_state_set(tg, EINA_TRUE);
225 elm_check_state_set(tg, EINA_FALSE);
228 elm_object_style_set(tg, "on&off");
229 evas_object_propagate_events_set(tg, EINA_FALSE);
230 evas_object_smart_callback_add(tg, "changed", _setting_location_net_cb, ugd);
235 static char *_setting_location_gl_mypos_text_get(void *data, Evas_Object * obj, const char *part)
237 return strdup(_(menu[LOCATION_MENU_MYPOS]));
240 static Evas_Object *setting_location_create_layout(Evas_Object * parent)
245 layout = elm_layout_add(parent);
246 elm_layout_theme_set(layout, "layout", "application", "default");
247 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
249 bg = elm_bg_add(layout);
250 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
251 elm_object_part_content_set(layout, "elm.swallow.bg", bg);
252 elm_object_style_set(bg, "group_list");
254 evas_object_show(layout);
259 Evas_Object *setting_location_create_navibar(Evas_Object * parent)
261 Evas_Object *naviframe;
263 naviframe = elm_naviframe_add(parent);
264 elm_object_part_content_set(parent, "elm.swallow.content", naviframe);
266 evas_object_show(naviframe);
271 static void setting_location_gl_gps_sel(void *data, Evas_Object *obj, void *event_info)
273 LOC_LOG("setting_location_gl_gps_sel");
274 struct ug_data *ugd = (struct ug_data *)data;
275 Eina_Bool state = elm_check_state_get(ugd->tg_gps);
277 ugd->is_gps = (!state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
278 elm_genlist_item_update(ugd->gi_gps);
279 setting_location_set_int(VCONFKEY_LOCATION_ENABLED, ugd->is_gps);
280 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
283 static void setting_location_gl_agps_sel(void *data, Evas_Object *obj, void *event_info)
285 LOC_LOG("setting_location_gl_agps_sel");
286 struct ug_data *ugd = (struct ug_data *)data;
287 Eina_Bool state = elm_check_state_get(ugd->tg_agps);
289 ugd->is_agps = (!state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
290 elm_genlist_item_update(ugd->gi_agps);
291 setting_location_set_int(VCONFKEY_LOCATION_AGPS_ENABLED, ugd->is_agps);
292 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
295 static void setting_location_gl_net_sel(void *data, Evas_Object *obj, void *event_info)
297 LOC_LOG("setting_location_gl_net_sel");
298 struct ug_data *ugd = (struct ug_data *)data;
299 Eina_Bool state = elm_check_state_get(ugd->tg_net);
301 ugd->is_net = (!state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
302 elm_genlist_item_update(ugd->gi_net);
303 setting_location_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, ugd->is_net);
304 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
307 static void setting_location_mypos_sel(void *data, Evas_Object *obj, void *event_info)
309 struct ug_data *ugd = (struct ug_data *)data;
311 elm_genlist_select_mode_set(ugd->genlist, ELM_OBJECT_SELECT_MODE_NONE);
313 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
314 setting_location_mypos_view(data);
318 static void setting_location_genlist_realized(void *data, Evas_Object *obj, void *gi)
323 Elm_Object_Item *item = gi;
324 struct ug_data *ugd = (struct ug_data *)data;
325 int index = (int)elm_genlist_item_index_get(gi);
326 int mypos_index = ugd->opt_index;
327 int applist_index = mypos_index + 3;
329 if (ugd->app_count == 2 && index == applist_index)
332 if ((index == GL_GPS_INDEX) || (index == applist_index)){
333 LOC_LOG("TOP index = %d", index);
334 elm_object_item_signal_emit(gi, "elm,state,top", "");
335 } else if ((index == mypos_index) || (index == applist_index + ugd->app_count - 2)) {
336 LOC_LOG("BOT index = %d", index);
337 elm_object_item_signal_emit(gi, "elm,state,bottom", "");
339 LOC_LOG("MID index = %d", index);
340 elm_object_item_signal_emit(gi, "elm,state,center", "");
344 Evas_Object *setting_location_create_gl(Evas_Object * parent, void *data)
346 LOC_LOG("setting_location_create_gl");
347 struct ug_data *ugd = (struct ug_data *)data;
350 Evas_Object *genlist;
352 genlist = elm_genlist_add(parent);
353 evas_object_smart_callback_add(genlist, "realized", setting_location_genlist_realized, ugd);
354 elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
356 ugd->itc_top_sep = elm_genlist_item_class_new();
357 ugd->itc_top_sep->item_style = "dialogue/separator";
358 ugd->itc_top_sep->func.text_get = NULL;
359 ugd->itc_top_sep->func.content_get = NULL;
360 ugd->itc_top_sep->func.state_get = NULL;
361 ugd->itc_top_sep->func.del = NULL;
362 ugd->gi_top_sep = elm_genlist_item_append(genlist, ugd->itc_top_sep, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
364 elm_genlist_item_select_mode_set(ugd->gi_top_sep, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
366 ugd->itc_gps = elm_genlist_item_class_new();
367 ugd->itc_gps->item_style = "dialogue/1text.1icon";
368 ugd->itc_gps->func.text_get = _setting_location_gl_gps_text_get;
369 ugd->itc_gps->func.content_get = _setting_location_gl_gps_check_get;
370 ugd->itc_gps->func.state_get = NULL;
371 ugd->itc_gps->func.del = NULL;
373 ugd->gi_gps = elm_genlist_item_append(genlist, ugd->itc_gps, (void *)ugd, NULL, ELM_GENLIST_ITEM_NONE, setting_location_gl_gps_sel, ugd);
376 ugd->itc_agps = elm_genlist_item_class_new();
377 ugd->itc_agps->item_style = "dialogue/1text.1icon";
378 ugd->itc_agps->func.text_get = _setting_location_gl_agps_text_get;
379 ugd->itc_agps->func.content_get = _setting_location_gl_agps_check_get;
380 ugd->itc_agps->func.state_get = NULL;
381 ugd->itc_agps->func.del = NULL;
383 ugd->gi_agps = elm_genlist_item_append(genlist, ugd->itc_agps, (void *)ugd, NULL, ELM_GENLIST_ITEM_NONE, setting_location_gl_agps_sel, ugd);
386 ugd->itc_net = elm_genlist_item_class_new();
387 ugd->itc_net->item_style = "dialogue/1text.1icon";
388 ugd->itc_net->func.text_get = _setting_location_gl_net_text_get;
389 ugd->itc_net->func.content_get = _setting_location_gl_net_check_get;
390 ugd->itc_net->func.state_get = NULL;
391 ugd->itc_net->func.del = NULL;
393 if (location_manager_is_supported_method(LOCATIONS_METHOD_WPS)) {
394 ugd->gi_net = elm_genlist_item_append(genlist, ugd->itc_net, (void *)ugd, NULL, ELM_GENLIST_ITEM_NONE, setting_location_gl_net_sel, ugd);
397 else ugd->gi_net = NULL;
399 ugd->itc_mypos = elm_genlist_item_class_new();
400 ugd->itc_mypos->item_style = "dialogue/1text";
401 ugd->itc_mypos->func.text_get = _setting_location_gl_mypos_text_get;
402 ugd->itc_mypos->func.content_get = NULL;
403 ugd->itc_mypos->func.state_get = NULL;
404 ugd->itc_mypos->func.del = NULL;
406 ugd->gi_mypos = elm_genlist_item_append(genlist, ugd->itc_mypos, (void *)ugd, NULL, ELM_GENLIST_ITEM_NONE, setting_location_mypos_sel, ugd);
409 ugd->itc_mid_sep = elm_genlist_item_class_new();
410 ugd->itc_mid_sep->item_style = "dialogue/separator";
411 ugd->itc_mid_sep->func.text_get = NULL;
412 ugd->itc_mid_sep->func.content_get = NULL;
413 ugd->itc_mid_sep->func.state_get = NULL;
414 ugd->itc_mid_sep->func.del = NULL;
415 ugd->gi_mid_sep = elm_genlist_item_append(genlist, ugd->itc_mid_sep, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
416 elm_genlist_item_select_mode_set(ugd->gi_mid_sep, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
421 static Evas_Object *setting_location_create_view(Evas_Object * parent, struct ug_data *ugd)
423 Evas_Object *layout_main;
424 Elm_Object_Item* navi_it;
425 Evas_Object *l_button;
426 Evas_Object *help_button;
428 layout_main = setting_location_create_layout(parent);
430 ugd->naviframe = setting_location_create_navibar(layout_main);
432 l_button = elm_button_add(ugd->naviframe);
433 elm_object_style_set(l_button, "naviframe/back_btn/default");
434 evas_object_smart_callback_add(l_button, "clicked", setting_location_back_cb, ugd);
436 ugd->genlist = setting_location_create_gl(ugd->naviframe, ugd);
437 evas_object_show(ugd->genlist);
439 navi_it = elm_naviframe_item_push(ugd->naviframe, _("IDS_LBS_HEADER_LOCATION"), l_button, NULL, ugd->genlist, NULL);
441 help_button = elm_button_add(ugd->naviframe);
442 elm_object_style_set(help_button, "naviframe/toolbar/default");
443 elm_object_text_set(help_button, S_("IDS_COM_BODY_HELP"));
444 evas_object_smart_callback_add(help_button, "clicked", setting_location_help_cb, ugd);
445 elm_object_item_part_content_set(navi_it, "toolbar_button2", help_button);
447 setting_location_get_location_app_list(ugd->genlist, ugd);
452 void gps_enabled_cb(keynode_t * key, void *data)
454 struct ug_data *ugd = (struct ug_data *)data;
455 vconf_get_int(VCONFKEY_LOCATION_ENABLED, &ugd->is_gps);
456 setting_location_check_di(ugd);
457 elm_genlist_item_update(ugd->gi_gps);
460 void net_enabled_cb(keynode_t * key, void *data)
462 struct ug_data *ugd = (struct ug_data *)data;
463 vconf_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED, &ugd->is_net);
464 setting_location_check_di(ugd);
465 elm_genlist_item_update(ugd->gi_net);
468 int setting_location_init(struct ug_data *ugd)
470 LOC_LOG("setting_location_init");
473 ret &= vconf_get_int(VCONFKEY_LOCATION_ENABLED, &ugd->is_gps);
474 ret &= vconf_get_int(VCONFKEY_LOCATION_AGPS_ENABLED, &ugd->is_agps);
475 ret &= vconf_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED, &ugd->is_net);
476 ret &= vconf_notify_key_changed(VCONFKEY_LOCATION_ENABLED, gps_enabled_cb, (void *)ugd);
477 ret &= vconf_notify_key_changed(VCONFKEY_LOCATION_NETWORK_ENABLED, net_enabled_cb, (void *)ugd);
479 setting_location_check_di(ugd);
484 int setting_location_deinit(struct ug_data *ugd)
488 ret = vconf_ignore_key_changed(VCONFKEY_LOCATION_ENABLED, gps_enabled_cb);
489 ret = vconf_ignore_key_changed(VCONFKEY_LOCATION_NETWORK_ENABLED, net_enabled_cb);
494 UG_MODULE_API int setting_plugin_reset(service_h service, void *priv)
496 if (vconf_set_int(VCONFKEY_LOCATION_ENABLED, KEY_DISABLED) != 0) {
499 if (vconf_set_int(VCONFKEY_LOCATION_AGPS_ENABLED, KEY_DISABLED) != 0) {
502 if (vconf_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, KEY_DISABLED) != 0) {
509 static void *on_create(ui_gadget_h ug, enum ug_mode mode, service_h service, void *priv)
517 bindtextdomain("ug-setting-location-efl", LANGDIR);
522 parent = ug_get_parent_layout(ug);
527 if (mode == UG_MODE_FULLVIEW) {
528 ugd->base = setting_location_create_view(parent, ugd);
529 setting_location_init(ugd);
537 static void on_start(ui_gadget_h ug, service_h service, void *priv)
539 LOC_LOG("on_start is called");
542 static void on_pause(ui_gadget_h ug, service_h service, void *priv)
544 LOC_LOG("on_pause is called");
547 static void on_resume(ui_gadget_h ug, service_h service, void *priv)
549 LOC_LOG("on_resume is called");
550 struct ug_data *ugd = (struct ug_data *)priv;
551 setting_location_delete_app_list(ugd->genlist, ugd);
552 setting_location_get_location_app_list(ugd->genlist, ugd);
553 setting_location_check_di(ugd);
556 static void on_destroy(ui_gadget_h ug, service_h service, void *priv)
558 struct ug_data *ugd = (struct ug_data *)priv;
565 char value[32] = {0,};
567 service_create(&result);
568 if (ugd->is_gps && ugd->is_net) strncpy(value, "GPSEnabled|WPSEnabled", sizeof(value));
569 else if (ugd->is_gps && !ugd->is_net) strncpy(value, "GPSEnabled|WPSDisabled", sizeof(value));
570 else if (!ugd->is_gps && ugd->is_net) strncpy(value, "GPSDisabled|WPSEnabled", sizeof(value));
571 else if (!ugd->is_gps && !ugd->is_net) strncpy(value, "GPSDisabled|WPSDisabled", sizeof(value));
572 service_add_extra_data(result, "State", value);
574 ug_send_result(ug, result);
575 service_destroy(result);
577 setting_location_deinit(ugd);
579 if (ugd->base != NULL) {
580 evas_object_del(ugd->base);
586 static void on_message(ui_gadget_h ug, service_h msg, service_h data, void *priv)
590 static void on_event(ui_gadget_h ug, enum ug_event event, service_h data, void *priv)
593 case UG_EVENT_LOW_MEMORY:
595 case UG_EVENT_LOW_BATTERY:
597 case UG_EVENT_LANG_CHANGE:
599 case UG_EVENT_ROTATE_PORTRAIT:
601 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
603 case UG_EVENT_ROTATE_LANDSCAPE:
605 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
612 static void on_key_event(ui_gadget_h ug, enum ug_key_event event, service_h data, void *priv)
619 case UG_KEY_EVENT_END:
627 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
635 ugd = calloc(1, sizeof(struct ug_data));
640 ops->create = on_create;
641 ops->start = on_start;
642 ops->pause = on_pause;
643 ops->resume = on_resume;
644 ops->destroy = on_destroy;
645 ops->message = on_message;
646 ops->event = on_event;
647 ops->key_event = on_key_event;
649 ops->opt = UG_OPT_INDICATOR_ENABLE;
654 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)