4 * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include "popup-common.h"
22 #include <pkgmgr-info.h>
23 #include <app_manager.h>
25 enum button_selected_e {
26 USB_DEVICE_CONFIRM_NOK,
30 #define USD_PATH "/Org/Tizen/System/USD"
31 #define USD_INTERFACE "org.tizen.system.usd"
32 #define USD_USB_DEVICE_CONFIRM_SIGNAL "USBDeviceOpenResult"
34 #define USBHOST_PATH "/Org/Tizen/System/Popup/System"
35 #define USBHOST_INTERFACE "org.tizen.system.popup.System"
36 #define USBHOST_APP_CONFIRM_SIGNAL "USBHostResult"
40 static const struct popup_ops usb_device_confirm_ops;
41 static Eina_Bool App_confirm_box = 0;
43 static char *items[] = {
44 "IDS_COM_POP_ALLOW_APPLICATION_P1SS_TO_ACCESS_USB_DEVICE_Q_ABB",
45 "IDS_COM_BODY_ALLOWS_AN_APPLICATION_TO_ACCESS_USB_DEVICES",
50 char* gl_text_get(int index)
53 return strdup(_(items[index]));
56 static void send_result_dbus_signal(int result)
62 snprintf(buf, sizeof(buf), "%d", result);
64 ret = broadcast_dbus_signal(USD_PATH,
66 USD_USB_DEVICE_CONFIRM_SIGNAL,
69 _E("Failed to broadcast_dbus_signal: %d", ret);
72 static void send_usbhost_result_dbus_signal(int result)
75 char buf1[8], buf2[8];
78 snprintf(buf1, sizeof(buf1), "%d", result);
80 snprintf(buf2, sizeof(buf2), "%d", App_confirm_box);
83 ret = broadcast_dbus_signal(USBHOST_PATH,
85 USBHOST_APP_CONFIRM_SIGNAL,
88 _E("Failed to broadcast_dbus_signal: %d", ret);
91 static void usb_device_confirm_ok_clicked(const struct popup_ops *ops)
93 _I("OK is selected.");
94 unload_simple_popup(ops);
95 send_result_dbus_signal(USB_DEVICE_CONFIRM_OK);
96 terminate_if_no_popup();
99 static void usb_device_confirm_cancel_clicked(const struct popup_ops *ops)
101 _I("CANCEL is selected.");
102 unload_simple_popup(ops);
103 send_result_dbus_signal(USB_DEVICE_CONFIRM_NOK);
104 terminate_if_no_popup();
107 static void usb_device_confirm_terminate(const struct popup_ops *ops)
109 _I("Terminate usb device confirm popup.");
110 send_result_dbus_signal(USB_DEVICE_CONFIRM_NOK);
111 terminate_if_no_popup();
114 static void usbhost_confirm_terminate(const struct popup_ops *ops)
116 _I("Terminate usb device confirm popup.");
117 terminate_if_no_popup();
120 static void usbhost_confirm_ok_clicked(void *data, Evas_Object *obj, void *event_info)
122 const struct popup_ops *ops = data;
124 _I("OK is selected.");
125 unload_simple_popup(ops);
126 send_usbhost_result_dbus_signal(USB_DEVICE_CONFIRM_OK);
127 terminate_if_no_popup();
130 static void usbhost_confirm_cancel_clicked(void *data, Evas_Object *obj, void *event_info)
132 const struct popup_ops *ops = data;
134 _I("CANCEL is selected.");
135 unload_simple_popup(ops);
136 send_usbhost_result_dbus_signal(USB_DEVICE_CONFIRM_NOK);
137 terminate_if_no_popup();
140 static int usbhost_get_contents(bundle *b, char *content, unsigned int len)
143 char *text = NULL, *app_pid = NULL, *app_name = NULL;
147 _E("Bundle is null return -EINVAL.");
151 app_pid = (char *)bundle_get_val(b, "_APP_PID_");
153 _E("Failed to get pid.");
160 ret = app_manager_get_app_id(pid, &app_name);
161 if (ret != APP_MANAGER_ERROR_NONE) {
162 _E("Failed to get app id: %d", ret);
166 text = gl_text_get(0);
168 snprintf(content, len, text, app_name);
177 check_changed_cb(void *data, Evas_Object *obj, void *event_info)
179 Eina_Bool state = elm_check_state_get(obj);
181 App_confirm_box = state;
184 static int usbhost_show(bundle *b, const struct popup_ops *ops)
189 Evas_Object *scroller;
193 struct object_ops *obj;
195 char content[BUF_MAX] = {'\0',};
197 ret = get_object_by_ops(ops, &obj);
199 _E("Failed to get object: %d", ret);
207 evas_object_show(win);
209 popup = elm_popup_add(win);
213 elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
214 elm_object_part_text_set(popup, "title,text", "USB Host Test");
215 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
218 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, event_back_key_up, (void*)ops);
221 layout = elm_layout_add(popup);
222 elm_layout_file_set(layout, ELM_USB_EDC, "popup_checkview_layout");
223 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
224 elm_object_part_text_set(layout, "elm.text", "Description text");
227 btn = elm_button_add(popup);
228 elm_object_style_set(btn, "bottom");
229 elm_object_text_set(btn, gl_text_get(3));
230 elm_object_part_content_set(popup, "button1", btn);
231 evas_object_smart_callback_add(btn, "clicked", usbhost_confirm_cancel_clicked, ops);
234 btn = elm_button_add(popup);
235 elm_object_style_set(btn, "bottom");
236 elm_object_text_set(btn, gl_text_get(2));
237 elm_object_part_content_set(popup, "button2", btn);
238 evas_object_smart_callback_add(btn, "clicked", usbhost_confirm_ok_clicked, ops);
241 check = elm_check_add(popup);
242 elm_object_text_set(check, gl_text_get(1));
243 elm_object_part_content_set(layout, "elm.swallow.end", check);
244 evas_object_smart_callback_add(check, "changed", check_changed_cb, NULL);
247 scroller = elm_scroller_add(layout);
248 elm_scroller_bounce_set(scroller, EINA_TRUE, EINA_TRUE);
249 elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
250 elm_object_part_content_set(layout, "elm.swallow.content", scroller);
253 label = elm_label_add(scroller);
254 elm_object_style_set(label, "popup/default");
255 elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
257 ret = usbhost_get_contents(b, content, sizeof(content));
261 elm_object_text_set(label, content);
262 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
263 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
264 evas_object_show(label);
265 elm_object_content_set(scroller, label);
267 elm_object_content_set(popup, layout);
269 evas_object_show(popup);
275 static const struct popup_ops usb_device_confirm_ops = {
276 .name = "usb_device_confirm",
277 .show = load_simple_popup,
278 .content = "Do you use this usb device?", /* TODO */
279 .left_text = "IDS_COM_SK_CANCEL",
280 .left = usb_device_confirm_cancel_clicked,
281 .right_text = "IDS_COM_SK_OK",
282 .right = usb_device_confirm_ok_clicked,
283 .terminate = usb_device_confirm_terminate,
286 static const struct popup_ops usbhost_confirm_ops = {
288 .pattern = FEEDBACK_PATTERN_LOWBATT,
289 .show = usbhost_show,
290 .terminate = usbhost_confirm_terminate,
293 /* Constructor to register usb_device popup */
294 static __attribute__ ((constructor)) void usb_device_register_popup(void)
296 register_popup(&usb_device_confirm_ops);
297 register_popup(&usbhost_confirm_ops);