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)
45 : __isHWBackButtonExist(false)
47 , __pAlbumViewIconList(null)
48 , __pContextMenuMore(null)
50 , __pPresentationModel(null)
54 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
57 AlbumListForm::~AlbumListForm(void)
60 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
64 AlbumListForm::Initialize(void)
67 result r = Form::Construct(IDL_FORM_ALBUM_LIST);
68 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
74 AlbumListForm::OnInitializing(void)
78 GalleryApp* pApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
80 __isHWBackButtonExist = false;
81 __isHWBackButtonExist = pApp->IsHwKeySupported();
82 AppLogDebug("EXIT(%s)", GetErrorMessage(r));
85 __pPresentationModel = AlbumListPresentationModel::GetInstance();
86 __pPresentationModel->ClearThumbnailRequests();
87 __pPresentationModel->AddPresentationModelListener(this);
89 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
91 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
93 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
95 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
97 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
101 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
106 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
109 AppLogDebug("ENTER __pPresentationModel(%x)", __pPresentationModel);
111 r = InitializeHeader();
114 AppLogDebug("[%s] Unable to set header.", GetErrorMessage(r));
117 r = InitializeFooter();
120 AppLogDebug("[%s] Unable to set footer.", GetErrorMessage(r));
123 __itemCount = __pPresentationModel->GetFolderCount();
124 CreateIconListView();
125 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
131 AlbumListForm::InitializeHeader(void)
133 AppLogDebug("ENTER");
134 Header* pHeader = GetHeader();
137 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
141 result r = pHeader->SetStyle(HEADER_STYLE_TITLE);
144 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
148 pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_GALLERY"));
149 pHeader->AddActionEventListener(*this);
151 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
156 AlbumListForm::InitializeFooter(void)
158 AppLogDebug("ENTER");
159 Footer* pFooter = GetFooter();
162 AppLogDebug("EXIT 1");
166 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
168 pFooter->SetBackButton();
169 SetFormBackEventListener(this);
173 pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON);
174 pFooter->SetBackButton();
175 pFooter->RemoveAllItems();
177 FooterItem itemCamera;
178 itemCamera.Construct(IDA_FOOTER_CAMERA);
179 itemCamera.SetText(ResourceManager::GetString(L"EMPTY_SPACE"));
180 Bitmap* pBitmap1 = ResourceManager::GetBitmapN(IDB_CONTROLBAR_CAMERA);
181 if (pBitmap1 != null)
183 itemCamera.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pBitmap1);
185 pFooter->AddItem(itemCamera);
189 if( __isHWBackButtonExist == false )
191 ButtonItem footerMore;
192 footerMore.Construct(BUTTON_ITEM_STYLE_ICON, IDA_FOOTER_MORE);
194 Bitmap* pBitmapMore = ResourceManager::GetBitmapN(IDB_CONTROLBAR_MORE);
195 Bitmap* pBitmapMoreDim = ResourceManager::GetBitmapN(IDB_CONTROLBAR_MORE_DISABLED);
196 Bitmap* pBitmapMorePressed = ResourceManager::GetBitmapN(IDB_CONTROLBAR_MORE_PRESSED);
198 if (pBitmapMore != null && pBitmapMoreDim != null && pBitmapMorePressed != null)
200 footerMore.SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapMore);
201 footerMore.SetIcon(BUTTON_ITEM_STATUS_DISABLED, pBitmapMoreDim);
202 footerMore.SetIcon(BUTTON_ITEM_STATUS_PRESSED, pBitmapMorePressed);
205 pFooter->SetButton(BUTTON_POSITION_LEFT, footerMore);
207 delete pBitmapMoreDim;
208 delete pBitmapMorePressed;
210 __pContextMenuMore = new (std::nothrow) ContextMenu();
211 __pContextMenuMore->Construct(Point(0, 0), CONTEXT_MENU_STYLE_LIST);
212 __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_COM_HEADER_EDIT"), IDA_FOOTER_EDIT);
213 __pContextMenuMore->SetShowState(false);
214 __pContextMenuMore->AddActionEventListener(*this);
218 __pOptionMenu = new (std::nothrow) OptionMenu();
219 __pOptionMenu->Construct();
220 __pOptionMenu->AddItem(ResourceManager::GetString(L"IDS_COM_HEADER_EDIT"),IDA_FOOTER_EDIT);
221 __pOptionMenu->SetShowState(false);
222 __pOptionMenu->AddActionEventListener(*this);
223 SetFormMenuEventListener(this);
226 SetFormBackEventListener(this);
228 pFooter->AddActionEventListener(*this);
229 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
235 AlbumListForm::CreateIconListView(void)
237 AppLogDebug("ENTER");
238 Dimension itemSize(W_FOLDER_SIZE, H_FOLDER_SIZE);
240 __pAlbumViewIconList = static_cast<IconListView*>(GetControl(L"IDC_ICONLISTVIEW_ALBUM_LIST"));
241 AppAssert(__pAlbumViewIconList);
243 __pAlbumViewIconList->SetItemProvider(*this);
244 __pAlbumViewIconList->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
245 __pAlbumViewIconList->AddIconListViewItemEventListener(*this);
247 Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
250 __pAlbumViewIconList->SetBitmapOfEmptyList(pBitmap);
254 __pAlbumViewIconList->SetShowState(true);
255 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
259 AlbumListForm::GetItemCount(void)
261 AppLogDebug("ENTER");
262 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
268 AlbumListForm::CreateItem(int index)
270 AppLogDebug("ENTER : index(%d)", index);
272 Bitmap* pBitmap = null;
273 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
274 if (pAlbumInfoList != null)
276 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
277 if (pAlbumInfo != null)
279 Bitmap* pAlbumBitmap = pAlbumInfo->GetFolderThumnailBitmap();
281 if (pAlbumBitmap == null)
283 __pPresentationModel->RequestThumbnail(index, 0);
286 pBitmap = __pPresentationModel->CreateMergeBitmapN(index);
290 IconListViewItem* pIconListview = new (std::nothrow) IconListViewItem();
291 pIconListview->Construct(*pBitmap);
293 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
295 return pIconListview;
299 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
305 AlbumListForm::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
307 AppLogDebug("ENTER");
308 if (status == ICON_LIST_VIEW_ITEM_SELECTED)
310 SceneManager* pSceneManager = SceneManager::GetInstance();
312 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
313 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
314 AlbumInfo* pSendAlbumInfo = new (std::nothrow) AlbumInfo();
315 pSendAlbumInfo->Construct(*pAlbumInfo);
317 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
318 pArrayList->Construct();
319 pArrayList->Add(pSendAlbumInfo);
321 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
323 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
325 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR), pArrayList);
327 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
329 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_VIDEO_LIST_EDITOR), pArrayList);
333 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR), pArrayList);
338 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST), pArrayList);
341 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
345 AlbumListForm::DeleteItem(int index, IconListViewItem* pItem)
347 AppLogDebug("ENTER");
349 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
355 AlbumListForm::OnTerminating(void)
357 AppLogDebug("ENTER");
358 __pPresentationModel->RemovePresentationModelListener(*this);
359 __pPresentationModel->RemoveContentEventListener(*this);
360 if (__pContextMenuMore != null)
362 delete __pContextMenuMore;
363 __pContextMenuMore = null;
365 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
371 AlbumListForm::OnActionPerformed(const Control& source, int actionId)
373 AppLogDebug("ENTER");
374 SceneManager* pSceneManager = SceneManager::GetInstance();
378 case IDA_FOOTER_CAMERA:
380 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
381 pDataList->Construct();
382 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_CAMERA_ALLOW_SWITCH),
383 new (std::nothrow) String(APPCONTROL_DATA_TRUE));
384 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_CAMERA,
385 APPCONTROL_OPERATION_ID_CREATE_CONTENT, null,
386 new (std::nothrow) String(APPCONTROL_MIME_IMAGE_JPG), pDataList, null);
390 case IDA_FOOTER_EDIT:
392 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST_EDITOR));
396 case IDA_FOOTER_MORE:
398 if (__pContextMenuMore->GetShowState() == false && __pPresentationModel->GetFolderCount() != 0)
400 Rectangle rect = source.GetBounds();
401 __pContextMenuMore->SetAnchorPosition(Point(rect.width/10, rect.y));
402 __pContextMenuMore->SetShowState(true);
403 __pContextMenuMore->Show();
407 __pContextMenuMore->SetShowState(false);
415 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
419 AlbumListForm::OnFormBackRequested(Form& source)
421 AppLogDebug("ENTER");
422 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
424 AppLogDebug("APP_CONTROL_MODE_PICK");
425 GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
428 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
430 pApp->SendAppControlResult(APP_CTRL_RESULT_CANCELED, null);
437 AppLogDebug("APP_CONTROL_MODE_MAIN");
438 UiApp* pApp = UiApp::GetInstance();
441 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
445 AlbumListForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
447 AppLogDebug("ENTER");
448 __pPresentationModel->AddContentEventListener(this);
450 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
452 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
454 __pPresentationModel->ClearThumbnailRequests(false);
455 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
457 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
459 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
463 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
468 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
470 __itemCount = __pPresentationModel->GetFolderCount();
472 if ( __itemCount == 0 )
474 GetFooter()->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
478 GetFooter()->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
481 if (__pAlbumViewIconList != null)
483 __pAlbumViewIconList->UpdateList();
487 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
491 AlbumListForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
493 AppLogDebug("ENTER");
494 __pPresentationModel->RemoveContentEventListener(*this);
495 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
499 AlbumListForm::OnContentUpdated(void)
501 AppLogDebug("ENTER");
503 if(__pContextMenuMore != null && __pContextMenuMore ->GetShowState() == true)
505 __pContextMenuMore->SetShowState(false);
508 if ( __pOptionMenu != null && __pOptionMenu ->GetShowState() == true)
510 __pOptionMenu->SetShowState(false);
511 __pOptionMenu->Show();
514 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
516 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
518 __pPresentationModel->ClearThumbnailRequests(false);
519 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
521 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
523 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
527 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
532 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
535 __itemCount = __pPresentationModel->GetFolderCount();
536 __pAlbumViewIconList->UpdateList();
538 if (__itemCount == 0 )
540 GetFooter()->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
544 GetFooter()->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
547 GetFooter()->Invalidate(true);
548 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
552 AlbumListForm::OnFileInfoChanged(const ContentType contentType)
554 AppLogDebug("ENTER");
556 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
560 AlbumListForm::OnThumbnailDecoded(const int index)
562 AppLogDebug("ENTER : index(%d)", index);
563 __pAlbumViewIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
564 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
568 AlbumListForm::Update(void)
570 AppLogDebug("ENTER");
571 result r = __pAlbumViewIconList->UpdateList();
572 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
578 AlbumListForm::OnFormMenuRequested (Tizen::Ui::Controls::Form &source)
581 if ( __pOptionMenu == null )
586 __pOptionMenu->SetShowState(true);
587 __pOptionMenu->Show();