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)
47 , __pContextMenuMore(null)
48 , __pPresentationModel(null)
51 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
54 AlbumListForm::~AlbumListForm(void)
57 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
61 AlbumListForm::Initialize(void)
64 result r = Form::Construct(IDL_FORM_ALBUM_LIST);
65 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
71 AlbumListForm::OnInitializing(void)
76 __pPresentationModel = AlbumListPresentationModel::GetInstance();
77 __pPresentationModel->ClearThumbnailRequests();
78 __pPresentationModel->AddPresentationModelListener(this);
80 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
82 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
84 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
86 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
88 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
92 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
97 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
100 AppLogDebug("ENTER __pPresentationModel(%x)", __pPresentationModel);
102 r = InitializeHeader();
105 AppLogDebug("[%s] Unable to set header.", GetErrorMessage(r));
108 r = InitializeFooter();
111 AppLogDebug("[%s] Unable to set footer.", GetErrorMessage(r));
114 __itemCount = __pPresentationModel->GetFolderCount();
115 CreateIconListView();
116 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
122 AlbumListForm::InitializeHeader(void)
124 AppLogDebug("ENTER");
125 Header* pHeader = GetHeader();
128 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
132 result r = pHeader->SetStyle(HEADER_STYLE_TITLE);
135 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
139 pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_GALLERY"));
140 pHeader->AddActionEventListener(*this);
142 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
147 AlbumListForm::InitializeFooter(void)
149 AppLogDebug("ENTER");
150 Footer* pFooter = GetFooter();
153 AppLogDebug("EXIT 1");
157 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
159 pFooter->SetBackButton();
160 SetFormBackEventListener(this);
164 pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON);
165 pFooter->SetBackButton();
166 pFooter->RemoveAllItems();
168 FooterItem itemCamera;
169 itemCamera.Construct(IDA_FOOTER_CAMERA);
170 itemCamera.SetText(ResourceManager::GetString(L"EMPTY_SPACE"));
171 Bitmap* pBitmap1 = ResourceManager::GetBitmapN(IDB_CONTROLBAR_CAMERA);
172 if (pBitmap1 != null)
174 itemCamera.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pBitmap1);
176 pFooter->AddItem(itemCamera);
179 ButtonItem footerMore;
180 footerMore.Construct(BUTTON_ITEM_STYLE_ICON, IDA_FOOTER_MORE);
181 Bitmap* pBitmapMore = ResourceManager::GetBitmapN(IDB_CONTROLBAR_MORE);
182 if (pBitmapMore != null)
184 footerMore.SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapMore);
186 pFooter->SetButton(BUTTON_POSITION_LEFT,footerMore);
189 __pContextMenuMore = new (std::nothrow) ContextMenu();
190 __pContextMenuMore->Construct(Point(0, 0), CONTEXT_MENU_STYLE_LIST);
191 __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_COM_HEADER_EDIT"), IDA_FOOTER_EDIT);
192 __pContextMenuMore->SetShowState(false);
193 __pContextMenuMore->AddActionEventListener(*this);
195 SetFormBackEventListener(this);
197 pFooter->AddActionEventListener(*this);
198 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
204 AlbumListForm::CreateIconListView(void)
206 AppLogDebug("ENTER");
207 Dimension itemSize(W_FOLDER_SIZE, H_FOLDER_SIZE);
209 __pAlbumViewIconList = static_cast<IconListView*>(GetControl(L"IDC_ICONLISTVIEW_ALBUM_LIST"));
210 AppAssert(__pAlbumViewIconList);
212 __pAlbumViewIconList->SetItemProvider(*this);
213 __pAlbumViewIconList->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
214 __pAlbumViewIconList->AddIconListViewItemEventListener(*this);
216 Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
219 __pAlbumViewIconList->SetBitmapOfEmptyList(pBitmap);
223 __pAlbumViewIconList->SetShowState(true);
224 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
228 AlbumListForm::GetItemCount(void)
230 AppLogDebug("ENTER");
231 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
237 AlbumListForm::CreateItem(int index)
239 AppLogDebug("ENTER : index(%d)", index);
241 Bitmap* pBitmap = null;
242 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
243 if (pAlbumInfoList != null)
245 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
246 if (pAlbumInfo != null)
248 Bitmap* pAlbumBitmap = pAlbumInfo->GetFolderThumnailBitmap();
250 if (pAlbumBitmap == null)
252 __pPresentationModel->RequestThumbnail(index, 0);
255 pBitmap = __pPresentationModel->CreateMergeBitmapN(index);
259 IconListViewItem* pIconListview = new (std::nothrow) IconListViewItem();
260 pIconListview->Construct(*pBitmap);
262 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
264 return pIconListview;
268 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
274 AlbumListForm::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
276 AppLogDebug("ENTER");
277 if (status == ICON_LIST_VIEW_ITEM_SELECTED)
279 SceneManager* pSceneManager = SceneManager::GetInstance();
281 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
282 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
283 AlbumInfo* pSendAlbumInfo = new (std::nothrow) AlbumInfo();
284 pSendAlbumInfo->Construct(*pAlbumInfo);
286 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
287 pArrayList->Construct();
288 pArrayList->Add(pSendAlbumInfo);
290 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
292 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
294 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR), pArrayList);
296 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
298 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_VIDEO_LIST_EDITOR), pArrayList);
302 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR), pArrayList);
307 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST), pArrayList);
310 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
314 AlbumListForm::DeleteItem(int index, IconListViewItem* pItem)
316 AppLogDebug("ENTER");
318 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
324 AlbumListForm::OnTerminating(void)
326 AppLogDebug("ENTER");
327 __pPresentationModel->RemovePresentationModelListener(*this);
328 __pPresentationModel->RemoveContentEventListener(*this);
329 if (__pContextMenuMore != null)
331 delete __pContextMenuMore;
332 __pContextMenuMore = null;
334 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
340 AlbumListForm::OnActionPerformed(const Control& source, int actionId)
342 AppLogDebug("ENTER");
343 SceneManager* pSceneManager = SceneManager::GetInstance();
347 case IDA_FOOTER_CAMERA:
349 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
350 pDataList->Construct();
351 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_CAMERA_ALLOW_SWITCH),
352 new (std::nothrow) String(APPCONTROL_DATA_TRUE));
353 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_CAMERA,
354 APPCONTROL_OPERATION_ID_CREATE_CONTENT, null,
355 new (std::nothrow) String(APPCONTROL_MIME_IMAGE_JPG), pDataList, null);
359 case IDA_FOOTER_EDIT:
361 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST_EDITOR));
365 case IDA_FOOTER_MORE:
367 if (__pContextMenuMore->GetShowState() == false && __pPresentationModel->GetFolderCount() != 0)
369 Rectangle rect = source.GetBounds();
370 __pContextMenuMore->SetAnchorPosition(Point(rect.width/10, rect.y));
371 __pContextMenuMore->SetShowState(true);
372 __pContextMenuMore->Show();
376 __pContextMenuMore->SetShowState(false);
384 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
388 AlbumListForm::OnFormBackRequested(Form& source)
390 AppLogDebug("ENTER");
391 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
393 AppLogDebug("APP_CONTROL_MODE_PICK");
394 GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
397 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
399 pApp->SendAppControlResult(APP_CTRL_RESULT_CANCELED, null);
406 AppLogDebug("APP_CONTROL_MODE_MAIN");
407 UiApp* pApp = UiApp::GetInstance();
410 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
414 AlbumListForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
416 AppLogDebug("ENTER");
417 __pPresentationModel->AddContentEventListener(this);
419 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
421 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
423 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
425 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
427 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
431 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
436 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
438 __itemCount = __pPresentationModel->GetFolderCount();
440 if (__pAlbumViewIconList != null)
442 __pAlbumViewIconList->UpdateList();
446 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
450 AlbumListForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
452 AppLogDebug("ENTER");
453 __pPresentationModel->RemoveContentEventListener(*this);
454 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
458 AlbumListForm::OnContentUpdated(void)
460 AppLogDebug("ENTER");
462 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
464 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
466 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
468 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
470 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
474 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
479 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
482 __itemCount = __pPresentationModel->GetFolderCount();
483 __pAlbumViewIconList->UpdateList();
484 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
488 AlbumListForm::OnFileInfoChanged(const ContentType contentType)
490 AppLogDebug("ENTER");
492 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
496 AlbumListForm::OnThumbnailDecoded(const int index)
498 AppLogDebug("ENTER : index(%d)", index);
499 __pAlbumViewIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
500 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
504 AlbumListForm::Update(void)
506 AppLogDebug("ENTER");
507 result r = __pAlbumViewIconList->UpdateList();
508 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));