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