bug fix: TC-1152
[profile/ivi/ico-uxf-homescreen.git] / src / homescreen / CicoHSBackWindow.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   Back Screen
11  *
12  * @date    Aug-08-2013
13  */
14 #include <tzplatform_config.h>
15 #include "CicoHSBackWindow.h"
16 #include "CicoResourceConfig.h"
17
18 /*============================================================================*/
19 /* functions                                                                  */
20 /*============================================================================*/
21 /*--------------------------------------------------------------------------*/
22 /**
23  * @brief   CicoHSBackWindow::CicoHSBackWindow
24  *          Constractor
25  *
26  * @param[in]   none
27  * @return      none
28  */
29 /*--------------------------------------------------------------------------*/
30 CicoHSBackWindow::CicoHSBackWindow(void)
31 {
32     evas = NULL;
33
34     CicoResourceConfig::GetImagePath(img_dir_path,ICO_HS_MAX_PATH_BUFF_LEN);
35
36 }
37
38 /*--------------------------------------------------------------------------*/
39 /**
40  * @brief   CicoHSBackWindow::~CicoHSBackWindow
41  *          Destractor
42  *
43  * @param[in]   none
44  * @return      none
45  */
46 /*--------------------------------------------------------------------------*/
47 CicoHSBackWindow::~CicoHSBackWindow(void)
48 {
49     /* Do not somthing to do */
50 }
51
52 /*--------------------------------------------------------------------------*/
53 /**
54  * @brief   CicoHSBackWindow::CreateBackWindow
55  *          create window (back)
56  *
57  * @param[in]   pos_x    position x
58  * @param[in]   pos_y    position y
59  * @param[in]   width    width
60  * @param[in]   height   height
61  * @return      OK or ERRROR
62  */
63 /*--------------------------------------------------------------------------*/
64 int
65 CicoHSBackWindow::CreateBackWindow(int pos_x,int pos_y,int width,int height)
66 {
67     int ret;
68
69     /*create window*/
70     ret = CreateWindow(ICO_HS_BACK_WINDOW_TITLE, pos_x, pos_y, width, height, EINA_TRUE);
71     if(ret != ICO_OK){
72        return ret;
73     }
74
75     /* evas get */
76     evas = ecore_evas_get(window);
77     if (!evas) {
78         ICO_ERR("CicoHSBackWindow::CreateBackWindow: could not get evas.");
79         return ICO_ERROR;
80     }
81
82     /* get configuration */
83     CicoGKeyFileConfig config;
84     config.Initialize(ICO_HOMESCREEN_CONFIG_FILE, ICO_SYC_PACKAGE_HOMESCREEN);
85
86     const char *back_image = config.ConfigGetFilePath(
87                                         "homescreen", "background",
88                                         ICO_SYC_CONFIGPATH_HOME_IMAGE,
89                                         ICO_SYC_PACKAGE_HOMESCREEN
90                                           "/" ICO_SYC_CONFIGPATH_PACKAGE_IMAGE,
91                                         NULL);
92     if (! back_image)   {
93         // if image file dos not exist, search system imahe files
94         const char *back_file = config.ConfigGetString(
95                                         "homescreen", "background",
96                                         ICO_HS_DEFAULT_BACK_WINDOW_IMAGE_FILE_FILE);
97         back_image = tzplatform_mkpath3(TZ_SYS_DATA,
98                                         ICO_HS_DEFAULT_BACK_WINDOW_IMAGE_FILE_DIR,
99                                         back_file);
100         if (access(back_image, R_OK) != 0)  {
101             // not exist, set default back image file
102             back_image = tzplatform_mkpath3(TZ_SYS_DATA,
103                                             ICO_HS_DEFAULT_BACK_WINDOW_IMAGE_FILE_DIR,
104                                             ICO_HS_DEFAULT_BACK_WINDOW_IMAGE_FILE_FILE);
105         }
106     }
107     ICO_DBG("CicoHSBackWindow::CreateBackWindow: background(%s)", back_image);
108
109     /* set object*/
110     canvas = evas_object_image_filled_add(evas);
111     evas_object_image_file_set(canvas, back_image, NULL);
112     int err = evas_object_image_load_error_get(canvas);
113     if (err != EVAS_LOAD_ERROR_NONE) {
114         ICO_ERR("CicoHSBackWindow::CreateBackWindow: backgound image is not exist");
115         evas_object_del(canvas);
116         FreeWindow();
117         return ICO_ERROR;
118     }
119     evas_object_image_fill_set(canvas, pos_x, pos_y, width, height);
120     evas_object_resize(canvas, width,height);
121     evas_object_show(canvas);
122
123     return ICO_OK;
124 }
125
126 /*--------------------------------------------------------------------------*/
127 /**
128  * @brief   CicoHSBackWindow::FreeBackWindow
129  *          free window (back)
130  *
131  * @param[in]   none
132  * @return      none
133  */
134 /*--------------------------------------------------------------------------*/
135 void
136 CicoHSBackWindow::FreeBackWindow(void)
137 {
138     evas_object_del(canvas);
139     FreeWindow();
140 }
141 // vim: set expandtab ts=4 sw=4: