Black theme applyed
[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.1 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9
10 * http://floralicense.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 <notification.h>
32 #include <efl_assist.h>
33
34 #include "wifi-direct.h"
35 #include "wfd-app.h"
36 #include "wfd-app-strings.h"
37 #include "wfd-app-util.h"
38
39 extern wfd_appdata_t *g_wfd_ad;
40 extern wfd_popup_t *g_wfd_pop;
41 extern unsigned char g_wfd_peer_mac[6];
42 extern unsigned char g_wfd_peer_name[32];
43 static Ecore_Timer *pb_timer = NULL;
44
45
46 /**
47  *      This function let the ug make a callback for click the button in popup
48  *      @return   void
49  *      @param[in] data the pointer to the main data structure
50  *      @param[in] obj the pointer to the evas object
51  *      @param[in] event_info the pointer to the event information
52  */
53 static void __popup_resp_cb(void *data, Evas_Object * obj, void *event_info)
54 {
55         __WDPOP_LOG_FUNC_ENTER__;
56         wfd_appdata_t *ad = wfd_get_appdata();
57         int result = -1;
58         int resp = (int) data;
59         char msg[WFD_POP_STR_MAX_LEN] = {0};
60
61         WDPOP_LOGI( "popup resp : %d\n", resp);
62
63         switch (resp) {
64         case /* MT */ WFD_POP_RESP_APRV_CONNECT_PBC_YES:
65         {
66                 WDPOP_LOGI(
67                                 "WFD_POP_RESP_APRV_CONNECT_PBC_YES\n");
68                 wfd_destroy_popup();
69
70                 result = wifi_direct_accept_connection(ad->peer_mac);
71                 WDPOP_LOGD(
72                                 "wifi_direct_accept_connection() result=[%d]\n",
73                                 result);
74                 if (result == WIFI_DIRECT_ERROR_NONE) {
75                         /* tickernoti popup */
76                         notification_status_message_post(_("IDS_WFD_POP_CONNECTING"));
77                 } else {
78                         WDPOP_LOGE(
79                                         "wifi_direct_accept_connection() FAILED!!\n");
80                         evas_object_hide(ad->win);
81
82                         /* tickernoti popup */
83                         snprintf(msg, WFD_POP_STR_MAX_LEN, IDS_WFD_POP_CONNECT_FAILED, ad->peer_name);
84                         notification_status_message_post(msg);
85                 }
86         }
87         break;
88
89         case WFD_POP_RESP_APRV_CONNECT_INVITATION_YES:
90                 WDPOP_LOGI(
91                                 "WFD_POP_RESP_APRV_CONNECT_INVITATION_YES [" MACSTR "]\n", MAC2STR(ad->peer_mac));
92                 wfd_destroy_popup();
93
94                 result = wifi_direct_connect(ad->peer_mac);
95                 WDPOP_LOGD(
96                                 "wifi_direct_connect() result=[%d]\n",
97                                 result);
98                 if (result == WIFI_DIRECT_ERROR_NONE) {
99                         /* tickernoti popup */
100                         notification_status_message_post(_("IDS_WFD_POP_CONNECTING"));
101                 } else {
102                         WDPOP_LOGE(
103                                         "wifi_direct_connect() FAILED!!\n");
104                         evas_object_hide(ad->win);
105
106                         /* tickernoti popup */
107                         snprintf(msg, WFD_POP_STR_MAX_LEN, IDS_WFD_POP_CONNECT_FAILED, ad->peer_name);
108                         notification_status_message_post(msg);
109                 }
110
111         break;
112
113         case /* MT */ WFD_POP_RESP_APRV_CONNECT_DISPLAY_OK:
114         {
115                 char *pin = NULL;
116
117                 WDPOP_LOGI(
118                                 "WFD_POP_RESP_APRV_CONNECT_DISPLAY_OK\n");
119                 wfd_destroy_popup();
120
121                 if (wifi_direct_generate_wps_pin() != WIFI_DIRECT_ERROR_NONE) {
122                         WDPOP_LOGD( "wifi_direct_generate_wps_pin() is failed\n");
123                         return;
124                 }
125
126                 if (wifi_direct_get_wps_pin(&pin) != WIFI_DIRECT_ERROR_NONE) {
127                         WDPOP_LOGD( "wifi_direct_generate_wps_pin() is failed\n");
128                         return;
129                 }
130
131                 strncpy(ad->pin_number, pin, 64);
132                 ad->pin_number[63] = '\0';
133                 free(pin);
134                 pin = NULL;
135                 WDPOP_LOGD( "button ok: pin [%s]", ad->pin_number);
136
137                 result = wifi_direct_accept_connection(ad->peer_mac);
138                 if (result == WIFI_DIRECT_ERROR_NONE) {
139                         wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_PIN, NULL);
140                 } else {
141                         WDPOP_LOGD(
142                                 "wifi_direct_accept_connection() failed. result=[%d]\n", result);
143                         /* tickernoti popup */
144                         snprintf(msg, WFD_POP_STR_MAX_LEN, IDS_WFD_POP_CONNECT_FAILED, ad->peer_name);
145                         notification_status_message_post(msg);
146                 }
147         }
148         break;
149
150         case /* MO */ WFD_POP_RESP_PROG_CONNECT_KEYPAD_OK:
151         {
152                 WDPOP_LOGI(
153                                 "WFD_POP_RESP_PROG_CONNECT_KEYPAD_OK\n");
154
155                 wfd_destroy_popup();
156
157                 int len = strlen(ad->pin_number);
158                 WDPOP_LOGD( "button ok: pin [%s]", ad->pin_number);
159
160                 if (len != 8) {
161                         if (len > 8)
162                                 notification_status_message_post(_("IDS_CST_BODY_PASSWORD_TOO_LONG"));
163                         else
164                                 notification_status_message_post(_("IDS_ST_BODY_PASSWORD_TOO_SHORT"));
165                         wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_KEYPAD, (void *) NULL);
166                         return;
167                 }
168
169                 int result = 0;
170                 WDPOP_LOGD( "pin=[%s]\n", ad->pin_number);
171
172                 result = wifi_direct_set_wps_pin(ad->pin_number);
173                 if (result != WIFI_DIRECT_ERROR_NONE) {
174                         /* tickernoti popup */
175                         snprintf(msg, WFD_POP_STR_MAX_LEN, IDS_WFD_POP_CONNECT_FAILED, ad->peer_name);
176                         notification_status_message_post(msg);
177                         return;
178                 }
179
180                 //result = wifi_direct_activate_pushbutton();
181                 result = wifi_direct_accept_connection(ad->peer_mac);
182                 WDPOP_LOGD(
183                                 "wifi_direct_accept_connection(%s) result=[%d]\n",
184                                 ad->peer_mac, result);
185                 if (result != WIFI_DIRECT_ERROR_NONE) {
186                         WDPOP_LOGE(
187                                         "wifi_direct_accept_connection() FAILED!!\n");
188                         evas_object_hide(ad->win);
189
190                         /* tickernoti popup */
191                         snprintf(msg, WFD_POP_STR_MAX_LEN, IDS_WFD_POP_CONNECT_FAILED, ad->peer_name);
192                         notification_status_message_post(msg);
193                 }
194         }
195         break;
196
197         case /* MT */ WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES:
198         {
199                 WDPOP_LOGI(
200                                 "WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES\n");
201                 wfd_destroy_popup();
202                 if (pb_timer) {
203                         ecore_timer_del(pb_timer);
204                         pb_timer = NULL;
205                 }
206
207                 wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_KEYPAD, (void *) NULL);
208         }
209         break;
210
211         case /* MT */ WFD_POP_RESP_APRV_CONNECT_NO:
212         {
213                 WDPOP_LOGI(
214                                 "WFD_POP_RESP_APRV_CONNECT_NO: destroy_popup...\n");
215
216                 wfd_destroy_popup();
217                 if (pb_timer) {
218                         ecore_timer_del(pb_timer);
219                         pb_timer = NULL;
220                 }
221
222                 result = wifi_direct_disconnect(ad->peer_mac);
223                 WDPOP_LOGD(
224                                 "wifi_direct_disconnect[%s] result=[%d]\n",
225                                 ad->peer_mac, result);
226         }
227         break;
228
229         default:
230         {
231                 WDPOP_LOGE( "Unknown respone\n");
232                 evas_object_hide(ad->win);
233         }
234         break;
235         }
236
237         __WDPOP_LOG_FUNC_EXIT__;
238 }
239
240 /**
241  *      This function let the app destroy the popup
242  *      @return   void
243  *      @param[in] null
244  */
245 void wfd_destroy_popup()
246 {
247         __WDPOP_LOG_FUNC_ENTER__;
248         wfd_appdata_t *ad = wfd_get_appdata();
249
250         if (ad == NULL) {
251                 WDPOP_LOGE( "ad is NULL\n");
252                 return;
253         }
254
255         if (ad->popup) {
256                 evas_object_del(ad->popup);
257                 ad->popup = NULL;
258         }
259
260         if (ad->popup_timeout_handle > 0) {
261                 g_source_remove(ad->popup_timeout_handle);
262                 ad->popup_timeout_handle = 0;
263         }
264
265         evas_object_hide(ad->win);
266
267         __WDPOP_LOG_FUNC_EXIT__;
268         return;
269 }
270
271 /**
272  *      This function let the app create a popup which includes no button
273  *      @return   popup
274  *      @param[in] win the window object
275  *      @param[in] pop the pointer to the prepared popup
276  */
277 static Evas_Object *wfd_draw_pop_type_a(Evas_Object * win, wfd_popup_t * pop)
278 {
279         __WDPOP_LOG_FUNC_ENTER__;
280         Evas_Object *popup;
281
282         popup = elm_popup_add(win);
283         ea_object_event_callback_add(popup, EA_CALLBACK_BACK, ea_popup_back_cb, NULL);
284         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
285         elm_object_text_set(popup, pop->text);
286         elm_popup_timeout_set(popup, pop->timeout);
287         evas_object_show(popup);
288         evas_object_show(win);
289
290         __WDPOP_LOG_FUNC_EXIT__;
291         return popup;
292 }
293
294 /**
295  *      This function let the app create a popup which includes one button
296  *      @return   popup
297  *      @param[in] win the window object
298  *      @param[in] pop the pointer to the prepared popup
299  */
300 static Evas_Object *wfd_draw_pop_type_b(Evas_Object * win, wfd_popup_t * pop)
301 {
302         __WDPOP_LOG_FUNC_ENTER__;
303         Evas_Object *popup = NULL;
304         Evas_Object *btn = NULL;
305
306         popup = elm_popup_add(win);
307         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
308         elm_object_text_set(popup, pop->text);
309
310         btn = elm_button_add(popup);
311         elm_object_style_set(btn, "popup_button/default");
312         elm_object_text_set(btn, pop->label1);
313         elm_object_part_content_set(popup, "button1", btn);
314         evas_object_smart_callback_add(btn, "clicked", __popup_resp_cb, (void *) pop->resp_data1);
315         ea_object_event_callback_add(popup, EA_CALLBACK_BACK, __popup_resp_cb, (void*) pop->resp_data1);
316
317         evas_object_show(popup);
318         evas_object_show(win);
319
320         __WDPOP_LOG_FUNC_EXIT__;
321         return popup;
322 }
323
324 /**
325  *      This function let the app create a popup which includes two buttons
326  *      @return   popup
327  *      @param[in] win the window object
328  *      @param[in] pop the pointer to the prepared popup
329  */
330 static Evas_Object *wfd_draw_pop_type_c(Evas_Object * win, wfd_popup_t * pop)
331 {
332         __WDPOP_LOG_FUNC_ENTER__;
333         Evas_Object *popup = NULL;
334         Evas_Object *btn1 = NULL, *btn2 = NULL;
335
336         popup = elm_popup_add(win);
337         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
338         elm_object_text_set(popup, pop->text);
339
340         btn1 = elm_button_add(popup);
341         elm_object_style_set(btn1, "popup_button/default");
342         elm_object_text_set(btn1, pop->label1);
343         elm_object_part_content_set(popup, "button1", btn1);
344         evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb,
345                 (void*) pop->resp_data1);
346
347         btn2 = elm_button_add(popup);
348         elm_object_style_set(btn2, "popup_button/default");
349         elm_object_text_set(btn2, pop->label2);
350         elm_object_part_content_set(popup, "button2", btn2);
351         evas_object_smart_callback_add(btn2, "clicked", __popup_resp_cb,
352                 (void*) pop->resp_data2);
353         ea_object_event_callback_add(popup, EA_CALLBACK_BACK, __popup_resp_cb,
354                 (void*) pop->resp_data2);
355
356         evas_object_show(popup);
357         evas_object_show(win);
358
359         __WDPOP_LOG_FUNC_EXIT__;
360         return popup;
361 }
362
363 /**
364  *      This function let the ug make a change callback for password input
365  *      @return   void
366  *      @param[in] data the pointer to the main data structure
367  *      @param[in] obj the pointer to the evas object
368  *      @param[in] event_info the pointer to the event information
369  */
370 static void _smart_ime_cb(void *data, Evas_Object * obj, void *event_info)
371 {
372         __WDPOP_LOG_FUNC_ENTER__;
373         wfd_appdata_t *ad = wfd_get_appdata();
374
375         Ecore_IMF_Context *imf_context = NULL;
376         imf_context = (Ecore_IMF_Context *) ad->pin_entry;
377
378         if (NULL == imf_context) {
379                 WDPOP_LOGE( "Error!!! Ecore_IMF_Context is NULL!!");
380                 return;
381         }
382
383         const char *txt = elm_entry_markup_to_utf8(elm_entry_entry_get((const Evas_Object *) imf_context));
384         if (NULL != txt) {
385                 WDPOP_LOGD( "* text [%s], len=[%d]", txt, strlen(txt));
386                 strncpy(ad->pin_number, txt, 64);
387                 ad->pin_number[63] = '\0';
388                 free(txt);
389         } else {
390                 WDPOP_LOGD( "Err!");
391         }
392
393         __WDPOP_LOG_FUNC_EXIT__;
394 }
395
396 /**
397  *      This function let the app make a change callback for password checkbox
398  *      @return   void
399  *      @param[in] data the pointer to the main data structure
400  *      @param[in] obj the pointer to the evas object
401  *      @param[in] event_info the pointer to the event information
402  */
403 static void _check_changed_cb(void *data, Evas_Object * obj, void *event_info)
404 {
405         wfd_appdata_t *ad = wfd_get_appdata();
406
407         if (obj == NULL) {
408                 return;
409         }
410
411         Eina_Bool state = elm_check_state_get(obj);
412         elm_entry_password_set(ad->pin_entry, !state);
413         elm_entry_autocapital_type_set(ad->pin_entry, ELM_AUTOCAPITAL_TYPE_NONE);
414 }
415
416 /**
417  *      This function let the app make a callback for progressbar timer
418  *      @return   if stop the timer, return ECORE_CALLBACK_CANCEL, else return ECORE_CALLBACK_RENEW
419  *      @param[in] data the pointer to the wps structure
420  */
421 static Eina_Bool _fn_pb_timer(void *data)
422 {
423         int step = 0;
424         double value = 0.0;
425         char time_label[32] = {0};
426         wfd_wps_display_popup_t *wps_display_popup = (wfd_wps_display_popup_t *) data;
427
428         if (NULL == wps_display_popup) {
429                 WDPOP_LOGE( "Param is NULL.\n");
430                 return ECORE_CALLBACK_CANCEL;
431         }
432
433         Evas_Object *progressbar = NULL;
434         Evas_Object *time = NULL;
435
436         progressbar = wps_display_popup->progressbar;
437         time = wps_display_popup->time;
438         value = elm_progressbar_value_get(progressbar);
439
440         if (value >= 1.0) {
441                 WDPOP_LOGE( "Progress end.\n");
442                 if (pb_timer) {
443                         ecore_timer_del(pb_timer);
444                         pb_timer = NULL;
445                 }
446                 wfd_destroy_popup();
447                 return ECORE_CALLBACK_CANCEL;
448         }
449
450         wps_display_popup->step++;
451         step = wps_display_popup->step;
452         value = ((double)step) / WFD_POP_TIMER_120;
453         elm_progressbar_value_set(progressbar, value);
454         WDPOP_LOGD( "step: %d, value: %f\n", wps_display_popup->step, value);
455
456         /* show the time label */
457         if (step < 60) {
458                 if (step < 10) {
459                         snprintf(time_label, 32, "00:0%d", step);
460                 } else {
461                         snprintf(time_label, 32, "00:%d", step);
462                 }
463         } else {
464                 if (step%60 < 10) {
465                         snprintf(time_label, 32, "0%d:0%d", step/60, step%60);
466                 } else {
467                         snprintf(time_label, 32, "0%d:%d", step/60, step%60);
468                 }
469         }
470
471         elm_object_text_set(time, time_label);
472
473         return ECORE_CALLBACK_RENEW;
474 }
475
476 /**
477  *      This function let the app create a edit filed
478  *      @return   edit filed
479  *      @param[in] parent the parent object
480  *      @param[in] title the pointer to the title of edit field
481  *      @param[in] guide the pointer to the text of guide
482  *      @param[in] single_line whether it can support single line
483  *      @param[in] is_editable whether it is avaliable to edit
484  */
485 static Evas_Object *_add_edit_field(Evas_Object *parent, const char *title, const char *guide, Eina_Bool single_line, Eina_Bool is_editable)
486 {
487         assertm_if(NULL == parent, "parent is NULL!!");
488
489         Evas_Object *layout = elm_layout_add(parent);
490         assertm_if(NULL == layout, "layout is NULL!!");
491
492         if (title && title[0] != '\0') {
493                 elm_layout_theme_set(layout, "layout", "editfield", "title");
494                 elm_object_part_text_set(layout, "elm.text", title);
495         } else {
496                 elm_layout_theme_set(layout, "layout", "editfield", "default");
497         }
498
499         Evas_Object *entry = elm_entry_add(parent);
500         assertm_if(NULL == entry, "entry is NULL!!");
501
502         elm_object_part_content_set(layout, "elm.swallow.content", entry);
503         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
504
505         if (guide && guide[0] != '\0') {
506                 elm_object_part_text_set(layout, "elm.guidetext", guide);
507         }
508
509         elm_entry_single_line_set(entry, single_line);
510         elm_entry_scrollable_set(entry, single_line);
511         elm_entry_editable_set(entry, is_editable);
512         elm_object_signal_emit(layout, "elm,state,eraser,hide", "elm");
513         evas_object_show(layout);
514
515         return layout;
516 }
517
518 /**
519  *      This function let the app create a display popup
520  *      @return   display popup
521  *      @param[in] win the window object
522  *      @param[in] pop the pointer to the prepared popup
523  */
524 Evas_Object *wfd_draw_pop_type_display(Evas_Object * win, wfd_popup_t * pop)
525 {
526         __WDPOP_LOG_FUNC_ENTER__;
527
528         Evas_Object *popup = NULL;
529         Evas_Object *label = NULL;
530         Evas_Object *progressbar = NULL;
531         Evas_Object *time = NULL;
532         static wfd_wps_display_popup_t wps_display_popup;
533
534         popup = elm_popup_add(win);
535         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, 0.0);
536
537         Evas_Object *box = elm_box_add(popup);
538         if (!box) {
539                 evas_object_del(popup);
540                 popup = NULL;
541                 return NULL;
542         }
543
544         evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, 0.0);
545         evas_object_size_hint_align_set(box, EVAS_HINT_FILL, 0.0);
546         elm_object_part_content_set(popup, NULL, box);
547         evas_object_show(box);
548
549         /* add label */
550         label = elm_label_add(box);
551         elm_object_style_set(label, "popup/default");
552         elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
553         elm_object_text_set(label, pop->text);
554         evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
555         evas_object_size_hint_align_set(label, EVAS_HINT_FILL, 0.0);
556         elm_box_pack_end(box, label);
557         evas_object_show(label);
558
559         /* add progressbar */
560         progressbar = elm_progressbar_add(box);
561         elm_object_style_set(progressbar, "list_progress");
562         elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
563         evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, 0.0);
564         evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, 0.0);
565         elm_progressbar_value_set(progressbar, 0.0);
566         elm_box_pack_end(box, progressbar);
567         evas_object_show(progressbar);
568
569         /* add time */
570         time = elm_label_add(box);
571         elm_object_style_set(time, "popup/default");
572         elm_object_text_set(time, "00:00");
573         evas_object_size_hint_weight_set(time, EVAS_HINT_EXPAND, 0.0);
574         evas_object_size_hint_align_set(time, EVAS_HINT_FILL, 0.0);
575         elm_box_pack_end(box, time);
576         evas_object_show(time);
577
578         /* start progressbar timer */
579         wps_display_popup.step = 0;
580         wps_display_popup.progressbar = progressbar;
581         wps_display_popup.time = time;
582         if(pb_timer)
583                 ecore_timer_del(pb_timer);
584         pb_timer = ecore_timer_add(1, _fn_pb_timer, &wps_display_popup);
585
586         /* add buttons */
587         if (pop->resp_data1 == WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES ||
588                 pop->resp_data1 == WFD_POP_RESP_APRV_CONNECT_NO) {
589                 Evas_Object *btn1 = NULL;
590                 btn1 = elm_button_add(popup);
591                 elm_object_style_set(btn1, "popup_button/default");
592                 elm_object_text_set(btn1, pop->label1);
593                 elm_object_part_content_set(popup, "button1", btn1);
594                 evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb,
595                         (void*) pop->resp_data1);
596         }
597
598         if (pop->resp_data2 == WFD_POP_RESP_APRV_CONNECT_NO) {
599                 Evas_Object *btn2 = NULL;
600                 btn2 = elm_button_add(popup);
601                 elm_object_style_set(btn2, "popup_button/default");
602                 elm_object_text_set(btn2, pop->label2);
603                 elm_object_part_content_set(popup, "button2", btn2);
604                 evas_object_smart_callback_add(btn2, "clicked", __popup_resp_cb,
605                         (void*) pop->resp_data2);
606                 ea_object_event_callback_add(popup, EA_CALLBACK_BACK, __popup_resp_cb,
607                         (void*) pop->resp_data2);
608         }
609
610         elm_object_content_set(popup, box);
611         evas_object_show(popup);
612         evas_object_show(win);
613
614         __WDPOP_LOG_FUNC_EXIT__;
615         return popup;
616 }
617
618 /**
619  *      This function let the app create a keypad popup
620  *      @return   keypad popup
621  *      @param[in] win the window object
622  *      @param[in] pop the pointer to the prepared popup
623  */
624 Evas_Object *wfd_draw_pop_type_keypad(Evas_Object * win, wfd_popup_t * pop)
625 {
626         __WDPOP_LOG_FUNC_ENTER__;
627         wfd_appdata_t *ad = wfd_get_appdata();
628
629         Evas_Object *conformant = NULL;
630         Evas_Object *layout = NULL;
631         Evas_Object *pinpopup = NULL;
632         Evas_Object *label = NULL;
633         Evas_Object *btn1 = NULL, *btn2 = NULL;
634
635         conformant = elm_conformant_add(win);
636         assertm_if(NULL == conformant, "conformant is NULL!!");
637         elm_win_conformant_set(win, EINA_TRUE);
638         elm_win_resize_object_add(win, conformant);
639         evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, 0.0);
640         evas_object_size_hint_align_set(conformant, EVAS_HINT_FILL, 0.0);
641         evas_object_show(conformant);
642
643         layout = elm_layout_add(conformant);
644         elm_object_content_set(conformant, layout);
645
646         pinpopup = elm_popup_add(layout);
647         assertm_if(NULL == pinpopup, "pinpopup is NULL!!");
648         evas_object_size_hint_weight_set(pinpopup, EVAS_HINT_EXPAND, 0.0);
649         elm_object_part_text_set(pinpopup, "title,text", _("IDS_WFD_POP_TITILE_CONNECTION"));
650
651         Evas_Object *box = elm_box_add(pinpopup);
652         if (!box) {
653                 evas_object_del(pinpopup);
654                 pinpopup = NULL;
655                 return NULL;
656         }
657
658         evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, 0.0);
659         evas_object_size_hint_align_set(box, EVAS_HINT_FILL, 0.0);
660         elm_object_part_content_set(pinpopup, NULL, box);
661         evas_object_show(box);
662
663         /* add label */
664         label = elm_label_add(box);
665         elm_object_style_set(label, "popup/default");
666         elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
667         elm_object_text_set(label, pop->text);
668         evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
669         evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
670         elm_box_pack_end(box, label);
671         evas_object_show(label);
672
673         /* add password */
674         Evas_Object *body = elm_layout_add(box);
675         if (!body) {
676                 evas_object_del(pinpopup);
677                 pinpopup = NULL;
678                 return NULL;
679         }
680
681         elm_layout_theme_set(body, "layout", "dialogue", "1icon");
682         evas_object_size_hint_weight_set(body, EVAS_HINT_EXPAND, 0.0);
683         evas_object_size_hint_align_set(body, EVAS_HINT_FILL, 0.0);
684
685         Evas_Object *editfield_pin = _add_edit_field(body, NULL, NULL, EINA_TRUE, EINA_TRUE);
686         Evas_Object *entry_pin = elm_object_part_content_get(editfield_pin, "elm.swallow.content");
687         ad->pin_entry = entry_pin;
688         evas_object_smart_callback_add(ad->pin_entry, "changed", _smart_ime_cb, NULL);
689         elm_object_part_content_set(body, "elm.icon", editfield_pin);
690         elm_box_pack_end(box, body);
691         evas_object_show(body);
692
693         elm_entry_password_set(ad->pin_entry, TRUE);
694
695         Evas_Object *check = elm_check_add(box);
696         elm_object_text_set(check, _("Show password"));
697         elm_object_focus_allow_set(check, EINA_FALSE);
698         evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, 0.0);
699         evas_object_size_hint_align_set(check, EVAS_HINT_FILL, 0.0);
700         evas_object_smart_callback_add(check, "changed", _check_changed_cb, NULL);
701         evas_object_show(check);
702         elm_box_pack_end(box, check);
703
704         /* add buttons */
705         btn1 = elm_button_add(pinpopup);
706         elm_object_style_set(btn1, "popup_button/default");
707         elm_object_text_set(btn1, pop->label1);
708         elm_object_part_content_set(pinpopup, "button1", btn1);
709         evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb, (void *)pop->resp_data1);
710
711         btn2 = elm_button_add(pinpopup);
712         elm_object_style_set(btn2, "popup_button/default");
713         elm_object_text_set(btn2, pop->label2);
714         elm_object_part_content_set(pinpopup, "button2", btn2);
715         evas_object_smart_callback_add(btn2, "clicked", __popup_resp_cb, (void *)pop->resp_data2);
716         ea_object_event_callback_add(pinpopup, EA_CALLBACK_BACK, __popup_resp_cb,
717                 (void*) pop->resp_data2);
718
719         elm_object_content_set(pinpopup, box);
720         evas_object_show(pinpopup);
721         evas_object_show(win);
722         elm_object_focus_set(ad->pin_entry, EINA_TRUE);
723
724         __WDPOP_LOG_FUNC_EXIT__;
725         return pinpopup;
726 }
727
728 /**
729  *      This function let the app create a popup
730  *      @return   void
731  *      @param[in] type the type of popup
732  *      @param[in] userdata the pointer to the data which will be used
733  */
734 void wfd_prepare_popup(int type, void *userdata)
735 {
736         __WDPOP_LOG_FUNC_ENTER__;
737         wfd_appdata_t *ad = wfd_get_appdata();
738         wfd_popup_t *pop = ad->popup_data;
739
740         wfd_destroy_popup();
741
742         memset(pop, 0, sizeof(wfd_popup_t));
743
744         pop->type = type;
745
746         switch (pop->type) {
747         case /* MT */ WFD_POP_APRV_CONNECTION_WPS_PUSHBUTTON_REQ:
748                 snprintf(pop->text, sizeof(pop->text), IDS_WFD_POP_CONNECT_Q,
749                                 ad->peer_name);
750                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_SK_YES"));
751                 snprintf(pop->label2, sizeof(pop->label2), "%s", dgettext("sys_string", "IDS_COM_SK_NO"));
752                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_PBC_YES;
753                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
754
755                 ad->popup = wfd_draw_pop_type_c(ad->win, pop);
756                 break;
757
758         case WFD_POP_APRV_CONNECTION_INVITATION_REQ:
759                 snprintf(pop->text, sizeof(pop->text), IDS_WFD_POP_CONNECT_Q,
760                                 ad->peer_name);
761                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_SK_YES"));
762                 snprintf(pop->label2, sizeof(pop->label2), "%s", dgettext("sys_string", "IDS_COM_SK_NO"));
763                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_INVITATION_YES;
764                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
765
766                 ad->popup = wfd_draw_pop_type_c(ad->win, pop);
767                 break;
768
769         case /* MT */ WFD_POP_APRV_CONNECTION_WPS_DISPLAY_REQ:
770                 snprintf(pop->text, sizeof(pop->text), IDS_WFD_POP_ENTER_PIN_WITH_KEYPAD,
771                                 ad->peer_name);
772                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_SK_OK"));
773                 snprintf(pop->label2, sizeof(pop->label2), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL"));
774                 pop->timeout = WFD_POP_TIMER_120;
775                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_DISPLAY_OK;
776                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
777
778                 ad->popup = wfd_draw_pop_type_c(ad->win, pop);
779                 break;
780
781         case /* MT */ WFD_POP_APRV_CONNECTION_WPS_KEYPAD_REQ:
782                 snprintf(pop->text, sizeof(pop->text), IDS_WFD_POP_ENTER_PIN,
783                                 ad->peer_name, WFD_POP_TIMER_120);
784                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_SK_OK"));
785                 snprintf(pop->label2, sizeof(pop->label2), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL"));
786                 pop->timeout = WFD_POP_TIMER_120;
787                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES;
788                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
789
790                 ad->popup = wfd_draw_pop_type_c(ad->win, pop);
791                 break;
792
793         case /* MT */ WFD_POP_PROG_CONNECT:
794                 snprintf(pop->text, sizeof(pop->text), "%s", _("IDS_WFD_POP_CONNECTING"));
795                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL"));
796                 pop->timeout = WFD_POP_TIMER_120;
797                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_NO;
798
799                 ad->popup = wfd_draw_pop_type_b(ad->win, pop);
800                 break;
801
802         case /* MO */ WFD_POP_PROG_CONNECT_WITH_KEYPAD:
803                 snprintf(pop->text, sizeof(pop->text), IDS_WFD_POP_CONNECTING_WITH_KEYPAD,
804                                 ad->peer_name, WFD_POP_TIMER_120, ad->peer_name);
805                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_SK_OK"));
806                 snprintf(pop->label2, sizeof(pop->label2), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL"));
807                 pop->timeout = WFD_POP_TIMER_120;
808                 pop->resp_data1 = WFD_POP_RESP_PROG_CONNECT_KEYPAD_OK;
809                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
810
811                 ad->popup = wfd_draw_pop_type_keypad(ad->win, pop);
812                 break;
813
814         case /* MO/MT */ WFD_POP_PROG_CONNECT_WITH_PIN:
815                 snprintf(pop->text, sizeof(pop->text), IDS_WFD_POP_CONNECTING_WITH_PIN,
816                         ad->peer_name, WFD_POP_TIMER_120, ad->pin_number);
817                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL"));
818                 pop->timeout = WFD_POP_TIMER_120;
819                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_NO;
820
821                 ad->popup = wfd_draw_pop_type_display(ad->win, pop);
822                 break;
823
824         case WFD_POP_PROG_CONNECT_CANCEL:
825                 snprintf(pop->text, sizeof(pop->text), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL"));
826                 pop->timeout = WFD_POP_TIMER_120;
827                 ad->popup = wfd_draw_pop_type_a(ad->win, pop);
828                 break;
829
830         default:
831                 break;
832         }
833
834         __WDPOP_LOG_FUNC_EXIT__;
835         return;
836 }