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