baa147982b62e0ca811f24bd93f02e91fa145ab8
[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.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                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         __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
86         if (__itemCount == 0)
87         {
88                 SceneManager* pSceneManager = SceneManager::GetInstance();
89                 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager", GetErrorMessage(GetLastResult()));
90
91                 pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_ALBUM_LIST));
92         }
93
94         __pContentIconListView->UpdateList();
95         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
96 }
97
98 result
99 AllListPanel::Initialize(void)
100 {
101         AppLogDebug("ENTER");
102         result r = Construct(RECT_INITIAL);
103         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
104
105         return r;
106 }
107
108 result
109 AllListPanel::OnInitializing(void)
110 {
111         AppLogDebug("ENTER");
112         const Form* pForm = dynamic_cast<Form*>(GetParent());
113         AppAssert(pForm);
114
115         __pPresentationModel = FileListPresentationModel::GetInstance();
116         __pPresentationModel->ClearThumbnailRequests();
117         __pPresentationModel->AddPresentationModelListener(this);
118
119         Rectangle clientAreaBounds = pForm->GetClientAreaBounds();
120         clientAreaBounds.x = clientAreaBounds.y = 0;
121         SetBounds(clientAreaBounds);
122
123         __pContentIconListView = new (std::nothrow) IconListView();
124         __pContentIconListView->Construct(Rectangle(0, 0, W_CLIENT, clientAreaBounds.height),
125                         DIMENSION_DEFAULT_THUMBNAIL, ICON_LIST_VIEW_STYLE_NORMAL, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
126         Bitmap* pBitmapEmpty = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
127         if (pBitmapEmpty != null)
128         {
129                 __pContentIconListView->SetBitmapOfEmptyList(pBitmapEmpty);
130                 delete pBitmapEmpty;
131         }
132         __pContentIconListView->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
133         __pContentIconListView->SetMargin(MARGIN_TYPE_LEFT, W_CONTENT_MARGIN);
134         __pContentIconListView->SetMargin(MARGIN_TYPE_RIGHT, W_CONTENT_MARGIN);
135         __pContentIconListView->SetMargin(MARGIN_TYPE_TOP, H_CONTENT_MARGIN);
136         __pContentIconListView->SetItemSpacing(W_CONTENT_SPACE, H_CONTENT_SPACE);
137         __pContentIconListView->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
138         __pContentIconListView->SetItemProvider(*this);
139         __pContentIconListView->SetCheckBoxPosition(ICON_LIST_VIEW_CHECK_BOX_POSITION_TOP_RIGHT);
140         __pContentIconListView->AddIconListViewItemEventListener(*this);
141         __pContentIconListView->SetTouchAnimationEnabled(false);
142         result r = AddControl(__pContentIconListView);
143         __pContentIconListView->SetShowState(true);
144
145         __itemCount = 0;
146         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
147
148         return r;
149 }
150
151 result
152 AllListPanel::OnTerminating(void)
153 {
154         AppLogDebug("ENTER");
155         SceneManager* pSceneManager = SceneManager::GetInstance();
156         AppAssert(pSceneManager);
157         if (pSceneManager->GetCurrentSceneId() == IDSCN_ALL_LIST)
158         {
159                 FileListForm* pFileListForm = dynamic_cast<FileListForm*>(pSceneManager->GetCurrentScene()->GetForm());
160                 __pPresentationModel->RemoveContentEventListener(pFileListForm);
161         }
162         __pPresentationModel->RemovePresentationModelListener(*this);
163         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
164
165         return E_SUCCESS;
166 }
167
168 int
169 AllListPanel::GetItemCount(void)
170 {
171         AppLogDebug("ENTER");
172         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
173
174         return __itemCount;
175 }
176
177 IconListViewItem*
178 AllListPanel::CreateItem(int index)
179 {
180         AppLogDebug("ENTER : index(%d)", index);
181         Bitmap* pBitmap=null;
182         String* pItemText=null;
183         result r = __pPresentationModel->GetThumbnailInSyncCacheN(index, pItemText, pBitmap);
184         if (r != E_SUCCESS)
185         {
186                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
187                 return null;
188         }
189
190         IconListViewItem* pIconListviewItem = new (std::nothrow) IconListViewItem();
191
192         if (pBitmap == null)
193         {
194                 __pPresentationModel->RequestThumbnail(index);
195                 pBitmap = CommonUtil::GetEmptyThumbnailN();
196         }
197
198         if (pItemText == null)
199         {
200                 pItemText = new (std::nothrow) String(ResourceManager::GetString(L"EMPTY_SPACE"));
201         }
202         else if ((*pItemText) != ResourceManager::GetString(L"EMPTY_SPACE"))
203         {
204                 delete pItemText;
205                 pItemText = new (std::nothrow) String(ResourceManager::GetString(L"EMPTY_SPACE"));
206         }
207
208         if (pItemText != null)
209         {
210                 pIconListviewItem->Construct(*pBitmap, pItemText);
211         }
212
213         if (pBitmap != null)
214         {
215                 delete pBitmap;
216         }
217         if (pItemText != null)
218         {
219                 delete pItemText;
220         }
221         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
222
223         return pIconListviewItem;
224 }
225
226 bool
227 AllListPanel::DeleteItem(int index, IconListViewItem* pItem)
228 {
229         AppLogDebug("ENTER : index(%d)", index);
230         delete pItem;
231         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
232
233         return true;
234 }
235
236 void
237 AllListPanel::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
238 {
239         AppLogDebug("ENTER");
240         result r = E_SUCCESS;
241         if (status == ICON_LIST_VIEW_ITEM_SELECTED)
242         {
243                 if (__pPresentationModel->GetCurrentAlbumContentInfoCount() <= 0)
244                 {
245                         AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
246                         return;
247                 }
248
249                 ArrayList* pArrayList = new (std::nothrow) ArrayList();
250                 pArrayList->Construct();
251                 int loopCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
252
253                 for (int i = 0; i < loopCount; ++i)
254                 {
255                         pArrayList->Add(new (std::nothrow) String(__pPresentationModel->GetContentFilePath(i)));
256                 }
257
258                 String listIndex;
259                 listIndex.Format(10, L"%d", index);
260
261                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
262                 pDataList->Construct();
263                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE), new (std::nothrow) String(APPCONTROL_DATA_IMAGE));
264                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), pArrayList);
265                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_INDEX), new (std::nothrow) String(listIndex));
266
267                 r = __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_IMAGE, APPCONTROL_OPERATION_ID_VIEW, null,
268                                 new (std::nothrow) String(APPCONTROL_MIME_IMAGE_ALL), pDataList, null);
269
270                 if (r == E_MAX_EXCEEDED)
271                 {
272                         MessageBox messageBox;
273                         messageBox.Construct(L"", ResourceManager::GetString(L"IDS_RCS_BODY_MAXIMUM_NUMBER_OF_FILES_EXCEEDED"),
274                                         MSGBOX_STYLE_NONE, 3000);
275                         int modalResult;
276                         messageBox.ShowAndWait(modalResult);
277                 }
278
279                 String* pTemp = null;
280                 loopCount = pArrayList->GetCount();
281                 for (int i = 0; i < loopCount; ++i)
282                 {
283                         pTemp = static_cast<String*>(pArrayList->GetAt(i));
284                         AppLog("print temp(%ls)", pTemp->GetPointer());
285                 }
286         }
287         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
288 }
289
290 void
291 AllListPanel::OnFileInfoChanged(const ContentType contentType)
292 {
293         AppLogDebug("ENTER");
294         if (contentType == CONTENT_TYPE_ALL || contentType == CONTENT_TYPE_IMAGE
295                 || contentType == CONTENT_TYPE_VIDEO)
296         {
297                 __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
298                 __pContentIconListView->UpdateList();
299         }
300         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
301 }
302
303 void
304 AllListPanel::OnThumbnailDecoded(const int index)
305 {
306         AppLogDebug("ENTER : index(%d)", index);
307         if (index >= 0)
308         {
309                 __pContentIconListView->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
310         }
311         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
312 }
313
314 void
315 AllListPanel::ChangeOrientation(void)
316 {
317         AppLogDebug("ENTER");
318         SceneManager* pSceneManager = SceneManager::GetInstance();
319         const Form* pForm = dynamic_cast<Form*>(pSceneManager->GetCurrentScene()->GetForm());
320         TryReturn(pForm != null, , "[%s] fail to get the form.", GetErrorMessage(GetLastResult()));
321
322         Rectangle clientAreaBounds = pForm->GetClientAreaBounds();
323         SetBounds(0, 0, clientAreaBounds.width, clientAreaBounds.height);
324         __pContentIconListView->SetBounds(0, 0, clientAreaBounds.width, clientAreaBounds.height);
325 }
326
327 void
328 AllListPanel::OnSceneActivatedN(const SceneId& previousSceneId,
329                                                                 const SceneId& currentSceneId, IList* pArgs)
330 {
331         AppLogDebug("ENTER");
332
333         ChangeOrientation();
334
335         __pPresentationModel = FileListPresentationModel::GetInstance();
336
337         if (currentSceneId == IDSCN_ALL_LIST)
338         {
339                 if (previousSceneId == IDSCN_ALBUM_LIST && pArgs != null)
340                 {
341                         AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pArgs->GetAt(0));
342                         if (pAlbumInfo == null)
343                         {
344                                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
345
346                                 return;
347                         }
348                         IList* pDirectoryList = pAlbumInfo->GetDirectoryListN();
349                         __pPresentationModel->SetCurrentAlbumInfo(pAlbumInfo->GetAlbumName(), *pDirectoryList);
350                         if (pDirectoryList != null)
351                         {
352                                 delete pDirectoryList;
353                         }
354
355                         delete pArgs;
356
357                         __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
358                         __pContentIconListView->UpdateList();
359                 }
360                 else
361                 {
362                         __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_ALL);
363                         __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
364                         __pContentIconListView->UpdateList();
365                 }
366         }
367         SceneManager* pSceneManager = SceneManager::GetInstance();
368         AppAssert(pSceneManager);
369         if (pSceneManager->GetCurrentSceneId() == IDSCN_ALL_LIST)
370         {
371                 FileListForm* pFileListForm = dynamic_cast<FileListForm*>(pSceneManager->GetCurrentScene()->GetForm());
372                 if (pFileListForm != null)
373                 {
374                         pFileListForm->SetTitleText(__pPresentationModel->GetCurrentAlbumName());
375
376                         if( __itemCount == 0)
377                         {
378                                 pFileListForm->SetMenuState(false);
379                         }
380                         else
381                         {
382                                 pFileListForm->SetMenuState(true);
383                         }
384
385                 }
386                 __pPresentationModel->AddContentEventListener(pFileListForm);
387         }
388         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
389 }
390
391 void
392 AllListPanel::OnSceneDeactivated(const SceneId& currentSceneId,
393                                                                 const SceneId& nextSceneId)
394 {
395         AppLogDebug("ENTER");
396         SceneManager* pSceneManager = SceneManager::GetInstance();
397         AppAssert(pSceneManager);
398         if (pSceneManager->GetCurrentSceneId() == IDSCN_ALL_LIST)
399         {
400                 FileListForm* pFileListForm = dynamic_cast<FileListForm*>(pSceneManager->GetCurrentScene()->GetForm());
401                 __pPresentationModel->RemoveContentEventListener(pFileListForm);
402         }
403         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
404 }