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