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
10 //==========================================================================
12 * @file CicoComponentimplementation.cpp
14 * @brief This file is implimentation of CicoStatusBarClockComponent class
15 * and CicoNotificationPanelComponent class
17 //==========================================================================
25 #include "CicoComponentImplementation.h"
28 #define IMG_DIR "/usr/apps/org.tizen.ico.statusbar/res/images/"
29 #define THEME_PATH "/usr/apps/org.tizen.ico.statusbar/res/themes/statusbar.edj"
31 /* Theme group name */
32 #define THEME_CLOCK_NAME "ClockImage"
33 #define THEME_NOTIFICATION_NAME "Notification"
35 // set image file path of clock
36 static const char *clock_image_path[] = {
49 IMG_DIR"time_ten.png",
53 /* define of special image index */
54 #define TIME_IMAGE_AM (10)
55 #define TIME_IMAGE_PM (11)
56 #define TIME_IMAGE_SP (12)
58 /* array of clock object name */
59 static const char *clock_image_object[] = {
69 /*--------------------------------------------------------------------------*/
71 * @brief default constructor
76 /*--------------------------------------------------------------------------*/
77 CicoStatusBarClockComponent::CicoStatusBarClockComponent()
81 /*--------------------------------------------------------------------------*/
88 /*--------------------------------------------------------------------------*/
89 CicoStatusBarClockComponent::~CicoStatusBarClockComponent()
93 /*--------------------------------------------------------------------------*/
95 * @brief initialize of clock component
97 * @param[in] windowobj
100 * @return true: success false: failed
102 /*--------------------------------------------------------------------------*/
104 CicoStatusBarClockComponent::Initialize(Evas_Object *windowobj, Evas *evas)
106 ICO_TRA("CicoStatusBarClockComponent::Initialize Enter");
108 /* initialize display clock image */
110 for(i=0; i<CLOCK_OBJECT_COUNT; i++ ){
111 last_clock_image[i] = -1;
114 /* make TimeImage object */
115 evasobj_=edje_object_add(evas);
116 if (!edje_object_file_set(evasobj_, THEME_PATH, THEME_CLOCK_NAME )) {
117 Edje_Load_Error err = edje_object_load_error_get(evasobj_);
118 const char *errmsg = edje_load_error_str(err);
119 ICO_ERR("could not load 'main' from statusbar.edj: %s",
124 /* move TimeImage to UpRight of window */
125 /* Do not need this process , if positiong of UpRight enabled with .EDC file */
127 Evas_Coord w_width=0;
128 Evas_Object* obj = NULL;
129 evas_object_geometry_get( windowobj, &x, &y, &w_width, &h );
130 evas_object_resize( evasobj_, w_width, h );
131 obj = (Evas_Object*)edje_object_part_object_get(evasobj_,"MIN1_img" );
132 evas_object_geometry_get( obj, &x, &y, &w, &h );
133 Evas_Coord offset = w_width - x - w -18;
135 for ( i=0; i<CLOCK_OBJECT_COUNT; i++ ) {
136 obj = (Evas_Object*)edje_object_part_object_get(
137 evasobj_, clock_image_object[i] );
139 evas_object_geometry_get( obj, &x, &y, &w, &h );
140 evas_object_move( obj, x+offset , y);
141 evas_object_show(obj);
145 /* initial display */
150 ICO_TRA("CicoStatusBarClockComponent::Initialize Leave");
154 /*--------------------------------------------------------------------------*/
156 * @brief update of clock component
159 * @return true: success false: failed
161 /*--------------------------------------------------------------------------*/
163 CicoStatusBarClockComponent::Update()
165 //ICO_TRA("CicoStatusBarClockComponent::Update Enter");
166 if (evasobj_ == NULL) {
171 nowtime = std::time(NULL);
172 std::tm *tm = std::localtime(&nowtime);
173 int min = tm->tm_min;
174 int hour = tm->tm_hour;
176 /* Make now clock image tabel */
177 int now_clock_image[CLOCK_OBJECT_COUNT];
179 now_clock_image[0]=TIME_IMAGE_PM;
182 now_clock_image[0]=TIME_IMAGE_AM;
184 time_t hour_m = hour % 12;
185 now_clock_image[1]=hour_m / 10;
186 now_clock_image[2]=hour_m % 10;
187 now_clock_image[3]=TIME_IMAGE_SP;
188 now_clock_image[4]=min / 10;
189 now_clock_image[5]=min % 10;
191 /* Set now clock image */
193 for ( i=0; i<CLOCK_OBJECT_COUNT; i++ ) {
195 /* if now clock image different last clock */
196 if ( now_clock_image[i] != last_clock_image[i] ) {
198 Evas_Object* obj = NULL;
199 obj = (Evas_Object*)edje_object_part_object_get(
200 evasobj_,clock_image_object[i] );
202 ICO_DBG("CicoStatusBarClockComponent image set[%s][%s]",
203 clock_image_object[i],clock_image_path[now_clock_image[i]]);
204 evas_object_image_file_set(obj,
205 clock_image_path[now_clock_image[i]], NULL);
206 // add update view area
207 // (Omitted update area is set so that evas_object_image_file_set())
208 //Evas_Coord x,y,w,h;
209 //evas_object_geometry_get( obj, &x, &y, &w, &h );
210 //evas_object_image_data_update_add( obj, x, y, w, h );
214 ICO_DBG("CicoStatusBarClockComponent image set error[object not found]" );
216 last_clock_image[i] = now_clock_image[i];
220 //ICO_TRA("CicoStatusBarClockComponent::Update Leave(true)");
224 /*--------------------------------------------------------------------------*/
226 * @brief get clock start position
228 * @param[out] x X axis
229 * @param[out] y Y axis
230 * @return true: success false: failed
232 /*--------------------------------------------------------------------------*/
234 CicoStatusBarClockComponent::GetClockStart( Evas_Coord *x_ret, Evas_Coord *y_ret)
236 ICO_TRA("CicoStatusBarClockComponent::GetClockStart Enter");
237 if (evasobj_ == NULL) {
238 ICO_TRA("CicoStatusBarClockComponent::GetClockStart Leave(false)");
242 Evas_Object* obj = NULL;
243 obj = (Evas_Object*)edje_object_part_object_get(
244 evasobj_, clock_image_object[0] );
246 ICO_TRA("CicoStatusBarClockComponent::GetClockStart Leave(false)");
251 evas_object_geometry_get( obj, &x, &y, &w, &h );
255 ICO_TRA("CicoStatusBarClockComponent::GetClockStart Leave(true)");
259 /*--------------------------------------------------------------------------*/
261 * @brief default constructor
266 /*--------------------------------------------------------------------------*/
267 CicoNotificationPanelComponent::CicoNotificationPanelComponent()
272 /*--------------------------------------------------------------------------*/
279 /*--------------------------------------------------------------------------*/
280 CicoNotificationPanelComponent::~CicoNotificationPanelComponent()
284 /*--------------------------------------------------------------------------*/
286 * @brief initialize of notification component
289 * @return true: success false: failed
291 /*--------------------------------------------------------------------------*/
293 CicoNotificationPanelComponent::Initialize(Evas_Object *window, Evas *evas)
295 ICO_TRA("CicoNotificationPanelComponent::Initialize Enter");
297 if (evasobj_ != NULL) {
298 ICO_TRA("CicoNotificationPanelComponent::Initialize Levae(false)");
302 if (window == NULL) {
303 ICO_TRA("CicoNotificationPanelComponent::Initialize Levae(false)");
307 /* create Notification object */
308 ICO_DBG("Create Text Module end");
309 evasobj_=edje_object_add(evas);
310 if (!edje_object_file_set(evasobj_, THEME_PATH, THEME_NOTIFICATION_NAME)) {
311 Edje_Load_Error err = edje_object_load_error_get(evasobj_);
312 const char *errmsg = edje_load_error_str(err);
313 ICO_ERR("could not load 'main' from statusbar.edj: %s",
318 evas_object_geometry_get( window, &x, &y, &w, &h );
319 evas_object_resize( evasobj_, w, h );
321 /* initial display */
325 ICO_TRA("CicoNotificationPanelComponent::Initialize Levae(true)");
329 /*--------------------------------------------------------------------------*/
331 * @brief set notification panel
334 * @param[in] iconpaht
335 * @param[in] soundpath
336 * @return true: success false: failed
338 /*--------------------------------------------------------------------------*/
340 CicoNotificationPanelComponent::SetNotification(const char *text,
341 const char *iconpath,
342 const char *soundpath)
344 ICO_TRA("CicoNotificationPanelComponent::SetNotification Enter"
345 "(text=%s icon=%s sound=%s)", text, iconpath, soundpath);
348 if (iconpath != NULL) {
349 Evas_Object* obj = NULL;
350 obj = (Evas_Object*)edje_object_part_object_get(
351 evasobj_, "noti_image");
353 ICO_DBG("SetNotification image set[%s]",iconpath);
354 evas_object_image_file_set(obj, iconpath, NULL);
357 ICO_DBG("SetNotification image set error[object not found]" );
368 ICO_TRA("CicoNotificationPanelComponent::SetNotification Leave");
371 //--------------------------------------------------------------------------
373 * @brief set text to Content_text
375 * @return true: success
377 //--------------------------------------------------------------------------
379 CicoNotificationPanelComponent::SetText(const char *text)
381 ICO_TRA("CicoNotificationPanelComponent::SetText Enter(text=%s)",
383 if ( text == NULL ) {
384 edje_object_part_text_set(evasobj_, "content_text", "");
387 edje_object_part_text_set(evasobj_, "content_text", text);
389 ICO_TRA("CicoNotificationPanelComponent::SetText Leave");
393 //--------------------------------------------------------------------------
395 * @brief set text to Content_text
397 * @return true: success
399 //--------------------------------------------------------------------------
401 CicoNotificationPanelComponent::SetTextEndPosition( Evas_Coord x_end, Evas_Coord y_end)
403 ICO_TRA("CicoNotificationPanelComponent::SetTextEndPosition Enter(%d,%d)",
406 if (evasobj_ == NULL) {
407 ICO_TRA("CicoNotificationPanelComponent::SetTextEndPosition Leave(false)");
411 Evas_Object* obj = NULL;
412 obj = (Evas_Object*)edje_object_part_object_get(
413 evasobj_, "content_text" );
415 ICO_TRA("CicoNotificationPanelComponent::SetTextEndPosition Leave(false)");
420 evas_object_geometry_get( obj, &x, &y, &w, &h );
421 evas_object_resize( evasobj_, x_end, h );
422 ICO_TRA("CicoNotificationPanelComponent::text width %d -> %d",w, x_end - x -1);
423 evas_object_resize( obj, x_end - x -1, h );
424 edje_object_calc_force( obj );
426 ICO_TRA("CicoNotificationPanelComponent::SetTextEndPosition Leave" );
429 // vim: set expandtab ts=4 sw=4: