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 GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
375 if (pApp != null && pApp->GetFrameActivated() == true)
377 pApp->SendAppControlResult(APP_CTRL_RESULT_CANCELED, null);
383 AppLogDebug("APP_CONTROL_MODE_MAIN");
384 UiApp* pApp = UiApp::GetInstance();
387 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
391 AlbumListForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
393 AppLogDebug("ENTER");
394 __pPresentationModel->AddContentEventListener(this);
396 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
398 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
400 __pPresentationModel->ClearThumbnailRequests(false);
401 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
403 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
405 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
409 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
414 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
416 __itemCount = __pPresentationModel->GetFolderCount();
418 if (__pAlbumViewIconList != null)
420 __pAlbumViewIconList->UpdateList();
424 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
428 AlbumListForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
430 AppLogDebug("ENTER");
431 __pPresentationModel->RemoveContentEventListener(*this);
432 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
436 AlbumListForm::OnContentUpdated(void)
438 AppLogDebug("ENTER");
440 if (__pOptionMenu != null && __pOptionMenu ->GetShowState() == true)
442 __pOptionMenu->SetShowState(false);
443 __pOptionMenu->Show();
446 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
448 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
450 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
452 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
454 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
458 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
463 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
466 __itemCount = __pPresentationModel->GetFolderCount();
467 __pAlbumViewIconList->UpdateList();
469 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
473 AlbumListForm::OnFileInfoChanged(const ContentType contentType)
475 AppLogDebug("ENTER");
477 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
481 AlbumListForm::OnThumbnailDecoded(const int index)
483 AppLogDebug("ENTER : index(%d)", index);
484 __pAlbumViewIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
485 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
489 AlbumListForm::OnAppControlCompleteResponseReceived(const AppId& appId, const Tizen::Base::String& operationId,
490 AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pExtraData)
492 AppLogDebug("OnAppControlCompleteResponseReceived : %d", appControlResult);
494 GalleryApp* pGalleryApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
495 TryReturnVoid(pGalleryApp != null, "pGalleryApp is null");
496 pGalleryApp->SetFrameEnabled(true);
500 AlbumListForm::Update(void)
502 AppLogDebug("ENTER");
503 result r = __pAlbumViewIconList->UpdateList();
504 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
510 AlbumListForm::OnFormMenuRequested (Tizen::Ui::Controls::Form &source)
513 if (__pOptionMenu == null || GetItemCount() == 0)
518 __pOptionMenu->SetShowState(true);
519 __pOptionMenu->Show();
523 AlbumListForm::OnOrientationChanged(const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
525 if (__pAlbumViewIconList != null)
527 RemoveControl(__pAlbumViewIconList);
530 __pAlbumViewIconList = new IconListView();
532 if (orientationStatus == ORIENTATION_STATUS_PORTRAIT)
534 __pAlbumViewIconList->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height),
535 Dimension(W_FOLDER_SIZE, H_FOLDER_SIZE), ICON_LIST_VIEW_STYLE_NORMAL, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
537 else if (orientationStatus == ORIENTATION_STATUS_LANDSCAPE || orientationStatus == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
539 int horizontalSpacing = 8;
540 int verticalSpacing = 60;
544 __pAlbumViewIconList->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height),
545 Dimension(width, height), ICON_LIST_VIEW_STYLE_NORMAL, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
547 __pAlbumViewIconList->SetItemSpacing(horizontalSpacing, verticalSpacing);
548 __pAlbumViewIconList->SetMargin(MARGIN_TYPE_TOP,60);
551 Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
555 __pAlbumViewIconList->SetBitmapOfEmptyList(pBitmap);
559 __pAlbumViewIconList->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
561 __pAlbumViewIconList->SetItemProvider(*this);
562 __pAlbumViewIconList->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
563 __pAlbumViewIconList->AddIconListViewItemEventListener(*this);
565 AddControl(__pAlbumViewIconList);