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