coding guidelines update
[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.0 (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 "GlTypes.h"
29
30 using namespace Tizen::App;
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::Graphics;
34 using namespace Tizen::Ui;
35 using namespace Tizen::Ui::Controls;
36 using namespace Tizen::Ui::Scenes;
37 using namespace Tizen::Content;
38
39 FileListForm::FileListForm(void)
40         : __pContextMenuMore(null)
41         , __pPresentationModel(null)
42 {
43         AppLogDebug("ENTER");
44         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
45 }
46
47 FileListForm::~FileListForm(void)
48 {
49         AppLogDebug("ENTER");
50         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
51 }
52
53 result
54 FileListForm::Initialize(void)
55 {
56         AppLogDebug("ENTER");
57         result r = Form::Construct(IDL_FORM_FILE_LIST);
58         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
59
60         return r;
61 }
62 result
63 FileListForm::OnInitializing(void)
64 {
65         AppLogDebug("ENTER");
66         Header* pHeader = GetHeader();
67         TryReturn(pHeader != null, E_FAILURE, "[%s] fail to get the Header.", GetErrorMessage(GetLastResult()));
68
69         __pPresentationModel = FileListPresentationModel::GetInstance();
70         __pPresentationModel->ClearThumbnailRequests();
71
72         __pPopUp = new (std::nothrow) SlideShowPopUp();
73
74         if (__pPopUp != null)
75         {
76                 __pPopUp->Initialize();
77                 __pPopUp->SetEventListner(this);
78                 AddControl(*__pPopUp);
79         }
80
81         InitializeFooter();
82         SetFormBackEventListener(this);
83         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
84
85         return E_SUCCESS;
86 }
87
88 result
89 FileListForm::OnTerminating(void)
90 {
91         AppLogDebug("ENTER");
92
93         if (__pContextMenuMore != null)
94         {
95                 delete __pContextMenuMore;
96                 __pContextMenuMore = null;
97         }
98         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
99
100         return E_SUCCESS;
101 }
102
103 void
104 FileListForm::OnContentUpdated()
105 {
106         AppLogDebug("ENTER");
107         SceneManager* pSceneManager = SceneManager::GetInstance();
108         static_cast<AllListPanel*>(pSceneManager->GetCurrentScene()->GetPanel())->Refresh();
109         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
110 }
111
112 void
113 FileListForm::OnActionPerformed(const Control& source, int actionId)
114 {
115         AppLogDebug("ENTER");
116         SceneManager* pSceneManager = SceneManager::GetInstance();
117         TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager", GetErrorMessage(GetLastResult()));
118
119         switch (actionId)
120         {
121         case IDA_FOOTER_MORE:
122         {
123                 AppLogDebug("ITEMCOUNT(%d)", __pPresentationModel->GetCurrentAlbumContentInfoCount());
124
125                 InitializeFooter();
126
127                 if (__pContextMenuMore->GetShowState() == false)
128                 {
129                         Rectangle rect = source.GetBounds();
130                         __pContextMenuMore->SetAnchorPosition(Point(rect.width/8, rect.y));
131                         __pContextMenuMore->SetShowState(true);
132                         __pContextMenuMore->Show();
133                 }
134                 else
135                 {
136                         __pContextMenuMore->SetShowState(false);
137                 }
138                 break;
139         }
140         case IDA_FOOTER_EDIT:
141         {
142                 if (pSceneManager->GetCurrentSceneId() == IDSCN_ALL_LIST)
143                 {
144                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST_EDITOR));
145                 }
146                 else if (pSceneManager->GetCurrentSceneId() == IDSCN_IMAGE_LIST)
147                 {
148                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR));
149                 }
150                 else if (pSceneManager->GetCurrentSceneId() == IDSCN_VIDEO_LIST)
151                 {
152                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_VIDEO_LIST_EDITOR));
153                 }
154                 else
155                 {
156                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST_EDITOR));
157                 }
158                 break;
159         }
160         case IDA_FOOTER_SLIDESHOW:
161         {
162
163                 if (__pPopUp != null)
164                 {
165                         __pPopUp->SetShowState(true);
166                         __pPopUp->Show();
167                 }
168
169                 break;
170         }
171         case IDA_FOOTER_CAMERA:
172         {
173                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
174                 pDataList->Construct();
175                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_CAMERA_ALLOW_SWITCH), new (std::nothrow) String(APPCONTROL_DATA_TRUE));
176                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_CAMERA, APPCONTROL_OPERATION_ID_CREATE_CONTENT,
177                                 null, new (std::nothrow) String(APPCONTROL_MIME_IMAGE_JPG), pDataList, null);
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 result
198 FileListForm::InitializeFooter(void)
199 {
200         AppLogDebug("ENTER");
201         result r = E_SUCCESS;
202         Footer* pFooter = GetFooter();
203         TryReturn(pFooter != null, E_FAILURE, "[%s] fail to get the Footer.", GetErrorMessage(GetLastResult()));
204
205         pFooter->RemoveAllItems();
206         pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON);
207
208         ButtonItem footerMore;
209         footerMore.Construct(BUTTON_ITEM_STYLE_ICON, IDA_FOOTER_MORE);
210         Bitmap* pBitmapMore = ResourceManager::GetBitmapN(IDB_CONTROLBAR_MORE);
211         if (pBitmapMore != null)
212         {
213                 footerMore.SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapMore);
214         }
215         pFooter->SetButton(BUTTON_POSITION_LEFT,footerMore);
216
217         FooterItem itemCamera;
218         itemCamera.Construct(IDA_FOOTER_CAMERA);
219         Bitmap* pBitmapCamera = ResourceManager::GetBitmapN(IDB_CONTROLBAR_CAMERA);
220         if (pBitmapCamera != null)
221         {
222                 itemCamera.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pBitmapCamera);
223         }
224         pFooter->AddItem(itemCamera);
225
226         if (__pContextMenuMore != null)
227         {
228                 delete __pContextMenuMore;
229                 __pContextMenuMore = null;
230         }
231
232         __pContextMenuMore = new (std::nothrow) ContextMenu();
233         __pContextMenuMore->Construct(Point(0, 0), CONTEXT_MENU_STYLE_LIST);
234
235         if (__pPresentationModel->GetCurrentAlbumContentInfoCount() > 1)
236         {
237                 __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_MEDIABR_BUTTON_SLIDE_SHOW"), IDA_FOOTER_SLIDESHOW);
238         }
239
240         if (__pPresentationModel->GetCurrentAlbumContentInfoCount() == 0)
241         {
242                 __pContextMenuMore->SetEnabled(false);
243         }
244         else
245         {
246                 __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_COM_HEADER_EDIT"), IDA_FOOTER_EDIT);
247                 __pContextMenuMore->SetShowState(false);
248                 __pContextMenuMore->AddActionEventListener(*this);
249         }
250
251         pFooter->SetBackButton();
252
253         pFooter->AddActionEventListener(*this);
254         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
255
256         return r;
257 }
258
259 void
260 FileListForm::SetTitleText(const String& titleText)
261 {
262         AppLogDebug("ENTER");
263         Header* pHeader = GetHeader();
264         TryReturnVoid(pHeader != null, "[%s] fail to get the Header.", GetErrorMessage(GetLastResult()));
265         pHeader->SetTitleText(titleText);
266         pHeader->Show();
267         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
268 }
269
270 void
271 FileListForm::OnSlideSettingPopUpItemSelected(int index)
272 {
273         if (__pPopUp != NULL)
274         {
275                 __pPopUp->SetShowState(false);
276         }
277
278         if (index == 0)
279         {
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                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_IMAGE, APPCONTROL_OPERATION_ID_VIEW, null,
295                                 new (std::nothrow) String(APPCONTROL_MIME_IMAGE_ALL), pDataList, null);
296         }
297         else if (index == 1)
298         {
299                 SceneManager* pSceneManager = SceneManager::GetInstance();
300                 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager", GetErrorMessage(GetLastResult()));
301
302                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SETTING_MAIN));
303         }
304 }