Removed redundant NULL check for ad in _gl_pswd_check_box_sel()
[apps/native/ug-wifi-direct.git] / popup-wifidirect / src / wfd-app-popup-view.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 /**
21  * This file implements wifi direct system popup view  functions.
22  *
23  * @file    wfd-app-popup-view.c
24  * @author  Sungsik Jang (sungsik.jang@samsung.com)
25  * @version 0.1
26  */
27
28 #include <libintl.h>
29 #include <glib.h>
30
31 #include <Elementary.h>
32 #include <vconf.h>
33 #include <notification.h>
34 #include <feedback.h>
35 #include <efl_extension.h>
36
37 #include "wfd-app.h"
38 #include "wfd-app-strings.h"
39 #include "wfd-app-util.h"
40 #include "wfd-app-popup-view.h"
41
42 extern wfd_appdata_t *g_wfd_ad;
43 extern wfd_popup_t *g_wfd_pop;
44 extern unsigned char g_wfd_peer_mac[6];
45 extern unsigned char g_wfd_peer_name[32];
46 static Ecore_Timer *pb_timer = NULL;
47 static Ecore_Timer *keypad_popup_timer = NULL;
48 static int keypad_popup_timeout = 0;
49
50 void _replace_1PS_2PD(char *buf, int buf_len, char *format_str, char* SD_1, int PD_2);
51
52 static void mouseup_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
53 {
54         Evas_Event_Mouse_Up *ev = event_info;
55         if (ev->button == 3)
56                 evas_object_del(obj);
57 }
58
59 /*static void keydown_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
60 {
61         Evas_Event_Key_Down *ev = event_info;
62         if (!strcmp(ev->keyname, KEY_BACK)) {
63                 evas_object_del(obj);
64         }
65 }*/
66
67 /**
68  *      This function let the ug make a callback for click the button in popup
69  *      @return   void
70  *      @param[in] data the pointer to the main data structure
71  *      @param[in] obj the pointer to the evas object
72  *      @param[in] event_info the pointer to the event information
73  */
74 static void __popup_resp_cb(void *data, Evas_Object * obj, void *event_info)
75 {
76         __WFD_APP_FUNC_ENTER__;
77         wfd_appdata_t *ad = wfd_get_appdata();
78         wfd_connection_info_s *connection = ad->connection;
79         int result = -1;
80         unsigned long int resp = (unsigned long int) data;
81         char msg[WFD_POP_STR_MAX_LEN] = {0};
82         char *format_str = NULL;
83
84         WFD_APP_LOG(WFD_APP_LOG_HIGH, "popup resp : %d\n", resp);
85
86         switch (resp) {
87         case /* MT */ WFD_POP_RESP_APRV_CONNECT_PBC_YES:
88         {
89                 WFD_APP_LOG(WFD_APP_LOG_HIGH,
90                                 "WFD_POP_RESP_APRV_CONNECT_PBC_YES\n");
91                 wfd_destroy_popup();
92
93                 result = wifi_direct_accept_connection(connection->peer_addr);
94                 if (result != WIFI_DIRECT_ERROR_NONE) {
95                         WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to accept connection(%d)", result);
96                         evas_object_hide(ad->win);
97
98                         /* tickernoti popup */
99                         format_str = D_("IDS_WIFI_POP_FAILED_TO_CONNECT_TO_PS");
100                         snprintf(msg, WFD_POP_STR_MAX_LEN, format_str, connection->peer_name);
101                         notification_status_message_post(msg);
102                 }
103                 WFD_APP_LOG(WFD_APP_LOG_LOW, "Succeeded to accept connection");
104         }
105         break;
106
107         case /* MT */ WFD_POP_RESP_APRV_CONNECT_DISPLAY_OK:
108         {
109                 WFD_APP_LOG(WFD_APP_LOG_HIGH,
110                                 "WFD_POP_RESP_APRV_CONNECT_DISPLAY_OK\n");
111                 wfd_destroy_popup();
112
113                 result = wifi_direct_accept_connection(connection->peer_addr);
114                 if (result == WIFI_DIRECT_ERROR_NONE) {
115                         wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_PIN, NULL);
116                 } else {
117                         WFD_APP_LOG(WFD_APP_LOG_LOW,
118                                 "wifi_direct_accept_connection() failed. result=[%d]\n", result);
119                         /* tickernoti popup */
120                         notification_status_message_post(D_("IDS_WIFI_POP_FAILED_TO_CONNECT_TO_PS"));
121                 }
122         }
123         break;
124
125         case /* MO */ WFD_POP_RESP_PROG_CONNECT_KEYPAD_OK:
126         {
127                 int result = 0;
128                 WFD_APP_LOG(WFD_APP_LOG_HIGH,
129                                 "WFD_POP_RESP_PROG_CONNECT_KEYPAD_OK\n");
130
131                 wfd_destroy_popup();
132
133                 int len = strlen(connection->wps_pin);
134                 WFD_APP_LOGSECURE(WFD_APP_LOG_LOW, "PIN [%s]", connection->wps_pin);
135
136                 if (len < 8 || len > 64) {
137                         WFD_APP_LOG(WFD_APP_LOG_ERROR, "Error, Incorrect PIN!!\n");
138                         keypad_popup_timeout--;
139                         /* tickernoti popup */
140                         notification_status_message_post(D_("IDS_COM_BODY_PINS_DO_NOT_MATCH"));
141
142                         /* redraw the popup */
143                         wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_KEYPAD, (void *) NULL);
144                         break;
145                 }
146                 keypad_popup_timeout = 0;
147
148                 result = wifi_direct_set_wps_pin(connection->wps_pin);
149                 if (result != WIFI_DIRECT_ERROR_NONE) {
150                         /* tickernoti popup */
151                         format_str = D_("IDS_WIFI_POP_FAILED_TO_CONNECT_TO_PS");
152                         snprintf(msg, WFD_POP_STR_MAX_LEN, format_str, connection->peer_name);
153                         notification_status_message_post(msg);
154                         return;
155                 }
156
157                 result = wifi_direct_accept_connection(connection->peer_addr);
158                 if (result != WIFI_DIRECT_ERROR_NONE) {
159                         WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to accept connection(%d)", result);
160                         evas_object_hide(ad->win);
161
162                         /* tickernoti popup */
163                         format_str = D_("IDS_WIFI_POP_FAILED_TO_CONNECT_TO_PS");
164                         snprintf(msg, WFD_POP_STR_MAX_LEN, format_str, connection->peer_name);
165                         notification_status_message_post(msg);
166                 }
167                 WFD_APP_LOG(WFD_APP_LOG_LOW, "Succeeded to connect with [%s]", connection->peer_addr);
168         }
169         break;
170
171         case /* MT */ WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES:
172         {
173                 WFD_APP_LOG(WFD_APP_LOG_HIGH,
174                                 "WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES\n");
175                 wfd_destroy_popup();
176                 if (pb_timer) {
177                         ecore_timer_del(pb_timer);
178                         pb_timer = NULL;
179                 }
180
181                 wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_KEYPAD, (void *) NULL);
182         }
183         break;
184
185         case /* MT */ WFD_POP_RESP_APRV_CONNECT_NO:
186         {
187                 WFD_APP_LOG(WFD_APP_LOG_HIGH,
188                                 "WFD_POP_RESP_APRV_CONNECT_NO: destroy_popup...\n");
189
190                 if (connection->peer_addr[0] != '\0') {
191                         result = wifi_direct_reject_connection(connection->peer_addr);
192                         if (result != WIFI_DIRECT_ERROR_NONE)
193                                 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to reject connection(%d)", result);
194                 } else {
195                         WFD_APP_LOG(WFD_APP_LOG_ERROR, "Peer's address is Zero MAC");
196                 }
197
198                 if (pb_timer) {
199                         ecore_timer_del(pb_timer);
200                         pb_timer = NULL;
201                 }
202
203                 wfd_destroy_popup();
204                 keypad_popup_timeout = 0;
205         }
206         break;
207
208         default:
209         {
210                 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Unknown respone\n");
211                 wfd_destroy_popup();
212         }
213         break;
214         }
215
216         __WFD_APP_FUNC_EXIT__;
217 }
218
219 /**
220  *      This function let the app destroy the popup
221  *      @return   void
222  *      @param[in] null
223  */
224 void wfd_destroy_popup()
225 {
226         __WFD_APP_FUNC_ENTER__;
227         wfd_appdata_t *ad = wfd_get_appdata();
228
229         if (ad == NULL) {
230                 WFD_APP_LOG(WFD_APP_LOG_ERROR, "ad is NULL\n");
231                 return;
232         }
233
234         if (keypad_popup_timer) {
235                 ecore_timer_del(keypad_popup_timer);
236                 keypad_popup_timer = NULL;
237         }
238
239         if (ad->popup) {
240                 evas_object_del(ad->popup);
241                 ad->popup = NULL;
242         }
243
244         if (ad->popup_timeout_handle > 0) {
245                 g_source_remove(ad->popup_timeout_handle);
246                 ad->popup_timeout_handle = 0;
247         }
248
249         if (ad->win)
250                 evas_object_hide(ad->win);
251
252         if (pb_timer) {
253                 ecore_timer_del(pb_timer);
254                 pb_timer = NULL;
255         }
256         __WFD_APP_FUNC_EXIT__;
257         return;
258 }
259
260 /**
261  *      This function let the app create a popup which includes no button
262  *      @return   popup
263  *      @param[in] win the window object
264  *      @param[in] pop the pointer to the prepared popup
265  */
266 static Evas_Object *wfd_draw_pop_type_a(Evas_Object * win, wfd_popup_t * pop)
267 {
268         __WFD_APP_FUNC_ENTER__;
269
270         wfd_appdata_t *ad = wfd_get_appdata();
271         Evas_Object *popup;
272
273         popup = elm_popup_add(win);
274         elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
275         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, __popup_resp_cb, NULL);
276         evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP, mouseup_cb, ad);
277 //      evas_object_event_callback_add(popup, EVAS_CALLBACK_KEY_DOWN, keydown_cb, ad);
278         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
279         elm_object_domain_translatable_text_set(popup, PACKAGE, pop->text);
280         elm_popup_timeout_set(popup, pop->timeout);
281
282         evas_object_show(popup);
283         evas_object_show(win);
284
285         __WFD_APP_FUNC_EXIT__;
286         return popup;
287 }
288
289 /**
290  *      This function let the app create a popup which includes one button
291  *      @return   popup
292  *      @param[in] win the window object
293  *      @param[in] pop the pointer to the prepared popup
294  */
295 static Evas_Object *wfd_draw_pop_type_b(Evas_Object * win, wfd_popup_t * pop)
296 {
297         __WFD_APP_FUNC_ENTER__;
298         Evas_Object *popup = NULL;
299         Evas_Object *btn = NULL;
300         wfd_appdata_t *ad = wfd_get_appdata();
301
302         popup = elm_popup_add(win);
303         elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
304         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, __popup_resp_cb, (void *) (intptr_t) pop->resp_data1);
305         evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP, mouseup_cb, ad);
306 //      evas_object_event_callback_add(popup, EVAS_CALLBACK_KEY_DOWN, keydown_cb, ad);
307         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
308         elm_object_domain_translatable_text_set(popup, PACKAGE, pop->text);
309
310         btn = elm_button_add(popup);
311         elm_object_style_set(btn, "popup");
312         elm_object_domain_translatable_text_set(btn, PACKAGE, pop->label1);
313         elm_object_part_content_set(popup, "button1", btn);
314         evas_object_smart_callback_add(btn, "clicked", __popup_resp_cb, (void *) (intptr_t) pop->resp_data1);
315
316         evas_object_show(popup);
317         evas_object_show(win);
318
319         __WFD_APP_FUNC_EXIT__;
320         return popup;
321 }
322
323 /**
324  *      This function let the app create a popup which includes two buttons
325  *      @return   popup
326  *      @param[in] win the window object
327  *      @param[in] pop the pointer to the prepared popup
328  */
329 static Evas_Object *wfd_draw_pop_type_c(Evas_Object * win, wfd_popup_t * pop)
330 {
331         __WFD_APP_FUNC_ENTER__;
332         Evas_Object *popup = NULL;
333         Evas_Object *btn1 = NULL, *btn2 = NULL;
334         wfd_appdata_t *ad = wfd_get_appdata();
335
336         popup = elm_popup_add(win);
337         elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
338         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, __popup_resp_cb, (void *) (intptr_t) pop->resp_data2);
339         evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP, mouseup_cb, ad);
340 //      evas_object_event_callback_add(popup, EVAS_CALLBACK_KEY_DOWN, keydown_cb, ad);
341         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
342         elm_object_domain_translatable_part_text_set(popup, "title,text",
343                         PACKAGE, D_("IDS_WIFI_HEADER_WI_FI_DIRECT_CONNECTION_ABB"));
344         elm_object_domain_translatable_text_set(popup, PACKAGE, pop->text);
345
346         btn1 = elm_button_add(popup);
347         elm_object_style_set(btn1, "popup");
348         elm_object_domain_translatable_text_set(btn1, PACKAGE, pop->label2);
349         elm_object_part_content_set(popup, "button1", btn1);
350         evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb,
351                 (void *) (intptr_t) pop->resp_data2);
352
353         btn2 = elm_button_add(popup);
354         elm_object_style_set(btn2, "popup");
355         elm_object_domain_translatable_text_set(btn2, PACKAGE, pop->label1);
356         elm_object_part_content_set(popup, "button2", btn2);
357         evas_object_smart_callback_add(btn2, "clicked", __popup_resp_cb,
358                 (void *) (intptr_t) pop->resp_data1);
359
360         evas_object_show(popup);
361         evas_object_show(win);
362
363         __WFD_APP_FUNC_EXIT__;
364         return popup;
365 }
366
367 static void _wfd_ug_automatic_turn_off_popup_cb(void *data, Evas_Object *obj, void *event_info)
368 {
369         __WFD_APP_FUNC_ENTER__;
370         wfd_appdata_t *ad = wfd_get_appdata();
371
372         if (ad->popup) {
373                 evas_object_del(ad->popup);
374                 ad->popup = NULL;
375         }
376
377         if (ad->win)
378                 evas_object_hide(ad->win);
379
380         __WFD_APP_FUNC_EXIT__;
381 }
382
383 Evas_Object *wfd_draw_pop_type_auto_deactivation(Evas_Object *win,  void *userdata)
384 {
385         __WFD_APP_FUNC_ENTER__;
386
387         Evas_Object *popup = NULL;
388         Evas_Object *btn = NULL;
389         char popup_text[MAX_POPUP_TEXT_SIZE] = {0};
390         char *format_str = NULL;
391         wfd_appdata_t *ad = wfd_get_appdata();
392
393         popup = elm_popup_add(win);
394         elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
395         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, _wfd_ug_automatic_turn_off_popup_cb, userdata);
396         evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP, mouseup_cb, ad);
397 //      evas_object_event_callback_add(popup, EVAS_CALLBACK_KEY_DOWN, keydown_cb, ad);
398         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
399         elm_object_domain_translatable_part_text_set(popup, "title,text",
400                         PACKAGE, "IDS_WIFI_BODY_WI_FI_DIRECT_ABB");
401         format_str = D_("IDS_WIFI_POP_THERE_HAS_BEEN_NO_ACTIVITY_FOR_PD_MINUTES_SINCE_WI_FI_DIRECT_WAS_ENABLED_MSG");
402         snprintf(popup_text, MAX_POPUP_TEXT_SIZE, format_str, 5);
403         elm_object_domain_translatable_text_set(popup, PACKAGE, popup_text);
404
405         btn = elm_button_add(popup);
406         elm_object_style_set(btn, "popup");
407         elm_object_domain_translatable_text_set(btn, PACKAGE, "IDS_BR_SK_OK");
408         elm_object_part_content_set(popup, "button1", btn);
409         evas_object_smart_callback_add(btn, "clicked", _wfd_ug_automatic_turn_off_popup_cb, userdata);
410
411         evas_object_show(popup);
412         evas_object_show(win);
413
414         __WFD_APP_FUNC_EXIT__;
415         return popup;
416 }
417
418 /**
419  *      This function let the ug make a change callback for password input
420  *      @return   void
421  *      @param[in] data the pointer to the main data structure
422  *      @param[in] obj the pointer to the evas object
423  *      @param[in] event_info the pointer to the event information
424  */
425 static void _smart_ime_cb(void *data, Evas_Object * obj, void *event_info)
426 {
427         __WFD_APP_FUNC_ENTER__;
428         wfd_appdata_t *ad = wfd_get_appdata();
429         wfd_connection_info_s *connection = ad->connection;
430
431         Ecore_IMF_Context *imf_context = NULL;
432         imf_context = (Ecore_IMF_Context *) ad->pin_entry;
433
434         if (NULL == imf_context) {
435                 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Error!!! Ecore_IMF_Context is NULL!!");
436                 return;
437         }
438
439         char *txt = elm_entry_markup_to_utf8(elm_entry_entry_get((const Evas_Object *) imf_context));
440         if (NULL != txt) {
441                 WFD_APP_LOG(WFD_APP_LOG_LOW, "* text [%s], len=[%d]", txt, strlen(txt));
442                 strncpy(connection->wps_pin, txt, sizeof(connection->wps_pin) - 1);
443                 WFD_IF_FREE_MEM(txt);
444         } else {
445                 WFD_APP_LOG(WFD_APP_LOG_LOW, "Err!");
446         }
447
448         __WFD_APP_FUNC_EXIT__;
449 }
450
451 /**
452  *      This function let the app make a callback for progressbar timer
453  *      @return   if stop the timer, return ECORE_CALLBACK_CANCEL, else return ECORE_CALLBACK_RENEW
454  *      @param[in] data the pointer to the wps structure
455  */
456 static Eina_Bool _fn_pb_timer(void *data)
457 {
458         int step = 0;
459         double value = 0.0;
460         char time_label[32] = {0};
461         wfd_wps_display_popup_t *wps_display_popup = (wfd_wps_display_popup_t *) data;
462
463         if (NULL == wps_display_popup) {
464                 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Param is NULL.\n");
465                 return ECORE_CALLBACK_CANCEL;
466         }
467
468         Evas_Object *progressbar = NULL;
469         Evas_Object *time = NULL;
470
471         progressbar = wps_display_popup->progressbar;
472         time = wps_display_popup->time;
473         value = elm_progressbar_value_get(progressbar);
474
475         wps_display_popup->step++;
476         step = wps_display_popup->step;
477         value = ((double)step) / WFD_POP_TIMER_120;
478
479         if (value >= 1.0) {
480                 WFD_APP_LOG(WFD_APP_LOG_LOW, "Progress end.\n");
481                 if (pb_timer) {
482                         ecore_timer_del(pb_timer);
483                         pb_timer = NULL;
484                 }
485                 wfd_destroy_popup();
486                 return ECORE_CALLBACK_CANCEL;
487         }
488
489         elm_progressbar_value_set(progressbar, value);
490         WFD_APP_LOG(WFD_APP_LOG_LOW, "step: %d, value: %f\n", wps_display_popup->step, value);
491
492         /* show the time label */
493         if (step < 60) {
494                 if (step < 10)
495                         snprintf(time_label, 32, "00:0%d", step);
496                 else
497                         snprintf(time_label, 32, "00:%d", step);
498         } else {
499                 if (step%60 < 10)
500                         snprintf(time_label, 32, "0%d:0%d", step/60, step%60);
501                 else
502                         snprintf(time_label, 32, "0%d:%d", step/60, step%60);
503         }
504
505         char *remaining_time_str = g_strdup_printf(
506                         "<font_size=40><align=center>%s</align></font_size>", time_label);
507         elm_object_text_set(time, remaining_time_str);
508         g_free(remaining_time_str);
509
510         return ECORE_CALLBACK_RENEW;
511 }
512
513 static Eina_Bool _keypad_popup_timer_cb(void *data)
514 {
515         __WFD_APP_FUNC_ENTER__;
516
517         char msg1[WFD_POP_STR_MAX_LEN] = {0};
518         char msg2[WFD_POP_STR_MAX_LEN] = {0};
519         char label_str[WFD_POP_STR_MAX_LEN] = {0, };
520         char * format_str = NULL;
521
522         Evas_Object *label = (Evas_Object*) data;
523         wfd_appdata_t *ad = wfd_get_appdata();
524         wfd_connection_info_s *connection = NULL;
525
526         WFD_RETV_IF(NULL == ad, FALSE, "NULL parameters(ad)\n");
527         WFD_RETV_IF(NULL == label, FALSE, "NULL parameters(label)\n");
528         if (NULL == ad->popup) {
529                 keypad_popup_timeout = 0;
530                 return ECORE_CALLBACK_CANCEL;
531         }
532
533         connection = ad->connection;
534
535         keypad_popup_timeout--;
536
537         if (keypad_popup_timeout > 0) {
538                 _replace_1PS_2PD((char *)msg1, sizeof(msg1),
539                                 D_("IDS_ST_BODY_CONNECT_WITH_PS_IN_PD_SECS_ABB"),
540                                 connection->peer_name, keypad_popup_timeout);
541
542                 format_str = D_("IDS_WIFI_POP_ENTER_PIN_TO_CONNECT_TO_PS");
543                 snprintf(msg2, sizeof(msg2), format_str, connection->peer_name);
544                 snprintf(label_str, sizeof(label_str), "%s %s", msg1, msg2);
545                 elm_object_domain_translatable_text_set(label, PACKAGE, label_str);
546
547         }
548
549         if (keypad_popup_timeout <= 0) {
550                 wfd_destroy_popup();
551                 keypad_popup_timeout = 0;
552                 __WFD_APP_FUNC_EXIT__;
553                 return ECORE_CALLBACK_CANCEL;
554         }
555
556         __WFD_APP_FUNC_EXIT__;
557         return ECORE_CALLBACK_RENEW;
558 }
559
560 /* This callback is for showing(hiding) X marked button. */
561 /*static void _changed_cb(void *data, Evas_Object *obj, void *event_info)
562 {
563         if (elm_object_focus_get(obj)) {
564                 if (elm_entry_is_empty(obj))
565                         elm_object_signal_emit(data, "elm,state,eraser,hide", "");
566                 else
567                         elm_object_signal_emit(data, "elm,state,eraser,show", "");
568         }
569 }*/
570
571 /* Focused callback will show X marked button and hide guidetext. */
572 /*static void _focused_cb(void *data, Evas_Object *obj, void *event_info)
573 {
574         if (!elm_entry_is_empty(obj))
575                 elm_object_signal_emit(data, "elm,state,eraser,show", "");
576         elm_object_signal_emit(data, "elm,state,rename,hide", "");
577 }*/
578
579 /*  Unfocused callback will show guidetext and hide X marked button. */
580 /*static void _unfocused_cb(void *data, Evas_Object *obj, void *event_info)
581 {
582         elm_object_signal_emit(data, "elm,state,eraser,hide", "");
583         elm_object_signal_emit(data, "elm,state,rename,show", "");
584 }*/
585
586 /* When X marked button clicked, make string as empty. */
587 /*static void _eraser_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
588 {
589         elm_object_focus_set(data, EINA_TRUE);
590         elm_entry_entry_set(data, "");
591 }*/
592
593 /**
594  *      This function let the app create a edit filed
595  *      @return   edit filed
596  *      @param[in] parent the parent object
597  *      @param[in] title the pointer to the title of edit field
598  *      @param[in] guide the pointer to the text of guide
599  *      @param[in] single_line whether it can support single line
600  *      @param[in] is_editable whether it is available to edit
601  */
602 /*static Evas_Object *_add_edit_field(Evas_Object *parent, const char *title, const char *guide, Eina_Bool single_line, Eina_Bool is_editable)
603 {
604         assertm_if(NULL == parent, "parent is NULL!!");
605
606         Evas_Object *layout = elm_layout_add(parent);
607         assertm_if(NULL == layout, "layout is NULL!!");
608
609         if (title && title[0] != '\0') {
610                 elm_layout_theme_set(layout, "layout", "dialogue/editfield/title", "default");
611                 elm_object_part_text_set(layout, "elm.text", title);
612         } else {
613                 elm_layout_theme_set(layout, "layout", "dialogue/editfield", "default");
614         }
615
616         Evas_Object *entry = elm_entry_add(layout);
617         assertm_if(NULL == entry, "entry is NULL!!");
618
619         if (guide && guide[0] != '\0') {
620                 elm_object_part_text_set(layout, "elm.guidetext", guide);
621         }
622
623         evas_object_smart_callback_add(entry, "changed", _changed_cb, layout);
624         evas_object_smart_callback_add(entry, "focused", _focused_cb, layout);
625         evas_object_smart_callback_add(entry, "unfocused", _unfocused_cb, layout);
626
627         elm_object_part_content_set(layout, "elm.icon.entry", entry);
628         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
629         evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
630
631         elm_entry_single_line_set(entry, single_line);
632         elm_entry_scrollable_set(entry, single_line);
633
634         Evas_Object *button = elm_button_add(parent);
635         elm_object_style_set(button, "editfield_clear");
636         elm_object_part_content_set(layout, "elm.icon.eraser", button);
637         evas_object_smart_callback_add(button, "clicked", _eraser_btn_clicked_cb, entry);
638         return layout;
639 }*/
640
641 /**
642  *      This function let the app create a display popup
643  *      @return   display popup
644  *      @param[in] win the window object
645  *      @param[in] pop the pointer to the prepared popup
646  */
647 Evas_Object *wfd_draw_pop_type_display(Evas_Object * win, wfd_popup_t * pop)
648 {
649         __WFD_APP_FUNC_ENTER__;
650         WFD_APP_LOG(WFD_APP_LOG_LOW, "wfd_draw_pop_type_display\n");
651
652         Evas_Object *popup = NULL;
653         Evas_Object *progressbar = NULL;
654         Evas_Object *time = NULL;
655         Evas_Object *layout;
656         static wfd_wps_display_popup_t wps_display_popup;
657         wfd_appdata_t *ad = wfd_get_appdata();
658
659         popup = elm_popup_add(win);
660         elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
661         evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP, mouseup_cb, ad);
662 //      evas_object_event_callback_add(popup, EVAS_CALLBACK_KEY_DOWN, keydown_cb, ad);
663         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, 0.0);
664         elm_object_domain_translatable_part_text_set(popup, "title,text",
665                          PACKAGE, D_("IDS_WIFI_HEADER_WI_FI_DIRECT_CONNECTION_ABB"));
666
667         layout = elm_layout_add(popup);
668         if (layout == NULL) {
669                 WFD_APP_LOG(WFD_APP_LOG_LOW, "Layout failed so returning !!");
670                 return NULL;
671         }
672
673         elm_layout_file_set(layout, WFD_EDJ_POPUP_PATH, "popup_wps_pin_layout");
674         elm_object_domain_translatable_part_text_set(layout, "elm.text.description",
675                          PACKAGE, pop->text);
676         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
677
678         /* add progressbar */
679         progressbar = elm_progressbar_add(layout);
680         elm_object_style_set(progressbar, "list_progress");
681         elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
682         evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, EVAS_HINT_FILL);
683         evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
684         elm_progressbar_value_set(progressbar, 0.0);
685         evas_object_show(progressbar);
686
687         /* add time */
688         time = elm_label_add(layout);
689         elm_label_line_wrap_set(time, ELM_WRAP_MIXED);
690         elm_object_text_set(time, D_("<font_size=40><align=center>00:00</align></font_size>"));
691         evas_object_size_hint_weight_set(time, EVAS_HINT_EXPAND, 0.0);
692         evas_object_size_hint_align_set(time, EVAS_HINT_FILL, EVAS_HINT_FILL);
693         evas_object_show(time);
694
695         elm_object_part_content_set(layout, "slider", progressbar);
696         elm_object_part_content_set(layout, "timer_label", time);
697
698
699         /* start progressbar timer */
700         wps_display_popup.step = 0;
701         wps_display_popup.progressbar = progressbar;
702         wps_display_popup.time = time;
703         pb_timer = ecore_timer_add(1, _fn_pb_timer, &wps_display_popup);
704
705         /* add buttons */
706         if (pop->resp_data2 == WFD_POP_RESP_APRV_CONNECT_NO) {
707                 Evas_Object *btn2 = NULL;
708                 btn2 = elm_button_add(popup);
709                 elm_object_style_set(btn2, "popup");
710                 elm_object_domain_translatable_text_set(btn2, PACKAGE, pop->label2);
711                 elm_object_part_content_set(popup, "button1", btn2);
712                 evas_object_smart_callback_add(btn2, "clicked", __popup_resp_cb,
713                                 (void *) (intptr_t) pop->resp_data2);
714                 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, __popup_resp_cb,
715                                 (void *) (intptr_t) pop->resp_data2);
716         }
717
718         if (pop->resp_data1 == WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES || pop->resp_data1 == WFD_POP_RESP_APRV_CONNECT_PBC_YES) {
719                 Evas_Object *btn1 = NULL;
720                 btn1 = elm_button_add(popup);
721                 elm_object_style_set(btn1, "popup");
722                 elm_object_domain_translatable_text_set(btn1, PACKAGE, pop->label1);
723                 elm_object_part_content_set(popup, "button2", btn1);
724                 evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb,
725                                 (void *) (intptr_t) pop->resp_data1);
726                 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, __popup_resp_cb,
727                                 (void *) (intptr_t) pop->resp_data1);
728         }
729
730         elm_object_content_set(popup, layout);
731         evas_object_show(popup);
732         evas_object_show(win);
733
734         __WFD_APP_FUNC_EXIT__;
735         return popup;
736 }
737
738 static void __popup_eraser_clicked_cb(void *data, Evas_Object *obj, void *event_info)
739 {
740         __WFD_APP_FUNC_ENTER__;
741         elm_entry_entry_set(data, "");
742         __WFD_APP_FUNC_EXIT__;
743 }
744
745 static void _entry_changed_cb(void *data, Evas_Object *obj, void *event_info)
746 {
747         __WFD_APP_FUNC_ENTER__;
748         if (elm_object_part_content_get(obj, "elm.swallow.clear")) {
749                 if (elm_object_focus_get(obj)) {
750                         if (elm_entry_is_empty(obj))
751                                 elm_object_signal_emit(obj, "elm,state,clear,hidden", "");
752                         else
753                                 elm_object_signal_emit(obj, "elm,state,clear,visible", "");
754                 }
755         }
756         __WFD_APP_FUNC_EXIT__;
757 }
758
759 static void _entry_focused_cb(void *data, Evas_Object *obj, void *event_info)
760 {
761         __WFD_APP_FUNC_ENTER__;
762
763         if (elm_object_part_content_get(obj, "elm.swallow.clear")) {
764                 if (!elm_entry_is_empty(obj))
765                         elm_object_signal_emit(obj, "elm,state,clear,visible", "");
766                 else
767                         elm_object_signal_emit(obj, "elm,state,clear,hidden", "");
768         }
769         elm_object_signal_emit(obj, "elm,state,focus,on", "");
770         __WFD_APP_FUNC_EXIT__;
771 }
772
773 static void _entry_keydown_cb(void *data, Evas *e, Evas_Object *obj,
774                 void *event_info)
775 {
776         __WFD_APP_FUNC_ENTER__;
777
778         Evas_Event_Key_Down *ev;
779         Evas_Object *entry = obj;
780
781         WFD_RET_IF(data == NULL, "Incorrect parameter data(NULL)\n");
782         WFD_RET_IF(event_info == NULL, "Incorrect parameter event_info(NULL)\n");
783         WFD_RET_IF(entry == NULL, "Incorrect parameter entry(NULL)\n");
784
785         ev = (Evas_Event_Key_Down *)event_info;
786
787         if (g_strcmp0(ev->key, "KP_Enter") == 0 || g_strcmp0(ev->key, "Return") == 0) {
788                 Ecore_IMF_Context *imf_context;
789
790                 imf_context = (Ecore_IMF_Context*)elm_entry_imf_context_get(entry);
791                 if (imf_context)
792                         ecore_imf_context_input_panel_hide(imf_context);
793
794                 elm_object_focus_set(entry, EINA_FALSE);
795         }
796 }
797
798 static char *__wfd_main_desc_label_get(void *data, Evas_Object *obj,
799                 const char *part)
800 {
801         __WFD_APP_FUNC_ENTER__;
802         if (obj == NULL || part == NULL)
803                 return NULL;
804
805         WFD_APP_LOG(WFD_APP_LOG_LOW, "wfd_rename desc\n");
806         char buf[WFD_POP_STR_MAX_LEN] = {0, };
807         char msg1[WFD_POP_STR_MAX_LEN] = {0, };
808         char msg2[WFD_POP_STR_MAX_LEN] = {0, };
809         char *format_str = NULL;
810         wfd_appdata_t *ad = wfd_get_appdata();
811         WFD_RETV_IF(ad == NULL, NULL, "Incorrect parameter(NULL)\n");
812         wfd_connection_info_s *connection = ad->connection;
813         WFD_RETV_IF(connection == NULL, NULL, "Incorrect parameter(NULL)\n");
814
815         if (!strcmp("elm.text.multiline", part)) {
816                 if (keypad_popup_timeout > 0)
817                                 ad->timeout = keypad_popup_timeout;
818
819                 _replace_1PS_2PD((char *)msg1, WFD_POP_STR_MAX_LEN,
820                                 D_("IDS_ST_BODY_CONNECT_WITH_PS_IN_PD_SECS_ABB"),
821                                 connection->peer_name, ad->timeout);
822
823                 format_str = D_("IDS_WIFI_POP_ENTER_PIN_TO_CONNECT_TO_PS");
824                 snprintf(msg2, WFD_POP_STR_MAX_LEN, format_str, connection->peer_name);
825
826                 WFD_APP_LOG(WFD_APP_LOG_LOW, "string %s %s", msg1, msg2);
827                 snprintf(buf, WFD_POP_STR_MAX_LEN,
828                                 "<font_size=30>%s %s</font_size>",
829                                 msg1, msg2);
830                 __WFD_APP_FUNC_EXIT__;
831                 return g_strdup(buf);
832         }
833         __WFD_APP_FUNC_EXIT__;
834         return NULL;
835 }
836
837 static Evas_Object *__wfd_pin_entry_icon_get(void *data, Evas_Object *obj,
838                 const char *part)
839 {
840         __WFD_APP_FUNC_ENTER__;
841         if (obj == NULL || part == NULL)
842                 return NULL;
843
844         wfd_appdata_t *ad = wfd_get_appdata();
845         WFD_RETV_IF(ad == NULL, NULL, "Incorrect parameter(NULL)\n");
846         Evas_Object *entry = NULL;
847         Evas_Object *button = NULL;
848         Ecore_IMF_Context *imf_context;
849         if (g_strcmp0(part, "elm.icon.entry")) {
850                 __WFD_APP_FUNC_EXIT__;
851                 return NULL;
852         }
853         static Elm_Entry_Filter_Accept_Set accept_set = {"0123456789", NULL};
854         entry = elm_entry_add(obj);
855         elm_entry_single_line_set(entry, EINA_TRUE);
856         elm_object_style_set(entry, "editfield");
857         elm_entry_scrollable_set(entry, EINA_TRUE);
858
859         eext_entry_selection_back_event_allow_set(entry, EINA_TRUE);
860         evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
861         evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
862         elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);
863         elm_entry_password_set(entry, EINA_TRUE);
864         elm_entry_prediction_allow_set(entry, EINA_FALSE);
865
866         elm_entry_markup_filter_append(entry,
867                         elm_entry_filter_accept_set, &accept_set);
868         elm_entry_input_panel_layout_set(entry,
869                         ELM_INPUT_PANEL_LAYOUT_DATETIME);
870         elm_object_signal_emit(entry, "elm,action,hide,search_icon", "");
871         elm_object_domain_translatable_part_text_set(entry, "elm.guide",
872                          PACKAGE, D_("IDS_WIFI_POP_PIN"));
873         elm_entry_input_panel_return_key_autoenabled_set(entry, EINA_TRUE);
874         elm_entry_input_panel_return_key_type_set(entry,
875                         ELM_INPUT_PANEL_RETURN_KEY_TYPE_DONE);
876
877         ad->pin_entry = entry;
878         imf_context = (Ecore_IMF_Context*)elm_entry_imf_context_get(entry);
879         if (imf_context) {
880                 ecore_imf_context_input_panel_return_key_type_set(imf_context,
881                 ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE);
882         }
883
884         button = elm_button_add(obj);
885         elm_object_style_set(button, "search_clear");
886         elm_object_focus_allow_set(button, EINA_FALSE);
887         elm_object_part_content_set(entry, "elm.swallow.clear", button);
888         evas_object_smart_callback_add(button, "clicked",
889                         __popup_eraser_clicked_cb, entry);
890
891         elm_object_signal_emit(entry, "elm,action,hide,search_icon", "");
892         evas_object_smart_callback_add(entry, "changed",
893                         _entry_changed_cb, NULL);
894         evas_object_smart_callback_add(entry, "preedit,changed",
895                         _entry_changed_cb, NULL);
896         evas_object_smart_callback_add(entry, "focused",
897                         _entry_focused_cb, NULL);
898         evas_object_event_callback_add(entry, EVAS_CALLBACK_KEY_DOWN,
899                         _entry_keydown_cb, ad);
900
901         elm_object_content_set(obj, entry);
902         evas_object_show(entry);
903         evas_object_smart_callback_add(entry, "changed", _smart_ime_cb, NULL);
904         elm_object_focus_set(entry, EINA_TRUE);
905         __WFD_APP_FUNC_EXIT__;
906         return entry;
907 }
908
909 static void _chk_changed_cb(void *data, Evas_Object *obj, void *ei)
910 {
911         __WFD_APP_FUNC_ENTER__;
912         if (obj == NULL || data == NULL)
913                 return;
914
915         Eina_Bool state = elm_check_state_get(obj);
916         if (state)
917                 elm_entry_password_set((Evas_Object *)data, EINA_FALSE);
918         else
919                 elm_entry_password_set((Evas_Object *)data, EINA_TRUE);
920
921         __WFD_APP_FUNC_EXIT__;
922 }
923
924 static void _gl_pswd_check_box_sel(void *data, Evas_Object *obj, void *ei)
925 {
926         __WFD_APP_FUNC_ENTER__;
927         Elm_Object_Item *item = NULL;
928         item = (Elm_Object_Item *)ei;
929         if (item == NULL)
930                 return;
931
932         wfd_appdata_t *ad = wfd_get_appdata();
933         if (ad == NULL) {
934                 WFD_APP_LOG(WFD_APP_LOG_LOW, "Incorrect parameter(NULL)\n");
935                 return;
936         }
937         Evas_Object *ck = elm_object_item_part_content_get(ei, "elm.icon.left");
938         elm_genlist_item_selected_set(item, EINA_FALSE);
939         Eina_Bool state = elm_check_state_get(ck);
940         elm_check_state_set(ck, !state);
941         _chk_changed_cb(ad->pin_entry, ck, NULL);
942
943         __WFD_APP_FUNC_EXIT__;
944 }
945
946 static char *__wfd_password_label(void *data, Evas_Object *obj, const char *part)
947 {
948         __WFD_APP_FUNC_ENTER__;
949
950         if (data == NULL || part == NULL)
951                 return NULL;
952
953         WFD_APP_LOG(WFD_APP_LOG_LOW, "Part %s", part);
954
955         if (!strcmp("elm.text", part)) {
956                 __WFD_APP_FUNC_EXIT__;
957                 return g_strdup(" Show password");
958         }
959         __WFD_APP_FUNC_EXIT__;
960         return NULL;
961 }
962
963 static Evas_Object *__wfd_password_check(void *data, Evas_Object *obj,
964                 const char *part)
965 {
966         __WFD_APP_FUNC_ENTER__;
967         if (obj == NULL || part == NULL)
968                 return NULL;
969
970         wfd_appdata_t *ad = wfd_get_appdata();
971         WFD_RETV_IF(ad == NULL, NULL, "Incorrect parameter(NULL)\n");
972         Evas_Object *check = NULL;
973
974         WFD_APP_LOG(WFD_APP_LOG_LOW, "Part %s", part);
975
976         if (!strcmp("elm.swallow.icon", part)) {
977                 check = elm_check_add(obj);
978                 evas_object_propagate_events_set(check, EINA_FALSE);
979                 evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
980                 evas_object_size_hint_weight_set(check,
981                                 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
982                 evas_object_smart_callback_add(check, "changed",
983                                 _chk_changed_cb, ad->pin_entry);
984                 elm_object_focus_allow_set(check, EINA_FALSE);
985                 __WFD_APP_FUNC_EXIT__;
986                 return check;
987         }
988         __WFD_APP_FUNC_EXIT__;
989         return check;
990 }
991
992
993 /**
994  *      This function let the app create a keypad popup
995  *      @return   keypad popup
996  *      @param[in] win the window object
997  *      @param[in] pop the pointer to the prepared popup
998  */
999 Evas_Object *wfd_draw_pop_type_keypad(Evas_Object * win, wfd_popup_t * pop)
1000 {
1001         __WFD_APP_FUNC_ENTER__;
1002         wfd_appdata_t *ad = wfd_get_appdata();
1003         WFD_RETV_IF(ad == NULL, NULL, "Incorrect parameter(NULL)\n");
1004         wfd_connection_info_s *connection = ad->connection;
1005         WFD_RETV_IF(connection == NULL, NULL, "Incorrect parameter(NULL)\n");
1006
1007         Evas_Object *pinpopup = NULL;
1008         Evas_Object *btn1 = NULL, *btn2 = NULL;
1009         Evas_Object *genlist = NULL;
1010         Elm_Object_Item *git = NULL;
1011
1012         ad->timeout = pop->timeout;
1013
1014         pinpopup = elm_popup_add(ad->layout);
1015         elm_popup_align_set(pinpopup, ELM_NOTIFY_ALIGN_FILL, 1.0);
1016         eext_object_event_callback_add(pinpopup, EEXT_CALLBACK_BACK, eext_popup_back_cb,
1017                         NULL);
1018         evas_object_size_hint_weight_set(pinpopup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1019         elm_object_domain_translatable_part_text_set(pinpopup, "title,text",
1020                          PACKAGE, D_("IDS_WIFI_HEADER_WI_FI_DIRECT_CONNECTION_ABB"));
1021
1022         genlist = elm_genlist_add(pinpopup);
1023         elm_genlist_homogeneous_set(genlist, EINA_TRUE);
1024         evas_object_size_hint_weight_set(genlist,
1025                         EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1026         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
1027         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
1028         elm_scroller_content_min_limit(genlist, EINA_FALSE, EINA_TRUE);
1029
1030         /* Entry genlist item */
1031         ad->pin_desc_itc = elm_genlist_item_class_new();
1032         if (ad->pin_desc_itc != NULL) {
1033                 ad->pin_desc_itc->item_style = WFD_GENLIST_MULTILINE_TEXT_STYLE;
1034                 ad->pin_desc_itc->func.text_get = __wfd_main_desc_label_get;
1035                 ad->pin_desc_itc->func.content_get = NULL;
1036                 ad->pin_desc_itc->func.state_get = NULL;
1037                 ad->pin_desc_itc->func.del = NULL;
1038
1039                 git = elm_genlist_item_append(genlist, ad->pin_desc_itc, ad, NULL,
1040                                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
1041                 if (git != NULL)
1042                         elm_genlist_item_select_mode_set(git,
1043                                                  ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1044
1045                 keypad_popup_timeout = pop->timeout;
1046                 keypad_popup_timer = ecore_timer_add(1, _keypad_popup_timer_cb,
1047                                 ad->pin_desc_itc);
1048         }
1049
1050         ad->pin_entry_itc = elm_genlist_item_class_new();
1051         if (ad->pin_entry_itc != NULL) {
1052                 ad->pin_entry_itc->item_style = "entry";
1053                 ad->pin_entry_itc->func.text_get = NULL;
1054                 ad->pin_entry_itc->func.content_get = __wfd_pin_entry_icon_get;
1055                 ad->pin_entry_itc->func.state_get = NULL;
1056                 ad->pin_entry_itc->func.del = NULL;
1057
1058                 elm_genlist_item_append(genlist, ad->pin_entry_itc, pinpopup,
1059                                 NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
1060         }
1061
1062         ad->paswd_itc = elm_genlist_item_class_new();
1063         if (ad->paswd_itc != NULL) {
1064                 ad->paswd_itc->item_style = WFD_GENLIST_1LINE_TEXT_ICON_STYLE;
1065                 ad->paswd_itc->func.text_get = __wfd_password_label;
1066                 ad->paswd_itc->func.content_get = __wfd_password_check;
1067                 ad->paswd_itc->func.state_get = NULL;
1068                 ad->paswd_itc->func.del = NULL;
1069
1070                 elm_genlist_item_append(genlist, ad->paswd_itc, pinpopup,
1071                                 NULL, ELM_GENLIST_ITEM_NONE, _gl_pswd_check_box_sel, (void *)ad);
1072         }
1073
1074         btn1 = elm_button_add(pinpopup);
1075         elm_object_style_set(btn1, "popup");
1076         elm_object_domain_translatable_text_set(btn1, PACKAGE, pop->label2);
1077         elm_object_part_content_set(pinpopup, "button1", btn1);
1078         evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb,
1079                         (void *) (intptr_t) pop->resp_data2);
1080
1081         btn2 = elm_button_add(pinpopup);
1082         elm_object_style_set(btn2, "popup");
1083         elm_object_domain_translatable_text_set(btn2, PACKAGE, pop->label1);
1084         elm_object_part_content_set(pinpopup, "button2", btn2);
1085         evas_object_smart_callback_add(btn2, "clicked", __popup_resp_cb,
1086                         (void *) (intptr_t) pop->resp_data1);
1087 #if defined(GENLIST_REALIZATION_MOTE_SET)
1088         elm_genlist_realization_mode_set(genlist, EINA_TRUE);
1089 #endif
1090         evas_object_show(genlist);
1091         elm_object_content_set(pinpopup, genlist);
1092
1093         evas_object_show(pinpopup);
1094         evas_object_show(win);
1095         elm_object_focus_set(ad->pin_entry, EINA_TRUE);
1096
1097         __WFD_APP_FUNC_EXIT__;
1098         return pinpopup;
1099 }
1100
1101
1102 void _replace_int(char *haystack, int size, char *niddle, int value)
1103 {
1104         __WFD_APP_FUNC_ENTER__;
1105         char*buf = NULL;
1106         char *p = NULL;
1107         char *q = NULL;
1108
1109         if (haystack == NULL || niddle == NULL || size <= 1)
1110                 return;
1111
1112         buf = g_strdup(haystack);
1113         p = strstr(buf, niddle);
1114         if (p == NULL) {
1115                 free(buf);
1116                 return;
1117         }
1118         q = p + strlen(niddle);
1119         *p = '\0';
1120
1121         snprintf(haystack, size-1, "%s%d%s", buf, value, q);
1122         free(buf);
1123         __WFD_APP_FUNC_EXIT__;
1124 }
1125
1126 void _replace_1PS_2PD(char *buf, int buf_len, char *format_str, char* SD_1, int PD_2)
1127 {
1128         __WFD_APP_FUNC_ENTER__;
1129         char text[WFD_POP_STR_MAX_LEN] = {0, };
1130
1131         strncpy(text, format_str, WFD_POP_STR_MAX_LEN-1);
1132         _replace_int(text, WFD_POP_STR_MAX_LEN, "%d", PD_2);
1133         _replace_int(text, WFD_POP_STR_MAX_LEN, "%2$d", PD_2);
1134         snprintf(buf, buf_len-1, text, SD_1);
1135         __WFD_APP_FUNC_EXIT__;
1136 }
1137
1138
1139 /**
1140  *      This function let the app create a popup
1141  *      @return   void
1142  *      @param[in] type the type of popup
1143  *      @param[in] userdata the pointer to the data which will be used
1144  */
1145 void wfd_prepare_popup(int type, void *user_data)
1146 {
1147         __WFD_APP_FUNC_ENTER__;
1148         wfd_appdata_t *ad = wfd_get_appdata();
1149         wfd_popup_t *pop = ad->popup_data;
1150         wfd_connection_info_s *connection = ad->connection;
1151         char text[WFD_POP_STR_MAX_LEN+1] = {0, };
1152         char text1[WFD_POP_STR_MAX_LEN+1] = {0, };
1153         wfd_destroy_popup();
1154         char *peer_name;
1155         char *format_str = NULL;
1156
1157         peer_name = elm_entry_utf8_to_markup(connection->peer_name);
1158
1159         memset(pop, 0, sizeof(wfd_popup_t));
1160
1161         pop->type = type;
1162
1163         switch (pop->type) {
1164         case /* MT */ WFD_POP_APRV_CONNECTION_WPS_PUSHBUTTON_REQ:
1165
1166                 _replace_1PS_2PD((char *)pop->text, sizeof(pop->text),
1167                                 D_("IDS_WIFI_POP_CONNECT_TO_PS_IN_PD_SECONDS"),
1168                                 peer_name, WFD_POP_TIMER_120);
1169
1170                 snprintf(pop->label1, sizeof(pop->label1), "%s", D_("IDS_WIFI_SK2_OK"));
1171                 snprintf(pop->label2, sizeof(pop->label2), "%s", D_("IDS_WIFI_SK_CANCEL"));
1172                 pop->timeout = WFD_POP_TIMER_120;
1173                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_PBC_YES;
1174                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
1175
1176                 ad->popup = wfd_draw_pop_type_display(ad->win, pop);
1177                 break;
1178
1179         case /* MT */ WFD_POP_APRV_CONNECTION_WPS_DISPLAY_REQ:
1180                 format_str = D_("IDS_WIFI_BODY_PS_IS_REQUESTING_A_WI_FI_DIRECT_CONNECTION_ALLOW_Q");
1181                 snprintf(pop->text, sizeof(pop->text), format_str, peer_name);
1182                 snprintf(pop->label1, sizeof(pop->label1), "%s", D_("IDS_WIFI_BUTTON_ALLOW"));
1183                 snprintf(pop->label2, sizeof(pop->label2), "%s", D_("IDS_BR_SK_CANCEL"));
1184                 pop->timeout = WFD_POP_TIMER_120;
1185                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_DISPLAY_OK;
1186                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
1187
1188                 ad->popup = wfd_draw_pop_type_c(ad->win, pop);
1189                 break;
1190
1191         case /* MT */ WFD_POP_APRV_CONNECTION_WPS_KEYPAD_REQ:
1192                 _replace_1PS_2PD((char *)pop->text, sizeof(pop->text),
1193                                         D_("IDS_WIFI_POP_CONNECT_TO_PS_IN_PD_SECONDS"),
1194                                         peer_name, WFD_POP_TIMER_120);
1195                 snprintf(pop->label1, sizeof(pop->label1), "%s", D_("IDS_BR_SK_OK"));
1196                 snprintf(pop->label2, sizeof(pop->label2), "%s", D_("IDS_BR_SK_CANCEL"));
1197                 pop->timeout = WFD_POP_TIMER_120;
1198                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES;
1199                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
1200
1201                 ad->popup = wfd_draw_pop_type_display(ad->win, pop);
1202                 break;
1203
1204         case /* MT */ WFD_POP_PROG_CONNECT:
1205                 snprintf(pop->text, sizeof(pop->text), "%s", D_("IDS_WIFI_BODY_CONNECTING_ING"));
1206                 snprintf(pop->label1, sizeof(pop->label1), "%s", D_("IDS_BR_SK_CANCEL"));
1207                 pop->timeout = WFD_POP_TIMER_120;
1208                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_NO;
1209
1210                 ad->popup = wfd_draw_pop_type_b(ad->win, pop);
1211                 break;
1212
1213         case /* MO */ WFD_POP_PROG_CONNECT_WITH_KEYPAD:
1214                 _replace_1PS_2PD((char *)text, sizeof(text),
1215                                                 D_("IDS_WIFI_POP_CONNECT_TO_PS_IN_PD_SECONDS"),
1216                                                 peer_name, WFD_POP_TIMER_120);
1217
1218                 snprintf(text1, WFD_POP_STR_MAX_LEN, "%s %s",
1219                                 text, D_("IDS_WIFI_POP_ENTER_PIN_TO_CONNECT_TO_PS"));
1220
1221                 snprintf(pop->text, sizeof(pop->text), text1, connection->peer_name);
1222
1223                 snprintf(pop->label1, sizeof(pop->label1), "%s", D_("IDS_WIFI_SK_CONNECT"));
1224                 snprintf(pop->label2, sizeof(pop->label2), "%s", D_("IDS_BR_SK_CANCEL"));
1225                 pop->timeout = WFD_POP_TIMER_120;
1226                 pop->resp_data1 = WFD_POP_RESP_PROG_CONNECT_KEYPAD_OK;
1227                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
1228
1229                 ad->popup = wfd_draw_pop_type_keypad(ad->win, pop);
1230                 break;
1231
1232         case /* MO/MT */ WFD_POP_PROG_CONNECT_WITH_PIN:
1233                 _replace_1PS_2PD((char *)text, sizeof(text),
1234                                 D_("IDS_WIFI_POP_CONNECT_TO_PS_IN_PD_SECONDS"),
1235                                 peer_name, WFD_POP_TIMER_120);
1236
1237                 snprintf(text1, WFD_POP_STR_MAX_LEN, "%s %s %s",
1238                                 text,
1239                                 "<br>",
1240                                 D_("IDS_WIFI_POP_PIN_CODE_PS"));
1241                 snprintf(pop->text, sizeof(pop->text), text1, connection->wps_pin);
1242
1243                 snprintf(pop->label2, sizeof(pop->label2), "%s", D_("IDS_BR_SK_CANCEL"));
1244                 pop->timeout = WFD_POP_TIMER_120;
1245                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
1246
1247                 ad->popup = wfd_draw_pop_type_display(ad->win, pop);
1248                 break;
1249
1250         case WFD_POP_PROG_CONNECT_CANCEL:
1251                 snprintf(pop->text, sizeof(pop->text), "%s", D_("IDS_BR_SK_CANCEL"));
1252                 pop->timeout = WFD_POP_TIMER_120;
1253                 ad->popup = wfd_draw_pop_type_a(ad->win, pop);
1254                 break;
1255
1256         default:
1257                 break;
1258         }
1259
1260         /* feedback play */
1261         int ret = -1;
1262         ret = feedback_play(FEEDBACK_PATTERN_GENERAL);
1263         if (ret != FEEDBACK_ERROR_NONE)
1264                 WFD_APP_LOG(WFD_APP_LOG_ERROR, "feedback_play error : %d\n", ret);
1265
1266         WFD_IF_FREE_MEM(peer_name);
1267         __WFD_APP_FUNC_EXIT__;
1268         return;
1269 }