tizen 2.3 release
[apps/home/net-popup.git] / src / net-popup.c
1 /*
2 *  net-popup
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 #include <glib.h>
21 #include <stdio.h>
22 #include <Ecore_X.h>
23 #include <syspopup.h>
24 #include <notification.h>
25 #include <efl_assist.h>
26 #include <notification_internal.h>
27 #include <app.h>
28 #include <appsvc.h>
29 #include <app_control.h>
30 #include <vconf.h>
31 #include <vconf-keys.h>
32 #include <dbus/dbus.h>
33 #include <dbus/dbus-glib.h>
34 #include <dbus/dbus-glib-lowlevel.h>
35
36 #include "net-popup.h"
37 #include "net-popup-strings.h"
38
39 #define LOCALEDIR                       "/usr/share/locale"
40 #define NETPOPUP_EDJ            "/usr/ug/res/edje/net-popup/netpopup-custom.edj"
41 #define QP_PRELOAD_NOTI_ICON_PATH "/usr/apps/org.tizen.quickpanel/shared/res/noti_icons"
42
43 #define NETCONFIG_NOTIFICATION_WIFI_ICON \
44                                         "/usr/share/icons/noti_wifi_in_range.png"
45 #define NETCONFIG_NOTIFICATION_WIFI_ICON_LITE \
46                                         "/usr/share/icons/noti_wifi_in_range_ongoing.png"
47 #define NETCONFIG_NOTIFICATION_WIFI_CAPTIVE_ICON \
48                                         "/usr/share/icons/B03_notify_Wi-fi_range.png"
49 #define NETCONFIG_NOTIFICATION_WIFI_IN_RANGE_ICON \
50                                                 "/usr/share/icons/Q02_Notification_wifi_in_range.png"
51 #define NETCONFIG_NOTIFICATION_WIFI_IN_RANGE_ICON_LITE \
52                                                 "/usr/share/icons/noti_wifi_in_range.png"
53 #define NETCONFIG_NOTIFICATION_WIFI_FOUND_TITLE \
54                 dgettext(PACKAGE, "IDS_COM_BODY_WI_FI_NETWORKS_AVAILABLE")
55 #define NETCONFIG_NOTIFICATION_WIFI_FOUND_CONTENT \
56                 dgettext(PACKAGE, "IDS_WIFI_SBODY_TAP_HERE_TO_CONNECT")
57 #define NETCONFIG_NOTIFICATION_WIFI_PORTAL_TITLE \
58                         dgettext(PACKAGE, "IDS_WIFI_HEADER_SIGN_IN_TO_WI_FI_NETWORK_ABB")
59 #define NETCONFIG_NOTIFICATION_WIFI_PORTAL_CONTENT "\"%s\""
60
61 #define USER_RESP_LEN 30
62 #define RESP_REMAIN_CONNECTED "RESP_REMAIN_CONNECTED"
63 #define RESP_WIFI_TETHERING_OFF "RESP_TETHERING_TYPE_WIFI_OFF"
64 #define RESP_WIFI_AP_TETHERING_OFF "RESP_TETHERING_TYPE_WIFI_AP_OFF"
65 #define RESP_TETHERING_ON "RESP_TETHERING_ON"
66 #define CAPTIVE_PORTAL_LOGIN "Login required to access Internet"
67 #define CAPTIVE_PORTAL_LOGIN_ERROR "Login not completed. Disconnected active Wifi"
68
69 static Ecore_Event_Handler *ecore_event_evas_handler;
70 static Ecore_Event_Handler *ecore_event_evas_quick_panel_handler;
71
72 #define BUF_SIZE 1024
73 long sizes[] = {1073741824, 1048576, 1024, 0};
74 char *units[] = {"GB", "MB", "KB", "B"};
75
76 static app_control_h g_req_handle = NULL;
77 static char * resp_popup_mode = NULL;
78
79 static DBusGConnection *conn = NULL;
80 static DBusGProxy *proxy = NULL;
81
82 static int __net_popup_show_notification(app_control_h request, void *data);
83 static int __toast_popup_show(app_control_h request, void *data);
84 static int __net_popup_show_popup(app_control_h request, void *data);
85 static void __net_popup_add_found_ap_noti(void);
86 static void __net_popup_del_found_ap_noti(void);
87 static void __net_popup_add_portal_noti(app_control_h request);
88 static void __net_popup_del_portal_noti(void);
89 static void __net_popup_show_popup_with_user_resp(app_control_h request, void *data);
90 static int _net_popup_send_user_resp(char *resp, Eina_Bool state);
91
92
93 DBusGProxy *__net_popup_init_dbus(void)
94 {
95         GError *err = NULL;
96
97         conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &err);
98         if (err != NULL) {
99                 g_error_free(err);
100                 return NULL;
101         }
102
103         proxy = dbus_g_proxy_new_for_name(conn, "net.netpopup",
104                         "/Netpopup", "net.netpopup");
105         if (proxy == NULL) {
106                 dbus_g_connection_unref(conn);
107                 conn = NULL;
108         }
109
110         return proxy;
111 }
112
113 void __net_popup_deinit_dbus(void)
114 {
115         if (proxy) {
116                 g_object_unref(proxy);
117                 proxy = NULL;
118         }
119
120         if (conn) {
121                 dbus_g_connection_unref(conn);
122                 conn = NULL;
123         }
124
125         return;
126 }
127
128 int __net_popup_send_dbus_msg(const char *resp)
129 {
130         if (conn == NULL || resp == NULL) {
131                 return -1;
132         }
133
134         DBusConnection *gconn = NULL;
135         DBusMessage *msg = NULL;
136         char *module = "wifi";
137
138         gconn = dbus_g_connection_get_connection(conn);
139         if (gconn == NULL) {
140                 return -1;
141         }
142
143         msg = dbus_message_new_signal("/Org/Tizen/Quickpanel",
144                                           "org.tizen.quickpanel",
145                                           "ACTIVITY");
146         if (!msg) {
147                 return -1;
148         }
149
150         if (!dbus_message_append_args(msg,
151                         DBUS_TYPE_STRING, &module,
152                         DBUS_TYPE_STRING, &resp,
153                         DBUS_TYPE_INVALID)) {
154                 dbus_message_unref(msg);
155                 return -1;
156         }
157
158         dbus_connection_send(gconn, msg, NULL);
159         dbus_message_unref(msg);
160
161         return 0;
162 }
163
164 static bool __net_popup_create(void *data)
165 {
166         log_print(NET_POPUP, "__net_popup_create()\n");
167
168         bindtextdomain(PACKAGE, LOCALEDIR);
169
170         return true;
171 }
172
173 static void __net_popup_terminate(void *data)
174 {
175         if (ecore_event_evas_handler) {
176                 ecore_event_handler_del(ecore_event_evas_handler);
177                 ecore_event_evas_handler = NULL;
178         }
179         if (ecore_event_evas_quick_panel_handler) {
180                 ecore_event_handler_del(ecore_event_evas_quick_panel_handler);
181                 ecore_event_evas_quick_panel_handler = NULL;
182         }
183
184         return;
185 }
186
187 static void __net_popup_pause(void *data)
188 {
189         log_print(NET_POPUP, "__net_popup_pause()");
190 }
191
192 static void __net_popup_resume(void *data)
193 {
194         return;
195 }
196
197 static Eina_Bool __key_release_event_cb(void *data, int type,
198                 void *event)
199 {
200         Evas_Event_Key_Down *ev = (Evas_Event_Key_Down *) event;
201
202         if (!ev) {
203                 return ECORE_CALLBACK_RENEW;
204         }
205
206         if (!ev->keyname) {
207                 return ECORE_CALLBACK_RENEW;
208         }
209
210         log_print(NET_POPUP, "key_release : %s", ev->keyname);
211         if (g_strcmp0(ev->keyname, "XF86Phone") == 0 ||
212                         g_strcmp0(ev->keyname, "XF86Stop") == 0) {
213                 elm_exit();
214         }
215
216         return ECORE_CALLBACK_DONE;
217 }
218
219 static Eina_Bool _ecore_event_client_message_cb(void *data, int type,
220                                                  void *event)
221 {
222         Ecore_X_Event_Client_Message *ev = event;
223
224         if (ev->message_type == ECORE_X_ATOM_E_ILLUME_QUICKPANEL_STATE) {
225                 if (ev->data.l[0] == ECORE_X_ATOM_E_ILLUME_QUICKPANEL_OFF) {
226                         log_print(NET_POPUP, "ECORE_X_ATOM_E_ILLUME_QUICKPANEL_OFF");
227                 } else if (ev->data.l[0] == ECORE_X_ATOM_E_ILLUME_QUICKPANEL_ON) {
228                         log_print(NET_POPUP, "ECORE_X_ATOM_E_ILLUME_QUICKPANEL_ON");
229                 }
230         }
231         return ECORE_CALLBACK_RENEW;
232 }
233
234 static void __net_popup_service_cb(app_control_h request, void *data)
235 {
236         log_print(NET_POPUP, "__net_popup_service_cb()\n");
237
238         int ret = 0;
239         char *type = NULL;
240
241         if (ecore_event_evas_handler == NULL) {
242                 ecore_event_evas_handler = ecore_event_handler_add(ECORE_EVENT_KEY_UP,
243                                 __key_release_event_cb, NULL);
244         }
245
246         if (ecore_event_evas_quick_panel_handler == NULL) {
247                 ecore_event_evas_quick_panel_handler = ecore_event_handler_add(
248                                 ECORE_X_EVENT_CLIENT_MESSAGE, _ecore_event_client_message_cb, NULL);
249         }
250
251         ret = app_control_get_extra_data(request, "_SYSPOPUP_TYPE_", &type);
252
253         ea_theme_changeable_ui_enabled_set(EINA_TRUE);
254
255         if (APP_CONTROL_ERROR_NONE != ret) {
256                 log_print(NET_POPUP, "Failed to get _SYSPOPUP_TYPE_ ret = %d", ret);
257                 g_free(type);
258                 elm_exit();
259                 return;
260         }
261
262         log_print(NET_POPUP, "type = %s\n", type);
263
264         if (g_str_equal(type, "notification")) {
265                 __net_popup_show_notification(request, data);
266                 elm_exit();
267         } else if (g_str_equal(type, "toast_popup")) {
268                 __toast_popup_show(request, data);
269         } else if (g_str_equal(type, "popup")) {
270                 __net_popup_show_popup(request, data);
271         } else if (g_str_equal(type, "add_found_ap_noti")) {
272                 __net_popup_add_found_ap_noti();
273                 elm_exit();
274         } else if (g_str_equal(type, "del_found_ap_noti")) {
275                 __net_popup_del_found_ap_noti();
276                 elm_exit();
277         } else if (g_str_equal(type, "add_portal_noti")) {
278                 __net_popup_add_portal_noti(request);
279                 elm_exit();
280         } else if (g_str_equal(type, "del_portal_noti")) {
281                 __net_popup_del_portal_noti();
282                 elm_exit();
283         } else if (g_str_equal(type, "popup_user_resp")) {
284                 app_control_clone(&g_req_handle, request);
285                 __net_popup_show_popup_with_user_resp(request, data);
286         } else {
287                 __net_popup_show_notification(request, data);
288                 elm_exit();
289         }
290         g_free(type);
291
292         return;
293 }
294
295 static void __net_popup_set_orientation(Evas_Object *win)
296 {
297         int rots[4] = { 0, 90, 180, 270 };
298
299         if (!elm_win_wm_rotation_supported_get(win)) {
300                 return;
301         }
302
303         elm_win_wm_rotation_available_rotations_set(win, rots, 4);
304 }
305
306 static Evas_Object* __net_popup_create_win(void)
307 {
308         Evas_Object *win = NULL;
309         Evas *e = NULL;
310         Ecore_Evas *ee = NULL;
311         int w, h;
312
313         win = elm_win_add(NULL, PACKAGE, ELM_WIN_NOTIFICATION);
314
315         e = evas_object_evas_get(win);
316         ee = ecore_evas_ecore_evas_get(e);
317         ecore_evas_name_class_set(ee,"APP_POPUP","APP_POPUP");
318         
319         elm_win_alpha_set(win, EINA_TRUE);
320         elm_win_borderless_set(win, EINA_TRUE);
321         ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
322         evas_object_resize(win, w, h);
323         utilx_set_system_notification_level (ecore_x_display_get(),
324                                 elm_win_xwindow_get(win),
325                                 UTILX_NOTIFICATION_LEVEL_LOW);
326
327         __net_popup_set_orientation(win);
328
329         return win;
330 }
331
332 static void _ok_button_clicked_cb(void *data, Evas_Object *obj, void *event_info)
333 {
334         if (data)
335                 evas_object_del(data);
336         elm_exit();
337 }
338
339 static void _timeout_cb(void *data, Evas_Object *obj, void *event_info)
340 {
341         evas_object_del(obj);
342
343         elm_exit();
344 }
345
346 static int __toast_popup_show(app_control_h request, void *data)
347 {
348         char buf[ALERT_STR_LEN_MAX] = "";
349         int ret = 0;
350         char *mode = NULL;
351         Evas_Object *twin = NULL;
352         Evas_Object *tpop = NULL;
353
354         ret = app_control_get_extra_data(request, "_SYSPOPUP_CONTENT_", &mode);
355         if (ret != APP_CONTROL_ERROR_NONE) {
356                 log_print(NET_POPUP, "Failed to get _SYSPOPUP_CONTENT_ ret = %d", ret);
357                 g_free(mode);
358                 elm_exit();
359                 return 0;
360         }
361
362         log_print(NET_POPUP, "_SYSPOPUP_CONTENT_ = %s\n", mode);
363
364         twin = __net_popup_create_win();
365         tpop = elm_popup_add(twin);
366         elm_object_style_set(tpop, "toast");
367         evas_object_size_hint_weight_set(tpop, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
368
369         elm_popup_timeout_set(tpop, 2.0);
370
371         evas_object_smart_callback_add(tpop, "timeout", _timeout_cb, twin);
372         if (strcmp(mode, "wrong password") == 0) {
373                 log_print(NET_POPUP, "alert wrong password\n");
374
375                 g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_ERR_WRONG_PASSWORD);
376         } else if (strcmp(mode, "no ap found") == 0) {
377                 log_print(NET_POPUP, "alert no ap found\n");
378
379                 g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_NO_AP_FOUND);
380         }else
381                 log_print(NET_POPUP, "%s\n", mode);
382
383         elm_object_part_text_set(tpop,"elm.text", buf);
384         evas_object_show(tpop);
385         evas_object_show(twin);
386         g_free(mode);
387
388         return 0;
389 }
390
391 static int __net_popup_show_notification(app_control_h request, void *data)
392 {
393         int ret = 0;
394         char *mode = NULL;
395         char buf[ALERT_STR_LEN_MAX] = "";
396         char *ap_name = NULL;
397
398         ret = app_control_get_extra_data(request, "_SYSPOPUP_CONTENT_", &mode);
399
400         if (APP_CONTROL_ERROR_NONE != ret) {
401                 log_print(NET_POPUP, "Failed to get _SYSPOPUP_CONTENT_");
402                 return 0;
403         }
404
405         secure_log_print(NET_POPUP, "_SYSPOPUP_CONTENT_ = %s\n", mode);
406
407         if (strcmp(mode, "connected") == 0) {
408                 notification_status_message_post(ALERT_STR_MOBILE_NETWORKS_CHARGE);
409                 log_print(NET_POPUP, "alert 3g\n");
410         } else if (strcmp(mode, "fail to connect") == 0) {
411                 notification_status_message_post(ALERT_STR_ERR_UNAVAILABLE);
412                 log_print(NET_POPUP, "alert err\n");
413         } else if (strcmp(mode, "unable to connect") == 0) {
414                 notification_status_message_post(ALERT_STR_ERR_CONNECT);
415                 log_print(NET_POPUP, "alert unable to connect\n");
416         } else if (strcmp(mode, "wrong password") == 0) {
417                 notification_status_message_post(ALERT_STR_ERR_WRONG_PASSWORD);
418                 log_print(NET_POPUP, "alert wrong password\n");
419         } else if (strcmp(mode, "not support") == 0) {
420                 notification_status_message_post(ALERT_STR_ERR_NOT_SUPPORT);
421                 log_print(NET_POPUP, "alert not support\n");
422         } else if (strcmp(mode, "wifi restricted") == 0) {
423                 notification_status_message_post(ALERT_STR_RESTRICTED_USE_WIFI);
424                 log_print(NET_POPUP, "alert wifi restricted\n");
425         } else if (strcmp(mode, "no ap found") == 0) {
426                 notification_status_message_post(ALERT_STR_NO_AP_FOUND);
427                 log_print(NET_POPUP, "alert no ap found\n");
428         } else if (strcmp(mode, "Lengthy Password") == 0) {
429                 notification_status_message_post(ALERT_STR_LENGHTY_PASSWORD);
430                 log_print(NET_POPUP, "Password entered crosses 64 bytes\n");
431         } else if (strcmp(mode, "Portal Login") == 0) {
432                 notification_status_message_post(CAPTIVE_PORTAL_LOGIN);
433                 log_print(NET_POPUP, "Please login to access Internet\n");
434         } else if (strcmp(mode, "Portal Login Error") == 0) {
435                 notification_status_message_post(CAPTIVE_PORTAL_LOGIN_ERROR);
436                 log_print(NET_POPUP, "Login not completed. Disconnected Wifi\n");
437         } else if (strcmp(mode, "wifi connected") == 0) {
438                 ret = app_control_get_extra_data(request, "_AP_NAME_", &ap_name);
439
440                 if (APP_CONTROL_ERROR_NONE != ret) {
441                         log_print(NET_POPUP, "Failed to get _AP_NAME_ ret = %d", ret);
442                         g_free(mode);
443                         return 0;
444                 }
445
446                 if (ap_name != NULL)
447                         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_WIFI_CONNECTED, ap_name);
448                 else
449                         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_WIFI_CONNECTED, "");
450
451                 notification_status_message_post(buf);
452
453                 log_print(NET_POPUP, "alert wifi connected\n");
454                 g_free(ap_name);
455         } else {
456                 notification_status_message_post(mode);
457                 log_print(NET_POPUP, "%s\n", mode);
458         }
459         g_free(mode);
460
461         return 0;
462 }
463
464 static int _net_popup_send_user_resp(char *resp, Eina_Bool state)
465 {
466         int ret = 0;
467         app_control_h reply = NULL;
468         char checkbox_str[USER_RESP_LEN] = { '\0', };
469
470         log_print(NET_POPUP, "Send the user response to the caller");
471         ret = app_control_create(&reply);
472         if (APP_CONTROL_ERROR_NONE != ret) {
473                 log_print(NET_POPUP, "Failed to create service ret = %d", ret);
474                 app_control_destroy(g_req_handle);
475                 g_req_handle = NULL;
476
477                 return false;
478         }
479
480         if (TRUE == state)
481                 g_strlcpy(checkbox_str, "TRUE", USER_RESP_LEN);
482         else
483                 g_strlcpy(checkbox_str, "FALSE", USER_RESP_LEN);
484
485         log_print(NET_POPUP, "Checkbox_str[%s]", checkbox_str);
486
487         ret = app_control_add_extra_data(reply, "_SYSPOPUP_RESP_", resp);
488         if (APP_CONTROL_ERROR_NONE == ret) {
489                 ret = app_control_add_extra_data(reply, "_SYSPOPUP_CHECKBOX_RESP_",
490                                 checkbox_str);
491                 if (APP_CONTROL_ERROR_NONE == ret) {
492                         ret = app_control_reply_to_launch_request(reply, g_req_handle,
493                                         APP_CONTROL_RESULT_SUCCEEDED);
494                         if (APP_CONTROL_ERROR_NONE == ret) {
495                                 log_print(NET_POPUP, "Service reply success");
496                                 ret = TRUE;
497                         } else {
498                                 log_print(NET_POPUP, "Service reply failed ret = %d", ret);
499                         }
500                 } else {
501                         log_print(NET_POPUP, "Service data addition failed ret = %d", ret);
502                 }
503         } else {
504                 log_print(NET_POPUP, "Service data addition failed ret = %d", ret);
505         }
506
507         app_control_destroy(reply);
508         app_control_destroy(g_req_handle);
509         g_req_handle = NULL;
510
511         return ret;
512 }
513
514 void _tethering_wifi_btn_yes_cb(void *data, Evas_Object *obj, void *event_info)
515 {
516         log_print(NET_POPUP, "_tethering_wifi_btn_yes_cb");
517
518         bool result = FALSE;
519         Evas_Object *popup = (Evas_Object *)data;
520
521         __net_popup_init_dbus();
522         __net_popup_send_dbus_msg("progress_off");
523         __net_popup_deinit_dbus();
524
525         result = _net_popup_send_user_resp(RESP_WIFI_TETHERING_OFF, FALSE);
526         if (true != result)
527                 log_print(NET_POPUP, "Failed to send user response ");
528
529         if (popup)
530                 evas_object_del(popup);
531
532         elm_exit();
533 }
534
535 void _tethering_wifi_ap_btn_yes_cb(void *data, Evas_Object *obj, void *event_info)
536 {
537         log_print(NET_POPUP, "_tethering_wifi_ap_btn_yes_cb");
538
539         bool result = FALSE;
540         Evas_Object *popup = (Evas_Object *)data;
541
542         __net_popup_init_dbus();
543         __net_popup_send_dbus_msg("progress_off");
544         __net_popup_deinit_dbus();
545
546         result = _net_popup_send_user_resp(RESP_WIFI_AP_TETHERING_OFF, FALSE);
547         if (true != result)
548                 log_print(NET_POPUP, "Failed to send user response ");
549
550         if (popup)
551                 evas_object_del(popup);
552
553         elm_exit();
554 }
555
556 void _btn_no_cb(void *data, Evas_Object *obj, void *event_info)
557 {
558         log_print(NET_POPUP, "_btn_no_cb");
559
560         bool result = FALSE;
561         Evas_Object *popup = (Evas_Object *)data;
562
563         result = _net_popup_send_user_resp(RESP_TETHERING_ON, FALSE);
564         if (true != result)
565                 log_print(NET_POPUP, "Failed to send user response ");
566
567         if (popup)
568                 evas_object_del(popup);
569
570         elm_exit();
571 }
572
573 static void __net_popup_show_popup_with_user_resp(app_control_h request,
574                 void *data)
575 {
576         Evas_Object *win;
577         Evas_Object *popup;
578         Evas_Object *layout;
579         Evas_Object *label;
580         Evas_Object *btn1;
581         Evas_Object *btn2;
582         int ret = 0;
583
584         ret = app_control_get_extra_data(request, "_SYSPOPUP_CONTENT_", &resp_popup_mode);
585         if (APP_CONTROL_ERROR_NONE != ret)
586                 log_print(NET_POPUP, "Failed to get _SYSPOPUP_CONTENT_ ret = %d", ret);
587
588         secure_log_print(NET_POPUP, "_SYSPOPUP_CONTENT_ = %s\n", resp_popup_mode);
589
590         win = __net_popup_create_win();
591         evas_object_show(win);
592
593         popup = elm_popup_add(win);
594         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
595                         EVAS_HINT_EXPAND);
596
597         if (g_strcmp0(resp_popup_mode, "TETHERING_TYPE_WIFI") == 0 ||
598                         g_strcmp0(resp_popup_mode, "TETHERING_TYPE_WIFI_AP") == 0) {
599                 log_print(NET_POPUP, "Drawing Wi-Fi Tethering OFF popup");
600
601                 __net_popup_init_dbus();
602                 elm_object_part_text_set(popup, "title,text", ALERT_STR_WIFI);
603
604                 layout = elm_layout_add(popup);
605                 elm_layout_file_set(layout, NETPOPUP_EDJ, "popup");
606                 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
607                                 EVAS_HINT_EXPAND);
608
609                 __net_popup_send_dbus_msg("progress_on");
610                 label = elm_label_add(popup);
611                 elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
612                 elm_object_text_set(label, ALERT_STR_WIFI_MOBILE_AP_ON);
613                 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND,
614                                 EVAS_HINT_EXPAND);
615                 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
616                 evas_object_show(label);
617
618                 elm_object_part_content_set(layout, "elm.swallow.content", label);
619                 evas_object_show(layout);
620                 elm_object_style_set(label, "popup/default");
621                 ea_object_event_callback_add(popup, EA_CALLBACK_BACK, _btn_no_cb, popup);
622                 elm_object_content_set(popup, label);
623
624                 btn1 = elm_button_add(popup);
625                 elm_object_style_set(btn1, "popup");
626                 elm_object_text_set(btn1, ALERT_STR_CANCEL);
627                 elm_object_part_content_set(popup, "button1", btn1);
628                 evas_object_smart_callback_add(btn1, "clicked",
629                                         _btn_no_cb, popup);
630
631                 btn2 = elm_button_add(popup);
632                 elm_object_style_set(btn2, "popup");
633                 elm_object_text_set(btn2, ALERT_STR_OK);
634                 elm_object_part_content_set(popup, "button2", btn2);
635
636                 if (g_strcmp0(resp_popup_mode, "TETHERING_TYPE_WIFI") == 0)
637                         evas_object_smart_callback_add(btn2, "clicked",
638                                 _tethering_wifi_btn_yes_cb, popup);
639                 else if (g_strcmp0(resp_popup_mode, "TETHERING_TYPE_WIFI_AP") == 0)
640                         evas_object_smart_callback_add(btn2, "clicked",
641                                 _tethering_wifi_ap_btn_yes_cb, popup);
642
643                 evas_object_show(popup);
644                 evas_object_show(win);
645                 __net_popup_deinit_dbus();
646         }
647 }
648
649 static int __net_popup_show_popup(app_control_h request, void *data)
650 {
651         Evas_Object *win;
652         Evas_Object *popup;
653         Evas_Object *button;
654         int ret = 0;
655         char *mode = NULL;
656
657         ret = app_control_get_extra_data(request, "_SYSPOPUP_CONTENT_", &mode);
658         if (APP_CONTROL_ERROR_NONE != ret) {
659                 log_print(NET_POPUP, "Failed to get _SYSPOPUP_CONTENT_ ret = %d", ret);
660                 g_free(mode);
661                 elm_exit();
662                 return 0;
663         }
664
665         secure_log_print(NET_POPUP, "_SYSPOPUP_CONTENT_ = %s\n", mode);
666
667         win = __net_popup_create_win();
668
669         popup = elm_popup_add(win);
670         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
671         if (strcmp(mode, "connected") == 0) {
672                 elm_object_text_set(popup, ALERT_STR_MOBILE_NETWORKS_CHARGE);
673                 log_print(NET_POPUP, "alert 3g\n");
674         } else if (strcmp(mode, "fail to connect") == 0) {
675                 elm_object_text_set(popup, ALERT_STR_ERR_UNAVAILABLE);
676                 log_print(NET_POPUP, "alert err\n");
677         } else if (strcmp(mode, "unable to connect") == 0) {
678                 elm_object_text_set(popup, ALERT_STR_ERR_CONNECT);
679                 log_print(NET_POPUP, "alert unable to connect\n");
680         } else if (strcmp(mode, "wrong password") == 0) {
681                 elm_object_text_set(popup, ALERT_STR_ERR_WRONG_PASSWORD);
682                 log_print(NET_POPUP, "alert wrong password\n");
683         } else if (strcmp(mode, "not support") == 0) {
684                 elm_object_text_set(popup, ALERT_STR_ERR_NOT_SUPPORT);
685                 log_print(NET_POPUP, "alert not support\n");
686         } else if (strcmp(mode, "wifi restricted") == 0) {
687                 elm_object_text_set(popup, ALERT_STR_RESTRICTED_USE_WIFI);
688                 log_print(NET_POPUP, "alert wifi restricted\n");
689         } else if (strcmp(mode, "no ap found") == 0) {
690                 elm_object_text_set(popup, ALERT_STR_NO_AP_FOUND);
691                 log_print(NET_POPUP, "alert no ap found\n");
692         } else if (strcmp(mode, "wifi connected") == 0) {
693                 char buf[ALERT_STR_LEN_MAX] = "";
694                 char *ap_name = NULL;
695
696                 ret = app_control_get_extra_data(request, "_AP_NAME_", &ap_name);
697
698                 if (ap_name != NULL)
699                         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_WIFI_CONNECTED, ap_name);
700                 else
701                         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_WIFI_CONNECTED, "");
702
703                 elm_object_text_set(popup, buf);
704
705                 log_print(NET_POPUP, "alert wifi connected\n");
706                 g_free(ap_name);
707         } else {
708                 elm_object_text_set(popup, mode);
709                 log_print(NET_POPUP, "%s\n", mode);
710         }
711
712         button = elm_button_add(popup);
713         elm_object_style_set(button, "popup");
714         elm_object_text_set(button, ALERT_STR_OK);
715         elm_object_part_content_set(popup, "button1", button);
716         evas_object_smart_callback_add(button, "clicked", _ok_button_clicked_cb, popup);
717         evas_object_show(popup);
718         evas_object_show(win);
719         g_free(mode);
720
721         return 0;
722 }
723
724 static void __net_popup_add_found_ap_noti(void)
725 {
726         int noti_flags = 0;
727         notification_h noti = NULL;
728         notification_list_h noti_list = NULL;
729         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
730         bundle *b = NULL;
731
732         notification_get_detail_list("net.netpopup", NOTIFICATION_GROUP_ID_NONE,
733                         NOTIFICATION_PRIV_ID_NONE, -1, &noti_list);
734         if (noti_list != NULL) {
735                 notification_free_list(noti_list);
736                 return;
737         }
738
739         noti = notification_new(NOTIFICATION_TYPE_ONGOING, NOTIFICATION_GROUP_ID_NONE,
740                         NOTIFICATION_PRIV_ID_NONE);
741         if (noti == NULL) {
742                 log_print(NET_POPUP, "Failed to create notification");
743                 return;
744         }
745
746         noti_err = notification_set_time(noti, time(NULL));
747         if(noti_err != NOTIFICATION_ERROR_NONE) {
748                 log_print(NET_POPUP, "Failed to notification_set_time : %d", noti_err);
749                 goto error;
750         }
751
752         noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
753                         QP_PRELOAD_NOTI_ICON_PATH"/noti_wifi_in_range.png");
754         if(noti_err != NOTIFICATION_ERROR_NONE) {
755                 log_print(NET_POPUP, "Failed to notification_set_image : %d", noti_err);
756                 goto error;
757         }
758
759         noti_err = notification_set_layout(noti, NOTIFICATION_LY_ONGOING_EVENT);
760         if (noti_err != NOTIFICATION_ERROR_NONE) {
761                 log_print(NET_POPUP, "Failed to notification_set_layout : %d", noti_err);
762                 goto error;
763         }
764
765         noti_err = notification_set_text_domain(noti, PACKAGE,
766                         LOCALEDIR);
767         if(noti_err != NOTIFICATION_ERROR_NONE) {
768                 log_print(NET_POPUP, "Failed to notification_set_text_domain : %d", noti_err);
769                 goto error;
770         }
771
772         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
773                         NETCONFIG_NOTIFICATION_WIFI_FOUND_TITLE,
774                         "IDS_COM_BODY_WI_FI_NETWORKS_AVAILABLE",
775                         NOTIFICATION_VARIABLE_TYPE_NONE);
776         if (noti_err != NOTIFICATION_ERROR_NONE) {
777                 log_print(NET_POPUP, "Failed to notification_set_title : %d", noti_err);
778                 goto error;
779         }
780
781         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
782                         NETCONFIG_NOTIFICATION_WIFI_FOUND_CONTENT,
783                         "IDS_WIFI_SBODY_TAP_HERE_TO_CONNECT",
784                         NOTIFICATION_VARIABLE_TYPE_NONE);
785         if (noti_err != NOTIFICATION_ERROR_NONE) {
786                 log_print(NET_POPUP, "Failed to notification_set_content: %d", noti_err);
787                 goto error;
788         }
789
790         noti_flags = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_INDICATOR;
791         noti_err = notification_set_display_applist(noti, noti_flags);
792         if(noti_err != NOTIFICATION_ERROR_NONE) {
793                 log_print(NET_POPUP, "Failed to notification_set_display_applist: %d", noti_err);
794                 goto error;
795         }
796
797         b = bundle_create();
798         bundle_add(b, "caller", "notification");
799
800         appsvc_set_pkgname(b, "net.wifi-qs");
801
802         noti_err = notification_set_execute_option(noti,
803                         NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "Launch", NULL, b);
804         if (noti_err != NOTIFICATION_ERROR_NONE) {
805                 log_print(NET_POPUP, "Failed to notification_set_execute_option");
806                 goto error;
807         }
808
809         noti_err = notification_insert(noti, NULL);
810         if (noti_err != NOTIFICATION_ERROR_NONE) {
811                 log_print(NET_POPUP, "Failed to insert notification");
812                 goto error;
813         }
814
815         log_print(NET_POPUP, "Successfully added notification");
816
817 error:
818         if (b != NULL)
819                 bundle_free(b);
820
821         if (noti != NULL)
822                 notification_free(noti);
823 }
824
825 static void __net_popup_del_found_ap_noti(void)
826 {
827         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
828
829         noti_err = notification_delete_all_by_type("net.netpopup",
830                         NOTIFICATION_TYPE_ONGOING);
831         if (noti_err != NOTIFICATION_ERROR_NONE) {
832                 log_print(NET_POPUP, "fail to notification_delete_by_priv_id");
833                 return;
834         }
835
836         log_print(NET_POPUP, "Successfully deleted notification");
837 }
838
839 static void __net_popup_add_portal_noti(app_control_h request)
840 {
841         int ret = 0;
842         int noti_flags = 0;
843         bundle *b = NULL;
844         char *ap_name = NULL;
845         notification_h noti = NULL;
846         app_control_h service_handle = NULL;
847         notification_list_h noti_list = NULL;
848         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
849
850         ret = app_control_get_extra_data(request, "_AP_NAME_", &ap_name);
851
852         if (ap_name == NULL || ret != APP_CONTROL_ERROR_NONE) {
853                 log_print(NET_POPUP, "Failed to retrieve connected AP name!!");
854                 g_free(ap_name);
855                 return;
856         }
857
858         log_print(NET_POPUP, "Successfully added notification");
859
860         notification_get_detail_list("net.netpopup", NOTIFICATION_GROUP_ID_NONE,
861                         NOTIFICATION_PRIV_ID_NONE, -1, &noti_list);
862         if (noti_list != NULL) {
863                 notification_free_list(noti_list);
864                 g_free(ap_name);
865                 return;
866         }
867
868         noti = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_NONE,
869                         NOTIFICATION_PRIV_ID_NONE);
870         if (noti == NULL) {
871                 log_print(NET_POPUP, "fail to create notification");
872                 g_free(ap_name);
873                 return;
874         }
875
876         noti_err = notification_set_time(noti, time(NULL));
877         if(noti_err != NOTIFICATION_ERROR_NONE) {
878                 log_print(NET_POPUP, "fail to notification_set_time : %d", noti_err);
879                 goto error;
880         }
881
882         noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
883                         NETCONFIG_NOTIFICATION_WIFI_ICON);
884         if(noti_err != NOTIFICATION_ERROR_NONE) {
885                 log_print(NET_POPUP, "fail to notification_set_image : %d", noti_err);
886                 goto error;
887         }
888
889         noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
890                         QP_PRELOAD_NOTI_ICON_PATH"/noti_wifi_in_range.png");
891         if(noti_err != NOTIFICATION_ERROR_NONE) {
892                 log_print(NET_POPUP, "fail to notification_set_image : %d", noti_err);
893                 goto error;
894         }
895         noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_MULTIPLE);
896         if (noti_err != NOTIFICATION_ERROR_NONE) {
897                 log_print(NET_POPUP, "fail to notification_set_layout : %d", noti_err);
898                 goto error;
899         }
900
901         noti_err = notification_set_text_domain(noti, PACKAGE,
902                         LOCALEDIR);
903         if(noti_err != NOTIFICATION_ERROR_NONE) {
904                 log_print(NET_POPUP, "fail to notification_set_text_domain : %d", noti_err);
905                 goto error;
906         }
907
908         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
909                         NETCONFIG_NOTIFICATION_WIFI_PORTAL_TITLE,
910                         "IDS_WIFI_HEADER_SIGN_IN_TO_WI_FI_NETWORK_ABB",
911                         NOTIFICATION_VARIABLE_TYPE_NONE);
912         if (noti_err != NOTIFICATION_ERROR_NONE) {
913                 log_print(NET_POPUP, "fail to notification_set_title : %d", noti_err);
914                 goto error;
915         }
916
917         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
918                         NETCONFIG_NOTIFICATION_WIFI_PORTAL_CONTENT,
919                         NETCONFIG_NOTIFICATION_WIFI_PORTAL_CONTENT,
920                         NOTIFICATION_VARIABLE_TYPE_STRING, ap_name,
921                         NOTIFICATION_VARIABLE_TYPE_NONE);
922         if (noti_err != NOTIFICATION_ERROR_NONE) {
923                 log_print(NET_POPUP, "fail to notification_set_content : %d", noti_err);
924                 goto error;
925         }
926
927         noti_flags = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_INDICATOR;
928         noti_err = notification_set_display_applist(noti, noti_flags);
929         if(noti_err != NOTIFICATION_ERROR_NONE) {
930                 log_print(NET_POPUP, "fail to notification_set_display_applist : %d", noti_err);
931                 goto error;
932         }
933
934         ret = app_control_create(&service_handle);
935         log_print(NET_POPUP, "service create ret[%d]", ret);
936         if(ret != APP_CONTROL_ERROR_NONE)
937                 goto error;
938
939         ret = app_control_set_operation(service_handle, APP_CONTROL_OPERATION_VIEW);
940         if(ret != APP_CONTROL_ERROR_NONE)
941                 goto error;
942
943         log_print(NET_POPUP, "service set operation is successful");
944
945         ret = app_control_set_uri(service_handle, "http://www.google.com");
946
947         app_control_to_bundle (service_handle, &b);
948         if(ret != APP_CONTROL_ERROR_NONE)
949                 goto error;
950
951         noti_err = notification_set_execute_option(noti,
952                         NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "Launch", NULL, b);
953         if (noti_err != NOTIFICATION_ERROR_NONE) {
954                 log_print(NET_POPUP, "fail to notification_set_execute_option");
955                 goto error;
956         }
957
958         noti_err = notification_insert(noti, NULL);
959         if (noti_err != NOTIFICATION_ERROR_NONE) {
960                 log_print(NET_POPUP, "fail to notification_insert");
961                 goto error;
962         }
963
964         log_print(NET_POPUP, "Successfully added notification");
965
966 error:
967         g_free(ap_name);
968         if (noti != NULL)
969                 notification_free(noti);
970
971         if (service_handle != NULL)
972                 app_control_destroy(service_handle);
973 }
974
975 static void __net_popup_del_portal_noti(void)
976 {
977         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
978
979         noti_err = notification_delete_all_by_type("net.netpopup", NOTIFICATION_TYPE_NOTI);
980         if (noti_err != NOTIFICATION_ERROR_NONE) {
981                 log_print(NET_POPUP, "fail to notification_delete_all_by_type");
982                 return;
983         }
984
985         log_print(NET_POPUP, "Successfully deleted notification");
986 }
987
988 EXPORT_API int main(int argc, char *argv[])
989 {
990         app_event_callback_s app_callback = {
991                 .create = __net_popup_create,
992                 .terminate = __net_popup_terminate,
993                 .pause = __net_popup_pause,
994                 .resume = __net_popup_resume,
995                 .app_control = __net_popup_service_cb,
996                 .low_memory =NULL,
997                 .low_battery =NULL,
998                 .device_orientation = NULL,
999                 .language_changed =NULL,
1000                 .region_format_changed =NULL,
1001         };
1002
1003         return app_efl_main(&argc, &argv, &app_callback, NULL);
1004 }
1005