Arrange code
[apps/osp/Gallery.git] / src / GlVideoListEditorPanel.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                GlVideoListEditorPanel.cpp
19  * @brief               This is the implementation file for VideoListEditorPanel class.
20  */
21
22 #include <FContent.h>
23 #include <FMedia.h>
24 #include "GlAlbumInfo.h"
25 #include "GlCommonUtil.h"
26 #include "GlFileListPresentationModel.h"
27 #include "GlGalleryApp.h"
28 #include "GlResourceManager.h"
29 #include "GlTypes.h"
30 #include "GlVideoListEditorPanel.h"
31 #include "GlFileListEditorForm.h"
32 #include "GlFileUpdateTimer.h"
33
34 using namespace Tizen::App;
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Content;
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Media;
40 using namespace Tizen::Ui::Controls;
41 using namespace Tizen::Ui::Scenes;
42
43 static const unsigned int COLOR_COUNT_LABEL = Color32<68, 68, 68>::Value;
44 static const unsigned int COLOR_SELECT_COUNT_FONT = Color32<255, 255, 255>::Value;
45 static const Color COLOR_THUMBNAIL_DIM (Color::GetColor(COLOR_ID_BLACK));
46 static const Rectangle RECT_VIDEO_THUMBNAIL(16, 16, 172, 128);
47 static const Rectangle RECT_INITIAL(0, 0, 10, 10);
48
49 static const int H_SELECTALL_REGION = 112;
50 static const int ALPHA_THUMBNAIL_DIM = 70;
51 static const int H_COUNT_LABEL = 48;
52 static const int COUNT_LABEL_FONT_SIZE = 33;
53 static const int LENGTH_COUNT_LABEL = 256;
54 static const int W_CLIENT_REGION = 720;
55 static const int H_VIDEO_ITEM = 160;
56 static const int GAP_W_VIDEO_TITLE = 16+172+16;
57 static const int GAP_H_VIDEO_TITLE = 22;
58 static const int W_VIDEO_TITLE = (16+172+16)+(16+64+16);
59 static const int H_VIDEO_TITLE = 64;
60 static const int FONT_SIZE_TITLE = 36;
61 static const int GAP_W_VIDEO_DURATION = 16+172+16;
62 static const int GAP_H_VIDEO_DURATION = 22+64;
63 static const int W_VIDEO_DURATION = (16+172+16)+(16+64+16);
64 static const int H_VIDEO_DURATION = 48;
65 static const int FONT_SIZE_DURATION = 32;
66
67 VideoListEditorPanel::VideoListEditorPanel(void)
68         : __pContentIconListView(null)
69         , __pCheckButton(null)
70         , __pLabelSelectCnt(null)
71         , __itemCount(0)
72         , __pPresentationModel(null)
73         , __pFileDelete(null)
74         , __pFileListEditorForm(null)
75 {
76         AppLogDebug("ENTER");
77         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
78 }
79
80 VideoListEditorPanel::~VideoListEditorPanel(void)
81 {
82         AppLogDebug("ENTER");
83         delete __pFileDelete;
84         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
85 }
86
87 result
88 VideoListEditorPanel::Initialize(void)
89 {
90         AppLogDebug("ENTER");
91         result r = Construct(RECT_INITIAL);
92         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
93
94         return r;
95 }
96
97 result
98 VideoListEditorPanel::OnInitializing(void)
99 {
100         AppLogDebug("ENTER");
101         const Form* pForm = dynamic_cast<Form*>(GetParent());
102         TryReturn(pForm != null, E_FAILURE, "[%s] fail to get the form.", GetErrorMessage(GetLastResult()));
103
104         __pPresentationModel = FileListPresentationModel::GetInstance();
105         __pPresentationModel->ClearThumbnailRequests();
106         __pPresentationModel->AddPresentationModelListener(this);
107         __itemCount = 0;
108
109         Rectangle clientAreaBounds = pForm->GetClientAreaBounds();
110         clientAreaBounds.x = clientAreaBounds.y = 0;
111         SetBounds(clientAreaBounds);
112
113         if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
114         {
115                 __pContentIconListView = new (std::nothrow) ListView();
116
117                 if (__pPresentationModel->GetAppControlSelectionMode() == APPCONTROL_SELECTION_MODE_MULTIPLE)
118                 {
119                         __pContentIconListView->Construct(Rectangle(0, 0, clientAreaBounds.width, clientAreaBounds.height), true, false);
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->SetItemProvider(*this);
128                         __pContentIconListView->AddListViewItemEventListener(*this);
129                         AddControl(__pContentIconListView);
130                         __pContentIconListView->SetShowState(true);
131
132                         __pLabelSelectCnt = new (std::nothrow) Label();
133                         __pLabelSelectCnt->Construct(Rectangle(0, clientAreaBounds.height - H_COUNT_LABEL,
134                                         clientAreaBounds.width, H_COUNT_LABEL), ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED"));
135                         __pLabelSelectCnt->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
136                         __pLabelSelectCnt->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
137                         __pLabelSelectCnt->SetBackgroundColor(COLOR_COUNT_LABEL);
138                         __pLabelSelectCnt->SetTextColor(Color(COLOR_SELECT_COUNT_FONT));
139                         __pLabelSelectCnt->SetTextConfig(COUNT_LABEL_FONT_SIZE, LABEL_TEXT_STYLE_BOLD);
140                         AddControl(__pLabelSelectCnt);
141                 }
142                 else
143                 {
144                         __pContentIconListView->Construct(Rectangle(0, 0, clientAreaBounds.width,
145                                         clientAreaBounds.height), true, false);
146                         Bitmap* pBitmapEmpty = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
147                         if (pBitmapEmpty != null)
148                         {
149                                 __pContentIconListView->SetBitmapOfEmptyList(pBitmapEmpty);
150                                 delete pBitmapEmpty;
151                         }
152                         __pContentIconListView->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
153                         __pContentIconListView->SetItemProvider(*this);
154                         __pContentIconListView->AddListViewItemEventListener(*this);
155                         AddControl(__pContentIconListView);
156                         __pContentIconListView->SetShowState(true);
157                 }
158         }
159         else
160         {
161                 __pContentIconListView = new (std::nothrow) ListView();
162                 __pContentIconListView->Construct(
163                                 Rectangle(0, H_SELECTALL_REGION, W_CLIENT_REGION, clientAreaBounds.height - H_SELECTALL_REGION),
164                                 true, false);
165                 Bitmap* pBitmapEmpty = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
166                 if (pBitmapEmpty != null)
167                 {
168                         __pContentIconListView->SetBitmapOfEmptyList(pBitmapEmpty);
169                         delete pBitmapEmpty;
170                 }
171                 __pContentIconListView->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
172                 __pContentIconListView->SetItemProvider(*this);
173                 __pContentIconListView->AddListViewItemEventListener(*this);
174                 AddControl(__pContentIconListView);
175                 __pContentIconListView->SetShowState(true);
176
177                 __pLabelSelectCnt = new (std::nothrow) Label();
178                 __pLabelSelectCnt->Construct(
179                                 Rectangle(0, clientAreaBounds.height - H_COUNT_LABEL, clientAreaBounds.width, H_COUNT_LABEL),
180                                 ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED"));
181                 __pLabelSelectCnt->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
182                 __pLabelSelectCnt->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
183                 __pLabelSelectCnt->SetBackgroundColor(COLOR_COUNT_LABEL);
184                 __pLabelSelectCnt->SetTextColor(Color(COLOR_SELECT_COUNT_FONT));
185                 __pLabelSelectCnt->SetTextConfig(COUNT_LABEL_FONT_SIZE, LABEL_TEXT_STYLE_BOLD);
186                 AddControl(__pLabelSelectCnt);
187
188         }
189         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
190
191         return E_SUCCESS;
192 }
193
194 result
195 VideoListEditorPanel::OnTerminating(void)
196 {
197         AppLogDebug("ENTER");
198         __pPresentationModel->RemovePresentationModelListener(*this);
199         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
200
201         return E_SUCCESS;
202 }
203
204 int
205 VideoListEditorPanel::GetItemCount(void)
206 {
207         AppLogDebug("ENTER");
208         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
209
210         return __itemCount;
211 }
212
213 ListItemBase*
214 VideoListEditorPanel::CreateItem(int index, int itemWidth)
215 {
216         AppLogDebug("ENTER : index(%d)", index);
217         CustomItem* pItem = new (std::nothrow) CustomItem();
218
219         Bitmap* pBitmap = null;
220         String* pItemText = null;
221         String* pTitle = null;
222         String* pDuration = null;
223
224         result r = __pPresentationModel->GetThumbnailVideoInSyncCacheN(index, pItemText, pBitmap, pDuration);
225         if (pBitmap == null || r == E_FAILURE)
226         {
227                 __pPresentationModel->RequestThumbnail(index);
228                 pBitmap = CommonUtil::GetEmptyThumbnailN();
229         }
230
231         if (pItemText == null)
232         {
233                 pItemText = new (std::nothrow) String(ResourceManager::GetString(L"EMPTY_SPACE"));
234         }
235
236         pTitle = new (std::nothrow) String(ResourceManager::GetString(L"EMPTY_SPACE"));
237
238         if (pDuration == null)
239         {
240                 pDuration = new (std::nothrow) String(ResourceManager::GetString(L"EMPTY_SPACE"));
241         }
242
243         if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
244         {
245                 if (__pPresentationModel->GetAppControlSelectionMode() == APPCONTROL_SELECTION_MODE_MULTIPLE)
246                 {
247                         pItem->Construct(Dimension(itemWidth, H_VIDEO_ITEM), LIST_ANNEX_STYLE_MARK);
248
249                         if (__pContentIconListView->IsItemChecked(index) == true)
250                         {
251                                 if (pBitmap != null)
252                                 {
253                                         BufferInfo bufferInfo;
254                                         pBitmap->Lock(bufferInfo, INFINITE);
255                                         pBitmap->Unlock();
256
257                                         Color dimColor(COLOR_THUMBNAIL_DIM);
258                                         dimColor.SetAlpha(ALPHA_THUMBNAIL_DIM);
259
260                                         Canvas canvas;
261                                         canvas.Construct(bufferInfo);
262                                         canvas.FillRectangle(dimColor, canvas.GetBounds());
263
264                                         Bitmap* pSelectedBitmap = new (std::nothrow) Bitmap();
265                                         pSelectedBitmap->Construct(canvas, canvas.GetBounds());
266                                         pItem->AddElement(RECT_VIDEO_THUMBNAIL, IDA_FORMAT_THUMBNAIL, *pBitmap, pSelectedBitmap);
267                                         delete pSelectedBitmap;
268                                 }
269                                 else
270                                 {
271                                         AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
272                                         delete pTitle;
273                                         delete pItemText;
274                                         delete pDuration;
275                                         return null;
276                                 }
277                         }
278                         else
279                         {
280                                 pItem->AddElement(RECT_VIDEO_THUMBNAIL, IDA_FORMAT_THUMBNAIL, *pBitmap);
281                         }
282
283                         if (pTitle == null)
284                         {
285                                 pTitle = new (std::nothrow) String(SINGLE_SPACE);
286                         }
287                         else if (pTitle->IsEmpty() == true)
288                         {
289                                 delete pTitle;
290                                 pTitle = new (std::nothrow) String(SINGLE_SPACE);
291                         }
292
293                         Rectangle titleRect(GAP_W_VIDEO_TITLE, GAP_H_VIDEO_TITLE, itemWidth-W_VIDEO_TITLE, H_VIDEO_TITLE);
294                         pItem->AddElement(titleRect, IDA_FORMAT_TITLE, *pTitle, FONT_SIZE_TITLE,
295                                         Color::GetColor(COLOR_ID_BLACK),null,null,false);
296
297                         Rectangle durationRect(GAP_W_VIDEO_DURATION, GAP_H_VIDEO_DURATION, itemWidth-W_VIDEO_DURATION,
298                                         H_VIDEO_DURATION);
299                         pItem->AddElement(durationRect, IDA_FORMAT_DURATION, *pDuration, FONT_SIZE_DURATION,
300                                         Color::GetColor(COLOR_ID_GREY),null,null,false);
301                 }
302                 else
303                 {
304                         pItem->Construct(Dimension(itemWidth, H_VIDEO_ITEM), LIST_ANNEX_STYLE_NORMAL);
305                         pItem->AddElement(RECT_VIDEO_THUMBNAIL, IDA_FORMAT_THUMBNAIL, *pBitmap);
306
307                         if (pTitle == null)
308                         {
309                                 pTitle = new (std::nothrow) String(SINGLE_SPACE);
310                         }
311                         else if (pTitle->IsEmpty() == true)
312                         {
313                                 delete pTitle;
314                                 pTitle = new (std::nothrow) String(SINGLE_SPACE);
315                         }
316
317                         Rectangle titleRect(GAP_W_VIDEO_TITLE, GAP_H_VIDEO_TITLE, itemWidth-W_VIDEO_TITLE, H_VIDEO_TITLE);
318                         pItem->AddElement(titleRect, IDA_FORMAT_TITLE, *pTitle, FONT_SIZE_TITLE,
319                                         Color::GetColor(COLOR_ID_BLACK), null, null, false);
320
321                         Rectangle durationRect(GAP_W_VIDEO_DURATION, GAP_H_VIDEO_DURATION, itemWidth-W_VIDEO_DURATION,
322                                         H_VIDEO_DURATION);
323                         pItem->AddElement(durationRect, IDA_FORMAT_DURATION, *pDuration, FONT_SIZE_DURATION,
324                                         Color::GetColor(COLOR_ID_GREY), null, null, false);
325                 }
326         }
327         else
328         {
329                 pItem->Construct(Dimension(itemWidth, H_VIDEO_ITEM), LIST_ANNEX_STYLE_MARK);
330                 if (__pContentIconListView->IsItemChecked(index) == true)
331                 {
332                         if (pBitmap != null)
333                         {
334                                 BufferInfo bufferInfo;
335                                 pBitmap->Lock(bufferInfo, INFINITE);
336                                 pBitmap->Unlock();
337                                 Color dimColor(COLOR_THUMBNAIL_DIM);
338                                 dimColor.SetAlpha(ALPHA_THUMBNAIL_DIM);
339
340                                 Canvas canvas;
341                                 canvas.Construct(bufferInfo);
342                                 canvas.FillRectangle(dimColor, canvas.GetBounds());
343
344                                 Bitmap* pSelectedBitmap = new (std::nothrow) Bitmap();
345                                 pSelectedBitmap->Construct(canvas, canvas.GetBounds());
346                                 pItem->AddElement(RECT_VIDEO_THUMBNAIL, IDA_FORMAT_THUMBNAIL, *pBitmap, pSelectedBitmap);
347                                 delete pSelectedBitmap;
348                         }
349                         else
350                         {
351                                 pItem->AddElement(RECT_VIDEO_THUMBNAIL, IDA_FORMAT_THUMBNAIL, *pBitmap);
352                         }
353                 }
354                 else
355                 {
356                         pItem->AddElement(RECT_VIDEO_THUMBNAIL, IDA_FORMAT_THUMBNAIL, *pBitmap);
357                 }
358
359                 if (pTitle == null)
360                 {
361                         pTitle = new (std::nothrow) String(SINGLE_SPACE);
362                 }
363                 else if (pTitle->IsEmpty() == true)
364                 {
365                         delete pTitle;
366                         pTitle = new (std::nothrow) String(SINGLE_SPACE);
367                 }
368
369                 Rectangle titleRect(GAP_W_VIDEO_TITLE, GAP_H_VIDEO_TITLE, itemWidth-W_VIDEO_TITLE, H_VIDEO_TITLE);
370                 pItem->AddElement(titleRect, IDA_FORMAT_TITLE, *pTitle, FONT_SIZE_TITLE,
371                                 Color::GetColor(COLOR_ID_BLACK), null, null, false);
372
373                 Rectangle durationRect(GAP_W_VIDEO_DURATION, GAP_H_VIDEO_DURATION, itemWidth - W_VIDEO_DURATION,
374                                 H_VIDEO_DURATION);
375                 pItem->AddElement(durationRect, IDA_FORMAT_DURATION, *pDuration, FONT_SIZE_DURATION,
376                                 Color::GetColor(COLOR_ID_GREY), null, null, false);
377         }
378
379         if (pBitmap != null)
380         {
381                 delete pBitmap;
382         }
383         if (pItemText != null)
384         {
385                 delete pItemText;
386         }
387         if (pTitle != null)
388         {
389                 delete pTitle;
390         }
391         if (pDuration != null)
392         {
393                 delete pDuration;
394         }
395         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
396
397         return pItem;
398 }
399
400 bool
401 VideoListEditorPanel::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
402 {
403         AppLogDebug("ENTER");
404         delete pItem;
405         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
406
407         return true;
408 }
409
410 void
411 VideoListEditorPanel::OnListViewItemStateChanged(ListView& listView, int index, int elementId,
412                 ListItemStatus status)
413 {
414         AppLogDebug("ENTER");
415
416         if (status == LIST_ITEM_STATUS_CHECKED || status == LIST_ITEM_STATUS_UNCHECKED)
417         {
418                 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
419                 {
420                         if (__pPresentationModel->GetAppControlSelectionMode() == APPCONTROL_SELECTION_MODE_MULTIPLE)
421                         {
422                                 int checkedCount = GetItemCheckedCount();
423                                 String strTmp;
424                                 if (checkedCount == 0)
425                                 {
426                                         strTmp = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
427                                 }
428                                 else if (checkedCount == 1)
429                                 {
430                                         strTmp = ResourceManager::GetString(L"IDS_VR_POP_1_ITEM_SELECTED");
431                                 }
432                                 else
433                                 {
434                                         strTmp.Format(LENGTH_COUNT_LABEL,
435                                                         ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), checkedCount);
436                                 }
437
438                                 __pLabelSelectCnt->SetText(strTmp);
439                                 __pLabelSelectCnt->RequestRedraw(true);
440                                 __pContentIconListView->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
441                         }
442                 }
443                 else
444                 {
445                         int checkedCount = GetItemCheckedCount();
446                         String strTmp;
447                         if (checkedCount == 0)
448                         {
449                                 strTmp = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
450                         }
451                         else if (checkedCount == 1)
452                         {
453                                 strTmp = ResourceManager::GetString(L"IDS_VR_POP_1_ITEM_SELECTED");
454                         }
455                         else
456                         {
457                                 strTmp.Format(LENGTH_COUNT_LABEL,
458                                                 ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), checkedCount);
459                         }
460
461                         __pLabelSelectCnt->SetText(strTmp);
462                         __pLabelSelectCnt->RequestRedraw(true);
463                         if (__pCheckButton->IsSelected())
464                         {
465                                 __pCheckButton->SetSelected(false);
466                         }
467                         __pContentIconListView->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
468                 }
469         }
470
471         if (    __pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK
472                 && __pPresentationModel->GetAppControlSelectionMode() != APPCONTROL_SELECTION_MODE_MULTIPLE)
473         {
474                 if (status == LIST_ITEM_STATUS_SELECTED)
475                 {
476                         HashMap* pMap = new (std::nothrow) HashMap(SingleObjectDeleter);
477                         result r = pMap->Construct();
478                         if (r == E_SUCCESS)
479                         {
480                                 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
481                                 pArrayList->Construct();
482
483                                 if (r == E_SUCCESS)
484                                 {
485                                         pArrayList->Add(new (std::nothrow) String(__pPresentationModel->GetContentFilePath(index)));
486                                         pMap->Add(new (std::nothrow) String(APPCONTROL_KEY_DATA_SELECTED), (Object*)pArrayList);
487
488                                         GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
489                                         if (pApp != null)
490                                         {
491                                                 pApp->SendAppControlResult(APP_CTRL_RESULT_SUCCEEDED, pMap);
492                                                 pApp->Terminate();
493                                         }
494                                         else
495                                         {
496                                                 delete pMap;
497                                         }
498                                 }
499                         }
500                         else
501                         {
502                                 delete pMap;
503                         }
504                 }
505         }
506         SetButtonState();
507         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
508 }
509
510 void
511 VideoListEditorPanel::OnFileInfoChanged(const ContentType contentType)
512 {
513         AppLogDebug("ENTER");
514         if (contentType == CONTENT_TYPE_VIDEO)
515         {
516                 __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_VIDEO);
517                 __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
518                 __pContentIconListView->UpdateList();
519         }
520         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
521 }
522
523 void
524 VideoListEditorPanel::OnThumbnailDecoded(const int index)
525 {
526         AppLogDebug("ENTER : index(%d)", index);
527         if (index >= 0)
528         {
529                 __pContentIconListView->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
530         }
531         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
532 }
533
534 void
535 VideoListEditorPanel::OnSceneActivatedN(const SceneId& previousSceneId,
536                                                                 const SceneId& currentSceneId, IList* pArgs)
537 {
538         AppLogDebug("ENTER");
539         SceneManager* pSceneManager = SceneManager::GetInstance();
540         __pFileListEditorForm = dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
541
542         __pPresentationModel = FileListPresentationModel::GetInstance();
543
544         if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
545         {
546                 if (currentSceneId == IDSCN_VIDEO_LIST_EDITOR)
547                 {
548                         if (previousSceneId == IDSCN_ALBUM_LIST)
549                         {
550                                 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pArgs->GetAt(0));
551                                 if (pAlbumInfo == null)
552                                 {
553                                         AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
554
555                                         return;
556                                 }
557
558                                 IList* pDirectoryList = pAlbumInfo->GetDirectoryListN();
559                                 __pPresentationModel->SetCurrentAlbumInfo(pAlbumInfo->GetAlbumName(), *pDirectoryList);
560
561                                 if (pDirectoryList != null)
562                                 {
563                                         delete pDirectoryList;
564                                 }
565                                 delete pArgs;
566
567                                 __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
568                                 __pContentIconListView->UpdateList();
569                         }
570                 }
571         }
572         else
573         {
574                 __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
575                 __pContentIconListView->RequestRedraw(true);
576         }
577
578         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
579 }
580
581 void
582 VideoListEditorPanel::OnSceneDeactivated(const SceneId& currentSceneId,
583                                                                 const SceneId& nextSceneId)
584 {
585         AppLogDebug("ENTER");
586         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
587 }
588
589 int
590 VideoListEditorPanel::GetItemCheckedCount(void) const
591 {
592         AppLogDebug("ENTER");
593         int count = 0;
594         if (__pContentIconListView != null)
595         {
596                 int loopCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
597                 for (int i = 0; i < loopCount; ++i)
598                 {
599                         if (__pContentIconListView->IsItemChecked(i))
600                         {
601                                 ++count;
602                         }
603                 }
604         }
605         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
606
607         return count;
608 }
609
610 IList*
611 VideoListEditorPanel::GetItemCheckedIndexListN(void) const
612 {
613         AppLogDebug("ENTER");
614         IList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
615         Integer* pIndex = null;
616
617         if (__pContentIconListView != null)
618         {
619                 int loopCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
620                 for (int i = 0; i < loopCount; ++i)
621                 {
622                         if (__pContentIconListView->IsItemChecked(i))
623                         {
624                                 pIndex = new (std::nothrow) Integer(i);
625                                 pList->Add(pIndex);
626                         }
627                 }
628         }
629         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
630
631         return pList;
632 }
633
634 void
635 VideoListEditorPanel::OnFileOpInvalidate(enum FileActionMode actionId)
636 {
637         SceneManager* pSceneManager = SceneManager::GetInstance();
638         FileListEditorForm* pFileListEditorForm =
639                                 dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
640         TryReturnVoid(pFileListEditorForm != null, "[%s] fail to get SceneManager.",
641                         GetErrorMessage(GetLastResult()));
642         pFileListEditorForm->Invalidate(true);
643 }
644
645 void
646 VideoListEditorPanel::OnRequestAppExitWithMultipleSelectionAppControlResult(void)
647 {
648         AppLogDebug("ENTER");
649         IList* pIndexList = GetItemCheckedIndexListN();
650
651         if (pIndexList->GetCount() <= 0)
652         {
653                 delete pIndexList;
654                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
655                 return;
656         }
657
658         HashMap* pMap = new (std::nothrow) HashMap(SingleObjectDeleter);
659         result r = pMap->Construct();
660
661         if (r == E_SUCCESS)
662         {
663                 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
664                 r = pArrayList->Construct();
665
666                 if (r == E_SUCCESS)
667                 {
668                         Integer* pTemp = null;
669                         int loopCount = pIndexList->GetCount();
670
671                         for (int i = 0; i < loopCount; ++i)
672                         {
673                                 pTemp = static_cast<Integer*>(pIndexList->GetAt(i));
674                                 pArrayList->Add(new (std::nothrow) String(__pPresentationModel->GetContentFilePath(pTemp->ToInt())));
675                         }
676
677                         pMap->Add(new (std::nothrow) String(APPCONTROL_KEY_DATA_SELECTED), (Object*)pArrayList);
678
679                         GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
680                         if (pApp != null)
681                         {
682                                 pApp->SendAppControlResult(APP_CTRL_RESULT_SUCCEEDED, pMap);
683                                 pApp->Terminate();
684                         }
685                         else
686                         {
687                                 delete pMap;
688                         }
689                 }
690                 else
691                 {
692                         delete pMap;
693                         delete pArrayList;
694                 }
695         }
696         else
697         {
698                 delete pMap;
699         }
700
701         delete pIndexList;
702         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
703 }
704
705 void
706 VideoListEditorPanel::OnSelectAllPressed(void)
707 {
708         bool needToSelectAll = true;
709         int checkedCount = GetItemCheckedCount();
710         int totalFileCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
711         if (checkedCount == totalFileCount)
712         {
713                 needToSelectAll = false;
714         }
715
716         if (needToSelectAll == true)
717         {
718                 for (int i = 0; i < totalFileCount; ++i)
719                 {
720                         if (__pContentIconListView->IsItemChecked(i) == false)
721                         {
722                                 __pContentIconListView->SetItemChecked(i, true);
723                                 __pContentIconListView->RefreshList(i, LIST_REFRESH_TYPE_ITEM_MODIFY);
724                         }
725                         __pFileListEditorForm->SetFooterButtonsState(true);
726                 }
727         }
728         else
729         {
730                 for (int i = 0; i < totalFileCount; ++i)
731                 {
732                         if (__pContentIconListView->IsItemChecked(i) == true)
733                         {
734                                 __pContentIconListView->SetItemChecked(i, false);
735                                 __pContentIconListView->RefreshList(i, LIST_REFRESH_TYPE_ITEM_MODIFY);
736                         }
737                         __pFileListEditorForm->SetFooterButtonsState(false);
738                 }
739         }
740
741         String tempString;
742         if (needToSelectAll == true)
743         {
744                 tempString.Format(LENGTH_COUNT_LABEL,
745                                                 ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), totalFileCount);
746         }
747         else
748         {
749                 tempString = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
750         }
751
752         __pLabelSelectCnt->SetText(tempString);
753         __pLabelSelectCnt->RequestRedraw(true);
754 }
755
756 void
757 VideoListEditorPanel::SetButtonState(void)
758 {
759         AppLogDebug("ENTER");
760         
761         SceneManager* pSceneManager = SceneManager::GetInstance();
762         TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
763
764         if (GetItemCheckedCount() > 0)
765         {
766                 __pFileListEditorForm->SetFooterButtonsState(true);
767         }
768         else
769         {
770                 __pFileListEditorForm->SetFooterButtonsState(false);
771         }
772         
773         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
774 }
775
776 void
777 VideoListEditorPanel::ChangeOrientation(void)
778 {
779         AppLogDebug("ENTER");
780         SceneManager* pSceneManager = SceneManager::GetInstance();
781         const Form* pForm = dynamic_cast<Form*>(pSceneManager->GetCurrentScene()->GetForm());
782         TryReturn(pForm != null,, "[%s] fail to get the form.", GetErrorMessage(GetLastResult()));
783
784         Rectangle clientAreaBounds = pForm->GetClientAreaBounds();
785         SetBounds(0, 0, clientAreaBounds.width, clientAreaBounds.height);
786         __pContentIconListView->SetBounds(0, 0, clientAreaBounds.width, clientAreaBounds.height);
787 }