Fixed prevent issue
[apps/osp/Gallery.git] / src / GlImageListPanel.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                GlImageListPanel.cpp
19  * @brief               This is the implementation file for ImageListPanel class.
20  */
21
22 #include <FContent.h>
23 #include <FMedia.h>
24 #include "GlAlbumInfo.h"
25 #include "GlCommonUtil.h"
26 #include "GlFileListForm.h"
27 #include "GlFileListPresentationModel.h"
28 #include "GlImageListPanel.h"
29 #include "GlTypes.h"
30
31 using namespace Tizen::App;
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Content;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Media;
37 using namespace Tizen::Ui;
38 using namespace Tizen::Ui::Controls;
39 using namespace Tizen::Ui::Scenes;
40
41 static const Rectangle RECT_INITIAL (0, 0, 10, 10);
42 static const int W_CLIENT = 720;
43 static const int H_CONTENT_MARGIN = 24;
44 static const int W_CONTENT_MARGIN = 14;
45 static const int W_CONTENT_SPACE = 20;
46 static const int H_CONTENT_SPACE = 24;
47
48 ImageListPanel::ImageListPanel(void)
49         : __itemCount(0)
50         , __pContentIconListView(null)
51         , __pPresentationModel(null)
52 {
53         AppLogDebug("ENTER");
54         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
55 }
56
57 ImageListPanel::~ImageListPanel(void)
58 {
59         AppLogDebug("ENTER");
60         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
61 }
62
63 result
64 ImageListPanel::Initialize(void)
65 {
66         AppLogDebug("ENTER");
67         result r = Construct(RECT_INITIAL);
68         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
69
70         return r;
71 }
72
73 result
74 ImageListPanel::OnInitializing(void)
75 {
76         AppLogDebug("ENTER");
77         const Form* pForm = dynamic_cast<Form*>(GetParent());
78         TryReturn(pForm != null, E_FAILURE, "[%s] fail to get the form.", GetErrorMessage(GetLastResult()));
79
80         __pPresentationModel = FileListPresentationModel::GetInstance();
81         __pPresentationModel->ClearThumbnailRequests();
82         __pPresentationModel->AddPresentationModelListener(this);
83
84         Rectangle clientAreaBounds = pForm->GetClientAreaBounds();
85         clientAreaBounds.x = clientAreaBounds.y = 0;
86         SetBounds(clientAreaBounds);
87         __pContentIconListView = new (std::nothrow) IconListView();
88         __pContentIconListView->Construct(Rectangle(0, 0, W_CLIENT, clientAreaBounds.height),
89                         DIMENSION_DEFAULT_THUMBNAIL, ICON_LIST_VIEW_STYLE_NORMAL, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
90         Bitmap* pBitmapEmpty = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
91         if (pBitmapEmpty != null)
92         {
93                 __pContentIconListView->SetBitmapOfEmptyList(pBitmapEmpty);
94                 delete pBitmapEmpty;
95         }
96         __pContentIconListView->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
97         __pContentIconListView->SetMargin(MARGIN_TYPE_LEFT, W_CONTENT_MARGIN);
98         __pContentIconListView->SetMargin(MARGIN_TYPE_RIGHT, W_CONTENT_MARGIN);
99         __pContentIconListView->SetMargin(MARGIN_TYPE_TOP, H_CONTENT_MARGIN);
100         __pContentIconListView->SetItemSpacing(W_CONTENT_SPACE, H_CONTENT_SPACE);
101         __pContentIconListView->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
102         __pContentIconListView->SetItemProvider(*this);
103         __pContentIconListView->SetCheckBoxPosition(ICON_LIST_VIEW_CHECK_BOX_POSITION_TOP_RIGHT);
104         __pContentIconListView->AddIconListViewItemEventListener(*this);
105         __pContentIconListView->SetTouchAnimationEnabled(false);
106         AddControl(__pContentIconListView);
107         __pContentIconListView->SetShowState(true);
108         __itemCount = 0;
109         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
110
111         return E_SUCCESS;
112 }
113
114 result
115 ImageListPanel::OnTerminating(void)
116 {
117         AppLogDebug("ENTER");
118         __pPresentationModel->RemovePresentationModelListener(*this);
119         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
120
121         return E_SUCCESS;
122 }
123
124 int
125 ImageListPanel::GetItemCount(void)
126 {
127         AppLogDebug("ENTER");
128         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
129
130         return __itemCount;
131 }
132
133 IconListViewItem*
134 ImageListPanel::CreateItem(int index)
135 {
136         AppLogDebug("ENTER");
137         IconListViewItem* pIconListviewItem = new (std::nothrow) IconListViewItem();
138         Bitmap* pBitmap = null;
139         String* pItemText = null;
140         result r = __pPresentationModel->GetThumbnailInSyncCacheN(index, pItemText, pBitmap);
141         if (pBitmap == null || r == E_FAILURE)
142         {
143                 __pPresentationModel->RequestThumbnail(index);
144                 pBitmap = CommonUtil::GetEmptyThumbnailN();
145         }
146
147         if (pItemText == null)
148         {
149                 pItemText = new (std::nothrow) String(ResourceManager::GetString(L"EMPTY_SPACE"));
150         }
151         else if ((*pItemText) != ResourceManager::GetString(L"EMPTY_SPACE"))
152         {
153                 delete pItemText;
154                 pItemText = new (std::nothrow) String(ResourceManager::GetString(L"EMPTY_SPACE"));
155         }
156
157         pIconListviewItem->Construct(*pBitmap, pItemText);
158
159         if (pBitmap != null)
160         {
161                 delete pBitmap;
162         }
163         if (pItemText != null)
164         {
165                 delete pItemText;
166         }
167         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
168
169         return pIconListviewItem;
170 }
171
172 bool
173 ImageListPanel::DeleteItem(int index, IconListViewItem* pItem)
174 {
175         AppLogDebug("ENTER");
176         delete pItem;
177         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
178
179         return true;
180 }
181
182 void
183 ImageListPanel::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
184 {
185         AppLogDebug("ENTER");
186         if (status == ICON_LIST_VIEW_ITEM_SELECTED)
187         {
188                 ArrayList* pArrayList = new (std::nothrow) ArrayList();
189                 pArrayList->Construct();
190                 int loopCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
191
192                 for (int i = 0; i < loopCount; ++i)
193                 {
194                         pArrayList->Add(new (std::nothrow) String(__pPresentationModel->GetContentFilePath(i)));
195                 }
196                 String listIndex;
197                 listIndex.Format(10, L"%d", index);
198
199                 const String mimeType = APPCONTROL_MIME_IMAGE_ALL;
200                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
201                 pDataList->Construct();
202                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE), new (std::nothrow) String(APPCONTROL_DATA_IMAGE));
203                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
204                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_INDEX), new (std::nothrow) String(listIndex));
205
206                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_IMAGE, APPCONTROL_OPERATION_ID_VIEW, null,
207                                 &mimeType, pDataList, null);
208         }
209         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
210 }
211
212 void
213 ImageListPanel::OnFileInfoChanged(const ContentType contentType)
214 {
215         AppLogDebug("ENTER");
216         if (contentType == CONTENT_TYPE_IMAGE)
217         {
218                 __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
219                 __pContentIconListView->UpdateList();
220         }
221         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
222 }
223
224 void
225 ImageListPanel::OnThumbnailDecoded(const int index)
226 {
227         AppLogDebug("ENTER : index(%d)", index);
228         if (index >= 0)
229         {
230                 __pContentIconListView->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
231         }
232         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
233 }
234
235 void
236 ImageListPanel::OnSceneActivatedN(const SceneId& previousSceneId,
237                                                                 const SceneId& currentSceneId, IList* pArgs)
238 {
239         AppLogDebug("ENTER");
240         __pPresentationModel = FileListPresentationModel::GetInstance();
241
242         if (currentSceneId == IDSCN_IMAGE_LIST)
243         {
244                 __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_IMAGE);
245                 __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
246                 __pContentIconListView->UpdateList();
247         }
248
249         SceneManager* pSceneManager = SceneManager::GetInstance();
250         AppAssert(pSceneManager);
251         if (pSceneManager->GetCurrentSceneId() == IDSCN_IMAGE_LIST)
252         {
253                 FileListForm* pFileListForm = dynamic_cast<FileListForm*>(pSceneManager->GetCurrentScene()->GetForm());
254                 if (pFileListForm != null)
255                 {
256                         pFileListForm->SetTitleText(__pPresentationModel->GetCurrentAlbumName());
257                 }
258         }
259         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
260 }
261
262 void
263 ImageListPanel::OnSceneDeactivated(const SceneId& currentSceneId,
264                                                                 const SceneId& nextSceneId)
265 {
266         AppLogDebug("ENTER");
267         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
268 }