Initialize Tizen 2.3
[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,SCENE_TRANSITION_ANIMATION_TYPE_NONE,SCENE_DESTROY_OPTION_KEEP));
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                 const String mimeType = APPCONTROL_MIME_IMAGE_ALL;
272
273                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
274                 pDataList->Construct();
275                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE), new (std::nothrow) String(APPCONTROL_DATA_IMAGE));
276                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), pArrayList);
277                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_INDEX), new (std::nothrow) String(listIndex));
278
279                 r = __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_IMAGE, APPCONTROL_OPERATION_ID_VIEW, null,
280                                 &mimeType, pDataList, null);
281
282                 if (r == E_MAX_EXCEEDED)
283                 {
284                         MessageBox messageBox;
285                         messageBox.Construct(L"", ResourceManager::GetString(L"IDS_RCS_BODY_MAXIMUM_NUMBER_OF_FILES_EXCEEDED"),
286                                         MSGBOX_STYLE_NONE, 3000);
287                         int modalResult;
288                         messageBox.ShowAndWait(modalResult);
289                 }
290
291                 String* pTemp = null;
292                 loopCount = pArrayList->GetCount();
293                 for (int i = 0; i < loopCount; ++i)
294                 {
295                         pTemp = static_cast<String*>(pArrayList->GetAt(i));
296                         AppLog("print temp(%ls)", pTemp->GetPointer());
297                 }
298         }
299         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
300 }
301
302 void
303 AllListPanel::OnFileInfoChanged(const ContentType contentType)
304 {
305         AppLogDebug("ENTER");
306         if (contentType == CONTENT_TYPE_ALL || contentType == CONTENT_TYPE_IMAGE
307                 || contentType == CONTENT_TYPE_VIDEO)
308         {
309                 __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
310                 __pContentIconListView->UpdateList();
311         }
312         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
313 }
314
315 void
316 AllListPanel::OnThumbnailDecoded(const int index)
317 {
318         AppLogDebug("ENTER : index(%d)", index);
319         if (index >= 0)
320         {
321                 __pContentIconListView->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
322         }
323         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
324 }
325
326 void
327 AllListPanel::ChangeOrientation(void)
328 {
329         AppLogDebug("ENTER");
330         SceneManager* pSceneManager = SceneManager::GetInstance();
331         const Form* pForm = dynamic_cast<Form*>(pSceneManager->GetCurrentScene()->GetForm());
332         TryReturn(pForm != null,, "[%s] fail to get the form.", GetErrorMessage(GetLastResult()));
333
334         Rectangle clientAreaBounds = pForm->GetClientAreaBounds();
335         SetBounds(0, 0, clientAreaBounds.width, clientAreaBounds.height);
336         __pContentIconListView->SetBounds(0, 0, clientAreaBounds.width, clientAreaBounds.height);
337 }
338
339 void
340 AllListPanel::OnSceneActivatedN(const SceneId& previousSceneId,
341                                                                 const SceneId& currentSceneId, IList* pArgs)
342 {
343         AppLogDebug("ENTER");
344         ChangeOrientation();
345
346         __pPresentationModel = FileListPresentationModel::GetInstance();
347
348         if (currentSceneId == IDSCN_ALL_LIST)
349         {
350                 if (previousSceneId == IDSCN_ALBUM_LIST && pArgs != null)
351                 {
352                         AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pArgs->GetAt(0));
353                         if (pAlbumInfo == null)
354                         {
355                                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
356
357                                 return;
358                         }
359                         IList* pDirectoryList = pAlbumInfo->GetDirectoryListN();
360                         __pPresentationModel->SetCurrentAlbumInfo(pAlbumInfo->GetAlbumName(), *pDirectoryList);
361                         if (pDirectoryList != null)
362                         {
363                                 delete pDirectoryList;
364                         }
365
366                         delete pArgs;
367
368                         __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
369                         __pContentIconListView->UpdateList();
370                 }
371                 else
372                 {
373                         __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_ALL);
374                         __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
375                         __pContentIconListView->UpdateList();
376                 }
377         }
378         SceneManager* pSceneManager = SceneManager::GetInstance();
379         AppAssert(pSceneManager);
380         if (pSceneManager->GetCurrentSceneId() == IDSCN_ALL_LIST)
381         {
382                 FileListForm* pFileListForm = dynamic_cast<FileListForm*>(pSceneManager->GetCurrentScene()->GetForm());
383                 if (pFileListForm != null)
384                 {
385                         pFileListForm->SetTitleText(__pPresentationModel->GetCurrentAlbumName());
386
387                         if (__itemCount == 0)
388                         {
389                                 pFileListForm->SetMenuState(false);
390                         }
391                         else
392                         {
393                                 pFileListForm->SetMenuState(true);
394                         }
395
396                 }
397                 __pPresentationModel->AddContentEventListener(pFileListForm);
398         }
399         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
400 }
401
402 void
403 AllListPanel::OnSceneDeactivated(const SceneId& currentSceneId,
404                                                                 const SceneId& nextSceneId)
405 {
406         AppLogDebug("ENTER");
407         SceneManager* pSceneManager = SceneManager::GetInstance();
408         AppAssert(pSceneManager);
409         if (pSceneManager->GetCurrentSceneId() == IDSCN_ALL_LIST)
410         {
411                 FileListForm* pFileListForm = dynamic_cast<FileListForm*>(pSceneManager->GetCurrentScene()->GetForm());
412                 __pPresentationModel->RemoveContentEventListener(pFileListForm);
413         }
414         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
415 }