Change the manifest and remove rule files
[apps/native/ug-wifi-direct.git] / ugapp-wifidirect / src / wfd-ugapp-main.c
1 /*
2 *  WiFi-Direct UG
3 *
4 * Copyright 2012 Samsung Electronics Co., Ltd
5
6 * Licensed under the Flora License, Version 1.1 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9
10 * http://floralicense.org/license
11
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20 /**
21  * This file implements wifi direct application main functions.
22  *
23  * @file    wfd-ug-app-main.c
24  * @author  Dongwook Lee (dwmax.lee@samsung.com)
25  * @version 0.1
26  */
27
28 #include <ui-gadget-module.h>
29 #include <libintl.h>
30
31 #include "wfd-ugapp.h"
32 #include "wfd-ugapp-util.h"
33
34
35 wfd_appdata_t *g_wfd_ad = NULL;
36 static struct ug_cbs wifi_direct_cbs;
37
38 wfd_appdata_t *wfd_get_appdata()
39 {
40         return g_wfd_ad;
41 }
42
43 void _ug_layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv)
44 {
45         __WDUA_LOG_FUNC_ENTER__;
46
47         Evas_Object *base = NULL;
48         base = ug_get_layout(ug);
49
50         if (!base) {
51                 WDUA_LOGE("ug_get_layout failed!");
52                 ug_destroy(ug);
53                 __WDUA_LOG_FUNC_EXIT__;
54                 return;
55         }
56
57         switch (mode) {
58         case UG_MODE_FULLVIEW:
59                 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
60                 elm_win_resize_object_add(ug_get_window(), base);
61                 evas_object_show(base);
62                 break;
63         default:
64                 break;
65         }
66
67         __WDUA_LOG_FUNC_EXIT__;
68 }
69
70 void _ug_destroy_cb(ui_gadget_h ug, void *priv)
71 {
72         __WDUA_LOG_FUNC_ENTER__;
73
74         // TODO: free all memory allocation
75
76         ug_destroy(ug);
77         elm_exit();
78 }
79
80 void ug_result_cb(ui_gadget_h ug, service_h service, void *priv)
81 {
82         __WDUA_LOG_FUNC_ENTER__;
83
84         // TODO: free all memory allocation
85
86         __WDUA_LOG_FUNC_EXIT__;
87 }
88
89 static int load_wifi_direct_ug(ui_gadget_h parent_ug, void *data)
90 {
91         __WDUA_LOG_FUNC_ENTER__;
92         wfd_appdata_t *ugd = (wfd_appdata_t *)data;
93         service_h handle = NULL;
94
95         UG_INIT_EFL(ugd->win, UG_OPT_INDICATOR_ENABLE);
96
97         memset(&wifi_direct_cbs, 0, sizeof(struct ug_cbs));
98
99         wifi_direct_cbs.layout_cb = _ug_layout_cb;
100         wifi_direct_cbs.result_cb = ug_result_cb;
101         wifi_direct_cbs.destroy_cb = _ug_destroy_cb;
102         wifi_direct_cbs.priv = ugd;
103
104         ugd->wifi_direct_ug = ug_create(parent_ug, "setting-wifidirect-efl", UG_MODE_FULLVIEW, handle, &wifi_direct_cbs);
105         if (ugd->wifi_direct_ug) {
106                 __WDUA_LOG_FUNC_EXIT__;
107                 return TRUE;
108         } else {
109                 __WDUA_LOG_FUNC_EXIT__;
110                 return FALSE;
111         }
112
113         __WDUA_LOG_FUNC_EXIT__;
114 }
115
116
117 static void _win_del(void *data, Evas_Object * obj, void *event)
118 {
119         elm_exit();
120 }
121
122 static Evas_Object *_create_win(Evas_Object * parent, const char *name)
123 {
124         Evas_Object *eo;
125         int w, h;
126
127         eo = elm_win_add(parent, name, ELM_WIN_BASIC);
128         if (eo) {
129                 elm_win_title_set(eo, name);
130                 elm_win_alpha_set(eo, EINA_TRUE);
131                 elm_win_conformant_set(eo, EINA_TRUE);
132                 evas_object_smart_callback_add(eo, "delete,request", _win_del, NULL);
133                 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
134                 evas_object_resize(eo, w, h);
135                 evas_object_show(eo);
136         }
137
138         return eo;
139 }
140
141 static Evas_Object* _set_win_icon(wfd_appdata_t *ad)
142 {
143         __WDUA_LOG_FUNC_ENTER__;
144
145         Evas_Object *icon = evas_object_image_add(evas_object_evas_get(ad->win));
146         evas_object_image_file_set(icon, DESKTOP_ICON, NULL);
147         elm_win_icon_object_set(ad->win, icon);
148
149         __WDUA_LOG_FUNC_EXIT__;
150         return icon;
151 }
152
153 static Evas_Object *_create_bg(Evas_Object *parent)
154 {
155         __WDUA_LOG_FUNC_ENTER__;
156
157         if (NULL == parent) {
158                 WDUA_LOGE("Incorrect parameter\n");
159                 return NULL;
160         }
161
162         Evas_Object *bg = elm_bg_add(parent);
163         if (NULL == bg) {
164                 WDUA_LOGE("Create background failed\n");
165                 return NULL;
166         }
167
168         evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
169         elm_win_resize_object_add(parent, bg);
170         evas_object_show(bg);
171
172         __WDUA_LOG_FUNC_EXIT__;
173         return bg;
174 }
175
176 static Evas_Object *_create_layout_main(Evas_Object *parent)
177 {
178         __WDUA_LOG_FUNC_ENTER__;
179
180         if (NULL == parent) {
181                 WDUA_LOGE("Incorrect parameter\n");
182                 return NULL;
183         }
184
185         Evas_Object *layout = elm_layout_add(parent);
186         if (NULL == layout) {
187                 WDUA_LOGE("Create layout failed\n");
188                 return NULL;
189         }
190
191         const char *profile = elm_config_profile_get();
192         if (!strcmp(profile, "mobile")) {
193                 elm_layout_theme_set(layout, "layout", "application", "default");
194         } else if (!strcmp(profile, "desktop")) {
195                 elm_layout_theme_set(layout, "layout", "application", "noindicator");
196         }
197
198         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
199         elm_object_content_set(parent, layout);
200         evas_object_show(layout);
201
202         __WDUA_LOG_FUNC_EXIT__;
203         return layout;
204 }
205
206 static void _win_profile_changed_cb(void *data, Evas_Object * obj, void *event_info)
207 {
208         __WDUA_LOG_FUNC_ENTER__;
209
210         if (data == NULL) {
211                 WDUA_LOGE("Incorrect parameter\n");
212                 return -1;
213         }
214
215         wfd_appdata_t *ad = (wfd_appdata_t *)data;
216         const char *profile = elm_config_profile_get();
217
218         if (!strcmp(profile, "desktop")) {  /* desktop mode */
219                 /* hide layout's indicator area */
220                 elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_HIDE);
221
222                 /* set window icon */
223                 if (!ad->icon)  {
224                         ad->icon = _set_win_icon(ad);
225                 }
226         }
227         else {  /* mobile mode */
228                 /* show layout's indicator area */
229                 elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
230         }
231
232         __WDUA_LOG_FUNC_EXIT__;
233 }
234
235 static int _app_create(void *data)
236 {
237         __WDUA_LOG_FUNC_ENTER__;
238         wfd_appdata_t *ad = wfd_get_appdata();
239
240         if (data == NULL) {
241                 WDUA_LOGE("Incorrect parameter\n");
242                 return -1;
243         }
244
245         bindtextdomain(PACKAGE, LOCALEDIR);
246
247         ad->win = _create_win(NULL, PACKAGE);
248         evas_object_smart_callback_add(ad->win, "profile,changed", _win_profile_changed_cb, ad);
249
250         /*Add conformat for indicator */
251         ad->bg = _create_bg(ad->win);
252         if (ad->bg == NULL) {
253                 WDUA_LOGE("Failed to create background");
254                 return -1;
255         }
256
257         ad->conform = elm_conformant_add(ad->win);
258         if (ad->conform == NULL) {
259                 WDUA_LOGE("Failed to create elm conformant");
260                 return -1;
261         }
262
263         elm_win_resize_object_add(ad->win, ad->conform);
264         evas_object_size_hint_weight_set(ad->conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
265         evas_object_show(ad->conform);
266
267         ad->top_layout = _create_layout_main(ad->conform);
268         if (ad->top_layout == NULL) {
269                 WDUA_LOGE("Failed to create top layout");
270                 return -1;
271         }
272
273         elm_object_content_set(ad->conform, ad->top_layout);
274
275         int r;
276
277         if (!ecore_x_display_get()) {
278                 return -1;
279         }
280
281         r = appcore_set_i18n(PACKAGE, NULL);
282         if (r != 0) {
283                 WDUA_LOGE("appcore_set_i18n error\n");
284                 return -1;
285         }
286
287         __WDUA_LOG_FUNC_EXIT__;
288         return 0;
289 }
290
291 static int _app_terminate(void *data)
292 {
293         __WDUA_LOG_FUNC_ENTER__;
294
295         if (data == NULL) {
296                 WDUA_LOGE("Incorrect parameter\n");
297                 return -1;
298         }
299
300         wfd_appdata_t *ad = (wfd_appdata_t *) data;
301
302         if (ad->win) {
303                 evas_object_del(ad->win);
304                 ad->win = NULL;
305         }
306
307         if (ad->bg) {
308                 evas_object_del(ad->bg);
309                 ad->bg = NULL;
310         }
311
312         if (ad->conform) {
313                 evas_object_del(ad->conform);
314                 ad->conform = NULL;
315         }
316
317         if (ad->top_layout) {
318                 evas_object_del(ad->top_layout);
319                 ad->top_layout = NULL;
320         }
321
322         if (ad->icon) {
323                 evas_object_del(ad->icon);
324                 ad->icon = NULL;
325         }
326
327         __WDUA_LOG_FUNC_EXIT__;
328         return 0;
329 }
330
331 static int _app_pause(void *data)
332 {
333         __WDUA_LOG_FUNC_ENTER__;
334         __WDUA_LOG_FUNC_EXIT__;
335         return 0;
336 }
337
338 static int _app_resume(void *data)
339 {
340         __WDUA_LOG_FUNC_ENTER__;
341         __WDUA_LOG_FUNC_EXIT__;
342         return 0;
343 }
344
345 static int _app_reset(bundle *b, void *data)
346 {
347         __WDUA_LOG_FUNC_ENTER__;
348
349         wfd_appdata_t *ad = wfd_get_appdata();
350         load_wifi_direct_ug(NULL, ad);
351
352         __WDUA_LOG_FUNC_EXIT__;
353         return 0;
354 }
355
356 int main(int argc, char *argv[])
357 {
358         wfd_appdata_t ad;
359         struct appcore_ops ops = {
360                 .create = _app_create,
361                 .terminate = _app_terminate,
362                 .pause = _app_pause,
363                 .resume = _app_resume,
364                 .reset = _app_reset,
365         };
366
367         memset(&ad, 0x0, sizeof(wfd_appdata_t));
368         ops.data = &ad;
369         g_wfd_ad = &ad;
370
371         return appcore_efl_main(PACKAGE, &argc, &argv, &ops);
372 }