Initialize Tizen 2.3
[apps/connectivity/bt-connection-popup.git] / src / bt-connection-main.c
1 /*
2 * bt-connection-popup
3 *
4 * Copyright 2012 Samsung Electronics Co., Ltd
5 *
6 * Contact: Hocheol Seo <hocheol.seo@samsung.com>
7 *           Injun Yang <injun.yang@samsung.com>
8 *           Seungyoun Ju <sy39.ju@samsung.com>
9 *
10 * Licensed under the Flora License, Version 1.1 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.tizenopensource.org/license
15 *
16 * Unless required by applicable law or agreed to in writing,
17 * software distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 *
22 */
23
24 #include <app.h>
25 #include <efl_assist.h>
26
27 #include "bt-connection-main.h"
28 #include "bt-connection-view.h"
29 #include "bt-connection-handler.h"
30 #include "bt-connection-ipc.h"
31
32 static Evas_Object* _create_win(const char *name)
33 {
34         Evas_Object *eo;
35         int w;
36         int h;
37
38         eo = elm_win_add(NULL, name, ELM_WIN_DIALOG_BASIC);
39         if (eo) {
40                 elm_win_title_set(eo, name);
41                 elm_win_borderless_set(eo, EINA_TRUE);
42                 ecore_x_window_size_get(ecore_x_window_root_first_get(),
43                                         &w, &h);
44                 evas_object_resize(eo, w, h);
45         }
46
47         return eo;
48 }
49
50 static Eina_Bool _pop_cb(void *data, Elm_Object_Item *it)
51 {
52         DBG("");
53
54         if (!data) {
55                 return EINA_FALSE;
56         }
57
58         elm_exit();
59         return EINA_FALSE;
60 }
61
62 void __destory_app_cb(void *data, Evas_Object *obj, void *event_info)
63 {
64         if (data == NULL)
65                 return;
66
67         DBG("EA Back on navi");
68
69         bt_app_data_t *ad = (bt_app_data_t *)data;
70
71         _bt_destroy_app(ad);
72 }
73
74 static Evas_Object* _create_layout_main(Evas_Object* parent)
75 {
76         Evas_Object *layout;
77
78         if (parent == NULL)
79                 return NULL;
80
81         layout = elm_layout_add(parent);
82         if (layout == NULL)
83                 return NULL;
84
85         elm_layout_theme_set(layout, "layout", "application", "default");
86         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
87         elm_object_part_content_set(parent, "elm.swallow.content", layout);
88         evas_object_show(layout);
89
90         return layout;
91 }
92
93 static Evas_Object* _create_naviframe(Evas_Object* parent)
94 {
95         Evas_Object *naviframe;
96
97         if (parent == NULL)
98                 return NULL;
99         naviframe = elm_naviframe_add(parent);
100         elm_object_part_content_set(parent, "elm.swallow.content", naviframe);
101
102         return naviframe;
103 }
104
105 static void _create_view_layout(bt_app_data_t *ad)
106 {
107         if (ad == NULL || ad->navi == NULL)
108                 return;
109
110         ea_object_event_callback_add(ad->navi, EA_CALLBACK_BACK,
111                 __destory_app_cb, ad);
112
113         _bt_create_connection_query_popup(ad);
114
115         DBG("-");
116 }
117
118 static int __initialize_view(bt_app_data_t *ad)
119 {
120         DBG("+");
121
122         Elm_Object_Item *navi_it;
123
124         if (ad == NULL)
125                 return -1;
126
127         ad->layout_main = _create_layout_main(ad->window);
128         if (!ad->layout_main)
129                 return -1;
130
131         ad->navi = _create_naviframe(ad->layout_main);
132
133         _create_view_layout(ad);
134
135         navi_it = elm_naviframe_item_push(ad->navi, NULL, NULL, NULL, ad->main_layout, NULL);
136         elm_naviframe_item_title_enabled_set(navi_it, EINA_FALSE, EINA_FALSE);
137         elm_naviframe_item_pop_cb_set(navi_it, _pop_cb, ad);
138         elm_naviframe_item_title_visible_set(navi_it, EINA_FALSE);
139
140         DBG("-");
141
142         return 0;
143 }
144
145 static bool app_create(void *data)
146 {
147         DBG("");
148
149         bt_app_data_t *ad;
150         ad = (bt_app_data_t *)data;
151
152         ad->initialize = FALSE;
153         ad->window = _create_win(PACKAGE);
154         if (ad->window == NULL)
155                 return FALSE;
156
157         evas_object_show(ad->window);
158
159         /* Handle rotation */
160         if (elm_win_wm_rotation_supported_get(ad->window)) {
161                 int rots[4] = {0, 90, 180, 270};
162                 elm_win_wm_rotation_available_rotations_set(ad->window,
163                                                         (const int*)(&rots), 4);
164         }
165
166         _bt_register_vconf_handler(ad);
167
168         return TRUE;
169 }
170
171 static void app_terminate(void *data)
172 {
173         DBG("");
174
175         int status;
176         bt_app_data_t *ad = (bt_app_data_t *)data;
177         if (ad == NULL)
178                 return;
179
180         status = _bt_get_wms_status();
181         if (status == WMS_DISCONNECTED) {
182                 /* In case WMS_CONNECTED, */
183                 /* we sent result on connected view */
184                 DBG("App terminiated. Send response (Not Connected)");
185                 _bt_send_result(ad, KEY_VAL_NOT_CONNECTED);
186         }
187
188         _bt_get_sap_status(); /* Check sap status */
189
190         return;
191 }
192
193 static void app_pause(void *data)
194 {
195         DBG("");
196         return;
197 }
198
199 static void app_resume(void *data)
200 {
201         DBG("");
202         return;
203 }
204
205 static void app_service(service_h service, void *data)
206 {
207         DBG("");
208
209         char *caller = NULL;
210         bt_app_data_t *ad;
211
212         ad = (bt_app_data_t *)data;
213         if (ad == NULL)
214                 return;
215
216         if (ad->dbus_conn == NULL) {
217                 _bt_dbus_signal_init(ad);
218         }
219
220         ad->service = service;
221         service_clone(&ad->service_clone, service);
222         service_get_caller(service, &caller);
223         DBG_SECURE("Launched by %s", caller);
224
225         if (__initialize_view(ad) < 0) {
226                 ERR("__initialize_view failed");
227         }
228
229         return;
230 }
231
232 static void app_lang_changed(void *data)
233 {
234         return;
235 }
236
237 static void app_regeion_changed(void *data)
238 {
239         return;
240 }
241
242 /**
243 * @describe
244 *   The entry of the program
245 *
246 * @param    argc
247 * @param    argv
248 * @param    int
249 * @exception
250 */
251 DLL_DEFAULT int main(int argc, char *argv[])
252 {
253         bt_app_data_t ad;
254
255         app_event_callback_s event_callback;
256
257         event_callback.create = app_create;
258         event_callback.terminate = app_terminate;
259         event_callback.pause = app_pause;
260         event_callback.resume = app_resume;
261         event_callback.service = app_service;
262         event_callback.low_memory = NULL;
263         event_callback.low_battery = NULL;
264         event_callback.device_orientation = NULL;
265         event_callback.language_changed = app_lang_changed;
266         event_callback.region_format_changed = app_regeion_changed;
267
268         memset(&ad, 0x0, sizeof(bt_app_data_t));
269         setenv("EVAS_NO_DRI_SWAPBUF", "1", 1);
270
271         DBG("");
272         return app_efl_main(&argc, &argv, &event_callback, &ad);
273
274 }