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