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