Change select all in AlbumListEditor
[apps/osp/Gallery.git] / src / GlAlbumListForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 /**
18  * @file                GlAlbumListForm.cpp
19  * @brief               This is the implementation file for AlbumListForm class.
20  */
21
22 #include <FApp.h>
23 #include "GlAlbumInfo.h"
24 #include "GlAlbumListForm.h"
25 #include "GlAlbumListPresentationModel.h"
26 #include "GlGalleryApp.h"
27 #include "GlResourceManager.h"
28
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;
41
42 static const int W_FOLDER_SIZE = 334;
43 static const int H_FOLDER_SIZE = 334;
44
45 AlbumListForm::AlbumListForm(void)
46         : __pAlbumViewIconList(null)
47         , __pContextMenuMore(null)
48         , __itemCount(0)
49         , __pPresentationModel(null)
50 {
51         AppLogDebug("ENTER");
52         __overlayMsg = false;
53         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
54 }
55
56 AlbumListForm::~AlbumListForm(void)
57 {
58         AppLogDebug("ENTER");
59         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
60 }
61
62 result
63 AlbumListForm::Initialize(void)
64 {
65         AppLogDebug("ENTER");
66         result r = Form::Construct(IDL_FORM_ALBUM_LIST);
67         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
68
69         return r;
70 }
71
72 result
73 AlbumListForm::OnInitializing(void)
74 {
75         AppLogDebug("ENTER");
76         result r = E_SUCCESS;
77
78         __pPresentationModel = AlbumListPresentationModel::GetInstance();
79         __pPresentationModel->ClearThumbnailRequests();
80         __pPresentationModel->AddPresentationModelListener(this);
81
82         if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
83         {
84                 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
85                 {
86                         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
87                 }
88                 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
89                 {
90                         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
91                 }
92                 else
93                 {
94                         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
95                 }
96         }
97         else
98         {
99                 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
100         }
101
102         AppLogDebug("ENTER __pPresentationModel(%x)", __pPresentationModel);
103
104         r = InitializeHeader();
105         if (r != E_SUCCESS)
106         {
107                 AppLogDebug("[%s] Unable to set header.", GetErrorMessage(r));
108         }
109
110         r = InitializeFooter();
111         if (r != E_SUCCESS)
112         {
113                 AppLogDebug("[%s] Unable to set footer.", GetErrorMessage(r));
114         }
115
116         __itemCount = __pPresentationModel->GetFolderCount();
117         CreateIconListView();
118         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
119
120         return r;
121 }
122
123 result
124 AlbumListForm::InitializeHeader(void)
125 {
126         AppLogDebug("ENTER");
127         Header* pHeader = GetHeader();
128         if (pHeader == null)
129         {
130                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
131
132                 return E_SYSTEM;
133         }
134
135         result r = pHeader->SetStyle(HEADER_STYLE_TITLE);
136         if (r != E_SUCCESS)
137         {
138                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
139
140                 return r;
141         }
142
143         pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_GALLERY"));
144         pHeader->AddActionEventListener(*this);
145
146         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
147         return E_SUCCESS;
148 }
149
150 result
151 AlbumListForm::InitializeFooter(void)
152 {
153         AppLogDebug("ENTER");
154         Footer* pFooter = GetFooter();
155         if (pFooter == null)
156         {
157                 AppLogDebug("EXIT 1");
158
159                 return E_SYSTEM;
160         }
161
162         if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
163         {
164                 pFooter->SetBackButton();
165                 SetFormBackEventListener(this);
166         }
167         else
168         {
169                 pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON);
170                 pFooter->SetBackButton();
171                 pFooter->RemoveAllItems();
172
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)
178                 {
179                         itemCamera.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pBitmap1);
180                 }
181                 pFooter->AddItem(itemCamera);
182                 delete pBitmap1;
183                 pBitmap1 = null;
184
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)
189                 {
190                         footerMore.SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapMore);
191                 }
192                 pFooter->SetButton(BUTTON_POSITION_LEFT,footerMore);
193                 delete pBitmapMore;
194
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);
200
201                 SetFormBackEventListener(this);
202         }
203         pFooter->AddActionEventListener(*this);
204         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
205
206         return E_SUCCESS;
207 }
208
209 void
210 AlbumListForm::CreateIconListView(void)
211 {
212         AppLogDebug("ENTER");
213         Dimension itemSize(W_FOLDER_SIZE, H_FOLDER_SIZE);
214
215         __pAlbumViewIconList = static_cast< IconListView* >(GetControl(L"IDC_ICONLISTVIEW_ALBUM_LIST"));
216         AppAssert(__pAlbumViewIconList);
217
218         __pAlbumViewIconList->SetItemProvider(*this);
219         __pAlbumViewIconList->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
220         __pAlbumViewIconList->AddIconListViewItemEventListener(*this);
221
222         Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
223         if (pBitmap != null)
224         {
225                 __pAlbumViewIconList->SetBitmapOfEmptyList(pBitmap);
226                 delete pBitmap;
227         }
228
229         __pAlbumViewIconList->SetShowState(true);
230         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
231 }
232
233 int
234 AlbumListForm::GetItemCount(void)
235 {
236         AppLogDebug("ENTER");
237         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
238
239         return  __itemCount;
240 }
241
242 IconListViewItem*
243 AlbumListForm::CreateItem(int index)
244 {
245         AppLogDebug("ENTER : index(%d)", index);
246
247         Bitmap* pBitmap = null;
248         IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
249         if (pAlbumInfoList != null)
250         {
251                 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
252                 if (pAlbumInfo != null)
253                 {
254                         Bitmap* pAlbumBitmap = pAlbumInfo->GetFolderThumnailBitmap();
255
256                         if (pAlbumBitmap == null)
257                         {
258                                 __pPresentationModel->RequestThumbnail(index, 0);
259                         }
260
261                         pBitmap = __pPresentationModel->CreateMergeBitmapN(index);
262
263                         if (pBitmap != null)
264                         {
265                                 IconListViewItem* pIconListview = new (std::nothrow) IconListViewItem();
266                                 pIconListview->Construct(*pBitmap);
267                                 delete pBitmap;
268                                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
269
270                                 return pIconListview;
271                         }
272                 }
273         }
274         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
275
276         return null;
277 }
278
279 void
280 AlbumListForm::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
281 {
282         AppLogDebug("ENTER");
283         if (status == ICON_LIST_VIEW_ITEM_SELECTED)
284         {
285                 SceneManager* pSceneManager = SceneManager::GetInstance();
286
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);
291
292                 ArrayList* aList = new (std::nothrow) ArrayList(SingleObjectDeleter);
293                 aList->Construct();
294                 aList->Add(pSendAlbumInfo);
295
296                 if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
297                 {
298                         if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
299                         {
300                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR), aList);
301                         }
302                         else if  (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
303                         {
304                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_VIDEO_LIST_EDITOR), aList);
305                         }
306                         else
307                         {
308                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR), aList);
309                         }
310                 }
311                 else
312                 {
313                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST), aList);
314                 }
315         }
316         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
317 }
318
319 bool
320 AlbumListForm::DeleteItem(int index, IconListViewItem* pItem)
321 {
322         AppLogDebug("ENTER");
323         delete pItem;
324         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
325
326         return true;
327 }
328
329 result
330 AlbumListForm::OnTerminating(void)
331 {
332         AppLogDebug("ENTER");
333         __pPresentationModel->RemovePresentationModelListener(*this);
334
335         if (__pContextMenuMore != null)
336         {
337                 delete __pContextMenuMore;
338                 __pContextMenuMore = null;
339         }
340         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
341
342         return E_SUCCESS;
343 }
344
345 void
346 AlbumListForm::OnActionPerformed(const Control& source, int actionId)
347 {
348         AppLogDebug("ENTER");
349         SceneManager* pSceneManager = SceneManager::GetInstance();
350
351         switch (actionId)
352         {
353         case ACTION_ID_FOOTER_CAMERA:
354                 {
355                         HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
356                         pDataList->Construct();
357                         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE),
358                                         new (std::nothrow) String(APPCONTROL_DATA_CAMERA));
359
360                         __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_CAMERA,
361                                         APPCONTROL_OPERATION_ID_CAPTURE, pDataList, null);
362                 }
363                 break;
364         case ACTION_ID_FOOTER_EDIT:
365                 {
366                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST_EDITOR));
367                 }
368                 break;
369         case ACTION_ID_FOOTER_MORE:
370                 {
371                         if (__pContextMenuMore->GetShowState() == false && __pPresentationModel->GetFolderCount() != 0)
372                         {
373                                 Rectangle rect = source.GetBounds();
374                                 __pContextMenuMore->SetAnchorPosition(Point(rect.width/8, rect.y));
375                                 __pContextMenuMore->SetShowState(true);
376                                 __pContextMenuMore->Show();
377                         }
378                         else
379                         {
380                                 __pContextMenuMore->SetShowState(false);
381                         }
382                 }
383                 break;
384         default:
385                 {
386                 }
387                 break;
388         }
389         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
390 }
391
392 void
393 AlbumListForm::OnFormBackRequested(Form& source)
394 {
395         AppLogDebug("ENTER");
396         if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
397         {
398                 AppLogDebug("APP_CONTROL_MODE_PICK");
399                 GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
400                 if (pApp != null)
401                 {
402                         if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
403                         {
404                                 pApp->SendAppControlResult(APP_CTRL_RESULT_CANCELED, null);
405                         }
406                         pApp->Terminate();
407                 }
408         }
409         else
410         {
411                 AppLogDebug("APP_CONTROL_MODE_MAIN");
412                 UiApp* pApp = UiApp::GetInstance();
413                 pApp->Terminate();
414         }
415         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
416 }
417
418 void
419 AlbumListForm::OnSceneActivatedN(const SceneId& previousSceneId,
420                                                                                   const SceneId& currentSceneId, IList* pArgs)
421 {
422         AppLogDebug("ENTER");
423
424         if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
425         {
426                 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
427                 {
428                         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
429                 }
430                 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
431                 {
432                         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
433                 }
434                 else
435                 {
436                         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
437                 }
438         }
439         else
440         {
441                 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
442         }
443         __itemCount = __pPresentationModel->GetFolderCount();
444
445         if (__pAlbumViewIconList != null)
446         {
447                 __pAlbumViewIconList->UpdateList();
448         }
449         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
450 }
451
452 void
453 AlbumListForm::OnSceneDeactivated(const SceneId& currentSceneId,
454                                                                                    const SceneId& nextSceneId)
455 {
456         AppLogDebug("ENTER");
457         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
458 }
459
460 void
461 AlbumListForm::OnUpdateContentList()
462 {
463         AppLogDebug("ENTER");
464
465         if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
466         {
467                 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
468                 {
469                         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
470                 }
471                 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
472                 {
473                         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
474                 }
475                 else
476                 {
477                         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
478                 }
479         }
480         else
481         {
482                 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
483         }
484
485         __itemCount = __pPresentationModel->GetFolderCount();
486         __pAlbumViewIconList->UpdateList();
487         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
488 }
489
490 void
491 AlbumListForm::OnFileInfoChanged(const ContentType contentType)
492 {
493         AppLogDebug("ENTER");
494         Update();
495         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
496 }
497
498 void
499 AlbumListForm::OnThumbnailDecoded(const int index)
500 {
501         AppLogDebug("ENTER : index(%d)", index);
502         __pAlbumViewIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
503         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
504 }
505
506 result
507 AlbumListForm::Update(void)
508 {
509         AppLogDebug("ENTER");
510         result r = __pAlbumViewIconList->UpdateList();
511         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
512
513         return r;
514 }