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