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("FAIL: 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("FAIL: broadcast_dbus_signal(%d)", ret);
91 static void usb_device_confirm_ok_clicked(const struct popup_ops *ops)
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)
147 _E("bundle is null return -EINVAL");
151 app_id = (char *)bundle_get_val(b, "_APP_PID_");
153 _E("Failed to get pid");
158 ret = app_manager_get_app_id(pid, &app_id);
159 if (ret != APP_MANAGER_ERROR_NONE) {
160 _E("Failed to get app id(%d)", ret);
164 text = gl_text_get(0);
166 snprintf(content, len, text, app_id);
175 check_changed_cb(void *data, Evas_Object *obj, void *event_info)
177 Eina_Bool state = elm_check_state_get(obj);
179 App_confirm_box = state;
182 static int usbhost_show(bundle *b, const struct popup_ops *ops)
187 Evas_Object *scroller;
191 struct object_ops *obj;
193 char content[BUF_MAX] = {'\0',};
195 ret = get_object_by_ops(ops, &obj);
197 _E("Failed to get object (%d)", ret);
205 evas_object_show(win);
207 popup = elm_popup_add(win);
211 elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
212 elm_object_part_text_set(popup, "title,text", "USB Host Test");
213 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
216 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, event_back_key_up, (void*)ops);
219 layout = elm_layout_add(popup);
220 elm_layout_file_set(layout, ELM_USB_EDC, "popup_checkview_layout");
221 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
222 elm_object_part_text_set(layout, "elm.text", "Description text");
225 btn = elm_button_add(popup);
226 elm_object_style_set(btn, "bottom");
227 elm_object_text_set(btn, gl_text_get(3));
228 elm_object_part_content_set(popup, "button1", btn);
229 evas_object_smart_callback_add(btn, "clicked", usbhost_confirm_cancel_clicked, ops);
232 btn = elm_button_add(popup);
233 elm_object_style_set(btn, "bottom");
234 elm_object_text_set(btn, gl_text_get(2));
235 elm_object_part_content_set(popup, "button2", btn);
236 evas_object_smart_callback_add(btn, "clicked", usbhost_confirm_ok_clicked, ops);
239 check = elm_check_add(popup);
240 elm_object_text_set(check, gl_text_get(1));
241 elm_object_part_content_set(layout, "elm.swallow.end", check);
242 evas_object_smart_callback_add(check, "changed", check_changed_cb, NULL);
245 scroller = elm_scroller_add(layout);
246 elm_scroller_bounce_set(scroller, EINA_TRUE, EINA_TRUE);
247 elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
248 elm_object_part_content_set(layout, "elm.swallow.content", scroller);
251 label = elm_label_add(scroller);
252 elm_object_style_set(label, "popup/default");
253 elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
255 ret = usbhost_get_contents(b, content, sizeof(content));
259 elm_object_text_set(label, content);
260 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
261 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
262 evas_object_show(label);
263 elm_object_content_set(scroller, label);
265 elm_object_content_set(popup, layout);
267 evas_object_show(popup);
273 static const struct popup_ops usb_device_confirm_ops = {
274 .name = "usb_device_confirm",
275 .show = load_simple_popup,
276 .content = "Do you use this usb device?", /* TODO */
277 .left_text = "IDS_COM_SK_CANCEL",
278 .left = usb_device_confirm_cancel_clicked,
279 .right_text = "IDS_COM_SK_OK",
280 .right = usb_device_confirm_ok_clicked,
281 .terminate = usb_device_confirm_terminate,
284 static const struct popup_ops usbhost_confirm_ops = {
286 .pattern = FEEDBACK_PATTERN_LOWBATT,
287 .show = usbhost_show,
288 .terminate = usbhost_confirm_terminate,
291 /* Constructor to register usb_device popup */
292 static __attribute__ ((constructor)) void usb_device_register_popup(void)
294 register_popup(&usb_device_confirm_ops);
295 register_popup(&usbhost_confirm_ops);