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);
167 pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON);
168 pFooter->RemoveAllItems();
170 FooterItem itemCamera;
171 itemCamera.Construct(IDA_FOOTER_CAMERA);
172 itemCamera.SetText(ResourceManager::GetString(L"EMPTY_SPACE"));
173 Bitmap* pBitmap1 = ResourceManager::GetBitmapN(IDB_CONTROLBAR_CAMERA);
174 if (pBitmap1 != null)
176 itemCamera.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pBitmap1);
178 pFooter->AddItem(itemCamera);
181 __pOptionMenu = new (std::nothrow) OptionMenu();
182 __pOptionMenu->Construct();
183 __pOptionMenu->AddItem(ResourceManager::GetString(L"IDS_COM_HEADER_EDIT"),IDA_FOOTER_EDIT);
184 __pOptionMenu->AddItem(ResourceManager::GetString(L"IDS_COM_HEADER_EDIT"), IDA_FOOTER_EDIT);
185 __pOptionMenu->SetShowState(false);
186 __pOptionMenu->AddActionEventListener(*this);
187 SetFormMenuEventListener(this);
188 SetFormBackEventListener(this);
191 pFooter->AddActionEventListener(*this);
192 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
198 AlbumListForm::CreateIconListView(void)
200 AppLogDebug("ENTER");
201 Dimension itemSize(W_FOLDER_SIZE, H_FOLDER_SIZE);
203 __pAlbumViewIconList = new IconListView();
204 __pAlbumViewIconList->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height),
205 Dimension(W_FOLDER_SIZE, H_FOLDER_SIZE), ICON_LIST_VIEW_STYLE_NORMAL, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
206 __pAlbumViewIconList->SetItemProvider(*this);
207 __pAlbumViewIconList->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
208 __pAlbumViewIconList->AddIconListViewItemEventListener(*this);
212 Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
216 __pAlbumViewIconList->SetBitmapOfEmptyList(pBitmap);
219 __pAlbumViewIconList->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
221 AddControl(*__pAlbumViewIconList);
223 __pAlbumViewIconList->SetShowState(true);
224 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
228 AlbumListForm::GetItemCount(void)
230 AppLogDebug("ENTER");
231 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
237 AlbumListForm::CreateItem(int index)
239 AppLogDebug("ENTER : index(%d)", index);
241 Bitmap* pBitmap = null;
242 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
243 if (pAlbumInfoList != null)
245 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
246 if (pAlbumInfo != null)
248 Bitmap* pAlbumBitmap = pAlbumInfo->GetFolderThumnailBitmap();
250 if (pAlbumBitmap == null)
252 __pPresentationModel->RequestThumbnail(index, 0);
255 pBitmap = __pPresentationModel->CreateMergeBitmapN(index);
259 IconListViewItem* pIconListview = new (std::nothrow) IconListViewItem();
260 pIconListview->Construct(*pBitmap);
262 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
264 return pIconListview;
268 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
274 AlbumListForm::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
276 AppLogDebug("ENTER");
277 if (status == ICON_LIST_VIEW_ITEM_SELECTED)
279 SceneManager* pSceneManager = SceneManager::GetInstance();
281 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
282 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
283 AlbumInfo* pSendAlbumInfo = new (std::nothrow) AlbumInfo();
284 pSendAlbumInfo->Construct(*pAlbumInfo);
286 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
287 pArrayList->Construct();
288 pArrayList->Add(pSendAlbumInfo);
290 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
292 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
294 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR), pArrayList);
296 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
298 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_VIDEO_LIST_EDITOR), pArrayList);
302 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR), pArrayList);
307 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST), pArrayList);
310 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
314 AlbumListForm::DeleteItem(int index, IconListViewItem* pItem)
316 AppLogDebug("ENTER");
318 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
324 AlbumListForm::OnTerminating(void)
326 AppLogDebug("ENTER");
327 __pPresentationModel->RemovePresentationModelListener(*this);
328 __pPresentationModel->RemoveContentEventListener(*this);
329 if (__pContextMenuMore != null)
331 delete __pContextMenuMore;
332 __pContextMenuMore = null;
334 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
340 AlbumListForm::OnActionPerformed(const Control& source, int actionId)
342 AppLogDebug("ENTER");
343 SceneManager* pSceneManager = SceneManager::GetInstance();
347 case IDA_FOOTER_CAMERA:
349 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
350 pDataList->Construct();
351 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_CAMERA_ALLOW_SWITCH),
352 new (std::nothrow) String(APPCONTROL_DATA_TRUE));
353 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_CAMERA,
354 APPCONTROL_OPERATION_ID_CREATE_CONTENT, null,
355 new (std::nothrow) String(APPCONTROL_MIME_IMAGE_JPG), pDataList, null);
359 case IDA_FOOTER_EDIT:
361 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST_EDITOR));
368 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
372 AlbumListForm::OnFormBackRequested(Form& source)
374 AppLogDebug("ENTER");
375 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
377 AppLogDebug("APP_CONTROL_MODE_PICK");
378 GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
381 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
383 pApp->SendAppControlResult(APP_CTRL_RESULT_CANCELED, null);
390 AppLogDebug("APP_CONTROL_MODE_MAIN");
391 UiApp* pApp = UiApp::GetInstance();
394 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
398 AlbumListForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
400 AppLogDebug("ENTER");
401 __pPresentationModel->AddContentEventListener(this);
403 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
405 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
407 __pPresentationModel->ClearThumbnailRequests(false);
408 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
410 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
412 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
416 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
421 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
423 __itemCount = __pPresentationModel->GetFolderCount();
425 if (__pAlbumViewIconList != null)
427 __pAlbumViewIconList->UpdateList();
431 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
435 AlbumListForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
437 AppLogDebug("ENTER");
438 __pPresentationModel->RemoveContentEventListener(*this);
439 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
443 AlbumListForm::OnContentUpdated(void)
445 AppLogDebug("ENTER");
447 if ( __pOptionMenu != null && __pOptionMenu ->GetShowState() == true)
449 __pOptionMenu->SetShowState(false);
450 __pOptionMenu->Show();
453 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
455 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
457 __pPresentationModel->ClearThumbnailRequests(false);
458 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
460 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
462 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
466 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
471 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
474 __itemCount = __pPresentationModel->GetFolderCount();
475 __pAlbumViewIconList->UpdateList();
477 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
481 AlbumListForm::OnFileInfoChanged(const ContentType contentType)
483 AppLogDebug("ENTER");
485 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
489 AlbumListForm::OnThumbnailDecoded(const int index)
491 AppLogDebug("ENTER : index(%d)", index);
492 __pAlbumViewIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
493 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
497 AlbumListForm::Update(void)
499 AppLogDebug("ENTER");
500 result r = __pAlbumViewIconList->UpdateList();
501 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
507 AlbumListForm::OnFormMenuRequested (Tizen::Ui::Controls::Form &source)
510 if ( __pOptionMenu == null )
515 __pOptionMenu->SetShowState(true);
516 __pOptionMenu->Show();
521 AlbumListForm::OnOrientationChanged(const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
524 if( __pAlbumViewIconList != null )
526 RemoveControl(__pAlbumViewIconList);
529 __pAlbumViewIconList = new IconListView();
531 if( orientationStatus == ORIENTATION_STATUS_PORTRAIT )
533 __pAlbumViewIconList->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height),
534 Dimension(W_FOLDER_SIZE, H_FOLDER_SIZE), ICON_LIST_VIEW_STYLE_NORMAL, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
536 else if (orientationStatus == ORIENTATION_STATUS_LANDSCAPE || orientationStatus == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
538 int horizontalSpacing = 8;
539 int verticalSpacing = 60;
543 __pAlbumViewIconList->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height),
544 Dimension(width, height), ICON_LIST_VIEW_STYLE_NORMAL, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
546 __pAlbumViewIconList->SetItemSpacing(horizontalSpacing, verticalSpacing);
547 __pAlbumViewIconList->SetMargin(MARGIN_TYPE_TOP,60);
550 Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
554 __pAlbumViewIconList->SetBitmapOfEmptyList(pBitmap);
558 __pAlbumViewIconList->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
560 __pAlbumViewIconList->SetItemProvider(*this);
561 __pAlbumViewIconList->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
562 __pAlbumViewIconList->AddIconListViewItemEventListener(*this);
564 AddControl(*__pAlbumViewIconList);