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));
69 if (ugd->app_count <= 1) {
73 for (i = 0; i < ugd->app_count; i++) {
74 elm_object_item_disabled_set(ugd->app_info[i].gi_app, !(ugd->is_gps || ugd->is_net));
78 static void setting_location_free_itc(Elm_Genlist_Item_Class *itc)
83 elm_genlist_item_class_free(itc);
87 static void setting_location_back_cb(void *data, Evas_Object * obj, void *event_info)
89 struct ug_data *ugd = (struct ug_data *)data;
92 setting_location_free_itc(ugd->itc_sep);
93 setting_location_free_itc(ugd->itc_bot_sep);
94 setting_location_free_itc(ugd->itc_gps);
95 setting_location_free_itc(ugd->itc_agps);
96 setting_location_free_itc(ugd->itc_net);
97 setting_location_free_itc(ugd->itc_mypos);
98 setting_location_free_itc(ugd->itc_msg);
99 setting_location_free_itc(ugd->itc_line);
100 if (ugd->app_count > 1) {
101 for (i = 0; i < ugd->app_count; i++) {
102 setting_location_free_itc(ugd->app_info[i].itc_app);
106 if (ugd->app_info != NULL) {
109 ug_destroy_me(ugd->ug);
112 static void setting_location_help_cb(void *data, Evas_Object * obj, void *event_info)
114 struct ug_data *ugd = (struct ug_data *)data;
116 setting_location_help_view(ugd);
119 static void _setting_location_gps_cb(void *data, Evas_Object * obj, void *event_info)
121 struct ug_data *ugd = (struct ug_data *)data;
123 Eina_Bool state = elm_check_state_get(obj);
125 ugd->is_gps = (state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
126 setting_location_set_int(VCONFKEY_LOCATION_ENABLED, ugd->is_gps);
127 setting_location_check_di(ugd);
130 static void _setting_location_agps_cb(void *data, Evas_Object * obj, void *event_info)
132 struct ug_data *ugd = (struct ug_data *)data;
134 Eina_Bool state = elm_check_state_get(obj);
136 if (ugd->is_gps == KEY_DISABLED) {
137 elm_check_state_set(obj, !state);
140 ugd->is_agps = (state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
141 setting_location_set_int(VCONFKEY_LOCATION_AGPS_ENABLED, ugd->is_agps);
144 static void _setting_location_net_cb(void *data, Evas_Object * obj, void *event_info)
146 struct ug_data *ugd = (struct ug_data *)data;
148 Eina_Bool state = elm_check_state_get(obj);
150 ugd->is_net = (state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
151 setting_location_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, ugd->is_net);
152 setting_location_check_di(ugd);
155 static char *_setting_location_gl_gps_text_get(void *data, Evas_Object * obj, const char *part)
157 return strdup(_(menu[LOCATION_MENU_ENABLE]));
160 static Evas_Object *_setting_location_gl_gps_check_get(void *data, Evas_Object * obj, const char *part)
162 struct ug_data *ugd = (struct ug_data *)data;
166 ugd->tg_gps = tg = elm_check_add(obj);
168 if (ugd->is_gps == KEY_ENABLED) {
169 elm_check_state_set(tg, EINA_TRUE);
171 elm_check_state_set(tg, EINA_FALSE);
174 elm_object_style_set(tg, "on&off");
175 evas_object_propagate_events_set(tg, EINA_FALSE);
176 evas_object_smart_callback_add(tg, "changed", _setting_location_gps_cb, ugd);
181 static char *_setting_location_gl_agps_text_get(void *data, Evas_Object * obj, const char *part)
183 return strdup(_(menu[LOCATION_MENU_AGPS]));
186 static Evas_Object *_setting_location_gl_agps_check_get(void *data, Evas_Object * obj, const char *part)
188 struct ug_data *ugd = (struct ug_data *)data;
192 ugd->tg_agps = tg = elm_check_add(obj);
194 if (ugd->is_agps == KEY_ENABLED) {
195 elm_check_state_set(tg, EINA_TRUE);
197 elm_check_state_set(tg, EINA_FALSE);
200 elm_object_style_set(tg, "on&off");
201 evas_object_propagate_events_set(tg, EINA_FALSE);
202 evas_object_smart_callback_add(tg, "changed", _setting_location_agps_cb, ugd);
207 static char *_setting_location_gl_net_text_get(void *data, Evas_Object * obj, const char *part)
209 return strdup(_(menu[LOCATION_MENU_NET]));
212 static Evas_Object *_setting_location_gl_net_check_get(void *data, Evas_Object * obj, const char *part)
214 struct ug_data *ugd = (struct ug_data *)data;
218 ugd->tg_net = tg = elm_check_add(obj);
220 if (ugd->is_net == KEY_ENABLED) {
221 elm_check_state_set(tg, EINA_TRUE);
223 elm_check_state_set(tg, EINA_FALSE);
226 elm_object_style_set(tg, "on&off");
227 evas_object_propagate_events_set(tg, EINA_FALSE);
228 evas_object_smart_callback_add(tg, "changed", _setting_location_net_cb, ugd);
233 static char *_setting_location_gl_mypos_text_get(void *data, Evas_Object * obj, const char *part)
235 return strdup(_(menu[LOCATION_MENU_MYPOS]));
238 static Evas_Object *setting_location_create_layout(Evas_Object * parent)
243 layout = elm_layout_add(parent);
244 elm_layout_theme_set(layout, "layout", "application", "default");
245 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
246 elm_win_resize_object_add(parent, layout);
248 bg = elm_bg_add(layout);
249 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
250 elm_object_part_content_set(layout, "elm.swallow.bg", bg);
251 elm_object_style_set(bg, "group_list");
253 evas_object_show(layout);
258 Evas_Object *setting_location_create_navibar(Evas_Object * parent)
260 Evas_Object *naviframe;
262 naviframe = elm_naviframe_add(parent);
263 //elm_object_style_set(navi_bar, "extended_fnbtn_top_style");
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 elm_check_state_set(ugd->tg_gps, !state);
278 ugd->is_gps = (!state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
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 elm_check_state_set(ugd->tg_agps, !state);
290 ugd->is_agps = (!state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
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 elm_check_state_set(ugd->tg_net, !state);
302 ugd->is_net = (!state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
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 Evas_Object *setting_location_create_gl(Evas_Object * parent, void *data)
320 LOC_LOG("setting_location_create_gl");
321 struct ug_data *ugd = (struct ug_data *)data;
323 Evas_Object *genlist;
324 Elm_Object_Item *item;
326 genlist = elm_genlist_add(parent);
327 elm_object_style_set(genlist, "dialogue");
328 elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
330 ugd->itc_sep = elm_genlist_item_class_new();
331 ugd->itc_sep->item_style = "dialogue/separator/21/with_line";
332 ugd->itc_sep->func.text_get = NULL;
333 ugd->itc_sep->func.content_get = NULL;
334 ugd->itc_sep->func.state_get = NULL;
335 ugd->itc_sep->func.del = NULL;
337 item = elm_genlist_item_append(genlist, ugd->itc_sep, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
338 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
340 ugd->itc_gps = elm_genlist_item_class_new();
341 ugd->itc_gps->item_style = "dialogue/1text.1icon";
342 ugd->itc_gps->func.text_get = _setting_location_gl_gps_text_get;
343 ugd->itc_gps->func.content_get = _setting_location_gl_gps_check_get;
344 ugd->itc_gps->func.state_get = NULL;
345 ugd->itc_gps->func.del = NULL;
347 ugd->gi_gps = elm_genlist_item_append(genlist, ugd->itc_gps, (void *)ugd, NULL, ELM_GENLIST_ITEM_NONE, setting_location_gl_gps_sel, ugd);
349 ugd->itc_agps = elm_genlist_item_class_new();
350 ugd->itc_agps->item_style = "dialogue/1text.1icon";
351 ugd->itc_agps->func.text_get = _setting_location_gl_agps_text_get;
352 ugd->itc_agps->func.content_get = _setting_location_gl_agps_check_get;
353 ugd->itc_agps->func.state_get = NULL;
354 ugd->itc_agps->func.del = NULL;
356 ugd->gi_agps = elm_genlist_item_append(genlist, ugd->itc_agps, (void *)ugd, NULL, ELM_GENLIST_ITEM_NONE, setting_location_gl_agps_sel, ugd);
358 ugd->itc_net = elm_genlist_item_class_new();
359 ugd->itc_net->item_style = "dialogue/1text.1icon";
360 ugd->itc_net->func.text_get = _setting_location_gl_net_text_get;
361 ugd->itc_net->func.content_get = _setting_location_gl_net_check_get;
362 ugd->itc_net->func.state_get = NULL;
363 ugd->itc_net->func.del = NULL;
365 ugd->gi_net = elm_genlist_item_append(genlist, ugd->itc_net, (void *)ugd, NULL, ELM_GENLIST_ITEM_NONE, setting_location_gl_net_sel, ugd);
367 ugd->itc_mypos = elm_genlist_item_class_new();
368 ugd->itc_mypos->item_style = "dialogue/1text.1icon";
369 ugd->itc_mypos->func.text_get = _setting_location_gl_mypos_text_get;
370 ugd->itc_mypos->func.content_get = NULL;
371 ugd->itc_mypos->func.state_get = NULL;
372 ugd->itc_mypos->func.del = NULL;
374 ugd->gi_mypos = elm_genlist_item_append(genlist, ugd->itc_mypos, (void *)ugd, NULL, ELM_GENLIST_ITEM_NONE, setting_location_mypos_sel, ugd);
379 void setting_location_add_bottom_sep(Evas_Object *genlist, struct ug_data *ugd)
381 Elm_Object_Item *item;
383 ugd->itc_bot_sep = elm_genlist_item_class_new();
384 ugd->itc_bot_sep->item_style = "dialogue/separator/20";
385 ugd->itc_bot_sep->func.text_get = NULL;
386 ugd->itc_bot_sep->func.content_get = NULL;
387 ugd->itc_bot_sep->func.state_get = NULL;
388 ugd->itc_bot_sep->func.del = NULL;
390 ugd->gi_bot_sep = elm_genlist_item_append(genlist, ugd->itc_bot_sep, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
391 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
394 static Evas_Object *setting_location_create_view(Evas_Object * parent, struct ug_data *ugd)
396 Evas_Object *layout_main;
397 Elm_Object_Item* navi_it;
398 Evas_Object *l_button;
399 Evas_Object *help_button;
400 Evas_Object *toolbar;
402 layout_main = setting_location_create_layout(parent);
404 ugd->naviframe = setting_location_create_navibar(layout_main);
406 l_button = elm_button_add(ugd->naviframe);
407 elm_object_style_set(l_button, "naviframe/back_btn/default");
408 evas_object_smart_callback_add(l_button, "clicked", setting_location_back_cb, ugd);
410 ugd->genlist = setting_location_create_gl(ugd->naviframe, ugd);
412 setting_location_get_location_app_list(ugd->genlist, ugd);
414 setting_location_add_bottom_sep(ugd->genlist, ugd);
416 evas_object_show(ugd->genlist);
418 navi_it = elm_naviframe_item_push(ugd->naviframe, _("IDS_LBS_BODY_LOCATION"), l_button, NULL, ugd->genlist, NULL);
420 toolbar = elm_toolbar_add(ugd->naviframe);
421 elm_toolbar_shrink_mode_set(toolbar, ELM_TOOLBAR_SHRINK_EXPAND);
423 help_button = (Evas_Object *)elm_toolbar_item_append(toolbar, NULL, _("IDS_COM_BODY_HELP"), setting_location_help_cb, ugd);
424 elm_object_item_disabled_set(elm_toolbar_item_append(toolbar, NULL, "", NULL, NULL), EINA_TRUE);
425 elm_object_item_part_content_set(navi_it, "controlbar", toolbar);
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");
521 struct ug_data *ugd = (struct ug_data *)priv;
523 elm_object_item_del(ugd->gi_bot_sep);
524 setting_location_free_itc(ugd->itc_bot_sep);
527 static void on_resume(ui_gadget_h ug, service_h service, void *priv)
529 LOC_LOG("on_resume is called");
530 struct ug_data *ugd = (struct ug_data *)priv;
531 setting_location_delete_app_list(ugd->genlist, ugd);
532 setting_location_get_location_app_list(ugd->genlist, ugd);
533 setting_location_add_bottom_sep(ugd->genlist, ugd);
534 setting_location_check_di(ugd);
537 static void on_destroy(ui_gadget_h ug, service_h service, void *priv)
539 struct ug_data *ugd = (struct ug_data *)priv;
546 char value[32] = {0,};
548 service_create(&result);
549 if (ugd->is_gps && ugd->is_net) strncpy(value, "GPSEnabled|WPSEnabled", sizeof(value));
550 else if (ugd->is_gps && !ugd->is_net) strncpy(value, "GPSEnabled|WPSDisabled", sizeof(value));
551 else if (!ugd->is_gps && ugd->is_net) strncpy(value, "GPSDisabled|WPSEnabled", sizeof(value));
552 else if (!ugd->is_gps && !ugd->is_net) strncpy(value, "GPSDisabled|WPSDisabled", sizeof(value));
553 service_add_extra_data(result, "State", value);
555 ug_send_result(ug, result);
557 setting_location_deinit(ugd);
559 if (ugd->base != NULL) {
560 evas_object_del(ugd->base);
566 static void on_message(ui_gadget_h ug, service_h msg, service_h data, void *priv)
570 static void on_event(ui_gadget_h ug, enum ug_event event, service_h data, void *priv)
573 case UG_EVENT_LOW_MEMORY:
575 case UG_EVENT_LOW_BATTERY:
577 case UG_EVENT_LANG_CHANGE:
579 case UG_EVENT_ROTATE_PORTRAIT:
581 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
583 case UG_EVENT_ROTATE_LANDSCAPE:
585 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
592 static void on_key_event(ui_gadget_h ug, enum ug_key_event event, service_h data, void *priv)
599 case UG_KEY_EVENT_END:
607 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
615 ugd = calloc(1, sizeof(struct ug_data));
620 ops->create = on_create;
621 ops->start = on_start;
622 ops->pause = on_pause;
623 ops->resume = on_resume;
624 ops->destroy = on_destroy;
625 ops->message = on_message;
626 ops->event = on_event;
627 ops->key_event = on_key_event;
629 ops->opt = UG_OPT_INDICATOR_ENABLE;
634 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)