Coding Idiom fixes
[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.0 (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_MEDIA_PATH = Environment::GetMediaPath();
44
45 static const int GAP_W_POPUP_ITEM = 5;
46 static const int W_DELETE_POPUP = 600;
47 static const int H_DELETE_POPUP = 300;
48 static const int H_DELETE_LABEL = 180;
49 static const int Y_DELETE_BUTTON = 180;
50 static const int H_DELETE_BUTTON = 80;
51
52 static const int FORMAT_BUFFER_SIZE = 256;
53
54 static const int X_POSITION_SHARE_CONTEXTMENU = 280;
55 static const int Y_POSITION_SHARE_CONTEXTMENU = 1140;
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         __pPresentationModel = AlbumListPresentationModel::GetInstance();
97         __pPresentationModel->ClearThumbnailRequests();
98         r = __pPresentationModel->AddPresentationModelListener(this);
99
100         SetFormBackEventListener(this);
101         GetHeader()->AddActionEventListener(*this);
102         GetFooter()->AddActionEventListener(*this);
103
104         r = InitializeControl();
105         if (r != E_SUCCESS)
106         {
107                 AppLogDebug("[%s] Unable to set InitializeControl.", GetErrorMessage(r));
108         }
109
110         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
111
112         return r;
113 }
114
115 result
116 AlbumListEditorForm::OnTerminating(void)
117 {
118         AppLogDebug("ENTER");
119         result r = E_SUCCESS;
120         r = __pPresentationModel->RemovePresentationModelListener(*this);
121
122         if (__pDeletePopup != null)
123         {
124                 delete __pDeletePopup;
125                 __pDeletePopup = null;
126         }
127         if (__pFileUpdateTimer != null)
128         {
129                 delete __pFileUpdateTimer;
130                 __pFileUpdateTimer = null;
131         }
132         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
133
134         return r;
135 }
136
137 void
138 AlbumListEditorForm::OnContentUpdated(void)
139 {
140         AppLogDebug("ENTER");
141         SceneManager* pSceneManager = SceneManager::GetInstance();
142         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
143         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
144 }
145
146 result
147 AlbumListEditorForm::InitializeControl(void)
148 {
149         AppLogDebug("ENTER");
150         result r = E_SUCCESS;
151         String tempString;
152
153         CreateIconListView();
154         __checkedCount = GetCheckedFolderCount();
155
156         __pSelectCountLabel = static_cast<Label*>(GetControl(L"IDC_LABEL_ALBUM_LIST_EDITOR_SELECTED"));
157         AppAssert(__pSelectCountLabel);
158
159         __pShareContextMenu = new (std::nothrow) ContextMenu();
160         r = __pShareContextMenu->Construct(Point(X_POSITION_SHARE_CONTEXTMENU, Y_POSITION_SHARE_CONTEXTMENU),
161                         CONTEXT_MENU_STYLE_LIST);
162         r = __pShareContextMenu->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_MESSAGE"),
163                         IDA_CONTEXT_MENU_MESSAGE);
164         r = __pShareContextMenu->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_EMAIL"), IDA_CONTEXT_MENU_EMAIL);
165         __pShareContextMenu->AddActionEventListener(*this);
166
167         r = InitializePopup();
168         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
169
170         return r;
171 }
172
173 result
174 AlbumListEditorForm::InitializePopup(void)
175 {
176         AppLogDebug("ENTER");
177         if (__pDeletePopup == null)
178         {
179                 __pDeletePopup = new (std::nothrow) Popup();
180                 __pDeletePopup->Construct(false, Dimension(W_DELETE_POPUP, H_DELETE_POPUP));
181
182                 Rectangle popupClientBounds = __pDeletePopup->GetClientAreaBounds();
183
184                 Label* pLabel = new (std::nothrow) Label();
185                 pLabel->Construct(Rectangle(0, 0, popupClientBounds.width, H_DELETE_LABEL),
186                                 ResourceManager::GetString(L"IDS_COM_POP_DELETE_Q"));
187
188                 Button* pDeleteButton = new (std::nothrow) Button();
189                 pDeleteButton->Construct(
190                                 Rectangle(0, Y_DELETE_BUTTON, popupClientBounds.width / 2 - GAP_W_POPUP_ITEM, H_DELETE_BUTTON),
191                                 ResourceManager::GetString(L"IDS_COM_BODY_DELETE"));
192                 pDeleteButton->SetColor(BUTTON_STATUS_NORMAL, COLOR_DELETE_BUTTON_NORMAL);
193                 pDeleteButton->SetColor(BUTTON_STATUS_PRESSED, COLOR_DELETE_BUTTON_PRESSED);
194                 pDeleteButton->SetTextColor(COLOR_DELETE_BUTTON_TEXT);
195                 pDeleteButton->SetActionId(IDA_DELETE_POPUP_DEL);
196                 pDeleteButton->AddActionEventListener(*this);
197
198                 Button* pCancelButton = new (std::nothrow) Button();
199                 pCancelButton->Construct(
200                                 Rectangle(popupClientBounds.width / 2 + GAP_W_POPUP_ITEM, Y_DELETE_BUTTON,
201                                                 popupClientBounds.width / 2 - GAP_W_POPUP_ITEM, H_DELETE_BUTTON),
202                                                 ResourceManager::GetString(L"IDS_COM_POP_CANCEL"));
203                 pCancelButton->SetActionId(IDA_DELETE_POPUP_CANCEL);
204                 pCancelButton->AddActionEventListener(*this);
205
206                 __pDeletePopup->AddControl(*pLabel);
207                 __pDeletePopup->AddControl(*pDeleteButton);
208                 __pDeletePopup->AddControl(*pCancelButton);
209         }
210         else
211         {
212                 __pDeletePopup->SetShowState(true);
213                 __pDeletePopup->Show();
214         }
215         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
216
217         return E_SUCCESS;
218 }
219
220 void
221 AlbumListEditorForm::CreateIconListView(void)
222 {
223         AppLogDebug("ENTER");
224         __pEditorFolderIconList = static_cast<IconListView*>(GetControl(L"IDC_ICONLISTVIEW_ALBUM_LIST_EDITOR"));
225         AppAssert(__pEditorFolderIconList);
226
227         __pEditorFolderIconList->SetItemProvider(*this);
228         __pEditorFolderIconList->AddIconListViewItemEventListener(*this);
229         __pEditorFolderIconList->SetShowState(true);
230         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
231 }
232
233 int
234 AlbumListEditorForm::GetItemCount(void)
235 {
236         AppLogDebug("ENTER");
237         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
238
239         return __pPresentationModel->GetFolderCount();
240 }
241
242 IconListViewItem*
243 AlbumListEditorForm::CreateItem(int index)
244 {
245         AppLogDebug("ENTER : index(%d)", index);
246         Bitmap* pBitmap = null;
247         Canvas* pEditAlbumCanvas = null;
248         Bitmap* pEditAlbumBitmap = null;
249         Bitmap* pBitmapRenameBg = null;
250         Bitmap* pBitmapRename = null;
251         String albumName ;
252         int canvasWidth = 64;
253         int canvasHeight = 64;
254
255         IconListViewItem* pIconListviewItem = new (std::nothrow) IconListViewItem();
256
257         IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
258         AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
259
260         Bitmap* pAlbumBitmap = pAlbumInfo->GetFolderThumnailBitmap();
261         if (pAlbumBitmap == null)
262         {
263                 __pPresentationModel->RequestThumbnail(index, 0);
264         }
265
266         pBitmap = __pPresentationModel->CreateMergeBitmapN(index);
267
268         if (__pEditorFolderIconList->IsItemChecked(index) == true)
269         {
270                 if (pBitmap != null)
271                 {
272                         BufferInfo bufferInfo;
273                         pBitmap->Lock(bufferInfo, INFINITE);
274                         pBitmap->Unlock();
275                         Color dimColor(COLOR_FOLDER_BITMAP_DIM);
276                         dimColor.SetAlpha(ALPHA_FOLDER_BITMAP_DIM);
277                         Canvas canvas;
278                         canvas.Construct(bufferInfo);
279                         canvas.FillRectangle(dimColor, canvas.GetBounds());
280                         Bitmap* pSelectedBitmap = new (std::nothrow) Bitmap();
281                         pSelectedBitmap->Construct(canvas, canvas.GetBounds());
282                         pIconListviewItem->Construct(*pBitmap, null, pSelectedBitmap);
283                         delete pSelectedBitmap;
284                 }
285         }
286         else
287         {
288                 pIconListviewItem->Construct(*pBitmap);
289         }
290
291         if (pBitmap != null)
292         {
293                 delete pBitmap;
294         }
295
296         pBitmapRenameBg = ResourceManager::GetBitmapN(IDB_ALBUM_EDIT_RENAME_BG);
297         pBitmapRename = ResourceManager::GetBitmapN(IDB_ALBUM_EDIT_RENAME);
298
299         if (pBitmapRenameBg != null && pBitmapRename != null)
300         {
301
302                 pEditAlbumCanvas = new (std::nothrow) Canvas();
303                 pEditAlbumCanvas->Construct(Rectangle(0, 0, canvasWidth, canvasHeight));
304                 pEditAlbumCanvas->DrawBitmap(Point(0, 0), *pBitmapRenameBg);
305                 pEditAlbumCanvas->DrawBitmap(Point(0, 0), *pBitmapRename);
306
307
308                 pEditAlbumBitmap = new (std::nothrow) Bitmap();
309
310                 if (pEditAlbumBitmap != NULL)
311                 {
312                         pEditAlbumBitmap->Construct(*pEditAlbumCanvas, Rectangle(0, 0, canvasWidth, canvasHeight));
313                         delete pEditAlbumCanvas;
314                 }
315
316                 albumName = pAlbumInfo->GetAlbumName();
317                 String reservedCameraName = ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB");
318                 String albumPath = pAlbumInfo->GetDirectory(0);
319                 albumPath.Append("/");
320
321                 if (index == 0 || reservedCameraName.Equals(albumName, true) || RESERVED_MEDIA_PATH.Equals(albumPath, true))
322                 {
323                         // rename disabled
324                 }
325                 else
326                 {
327                         pIconListviewItem->SetOverlayBitmap(IDA_ALBUM_EDIT, pEditAlbumBitmap, ALIGNMENT_RIGHT, ALIGNMENT_TOP);
328                 }
329
330                 if (pEditAlbumBitmap != null)
331                 {
332                         delete pEditAlbumBitmap;
333                 }
334         }
335
336         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
337
338         return pIconListviewItem;
339 }
340
341 void
342 AlbumListEditorForm::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
343 {
344         AppLogDebug("ENTER");
345
346         if (status == ICON_LIST_VIEW_ITEM_CHECKED || status == ICON_LIST_VIEW_ITEM_UNCHECKED)
347         {
348                 if (status == ICON_LIST_VIEW_ITEM_CHECKED)
349                 {
350                         ++__checkedCount;
351                 }
352                 else if (status == ICON_LIST_VIEW_ITEM_UNCHECKED)
353                 {
354                         --__checkedCount;
355                 }
356
357                 String tempString;
358                 if (__checkedCount == 0)
359                 {
360                         tempString = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
361                 }
362                 else if (__checkedCount == 1)
363                 {
364                         tempString = ResourceManager::GetString(L"IDS_VR_POP_1_ITEM_SELECTED");
365                 }
366                 else
367                 {
368                         tempString.Format(FORMAT_BUFFER_SIZE, ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), __checkedCount);
369                 }
370
371                 __pSelectCountLabel->SetText(tempString);
372                 __pSelectCountLabel->RequestRedraw();
373                 __pEditorFolderIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
374         }
375
376         SetButtonState();
377         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
378 }
379
380 void
381 AlbumListEditorForm::OnIconListViewOverlayBitmapSelected (IconListView &iconListView, int index,
382                 int overlayBitmapId)
383 {
384         AppLogDebug("ENTER");
385         SceneManager* pSceneManager = SceneManager::GetInstance();
386
387         ArrayList* pSelectedIndex = new (std::nothrow) ArrayList(SingleObjectDeleter);
388         pSelectedIndex->Construct();
389         //Adding the Action Type
390         pSelectedIndex->Add(new (std::nothrow) Integer(ALBUM_RENAME));
391         pSelectedIndex->Add(new (std::nothrow) Integer(FILE_ACTION_MOVE));
392         pSelectedIndex->Add(new (std::nothrow) Integer(index));
393
394         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_NAME_EDITOR), pSelectedIndex);
395         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
396 }
397
398 bool
399 AlbumListEditorForm::DeleteItem(int index, IconListViewItem* pItem)
400 {
401         AppLogDebug("ENTER");
402         delete pItem;
403         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
404
405         return true;
406 }
407
408 result
409 AlbumListEditorForm::DeleteFolder(void)
410 {
411
412         AppLogDebug("ENTER");
413         IList* pIndexList = GetItemCheckedIndexListN();
414         if (pIndexList->GetCount() <= 0)
415         {
416                 delete pIndexList;
417                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
418                 return E_FAILURE;
419         }
420
421         if (__pFileUpdateTimer != null)
422         {
423                 delete __pFileUpdateTimer;
424         }
425         __pFileUpdateTimer = new (std::nothrow) FileUpdateTimer(pIndexList, __pPresentationModel, this, FILE_ACTION_DELETE);
426         result r = __pFileUpdateTimer->StartTimer();
427
428         if (IsFailed(r))
429         {
430                 delete __pFileUpdateTimer;
431                 __pFileUpdateTimer = null;
432                 return E_FAILURE;
433         }
434         else
435         {
436                 __pPresentationModel->SetUpdateProgressStatus(true);
437         }
438         return E_SUCCESS;
439 }
440
441 IList*
442 AlbumListEditorForm::GetItemCheckedIndexListN(void) const
443 {
444         AppLogDebug("ENTER");
445         IList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
446         Integer* pIndex = null;
447
448         if (__pEditorFolderIconList!=null)
449         {
450                 int loopCount = __pPresentationModel->GetFolderCount();
451                 for (int i = 0; i < loopCount; ++i)
452                 {
453                         if (__pEditorFolderIconList->IsItemChecked(i) == true)
454                         {
455                                 pIndex = new (std::nothrow) Integer(i);
456                                 pList->Add(pIndex);
457                                 AppLogDebug("checked index(%d)", i);
458                         }
459                 }
460         }
461         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
462
463         return pList;
464 }
465
466 void
467 AlbumListEditorForm::SetAllCheckState(const bool state)
468 {
469         AppLogDebug("ENTER");
470
471         int maxCount = __pPresentationModel->GetFolderCount();
472         String tempString;
473
474         if (state == true)
475         {
476                 if (maxCount == 1)
477                 {
478                         tempString = ResourceManager::GetString(L"IDS_VR_POP_1_ITEM_SELECTED;");
479                 }
480                 else
481                 {
482                         tempString.Format(FORMAT_BUFFER_SIZE,
483                                         ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), maxCount);
484                 }
485         }
486         else
487         {
488                 tempString = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
489         }
490
491         for (int i = 0; i < maxCount; ++i)
492         {
493                 __pEditorFolderIconList->SetItemChecked(i, state);
494                 __pEditorFolderIconList->RefreshList(i, LIST_REFRESH_TYPE_ITEM_MODIFY);
495         }
496
497         __pEditorFolderIconList->Draw();
498         __pSelectCountLabel->SetText(tempString);
499         __pSelectCountLabel->RequestRedraw();
500         __checkedCount = GetCheckedFolderCount();
501
502         SetButtonState();
503
504         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
505 }
506
507 int
508 AlbumListEditorForm::GetCheckedFolderCount(void) const
509 {
510         AppLogDebug("ENTER");
511         int maxCount = __pPresentationModel->GetFolderCount();
512         int count = 0;
513
514         for (int i = 0 ; i < maxCount; ++i)
515         {
516                 if (__pEditorFolderIconList->IsItemChecked (i))
517                 {
518                         count++;
519                 }
520         }
521         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
522
523         return count;
524 }
525
526 void
527 AlbumListEditorForm::OnActionPerformed(const Control& source, int actionId)
528 {
529         AppLogDebug("ENTER");
530         switch (actionId)
531         {
532         case IDA_ALBUM_LIST_SELECT_ALL:
533         {
534                 if (__pPresentationModel->GetFolderCount() == GetCheckedFolderCount())
535                 {
536                         SetAllCheckState(false);
537                 }
538                 else
539                 {
540                         SetAllCheckState(true);
541                 }
542         }
543         break;
544
545         case IDA_FOOTER_DELETE:
546         {
547                 __pDeletePopup->SetShowState(true);
548                 __pDeletePopup->Show();
549         }
550         break;
551
552         case IDA_FOOTER_SHARE:
553         {
554                 __pShareContextMenu->SetShowState(true);
555                 __pShareContextMenu->Show();
556         }
557         break;
558
559         case IDA_CONTEXT_MENU_MESSAGE:
560         {
561                 OnRequestMessage();
562         }
563         break;
564
565         case IDA_CONTEXT_MENU_EMAIL:
566         {
567                 OnRequestEmail();
568         }
569         break;
570
571         case IDA_DELETE_POPUP_DEL:
572         {
573                 __pDeletePopup->SetShowState(false);
574                 __pDeletePopup->Show();
575                 DeleteFolder();
576         }
577         break;
578
579         case IDA_DELETE_POPUP_CANCEL:
580         {
581                 __pDeletePopup->SetShowState(false);
582                 __pDeletePopup->Show();
583         }
584         break;
585
586         default:
587                 break;
588         }
589         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
590 }
591
592 void
593 AlbumListEditorForm::OnFormBackRequested(Form& source)
594 {
595         AppLogDebug("ENTER");
596         SceneManager* pSceneManager = SceneManager::GetInstance();
597         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
598         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
599 }
600
601 void
602 AlbumListEditorForm::OnSceneActivatedN(const SceneId& previousSceneId,
603                 const SceneId& currentSceneId, IList* pArgs)
604 {
605         AppLogDebug("ENTER OnSceneActivatedN");
606         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
607         __pEditorFolderIconList->UpdateList();
608         __pPresentationModel->AddContentEventListener(this);
609
610         __checkedCount = GetCheckedFolderCount();
611
612         String tempString;
613
614         if (__checkedCount == 0)
615         {
616                 tempString = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
617         }
618         else if (__checkedCount == 1)
619         {
620                 tempString = ResourceManager::GetString(L"IDS_VR_POP_1_ITEM_SELECTED");
621         }
622         else
623         {
624                 tempString.Format(FORMAT_BUFFER_SIZE,
625                                 ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), __checkedCount);
626         }
627
628         __pSelectCountLabel->SetText(tempString);
629         __pSelectCountLabel->RequestRedraw();
630
631         SetButtonState();
632         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
633 }
634
635 void
636 AlbumListEditorForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
637 {
638         AppLogDebug("ENTER");
639         __pPresentationModel->RemoveContentEventListener(*this);
640         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
641 }
642
643 void
644 AlbumListEditorForm::OnFileInfoChanged(const ContentType contentType)
645 {
646         AppLogDebug("ENTER");
647         Update();
648         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
649 }
650
651 void
652 AlbumListEditorForm::OnThumbnailDecoded(const int index)
653 {
654         AppLogDebug("ENTER : index(%d)", index);
655         __pEditorFolderIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
656         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
657 }
658
659 void AlbumListEditorForm::OnFileOpInvalidate(enum FileActionMode actionId)
660 {
661         Invalidate(true);
662 }
663
664 void AlbumListEditorForm::OnFileOpComplete(enum FileActionMode actionId, enum FileActionCompleteRes res)
665 {
666         AppLogDebug("ENTER");
667         __pPresentationModel->SetUpdateProgressStatus(false);
668         SetAllCheckState(false);
669         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
670         __pEditorFolderIconList->UpdateList();
671
672         SceneManager* pSceneManager = SceneManager::GetInstance();
673         AppAssert(pSceneManager);
674         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
675 }
676
677 result
678 AlbumListEditorForm::Update(void)
679 {
680         AppLogDebug("ENTER");
681         result r = __pEditorFolderIconList->UpdateList();
682         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
683
684         return r;
685 }
686
687 void
688 AlbumListEditorForm::OnRequestMessage(void)
689 {
690         AppLogDebug("ENTER");
691
692         int checkCount = GetCheckedFolderCount();
693
694         if (checkCount <= 0)
695         {
696                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
697
698                 return;
699         }
700
701         IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
702
703         int maxCount = __pPresentationModel->GetFolderCount();
704         ContentManager contentManager;
705         result r = contentManager.Construct();
706         if (r == E_SUCCESS)
707         {
708                 if (maxCount <= 0)
709                 {
710                         AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
711                         return;
712                 }
713
714                 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
715                 pArrayList->Construct();
716                 for (int i = 0; i < maxCount; ++i)
717                 {
718                         if (__pEditorFolderIconList->IsItemChecked (i))
719                         {
720                                 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(i));
721                                 IList* pContentIdList = pAlbumInfo->GetContentIdListN();
722                                 int loopCount = pContentIdList->GetCount();
723                                 for (int k = 0; k < loopCount; ++k)
724                                 {
725                                         ContentId* pContentId = static_cast<ContentId*>(pContentIdList->GetAt(k));
726                                         ContentInfo* pContentInfo = contentManager.GetContentInfoN(*pContentId);
727
728                                         if (pContentInfo == null)
729                                         {
730                                                 break;
731                                         }
732
733                                         pArrayList->Add(new (std::nothrow) String(pContentInfo->GetContentPath()));
734                                 }
735
736                                 if (i == 0)
737                                 {
738                                         break;
739                                 }
740                         }
741                 }
742
743                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
744                 pDataList->Construct();
745                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_MESSAGE_TYPE), new (std::nothrow) String(APPCONTROL_DATA_MMS));
746                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
747
748                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_MESSAGE, APPCONTROL_OPERATION_ID_COMPOSE,
749                                 null, null, pDataList, null);
750         }
751         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
752 }
753
754 void
755 AlbumListEditorForm::OnRequestEmail(void)
756 {
757         AppLogDebug("ENTER");
758
759         int checkCount = GetCheckedFolderCount();
760
761         if (checkCount <= 0)
762         {
763                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
764
765                 return;
766         }
767
768         IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
769
770         int maxCount = __pPresentationModel->GetFolderCount();
771         ContentManager contentManager;
772         result r = contentManager.Construct();
773         if (r == E_SUCCESS)
774         {
775                 if (maxCount <= 0)
776                 {
777                         AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
778                         return;
779                 }
780
781                 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
782                 pArrayList->Construct();
783                 for (int i = 0; i < maxCount; ++i)
784                 {
785                         if (__pEditorFolderIconList->IsItemChecked(i))
786                         {
787                                 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(i));
788                                 IList* pContentIdList = pAlbumInfo->GetContentIdListN();
789                                 int loopCount = pContentIdList->GetCount();
790                                 for (int k = 0; k < loopCount; ++k)
791                                 {
792                                         ContentId* pContentId = static_cast<ContentId*>(pContentIdList->GetAt(k));
793                                         ContentInfo* pContentInfo = contentManager.GetContentInfoN(*pContentId);
794
795                                         if (pContentInfo == null)
796                                         {
797                                                 break;
798                                         }
799
800                                         pArrayList->Add(new (std::nothrow) String(pContentInfo->GetContentPath()));
801                                 }
802
803                                 if (i == 0)
804                                 {
805                                         break;
806                                 }
807                         }
808                 }
809
810                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
811                 pDataList->Construct();
812                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
813
814                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_EMAIL, APPCONTROL_OPERATION_ID_COMPOSE,
815                                 new (std::nothrow) String(APPCONTROL_URI_MAIL_TO), null, pDataList, null);
816         }
817         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
818 }
819
820 void
821 AlbumListEditorForm::SetFooterButtonsState(const bool enableState)
822 {
823         AppLogDebug("ENTER");
824         Footer* pFooter = GetFooter();
825         AppAssert(pFooter);
826
827         if (enableState == true)
828         {
829                 pFooter->SetItemEnabled(0, true);
830                 pFooter->SetItemEnabled(1, true);
831         }
832         else
833         {
834                 pFooter->SetItemEnabled(0, false);
835                 pFooter->SetItemEnabled(1, false);
836         }
837
838         pFooter->RequestRedraw(true);
839         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
840 }
841
842 void
843 AlbumListEditorForm::SetButtonState(void)
844 {
845         AppLogDebug("ENTER");
846         if (GetCheckedFolderCount() > 0)
847         {
848                 AppLogDebug("BUTTONSTATE : Request Enable");
849                 SetFooterButtonsState(true);
850         }
851         else
852         {
853                 AppLogDebug("BUTTONSTATE : Request disable");
854                 SetFooterButtonsState(false);
855         }
856         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
857 }