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 //==========================================================================
24 #include "CicoComponentImplementation.h"
27 #define IMG_DIR "/usr/apps/org.tizen.ico.statusbar/res/images/"
28 #define THEME_PATH "/usr/apps/org.tizen.ico.statusbar/res/themes/statusbar.edj"
30 /* Theme group name */
31 #define THEME_CLOCK_NAME "ClockImage"
32 #define THEME_NOTIFICATION_NAME "Notification"
34 // set image file path of clock
35 static const char *clock_image_path[] = {
48 IMG_DIR"time_ten.png",
52 /* define of special image index */
53 #define TIME_IMAGE_AM (10)
54 #define TIME_IMAGE_PM (11)
55 #define TIME_IMAGE_SP (12)
57 /* array of clock object name */
58 static const char *clock_image_object[] = {
68 /*--------------------------------------------------------------------------*/
70 * @brief default constructor
75 /*--------------------------------------------------------------------------*/
76 CicoStatusBarClockComponent::CicoStatusBarClockComponent()
80 /*--------------------------------------------------------------------------*/
87 /*--------------------------------------------------------------------------*/
88 CicoStatusBarClockComponent::~CicoStatusBarClockComponent()
92 /*--------------------------------------------------------------------------*/
94 * @brief initialize of clock component
96 * @param[in] windowobj
99 * @return true: success false: failed
101 /*--------------------------------------------------------------------------*/
103 CicoStatusBarClockComponent::Initialize(Evas_Object *windowobj, Evas *evas)
105 ICO_TRA("CicoStatusBarClockComponent::Initialize Enter");
107 /* initialize display clock image */
109 for(i=0; i<CLOCK_OBJECT_COUNT; i++ ){
110 last_clock_image[i] = -1;
113 /* make TimeImage object */
114 evasobj_=edje_object_add(evas);
115 if (!edje_object_file_set(evasobj_, THEME_PATH, THEME_CLOCK_NAME )) {
116 Edje_Load_Error err = edje_object_load_error_get(evasobj_);
117 const char *errmsg = edje_load_error_str(err);
118 ICO_ERR("could not load 'main' from statusbar.edj: %s",
123 /* move TimeImage to UpRight of window */
124 /* Do not need this process , if positiong of UpRight enabled with .EDC file */
126 Evas_Coord w_width=0;
127 Evas_Object* obj = NULL;
128 evas_object_geometry_get( windowobj, &x, &y, &w_width, &h );
129 evas_object_resize( evasobj_, w_width, h );
130 obj = (Evas_Object*)edje_object_part_object_get(evasobj_,"MIN1_img" );
131 evas_object_geometry_get( obj, &x, &y, &w, &h );
132 Evas_Coord offset = w_width - x - w -18;
134 for ( i=0; i<CLOCK_OBJECT_COUNT; i++ ) {
135 obj = (Evas_Object*)edje_object_part_object_get(
136 evasobj_, clock_image_object[i] );
138 evas_object_geometry_get( obj, &x, &y, &w, &h );
139 evas_object_move( obj, x+offset , y);
140 evas_object_show(obj);
144 /* initial display */
149 ICO_TRA("CicoStatusBarClockComponent::Initialize Leave");
153 /*--------------------------------------------------------------------------*/
155 * @brief update of clock component
158 * @return true: success false: failed
160 /*--------------------------------------------------------------------------*/
162 CicoStatusBarClockComponent::Update()
164 //ICO_TRA("CicoStatusBarClockComponent::Update Enter");
165 if (evasobj_ == NULL) {
170 nowtime = std::time(NULL);
171 std::tm *tm = std::localtime(&nowtime);
172 int min = tm->tm_min;
173 int hour = tm->tm_hour;
175 /* Make now clock image tabel */
176 int now_clock_image[CLOCK_OBJECT_COUNT];
178 now_clock_image[0]=TIME_IMAGE_PM;
181 now_clock_image[0]=TIME_IMAGE_AM;
183 time_t hour_m = hour % 12;
184 now_clock_image[1]=hour_m / 10;
185 now_clock_image[2]=hour_m % 10;
186 now_clock_image[3]=TIME_IMAGE_SP;
187 now_clock_image[4]=min / 10;
188 now_clock_image[5]=min % 10;
190 /* Set now clock image */
192 for ( i=0; i<CLOCK_OBJECT_COUNT; i++ ) {
194 /* if now clock image different last clock */
195 if ( now_clock_image[i] != last_clock_image[i] ) {
197 Evas_Object* obj = NULL;
198 obj = (Evas_Object*)edje_object_part_object_get(
199 evasobj_,clock_image_object[i] );
201 ICO_DBG("CicoStatusBarClockComponent image set[%s][%s]",
202 clock_image_object[i],clock_image_path[now_clock_image[i]]);
203 evas_object_image_file_set(obj,
204 clock_image_path[now_clock_image[i]], NULL);
205 // add update view area
206 // (Omitted update area is set so that evas_object_image_file_set())
207 //Evas_Coord x,y,w,h;
208 //evas_object_geometry_get( obj, &x, &y, &w, &h );
209 //evas_object_image_data_update_add( obj, x, y, w, h );
213 ICO_DBG("CicoStatusBarClockComponent image set error[object not found]" );
215 last_clock_image[i] = now_clock_image[i];
219 //ICO_TRA("CicoStatusBarClockComponent::Update Leave(true)");
223 /*--------------------------------------------------------------------------*/
225 * @brief get clock start position
227 * @param[out] x X axis
228 * @param[out] y Y axis
229 * @return true: success false: failed
231 /*--------------------------------------------------------------------------*/
233 CicoStatusBarClockComponent::GetClockStart( Evas_Coord *x_ret, Evas_Coord *y_ret)
235 ICO_TRA("CicoStatusBarClockComponent::GetClockStart Enter");
236 if (evasobj_ == NULL) {
237 ICO_TRA("CicoStatusBarClockComponent::GetClockStart Leave(false)");
241 Evas_Object* obj = NULL;
242 obj = (Evas_Object*)edje_object_part_object_get(
243 evasobj_, clock_image_object[0] );
245 ICO_TRA("CicoStatusBarClockComponent::GetClockStart Leave(false)");
250 evas_object_geometry_get( obj, &x, &y, &w, &h );
254 ICO_TRA("CicoStatusBarClockComponent::GetClockStart Leave(true)");
258 /*--------------------------------------------------------------------------*/
260 * @brief default constructor
265 /*--------------------------------------------------------------------------*/
266 CicoNotificationPanelComponent::CicoNotificationPanelComponent()
271 /*--------------------------------------------------------------------------*/
278 /*--------------------------------------------------------------------------*/
279 CicoNotificationPanelComponent::~CicoNotificationPanelComponent()
283 /*--------------------------------------------------------------------------*/
285 * @brief initialize of notification component
288 * @return true: success false: failed
290 /*--------------------------------------------------------------------------*/
292 CicoNotificationPanelComponent::Initialize(Evas_Object *window, Evas *evas)
294 ICO_TRA("CicoNotificationPanelComponent::Initialize Enter");
296 if (evasobj_ != NULL) {
297 ICO_TRA("CicoNotificationPanelComponent::Initialize Levae(false)");
301 if (window == NULL) {
302 ICO_TRA("CicoNotificationPanelComponent::Initialize Levae(false)");
306 /* create Notification object */
307 ICO_DBG("Create Text Module end");
308 evasobj_=edje_object_add(evas);
309 if (!edje_object_file_set(evasobj_, THEME_PATH, THEME_NOTIFICATION_NAME)) {
310 Edje_Load_Error err = edje_object_load_error_get(evasobj_);
311 const char *errmsg = edje_load_error_str(err);
312 ICO_ERR("could not load 'main' from statusbar.edj: %s",
317 evas_object_geometry_get( window, &x, &y, &w, &h );
318 evas_object_resize( evasobj_, w, h );
320 /* initial display */
324 ICO_TRA("CicoNotificationPanelComponent::Initialize Levae(true)");
328 /*--------------------------------------------------------------------------*/
330 * @brief set notification panel
333 * @param[in] iconpaht
334 * @param[in] soundpath
335 * @return true: success false: failed
337 /*--------------------------------------------------------------------------*/
339 CicoNotificationPanelComponent::SetNotification(const char *text,
340 const char *iconpath,
341 const char *soundpath)
343 ICO_TRA("CicoNotificationPanelComponent::SetNotification Enter"
344 "(text=%s icon=%s sound=%s)", text, iconpath, soundpath);
347 if (iconpath != NULL) {
348 Evas_Object* obj = NULL;
349 obj = (Evas_Object*)edje_object_part_object_get(
350 evasobj_, "noti_image");
352 ICO_DBG("SetNotification image set[%s]",iconpath);
353 evas_object_image_file_set(obj, iconpath, NULL);
356 ICO_DBG("SetNotification image set error[object not found]" );
367 ICO_TRA("CicoNotificationPanelComponent::SetNotification Leave");
370 //--------------------------------------------------------------------------
372 * @brief set text to Content_text
374 * @return true: success
376 //--------------------------------------------------------------------------
378 CicoNotificationPanelComponent::SetText(const char *text)
380 ICO_TRA("CicoNotificationPanelComponent::SetText Enter(text=%s)",
382 if ( text == NULL ) {
383 edje_object_part_text_set(evasobj_, "content_text", "");
386 edje_object_part_text_set(evasobj_, "content_text", text);
388 ICO_TRA("CicoNotificationPanelComponent::SetText Leave");
392 //--------------------------------------------------------------------------
394 * @brief set text to Content_text
396 * @return true: success
398 //--------------------------------------------------------------------------
400 CicoNotificationPanelComponent::SetTextEndPosition( Evas_Coord x_end, Evas_Coord y_end)
402 ICO_TRA("CicoNotificationPanelComponent::SetTextEndPosition Enter(%d,%d)",
405 if (evasobj_ == NULL) {
406 ICO_TRA("CicoNotificationPanelComponent::SetTextEndPosition Leave(false)");
410 Evas_Object* obj = NULL;
411 obj = (Evas_Object*)edje_object_part_object_get(
412 evasobj_, "content_text" );
414 ICO_TRA("CicoNotificationPanelComponent::SetTextEndPosition Leave(false)");
419 evas_object_geometry_get( obj, &x, &y, &w, &h );
420 evas_object_resize( evasobj_, x_end, h );
421 ICO_TRA("CicoNotificationPanelComponent::text width %d -> %d",w, x_end - x -1);
422 evas_object_resize( obj, x_end - x -1, h );
423 edje_object_calc_force( obj );
425 ICO_TRA("CicoNotificationPanelComponent::SetTextEndPosition Leave" );
428 // vim: set expandtab ts=4 sw=4: