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