1668f498f9cafde46f8baa04af9ff2c0e12fa110
[apps/osp/Gallery.git] / src / GlFileListForm.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                GlFileListForm.cpp
19  * @brief               This is the implementation file for FileListForm class.
20  */
21
22 #include "GlAlbumInfo.h"
23 #include "GlAllListPanel.h"
24 #include "GlFileListForm.h"
25 #include "GlFileListPresentationModel.h"
26 #include "GlGalleryApp.h"
27 #include "GlResourceManager.h"
28 #include "GlSlideSettingListener.h"
29 #include "GlSlideShowPopUp.h"
30 #include "GlTypes.h"
31
32 using namespace Tizen::App;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Ui;
37 using namespace Tizen::Ui::Controls;
38 using namespace Tizen::Ui::Scenes;
39 using namespace Tizen::Content;
40
41 FileListForm::FileListForm(void)
42         : __isHWBackButtonExist(false)
43         , __pContextMenuMore(null)
44         , __pOptionMenu(null)
45         , __pPopUp(null)
46         , __pPresentationModel(null)
47 {
48         AppLogDebug("ENTER");
49         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
50 }
51
52 FileListForm::~FileListForm(void)
53 {
54         AppLogDebug("ENTER");
55         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
56 }
57
58 result
59 FileListForm::Initialize(void)
60 {
61         AppLogDebug("ENTER");
62         result r = Form::Construct(IDL_FORM_FILE_LIST);
63         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
64
65         return r;
66 }
67 result
68 FileListForm::OnInitializing(void)
69 {
70         AppLogDebug("ENTER");
71         Header* pHeader = GetHeader();
72         TryReturn(pHeader != null, E_FAILURE, "[%s] fail to get the Header.", GetErrorMessage(GetLastResult()));
73
74          __isHWBackButtonExist = false;
75
76            SetFormMenuEventListener(this);
77            GalleryApp* pApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
78
79            __isHWBackButtonExist = pApp->IsHwKeySupported();
80
81         __pPresentationModel = FileListPresentationModel::GetInstance();
82         __pPresentationModel->ClearThumbnailRequests();
83
84         __pPopUp = new (std::nothrow) SlideShowPopUp();
85
86         if (__pPopUp != null)
87         {
88                 __pPopUp->Initialize();
89                 __pPopUp->SetEventListner(this);
90                 AddControl(__pPopUp);
91         }
92
93         InitializeFooter();
94         SetFormBackEventListener(this);
95         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
96
97         return E_SUCCESS;
98 }
99
100 result
101 FileListForm::OnTerminating(void)
102 {
103         AppLogDebug("ENTER");
104
105         if (__pContextMenuMore != null)
106         {
107                 delete __pContextMenuMore;
108                 __pContextMenuMore = null;
109         }
110
111         if ( __pOptionMenu != null )
112         {
113                 delete __pOptionMenu;
114                 __pOptionMenu = null;
115         }
116
117         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
118
119         return E_SUCCESS;
120 }
121
122 void
123 FileListForm::OnContentUpdated()
124 {
125         AppLogDebug("ENTER");
126         SceneManager* pSceneManager = SceneManager::GetInstance();
127         static_cast<AllListPanel*>(pSceneManager->GetCurrentScene()->GetPanel())->Refresh();
128         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
129 }
130
131 void
132 FileListForm::OnActionPerformed(const Control& source, int actionId)
133 {
134         AppLogDebug("ENTER");
135         SceneManager* pSceneManager = SceneManager::GetInstance();
136         TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager", GetErrorMessage(GetLastResult()));
137
138         switch (actionId)
139         {
140         case IDA_FOOTER_MORE:
141         {
142                 AppLogDebug("ITEMCOUNT(%d)", __pPresentationModel->GetCurrentAlbumContentInfoCount());
143
144                 InitializeFooter();
145
146                 if (__pContextMenuMore->GetShowState() == false)
147                 {
148                         Rectangle rect = source.GetBounds();
149                         __pContextMenuMore->SetAnchorPosition(Point(rect.width / 10, rect.y));
150                         __pContextMenuMore->SetShowState(true);
151                         __pContextMenuMore->Show();
152                 }
153                 else
154                 {
155                         __pContextMenuMore->SetShowState(false);
156                 }
157         }
158         break;
159
160         case IDA_FOOTER_EDIT:
161         {
162                 if (pSceneManager->GetCurrentSceneId() == IDSCN_ALL_LIST)
163                 {
164                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST_EDITOR));
165                 }
166                 else if (pSceneManager->GetCurrentSceneId() == IDSCN_IMAGE_LIST)
167                 {
168                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR));
169                 }
170                 else if (pSceneManager->GetCurrentSceneId() == IDSCN_VIDEO_LIST)
171                 {
172                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_VIDEO_LIST_EDITOR));
173                 }
174                 else
175                 {
176                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST_EDITOR));
177                 }
178         }
179         break;
180
181         case IDA_FOOTER_SLIDESHOW:
182         {
183
184                 if (__pPopUp != null)
185                 {
186                         __pPopUp->SetShowState(true);
187                         __pPopUp->Show();
188                 }
189         }
190         break;
191
192         case IDA_FOOTER_CAMERA:
193         {
194                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
195                 pDataList->Construct();
196                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_CAMERA_ALLOW_SWITCH), new (std::nothrow) String(APPCONTROL_DATA_TRUE));
197                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_CAMERA, APPCONTROL_OPERATION_ID_CREATE_CONTENT,
198                                 null, new (std::nothrow) String(APPCONTROL_MIME_IMAGE_JPG), pDataList, null);
199         }
200         break;
201
202         default:
203                 break;
204         }
205         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
206 }
207
208 void
209 FileListForm::OnFormBackRequested(Form& source)
210 {
211         AppLogDebug("ENTER");
212         SceneManager* pSceneManager = SceneManager::GetInstance();
213         TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager", GetErrorMessage(GetLastResult()));
214
215         pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_ALBUM_LIST));
216         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
217 }
218
219 result
220 FileListForm::InitializeFooter(void)
221 {
222         AppLogDebug("ENTER");
223         result r = E_SUCCESS;
224         Footer* pFooter = GetFooter();
225         TryReturn(pFooter != null, E_FAILURE, "[%s] fail to get the Footer.", GetErrorMessage(GetLastResult()));
226
227         pFooter->RemoveAllItems();
228         pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON);
229
230
231         if ( __isHWBackButtonExist == false )
232         {
233                 ButtonItem footerMore;
234                 footerMore.Construct(BUTTON_ITEM_STYLE_ICON, IDA_FOOTER_MORE);
235                 Bitmap* pBitmapMore = ResourceManager::GetBitmapN(IDB_CONTROLBAR_MORE);
236                 Bitmap* pBitmapMoreDim = ResourceManager::GetBitmapN(IDB_CONTROLBAR_MORE_DISABLED);
237                 Bitmap* pBitmapMorePressed = ResourceManager::GetBitmapN(IDB_CONTROLBAR_MORE_PRESSED);
238
239                 if (pBitmapMore != null && pBitmapMoreDim != null && pBitmapMorePressed != null)
240                 {
241                         footerMore.SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapMore);
242                         footerMore.SetIcon(BUTTON_ITEM_STATUS_DISABLED, pBitmapMoreDim);
243                         footerMore.SetIcon(BUTTON_ITEM_STATUS_PRESSED, pBitmapMorePressed);
244                 }
245                 pFooter->SetButton(BUTTON_POSITION_LEFT, footerMore);
246
247                 delete pBitmapMore;
248                 delete pBitmapMoreDim;
249                 delete pBitmapMorePressed;
250         }
251
252         FooterItem itemCamera;
253         itemCamera.Construct(IDA_FOOTER_CAMERA);
254         Bitmap* pBitmapCamera = ResourceManager::GetBitmapN(IDB_CONTROLBAR_CAMERA);
255         if (pBitmapCamera != null)
256         {
257                 itemCamera.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pBitmapCamera);
258         }
259         pFooter->AddItem(itemCamera);
260
261         if ( __isHWBackButtonExist == false )
262         {
263
264                 if (__pContextMenuMore != null)
265                 {
266                         delete __pContextMenuMore;
267                         __pContextMenuMore = null;
268                 }
269
270                 __pContextMenuMore = new (std::nothrow) ContextMenu();
271                 __pContextMenuMore->Construct(Point(0, 0), CONTEXT_MENU_STYLE_LIST);
272
273                 if (__pPresentationModel->GetCurrentAlbumContentInfoCount() > 1)
274                 {
275                         __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_MEDIABR_OPT_SLIDESHOW"), IDA_FOOTER_SLIDESHOW);
276                 }
277
278                 if (__pPresentationModel->GetCurrentAlbumContentInfoCount() == 0)
279                 {
280                         __pContextMenuMore->SetEnabled(false);
281                 }
282                 else
283                 {
284                         __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_COM_HEADER_EDIT"), IDA_FOOTER_EDIT);
285                         __pContextMenuMore->SetShowState(false);
286                         __pContextMenuMore->AddActionEventListener(*this);
287                 }
288         }
289         else
290         {
291                 if (__pOptionMenu != null)
292                 {
293                         delete __pOptionMenu;
294                         __pOptionMenu = null;
295                 }
296
297                 __pOptionMenu = new (std::nothrow) OptionMenu();
298                 __pOptionMenu->Construct();
299
300                 if (__pPresentationModel->GetCurrentAlbumContentInfoCount() > 1)
301                 {
302                         __pOptionMenu->AddItem(ResourceManager::GetString(L"IDS_MEDIABR_OPT_SLIDESHOW"), IDA_FOOTER_SLIDESHOW);
303                 }
304
305                 if (__pPresentationModel->GetCurrentAlbumContentInfoCount() == 0)
306                 {
307                         __pOptionMenu->SetEnabled(false);
308                 }
309                 else
310                 {
311                         __pOptionMenu->AddItem(ResourceManager::GetString(L"IDS_COM_HEADER_EDIT"), IDA_FOOTER_EDIT);
312                         __pOptionMenu->AddActionEventListener(*this);
313                 }
314
315         }
316         pFooter->SetBackButton();
317
318         pFooter->AddActionEventListener(*this);
319         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
320
321         return r;
322 }
323
324 void
325 FileListForm::SetTitleText(const String& titleText)
326 {
327         AppLogDebug("ENTER");
328         Header* pHeader = GetHeader();
329         TryReturnVoid(pHeader != null, "[%s] fail to get the Header.", GetErrorMessage(GetLastResult()));
330         pHeader->SetTitleText(titleText);
331         pHeader->Show();
332         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
333 }
334
335 void
336 FileListForm::OnSlideSettingPopUpItemSelected(int index)
337 {
338         if (__pPopUp != NULL)
339         {
340                 __pPopUp->SetShowState(false);
341         }
342
343         if (index == 0)
344         {
345                 result r = E_SUCCESS;
346                 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
347                 pArrayList->Construct();
348                 int loopCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
349
350                 for (int i = 0; i < loopCount; ++i)
351                 {
352                         pArrayList->Add(new (std::nothrow) String(__pPresentationModel->GetContentFilePath(i)));
353                 }
354
355                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
356                 pDataList->Construct();
357                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE), new (std::nothrow) String(APPCONTROL_DATA_SLIDE_SHOW));
358                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
359
360                 r = __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_IMAGE, APPCONTROL_OPERATION_ID_VIEW, null,
361                                 new (std::nothrow) String(APPCONTROL_MIME_IMAGE_ALL), pDataList, null);
362
363                 if (r == E_MAX_EXCEEDED)
364                 {
365                         MessageBox messageBox;
366                         messageBox.Construct(L"", ResourceManager::GetString(L"IDS_RCS_BODY_MAXIMUM_NUMBER_OF_FILES_EXCEEDED"),
367                                         MSGBOX_STYLE_NONE, 3000);
368                         int modalResult;
369                         messageBox.ShowAndWait(modalResult);
370                 }
371         }
372         else if (index == 1)
373         {
374                 SceneManager* pSceneManager = SceneManager::GetInstance();
375                 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager", GetErrorMessage(GetLastResult()));
376
377                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SETTING_MAIN));
378         }
379 }
380
381 void
382 FileListForm::SetFooterState(bool state)
383 {
384         GetFooter()->SetButtonEnabled(BUTTON_POSITION_LEFT,state);
385         GetFooter()->Invalidate(true);
386 }
387
388 void
389 FileListForm::OnFormMenuRequested (Tizen::Ui::Controls::Form &source)
390 {
391
392         InitializeFooter();
393
394         if ( __pOptionMenu == null )
395         {
396                 return ;
397         }
398
399         __pOptionMenu->Show();
400         __pOptionMenu->SetShowState(true);
401
402 }