Revert "Corresponding to TizenIVI3.0 M14.3, GENIVI-LayerManagement was used instead...
[profile/ivi/ico-uxf-homescreen.git] / src / statusbar / CicoStatusBar.cpp
1 /*
2  * Copyright (c) 2013, 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 #include <cassert>
11 #include <Ecore.h>
12 #include <Ecore_Wayland.h>
13 #include <Evas.h>
14 #include <Edje.h>
15 #include <ico_log.h>
16 #include "CicoStatusBar.h"
17
18 using namespace std;
19
20 const int CicoStatusBar::STATUSBAR_POSX = 0;
21 const int CicoStatusBar::STATUSBAR_POSY = 0;
22 const int CicoStatusBar::STATUSBAR_HEIGHT = 64;
23
24 //--------------------------------------------------------------------------
25 /**
26  *  @brief  default constructor
27  *  @param[in]  none
28  *  @return     none
29  */
30 //--------------------------------------------------------------------------
31 CicoStatusBar::CicoStatusBar()
32     : CicoCommonWindow()
33 {
34     notitimer_ = NULL;
35     clockcomp_ = NULL;
36     noticomp_  = NULL;
37 }
38
39 //--------------------------------------------------------------------------
40 /**
41  *  @brief  default destructor
42  *  @param[in]  none
43  *  @return     none
44  */
45 //--------------------------------------------------------------------------
46 CicoStatusBar::~CicoStatusBar()
47 {
48     ICO_TRA("CicoStatusBar::~CicoStatusBar() Enter");
49     if (notitimer_ != NULL) {
50         ecore_timer_del(notitimer_);
51     }
52
53     while( !noti_list.empty() ) {
54         DeleteNotification();
55     }
56
57     delete clockcomp_;
58     delete noticomp_;
59     ICO_TRA("CicoStatusBar::~CicoStatusBar() Leave");
60 }
61
62 //--------------------------------------------------------------------------
63 /**
64  *  @brief  initialize status bar
65  *  @param[in]  void
66  *  @return     true: success   false: failed
67  */
68 //--------------------------------------------------------------------------
69 bool
70 CicoStatusBar::Initialize(void)
71 {
72     ICO_TRA("CicoStatusBar::Initialize() Enter");
73     ICO_DBG("Initialize start window_.");
74
75     ecore_evas_init();
76     edje_init();
77
78     window_ = ecore_evas_new(NULL, 0, 0, 1, 1, "frame=0");
79     if (window_ == NULL) {
80         return false;
81     }
82     ecore_wl_screen_size_get(&width_, &height_);
83
84     ecore_evas_size_min_set(window_, width_, STATUSBAR_HEIGHT);
85     ecore_evas_size_max_set(window_, width_, STATUSBAR_HEIGHT);
86
87     ecore_evas_move(window_, STATUSBAR_POSX, STATUSBAR_POSY);
88     ecore_evas_resize(window_, width_, STATUSBAR_HEIGHT);
89
90     // if use alpha need to ecore_evas_alpha_set(window_, 1);
91     ICO_DBG("Initialize end window_.");
92
93     ICO_DBG("Initialize start windowobj_.");
94     windowobj_ = evas_object_rectangle_add(ecore_evas_get(window_));
95
96     // statusbar RGBcolor setting
97     evas_object_color_set(windowobj_, 0, 0, 0, 255);
98     ICO_DBG("Initialize setpos windowobj_.");
99
100     SetPos(STATUSBAR_POSX, STATUSBAR_POSY);
101     ICO_DBG("Initialize setsize windowobj_.");
102     SetSize(width_, STATUSBAR_HEIGHT);
103
104     ecore_evas_object_associate(window_, windowobj_,
105                                 ECORE_EVAS_OBJECT_ASSOCIATE_BASE);
106     /*  update initial view  */
107     Show();
108     ecore_main_loop_iterate();
109
110     ICO_DBG("Initialize end windowobj_.");
111
112     ICO_DBG("Initialize start Clock_Component.");
113     clockcomp_ = new CicoStatusBarClockComponent();
114     if (!clockcomp_->Initialize(windowobj_, ecore_evas_get(window_) )){
115         ICO_ERR("Failed to initialize Clock_Componet.");
116         return false;
117     }
118     ICO_DBG("Initialize end Clock_Component.");
119
120     ICO_DBG("Initialize start Notification_Component.");
121     noticomp_ = new CicoNotificationPanelComponent();
122     if (!noticomp_->Initialize(windowobj_,ecore_evas_get(window_))) {
123         ICO_ERR("Failed to initialize Notification_Component.");
124         return false;
125     }
126
127     noticomp_->SetPos(STATUSBAR_POSX, STATUSBAR_POSY);
128     notiservice_.SetCallback(NotificationCallback, this);
129     ICO_DBG("Initialize end Notification_Component.");
130
131     // set notification text end
132     Evas_Coord x, y;
133     if ( clockcomp_-> GetClockStart( &x, &y ) ) {
134         noticomp_->SetTextEndPosition( x, y );
135     }
136
137     //Show();
138     //ecore_main_loop_iterate();
139     //clockcomp_->Update();
140
141     // add timer callback function of time update
142     ecore_timer_add(3.0, ecoreUpdateTimeCB, this);
143
144     ICO_TRA("CicoStatusBar::Initialize() Leave");
145     return true;
146 }
147
148 /*--------------------------------------------------------------------------*/
149 /**
150  * @brief   update clock
151  *
152  * @param[in]   none
153  * @return      clockcomp_->Update()
154                 false :update failed
155  */
156 /*--------------------------------------------------------------------------*/
157 bool
158 CicoStatusBar::UpdateTime()
159 {
160     //ICO_TRA("CicoStatusBar::UpdateTime() Enter");
161     if (window_ != NULL && windowobj_ != NULL && clockcomp_ != NULL) {
162         //ICO_TRA("CicoStatusBar::UpdateTime() Leave");
163         return clockcomp_->Update();
164     }
165
166     ICO_ERR("Faied to update Clock_Componet.");
167     return false;
168 }
169
170 /*--------------------------------------------------------------------------*/
171 /**
172  *  @brief   update notification panel
173  *  @param[in]  msg     message
174  *  @param[in]  iconpaht    icon image path
175  *  @param[in]  soundpath   sound data path
176  *  @return     true: success   false: failed
177  */
178 /*--------------------------------------------------------------------------*/
179 bool
180 CicoStatusBar::UpdateNotificationPanel()
181 {
182
183     /*  if timer is active then wait timeout  */
184     if (notitimer_ != NULL) {
185         ICO_TRA("CicoStatusBar::UpdateNotificationPanel Timer not Terminate" );
186         return false;
187     }
188
189     /*  get Notification , if it is empty then return  */
190     CicoNotification* noti = GetNotification();
191     if (noti == NULL) {
192         ICO_TRA("CicoStatusBar::UpdateNotificationPanel empty" );
193         return false;
194     }
195     const char *msg = noti->GetContent();
196     const char *iconpath = noti->GetIconPath();
197     const char *soundpath = NULL;
198
199     /*  show Notification */
200     ICO_TRA("CicoStatusBar::UpdateNotificationPanel Enter"
201             "(msg=%s icon=%s sound=%s)", msg, iconpath, soundpath);
202     if (msg == NULL && iconpath == NULL && soundpath == NULL) {
203         ICO_ERR("notification info is NULL.");
204         DeleteNotification();
205         return false;
206     }
207     noticomp_->SetNotification(msg, iconpath, soundpath);
208     noticomp_->Show();
209
210     /* delete Notification and set disp timer */
211     DeleteNotification();
212
213     notitimer_ = ecore_timer_add(3.0, HideNotification, this);
214     ICO_TRA("CicoStatusBar::UpdateNotificationPanel Leave");
215     return true;
216 }
217
218 /*--------------------------------------------------------------------------*/
219 /**
220  * @brief   notification callback
221  *
222  * @param[in]   data    StatusBar object
223  * @param[in]   type    notification type
224  * @param[in]   op_list notification open list
225  * @param[in]   num_op  notification open number
226  * @return      none
227  */
228 /*--------------------------------------------------------------------------*/
229 void
230 CicoStatusBar::NotificationCallback(void *data,
231                                     notification_type_e type,
232                                     notification_op *op_list,
233                                     int num_op)
234 {
235     ICO_TRA("CicoStatusBar::NotificationCallback Enter(type=%d num_op=%d)",
236             type, num_op);
237     CicoStatusBar *sb = reinterpret_cast<CicoStatusBar*>(data);
238     notification_op_type_e op_type;
239
240     for (int i = 0; i < num_op; i++) {
241         op_type = op_list[i].type;
242         switch (op_type) {
243         case NOTIFICATION_OP_INSERT :
244         case NOTIFICATION_OP_UPDATE :
245             ICO_DBG("NOTIFICATION_OP_INSERT/NOTIFICATION_OP_UPDATE");
246
247             /*  add notification and update SB  */
248             sb->AddNotification( op_list[i].noti );
249             sb->UpdateNotificationPanel();
250
251             break;
252         case NOTIFICATION_OP_DELETE:
253             ICO_DBG("NOTIFICATION_OP_DELETE");
254             sb->DeleteNotification( op_list[i].priv_id );
255             break;
256         case NOTIFICATION_OP_DELETE_ALL:
257             ICO_DBG("NOTIFICATION_OP_DELETE_ALL");
258             break;
259         case NOTIFICATION_OP_REFRESH:
260             ICO_DBG("NOTIFICATION_OP_REFRESH");
261             break;
262         case NOTIFICATION_OP_SERVICE_READY:
263             ICO_DBG("NOTIFICATION_OP_SERVICE_READY");
264             break;
265         default :
266             break;
267         }
268     }
269     ICO_TRA("CicoStatusBar::NotificationCallback Leave");
270 }
271
272 /*--------------------------------------------------------------------------*/
273 /**
274  * @brief   hide notification panel
275  *
276  * @param[in]   data    StatusBar object
277  * @return      ECORE_CALLBACK_CANCEL
278  */
279 /*--------------------------------------------------------------------------*/
280 Eina_Bool
281 CicoStatusBar::HideNotification(void *data)
282 {
283     ICO_TRA("CicoStatusBar::HideNotification() Enter");
284     CicoStatusBar *sb = reinterpret_cast<CicoStatusBar*>(data);
285     sb->noticomp_->Hide();
286     ecore_timer_del(sb->notitimer_);
287     sb->notitimer_ = NULL;
288
289     /*  update notification ,if Notification exist in the queue   */
290     sb->UpdateNotificationPanel();
291
292     ICO_TRA("CicoStatusBar::HideNotification Leave");
293     return ECORE_CALLBACK_CANCEL;
294 }
295
296 /*--------------------------------------------------------------------------*/
297 /**
298  * @brief    add last notification
299  *
300  * @param[in]   sb    StatusBar object
301  * @param[in]   noti_h  notification handle
302  * @return      non
303  */
304 /*--------------------------------------------------------------------------*/
305 void
306 CicoStatusBar::AddNotification(notification_h noti_h)
307 {
308     ICO_TRA("CicoStatusBar::AddNotification() Enter");
309
310     CicoNotification *noti = new CicoNotification( noti_h );
311     if (noti->GetType() != NOTIFICATION_TYPE_ONGOING ) {
312         delete noti;
313         return;
314     }
315     noti_list.push_back(noti);
316
317     ICO_TRA("CicoStatusBar::AddNotification Leave");
318 }
319
320 /*--------------------------------------------------------------------------*/
321 /**
322  * @brief    get first notification
323  *
324  * @param[in]   sb    StatusBar object
325  * @return      CicoNotification class pointer
326  */
327 /*--------------------------------------------------------------------------*/
328 CicoNotification*
329 CicoStatusBar::GetNotification()
330 {
331     ICO_TRA("CicoStatusBar::GetNotification() Enter");
332
333     if ( ! noti_list.empty() ) {
334         CicoNotification *noti = noti_list.front();
335         if ( noti ) {
336             return noti;
337         }
338         else {
339             DeleteNotification();
340         }
341     }
342     ICO_TRA("CicoStatusBar::GetNotification Leave");
343     return NULL;
344 }
345
346 /*--------------------------------------------------------------------------*/
347 /*
348  * @brief    delete first notification
349  *
350  * @param[in]   sb    StatusBar object
351  * @return      none
352  */
353 /*--------------------------------------------------------------------------*/
354 void
355 CicoStatusBar::DeleteNotification()
356 {
357     ICO_TRA("CicoStatusBar::DeleteNotification() Enter");
358
359     if ( ! noti_list.empty() ) {
360         CicoNotification *noti = noti_list.front();
361         delete noti;
362         noti_list.pop_front();
363     }
364
365     ICO_TRA("CicoStatusBar::DeleteNotification Leave");
366 }
367
368 /*--------------------------------------------------------------------------*/
369 /**
370  * @brief    delete  notification
371  *
372  * @param[in]   sb    StatusBar object
373  * @param[in]   noti_h  notification handle
374  * @return      none
375  */
376 /*--------------------------------------------------------------------------*/
377 void
378 CicoStatusBar::DeleteNotification(int priv_id)
379 {
380     ICO_TRA("CicoStatusBar::DeleteNotification() Enter");
381
382     List_CicoNoti_pt pt = noti_list.begin();
383     for (; pt != noti_list.end(); ++pt) {
384
385         CicoNotification *noti_src = *pt;
386         if ( priv_id == noti_src->GetPrivId() ) {
387
388             delete noti_src;
389             noti_list.erase(pt);
390             break;
391         }
392     }
393
394     ICO_TRA("CicoStatusBar::DeleteNotification Leave");
395 }
396
397
398 //==========================================================================
399 //  public functions
400 //==========================================================================
401 //--------------------------------------------------------------------------
402 /**
403  *  @brief  callback function of time update
404  *
405  *  @param [in] data    user date
406  */
407 //--------------------------------------------------------------------------
408 Eina_Bool
409 CicoStatusBar::ecoreUpdateTimeCB(void *data)
410 {
411     assert(data != NULL);
412     CicoStatusBar* statusbar = reinterpret_cast<CicoStatusBar*>(data);
413     assert(statusbar->UpdateTime());
414     return ECORE_CALLBACK_RENEW;
415 }
416 // vim: set expandtab ts=4 sw=4: