2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
18 * @file GlAlbumListForm.cpp
19 * @brief This is the implementation file for AlbumListForm class.
22 #include "GlAlbumInfo.h"
23 #include "GlAlbumListForm.h"
24 #include "GlAlbumListPresentationModel.h"
25 #include "GlGalleryApp.h"
26 #include "GlResourceManager.h"
28 using namespace Tizen::App;
29 using namespace Tizen::Base;
30 using namespace Tizen::Base::Collection;
31 using namespace Tizen::Base::Runtime;
32 using namespace Tizen::Content;
33 using namespace Tizen::Graphics;
34 using namespace Tizen::Io;
35 using namespace Tizen::Media;
36 using namespace Tizen::System;
37 using namespace Tizen::Ui;
38 using namespace Tizen::Ui::Controls;
39 using namespace Tizen::Ui::Scenes;
41 static const int W_FOLDER_SIZE = 348;
42 static const int H_FOLDER_SIZE = 348;
44 AlbumListForm::AlbumListForm(void)
46 , __pAlbumViewIconList(null)
47 , __pContextMenuMore(null)
48 , __pPresentationModel(null)
51 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
54 AlbumListForm::~AlbumListForm(void)
57 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
61 AlbumListForm::Initialize(void)
64 result r = Form::Construct(IDL_FORM_ALBUM_LIST);
65 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
71 AlbumListForm::OnInitializing(void)
76 __pPresentationModel = AlbumListPresentationModel::GetInstance();
77 __pPresentationModel->ClearThumbnailRequests();
78 __pPresentationModel->AddPresentationModelListener(this);
80 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
82 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
84 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
86 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
88 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
92 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
97 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
100 AppLogDebug("ENTER __pPresentationModel(%x)", __pPresentationModel);
102 r = InitializeHeader();
105 AppLogDebug("[%s] Unable to set header.", GetErrorMessage(r));
108 r = InitializeFooter();
111 AppLogDebug("[%s] Unable to set footer.", GetErrorMessage(r));
114 __itemCount = __pPresentationModel->GetFolderCount();
115 CreateIconListView();
116 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
122 AlbumListForm::InitializeHeader(void)
124 AppLogDebug("ENTER");
125 Header* pHeader = GetHeader();
128 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
132 result r = pHeader->SetStyle(HEADER_STYLE_TITLE);
135 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
139 pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_GALLERY"));
140 pHeader->AddActionEventListener(*this);
142 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
147 AlbumListForm::InitializeFooter(void)
149 AppLogDebug("ENTER");
150 Footer* pFooter = GetFooter();
153 AppLogDebug("EXIT 1");
157 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
159 pFooter->SetBackButton();
160 SetFormBackEventListener(this);
164 pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON);
165 pFooter->SetBackButton();
166 pFooter->RemoveAllItems();
168 FooterItem itemCamera;
169 itemCamera.Construct(IDA_FOOTER_CAMERA);
170 itemCamera.SetText(ResourceManager::GetString(L"EMPTY_SPACE"));
171 Bitmap* pBitmap1 = ResourceManager::GetBitmapN(IDB_CONTROLBAR_CAMERA);
172 if (pBitmap1 != null)
174 itemCamera.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pBitmap1);
176 pFooter->AddItem(itemCamera);
179 ButtonItem footerMore;
180 footerMore.Construct(BUTTON_ITEM_STYLE_ICON, IDA_FOOTER_MORE);
182 Bitmap* pBitmapMore = ResourceManager::GetBitmapN(IDB_CONTROLBAR_MORE);
183 Bitmap* pBitmapMoreDim = ResourceManager::GetBitmapN(IDB_CONTROLBAR_MORE_DISABLED);
184 Bitmap* pBitmapMorePressed = ResourceManager::GetBitmapN(IDB_CONTROLBAR_MORE_PRESSED);
186 if (pBitmapMore != null && pBitmapMoreDim != null && pBitmapMorePressed != null)
188 footerMore.SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapMore);
189 footerMore.SetIcon(BUTTON_ITEM_STATUS_DISABLED, pBitmapMoreDim);
190 footerMore.SetIcon(BUTTON_ITEM_STATUS_PRESSED, pBitmapMorePressed);
193 pFooter->SetButton(BUTTON_POSITION_LEFT, footerMore);
195 delete pBitmapMoreDim;
196 delete pBitmapMorePressed;
198 __pContextMenuMore = new (std::nothrow) ContextMenu();
199 __pContextMenuMore->Construct(Point(0, 0), CONTEXT_MENU_STYLE_LIST);
200 __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_COM_HEADER_EDIT"), IDA_FOOTER_EDIT);
201 __pContextMenuMore->SetShowState(false);
202 __pContextMenuMore->AddActionEventListener(*this);
204 SetFormBackEventListener(this);
206 pFooter->AddActionEventListener(*this);
207 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
213 AlbumListForm::CreateIconListView(void)
215 AppLogDebug("ENTER");
216 Dimension itemSize(W_FOLDER_SIZE, H_FOLDER_SIZE);
218 __pAlbumViewIconList = static_cast<IconListView*>(GetControl(L"IDC_ICONLISTVIEW_ALBUM_LIST"));
219 AppAssert(__pAlbumViewIconList);
221 __pAlbumViewIconList->SetItemProvider(*this);
222 __pAlbumViewIconList->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
223 __pAlbumViewIconList->AddIconListViewItemEventListener(*this);
225 Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
228 __pAlbumViewIconList->SetBitmapOfEmptyList(pBitmap);
232 __pAlbumViewIconList->SetShowState(true);
233 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
237 AlbumListForm::GetItemCount(void)
239 AppLogDebug("ENTER");
240 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
246 AlbumListForm::CreateItem(int index)
248 AppLogDebug("ENTER : index(%d)", index);
250 Bitmap* pBitmap = null;
251 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
252 if (pAlbumInfoList != null)
254 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
255 if (pAlbumInfo != null)
257 Bitmap* pAlbumBitmap = pAlbumInfo->GetFolderThumnailBitmap();
259 if (pAlbumBitmap == null)
261 __pPresentationModel->RequestThumbnail(index, 0);
264 pBitmap = __pPresentationModel->CreateMergeBitmapN(index);
268 IconListViewItem* pIconListview = new (std::nothrow) IconListViewItem();
269 pIconListview->Construct(*pBitmap);
271 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
273 return pIconListview;
277 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
283 AlbumListForm::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
285 AppLogDebug("ENTER");
286 if (status == ICON_LIST_VIEW_ITEM_SELECTED)
288 SceneManager* pSceneManager = SceneManager::GetInstance();
290 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
291 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
292 AlbumInfo* pSendAlbumInfo = new (std::nothrow) AlbumInfo();
293 pSendAlbumInfo->Construct(*pAlbumInfo);
295 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
296 pArrayList->Construct();
297 pArrayList->Add(pSendAlbumInfo);
299 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
301 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
303 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR), pArrayList);
305 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
307 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_VIDEO_LIST_EDITOR), pArrayList);
311 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR), pArrayList);
316 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST), pArrayList);
319 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
323 AlbumListForm::DeleteItem(int index, IconListViewItem* pItem)
325 AppLogDebug("ENTER");
327 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
333 AlbumListForm::OnTerminating(void)
335 AppLogDebug("ENTER");
336 __pPresentationModel->RemovePresentationModelListener(*this);
337 __pPresentationModel->RemoveContentEventListener(*this);
338 if (__pContextMenuMore != null)
340 delete __pContextMenuMore;
341 __pContextMenuMore = null;
343 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
349 AlbumListForm::OnActionPerformed(const Control& source, int actionId)
351 AppLogDebug("ENTER");
352 SceneManager* pSceneManager = SceneManager::GetInstance();
356 case IDA_FOOTER_CAMERA:
358 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
359 pDataList->Construct();
360 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_CAMERA_ALLOW_SWITCH),
361 new (std::nothrow) String(APPCONTROL_DATA_TRUE));
362 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_CAMERA,
363 APPCONTROL_OPERATION_ID_CREATE_CONTENT, null,
364 new (std::nothrow) String(APPCONTROL_MIME_IMAGE_JPG), pDataList, null);
368 case IDA_FOOTER_EDIT:
370 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST_EDITOR));
374 case IDA_FOOTER_MORE:
376 if (__pContextMenuMore->GetShowState() == false && __pPresentationModel->GetFolderCount() != 0)
378 Rectangle rect = source.GetBounds();
379 __pContextMenuMore->SetAnchorPosition(Point(rect.width/10, rect.y));
380 __pContextMenuMore->SetShowState(true);
381 __pContextMenuMore->Show();
385 __pContextMenuMore->SetShowState(false);
393 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
397 AlbumListForm::OnFormBackRequested(Form& source)
399 AppLogDebug("ENTER");
400 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
402 AppLogDebug("APP_CONTROL_MODE_PICK");
403 GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
406 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
408 pApp->SendAppControlResult(APP_CTRL_RESULT_CANCELED, null);
415 AppLogDebug("APP_CONTROL_MODE_MAIN");
416 UiApp* pApp = UiApp::GetInstance();
419 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
423 AlbumListForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
425 AppLogDebug("ENTER");
426 __pPresentationModel->AddContentEventListener(this);
428 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
430 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
432 __pPresentationModel->ClearThumbnailRequests(false);
433 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
435 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
437 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
441 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
446 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
448 __itemCount = __pPresentationModel->GetFolderCount();
450 if ( __itemCount == 0 )
452 GetFooter()->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
456 GetFooter()->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
459 if (__pAlbumViewIconList != null)
461 __pAlbumViewIconList->UpdateList();
465 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
469 AlbumListForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
471 AppLogDebug("ENTER");
472 __pPresentationModel->RemoveContentEventListener(*this);
473 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
477 AlbumListForm::OnContentUpdated(void)
479 AppLogDebug("ENTER");
481 if( __pContextMenuMore ->GetShowState() == true)
483 __pContextMenuMore->SetShowState(false);
486 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
488 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
490 __pPresentationModel->ClearThumbnailRequests(false);
491 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
493 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
495 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
499 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
504 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
507 __itemCount = __pPresentationModel->GetFolderCount();
508 __pAlbumViewIconList->UpdateList();
510 if (__itemCount == 0 )
512 GetFooter()->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
516 GetFooter()->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
519 GetFooter()->Invalidate(true);
520 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
524 AlbumListForm::OnFileInfoChanged(const ContentType contentType)
526 AppLogDebug("ENTER");
528 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
532 AlbumListForm::OnThumbnailDecoded(const int index)
534 AppLogDebug("ENTER : index(%d)", index);
535 __pAlbumViewIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
536 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
540 AlbumListForm::Update(void)
542 AppLogDebug("ENTER");
543 result r = __pAlbumViewIconList->UpdateList();
544 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));