Change select all in AlbumListEditor
[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 <FApp.h>
23 #include "GlAlbumInfo.h"
24 #include "GlAlbumListEditorForm.h"
25 #include "GlAlbumListPresentationModel.h"
26 #include "GlResourceManager.h"
27 #include "GlTypes.h"
28
29 using namespace Tizen::App;
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Content;
33 using namespace Tizen::Graphics;
34 using namespace Tizen::Media;
35 using namespace Tizen::Io;
36 using namespace Tizen::System;
37 using namespace Tizen::Ui;
38 using namespace Tizen::Ui::Controls;
39 using namespace Tizen::Ui::Scenes;
40
41 static const unsigned int COLOR_SELECT_COUNT_LABEL = Color32<68, 68, 68>::Value;
42 static const unsigned int COLOR_SELECT_COUNT_FONT = Color32<255, 255, 255>::Value;
43 static const unsigned int COLOR_DELETE_BUTTON_NORMAL = Color32<208, 82, 82>::Value;
44 static const unsigned int COLOR_DELETE_BUTTON_PRESSED = Color32<194, 71, 71>::Value;
45 static const unsigned int COLOR_DELETE_BUTTON_TEXT = Color32<248, 246, 239>::Value;
46
47 static const int W_FOLDER_SIZE = 334;
48 static const int H_FOLDER_SIZE = 334;
49
50 static const int W_BUTTON_RENAME_SIZE = 64;
51 static const int H_BUTTON_RENAME_SIZE = 64;
52
53 static const int GAP_W_POPUP_ITEM = 5;
54 static const int W_DELETE_POPUP = 600;
55 static const int H_DELETE_POPUP = 300;
56 static const int H_DELETE_LABEL = 180;
57 static const int Y_DELETE_BUTTON = 180;
58 static const int H_DELETE_BUTTON = 80;
59
60 static const int H_CHECKBOX = 80;
61 static const int GAP_H_ICON_LIST_VIEW = 40;
62
63 static const int H_SELECT_COUNT_LABEL = 48;
64
65 static const int FORMAT_BUFFER_SIZE = 256;
66
67 static const int X_POSITION_SHARE_CONTEXTMENU = 300;
68 static const int Y_POSITION_SHARE_CONTEXTMENU = 1180;
69
70 static const Color COLOR_FOLDER_BITMAP_DIM(Color::GetColor(COLOR_ID_BLACK));
71 static const int ALPHA_FOLDER_BITMAP_DIM = 70;
72
73 AlbumListEditorForm::AlbumListEditorForm()
74         : __checkedCount(0)
75         , __pSelectCountLabel(null)
76         , __pEditorFolderIconList(null)
77         , __pShareContextMenu(null)
78         , __pDeletePopup(null)
79         , __pEditFolderBitmap(null)
80         , __pPresentationModel(null)
81 {
82         AppLogDebug("ENTER");
83         __overlayMsg = false;
84         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
85 }
86
87 AlbumListEditorForm::~AlbumListEditorForm()
88 {
89         AppLogDebug("ENTER");
90         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
91 }
92
93 result
94 AlbumListEditorForm::Initialize(void)
95 {
96         AppLogDebug("ENTER");
97         result r = Form::Construct(IDL_FORM_ALBUM_LIST_EDITOR);
98         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
99
100         return r;
101 }
102
103 result
104 AlbumListEditorForm::OnInitializing(void)
105 {
106         AppLogDebug("ENTER");
107         result r = E_SUCCESS;
108
109         SetRenameButtonImage();
110
111         __pPresentationModel = AlbumListPresentationModel::GetInstance();
112         __pPresentationModel->ClearThumbnailRequests();
113         __pPresentationModel->AddPresentationModelListener(this);
114
115         r = InitializeHeader();
116         if (r != E_SUCCESS)
117         {
118                 AppLogDebug("[%s] Unable to InitializeHeader.", GetErrorMessage(r));
119         }
120
121         r = InitializeFooter();
122         if (r != E_SUCCESS)
123         {
124                 AppLogDebug("[%s] Unable to set InitializeFooter.", GetErrorMessage(r));
125         }
126
127         r = InitializeControl();
128         if (r != E_SUCCESS)
129         {
130                 AppLogDebug("[%s] Unable to set InitializeControl.", GetErrorMessage(r));
131         }
132
133         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
134
135         return r;
136 }
137
138 result
139 AlbumListEditorForm::OnTerminating(void)
140 {
141         AppLogDebug("ENTER");
142         __pPresentationModel->RemovePresentationModelListener(*this);
143
144         if (__pDeletePopup != null)
145         {
146                 delete __pDeletePopup;
147                 __pDeletePopup = null;
148         }
149
150         if (__pEditFolderBitmap != null)
151         {
152                 delete __pEditFolderBitmap;
153                 __pEditFolderBitmap = null;
154         }
155         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
156
157         return E_SUCCESS;
158 }
159
160 void
161 AlbumListEditorForm::OnUpdateContentList()
162 {
163         AppLogDebug("ENTER");
164         SceneManager* pSceneManager = SceneManager::GetInstance();
165         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
166         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
167 }
168
169 result
170 AlbumListEditorForm::SetRenameButtonImage(void)
171 {
172         AppLogDebug("ENTER");
173         Bitmap* pSrcBitmap1 = ResourceManager::GetBitmapN(IDB_BUTTON_CIRCLE_BACKGROUND);
174         Bitmap* pSrcBitmap2 = ResourceManager::GetBitmapN(IDB_BUTTON_RENAME);
175
176         Bitmap* pBitmap = new (std::nothrow) Bitmap();
177         BufferInfo bufferinfo;
178         Canvas canvas;
179         Dimension size(W_BUTTON_RENAME_SIZE, H_BUTTON_RENAME_SIZE);
180         result r = pBitmap->Construct(size, BITMAP_PIXEL_FORMAT_ARGB8888);
181         r = pBitmap->Lock(bufferinfo);
182         r = canvas.Construct(bufferinfo);
183
184         if (pSrcBitmap1 != null)
185         {
186                 canvas.DrawBitmap(Point(0, 0), *pSrcBitmap1);
187                 delete pSrcBitmap1;
188                 pSrcBitmap1 = null;
189         }
190         if (pSrcBitmap2 != null)
191         {
192                 canvas.DrawBitmap(Point(0, 0), *pSrcBitmap2);
193                 delete pSrcBitmap2;
194                 pSrcBitmap2 = null;
195         }
196
197         pBitmap->Unlock();
198
199         __pEditFolderBitmap = pBitmap;
200         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
201
202         return E_SUCCESS;
203 }
204
205 result
206 AlbumListEditorForm::InitializeHeader(void)
207 {
208         AppLogDebug("ENTER");
209         Header* pHeader = GetHeader();
210         if (pHeader == null)
211         {
212                 AppLogDebug("EXIT 1");
213
214                 return E_SYSTEM;
215         }
216
217         result r = pHeader->SetStyle(HEADER_STYLE_TITLE);
218         if (r != E_SUCCESS)
219         {
220                 AppLogDebug("EXIT 2");
221
222                 return r;
223         }
224
225         pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_GALLERY"));
226         pHeader->AddActionEventListener(*this);
227
228         ButtonItem selectAll;
229         selectAll.Construct(BUTTON_ITEM_STYLE_ICON, ACTION_ID_ALBUM_LIST_SELECT_ALL);
230         Bitmap* pBitmapSelectAll = ResourceManager::GetBitmapN(IDB_ICON_SELECT_ALL);
231         Bitmap* pBitmapSelectAllPress = ResourceManager::GetBitmapN(IDB_ICON_SELECT_ALL_PRESS);
232         if (pBitmapSelectAll != null)
233         {
234                 selectAll.SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapSelectAll);
235         }
236         if (pBitmapSelectAll != null)
237         {
238                 selectAll.SetIcon(BUTTON_ITEM_STATUS_PRESSED, pBitmapSelectAllPress);
239         }
240         pHeader->SetButton(BUTTON_POSITION_RIGHT, selectAll);
241         delete pBitmapSelectAll;
242
243         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
244
245         return E_SUCCESS;
246 }
247
248 result
249 AlbumListEditorForm::InitializeFooter(void)
250 {
251         AppLogDebug("ENTER");
252         Footer* pFooter = GetFooter();
253         if (pFooter == null)
254         {
255                 AppLogDebug("EXIT 1");
256
257                 return E_SYSTEM;
258         }
259
260         pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON);
261         pFooter->RemoveAllItems();
262         pFooter->SetBackButtonEnabled(true);
263         pFooter->SetBackButton();
264         SetFormBackEventListener(this);
265
266         FooterItem itemShare;
267         itemShare.Construct(ACTION_ID_FOOTER_SHARE);
268         itemShare.SetText(ResourceManager::GetString(L"EMPTY_SPACE"));
269         Bitmap* pShareBitmap = ResourceManager::GetBitmapN(IDB_CONTROLBAR_SHARE);
270         Bitmap* pShareBitmapDim = ResourceManager::GetBitmapN(IDB_CONTROLBAR_SHARE_DIM);
271         if (pShareBitmap != null && pShareBitmapDim !=null )
272         {
273                 itemShare.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pShareBitmap);
274                 itemShare.SetIcon(FOOTER_ITEM_STATUS_DISABLED, pShareBitmapDim);
275         }
276
277         pFooter->AddItem(itemShare);
278         delete pShareBitmap;
279         delete pShareBitmapDim;
280
281         FooterItem itemDelete;
282         itemDelete.Construct(ACTION_ID_FOOTER_DELETE);
283         itemDelete.SetText(ResourceManager::GetString(L"EMPTY_SPACE"));
284         Bitmap* pBitmapDelete = ResourceManager::GetBitmapN(IDB_CONTROLBAR_DELETE);
285         Bitmap* pBitmapDeleteDim = ResourceManager::GetBitmapN(IDB_CONTROLBAR_DELETE_DIM);
286
287         if (pBitmapDelete != null)
288         {
289                 itemDelete.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pBitmapDelete);
290         }
291
292         if( pBitmapDeleteDim != null)
293         {
294                 itemDelete.SetIcon(FOOTER_ITEM_STATUS_DISABLED, pBitmapDeleteDim);
295         }
296
297         pFooter->AddItem(itemDelete);
298         delete pBitmapDelete;
299         delete pBitmapDeleteDim;
300
301         pFooter->AddActionEventListener(*this);
302         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
303
304         return E_SUCCESS;
305 }
306
307 result
308 AlbumListEditorForm::InitializeControl()
309 {
310         AppLogDebug("ENTER");
311         String tempString;
312
313         CreateIconListView();
314         __checkedCount = GetCheckedFolder();
315         tempString.Format(FORMAT_BUFFER_SIZE, L"%ls (%d)",
316                         ResourceManager::GetString(L"IDS_COM_BODY_SELECTED").GetPointer(), __checkedCount);
317
318         __pSelectCountLabel = new (std::nothrow) Label();
319         __pSelectCountLabel->Construct(Rectangle(0, GetClientAreaBounds().height - H_SELECT_COUNT_LABEL,
320                         GetClientAreaBounds().width, H_SELECT_COUNT_LABEL), tempString);
321
322         __pSelectCountLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
323         __pSelectCountLabel->SetTextHorizontalAlignment(ALIGNMENT_CENTER);
324         __pSelectCountLabel->SetBackgroundColor(Color(COLOR_SELECT_COUNT_LABEL));
325         __pSelectCountLabel->SetTextColor(Color(COLOR_SELECT_COUNT_FONT));
326         AddControl(*__pSelectCountLabel);
327
328         __pShareContextMenu = new ContextMenu();
329         __pShareContextMenu->Construct(Point(X_POSITION_SHARE_CONTEXTMENU, Y_POSITION_SHARE_CONTEXTMENU),
330                         CONTEXT_MENU_STYLE_LIST);
331         __pShareContextMenu->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_MESSAGE"),
332                         ACTION_ID_CONTEXT_MENU_MESSAGE);
333         __pShareContextMenu->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_EMAIL"), ACTION_ID_CONTEXT_MENU_EMAIL);
334         __pShareContextMenu->AddActionEventListener(*this);
335
336         InitializePopup();
337         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
338
339         return E_SUCCESS;
340 }
341
342 result
343 AlbumListEditorForm::InitializePopup(void)
344 {
345         AppLogDebug("ENTER");
346         if (__pDeletePopup == null)
347         {
348                 __pDeletePopup = new (std::nothrow) Popup();
349                 __pDeletePopup->Construct(false, Dimension(W_DELETE_POPUP, H_DELETE_POPUP));
350
351                 Rectangle popupClientBounds = __pDeletePopup->GetClientAreaBounds();
352
353                 Label* pLabel = new (std::nothrow) Label();
354                 pLabel->Construct(Rectangle(0, 0, popupClientBounds.width, H_DELETE_LABEL),
355                                 ResourceManager::GetString(L"IDS_COM_POP_DELETE_Q"));
356
357                 Button* pDeleteButton = new (std::nothrow) Button();
358                 pDeleteButton->Construct(
359                                 Rectangle(0, Y_DELETE_BUTTON, popupClientBounds.width / 2 - GAP_W_POPUP_ITEM, H_DELETE_BUTTON),
360                                 ResourceManager::GetString(L"IDS_COM_BODY_DELETE"));
361                 pDeleteButton->SetColor(BUTTON_STATUS_NORMAL, COLOR_DELETE_BUTTON_NORMAL);
362                 pDeleteButton->SetColor(BUTTON_STATUS_PRESSED, COLOR_DELETE_BUTTON_PRESSED);
363                 pDeleteButton->SetTextColor(COLOR_DELETE_BUTTON_TEXT);
364                 pDeleteButton->SetActionId(ACTION_ID_DELETE_POPUP_DEL);
365                 pDeleteButton->AddActionEventListener(*this);
366
367                 Button* pCancelButton = new (std::nothrow) Button();
368                 pCancelButton->Construct(
369                                 Rectangle(popupClientBounds.width / 2 + GAP_W_POPUP_ITEM, Y_DELETE_BUTTON,
370                                                 popupClientBounds.width / 2 - GAP_W_POPUP_ITEM, H_DELETE_BUTTON),
371                                                 ResourceManager::GetString(L"IDS_COM_POP_CANCEL"));
372                 pCancelButton->SetActionId(ACTION_ID_DELETE_POPUP_CANCEL);
373                 pCancelButton->AddActionEventListener(*this);
374
375                 __pDeletePopup->AddControl(*pLabel);
376                 __pDeletePopup->AddControl(*pDeleteButton);
377                 __pDeletePopup->AddControl(*pCancelButton);
378         }
379         else
380         {
381                 __pDeletePopup->SetShowState(true);
382                 __pDeletePopup->Show();
383         }
384         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
385
386         return E_SUCCESS;
387 }
388
389 void
390 AlbumListEditorForm::CreateIconListView(void)
391 {
392         AppLogDebug("ENTER");
393         Dimension itemSize(W_FOLDER_SIZE, H_FOLDER_SIZE);
394         __pEditorFolderIconList = new (std::nothrow) IconListView();
395         __pEditorFolderIconList->Construct(Rectangle(0, 0, GetClientAreaBounds().width,
396                         GetClientAreaBounds().height - H_CHECKBOX - GAP_H_ICON_LIST_VIEW), itemSize,
397                         ICON_LIST_VIEW_STYLE_MARK, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
398         Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
399         if (pBitmap != null)
400         {
401                 __pEditorFolderIconList->SetBitmapOfEmptyList(pBitmap);
402                 delete pBitmap;
403         }
404         __pEditorFolderIconList->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
405         __pEditorFolderIconList->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
406         __pEditorFolderIconList->SetItemProvider(*this);
407         __pEditorFolderIconList->SetTouchAnimationEnabled(false);
408         __pEditorFolderIconList->AddIconListViewItemEventListener(*this);
409         AddControl(*__pEditorFolderIconList);
410         __pEditorFolderIconList->SetShowState(true);
411         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
412 }
413
414 int
415 AlbumListEditorForm::GetItemCount(void)
416 {
417         AppLogDebug("ENTER");
418         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
419
420         return __pPresentationModel->GetFolderCount();
421 }
422
423 IconListViewItem*
424 AlbumListEditorForm::CreateItem(int index)
425 {
426         AppLogDebug("ENTER : index(%d)", index);
427         Bitmap* pBitmap = null;
428         IconListViewItem* pIconListview = new IconListViewItem();
429
430         IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
431         AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
432
433         Bitmap* pAlbumBitmap = pAlbumInfo->GetFolderThumnailBitmap();
434         if (pAlbumBitmap == null)
435         {
436                 __pPresentationModel->RequestThumbnail(index, 0);
437         }
438
439         pBitmap = __pPresentationModel->CreateMergeBitmapN(index);
440
441         if (__pEditorFolderIconList->IsItemChecked(index) == true)
442         {
443                 if (pBitmap != null)
444                 {
445                         BufferInfo bufferInfo;
446                         pBitmap->Lock(bufferInfo, INFINITE);
447                         pBitmap->Unlock();
448                         Color dimColor(COLOR_FOLDER_BITMAP_DIM);
449                         dimColor.SetAlpha(ALPHA_FOLDER_BITMAP_DIM);
450                         Canvas canvas;
451                         canvas.Construct(bufferInfo);
452                         canvas.FillRectangle(dimColor, canvas.GetBounds());
453                         Bitmap* pSelectedBitmap = new (std::nothrow) Bitmap();
454                         pSelectedBitmap->Construct(canvas, canvas.GetBounds());
455                         pIconListview->Construct(*pBitmap, null, pSelectedBitmap);
456                         delete pSelectedBitmap;
457                 }
458         }
459         else
460         {
461                 pIconListview->Construct(*pBitmap);
462         }
463
464         if (pBitmap != null)
465         {
466                 delete pBitmap;
467         }
468         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
469
470         return pIconListview;
471 }
472
473 void
474 AlbumListEditorForm::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
475 {
476         AppLogDebug("ENTER");
477         String tempString;
478
479         if (status == ICON_LIST_VIEW_ITEM_CHECKED || status == ICON_LIST_VIEW_ITEM_UNCHECKED)
480         {
481                 __checkedCount = GetCheckedFolder();
482                 tempString.Format(FORMAT_BUFFER_SIZE, L"%ls (%d)",
483                                 ResourceManager::GetString(L"IDS_COM_BODY_SELECTED").GetPointer(), __checkedCount);
484                 __pSelectCountLabel->SetText(tempString);
485                 __pSelectCountLabel->RequestRedraw();
486                 __pEditorFolderIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
487         }
488         SetButtonState();
489         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
490 }
491
492 void
493 AlbumListEditorForm::OnIconListViewOverlayBitmapSelected (IconListView &iconListView, int index,
494                 int overlayBitmapId)
495 {
496         AppLogDebug("ENTER");
497         SceneManager* pSceneManager = SceneManager::GetInstance();
498
499         if (overlayBitmapId == ACTION_ID_EDITE_FOLDER)
500         {
501                 ArrayList* pSelectedIndex = new (std::nothrow) ArrayList(SingleObjectDeleter);
502                 pSelectedIndex->Construct();
503                 pSelectedIndex->Add(new (std::nothrow) Integer(index));
504
505                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_NAME_EDITOR), pSelectedIndex);
506         }
507         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
508 }
509
510 bool
511 AlbumListEditorForm::DeleteItem(int index, IconListViewItem* pItem)
512 {
513         AppLogDebug("ENTER");
514         delete pItem;
515         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
516
517         return true;
518 }
519
520 result
521 AlbumListEditorForm::DeleteFolder()
522 {
523         AppLogDebug("ENTER");
524         int maxCount = __pPresentationModel->GetFolderCount();
525         result r = E_FAILURE;
526
527         int checkedCount = 0;
528
529         for (int i = 0 ; i < maxCount; ++i)
530         {
531                 if (__pEditorFolderIconList->IsItemChecked(i) == true)
532                 {
533                         ++checkedCount;
534                         __pPresentationModel->DeleteContentInfoInDirectory(i, CONTENT_TYPE_ALL);
535                         if (i == 0)
536                         {
537                                 break;
538                         }
539                 }
540         }
541
542         if (checkedCount == 0)
543         {
544                 r = E_FAILURE;
545         }
546         else
547         {
548                 r = E_SUCCESS;
549         }
550
551         SetAllCheckState(false);
552         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
553         __pEditorFolderIconList->UpdateList();
554         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
555
556         return r;
557 }
558
559 void
560 AlbumListEditorForm::SetAllCheckState(bool state)
561 {
562         AppLogDebug("ENTER");
563         int maxCount = __pPresentationModel->GetFolderCount();
564         String tempString;
565
566         if (state == true)
567         {
568                 tempString.Format(FORMAT_BUFFER_SIZE, L"%ls (%d)",
569                                 ResourceManager::GetString(L"IDS_COM_BODY_SELECTED").GetPointer(), maxCount);
570         }
571         else
572         {
573                 tempString.Format(FORMAT_BUFFER_SIZE, L"%ls (%d)",
574                                 ResourceManager::GetString(L"IDS_COM_BODY_SELECTED").GetPointer(), 0);
575         }
576
577         for (int i = 0 ; i < maxCount; ++i)
578         {
579                 __pEditorFolderIconList->SetItemChecked(i, state);
580                 __pEditorFolderIconList->RefreshList(i, LIST_REFRESH_TYPE_ITEM_MODIFY);
581         }
582
583         __pEditorFolderIconList->Draw();
584         __pSelectCountLabel->SetText(tempString);
585         __pSelectCountLabel->RequestRedraw();
586         __checkedCount = GetCheckedFolder();
587
588         SetButtonState();
589         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
590 }
591
592 int
593 AlbumListEditorForm::GetCheckedFolder()
594 {
595         AppLogDebug("ENTER");
596         int maxCount = __pPresentationModel->GetFolderCount();
597         int count = 0;
598
599         for (int i = 0 ; i < maxCount; ++i)
600         {
601                 if (__pEditorFolderIconList->IsItemChecked (i))
602                 {
603                         count++;
604                 }
605         }
606         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
607
608         return count;
609 }
610
611 void
612 AlbumListEditorForm::OnActionPerformed(const Control& source, int actionId)
613 {
614         AppLogDebug("ENTER");
615         switch (actionId)
616         {
617         case ACTION_ID_ALBUM_LIST_SELECT_ALL:
618                 SetAllCheckState(true);
619                 break;
620         case ACTION_ID_FOOTER_DELETE:
621                 if (__checkedCount > 0)
622                 {
623                         __pDeletePopup->SetShowState(true);
624                         __pDeletePopup->Show();
625                 }
626                 break;
627         case ACTION_ID_FOOTER_SHARE:
628                 __pShareContextMenu->SetShowState(true);
629                 __pShareContextMenu->Show();
630                 break;
631         case ACTION_ID_CONTEXT_MENU_MESSAGE:
632         {
633                 OnRequestMessage();
634                 break;
635         }
636         case ACTION_ID_CONTEXT_MENU_EMAIL:
637         {
638                 OnRequestEmail();
639                 break;
640         }
641         case ACTION_ID_DELETE_POPUP_DEL:
642         {
643                 __pDeletePopup->SetShowState(false);
644                 __pDeletePopup->Show();
645                 result r = DeleteFolder();
646                 AppLogDebug("CHECKBUTTONSTATE : R1");
647                 if (r == E_SUCCESS)
648                 {
649                         AppLogDebug("CHECKBUTTONSTATE : R2");
650                         SceneManager* pSceneManager = SceneManager::GetInstance();
651                         AppAssert(pSceneManager);
652                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
653                 }
654                 AppLogDebug("CHECKBUTTONSTATE : R3");
655                 break;
656         }
657         case ACTION_ID_DELETE_POPUP_CANCEL:
658         {
659                 __pDeletePopup->SetShowState(false);
660                 __pDeletePopup->Show();
661                 break;
662         }
663         default:
664                 break;
665         }
666         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
667 }
668
669 void
670 AlbumListEditorForm::OnFormBackRequested(Form& source)
671 {
672         AppLogDebug("ENTER");
673         SceneManager* pSceneManager = SceneManager::GetInstance();
674         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
675         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
676 }
677
678 void
679 AlbumListEditorForm::OnSceneActivatedN(const SceneId& previousSceneId,
680                 const SceneId& currentSceneId, IList* pArgs)
681 {
682         AppLogDebug("ENTER OnSceneActivatedN");
683         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
684         __pEditorFolderIconList->UpdateList();
685
686         __checkedCount = GetCheckedFolder();
687
688         String tempString;
689         tempString.Format(FORMAT_BUFFER_SIZE, L"%ls (%d)",
690                         ResourceManager::GetString(L"IDS_COM_BODY_SELECTED").GetPointer(), __checkedCount);
691         __pSelectCountLabel->SetText(tempString);
692         __pSelectCountLabel->RequestRedraw();
693
694         SetButtonState();
695         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
696 }
697
698 void
699 AlbumListEditorForm::OnSceneDeactivated(const SceneId& currentSceneId,
700                 const SceneId& nextSceneId)
701 {
702         AppLogDebug("ENTER");
703         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
704 }
705
706 void
707 AlbumListEditorForm::OnFileInfoChanged(const ContentType contentType)
708 {
709         AppLogDebug("ENTER");
710         Update();
711         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
712 }
713
714 void
715 AlbumListEditorForm::OnThumbnailDecoded(const int index)
716 {
717         AppLogDebug("ENTER : index(%d)", index);
718         __pEditorFolderIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
719         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
720 }
721
722 result
723 AlbumListEditorForm::Update(void)
724 {
725         AppLogDebug("ENTER");
726         result r = __pEditorFolderIconList->UpdateList();
727         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
728
729         return r;
730 }
731
732 void
733 AlbumListEditorForm::OnRequestMessage(void)
734 {
735         AppLogDebug("ENTER");
736
737         int checkCount = GetCheckedFolder();
738
739         if (checkCount <= 0)
740         {
741                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
742
743                 return;
744         }
745
746         String combineText;
747
748         IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
749
750         int maxCount = __pPresentationModel->GetFolderCount();
751         ContentManager contentManager;
752         result r = contentManager.Construct();
753         if (r == E_SUCCESS)
754         {
755                 if (maxCount <= 0)
756                 {
757                         AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
758
759                         return;
760                 }
761                 for (int i = 0 ; i < maxCount; ++i)
762                 {
763                         if (__pEditorFolderIconList->IsItemChecked (i))
764                         {
765                                 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(i));
766                                 IList* pContentIdList = pAlbumInfo->GetContentIdListN();
767                                 int loopCount = pContentIdList->GetCount();
768                                 for (int k = 0; k < loopCount; ++k)
769                                 {
770                                         ContentId* pContentId = static_cast<ContentId*>(pContentIdList->GetAt(k));
771                                         ContentInfo* pContentInfo = contentManager.GetContentInfoN(*pContentId);
772
773                                         if (pContentInfo == null)
774                                         {
775                                                 break;
776                                         }
777                                         String path = pContentInfo->GetContentPath();
778                                         if (combineText.CompareTo(EMPTY_SPACE) != 0)
779                                         {
780                                                 combineText.Append(L";");
781                                         }
782                                         combineText.Append(path);
783                                 }
784
785                                 if (i == 0)
786                                 {
787                                         break;
788                                 }
789                         }
790                 }
791
792                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
793                 pDataList->Construct();
794                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE),
795                                 new (std::nothrow) String(APPCONTROL_DATA_MMS));
796                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_ATTACHMENTS),
797                                 new (std::nothrow) String(combineText));
798
799                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_MESSAGE, APPCONTROL_OPERATION_ID_COMPOSE,
800                                 pDataList, null);
801         }
802         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
803 }
804
805 void
806 AlbumListEditorForm::OnRequestEmail(void)
807 {
808         AppLogDebug("ENTER");
809
810         int checkCount = GetCheckedFolder();
811
812         if (checkCount <= 0)
813         {
814                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
815
816                 return;
817         }
818
819         String combineText;
820
821         IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
822
823         int maxCount = __pPresentationModel->GetFolderCount();
824         ContentManager contentManager;
825         result r = contentManager.Construct();
826         if (r == E_SUCCESS)
827         {
828                 if (maxCount <= 0)
829                 {
830                         AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
831
832                         return;
833                 }
834                 for (int i = 0 ; i < maxCount; ++i)
835                 {
836                         if (__pEditorFolderIconList->IsItemChecked (i))
837                         {
838                                 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(i));
839                                 IList* pContentIdList = pAlbumInfo->GetContentIdListN();
840                                 int loopCount = pContentIdList->GetCount();
841                                 for (int k = 0; k < loopCount; ++k)
842                                 {
843                                         ContentId* pContentId = static_cast<ContentId*>(pContentIdList->GetAt(k));
844                                         ContentInfo* pContentInfo = contentManager.GetContentInfoN(*pContentId);
845
846                                         if (pContentInfo == null)
847                                         {
848                                                 break;
849                                         }
850                                         String path = pContentInfo->GetContentPath();
851                                         if (combineText.CompareTo(EMPTY_SPACE) != 0)
852                                         {
853                                                 combineText.Append(L";");
854                                         }
855                                         combineText.Append(path);
856                                 }
857
858                                 if (i == 0)
859                                 {
860                                         break;
861                                 }
862                         }
863                 }
864
865                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
866                 pDataList->Construct();
867                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_ATTACHMENTS),
868                                 new (std::nothrow) String(combineText));
869
870                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_EMAIL,
871                                 APPCONTROL_OPERATION_ID_COMPOSE, pDataList, null);
872         }
873         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
874 }
875
876 void
877 AlbumListEditorForm::SetFooterButtonsState(bool enableState)
878 {
879         AppLogDebug("ENTER");
880         Footer* pFooter = GetFooter();
881         AppAssert(pFooter);
882
883         if (enableState == true)
884         {
885                 pFooter->SetItemEnabled(0, true);
886                 pFooter->SetItemEnabled(1, true);
887         }
888         else
889         {
890                 pFooter->SetItemEnabled(0, false);
891                 pFooter->SetItemEnabled(1, false);
892         }
893
894         pFooter->RequestRedraw(true);
895         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
896 }
897
898 void
899 AlbumListEditorForm::SetButtonState(void)
900 {
901         AppLogDebug("ENTER");
902         if (GetCheckedFolder() > 0)
903         {
904                 AppLogDebug("BUTTONSTATE : Request Enable");
905                 SetFooterButtonsState(true);
906         }
907         else
908         {
909                 AppLogDebug("BUTTONSTATE : Request disable");
910                 SetFooterButtonsState(false);
911         }
912         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
913 }