bug fix: HomeScreen sometimes fails in connection with SystemController at the time...
[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 sur:%d, priv_id:%d", m_resourceId, GetPrivId());
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     if (false == createMainWindow()) {
256         ICO_TRA("Leave(ERR)");
257         return false;
258     }
259     m_theme = edje_object_add(ecore_evas_get(m_window));
260     if (NULL == m_theme) {
261         ICO_ERR("could not create edje object!");
262         ICO_TRA("Leave(ERR)");
263         return false;
264     }
265     if (!edje_object_file_set(m_theme, ICO_OS_THEMES_EDJ_FILEPATH, "main")) {
266         Edje_Load_Error err = edje_object_load_error_get(m_theme);
267         const char *errmsg = edje_load_error_str(err);
268         ICO_ERR("could not load 'main' from onscreen.edj: %s", errmsg);
269         evas_object_del(m_theme);
270         m_theme = NULL;
271         return false;
272     }
273     // icon setup
274     m_icon = evas_object_image_filled_add(ecore_evas_get(m_window));
275     edje_object_part_swallow(m_theme, "icon", m_icon);
276     /* getting size of screen */
277     /* home screen size is full of display*/
278     int display_width  = 0;
279     int display_height = 0;
280     ecore_wl_screen_size_get(&display_width, &display_height);
281
282     ICO_DBG("display size w/h=%d/%d", display_width, display_height);
283     int popup_x = (display_width / 2) - (POPUP_FRAME_WIDTH / 2);
284     int popup_y = (display_height / 2) - (POPUP_FRAME_HEIGHT/ 2);
285     ICO_DBG("popup postion x/y=%d/%d", popup_x, popup_y);
286     evas_object_move(m_theme, popup_x, popup_y);
287     evas_object_resize(m_theme, POPUP_FRAME_WIDTH, POPUP_FRAME_HEIGHT);
288
289     Evas_Object* obj = NULL;
290     obj = (Evas_Object*)edje_object_part_object_get(m_theme, "button_text");
291     if (NULL != obj) {
292         evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_UP,
293                                        evasMouseUpCB, this);
294     }
295
296     obj = (Evas_Object*)edje_object_part_object_get(m_theme, "button");
297     if (NULL != obj) {
298         evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_UP,
299                                        evasMouseUpCB, this);
300     }
301     evas_object_show(m_theme);
302     ICO_TRA("Leave(OK)");
303     return true;
304 }
305
306 bool
307 CicoOSPopWindow::createMainWindow()
308 {
309     ICO_TRA("Enter");
310     // Window setup
311     m_window = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, "frame=0");
312     if (NULL == m_window) {
313         ICO_ERR("ecore_evas_new() error");
314         ICO_TRA("Leave(ERR)");
315         return false;
316     }
317     ecore_evas_show(m_window);
318     ICO_TRA("Leave");
319     return true;
320 }
321
322 //--------------------------------------------------------------------------
323 /**
324  * @brief   callback function of evas mouse up event
325  *
326  * @param [in] data         The user data passed from the callback
327  *                          registration function
328  * @param [in] e            The handle to the popup window
329  * @param [in] obj          The handle to the Evas object
330  * @param [in] event_info   Event information
331  *
332  */
333 //--------------------------------------------------------------------------
334 void
335 CicoOSPopWindow::evasMouseUpCB(void *data, Evas *e, Evas_Object *obj,
336                                void *event_info)
337 {
338     ICO_TRA("Enter %x, %x, %x, %x", data, e, obj, event_info);
339     if (NULL != obj) {
340         ICO_DBG("_____ obj name=%s", evas_object_name_get(obj));
341     }
342     static_cast<CicoOSPopWindow*>(data)->hidePopup();
343     ICO_TRA("Leave");
344 }
345
346
347 static char id0_ECU[]         = "Center";
348
349 static char id00_display[]   = "Center";
350 // static char id01_display[]   = "Mid";
351
352 // static char id001_layer[]    = "Application";
353 // static char id002_layer[]    = "SoftKeyboard";
354 // static char id003_layer[]    = "HomeScreen";
355 // static char id004_layer[]    = "ControlBar";
356 // static char id005_layer[]    = "InterruptApp";
357 static char id006_layer[]    = "OnScreen";
358 // static char id007_layer[]    = "Touch";
359 // static char id008_layer[]    = "Cursor";
360 // static char id011_layer[]    = "MainApp";
361 // static char id012_layer[]    = "SubDispMainApp";
362 // static char id013_layer[]    = "SubDispSubApp";
363
364 static char id00611_layout[] = "Whole";
365 // static char id00612_layout[] = "Half";
366
367 static char id006111_area[]  = "Full";
368 // static char id006121_area[]  = "Upper";
369 // static char id006122_area[]  = "Lower";
370
371 static char role_incoming[] = "incoming";
372 static char role_message[]  = "message";
373 void
374 CicoOSPopWindow::makeResWindowT(ico_syc_res_window_t& w)
375 {
376     w.ECU         = id0_ECU;
377     w.display     = id00_display;
378     w.layer       = id006_layer;
379     w.layout      = id00611_layout;
380     w.area        = id006111_area;
381     w.dispatchApp = (char*)GetPkgname();
382     if (0 == strcmp(w.dispatchApp,"org.tizen.dialer")) {
383         w.role    = role_incoming;
384     }
385     else {
386         w.role    = role_message;
387     }
388     w.resourceId  = m_resourceId;
389 }
390
391 // vim: set expandtab ts=4 sw=4: