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->AddItem(ResourceManager::GetString(L"IDS_COM_HEADER_EDIT"), IDA_FOOTER_EDIT);
222 __pOptionMenu->SetShowState(false);
223 __pOptionMenu->AddActionEventListener(*this);
224 SetFormMenuEventListener(this);
227 SetFormBackEventListener(this);
229 pFooter->AddActionEventListener(*this);
230 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
236 AlbumListForm::CreateIconListView(void)
238 AppLogDebug("ENTER");
239 Dimension itemSize(W_FOLDER_SIZE, H_FOLDER_SIZE);
241 __pAlbumViewIconList = static_cast<IconListView*>(GetControl(L"IDC_ICONLISTVIEW_ALBUM_LIST"));
242 AppAssert(__pAlbumViewIconList);
244 __pAlbumViewIconList->SetItemProvider(*this);
245 __pAlbumViewIconList->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
246 __pAlbumViewIconList->AddIconListViewItemEventListener(*this);
248 Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
251 __pAlbumViewIconList->SetBitmapOfEmptyList(pBitmap);
255 __pAlbumViewIconList->SetShowState(true);
256 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
260 AlbumListForm::GetItemCount(void)
262 AppLogDebug("ENTER");
263 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
269 AlbumListForm::CreateItem(int index)
271 AppLogDebug("ENTER : index(%d)", index);
273 Bitmap* pBitmap = null;
274 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
275 if (pAlbumInfoList != null)
277 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
278 if (pAlbumInfo != null)
280 Bitmap* pAlbumBitmap = pAlbumInfo->GetFolderThumnailBitmap();
282 if (pAlbumBitmap == null)
284 __pPresentationModel->RequestThumbnail(index, 0);
287 pBitmap = __pPresentationModel->CreateMergeBitmapN(index);
291 IconListViewItem* pIconListview = new (std::nothrow) IconListViewItem();
292 pIconListview->Construct(*pBitmap);
294 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
296 return pIconListview;
300 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
306 AlbumListForm::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
308 AppLogDebug("ENTER");
309 if (status == ICON_LIST_VIEW_ITEM_SELECTED)
311 SceneManager* pSceneManager = SceneManager::GetInstance();
313 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
314 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
315 AlbumInfo* pSendAlbumInfo = new (std::nothrow) AlbumInfo();
316 pSendAlbumInfo->Construct(*pAlbumInfo);
318 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
319 pArrayList->Construct();
320 pArrayList->Add(pSendAlbumInfo);
322 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
324 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
326 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR), pArrayList);
328 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
330 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_VIDEO_LIST_EDITOR), pArrayList);
334 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR), pArrayList);
339 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST), pArrayList);
342 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
346 AlbumListForm::DeleteItem(int index, IconListViewItem* pItem)
348 AppLogDebug("ENTER");
350 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
356 AlbumListForm::OnTerminating(void)
358 AppLogDebug("ENTER");
359 __pPresentationModel->RemovePresentationModelListener(*this);
360 __pPresentationModel->RemoveContentEventListener(*this);
361 if (__pContextMenuMore != null)
363 delete __pContextMenuMore;
364 __pContextMenuMore = null;
366 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
372 AlbumListForm::OnActionPerformed(const Control& source, int actionId)
374 AppLogDebug("ENTER");
375 SceneManager* pSceneManager = SceneManager::GetInstance();
379 case IDA_FOOTER_CAMERA:
381 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
382 pDataList->Construct();
383 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_CAMERA_ALLOW_SWITCH),
384 new (std::nothrow) String(APPCONTROL_DATA_TRUE));
385 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_CAMERA,
386 APPCONTROL_OPERATION_ID_CREATE_CONTENT, null,
387 new (std::nothrow) String(APPCONTROL_MIME_IMAGE_JPG), pDataList, null);
391 case IDA_FOOTER_EDIT:
393 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST_EDITOR));
397 case IDA_FOOTER_MORE:
399 if (__pContextMenuMore->GetShowState() == false && __pPresentationModel->GetFolderCount() != 0)
401 Rectangle rect = source.GetBounds();
402 __pContextMenuMore->SetAnchorPosition(Point(rect.width/10, rect.y));
403 __pContextMenuMore->SetShowState(true);
404 __pContextMenuMore->Show();
408 __pContextMenuMore->SetShowState(false);
416 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
420 AlbumListForm::OnFormBackRequested(Form& source)
422 AppLogDebug("ENTER");
423 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
425 AppLogDebug("APP_CONTROL_MODE_PICK");
426 GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
429 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
431 pApp->SendAppControlResult(APP_CTRL_RESULT_CANCELED, null);
438 AppLogDebug("APP_CONTROL_MODE_MAIN");
439 UiApp* pApp = UiApp::GetInstance();
442 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
446 AlbumListForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
448 AppLogDebug("ENTER");
449 __pPresentationModel->AddContentEventListener(this);
451 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
453 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
455 __pPresentationModel->ClearThumbnailRequests(false);
456 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
458 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
460 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
464 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
469 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
471 __itemCount = __pPresentationModel->GetFolderCount();
473 if ( __itemCount == 0 )
475 GetFooter()->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
479 GetFooter()->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
482 if (__pAlbumViewIconList != null)
484 __pAlbumViewIconList->UpdateList();
488 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
492 AlbumListForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
494 AppLogDebug("ENTER");
495 __pPresentationModel->RemoveContentEventListener(*this);
496 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
500 AlbumListForm::OnContentUpdated(void)
502 AppLogDebug("ENTER");
504 if(__pContextMenuMore != null && __pContextMenuMore ->GetShowState() == true)
506 __pContextMenuMore->SetShowState(false);
509 if ( __pOptionMenu != null && __pOptionMenu ->GetShowState() == true)
511 __pOptionMenu->SetShowState(false);
512 __pOptionMenu->Show();
515 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
517 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
519 __pPresentationModel->ClearThumbnailRequests(false);
520 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
522 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
524 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
528 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
533 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
536 __itemCount = __pPresentationModel->GetFolderCount();
537 __pAlbumViewIconList->UpdateList();
539 if (__itemCount == 0 )
541 GetFooter()->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
545 GetFooter()->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
548 GetFooter()->Invalidate(true);
549 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
553 AlbumListForm::OnFileInfoChanged(const ContentType contentType)
555 AppLogDebug("ENTER");
557 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
561 AlbumListForm::OnThumbnailDecoded(const int index)
563 AppLogDebug("ENTER : index(%d)", index);
564 __pAlbumViewIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
565 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
569 AlbumListForm::Update(void)
571 AppLogDebug("ENTER");
572 result r = __pAlbumViewIconList->UpdateList();
573 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
579 AlbumListForm::OnFormMenuRequested (Tizen::Ui::Controls::Form &source)
582 if ( __pOptionMenu == null )
587 __pOptionMenu->SetShowState(true);
588 __pOptionMenu->Show();