Send mime to Camera
[apps/osp/Gallery.git] / src / GlAllListPanel.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                GlAllListPanel.cpp
19  * @brief               This is the implementation file for AllListPanel class.
20  */
21
22 #include <FContent.h>
23 #include <FMedia.h>
24 #include "GlAlbumInfo.h"
25 #include "GlAllListPanel.h"
26 #include "GlCommonUtil.h"
27 #include "GlFileListForm.h"
28 #include "GlFileListPresentationModel.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::Content;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Media;
37 using namespace Tizen::Ui;
38 using namespace Tizen::Ui::Controls;
39 using namespace Tizen::Ui::Scenes;
40
41 static const Rectangle RECT_INITIAL (0, 0, 10, 10);
42 static const int W_CLIENT = 720;
43 static const int H_CONTENT_MARGIN = 9;
44 static const int W_CONTENT_MARGIN = 6;
45 static const int W_CONTENT_SPACE = 6;
46 static const int H_CONTENT_SPACE = 6;
47
48 AllListPanel::AllListPanel()
49         : __pContentIconListView(null)
50         , __itemCount(0)
51         , __pPresentationModel(null)
52 {
53         AppLogDebug("ENTER");
54         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
55 }
56
57 AllListPanel::~AllListPanel()
58 {
59         AppLogDebug("ENTER");
60         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
61 }
62
63 void
64 AllListPanel::Refresh(void)
65 {
66         AppLogDebug("ENTER");
67         if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
68         {
69                 if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
70                 {
71                         __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_IMAGE);
72                 }
73                 else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
74                 {
75                         __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_VIDEO);
76                 }
77                 else
78                 {
79                         __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_VIDEO);
80                 }
81         }
82         else
83         {
84                 __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_ALL);
85         }
86
87         __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
88         __pContentIconListView->UpdateList();
89         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
90 }
91
92 result
93 AllListPanel::Initialize(void)
94 {
95         AppLogDebug("ENTER");
96         result r = Construct(RECT_INITIAL);
97         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
98
99         return r;
100 }
101
102 result
103 AllListPanel::OnInitializing(void)
104 {
105         AppLogDebug("ENTER");
106         const Form* pForm = dynamic_cast<Form*>(GetParent());
107         AppAssert(pForm);
108
109         __pPresentationModel = FileListPresentationModel::GetInstance();
110         __pPresentationModel->ClearThumbnailRequests();
111         __pPresentationModel->AddPresentationModelListener(this);
112
113         Rectangle clientAreaBounds = pForm->GetClientAreaBounds();
114         clientAreaBounds.x = clientAreaBounds.y = 0;
115         SetBounds(clientAreaBounds);
116
117         __pContentIconListView = new (std::nothrow) IconListView();
118         __pContentIconListView->Construct(Rectangle(0, 0, W_CLIENT, clientAreaBounds.height),
119                         DIMENSION_DEFAULT_THUMBNAIL, ICON_LIST_VIEW_STYLE_NORMAL, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
120         Bitmap* pBitmapEmpty = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
121         if (pBitmapEmpty != null)
122         {
123                 __pContentIconListView->SetBitmapOfEmptyList(pBitmapEmpty);
124                 delete pBitmapEmpty;
125         }
126         __pContentIconListView->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
127         __pContentIconListView->SetMargin(MARGIN_TYPE_LEFT, W_CONTENT_MARGIN);
128         __pContentIconListView->SetMargin(MARGIN_TYPE_RIGHT, W_CONTENT_MARGIN);
129         __pContentIconListView->SetMargin(MARGIN_TYPE_TOP, H_CONTENT_MARGIN);
130         __pContentIconListView->SetItemSpacing(W_CONTENT_SPACE, H_CONTENT_SPACE);
131         __pContentIconListView->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
132         __pContentIconListView->SetItemProvider(*this);
133         __pContentIconListView->SetCheckBoxPosition(ICON_LIST_VIEW_CHECK_BOX_POSITION_TOP_RIGHT);
134         __pContentIconListView->AddIconListViewItemEventListener(*this);
135         __pContentIconListView->SetTouchAnimationEnabled(false);
136         result r = AddControl(*__pContentIconListView);
137         __pContentIconListView->SetShowState(true);
138
139         __itemCount = 0;
140         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
141
142         return r;
143 }
144
145 result
146 AllListPanel::OnTerminating(void)
147 {
148         AppLogDebug("ENTER");
149         __pPresentationModel->RemovePresentationModelListener(*this);
150         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
151
152         return E_SUCCESS;
153 }
154
155 int
156 AllListPanel::GetItemCount(void)
157 {
158         AppLogDebug("ENTER");
159         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
160
161         return __itemCount;
162 }
163
164 IconListViewItem*
165 AllListPanel::CreateItem(int index)
166 {
167         AppLogDebug("ENTER : index(%d)", index);
168         Bitmap* pBitmap=null;
169         String* pItemText=null;
170         result r = __pPresentationModel->GetThumbnailInSyncCacheN(index, pItemText, pBitmap);
171         if (r != E_SUCCESS)
172         {
173                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
174                 return null;
175         }
176
177         IconListViewItem* pIconListviewItem = new (std::nothrow) IconListViewItem();
178
179         if (pBitmap == null)
180         {
181                 __pPresentationModel->RequestThumbnail(index);
182                 pBitmap = CommonUtil::GetEmptyThumbnailN();
183         }
184
185         if (pItemText == null)
186         {
187                 pItemText = new (std::nothrow) String(ResourceManager::GetString(L"EMPTY_SPACE"));
188         }
189         else if ((*pItemText) != ResourceManager::GetString(L"EMPTY_SPACE"))
190         {
191                 delete pItemText;
192                 pItemText = new (std::nothrow) String(ResourceManager::GetString(L"EMPTY_SPACE"));
193         }
194
195         if (pItemText != null)
196         {
197                 pIconListviewItem->Construct(*pBitmap, pItemText);
198         }
199
200         if (pBitmap != null)
201         {
202                 delete pBitmap;
203         }
204         if (pItemText != null)
205         {
206                 delete pItemText;
207         }
208         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
209
210         return pIconListviewItem;
211 }
212
213 bool
214 AllListPanel::DeleteItem(int index, IconListViewItem* pItem)
215 {
216         AppLogDebug("ENTER : index(%d)", index);
217         delete pItem;
218         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
219
220         return true;
221 }
222
223 void
224 AllListPanel::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
225 {
226         AppLogDebug("ENTER");
227         if (status == ICON_LIST_VIEW_ITEM_SELECTED)
228         {
229                 if (__pPresentationModel->GetCurrentAlbumContentInfoCount() <= 0)
230                 {
231                         AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
232                         return;
233                 }
234
235                 ArrayList* pArrayList = new (std::nothrow) ArrayList();
236                 pArrayList->Construct();
237                 int loopCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
238
239                 for (int i = 0 ; i < loopCount; ++i)
240                 {
241                         pArrayList->Add(new (std::nothrow) String(__pPresentationModel->GetContentFilePath(i)));
242                 }
243
244                 String listIndex;
245                 listIndex.Format(10, L"%d", index);
246
247                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
248                 pDataList->Construct();
249                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE), new (std::nothrow) String(APPCONTROL_DATA_IMAGE));
250                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), pArrayList);
251                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_INDEX), new (std::nothrow) String(listIndex));
252
253                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_IMAGE, APPCONTROL_OPERATION_ID_VIEW, null,
254                                 pDataList, null);
255
256                 String* temp;
257                 loopCount = pArrayList->GetCount();
258                 for (int i = 0; i < loopCount; ++i)
259                 {
260                         temp = static_cast<String*>(pArrayList->GetAt(i));
261                         AppLog("print temp(%ls)", temp->GetPointer());
262                 }
263         }
264         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
265 }
266
267 void
268 AllListPanel::OnFileInfoChanged(const ContentType contentType)
269 {
270         AppLogDebug("ENTER");
271         if (contentType == CONTENT_TYPE_ALL
272                 || contentType == CONTENT_TYPE_IMAGE
273                 || contentType == CONTENT_TYPE_VIDEO)
274         {
275                 __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
276                 __pContentIconListView->UpdateList();
277         }
278         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
279 }
280
281 void
282 AllListPanel::OnThumbnailDecoded(const int index)
283 {
284         AppLogDebug("ENTER : index(%d)", index);
285         if (index >= 0)
286         {
287                 __pContentIconListView->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
288         }
289         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
290 }
291
292 void
293 AllListPanel::OnSceneActivatedN(const SceneId& previousSceneId,
294                                                                 const SceneId& currentSceneId, IList* pArgs)
295 {
296         AppLogDebug("ENTER");
297         __pPresentationModel = FileListPresentationModel::GetInstance();
298
299         if (currentSceneId == IDSCN_ALL_LIST)
300         {
301                 if (previousSceneId == IDSCN_ALBUM_LIST)
302                 {
303                         AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pArgs->GetAt(0));
304                         if (pAlbumInfo == null)
305                         {
306                                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
307
308                                 return;
309                         }
310                         IList* pDirectoryList = pAlbumInfo->GetDirectoryListN();
311                         __pPresentationModel->SetCurrentAlbumInfo(pAlbumInfo->GetAlbumName(), *pDirectoryList);
312                         if (pDirectoryList != null)
313                         {
314                                 delete pDirectoryList;
315                         }
316
317                         delete pArgs;
318
319                         __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
320                         __pContentIconListView->UpdateList();
321                 }
322                 else
323                 {
324                         __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_ALL);
325                         __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
326                         __pContentIconListView->UpdateList();
327                 }
328         }
329
330         SceneManager* pSceneManager = SceneManager::GetInstance();
331         AppAssert(pSceneManager);
332         if (pSceneManager->GetCurrentSceneId() == IDSCN_ALL_LIST)
333         {
334                 FileListForm* pFileListForm = dynamic_cast<FileListForm*>(pSceneManager->GetCurrentScene()->GetForm());
335                 if (pFileListForm != null)
336                 {
337                         pFileListForm->SetTitleText(__pPresentationModel->GetCurrentAlbumName());
338                 }
339         }
340         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
341 }
342
343 void
344 AllListPanel::OnSceneDeactivated(const SceneId& currentSceneId,
345                                                                 const SceneId& nextSceneId)
346 {
347         AppLogDebug("ENTER");
348         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
349 }
350
351 void
352 AllListPanel::UpdatePanelContent()
353 {
354         AppLogDebug("ENTER");
355         Refresh();
356         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
357 }