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