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