Tizen 2.1 base
[apps/osp/Home.git] / src / HmHomeItemInfo.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file        HmHomeItemInfo.cpp
19  * @brief       Keeps implementation of the HomeItemInfo
20  * Implements the HomeItemInfo class, it keeps the information of all the applications installed.
21  */
22
23 #include <FBase.h>
24 #include <FGraphics.h>
25 #include "HmHomeItemInfo.h"
26 #include "HmTypes.h"
27
28 using namespace Tizen::App;
29 using namespace Tizen::App::Package;
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Graphics;
33
34 HomeItemInfo::HomeItemInfo(void)
35         : __isVisibleInMainMenu(false)
36         , __isUninstallable(false)
37         , __pageNumber(0)
38         , __position(-1)
39         , __pAppIcon(null)
40 {
41         // No implementation needed
42
43 }
44
45 HomeItemInfo::~HomeItemInfo(void)
46 {
47         // No implementation needed
48 }
49
50 String
51 HomeItemInfo::GetAppId(void) const
52 {
53         // returns application id
54         return __appId;
55 }
56
57 Bitmap*
58 HomeItemInfo::GetApplicationIcon(void) const
59 {
60         // returns the application icon
61         return __pAppIcon;
62 }
63
64 String
65 HomeItemInfo::GetAppName(void) const
66 {
67         // returns the name of the application
68         return __appName;
69 }
70
71 String
72 HomeItemInfo::GetIconPath(void) const
73 {
74         // returns the path of the application icon
75         return __appIconPath;
76 }
77
78 String
79 HomeItemInfo::GetPackageId(void) const
80 {
81         // returns package id
82         return __packageId;
83 }
84
85 void
86 HomeItemInfo::GetPositionInHomeScreen(int& pageNumber, int& position) const
87 {
88         pageNumber = __pageNumber;
89         position = __position;
90         return;
91 }
92
93 result
94 HomeItemInfo::Initialize(PackageAppInfo* pPackAppInfo, PackageInfo* pPackInfo)
95 {
96         TryReturn(pPackAppInfo != null && pPackInfo != null, E_INVALID_ARG, "Invalid arguments");
97
98         result r = E_SUCCESS;
99
100         __isVisibleInMainMenu = pPackAppInfo->IsMenuIconVisible();
101
102         if (__isVisibleInMainMenu)
103         {
104                 // gets the path of the icon if icon is available
105                 String appIconPath = pPackAppInfo->GetAppMenuIconPath();
106
107                 // sets the icon path if icon path is not empty
108                 if (!appIconPath.IsEmpty() && !appIconPath.Equals(L"(null)", true))
109                 {
110                         __appIconPath = appIconPath;
111                 }
112 //              // sets the icon path if icon path is empty temporarily.
113 //              else
114 //              {
115 //                      __appIconPath = IDB_DEFAULT_APP_ICON;
116 //              }
117
118                 // gets the application id
119                 AppId appId = pPackAppInfo->GetAppId();
120                 // sets the application Id
121                 if (!appId.IsEmpty())
122                 {
123                         __appId = appId;
124                 }
125
126                 // gets the application name
127                 String appName = pPackAppInfo->GetAppDisplayName();
128                 // sets the application name
129                 if (!appName.IsEmpty())
130                 {
131                         __appName = appName;
132                 }
133         }
134
135         __isUninstallable = pPackInfo->IsUninstallable();
136         __packageId = pPackInfo->GetId();
137
138         return r;
139 }
140
141 bool
142 HomeItemInfo::IsUnistallable(void) const
143 {
144         // returns true if application is uninstallable else false
145         return __isUninstallable;
146 }
147
148 bool
149 HomeItemInfo::IsVisibleInMainMenu(void) const
150 {
151         // returns true if application icon can be shown in home else false
152         return __isVisibleInMainMenu;
153 }
154
155 void
156 HomeItemInfo::SetApplicationIcon(Bitmap* pAppIconBitmap)
157 {
158         // sets the icon for the application
159         if (__pAppIcon != null)
160         {
161                 delete __pAppIcon;
162                 __pAppIcon = null;
163         }
164         __pAppIcon = pAppIconBitmap;
165         return;
166 }
167
168 void
169 HomeItemInfo::SetApplicationName(String& newAppName)
170 {
171         __appName = newAppName;
172 }
173
174 void
175 HomeItemInfo::SetItemIndex(int newIndex)
176 {
177         __position = newIndex;
178 }
179
180 void
181 HomeItemInfo::SetPositionInHomeScreen(int pageNumber, int position)
182 {
183         // sets the position of the application icon
184         __pageNumber = pageNumber;
185         __position = position;
186         return;
187 }