[ug-wifi-direct]Remove X dependencies
[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.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 #include <glib.h>
22
23 #include <Elementary.h>
24 #include <vconf.h>
25 #include <ui-gadget-module.h>
26 #include <wifi-direct.h>
27 #include <efl_extension.h>
28
29 #include "wfd_ug.h"
30 #include "wfd_ug_view.h"
31 #include "wfd_client.h"
32
33 #define KEY_BACK "XF86Back"
34
35 static void delete_popup(void *data)
36 {
37         __FUNC_ENTER__;
38         struct ug_data *ugd = (struct ug_data *) data;
39         if (NULL == ugd) {
40                 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
41                 return;
42         }
43
44         evas_object_del(ugd->act_popup);
45         ugd->act_popup = NULL;
46         __FUNC_EXIT__;
47 }
48
49 static void pushbutton_accept_connect_cb(void *data, Evas_Object * obj,
50                 void *event_info)
51 {
52         __FUNC_ENTER__;
53
54         struct ug_data *ugd = (struct ug_data *) data;
55         if (NULL == ugd) {
56                 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
57                 return;
58         }
59         int result = -1;
60         result = wifi_direct_accept_connection(ugd->mac_addr_req);
61         if (result != WIFI_DIRECT_ERROR_NONE) {
62                 DBG(LOG_INFO,"Failed to connect");
63         }
64         delete_popup(ugd);
65
66         __FUNC_EXIT__;
67 }
68
69 static void pushbutton_reject_connect_cb(void *data, Evas_Object * obj,
70                 void *event_info)
71 {
72         __FUNC_ENTER__;
73
74         struct ug_data *ugd = (struct ug_data *) data;
75         if (NULL == ugd) {
76                 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
77                 return;
78         }
79         int result = -1;
80         if (ugd->mac_addr_req[0] != '\0') {
81                 result = wifi_direct_reject_connection(ugd->mac_addr_req);
82                 if (result != WIFI_DIRECT_ERROR_NONE)
83                         DBG(LOG_INFO,"Failed to reject connection");
84         } else {
85                 DBG(LOG_INFO,"No Peer mac address");
86         }
87         delete_popup(ugd);
88
89         __FUNC_EXIT__;
90 }
91 #ifndef MODEL_BUILD_FEATURE_WLAN_CONCURRENT_MODE
92 static void _mouseup_wifi_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
93 {
94         Evas_Event_Mouse_Up *ev = event_info;
95         if (ev->button == 3) {
96                 struct ug_data *ugd = (struct ug_data *) data;
97
98                 evas_object_del(ugd->act_popup);
99                 ugd->act_popup = NULL;
100         }
101 }
102
103 static void _keydown_wifi_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
104 {
105
106         Evas_Event_Key_Down *ev = event_info;
107         if (!strcmp(ev->keyname, KEY_BACK)) {
108                 struct ug_data *ugd = (struct ug_data *) data;
109
110                 ugd->head_text_mode = HEAD_TEXT_TYPE_DIRECT;
111                 wfd_ug_view_refresh_glitem(ugd->head);
112
113                 evas_object_del(ugd->act_popup);
114                 ugd->act_popup = NULL;
115         }
116 }
117 #endif /* MODEL_BUILD_FEATURE_WLAN_CONCURRENT_MODE */
118
119
120 static void _mouseup_hotspot_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
121 {
122         Evas_Event_Mouse_Up *ev = event_info;
123         if (ev->button == 3) {
124                 struct ug_data *ugd = (struct ug_data *) data;
125
126 #ifdef WFD_ON_OFF_GENLIST
127                 wfd_ug_refresh_on_off_check(ugd);
128 #endif
129                 evas_object_del(ugd->act_popup);
130                 ugd->act_popup = NULL;
131         }
132 }
133 static void _keydown_hotspot_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
134 {
135         Evas_Event_Key_Down *ev = event_info;
136         if (!strcmp(ev->keyname, KEY_BACK)) {
137                 struct ug_data *ugd = (struct ug_data *) data;
138
139                 ugd->head_text_mode = HEAD_TEXT_TYPE_DIRECT;
140                 wfd_ug_view_refresh_glitem(ugd->head);
141
142                 evas_object_del(ugd->act_popup);
143                 ugd->act_popup = NULL;
144         }
145 }
146
147 static void _mouseup_disconnect_all_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
148 {
149         Evas_Event_Mouse_Up *ev = event_info;
150         if (ev->button == 3) {
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                 evas_object_del(ugd->act_popup);
158                 ugd->act_popup = NULL;
159         }
160 }
161
162 /*static void _keydown_disconnect_all_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
163 {
164         Evas_Event_Key_Down *ev = event_info;
165         if (!strcmp(ev->keyname, KEY_BACK)) {
166                 struct ug_data *ugd = (struct ug_data *) data;
167                 if (NULL == ugd) {
168                         DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
169                         return;
170                 }
171
172                 evas_object_del(ugd->act_popup);
173                 ugd->act_popup = NULL;
174         }
175 }*/
176
177
178 /**
179  *      This function let the ug call it when click 'ok' button in hotspot action popup
180  *      @return   void
181  *      @param[in] data the pointer to the main data structure
182  *      @param[in] obj the pointer to the evas object
183  *      @param[in] event_info the pointer to the event information
184  */
185 static void _wfd_ug_act_popup_hotspot_ok_cb(void *data, Evas_Object *obj, void *event_info)
186 {
187         __FUNC_ENTER__;
188         int result = -1;
189         struct ug_data *ugd = (struct ug_data *) data;
190
191         result = wfd_mobile_ap_off(ugd);
192         if (0 == result) {
193 #ifdef WFD_ON_OFF_GENLIST
194                 /* refresh the header */
195                 if (ugd->on_off_check) {
196                         elm_check_state_set(ugd->on_off_check, TRUE);
197                         elm_object_disabled_set(ugd->on_off_check, TRUE);
198                 }
199 #endif
200
201                 /* while activating/deactivating, disable the buttons */
202                 if (ugd->scan_toolbar) {
203                         wfd_ug_view_refresh_button(ugd->scan_toolbar, "IDS_WIFI_SK4_SCAN", FALSE);
204                 }
205
206                 if (ugd->multiconn_scan_stop_btn) {
207                         wfd_ug_view_refresh_button(ugd->multiconn_scan_stop_btn, "IDS_WIFI_SK4_SCAN", FALSE);
208                 }
209
210                 if (ugd->back_btn) {
211                         elm_object_disabled_set(ugd->back_btn, TRUE);
212                 }
213                 ugd->is_hotspot_locally_disabled = TRUE;
214         }
215
216         evas_object_del(ugd->act_popup);
217         ugd->act_popup = NULL;
218         __FUNC_EXIT__;
219 }
220
221 /**
222  *      This function let the ug call it when click 'cancel' button in hotspot action popup
223  *      @return   void
224  *      @param[in] data the pointer to the main data structure
225  *      @param[in] obj the pointer to the evas object
226  *      @param[in] event_info the pointer to the event information
227  */
228 static void _wfd_ug_act_popup_hotspot_cancel_cb(void *data, Evas_Object *obj, void *event_info)
229 {
230         __FUNC_ENTER__;
231         struct ug_data *ugd = (struct ug_data *) data;
232
233 #ifdef WFD_ON_OFF_GENLIST
234         wfd_ug_refresh_on_off_check(ugd);
235 #endif
236
237         wfd_client_destroy_tethering(ugd);
238
239         evas_object_del(ugd->act_popup);
240         ugd->act_popup = NULL;
241         __FUNC_EXIT__;
242 }
243
244 #ifndef MODEL_BUILD_FEATURE_WLAN_CONCURRENT_MODE
245 /**
246  *      This function let the ug call it when click 'ok' button in wifi action popup
247  *      @return   void
248  *      @param[in] data the pointer to the main data structure
249  *      @param[in] obj the pointer to the evas object
250  *      @param[in] event_info the pointer to the event information
251  */
252 static void _wfd_ug_act_popup_wifi_ok_cb(void *data, Evas_Object *obj, void *event_info)
253 {
254         __FUNC_ENTER__;
255         int result = -1;
256         struct ug_data *ugd = (struct ug_data *) data;
257
258         result = wfd_wifi_off(ugd);
259         if (0 == result) {
260 #ifdef WFD_ON_OFF_GENLIST
261                 /* refresh the header */
262                 if (ugd->on_off_check) {
263                         elm_check_state_set(ugd->on_off_check, TRUE);
264                         elm_object_disabled_set(ugd->on_off_check, TRUE);
265                 }
266 #endif
267                 /* while activating/deactivating, disable the buttons */
268                 if (ugd->scan_toolbar) {
269                         wfd_ug_view_refresh_button(ugd->scan_toolbar, "IDS_WIFI_SK4_SCAN", FALSE);
270                 }
271
272                 if (ugd->multiconn_scan_stop_btn) {
273                         wfd_ug_view_refresh_button(ugd->multiconn_scan_stop_btn, "IDS_WIFI_SK4_SCAN", FALSE);
274                 }
275
276                 if (ugd->back_btn) {
277                         elm_object_disabled_set(ugd->back_btn, TRUE);
278                 }
279         }
280
281         evas_object_del(ugd->act_popup);
282         ugd->act_popup = NULL;
283         __FUNC_EXIT__;
284 }
285
286 /**
287  *      This function let the ug call it when click 'cancel' button in wifi action popup
288  *      @return   void
289  *      @param[in] data the pointer to the main data structure
290  *      @param[in] obj the pointer to the evas object
291  *      @param[in] event_info the pointer to the event information
292  */
293 static void _wfd_ug_act_popup_wifi_cancel_cb(void *data, Evas_Object *obj, void *event_info)
294 {
295         __FUNC_ENTER__;
296         struct ug_data *ugd = (struct ug_data *) data;
297
298 #ifdef WFD_ON_OFF_GENLIST
299         wfd_ug_refresh_on_off_check(ugd);
300 #endif
301         evas_object_del(ugd->act_popup);
302         ugd->act_popup = NULL;
303         __FUNC_EXIT__;
304 }
305
306 #endif /* MODEL_BUILD_FEATURE_WLAN_CONCURRENT_MODE */
307
308 gboolean _wfd_disconnect_idle_cb(gpointer user_data)
309 {
310         __FUNC_ENTER__;
311         GList *iterator = NULL;
312
313         struct ug_data *ugd = (struct ug_data *) user_data;
314         if (NULL == ugd) {
315                 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
316                 return FALSE;
317         }
318         Evas_Object *content;
319         content = elm_object_part_content_unset(ugd->layout, "button.next");
320         WFD_IF_DEL_OBJ(content);
321
322         wfd_ug_view_init_genlist(ugd, true);
323
324         if (0 != wfd_client_disconnect(NULL)) {
325                 DBG(LOG_ERROR, "Disconnection Failed !!!\n");
326         }
327
328         ugd->wfd_discovery_status = WIFI_DIRECT_DISCOVERY_SOCIAL_CHANNEL_START;
329         discover_cb(WIFI_DIRECT_ERROR_NONE, WIFI_DIRECT_DISCOVERY_STARTED, ugd);
330
331         if (ugd->multi_connect_mode != WFD_MULTI_CONNECT_MODE_NONE) {
332                 wfd_free_multi_selected_peers(ugd);
333         } else {
334                 /* update the connecting icon */
335                 for (iterator = ugd->raw_discovered_peer_list; iterator; iterator = iterator->next) {
336                         ((device_type_s *)iterator->data)->conn_status = PEER_CONN_STATUS_DISCONNECTED;
337                         wfd_ug_view_refresh_glitem(((device_type_s *)iterator->data)->gl_item);
338                 }
339         }
340
341         __FUNC_EXIT__;
342         return FALSE;
343 }
344
345 gboolean _wfd_cancel_connect_idle_cb(gpointer user_data)
346 {
347         __FUNC_ENTER__;
348
349         int res;
350         GList *iterator = NULL;
351         struct ug_data *ugd = (struct ug_data *) user_data;
352         if (NULL == ugd || NULL == ugd->mac_addr_connecting) {
353                 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
354                 return FALSE;
355         }
356
357         res = wifi_direct_cancel_connection(ugd->mac_addr_connecting);
358         if (res != WIFI_DIRECT_ERROR_NONE) {
359                 DBG(LOG_ERROR, "Failed wifi_direct_cancel_connection() [%d]\n", res);
360                 return FALSE;
361         }
362
363         ugd->mac_addr_connecting = NULL;
364         if (ugd->multi_connect_mode != WFD_MULTI_CONNECT_MODE_NONE) {
365                 if (ugd->raw_connected_peer_cnt > 0) {
366                         res = wifi_direct_disconnect_all();
367                         if (res != WIFI_DIRECT_ERROR_NONE) {
368                                 DBG(LOG_ERROR, "Failed wifi_direct_disconnect_all() [%d]\n", res);
369                                 return FALSE;
370                         }
371                 }
372
373                 wfd_free_multi_selected_peers(ugd);
374                 wfd_ug_view_init_genlist(ugd, true);
375         } else {
376                 /* update the connecting icon */
377                 for (iterator = ugd->raw_discovered_peer_list; iterator; iterator = iterator->next) {
378                         ((device_type_s *)iterator->data)->conn_status = PEER_CONN_STATUS_DISCONNECTED;
379                 }
380                 wfd_ug_view_init_genlist(ugd, false);
381         }
382
383         __FUNC_EXIT__;
384         return FALSE;
385 }
386
387 /**
388  *      This function let the ug call it when click 'ok' button in cancel connection popup
389  *      @return   void
390  *      @param[in] data the pointer to the main data structure
391  *      @param[in] obj the pointer to the evas object
392  *      @param[in] event_info the pointer to the event information
393  */
394 static void _wfd_ug_act_popup_cancel_connect_ok_cb(void *data, Evas_Object *obj, void *event_info)
395 {
396         __FUNC_ENTER__;
397
398         struct ug_data *ugd = (struct ug_data *) data;
399         if (NULL == ugd) {
400                 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
401                 return;
402         }
403
404         evas_object_del(ugd->act_popup);
405         ugd->act_popup = NULL;
406
407         g_idle_add(_wfd_cancel_connect_idle_cb, ugd);
408
409         __FUNC_EXIT__;
410 }
411
412 /**
413  *      This function let the ug call it when click 'ok' button in disconnect all popup
414  *      @return   void
415  *      @param[in] data the pointer to the main data structure
416  *      @param[in] obj the pointer to the evas object
417  *      @param[in] event_info the pointer to the event information
418  */
419 static void _wfd_ug_act_popup_disconnect_all_ok_cb(void *data, Evas_Object *obj, void *event_info)
420 {
421         __FUNC_ENTER__;
422
423         struct ug_data *ugd = (struct ug_data *) data;
424         if (NULL == ugd) {
425                 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
426                 return;
427         }
428
429         evas_object_del(ugd->act_popup);
430         ugd->act_popup = NULL;
431
432         g_idle_add(_wfd_disconnect_idle_cb, ugd);
433
434         __FUNC_EXIT__;
435 }
436
437 /**
438  *      This function let the ug call it when click 'cancel' button in disconnect all popup
439  *      @return   void
440  *      @param[in] data the pointer to the main data structure
441  *      @param[in] obj the pointer to the evas object
442  *      @param[in] event_info the pointer to the event information
443  */
444 static void _wfd_ug_act_popup_cancel_cb(void *data, Evas_Object *obj, void *event_info)
445 {
446         __FUNC_ENTER__;
447
448         struct ug_data *ugd = (struct ug_data *) data;
449         if (NULL == ugd) {
450                 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
451                 return;
452         }
453
454         evas_object_del(ugd->act_popup);
455         ugd->act_popup = NULL;
456
457         __FUNC_EXIT__;
458 }
459
460 void act_popup_language_changed(void *data, Evas_Object *obj, void *event_info)
461 {
462         __FUNC_ENTER__;
463
464         int popup_type = (int)data;
465         Evas_Object *btn1 = NULL;
466         Evas_Object *btn2 = NULL;
467         struct ug_data *ugd = wfd_get_ug_data();
468
469         if (!ugd || !ugd->act_popup) {
470                 DBG(LOG_ERROR, "NULL parameters.\n");
471                 return;
472         }
473
474         btn1 = elm_object_part_content_get(ugd->act_popup, "button1");
475         btn2 = elm_object_part_content_get(ugd->act_popup, "button2");
476         elm_object_domain_translatable_text_set(btn1, PACKAGE,
477                         "IDS_BR_SK_CANCEL");
478         elm_object_domain_translatable_text_set(btn2, PACKAGE,
479                         "IDS_BR_SK_OK");
480
481         switch(popup_type) {
482
483         case POPUP_TYPE_HOTSPOT_OFF:
484                 elm_object_domain_translatable_text_set(btn1, PACKAGE,
485                                 "IDS_BR_SK_NO");
486                 elm_object_domain_translatable_text_set(btn2, PACKAGE,
487                                 "IDS_BR_SK_YES");
488                 elm_object_domain_translatable_text_set(ugd->act_popup, PACKAGE,
489                                 "IDS_WIFI_BODY_USING_WI_FI_DIRECT_WILL_DISCONNECT_CURRENT_WI_FI_TETHERING_CONTINUE_Q");
490                 break;
491
492         case POP_TYPE_DISCONNECT:
493                 elm_object_domain_translatable_text_set(ugd->act_popup, PACKAGE,
494                                 "IDS_WIFI_POP_CURRENT_CONNECTION_WILL_BE_DISCONNECTED_CONTINUE_Q");
495                 break;
496         case POP_TYPE_SCAN_AGAIN:
497                 elm_object_domain_translatable_text_set(ugd->act_popup, PACKAGE,
498                                 "IDS_WIFI_BODY_CURRENT_CONNECTION_WILL_BE_DISCONNECTED_SO_THAT_SCANNING_CAN_START_CONTINUE_Q");
499                 break;
500         case POP_TYPE_CANCEL_CONNECT:
501                 elm_object_domain_translatable_text_set(ugd->act_popup, PACKAGE,
502                                 "IDS_WIFI_POP_THIS_WI_FI_DIRECT_CONNECTION_WILL_BE_CANCELLED");
503                 break;
504         case POP_TYPE_ACCEPT_CONNECTION:
505                 elm_object_domain_translatable_text_set(ugd->act_popup, PACKAGE,
506                                 "IDS_WIFI_BODY_PS_IS_REQUESTING_A_WI_FI_DIRECT_CONNECTION_ALLOW_Q");
507                 break;
508         default:
509                 break;
510         }
511
512         __FUNC_EXIT__;
513 }
514
515 /**
516  *      This function let the ug create a action popup
517  *      @return   void
518  *      @param[in] data the pointer to the main data structure
519  *      @param[in] message the pointer to the text of popup
520  *      @param[in] popup_type the message type
521  */
522 void wfd_ug_act_popup(void *data, const char *message, int popup_type)
523 {
524         __FUNC_ENTER__;
525         struct ug_data *ugd = (struct ug_data *) data;
526         Evas_Object *popup = NULL;
527         Evas_Object *btn1 = NULL, *btn2 = NULL;
528
529         WFD_IF_DEL_OBJ(ugd->act_popup);
530
531         popup = elm_popup_add(ugd->base);
532         elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
533         eext_object_event_callback_add(popup, EA_CALLBACK_BACK, eext_popup_back_cb, NULL);
534         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
535         elm_object_domain_translatable_part_text_set(popup, "title,text",
536                          PACKAGE, _("IDS_WIFI_HEADER_WI_FI_DIRECT_CONNECTION_ABB"));
537         elm_object_domain_translatable_text_set(popup, PACKAGE, message);
538         evas_object_smart_callback_add(popup, "language,changed", act_popup_language_changed, (void *)popup_type);
539
540         btn1 = elm_button_add(popup);
541         btn2 = elm_button_add(popup);
542         elm_object_style_set(btn1, "popup");
543         elm_object_style_set(btn2, "popup");
544
545         /* set the different text by type */
546         if (
547 #ifndef MODEL_BUILD_FEATURE_WLAN_CONCURRENT_MODE
548                 popup_type == POPUP_TYPE_WIFI_OFF ||
549 #endif
550
551                 popup_type == POPUP_TYPE_HOTSPOT_OFF ||
552
553                 FALSE) {
554                 elm_object_domain_translatable_part_text_set(popup, "title,text",
555                                  PACKAGE, "IDS_WIFI_BODY_WI_FI_DIRECT_ABB");
556                 elm_object_domain_translatable_text_set(btn1, PACKAGE,
557                                 "IDS_BR_SK_CANCEL");
558                 elm_object_domain_translatable_text_set(btn2, PACKAGE,
559                                 "IDS_ST_BUTTON_ENABLE");
560         } else if (popup_type == POP_TYPE_CANCEL_CONNECT) {
561                 elm_object_domain_translatable_text_set(btn1, PACKAGE,
562                                 "IDS_BR_SK_CANCEL");
563                 elm_object_domain_translatable_text_set(btn2, PACKAGE,
564                                 "IDS_WIFI_SK_STOP");
565         } else if (popup_type == POP_TYPE_DISCONNECT) {
566                 elm_object_domain_translatable_part_text_set(popup, "title,text",
567                                  PACKAGE, "IDS_WIFI_SK_DISCONNECT");
568                 elm_object_domain_translatable_text_set(btn1, PACKAGE,
569                                 "IDS_BR_SK_CANCEL");
570                 elm_object_domain_translatable_text_set(btn2, PACKAGE,
571                                 "IDS_BR_SK_OK");
572
573         } else if (popup_type == POP_TYPE_SCAN_AGAIN) {
574                 elm_object_domain_translatable_part_text_set(popup, "title,text",
575                                  PACKAGE, "IDS_WIFI_SK4_SCAN");
576                 elm_object_domain_translatable_text_set(btn1, PACKAGE,
577                                 "IDS_BR_SK_CANCEL");
578                 elm_object_domain_translatable_text_set(btn2, PACKAGE,
579                                 "IDS_BR_SK_OK");
580         } else if (popup_type == POP_TYPE_ACCEPT_CONNECTION) {
581                 elm_object_domain_translatable_part_text_set(popup, "title,text",
582                                  PACKAGE, "IDS_WIFI_BODY_WI_FI_DIRECT_ABB");
583                 elm_object_domain_translatable_text_set(btn1, PACKAGE,
584                                 "IDS_BR_SK_CANCEL");
585                 elm_object_domain_translatable_text_set(btn2, PACKAGE,
586                                 "IDS_WIFI_SK_CONNECT");
587         } else {
588                 elm_object_domain_translatable_text_set(btn1, PACKAGE,
589                                 "IDS_BR_SK_CANCEL");
590                 elm_object_domain_translatable_text_set(btn2, PACKAGE,
591                                 "IDS_BR_SK_OK");
592         }
593
594         elm_object_part_content_set(popup, "button1", btn1);
595         elm_object_part_content_set(popup, "button2", btn2);
596
597         /* set the different callback by type */
598 #ifndef MODEL_BUILD_FEATURE_WLAN_CONCURRENT_MODE
599         if (popup_type == POPUP_TYPE_WIFI_OFF) {
600                 evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP, _mouseup_wifi_cb, (void *)ugd);
601 //              evas_object_event_callback_add(popup, EVAS_CALLBACK_KEY_DOWN, _keydown_wifi_cb, (void *)ugd);
602
603                 evas_object_smart_callback_add(btn1, "clicked", _wfd_ug_act_popup_wifi_cancel_cb, (void *)ugd);
604                 evas_object_smart_callback_add(btn2, "clicked", _wfd_ug_act_popup_wifi_ok_cb, (void *)ugd);
605         } else
606 #endif /* MODEL_BUILD_FEATURE_WLAN_CONCURRENT_MODE */
607
608         if (popup_type == POPUP_TYPE_HOTSPOT_OFF) {
609                 evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP, _mouseup_hotspot_cb, (void *)ugd);
610 //              evas_object_event_callback_add(popup, EVAS_CALLBACK_KEY_DOWN, _keydown_hotspot_cb, (void *)ugd);
611
612                 evas_object_smart_callback_add(btn1, "clicked", _wfd_ug_act_popup_hotspot_cancel_cb, (void *)ugd);
613                 evas_object_smart_callback_add(btn2, "clicked", _wfd_ug_act_popup_hotspot_ok_cb, (void *)ugd);
614         } else
615
616         if (popup_type == POP_TYPE_DISCONNECT ||
617                 popup_type == POP_TYPE_SCAN_AGAIN) {
618                 evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP, _mouseup_disconnect_all_cb, (void *)ugd);
619 //              evas_object_event_callback_add(popup, EVAS_CALLBACK_KEY_DOWN, _keydown_disconnect_all_cb, (void *)ugd);
620
621                 evas_object_smart_callback_add(btn1, "clicked", _wfd_ug_act_popup_cancel_cb, (void *)ugd);
622                 evas_object_smart_callback_add(btn2, "clicked", _wfd_ug_act_popup_disconnect_all_ok_cb, (void *)ugd);
623         } else if (popup_type == POP_TYPE_CANCEL_CONNECT) {
624                 evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP, _mouseup_disconnect_all_cb, (void *)ugd);
625
626                 evas_object_smart_callback_add(btn1, "clicked", _wfd_ug_act_popup_cancel_cb, (void *)ugd);
627                 evas_object_smart_callback_add(btn2, "clicked", _wfd_ug_act_popup_cancel_connect_ok_cb, (void *)ugd);
628         } else if (popup_type == POP_TYPE_ACCEPT_CONNECTION ) {
629                 evas_object_smart_callback_add(btn1, "clicked",
630                                 pushbutton_reject_connect_cb, (void *)ugd);
631                 evas_object_smart_callback_add(btn2, "clicked",
632                                 pushbutton_accept_connect_cb, (void *)ugd);
633         }
634
635         evas_object_show(popup);
636         ugd->act_popup = popup;
637         __FUNC_EXIT__;
638 }
639
640 /**
641  *      This function let the ug remove the action popup
642  *      @return   void
643  *      @param[in] data the pointer to the main data structure
644  */
645 void wfg_ug_act_popup_remove(void *data)
646 {
647         __FUNC_ENTER__;
648         struct ug_data *ugd = (struct ug_data *) data;
649
650         if (ugd->act_popup) {
651                 evas_object_del(ugd->act_popup);
652                 ugd->act_popup = NULL;
653         }
654         __FUNC_EXIT__;
655 }
656
657 /**
658  *      This function let the ug call it when click 'ok' button in warning popup of terminated problem
659  *      @return   void
660  *      @param[in] data the pointer to the main data structure
661  *      @param[in] obj the pointer to the evas object
662  *      @param[in] event_info the pointer to the event information
663  */
664 static void _wfd_ug_terminate_popup_cb(void *data, Evas_Object *obj, void *event_info)
665 {
666         __FUNC_ENTER__;
667         struct ug_data *ugd = (struct ug_data *) data;
668
669         evas_object_del(ugd->warn_popup);
670         ugd->warn_popup = NULL;
671
672         wfd_ug_view_free_peers(ugd);
673
674         ug_destroy_me(ugd->ug);
675         __FUNC_EXIT__;
676 }
677
678 /**
679  *      This function let the ug call it when click 'ok' button in warning popup of turning off WFD automatically
680  *      @return   void
681  *      @param[in] data the pointer to the main data structure
682  *      @param[in] obj the pointer to the evas object
683  *      @param[in] event_info the pointer to the event information
684  */
685 /*static void _wfd_ug_automatic_turn_off_popup_cb(void *data, Evas_Object *obj, void *event_info)
686 {
687         __FUNC_ENTER__;
688         struct ug_data *ugd = (struct ug_data *) data;
689
690         evas_object_del(ugd->warn_popup);
691         ugd->warn_popup = NULL;
692
693         __FUNC_EXIT__;
694 }*/
695
696 /**
697  *      This function let the ug call it when click 'ok' button in warning popup
698  *      @return   void
699  *      @param[in] data the pointer to the main data structure
700  *      @param[in] obj the pointer to the evas object
701  *      @param[in] event_info the pointer to the event information
702  */
703 static void _wfd_ug_warn_popup_cb(void *data, Evas_Object *obj, void *event_info)
704 {
705         __FUNC_ENTER__;
706         struct ug_data *ugd = (struct ug_data *) data;
707
708         evas_object_del(ugd->warn_popup);
709         ugd->warn_popup = NULL;
710
711         if (ugd->rename_entry) {
712                 elm_object_focus_set(ugd->rename_entry, EINA_TRUE);
713         }
714
715         __FUNC_EXIT__;
716 }
717
718 void warn_popup_language_changed(void *data, Evas_Object *obj, void *event_info)
719 {
720         __FUNC_ENTER__;
721
722         int popup_type = (int)data;
723         struct ug_data *ugd = wfd_get_ug_data();
724         char popup_text[MAX_POPUP_TEXT_SIZE] = {0};
725         Evas_Object *btn = NULL;
726
727         if (!ugd || !ugd->warn_popup) {
728                 DBG(LOG_ERROR, "NULL parameters.\n");
729                 return;
730         }
731
732         btn = elm_object_part_content_get(ugd->warn_popup, "button1");
733         elm_object_domain_translatable_text_set(btn, PACKAGE,
734                         "IDS_BR_SK_OK");
735
736         switch(popup_type) {
737         case POPUP_TYPE_ACTIVATE_FAIL_POLICY_RESTRICTS:
738                 elm_object_domain_translatable_text_set(ugd->warn_popup, PACKAGE,
739                                 "IDS_COM_POP_SECURITY_POLICY_RESTRICTS_USE_OF_WI_FI");
740                 break;
741         case POPUP_TYPE_TERMINATE:
742                 elm_object_domain_translatable_text_set(ugd->warn_popup, PACKAGE,
743                                 "IDS_COM_POP_FAILED");
744                 break;
745         case POPUP_TYPE_TERMINATE_DEACTIVATE_FAIL:
746                 elm_object_domain_translatable_text_set(ugd->warn_popup, PACKAGE,
747                                 "IDS_WIFI_POP_DEACTIVATION_FAILED");
748                 break;
749         case POPUP_TYPE_TERMINATE_NOT_SUPPORT:
750                 elm_object_domain_translatable_text_set(ugd->warn_popup, PACKAGE,
751                                 "IDS_ST_POP_NOT_SUPPORTED");
752                 break;
753         case POP_TYPE_BUSY_DEVICE_POPUP:
754                 elm_object_domain_translatable_text_set(ugd->warn_popup, PACKAGE,
755                                 "IDS_ST_POP_DEVICE_CONNECTED_TO_ANOTHER_DEVICE");
756                 break;
757         case POP_TYPE_MULTI_CONNECT_POPUP:
758                 snprintf(popup_text, MAX_POPUP_TEXT_SIZE, _("IDS_ST_POP_YOU_CAN_CONNECT_UP_TO_PD_DEVICES_AT_THE_SAME_TIME"), MAX_CONNECTED_PEER_NUM);
759                 elm_object_domain_translatable_text_set(ugd->warn_popup, PACKAGE,
760                                 popup_text);
761                 break;
762         default:
763                 break;
764         }
765
766         __FUNC_EXIT__;
767 }
768
769 /**
770  *      This function let the ug create a warning popup
771  *      @return   void
772  *      @param[in] data the pointer to the main data structure
773  *      @param[in] message the pointer to the text of popup
774  *      @param[in] popup_type the message type
775  */
776 void wfd_ug_warn_popup(void *data, const char *message, int popup_type)
777 {
778         __FUNC_ENTER__;
779         struct ug_data *ugd = (struct ug_data *) data;
780         Evas_Object *popup = NULL;
781         Evas_Object *btn = NULL;
782
783         popup = elm_popup_add(ugd->base);
784         elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
785         eext_object_event_callback_add(popup, EA_CALLBACK_BACK, eext_popup_back_cb, NULL);
786         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
787         if (popup_type == POP_TYPE_MULTI_CONNECT_POPUP ||
788                 popup_type == POP_TYPE_BUSY_DEVICE_POPUP) {
789                 elm_object_domain_translatable_part_text_set(popup, "title,text",
790                                  PACKAGE, "IDS_WIFI_HEADER_UNABLE_TO_CONNECT_ABB2");
791         } else {
792                 elm_object_domain_translatable_part_text_set(popup, "title,text",
793                                  PACKAGE, _("IDS_WIFI_HEADER_WI_FI_DIRECT_CONNECTION_ABB"));
794         }
795         elm_object_domain_translatable_text_set(popup, PACKAGE, message);
796         evas_object_smart_callback_add(popup, "language,changed", warn_popup_language_changed, (void *)popup_type);
797
798         btn = elm_button_add(popup);
799         elm_object_style_set(btn, "popup");
800         elm_object_domain_translatable_text_set(btn, PACKAGE, "IDS_BR_SK_OK");
801         elm_object_part_content_set(popup, "button1", btn);
802         if (popup_type == POPUP_TYPE_TERMINATE ||
803                 popup_type == POPUP_TYPE_TERMINATE_DEACTIVATE_FAIL ||
804                 popup_type == POPUP_TYPE_TERMINATE_NOT_SUPPORT) {
805                 evas_object_smart_callback_add(btn, "clicked", _wfd_ug_terminate_popup_cb, (void *)ugd);
806         } else {
807                 evas_object_smart_callback_add(btn, "clicked", _wfd_ug_warn_popup_cb, (void *)ugd);
808         }
809
810         evas_object_show(popup);
811         ugd->warn_popup = popup;
812         __FUNC_EXIT__;
813 }
814