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