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 const String mimeType = APPCONTROL_MIME_IMAGE_JPG;
347 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
348 pDataList->Construct();
349 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_CAMERA_ALLOW_SWITCH),
350 new (std::nothrow) String(APPCONTROL_DATA_TRUE));
351 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_CAMERA,
352 APPCONTROL_OPERATION_ID_CREATE_CONTENT, null, &mimeType, pDataList, this);
357 case IDA_FOOTER_EDIT:
359 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST_EDITOR));
366 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
370 AlbumListForm::OnFormBackRequested(Form& source)
372 AppLogDebug("ENTER");
373 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
375 GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
376 if (pApp != null && pApp->GetFrameActivated() == true)
378 pApp->SendAppControlResult(APP_CTRL_RESULT_CANCELED, null);
384 AppLogDebug("APP_CONTROL_MODE_MAIN");
385 UiApp* pApp = UiApp::GetInstance();
388 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
392 AlbumListForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
394 AppLogDebug("ENTER");
395 __pPresentationModel->AddContentEventListener(this);
397 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
399 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
401 __pPresentationModel->ClearThumbnailRequests(false);
402 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
404 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
406 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
410 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
415 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
417 __itemCount = __pPresentationModel->GetFolderCount();
419 if (__pAlbumViewIconList != null)
421 __pAlbumViewIconList->UpdateList();
425 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
429 AlbumListForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
431 AppLogDebug("ENTER");
432 __pPresentationModel->RemoveContentEventListener(*this);
433 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
437 AlbumListForm::OnContentUpdated(void)
439 AppLogDebug("ENTER");
441 if (__pOptionMenu != null && __pOptionMenu ->GetShowState() == true)
443 __pOptionMenu->SetShowState(false);
444 __pOptionMenu->Show();
447 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
449 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
451 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
453 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
455 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
459 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
464 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
467 __itemCount = __pPresentationModel->GetFolderCount();
468 __pAlbumViewIconList->UpdateList();
470 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
474 AlbumListForm::OnFileInfoChanged(const ContentType contentType)
476 AppLogDebug("ENTER");
478 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
482 AlbumListForm::OnThumbnailDecoded(const int index)
484 AppLogDebug("ENTER : index(%d)", index);
485 __pAlbumViewIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
486 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
490 AlbumListForm::OnAppControlCompleteResponseReceived(const AppId& appId, const Tizen::Base::String& operationId,
491 AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pExtraData)
493 AppLogDebug("OnAppControlCompleteResponseReceived : %d", appControlResult);
495 GalleryApp* pGalleryApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
496 TryReturnVoid(pGalleryApp != null, "pGalleryApp is null");
497 pGalleryApp->SetFrameEnabled(true);
501 AlbumListForm::Update(void)
503 AppLogDebug("ENTER");
504 result r = __pAlbumViewIconList->UpdateList();
505 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
511 AlbumListForm::OnFormMenuRequested (Tizen::Ui::Controls::Form &source)
514 if (__pOptionMenu == null || GetItemCount() == 0)
519 __pOptionMenu->SetShowState(true);
520 __pOptionMenu->Show();
524 AlbumListForm::OnOrientationChanged(const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
526 if (__pAlbumViewIconList != null)
528 RemoveControl(__pAlbumViewIconList);
531 __pAlbumViewIconList = new IconListView();
533 if (orientationStatus == ORIENTATION_STATUS_PORTRAIT)
535 __pAlbumViewIconList->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height),
536 Dimension(W_FOLDER_SIZE, H_FOLDER_SIZE), ICON_LIST_VIEW_STYLE_NORMAL, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
538 else if (orientationStatus == ORIENTATION_STATUS_LANDSCAPE || orientationStatus == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
540 int horizontalSpacing = 8;
541 int verticalSpacing = 60;
545 __pAlbumViewIconList->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height),
546 Dimension(width, height), ICON_LIST_VIEW_STYLE_NORMAL, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
548 __pAlbumViewIconList->SetItemSpacing(horizontalSpacing, verticalSpacing);
549 __pAlbumViewIconList->SetMargin(MARGIN_TYPE_TOP,60);
552 Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
556 __pAlbumViewIconList->SetBitmapOfEmptyList(pBitmap);
560 __pAlbumViewIconList->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
562 __pAlbumViewIconList->SetItemProvider(*this);
563 __pAlbumViewIconList->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
564 __pAlbumViewIconList->AddIconListViewItemEventListener(*this);
566 AddControl(__pAlbumViewIconList);