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 <tzplatform_config.h>
18 #include "CicoOnScreen.h"
19 #include "CicoNotification.h"
20 #include "CicoOSPopWindow.h"
21 #include "ico_syc_type.h"
22 #include "ico_syc_private.h"
23 #include "ico_syc_appresctl.h"
24 #include "CicoOSClient.h"
28 //==========================================================================
30 //==========================================================================
31 Ecore_Evas* CicoOSPopWindow::m_window = NULL;
33 //==========================================================================
35 //==========================================================================
37 //--------------------------------------------------------------------------
39 * @brief CicoOnScreen::CicoOnScreen
45 //--------------------------------------------------------------------------
46 CicoOSPopWindow::CicoOSPopWindow(notification_type_e type) : CicoNotification(type)
48 ICO_TRA("Enter type(%d)", (int)type);
51 m_resourceId = CicoOnScreen::GetResourceId();
53 m_buttonTouch = false;
57 CicoOSPopWindow::CicoOSPopWindow(notification_h noti) : CicoNotification(noti)
62 m_resourceId = CicoOnScreen::GetResourceId();
64 m_buttonTouch = false;
68 //--------------------------------------------------------------------------
70 * @brief CicoOnScreen::~CicoOnScreen
76 //--------------------------------------------------------------------------
77 CicoOSPopWindow::~CicoOSPopWindow(void)
79 ICO_TRA("Enter sur:%08x, priv_id:%d", m_resourceId, GetPrivId());
81 if (NULL != m_context) {
82 int r = ico_syc_release_res(m_context);
83 ICO_DBG("_____ %d = ico_syc_release_res", r);
85 ICO_DBG("_____ %d, %d", (int)m_buttonTouch, (int)m_appsvc_pkgname.empty());
87 if ((true == m_buttonTouch) && (false == m_appsvc_pkgname.empty())) {
88 CicoOSClient* cosc = CicoOSClient::getInstance();
90 int r = cosc->sendLaunchMessage(m_appsvc_pkgname);
91 ICO_DBG("_____ SendMsg:%d, %s", r, m_appsvc_pkgname.c_str());
96 usleep(POPUP_DELETE_WAIT*1000);
97 evas_object_hide(m_theme);
98 evas_object_del(m_theme);
102 evas_object_hide(m_icon);
103 evas_object_del(m_icon);
109 //--------------------------------------------------------------------------
111 * @brief CicoOnScreen::ShowPopup
117 //--------------------------------------------------------------------------
119 CicoOSPopWindow::showPopup()
123 if (NULL == m_theme) {
124 if (false == InitializeWindow()) {
125 ICO_TRA("Leave false");
129 // get caller pachage name
130 const char *pkgname = GetPkgname();
133 int priv_id = GetPrivId();
136 const char *title = GetTitle();
139 const char *content = GetContent();
141 // Get execute option
142 const char *text = NULL;
143 bundle *service_handle = NULL;
144 (void)GetExecuteOption(NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, &text,
148 const char *icon = GetIconPath();
149 ICO_DBG("Received: %s : %i : %s : %s : %s : %p",
150 pkgname, priv_id, title, content, text, (void *)service_handle);
152 if (NULL != service_handle) {
153 const char* pn = appsvc_get_pkgname(service_handle);
155 ICO_DBG("Received: appsvc_get_pkgname:%s", pn);
156 m_appsvc_pkgname = pn;
157 m_buttonTouch = false;
162 if (NULL != m_icon) {
163 evas_object_image_file_set(m_icon, icon, NULL);
164 evas_object_show(m_icon);
169 if (!edje_object_part_text_set(m_theme, "title_text", title)) {
170 ICO_WRN("could not set the text. Maybe part 'text' does not exist?");
175 if (strlen(content) <= 25) {
176 ICO_DBG("content text center");
177 if (!edje_object_part_text_set(m_theme, "content_text_center", content)) {
178 ICO_WRN("could not set the text. Maybe part 'text' does not exist?");
180 if (!edje_object_part_text_set(m_theme, "content_text_left", "")) {
181 ICO_WRN("could not set the text. Maybe part 'text' does not exist?");
185 ICO_DBG("content text left");
186 if (!edje_object_part_text_set(m_theme, "content_text_left", content)) {
187 ICO_WRN("could not set the text. Maybe part 'text' does not exist?");
189 if (!edje_object_part_text_set(m_theme, "content_text_center", "")) {
190 ICO_WRN("could not set the text. Maybe part 'text' does not exist?");
196 if (!edje_object_part_text_set(m_theme, "button_text", text)) {
197 ICO_WRN("could not set the text. Maybe part 'text' does not exist?");
201 if (!edje_object_part_text_set(m_theme, "button_text", "OK")) {
202 ICO_WRN("could not set the text. Maybe part 'text' does not exist?");
206 evas_object_show(m_theme);
207 ICO_TRA("Leave true");
212 CicoOSPopWindow::acquireRes()
215 if (NULL != m_context) {
216 ICO_TRA("Leave false");
219 ico_syc_res_window_t w;
221 m_context = ico_syc_acquire_res(&w, NULL, NULL, ICO_SYC_RES_ONSCREEN);
222 if (NULL == m_context) {
223 ICO_TRA("Leave false");
226 ICO_TRA("Leave true");
230 //--------------------------------------------------------------------------
232 * @brief CicoOnScreen::HidePopup
235 * @param[in] data The user data passed from the callback
236 * registration function
237 * @param[in] e The handle to the popup window
238 * @param[in] obj The handle to the Evas object
239 * @param[in] event_info Event information
242 //--------------------------------------------------------------------------
244 CicoOSPopWindow::hidePopup(bool buttonTouch)
246 ICO_TRA("Enter %s", buttonTouch? "true": "false");
247 m_buttonTouch = buttonTouch;
253 CicoOSPopWindow::releaseRes()
256 if (NULL != m_context) {
257 int r = ico_syc_release_res(m_context);
258 ICO_DBG("_____ %d = ico_syc_release_res", r);
259 if (ICO_SYC_ERR_NONE == r) {
261 ICO_TRA("Leave true");
265 ICO_TRA("Leave false");
269 //--------------------------------------------------------------------------
271 * @brief CicoOnScreen::InitializeWindow
272 * Initialize popup window
277 //--------------------------------------------------------------------------
279 CicoOSPopWindow::InitializeWindow(void)
283 if (NULL == m_window) {
284 if (false == createMainWindow()) {
285 ICO_TRA("Leave(ERR)");
289 m_theme = edje_object_add(ecore_evas_get(m_window));
290 if (NULL == m_theme) {
291 ICO_ERR("could not create edje object!");
292 ICO_TRA("Leave(ERR)");
295 if (! edje_object_file_set(m_theme,
296 tzplatform_mkpath(TZ_SYS_RO_APP,
297 ICO_OS_THEMES_EDJ_FILEPATH), "main")) {
298 Edje_Load_Error err = edje_object_load_error_get(m_theme);
299 const char *errmsg = edje_load_error_str(err);
300 ICO_ERR("could not load 'main' from onscreen.edj: %s", errmsg);
301 evas_object_del(m_theme);
306 m_icon = evas_object_image_filled_add(ecore_evas_get(m_window));
307 evas_object_pointer_mode_set(m_icon, EVAS_OBJECT_POINTER_MODE_NOGRAB);
308 edje_object_part_swallow(m_theme, "icon", m_icon);
310 /* getting size of screen */
311 /* home screen size is full of display */
312 int display_width = 0;
313 int display_height = 0;
314 ecore_wl_screen_size_get(&display_width, &display_height);
316 ICO_DBG("display size w/h=%d/%d", display_width, display_height);
317 int popup_x = (display_width / 2) - (POPUP_FRAME_WIDTH / 2);
318 int popup_y = (display_height / 2) - (POPUP_FRAME_HEIGHT/ 2);
319 ICO_DBG("popup postion x/y=%d/%d", popup_x, popup_y);
320 evas_object_move(m_theme, popup_x, popup_y);
321 evas_object_resize(m_theme, POPUP_FRAME_WIDTH, POPUP_FRAME_HEIGHT);
323 Evas_Object* obj = NULL;
324 obj = (Evas_Object*)edje_object_part_object_get(m_theme, "button_text");
326 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_UP,
327 evasMouseUpCB, this);
330 obj = (Evas_Object*)edje_object_part_object_get(m_theme, "button");
332 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_UP,
333 evasMouseUpCB, this);
335 evas_object_show(m_theme);
336 ICO_TRA("Leave(OK)");
341 CicoOSPopWindow::createMainWindow()
346 m_window = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, "frame=0");
347 if (NULL == m_window) {
348 ICO_ERR("ecore_evas_new() error");
349 ICO_TRA("Leave(ERR)");
353 ecore_evas_title_set(m_window, POPUP_WINDOW_TITLE);
354 ecore_evas_alpha_set(m_window, EINA_TRUE);
355 ecore_evas_show(m_window);
362 CicoOSPopWindow::removeMainWindow()
366 if (NULL != m_window) {
367 ecore_evas_free(m_window);
373 //--------------------------------------------------------------------------
375 * @brief callback function of evas mouse up event
377 * @param [in] data The user data passed from the callback
378 * registration function
379 * @param [in] e The handle to the popup window
380 * @param [in] obj The handle to the Evas object
381 * @param [in] event_info Event information
384 //--------------------------------------------------------------------------
386 CicoOSPopWindow::evasMouseUpCB(void *data, Evas *e, Evas_Object *obj,
389 ICO_TRA("Enter %x, %x, %x, %x", data, e, obj, event_info);
391 ICO_DBG("_____ obj name=%s", evas_object_name_get(obj));
393 static_cast<CicoOSPopWindow*>(data)->hidePopup(true);
398 static const char id0_ECU[] = "Center";
400 static const char id00_display[] = "Center";
401 static const char id006_layer[] = "OnScreen";
402 static const char id00611_layout[] = "Whole";
403 static const char id006111_area[] = "Full";
405 static const char role_incoming[] = "incoming";
406 static const char role_message[] = "message";
409 CicoOSPopWindow::makeResWindowT(ico_syc_res_window_t& w)
412 w.display = id00_display;
413 w.layer = id006_layer;
414 w.layout = id00611_layout;
415 w.area = id006111_area;
416 w.dispatchApp = (char*)GetPkgname();
417 if (0 == strcmp(w.dispatchApp, ICO_SYC_PACKAGE_DIALER)) {
418 w.role = role_incoming;
421 w.role = role_message;
423 w.resourceId = m_resourceId;
426 // vim: set expandtab ts=4 sw=4: