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