modify license statement
[framework/location/ug-setting-location-efl.git] / libug-setting-location-efl.c
1 /*
2  * Open Service Platform
3  * Copyright (c) 2012-2013  Samsung Electronics Co., Ltd
4  *
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
8  *
9  *    http://floralicense.org/license/
10  *
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.
16  */
17
18 #ifndef UG_MODULE_API
19 #define UG_MODULE_API __attribute__ ((visibility("default")))
20 #endif
21
22 #include <Elementary.h>
23 #include <ui-gadget-module.h>
24 #include <vconf.h>
25 #include <vconf-internal-location-keys.h>
26
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"
31
32 #define END_KEY_EVENT   FALSE
33
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")
39 };
40
41 #define LOCATION_MENU_ENABLE    0
42 #define LOCATION_MENU_AGPS      1
43 #define LOCATION_MENU_NET       2
44 #define LOCATION_MENU_MYPOS     3
45
46 #define GL_GPS_INDEX            1
47
48 int setting_location_set_int(const char *path, int val)
49 {
50         int ret = vconf_set_int(path, val);
51         if (ret == 0) {
52                 return TRUE;
53         }
54         return FALSE;
55 }
56
57 void setting_location_check_di(void *data)
58 {
59         LOC_LOG("setting_location_check_di");
60         struct ug_data *ugd = (struct ug_data *)data;
61         int i;
62
63         elm_check_state_set(ugd->tg_gps, ugd->is_gps);
64         elm_object_item_disabled_set(ugd->gi_agps, !ugd->is_gps);
65
66         elm_check_state_set(ugd->tg_net, ugd->is_net);
67
68         elm_object_item_disabled_set(ugd->gi_mypos, !(ugd->is_gps || ugd->is_net));
69 }
70
71 static void setting_location_free_itc(Elm_Genlist_Item_Class *itc)
72 {
73         if (itc == NULL) {
74                 return;
75         }
76         elm_genlist_item_class_free(itc);
77 }
78
79 static void setting_location_back_cb(void *data, Evas_Object * obj, void *event_info)
80 {
81         LOC_LOG("setting_location_back_cb");
82         struct ug_data *ugd = (struct ug_data *)data;
83         int i;
84
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);
91
92         ug_destroy_me(ugd->ug);
93 }
94
95 static void setting_location_help_cb(void *data, Evas_Object * obj, void *event_info)
96 {
97         struct ug_data *ugd = (struct ug_data *)data;
98
99         setting_location_help_view(ugd);
100 }
101
102 static void _setting_location_gps_cb(void *data, Evas_Object * obj, void *event_info)
103 {
104         struct ug_data *ugd = (struct ug_data *)data;
105
106         Eina_Bool state = elm_check_state_get(obj);
107
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);
111 }
112
113 static void _setting_location_agps_cb(void *data, Evas_Object * obj, void *event_info)
114 {
115         struct ug_data *ugd = (struct ug_data *)data;
116
117         Eina_Bool state = elm_check_state_get(obj);
118
119         if (ugd->is_gps == KEY_DISABLED) {
120                 elm_check_state_set(obj, !state);
121                 return;
122         }
123         ugd->is_agps = (state == EINA_TRUE) ? KEY_ENABLED : KEY_DISABLED;
124         setting_location_set_int(VCONFKEY_LOCATION_AGPS_ENABLED, ugd->is_agps);
125 }
126
127 static void _setting_location_net_cb(void *data, Evas_Object * obj, void *event_info)
128 {
129         struct ug_data *ugd = (struct ug_data *)data;
130
131         Eina_Bool state = elm_check_state_get(obj);
132
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);
136 }
137
138 static char *_setting_location_gl_gps_text_get(void *data, Evas_Object * obj, const char *part)
139 {
140         return strdup(_(menu[LOCATION_MENU_ENABLE]));
141 }
142
143 static Evas_Object *_setting_location_gl_gps_check_get(void *data, Evas_Object * obj, const char *part)
144 {
145         struct ug_data *ugd = (struct ug_data *)data;
146
147         Evas_Object *tg;
148
149         ugd->tg_gps = tg = elm_check_add(obj);
150
151         if (ugd->is_gps == KEY_ENABLED) {
152                 elm_check_state_set(tg, EINA_TRUE);
153         } else {
154                 elm_check_state_set(tg, EINA_FALSE);
155         }
156
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);
160
161         return tg;
162 }
163
164 static char *_setting_location_gl_agps_text_get(void *data, Evas_Object * obj, const char *part)
165 {
166         return strdup(_(menu[LOCATION_MENU_AGPS]));
167 }
168
169 static Evas_Object *_setting_location_gl_agps_check_get(void *data, Evas_Object * obj, const char *part)
170 {
171         struct ug_data *ugd = (struct ug_data *)data;
172
173         Evas_Object *tg;
174
175         ugd->tg_agps = tg = elm_check_add(obj);
176
177         if (ugd->is_agps == KEY_ENABLED) {
178                 elm_check_state_set(tg, EINA_TRUE);
179         } else {
180                 elm_check_state_set(tg, EINA_FALSE);
181         }
182
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);
186
187         return tg;
188 }
189
190 static char *_setting_location_gl_net_text_get(void *data, Evas_Object * obj, const char *part)
191 {
192         return strdup(_(menu[LOCATION_MENU_NET]));
193 }
194
195 static Evas_Object *_setting_location_gl_net_check_get(void *data, Evas_Object * obj, const char *part)
196 {
197         struct ug_data *ugd = (struct ug_data *)data;
198
199         Evas_Object *tg;
200
201         ugd->tg_net = tg = elm_check_add(obj);
202
203         if (ugd->is_net == KEY_ENABLED) {
204                 elm_check_state_set(tg, EINA_TRUE);
205         } else {
206                 elm_check_state_set(tg, EINA_FALSE);
207         }
208
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);
212
213         return tg;
214 }
215
216 static char *_setting_location_gl_mypos_text_get(void *data, Evas_Object * obj, const char *part)
217 {
218         return strdup(_(menu[LOCATION_MENU_MYPOS]));
219 }
220
221 static Evas_Object *setting_location_create_layout(Evas_Object * parent)
222 {
223         Evas_Object *layout;
224         Evas_Object *bg;
225
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);
229
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");
234         
235         evas_object_show(layout);
236
237         return layout;
238 }
239
240 Evas_Object *setting_location_create_navibar(Evas_Object * parent)
241 {
242         Evas_Object *naviframe;
243
244         naviframe = elm_naviframe_add(parent);
245         elm_object_part_content_set(parent, "elm.swallow.content", naviframe);
246
247         evas_object_show(naviframe);
248
249         return naviframe;
250 }
251
252 static void setting_location_gl_gps_sel(void *data, Evas_Object *obj, void *event_info)
253 {
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);
257
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);
262 }
263
264 static void setting_location_gl_agps_sel(void *data, Evas_Object *obj, void *event_info)
265 {
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);
269
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);
274 }
275
276 static void setting_location_gl_net_sel(void *data, Evas_Object *obj, void *event_info)
277 {
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);
281
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);
286 }
287
288 static void setting_location_mypos_sel(void *data, Evas_Object *obj, void *event_info)
289 {
290         struct ug_data *ugd = (struct ug_data *)data;
291
292         elm_genlist_select_mode_set(ugd->genlist, ELM_OBJECT_SELECT_MODE_NONE);
293
294         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
295         setting_location_mypos_view(data);
296         return;
297 }
298
299 static void setting_location_genlist_realized(void *data, Evas_Object *obj, void *gi)
300 {
301         if (!gi) {
302                 return;
303         }
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;
309
310         if (ugd->app_count == 2 && index == applist_index)
311                 return;
312
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", "");
319         } else {
320                 LOC_LOG("MID index = %d", index);
321                 elm_object_item_signal_emit(gi, "elm,state,center", "");
322         }
323 }
324
325 Evas_Object *setting_location_create_gl(Evas_Object * parent, void *data)
326 {
327         LOC_LOG("setting_location_create_gl");
328         struct ug_data *ugd = (struct ug_data *)data;
329
330         Evas_Object *genlist;
331
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);
335
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);
343         ugd->opt_index = 0;
344         elm_genlist_item_select_mode_set(ugd->gi_top_sep, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
345
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;
352
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);
354         ugd->opt_index++;
355
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;
362
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);
364         ugd->opt_index++;
365
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;
372
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);
375                 ugd->opt_index++;
376         }
377         else ugd->gi_net = NULL;
378
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;
385
386         ugd->gi_mypos = elm_genlist_item_append(genlist, ugd->itc_mypos, (void *)ugd, NULL, ELM_GENLIST_ITEM_NONE, setting_location_mypos_sel, ugd);
387         ugd->opt_index++;
388
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);
397
398         return genlist;
399 }
400
401 static Evas_Object *setting_location_create_view(Evas_Object * parent, struct ug_data *ugd)
402 {
403         Evas_Object *layout_main;
404         Elm_Object_Item* navi_it;
405         Evas_Object *l_button;
406         Evas_Object *help_button;
407
408         layout_main = setting_location_create_layout(parent);
409
410         ugd->naviframe = setting_location_create_navibar(layout_main);
411
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);
415
416         ugd->genlist = setting_location_create_gl(ugd->naviframe, ugd);
417         evas_object_show(ugd->genlist);
418
419         navi_it = elm_naviframe_item_push(ugd->naviframe, _("IDS_LBS_HEADER_LOCATION"), l_button, NULL, ugd->genlist, NULL);
420
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);
426
427         return layout_main;
428 }
429
430 void gps_enabled_cb(keynode_t * key, void *data)
431 {
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);
436 }
437
438 void net_enabled_cb(keynode_t * key, void *data)
439 {
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);
444 }
445
446 int setting_location_init(struct ug_data *ugd)
447 {
448         LOC_LOG("setting_location_init");
449         int ret = TRUE;
450
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);
456
457         setting_location_check_di(ugd);
458
459         return ret;
460 }
461
462 int setting_location_deinit(struct ug_data *ugd)
463 {
464         int ret = TRUE;
465
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);
468
469         return ret;
470 }
471
472 UG_MODULE_API int setting_plugin_reset(service_h service, void *priv)
473 {
474         if (vconf_set_int(VCONFKEY_LOCATION_ENABLED, KEY_DISABLED) != 0) {
475                 return -1;
476         }
477         if (vconf_set_int(VCONFKEY_LOCATION_AGPS_ENABLED, KEY_DISABLED) != 0) {
478                 return -1;
479         }
480         if (vconf_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, KEY_DISABLED) != 0) {
481                 return -1;
482         }
483
484         return 0;
485 }
486
487 static void *on_create(ui_gadget_h ug, enum ug_mode mode, service_h service, void *priv)
488 {
489         Evas_Object *parent;
490         struct ug_data *ugd;
491
492         if (!ug || !priv)
493                 return NULL;
494
495         bindtextdomain("ug-setting-location-efl", LANGDIR);
496
497         ugd = priv;
498         ugd->ug = ug;
499
500         parent = ug_get_parent_layout(ug);
501         if (!parent) {
502                 return NULL;
503         }
504
505         if (mode == UG_MODE_FULLVIEW) {
506                 ugd->base = setting_location_create_view(parent, ugd);
507                 setting_location_init(ugd);
508         } else {
509                 return NULL;
510         }
511
512         return ugd->base;
513 }
514
515 static void on_start(ui_gadget_h ug, service_h service, void *priv)
516 {
517         LOC_LOG("on_start is called");
518 }
519
520 static void on_pause(ui_gadget_h ug, service_h service, void *priv)
521 {
522         LOC_LOG("on_pause is called");
523 }
524
525 static void on_resume(ui_gadget_h ug, service_h service, void *priv)
526 {
527         LOC_LOG("on_resume is called");
528         struct ug_data *ugd = (struct ug_data *)priv;
529         setting_location_check_di(ugd);
530 }
531
532 static void on_destroy(ui_gadget_h ug, service_h service, void *priv)
533 {
534         struct ug_data *ugd = (struct ug_data *)priv;
535
536         if (!ug || !priv) {
537                 return;
538         }
539
540         service_h result;
541         char value[32] = {0,};
542
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);
549
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);
553
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);
557
558         ug_send_result(ug, result);
559         service_destroy(result);
560
561         setting_location_deinit(ugd);
562
563         if (ugd->base != NULL) {
564                 evas_object_del(ugd->base);
565         }
566
567         ugd->base = NULL;
568 }
569
570 static void on_message(ui_gadget_h ug, service_h msg, service_h data, void *priv)
571 {
572 }
573
574 static void on_event(ui_gadget_h ug, enum ug_event event, service_h data, void *priv)
575 {
576         switch (event) {
577         case UG_EVENT_LOW_MEMORY:
578                 break;
579         case UG_EVENT_LOW_BATTERY:
580                 break;
581         case UG_EVENT_LANG_CHANGE:
582                 break;
583         case UG_EVENT_ROTATE_PORTRAIT:
584                 break;
585         case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
586                 break;
587         case UG_EVENT_ROTATE_LANDSCAPE:
588                 break;
589         case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
590                 break;
591         default:
592                 break;
593         }
594 }
595
596 static void on_key_event(ui_gadget_h ug, enum ug_key_event event, service_h data, void *priv)
597 {
598         if (!ug) {
599                 return;
600         }
601
602         switch (event) {
603         case UG_KEY_EVENT_END:
604                 ug_destroy_me(ug);
605                 break;
606         default:
607                 break;
608         }
609 }
610
611 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
612 {
613         struct ug_data *ugd;
614
615         if (!ops) {
616                 return -1;
617         }
618
619         ugd = calloc(1, sizeof(struct ug_data));
620         if (!ugd) {
621                 return -1;
622         }
623
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;
632         ops->priv = ugd;
633         ops->opt = UG_OPT_INDICATOR_ENABLE;
634
635         return 0;
636 }
637
638 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
639 {
640         struct ug_data *ugd;
641
642         if (!ops) {
643                 return;
644         }
645
646         ugd = ops->priv;
647
648         if (ugd) {
649                 free(ugd);
650         }
651 }