tizen 2.3.1 release
[apps/home/settings.git] / setting-flightmode / src / setting-flightmode.c
1 /*
2  * setting
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
5  *
6  * Contact: MyoungJune Park <mj2004.park@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 #include <setting-flightmode.h>
22
23 #ifndef UG_MODULE_API
24 #define UG_MODULE_API __attribute__ ((visibility("default")))
25 #endif
26
27 static void setting_flightmode_ug_cb_resize(void *data, Evas *e,
28                                             Evas_Object *obj, void *event_info)
29 {
30         SettingFlightModeUG *ad = (SettingFlightModeUG *) data;
31         setting_view_update(&setting_view_flightmode_main, ad);
32 }
33
34 setting_view *__get_flightmode_view_to_load(void *data, app_control_h service)
35 {
36         SETTING_TRACE_BEGIN;
37         setting_retvm_if((!data), NULL, "data is NULL");
38
39         setting_view_node_table_intialize();
40
41         /* default action */
42         setting_view_node_table_register(&setting_view_flightmode_main, NULL);
43         return &setting_view_flightmode_main;
44 }
45
46 static void *setting_flightmode_ug_on_create(ui_gadget_h ug,
47                                              enum ug_mode mode, app_control_h service,
48                                              void *priv)
49 {
50         SETTING_TRACE_BEGIN;
51         setting_retvm_if((!priv), NULL, "!priv");
52         SettingFlightModeUG *flightmodeUG = priv;
53         flightmodeUG->ug = ug;
54         flightmodeUG->bundle_data = service;
55         setting_set_i18n(SETTING_PACKAGE, SETTING_LOCALEDIR);
56
57         flightmodeUG->win_main_layout = (Evas_Object *) ug_get_parent_layout(ug);
58         flightmodeUG->win_get = (Evas_Object *) ug_get_window();
59
60         evas_object_show(flightmodeUG->win_main_layout);
61         flightmodeUG->evas = evas_object_evas_get(flightmodeUG->win_main_layout);
62
63         setting_retvm_if(flightmodeUG->win_main_layout == NULL, NULL,
64                          "cannot get main window ");
65
66         /* register view node table */
67         flightmodeUG->view_to_load = __get_flightmode_view_to_load(flightmodeUG, service);
68         setting_retvm_if(NULL == flightmodeUG->view_to_load, NULL, "NULL == flightmodeUG->view_to_load");
69
70         setting_create_Gendial_itc("dialogue/1text.2icon", &(flightmodeUG->itc_1text_2icon));
71
72         /* creating a view. */
73         setting_view_node_set_cur_view(flightmodeUG->view_to_load);
74         setting_view_create(flightmodeUG->view_to_load, (void *)flightmodeUG);
75
76         evas_object_event_callback_add(flightmodeUG->win_main_layout,
77                                        EVAS_CALLBACK_RESIZE,
78                                        setting_flightmode_ug_cb_resize, flightmodeUG);
79
80         /*---------------------------------------------------------------- */
81         /* add genlist */
82         /*---------------------------------------------------------------- */
83         return flightmodeUG->ly_main;
84 }
85
86 static void setting_flightmode_ug_on_start(ui_gadget_h ug, app_control_h service,
87                                            void *priv)
88 {
89 }
90
91 static void setting_flightmode_ug_on_pause(ui_gadget_h ug, app_control_h service,
92                                            void *priv)
93 {
94 }
95
96 static void setting_flightmode_ug_on_resume(ui_gadget_h ug, app_control_h service,
97                                             void *priv)
98 {
99 }
100
101 static void setting_flightmode_ug_on_destroy(ui_gadget_h ug, app_control_h service,
102                                              void *priv)
103 {
104         SETTING_TRACE_BEGIN;
105         setting_retm_if((!priv), "!priv");
106         SettingFlightModeUG *flightmodeUG = priv;
107         evas_object_event_callback_del(flightmodeUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_flightmode_ug_cb_resize);   /*fix flash issue for gallery */
108         flightmodeUG->ug = ug;
109         if (flightmodeUG->bg) {
110                 evas_object_del(flightmodeUG->bg);
111         }
112         flightmodeUG->bg = NULL;
113
114         /* called when this shared gadget is terminated. similar with app_exit */
115         setting_view_destroy(&setting_view_flightmode_main, flightmodeUG);
116
117         if (NULL != ug_get_layout(flightmodeUG->ug)) {
118                 evas_object_hide((Evas_Object *) ug_get_layout(flightmodeUG->ug));
119                 evas_object_del((Evas_Object *) ug_get_layout(flightmodeUG->ug));
120         }
121 }
122
123 static void setting_flightmode_ug_on_message(ui_gadget_h ug, app_control_h msg,
124                                              app_control_h service, void *priv)
125 {
126         SETTING_TRACE_BEGIN;
127 }
128
129 static void setting_flightmode_ug_on_event(ui_gadget_h ug,
130                                            enum ug_event event, app_control_h service,
131                                            void *priv)
132 {
133         SETTING_TRACE_BEGIN;
134         switch (event) {
135                 case UG_EVENT_LOW_MEMORY:
136                         break;
137                 case UG_EVENT_LOW_BATTERY:
138                         break;
139                 case UG_EVENT_LANG_CHANGE:
140                         break;
141                 case UG_EVENT_ROTATE_PORTRAIT:
142                         break;
143                 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
144                         break;
145                 case UG_EVENT_ROTATE_LANDSCAPE:
146                         break;
147                 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
148                         break;
149                 case UG_EVENT_REGION_CHANGE:
150                         break;
151                 default:
152                         break;
153         }
154 }
155
156 static void setting_flightmode_ug_on_key_event(ui_gadget_h ug,
157                                                enum ug_key_event event,
158                                                app_control_h service, void *priv)
159 {
160         SETTING_TRACE_BEGIN;
161         SettingFlightModeUG *ad = (SettingFlightModeUG *) priv;
162
163         switch (event) {
164                 case UG_KEY_EVENT_END: {
165                                 if (elm_naviframe_top_item_get(ad->navi_bar) ==
166                                     elm_naviframe_bottom_item_get(ad->
167                                                                   navi_bar)) {
168                                         ug_destroy_me(ug);
169                                 } else {
170
171                                         setting_view_cb_at_endKey(ad);
172                                 }
173                         }
174                         break;
175                 default:
176                         break;
177         }
178 }
179
180 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
181 {
182         SETTING_TRACE_BEGIN;
183         SettingFlightModeUG *flightmodeUG = calloc(1, sizeof(SettingFlightModeUG));
184         setting_retvm_if(!flightmodeUG, -1, "Create SettingFlightModeUG obj failed");
185
186         ops->create = setting_flightmode_ug_on_create;
187         ops->start = setting_flightmode_ug_on_start;
188         ops->pause = setting_flightmode_ug_on_pause;
189         ops->resume = setting_flightmode_ug_on_resume;
190         ops->destroy = setting_flightmode_ug_on_destroy;
191         ops->message = setting_flightmode_ug_on_message;
192         ops->event = setting_flightmode_ug_on_event;
193         ops->key_event = setting_flightmode_ug_on_key_event;
194         ops->priv = flightmodeUG;
195         ops->opt = UG_OPT_INDICATOR_ENABLE;
196         return 0;
197 }
198
199 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
200 {
201         SETTING_TRACE_BEGIN;
202         struct SettingFlightModeUG *flightmodeUG;
203         setting_retm_if(!ops, "ops == NULL");
204
205         flightmodeUG = ops->priv;
206         if (flightmodeUG) {
207                 FREE(flightmodeUG);
208         }
209 }
210
211 /* ***************************************************
212 **
213 ** general func
214 **
215 ** **************************************************/
216
217 /**
218 * Reset function to 'reset' the settings of the UG, it will be invoked by 'Reset' UG
219 *
220 * @param[in] data
221 * @param[in] priv
222 */
223