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