Removed the deprecated Menu and Back buuton api
[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         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
90
91         return E_SUCCESS;
92 }
93
94 result
95 FileListForm::OnTerminating(void)
96 {
97         AppLogDebug("ENTER");
98
99         if ( __pOptionMenu != null )
100         {
101                 delete __pOptionMenu;
102                 __pOptionMenu = null;
103         }
104
105         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
106
107         return E_SUCCESS;
108 }
109
110 void
111 FileListForm::OnContentUpdated()
112 {
113         AppLogDebug("ENTER");
114         SceneManager* pSceneManager = SceneManager::GetInstance();
115         static_cast<AllListPanel*>(pSceneManager->GetCurrentScene()->GetPanel())->Refresh();
116         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
117 }
118
119 void
120 FileListForm::OnActionPerformed(const Control& source, int actionId)
121 {
122         AppLogDebug("ENTER");
123         SceneManager* pSceneManager = SceneManager::GetInstance();
124         TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager", GetErrorMessage(GetLastResult()));
125
126         switch (actionId)
127         {
128         case IDA_FOOTER_EDIT:
129         {
130                 if (pSceneManager->GetCurrentSceneId() == IDSCN_ALL_LIST)
131                 {
132                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST_EDITOR));
133                 }
134                 else if (pSceneManager->GetCurrentSceneId() == IDSCN_IMAGE_LIST)
135                 {
136                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR));
137                 }
138                 else if (pSceneManager->GetCurrentSceneId() == IDSCN_VIDEO_LIST)
139                 {
140                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_VIDEO_LIST_EDITOR));
141                 }
142                 else
143                 {
144                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST_EDITOR));
145                 }
146         }
147         break;
148
149         case IDA_FOOTER_SLIDESHOW:
150         {
151
152                 if (__pPopUp != null)
153                 {
154                         __pPopUp->SetShowState(true);
155                         __pPopUp->Show();
156                 }
157         }
158         break;
159
160         case IDA_FOOTER_CAMERA:
161         {
162                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
163                 pDataList->Construct();
164                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_CAMERA_ALLOW_SWITCH), new (std::nothrow) String(APPCONTROL_DATA_TRUE));
165                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_CAMERA, APPCONTROL_OPERATION_ID_CREATE_CONTENT,
166                                 null, new (std::nothrow) String(APPCONTROL_MIME_IMAGE_JPG), pDataList, null);
167         }
168         break;
169
170         default:
171                 break;
172         }
173         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
174 }
175
176 void
177 FileListForm::OnFormBackRequested(Form& source)
178 {
179         AppLogDebug("ENTER");
180         SceneManager* pSceneManager = SceneManager::GetInstance();
181         TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager", GetErrorMessage(GetLastResult()));
182
183         pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_ALBUM_LIST));
184         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
185 }
186
187 result
188 FileListForm::InitializeFooter(void)
189 {
190         AppLogDebug("ENTER");
191         result r = E_SUCCESS;
192         Footer* pFooter = GetFooter();
193         TryReturn(pFooter != null, E_FAILURE, "[%s] fail to get the Footer.", GetErrorMessage(GetLastResult()));
194
195         pFooter->RemoveAllItems();
196         pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON);
197
198         FooterItem itemCamera;
199         itemCamera.Construct(IDA_FOOTER_CAMERA);
200         Bitmap* pBitmapCamera = ResourceManager::GetBitmapN(IDB_CONTROLBAR_CAMERA);
201         if (pBitmapCamera != null)
202         {
203                 itemCamera.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pBitmapCamera);
204         }
205         pFooter->AddItem(itemCamera);
206
207
208         if (__pOptionMenu != null)
209         {
210                 delete __pOptionMenu;
211                 __pOptionMenu = null;
212         }
213
214         __pOptionMenu = new (std::nothrow) OptionMenu();
215         __pOptionMenu->Construct();
216
217         if (__pPresentationModel->GetCurrentAlbumContentInfoCount() > 1)
218         {
219                 __pOptionMenu->AddItem(ResourceManager::GetString(L"IDS_MEDIABR_OPT_SLIDESHOW"), IDA_FOOTER_SLIDESHOW);
220         }
221
222         if (__pPresentationModel->GetCurrentAlbumContentInfoCount() == 0)
223         {
224                 __pOptionMenu->SetEnabled(false);
225         }
226         else
227         {
228                 __pOptionMenu->AddItem(ResourceManager::GetString(L"IDS_COM_HEADER_EDIT"), IDA_FOOTER_EDIT);
229                 __pOptionMenu->AddActionEventListener(*this);
230         }
231
232         pFooter->AddActionEventListener(*this);
233         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
234
235         return r;
236 }
237
238 void
239 FileListForm::SetTitleText(const String& titleText)
240 {
241         AppLogDebug("ENTER");
242         Header* pHeader = GetHeader();
243         TryReturnVoid(pHeader != null, "[%s] fail to get the Header.", GetErrorMessage(GetLastResult()));
244         pHeader->SetTitleText(titleText);
245         pHeader->Show();
246         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
247 }
248
249 void
250 FileListForm::OnSlideSettingPopUpItemSelected(int index)
251 {
252         if (__pPopUp != NULL)
253         {
254                 __pPopUp->SetShowState(false);
255         }
256
257         if (index == 0)
258         {
259                 result r = E_SUCCESS;
260                 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
261                 pArrayList->Construct();
262                 int loopCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
263
264                 for (int i = 0; i < loopCount; ++i)
265                 {
266                         pArrayList->Add(new (std::nothrow) String(__pPresentationModel->GetContentFilePath(i)));
267                 }
268
269                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
270                 pDataList->Construct();
271                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE), new (std::nothrow) String(APPCONTROL_DATA_SLIDE_SHOW));
272                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
273
274                 r = __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_IMAGE, APPCONTROL_OPERATION_ID_VIEW, null,
275                                 new (std::nothrow) String(APPCONTROL_MIME_IMAGE_ALL), pDataList, null);
276
277                 if (r == E_MAX_EXCEEDED)
278                 {
279                         MessageBox messageBox;
280                         messageBox.Construct(L"", ResourceManager::GetString(L"IDS_RCS_BODY_MAXIMUM_NUMBER_OF_FILES_EXCEEDED"),
281                                         MSGBOX_STYLE_NONE, 3000);
282                         int modalResult;
283                         messageBox.ShowAndWait(modalResult);
284                 }
285         }
286         else if (index == 1)
287         {
288                 SceneManager* pSceneManager = SceneManager::GetInstance();
289                 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager", GetErrorMessage(GetLastResult()));
290
291                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SETTING_MAIN));
292         }
293 }
294
295 void
296 FileListForm::SetMenuState(bool state)
297 {
298         __menuState = state;
299 }
300
301 void
302 FileListForm::OnFormMenuRequested (Tizen::Ui::Controls::Form &source)
303 {
304
305         if (__menuState == true )
306         {
307                 InitializeFooter();
308
309                 if ( __pOptionMenu == null )
310                 {
311                         return ;
312                 }
313
314                 __pOptionMenu->SetShowState(true);
315                 __pOptionMenu->Show();
316         }
317
318 }