40c936dc19b26e276fbd65e37d22644d7380ecf3
[profile/ivi/ico-uxf-homescreen.git] / src / homescreen / CicoHSControlBarWindow.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  * @brief   control bar window
11  *
12  * @date    Aug-08-2013
13  */
14 #include "CicoHSControlBarWindow.h"
15 #include "CicoHSControlBarTouch.h"
16 #include "CicoGKeyFileConfig.h"
17 #include "CicoResourceConfig.h"
18 #include "CicoHomeScreen.h"
19 #include "CicoHSSystemState.h"
20 #include "CicoSound.h"
21
22 /*============================================================================*/
23 /* functions                                                                  */
24 /*============================================================================*/
25 /*--------------------------------------------------------------------------*/
26 /**
27  * @brief   CicoHSControlBarWindow::CicoHSControlBarWindow
28  *          Constractor
29  *
30  * @param[in]   none
31  * @return      none
32  */
33 /*--------------------------------------------------------------------------*/
34 CicoHSControlBarWindow::CicoHSControlBarWindow(void)
35 {
36     ICO_DBG("CicoHSControlBarWindow::CicoHSControlBarWindow: Enter");
37
38     evas = NULL;
39
40     CicoResourceConfig::GetImagePath(img_dir_path, ICO_HS_MAX_PATH_BUFF_LEN);
41
42     CicoGKeyFileConfig config;
43     config.Initialize(ICO_HOMESCREEN_CONFIG_FILE);
44     const char *value = config.ConfigGetString("switchzone", "keyname", "m");
45     if (strlen(value) > (sizeof(changeZoneKeyName) - 1)) {
46         ICO_WRN("[switchzone] keyname is strlen overflow. use default keyname(m)");
47     }
48     else {
49         memset(changeZoneKeyName, 0, sizeof(changeZoneKeyName));
50         strncpy(changeZoneKeyName, value, strlen(value));
51     }
52
53     value = config.ConfigGetString("standardswitch", "homekeyname", "h");
54     if (strlen(value) > (sizeof(homeKeyName) - 1)) {
55         ICO_WRN("[standardswitch] keyname is strlen overflow. use default keyname(h)");
56     }
57     else {
58         memset(homeKeyName, 0, sizeof(homeKeyName));
59         strncpy(homeKeyName, value, strlen(value));
60     }
61
62     value = config.ConfigGetString("standardswitch", "backkeyname", "b");
63     if (strlen(value) > (sizeof(backKeyName) - 1)) {
64         ICO_WRN("[standardswitch] keyname is strlen overflow. use default keyname(b)");
65     }
66     else {
67         memset(backKeyName, 0, sizeof(backKeyName));
68         strncpy(backKeyName, value, strlen(value));
69     }
70
71     value = config.ConfigGetString("standardswitch", "menukeyname", "l");
72     menuKeyName[0] = value[0];
73     if (strlen(value) > (sizeof(menuKeyName) - 1)) {
74         ICO_WRN("[standardswitch] keyname is strlen overflow. use default keyname(l)");
75     }
76     else {
77         memset(menuKeyName, 0, sizeof(menuKeyName));
78         strncpy(menuKeyName, value, strlen(value));
79     }
80     ICO_DBG("Assigned key config : changeZone[%s]", changeZoneKeyName);
81     ICO_DBG("Assigned key config : home[%s]", homeKeyName);
82     ICO_DBG("Assigned key config : back[%s]", backKeyName);
83     ICO_DBG("Assigned key config : menu[%s]", menuKeyName);
84
85     char tmp_str[16];
86     for (unsigned int ii = 0; ii < ICO_HS_CONTROL_BAR_SHORTCUT_MAX_NUM; ii++) {
87         sprintf(tmp_str, ICO_HS_CONTROL_BAR_CONFIG_SHORTCUT_APP"%d", ii);
88         value = config.ConfigGetString(ICO_HS_CONFIG_CONTROL_BAR, tmp_str, NULL);
89         if ((NULL != value) && (0 != strcmp(value, "none"))) {
90             shortcut_appid[ii] = value;
91             ICO_DBG("shortcut_appid[%d] = [%s]", ii, shortcut_appid[ii]);
92         }
93         else {
94             shortcut_appid[ii] = NULL;
95             ICO_DBG("shortcut_appid[%d] = NULL", ii);
96         }
97     }
98     ICO_DBG("CicoHSControlBarWindow::CicoHSControlBarWindow: Leave");
99 }
100
101 /*--------------------------------------------------------------------------*/
102 /**
103  * @brief   CicoHSControlBarWindow::~CicoHSControlBarWindow
104  *          Destractor
105  *
106  * @param[in]   none
107  * @return      none
108  */
109 /*--------------------------------------------------------------------------*/
110 CicoHSControlBarWindow::~CicoHSControlBarWindow(void)
111 {
112     /* not somthing to do */
113 }
114
115 /*--------------------------------------------------------------------------*/
116 /**
117  * @brief   CicoHSControlBarWindow::CreateControlBarWindow
118  *          crate window (control bar)
119  *
120  * @param[in]   pos_x    position x
121  * @param[in]   pos_y    position y
122  * @param[in]   width    width
123  * @param[in]   height   height
124  * @return      OK or ERRROR
125  */
126 /*--------------------------------------------------------------------------*/
127 int
128 CicoHSControlBarWindow::CreateControlBarWindow(int pos_x, int pos_y,
129                                                int width, int height)
130 {
131     int ret;
132     char img_path[ICO_HS_MAX_PATH_BUFF_LEN];
133
134     ICO_DBG("CicoHSControlBarWindow::CreateControlBarWindow: Enter(x/y=%d/%d,w/h=%d/%d)",
135             pos_x, pos_y, width, height);
136
137     /*create window*/
138     ret = CreateWindow(ICO_HS_CONTROL_BAR_WINDOW_TITLE,
139                        pos_x, pos_y, width, height, EINA_TRUE);
140     if(ret != ICO_OK){
141         ICO_ERR("CreateWindow failed.");
142         ICO_DBG("CicoHSControlBarWindow::CreateControlBarWindow: Leave(Error=%d)", ret);
143         return ret;
144     }
145
146     /* get evas */
147     evas = ecore_evas_get(window);
148     if (!evas) {
149         ICO_ERR("ecore_evas_get failed.");
150         ICO_DBG("CicoHSControlBarWindow::CreateControlBarWindow Leave(ERROR)");
151         return ICO_ERROR;
152     }
153
154     // create background evas object
155     background = evas_object_rectangle_add(evas);
156
157     // add callback functions
158     evas_object_event_callback_add(background, EVAS_CALLBACK_KEY_DOWN,
159                                    CicoHSControlBarWindow::evasKeyDownCB, this);
160
161     // key grab
162     evas_object_focus_set(background, EINA_FALSE);
163     Eina_Bool eret = evas_object_key_grab(background, (const char*)changeZoneKeyName,
164                                           0, 0, EINA_TRUE);
165     if (EINA_FALSE == eret) {
166         ICO_WRN("evas_object_key_grab failed.");
167     }
168     eret = evas_object_key_grab(background, (const char*)homeKeyName,
169                                 0, 0, EINA_TRUE);
170     if (EINA_FALSE == eret) {
171         ICO_WRN("evas_object_key_grab failed.");
172     }
173     eret = evas_object_key_grab(background, (const char*)backKeyName,
174                                 0, 0, EINA_TRUE);
175     if (EINA_FALSE == eret) {
176         ICO_WRN("evas_object_key_grab failed.");
177     }
178     eret = evas_object_key_grab(background, (const char*)menuKeyName,
179                                 0, 0, EINA_TRUE);
180     if (EINA_FALSE == eret) {
181         ICO_WRN("evas_object_key_grab failed.");
182     }
183
184     // set background coloer
185     evas_object_color_set(background,128,128,128,255);
186
187     // change window geometry
188     evas_object_move(background, 0, 0);
189     evas_object_resize(background, width,height);
190
191     // show window
192     evas_object_show(background);
193
194     // home button
195     // image file name
196     snprintf(img_path, sizeof(img_path), "%s%s",
197              img_dir_path, ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_DAY);
198
199     // set object
200     menu_btn = evas_object_image_filled_add(evas);
201
202     // preload image
203     snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
204              ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_DAY2);
205     evas_object_image_file_set(menu_btn, img_path, NULL);
206
207     snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
208              ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_NIHGT);
209     evas_object_image_file_set(menu_btn, img_path, NULL);
210
211     snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
212              ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_NIHGT2);
213     evas_object_image_file_set(menu_btn, img_path, NULL);
214
215     // load fisrt show icon image
216     snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
217              ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_DAY);
218     evas_object_image_file_set(menu_btn, img_path, NULL);
219
220     evas_object_move(menu_btn,
221                      (width/2) - (ICO_HS_CONTROL_BAR_MENU_BTN_WIDTH /2),
222                      ICO_HS_CONTROL_BAR_MENU_BTN_START_POS_Y);
223     evas_object_resize(menu_btn, ICO_HS_CONTROL_BAR_MENU_BTN_WIDTH,
224                        ICO_HS_CONTROL_BAR_MENU_BTN_HEIGHT);
225     evas_object_event_callback_add(menu_btn, EVAS_CALLBACK_MOUSE_DOWN,
226                                    CicoHSControlBarTouch::TouchDownControlBar,
227                                    NULL);
228     evas_object_event_callback_add(menu_btn, EVAS_CALLBACK_MOUSE_UP,
229                                    CicoHSControlBarTouch::TouchUpControlBar,
230                                    NULL);
231     evas_object_show(menu_btn);
232
233     /* shortcut */
234     AddShortcut(evas, width);
235
236     ICO_DBG("CicoHSControlBarWindow::CreateControlBarWindow: Leave");
237     return ICO_OK;
238 }
239
240 /*--------------------------------------------------------------------------*/
241 /**
242  * @brief   CicoHSControlBarWindow::AddShortcut
243  *          shortcut addition (control bar)
244  *
245  * @param[in]   evas     Evas Object
246  * @param[in]   width    width
247  * @return      none
248  */
249 /*--------------------------------------------------------------------------*/
250 void
251 CicoHSControlBarWindow::AddShortcut(Evas *evas, int width)
252 {
253     ICO_TRA("CicoHSControlBarWindow::AddShortcut Enter");
254
255     int escPosX;
256     int x;
257     int tmp_space;
258     int s_cnt = 0;
259     const char *tmp_appid;
260     CicoHSLifeCycleController *life_cycle_controller;
261
262     /* menu button x position */
263     escPosX = (width / 2) - (ICO_HS_CONTROL_BAR_MENU_BTN_WIDTH / 2);
264
265     life_cycle_controller = CicoHSLifeCycleController::getInstance();
266
267     tmp_space = (width - (ICO_HS_CONTROL_BAR_MENU_BTN_WIDTH
268                 * ICO_HS_CONTROL_BAR_BTN_MAX_NUM))
269                 / (ICO_HS_CONTROL_BAR_BTN_MAX_NUM + 1);
270     ICO_DBG("CicoHSControlBarWindow::AddShortcut tmp_space = [%d]",
271             tmp_space);
272
273     for (unsigned ii = 0; ii < ICO_HS_CONTROL_BAR_BTN_MAX_NUM; ii++) {
274         x = (ICO_HS_CONTROL_BAR_SHORTCUT_BTN_WIDTH * ii) +
275             (tmp_space * (ii + 1));
276
277         if ((x <= escPosX) &&
278            ((x + ICO_HS_CONTROL_BAR_SHORTCUT_BTN_WIDTH) >= escPosX)) {
279             /* The position of a menu button is skipped */
280             continue;
281         }
282         ICO_DBG("CicoHSControlBarWindow::AddShortcut x = [%d]", x);
283
284         tmp_appid = (const char *)(shortcut_appid[s_cnt]);
285         if (tmp_appid == NULL) {
286             /* No shortcut appid */
287             s_cnt++;
288             continue;
289         }
290
291         /* get APP information */
292         std::vector<CicoAilItems> aillist =
293         life_cycle_controller->getAilList();
294
295         /* add shortcut object */
296         for (unsigned int kk = 0; kk < aillist.size(); kk++ ) {
297             if (strncmp(aillist[kk].m_appid.c_str(), tmp_appid,
298                 ICO_HS_MAX_PROCESS_NAME) == 0) {
299                 ICO_DBG("CicoHSControlBarWindow::AddShortcut tmp_appid = [%s]",
300                         tmp_appid);
301                 shortcut[s_cnt] = evas_object_image_filled_add(evas);
302                 evas_object_image_file_set(shortcut[s_cnt],
303                                   aillist[kk].m_icon.c_str(), NULL);
304                 evas_object_move(shortcut[s_cnt], x,
305                                   ICO_HS_CONTROL_BAR_SHORTCUT_BTN_START_POS_Y);
306                 evas_object_resize(shortcut[s_cnt],
307                                   ICO_HS_CONTROL_BAR_SHORTCUT_BTN_WIDTH,
308                                   ICO_HS_CONTROL_BAR_SHORTCUT_BTN_HEIGHT);
309                 evas_object_event_callback_add(shortcut[s_cnt],
310                                   EVAS_CALLBACK_MOUSE_UP,
311                                   CicoHSControlBarTouch::TouchUpControlBar,
312                                   tmp_appid);
313                 evas_object_show(shortcut[s_cnt]);
314             }
315         }
316         s_cnt++;
317     }
318
319     ICO_TRA("CicoHSControlBarWindow::AddShortcut Leave");
320     return;
321 }
322
323 /*--------------------------------------------------------------------------*/
324 /**
325  * @brief   CicoHSControlBarWindow::FreeControlBarWindow
326  *          free window (control bar)
327  *
328  * @param[in]   none
329  * @return      none
330  */
331 /*--------------------------------------------------------------------------*/
332 void
333 CicoHSControlBarWindow::FreeControlBarWindow(void)
334 {
335     evas_object_del(background);
336     evas_object_del(menu_btn);
337     FreeWindow();
338 }
339
340 /*--------------------------------------------------------------------------*/
341 /**
342  * @brief   CicoHSControlBarWindow::TouchHome
343  *          touch home button
344  *
345  * @param[in]   none
346  * @return      none
347  */
348 /*--------------------------------------------------------------------------*/
349 void
350 CicoHSControlBarWindow::TouchHome(void)
351 {
352     ActivationUpdate();
353     if (true == CicoHSSystemState::getInstance()->getRegulation()) {
354         CicoSound::GetInstance()->PlayFailureSound();
355     }
356     else {
357         CicoSound::GetInstance()->PlayOperationSound();
358     }
359     CicoHomeScreen::ChangeMode(ICO_HS_SHOW_HIDE_PATTERN_SLIDE);
360 }
361
362 /*--------------------------------------------------------------------------*/
363 /**
364  * @brief   CicoHSControlBarWindow::SetNightMode
365  *          set night mode color theme chagne
366  *
367  * @param   none
368  * @return  none
369  */
370 /*--------------------------------------------------------------------------*/
371 void
372 CicoHSControlBarWindow::SetNightMode(void)
373 {
374     ICO_TRA("CicoHSControlBarWindow::SetNightMode Enter");
375
376     bool state = CicoHSSystemState::getInstance()->getNightMode();
377
378     char img_path[ICO_HS_MAX_PATH_BUFF_LEN];
379     if (true == state) {
380         ICO_DBG("ICO_SYC_STATE_ON");
381         evas_object_color_set(background,0,0,0,255);
382         if (true == CicoHSSystemState::getInstance()->getRegulation()) {
383             ICO_DBG("Regulation=ON");
384             snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
385                      ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_NIHGT2);
386         }
387         else {
388             ICO_DBG("Regulation=OFF");
389             snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
390                      ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_NIHGT);
391         }
392         evas_object_image_file_set(menu_btn, img_path, NULL);
393     }
394     else {
395         ICO_DBG("ICO_SYC_STATE_OFF");
396         evas_object_color_set(background,128,128,128,255);
397         if (true == CicoHSSystemState::getInstance()->getRegulation()) {
398             ICO_DBG("Regulation=ON");
399             snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
400                      ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_DAY2);
401         }
402         else {
403             ICO_DBG("Regulation=OFF");
404             snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
405                      ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_DAY);
406         }
407         evas_object_image_file_set(menu_btn, img_path, NULL);
408     }
409
410     ICO_TRA("CicoHSControlBarWindow::SetNightMode Leave");
411 }
412
413 /*--------------------------------------------------------------------------*/
414 /**
415  * @brief   CicoHSControlBarWindow::SetRegulation
416  *          set regulation color theme chagne
417  *
418  * @param   none
419  * @return  none
420  */
421 /*--------------------------------------------------------------------------*/
422 void
423 CicoHSControlBarWindow::SetRegulation(void)
424 {
425     ICO_TRA("CicoHSControlBarWindow::SetRegulation Enter");
426
427     char img_path[ICO_HS_MAX_PATH_BUFF_LEN];
428     if (true == CicoHSSystemState::getInstance()->getNightMode()) {
429         ICO_DBG("NightMode=ON");
430         if (true == CicoHSSystemState::getInstance()->getRegulation()) {
431             ICO_DBG("Regulation=ON");
432             snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
433                      ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_NIHGT2);
434         }
435         else {
436             ICO_DBG("Regulation=OFF");
437             snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
438                      ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_NIHGT);
439         }
440     }
441     else {
442         ICO_DBG("NightMode=OFF");
443         if (true == CicoHSSystemState::getInstance()->getRegulation()) {
444             ICO_DBG("Regulation=ON");
445             snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
446                      ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_DAY2);
447         }
448         else {
449             ICO_DBG("Regulation=OFF");
450             snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
451                      ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_DAY);
452         }
453     }
454     evas_object_image_file_set(menu_btn, img_path, NULL);
455
456     ICO_TRA("CicoHSControlBarWindow::SetRegulation Leave");
457 }
458
459 /*--------------------------------------------------------------------------*/
460 /**
461  * @brief   CicoHSControlBarWindow::SetWindowID
462  *          set appid and surface
463  *
464  * @param[in]   none
465  * @return      none
466  */
467 /*--------------------------------------------------------------------------*/
468 void
469 CicoHSControlBarWindow::SetWindowID(const char *appid,int surface)
470 {
471     strncpy(this->appid,appid,ICO_HS_MAX_PROCESS_NAME);
472     this->surface = surface;
473 }
474
475 /*--------------------------------------------------------------------------*/
476 /**
477  * @brief   CicoHSControlBarWindow::GetSurfaceId
478  *          get surface id of control bar window
479  *
480  * @return  surface id
481  */
482 /*--------------------------------------------------------------------------*/
483 int
484 CicoHSControlBarWindow::GetSurfaceId(void)
485 {
486     return this->surface;
487 }
488
489 /*--------------------------------------------------------------------------*/
490 /**
491  * @brief   CicoHSControlBarWindow::GetAppId
492  *          get application id of control bar
493  *
494  * @return  application id
495  */
496 /*--------------------------------------------------------------------------*/
497 const char *
498 CicoHSControlBarWindow::GetAppId(void)
499 {
500     return this->appid;
501 }
502
503 /*--------------------------------------------------------------------------*/
504 /**
505  * @brief   CicoHSControlBarWindow::TouchShortcut
506  *          touch shortcut button
507  *
508  * @param[in]   none
509  * @return      none
510  */
511 /*--------------------------------------------------------------------------*/
512 void
513 CicoHSControlBarWindow::TouchShortcut(const char *appid)
514 {
515     ICO_TRA("CicoHSControlBarWindow::TouchShortcut Enter");
516     ActivationUpdate();
517
518     CicoSound::GetInstance()->PlayOperationSound();
519
520     if (appid != NULL) {
521         ICO_DBG("CicoHSControlBarWindow::TouchShortcut appid = [%s]", appid);
522         CicoHomeScreen::ExecuteApp(appid);
523     }
524     ICO_TRA("CicoHSControlBarWindow::TouchShortcut Leave");
525 }
526
527 //--------------------------------------------------------------------------
528 /**
529  *  @brief  key up event callback function
530  *
531  *  @pamam [in] data    user data
532  *  @param [in] evas    evas instcance
533  *  @param [in] obj     evas object instcance
534  *  @param [in] info    event information(Evas_Event_Key_Down)
535  */
536 //--------------------------------------------------------------------------
537 void
538 CicoHSControlBarWindow::onKeyDown(void *data, Evas *evas,
539                                   Evas_Object *obj, void *info)
540 {
541     Evas_Event_Key_Down *evinfo = NULL;
542     evinfo = (Evas_Event_Key_Down*)info;
543
544     CicoSound::GetInstance()->PlayOperationSound();
545
546     ICO_PRF("TOUCH_EVENT Key Down keyname=%s, key=%d",
547             evinfo->keyname, (char)*evinfo->key);
548
549     if (0 == strcmp(evinfo->keyname, changeZoneKeyName)) {
550         CicoHomeScreen::ChangeZone();
551     }
552     else if (0 == strcmp(evinfo->keyname, homeKeyName)) {
553         TouchHome();
554     }
555     else if (0 == strcmp(evinfo->keyname, backKeyName)) {
556         // TODO not assinded funciton
557     }
558     else if (0 == strcmp(evinfo->keyname, menuKeyName)) {
559         // TODO not assinded funciton
560     }
561 }
562
563 //--------------------------------------------------------------------------
564 /**
565  *  @brief  key up event callback function
566  *
567  *  @pamam [in] data    user data
568  *  @param [in] evas    evas instcance
569  *  @param [in] obj     evas object instcance
570  *  @param [in] info    event information(Evas_Event_Key_Down)
571  */
572 //--------------------------------------------------------------------------
573 void
574 CicoHSControlBarWindow::evasKeyDownCB(void *data, Evas *evas,
575                                       Evas_Object *obj, void *info)
576 {
577     CicoHSControlBarWindow *ctrlbarwin = (CicoHSControlBarWindow*)(data);
578     ctrlbarwin->onKeyDown(data, evas, obj, info);
579 }
580
581 //--------------------------------------------------------------------------
582 /**
583  *  @brief  Activation update swipe app
584  *
585  *  @return bool
586  *  @retval true update
587  *  @retval false no update
588  */
589 //--------------------------------------------------------------------------
590 bool
591 CicoHSControlBarWindow::ActivationUpdate(void)
592 {
593     return CicoHomeScreen::ActivationUpdate();
594 }
595 // vim: set expandtab ts=4 sw=4: