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