2 * Copyright (c) 2014, TOYOTA MOTOR CORPORATION.
4 * This program is licensed under the terms and conditions of the
5 * Apache License, version 2.0. The full text of the Apache License is at
6 * http://www.apache.org/licenses/LICENSE-2.0
10 * @brief On Screen Popup Window
15 #include <Ecore_Wayland.h>
16 #include <appsvc/appsvc.h>
17 #include "CicoOnScreen.h"
18 #include "CicoNotification.h"
19 #include "CicoOSPopWindow.h"
20 #include "ico_syc_type.h"
21 #include "ico_syc_appresctl.h"
22 #include "CicoOSClient.h"
26 //==========================================================================
28 //==========================================================================
29 Ecore_Evas* CicoOSPopWindow::m_window = NULL;
31 //==========================================================================
33 //==========================================================================
35 //--------------------------------------------------------------------------
37 * @brief CicoOnScreen::CicoOnScreen
43 //--------------------------------------------------------------------------
44 CicoOSPopWindow::CicoOSPopWindow(notification_type_e type) : CicoNotification(type)
46 ICO_TRA("Enter type(%d)", (int)type);
49 m_resourceId = CicoOnScreen::GetResourceId();
51 m_buttonTouch = false;
55 CicoOSPopWindow::CicoOSPopWindow(notification_h noti) : CicoNotification(noti)
60 m_resourceId = CicoOnScreen::GetResourceId();
62 m_buttonTouch = false;
66 //--------------------------------------------------------------------------
68 * @brief CicoOnScreen::~CicoOnScreen
74 //--------------------------------------------------------------------------
75 CicoOSPopWindow::~CicoOSPopWindow(void)
77 ICO_TRA("Enter sur:%08x, priv_id:%d", m_resourceId, GetPrivId());
79 if (NULL != m_context) {
80 int r = ico_syc_release_res(m_context);
81 ICO_DBG("_____ %d = ico_syc_release_res", r);
83 ICO_DBG("_____ %d, %d", (int)m_buttonTouch, (int)m_appsvc_pkgname.empty());
85 if ((true == m_buttonTouch) && (false == m_appsvc_pkgname.empty())) {
86 CicoOSClient* cosc = CicoOSClient::getInstance();
88 int r = cosc->sendLaunchMessage(m_appsvc_pkgname);
89 ICO_DBG("_____ SendMsg:%d, %s", r, m_appsvc_pkgname.c_str());
94 usleep(POPUP_DELETE_WAIT*1000);
95 evas_object_hide(m_theme);
96 evas_object_del(m_theme);
100 evas_object_hide(m_icon);
101 evas_object_del(m_icon);
107 //--------------------------------------------------------------------------
109 * @brief CicoOnScreen::ShowPopup
115 //--------------------------------------------------------------------------
117 CicoOSPopWindow::showPopup()
121 if (NULL == m_theme) {
122 if (false == InitializeWindow()) {
123 ICO_TRA("Leave false");
127 // get caller pachage name
128 const char *pkgname = GetPkgname();
131 int priv_id = GetPrivId();
134 const char *title = GetTitle();
137 const char *content = GetContent();
139 // Get execute option
140 const char *text = NULL;
141 bundle *service_handle = NULL;
142 (void)GetExecuteOption(NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, &text,
146 const char *icon = GetIconPath();
147 ICO_DBG("Received: %s : %i : %s : %s : %s : %p",
148 pkgname, priv_id, title, content, text, (void *)service_handle);
150 if (NULL != service_handle) {
151 const char* pn = appsvc_get_pkgname(service_handle);
153 ICO_DBG("Received: appsvc_get_pkgname:%s", pn);
154 m_appsvc_pkgname = pn;
155 m_buttonTouch = false;
160 if (NULL != m_icon) {
161 evas_object_image_file_set(m_icon, icon, NULL);
162 evas_object_show(m_icon);
167 if (!edje_object_part_text_set(m_theme, "title_text", title)) {
168 ICO_WRN("could not set the text. Maybe part 'text' does not exist?");
173 if (strlen(content) <= 25) {
174 ICO_DBG("content text center");
175 if (!edje_object_part_text_set(m_theme, "content_text_center", content)) {
176 ICO_WRN("could not set the text. Maybe part 'text' does not exist?");
178 if (!edje_object_part_text_set(m_theme, "content_text_left", "")) {
179 ICO_WRN("could not set the text. Maybe part 'text' does not exist?");
183 ICO_DBG("content text left");
184 if (!edje_object_part_text_set(m_theme, "content_text_left", content)) {
185 ICO_WRN("could not set the text. Maybe part 'text' does not exist?");
187 if (!edje_object_part_text_set(m_theme, "content_text_center", "")) {
188 ICO_WRN("could not set the text. Maybe part 'text' does not exist?");
194 if (!edje_object_part_text_set(m_theme, "button_text", text)) {
195 ICO_WRN("could not set the text. Maybe part 'text' does not exist?");
199 if (!edje_object_part_text_set(m_theme, "button_text", "OK")) {
200 ICO_WRN("could not set the text. Maybe part 'text' does not exist?");
204 evas_object_show(m_theme);
205 ICO_TRA("Leave true");
210 CicoOSPopWindow::acquireRes()
213 if (NULL != m_context) {
214 ICO_TRA("Leave false");
217 ico_syc_res_window_t w;
219 m_context = ico_syc_acquire_res(&w, NULL, NULL, ICO_SYC_RES_ONSCREEN);
220 if (NULL == m_context) {
221 ICO_TRA("Leave false");
224 ICO_TRA("Leave true");
228 //--------------------------------------------------------------------------
230 * @brief CicoOnScreen::HidePopup
233 * @param[in] data The user data passed from the callback
234 * registration function
235 * @param[in] e The handle to the popup window
236 * @param[in] obj The handle to the Evas object
237 * @param[in] event_info Event information
240 //--------------------------------------------------------------------------
242 CicoOSPopWindow::hidePopup(bool buttonTouch)
244 ICO_TRA("Enter %s", buttonTouch? "true": "false");
245 m_buttonTouch = buttonTouch;
251 CicoOSPopWindow::releaseRes()
254 if (NULL != m_context) {
255 int r = ico_syc_release_res(m_context);
256 ICO_DBG("_____ %d = ico_syc_release_res", r);
257 if (ICO_SYC_ERR_NONE == r) {
259 ICO_TRA("Leave true");
263 ICO_TRA("Leave false");
267 //--------------------------------------------------------------------------
269 * @brief CicoOnScreen::InitializeWindow
270 * Initialize popup window
275 //--------------------------------------------------------------------------
277 CicoOSPopWindow::InitializeWindow(void)
281 if (NULL == m_window) {
282 if (false == createMainWindow()) {
283 ICO_TRA("Leave(ERR)");
287 m_theme = edje_object_add(ecore_evas_get(m_window));
288 if (NULL == m_theme) {
289 ICO_ERR("could not create edje object!");
290 ICO_TRA("Leave(ERR)");
293 if (! edje_object_file_set(m_theme, ICO_OS_THEMES_EDJ_FILEPATH, "main")) {
294 Edje_Load_Error err = edje_object_load_error_get(m_theme);
295 const char *errmsg = edje_load_error_str(err);
296 ICO_ERR("could not load 'main' from onscreen.edj: %s", errmsg);
297 evas_object_del(m_theme);
302 m_icon = evas_object_image_filled_add(ecore_evas_get(m_window));
303 evas_object_pointer_mode_set(m_icon, EVAS_OBJECT_POINTER_MODE_NOGRAB);
304 edje_object_part_swallow(m_theme, "icon", m_icon);
306 /* getting size of screen */
307 /* home screen size is full of display */
308 int display_width = 0;
309 int display_height = 0;
310 ecore_wl_screen_size_get(&display_width, &display_height);
312 ICO_DBG("display size w/h=%d/%d", display_width, display_height);
313 int popup_x = (display_width / 2) - (POPUP_FRAME_WIDTH / 2);
314 int popup_y = (display_height / 2) - (POPUP_FRAME_HEIGHT/ 2);
315 ICO_DBG("popup postion x/y=%d/%d", popup_x, popup_y);
316 evas_object_move(m_theme, popup_x, popup_y);
317 evas_object_resize(m_theme, POPUP_FRAME_WIDTH, POPUP_FRAME_HEIGHT);
319 Evas_Object* obj = NULL;
320 obj = (Evas_Object*)edje_object_part_object_get(m_theme, "button_text");
322 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_UP,
323 evasMouseUpCB, this);
326 obj = (Evas_Object*)edje_object_part_object_get(m_theme, "button");
328 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_UP,
329 evasMouseUpCB, this);
331 evas_object_show(m_theme);
332 ICO_TRA("Leave(OK)");
337 CicoOSPopWindow::createMainWindow()
342 m_window = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, "frame=0");
343 if (NULL == m_window) {
344 ICO_ERR("ecore_evas_new() error");
345 ICO_TRA("Leave(ERR)");
349 ecore_evas_title_set(m_window, POPUP_WINDOW_TITLE);
350 ecore_evas_alpha_set(m_window, EINA_TRUE);
351 ecore_evas_show(m_window);
358 CicoOSPopWindow::removeMainWindow()
362 if (NULL != m_window) {
363 ecore_evas_free(m_window);
369 //--------------------------------------------------------------------------
371 * @brief callback function of evas mouse up event
373 * @param [in] data The user data passed from the callback
374 * registration function
375 * @param [in] e The handle to the popup window
376 * @param [in] obj The handle to the Evas object
377 * @param [in] event_info Event information
380 //--------------------------------------------------------------------------
382 CicoOSPopWindow::evasMouseUpCB(void *data, Evas *e, Evas_Object *obj,
385 ICO_TRA("Enter %x, %x, %x, %x", data, e, obj, event_info);
387 ICO_DBG("_____ obj name=%s", evas_object_name_get(obj));
389 static_cast<CicoOSPopWindow*>(data)->hidePopup(true);
394 static const char id0_ECU[] = "Center";
396 static const char id00_display[] = "Center";
397 static const char id006_layer[] = "OnScreen";
398 static const char id00611_layout[] = "Whole";
399 static const char id006111_area[] = "Full";
401 static const char role_incoming[] = "incoming";
402 static const char role_message[] = "message";
405 CicoOSPopWindow::makeResWindowT(ico_syc_res_window_t& w)
408 w.display = id00_display;
409 w.layer = id006_layer;
410 w.layout = id00611_layout;
411 w.area = id006111_area;
412 w.dispatchApp = (char*)GetPkgname();
413 if (0 == strcmp(w.dispatchApp,"org.tizen.dialer")) {
414 w.role = role_incoming;
417 w.role = role_message;
419 w.resourceId = m_resourceId;
422 // vim: set expandtab ts=4 sw=4: