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