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 __pPresentationModel = AlbumListPresentationModel::GetInstance();
78 __pPresentationModel->ClearThumbnailRequests();
79 __pPresentationModel->AddPresentationModelListener(this);
81 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
83 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
85 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
87 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
89 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
93 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
98 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
101 AppLogDebug("ENTER __pPresentationModel(%x)", __pPresentationModel);
103 r = InitializeHeader();
106 AppLogDebug("[%s] Unable to set header.", GetErrorMessage(r));
109 r = InitializeFooter();
112 AppLogDebug("[%s] Unable to set footer.", GetErrorMessage(r));
115 __itemCount = __pPresentationModel->GetFolderCount();
116 CreateIconListView();
117 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
123 AlbumListForm::InitializeHeader(void)
125 AppLogDebug("ENTER");
126 Header* pHeader = GetHeader();
129 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
133 result r = pHeader->SetStyle(HEADER_STYLE_TITLE);
136 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
140 pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_GALLERY"));
141 pHeader->AddActionEventListener(*this);
143 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
148 AlbumListForm::InitializeFooter(void)
150 AppLogDebug("ENTER");
151 Footer* pFooter = GetFooter();
154 AppLogDebug("EXIT 1");
158 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
160 pFooter->SetBackButton();
161 SetFormBackEventListener(this);
165 pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON);
166 pFooter->SetBackButton();
167 pFooter->SetMenuButton();
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 = static_cast<IconListView*>(GetControl(L"IDC_ICONLISTVIEW_ALBUM_LIST"));
204 AppAssert(__pAlbumViewIconList);
206 __pAlbumViewIconList->SetItemProvider(*this);
207 __pAlbumViewIconList->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
208 __pAlbumViewIconList->AddIconListViewItemEventListener(*this);
210 Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
213 __pAlbumViewIconList->SetBitmapOfEmptyList(pBitmap);
217 __pAlbumViewIconList->SetShowState(true);
218 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
222 AlbumListForm::GetItemCount(void)
224 AppLogDebug("ENTER");
225 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
231 AlbumListForm::CreateItem(int index)
233 AppLogDebug("ENTER : index(%d)", index);
235 Bitmap* pBitmap = null;
236 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
237 if (pAlbumInfoList != null)
239 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
240 if (pAlbumInfo != null)
242 Bitmap* pAlbumBitmap = pAlbumInfo->GetFolderThumnailBitmap();
244 if (pAlbumBitmap == null)
246 __pPresentationModel->RequestThumbnail(index, 0);
249 pBitmap = __pPresentationModel->CreateMergeBitmapN(index);
253 IconListViewItem* pIconListview = new (std::nothrow) IconListViewItem();
254 pIconListview->Construct(*pBitmap);
256 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
258 return pIconListview;
262 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
268 AlbumListForm::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
270 AppLogDebug("ENTER");
271 if (status == ICON_LIST_VIEW_ITEM_SELECTED)
273 SceneManager* pSceneManager = SceneManager::GetInstance();
275 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
276 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
277 AlbumInfo* pSendAlbumInfo = new (std::nothrow) AlbumInfo();
278 pSendAlbumInfo->Construct(*pAlbumInfo);
280 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
281 pArrayList->Construct();
282 pArrayList->Add(pSendAlbumInfo);
284 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
286 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
288 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR), pArrayList);
290 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
292 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_VIDEO_LIST_EDITOR), pArrayList);
296 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR), pArrayList);
301 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST), pArrayList);
304 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
308 AlbumListForm::DeleteItem(int index, IconListViewItem* pItem)
310 AppLogDebug("ENTER");
312 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
318 AlbumListForm::OnTerminating(void)
320 AppLogDebug("ENTER");
321 __pPresentationModel->RemovePresentationModelListener(*this);
322 __pPresentationModel->RemoveContentEventListener(*this);
323 if (__pContextMenuMore != null)
325 delete __pContextMenuMore;
326 __pContextMenuMore = null;
328 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
334 AlbumListForm::OnActionPerformed(const Control& source, int actionId)
336 AppLogDebug("ENTER");
337 SceneManager* pSceneManager = SceneManager::GetInstance();
341 case IDA_FOOTER_CAMERA:
343 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
344 pDataList->Construct();
345 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_CAMERA_ALLOW_SWITCH),
346 new (std::nothrow) String(APPCONTROL_DATA_TRUE));
347 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_CAMERA,
348 APPCONTROL_OPERATION_ID_CREATE_CONTENT, null,
349 new (std::nothrow) String(APPCONTROL_MIME_IMAGE_JPG), pDataList, null);
353 case IDA_FOOTER_EDIT:
355 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST_EDITOR));
362 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
366 AlbumListForm::OnFormBackRequested(Form& source)
368 AppLogDebug("ENTER");
369 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
371 AppLogDebug("APP_CONTROL_MODE_PICK");
372 GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
375 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
377 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 ( __itemCount == 0 )
421 GetFooter()->SetMenuButtonEnabled(false);
425 GetFooter()->SetMenuButtonEnabled(true);
428 if (__pAlbumViewIconList != null)
430 __pAlbumViewIconList->UpdateList();
434 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
438 AlbumListForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
440 AppLogDebug("ENTER");
441 __pPresentationModel->RemoveContentEventListener(*this);
442 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
446 AlbumListForm::OnContentUpdated(void)
448 AppLogDebug("ENTER");
450 if ( __pOptionMenu != null && __pOptionMenu ->GetShowState() == true)
452 __pOptionMenu->SetShowState(false);
453 __pOptionMenu->Show();
456 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
458 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
460 __pPresentationModel->ClearThumbnailRequests(false);
461 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
463 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
465 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
469 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
474 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
477 __itemCount = __pPresentationModel->GetFolderCount();
478 __pAlbumViewIconList->UpdateList();
480 if (__itemCount == 0 )
482 GetFooter()->SetMenuButtonEnabled(false);
486 GetFooter()->SetMenuButtonEnabled(true);
489 GetFooter()->Invalidate(true);
490 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
494 AlbumListForm::OnFileInfoChanged(const ContentType contentType)
496 AppLogDebug("ENTER");
498 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
502 AlbumListForm::OnThumbnailDecoded(const int index)
504 AppLogDebug("ENTER : index(%d)", index);
505 __pAlbumViewIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
506 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
510 AlbumListForm::Update(void)
512 AppLogDebug("ENTER");
513 result r = __pAlbumViewIconList->UpdateList();
514 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
520 AlbumListForm::OnFormMenuRequested (Tizen::Ui::Controls::Form &source)
523 if ( __pOptionMenu == null )
528 __pOptionMenu->SetShowState(true);
529 __pOptionMenu->Show();