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 SetFormBackEventListener(this);
164 pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON);
165 pFooter->RemoveAllItems();
167 FooterItem itemCamera;
168 itemCamera.Construct(IDA_FOOTER_CAMERA);
169 itemCamera.SetText(ResourceManager::GetString(L"EMPTY_SPACE"));
170 Bitmap* pBitmap1 = ResourceManager::GetBitmapN(IDB_CONTROLBAR_CAMERA);
171 if (pBitmap1 != null)
173 itemCamera.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pBitmap1);
175 pFooter->AddItem(itemCamera);
178 __pOptionMenu = new (std::nothrow) OptionMenu();
179 __pOptionMenu->Construct();
180 __pOptionMenu->AddItem(ResourceManager::GetString(L"IDS_COM_HEADER_EDIT"),IDA_FOOTER_EDIT);
181 __pOptionMenu->AddItem(ResourceManager::GetString(L"IDS_COM_HEADER_EDIT"), IDA_FOOTER_EDIT);
182 __pOptionMenu->SetShowState(false);
183 __pOptionMenu->AddActionEventListener(*this);
184 SetFormMenuEventListener(this);
185 SetFormBackEventListener(this);
188 pFooter->AddActionEventListener(*this);
189 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
195 AlbumListForm::CreateIconListView(void)
197 AppLogDebug("ENTER");
198 Dimension itemSize(W_FOLDER_SIZE, H_FOLDER_SIZE);
200 __pAlbumViewIconList = static_cast<IconListView*>(GetControl(L"IDC_ICONLISTVIEW_ALBUM_LIST"));
201 AppAssert(__pAlbumViewIconList);
203 __pAlbumViewIconList->SetItemProvider(*this);
204 __pAlbumViewIconList->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
205 __pAlbumViewIconList->AddIconListViewItemEventListener(*this);
207 Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
210 __pAlbumViewIconList->SetBitmapOfEmptyList(pBitmap);
214 __pAlbumViewIconList->SetShowState(true);
215 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
219 AlbumListForm::GetItemCount(void)
221 AppLogDebug("ENTER");
222 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
228 AlbumListForm::CreateItem(int index)
230 AppLogDebug("ENTER : index(%d)", index);
232 Bitmap* pBitmap = null;
233 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
234 if (pAlbumInfoList != null)
236 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
237 if (pAlbumInfo != null)
239 Bitmap* pAlbumBitmap = pAlbumInfo->GetFolderThumnailBitmap();
241 if (pAlbumBitmap == null)
243 __pPresentationModel->RequestThumbnail(index, 0);
246 pBitmap = __pPresentationModel->CreateMergeBitmapN(index);
250 IconListViewItem* pIconListview = new (std::nothrow) IconListViewItem();
251 pIconListview->Construct(*pBitmap);
253 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
255 return pIconListview;
259 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
265 AlbumListForm::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
267 AppLogDebug("ENTER");
268 if (status == ICON_LIST_VIEW_ITEM_SELECTED)
270 SceneManager* pSceneManager = SceneManager::GetInstance();
272 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
273 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
274 AlbumInfo* pSendAlbumInfo = new (std::nothrow) AlbumInfo();
275 pSendAlbumInfo->Construct(*pAlbumInfo);
277 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
278 pArrayList->Construct();
279 pArrayList->Add(pSendAlbumInfo);
281 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
283 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
285 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR), pArrayList);
287 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
289 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_VIDEO_LIST_EDITOR), pArrayList);
293 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR), pArrayList);
298 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST), pArrayList);
301 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
305 AlbumListForm::DeleteItem(int index, IconListViewItem* pItem)
307 AppLogDebug("ENTER");
309 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
315 AlbumListForm::OnTerminating(void)
317 AppLogDebug("ENTER");
318 __pPresentationModel->RemovePresentationModelListener(*this);
319 __pPresentationModel->RemoveContentEventListener(*this);
320 if (__pContextMenuMore != null)
322 delete __pContextMenuMore;
323 __pContextMenuMore = null;
325 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
331 AlbumListForm::OnActionPerformed(const Control& source, int actionId)
333 AppLogDebug("ENTER");
334 SceneManager* pSceneManager = SceneManager::GetInstance();
338 case IDA_FOOTER_CAMERA:
340 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
341 pDataList->Construct();
342 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_CAMERA_ALLOW_SWITCH),
343 new (std::nothrow) String(APPCONTROL_DATA_TRUE));
344 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_CAMERA,
345 APPCONTROL_OPERATION_ID_CREATE_CONTENT, null,
346 new (std::nothrow) String(APPCONTROL_MIME_IMAGE_JPG), pDataList, null);
350 case IDA_FOOTER_EDIT:
352 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST_EDITOR));
359 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
363 AlbumListForm::OnFormBackRequested(Form& source)
365 AppLogDebug("ENTER");
366 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
368 AppLogDebug("APP_CONTROL_MODE_PICK");
369 GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
372 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
374 pApp->SendAppControlResult(APP_CTRL_RESULT_CANCELED, null);
381 AppLogDebug("APP_CONTROL_MODE_MAIN");
382 UiApp* pApp = UiApp::GetInstance();
385 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
389 AlbumListForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
391 AppLogDebug("ENTER");
392 __pPresentationModel->AddContentEventListener(this);
394 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
396 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
398 __pPresentationModel->ClearThumbnailRequests(false);
399 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
401 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
403 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
407 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
412 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
414 __itemCount = __pPresentationModel->GetFolderCount();
416 if (__pAlbumViewIconList != null)
418 __pAlbumViewIconList->UpdateList();
422 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
426 AlbumListForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
428 AppLogDebug("ENTER");
429 __pPresentationModel->RemoveContentEventListener(*this);
430 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
434 AlbumListForm::OnContentUpdated(void)
436 AppLogDebug("ENTER");
438 if ( __pOptionMenu != null && __pOptionMenu ->GetShowState() == true)
440 __pOptionMenu->SetShowState(false);
441 __pOptionMenu->Show();
444 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
446 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
448 __pPresentationModel->ClearThumbnailRequests(false);
449 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
451 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
453 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
457 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
462 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
465 __itemCount = __pPresentationModel->GetFolderCount();
466 __pAlbumViewIconList->UpdateList();
468 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
472 AlbumListForm::OnFileInfoChanged(const ContentType contentType)
474 AppLogDebug("ENTER");
476 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
480 AlbumListForm::OnThumbnailDecoded(const int index)
482 AppLogDebug("ENTER : index(%d)", index);
483 __pAlbumViewIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
484 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
488 AlbumListForm::Update(void)
490 AppLogDebug("ENTER");
491 result r = __pAlbumViewIconList->UpdateList();
492 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
498 AlbumListForm::OnFormMenuRequested (Tizen::Ui::Controls::Form &source)
501 if ( __pOptionMenu == null )
506 __pOptionMenu->SetShowState(true);
507 __pOptionMenu->Show();