9d1b3eb532c4b4e13594f3f879bf1c405408f0c4
[apps/osp/Gallery.git] / src / GlAllListPanel.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                GlAllListPanel.cpp
19  * @brief               This is the implementation file for AllListPanel class.
20  */
21
22 #include "GlAlbumInfo.h"
23 #include "GlAllListPanel.h"
24 #include "GlCommonUtil.h"
25 #include "GlFileListForm.h"
26 #include "GlFileListPresentationModel.h"
27 #include "GlTypes.h"
28
29 using namespace Tizen::App;
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Content;
33 using namespace Tizen::Graphics;
34 using namespace Tizen::Media;
35 using namespace Tizen::Ui;
36 using namespace Tizen::Ui::Controls;
37 using namespace Tizen::Ui::Scenes;
38
39 static const Rectangle RECT_INITIAL (0, 0, 10, 10);
40 static const int W_CLIENT = 720;
41 static const int H_CONTENT_MARGIN = 9;
42 static const int W_CONTENT_MARGIN = 6;
43 static const int W_CONTENT_SPACE = 6;
44 static const int H_CONTENT_SPACE = 6;
45
46 AllListPanel::AllListPanel(void)
47         : __itemCount(0)
48         , __pContentIconListView(null)
49         , __pPresentationModel(null)
50 {
51         AppLogDebug("ENTER");
52         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
53 }
54
55 AllListPanel::~AllListPanel(void)
56 {
57         AppLogDebug("ENTER");
58         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
59 }
60
61 void
62 AllListPanel::Refresh(void)
63 {
64         AppLogDebug("ENTER");
65         if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
66         {
67                 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
68                 {
69                         __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_IMAGE);
70                 }
71                 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
72                 {
73                         __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_VIDEO);
74                 }
75                 else
76                 {
77                         __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_VIDEO);
78                 }
79         }
80         else
81         {
82                 __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_ALL);
83         }
84
85          __pPresentationModel->ClearImageCache();\r
86 \r
87         __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
88         if (__itemCount == 0)
89         {
90                 SceneManager* pSceneManager = SceneManager::GetInstance();
91                 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager", GetErrorMessage(GetLastResult()));
92
93                 pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_ALBUM_LIST));
94         }
95 \r
96         __pContentIconListView->UpdateList();
97         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
98 }
99
100 result
101 AllListPanel::Initialize(void)
102 {
103         AppLogDebug("ENTER");
104         result r = Construct(RECT_INITIAL);
105         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
106
107         return r;
108 }
109
110 result
111 AllListPanel::OnInitializing(void)
112 {
113         AppLogDebug("ENTER");
114         const Form* pForm = dynamic_cast<Form*>(GetParent());
115         AppAssert(pForm);
116
117         __pPresentationModel = FileListPresentationModel::GetInstance();
118         __pPresentationModel->ClearThumbnailRequests();
119         __pPresentationModel->AddPresentationModelListener(this);
120
121         Rectangle clientAreaBounds = pForm->GetClientAreaBounds();
122         clientAreaBounds.x = clientAreaBounds.y = 0;
123         SetBounds(clientAreaBounds);
124
125         __pContentIconListView = new (std::nothrow) IconListView();
126         __pContentIconListView->Construct(Rectangle(0, 0, W_CLIENT, clientAreaBounds.height),
127                         DIMENSION_DEFAULT_THUMBNAIL, ICON_LIST_VIEW_STYLE_NORMAL, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
128         Bitmap* pBitmapEmpty = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
129         if (pBitmapEmpty != null)
130         {
131                 __pContentIconListView->SetBitmapOfEmptyList(pBitmapEmpty);
132                 delete pBitmapEmpty;
133         }
134         __pContentIconListView->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
135         __pContentIconListView->SetMargin(MARGIN_TYPE_LEFT, W_CONTENT_MARGIN);
136         __pContentIconListView->SetMargin(MARGIN_TYPE_RIGHT, W_CONTENT_MARGIN);
137         __pContentIconListView->SetMargin(MARGIN_TYPE_TOP, H_CONTENT_MARGIN);
138         __pContentIconListView->SetItemSpacing(W_CONTENT_SPACE, H_CONTENT_SPACE);
139         __pContentIconListView->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
140         __pContentIconListView->SetItemProvider(*this);
141         __pContentIconListView->SetCheckBoxPosition(ICON_LIST_VIEW_CHECK_BOX_POSITION_TOP_RIGHT);
142         __pContentIconListView->AddIconListViewItemEventListener(*this);
143         __pContentIconListView->SetTouchAnimationEnabled(false);
144         result r = AddControl(*__pContentIconListView);
145         __pContentIconListView->SetShowState(true);
146
147         __itemCount = 0;
148         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
149
150         return r;
151 }
152
153 result
154 AllListPanel::OnTerminating(void)
155 {
156         AppLogDebug("ENTER");
157         SceneManager* pSceneManager = SceneManager::GetInstance();
158         AppAssert(pSceneManager);
159         if (pSceneManager->GetCurrentSceneId() == IDSCN_ALL_LIST)
160         {
161                 FileListForm* pFileListForm = dynamic_cast<FileListForm*>(pSceneManager->GetCurrentScene()->GetForm());
162                 __pPresentationModel->RemoveContentEventListener(pFileListForm);
163         }
164         __pPresentationModel->RemovePresentationModelListener(*this);
165         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
166
167         return E_SUCCESS;
168 }
169
170 int
171 AllListPanel::GetItemCount(void)
172 {
173         AppLogDebug("ENTER");
174         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
175
176         return __itemCount;
177 }
178
179 IconListViewItem*
180 AllListPanel::CreateItem(int index)
181 {
182         AppLogDebug("ENTER : index(%d)", index);
183         Bitmap* pBitmap=null;
184         String* pItemText=null;
185         result r = __pPresentationModel->GetThumbnailInSyncCacheN(index, pItemText, pBitmap);
186         if (r != E_SUCCESS)
187         {
188                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
189                 return null;
190         }
191
192         IconListViewItem* pIconListviewItem = new (std::nothrow) IconListViewItem();
193
194         if (pBitmap == null)
195         {
196                 __pPresentationModel->RequestThumbnail(index);
197                 pBitmap = CommonUtil::GetEmptyThumbnailN();
198         }
199
200         if (pItemText == null)
201         {
202                 pItemText = new (std::nothrow) String(ResourceManager::GetString(L"EMPTY_SPACE"));
203         }
204         else if ((*pItemText) != ResourceManager::GetString(L"EMPTY_SPACE"))
205         {
206                 delete pItemText;
207                 pItemText = new (std::nothrow) String(ResourceManager::GetString(L"EMPTY_SPACE"));
208         }
209
210         if (pItemText != null)
211         {
212                 pIconListviewItem->Construct(*pBitmap, pItemText);
213         }
214
215         if (pBitmap != null)
216         {
217                 delete pBitmap;
218         }
219         if (pItemText != null)
220         {
221                 delete pItemText;
222         }
223         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
224
225         return pIconListviewItem;
226 }
227
228 bool
229 AllListPanel::DeleteItem(int index, IconListViewItem* pItem)
230 {
231         AppLogDebug("ENTER : index(%d)", index);
232         delete pItem;
233         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
234
235         return true;
236 }
237
238 void
239 AllListPanel::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
240 {
241         AppLogDebug("ENTER");
242         if (status == ICON_LIST_VIEW_ITEM_SELECTED)
243         {
244                 if (__pPresentationModel->GetCurrentAlbumContentInfoCount() <= 0)
245                 {
246                         AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
247                         return;
248                 }
249
250                 ArrayList* pArrayList = new (std::nothrow) ArrayList();
251                 pArrayList->Construct();
252                 int loopCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
253
254                 for (int i = 0; i < loopCount; ++i)
255                 {
256                         pArrayList->Add(new (std::nothrow) String(__pPresentationModel->GetContentFilePath(i)));
257                 }
258
259                 String listIndex;
260                 listIndex.Format(10, L"%d", index);
261
262                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
263                 pDataList->Construct();
264                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE), new (std::nothrow) String(APPCONTROL_DATA_IMAGE));
265                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), pArrayList);
266                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_INDEX), new (std::nothrow) String(listIndex));
267
268                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_IMAGE, APPCONTROL_OPERATION_ID_VIEW, null,
269                                 new (std::nothrow) String(APPCONTROL_MIME_IMAGE_ALL), pDataList, null);
270
271                 String* pTemp = null;
272                 loopCount = pArrayList->GetCount();
273                 for (int i = 0; i < loopCount; ++i)
274                 {
275                         pTemp = static_cast<String*>(pArrayList->GetAt(i));
276                         AppLog("print temp(%ls)", pTemp->GetPointer());
277                 }
278         }
279         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
280 }
281
282 void
283 AllListPanel::OnFileInfoChanged(const ContentType contentType)
284 {
285         AppLogDebug("ENTER");
286         if (contentType == CONTENT_TYPE_ALL || contentType == CONTENT_TYPE_IMAGE
287                 || contentType == CONTENT_TYPE_VIDEO)
288         {
289                 __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
290                 __pContentIconListView->UpdateList();
291         }
292         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
293 }
294
295 void
296 AllListPanel::OnThumbnailDecoded(const int index)
297 {
298         AppLogDebug("ENTER : index(%d)", index);
299         if (index >= 0)
300         {
301                 __pContentIconListView->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
302         }
303         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
304 }
305
306 void
307 AllListPanel::OnSceneActivatedN(const SceneId& previousSceneId,
308                                                                 const SceneId& currentSceneId, IList* pArgs)
309 {
310         AppLogDebug("ENTER");
311
312         __pPresentationModel = FileListPresentationModel::GetInstance();
313
314         if (currentSceneId == IDSCN_ALL_LIST)
315         {
316                 if (previousSceneId == IDSCN_ALBUM_LIST && pArgs != null)
317                 {
318                         AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pArgs->GetAt(0));
319                         if (pAlbumInfo == null)
320                         {
321                                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
322
323                                 return;
324                         }
325                         IList* pDirectoryList = pAlbumInfo->GetDirectoryListN();
326                         __pPresentationModel->SetCurrentAlbumInfo(pAlbumInfo->GetAlbumName(), *pDirectoryList);
327                         if (pDirectoryList != null)
328                         {
329                                 delete pDirectoryList;
330                         }
331
332                         delete pArgs;
333
334                         __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
335                         __pContentIconListView->UpdateList();
336                 }
337                 else
338                 {
339                         __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_ALL);
340                         __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
341                         __pContentIconListView->UpdateList();
342                 }
343         }
344         SceneManager* pSceneManager = SceneManager::GetInstance();
345         AppAssert(pSceneManager);
346         if (pSceneManager->GetCurrentSceneId() == IDSCN_ALL_LIST)
347         {
348                 FileListForm* pFileListForm = dynamic_cast<FileListForm*>(pSceneManager->GetCurrentScene()->GetForm());
349                 if (pFileListForm != null)
350                 {
351                         pFileListForm->SetTitleText(__pPresentationModel->GetCurrentAlbumName());
352                 }
353                 __pPresentationModel->AddContentEventListener(pFileListForm);
354         }
355         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
356 }
357
358 void
359 AllListPanel::OnSceneDeactivated(const SceneId& currentSceneId,
360                                                                 const SceneId& nextSceneId)
361 {
362         AppLogDebug("ENTER");
363         SceneManager* pSceneManager = SceneManager::GetInstance();
364         AppAssert(pSceneManager);
365         if (pSceneManager->GetCurrentSceneId() == IDSCN_ALL_LIST)
366         {
367                 FileListForm* pFileListForm = dynamic_cast<FileListForm*>(pSceneManager->GetCurrentScene()->GetForm());
368                 __pPresentationModel->RemoveContentEventListener(pFileListForm);
369         }
370         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
371 }