Fixed memory leaks
[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(
206                                 Rectangle(10, Y_DELETE_BUTTON, popupClientBounds.width / 2 - GAP_W_POPUP_ITEM -10, H_DELETE_BUTTON),
207                                 ResourceManager::GetString(L"IDS_COM_BODY_DELETE"));
208                 pDeleteButton->SetColor(BUTTON_STATUS_NORMAL, COLOR_DELETE_BUTTON_NORMAL);
209                 pDeleteButton->SetColor(BUTTON_STATUS_PRESSED, COLOR_DELETE_BUTTON_PRESSED);
210                 pDeleteButton->SetTextColor(COLOR_DELETE_BUTTON_TEXT);
211                 pDeleteButton->SetActionId(IDA_DELETE_POPUP_DEL);
212                 pDeleteButton->AddActionEventListener(*this);
213
214                 Button* pCancelButton = new (std::nothrow) Button();
215                 pCancelButton->Construct(
216                                 Rectangle(popupClientBounds.width / 2 + GAP_W_POPUP_ITEM, Y_DELETE_BUTTON,
217                                                 popupClientBounds.width / 2 - GAP_W_POPUP_ITEM -10, H_DELETE_BUTTON),
218                                                 ResourceManager::GetString(L"IDS_COM_POP_CANCEL"));
219                 pCancelButton->SetActionId(IDA_DELETE_POPUP_CANCEL);
220                 pCancelButton->AddActionEventListener(*this);
221
222                 __pDeletePopup->AddControl(pLabel);
223                 __pDeletePopup->AddControl(pDeleteButton);
224                 __pDeletePopup->AddControl(pCancelButton);
225         }
226         else
227         {
228                 __pDeletePopup->SetShowState(true);
229                 __pDeletePopup->Show();
230         }
231         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
232
233         return E_SUCCESS;
234 }
235
236 void
237 AlbumListEditorForm::CreateIconListView(void)
238 {
239         AppLogDebug("ENTER");
240
241
242         __pEditorFolderIconList = new IconListView();
243         __pEditorFolderIconList->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height - __pSelectCountLabel->GetHeight()),
244                     Dimension(348, 348), ICON_LIST_VIEW_STYLE_MARK, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
245         __pEditorFolderIconList->SetCheckBoxPosition(ICON_LIST_VIEW_CHECK_BOX_POSITION_TOP_LEFT);
246         __pEditorFolderIconList->SetTouchAnimationEnabled(false);
247         __pEditorFolderIconList->SetItemProvider(*this);
248         __pEditorFolderIconList->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
249         __pEditorFolderIconList->AddIconListViewItemEventListener(*this);
250
251         Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
252
253         if (pBitmap != null)
254         {
255                 __pEditorFolderIconList->SetBitmapOfEmptyList(pBitmap);
256                 delete pBitmap;
257         }
258
259         __pEditorFolderIconList->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
260
261         AddControl(*__pEditorFolderIconList);
262
263         __pEditorFolderIconList->SetShowState(true);
264
265         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
266 }
267
268 int
269 AlbumListEditorForm::GetItemCount(void)
270 {
271         AppLogDebug("ENTER");
272         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
273
274         return __pPresentationModel->GetFolderCount();
275 }
276
277 IconListViewItem*
278 AlbumListEditorForm::CreateItem(int index)
279 {
280         AppLogDebug("ENTER : index(%d)", index);
281         Bitmap* pBitmap = null;
282         Canvas* pEditAlbumCanvas = null;
283         Bitmap* pEditAlbumBitmap = null;
284         Bitmap* pBitmapRenameBg = null;
285         Bitmap* pBitmapRename = null;
286         String albumName ;
287         int canvasWidth = 64;
288         int canvasHeight = 64;
289
290         IconListViewItem* pIconListviewItem = new (std::nothrow) IconListViewItem();
291
292         IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
293         AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
294
295         Bitmap* pAlbumBitmap = pAlbumInfo->GetFolderThumnailBitmap();
296         if (pAlbumBitmap == null)
297         {
298                 __pPresentationModel->RequestThumbnail(index, 0);
299         }
300
301         pBitmap = __pPresentationModel->CreateMergeBitmapN(index);
302
303         if (__pEditorFolderIconList->IsItemChecked(index) == true)
304         {
305                 if (pBitmap != null)
306                 {
307                         BufferInfo bufferInfo;
308                         pBitmap->Lock(bufferInfo, INFINITE);
309                         pBitmap->Unlock();
310                         Color dimColor(COLOR_FOLDER_BITMAP_DIM);
311                         dimColor.SetAlpha(ALPHA_FOLDER_BITMAP_DIM);
312                         Canvas canvas;
313                         canvas.Construct(bufferInfo);
314                         canvas.FillRectangle(dimColor, canvas.GetBounds());
315                         Bitmap* pSelectedBitmap = new (std::nothrow) Bitmap();
316                         pSelectedBitmap->Construct(canvas, canvas.GetBounds());
317                         pIconListviewItem->Construct(*pBitmap, null, pSelectedBitmap);
318                         delete pSelectedBitmap;
319                 }
320         }
321         else
322         {
323                 pIconListviewItem->Construct(*pBitmap);
324         }
325
326         if (pBitmap != null)
327         {
328                 delete pBitmap;
329         }
330
331         pBitmapRenameBg = ResourceManager::GetBitmapN(IDB_ALBUM_EDIT_RENAME_BG);
332         pBitmapRename = ResourceManager::GetBitmapN(IDB_ALBUM_EDIT_RENAME);
333
334         if (pBitmapRenameBg != null && pBitmapRename != null)
335         {
336
337                 pEditAlbumCanvas = new (std::nothrow) Canvas();
338                 pEditAlbumCanvas->Construct(Rectangle(0, 0, canvasWidth, canvasHeight));
339                 pEditAlbumCanvas->DrawBitmap(Point(0, 0), *pBitmapRenameBg);
340                 pEditAlbumCanvas->DrawBitmap(Point(0, 0), *pBitmapRename);
341
342
343                 pEditAlbumBitmap = new (std::nothrow) Bitmap();
344
345                 if (pEditAlbumBitmap != NULL)
346                 {
347                         pEditAlbumBitmap->Construct(*pEditAlbumCanvas, Rectangle(0, 0, canvasWidth, canvasHeight));
348
349                 }
350                 delete pEditAlbumCanvas;
351
352                 albumName = pAlbumInfo->GetAlbumName();
353                 String reservedCameraName = ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB");
354                 String albumPath = pAlbumInfo->GetDirectory(0);
355                 albumPath.Append(DIRECTORY_SEPARATOR);
356
357                 if (index == 0 || (reservedCameraName.Equals(albumName, true) &&
358                         (RESERVED_CAMERA_PATH.Equals(albumPath, true) || RESERVED_CAMERA_PATH_EXT.Equals(albumPath, true)))
359                         || RESERVED_MEDIA_PATH.Equals(albumPath, true) || RESERVED_EXTERNAL_MEDIA_PATH.Equals(albumPath, true))
360                 {
361                         // rename disabled
362                 }
363                 else
364                 {
365                         pIconListviewItem->SetOverlayBitmap(IDA_ALBUM_EDIT, pEditAlbumBitmap, ALIGNMENT_RIGHT, ALIGNMENT_TOP);
366                 }
367
368                 if (pEditAlbumBitmap != null)
369                 {
370                         delete pEditAlbumBitmap;
371                 }
372         }
373
374         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
375
376         return pIconListviewItem;
377 }
378
379 void
380 AlbumListEditorForm::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
381 {
382         AppLogDebug("ENTER");
383
384         if (status == ICON_LIST_VIEW_ITEM_CHECKED || status == ICON_LIST_VIEW_ITEM_UNCHECKED)
385         {
386                 if (status == ICON_LIST_VIEW_ITEM_CHECKED)
387                 {
388                         ++__checkedCount;
389                 }
390                 else if (status == ICON_LIST_VIEW_ITEM_UNCHECKED)
391                 {
392                         --__checkedCount;
393                 }
394
395                 String tempString;
396                 if (__checkedCount == 0)
397                 {
398                         tempString = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
399                 }
400                 else if (__checkedCount == 1)
401                 {
402                         tempString = ResourceManager::GetString(L"IDS_VR_POP_1_ITEM_SELECTED");
403                 }
404                 else
405                 {
406                         tempString.Format(FORMAT_BUFFER_SIZE, ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), __checkedCount);
407                 }
408
409                 __pSelectCountLabel->SetText(tempString);
410                 __pSelectCountLabel->RequestRedraw();
411                 __pEditorFolderIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
412         }
413
414         SetButtonState();
415         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
416 }
417
418 void
419 AlbumListEditorForm::OnIconListViewOverlayBitmapSelected (IconListView &iconListView, int index,
420                 int overlayBitmapId)
421 {
422         AppLogDebug("ENTER");
423         SceneManager* pSceneManager = SceneManager::GetInstance();
424
425         ArrayList* pSelectedIndex = new (std::nothrow) ArrayList(SingleObjectDeleter);
426         pSelectedIndex->Construct();
427         //Adding the Action Type
428         pSelectedIndex->Add(new (std::nothrow) Integer(ALBUM_RENAME));
429         pSelectedIndex->Add(new (std::nothrow) Integer(FILE_ACTION_MOVE));
430         pSelectedIndex->Add(new (std::nothrow) Integer(index));
431
432         if( __pEditorFolderIconList->IsItemChecked(index) == false )
433         {
434                 __pEditorFolderIconList->SetItemChecked(index,true);
435         }
436         else
437         {
438                 __pEditorFolderIconList->SetItemChecked(index,false);
439         }
440         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_NAME_EDITOR), pSelectedIndex);
441         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
442 }
443
444 bool
445 AlbumListEditorForm::DeleteItem(int index, IconListViewItem* pItem)
446 {
447         AppLogDebug("ENTER");
448         delete pItem;
449         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
450
451         return true;
452 }
453
454 result
455 AlbumListEditorForm::DeleteFolder(void)
456 {
457
458         AppLogDebug("ENTER");
459         IList* pIndexList = GetItemCheckedIndexListN();
460         if (pIndexList->GetCount() <= 0)
461         {
462                 delete pIndexList;
463                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
464                 return E_FAILURE;
465         }
466
467         if (__pFileUpdateTimer != null)
468         {
469                 delete __pFileUpdateTimer;
470         }
471         __pFileUpdateTimer = new (std::nothrow) FileUpdateTimer(pIndexList, __pPresentationModel, this, FILE_ACTION_DELETE);
472         result r = __pFileUpdateTimer->StartTimer();
473
474         if (IsFailed(r))
475         {
476                 delete __pFileUpdateTimer;
477                 __pFileUpdateTimer = null;
478                 return E_FAILURE;
479         }
480         else
481         {
482                 __pPresentationModel->SetUpdateProgressStatus(true);
483         }
484         return E_SUCCESS;
485 }
486
487 IList*
488 AlbumListEditorForm::GetItemCheckedIndexListN(void) const
489 {
490         AppLogDebug("ENTER");
491         IList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
492         Integer* pIndex = null;
493
494         if (__pEditorFolderIconList!=null)
495         {
496                 int loopCount = __pPresentationModel->GetFolderCount();
497                 for (int i = 0; i < loopCount; ++i)
498                 {
499                         if (__pEditorFolderIconList->IsItemChecked(i) == true)
500                         {
501                                 pIndex = new (std::nothrow) Integer(i);
502                                 pList->Add(pIndex);
503                                 AppLogDebug("checked index(%d)", i);
504                         }
505                 }
506         }
507         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
508
509         return pList;
510 }
511
512 void
513 AlbumListEditorForm::SetAllCheckState(const bool state)
514 {
515         AppLogDebug("ENTER");
516
517         int maxCount = __pPresentationModel->GetFolderCount();
518         String tempString;
519
520         if (state == true)
521         {
522                 if (maxCount == 1)
523                 {
524                         tempString = ResourceManager::GetString(L"IDS_VR_POP_1_ITEM_SELECTED;");
525                 }
526                 else
527                 {
528                         tempString.Format(FORMAT_BUFFER_SIZE,
529                                         ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), maxCount);
530                 }
531         }
532         else
533         {
534                 tempString = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
535         }
536
537         for (int i = 0; i < maxCount; ++i)
538         {
539                 __pEditorFolderIconList->SetItemChecked(i, state);
540                 __pEditorFolderIconList->RefreshList(i, LIST_REFRESH_TYPE_ITEM_MODIFY);
541         }
542
543         __pEditorFolderIconList->Draw();
544         __pSelectCountLabel->SetText(tempString);
545         __pSelectCountLabel->RequestRedraw();
546         __checkedCount = GetCheckedFolderCount();
547
548         SetButtonState();
549
550         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
551 }
552
553 int
554 AlbumListEditorForm::GetCheckedFolderCount(void) const
555 {
556         AppLogDebug("ENTER");
557         int maxCount = __pPresentationModel->GetFolderCount();
558         int count = 0;
559
560         for (int i = 0 ; i < maxCount; ++i)
561         {
562                 if (__pEditorFolderIconList->IsItemChecked (i))
563                 {
564                         count++;
565                 }
566         }
567         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
568
569         return count;
570 }
571
572 void
573 AlbumListEditorForm::OnActionPerformed(const Control& source, int actionId)
574 {
575         AppLogDebug("ENTER");
576         switch (actionId)
577         {
578         case IDA_ALBUM_LIST_SELECT_ALL:
579         {
580                 if (__pPresentationModel->GetFolderCount() == GetCheckedFolderCount())
581                 {
582                         SetAllCheckState(false);
583                 }
584                 else
585                 {
586                         SetAllCheckState(true);
587                 }
588         }
589         break;
590
591         case IDA_FOOTER_DELETE:
592         {
593                 __pDeletePopup->SetShowState(true);
594                 __pDeletePopup->Show();
595         }
596         break;
597
598         case IDA_FOOTER_SHARE:
599         {
600
601                 if( __pShareContextMenu != NULL)
602                 {
603                         delete __pShareContextMenu;
604                         __pShareContextMenu = null;
605                 }
606
607                 __pShareContextMenu = new (std::nothrow) ContextMenu();
608                 __pShareContextMenu->Construct(Point(GetClientAreaBounds().width/3 + 15, GetClientAreaBounds().height + __pSelectCountLabel->GetHeight() + 5),
609                                 CONTEXT_MENU_STYLE_LIST, CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD);
610                  __pShareContextMenu->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_MESSAGE"),
611                                 IDA_CONTEXT_MENU_MESSAGE);
612                 __pShareContextMenu->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_EMAIL"), IDA_CONTEXT_MENU_EMAIL);
613                 __pShareContextMenu->SetFocusable(true);
614                 __pShareContextMenu->AddActionEventListener(*this);
615                 __pShareContextMenu->SetShowState(true);
616                 __pShareContextMenu->Show();
617         }
618         break;
619
620         case IDA_CONTEXT_MENU_MESSAGE:
621         {
622                 OnRequestMessage();
623         }
624         break;
625
626         case IDA_CONTEXT_MENU_EMAIL:
627         {
628                 OnRequestEmail();
629         }
630         break;
631
632         case IDA_DELETE_POPUP_DEL:
633         {
634                 __pDeletePopup->SetShowState(false);
635                 __pDeletePopup->Show();
636                 DeleteFolder();
637         }
638         break;
639
640         case IDA_DELETE_POPUP_CANCEL:
641         {
642                 __pDeletePopup->SetShowState(false);
643                 __pDeletePopup->Show();
644         }
645         break;
646
647         default:
648                 break;
649         }
650         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
651 }
652
653 void
654 AlbumListEditorForm::OnFormBackRequested(Form& source)
655 {
656         AppLogDebug("ENTER");
657         SceneManager* pSceneManager = SceneManager::GetInstance();
658         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
659         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
660 }
661
662 void
663 AlbumListEditorForm::OnSceneActivatedN(const SceneId& previousSceneId,
664                 const SceneId& currentSceneId, IList* pArgs)
665 {
666         AppLogDebug("ENTER OnSceneActivatedN");
667         String tempString;
668
669
670         int count = __pPresentationModel->GetFolderCount();
671
672         __pPresentationModel->AddContentEventListener(this);
673
674         __checkedCount = GetCheckedFolderCount();
675
676         if ( previousSceneId == IDSCN_ALBUM_NAME_EDITOR )
677         {
678
679                 if (__checkedCount ==  0)
680                 {
681                         tempString = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
682                 }
683                 else
684                 {
685                         tempString.Format(FORMAT_BUFFER_SIZE,
686                                         ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), __checkedCount);
687                 }
688         }
689         else
690         {
691                 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
692
693                 for ( int index = 0 ; index < count ; index++ )
694                 {
695                         __pEditorFolderIconList->SetItemChecked(index,false);
696                 }
697
698                 __pEditorFolderIconList->UpdateList();
699
700                 tempString = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
701         }
702
703         __pSelectCountLabel->SetText(tempString);
704         __pSelectCountLabel->Invalidate(true);
705
706         SetButtonState();
707         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
708 }
709
710 void
711 AlbumListEditorForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
712 {
713         AppLogDebug("ENTER");
714         __pPresentationModel->RemoveContentEventListener(*this);
715
716         if (nextSceneId != IDSCN_ALBUM_NAME_EDITOR )
717         {
718                 int loopCount = __pPresentationModel->GetFolderCount();
719
720                 for( int count = 0 ; count < loopCount ; count++ )
721                 {
722                         __pEditorFolderIconList->SetItemChecked(count,false);
723                 }
724                 __pEditorFolderIconList->UpdateList();
725         }
726
727         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
728 }
729
730 void
731 AlbumListEditorForm::OnFileInfoChanged(const ContentType contentType)
732 {
733         AppLogDebug("ENTER");
734         Update();
735         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
736 }
737
738 void
739 AlbumListEditorForm::OnThumbnailDecoded(const int index)
740 {
741         AppLogDebug("ENTER : index(%d)", index);
742         __pEditorFolderIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
743         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
744 }
745
746 void AlbumListEditorForm::OnFileOpInvalidate(enum FileActionMode actionId)
747 {
748         Invalidate(true);
749 }
750
751 void AlbumListEditorForm::OnFileOpComplete(enum FileActionMode actionId, enum FileActionCompleteRes res)
752 {
753         AppLogDebug("ENTER");
754         __pPresentationModel->SetUpdateProgressStatus(false);
755         SetAllCheckState(false);
756         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
757         __pEditorFolderIconList->UpdateList();
758
759         SceneManager* pSceneManager = SceneManager::GetInstance();
760         AppAssert(pSceneManager);
761         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
762 }
763
764 bool AlbumListEditorForm::OnKeyReleased(Control& source, const Tizen::Ui::KeyEventInfo& keyEventInfo)
765 {
766         AppLogDebug("ENTER");
767
768         if(keyEventInfo.GetKeyCode() == KEY_BACK)
769         {
770                 __pDeletePopup->SetShowState(false);
771                 __pDeletePopup->Show();
772         }
773         return true;
774 }
775
776 result
777 AlbumListEditorForm::Update(void)
778 {
779         AppLogDebug("ENTER");
780         result r = __pEditorFolderIconList->UpdateList();
781         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
782
783         return r;
784 }
785
786 void
787 AlbumListEditorForm::OnRequestMessage(void)
788 {
789         AppLogDebug("ENTER");
790
791         int checkCount = GetCheckedFolderCount();
792
793         if (checkCount <= 0)
794         {
795                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
796
797                 return;
798         }
799
800         IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
801
802         int maxCount = __pPresentationModel->GetFolderCount();
803         ContentManager contentManager;
804         result r = contentManager.Construct();
805         if (r == E_SUCCESS)
806         {
807                 if (maxCount <= 0)
808                 {
809                         AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
810                         return;
811                 }
812
813                 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
814                 pArrayList->Construct();
815                 for (int i = 0; i < maxCount; ++i)
816                 {
817                         if (__pEditorFolderIconList->IsItemChecked (i))
818                         {
819                                 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(i));
820                                 IList* pContentIdList = pAlbumInfo->GetContentIdListN();
821                                 int loopCount = pContentIdList->GetCount();
822                                 for (int k = 0; k < loopCount; ++k)
823                                 {
824                                         ContentId* pContentId = static_cast<ContentId*>(pContentIdList->GetAt(k));
825                                         ContentInfo* pContentInfo = contentManager.GetContentInfoN(*pContentId);
826
827                                         if (pContentInfo == null)
828                                         {
829                                                 break;
830                                         }
831
832                                         pArrayList->Add(new (std::nothrow) String(pContentInfo->GetContentPath()));
833                                 }
834
835                                 if (i == 0)
836                                 {
837                                         break;
838                                 }
839                         }
840                 }
841
842                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
843                 pDataList->Construct();
844                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_MESSAGE_TYPE), new (std::nothrow) String(APPCONTROL_DATA_MMS));
845                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
846
847                 r = __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_MESSAGE, APPCONTROL_OPERATION_ID_COMPOSE,
848                                 null, null, pDataList, null);
849
850                 if (r == E_MAX_EXCEEDED)
851                 {
852                         MessageBox messageBox;
853                         messageBox.Construct(L"", ResourceManager::GetString(L"IDS_RCS_BODY_MAXIMUM_NUMBER_OF_FILES_EXCEEDED"),
854                                         MSGBOX_STYLE_NONE, 3000);
855                         int modalResult;
856                         messageBox.ShowAndWait(modalResult);
857                 }
858         }
859         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
860 }
861
862 void
863 AlbumListEditorForm::OnRequestEmail(void)
864 {
865         AppLogDebug("ENTER");
866
867         int checkCount = GetCheckedFolderCount();
868
869         if (checkCount <= 0)
870         {
871                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
872
873                 return;
874         }
875
876         IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
877
878         int maxCount = __pPresentationModel->GetFolderCount();
879         ContentManager contentManager;
880         result r = contentManager.Construct();
881         if (r == E_SUCCESS)
882         {
883                 if (maxCount <= 0)
884                 {
885                         AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
886                         return;
887                 }
888
889                 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
890                 pArrayList->Construct();
891                 for (int i = 0; i < maxCount; ++i)
892                 {
893                         if (__pEditorFolderIconList->IsItemChecked(i))
894                         {
895                                 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(i));
896                                 IList* pContentIdList = pAlbumInfo->GetContentIdListN();
897                                 int loopCount = pContentIdList->GetCount();
898                                 for (int k = 0; k < loopCount; ++k)
899                                 {
900                                         ContentId* pContentId = static_cast<ContentId*>(pContentIdList->GetAt(k));
901                                         ContentInfo* pContentInfo = contentManager.GetContentInfoN(*pContentId);
902
903                                         if (pContentInfo == null)
904                                         {
905                                                 break;
906                                         }
907
908                                         pArrayList->Add(new (std::nothrow) String(pContentInfo->GetContentPath()));
909                                 }
910
911                                 if (i == 0)
912                                 {
913                                         break;
914                                 }
915                         }
916                 }
917
918                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
919                 pDataList->Construct();
920                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
921
922                 r = __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_EMAIL, APPCONTROL_OPERATION_ID_COMPOSE,
923                                 new (std::nothrow) String(APPCONTROL_URI_MAIL_TO), null, pDataList, null);
924
925                 if (r == E_MAX_EXCEEDED)
926                 {
927                         MessageBox messageBox;
928                         messageBox.Construct(L"", ResourceManager::GetString(L"IDS_RCS_BODY_MAXIMUM_NUMBER_OF_FILES_EXCEEDED"),
929                                         MSGBOX_STYLE_NONE, 3000);
930                         int modalResult;
931                         messageBox.ShowAndWait(modalResult);
932                 }
933         }
934         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
935 }
936
937 void
938 AlbumListEditorForm::SetFooterButtonsState(const bool enableState)
939 {
940         AppLogDebug("ENTER");
941         Footer* pFooter = GetFooter();
942         AppAssert(pFooter);
943
944         if (enableState == true)
945         {
946                 pFooter->SetItemEnabled(0, true);
947                 pFooter->SetItemEnabled(1, true);
948         }
949         else
950         {
951                 pFooter->SetItemEnabled(0, false);
952                 pFooter->SetItemEnabled(1, false);
953         }
954
955         pFooter->RequestRedraw(true);
956         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
957 }
958
959 void
960 AlbumListEditorForm::SetButtonState(void)
961 {
962         AppLogDebug("ENTER");
963         if (GetCheckedFolderCount() > 0)
964         {
965                 AppLogDebug("BUTTONSTATE : Request Enable");
966                 SetFooterButtonsState(true);
967         }
968         else
969         {
970                 AppLogDebug("BUTTONSTATE : Request disable");
971                 SetFooterButtonsState(false);
972         }
973         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
974 }
975
976
977 void
978 AlbumListEditorForm::OnOrientationChanged(const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
979 {
980
981         IList* pIndexList = GetItemCheckedIndexListN();
982
983         if( __pEditorFolderIconList != null )
984         {
985                 RemoveControl(__pEditorFolderIconList);
986         }
987
988         __pEditorFolderIconList = new IconListView();
989
990         if( orientationStatus == ORIENTATION_STATUS_PORTRAIT )
991         {
992                 __pEditorFolderIconList->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height- __pSelectCountLabel->GetHeight()),
993                     Dimension(348, 348), ICON_LIST_VIEW_STYLE_MARK, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
994         }
995         else if (orientationStatus == ORIENTATION_STATUS_LANDSCAPE || orientationStatus == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
996         {
997                 int horizontalSpacing = 8;
998                 int verticalSpacing = 60;
999         int height = 424;
1000         int width = 410;
1001
1002         __pEditorFolderIconList->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height - __pSelectCountLabel->GetHeight()),
1003                                     Dimension(width, height), ICON_LIST_VIEW_STYLE_MARK, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
1004
1005         __pEditorFolderIconList->SetItemSpacing(horizontalSpacing, verticalSpacing);
1006         __pEditorFolderIconList->SetMargin(MARGIN_TYPE_TOP,40);
1007         }
1008
1009         Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
1010
1011         if (pBitmap != null)
1012         {
1013                 __pEditorFolderIconList->SetBitmapOfEmptyList(pBitmap);
1014                 delete pBitmap;
1015         }
1016
1017         __pEditorFolderIconList->SetCheckBoxPosition(ICON_LIST_VIEW_CHECK_BOX_POSITION_TOP_LEFT);
1018         __pEditorFolderIconList->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
1019         __pEditorFolderIconList->SetTouchAnimationEnabled(false);
1020         __pEditorFolderIconList->SetItemProvider(*this);
1021         __pEditorFolderIconList->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
1022         __pEditorFolderIconList->AddIconListViewItemEventListener(*this);
1023
1024         AddControl(*__pEditorFolderIconList);
1025
1026         int loopCount = pIndexList->GetCount();
1027         int index = -1 ;
1028         for(int count = 0 ; count < loopCount; count ++)
1029         {
1030                 Integer* pRealIndex = static_cast<Integer*>(pIndexList->GetAt(count));
1031                  index = pRealIndex->ToInt();
1032                 __pEditorFolderIconList->SetItemChecked(index, true);
1033                 __pEditorFolderIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
1034         }
1035
1036 }
1037