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