fixed text bug
[apps/home/ug-wifi-direct.git] / popup-wifidirect / src / wfd-app-popup-view.c
1 /*
2 *  WiFi-Direct UG
3 *
4 * Copyright 2012  Samsung Electronics Co., Ltd
5
6 * Licensed under the Flora License, Version 1.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9
10 * http://www.tizenopensource.org/license
11
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20 /**
21  * This file implements wifi direct system popup view  functions.
22  *
23  * @file    wfd-app-popup-view.c
24  * @author  Sungsik Jang (sungsik.jang@samsung.com)
25  * @version 0.1
26  */
27
28 #include <libintl.h>
29 #include <glib.h>
30
31 #include "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 static void __popup_resp_cb(void *data, Evas_Object * obj, void *event_info)
45 {
46         __WFD_APP_FUNC_ENTER__;
47
48         wfd_appdata_t *ad = wfd_get_appdata();
49         int result = -1;
50         int resp = (int) data;
51         Evas_Object *btn = obj;
52         char msg[WFD_POP_STR_MAX_LEN] = {0};
53
54         WFD_APP_LOG(WFD_APP_LOG_HIGH, "popup resp : %d\n", resp);
55
56         switch (resp)
57         {
58         case /* MT */ WFD_POP_RESP_APRV_CONNECT_PBC_YES:
59         {
60                 WFD_APP_LOG(WFD_APP_LOG_HIGH,
61                                 "WFD_POP_RESP_APRV_CONNECT_PBC_YES\n");
62                 wfd_destroy_popup();
63
64                 result = wifi_direct_accept_connection(ad->peer_mac);
65                 WFD_APP_LOG(WFD_APP_LOG_LOW,
66                                 "wifi_direct_accept_connection() result=[%d]\n",
67                                 result);
68                 if (result == WIFI_DIRECT_ERROR_NONE)
69                 {
70                         /* tickernoti popup */
71                         wfd_tickernoti_popup(_("IDS_WFD_POP_CONNECTING"));
72                 }
73                 else
74                 {
75                         WFD_APP_LOG(WFD_APP_LOG_ERROR,
76                                         "wifi_direct_accept_connection() FAILED!!\n");
77                         evas_object_hide(ad->win);
78
79                         /* tickernoti popup */
80                         snprintf(msg, WFD_POP_STR_MAX_LEN, _("IDS_WFD_POP_CONNECT_FAILED"), ad->peer_name);
81                         wfd_tickernoti_popup(msg);
82                 }
83         }
84         break;
85
86         case /* MT */ WFD_POP_RESP_APRV_CONNECT_DISPLAY_YES:
87         {
88                 char *pin = NULL;
89
90                 WFD_APP_LOG(WFD_APP_LOG_HIGH,
91                                 "WFD_POP_RESP_APRV_CONNECT_DISPLAY_YES\n");
92                 wfd_destroy_popup();
93                 if (pb_timer) {
94                         ecore_timer_del(pb_timer);
95                         pb_timer = NULL;
96                 }
97
98                 if (wifi_direct_generate_wps_pin() != WIFI_DIRECT_ERROR_NONE)
99                 {
100                         WFD_APP_LOG(WFD_APP_LOG_LOW, "wifi_direct_generate_wps_pin() is failed\n");
101                         return;
102                 }
103
104                 if (wifi_direct_get_wps_pin(&pin) != WIFI_DIRECT_ERROR_NONE)
105                 {
106                         WFD_APP_LOG(WFD_APP_LOG_LOW, "wifi_direct_generate_wps_pin() is failed\n");
107                         return;
108                 }
109                 strncpy(ad->pin_number, pin, 32);
110                 free(pin);
111                 pin = NULL;
112
113                 WFD_APP_LOG(WFD_APP_LOG_LOW, "button ok: pin [%s]", ad->pin_number);
114
115                 result = wifi_direct_accept_connection(ad->peer_mac);
116                 WFD_APP_LOG(WFD_APP_LOG_LOW,
117                                 "wifi_direct_accept_connection() failed. result=[%d]\n",
118                                 result);
119                 if (result == WIFI_DIRECT_ERROR_NONE)
120                 {
121                         evas_object_hide(ad->win);
122                         wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_PIN, NULL);
123                 }
124                 else
125                 {
126                         /* tickernoti popup */
127                         wfd_tickernoti_popup(_("IDS_WFD_POP_CONNECT_FAILED"));
128                 }
129         }
130         break;
131
132         case /* MO */ WFD_POP_RESP_PROG_CONNECT_KEYPAD_OK:
133         case /* MT */ WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES:
134         {
135                 WFD_APP_LOG(WFD_APP_LOG_HIGH,
136                                 "WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES\n");
137                 wfd_destroy_popup();
138
139                 int len = strlen(ad->pin_number);
140                 WFD_APP_LOG(WFD_APP_LOG_LOW, "button ok: pin [%s]", ad->pin_number);
141
142                 if (len > 7 && len < 64)
143                 {
144                         int result = 0;
145                         WFD_APP_LOG(WFD_APP_LOG_LOW, "pin=[%s]\n", ad->pin_number);
146
147                         result = wifi_direct_set_wps_pin(ad->pin_number);
148
149                         if (result != WIFI_DIRECT_ERROR_NONE)
150                         {
151                                 /* tickernoti popup */
152                                 snprintf(msg, WFD_POP_STR_MAX_LEN, _("IDS_WFD_POP_CONNECT_FAILED"), ad->peer_name);
153                                 wfd_tickernoti_popup(msg);
154                                 return;
155                         }
156
157                         //result = wifi_direct_activate_pushbutton();
158                         result = wifi_direct_accept_connection(ad->peer_mac);
159                         WFD_APP_LOG(WFD_APP_LOG_LOW,
160                                         "wifi_direct_accept_connection(%s) result=[%d]\n",
161                                         ad->peer_mac, result);
162                         if (result != WIFI_DIRECT_ERROR_NONE)
163                         {
164                                 WFD_APP_LOG(WFD_APP_LOG_ERROR,
165                                                 "wifi_direct_accept_connection() FAILED!!\n");
166                                 evas_object_hide(ad->win);
167
168                                 /* tickernoti popup */
169                                 snprintf(msg, WFD_POP_STR_MAX_LEN, _("IDS_WFD_POP_CONNECT_FAILED"), ad->peer_name);
170                                 wfd_tickernoti_popup(msg);
171                         }
172                 }
173                 else
174                 {
175                         WFD_APP_LOG(WFD_APP_LOG_ERROR, "Error, Incorrect PIN!!\n");
176
177                         /* tickernoti popup */
178                         wfd_tickernoti_popup(_("IDS_WFD_POP_PIN_INVALID"));
179
180                         /* redraw the popup */
181                         if (WFD_POP_RESP_PROG_CONNECT_KEYPAD_OK == resp) {
182                                 wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_KEYPAD, (void *) NULL);
183                         } else {
184                                 wfd_prepare_popup(WFD_POP_APRV_CONNECTION_WPS_KEYPAD_REQ, (void *) NULL);
185                         }
186
187                         return;
188                 }
189         }
190         break;
191
192         case /* MT */ WFD_POP_RESP_APRV_CONNECT_NO:
193         {
194                 WFD_APP_LOG(WFD_APP_LOG_HIGH,
195                                 "WFD_POP_RESP_APRV_CONNECT_NO: destroy_popup...\n");
196
197                 wfd_destroy_popup();
198                 if (pb_timer) {
199                         ecore_timer_del(pb_timer);
200                         pb_timer = NULL;
201                 }
202
203                 result = wifi_direct_disconnect(ad->peer_mac);
204                 WFD_APP_LOG(WFD_APP_LOG_LOW,
205                                 "wifi_direct_disconnect[%s] result=[%d]\n",
206                                 ad->peer_mac, result);
207         }
208         break;
209
210         case WFD_POP_RESP_PROG_CONNECT_CANCEL:
211         {
212                 WFD_APP_LOG(WFD_APP_LOG_HIGH, "WFD_POP_RESP_PROG_CONNECT_CANCEL\n");
213                 wfd_destroy_popup();
214
215                 result = wifi_direct_disconnect(ad->peer_mac);
216                 WFD_APP_LOG(WFD_APP_LOG_LOW,
217                                 "wifi_direct_disconnect[%s] result=[%d]\n",
218                                 ad->peer_mac, result);
219
220                 if (result == WIFI_DIRECT_ERROR_NONE)
221                 {
222                         /* tickernoti popup */
223                         snprintf(msg, WFD_POP_STR_MAX_LEN, _("IDS_WFD_POP_DISCONNECTED"), ad->peer_name);
224                         wfd_tickernoti_popup(msg);
225                 }
226                 else
227                 {
228                         WFD_APP_LOG(WFD_APP_LOG_ERROR,
229                                         "wifi_direct_disconnect() FAILED!!\n");
230
231                         /* tickernoti popup */
232                         snprintf(msg, WFD_POP_STR_MAX_LEN, _("IDS_WFD_POP_DISCONNECT_FAILED"), ad->peer_name);
233                         wfd_tickernoti_popup(msg);
234                 }
235         }
236         break;
237
238         case WFD_POP_RESP_AUTOMATIC_TURNOFF_OK:
239         {
240                 WFD_APP_LOG(WFD_APP_LOG_HIGH, "WFD_POP_RESP_AUTOMATIC_TURNOFF_OK\n");
241
242                 /* turn off the Wi-Fi Direct */
243                 result = wifi_direct_get_state(&ad->wfd_status);
244                 if (result != WIFI_DIRECT_ERROR_NONE) {
245                         WFD_APP_LOG(WFD_APP_LOG_LOW, "Failed to get link status. [%d]\n", result);
246                         return;
247                 }
248
249                 if (ad->wfd_status < WIFI_DIRECT_STATE_ACTIVATING) {
250                         WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi Direct is already deactivated\n");
251                 } else {
252                         ad->wfd_status = WIFI_DIRECT_STATE_DEACTIVATING;
253                         wifi_direct_deactivate();
254                 }
255
256                 wfd_destroy_popup();
257         }
258         break;
259
260         default:
261         {
262                 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Unknown respone\n");
263                 evas_object_hide(ad->win);
264         }
265         break;
266         }
267
268         __WFD_APP_FUNC_EXIT__;
269 }
270
271 static Evas_Object *__create_progress_layout(Evas_Object * parent,
272                                              const char *text)
273 {
274     __WFD_APP_FUNC_ENTER__;
275
276     if (parent == NULL || text == NULL)
277     {
278         WFD_APP_LOG(WFD_APP_LOG_ERROR, "param is NULL\n");
279         return NULL;
280     }
281
282     Evas_Object *progressbar = NULL, *layout = NULL;
283     Evas_Object *label = NULL;
284     int w = 0, h = 0;
285
286     layout = elm_layout_add(parent);
287     if (layout == NULL)
288     {
289         WFD_APP_LOG(WFD_APP_LOG_ERROR, "layout is NULL\n");
290         return NULL;
291     }
292
293     elm_layout_file_set(layout, EDJ_NAME, "progress_popup");
294     evas_object_size_hint_weight_set(layout,
295                                      EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
296
297     progressbar = elm_progressbar_add(layout);
298     if (progressbar == NULL)
299     {
300         WFD_APP_LOG(WFD_APP_LOG_ERROR, "progressbar is NULL\n");
301         evas_object_del(layout);
302         return NULL;
303     }
304     elm_object_style_set(progressbar, "list_process");
305     evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, 0.5);
306     evas_object_size_hint_weight_set(progressbar,
307                                      EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
308     elm_object_part_content_set(layout, "popup_pb", progressbar);
309     elm_progressbar_pulse(progressbar, EINA_TRUE);
310
311     label = elm_label_add(layout);
312     if (label == NULL)
313     {
314         WFD_APP_LOG(WFD_APP_LOG_ERROR, "label is NULL\n");
315         evas_object_del(layout);
316         evas_object_del(progressbar);
317         return NULL;
318     }
319     elm_object_style_set(label, "popup_description/default");
320     elm_object_part_content_set(layout, "popup_progress_text", label);
321     edje_object_part_geometry_get(layout, "popup_progress_text", NULL, NULL, &w,
322                                   &h);
323     elm_label_line_wrap_set(label, ELM_WRAP_WORD);
324     elm_label_wrap_width_set(label, w);
325     elm_object_text_set(label, text);
326
327     evas_object_show(layout);
328
329     __WFD_APP_FUNC_EXIT__;
330
331     return layout;
332 }
333
334
335 void wfd_destroy_popup()
336 {
337     __WFD_APP_FUNC_ENTER__;
338
339     wfd_appdata_t *ad = wfd_get_appdata();
340
341     if (ad == NULL)
342     {
343         WFD_APP_LOG(WFD_APP_LOG_ERROR, "ad is NULL\n");
344         return;
345     }
346
347     if (ad->popup)
348     {
349         evas_object_del(ad->popup);
350         ad->popup = NULL;
351     }
352
353     if (ad->popup_timeout_handle > 0)
354     {
355         g_source_remove(ad->popup_timeout_handle);
356         ad->popup_timeout_handle = 0;
357     }
358
359     evas_object_hide(ad->win);
360
361     __WFD_APP_FUNC_EXIT__;
362     return;
363 }
364
365 static Evas_Object *wfd_draw_pop_type_a(Evas_Object * win, wfd_popup_t * pop)
366 {                               //no button with spin
367     __WFD_APP_FUNC_ENTER__;
368
369     Evas_Object *popup;
370
371     popup = elm_popup_add(win);
372     evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
373     elm_object_text_set(popup, pop->text);
374     elm_popup_timeout_set(popup, pop->timeout);
375     evas_object_show(popup);
376     evas_object_show(win);
377
378     __WFD_APP_FUNC_EXIT__;
379     return popup;
380 }
381
382 static Evas_Object *wfd_draw_pop_type_b(Evas_Object * win, wfd_popup_t * pop)
383 {                               //one button with spin
384     __WFD_APP_FUNC_ENTER__;
385
386     Evas_Object *popup = NULL;
387     Evas_Object *btn = NULL;
388
389     popup = elm_popup_add(win);
390     evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
391     elm_object_text_set(popup, pop->text);
392
393     btn = elm_button_add(popup);
394     elm_object_style_set(btn, "popup_button/default");
395     elm_object_text_set(btn, pop->label1);
396     elm_object_part_content_set(popup, "button1", btn);
397     evas_object_smart_callback_add(btn, "clicked", __popup_resp_cb,
398                                    (void *) pop->resp_data1);
399
400     evas_object_show(popup);
401     evas_object_show(win);
402
403     __WFD_APP_FUNC_EXIT__;
404     return popup;
405 }
406
407 static Evas_Object *wfd_draw_pop_type_c(Evas_Object * win, wfd_popup_t * pop)
408 {                               //two button
409     __WFD_APP_FUNC_ENTER__;
410
411     Evas_Object *popup = NULL;
412     Evas_Object *btn1 = NULL, *btn2 = NULL;
413
414     popup = elm_popup_add(win);
415     evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
416     elm_object_text_set(popup, pop->text);
417
418     btn1 = elm_button_add(popup);
419     elm_object_style_set(btn1, "popup_button/default");
420     elm_object_text_set(btn1, pop->label1);
421     elm_object_part_content_set(popup, "button1", btn1);
422     evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb,
423                                    (void *) pop->resp_data1);
424
425     btn2 = elm_button_add(popup);
426     elm_object_style_set(btn2, "popup_button/default");
427     elm_object_text_set(btn2, pop->label2);
428     elm_object_part_content_set(popup, "button2", btn2);
429     evas_object_smart_callback_add(btn2, "clicked", __popup_resp_cb,
430                                    (void *) pop->resp_data2);
431
432     evas_object_show(popup);
433     evas_object_show(win);
434
435     __WFD_APP_FUNC_EXIT__;
436     return popup;
437 }
438
439 static Evas_Object *wfd_draw_pop_type_d(Evas_Object * win, wfd_popup_t * pop)
440 {                               //text with spin
441     __WFD_APP_FUNC_ENTER__;
442
443     Evas_Object *popup;
444     Evas_Object *layout;
445
446     popup = elm_popup_add(win);
447     evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
448     elm_object_style_set(popup, "customstyle");
449     layout = __create_progress_layout(popup, pop->text);
450     elm_popup_timeout_set(popup, pop->timeout);
451     elm_object_content_set(popup, layout);
452     evas_object_show(popup);
453     evas_object_show(win);
454
455     __WFD_APP_FUNC_EXIT__;
456     return popup;
457 }
458
459 static void __popup_block_clicked_cb(void *data, Evas_Object * obj,
460                                      void *event_info)
461 {
462     wfd_appdata_t *ad = wfd_get_appdata();
463     wfd_popup_t *pop = NULL;
464
465     if (ad != NULL)
466         pop = ad->popup;
467
468     if (ad->win != NULL)
469         evas_object_hide(ad->win);
470
471     if (ad->popup_timeout_handle > 0)
472     {
473         g_source_remove(ad->popup_timeout_handle);
474         ad->popup_timeout_handle = 0;
475     }
476 }
477
478 gboolean __popup_remove_timeout_cb(gpointer user_data)
479 {
480     wfd_appdata_t *ad = wfd_get_appdata();
481     wfd_popup_t *pop = NULL;
482
483     if (ad != NULL)
484         pop = ad->popup;
485     else
486         return false;
487
488     if (pop != user_data)
489         return false;
490
491     if (ad->win != NULL)
492         evas_object_hide(ad->win);
493
494     ad->popup_timeout_handle = 0;
495     return false;
496 }
497
498 static Evas_Object *wfd_draw_pop_type_e(Evas_Object * win, wfd_popup_t * pop)
499 {
500     __WFD_APP_FUNC_ENTER__;
501
502     wfd_appdata_t *ad = wfd_get_appdata();
503     Evas_Object *popup;
504
505     if (ad == NULL)
506         return NULL;
507
508     popup = elm_popup_add(win);
509     evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
510     elm_object_text_set(popup, pop->text);
511     evas_object_smart_callback_add(popup, "block,clicked",
512                                    __popup_block_clicked_cb, NULL);
513     ad->popup_timeout_handle =
514         g_timeout_add(3000, __popup_remove_timeout_cb, popup);
515     evas_object_show(popup);
516     evas_object_show(win);
517
518     __WFD_APP_FUNC_EXIT__;
519     return popup;
520 }
521
522
523 static void _smart_ime_cb(void *data, Evas_Object * obj, void *event_info)
524 {
525     __WFD_APP_FUNC_ENTER__;
526     wfd_appdata_t *ad = wfd_get_appdata();
527
528     Ecore_IMF_Context *imf_context = NULL;
529     imf_context = (Ecore_IMF_Context *) ad->pin_entry;
530
531     if (NULL == imf_context)
532     {
533         WFD_APP_LOG(WFD_APP_LOG_ERROR, "Error!!! Ecore_IMF_Context is NULL!!");
534         return;
535     }
536
537     const char *txt =
538         elm_entry_markup_to_utf8(elm_entry_entry_get
539                                  ((const Evas_Object *) imf_context));
540
541     if (NULL != txt)
542     {
543         WFD_APP_LOG(WFD_APP_LOG_LOW, "* text [%s], len=[%d]", txt, strlen(txt));
544         strncpy(ad->pin_number, txt, sizeof(ad->pin_number));
545     }
546     else
547     {
548         WFD_APP_LOG(WFD_APP_LOG_LOW, "Err!");
549     }
550
551     __WFD_APP_FUNC_EXIT__;
552 }
553
554
555 //#ifdef HIDE_PIN_NUMBER
556 #if 1
557 static void _check_changed_cb(void *data, Evas_Object * obj, void *event_info)
558 {
559     wfd_appdata_t *ad = wfd_get_appdata();
560
561     if (obj == NULL)
562         return;
563
564     Eina_Bool state = elm_check_state_get(obj);
565     elm_entry_password_set(ad->pin_entry, !state);
566 }
567 #endif
568
569 static Eina_Bool _fn_pb_timer(void *data)
570 {
571         int step = 0;
572         double value = 0.0;
573         char time_label[32] = {0};
574         wfd_wps_display_popup_t *wps_display_popup = (wfd_wps_display_popup_t*) data;
575
576         if (NULL == wps_display_popup) {
577                 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Param is NULL.\n");
578                 return ECORE_CALLBACK_CANCEL;
579         }
580
581         Evas_Object *progressbar = NULL;
582         Evas_Object *time = NULL;
583
584         progressbar = wps_display_popup->progressbar;
585         time = wps_display_popup->time;
586         value = elm_progressbar_value_get(progressbar);
587
588         if (value >= 1.0) {
589                 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Progress end.\n");
590                 return ECORE_CALLBACK_CANCEL;
591         }
592
593         wps_display_popup->step++;
594         step = wps_display_popup->step;
595         value = ((double)step) / WFD_POP_TIMER_120;
596         elm_progressbar_value_set(progressbar, value);
597         WFD_APP_LOG(WFD_APP_LOG_LOW, "step: %d, value: %f\n", wps_display_popup->step, value);
598
599         /* show the time label */
600         if (step < 60) {
601                 if (step < 10) {
602                         snprintf(time_label, 32, "00:0%d", step);
603                 } else {
604                         snprintf(time_label, 32, "00:%d", step);
605                 }
606         } else {
607                 if (step%60 < 10) {
608                         snprintf(time_label, 32, "0%d:0%d", step/60, step%60);
609                 } else {
610                         snprintf(time_label, 32, "0%d:%d", step/60, step%60);
611                 }
612         }
613
614         elm_object_text_set(time, time_label);
615
616         return ECORE_CALLBACK_RENEW;
617 }
618
619 static Evas_Object * _add_edit_field(Evas_Object *parent, const char *title, const char *guide, Eina_Bool single_line, Eina_Bool is_editable)
620 {
621         assertm_if(NULL == parent, "parent is NULL!!");
622
623         Evas_Object *layout = elm_layout_add(parent);
624         assertm_if(NULL == layout, "layout is NULL!!");
625
626         if (title && title[0] != '\0') {
627                 elm_layout_theme_set(layout, "layout", "editfield", "title");
628                 elm_object_part_text_set(layout, "elm.text", title);
629         }
630         else {
631                 elm_layout_theme_set(layout, "layout", "editfield", "default");
632         }
633
634         Evas_Object *entry = elm_entry_add(parent);
635         assertm_if(NULL == entry, "entry is NULL!!");
636
637         elm_object_part_content_set(layout, "elm.swallow.content", entry);
638         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
639
640         if (guide && guide[0] != '\0') {
641                 elm_object_part_text_set(layout, "elm.guidetext", guide);
642         }
643
644         elm_entry_single_line_set(entry, single_line);
645         elm_entry_scrollable_set(entry, single_line);
646         elm_entry_editable_set(entry, is_editable);
647         elm_object_signal_emit(layout, "elm,state,eraser,hide", "elm");
648         evas_object_show(layout);
649
650         return layout;
651 }
652
653 Evas_Object *wfd_draw_pop_type_display(Evas_Object * win, wfd_popup_t * pop)
654 {
655     __WFD_APP_FUNC_ENTER__;
656
657     Evas_Object *popup = NULL;
658     Evas_Object *label = NULL;
659     Evas_Object *layout = NULL;
660     Evas_Object *progressbar = NULL;
661     Evas_Object *time = NULL;
662     Evas_Object *btn1 = NULL;
663     Evas_Object *btn2 = NULL;
664     static wfd_wps_display_popup_t wps_display_popup;
665
666     popup = elm_popup_add(win);
667     elm_object_style_set(popup, "customstyle");
668     evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, 0.0);
669
670     Evas_Object *box = elm_box_add(popup);
671     if (!box) {
672         evas_object_del(popup);
673         popup = NULL;
674         return NULL;
675     }
676
677     evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, 0.0);
678     evas_object_size_hint_align_set(box, EVAS_HINT_FILL, 0.0);
679     elm_object_part_content_set(popup, NULL, box);
680     evas_object_show(box);
681
682     /* add label */
683     label = elm_label_add(box);
684     elm_object_style_set(label, "popup/default");
685     elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
686     elm_object_text_set(label, pop->text);
687     evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
688     evas_object_size_hint_align_set(label, EVAS_HINT_FILL, 0.0);
689     elm_box_pack_end(box, label);
690     evas_object_show(label);
691
692     /* add progressbar */
693     progressbar = elm_progressbar_add(box);
694     elm_object_style_set(progressbar, "list_progress");
695     elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
696     evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, 0.0);
697     evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, 0.0);
698     elm_progressbar_value_set(progressbar, 0.0);
699     elm_box_pack_end(box, progressbar);
700     evas_object_show(progressbar);
701
702     /* add time */
703     time = elm_label_add(box);
704     elm_object_style_set(time, "popup/default");
705     elm_object_text_set(time, "00:00");
706     evas_object_size_hint_weight_set(time, EVAS_HINT_EXPAND, 0.0);
707     evas_object_size_hint_align_set(time, EVAS_HINT_FILL, 0.0);
708     elm_box_pack_end(box, time);
709     evas_object_show(time);
710
711     /* start progressbar timer */
712     wps_display_popup.step = 0;
713     wps_display_popup.progressbar= progressbar;
714     wps_display_popup.time = time;
715     pb_timer = ecore_timer_add(1, _fn_pb_timer, &wps_display_popup);
716
717     /* add cancel buttons */
718     btn1 = elm_button_add(popup);
719     elm_object_style_set(btn1, "popup_button/default");
720     elm_object_text_set(btn1, pop->label1);
721     elm_object_part_content_set(popup, "button1", btn1);
722     evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb,
723                                    (void *) pop->resp_data1);
724
725     btn2 = elm_button_add(popup);
726     elm_object_style_set(btn2, "popup_button/default");
727     elm_object_text_set(btn2, pop->label2);
728     elm_object_part_content_set(popup, "button2", btn2);
729     evas_object_smart_callback_add(btn2, "clicked", __popup_resp_cb,
730                                    (void *) pop->resp_data2);
731
732     elm_object_content_set(popup, box);
733     evas_object_show(popup);
734     evas_object_show(win);
735
736     __WFD_APP_FUNC_EXIT__;
737     return popup;
738 }
739
740 Evas_Object *wfd_draw_pop_type_keypad(Evas_Object * win, wfd_popup_t * pop)
741 {
742     __WFD_APP_FUNC_ENTER__;
743     wfd_appdata_t *ad = wfd_get_appdata();
744
745     Evas_Object *conformant = NULL;
746     Evas_Object *layout = NULL;
747     Evas_Object *pinpopup = NULL;
748     Evas_Object *label = NULL;
749     Evas_Object *btn1 = NULL, *btn2 = NULL;
750
751     conformant = elm_conformant_add(win);
752     assertm_if(NULL == conformant, "conformant is NULL!!");
753     elm_win_conformant_set(win, EINA_TRUE);
754     elm_win_resize_object_add(win, conformant);
755     evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, 0.0);
756     evas_object_size_hint_align_set(conformant, EVAS_HINT_FILL, 0.0);
757     evas_object_show(conformant);
758
759     layout = elm_layout_add(conformant);
760     elm_object_content_set(conformant, layout);
761
762     pinpopup = elm_popup_add(layout);
763     assertm_if(NULL == pinpopup, "pinpopup is NULL!!");
764     elm_object_style_set(pinpopup, "customstyle");
765     evas_object_size_hint_weight_set(pinpopup, EVAS_HINT_EXPAND, 0.0);
766     elm_object_part_text_set(pinpopup, "title,text", _("IDS_WFD_POP_TITILE_CONNECTION"));
767
768     Evas_Object *box = elm_box_add(pinpopup);
769     if (!box) {
770         evas_object_del(pinpopup);
771         pinpopup = NULL;
772         return NULL;
773     }
774
775     evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, 0.0);
776     evas_object_size_hint_align_set(box, EVAS_HINT_FILL, 0.0);
777     elm_object_part_content_set(pinpopup, NULL, box);
778     evas_object_show(box);
779
780     /* add label */
781     label = elm_label_add(box);
782     elm_object_style_set(label, "popup/default");
783     elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
784     elm_object_text_set(label, pop->text);
785     evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
786     evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
787     elm_box_pack_end(box, label);
788     evas_object_show(label);
789
790     /* add password */
791     Evas_Object *body = elm_layout_add(box);
792     if (!body) {
793         evas_object_del(pinpopup);
794         pinpopup = NULL;
795         return NULL;
796     }
797
798     elm_layout_theme_set(body, "layout", "dialogue", "1icon");
799     evas_object_size_hint_weight_set(body, EVAS_HINT_EXPAND, 0.0);
800     evas_object_size_hint_align_set(body, EVAS_HINT_FILL, 0.0);
801
802     Evas_Object *editfield_pin = _add_edit_field(body, NULL, NULL, EINA_TRUE, EINA_TRUE);
803     Evas_Object *entry_pin = elm_object_part_content_get(editfield_pin, "elm.swallow.content");
804     ad->pin_entry = entry_pin;
805     evas_object_smart_callback_add(ad->pin_entry, "changed", _smart_ime_cb, NULL);
806     elm_object_part_content_set(body, "elm.icon", editfield_pin);
807     elm_box_pack_end(box, body);
808     evas_object_show(body);
809
810 //#ifdef HIDE_PIN_NUMBER
811 #if 1
812     elm_entry_password_set(ad->pin_entry, TRUE);
813
814     Evas_Object *check = elm_check_add(box);
815     elm_object_text_set(check, _("Show password"));
816     elm_object_focus_allow_set(check, EINA_FALSE);
817     evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, 0.0);
818     evas_object_size_hint_align_set(check, EVAS_HINT_FILL, 0.0);
819     evas_object_smart_callback_add(check, "changed", _check_changed_cb, NULL);
820     evas_object_show(check);
821     elm_box_pack_end(box, check);
822 #endif
823
824     /* add buttons */
825     btn1 = elm_button_add(pinpopup);
826     elm_object_style_set(btn1, "popup_button/default");
827     elm_object_text_set(btn1, pop->label1);
828     elm_object_part_content_set(pinpopup, "button1", btn1);
829     evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb,
830                                    (void *) pop->resp_data1);
831
832     btn2 = elm_button_add(pinpopup);
833     elm_object_style_set(btn2, "popup_button/default");
834     elm_object_text_set(btn2, pop->label2);
835     elm_object_part_content_set(pinpopup, "button2", btn2);
836     evas_object_smart_callback_add(btn2, "clicked", __popup_resp_cb,
837                                    (void *) pop->resp_data2);
838
839     elm_object_content_set(pinpopup, box);
840     evas_object_show(pinpopup);
841     evas_object_show(win);
842     elm_object_focus_set(ad->pin_entry, EINA_TRUE);
843
844     __WFD_APP_FUNC_EXIT__;
845
846     return pinpopup;
847 }
848
849 void wfd_prepare_popup(int type, void *userdata)
850 {
851         __WFD_APP_FUNC_ENTER__;
852         wfd_appdata_t *ad = wfd_get_appdata();
853         wfd_popup_t *pop = ad->popup_data;
854
855         wfd_destroy_popup();
856
857         memset(pop, 0, sizeof(wfd_popup_t));
858
859         pop->type = type;
860
861         switch (pop->type)
862         {
863
864         case /* MT */ WFD_POP_APRV_CONNECTION_WPS_PUSHBUTTON_REQ:
865         {
866                 snprintf(pop->text, sizeof(pop->text), IDS_WFD_POP_CONNECT_Q, // WFD_STR_POP_APRV_CONNECT4
867                                 ad->peer_name);
868                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_SK_YES")); // IDS_WFD_BUTN_YES
869                 snprintf(pop->label2, sizeof(pop->label2), "%s", dgettext("sys_string", "IDS_COM_SK_NO")); // WFD_STR_BUTN_NO
870                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_PBC_YES;
871                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
872
873                 ad->popup = wfd_draw_pop_type_c(ad->win, pop);
874         }
875         break;
876
877         case /* MT */ WFD_POP_APRV_CONNECTION_WPS_DISPLAY_REQ:
878         {
879                 char *pin = (char *) userdata;
880                 snprintf(pop->text, sizeof(pop->text), IDS_WFD_POP_CONNECT_Q, //WFD_STR_POP_APRV_CONNECT4"<br>PIN:%s"
881                                 ad->peer_name, WFD_POP_TIMER_120, ad->pin_number);
882                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_SK_YES")); // IDS_WFD_BUTN_YES
883                 snprintf(pop->label2, sizeof(pop->label2), "%s", dgettext("sys_string", "IDS_COM_SK_NO")); // WFD_STR_BUTN_NO
884                 pop->timeout = WFD_POP_TIMER_120;
885                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_DISPLAY_YES;
886                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
887
888                 ad->popup = wfd_draw_pop_type_display(ad->win, pop);
889         }
890         break;
891
892         case /*MO/MT */ WFD_POP_APRV_CONNECTION_WPS_KEYPAD_REQ:
893         {
894                 snprintf(pop->text, sizeof(pop->text), IDS_WFD_POP_ENTER_PIN, // WFD_STR_POP_APRV_CONNECT4
895                                 ad->peer_name, WFD_POP_TIMER_120, ad->peer_name);
896                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_SK_YES")); // IDS_WFD_BUTN_YES
897                 snprintf(pop->label2, sizeof(pop->label2), "%s", dgettext("sys_string", "IDS_COM_SK_NO")); // WFD_STR_BUTN_NO
898                 pop->timeout = WFD_POP_TIMER_120;
899                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES;
900                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
901
902                 ad->popup = wfd_draw_pop_type_keypad(ad->win, pop);
903         }
904         break;
905
906         case /* MT */ WFD_POP_PROG_CONNECT:
907         {
908                 snprintf(pop->text, sizeof(pop->text), "%s", _("IDS_WFD_POP_CONNECTING")); // WFD_STR_POP_PROG_CONNECT
909                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL")); // WFD_STR_BTN_CANCEL
910                 pop->timeout = WFD_POP_TIMER_120;
911                 pop->resp_data1 = WFD_POP_RESP_PROG_CONNECT_CANCEL;
912
913                 ad->popup = wfd_draw_pop_type_b(ad->win, pop);
914         }
915         break;
916
917         case /* MO */ WFD_POP_PROG_CONNECT_WITH_KEYPAD:
918         {
919                 snprintf(pop->text, sizeof(pop->text), IDS_WFD_POP_ENTER_PIN, // WFD_STR_POP_ENTER_PIN
920                                 ad->peer_name, WFD_POP_TIMER_120, ad->peer_name);
921                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_SK_OK")); // WFD_STR_BTN_OK
922                 snprintf(pop->label2, sizeof(pop->label2), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL")); // WFD_STR_BTN_CANCEL
923                 pop->timeout = WFD_POP_TIMER_120;
924                 pop->resp_data1 = WFD_POP_RESP_PROG_CONNECT_KEYPAD_OK;
925                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
926
927                 ad->popup = wfd_draw_pop_type_keypad(ad->win, pop);
928         }
929         break;
930
931         case /* MO/MT */ WFD_POP_PROG_CONNECT_WITH_PIN:
932                 snprintf(pop->text, sizeof(pop->text), "%s %s", IDS_WFD_POP_CONNECTING_WITH_PIN, ad->pin_number); // WFD_STR_POP_PROG_CONNECT_WITH_PIN
933                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL")); // WFD_STR_BTN_CANCEL
934                 pop->timeout = WFD_POP_TIMER_120;
935                 pop->resp_data1 = WFD_POP_RESP_PROG_CONNECT_CANCEL;
936
937                 ad->popup = wfd_draw_pop_type_b(ad->win, pop);
938                 break;
939
940         case WFD_POP_PROG_CONNECT_CANCEL:
941         {
942                 snprintf(pop->text, sizeof(pop->text), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL")); // WFD_STR_POP_PROG_CANCEL
943                 pop->timeout = WFD_POP_TIMER_120;
944                 ad->popup = wfd_draw_pop_type_a(ad->win, pop);
945         }
946         break;
947
948         case WFD_POP_INCORRECT_PIN:
949                 snprintf(pop->text, sizeof(pop->text), "%s", _("IDS_WFD_POP_PIN_INVALID")); // WFD_STR_POP_INVALID_PIN
950                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_SK_OK")); // WFD_STR_BTN_OK
951                 pop->timeout = WFD_POP_TIMER_3;
952                 pop->resp_data1 = WFD_POP_RESP_OK;
953                 break;
954
955         case WFD_POP_NOTI_CONNECTED:
956                 snprintf(pop->text, sizeof(pop->text), "%s", _("IDS_WFD_POP_CONNECTED")); // WFD_STR_POP_NOTI_CONNECTED
957                 pop->timeout = WFD_POP_TIMER_3;
958
959                 ad->popup = wfd_draw_pop_type_e(ad->win, pop);
960                 break;
961
962         case WFD_POP_FAIL_CONNECT:
963                 snprintf(pop->text, sizeof(pop->text), "%s", _("IDS_WFD_POP_DISCONNECT_FAILED")); // IDS_WFD_POP_DISCONNECT_FAILED
964                 pop->timeout = WFD_POP_TIMER_3;
965
966                 ad->popup = wfd_draw_pop_type_e(ad->win, pop);
967                 break;
968         case WFD_POP_AUTOMATIC_TURN_OFF:
969                 snprintf(pop->text, sizeof(pop->text), "%s", IDS_WFD_POP_AUTOMATIC_TURN_OFF);
970                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_SK_OK"));
971                 snprintf(pop->label2, sizeof(pop->label2), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL"));
972                 pop->timeout = WFD_POP_TIMER_120;
973                 pop->resp_data1 = WFD_POP_RESP_AUTOMATIC_TURNOFF_OK;
974
975                 ad->popup = wfd_draw_pop_type_b(ad->win, pop);
976
977                 break;
978         default:
979                 break;
980         }
981
982         __WFD_APP_FUNC_EXIT__;
983         return;
984 }
985
986 void wfd_tickernoti_popup(char *msg)
987 {
988         __WFD_APP_FUNC_ENTER__;
989
990         int ret = -1;
991         bundle *b = NULL;
992
993         b = bundle_create();
994         if (!b) {
995                 WFD_APP_LOG(WFD_APP_LOG_LOW, "FAIL: bundle_create()\n");
996                 return;
997         }
998
999         /* tickernoti style */
1000         ret = bundle_add(b, "0", "info");
1001         if (ret) {
1002                 WFD_APP_LOG(WFD_APP_LOG_LOW, "Fail to add tickernoti style\n");
1003                 bundle_free(b);
1004                 return;
1005         }
1006
1007         /* popup text */
1008         ret = bundle_add(b, "1", msg);
1009         if (ret) {
1010                 WFD_APP_LOG(WFD_APP_LOG_LOW, "Fail to add popup text\n");
1011                 bundle_free(b);
1012                 return;
1013         }
1014
1015         /* orientation of tickernoti */
1016         ret = bundle_add(b, "2", "0");
1017         if (ret) {
1018                 WFD_APP_LOG(WFD_APP_LOG_LOW, "Fail to add orientation of tickernoti\n");
1019                 bundle_free(b);
1020                 return;
1021         }
1022
1023         /* timeout(second) of tickernoti */
1024         ret = bundle_add(b, "3", "3");
1025         if (ret) {
1026                 WFD_APP_LOG(WFD_APP_LOG_LOW, "Fail to add timeout of tickernoti\n");
1027                 bundle_free(b);
1028                 return;
1029         }
1030
1031         /* launch tickernoti */
1032         ret = syspopup_launch(TICKERNOTI_SYSPOPUP, b);
1033         if (ret) {
1034                 WFD_APP_LOG(WFD_APP_LOG_LOW, "Fail to launch syspopup\n");
1035         }
1036
1037         bundle_free(b);
1038         __WFD_APP_FUNC_EXIT__;
1039 }
1040