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