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