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