Fixed issue 48313
[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
42 FileListForm::FileListForm(void)
43         : __menuState(true)
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
56         if (__pPopUp != NULL)
57         {
58                 delete __pPopUp;
59                 __pPopUp = NULL;
60         }
61
62
63         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
64 }
65
66 result
67 FileListForm::Initialize(void)
68 {
69         AppLogDebug("ENTER");
70         result r = Form::Construct(IDL_FORM_FILE_LIST);
71         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
72
73         return r;
74 }
75 result
76 FileListForm::OnInitializing(void)
77 {
78         AppLogDebug("ENTER");
79         Header* pHeader = GetHeader();
80         TryReturn(pHeader != null, E_FAILURE, "[%s] fail to get the Header.", GetErrorMessage(GetLastResult()));
81
82            SetFormMenuEventListener(this);
83
84         __pPresentationModel = FileListPresentationModel::GetInstance();
85         __pPresentationModel->ClearThumbnailRequests();
86
87         InitializeFooter();
88         SetFormBackEventListener(this);
89         SetOrientation(ORIENTATION_AUTOMATIC);
90         AddOrientationEventListener(*this);
91         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
92
93         return E_SUCCESS;
94 }
95
96 result
97 FileListForm::OnTerminating(void)
98 {
99         AppLogDebug("ENTER");
100
101         if (__pOptionMenu != null)
102         {
103                 delete __pOptionMenu;
104                 __pOptionMenu = null;
105         }
106
107         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
108
109         return E_SUCCESS;
110 }
111
112 void
113 FileListForm::OnContentUpdated()
114 {
115         AppLogDebug("ENTER");
116         SceneManager* pSceneManager = SceneManager::GetInstance();
117         static_cast<AllListPanel*>(pSceneManager->GetCurrentScene()->GetPanel())->Refresh();
118         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
119 }
120
121 void
122 FileListForm::OnActionPerformed(const Control& source, int actionId)
123 {
124         AppLogDebug("ENTER");
125         SceneManager* pSceneManager = SceneManager::GetInstance();
126         TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager", GetErrorMessage(GetLastResult()));
127
128         switch (actionId)
129         {
130         case IDA_FOOTER_EDIT:
131         {
132                 if (pSceneManager->GetCurrentSceneId() == IDSCN_ALL_LIST)
133                 {
134                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST_EDITOR));
135                 }
136                 else if (pSceneManager->GetCurrentSceneId() == IDSCN_IMAGE_LIST)
137                 {
138                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR));
139                 }
140                 else if (pSceneManager->GetCurrentSceneId() == IDSCN_VIDEO_LIST)
141                 {
142                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_VIDEO_LIST_EDITOR));
143                 }
144                 else
145                 {
146                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST_EDITOR));
147                 }
148         }
149         break;
150
151         case IDA_FOOTER_SLIDESHOW:
152         {
153
154                 if (__pPopUp != NULL)
155                 {
156                         delete __pPopUp;
157                         __pPopUp = NULL;
158                 }
159                 __pPopUp = new (std::nothrow) SlideShowPopUp();
160
161                 if (__pPopUp != null)
162                 {
163                         __pPopUp->Initialize();
164                         __pPopUp->SetEventListner(this);
165                         __pPopUp->SetShowState(true);
166                         __pPopUp->Show();
167                 }
168         }
169         break;
170
171         case IDA_FOOTER_CAMERA:
172         {
173                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
174                 pDataList->Construct();
175                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_CAMERA_ALLOW_SWITCH), new (std::nothrow) String(APPCONTROL_DATA_TRUE));
176                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_CAMERA, APPCONTROL_OPERATION_ID_CREATE_CONTENT,
177                                 null, new (std::nothrow) String(APPCONTROL_MIME_IMAGE_JPG), pDataList, null);
178         }
179         break;
180
181         default:
182                 break;
183         }
184         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
185 }
186
187 void
188 FileListForm::OnFormBackRequested(Form& source)
189 {
190         AppLogDebug("ENTER");
191         SceneManager* pSceneManager = SceneManager::GetInstance();
192         TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager", GetErrorMessage(GetLastResult()));
193
194         pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_ALBUM_LIST));
195         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
196 }
197
198 void
199 FileListForm::OnOrientationChanged(const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
200 {
201
202
203         SceneManager* pSceneManager = SceneManager::GetInstance();
204         pSceneManager->GetCurrentScene();
205
206         if (pSceneManager->GetCurrentSceneId() == IDSCN_ALL_LIST)
207         {
208                 AllListPanel* pListPanel = dynamic_cast<AllListPanel*>(pSceneManager->GetCurrentScene()->GetPanel());
209                 if (pListPanel != null)
210                 {
211                         pListPanel->ChangeOrientation();
212                 }
213         }
214 }
215
216 result
217 FileListForm::InitializeFooter(void)
218 {
219         AppLogDebug("ENTER");
220         result r = E_SUCCESS;
221         Footer* pFooter = GetFooter();
222         TryReturn(pFooter != null, E_FAILURE, "[%s] fail to get the Footer.", GetErrorMessage(GetLastResult()));
223
224         pFooter->RemoveAllItems();
225         pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON);
226
227         FooterItem itemCamera;
228         itemCamera.Construct(IDA_FOOTER_CAMERA);
229         Bitmap* pBitmapCamera = ResourceManager::GetBitmapN(IDB_CONTROLBAR_CAMERA);
230         if (pBitmapCamera != null)
231         {
232                 itemCamera.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pBitmapCamera);
233         }
234         pFooter->AddItem(itemCamera);
235
236         delete pBitmapCamera;
237
238         if (__pOptionMenu != null)
239         {
240                 delete __pOptionMenu;
241                 __pOptionMenu = null;
242         }
243
244         __pOptionMenu = new (std::nothrow) OptionMenu();
245         __pOptionMenu->Construct();
246
247         if (__pPresentationModel->GetCurrentAlbumContentInfoCount() > 1)
248         {
249                 __pOptionMenu->AddItem(ResourceManager::GetString(L"IDS_MEDIABR_OPT_SLIDESHOW"), IDA_FOOTER_SLIDESHOW);
250         }
251
252         if (__pPresentationModel->GetCurrentAlbumContentInfoCount() == 0)
253         {
254                 __pOptionMenu->SetEnabled(false);
255         }
256         else
257         {
258                 __pOptionMenu->AddItem(ResourceManager::GetString(L"IDS_COM_HEADER_EDIT"), IDA_FOOTER_EDIT);
259                 __pOptionMenu->AddActionEventListener(*this);
260         }
261
262         pFooter->AddActionEventListener(*this);
263         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
264
265         return r;
266 }
267
268 void
269 FileListForm::SetTitleText(const String& titleText)
270 {
271         AppLogDebug("ENTER");
272         Header* pHeader = GetHeader();
273         TryReturnVoid(pHeader != null, "[%s] fail to get the Header.", GetErrorMessage(GetLastResult()));
274
275         if (titleText == ALL_ALBUMS_REAL_NAME)
276         {
277                 String text = ResourceManager::GetString(L"IDS_MEDIABR_BODY_ALL_ALBUMS");
278                 pHeader->SetTitleText(text);
279         }
280         else
281         {
282                 pHeader->SetTitleText(titleText);
283         }
284
285         pHeader->Show();
286         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
287 }
288
289 void
290 FileListForm::OnSlideSettingPopUpItemSelected(int index)
291 {
292         if (__pPopUp != NULL)
293         {
294                 __pPopUp->SetShowState(false);
295         }
296
297         if (index == 0)
298         {
299                 result r = E_SUCCESS;
300                 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
301                 pArrayList->Construct();
302                 int loopCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
303
304                 for (int i = 0; i < loopCount; ++i)
305                 {
306                         pArrayList->Add(new (std::nothrow) String(__pPresentationModel->GetContentFilePath(i)));
307                 }
308
309                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
310                 pDataList->Construct();
311                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE), new (std::nothrow) String(APPCONTROL_DATA_SLIDE_SHOW));
312                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
313
314                 r = __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_IMAGE, APPCONTROL_OPERATION_ID_VIEW, null,
315                                 new (std::nothrow) String(APPCONTROL_MIME_IMAGE_ALL), pDataList, null);
316
317                 if (r == E_MAX_EXCEEDED)
318                 {
319                         MessageBox messageBox;
320                         messageBox.Construct(L"", ResourceManager::GetString(L"IDS_RCS_BODY_MAXIMUM_NUMBER_OF_FILES_EXCEEDED"),
321                                         MSGBOX_STYLE_NONE, 3000);
322                         int modalResult;
323                         messageBox.ShowAndWait(modalResult);
324                 }
325         }
326         else if (index == 1)
327         {
328                 SceneManager* pSceneManager = SceneManager::GetInstance();
329                 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager", GetErrorMessage(GetLastResult()));
330
331                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SETTING_MAIN));
332         }
333 }
334
335 void
336 FileListForm::SetMenuState(bool state)
337 {
338         __menuState = state;
339 }
340
341 void
342 FileListForm::OnFormMenuRequested (Tizen::Ui::Controls::Form &source)
343 {
344
345         if (__menuState == true)
346         {
347                 InitializeFooter();
348
349                 if (__pOptionMenu == null)
350                 {
351                         return;
352                 }
353
354                 __pOptionMenu->SetShowState(true);
355                 __pOptionMenu->Show();
356         }
357 }
358