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