254a4e9c6b274fa408e65e2f444c3d51261d2936
[apps/home/ug-wifi-direct.git] / ug-wifidirect / src / wfd_ug_popup.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 #include <libintl.h>
21
22 #include <assert.h>
23 #include <glib.h>
24
25 #include <Elementary.h>
26 #include <vconf.h>
27 #include <ui-gadget-module.h>
28 #include <wifi-direct.h>
29
30 #include "wfd_ug.h"
31 #include "wfd_ug_view.h"
32 #include "wfd_client.h"
33
34 static void _wfd_ug_act_popup_wifi_ok_cb(void *data, Evas_Object *obj, void *event_info)
35 {
36     __FUNC_ENTER__;
37     struct ug_data *ugd = (struct ug_data*) data;
38
39     // TODO: Turn off WiFi
40     ugd->wfd_status = WFD_LINK_STATUS_DEACTIVATED;
41     wfd_wifi_off(ugd);
42
43      evas_object_del(ugd->act_popup);
44      ugd->act_popup = NULL;
45     __FUNC_EXIT__;
46 }
47
48 static void _wfd_ug_act_popup_wifi_cancel_cb(void *data, Evas_Object *obj, void *event_info)
49 {
50     __FUNC_ENTER__;
51     struct ug_data *ugd = (struct ug_data*) data;
52
53     // TODO: set genlist head item as "WiFi Direct"
54     ugd->head_text_mode = HEAD_TEXT_TYPE_DIRECT;
55     wfd_ug_view_refresh_glitem(ugd->head);
56
57      evas_object_del(ugd->act_popup);
58      ugd->act_popup = NULL;
59     __FUNC_EXIT__;
60 }
61
62 static void _wfd_ug_act_popup_disconnect_ok_cb(void *data, Evas_Object *obj, void *event_info)
63 {
64         __FUNC_ENTER__;
65
66         char *mac_addr = NULL;
67         struct ug_data *ugd = (struct ug_data*) data;
68
69         if (NULL == ugd) {
70                 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
71                 return;
72         }
73
74         if (ugd->gl_connected_peer_cnt < 1) {
75                 DBG(LOG_ERROR, "No connected peer\n");
76                 evas_object_del(ugd->act_popup);
77                 ugd->act_popup = NULL;
78                 return;
79         }
80
81         /* just one peer */
82         mac_addr = ugd->gl_connected_peers[0].mac_addr;
83         wfd_client_disconnect(mac_addr);
84         if (ugd->multi_connect_mode == WFD_MULTI_CONNECT_MODE_IN_PROGRESS) {
85                 wfd_stop_multi_connect(ugd);
86         }
87
88         evas_object_del(ugd->act_popup);
89         ugd->act_popup = NULL;
90
91         __FUNC_EXIT__;
92 }
93
94 static void _wfd_ug_act_popup_disconnect_cancel_cb(void *data, Evas_Object *obj, void *event_info)
95 {
96         __FUNC_ENTER__;
97
98         struct ug_data *ugd = (struct ug_data*) data;
99         if (NULL == ugd) {
100                 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
101                 return;
102         }
103
104         evas_object_del(ugd->act_popup);
105         ugd->act_popup = NULL;
106
107         __FUNC_EXIT__;
108 }
109
110 static void _wfd_ug_act_popup_disconnect_all_ok_cb(void *data, Evas_Object *obj, void *event_info)
111 {
112         __FUNC_ENTER__;
113
114         struct ug_data *ugd = (struct ug_data*) data;
115         if (NULL == ugd) {
116                 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
117                 return;
118         }
119
120         wfd_client_disconnect(NULL);
121         if (ugd->multi_connect_mode == WFD_MULTI_CONNECT_MODE_IN_PROGRESS) {
122                 wfd_stop_multi_connect(ugd);
123         }
124
125         evas_object_del(ugd->act_popup);
126         ugd->act_popup = NULL;
127
128         __FUNC_EXIT__;
129 }
130
131 static void _wfd_ug_act_popup_disconnect_all_cancel_cb(void *data, Evas_Object *obj, void *event_info)
132 {
133         __FUNC_ENTER__;
134
135         struct ug_data *ugd = (struct ug_data*) data;
136         if (NULL == ugd) {
137                 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
138                 return;
139         }
140
141         evas_object_del(ugd->act_popup);
142         ugd->act_popup = NULL;
143
144         __FUNC_EXIT__;
145 }
146
147 static void _wfd_ug_act_popup_scan_again_ok_cb(void *data, Evas_Object *obj, void *event_info)
148 {
149         __FUNC_ENTER__;
150
151         struct ug_data *ugd = (struct ug_data*) data;
152         if (NULL == ugd) {
153                 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
154                 return;
155         }
156
157         if (ugd->conn_wfd_item != NULL) {
158                 elm_object_item_del(ugd->conn_wfd_item);
159                 ugd->conn_wfd_item = NULL;
160         }
161
162         /* cancel the current connection */
163         wfd_client_disconnect(NULL);
164         if (ugd->multi_connect_mode == WFD_MULTI_CONNECT_MODE_IN_PROGRESS) {
165                 wfd_stop_multi_connect(ugd);
166         }
167
168         /* start discovery again */
169         wfd_client_start_discovery(ugd);
170         evas_object_del(ugd->act_popup);
171         ugd->act_popup = NULL;
172
173         __FUNC_EXIT__;
174 }
175
176 static void _wfd_ug_act_popup_scan_again_cancel_cb(void *data, Evas_Object *obj, void *event_info)
177 {
178         __FUNC_ENTER__;
179
180         struct ug_data *ugd = (struct ug_data*) data;
181
182         evas_object_del(ugd->act_popup);
183         ugd->act_popup = NULL;
184
185         __FUNC_EXIT__;
186 }
187
188 void wfd_ug_act_popup(void *data, const char *message, int popup_type)
189 {
190         __FUNC_ENTER__;
191         struct ug_data *ugd = (struct ug_data*) data;
192         Evas_Object *popup = NULL;
193         Evas_Object *btn1 = NULL, *btn2 = NULL;
194
195         popup = elm_popup_add(ugd->base);
196         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
197         elm_object_text_set(popup, message);
198
199         btn1 = elm_button_add(popup);
200         btn2 = elm_button_add(popup);
201         elm_object_style_set(btn1, "popup_button/default");
202         elm_object_style_set(btn2, "popup_button/default");
203
204         /* set the different text by type */
205         if (popup_type == POPUP_TYPE_WIFI_OFF) {
206                 elm_object_text_set(btn1, S_("IDS_COM_SK_YES"));
207                 elm_object_text_set(btn2, S_("IDS_COM_SK_NO"));
208         } else {
209                 elm_object_text_set(btn1, S_("IDS_COM_SK_OK"));
210                 elm_object_text_set(btn2, S_("IDS_COM_SK_CANCEL"));
211         }
212
213         elm_object_part_content_set(popup, "button1", btn1);
214         elm_object_part_content_set(popup, "button2", btn2);
215
216         /* set the different callback by type */
217         if (popup_type == POPUP_TYPE_WIFI_OFF) {
218                 evas_object_smart_callback_add(btn1, "clicked", _wfd_ug_act_popup_wifi_ok_cb, (void*) ugd);
219                 evas_object_smart_callback_add(btn2, "clicked", _wfd_ug_act_popup_wifi_cancel_cb, (void*) ugd);
220         } else if (popup_type == POP_TYPE_DISCONNECT) {
221                 //evas_object_smart_callback_add(btn1, "clicked", _wfd_ug_act_popup_disconnect_ok_cb, (void*) ugd);
222                 evas_object_smart_callback_add(btn1, "clicked", _wfd_ug_act_popup_disconnect_all_ok_cb, (void*) ugd);
223                 evas_object_smart_callback_add(btn2, "clicked", _wfd_ug_act_popup_disconnect_cancel_cb, (void*) ugd);
224         } else if (popup_type == POP_TYPE_DISCONNECT_ALL) {
225                 evas_object_smart_callback_add(btn1, "clicked", _wfd_ug_act_popup_disconnect_all_ok_cb, (void*) ugd);
226                 evas_object_smart_callback_add(btn2, "clicked", _wfd_ug_act_popup_disconnect_all_cancel_cb, (void*) ugd);
227         } else if (popup_type == POP_TYPE_SCAN_AGAIN) {
228                 evas_object_smart_callback_add(btn1, "clicked", _wfd_ug_act_popup_scan_again_ok_cb, (void*) ugd);
229                 evas_object_smart_callback_add(btn2, "clicked", _wfd_ug_act_popup_scan_again_cancel_cb, (void*) ugd);
230         }
231
232         evas_object_show(popup);
233         ugd->act_popup = popup;
234         __FUNC_EXIT__;
235 }
236
237 void wfg_ug_act_popup_remove(void *data)
238 {
239     __FUNC_ENTER__;
240     struct ug_data *ugd = (struct ug_data*) data;
241
242     if(ugd->act_popup)
243     {
244         evas_object_del(ugd->act_popup);
245         ugd->act_popup = NULL;
246     }
247     __FUNC_EXIT__;
248 }
249
250 static void _wfd_ug_terminate_popup_cb(void *data, Evas_Object *obj, void *event_info)
251 {
252     __FUNC_ENTER__;
253     struct ug_data *ugd = (struct ug_data*) data;
254
255     evas_object_del(ugd->warn_popup);
256     ugd->warn_popup = NULL;
257
258     wfd_ug_view_free_peers(ugd);
259
260     ug_destroy_me(ugd->ug);
261     __FUNC_EXIT__;
262 }
263
264 static void _wfd_ug_warn_popup_cb(void *data, Evas_Object *obj, void *event_info)
265 {
266     __FUNC_ENTER__;
267     struct ug_data *ugd = (struct ug_data*) data;
268
269     evas_object_del(ugd->warn_popup);
270     ugd->warn_popup = NULL;
271
272     __FUNC_EXIT__;
273 }
274
275 void wfd_ug_warn_popup(void *data, const char *message, int popup_type)
276 {
277     __FUNC_ENTER__;
278     struct ug_data *ugd = (struct ug_data*) data;
279     Evas_Object *popup = NULL;
280     Evas_Object *btn = NULL;
281
282     popup = elm_popup_add(ugd->base);
283     evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
284     elm_object_text_set(popup, message);
285
286     btn = elm_button_add(popup);
287     elm_object_style_set(btn, "popup_button/default");
288     elm_object_text_set(btn, S_("IDS_COM_SK_OK"));
289     elm_object_part_content_set(popup, "button1", btn);
290     if(popup_type == POPUP_TYPE_TERMINATE)
291         evas_object_smart_callback_add(btn, "clicked", _wfd_ug_terminate_popup_cb, (void*) ugd);
292     else
293         evas_object_smart_callback_add(btn, "clicked", _wfd_ug_warn_popup_cb, (void*) ugd);
294
295     evas_object_show(popup);
296     ugd->warn_popup = popup;
297     __FUNC_EXIT__;
298 }
299
300 void wfg_ug_warn_popup_remove(void *data)
301 {
302     __FUNC_ENTER__;
303     struct ug_data *ugd = (struct ug_data*) data;
304
305     if(ugd->warn_popup)
306     {
307         evas_object_del(ugd->warn_popup);
308         ugd->warn_popup = NULL;
309     }
310     __FUNC_EXIT__;
311 }
312
313
314 void wfd_ug_tickernoti_popup(char *msg)
315 {
316         __FUNC_ENTER__;
317
318         int ret = -1;
319         bundle *b = NULL;
320
321         b = bundle_create();
322         if (!b) {
323                 DBG(LOG_ERROR, "FAIL: bundle_create()\n");
324                 return;
325         }
326
327         /* tickernoti style */
328         ret = bundle_add(b, "0", "info");
329         if (ret) {
330                 DBG(LOG_ERROR, "Fail to add tickernoti style\n");
331                 bundle_free(b);
332                 return;
333         }
334
335         /* popup text */
336         ret = bundle_add(b, "1", msg);
337         if (ret) {
338                 DBG(LOG_ERROR, "Fail to add popup text\n");
339                 bundle_free(b);
340                 return;
341         }
342
343         /* orientation of tickernoti */
344         ret = bundle_add(b, "2", "1");
345         if (ret) {
346                 DBG(LOG_ERROR, "Fail to add orientation of tickernoti\n");
347                 bundle_free(b);
348                 return;
349         }
350
351         /* timeout(second) of tickernoti */
352         ret = bundle_add(b, "3", "3");
353         if (ret) {
354                 DBG(LOG_ERROR, "Fail to add timeout of tickernoti\n");
355                 bundle_free(b);
356                 return;
357         }
358
359         /* launch tickernoti */
360         ret = syspopup_launch(TICKERNOTI_SYSPOPUP, b);
361         if (ret) {
362                 DBG(LOG_ERROR, "Fail to launch syspopup\n");
363         }
364
365         bundle_free(b);
366         __FUNC_EXIT__;
367 }
368