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