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)
48 , __pPresentationModel(null)
52 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
55 AlbumListForm::~AlbumListForm(void)
58 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
62 AlbumListForm::Initialize(void)
65 result r = Form::Construct(IDL_FORM_ALBUM_LIST);
66 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
72 AlbumListForm::OnInitializing(void)
77 SetOrientation(ORIENTATION_AUTOMATIC);
78 AddOrientationEventListener(*this);
80 __pPresentationModel = AlbumListPresentationModel::GetInstance();
81 __pPresentationModel->ClearThumbnailRequests();
82 __pPresentationModel->AddPresentationModelListener(this);
84 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
86 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
88 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
90 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
92 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
96 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
101 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
104 AppLogDebug("ENTER __pPresentationModel(%x)", __pPresentationModel);
106 r = InitializeHeader();
109 AppLogDebug("[%s] Unable to set header.", GetErrorMessage(r));
112 r = InitializeFooter();
115 AppLogDebug("[%s] Unable to set footer.", GetErrorMessage(r));
118 __itemCount = __pPresentationModel->GetFolderCount();
119 CreateIconListView();
120 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
126 AlbumListForm::InitializeHeader(void)
128 AppLogDebug("ENTER");
129 Header* pHeader = GetHeader();
132 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
136 result r = pHeader->SetStyle(HEADER_STYLE_TITLE);
139 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
143 pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_GALLERY"));
144 pHeader->AddActionEventListener(*this);
146 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
151 AlbumListForm::InitializeFooter(void)
153 AppLogDebug("ENTER");
154 Footer* pFooter = GetFooter();
157 AppLogDebug("EXIT 1");
161 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
163 SetFormBackEventListener(this);
164 pFooter->SetShowState(false);
168 pFooter->SetShowState(true);
169 pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON);
170 pFooter->RemoveAllItems();
172 FooterItem itemCamera;
173 itemCamera.Construct(IDA_FOOTER_CAMERA);
174 itemCamera.SetText(ResourceManager::GetString(L"EMPTY_SPACE"));
175 Bitmap* pBitmap1 = ResourceManager::GetBitmapN(IDB_CONTROLBAR_CAMERA);
176 if (pBitmap1 != null)
178 itemCamera.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pBitmap1);
180 pFooter->AddItem(itemCamera);
183 __pOptionMenu = new (std::nothrow) OptionMenu();
184 __pOptionMenu->Construct();
185 __pOptionMenu->AddItem(ResourceManager::GetString(L"IDS_COM_HEADER_EDIT"),IDA_FOOTER_EDIT);
186 __pOptionMenu->AddItem(ResourceManager::GetString(L"IDS_COM_HEADER_EDIT"), IDA_FOOTER_EDIT);
187 __pOptionMenu->SetShowState(false);
188 __pOptionMenu->AddActionEventListener(*this);
189 SetFormMenuEventListener(this);
190 SetFormBackEventListener(this);
193 pFooter->AddActionEventListener(*this);
194 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
200 AlbumListForm::CreateIconListView(void)
202 AppLogDebug("ENTER");
203 Dimension itemSize(W_FOLDER_SIZE, H_FOLDER_SIZE);
205 __pAlbumViewIconList = new IconListView();
206 __pAlbumViewIconList->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height),
207 Dimension(W_FOLDER_SIZE, H_FOLDER_SIZE), ICON_LIST_VIEW_STYLE_NORMAL, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
208 __pAlbumViewIconList->SetItemProvider(*this);
209 __pAlbumViewIconList->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
210 __pAlbumViewIconList->AddIconListViewItemEventListener(*this);
214 Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
218 __pAlbumViewIconList->SetBitmapOfEmptyList(pBitmap);
221 __pAlbumViewIconList->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
223 AddControl(__pAlbumViewIconList);
225 __pAlbumViewIconList->SetShowState(true);
226 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
230 AlbumListForm::GetItemCount(void)
232 AppLogDebug("ENTER");
233 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
239 AlbumListForm::CreateItem(int index)
241 AppLogDebug("ENTER : index(%d)", index);
243 Bitmap* pBitmap = null;
244 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
245 if (pAlbumInfoList != null)
247 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
248 if (pAlbumInfo != null)
250 Bitmap* pAlbumBitmap = pAlbumInfo->GetFolderThumnailBitmap();
252 if (pAlbumBitmap == null)
254 __pPresentationModel->RequestThumbnail(index, 0);
257 pBitmap = __pPresentationModel->CreateMergeBitmapN(index);
261 IconListViewItem* pIconListview = new (std::nothrow) IconListViewItem();
262 pIconListview->Construct(*pBitmap);
264 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
266 return pIconListview;
270 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
276 AlbumListForm::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
278 AppLogDebug("ENTER");
279 if (status == ICON_LIST_VIEW_ITEM_SELECTED)
281 SceneManager* pSceneManager = SceneManager::GetInstance();
283 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
284 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
285 AlbumInfo* pSendAlbumInfo = new (std::nothrow) AlbumInfo();
286 pSendAlbumInfo->Construct(*pAlbumInfo);
288 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
289 pArrayList->Construct();
290 pArrayList->Add(pSendAlbumInfo);
292 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
294 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
296 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR), pArrayList);
298 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
300 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_VIDEO_LIST_EDITOR), pArrayList);
304 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR), pArrayList);
309 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST), pArrayList);
312 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
316 AlbumListForm::DeleteItem(int index, IconListViewItem* pItem)
318 AppLogDebug("ENTER");
320 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
326 AlbumListForm::OnTerminating(void)
328 AppLogDebug("ENTER");
329 __pPresentationModel->RemovePresentationModelListener(*this);
330 __pPresentationModel->RemoveContentEventListener(*this);
331 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
337 AlbumListForm::OnActionPerformed(const Control& source, int actionId)
339 AppLogDebug("ENTER");
340 SceneManager* pSceneManager = SceneManager::GetInstance();
344 case IDA_FOOTER_CAMERA:
346 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
347 pDataList->Construct();
348 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_CAMERA_ALLOW_SWITCH),
349 new (std::nothrow) String(APPCONTROL_DATA_TRUE));
350 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_CAMERA,
351 APPCONTROL_OPERATION_ID_CREATE_CONTENT, null,
352 new (std::nothrow) String(APPCONTROL_MIME_IMAGE_JPG), pDataList, this);
356 case IDA_FOOTER_EDIT:
358 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST_EDITOR));
365 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
369 AlbumListForm::OnFormBackRequested(Form& source)
371 AppLogDebug("ENTER");
372 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
374 AppLogDebug("APP_CONTROL_MODE_PICK");
375 GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
376 if (pApp != null && pApp->GetFrameActivated() == true)
378 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
380 pApp->SendAppControlResult(APP_CTRL_RESULT_CANCELED, null);
387 AppLogDebug("APP_CONTROL_MODE_MAIN");
388 UiApp* pApp = UiApp::GetInstance();
391 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
395 AlbumListForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
397 AppLogDebug("ENTER");
398 __pPresentationModel->AddContentEventListener(this);
400 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
402 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
404 __pPresentationModel->ClearThumbnailRequests(false);
405 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
407 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
409 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
413 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
418 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
420 __itemCount = __pPresentationModel->GetFolderCount();
422 if (__pAlbumViewIconList != null)
424 __pAlbumViewIconList->UpdateList();
428 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
432 AlbumListForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
434 AppLogDebug("ENTER");
435 __pPresentationModel->RemoveContentEventListener(*this);
436 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
440 AlbumListForm::OnContentUpdated(void)
442 AppLogDebug("ENTER");
444 if (__pOptionMenu != null && __pOptionMenu ->GetShowState() == true)
446 __pOptionMenu->SetShowState(false);
447 __pOptionMenu->Show();
450 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
452 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
454 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
456 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
458 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
462 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
467 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
470 __itemCount = __pPresentationModel->GetFolderCount();
471 __pAlbumViewIconList->UpdateList();
473 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
477 AlbumListForm::OnFileInfoChanged(const ContentType contentType)
479 AppLogDebug("ENTER");
481 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
485 AlbumListForm::OnThumbnailDecoded(const int index)
487 AppLogDebug("ENTER : index(%d)", index);
488 __pAlbumViewIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
489 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
493 AlbumListForm::OnAppControlCompleteResponseReceived(const AppId& appId, const Tizen::Base::String& operationId,
494 AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pExtraData)
496 AppLogDebug("OnAppControlCompleteResponseReceived : %d", appControlResult);
498 GalleryApp* pGalleryApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
499 TryReturnVoid(pGalleryApp != null, "pGalleryApp is null");
500 pGalleryApp->SetFrameEnabled(true);
504 AlbumListForm::Update(void)
506 AppLogDebug("ENTER");
507 result r = __pAlbumViewIconList->UpdateList();
508 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
514 AlbumListForm::OnFormMenuRequested (Tizen::Ui::Controls::Form &source)
517 if (__pOptionMenu == null || GetItemCount() == 0)
522 __pOptionMenu->SetShowState(true);
523 __pOptionMenu->Show();
527 AlbumListForm::OnOrientationChanged(const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
529 if (__pAlbumViewIconList != null)
531 RemoveControl(__pAlbumViewIconList);
534 __pAlbumViewIconList = new IconListView();
536 if (orientationStatus == ORIENTATION_STATUS_PORTRAIT)
538 __pAlbumViewIconList->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height),
539 Dimension(W_FOLDER_SIZE, H_FOLDER_SIZE), ICON_LIST_VIEW_STYLE_NORMAL, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
541 else if (orientationStatus == ORIENTATION_STATUS_LANDSCAPE || orientationStatus == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
543 int horizontalSpacing = 8;
544 int verticalSpacing = 60;
548 __pAlbumViewIconList->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height),
549 Dimension(width, height), ICON_LIST_VIEW_STYLE_NORMAL, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
551 __pAlbumViewIconList->SetItemSpacing(horizontalSpacing, verticalSpacing);
552 __pAlbumViewIconList->SetMargin(MARGIN_TYPE_TOP,60);
555 Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
559 __pAlbumViewIconList->SetBitmapOfEmptyList(pBitmap);
563 __pAlbumViewIconList->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
565 __pAlbumViewIconList->SetItemProvider(*this);
566 __pAlbumViewIconList->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
567 __pAlbumViewIconList->AddIconListViewItemEventListener(*this);
569 AddControl(__pAlbumViewIconList);