0172a15423c8e8ec56b68b54bd3d544add779dc6
[apps/osp/Gallery.git] / src / GlAllListEditorPanel.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                GlAllListEditorPanel.cpp
19  * @brief               This is the implementation file for AllListEditorPanel class.
20  */
21
22 #include <FContent.h>
23 #include "GlAllListEditorPanel.h"
24 #include "GlCommonUtil.h"
25 #include "GlFileUpdateTimer.h"
26 #include "GlFileListEditorForm.h"
27 #include "GlFileListPresentationModel.h"
28 #include "GlResourceManager.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::Base::Utility;
35 using namespace Tizen::Content;
36 using namespace Tizen::Graphics;
37 using namespace Tizen::Media;
38 using namespace Tizen::Ui::Controls;
39 using namespace Tizen::Ui::Scenes;
40
41 static const int H_COUNT_LABEL = 48;
42 static const int H_COUNT_LABEL_BUTTON = 42;
43 static const int W_COUNT_LABEL_BUTTON = 42;
44 static const int COUNT_LABEL_FONT_SIZE = 33;
45 static const int H_CONTENT_MARGIN = 9;
46 static const int W_CONTENT_MARGIN = 6;
47 static const int W_CONTENT_SPACE = 6;
48 static const int H_CONTENT_SPACE = 6;
49 static const int LENGTH_COUNT_LABEL = 256;
50 static const unsigned int COLOR_COUNT_LABEL = Color32<68, 68, 68>::Value;
51 static const unsigned int COLOR_SELECT_COUNT_FONT = Color32<255, 255, 255>::Value;
52 static const unsigned int COLOR_COUNT_LABEL_BUTTON = Color32<120, 120, 120>::Value;
53 static const Color COLOR_THUMBNAIL_DIM (Color::GetColor(COLOR_ID_BLACK));
54 static const int ALPHA_THUMBNAIL_DIM = 70;
55
56 static const Rectangle RECT_INITIAL (0, 0, 10, 10);
57
58 AllListEditorPanel::AllListEditorPanel(void)
59         : __itemCount(0)
60         , __pContentIconListView(null)
61         , __pLabelSelectCnt(null)
62         , __pButtonSelectRegion(null)
63         , __pFileUpdateTimer(null)
64         , __pFileListEditorForm(null)
65         , __pPresentationModel(null)
66 {
67         AppLogDebug("ENTER");
68         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
69 }
70
71 AllListEditorPanel::~AllListEditorPanel(void)
72 {
73         AppLogDebug("ENTER");
74         delete __pFileUpdateTimer;
75         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
76 }
77
78 result
79 AllListEditorPanel::Initialize(void)
80 {
81         AppLogDebug("ENTER");
82         result r = Construct(RECT_INITIAL);
83         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
84
85         return r;
86 }
87
88 result
89 AllListEditorPanel::OnInitializing(void)
90 {
91         AppLogDebug("ENTER");
92         const Form* pForm = dynamic_cast<Form*>(GetParent());
93         TryReturn(pForm != null, E_FAILURE, "[%s] fail to get the form.", GetErrorMessage(GetLastResult()));
94
95         __pPresentationModel = FileListPresentationModel::GetInstance();
96         __pPresentationModel->ClearThumbnailRequests();
97         __pPresentationModel->AddPresentationModelListener(this);
98
99         Rectangle clientAreaBounds = pForm->GetClientAreaBounds();
100         SetBounds(0, 0, clientAreaBounds.width, clientAreaBounds.height);
101
102         __pContentIconListView = new (std::nothrow) IconListView();
103         __pContentIconListView->Construct(Rectangle(0, 0, clientAreaBounds.width, clientAreaBounds.height - H_COUNT_LABEL),
104                         DIMENSION_DEFAULT_THUMBNAIL, ICON_LIST_VIEW_STYLE_MARK, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
105         Bitmap* pBitmapEmpty = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
106         if (pBitmapEmpty != null)
107         {
108                 __pContentIconListView->SetBitmapOfEmptyList(pBitmapEmpty);
109                 delete pBitmapEmpty;
110         }
111         __pContentIconListView->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
112         __pContentIconListView->SetMargin(MARGIN_TYPE_LEFT, W_CONTENT_MARGIN);
113         __pContentIconListView->SetMargin(MARGIN_TYPE_RIGHT, W_CONTENT_MARGIN);
114         __pContentIconListView->SetMargin(MARGIN_TYPE_TOP, H_CONTENT_MARGIN);
115         __pContentIconListView->SetItemSpacing(W_CONTENT_SPACE, H_CONTENT_SPACE);
116         __pContentIconListView->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
117         __pContentIconListView->SetItemProvider(*this);
118         __pContentIconListView->SetCheckBoxPosition(ICON_LIST_VIEW_CHECK_BOX_POSITION_TOP_LEFT);
119         __pContentIconListView->AddIconListViewItemEventListener(*this);
120         __pContentIconListView->SetTouchAnimationEnabled(false);
121         AddControl(__pContentIconListView);
122         __pContentIconListView->SetShowState(true);
123
124         __pLabelSelectCnt = new (std::nothrow) Label();
125         String strTmp;
126         strTmp = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED").GetPointer();
127         __pLabelSelectCnt->Construct(
128                         Rectangle(0, clientAreaBounds.height - H_COUNT_LABEL, clientAreaBounds.width, H_COUNT_LABEL), strTmp);
129         __pLabelSelectCnt->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
130         __pLabelSelectCnt->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
131         __pLabelSelectCnt->SetBackgroundColor(COLOR_COUNT_LABEL);
132         __pLabelSelectCnt->SetTextColor(Color(COLOR_SELECT_COUNT_FONT));
133         __pLabelSelectCnt->SetTextConfig(COUNT_LABEL_FONT_SIZE, LABEL_TEXT_STYLE_BOLD);
134         AddControl(__pLabelSelectCnt);
135         __pLabelSelectCnt->Invalidate(true);
136
137         __pButtonSelectRegion = new (std::nothrow) Button();
138         __pButtonSelectRegion->Construct(Rectangle(clientAreaBounds.width - W_COUNT_LABEL_BUTTON - 10,
139                         clientAreaBounds.height - H_COUNT_LABEL_BUTTON - 4, W_COUNT_LABEL_BUTTON, H_COUNT_LABEL_BUTTON),
140                         EMPTY_SPACE);
141         __pButtonSelectRegion->SetActionId(IDA_BUTTON_MOVE_TO_SELECTION);
142         __pButtonSelectRegion->SetColor(BUTTON_STATUS_NORMAL, COLOR_COUNT_LABEL_BUTTON);
143         Bitmap* pSelectionBitmap = ResourceManager::GetBitmapN(IDB_BUTTON_MOVE_SELECTION);
144         if (pSelectionBitmap != null)
145         {
146                 Rectangle buttonRegionRect = __pButtonSelectRegion->GetBounds();
147                 pSelectionBitmap->Scale(Dimension(buttonRegionRect.width, buttonRegionRect.height));
148                 __pButtonSelectRegion->SetNormalBitmap(Point(buttonRegionRect.width, buttonRegionRect.height),
149                                 *pSelectionBitmap);
150         }
151         AddControl(__pButtonSelectRegion);
152
153         if (pSelectionBitmap != null)
154         {
155                 delete pSelectionBitmap;
156         }
157         __pButtonSelectRegion->AddActionEventListener(*this);
158
159         __itemCount = 0;
160         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
161
162         return E_SUCCESS;
163 }
164
165 result
166 AllListEditorPanel::OnTerminating(void)
167 {
168         AppLogDebug("ENTER");
169         __pPresentationModel->RemovePresentationModelListener(*this);
170         __pPresentationModel->RemoveContentEventListener(__pFileListEditorForm);
171         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
172
173         return E_SUCCESS;
174 }
175
176 void
177 AllListEditorPanel::OnActionPerformed(const Control& source, int actionId)
178 {
179         AppLogDebug("ENTER");
180         SceneManager* pSceneManager = SceneManager::GetInstance();
181         TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
182
183         switch (actionId)
184         {
185         case IDA_BUTTON_CHECKED:
186         {
187                 int loopCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
188                 for (int i=0; i < loopCount; ++i)
189                 {
190                         if (__pContentIconListView->IsItemChecked(i) == false)
191                         {
192                                 __pContentIconListView->SetItemChecked(i, true);
193                                 __pContentIconListView->RefreshList(i, LIST_REFRESH_TYPE_ITEM_MODIFY);
194                         }
195                 }
196                 int checkedCount = GetItemCheckedCount();
197                 String strTmp;
198
199                 if (checkedCount == 0)
200                 {
201                         strTmp = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
202                 }
203                 else if (checkedCount == 1)
204                 {
205                         strTmp = ResourceManager::GetString(L"IDS_VR_POP_1_ITEM_SELECTED");
206                 }
207                 else
208                 {
209                         strTmp.Format(LENGTH_COUNT_LABEL,
210                                         ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), checkedCount);
211                 }
212
213                 __pLabelSelectCnt->SetText(strTmp);
214                 __pLabelSelectCnt->RequestRedraw(true);
215                 SetButtonState();
216         }
217         break;
218
219         case IDA_BUTTON_UNCHECKED:
220         {
221                 int loopCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
222                 for (int i = 0; i < loopCount; ++i)
223                 {
224                         if (__pContentIconListView->IsItemChecked(i) == true)
225                         {
226                                 __pContentIconListView->SetItemChecked(i,false);
227                         }
228                 }
229                 int checkedCount = GetItemCheckedCount();
230                 String strTmp;
231
232                 if (checkedCount == 0)
233                 {
234                         strTmp = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
235                 }
236                 else if (checkedCount == 1)
237                 {
238                         strTmp = ResourceManager::GetString(L"IDS_VR_POP_1_ITEM_SELECTED");
239                 }
240                 else
241                 {
242                         strTmp.Format(LENGTH_COUNT_LABEL,
243                                         ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), checkedCount);
244                 }
245
246                 __pLabelSelectCnt->SetText(strTmp);
247                 __pLabelSelectCnt->RequestRedraw(true);
248                 __pContentIconListView->UpdateList();
249                 SetButtonState();
250         }
251         break;
252
253         case IDA_BUTTON_MOVE_TO_SELECTION:
254         {
255                 if (pSceneManager->GetCurrentSceneId() == IDSCN_ALL_LIST_EDITOR)
256                 {
257                         IList* pList = GetItemCheckedIndexListN();
258                         if (pList == null)
259                         {
260                                 pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
261                         }
262                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST_SELECTION), pList);
263                 }
264                 else
265                 {
266                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST_SELECTION));
267                 }
268         }
269         break;
270
271         default:
272                 break;
273         }
274         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
275 }
276
277 int
278 AllListEditorPanel::GetItemCount(void)
279 {
280         AppLogDebug("ENTER");
281         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
282
283         return __itemCount;
284 }
285
286 IconListViewItem*
287 AllListEditorPanel::CreateItem(int index)
288 {
289         AppLogDebug("ENTER : index(%d)", index);
290         IconListViewItem* pIconListviewItem;
291         Bitmap* pBitmap = null;
292         String* pItemText = null;
293         result r = __pPresentationModel->GetThumbnailInSyncCacheN(index, pItemText, pBitmap);
294         if (pBitmap == null || r == E_FAILURE)
295         {
296                 __pPresentationModel->RequestThumbnail(index);
297                 pBitmap = CommonUtil::GetEmptyThumbnailN();
298         }
299
300         if (pItemText == null)
301         {
302                 pItemText = new (std::nothrow) String(ResourceManager::GetString(L"EMPTY_SPACE"));
303         }
304         else if ((*pItemText) != ResourceManager::GetString(L"EMPTY_SPACE"))
305         {
306                 delete pItemText;
307                 pItemText = new (std::nothrow) String(ResourceManager::GetString(L"EMPTY_SPACE"));
308         }
309
310         if (__pContentIconListView->IsItemChecked(index) == true)
311         {
312                 if (pBitmap != null)
313                 {
314                         BufferInfo bufferInfo;
315                         pBitmap->Lock(bufferInfo, INFINITE);
316                         pBitmap->Unlock();
317                         Color dimColor(COLOR_THUMBNAIL_DIM);
318                         dimColor.SetAlpha(ALPHA_THUMBNAIL_DIM);
319
320                         Canvas canvas;
321                         canvas.Construct(bufferInfo);
322                         canvas.FillRectangle(dimColor, canvas.GetBounds());
323
324                         Bitmap* pSelectedBitmap = new (std::nothrow) Bitmap();
325                         pSelectedBitmap->Construct(canvas, canvas.GetBounds());
326                         pIconListviewItem = new (std::nothrow) IconListViewItem();
327                         pIconListviewItem->Construct(*pBitmap, pItemText, pSelectedBitmap);
328                         delete pSelectedBitmap;
329                 }
330                 else
331                 {
332                         AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
333                         delete pItemText;
334                         return null;
335                 }
336         }
337         else
338         {
339                 pIconListviewItem = new (std::nothrow) IconListViewItem();
340                 pIconListviewItem->Construct(*pBitmap, pItemText);
341         }
342
343         if (pBitmap != null)
344         {
345                 delete pBitmap;
346         }
347         if (pItemText != null)
348         {
349                 delete pItemText;
350         }
351         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
352
353         return pIconListviewItem;
354 }
355
356 bool
357 AllListEditorPanel::DeleteItem(int index, IconListViewItem* pItem)
358 {
359         AppLogDebug("ENTER");
360         delete pItem;
361         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
362
363         return true;
364 }
365
366 void
367 AllListEditorPanel::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
368 {
369         AppLogDebug("ENTER");
370         if (status == ICON_LIST_VIEW_ITEM_CHECKED || status == ICON_LIST_VIEW_ITEM_UNCHECKED)
371         {
372                 int checkedCount = GetItemCheckedCount();
373                 String strTmp;
374
375                 if (checkedCount == 0)
376                 {
377                         strTmp = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
378                 }
379                 else if (checkedCount == 1)
380                 {
381                         strTmp = ResourceManager::GetString(L"IDS_VR_POP_1_ITEM_SELECTED");
382                 }
383                 else
384                 {
385                         strTmp.Format(LENGTH_COUNT_LABEL,
386                                         ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), checkedCount);
387                 }
388
389                 __pLabelSelectCnt->SetText(strTmp);
390                 __pLabelSelectCnt->RequestRedraw(true);
391                 __pContentIconListView->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
392         }
393         SetButtonState();
394         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
395 }
396
397 void
398 AllListEditorPanel::OnFileInfoChanged(const ContentType contentType)
399 {
400         AppLogDebug("ENTER");
401         if (contentType == CONTENT_TYPE_ALL
402                 || contentType == CONTENT_TYPE_IMAGE
403                 || contentType == CONTENT_TYPE_VIDEO)
404         {
405                 __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_ALL);
406                 __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
407                 __pContentIconListView->UpdateList();
408         }
409         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
410 }
411
412 void
413 AllListEditorPanel::OnThumbnailDecoded(const int index)
414 {
415         AppLogDebug("ENTER : index(%d)", index);
416         if (index >= 0)
417         {
418                 __pContentIconListView->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
419         }
420         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
421 }
422
423 void
424 AllListEditorPanel::OnSceneActivatedN(const SceneId& previousSceneId,
425                                                                 const SceneId& currentSceneId, IList* pArgs)
426 {
427         AppLogDebug("ENTER");
428         __pPresentationModel = FileListPresentationModel::GetInstance();
429
430         SceneManager* pSceneManager = SceneManager::GetInstance();
431         TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
432         __pFileListEditorForm = dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
433         TryReturnVoid(__pFileListEditorForm != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
434         __pPresentationModel->AddContentEventListener(__pFileListEditorForm);
435
436         if (previousSceneId == IDSCN_ALL_LIST_SELECTION)
437         {
438                 if (pArgs != null)
439                 {
440                         if (__pContentIconListView != null)
441                         {
442                                 int loopCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
443                                 for (int i = 0; i < loopCount; ++i)
444                                 {
445                                         __pContentIconListView->SetItemChecked(i, false);
446                                 }
447                                 __pContentIconListView->UpdateList();
448                         }
449
450                         if (pArgs->GetCount() > 0) //SomeItems are Still Selected.
451                         {
452                                 IList* pSeletedIndexList = pArgs;
453                                 int loopCount = pSeletedIndexList->GetCount();
454                                 if (__pContentIconListView != null)
455                                 {
456                                         for (int i = 0; i < loopCount; ++i)
457                                         {
458                                                 int index = static_cast<Integer*>(pSeletedIndexList->GetAt(i))->ToInt();
459                                                 __pContentIconListView->SetItemChecked(index, true);
460                                         }
461                                         __pContentIconListView->UpdateList();
462                                 }
463                         }
464                 }
465
466                 int checkedCount = GetItemCheckedCount();
467                 String strTmp;
468
469                 if (checkedCount == 0)
470                 {
471                         strTmp = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
472                 }
473                 else if (checkedCount == 1)
474                 {
475                         strTmp = ResourceManager::GetString(L"IDS_VR_POP_1_ITEM_SELECTED");
476                 }
477                 else
478                 {
479                         strTmp.Format(LENGTH_COUNT_LABEL,
480                                         ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), checkedCount);
481                 }
482
483                 __pLabelSelectCnt->SetText(strTmp);
484                 __pLabelSelectCnt->RequestRedraw(true);
485         }
486         else if (previousSceneId == IDSCN_ALL_LIST)
487         {
488                 ResetSelection();
489         }
490
491         SetButtonState();
492
493         __pFileListEditorForm->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_EDIT"));
494         
495         if (pArgs != null && pArgs->GetCount() > 0 && previousSceneId != IDSCN_ALL_LIST_SELECTION)
496         {
497                 String* pDirectory = static_cast<String*>(pArgs->GetAt(0));
498                 if (pDirectory != null && pDirectory->GetLength() > 0)
499                 {
500                         __pFileListEditorForm->MoveToAlbum(*pDirectory);
501                 }
502         }
503
504         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
505 }
506
507 void
508 AllListEditorPanel::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
509 {
510         AppLogDebug("ENTER");
511         __pPresentationModel->RemoveContentEventListener(__pFileListEditorForm);
512         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
513 }
514
515 int
516 AllListEditorPanel::GetItemCheckedCount(void) const
517 {
518         AppLogDebug("ENTER");
519         int count = 0;
520         if (__pContentIconListView != null)
521         {
522                 int loopCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
523                 for (int i = 0; i < loopCount; ++i)
524                 {
525                         if (__pContentIconListView->IsItemChecked(i))
526                         {
527                                 ++count;
528                         }
529                         else
530                         {
531                                 AppLog("Index i = %d is Not Checked", i);
532                         }
533                 }
534         }
535         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
536
537         return count;
538 }
539
540 IList*
541 AllListEditorPanel::GetItemCheckedIndexListN(void) const
542 {
543         AppLogDebug("ENTER");
544         IList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
545         Integer* pIndex = null;
546
547         if (__pContentIconListView!=null)
548         {
549                 int loopCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
550                 for (int i = 0; i < loopCount; ++i)
551                 {
552                         if (__pContentIconListView->IsItemChecked(i) == true)
553                         {
554                                 pIndex = new (std::nothrow) Integer(i);
555                                 pList->Add(pIndex);
556                                 AppLogDebug("checked index(%d)", i);
557                         }
558                 }
559         }
560         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
561
562         return pList;
563 }
564
565 result
566 AllListEditorPanel::OnRequestDelete(void)
567 {
568         AppLogDebug("ENTER");
569         IList* pIndexList = GetItemCheckedIndexListN();
570         if (pIndexList->GetCount() <= 0)
571         {
572                 delete pIndexList;
573                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
574
575                 return E_FAILURE;
576         }
577
578         delete __pFileUpdateTimer;
579         __pFileUpdateTimer = new (std::nothrow) FileUpdateTimer(pIndexList, __pPresentationModel, this, FILE_ACTION_DELETE);
580         result r = __pFileUpdateTimer->StartTimer();
581
582         if (IsFailed(r))
583         {
584                 delete __pFileUpdateTimer;
585                 __pFileUpdateTimer = null;
586                 return E_FAILURE;
587         }
588         else
589         {
590                 __pPresentationModel->SetUpdateProgressStatus(true);
591         }
592         return E_SUCCESS;
593 }
594
595 void AllListEditorPanel::OnFileOpInvalidate(enum FileActionMode actionId)
596 {
597         __pFileListEditorForm->Invalidate(true);
598 }
599
600 void AllListEditorPanel::OnFileOpComplete(enum FileActionMode actionId, enum FileActionCompleteRes res)
601 {
602         __pPresentationModel->SetUpdateProgressStatus(false);
603
604         __pLabelSelectCnt->SetText(ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED"));
605         __pLabelSelectCnt->RequestRedraw(true);
606
607         __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_ALL);
608         __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
609         __pContentIconListView->UpdateList();
610
611         SceneManager* pSceneManager = SceneManager::GetInstance();
612         if (GetItemCount() > 0)
613         {
614                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST,SCENE_TRANSITION_ANIMATION_TYPE_NONE,
615                                                                    SCENE_HISTORY_OPTION_ADD_HISTORY, SCENE_DESTROY_OPTION_DESTROY));
616         }
617         else
618         {
619                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST,SCENE_TRANSITION_ANIMATION_TYPE_NONE,
620                                                                    SCENE_HISTORY_OPTION_ADD_HISTORY, SCENE_DESTROY_OPTION_DESTROY));
621         }
622         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
623 }
624
625 result
626 AllListEditorPanel::OnRequestMessage(void)
627 {
628         AppLogDebug("ENTER");
629         result r = E_SUCCESS;
630         IList* pIndexList = GetItemCheckedIndexListN();
631         if (pIndexList == null || pIndexList->GetCount() <= 0)
632         {
633                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
634
635                 return E_FAILURE;
636         }
637
638         Integer* pIndex = null;
639         int checkedIndex;
640         ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
641         pArrayList->Construct();
642         int loopCount = pIndexList->GetCount();
643
644         for (int i = 0; i < loopCount; ++i)
645         {
646                 pIndex = static_cast<Integer*>(pIndexList->GetAt(i));
647                 if (pIndex != null)
648                 {
649                         checkedIndex = pIndex->ToInt();
650                         pArrayList->Add(new (std::nothrow) String(__pPresentationModel->GetContentFilePath(checkedIndex)));
651                 }
652         }
653
654         HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
655         pDataList->Construct();
656         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_MESSAGE_TYPE), new (std::nothrow) String(APPCONTROL_DATA_MMS));
657         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
658
659         r = __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_MESSAGE, APPCONTROL_OPERATION_ID_COMPOSE, null,
660                         null, pDataList, null);
661
662         if (r == E_MAX_EXCEEDED)
663         {
664                 MessageBox messageBox;
665                 messageBox.Construct(L"", ResourceManager::GetString(L"IDS_RCS_BODY_MAXIMUM_NUMBER_OF_FILES_EXCEEDED"),
666                                 MSGBOX_STYLE_NONE, 3000);
667                 int modalResult;
668                 messageBox.ShowAndWait(modalResult);
669         }
670         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
671
672         return r;
673 }
674
675 result
676 AllListEditorPanel::OnRequestEmail(void)
677 {
678         AppLogDebug("ENTER");
679         result r = E_SUCCESS;
680
681         IList* pIndexList = GetItemCheckedIndexListN();
682         if (pIndexList == null || pIndexList->GetCount() <= 0)
683         {
684                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
685
686                 return E_FAILURE;
687         }
688
689         Integer* pIndex = null;
690         int checkedIndex;
691         ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
692         pArrayList->Construct();
693         int loopCount = pIndexList->GetCount();
694
695         for (int i = 0; i < loopCount; ++i)
696         {
697                 pIndex = static_cast<Integer*>(pIndexList->GetAt(i));
698                 if (pIndex != null)
699                 {
700                         checkedIndex = pIndex->ToInt();
701                         pArrayList->Add(new (std::nothrow) String(__pPresentationModel->GetContentFilePath(checkedIndex)));
702                 }
703         }
704
705         HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
706         pDataList->Construct();
707         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
708
709         r = __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_EMAIL, APPCONTROL_OPERATION_ID_COMPOSE,
710                         new (std::nothrow) String(APPCONTROL_URI_MAIL_TO), null, pDataList, null);
711
712         if (r == E_MAX_EXCEEDED)
713         {
714                 MessageBox messageBox;
715                 messageBox.Construct(L"", ResourceManager::GetString(L"IDS_RCS_BODY_MAXIMUM_NUMBER_OF_FILES_EXCEEDED"),
716                                 MSGBOX_STYLE_NONE, 3000);
717                 int modalResult;
718                 messageBox.ShowAndWait(modalResult);
719         }
720
721         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
722
723         return r;
724 }
725
726 result
727 AllListEditorPanel::OnRequestSlideShow(void)
728 {
729         AppLogDebug("ENTER");
730         result r = E_SUCCESS;
731         IList* pIndexList = GetItemCheckedIndexListN();
732         if (pIndexList == null)
733         {
734                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
735                 return E_FAILURE;
736         }
737
738         Integer* pRealIndex = null;
739         int realIndex = -1;
740         ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
741         pArrayList->Construct();
742         int loopCount = pIndexList->GetCount();
743
744         for (int i = 0; i < loopCount; ++i)
745         {
746                 pRealIndex = static_cast<Integer*>(pIndexList->GetAt(i));
747                 if (pRealIndex != null)
748                 {
749                         realIndex = pRealIndex->ToInt();
750                         pArrayList->Add(new (std::nothrow) String(__pPresentationModel->GetContentFilePath(realIndex)));
751                 }
752         }
753
754         HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
755         pDataList->Construct();
756         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE), new (std::nothrow) String(APPCONTROL_DATA_SLIDE_SHOW));
757         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
758
759         r = __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_IMAGE, APPCONTROL_OPERATION_ID_VIEW, null,
760                         new (std::nothrow) String(APPCONTROL_MIME_IMAGE_ALL), pDataList, null);
761
762         if (r == E_MAX_EXCEEDED)
763         {
764                 MessageBox messageBox;
765                 messageBox.Construct(L"", ResourceManager::GetString(L"IDS_RCS_BODY_MAXIMUM_NUMBER_OF_FILES_EXCEEDED"),
766                                 MSGBOX_STYLE_NONE, 3000);
767                 int modalResult;
768                 messageBox.ShowAndWait(modalResult);
769         }
770
771         delete pIndexList;
772         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
773
774         return r;
775 }
776
777 void
778 AllListEditorPanel::ResetSelection(void)
779 {
780         AppLogDebug("ENTER");
781         __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_ALL);
782         __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
783
784         for ( int index = 0; index < __itemCount; index++)
785         {
786                 __pContentIconListView->SetItemChecked(index, false);
787         }
788
789         __pContentIconListView->UpdateList();
790
791         String strTmp;
792         strTmp = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
793
794         __pLabelSelectCnt->SetText(strTmp);
795         __pLabelSelectCnt->RequestRedraw(true);
796         SetButtonState();
797         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
798 }
799
800 void
801 AllListEditorPanel::SetButtonState(void)
802 {
803         AppLogDebug("ENTER");
804         SceneManager* pSceneManager = SceneManager::GetInstance();
805         TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
806
807         if (GetItemCheckedCount() > 0)
808         {
809                 AppLogDebug("BUTTONSTATE : Request Enable");
810                 __pFileListEditorForm->SetFooterButtonsState(true);
811                 __pButtonSelectRegion->SetShowState(true);
812         }
813         else
814         {
815                 AppLogDebug("BUTTONSTATE : Request disable");
816                 __pFileListEditorForm->SetFooterButtonsState(false);
817                 __pButtonSelectRegion->SetShowState(false);
818         }
819         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
820 }
821
822 void
823 AllListEditorPanel::OnSelectAllPressed(void)
824 {
825         bool needToSelectAll = true;
826         int checkedCount = GetItemCheckedCount();
827         int totalFileCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
828         if (checkedCount == totalFileCount)
829         {
830                 needToSelectAll = false;
831         }
832
833         if (needToSelectAll == true)
834         {
835                 for (int i = 0; i < totalFileCount; ++i)
836                 {
837                         if (__pContentIconListView->IsItemChecked(i) == false)
838                         {
839                                 __pContentIconListView->SetItemChecked(i,true);
840                                 __pContentIconListView->RefreshList(i, LIST_REFRESH_TYPE_ITEM_MODIFY);
841                         }
842                 }
843         }
844         else
845         {
846                 for (int i = 0; i < totalFileCount; ++i)
847                 {
848                         if (__pContentIconListView->IsItemChecked(i) == true)
849                         {
850                                 __pContentIconListView->SetItemChecked(i, false);
851                                 __pContentIconListView->RefreshList(i, LIST_REFRESH_TYPE_ITEM_MODIFY);
852                         }
853                 }
854         }
855
856         String tempString;
857         if (needToSelectAll == true)
858         {
859                 tempString.Format(LENGTH_COUNT_LABEL,
860                                                 ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), totalFileCount);
861         }
862         else
863         {
864                 tempString = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
865         }
866
867         __pLabelSelectCnt->SetText(tempString);
868         __pLabelSelectCnt->RequestRedraw(true);
869         SetButtonState();
870 }
871
872 result
873 AllListEditorPanel::OnRequestRotate(RotateMode rotateMode)
874 {
875         AppLogDebug("ENTER");
876         IList* pIndexList = GetItemCheckedIndexListN();
877         if (pIndexList == null)
878         {
879                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
880                 return E_FAILURE;
881         }
882         else if (pIndexList->GetCount() <= 0)
883         {
884                 delete pIndexList;
885                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
886
887                 return E_FAILURE;
888         }
889
890         delete __pFileUpdateTimer;
891         __pFileUpdateTimer = new (std::nothrow) FileUpdateTimer(pIndexList, __pPresentationModel, this, FILE_ACTION_ROTATE, rotateMode);
892         result r = __pFileUpdateTimer->StartTimer();
893
894         if (IsFailed(r))
895         {
896                 delete __pFileUpdateTimer;
897                 __pFileUpdateTimer = null;
898                 return E_FAILURE;
899         }
900         else
901         {
902                 __pPresentationModel->SetUpdateProgressStatus(true);
903         }
904         return E_SUCCESS;
905 }
906
907 void AllListEditorPanel::CancelUpdateProgress(void)
908 {
909         if( __pFileUpdateTimer!= null && __pFileUpdateTimer->IsStarted())
910         {
911                 __pFileUpdateTimer->Cancel();
912                 delete __pFileUpdateTimer;
913                 __pFileUpdateTimer = null;
914         }
915 }