b0d35d60505ebed8ee1883498e7b647bd10ce492
[apps/home/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.0 (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://www.tizenopensource.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
44 _ug_layout_cb(struct ui_gadget *ug, enum ug_mode mode, void *priv)
45 {
46         __WFD_APP_FUNC_ENTER__;
47
48     Evas_Object *base = NULL;
49     base = ug_get_layout(ug);
50
51     if (!base)
52     {
53         WFD_APP_LOG(WFD_APP_LOG_LOW,"ug_get_layout failed!");
54         ug_destroy(ug);
55         return;
56     }
57
58     switch (mode)
59     {
60         case UG_MODE_FULLVIEW:
61             evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
62             elm_win_resize_object_add(ug_get_window(), base);
63             evas_object_show(base);
64             break;
65         default:
66           break;
67     }
68 }
69
70 void
71 _ug_destroy_cb(struct ui_gadget *ug, void *priv)
72 {
73         __WFD_APP_FUNC_ENTER__;
74
75     // TODO: free all memory allocation
76
77     ug_destroy(ug);
78     elm_exit();
79 }
80
81 void ug_result_cb(struct ui_gadget *ug, bundle * result, void *priv)
82 {
83         __WFD_APP_FUNC_ENTER__;
84
85     // TODO: free all memory allocation
86
87 }
88
89 static int load_wifi_direct_ug(struct ui_gadget *parent_ug, void *data)
90 {
91         __WFD_APP_FUNC_ENTER__;
92     wfd_appdata_t *ugd = (wfd_appdata_t *)data;
93     bundle *param = 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, param, &wifi_direct_cbs);
105     if (ugd->wifi_direct_ug)
106         return TRUE;
107     else
108         return FALSE;
109 }
110
111
112 static void _win_del(void *data, Evas_Object * obj, void *event)
113 {
114     elm_exit();
115 }
116
117 static Evas_Object *_create_win(Evas_Object * parent, const char *name)
118 {
119     Evas_Object *eo;
120     int w, h;
121
122     eo = elm_win_add(parent, name, ELM_WIN_BASIC);
123     if (eo)
124     {
125         elm_win_title_set(eo, name);
126         elm_win_borderless_set(eo, EINA_TRUE);
127         elm_win_alpha_set(eo, EINA_TRUE);
128         evas_object_smart_callback_add(eo, "delete,request", _win_del, NULL);
129         ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
130         evas_object_resize(eo, w, h);
131         evas_object_show(eo);
132         //evas_object_raise(eo);
133     }
134
135     return eo;
136 }
137
138
139 static int _app_create(void *data)
140 {
141     __WFD_APP_FUNC_ENTER__;
142
143     wfd_appdata_t *ad = wfd_get_appdata();
144
145     if (data == NULL)
146     {
147         WFD_APP_LOG(WFD_APP_LOG_LOW, "Incorrect parameter\n");
148         return -1;
149     }
150
151     bindtextdomain(PACKAGE, LOCALEDIR);
152
153     ad->win = _create_win(NULL, PACKAGE);
154     elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
155
156     int r;
157
158     if (!ecore_x_display_get())
159         return -1;
160
161     r = appcore_set_i18n(PACKAGE, NULL);
162     if (r != 0)
163     {
164         WFD_APP_LOG(WFD_APP_LOG_LOW, "appcore_set_i18n error\n");
165         return -1;
166     }
167
168     __WFD_APP_FUNC_EXIT__;
169
170     return 0;
171 }
172
173 static int _app_terminate(void *data)
174 {
175         __WFD_APP_FUNC_ENTER__;
176
177         if (data == NULL)
178         {
179                 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Incorrect parameter\n");
180                 return -1;
181         }
182
183         wfd_appdata_t *ad = (wfd_appdata_t *) data;
184
185         if (ad->win)
186         {
187                 evas_object_del(ad->win);
188                 ad->win = NULL;
189         }
190
191         __WFD_APP_FUNC_EXIT__;
192
193         return 0;
194 }
195
196 static int _app_pause(void *data)
197 {
198     __WFD_APP_FUNC_ENTER__;
199     __WFD_APP_FUNC_EXIT__;
200     return 0;
201 }
202
203 static int _app_resume(void *data)
204 {
205     __WFD_APP_FUNC_ENTER__;
206     __WFD_APP_FUNC_EXIT__;
207     return 0;
208 }
209
210 static int _app_reset(bundle * b, void *data)
211 {
212     __WFD_APP_FUNC_ENTER__;
213
214     wfd_appdata_t *ad = wfd_get_appdata();
215
216     load_wifi_direct_ug(NULL, ad);
217
218     __WFD_APP_FUNC_EXIT__;
219     return 0;
220 }
221
222 int main(int argc, char *argv[])
223 {
224     wfd_appdata_t ad;
225     struct appcore_ops ops = {
226         .create = _app_create,
227         .terminate = _app_terminate,
228         .pause = _app_pause,
229         .resume = _app_resume,
230         .reset = _app_reset,
231     };
232
233     memset(&ad, 0x0, sizeof(wfd_appdata_t));
234     ops.data = &ad;
235     g_wfd_ad = &ad;
236
237     return appcore_efl_main(PACKAGE, &argc, &argv, &ops);
238 }