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