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