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