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