Fixed issue 51868
[apps/osp/Gallery.git] / src / GlAlbumListEditorForm.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                GlAlbumListEditorForm.cpp
19  * @brief               This is the implementation file for AlbumListEditorForm class.
20  */
21
22 #include "GlAlbumInfo.h"
23 #include "GlAlbumListEditorForm.h"
24 #include "GlAlbumListPresentationModel.h"
25 #include "GlResourceManager.h"
26 #include "GlTypes.h"
27
28 using namespace Tizen::App;
29 using namespace Tizen::Base;
30 using namespace Tizen::Base::Collection;
31 using namespace Tizen::Content;
32 using namespace Tizen::Graphics;
33 using namespace Tizen::Io;
34 using namespace Tizen::Media;
35 using namespace Tizen::System;
36 using namespace Tizen::Ui;
37 using namespace Tizen::Ui::Controls;
38 using namespace Tizen::Ui::Scenes;
39
40 static const unsigned int COLOR_DELETE_BUTTON_NORMAL = Color32<208, 82, 82>::Value;
41 static const unsigned int COLOR_DELETE_BUTTON_PRESSED = Color32<194, 71, 71>::Value;
42 static const unsigned int COLOR_DELETE_BUTTON_TEXT = Color32<248, 246, 239>::Value;
43 static const String RESERVED_CAMERA_PATH = Environment::GetMediaPath() + L"Camera" + DIRECTORY_SEPARATOR;
44 static const String RESERVED_CAMERA_PATH_EXT = Environment::GetExternalStoragePath() + L"Camera" + DIRECTORY_SEPARATOR;
45 static const String RESERVED_MEDIA_PATH = Environment::GetMediaPath();
46 static const String RESERVED_EXTERNAL_MEDIA_PATH = Environment::GetExternalStoragePath();
47
48 static const int GAP_W_POPUP_ITEM = 5;
49 static const int W_DELETE_POPUP = 620;
50 static const int H_DELETE_POPUP = 300;
51 static const int H_DELETE_LABEL = 180;
52 static const int Y_DELETE_BUTTON = 180;
53 static const int H_DELETE_BUTTON = 80;
54
55 static const int FORMAT_BUFFER_SIZE = 256;
56
57 static const Color COLOR_FOLDER_BITMAP_DIM(Color::GetColor(COLOR_ID_BLACK));
58 static const int ALPHA_FOLDER_BITMAP_DIM = 70;
59
60 static const int IDA_ALBUM_EDIT = 503;
61
62 AlbumListEditorForm::AlbumListEditorForm(void)
63         : __checkedCount(0)
64         , __pSelectCountLabel(null)
65         , __pEditorFolderIconList(null)
66         , __pShareContextMenu(null)
67         , __pDeletePopup(null)
68         , __pFileUpdateTimer(null)
69         , __pPresentationModel(null)
70 {
71         AppLogDebug("ENTER");
72         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
73 }
74
75 AlbumListEditorForm::~AlbumListEditorForm(void)
76 {
77         AppLogDebug("ENTER");
78         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
79 }
80
81 result
82 AlbumListEditorForm::Initialize(void)
83 {
84         AppLogDebug("ENTER");
85         result r = Form::Construct(IDL_FORM_ALBUM_LIST_EDITOR);
86         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
87
88         return r;
89 }
90
91 result
92 AlbumListEditorForm::OnInitializing(void)
93 {
94         AppLogDebug("ENTER");
95         result r = E_SUCCESS;
96
97         SetOrientation(ORIENTATION_AUTOMATIC);
98         AddOrientationEventListener(*this);
99
100         __pPresentationModel = AlbumListPresentationModel::GetInstance();
101         __pPresentationModel->ClearThumbnailRequests();
102         r = __pPresentationModel->AddPresentationModelListener(this);
103
104         SetFormBackEventListener(this);
105         GetHeader()->AddActionEventListener(*this);
106         GetFooter()->AddActionEventListener(*this);
107
108         r = InitializeControl();
109         if (r != E_SUCCESS)
110         {
111                 AppLogDebug("[%s] Unable to set InitializeControl.", GetErrorMessage(r));
112         }
113
114         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
115
116         return r;
117 }
118
119 result
120 AlbumListEditorForm::OnTerminating(void)
121 {
122         AppLogDebug("ENTER");
123         result r = E_SUCCESS;
124         r = __pPresentationModel->RemovePresentationModelListener(*this);
125         __pPresentationModel->RemoveContentEventListener(*this);
126
127         if (__pDeletePopup != null)
128         {
129                 delete __pDeletePopup;
130                 __pDeletePopup = null;
131         }
132         if (__pFileUpdateTimer != null)
133         {
134                 delete __pFileUpdateTimer;
135                 __pFileUpdateTimer = null;
136         }
137         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
138
139         return r;
140 }
141
142 void
143 AlbumListEditorForm::OnContentUpdated(void)
144 {
145         AppLogDebug("ENTER");
146         int maxCount = __pPresentationModel->GetFolderCount();
147         if (__pDeletePopup != null)
148         {
149                 if (__pDeletePopup->IsVisible() == true)
150                 {
151                         __pDeletePopup->Destroy();
152                         __pDeletePopup = null;
153                         InitializePopup();
154                 }
155         }
156
157         for (int i = 0; i < maxCount; ++i)
158         {
159                 __pEditorFolderIconList->SetItemChecked(i, false);
160         }
161         SceneManager* pSceneManager = SceneManager::GetInstance();
162         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
163         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
164 }
165
166 result
167 AlbumListEditorForm::InitializeControl(void)
168 {
169         AppLogDebug("ENTER");
170         result r = E_SUCCESS;
171         String tempString;
172
173         __pSelectCountLabel = static_cast<Label*>(GetControl(L"IDC_LABEL_ALBUM_LIST_EDITOR_SELECTED"));
174                 AppAssert(__pSelectCountLabel);
175
176         CreateIconListView();
177         __checkedCount = GetCheckedFolderCount();
178
179
180         r = InitializePopup();
181         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
182
183         return r;
184 }
185
186 result
187 AlbumListEditorForm::InitializePopup(void)
188 {
189         AppLogDebug("ENTER");
190         if (__pDeletePopup == null)
191         {
192                 __pDeletePopup = new (std::nothrow) Popup();
193                 __pDeletePopup->Construct(false, Dimension(W_DELETE_POPUP, H_DELETE_POPUP));
194                 __pDeletePopup->SetPropagatedKeyEventListener(this);
195
196                 Rectangle popupClientBounds = __pDeletePopup->GetClientAreaBounds();
197
198                 Label* pLabel = new (std::nothrow) Label();
199                 pLabel->Construct(Rectangle(0, 0, popupClientBounds.width, H_DELETE_LABEL),
200                                 ResourceManager::GetString(L"IDS_COM_POP_DELETE_Q"));
201                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
202                 pLabel->SetTextConfig(34,LABEL_TEXT_STYLE_BOLD);
203
204                 Button* pDeleteButton = new (std::nothrow) Button();
205                 pDeleteButton->Construct(Rectangle(popupClientBounds.width / 2 + GAP_W_POPUP_ITEM, Y_DELETE_BUTTON,     popupClientBounds.width / 2 - GAP_W_POPUP_ITEM -10, H_DELETE_BUTTON),
206                                 ResourceManager::GetString(L"IDS_COM_BODY_DELETE"));
207                 pDeleteButton->SetColor(BUTTON_STATUS_NORMAL, COLOR_DELETE_BUTTON_NORMAL);
208                 pDeleteButton->SetColor(BUTTON_STATUS_PRESSED, COLOR_DELETE_BUTTON_PRESSED);
209                 pDeleteButton->SetTextColor(COLOR_DELETE_BUTTON_TEXT);
210                 pDeleteButton->SetActionId(IDA_DELETE_POPUP_DEL);
211                 pDeleteButton->AddActionEventListener(*this);
212
213                 Button* pCancelButton = new (std::nothrow) Button();
214                 pCancelButton->Construct(Rectangle(10, Y_DELETE_BUTTON, popupClientBounds.width / 2 - GAP_W_POPUP_ITEM -10, H_DELETE_BUTTON),
215                                 ResourceManager::GetString(L"IDS_COM_POP_CANCEL"));
216                 pCancelButton->SetActionId(IDA_DELETE_POPUP_CANCEL);
217                 pCancelButton->AddActionEventListener(*this);
218
219                 __pDeletePopup->AddControl(pLabel);
220                 __pDeletePopup->AddControl(pDeleteButton);
221                 __pDeletePopup->AddControl(pCancelButton);
222         }
223         else
224         {
225                 __pDeletePopup->SetShowState(true);
226                 __pDeletePopup->Show();
227         }
228         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
229
230         return E_SUCCESS;
231 }
232
233 void
234 AlbumListEditorForm::CreateIconListView(void)
235 {
236         AppLogDebug("ENTER");
237
238
239         __pEditorFolderIconList = new IconListView();
240         __pEditorFolderIconList->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height - __pSelectCountLabel->GetHeight()),
241                     Dimension(348, 348), ICON_LIST_VIEW_STYLE_MARK, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
242         __pEditorFolderIconList->SetCheckBoxPosition(ICON_LIST_VIEW_CHECK_BOX_POSITION_TOP_LEFT);
243         __pEditorFolderIconList->SetTouchAnimationEnabled(false);
244         __pEditorFolderIconList->SetItemProvider(*this);
245         __pEditorFolderIconList->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
246         __pEditorFolderIconList->AddIconListViewItemEventListener(*this);
247
248         Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
249
250         if (pBitmap != null)
251         {
252                 __pEditorFolderIconList->SetBitmapOfEmptyList(pBitmap);
253                 delete pBitmap;
254         }
255
256         __pEditorFolderIconList->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
257
258         AddControl(__pEditorFolderIconList);
259
260         __pEditorFolderIconList->SetShowState(true);
261
262         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
263 }
264
265 int
266 AlbumListEditorForm::GetItemCount(void)
267 {
268         AppLogDebug("ENTER");
269         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
270
271         return __pPresentationModel->GetFolderCount();
272 }
273
274 IconListViewItem*
275 AlbumListEditorForm::CreateItem(int index)
276 {
277         AppLogDebug("ENTER : index(%d)", index);
278         Bitmap* pBitmap = null;
279         Canvas* pEditAlbumCanvas = null;
280         Bitmap* pEditAlbumBitmap = null;
281         Bitmap* pBitmapRenameBg = null;
282         Bitmap* pBitmapRename = null;
283         String albumName;
284         int canvasWidth = 75;
285         int canvasHeight = 75;
286
287         IconListViewItem* pIconListviewItem = new (std::nothrow) IconListViewItem();
288
289         IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
290         AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
291
292         Bitmap* pAlbumBitmap = pAlbumInfo->GetFolderThumnailBitmap();
293         if (pAlbumBitmap == null)
294         {
295                 __pPresentationModel->RequestThumbnail(index, 0);
296         }
297
298         pBitmap = __pPresentationModel->CreateMergeBitmapN(index);
299
300         if (__pEditorFolderIconList->IsItemChecked(index) == true)
301         {
302                 if (pBitmap != null)
303                 {
304                         BufferInfo bufferInfo;
305                         pBitmap->Lock(bufferInfo, INFINITE);
306                         pBitmap->Unlock();
307                         Color dimColor(COLOR_FOLDER_BITMAP_DIM);
308                         dimColor.SetAlpha(ALPHA_FOLDER_BITMAP_DIM);
309                         Canvas canvas;
310                         canvas.Construct(bufferInfo);
311                         canvas.FillRectangle(dimColor, canvas.GetBounds());
312                         Bitmap* pSelectedBitmap = new (std::nothrow) Bitmap();
313                         pSelectedBitmap->Construct(canvas, canvas.GetBounds());
314                         pIconListviewItem->Construct(*pBitmap, null, pSelectedBitmap);
315                         delete pSelectedBitmap;
316                 }
317         }
318         else
319         {
320                 pIconListviewItem->Construct(*pBitmap);
321         }
322
323         if (pBitmap != null)
324         {
325                 delete pBitmap;
326         }
327
328         pBitmapRenameBg = ResourceManager::GetBitmapN(IDB_ALBUM_EDIT_RENAME_BG);
329         pBitmapRename = ResourceManager::GetBitmapN(IDB_ALBUM_EDIT_RENAME);
330
331         if (pBitmapRenameBg != null && pBitmapRename != null)
332         {
333
334                 pEditAlbumCanvas = new (std::nothrow) Canvas();
335                 pEditAlbumCanvas->Construct(Rectangle(0, 0, canvasWidth, canvasHeight));
336                 pEditAlbumCanvas->DrawBitmap(Point(0, 6), *pBitmapRenameBg);
337                 pEditAlbumCanvas->DrawBitmap(Point(0, 6), *pBitmapRename);
338
339
340                 pEditAlbumBitmap = new (std::nothrow) Bitmap();
341
342                 if (pEditAlbumBitmap != NULL)
343                 {
344                         pEditAlbumBitmap->Construct(*pEditAlbumCanvas, Rectangle(0, 0, canvasWidth, canvasHeight));
345
346                 }
347                 delete pEditAlbumCanvas;
348
349                 albumName = pAlbumInfo->GetAlbumName();
350
351                 if (albumName == ALL_ALBUMS_REAL_NAME)
352                 {
353                         albumName = ResourceManager::GetString(L"IDS_MEDIABR_BODY_ALL_ALBUMS");
354                 }
355
356                 String reservedCameraName = ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB");
357                 String albumPath = pAlbumInfo->GetDirectory(0);
358                 albumPath.Append(DIRECTORY_SEPARATOR);
359
360                 if (index == 0 || (reservedCameraName.Equals(albumName, true) &&
361                         (RESERVED_CAMERA_PATH.Equals(albumPath, true) || RESERVED_CAMERA_PATH_EXT.Equals(albumPath, true)))
362                         || RESERVED_MEDIA_PATH.Equals(albumPath, true) || RESERVED_EXTERNAL_MEDIA_PATH.Equals(albumPath, true))
363                 {
364                         // rename disabled
365                 }
366                 else
367                 {
368                         pIconListviewItem->SetOverlayBitmap(IDA_ALBUM_EDIT, pEditAlbumBitmap, ALIGNMENT_RIGHT, ALIGNMENT_TOP);
369                 }
370
371                 if (pEditAlbumBitmap != null)
372                 {
373                         delete pEditAlbumBitmap;
374                 }
375         }
376
377         if (pBitmapRenameBg)
378         {
379                 delete pBitmapRenameBg;
380         }
381         if (pBitmapRename)
382         {
383                 delete pBitmapRename;
384         }
385
386         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
387
388         return pIconListviewItem;
389 }
390
391 void
392 AlbumListEditorForm::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
393 {
394         AppLogDebug("ENTER");
395
396         if (status == ICON_LIST_VIEW_ITEM_CHECKED || status == ICON_LIST_VIEW_ITEM_UNCHECKED)
397         {
398                 if (status == ICON_LIST_VIEW_ITEM_CHECKED)
399                 {
400                         ++__checkedCount;
401                 }
402                 else if (status == ICON_LIST_VIEW_ITEM_UNCHECKED)
403                 {
404                         --__checkedCount;
405                 }
406
407                 String tempString;
408                 if (__checkedCount == 0)
409                 {
410                         tempString = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
411                 }
412                 else if (__checkedCount == 1)
413                 {
414                         tempString = ResourceManager::GetString(L"IDS_VR_POP_1_ITEM_SELECTED");
415                 }
416                 else
417                 {
418                         tempString.Format(FORMAT_BUFFER_SIZE, ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), __checkedCount);
419                 }
420
421                 __pSelectCountLabel->SetText(tempString);
422                 __pSelectCountLabel->RequestRedraw();
423                 __pEditorFolderIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
424         }
425
426         SetButtonState();
427         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
428 }
429
430 void
431 AlbumListEditorForm::OnIconListViewOverlayBitmapSelected (IconListView &iconListView, int index,
432                 int overlayBitmapId)
433 {
434         AppLogDebug("ENTER");
435         SceneManager* pSceneManager = SceneManager::GetInstance();
436
437         ArrayList* pSelectedIndex = new (std::nothrow) ArrayList(SingleObjectDeleter);
438         pSelectedIndex->Construct();
439         //Adding the Action Type
440         pSelectedIndex->Add(new (std::nothrow) Integer(ALBUM_RENAME));
441         pSelectedIndex->Add(new (std::nothrow) Integer(FILE_ACTION_MOVE));
442         pSelectedIndex->Add(new (std::nothrow) Integer(index));
443
444         if (__pEditorFolderIconList->IsItemChecked(index) == false)
445         {
446                 __pEditorFolderIconList->SetItemChecked(index,true);
447         }
448         else
449         {
450                 __pEditorFolderIconList->SetItemChecked(index,false);
451         }
452         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_NAME_EDITOR), pSelectedIndex);
453         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
454 }
455
456 bool
457 AlbumListEditorForm::DeleteItem(int index, IconListViewItem* pItem)
458 {
459         AppLogDebug("ENTER");
460         delete pItem;
461         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
462
463         return true;
464 }
465
466 result
467 AlbumListEditorForm::DeleteFolder(void)
468 {
469
470         AppLogDebug("ENTER");
471         IList* pIndexList = GetItemCheckedIndexListN();
472         if (pIndexList->GetCount() <= 0)
473         {
474                 delete pIndexList;
475                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
476                 return E_FAILURE;
477         }
478
479         if (__pFileUpdateTimer != null)
480         {
481                 delete __pFileUpdateTimer;
482         }
483         __pFileUpdateTimer = new (std::nothrow) FileUpdateTimer(pIndexList, __pPresentationModel, this, FILE_ACTION_DELETE);
484         result r = __pFileUpdateTimer->StartTimer();
485
486         if (IsFailed(r))
487         {
488                 delete __pFileUpdateTimer;
489                 __pFileUpdateTimer = null;
490                 return E_FAILURE;
491         }
492         else
493         {
494                 __pPresentationModel->SetUpdateProgressStatus(true);
495         }
496         return E_SUCCESS;
497 }
498
499 IList*
500 AlbumListEditorForm::GetItemCheckedIndexListN(void) const
501 {
502         AppLogDebug("ENTER");
503         IList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
504         Integer* pIndex = null;
505
506         if (__pEditorFolderIconList!=null)
507         {
508                 int loopCount = __pPresentationModel->GetFolderCount();
509                 for (int i = 0; i < loopCount; ++i)
510                 {
511                         if (__pEditorFolderIconList->IsItemChecked(i) == true)
512                         {
513                                 pIndex = new (std::nothrow) Integer(i);
514                                 pList->Add(pIndex);
515                                 AppLogDebug("checked index(%d)", i);
516                         }
517                 }
518         }
519         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
520
521         return pList;
522 }
523
524 void
525 AlbumListEditorForm::SetAllCheckState(const bool state)
526 {
527         AppLogDebug("ENTER");
528
529         int maxCount = __pPresentationModel->GetFolderCount();
530         String tempString;
531
532         if (state == true)
533         {
534                 if (maxCount == 1)
535                 {
536                         tempString = ResourceManager::GetString(L"IDS_VR_POP_1_ITEM_SELECTED;");
537                 }
538                 else
539                 {
540                         tempString.Format(FORMAT_BUFFER_SIZE,
541                                         ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), maxCount);
542                 }
543         }
544         else
545         {
546                 tempString = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
547         }
548
549         for (int i = 0; i < maxCount; ++i)
550         {
551                 __pEditorFolderIconList->SetItemChecked(i, state);
552                 __pEditorFolderIconList->RefreshList(i, LIST_REFRESH_TYPE_ITEM_MODIFY);
553         }
554
555         __pEditorFolderIconList->Draw();
556         __pSelectCountLabel->SetText(tempString);
557         __pSelectCountLabel->RequestRedraw();
558         __checkedCount = GetCheckedFolderCount();
559
560         SetButtonState();
561
562         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
563 }
564
565 int
566 AlbumListEditorForm::GetCheckedFolderCount(void) const
567 {
568         AppLogDebug("ENTER");
569         int maxCount = __pPresentationModel->GetFolderCount();
570         int count = 0;
571
572         for (int i = 0; i < maxCount; ++i)
573         {
574                 if (__pEditorFolderIconList->IsItemChecked (i))
575                 {
576                         ++count;
577                 }
578         }
579         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
580
581         return count;
582 }
583
584 void
585 AlbumListEditorForm::OnActionPerformed(const Control& source, int actionId)
586 {
587         AppLogDebug("ENTER");
588         switch (actionId)
589         {
590         case IDA_ALBUM_LIST_SELECT_ALL:
591         {
592                 if (__pPresentationModel->GetFolderCount() == GetCheckedFolderCount())
593                 {
594                         SetAllCheckState(false);
595                 }
596                 else
597                 {
598                         SetAllCheckState(true);
599                 }
600         }
601         break;
602
603         case IDA_FOOTER_DELETE:
604         {
605                 __pDeletePopup->SetShowState(true);
606                 __pDeletePopup->Show();
607         }
608         break;
609
610         case IDA_FOOTER_SHARE:
611         {
612
613                 if (__pShareContextMenu != NULL)
614                 {
615                         delete __pShareContextMenu;
616                         __pShareContextMenu = null;
617                 }
618
619
620                 Bitmap* pBitmapEmailContextItem = null;
621                 Bitmap* pBitmapMessageContextItem = null;
622                 pBitmapEmailContextItem = ResourceManager::GetBitmapN(IDB_IMAGE_CONTEXT_EMAIL_ICON);
623                 pBitmapMessageContextItem = ResourceManager::GetBitmapN(IDB_IMAGE_CONTEXT_MESSAGE_ICON);
624
625                 __pShareContextMenu = new (std::nothrow) ContextMenu();
626                 __pShareContextMenu->Construct(Point(GetClientAreaBounds().width/3 + 15, GetClientAreaBounds().height + __pSelectCountLabel->GetHeight() + 5),
627                                 CONTEXT_MENU_STYLE_LIST, CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD);
628
629                 if ( pBitmapMessageContextItem != null)
630                 {
631                  __pShareContextMenu->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_MESSAGE"),
632                                 IDA_CONTEXT_MENU_MESSAGE , *pBitmapMessageContextItem, null, null);
633
634                          delete pBitmapMessageContextItem;
635                 }
636
637                 if ( pBitmapEmailContextItem != null)
638                 {
639                         __pShareContextMenu->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_EMAIL"), IDA_CONTEXT_MENU_EMAIL,
640                                         *pBitmapEmailContextItem, null, null);
641
642                          delete pBitmapEmailContextItem;
643                 }
644
645                 __pShareContextMenu->SetFocusable(true);
646                 __pShareContextMenu->AddActionEventListener(*this);
647                 __pShareContextMenu->SetShowState(true);
648                 __pShareContextMenu->Show();
649         }
650         break;
651
652         case IDA_CONTEXT_MENU_MESSAGE:
653         {
654                 OnRequestMessage();
655         }
656         break;
657
658         case IDA_CONTEXT_MENU_EMAIL:
659         {
660                 OnRequestEmail();
661         }
662         break;
663
664         case IDA_DELETE_POPUP_DEL:
665         {
666                 __pDeletePopup->SetShowState(false);
667                 __pDeletePopup->Show();
668                 DeleteFolder();
669         }
670         break;
671
672         case IDA_DELETE_POPUP_CANCEL:
673         {
674                 __pDeletePopup->SetShowState(false);
675                 __pDeletePopup->Show();
676         }
677         break;
678
679         default:
680                 break;
681         }
682         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
683 }
684
685 void
686 AlbumListEditorForm::OnFormBackRequested(Form& source)
687 {
688         AppLogDebug("ENTER");
689         SceneManager* pSceneManager = SceneManager::GetInstance();
690         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
691         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
692 }
693
694 void
695 AlbumListEditorForm::OnSceneActivatedN(const SceneId& previousSceneId,
696                 const SceneId& currentSceneId, IList* pArgs)
697 {
698         AppLogDebug("ENTER OnSceneActivatedN");
699         String tempString;
700
701
702         int count = __pPresentationModel->GetFolderCount();
703
704         __pPresentationModel->AddContentEventListener(this);
705
706         __checkedCount = GetCheckedFolderCount();
707
708         if (previousSceneId == IDSCN_ALBUM_NAME_EDITOR)
709         {
710
711                 if (__checkedCount ==  0)
712                 {
713                         tempString = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
714                 }
715                 else
716                 {
717                         tempString.Format(FORMAT_BUFFER_SIZE,
718                                         ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), __checkedCount);
719                 }
720         }
721         else
722         {
723                 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
724
725                 for (int index = 0; index < count; ++index)
726                 {
727                         __pEditorFolderIconList->SetItemChecked(index,false);
728                 }
729
730                 __pEditorFolderIconList->UpdateList();
731                 __checkedCount = 0;
732
733                 tempString = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
734         }
735
736         __pSelectCountLabel->SetText(tempString);
737         __pSelectCountLabel->Invalidate(true);
738
739         SetButtonState();
740         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
741 }
742
743 void
744 AlbumListEditorForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
745 {
746         AppLogDebug("ENTER");
747         __pPresentationModel->RemoveContentEventListener(*this);
748
749         if (nextSceneId != IDSCN_ALBUM_NAME_EDITOR)
750         {
751                 int loopCount = __pPresentationModel->GetFolderCount();
752
753                 for (int count = 0; count < loopCount; ++count)
754                 {
755                         __pEditorFolderIconList->SetItemChecked(count,false);
756                 }
757                 __pEditorFolderIconList->UpdateList();
758         }
759
760         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
761 }
762
763 void
764 AlbumListEditorForm::OnFileInfoChanged(const ContentType contentType)
765 {
766         AppLogDebug("ENTER");
767         Update();
768         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
769 }
770
771 void
772 AlbumListEditorForm::OnThumbnailDecoded(const int index)
773 {
774         AppLogDebug("ENTER : index(%d)", index);
775         __pEditorFolderIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
776         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
777 }
778
779 void AlbumListEditorForm::OnFileOpInvalidate(enum FileActionMode actionId)
780 {
781         Invalidate(true);
782 }
783
784 void AlbumListEditorForm::OnFileOpComplete(enum FileActionMode actionId, enum FileActionCompleteRes res)
785 {
786         AppLogDebug("ENTER");
787         __pPresentationModel->SetUpdateProgressStatus(false);
788         SetAllCheckState(false);
789         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
790         __pEditorFolderIconList->UpdateList();
791
792         SceneManager* pSceneManager = SceneManager::GetInstance();
793         AppAssert(pSceneManager);
794         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
795         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
796 }
797
798 bool AlbumListEditorForm::OnKeyReleased(Control& source, const Tizen::Ui::KeyEventInfo& keyEventInfo)
799 {
800         AppLogDebug("ENTER");
801
802         if (keyEventInfo.GetKeyCode() == KEY_BACK || keyEventInfo.GetKeyCode() == KEY_ESC)
803         {
804                 __pDeletePopup->SetShowState(false);
805                 __pDeletePopup->Show();
806         }
807         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
808         return false;
809 }
810
811 result
812 AlbumListEditorForm::Update(void)
813 {
814         AppLogDebug("ENTER");
815         result r = __pEditorFolderIconList->UpdateList();
816         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
817
818         return r;
819 }
820
821 void
822 AlbumListEditorForm::OnRequestMessage(void)
823 {
824         AppLogDebug("ENTER");
825
826         int checkCount = GetCheckedFolderCount();
827
828         if (checkCount <= 0)
829         {
830                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
831
832                 return;
833         }
834
835         IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
836
837         int maxCount = __pPresentationModel->GetFolderCount();
838         ContentManager contentManager;
839         result r = contentManager.Construct();
840         if (r == E_SUCCESS)
841         {
842                 if (maxCount <= 0)
843                 {
844                         AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
845                         return;
846                 }
847
848                 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
849                 pArrayList->Construct();
850                 for (int i = 0; i < maxCount; ++i)
851                 {
852                         if (__pEditorFolderIconList->IsItemChecked (i))
853                         {
854                                 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(i));
855                                 IList* pContentIdList = pAlbumInfo->GetContentIdListN();
856                                 int loopCount = pContentIdList->GetCount();
857                                 for (int k = 0; k < loopCount; ++k)
858                                 {
859                                         ContentId* pContentId = static_cast<ContentId*>(pContentIdList->GetAt(k));
860                                         ContentInfo* pContentInfo = contentManager.GetContentInfoN(*pContentId);
861
862                                         if (pContentInfo == null)
863                                         {
864                                                 break;
865                                         }
866
867                                         pArrayList->Add(new (std::nothrow) String(pContentInfo->GetContentPath()));
868                                 }
869
870                                 if (i == 0)
871                                 {
872                                         break;
873                                 }
874                         }
875                 }
876
877                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
878                 pDataList->Construct();
879                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_MESSAGE_TYPE), new (std::nothrow) String(APPCONTROL_DATA_MMS));
880                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
881
882                 r = __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_MESSAGE, APPCONTROL_OPERATION_ID_COMPOSE,
883                                 null, null, pDataList, null);
884
885                 if (r == E_MAX_EXCEEDED)
886                 {
887                         MessageBox messageBox;
888                         messageBox.Construct(L"", ResourceManager::GetString(L"IDS_RCS_BODY_MAXIMUM_NUMBER_OF_FILES_EXCEEDED"),
889                                         MSGBOX_STYLE_NONE, 3000);
890                         int modalResult;
891                         messageBox.ShowAndWait(modalResult);
892                 }
893         }
894         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
895 }
896
897 void
898 AlbumListEditorForm::OnRequestEmail(void)
899 {
900         AppLogDebug("ENTER");
901
902         int checkCount = GetCheckedFolderCount();
903
904         if (checkCount <= 0)
905         {
906                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
907
908                 return;
909         }
910
911         IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
912
913         int maxCount = __pPresentationModel->GetFolderCount();
914         ContentManager contentManager;
915         result r = contentManager.Construct();
916         if (r == E_SUCCESS)
917         {
918                 if (maxCount <= 0)
919                 {
920                         AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
921                         return;
922                 }
923
924                 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
925                 pArrayList->Construct();
926                 for (int i = 0; i < maxCount; ++i)
927                 {
928                         if (__pEditorFolderIconList->IsItemChecked(i))
929                         {
930                                 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(i));
931                                 IList* pContentIdList = pAlbumInfo->GetContentIdListN();
932                                 int loopCount = pContentIdList->GetCount();
933                                 for (int k = 0; k < loopCount; ++k)
934                                 {
935                                         ContentId* pContentId = static_cast<ContentId*>(pContentIdList->GetAt(k));
936                                         ContentInfo* pContentInfo = contentManager.GetContentInfoN(*pContentId);
937
938                                         if (pContentInfo == null)
939                                         {
940                                                 break;
941                                         }
942
943                                         pArrayList->Add(new (std::nothrow) String(pContentInfo->GetContentPath()));
944                                 }
945
946                                 if (i == 0)
947                                 {
948                                         break;
949                                 }
950                         }
951                 }
952
953                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
954                 pDataList->Construct();
955                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
956
957                 r = __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_EMAIL, APPCONTROL_OPERATION_ID_COMPOSE,
958                                 new (std::nothrow) String(APPCONTROL_URI_MAIL_TO), null, pDataList, null);
959
960                 if (r == E_MAX_EXCEEDED)
961                 {
962                         MessageBox messageBox;
963                         messageBox.Construct(L"", ResourceManager::GetString(L"IDS_RCS_BODY_MAXIMUM_NUMBER_OF_FILES_EXCEEDED"),
964                                         MSGBOX_STYLE_NONE, 3000);
965                         int modalResult;
966                         messageBox.ShowAndWait(modalResult);
967                 }
968         }
969         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
970 }
971
972 void
973 AlbumListEditorForm::SetFooterButtonsState(const bool enableState)
974 {
975         AppLogDebug("ENTER");
976         Footer* pFooter = GetFooter();
977         AppAssert(pFooter);
978
979         if (enableState == true)
980         {
981                 pFooter->SetItemEnabled(0, true);
982                 pFooter->SetItemEnabled(1, true);
983         }
984         else
985         {
986                 pFooter->SetItemEnabled(0, false);
987                 pFooter->SetItemEnabled(1, false);
988         }
989
990         pFooter->RequestRedraw(true);
991         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
992 }
993
994 void
995 AlbumListEditorForm::SetButtonState(void)
996 {
997         AppLogDebug("ENTER");
998         if (GetCheckedFolderCount() > 0)
999         {
1000                 AppLogDebug("BUTTONSTATE : Request Enable");
1001                 SetFooterButtonsState(true);
1002         }
1003         else
1004         {
1005                 AppLogDebug("BUTTONSTATE : Request disable");
1006                 SetFooterButtonsState(false);
1007         }
1008         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1009 }
1010
1011
1012 void
1013 AlbumListEditorForm::OnOrientationChanged(const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
1014 {
1015
1016         IList* pIndexList = GetItemCheckedIndexListN();
1017
1018         if (__pEditorFolderIconList != null)
1019         {
1020                 RemoveControl(__pEditorFolderIconList);
1021         }
1022
1023         __pEditorFolderIconList = new IconListView();
1024
1025         if (orientationStatus == ORIENTATION_STATUS_PORTRAIT)
1026         {
1027                 __pEditorFolderIconList->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height- __pSelectCountLabel->GetHeight()),
1028                     Dimension(348, 348), ICON_LIST_VIEW_STYLE_MARK, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
1029         }
1030         else if (orientationStatus == ORIENTATION_STATUS_LANDSCAPE || orientationStatus == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
1031         {
1032                 int horizontalSpacing = 8;
1033                 int verticalSpacing = 60;
1034         int height = 424;
1035         int width = 410;
1036
1037         __pEditorFolderIconList->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height - __pSelectCountLabel->GetHeight()),
1038                                     Dimension(width, height), ICON_LIST_VIEW_STYLE_MARK, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
1039
1040         __pEditorFolderIconList->SetItemSpacing(horizontalSpacing, verticalSpacing);
1041         __pEditorFolderIconList->SetMargin(MARGIN_TYPE_TOP,40);
1042         }
1043
1044         Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
1045
1046         if (pBitmap != null)
1047         {
1048                 __pEditorFolderIconList->SetBitmapOfEmptyList(pBitmap);
1049                 delete pBitmap;
1050         }
1051
1052         __pEditorFolderIconList->SetCheckBoxPosition(ICON_LIST_VIEW_CHECK_BOX_POSITION_TOP_LEFT);
1053         __pEditorFolderIconList->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
1054         __pEditorFolderIconList->SetTouchAnimationEnabled(false);
1055         __pEditorFolderIconList->SetItemProvider(*this);
1056         __pEditorFolderIconList->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
1057         __pEditorFolderIconList->AddIconListViewItemEventListener(*this);
1058
1059         AddControl(__pEditorFolderIconList);
1060
1061         int loopCount = pIndexList->GetCount();
1062         int index = -1;
1063         for (int count = 0; count < loopCount; ++count)
1064         {
1065                 Integer* pRealIndex = static_cast<Integer*>(pIndexList->GetAt(count));
1066                  index = pRealIndex->ToInt();
1067                 __pEditorFolderIconList->SetItemChecked(index, true);
1068                 __pEditorFolderIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
1069         }
1070 }