Flora license update
[apps/osp/Home.git] / src / HmCustomIconListProvider.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (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        HmCustomIconListProvider.cpp = false;
19  * @brief       This is the implementation for the IconListItemProviderCustom class
20  * This class contains the functions which are required managing the IconListView's items
21  */
22
23 #include "HmApplicationUtils.h"
24 #include "HmCustomIconListProvider.h"
25 #include "HmCustomPageControl.h"
26 #include "HmHomeItemInfo.h"
27 #include "HmTypes.h"
28
29 using namespace Tizen::App;
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Graphics;
33 using namespace Tizen::Ui;
34 using namespace Tizen::Ui::Controls;
35
36 CustomIconListProvider::CustomIconListProvider(int index)
37         : __editMode(false)
38         , __isProjectedItemInvalid(false)
39         , __index(index)
40         , __iconsPerPage(0)
41         , __currentIndex(-1)
42         , __pPageItemProvider(null)
43         , __pMovementItem(null)
44         , __pOverayBitmap(null)
45 {
46         // No implementation required
47 }
48
49 CustomIconListProvider::~CustomIconListProvider(void)
50 {
51         if (__pOverayBitmap != null)
52         {
53                 delete __pOverayBitmap;
54                 __pOverayBitmap = null;
55         }
56 }
57
58 bool
59 CustomIconListProvider::GetEditMode(void) const
60 {
61         return __editMode;
62 }
63
64 IconListViewItem*
65 CustomIconListProvider::GetMovingItem(void) const
66 {
67         return __pMovementItem;
68 }
69
70 int
71 CustomIconListProvider::GetMovingItemIndex() const
72 {
73         return __currentIndex;
74 }
75
76 IPageControlItemProvider*
77 CustomIconListProvider::GetPageControlItemProvider(void)
78 {
79         return __pPageItemProvider;
80 }
81
82 void
83 CustomIconListProvider::SetEditMode(bool editMode)
84 {
85         // sets the edit mode
86         __editMode = editMode;
87         return;
88 }
89
90 void
91 CustomIconListProvider::SetIndex(int index)
92 {
93         // sets the index of the provider
94         __index = index;
95         return;
96 }
97
98 void
99 CustomIconListProvider::SetMaxCountOfIcons(int iconCount)
100 {
101         // sets the maximum number of icons in the page.
102         __iconsPerPage = iconCount;
103         return;
104 }
105
106 void
107 CustomIconListProvider::SetMovingItem(Tizen::Ui::Controls::IconListViewItem* pMovedItem)
108 {
109         __pMovementItem = pMovedItem;
110 }
111
112 void
113 CustomIconListProvider::SetMovingItemIndex(int movedIndex)
114 {
115         __currentIndex = movedIndex;
116 }
117
118 void
119 CustomIconListProvider::SetPageControlItemProvider(IPageControlItemProvider* pItemProvider)
120 {
121         __pPageItemProvider = pItemProvider;
122 }
123
124 void
125 CustomIconListProvider::SetProjectedItemInvalid(bool isInvalid)
126 {
127         __isProjectedItemInvalid = isInvalid;
128 }
129
130 IconListViewItem*
131 CustomIconListProvider::CreateItem(int index)
132 {
133         IconListViewItem* pItem = null;
134         HomeItemInfo* pItemInfo = null;
135
136         pItemInfo = __pPageItemProvider->GetItem(__index, index);
137         // if application icon
138         if (pItemInfo != null)
139         {
140
141                 if (__pMovementItem != null && __currentIndex == index && !__isProjectedItemInvalid)
142                 {
143                         pItem = __pMovementItem;
144                 }
145                 else
146                 {
147                         Bitmap* pItemBitmap = null;
148                         String appName = static_cast<HomeItemInfo*>(pItemInfo)->GetAppName();
149                         String iconPath = pItemInfo->GetIconPath();
150
151                         if (!iconPath.IsEmpty())
152                         {
153                                 // gets the application icon if exists
154                                 pItemBitmap = pItemInfo->GetApplicationIcon();
155                                 // creates the icon if application icon doesn't exist.
156                                 if (pItemBitmap == null)
157                                 {
158                                         pItemBitmap = ApplicationUtils::GetApplicationIconBitmapN(iconPath, appName);
159                                         pItemInfo->SetApplicationIcon(pItemBitmap);
160                                 }
161                         }
162                         // constructs the item for the IconListView
163                         if (pItemBitmap != null)
164                         {
165                                 pItem = new (std::nothrow) IconListViewItem(); //
166                                 pItem->Construct(*pItemBitmap);
167                         }
168                 }
169
170
171                 if (__editMode)
172                 {
173                         bool showDeleteButton = true;
174
175                         if (pItemInfo != null)
176                         {
177                                 showDeleteButton = pItemInfo->IsUnistallable();
178                         }
179
180                         if (showDeleteButton)
181                         {
182                                 if (__pOverayBitmap == null)
183                                 {
184                                         __pOverayBitmap = ApplicationUtils::GetResourceBitmapN(IDB_CLOSE_ICON);
185                                 }
186
187                                 if (__pOverayBitmap != null)
188                                 {
189                                         // adds overlay bitmap to IconListView items if in edit mode.
190                                         if (pItem != null)
191                                         {
192                                                 pItem->SetOverlayBitmap(IDA_OVERLAYBITMAP_CLOSE, __pOverayBitmap, ALIGNMENT_RIGHT, ALIGNMENT_TOP);
193                                         }
194                                 }
195                         }
196                 }
197         }
198         return pItem;
199 }
200
201 bool
202 CustomIconListProvider::DeleteItem(int index, IconListViewItem* pItem)
203 {
204         if (pItem != null)
205         {
206                 if (__pMovementItem != null && __pMovementItem->GetHashCode() == pItem->GetHashCode())
207                 {
208                         return true;
209                 }
210
211                 delete pItem;
212                 pItem = null;
213                 return true;
214         }
215
216         return false;
217 }
218
219 int
220 CustomIconListProvider::GetItemCount(void)
221 {
222         if (__pPageItemProvider != null)
223         {
224                 return __pPageItemProvider->GetItemCount(__index);
225         }
226
227         return 0;
228 }