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