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);
81 __pPresentationModel->AddContentEventListener(this);
83 if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
85 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
87 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
89 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
91 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
95 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
100 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
103 AppLogDebug("ENTER __pPresentationModel(%x)", __pPresentationModel);
105 r = InitializeHeader();
108 AppLogDebug("[%s] Unable to set header.", GetErrorMessage(r));
111 r = InitializeFooter();
114 AppLogDebug("[%s] Unable to set footer.", GetErrorMessage(r));
117 __itemCount = __pPresentationModel->GetFolderCount();
118 CreateIconListView();
119 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
125 AlbumListForm::InitializeHeader(void)
127 AppLogDebug("ENTER");
128 Header* pHeader = GetHeader();
131 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
136 result r = pHeader->SetStyle(HEADER_STYLE_TITLE);
139 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
144 pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_GALLERY"));
145 pHeader->AddActionEventListener(*this);
147 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
152 AlbumListForm::InitializeFooter(void)
154 AppLogDebug("ENTER");
155 Footer* pFooter = GetFooter();
158 AppLogDebug("EXIT 1");
163 if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
165 pFooter->SetBackButton();
166 SetFormBackEventListener(this);
170 pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON);
171 pFooter->SetBackButton();
172 pFooter->RemoveAllItems();
174 FooterItem itemCamera;
175 itemCamera.Construct(ACTION_ID_FOOTER_CAMERA);
176 itemCamera.SetText(ResourceManager::GetString(L"EMPTY_SPACE"));
177 Bitmap* pBitmap1 = ResourceManager::GetBitmapN(IDB_CONTROLBAR_CAMERA);
178 if (pBitmap1 != null)
180 itemCamera.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pBitmap1);
182 pFooter->AddItem(itemCamera);
185 ButtonItem footerMore;
186 footerMore.Construct(BUTTON_ITEM_STYLE_ICON, ACTION_ID_FOOTER_MORE);
187 Bitmap* pBitmapMore = ResourceManager::GetBitmapN(IDB_CONTROLBAR_MORE);
188 if (pBitmapMore != null)
190 footerMore.SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapMore);
192 pFooter->SetButton(BUTTON_POSITION_LEFT,footerMore);
195 __pContextMenuMore = new (std::nothrow) ContextMenu();
196 __pContextMenuMore->Construct(Point(0, 0), CONTEXT_MENU_STYLE_LIST);
197 __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_COM_HEADER_EDIT"), ACTION_ID_FOOTER_EDIT);
198 __pContextMenuMore->SetShowState(false);
199 __pContextMenuMore->AddActionEventListener(*this);
201 SetFormBackEventListener(this);
203 pFooter->AddActionEventListener(*this);
204 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
210 AlbumListForm::CreateIconListView(void)
212 AppLogDebug("ENTER");
213 Dimension itemSize(W_FOLDER_SIZE, H_FOLDER_SIZE);
215 __pAlbumViewIconList = static_cast< IconListView* >(GetControl(L"IDC_ICONLISTVIEW_ALBUM_LIST"));
216 AppAssert(__pAlbumViewIconList);
218 __pAlbumViewIconList->SetItemProvider(*this);
219 __pAlbumViewIconList->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
220 __pAlbumViewIconList->AddIconListViewItemEventListener(*this);
222 Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
225 __pAlbumViewIconList->SetBitmapOfEmptyList(pBitmap);
229 __pAlbumViewIconList->SetShowState(true);
230 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
234 AlbumListForm::GetItemCount(void)
236 AppLogDebug("ENTER");
237 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
243 AlbumListForm::CreateItem(int index)
245 AppLogDebug("ENTER : index(%d)", index);
247 Bitmap* pBitmap = null;
248 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
249 if (pAlbumInfoList != null)
251 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
252 if (pAlbumInfo != null)
254 Bitmap* pAlbumBitmap = pAlbumInfo->GetFolderThumnailBitmap();
256 if (pAlbumBitmap == null)
258 __pPresentationModel->RequestThumbnail(index, 0);
261 pBitmap = __pPresentationModel->CreateMergeBitmapN(index);
265 IconListViewItem* pIconListview = new (std::nothrow) IconListViewItem();
266 pIconListview->Construct(*pBitmap);
268 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
270 return pIconListview;
274 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
280 AlbumListForm::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
282 AppLogDebug("ENTER");
283 if (status == ICON_LIST_VIEW_ITEM_SELECTED)
285 SceneManager* pSceneManager = SceneManager::GetInstance();
287 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
288 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
289 AlbumInfo* pSendAlbumInfo = new (std::nothrow) AlbumInfo();
290 pSendAlbumInfo->Construct(*pAlbumInfo);
292 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
293 pArrayList->Construct();
294 pArrayList->Add(pSendAlbumInfo);
296 if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
298 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
300 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR), pArrayList);
302 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
304 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_VIDEO_LIST_EDITOR), pArrayList);
308 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR), pArrayList);
313 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST), pArrayList);
316 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
320 AlbumListForm::DeleteItem(int index, IconListViewItem* pItem)
322 AppLogDebug("ENTER");
324 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
330 AlbumListForm::OnTerminating(void)
332 AppLogDebug("ENTER");
333 __pPresentationModel->RemovePresentationModelListener(*this);
334 __pPresentationModel->RemoveContentEventListener(*this);
336 if (__pContextMenuMore != null)
338 delete __pContextMenuMore;
339 __pContextMenuMore = null;
341 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
347 AlbumListForm::OnActionPerformed(const Control& source, int actionId)
349 AppLogDebug("ENTER");
350 SceneManager* pSceneManager = SceneManager::GetInstance();
354 case ACTION_ID_FOOTER_CAMERA:
356 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
357 pDataList->Construct();
358 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_CAMERA_ALLOW_SWITCH),
359 new (std::nothrow) String(APPCONTROL_DATA_TRUE));
361 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_CAMERA,
362 APPCONTROL_OPERATION_ID_CREATE_CONTENT, new (std::nothrow) String(APPCONTROL_MIME_IMAGE_JPG),
366 case ACTION_ID_FOOTER_EDIT:
368 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST_EDITOR));
371 case ACTION_ID_FOOTER_MORE:
373 if (__pContextMenuMore->GetShowState() == false && __pPresentationModel->GetFolderCount() != 0)
375 Rectangle rect = source.GetBounds();
376 __pContextMenuMore->SetAnchorPosition(Point(rect.width/8, rect.y));
377 __pContextMenuMore->SetShowState(true);
378 __pContextMenuMore->Show();
382 __pContextMenuMore->SetShowState(false);
391 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
395 AlbumListForm::OnFormBackRequested(Form& source)
397 AppLogDebug("ENTER");
398 if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
400 AppLogDebug("APP_CONTROL_MODE_PICK");
401 GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
404 if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
406 pApp->SendAppControlResult(APP_CTRL_RESULT_CANCELED, null);
413 AppLogDebug("APP_CONTROL_MODE_MAIN");
414 UiApp* pApp = UiApp::GetInstance();
417 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
421 AlbumListForm::OnSceneActivatedN(const SceneId& previousSceneId,
422 const SceneId& currentSceneId, IList* pArgs)
424 AppLogDebug("ENTER");
426 if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
428 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
430 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
432 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
434 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
438 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
443 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
445 __itemCount = __pPresentationModel->GetFolderCount();
447 if (__pAlbumViewIconList != null)
449 __pAlbumViewIconList->UpdateList();
453 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
457 AlbumListForm::OnSceneDeactivated(const SceneId& currentSceneId,
458 const SceneId& nextSceneId)
460 AppLogDebug("ENTER");
461 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
465 AlbumListForm::OnContentUpdated()
467 AppLogDebug("ENTER");
469 if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
471 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
473 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
475 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
477 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
481 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
486 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
489 __itemCount = __pPresentationModel->GetFolderCount();
490 __pAlbumViewIconList->UpdateList();
491 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
495 AlbumListForm::OnFileInfoChanged(const ContentType contentType)
497 AppLogDebug("ENTER");
499 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
503 AlbumListForm::OnThumbnailDecoded(const int index)
505 AppLogDebug("ENTER : index(%d)", index);
506 __pAlbumViewIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
507 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
511 AlbumListForm::Update(void)
513 AppLogDebug("ENTER");
514 result r = __pAlbumViewIconList->UpdateList();
515 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));