Change the manifest and remove rule files
[apps/native/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.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 #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 /**
35  *      This function let the ug call it when click 'ok' button in hotspot action popup
36  *      @return   void
37  *      @param[in] data the pointer to the main data structure
38  *      @param[in] obj the pointer to the evas object
39  *      @param[in] event_info the pointer to the event information
40  */
41 static void _wfd_ug_act_popup_hotspot_ok_cb(void *data, Evas_Object *obj, void *event_info)
42 {
43         __WDUG_LOG_FUNC_ENTER__;
44         int result = -1;
45         struct ug_data *ugd = (struct ug_data *) data;
46
47         result = wfd_mobile_ap_off(ugd);
48         if (0 == result) {
49                 /* refresh the header */
50                 ugd->head_text_mode = HEAD_TEXT_TYPE_ACTIVATING;
51                 wfd_ug_view_refresh_glitem(ugd->head);
52
53                 /* while activating/deactivating, disable the buttons */
54                 if (ugd->scan_btn) {
55                         wfd_ug_view_refresh_button(ugd->scan_btn, _("IDS_WFD_BUTTON_SCAN"), FALSE);
56                 }
57
58                 if (ugd->multi_scan_btn) {
59                         wfd_ug_view_refresh_button(ugd->multi_scan_btn, _("IDS_WFD_BUTTON_SCAN"), FALSE);
60                 }
61
62                 if (ugd->back_btn) {
63                         elm_object_disabled_set(ugd->back_btn, TRUE);
64                 }
65         }
66
67         evas_object_del(ugd->act_popup);
68         ugd->act_popup = NULL;
69         __WDUG_LOG_FUNC_EXIT__;
70 }
71
72 /**
73  *      This function let the ug call it when click 'cancel' button in hotspot action popup
74  *      @return   void
75  *      @param[in] data the pointer to the main data structure
76  *      @param[in] obj the pointer to the evas object
77  *      @param[in] event_info the pointer to the event information
78  */
79 static void _wfd_ug_act_popup_hotspot_cancel_cb(void *data, Evas_Object *obj, void *event_info)
80 {
81         __WDUG_LOG_FUNC_ENTER__;
82         struct ug_data *ugd = (struct ug_data *) data;
83
84         ugd->head_text_mode = HEAD_TEXT_TYPE_DIRECT;
85         wfd_ug_view_refresh_glitem(ugd->head);
86
87         evas_object_del(ugd->act_popup);
88         ugd->act_popup = NULL;
89         __WDUG_LOG_FUNC_EXIT__;
90 }
91
92 /**
93  *      This function let the ug call it when click 'ok' button in wifi action popup
94  *      @return   void
95  *      @param[in] data the pointer to the main data structure
96  *      @param[in] obj the pointer to the evas object
97  *      @param[in] event_info the pointer to the event information
98  */
99 static void _wfd_ug_act_popup_wifi_ok_cb(void *data, Evas_Object *obj, void *event_info)
100 {
101         __WDUG_LOG_FUNC_ENTER__;
102         int result = -1;
103         struct ug_data *ugd = (struct ug_data *) data;
104
105         result = wfd_wifi_off(ugd);
106         if (0 == result) {
107                 /* refresh the header */
108                 ugd->head_text_mode = HEAD_TEXT_TYPE_ACTIVATING;
109                 wfd_ug_view_refresh_glitem(ugd->head);
110
111                 /* while activating/deactivating, disable the buttons */
112                 if (ugd->scan_btn) {
113                         wfd_ug_view_refresh_button(ugd->scan_btn, _("IDS_WFD_BUTTON_SCAN"), FALSE);
114                 }
115
116                 if (ugd->multi_scan_btn) {
117                         wfd_ug_view_refresh_button(ugd->multi_scan_btn, _("IDS_WFD_BUTTON_SCAN"), FALSE);
118                 }
119
120                 if (ugd->back_btn) {
121                         elm_object_disabled_set(ugd->back_btn, TRUE);
122                 }
123         }
124
125         evas_object_del(ugd->act_popup);
126         ugd->act_popup = NULL;
127         __WDUG_LOG_FUNC_EXIT__;
128 }
129
130 /**
131  *      This function let the ug call it when click 'cancel' button in wifi action popup
132  *      @return   void
133  *      @param[in] data the pointer to the main data structure
134  *      @param[in] obj the pointer to the evas object
135  *      @param[in] event_info the pointer to the event information
136  */
137 static void _wfd_ug_act_popup_wifi_cancel_cb(void *data, Evas_Object *obj, void *event_info)
138 {
139         __WDUG_LOG_FUNC_ENTER__;
140         struct ug_data *ugd = (struct ug_data *) data;
141
142         ugd->head_text_mode = HEAD_TEXT_TYPE_DIRECT;
143         wfd_ug_view_refresh_glitem(ugd->head);
144
145         evas_object_del(ugd->act_popup);
146         ugd->act_popup = NULL;
147         __WDUG_LOG_FUNC_EXIT__;
148 }
149
150 /**
151  *      This function let the ug call it when click 'ok' button in disconnect all popup
152  *      @return   void
153  *      @param[in] data the pointer to the main data structure
154  *      @param[in] obj the pointer to the evas object
155  *      @param[in] event_info the pointer to the event information
156  */
157 static void _wfd_ug_act_popup_disconnect_all_ok_cb(void *data, Evas_Object *obj, void *event_info)
158 {
159         __WDUG_LOG_FUNC_ENTER__;
160         int i = 0;
161         struct ug_data *ugd = (struct ug_data *) data;
162         if (NULL == ugd) {
163                 WDUG_LOGE("Incorrect parameter(NULL)\n");
164                 return;
165         }
166
167         wfd_client_disconnect(NULL);
168
169         if (ugd->multi_connect_mode != WFD_MULTI_CONNECT_MODE_NONE) {
170                 wfd_free_multi_selected_peers(ugd);
171         } else {
172                 /* update the connecting icon */
173                 for (i = 0; i < ugd->raw_discovered_peer_cnt; i++) {
174                         ugd->raw_discovered_peers[i].conn_status = PEER_CONN_STATUS_DISCONNECTED;
175                         wfd_ug_view_refresh_glitem(ugd->raw_discovered_peers[i].gl_item);
176                 }
177         }
178
179         evas_object_del(ugd->act_popup);
180         ugd->act_popup = NULL;
181
182         __WDUG_LOG_FUNC_EXIT__;
183 }
184
185 /**
186  *      This function let the ug call it when click 'cancel' button in disconnect all popup
187  *      @return   void
188  *      @param[in] data the pointer to the main data structure
189  *      @param[in] obj the pointer to the evas object
190  *      @param[in] event_info the pointer to the event information
191  */
192 static void _wfd_ug_act_popup_disconnect_all_cancel_cb(void *data, Evas_Object *obj, void *event_info)
193 {
194         __WDUG_LOG_FUNC_ENTER__;
195
196         struct ug_data *ugd = (struct ug_data *) data;
197         if (NULL == ugd) {
198                 WDUG_LOGE("Incorrect parameter(NULL)\n");
199                 return;
200         }
201
202         evas_object_del(ugd->act_popup);
203         ugd->act_popup = NULL;
204
205         __WDUG_LOG_FUNC_EXIT__;
206 }
207
208 /**
209  *      This function let the ug create a action popup
210  *      @return   void
211  *      @param[in] data the pointer to the main data structure
212  *      @param[in] message the pointer to the text of popup
213  *      @param[in] popup_type the message type
214  */
215 void wfd_ug_act_popup(void *data, const char *message, int popup_type)
216 {
217         __WDUG_LOG_FUNC_ENTER__;
218         struct ug_data *ugd = (struct ug_data *) data;
219         Evas_Object *popup = NULL;
220         Evas_Object *btn1 = NULL, *btn2 = NULL;
221
222         popup = elm_popup_add(ugd->base);
223         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
224         elm_object_text_set(popup, message);
225
226         btn1 = elm_button_add(popup);
227         btn2 = elm_button_add(popup);
228         elm_object_style_set(btn1, "popup_button/default");
229         elm_object_style_set(btn2, "popup_button/default");
230
231         /* set the different text by type */
232         if (popup_type == POPUP_TYPE_WIFI_OFF || popup_type == POPUP_TYPE_HOTSPOT_OFF) {
233                 elm_object_text_set(btn1, S_("IDS_COM_SK_YES"));
234                 elm_object_text_set(btn2, S_("IDS_COM_SK_NO"));
235         } else {
236                 elm_object_text_set(btn1, S_("IDS_COM_SK_OK"));
237                 elm_object_text_set(btn2, S_("IDS_COM_SK_CANCEL"));
238         }
239
240         elm_object_part_content_set(popup, "button1", btn1);
241         elm_object_part_content_set(popup, "button2", btn2);
242
243         /* set the different callback by type */
244         if (popup_type == POPUP_TYPE_WIFI_OFF) {
245                 evas_object_smart_callback_add(btn1, "clicked", _wfd_ug_act_popup_wifi_ok_cb, (void *)ugd);
246                 evas_object_smart_callback_add(btn2, "clicked", _wfd_ug_act_popup_wifi_cancel_cb, (void *)ugd);
247         } else if (popup_type == POPUP_TYPE_HOTSPOT_OFF) {
248                 evas_object_smart_callback_add(btn1, "clicked", _wfd_ug_act_popup_hotspot_ok_cb, (void *)ugd);
249                 evas_object_smart_callback_add(btn2, "clicked", _wfd_ug_act_popup_hotspot_cancel_cb, (void *)ugd);
250         } else if (popup_type == POP_TYPE_DISCONNECT ||
251                 popup_type == POP_TYPE_DISCONNECT_ALL ||
252                 popup_type == POP_TYPE_SCAN_AGAIN) {
253                 evas_object_smart_callback_add(btn1, "clicked", _wfd_ug_act_popup_disconnect_all_ok_cb, (void *)ugd);
254                 evas_object_smart_callback_add(btn2, "clicked", _wfd_ug_act_popup_disconnect_all_cancel_cb, (void *)ugd);
255         }
256
257         evas_object_show(popup);
258         ugd->act_popup = popup;
259         __WDUG_LOG_FUNC_EXIT__;
260 }
261
262 /**
263  *      This function let the ug remove the action popup
264  *      @return   void
265  *      @param[in] data the pointer to the main data structure
266  */
267 void wfg_ug_act_popup_remove(void *data)
268 {
269         __WDUG_LOG_FUNC_ENTER__;
270         struct ug_data *ugd = (struct ug_data *) data;
271
272         if (ugd->act_popup) {
273                 evas_object_del(ugd->act_popup);
274                 ugd->act_popup = NULL;
275         }
276         __WDUG_LOG_FUNC_EXIT__;
277 }
278
279 /**
280  *      This function let the ug call it when click 'ok' button in warning popup of terminated problem
281  *      @return   void
282  *      @param[in] data the pointer to the main data structure
283  *      @param[in] obj the pointer to the evas object
284  *      @param[in] event_info the pointer to the event information
285  */
286 static void _wfd_ug_terminate_popup_cb(void *data, Evas_Object *obj, void *event_info)
287 {
288         __WDUG_LOG_FUNC_ENTER__;
289         struct ug_data *ugd = (struct ug_data *) data;
290
291         evas_object_del(ugd->warn_popup);
292         ugd->warn_popup = NULL;
293
294         wfd_ug_view_free_peers(ugd);
295
296         ug_destroy_me(ugd->ug);
297         __WDUG_LOG_FUNC_EXIT__;
298 }
299
300 /**
301  *      This function let the ug call it when click 'ok' button in warning popup of turning off WFD automatically
302  *      @return   void
303  *      @param[in] data the pointer to the main data structure
304  *      @param[in] obj the pointer to the evas object
305  *      @param[in] event_info the pointer to the event information
306  */
307 static void _wfd_ug_automatic_turn_off_popup_cb(void *data, Evas_Object *obj, void *event_info)
308 {
309         __WDUG_LOG_FUNC_ENTER__;
310         struct ug_data *ugd = (struct ug_data *) data;
311
312         evas_object_del(ugd->warn_popup);
313         ugd->warn_popup = NULL;
314
315         /* turn off the Wi-Fi Direct */
316         wfd_client_switch_off(ugd);
317
318         /* antomaticlly turn on tethering mode */
319         if (TRUE == ugd->is_hotspot_off) {
320                 wfd_mobile_ap_on(ugd);
321         }
322
323         __WDUG_LOG_FUNC_EXIT__;
324 }
325
326 /**
327  *      This function let the ug call it when click 'ok' button in warning popup
328  *      @return   void
329  *      @param[in] data the pointer to the main data structure
330  *      @param[in] obj the pointer to the evas object
331  *      @param[in] event_info the pointer to the event information
332  */
333 static void _wfd_ug_warn_popup_cb(void *data, Evas_Object *obj, void *event_info)
334 {
335         __WDUG_LOG_FUNC_ENTER__;
336         struct ug_data *ugd = (struct ug_data *) data;
337
338         evas_object_del(ugd->warn_popup);
339         ugd->warn_popup = NULL;
340
341         __WDUG_LOG_FUNC_EXIT__;
342 }
343
344 /**
345  *      This function let the ug create a warning popup
346  *      @return   void
347  *      @param[in] data the pointer to the main data structure
348  *      @param[in] message the pointer to the text of popup
349  *      @param[in] popup_type the message type
350  */
351 void wfd_ug_warn_popup(void *data, const char *message, int popup_type)
352 {
353         __WDUG_LOG_FUNC_ENTER__;
354         struct ug_data *ugd = (struct ug_data *) data;
355         Evas_Object *popup = NULL;
356         Evas_Object *btn = NULL;
357
358         popup = elm_popup_add(ugd->base);
359         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
360         elm_object_part_text_set(popup, "title,text", _("IDS_WFD_POP_TITILE_CONNECTION"));
361         elm_object_text_set(popup, message);
362
363         btn = elm_button_add(popup);
364         elm_object_style_set(btn, "popup_button/default");
365         elm_object_text_set(btn, S_("IDS_COM_SK_OK"));
366         elm_object_part_content_set(popup, "button1", btn);
367         if (popup_type == POPUP_TYPE_TERMINATE) {
368                 evas_object_smart_callback_add(btn, "clicked", _wfd_ug_terminate_popup_cb, (void *)ugd);
369         } else if (popup_type == POP_TYPE_AUTOMATIC_TURN_OFF) {
370                 evas_object_smart_callback_add(btn, "clicked", _wfd_ug_automatic_turn_off_popup_cb, (void *)ugd);
371         } else {
372                 evas_object_smart_callback_add(btn, "clicked", _wfd_ug_warn_popup_cb, (void *)ugd);
373         }
374
375         evas_object_show(popup);
376         ugd->warn_popup = popup;
377         __WDUG_LOG_FUNC_EXIT__;
378 }
379