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