Hid the footer in AlbumList when launched as appControl
[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         SetOrientation(ORIENTATION_AUTOMATIC);
78         AddOrientationEventListener(*this);
79
80         __pPresentationModel = AlbumListPresentationModel::GetInstance();
81         __pPresentationModel->ClearThumbnailRequests();
82         __pPresentationModel->AddPresentationModelListener(this);
83
84         if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
85         {
86                 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
87                 {
88                         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
89                 }
90                 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
91                 {
92                         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
93                 }
94                 else
95                 {
96                         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
97                 }
98         }
99         else
100         {
101                 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
102         }
103
104         AppLogDebug("ENTER __pPresentationModel(%x)", __pPresentationModel);
105
106         r = InitializeHeader();
107         if (r != E_SUCCESS)
108         {
109                 AppLogDebug("[%s] Unable to set header.", GetErrorMessage(r));
110         }
111
112         r = InitializeFooter();
113         if (r != E_SUCCESS)
114         {
115                 AppLogDebug("[%s] Unable to set footer.", GetErrorMessage(r));
116         }
117
118         __itemCount = __pPresentationModel->GetFolderCount();
119         CreateIconListView();
120         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
121
122         return r;
123 }
124
125 result
126 AlbumListForm::InitializeHeader(void)
127 {
128         AppLogDebug("ENTER");
129         Header* pHeader = GetHeader();
130         if (pHeader == null)
131         {
132                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
133                 return E_SYSTEM;
134         }
135
136         result r = pHeader->SetStyle(HEADER_STYLE_TITLE);
137         if (r != E_SUCCESS)
138         {
139                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
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                 return E_SYSTEM;
159         }
160
161         if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
162         {
163                 SetFormBackEventListener(this);
164                 pFooter->SetShowState(false);
165         }
166         else
167         {
168                 pFooter->SetShowState(true);
169                 pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON);
170                 pFooter->RemoveAllItems();
171
172                 FooterItem itemCamera;
173                 itemCamera.Construct(IDA_FOOTER_CAMERA);
174                 itemCamera.SetText(ResourceManager::GetString(L"EMPTY_SPACE"));
175                 Bitmap* pBitmap1 = ResourceManager::GetBitmapN(IDB_CONTROLBAR_CAMERA);
176                 if (pBitmap1 != null)
177                 {
178                         itemCamera.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pBitmap1);
179                 }
180                 pFooter->AddItem(itemCamera);
181                 delete pBitmap1;
182
183                 __pOptionMenu = new (std::nothrow) OptionMenu();
184                 __pOptionMenu->Construct();
185                 __pOptionMenu->AddItem(ResourceManager::GetString(L"IDS_COM_HEADER_EDIT"),IDA_FOOTER_EDIT);
186                 __pOptionMenu->AddItem(ResourceManager::GetString(L"IDS_COM_HEADER_EDIT"), IDA_FOOTER_EDIT);
187                 __pOptionMenu->SetShowState(false);
188                 __pOptionMenu->AddActionEventListener(*this);
189                 SetFormMenuEventListener(this);
190                 SetFormBackEventListener(this);
191         }
192
193         pFooter->AddActionEventListener(*this);
194         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
195
196         return E_SUCCESS;
197 }
198
199 void
200 AlbumListForm::CreateIconListView(void)
201 {
202         AppLogDebug("ENTER");
203         Dimension itemSize(W_FOLDER_SIZE, H_FOLDER_SIZE);
204
205         __pAlbumViewIconList = new IconListView();
206         __pAlbumViewIconList->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height),
207                     Dimension(W_FOLDER_SIZE, H_FOLDER_SIZE), ICON_LIST_VIEW_STYLE_NORMAL, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
208         __pAlbumViewIconList->SetItemProvider(*this);
209         __pAlbumViewIconList->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
210         __pAlbumViewIconList->AddIconListViewItemEventListener(*this);
211
212
213
214         Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
215
216         if (pBitmap != null)
217         {
218                 __pAlbumViewIconList->SetBitmapOfEmptyList(pBitmap);
219                 delete pBitmap;
220         }
221         __pAlbumViewIconList->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
222
223         AddControl(*__pAlbumViewIconList);
224
225         __pAlbumViewIconList->SetShowState(true);
226         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
227 }
228
229 int
230 AlbumListForm::GetItemCount(void)
231 {
232         AppLogDebug("ENTER");
233         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
234
235         return  __itemCount;
236 }
237
238 IconListViewItem*
239 AlbumListForm::CreateItem(int index)
240 {
241         AppLogDebug("ENTER : index(%d)", index);
242
243         Bitmap* pBitmap = null;
244         IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
245         if (pAlbumInfoList != null)
246         {
247                 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
248                 if (pAlbumInfo != null)
249                 {
250                         Bitmap* pAlbumBitmap = pAlbumInfo->GetFolderThumnailBitmap();
251
252                         if (pAlbumBitmap == null)
253                         {
254                                 __pPresentationModel->RequestThumbnail(index, 0);
255                         }
256
257                         pBitmap = __pPresentationModel->CreateMergeBitmapN(index);
258
259                         if (pBitmap != null)
260                         {
261                                 IconListViewItem* pIconListview = new (std::nothrow) IconListViewItem();
262                                 pIconListview->Construct(*pBitmap);
263                                 delete pBitmap;
264                                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
265
266                                 return pIconListview;
267                         }
268                 }
269         }
270         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
271
272         return null;
273 }
274
275 void
276 AlbumListForm::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
277 {
278         AppLogDebug("ENTER");
279         if (status == ICON_LIST_VIEW_ITEM_SELECTED)
280         {
281                 SceneManager* pSceneManager = SceneManager::GetInstance();
282
283                 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
284                 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
285                 AlbumInfo* pSendAlbumInfo = new (std::nothrow) AlbumInfo();
286                 pSendAlbumInfo->Construct(*pAlbumInfo);
287
288                 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
289                 pArrayList->Construct();
290                 pArrayList->Add(pSendAlbumInfo);
291
292                 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
293                 {
294                         if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
295                         {
296                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR), pArrayList);
297                         }
298                         else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
299                         {
300                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_VIDEO_LIST_EDITOR), pArrayList);
301                         }
302                         else
303                         {
304                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR), pArrayList);
305                         }
306                 }
307                 else
308                 {
309                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST), pArrayList);
310                 }
311         }
312         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
313 }
314
315 bool
316 AlbumListForm::DeleteItem(int index, IconListViewItem* pItem)
317 {
318         AppLogDebug("ENTER");
319         delete pItem;
320         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
321
322         return true;
323 }
324
325 result
326 AlbumListForm::OnTerminating(void)
327 {
328         AppLogDebug("ENTER");
329         __pPresentationModel->RemovePresentationModelListener(*this);
330         __pPresentationModel->RemoveContentEventListener(*this);
331         if (__pContextMenuMore != null)
332         {
333                 delete __pContextMenuMore;
334                 __pContextMenuMore = null;
335         }
336         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
337
338         return E_SUCCESS;
339 }
340
341 void
342 AlbumListForm::OnActionPerformed(const Control& source, int actionId)
343 {
344         AppLogDebug("ENTER");
345         SceneManager* pSceneManager = SceneManager::GetInstance();
346
347         switch (actionId)
348         {
349         case IDA_FOOTER_CAMERA:
350         {
351                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
352                 pDataList->Construct();
353                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_CAMERA_ALLOW_SWITCH),
354                                 new (std::nothrow) String(APPCONTROL_DATA_TRUE));
355                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_CAMERA,
356                                 APPCONTROL_OPERATION_ID_CREATE_CONTENT, null,
357                                 new (std::nothrow) String(APPCONTROL_MIME_IMAGE_JPG), pDataList, null);
358         }
359         break;
360
361         case IDA_FOOTER_EDIT:
362         {
363                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST_EDITOR));
364         }
365         break;
366
367         default:
368                 break;
369         }
370         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
371 }
372
373 void
374 AlbumListForm::OnFormBackRequested(Form& source)
375 {
376         AppLogDebug("ENTER");
377         if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
378         {
379                 AppLogDebug("APP_CONTROL_MODE_PICK");
380                 GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
381                 if (pApp != null)
382                 {
383                         if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
384                         {
385                                 pApp->SendAppControlResult(APP_CTRL_RESULT_CANCELED, null);
386                         }
387                         pApp->Terminate();
388                 }
389         }
390         else
391         {
392                 AppLogDebug("APP_CONTROL_MODE_MAIN");
393                 UiApp* pApp = UiApp::GetInstance();
394                 pApp->Terminate();
395         }
396         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
397 }
398
399 void
400 AlbumListForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
401 {
402         AppLogDebug("ENTER");
403         __pPresentationModel->AddContentEventListener(this);
404
405         if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
406         {
407                 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
408                 {
409                         __pPresentationModel->ClearThumbnailRequests(false);
410                         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
411                 }
412                 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
413                 {
414                         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
415                 }
416                 else
417                 {
418                         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
419                 }
420         }
421         else
422         {
423                 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
424         }
425         __itemCount = __pPresentationModel->GetFolderCount();
426
427         if (__pAlbumViewIconList != null)
428         {
429                 __pAlbumViewIconList->UpdateList();
430         }
431
432         Invalidate(true);
433         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
434 }
435
436 void
437 AlbumListForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
438 {
439         AppLogDebug("ENTER");
440         __pPresentationModel->RemoveContentEventListener(*this);
441         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
442 }
443
444 void
445 AlbumListForm::OnContentUpdated(void)
446 {
447         AppLogDebug("ENTER");
448
449         if ( __pOptionMenu != null && __pOptionMenu ->GetShowState() == true)
450         {
451                 __pOptionMenu->SetShowState(false);
452                 __pOptionMenu->Show();
453         }
454
455         if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
456         {
457                 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
458                 {
459                         __pPresentationModel->ClearThumbnailRequests(false);
460                         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
461                 }
462                 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
463                 {
464                         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
465                 }
466                 else
467                 {
468                         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_VIDEO);
469                 }
470         }
471         else
472         {
473                 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
474         }
475
476         __itemCount = __pPresentationModel->GetFolderCount();
477         __pAlbumViewIconList->UpdateList();
478
479         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
480 }
481
482 void
483 AlbumListForm::OnFileInfoChanged(const ContentType contentType)
484 {
485         AppLogDebug("ENTER");
486         Update();
487         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
488 }
489
490 void
491 AlbumListForm::OnThumbnailDecoded(const int index)
492 {
493         AppLogDebug("ENTER : index(%d)", index);
494         __pAlbumViewIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
495         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
496 }
497
498 result
499 AlbumListForm::Update(void)
500 {
501         AppLogDebug("ENTER");
502         result r = __pAlbumViewIconList->UpdateList();
503         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
504
505         return r;
506 }
507
508 void
509 AlbumListForm::OnFormMenuRequested (Tizen::Ui::Controls::Form &source)
510 {
511
512         if ( __pOptionMenu == null )
513         {
514                 return ;
515         }
516
517         __pOptionMenu->SetShowState(true);
518         __pOptionMenu->Show();
519
520 }
521
522 void
523 AlbumListForm::OnOrientationChanged(const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
524 {
525
526         if( __pAlbumViewIconList != null )
527         {
528                 RemoveControl(__pAlbumViewIconList);
529         }
530
531         __pAlbumViewIconList = new IconListView();
532
533         if( orientationStatus == ORIENTATION_STATUS_PORTRAIT )
534         {
535         __pAlbumViewIconList->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height),
536                     Dimension(W_FOLDER_SIZE, H_FOLDER_SIZE), ICON_LIST_VIEW_STYLE_NORMAL, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
537         }
538         else if (orientationStatus == ORIENTATION_STATUS_LANDSCAPE || orientationStatus == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
539         {
540                 int horizontalSpacing = 8;
541                 int verticalSpacing = 60;
542         int height = 424;
543         int width = 410;
544
545                 __pAlbumViewIconList->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height),
546                                     Dimension(width, height), ICON_LIST_VIEW_STYLE_NORMAL, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
547
548                 __pAlbumViewIconList->SetItemSpacing(horizontalSpacing, verticalSpacing);
549                 __pAlbumViewIconList->SetMargin(MARGIN_TYPE_TOP,60);
550         }
551
552         Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
553
554         if (pBitmap != null)
555         {
556                 __pAlbumViewIconList->SetBitmapOfEmptyList(pBitmap);
557                 delete pBitmap;
558         }
559
560         __pAlbumViewIconList->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
561
562         __pAlbumViewIconList->SetItemProvider(*this);
563         __pAlbumViewIconList->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
564         __pAlbumViewIconList->AddIconListViewItemEventListener(*this);
565
566         AddControl(*__pAlbumViewIconList);
567
568 }
569
570
571
572
573
574