133b067d85b0f3c7ce90d9846c110e3eedf91a73
[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
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                 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
654
655                 for ( int index = 0 ; index < count ; index++ )
656                 {
657                         __pEditorFolderIconList->SetItemChecked(index,false);
658                 }
659
660                 __pEditorFolderIconList->UpdateList();
661
662                 tempString = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
663         }
664
665         __pSelectCountLabel->SetText(tempString);
666         __pSelectCountLabel->Invalidate(true);
667
668         SetButtonState();
669         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
670 }
671
672 void
673 AlbumListEditorForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
674 {
675         AppLogDebug("ENTER");
676         __pPresentationModel->RemoveContentEventListener(*this);
677         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
678 }
679
680 void
681 AlbumListEditorForm::OnFileInfoChanged(const ContentType contentType)
682 {
683         AppLogDebug("ENTER");
684         Update();
685         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
686 }
687
688 void
689 AlbumListEditorForm::OnThumbnailDecoded(const int index)
690 {
691         AppLogDebug("ENTER : index(%d)", index);
692         __pEditorFolderIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
693         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
694 }
695
696 void AlbumListEditorForm::OnFileOpInvalidate(enum FileActionMode actionId)
697 {
698         Invalidate(true);
699 }
700
701 void AlbumListEditorForm::OnFileOpComplete(enum FileActionMode actionId, enum FileActionCompleteRes res)
702 {
703         AppLogDebug("ENTER");
704         __pPresentationModel->SetUpdateProgressStatus(false);
705         SetAllCheckState(false);
706         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
707         __pEditorFolderIconList->UpdateList();
708
709         SceneManager* pSceneManager = SceneManager::GetInstance();
710         AppAssert(pSceneManager);
711         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
712 }
713
714 result
715 AlbumListEditorForm::Update(void)
716 {
717         AppLogDebug("ENTER");
718         result r = __pEditorFolderIconList->UpdateList();
719         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
720
721         return r;
722 }
723
724 void
725 AlbumListEditorForm::OnRequestMessage(void)
726 {
727         AppLogDebug("ENTER");
728
729         int checkCount = GetCheckedFolderCount();
730
731         if (checkCount <= 0)
732         {
733                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
734
735                 return;
736         }
737
738         IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
739
740         int maxCount = __pPresentationModel->GetFolderCount();
741         ContentManager contentManager;
742         result r = contentManager.Construct();
743         if (r == E_SUCCESS)
744         {
745                 if (maxCount <= 0)
746                 {
747                         AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
748                         return;
749                 }
750
751                 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
752                 pArrayList->Construct();
753                 for (int i = 0; i < maxCount; ++i)
754                 {
755                         if (__pEditorFolderIconList->IsItemChecked (i))
756                         {
757                                 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(i));
758                                 IList* pContentIdList = pAlbumInfo->GetContentIdListN();
759                                 int loopCount = pContentIdList->GetCount();
760                                 for (int k = 0; k < loopCount; ++k)
761                                 {
762                                         ContentId* pContentId = static_cast<ContentId*>(pContentIdList->GetAt(k));
763                                         ContentInfo* pContentInfo = contentManager.GetContentInfoN(*pContentId);
764
765                                         if (pContentInfo == null)
766                                         {
767                                                 break;
768                                         }
769
770                                         pArrayList->Add(new (std::nothrow) String(pContentInfo->GetContentPath()));
771                                 }
772
773                                 if (i == 0)
774                                 {
775                                         break;
776                                 }
777                         }
778                 }
779
780                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
781                 pDataList->Construct();
782                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_MESSAGE_TYPE), new (std::nothrow) String(APPCONTROL_DATA_MMS));
783                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
784
785                 r = __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_MESSAGE, APPCONTROL_OPERATION_ID_COMPOSE,
786                                 null, null, pDataList, null);
787
788                 if (r == E_MAX_EXCEEDED)
789                 {
790                         MessageBox messageBox;
791                         messageBox.Construct(L"", ResourceManager::GetString(L"IDS_RCS_BODY_MAXIMUM_NUMBER_OF_FILES_EXCEEDED"),
792                                         MSGBOX_STYLE_NONE, 3000);
793                         int modalResult;
794                         messageBox.ShowAndWait(modalResult);
795                 }
796         }
797         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
798 }
799
800 void
801 AlbumListEditorForm::OnRequestEmail(void)
802 {
803         AppLogDebug("ENTER");
804
805         int checkCount = GetCheckedFolderCount();
806
807         if (checkCount <= 0)
808         {
809                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
810
811                 return;
812         }
813
814         IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
815
816         int maxCount = __pPresentationModel->GetFolderCount();
817         ContentManager contentManager;
818         result r = contentManager.Construct();
819         if (r == E_SUCCESS)
820         {
821                 if (maxCount <= 0)
822                 {
823                         AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
824                         return;
825                 }
826
827                 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
828                 pArrayList->Construct();
829                 for (int i = 0; i < maxCount; ++i)
830                 {
831                         if (__pEditorFolderIconList->IsItemChecked(i))
832                         {
833                                 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(i));
834                                 IList* pContentIdList = pAlbumInfo->GetContentIdListN();
835                                 int loopCount = pContentIdList->GetCount();
836                                 for (int k = 0; k < loopCount; ++k)
837                                 {
838                                         ContentId* pContentId = static_cast<ContentId*>(pContentIdList->GetAt(k));
839                                         ContentInfo* pContentInfo = contentManager.GetContentInfoN(*pContentId);
840
841                                         if (pContentInfo == null)
842                                         {
843                                                 break;
844                                         }
845
846                                         pArrayList->Add(new (std::nothrow) String(pContentInfo->GetContentPath()));
847                                 }
848
849                                 if (i == 0)
850                                 {
851                                         break;
852                                 }
853                         }
854                 }
855
856                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
857                 pDataList->Construct();
858                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
859
860                 r = __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_EMAIL, APPCONTROL_OPERATION_ID_COMPOSE,
861                                 new (std::nothrow) String(APPCONTROL_URI_MAIL_TO), null, pDataList, null);
862
863                 if (r == E_MAX_EXCEEDED)
864                 {
865                         MessageBox messageBox;
866                         messageBox.Construct(L"", ResourceManager::GetString(L"IDS_RCS_BODY_MAXIMUM_NUMBER_OF_FILES_EXCEEDED"),
867                                         MSGBOX_STYLE_NONE, 3000);
868                         int modalResult;
869                         messageBox.ShowAndWait(modalResult);
870                 }
871         }
872         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
873 }
874
875 void
876 AlbumListEditorForm::SetFooterButtonsState(const bool enableState)
877 {
878         AppLogDebug("ENTER");
879         Footer* pFooter = GetFooter();
880         AppAssert(pFooter);
881
882         if (enableState == true)
883         {
884                 pFooter->SetItemEnabled(0, true);
885                 pFooter->SetItemEnabled(1, true);
886         }
887         else
888         {
889                 pFooter->SetItemEnabled(0, false);
890                 pFooter->SetItemEnabled(1, false);
891         }
892
893         pFooter->RequestRedraw(true);
894         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
895 }
896
897 void
898 AlbumListEditorForm::SetButtonState(void)
899 {
900         AppLogDebug("ENTER");
901         if (GetCheckedFolderCount() > 0)
902         {
903                 AppLogDebug("BUTTONSTATE : Request Enable");
904                 SetFooterButtonsState(true);
905         }
906         else
907         {
908                 AppLogDebug("BUTTONSTATE : Request disable");
909                 SetFooterButtonsState(false);
910         }
911         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
912 }