574504c24cd61fd790c5bcafa59d58ab08c7ed63
[profile/ivi/ico-uxf-homescreen.git] / src / statusbar / CicoComponentImplementation.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 //==========================================================================
11 /**
12  *  @file   CicoComponentimplementation.cpp
13  *
14  *  @brief  This file is implimentation of CicoStatusBarClockComponent class
15  *                                  and CicoNotificationPanelComponent class
16  */
17 //==========================================================================
18
19 #include <Edje.h>
20 #include <ctime>
21 #include <cassert>
22 #include <memory>
23
24 #include <ico_log.h>
25 #include "CicoComponentImplementation.h"
26
27 /*  define of path   */
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"
30
31 /*  Theme group name  */
32 #define THEME_CLOCK_NAME "ClockImage"
33 #define THEME_NOTIFICATION_NAME "Notification"
34
35 // set image file path of clock
36 static const char *clock_image_path[] = {
37     IMG_DIR"time_0.png",
38     IMG_DIR"time_1.png",
39     IMG_DIR"time_2.png",
40     IMG_DIR"time_3.png",
41     IMG_DIR"time_4.png",
42     IMG_DIR"time_5.png",
43     IMG_DIR"time_6.png",
44     IMG_DIR"time_7.png",
45     IMG_DIR"time_8.png",
46     IMG_DIR"time_9.png",
47     IMG_DIR"time_am.png",
48     IMG_DIR"time_pm.png",
49     IMG_DIR"time_ten.png",
50     NULL
51 };
52
53 /*  define of special image index  */
54 #define TIME_IMAGE_AM (10)
55 #define TIME_IMAGE_PM (11)
56 #define TIME_IMAGE_SP (12)
57
58 /*  array of clock object name  */
59 static const char *clock_image_object[] = {
60     "AM_PM_img",
61     "HOUR10_img",
62     "HOUR1_img",
63     "TIME_SP_img",
64     "MIN10_img",
65     "MIN1_img",
66     NULL
67 };
68
69 /*--------------------------------------------------------------------------*/
70 /**
71  *  @brief   default constructor
72  *
73  *  @param[in]   none
74  *  @return      none
75  */
76 /*--------------------------------------------------------------------------*/
77 CicoStatusBarClockComponent::CicoStatusBarClockComponent()
78 {
79 }
80
81 /*--------------------------------------------------------------------------*/
82 /**
83  *  @brief   destructor
84  *
85  *  @param[in]   none
86  *  @return      none
87  */
88 /*--------------------------------------------------------------------------*/
89 CicoStatusBarClockComponent::~CicoStatusBarClockComponent()
90 {
91 }
92
93 /*--------------------------------------------------------------------------*/
94 /**
95  * @brief   initialize of clock component
96  *
97  *  @param[in]  windowobj
98  *  @param[in]  posx
99  *  @param[in]  posy
100  *  @return     true: success   false: failed
101  */
102 /*--------------------------------------------------------------------------*/
103 bool
104 CicoStatusBarClockComponent::Initialize(Evas_Object *windowobj, Evas *evas)
105 {
106     ICO_TRA("CicoStatusBarClockComponent::Initialize Enter");
107
108     /*  initialize display clock image */
109     int i;
110     for(i=0; i<CLOCK_OBJECT_COUNT; i++ ){
111         last_clock_image[i] = -1;
112     }
113
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",
120                 errmsg);
121         return false;
122     }
123
124     /*  move TimeImage to UpRight of window  */
125     /*  Do not need this process , if positiong of UpRight enabled with .EDC file */
126     Evas_Coord x,y,w,h;
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;
134
135     for ( i=0; i<CLOCK_OBJECT_COUNT; i++ ) {
136         obj = (Evas_Object*)edje_object_part_object_get(
137                         evasobj_, clock_image_object[i] );
138         if ( obj != NULL ) {
139             evas_object_geometry_get( obj, &x, &y, &w, &h );
140             evas_object_move( obj, x+offset , y);
141             evas_object_show(obj);
142         }
143     }
144
145     /*  initial display  */
146     bool ret = true;
147     ret = Update();
148     Show();
149
150     ICO_TRA("CicoStatusBarClockComponent::Initialize Leave");
151     return ret;
152 }
153
154 /*--------------------------------------------------------------------------*/
155 /**
156  * @brief   update of clock component
157  *
158  *  @param[in]  none
159  *  @return     true: success   false: failed
160  */
161 /*--------------------------------------------------------------------------*/
162 bool
163 CicoStatusBarClockComponent::Update()
164 {
165     //ICO_TRA("CicoStatusBarClockComponent::Update Enter");
166     if (evasobj_ == NULL) {
167         return false;
168     }
169
170     time_t nowtime;
171     nowtime = std::time(NULL);
172     std::tm *tm = std::localtime(&nowtime);
173     int min = tm->tm_min;
174     int hour = tm->tm_hour;
175
176     /*  Make now clock image tabel  */
177     int now_clock_image[CLOCK_OBJECT_COUNT];
178     if (hour > 11) {
179         now_clock_image[0]=TIME_IMAGE_PM;
180     }
181     else {
182         now_clock_image[0]=TIME_IMAGE_AM;
183     }
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;
190
191     /*  Set now clock image  */
192     int i;
193     for ( i=0; i<CLOCK_OBJECT_COUNT; i++ ) {
194
195         /*  if now clock image different last clock  */
196         if ( now_clock_image[i] != last_clock_image[i] ) {
197
198             Evas_Object* obj = NULL;
199             obj = (Evas_Object*)edje_object_part_object_get(
200                          evasobj_,clock_image_object[i] );
201             if ( obj != NULL ) {
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 );
211
212             }
213             else {
214                 ICO_DBG("CicoStatusBarClockComponent image set error[object not found]" );
215             }
216             last_clock_image[i] = now_clock_image[i];
217         }
218     }
219
220     //ICO_TRA("CicoStatusBarClockComponent::Update Leave(true)");
221     return true;
222 }
223
224 /*--------------------------------------------------------------------------*/
225 /**
226  *  @brief   get clock start position
227  *
228  *  @param[out]  x  X axis
229  *  @param[out]  y  Y axis
230  *  @return     true: success   false: failed
231  */
232 /*--------------------------------------------------------------------------*/
233 bool
234 CicoStatusBarClockComponent::GetClockStart( Evas_Coord *x_ret, Evas_Coord *y_ret)
235 {
236     ICO_TRA("CicoStatusBarClockComponent::GetClockStart Enter");
237     if (evasobj_ == NULL) {
238         ICO_TRA("CicoStatusBarClockComponent::GetClockStart Leave(false)");
239         return false;
240     }
241
242     Evas_Object* obj = NULL;
243     obj = (Evas_Object*)edje_object_part_object_get(
244                  evasobj_, clock_image_object[0] );
245     if ( obj == NULL ) {
246         ICO_TRA("CicoStatusBarClockComponent::GetClockStart Leave(false)");
247         return false;
248     }
249
250     Evas_Coord x,y,w,h;
251     evas_object_geometry_get( obj, &x, &y, &w, &h );
252     *x_ret = x;
253     *y_ret = y;
254
255     ICO_TRA("CicoStatusBarClockComponent::GetClockStart Leave(true)");
256     return true;
257 }
258
259 /*--------------------------------------------------------------------------*/
260 /**
261  * @brief   default constructor
262  *
263  *  @param[in]  none
264  *  @return     none
265  */
266 /*--------------------------------------------------------------------------*/
267 CicoNotificationPanelComponent::CicoNotificationPanelComponent()
268     : CicoCommonModule()
269 {
270 }
271
272 /*--------------------------------------------------------------------------*/
273 /**
274  *  @brief   destructor
275  *
276  *  @param[in]  none
277  *  @return     none
278  */
279 /*--------------------------------------------------------------------------*/
280 CicoNotificationPanelComponent::~CicoNotificationPanelComponent()
281 {
282 }
283
284 /*--------------------------------------------------------------------------*/
285 /**
286  *  @brief   initialize of notification component
287  *
288  *  @param[in]  window
289  *  @return     true: success   false: failed
290  */
291 /*--------------------------------------------------------------------------*/
292 bool
293 CicoNotificationPanelComponent::Initialize(Evas_Object *window, Evas *evas)
294 {
295     ICO_TRA("CicoNotificationPanelComponent::Initialize Enter");
296
297     if (evasobj_ != NULL) {
298         ICO_TRA("CicoNotificationPanelComponent::Initialize Levae(false)");
299         return false;
300     }
301
302     if (window == NULL) {
303         ICO_TRA("CicoNotificationPanelComponent::Initialize Levae(false)");
304         return false;
305     }
306
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",
314                 errmsg);
315         return false;
316     }
317     Evas_Coord x,y,w,h;
318     evas_object_geometry_get( window, &x, &y, &w, &h );
319     evas_object_resize( evasobj_, w, h );
320
321     /*  initial display  */
322     SetText("");
323     Hide();
324
325     ICO_TRA("CicoNotificationPanelComponent::Initialize Levae(true)");
326     return true;
327 }
328
329 /*--------------------------------------------------------------------------*/
330 /**
331  *  @brief   set notification panel
332  *
333  *  @param[in]  text
334  *  @param[in]  iconpaht
335  *  @param[in]  soundpath
336  *  @return     true: success   false: failed
337  */
338 /*--------------------------------------------------------------------------*/
339 void
340 CicoNotificationPanelComponent::SetNotification(const char *text,
341                                                 const char *iconpath,
342                                                 const char *soundpath)
343 {
344     ICO_TRA("CicoNotificationPanelComponent::SetNotification Enter"
345             "(text=%s icon=%s sound=%s)", text, iconpath, soundpath);
346
347     /*  set image file  */
348     if (iconpath != NULL) {
349         Evas_Object* obj = NULL;
350         obj = (Evas_Object*)edje_object_part_object_get(
351                      evasobj_, "noti_image");
352         if ( obj != NULL ) {
353             ICO_DBG("SetNotification image set[%s]",iconpath);
354             evas_object_image_file_set(obj, iconpath, NULL);
355         }
356         else {
357             ICO_DBG("SetNotification image set error[object not found]" );
358         }
359     }
360
361     /*  set text  */
362     if (text != NULL) {
363         SetText(text);
364     }
365
366     Show();
367
368     ICO_TRA("CicoNotificationPanelComponent::SetNotification Leave");
369 }
370
371 //--------------------------------------------------------------------------
372 /**
373  *  @brief  set text to Content_text
374  *  @param[in]  text
375  *  @return     true: success
376  */
377 //--------------------------------------------------------------------------
378 bool
379 CicoNotificationPanelComponent::SetText(const char *text)
380 {
381     ICO_TRA("CicoNotificationPanelComponent::SetText Enter(text=%s)",
382             text? text:"NULL");
383     if ( text == NULL ) {
384         edje_object_part_text_set(evasobj_, "content_text", "");
385         return true;
386     }
387     edje_object_part_text_set(evasobj_, "content_text", text);
388
389     ICO_TRA("CicoNotificationPanelComponent::SetText Leave");
390     return true;
391 }
392
393 //--------------------------------------------------------------------------
394 /**
395  *  @brief  set text to Content_text
396  *  @param[in]  text
397  *  @return     true: success
398  */
399 //--------------------------------------------------------------------------
400 void
401 CicoNotificationPanelComponent::SetTextEndPosition( Evas_Coord x_end, Evas_Coord y_end)
402 {
403     ICO_TRA("CicoNotificationPanelComponent::SetTextEndPosition Enter(%d,%d)",
404             x_end,y_end);
405
406     if (evasobj_ == NULL) {
407         ICO_TRA("CicoNotificationPanelComponent::SetTextEndPosition Leave(false)");
408         return;
409     }
410
411     Evas_Object* obj = NULL;
412     obj = (Evas_Object*)edje_object_part_object_get(
413                  evasobj_, "content_text" );
414     if ( obj == NULL ) {
415         ICO_TRA("CicoNotificationPanelComponent::SetTextEndPosition Leave(false)");
416         return;
417     }
418
419     Evas_Coord x,y,w,h;
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 );
425
426     ICO_TRA("CicoNotificationPanelComponent::SetTextEndPosition Leave" );
427 }
428
429 // vim: set expandtab ts=4 sw=4: