Initialize Tizen 2.3
[apps/osp/Gallery.git] / src / GlVideoListPanel.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                GlVideoListPanel.cpp
19  * @brief               This is the implementation file for VideoListPanel class.
20  */
21
22 #include <FContent.h>
23 #include <FMedia.h>
24 #include "GlAlbumInfo.h"
25 #include "GlCommonUtil.h"
26 #include "GlFileListForm.h"
27 #include "GlFileListPresentationModel.h"
28 #include "GlTypes.h"
29 #include "GlVideoListPanel.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 int H_VIDEO_ITEM = 160;
42 static const int GAP_W_VIDEO_TITLE = 16+172+16;
43 static const int GAP_H_VIDEO_TITLE = 22;
44 static const int W_VIDEO_TITLE = (16+172+16)+(16+64+16);
45 static const int H_VIDEO_TITLE = 64;
46 static const int FONT_SIZE_TITLE = 36;
47 static const int GAP_W_VIDEO_DURATION = 16+172+16;
48 static const int GAP_H_VIDEO_DURATION = 22+64;
49 static const int W_VIDEO_DURATION = (16+172+16)+(16+64+16);
50 static const int H_VIDEO_DURATION = 48;
51 static const int FONT_SIZE_DURATION = 32;
52 static const int W_CLIENT_REGION = 720;
53 static const Rectangle RECT_INITIAL (0, 0, 10, 10);
54 static const Rectangle RECT_VIDEO_THUMBNAIL (16, 16, 172, 128);
55
56 VideoListPanel::VideoListPanel(void)
57         : __itemCount(0)
58         , __pContentListView(null)
59         , __pPresentationModel(0)
60 {
61         AppLogDebug("ENTER");
62         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
63 }
64
65 VideoListPanel::~VideoListPanel(void)
66 {
67         AppLogDebug("ENTER");
68         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
69 }
70
71 result
72 VideoListPanel::Initialize(void)
73 {
74         AppLogDebug("ENTER");
75         result r = Construct(RECT_INITIAL);
76         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
77
78         return r;
79 }
80
81 result
82 VideoListPanel::OnInitializing(void)
83 {
84         AppLogDebug("ENTER");
85         const Form* pForm = dynamic_cast<Form*>(GetParent());
86         TryReturn(pForm != null, E_FAILURE, "[%s] fail to get the form.", GetErrorMessage(GetLastResult()));
87
88         __pPresentationModel = FileListPresentationModel::GetInstance();
89         __pPresentationModel->ClearThumbnailRequests();
90         __pPresentationModel->AddPresentationModelListener(this);
91
92         Rectangle clientAreaBounds = pForm->GetClientAreaBounds();
93         clientAreaBounds.x = clientAreaBounds.y = 0;
94         SetBounds(clientAreaBounds);
95         __pContentListView = new (std::nothrow) ListView();
96         __pContentListView->Construct(Rectangle(0, 0, W_CLIENT_REGION, clientAreaBounds.height), true, false);
97         Bitmap* pBitmapEmpty = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
98         if (pBitmapEmpty != null)
99         {
100                 __pContentListView->SetBitmapOfEmptyList(pBitmapEmpty);
101                 delete pBitmapEmpty;
102         }
103         __pContentListView->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
104         __pContentListView->SetItemProvider(*this);
105         __pContentListView->AddListViewItemEventListener(*this);
106         AddControl(__pContentListView);
107         __pContentListView->SetShowState(true);
108         __itemCount = 0;
109         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
110
111         return E_SUCCESS;
112 }
113
114 result
115 VideoListPanel::OnTerminating(void)
116 {
117         AppLogDebug("ENTER");
118         __pPresentationModel->RemovePresentationModelListener(*this);
119         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
120
121         return E_SUCCESS;
122 }
123
124 int
125 VideoListPanel::GetItemCount(void)
126 {
127         AppLogDebug("ENTER");
128         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
129
130         return __itemCount;
131 }
132
133 ListItemBase*
134 VideoListPanel::CreateItem(int index, int itemWidth)
135 {
136         AppLogDebug("ENTER : index(%d)", index);
137         CustomItem* pItem = new (std::nothrow) CustomItem();
138         pItem->Construct(Dimension(itemWidth, H_VIDEO_ITEM), LIST_ANNEX_STYLE_NORMAL);
139
140         Bitmap* pBitmap = null;
141         String* pItemText = null;
142         String* pTitle = null;
143         String* pDuration = null;
144
145         result r = __pPresentationModel->GetThumbnailVideoInSyncCacheN(index, pItemText, pBitmap, pDuration);
146         if (pBitmap == null || r == E_FAILURE)
147         {
148                 __pPresentationModel->RequestThumbnail(index);
149                 pBitmap = CommonUtil::GetEmptyThumbnailN();
150         }
151
152         pItem->AddElement(RECT_VIDEO_THUMBNAIL, IDA_FORMAT_THUMBNAIL, *pBitmap);
153         pTitle = new (std::nothrow) String(SINGLE_SPACE);
154         Rectangle titleRect(GAP_W_VIDEO_TITLE, GAP_H_VIDEO_TITLE, itemWidth-W_VIDEO_TITLE, H_VIDEO_TITLE);
155         pItem->AddElement(titleRect, IDA_FORMAT_TITLE, *pTitle, FONT_SIZE_TITLE,
156                         Color::GetColor(COLOR_ID_BLACK), null, null, false);
157
158         Rectangle durationRect(GAP_W_VIDEO_DURATION, GAP_H_VIDEO_DURATION, itemWidth-W_VIDEO_DURATION,
159                         H_VIDEO_DURATION);
160         pItem->AddElement(durationRect, IDA_FORMAT_DURATION, *pDuration, FONT_SIZE_DURATION,
161                         Color::GetColor(COLOR_ID_GREY), null, null, false);
162
163         if (pBitmap != null)
164         {
165                 delete pBitmap;
166         }
167         if (pItemText != null)
168         {
169                 delete pItemText;
170         }
171         if (pTitle != null)
172         {
173                 delete pTitle;
174         }
175         if (pDuration != null)
176         {
177                 delete pDuration;
178         }
179         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
180
181         return pItem;
182 }
183
184 bool
185 VideoListPanel::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
186 {
187         AppLogDebug("ENTER");
188         delete pItem;
189         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
190
191         return true;
192 }
193
194 void
195 VideoListPanel::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
196 {
197         AppLogDebug("ENTER");
198         if (status == LIST_ITEM_STATUS_SELECTED)
199         {
200                 IList* pList = new (std::nothrow) ArrayList();
201                 int loopCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
202
203                 for (int i = 0; i < loopCount; ++i)
204                 {
205                         pList->Add(new (std::nothrow) String(__pPresentationModel->GetContentFilePath(i)));
206                 }
207                 String listIndex;
208                 listIndex.Format(10, L"%d", index);
209
210                 const String mimeType = APPCONTROL_MIME_IMAGE_ALL;
211                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
212                 pDataList->Construct();
213                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE), new (std::nothrow) String(APPCONTROL_DATA_IMAGE));
214                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pList);
215                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_INDEX), new (std::nothrow) String(listIndex));
216
217                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_IMAGE, APPCONTROL_OPERATION_ID_VIEW, null,
218                                 &mimeType, pDataList, null);
219         }
220         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
221 }
222
223 void
224 VideoListPanel::OnFileInfoChanged(const ContentType contentType)
225 {
226         AppLogDebug("ENTER");
227         if (contentType == CONTENT_TYPE_VIDEO)
228         {
229                 __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
230                 __pContentListView->UpdateList();
231         }
232         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
233 }
234
235 void
236 VideoListPanel::OnThumbnailDecoded(const int index)
237 {
238         AppLogDebug("ENTER : index(%d)", index);
239         if (index >= 0)
240         {
241                 __pContentListView->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
242         }
243         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
244 }
245
246 void
247 VideoListPanel::OnSceneActivatedN(const SceneId& previousSceneId,
248                                                                 const SceneId& currentSceneId, IList* pArgs)
249 {
250         AppLogDebug("ENTER");
251         __pPresentationModel = FileListPresentationModel::GetInstance();
252
253         if (currentSceneId == IDSCN_VIDEO_LIST)
254         {
255                 __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_VIDEO);
256                 __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
257                 __pContentListView->UpdateList();
258         }
259
260         SceneManager* pSceneManager = SceneManager::GetInstance();
261         AppAssert(pSceneManager);
262         if (pSceneManager->GetCurrentSceneId() == IDSCN_VIDEO_LIST)
263         {
264                 FileListForm* pFileListForm = dynamic_cast<FileListForm*>(pSceneManager->GetCurrentScene()->GetForm());
265                 if (pFileListForm != null)
266                 {
267                         pFileListForm->SetTitleText(__pPresentationModel->GetCurrentAlbumName());
268                 }
269         }
270         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
271 }