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