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