2 * Open Service Platform
3 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd
5 * Licensed under the Flora License, Version 1.1 (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>
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-log.h"
32 #define END_KEY_EVENT FALSE
34 static char *menu[] = {
35 N_("IDS_LBS_BODY_GPS"),
36 N_("IDS_LBS_BODY_ADVANCED_GPS"),
37 N_("IDS_LBS_BODY_NETWORK_POSITION"),
38 N_("IDS_LBS_BODY_MY_POSITION")
41 #define LOCATION_MENU_ENABLE 0
42 #define LOCATION_MENU_AGPS 1
43 #define LOCATION_MENU_NET 2
44 #define LOCATION_MENU_MYPOS 3
46 #define GL_GPS_INDEX 1
48 int setting_location_set_int(const char *path, int val)
50 int ret = vconf_set_int(path, val);
57 void setting_location_check_di(void *data)
59 LOC_LOG("setting_location_check_di");
60 struct ug_data *ugd = (struct ug_data *)data;
63 elm_check_state_set(ugd->tg_gps, ugd->is_gps);
64 elm_object_item_disabled_set(ugd->gi_agps, !ugd->is_gps);
66 elm_check_state_set(ugd->tg_net, ugd->is_net);
68 elm_object_item_disabled_set(ugd->gi_mypos, !(ugd->is_gps || ugd->is_net));
71 static void setting_location_free_itc(Elm_Genlist_Item_Class *itc)
76 elm_genlist_item_class_free(itc);
79 static void setting_location_back_cb(void *data, Evas_Object * obj, void *event_info)
81 LOC_LOG("setting_location_back_cb");
82 struct ug_data *ugd = (struct ug_data *)data;
85 setting_location_free_itc(ugd->itc_top_sep);
86 setting_location_free_itc(ugd->itc_mid_sep);
87 setting_location_free_itc(ugd->itc_gps);
88 setting_location_free_itc(ugd->itc_agps);
89 setting_location_free_itc(ugd->itc_net);
90 setting_location_free_itc(ugd->itc_mypos);
92 ug_destroy_me(ugd->ug);
95 static void setting_location_help_cb(void *data, Evas_Object * obj, void *event_info)
97 struct ug_data *ugd = (struct ug_data *)data;
99 setting_location_help_view(ugd);
102 static void _setting_location_gps_cb(void *data, Evas_Object * obj, void *event_info)
104 struct ug_data *ugd = (struct ug_data *)data;
106 Eina_Bool state = elm_check_state_get(obj);
108 ugd->is_gps = (state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
109 setting_location_set_int(VCONFKEY_LOCATION_ENABLED, ugd->is_gps);
110 setting_location_check_di(ugd);
113 static void _setting_location_agps_cb(void *data, Evas_Object * obj, void *event_info)
115 struct ug_data *ugd = (struct ug_data *)data;
117 Eina_Bool state = elm_check_state_get(obj);
119 if (ugd->is_gps == KEY_DISABLED) {
120 elm_check_state_set(obj, !state);
123 ugd->is_agps = (state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
124 setting_location_set_int(VCONFKEY_LOCATION_AGPS_ENABLED, ugd->is_agps);
127 static void _setting_location_net_cb(void *data, Evas_Object * obj, void *event_info)
129 struct ug_data *ugd = (struct ug_data *)data;
131 Eina_Bool state = elm_check_state_get(obj);
133 ugd->is_net = (state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
134 setting_location_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, ugd->is_net);
135 setting_location_check_di(ugd);
138 static char *_setting_location_gl_gps_text_get(void *data, Evas_Object * obj, const char *part)
140 return strdup(_(menu[LOCATION_MENU_ENABLE]));
143 static Evas_Object *_setting_location_gl_gps_check_get(void *data, Evas_Object * obj, const char *part)
145 struct ug_data *ugd = (struct ug_data *)data;
149 ugd->tg_gps = tg = elm_check_add(obj);
151 if (ugd->is_gps == KEY_ENABLED) {
152 elm_check_state_set(tg, EINA_TRUE);
154 elm_check_state_set(tg, EINA_FALSE);
157 elm_object_style_set(tg, "on&off");
158 evas_object_propagate_events_set(tg, EINA_FALSE);
159 evas_object_smart_callback_add(tg, "changed", _setting_location_gps_cb, ugd);
164 static char *_setting_location_gl_agps_text_get(void *data, Evas_Object * obj, const char *part)
166 return strdup(_(menu[LOCATION_MENU_AGPS]));
169 static Evas_Object *_setting_location_gl_agps_check_get(void *data, Evas_Object * obj, const char *part)
171 struct ug_data *ugd = (struct ug_data *)data;
175 ugd->tg_agps = tg = elm_check_add(obj);
177 if (ugd->is_agps == KEY_ENABLED) {
178 elm_check_state_set(tg, EINA_TRUE);
180 elm_check_state_set(tg, EINA_FALSE);
183 elm_object_style_set(tg, "on&off");
184 evas_object_propagate_events_set(tg, EINA_FALSE);
185 evas_object_smart_callback_add(tg, "changed", _setting_location_agps_cb, ugd);
190 static char *_setting_location_gl_net_text_get(void *data, Evas_Object * obj, const char *part)
192 return strdup(_(menu[LOCATION_MENU_NET]));
195 static Evas_Object *_setting_location_gl_net_check_get(void *data, Evas_Object * obj, const char *part)
197 struct ug_data *ugd = (struct ug_data *)data;
201 ugd->tg_net = tg = elm_check_add(obj);
203 if (ugd->is_net == KEY_ENABLED) {
204 elm_check_state_set(tg, EINA_TRUE);
206 elm_check_state_set(tg, EINA_FALSE);
209 elm_object_style_set(tg, "on&off");
210 evas_object_propagate_events_set(tg, EINA_FALSE);
211 evas_object_smart_callback_add(tg, "changed", _setting_location_net_cb, ugd);
216 static char *_setting_location_gl_mypos_text_get(void *data, Evas_Object * obj, const char *part)
218 return strdup(_(menu[LOCATION_MENU_MYPOS]));
221 static Evas_Object *setting_location_create_layout(Evas_Object * parent)
226 layout = elm_layout_add(parent);
227 elm_layout_theme_set(layout, "layout", "application", "default");
228 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
230 bg = elm_bg_add(layout);
231 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
232 elm_object_part_content_set(layout, "elm.swallow.bg", bg);
233 elm_object_style_set(bg, "group_list");
235 evas_object_show(layout);
240 Evas_Object *setting_location_create_navibar(Evas_Object * parent)
242 Evas_Object *naviframe;
244 naviframe = elm_naviframe_add(parent);
245 elm_object_part_content_set(parent, "elm.swallow.content", naviframe);
247 evas_object_show(naviframe);
252 static void setting_location_gl_gps_sel(void *data, Evas_Object *obj, void *event_info)
254 LOC_LOG("setting_location_gl_gps_sel");
255 struct ug_data *ugd = (struct ug_data *)data;
256 Eina_Bool state = elm_check_state_get(ugd->tg_gps);
258 ugd->is_gps = (!state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
259 elm_genlist_item_update(ugd->gi_gps);
260 setting_location_set_int(VCONFKEY_LOCATION_ENABLED, ugd->is_gps);
261 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
264 static void setting_location_gl_agps_sel(void *data, Evas_Object *obj, void *event_info)
266 LOC_LOG("setting_location_gl_agps_sel");
267 struct ug_data *ugd = (struct ug_data *)data;
268 Eina_Bool state = elm_check_state_get(ugd->tg_agps);
270 ugd->is_agps = (!state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
271 elm_genlist_item_update(ugd->gi_agps);
272 setting_location_set_int(VCONFKEY_LOCATION_AGPS_ENABLED, ugd->is_agps);
273 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
276 static void setting_location_gl_net_sel(void *data, Evas_Object *obj, void *event_info)
278 LOC_LOG("setting_location_gl_net_sel");
279 struct ug_data *ugd = (struct ug_data *)data;
280 Eina_Bool state = elm_check_state_get(ugd->tg_net);
282 ugd->is_net = (!state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
283 elm_genlist_item_update(ugd->gi_net);
284 setting_location_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, ugd->is_net);
285 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
288 static void setting_location_mypos_sel(void *data, Evas_Object *obj, void *event_info)
290 struct ug_data *ugd = (struct ug_data *)data;
292 elm_genlist_select_mode_set(ugd->genlist, ELM_OBJECT_SELECT_MODE_NONE);
294 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
295 setting_location_mypos_view(data);
299 static void setting_location_genlist_realized(void *data, Evas_Object *obj, void *gi)
304 Elm_Object_Item *item = gi;
305 struct ug_data *ugd = (struct ug_data *)data;
306 int index = (int)elm_genlist_item_index_get(gi);
307 int mypos_index = ugd->opt_index;
308 int applist_index = mypos_index + 3;
310 if (ugd->app_count == 2 && index == applist_index)
313 if ((index == GL_GPS_INDEX) || (index == applist_index)){
314 LOC_LOG("TOP index = %d", index);
315 elm_object_item_signal_emit(gi, "elm,state,top", "");
316 } else if ((index == mypos_index) || (index == applist_index + ugd->app_count - 2)) {
317 LOC_LOG("BOT index = %d", index);
318 elm_object_item_signal_emit(gi, "elm,state,bottom", "");
320 LOC_LOG("MID index = %d", index);
321 elm_object_item_signal_emit(gi, "elm,state,center", "");
325 Evas_Object *setting_location_create_gl(Evas_Object * parent, void *data)
327 LOC_LOG("setting_location_create_gl");
328 struct ug_data *ugd = (struct ug_data *)data;
330 Evas_Object *genlist;
332 genlist = elm_genlist_add(parent);
333 evas_object_smart_callback_add(genlist, "realized", setting_location_genlist_realized, ugd);
334 elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
336 ugd->itc_top_sep = elm_genlist_item_class_new();
337 ugd->itc_top_sep->item_style = "dialogue/separator";
338 ugd->itc_top_sep->func.text_get = NULL;
339 ugd->itc_top_sep->func.content_get = NULL;
340 ugd->itc_top_sep->func.state_get = NULL;
341 ugd->itc_top_sep->func.del = NULL;
342 ugd->gi_top_sep = elm_genlist_item_append(genlist, ugd->itc_top_sep, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
344 elm_genlist_item_select_mode_set(ugd->gi_top_sep, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
346 ugd->itc_gps = elm_genlist_item_class_new();
347 ugd->itc_gps->item_style = "dialogue/1text.1icon";
348 ugd->itc_gps->func.text_get = _setting_location_gl_gps_text_get;
349 ugd->itc_gps->func.content_get = _setting_location_gl_gps_check_get;
350 ugd->itc_gps->func.state_get = NULL;
351 ugd->itc_gps->func.del = NULL;
353 ugd->gi_gps = elm_genlist_item_append(genlist, ugd->itc_gps, (void *)ugd, NULL, ELM_GENLIST_ITEM_NONE, setting_location_gl_gps_sel, ugd);
356 ugd->itc_agps = elm_genlist_item_class_new();
357 ugd->itc_agps->item_style = "dialogue/1text.1icon";
358 ugd->itc_agps->func.text_get = _setting_location_gl_agps_text_get;
359 ugd->itc_agps->func.content_get = _setting_location_gl_agps_check_get;
360 ugd->itc_agps->func.state_get = NULL;
361 ugd->itc_agps->func.del = NULL;
363 ugd->gi_agps = elm_genlist_item_append(genlist, ugd->itc_agps, (void *)ugd, NULL, ELM_GENLIST_ITEM_NONE, setting_location_gl_agps_sel, ugd);
366 ugd->itc_net = elm_genlist_item_class_new();
367 ugd->itc_net->item_style = "dialogue/1text.1icon";
368 ugd->itc_net->func.text_get = _setting_location_gl_net_text_get;
369 ugd->itc_net->func.content_get = _setting_location_gl_net_check_get;
370 ugd->itc_net->func.state_get = NULL;
371 ugd->itc_net->func.del = NULL;
373 if (location_manager_is_supported_method(LOCATIONS_METHOD_WPS)) {
374 ugd->gi_net = elm_genlist_item_append(genlist, ugd->itc_net, (void *)ugd, NULL, ELM_GENLIST_ITEM_NONE, setting_location_gl_net_sel, ugd);
377 else ugd->gi_net = NULL;
379 ugd->itc_mypos = elm_genlist_item_class_new();
380 ugd->itc_mypos->item_style = "dialogue/1text";
381 ugd->itc_mypos->func.text_get = _setting_location_gl_mypos_text_get;
382 ugd->itc_mypos->func.content_get = NULL;
383 ugd->itc_mypos->func.state_get = NULL;
384 ugd->itc_mypos->func.del = NULL;
386 ugd->gi_mypos = elm_genlist_item_append(genlist, ugd->itc_mypos, (void *)ugd, NULL, ELM_GENLIST_ITEM_NONE, setting_location_mypos_sel, ugd);
389 ugd->itc_mid_sep = elm_genlist_item_class_new();
390 ugd->itc_mid_sep->item_style = "dialogue/separator";
391 ugd->itc_mid_sep->func.text_get = NULL;
392 ugd->itc_mid_sep->func.content_get = NULL;
393 ugd->itc_mid_sep->func.state_get = NULL;
394 ugd->itc_mid_sep->func.del = NULL;
395 ugd->gi_mid_sep = elm_genlist_item_append(genlist, ugd->itc_mid_sep, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
396 elm_genlist_item_select_mode_set(ugd->gi_mid_sep, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
401 static Evas_Object *setting_location_create_view(Evas_Object * parent, struct ug_data *ugd)
403 Evas_Object *layout_main;
404 Elm_Object_Item* navi_it;
405 Evas_Object *l_button;
406 Evas_Object *help_button;
408 layout_main = setting_location_create_layout(parent);
410 ugd->naviframe = setting_location_create_navibar(layout_main);
412 l_button = elm_button_add(ugd->naviframe);
413 elm_object_style_set(l_button, "naviframe/back_btn/default");
414 evas_object_smart_callback_add(l_button, "clicked", setting_location_back_cb, ugd);
416 ugd->genlist = setting_location_create_gl(ugd->naviframe, ugd);
417 evas_object_show(ugd->genlist);
419 navi_it = elm_naviframe_item_push(ugd->naviframe, _("IDS_LBS_HEADER_LOCATION"), l_button, NULL, ugd->genlist, NULL);
421 help_button = elm_button_add(ugd->naviframe);
422 elm_object_style_set(help_button, "naviframe/toolbar/default");
423 elm_object_text_set(help_button, S_("IDS_COM_BODY_HELP"));
424 evas_object_smart_callback_add(help_button, "clicked", setting_location_help_cb, ugd);
425 elm_object_item_part_content_set(navi_it, "toolbar_button2", 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);
435 elm_genlist_item_update(ugd->gi_gps);
438 void net_enabled_cb(keynode_t * key, void *data)
440 struct ug_data *ugd = (struct ug_data *)data;
441 vconf_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED, &ugd->is_net);
442 setting_location_check_di(ugd);
443 elm_genlist_item_update(ugd->gi_net);
446 int setting_location_init(struct ug_data *ugd)
448 LOC_LOG("setting_location_init");
451 ret &= vconf_get_int(VCONFKEY_LOCATION_ENABLED, &ugd->is_gps);
452 ret &= vconf_get_int(VCONFKEY_LOCATION_AGPS_ENABLED, &ugd->is_agps);
453 ret &= vconf_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED, &ugd->is_net);
454 ret &= vconf_notify_key_changed(VCONFKEY_LOCATION_ENABLED, gps_enabled_cb, (void *)ugd);
455 ret &= vconf_notify_key_changed(VCONFKEY_LOCATION_NETWORK_ENABLED, net_enabled_cb, (void *)ugd);
457 setting_location_check_di(ugd);
462 int setting_location_deinit(struct ug_data *ugd)
466 ret = vconf_ignore_key_changed(VCONFKEY_LOCATION_ENABLED, gps_enabled_cb);
467 ret = vconf_ignore_key_changed(VCONFKEY_LOCATION_NETWORK_ENABLED, net_enabled_cb);
472 UG_MODULE_API int setting_plugin_reset(service_h service, void *priv)
474 if (vconf_set_int(VCONFKEY_LOCATION_ENABLED, KEY_DISABLED) != 0) {
477 if (vconf_set_int(VCONFKEY_LOCATION_AGPS_ENABLED, KEY_DISABLED) != 0) {
480 if (vconf_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, KEY_DISABLED) != 0) {
487 static void *on_create(ui_gadget_h ug, enum ug_mode mode, service_h service, void *priv)
495 bindtextdomain("ug-setting-location-efl", LANGDIR);
500 parent = ug_get_parent_layout(ug);
505 if (mode == UG_MODE_FULLVIEW) {
506 ugd->base = setting_location_create_view(parent, ugd);
507 setting_location_init(ugd);
515 static void on_start(ui_gadget_h ug, service_h service, void *priv)
517 LOC_LOG("on_start is called");
520 static void on_pause(ui_gadget_h ug, service_h service, void *priv)
522 LOC_LOG("on_pause is called");
525 static void on_resume(ui_gadget_h ug, service_h service, void *priv)
527 LOC_LOG("on_resume is called");
528 struct ug_data *ugd = (struct ug_data *)priv;
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 if (ugd->is_gps) strncpy(value, "enable", sizeof(value));
551 else if (!ugd->is_gps) strncpy(value, "disable", sizeof(value));
552 service_add_extra_data(result, "http://tizen.org/appcontrol/data/location/gps", value);
554 if (ugd->is_net) strncpy(value, "enable", sizeof(value));
555 else if (!ugd->is_net) strncpy(value, "disable", sizeof(value));
556 service_add_extra_data(result, "http://tizen.org/appcontrol/data/location/wps", value);
558 ug_send_result(ug, result);
559 service_destroy(result);
561 setting_location_deinit(ugd);
563 if (ugd->base != NULL) {
564 evas_object_del(ugd->base);
570 static void on_message(ui_gadget_h ug, service_h msg, service_h data, void *priv)
574 static void on_event(ui_gadget_h ug, enum ug_event event, service_h data, void *priv)
577 case UG_EVENT_LOW_MEMORY:
579 case UG_EVENT_LOW_BATTERY:
581 case UG_EVENT_LANG_CHANGE:
583 case UG_EVENT_ROTATE_PORTRAIT:
585 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
587 case UG_EVENT_ROTATE_LANDSCAPE:
589 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
596 static void on_key_event(ui_gadget_h ug, enum ug_key_event event, service_h data, void *priv)
603 case UG_KEY_EVENT_END:
611 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
619 ugd = calloc(1, sizeof(struct ug_data));
624 ops->create = on_create;
625 ops->start = on_start;
626 ops->pause = on_pause;
627 ops->resume = on_resume;
628 ops->destroy = on_destroy;
629 ops->message = on_message;
630 ops->event = on_event;
631 ops->key_event = on_key_event;
633 ops->opt = UG_OPT_INDICATOR_ENABLE;
638 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)