2 * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
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
12 #include <Ecore_Wayland.h>
16 #include "CicoStatusBar.h"
20 const int CicoStatusBar::STATUSBAR_POSX = 0;
21 const int CicoStatusBar::STATUSBAR_POSY = 0;
22 const int CicoStatusBar::STATUSBAR_HEIGHT = 64;
24 //--------------------------------------------------------------------------
26 * @brief default constructor
30 //--------------------------------------------------------------------------
31 CicoStatusBar::CicoStatusBar()
39 //--------------------------------------------------------------------------
41 * @brief default destructor
45 //--------------------------------------------------------------------------
46 CicoStatusBar::~CicoStatusBar()
48 ICO_TRA("CicoStatusBar::~CicoStatusBar() Enter");
49 if (notitimer_ != NULL) {
50 ecore_timer_del(notitimer_);
53 while( !noti_list.empty() ) {
59 ICO_TRA("CicoStatusBar::~CicoStatusBar() Leave");
62 //--------------------------------------------------------------------------
64 * @brief initialize status bar
66 * @return true: success false: failed
68 //--------------------------------------------------------------------------
70 CicoStatusBar::Initialize(void)
72 ICO_TRA("CicoStatusBar::Initialize() Enter");
73 ICO_DBG("Initialize start window_.");
78 window_ = ecore_evas_new(NULL, 0, 0, 1, 1, "frame=0");
79 if (window_ == NULL) {
82 ecore_wl_screen_size_get(&width_, &height_);
84 ecore_evas_size_min_set(window_, width_, STATUSBAR_HEIGHT);
85 ecore_evas_size_max_set(window_, width_, STATUSBAR_HEIGHT);
87 ecore_evas_move(window_, STATUSBAR_POSX, STATUSBAR_POSY);
88 ecore_evas_resize(window_, width_, STATUSBAR_HEIGHT);
90 // if use alpha need to ecore_evas_alpha_set(window_, 1);
91 ICO_DBG("Initialize end window_.");
93 ICO_DBG("Initialize start windowobj_.");
94 windowobj_ = evas_object_rectangle_add(ecore_evas_get(window_));
96 // statusbar RGBcolor setting
97 evas_object_color_set(windowobj_, 0, 0, 0, 255);
98 ICO_DBG("Initialize setpos windowobj_.");
100 SetPos(STATUSBAR_POSX, STATUSBAR_POSY);
101 ICO_DBG("Initialize setsize windowobj_.");
102 SetSize(width_, STATUSBAR_HEIGHT);
104 ecore_evas_object_associate(window_, windowobj_,
105 ECORE_EVAS_OBJECT_ASSOCIATE_BASE);
106 /* update initial view */
108 ecore_main_loop_iterate();
110 ICO_DBG("Initialize end windowobj_.");
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.");
118 ICO_DBG("Initialize end Clock_Component.");
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.");
127 noticomp_->SetPos(STATUSBAR_POSX, STATUSBAR_POSY);
128 notiservice_.SetCallback(NotificationCallback, this);
129 ICO_DBG("Initialize end Notification_Component.");
131 // set notification text end
133 if ( clockcomp_-> GetClockStart( &x, &y ) ) {
134 noticomp_->SetTextEndPosition( x, y );
138 //ecore_main_loop_iterate();
139 //clockcomp_->Update();
141 // add timer callback function of time update
142 ecore_timer_add(3.0, ecoreUpdateTimeCB, this);
144 ICO_TRA("CicoStatusBar::Initialize() Leave");
148 /*--------------------------------------------------------------------------*/
150 * @brief update clock
153 * @return clockcomp_->Update()
156 /*--------------------------------------------------------------------------*/
158 CicoStatusBar::UpdateTime()
160 //ICO_TRA("CicoStatusBar::UpdateTime() Enter");
161 if (window_ != NULL && windowobj_ != NULL && clockcomp_ != NULL) {
162 //ICO_TRA("CicoStatusBar::UpdateTime() Leave");
163 return clockcomp_->Update();
166 ICO_ERR("Faied to update Clock_Componet.");
170 /*--------------------------------------------------------------------------*/
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
178 /*--------------------------------------------------------------------------*/
180 CicoStatusBar::UpdateNotificationPanel()
183 /* if timer is active then wait timeout */
184 if (notitimer_ != NULL) {
185 ICO_TRA("CicoStatusBar::UpdateNotificationPanel Timer not Terminate" );
189 /* get Notification , if it is empty then return */
190 CicoNotification* noti = GetNotification();
192 ICO_TRA("CicoStatusBar::UpdateNotificationPanel empty" );
195 const char *msg = noti->GetContent();
196 const char *iconpath = noti->GetIconPath();
197 const char *soundpath = NULL;
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();
207 noticomp_->SetNotification(msg, iconpath, soundpath);
210 /* delete Notification and set disp timer */
211 DeleteNotification();
213 notitimer_ = ecore_timer_add(3.0, HideNotification, this);
214 ICO_TRA("CicoStatusBar::UpdateNotificationPanel Leave");
218 /*--------------------------------------------------------------------------*/
220 * @brief notification callback
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
228 /*--------------------------------------------------------------------------*/
230 CicoStatusBar::NotificationCallback(void *data,
231 notification_type_e type,
232 notification_op *op_list,
235 ICO_TRA("CicoStatusBar::NotificationCallback Enter(type=%d num_op=%d)",
237 CicoStatusBar *sb = reinterpret_cast<CicoStatusBar*>(data);
238 notification_op_type_e op_type;
240 for (int i = 0; i < num_op; i++) {
241 op_type = op_list[i].type;
243 case NOTIFICATION_OP_INSERT :
244 case NOTIFICATION_OP_UPDATE :
245 ICO_DBG("NOTIFICATION_OP_INSERT/NOTIFICATION_OP_UPDATE");
247 /* add notification and update SB */
248 sb->AddNotification( op_list[i].noti );
249 sb->UpdateNotificationPanel();
252 case NOTIFICATION_OP_DELETE:
253 ICO_DBG("NOTIFICATION_OP_DELETE");
254 sb->DeleteNotification( op_list[i].priv_id );
256 case NOTIFICATION_OP_DELETE_ALL:
257 ICO_DBG("NOTIFICATION_OP_DELETE_ALL");
259 case NOTIFICATION_OP_REFRESH:
260 ICO_DBG("NOTIFICATION_OP_REFRESH");
262 case NOTIFICATION_OP_SERVICE_READY:
263 ICO_DBG("NOTIFICATION_OP_SERVICE_READY");
269 ICO_TRA("CicoStatusBar::NotificationCallback Leave");
272 /*--------------------------------------------------------------------------*/
274 * @brief hide notification panel
276 * @param[in] data StatusBar object
277 * @return ECORE_CALLBACK_CANCEL
279 /*--------------------------------------------------------------------------*/
281 CicoStatusBar::HideNotification(void *data)
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;
289 /* update notification ,if Notification exist in the queue */
290 sb->UpdateNotificationPanel();
292 ICO_TRA("CicoStatusBar::HideNotification Leave");
293 return ECORE_CALLBACK_CANCEL;
296 /*--------------------------------------------------------------------------*/
298 * @brief add last notification
300 * @param[in] sb StatusBar object
301 * @param[in] noti_h notification handle
304 /*--------------------------------------------------------------------------*/
306 CicoStatusBar::AddNotification(notification_h noti_h)
308 ICO_TRA("CicoStatusBar::AddNotification() Enter");
310 CicoNotification *noti = new CicoNotification( noti_h );
311 if (noti->GetType() != NOTIFICATION_TYPE_ONGOING ) {
315 noti_list.push_back(noti);
317 ICO_TRA("CicoStatusBar::AddNotification Leave");
320 /*--------------------------------------------------------------------------*/
322 * @brief get first notification
324 * @param[in] sb StatusBar object
325 * @return CicoNotification class pointer
327 /*--------------------------------------------------------------------------*/
329 CicoStatusBar::GetNotification()
331 ICO_TRA("CicoStatusBar::GetNotification() Enter");
333 if ( ! noti_list.empty() ) {
334 CicoNotification *noti = noti_list.front();
339 DeleteNotification();
342 ICO_TRA("CicoStatusBar::GetNotification Leave");
346 /*--------------------------------------------------------------------------*/
348 * @brief delete first notification
350 * @param[in] sb StatusBar object
353 /*--------------------------------------------------------------------------*/
355 CicoStatusBar::DeleteNotification()
357 ICO_TRA("CicoStatusBar::DeleteNotification() Enter");
359 if ( ! noti_list.empty() ) {
360 CicoNotification *noti = noti_list.front();
362 noti_list.pop_front();
365 ICO_TRA("CicoStatusBar::DeleteNotification Leave");
368 /*--------------------------------------------------------------------------*/
370 * @brief delete notification
372 * @param[in] sb StatusBar object
373 * @param[in] noti_h notification handle
376 /*--------------------------------------------------------------------------*/
378 CicoStatusBar::DeleteNotification(int priv_id)
380 ICO_TRA("CicoStatusBar::DeleteNotification() Enter");
382 List_CicoNoti_pt pt = noti_list.begin();
383 for (; pt != noti_list.end(); ++pt) {
385 CicoNotification *noti_src = *pt;
386 if ( priv_id == noti_src->GetPrivId() ) {
394 ICO_TRA("CicoStatusBar::DeleteNotification Leave");
398 //==========================================================================
400 //==========================================================================
401 //--------------------------------------------------------------------------
403 * @brief callback function of time update
405 * @param [in] data user date
407 //--------------------------------------------------------------------------
409 CicoStatusBar::ecoreUpdateTimeCB(void *data)
411 assert(data != NULL);
412 CicoStatusBar* statusbar = reinterpret_cast<CicoStatusBar*>(data);
413 assert(statusbar->UpdateTime());
414 return ECORE_CALLBACK_RENEW;
416 // vim: set expandtab ts=4 sw=4: