Fork for IVI: mesa fixing
[profile/ivi/uifw.git] / src / ui / controls / FUiCtrl_GalleryItemProviderAdaptor.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 #include <FBaseErrors.h>
18 #include <FBaseSysLog.h>
19 #include <FGrpBitmap.h>
20 #include "FUiCtrl_GalleryItemProviderAdaptor.h"
21 #include "FUiCtrl_IGalleryItemProvider.h"
22 #include "FUiCtrl_GalleryItem.h"
23 #include "FUiCtrl_GalleryBitmap.h"
24
25
26 using namespace Tizen::Graphics;
27
28 namespace Tizen { namespace Ui { namespace Controls {
29
30 _GalleryItemProviderAdaptor::_GalleryItemProviderAdaptor(_IGalleryItemProvider& itemProvider)
31         : __itemProvider(itemProvider)
32 {
33         // Do nothing.
34 }
35
36 _GalleryItemProviderAdaptor::~_GalleryItemProviderAdaptor(void)
37 {
38         // Do nothing.
39 }
40
41 result
42 _GalleryItemProviderAdaptor::SetGalleryItemProvider(_IGalleryItemProvider& itemProvider)
43 {
44         __itemProvider = itemProvider;
45
46         return E_SUCCESS;
47 }
48
49 _IListItemCommon*
50 _GalleryItemProviderAdaptor::LoadItem(int groupIndex, int itemIndex)
51 {
52         SysTryReturn(NID_UI_CTRL, itemIndex >= 0, null, E_INVALID_ARG, "[E_INVALID_ARG] Item index argument is negative.");
53
54         _GalleryItem* pItem = __itemProvider.CreateItem(itemIndex);
55         SysTryReturn(NID_UI_CTRL, pItem != null, null, E_SYSTEM, "[E_SYSTEM] Did not create a GalleryItem");
56
57         SetLastResult(E_SUCCESS);
58
59         return pItem;
60 }
61
62 result
63 _GalleryItemProviderAdaptor::UnloadItem(_IListItemCommon* pItem, int groupIndex, int itemIndex)
64 {
65         SysTryReturn(NID_UI_CTRL, pItem != null, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Gallery Item is null");
66         SysTryReturn(NID_UI_CTRL, itemIndex >= 0, null, E_INVALID_ARG, "[E_INVALID_ARG] Item index is negative.");
67         //SysTryReturn(NID_UI_CTRL, itemIndex < GetItemCount(), null, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Item index argument is out of range.");
68
69         _GalleryItem* pGalleryItem = dynamic_cast<_GalleryItem*>(pItem);
70         SysTryReturn(NID_UI_CTRL, pGalleryItem != null, E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] pItem is not a _GalleryItem object");
71
72         bool deleteSuccess = true;
73         if (pGalleryItem->GetAppInfo() != null)
74         {
75                 deleteSuccess = __itemProvider.UnloadItem(itemIndex, pGalleryItem);
76         }
77         else
78         {
79                 delete pGalleryItem;
80         }
81
82         if (deleteSuccess == true)
83         {
84                 return E_SUCCESS;
85         }
86         else if (GetLastResult() != E_SUCCESS)
87         {
88                 return GetLastResult();
89         }
90         else
91         {
92                 return E_INVALID_STATE;
93         }
94 }
95
96 int
97 _GalleryItemProviderAdaptor::GetItemCount(int groupIndex) const
98 {
99         return __itemProvider.GetItemCount();
100 }
101
102 result
103 _GalleryItemProviderAdaptor::DeleteItem(_IListItemCommon* pItem, int groupIndex, int itemIndex)
104 {
105         SysTryReturn(NID_UI_CTRL, pItem != null, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Gallery Item is null.");
106         SysTryReturn(NID_UI_CTRL, itemIndex >= 0, null, E_INVALID_ARG, "[E_INVALID_ARG] Item index is negative.");
107
108         _GalleryItem* pGalleryItem = dynamic_cast<_GalleryItem*>(pItem);
109         SysTryReturn(NID_UI_CTRL, pGalleryItem != null, E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] pItem is not a _GalleryItem object");
110
111         bool deleteSuccess = true;
112         if (pGalleryItem->GetAppInfo() != null)
113         {
114                 deleteSuccess = __itemProvider.DeleteItem(itemIndex, pGalleryItem);
115         }
116         else
117         {
118                 delete pGalleryItem;
119         }
120
121         if (deleteSuccess == true)
122         {
123                 return E_SUCCESS;
124         }
125         else if (GetLastResult() != E_SUCCESS)
126         {
127                 return GetLastResult();
128         }
129         else
130         {
131                 return E_INVALID_STATE;
132         }
133 }
134
135 }}} // Tizen::Ui::Controls