d3ba7116a7c9c5b17ab0833ac29d8c2708abf62a
[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         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
55 }
56
57 result
58 FileListForm::Initialize(void)
59 {
60         AppLogDebug("ENTER");
61         result r = Form::Construct(IDL_FORM_FILE_LIST);
62         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
63
64         return r;
65 }
66 result
67 FileListForm::OnInitializing(void)
68 {
69         AppLogDebug("ENTER");
70         Header* pHeader = GetHeader();
71         TryReturn(pHeader != null, E_FAILURE, "[%s] fail to get the Header.", GetErrorMessage(GetLastResult()));
72
73            SetFormMenuEventListener(this);
74
75         __pPresentationModel = FileListPresentationModel::GetInstance();
76         __pPresentationModel->ClearThumbnailRequests();
77
78         __pPopUp = new (std::nothrow) SlideShowPopUp();
79
80         if (__pPopUp != null)
81         {
82                 __pPopUp->Initialize();
83                 __pPopUp->SetEventListner(this);
84                 AddControl(__pPopUp);
85         }
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                         __pPopUp->SetShowState(true);
157                         __pPopUp->Show();
158                 }
159         }
160         break;
161
162         case IDA_FOOTER_CAMERA:
163         {
164                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
165                 pDataList->Construct();
166                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_CAMERA_ALLOW_SWITCH), new (std::nothrow) String(APPCONTROL_DATA_TRUE));
167                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_CAMERA, APPCONTROL_OPERATION_ID_CREATE_CONTENT,
168                                 null, new (std::nothrow) String(APPCONTROL_MIME_IMAGE_JPG), pDataList, null);
169         }
170         break;
171
172         default:
173                 break;
174         }
175         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
176 }
177
178 void
179 FileListForm::OnFormBackRequested(Form& source)
180 {
181         AppLogDebug("ENTER");
182         SceneManager* pSceneManager = SceneManager::GetInstance();
183         TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager", GetErrorMessage(GetLastResult()));
184
185         pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_ALBUM_LIST));
186         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
187 }
188
189 void
190 FileListForm::OnOrientationChanged(const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
191 {
192
193
194         SceneManager* pSceneManager = SceneManager::GetInstance();
195         pSceneManager->GetCurrentScene();
196
197         if (pSceneManager->GetCurrentSceneId() == IDSCN_ALL_LIST)
198         {
199                 AllListPanel* pListPanel = dynamic_cast<AllListPanel*>(pSceneManager->GetCurrentScene()->GetPanel());
200                 if (pListPanel != null)
201                 {
202                         pListPanel->ChangeOrientation();
203                 }
204         }
205 }
206
207 result
208 FileListForm::InitializeFooter(void)
209 {
210         AppLogDebug("ENTER");
211         result r = E_SUCCESS;
212         Footer* pFooter = GetFooter();
213         TryReturn(pFooter != null, E_FAILURE, "[%s] fail to get the Footer.", GetErrorMessage(GetLastResult()));
214
215         pFooter->RemoveAllItems();
216         pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON);
217
218         FooterItem itemCamera;
219         itemCamera.Construct(IDA_FOOTER_CAMERA);
220         Bitmap* pBitmapCamera = ResourceManager::GetBitmapN(IDB_CONTROLBAR_CAMERA);
221         if (pBitmapCamera != null)
222         {
223                 itemCamera.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pBitmapCamera);
224         }
225         pFooter->AddItem(itemCamera);
226
227
228         if (__pOptionMenu != null)
229         {
230                 delete __pOptionMenu;
231                 __pOptionMenu = null;
232         }
233
234         __pOptionMenu = new (std::nothrow) OptionMenu();
235         __pOptionMenu->Construct();
236
237         if (__pPresentationModel->GetCurrentAlbumContentInfoCount() > 1)
238         {
239                 __pOptionMenu->AddItem(ResourceManager::GetString(L"IDS_MEDIABR_OPT_SLIDESHOW"), IDA_FOOTER_SLIDESHOW);
240         }
241
242         if (__pPresentationModel->GetCurrentAlbumContentInfoCount() == 0)
243         {
244                 __pOptionMenu->SetEnabled(false);
245         }
246         else
247         {
248                 __pOptionMenu->AddItem(ResourceManager::GetString(L"IDS_COM_HEADER_EDIT"), IDA_FOOTER_EDIT);
249                 __pOptionMenu->AddActionEventListener(*this);
250         }
251
252         pFooter->AddActionEventListener(*this);
253         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
254
255         return r;
256 }
257
258 void
259 FileListForm::SetTitleText(const String& titleText)
260 {
261         AppLogDebug("ENTER");
262         Header* pHeader = GetHeader();
263         TryReturnVoid(pHeader != null, "[%s] fail to get the Header.", GetErrorMessage(GetLastResult()));
264         pHeader->SetTitleText(titleText);
265         pHeader->Show();
266         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
267 }
268
269 void
270 FileListForm::OnSlideSettingPopUpItemSelected(int index)
271 {
272         if (__pPopUp != NULL)
273         {
274                 __pPopUp->SetShowState(false);
275         }
276
277         if (index == 0)
278         {
279                 result r = E_SUCCESS;
280                 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
281                 pArrayList->Construct();
282                 int loopCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
283
284                 for (int i = 0; i < loopCount; ++i)
285                 {
286                         pArrayList->Add(new (std::nothrow) String(__pPresentationModel->GetContentFilePath(i)));
287                 }
288
289                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
290                 pDataList->Construct();
291                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE), new (std::nothrow) String(APPCONTROL_DATA_SLIDE_SHOW));
292                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
293
294                 r = __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_IMAGE, APPCONTROL_OPERATION_ID_VIEW, null,
295                                 new (std::nothrow) String(APPCONTROL_MIME_IMAGE_ALL), pDataList, null);
296
297                 if (r == E_MAX_EXCEEDED)
298                 {
299                         MessageBox messageBox;
300                         messageBox.Construct(L"", ResourceManager::GetString(L"IDS_RCS_BODY_MAXIMUM_NUMBER_OF_FILES_EXCEEDED"),
301                                         MSGBOX_STYLE_NONE, 3000);
302                         int modalResult;
303                         messageBox.ShowAndWait(modalResult);
304                 }
305         }
306         else if (index == 1)
307         {
308                 SceneManager* pSceneManager = SceneManager::GetInstance();
309                 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager", GetErrorMessage(GetLastResult()));
310
311                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SETTING_MAIN));
312         }
313 }
314
315 void
316 FileListForm::SetMenuState(bool state)
317 {
318         __menuState = state;
319 }
320
321 void
322 FileListForm::OnFormMenuRequested (Tizen::Ui::Controls::Form &source)
323 {
324
325         if (__menuState == true )
326         {
327                 InitializeFooter();
328
329                 if ( __pOptionMenu == null )
330                 {
331                         return ;
332                 }
333
334                 __pOptionMenu->SetShowState(true);
335                 __pOptionMenu->Show();
336         }
337
338 }