Notification launch support. (TIVI-2926/1892)
[profile/ivi/ico-uxf-homescreen.git] / src / onscreen / CicoOSPopWindow.cpp
1 /*
2  * Copyright (c) 2014, TOYOTA MOTOR CORPORATION.
3  *
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
7  *
8  */
9 /**
10  * @brief   On Screen Popup Window
11  *
12  * @date    Feb-17-2014
13  */
14 #include <Ecore.h>
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"
23
24 using namespace std;
25
26 //==========================================================================
27 // static members
28 //==========================================================================
29
30 //==========================================================================
31 // functions
32 //==========================================================================
33
34 //--------------------------------------------------------------------------
35 /**
36  * @brief   CicoOnScreen::CicoOnScreen
37  *          Constractor
38  *
39  * @param[in]   none
40  * @return      none
41  */
42 //--------------------------------------------------------------------------
43 CicoOSPopWindow::CicoOSPopWindow(notification_type_e type) : CicoNotification(type)
44 {
45     ICO_TRA("Enter type(%d)", (int)type);
46     m_window      = NULL;
47     m_icon        = NULL;
48     m_theme       = NULL;
49     m_resourceId  = 0;
50     m_context     = NULL;
51     m_buttonTouch = false;
52     ICO_TRA("Leave");
53 }
54
55 CicoOSPopWindow::CicoOSPopWindow(notification_h noti) : CicoNotification(noti)
56 {
57     ICO_TRA("Enter");
58     m_window      = NULL;
59     m_icon        = NULL;
60     m_theme       = NULL;
61     m_resourceId  = 0;
62     m_context     = NULL;
63     m_buttonTouch = false;
64     ICO_TRA("Leave");
65 }
66 //--------------------------------------------------------------------------
67 /**
68  * @brief   CicoOnScreen::~CicoOnScreen
69  *          Destractor
70  *
71  * @param[in]   none
72  * @return      none
73  */
74 //--------------------------------------------------------------------------
75 CicoOSPopWindow::~CicoOSPopWindow(void)
76 {
77     ICO_TRA("Enter sur:%d, priv_id:%d", m_resourceId, GetPrivId());
78     if (NULL != m_window) {
79         ecore_evas_free(m_window);
80         m_window = NULL;
81     }
82     // if (NULL != m_icon) /* import m_window */
83     m_icon = NULL;
84     // if (NULL != m_theme) /* import m_window */
85     m_theme = NULL;
86     if (NULL != m_context) {
87         int r = ico_syc_release_res(m_context);
88         ICO_DBG("_____ %d = ico_syc_release_res", r);
89     }
90
91     ICO_DBG("_____ %d, %d", (int)m_buttonTouch, (int)m_appsvc_pkgname.empty());
92
93     if ((true == m_buttonTouch) && (false == m_appsvc_pkgname.empty())) {
94         CicoOSClient* cosc = CicoOSClient::getInstance();
95         if (NULL != cosc) {
96             int r = cosc->sendLaunchMessage(m_appsvc_pkgname);
97             ICO_DBG("_____ SendMsg:%d, %s", r, m_appsvc_pkgname.c_str());
98         }
99     }
100
101     ICO_TRA("Leave");
102 }
103
104 //--------------------------------------------------------------------------
105 /**
106  * @brief   CicoOnScreen::ShowPopup
107  *          Show popup window
108  *
109  * @param[in]   none
110  * @return      none
111  */
112 //--------------------------------------------------------------------------
113 bool
114 CicoOSPopWindow::showPopup()
115 {
116     ICO_TRA("Enter");
117     if (NULL == m_window) {
118         if (false == InitializeWindow()) {
119             ICO_TRA("Leave false");
120             return false;
121         }
122     }
123     // get caller pachage name
124     const char *pkgname = GetPkgname();
125
126     // get priv_id
127     int priv_id = GetPrivId();
128
129     // Get title
130     const char *title = GetTitle();
131
132     // Get content
133     const char *content = GetContent();
134
135     // Get execute option
136     const char *text = NULL;
137     bundle *service_handle = NULL;
138     (void)GetExecuteOption(NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, &text,
139                            &service_handle);
140
141     // Get icon path
142     const char *icon = GetIconPath();
143     ICO_DBG("Received: %s : %i : %s : %s : %s : %x",
144             pkgname, priv_id, title, content,
145             text, (int)service_handle);
146
147     if (NULL != service_handle) {
148         const char* pn = appsvc_get_pkgname(service_handle);
149         if (NULL != pn) {
150             ICO_DBG("Received: appsvc_get_pkgname:%s", pn);
151             m_appsvc_pkgname = pn;
152             m_buttonTouch = false;
153         }
154     }
155
156     if (icon) {
157         if (NULL != m_icon) {
158             evas_object_image_file_set(m_icon, icon, NULL);
159             evas_object_show(m_icon);
160         }
161     }
162
163     if (title) {
164         if (!edje_object_part_text_set(m_theme, "title_text", title)) {
165             ICO_WRN("could not set the text. Maybe part 'text' does not exist?");
166         }
167     }
168
169     if (content) {
170         if (strlen(content) <= 25) {
171             ICO_DBG("content text center");
172             if (!edje_object_part_text_set(m_theme, "content_text_center", content)) {
173                 ICO_WRN("could not set the text. Maybe part 'text' does not exist?");
174             }
175             if (!edje_object_part_text_set(m_theme, "content_text_left", "")) {
176                 ICO_WRN("could not set the text. Maybe part 'text' does not exist?");
177             }
178         }
179         else {
180             ICO_DBG("content text left");
181             if (!edje_object_part_text_set(m_theme, "content_text_left", content)) {
182                 ICO_WRN("could not set the text. Maybe part 'text' does not exist?");
183             }
184             if (!edje_object_part_text_set(m_theme, "content_text_center", "")) {
185                 ICO_WRN("could not set the text. Maybe part 'text' does not exist?");
186             }
187         }
188     }
189
190     if (text) {
191         if (!edje_object_part_text_set(m_theme, "button_text", text)) {
192             ICO_WRN("could not set the text. Maybe part 'text' does not exist?");
193         }
194     }
195     else {
196         if (!edje_object_part_text_set(m_theme, "button_text", "OK")) {
197             ICO_WRN("could not set the text. Maybe part 'text' does not exist?");
198         }
199     }
200
201     evas_object_show(m_theme);
202     ICO_TRA("Leave true");
203     return true;
204 }
205
206 bool 
207 CicoOSPopWindow::acquireRes()
208 {
209     ICO_TRA("Enter");
210     if (NULL != m_context) {
211         ICO_TRA("Leave false");
212         return false;
213     }
214     ico_syc_res_window_t w;
215     makeResWindowT(w);
216     m_context = ico_syc_acquire_res( &w, NULL, NULL, ICO_SYC_RES_ONSCREEN);
217     if (NULL == m_context) {
218         ICO_TRA("Leave false");
219         return false;
220     }
221     ICO_TRA("Leave true");
222     return true;
223 }
224
225 //--------------------------------------------------------------------------
226 /**
227  * @brief   CicoOnScreen::HidePopup
228  *          Hide popup window
229  *
230  * @param[in]   data        The user data passed from the callback
231  *                          registration function
232  * @param[in]   e           The handle to the popup window
233  * @param[in]   obj         The handle to the Evas object
234  * @param[in]   event_info  Event information
235  * @return      none
236  */
237 //--------------------------------------------------------------------------
238 void
239 CicoOSPopWindow::hidePopup(bool buttonTouch)
240 {
241     ICO_TRA("Enter %s", buttonTouch? "true": "false");
242     m_buttonTouch = buttonTouch;
243     releaseRes();
244     ICO_TRA("Leave");
245 }
246
247 bool    
248 CicoOSPopWindow::releaseRes()
249 {
250     ICO_TRA("Enter");
251     if (NULL != m_context) {
252         int r = ico_syc_release_res(m_context);
253         ICO_DBG("_____ %d = ico_syc_release_res", r);
254         if (ICO_SYC_ERR_NONE == r) {
255             m_context = NULL;
256             ICO_TRA("Leave true");
257             return true;
258         }
259     }
260     ICO_TRA("Leave false");
261     return false;
262 }
263
264
265 //--------------------------------------------------------------------------
266 /**
267  * @brief   CicoOnScreen::InitializePopup
268  *          Initialize popup window
269  *
270  * @param[in]   none
271  * @return      none
272  */
273 //--------------------------------------------------------------------------
274 bool
275 CicoOSPopWindow::InitializeWindow(void)
276 {
277     ICO_TRA("Enter");
278     if (false == createMainWindow()) {
279         ICO_TRA("Leave(ERR)");
280         return false;
281     }
282     m_theme = edje_object_add(ecore_evas_get(m_window));
283     if (NULL == m_theme) {
284         ICO_ERR("could not create edje object!");
285         ICO_TRA("Leave(ERR)");
286         return false;
287     }
288     if (!edje_object_file_set(m_theme, ICO_OS_THEMES_EDJ_FILEPATH, "main")) {
289         Edje_Load_Error err = edje_object_load_error_get(m_theme);
290         const char *errmsg = edje_load_error_str(err);
291         ICO_ERR("could not load 'main' from onscreen.edj: %s", errmsg);
292         evas_object_del(m_theme);
293         m_theme = NULL;
294         return false;
295     }
296     // icon setup
297     m_icon = evas_object_image_filled_add(ecore_evas_get(m_window));
298     edje_object_part_swallow(m_theme, "icon", m_icon);
299     /* getting size of screen */
300     /* home screen size is full of display*/
301     int display_width  = 0;
302     int display_height = 0;
303     ecore_wl_screen_size_get(&display_width, &display_height);
304
305     ICO_DBG("display size w/h=%d/%d", display_width, display_height);
306     int popup_x = (display_width / 2) - (POPUP_FRAME_WIDTH / 2);
307     int popup_y = (display_height / 2) - (POPUP_FRAME_HEIGHT/ 2);
308     ICO_DBG("popup postion x/y=%d/%d", popup_x, popup_y);
309     evas_object_move(m_theme, popup_x, popup_y);
310     evas_object_resize(m_theme, POPUP_FRAME_WIDTH, POPUP_FRAME_HEIGHT);
311
312     Evas_Object* obj = NULL;
313     obj = (Evas_Object*)edje_object_part_object_get(m_theme, "button_text");
314     if (NULL != obj) {
315         evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_UP,
316                                        evasMouseUpCB, this);
317     }
318
319     obj = (Evas_Object*)edje_object_part_object_get(m_theme, "button");
320     if (NULL != obj) {
321         evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_UP,
322                                        evasMouseUpCB, this);
323     }
324     evas_object_show(m_theme);
325     ICO_TRA("Leave(OK)");
326     return true;
327 }
328
329 bool
330 CicoOSPopWindow::createMainWindow()
331 {
332     ICO_TRA("Enter");
333     // Window setup
334     m_window = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, "frame=0");
335     if (NULL == m_window) {
336         ICO_ERR("ecore_evas_new() error");
337         ICO_TRA("Leave(ERR)");
338         return false;
339     }
340     ecore_evas_alpha_set(m_window, EINA_TRUE);
341     ecore_evas_show(m_window);
342     ICO_TRA("Leave");
343     return true;
344 }
345
346 //--------------------------------------------------------------------------
347 /**
348  * @brief   callback function of evas mouse up event
349  *
350  * @param [in] data         The user data passed from the callback
351  *                          registration function
352  * @param [in] e            The handle to the popup window
353  * @param [in] obj          The handle to the Evas object
354  * @param [in] event_info   Event information
355  *
356  */
357 //--------------------------------------------------------------------------
358 void
359 CicoOSPopWindow::evasMouseUpCB(void *data, Evas *e, Evas_Object *obj,
360                                void *event_info)
361 {
362     ICO_TRA("Enter %x, %x, %x, %x", data, e, obj, event_info);
363     if (NULL != obj) {
364         ICO_DBG("_____ obj name=%s", evas_object_name_get(obj));
365     }
366     static_cast<CicoOSPopWindow*>(data)->hidePopup(true);
367     ICO_TRA("Leave");
368 }
369
370
371 static char id0_ECU[]         = "Center";
372
373 static char id00_display[]   = "Center";
374 // static char id01_display[]   = "Mid";
375
376 // static char id001_layer[]    = "Application";
377 // static char id002_layer[]    = "SoftKeyboard";
378 // static char id003_layer[]    = "HomeScreen";
379 // static char id004_layer[]    = "ControlBar";
380 // static char id005_layer[]    = "InterruptApp";
381 static char id006_layer[]    = "OnScreen";
382 // static char id007_layer[]    = "Touch";
383 // static char id008_layer[]    = "Cursor";
384 // static char id011_layer[]    = "MainApp";
385 // static char id012_layer[]    = "SubDispMainApp";
386 // static char id013_layer[]    = "SubDispSubApp";
387
388 static char id00611_layout[] = "Whole";
389 // static char id00612_layout[] = "Half";
390
391 static char id006111_area[]  = "Full";
392 // static char id006121_area[]  = "Upper";
393 // static char id006122_area[]  = "Lower";
394
395 static char role_incoming[] = "incoming";
396 static char role_message[]  = "message";
397 void
398 CicoOSPopWindow::makeResWindowT(ico_syc_res_window_t& w)
399 {
400     w.ECU         = id0_ECU;
401     w.display     = id00_display;
402     w.layer       = id006_layer;
403     w.layout      = id00611_layout;
404     w.area        = id006111_area;
405     w.dispatchApp = (char*)GetPkgname();
406     if (0 == strcmp(w.dispatchApp,"org.tizen.dialer")) {
407         w.role    = role_incoming;
408     }
409     else {
410         w.role    = role_message;
411     }
412     w.resourceId  = m_resourceId;
413 }
414
415 // vim: set expandtab ts=4 sw=4: