2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (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.
23 #include "GlAlbumInfo.h"
24 #include "GlAlbumListForm.h"
25 #include "GlAlbumListPresentationModel.h"
26 #include "GlGalleryApp.h"
27 #include "GlResourceManager.h"
29 using namespace Tizen::App;
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Base::Runtime;
33 using namespace Tizen::Content;
34 using namespace Tizen::Graphics;
35 using namespace Tizen::Io;
36 using namespace Tizen::Media;
37 using namespace Tizen::System;
38 using namespace Tizen::Ui;
39 using namespace Tizen::Ui::Controls;
40 using namespace Tizen::Ui::Scenes;
42 static const int W_FOLDER_SIZE = 348;
43 static const int H_FOLDER_SIZE = 348;
45 AlbumListForm::AlbumListForm(void)
46 : __pAlbumViewIconList(null)
47 , __pContextMenuMore(null)
49 , __pPresentationModel(null)
53 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
56 AlbumListForm::~AlbumListForm(void)
59 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
63 AlbumListForm::Initialize(void)
66 result r = Form::Construct(IDL_FORM_ALBUM_LIST);
67 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
73 AlbumListForm::OnInitializing(void)
78 __pPresentationModel = AlbumListPresentationModel::GetInstance();
79 __pPresentationModel->ClearThumbnailRequests();
80 __pPresentationModel->AddPresentationModelListener(this);
82 if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
84 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
86 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
88 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
90 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
94 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
99 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
102 AppLogDebug("ENTER __pPresentationModel(%x)", __pPresentationModel);
104 r = InitializeHeader();
107 AppLogDebug("[%s] Unable to set header.", GetErrorMessage(r));
110 r = InitializeFooter();
113 AppLogDebug("[%s] Unable to set footer.", GetErrorMessage(r));
116 __itemCount = __pPresentationModel->GetFolderCount();
117 CreateIconListView();
118 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
124 AlbumListForm::InitializeHeader(void)
126 AppLogDebug("ENTER");
127 Header* pHeader = GetHeader();
130 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
135 result r = pHeader->SetStyle(HEADER_STYLE_TITLE);
138 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");
162 if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
164 pFooter->SetBackButton();
165 SetFormBackEventListener(this);
169 pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON);
170 pFooter->SetBackButton();
171 pFooter->RemoveAllItems();
173 FooterItem itemCamera;
174 itemCamera.Construct(ACTION_ID_FOOTER_CAMERA);
175 itemCamera.SetText(ResourceManager::GetString(L"EMPTY_SPACE"));
176 Bitmap* pBitmap1 = ResourceManager::GetBitmapN(IDB_CONTROLBAR_CAMERA);
177 if (pBitmap1 != null)
179 itemCamera.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pBitmap1);
181 pFooter->AddItem(itemCamera);
184 ButtonItem footerMore;
185 footerMore.Construct(BUTTON_ITEM_STYLE_ICON, ACTION_ID_FOOTER_MORE);
186 Bitmap* pBitmapMore = ResourceManager::GetBitmapN(IDB_CONTROLBAR_MORE);
187 if (pBitmapMore != null)
189 footerMore.SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapMore);
191 pFooter->SetButton(BUTTON_POSITION_LEFT,footerMore);
194 __pContextMenuMore = new (std::nothrow) ContextMenu();
195 __pContextMenuMore->Construct(Point(0, 0), CONTEXT_MENU_STYLE_LIST);
196 __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_COM_HEADER_EDIT"), ACTION_ID_FOOTER_EDIT);
197 __pContextMenuMore->SetShowState(false);
198 __pContextMenuMore->AddActionEventListener(*this);
200 SetFormBackEventListener(this);
202 pFooter->AddActionEventListener(*this);
203 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
209 AlbumListForm::CreateIconListView(void)
211 AppLogDebug("ENTER");
212 Dimension itemSize(W_FOLDER_SIZE, H_FOLDER_SIZE);
214 __pAlbumViewIconList = static_cast< IconListView* >(GetControl(L"IDC_ICONLISTVIEW_ALBUM_LIST"));
215 AppAssert(__pAlbumViewIconList);
217 __pAlbumViewIconList->SetItemProvider(*this);
218 __pAlbumViewIconList->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
219 __pAlbumViewIconList->AddIconListViewItemEventListener(*this);
221 Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
224 __pAlbumViewIconList->SetBitmapOfEmptyList(pBitmap);
228 __pAlbumViewIconList->SetShowState(true);
229 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
233 AlbumListForm::GetItemCount(void)
235 AppLogDebug("ENTER");
236 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
242 AlbumListForm::CreateItem(int index)
244 AppLogDebug("ENTER : index(%d)", index);
246 Bitmap* pBitmap = null;
247 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
248 if (pAlbumInfoList != null)
250 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
251 if (pAlbumInfo != null)
253 Bitmap* pAlbumBitmap = pAlbumInfo->GetFolderThumnailBitmap();
255 if (pAlbumBitmap == null)
257 __pPresentationModel->RequestThumbnail(index, 0);
260 pBitmap = __pPresentationModel->CreateMergeBitmapN(index);
264 IconListViewItem* pIconListview = new (std::nothrow) IconListViewItem();
265 pIconListview->Construct(*pBitmap);
267 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
269 return pIconListview;
273 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
279 AlbumListForm::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
281 AppLogDebug("ENTER");
282 if (status == ICON_LIST_VIEW_ITEM_SELECTED)
284 SceneManager* pSceneManager = SceneManager::GetInstance();
286 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
287 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
288 AlbumInfo* pSendAlbumInfo = new (std::nothrow) AlbumInfo();
289 pSendAlbumInfo->Construct(*pAlbumInfo);
291 ArrayList* aList = new (std::nothrow) ArrayList(SingleObjectDeleter);
293 aList->Add(pSendAlbumInfo);
295 if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
297 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
299 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR), aList);
301 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
303 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_VIDEO_LIST_EDITOR), aList);
307 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR), aList);
312 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST), aList);
315 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
319 AlbumListForm::DeleteItem(int index, IconListViewItem* pItem)
321 AppLogDebug("ENTER");
323 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
329 AlbumListForm::OnTerminating(void)
331 AppLogDebug("ENTER");
332 __pPresentationModel->RemovePresentationModelListener(*this);
334 if (__pContextMenuMore != null)
336 delete __pContextMenuMore;
337 __pContextMenuMore = null;
339 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
345 AlbumListForm::OnActionPerformed(const Control& source, int actionId)
347 AppLogDebug("ENTER");
348 SceneManager* pSceneManager = SceneManager::GetInstance();
352 case ACTION_ID_FOOTER_CAMERA:
354 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
355 pDataList->Construct();
356 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE),
357 new (std::nothrow) String(APPCONTROL_DATA_CAMERA));
359 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_CAMERA,
360 APPCONTROL_OPERATION_ID_CAPTURE, pDataList, null);
363 case ACTION_ID_FOOTER_EDIT:
365 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST_EDITOR));
368 case ACTION_ID_FOOTER_MORE:
370 if (__pContextMenuMore->GetShowState() == false && __pPresentationModel->GetFolderCount() != 0)
372 Rectangle rect = source.GetBounds();
373 __pContextMenuMore->SetAnchorPosition(Point(rect.width/8, rect.y));
374 __pContextMenuMore->SetShowState(true);
375 __pContextMenuMore->Show();
379 __pContextMenuMore->SetShowState(false);
388 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
392 AlbumListForm::OnFormBackRequested(Form& source)
394 AppLogDebug("ENTER");
395 if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
397 AppLogDebug("APP_CONTROL_MODE_PICK");
398 GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
401 if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
403 pApp->SendAppControlResult(APP_CTRL_RESULT_CANCELED, null);
410 AppLogDebug("APP_CONTROL_MODE_MAIN");
411 UiApp* pApp = UiApp::GetInstance();
414 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
418 AlbumListForm::OnSceneActivatedN(const SceneId& previousSceneId,
419 const SceneId& currentSceneId, IList* pArgs)
421 AppLogDebug("ENTER");
423 if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
425 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
427 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
429 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
431 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
435 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
440 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
442 __itemCount = __pPresentationModel->GetFolderCount();
444 if (__pAlbumViewIconList != null)
446 __pAlbumViewIconList->UpdateList();
450 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
454 AlbumListForm::OnSceneDeactivated(const SceneId& currentSceneId,
455 const SceneId& nextSceneId)
457 AppLogDebug("ENTER");
458 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
462 AlbumListForm::OnUpdateContentList()
464 AppLogDebug("ENTER");
466 if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
468 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
470 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
472 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
474 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
478 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
483 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
486 __itemCount = __pPresentationModel->GetFolderCount();
487 __pAlbumViewIconList->UpdateList();
488 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
492 AlbumListForm::OnFileInfoChanged(const ContentType contentType)
494 AppLogDebug("ENTER");
496 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
500 AlbumListForm::OnThumbnailDecoded(const int index)
502 AppLogDebug("ENTER : index(%d)", index);
503 __pAlbumViewIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
504 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
508 AlbumListForm::Update(void)
510 AppLogDebug("ENTER");
511 result r = __pAlbumViewIconList->UpdateList();
512 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));