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