Modify share via message
[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                         pSelectedBitmap = null;
455                 }
456         }
457         else
458         {
459                 pIconListview->Construct(*pBitmap);
460         }
461
462         if (pBitmap != null)
463         {
464                 delete pBitmap;
465         }
466         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
467
468         return pIconListview;
469 }
470
471 void
472 AlbumListEditorForm::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
473 {
474         AppLogDebug("ENTER");
475         String tempString;
476
477         if (status == ICON_LIST_VIEW_ITEM_CHECKED || status == ICON_LIST_VIEW_ITEM_UNCHECKED)
478         {
479                 __checkedCount = GetCheckedFolder();
480                 tempString.Format(FORMAT_BUFFER_SIZE, L"%ls (%d)",
481                                 ResourceManager::GetString(L"IDS_COM_BODY_SELECTED").GetPointer(), __checkedCount);
482                 __pSelectCountLabel->SetText(tempString);
483                 __pSelectCountLabel->RequestRedraw();
484                 __pEditorFolderIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
485                 int maxCount = __pPresentationModel->GetFolderCount();
486
487                 if (__pAllCheckButton->IsSelected() == true)
488                 {
489                         __pAllCheckButton->SetSelected(false);
490                 }
491                 else
492                 {
493                         if (__checkedCount == maxCount)
494                         {
495                                 AppLogDebug("SELECTIONTEST(%d)(%d)",__checkedCount,  maxCount);
496                                 __pAllCheckButton->SetSelected(true);
497                         }
498                 }
499         }
500         SetButtonState();
501         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
502 }
503
504 void
505 AlbumListEditorForm::OnIconListViewOverlayBitmapSelected (IconListView &iconListView, int index,
506                 int overlayBitmapId)
507 {
508         AppLogDebug("ENTER");
509         SceneManager* pSceneManager = SceneManager::GetInstance();
510
511         if (overlayBitmapId == ACTION_ID_EDITE_FOLDER)
512         {
513                 ArrayList* pSelectedIndex = new (std::nothrow) ArrayList(SingleObjectDeleter);
514                 pSelectedIndex->Construct();
515                 pSelectedIndex->Add(new (std::nothrow) Integer(index));
516
517                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_NAME_EDITOR), pSelectedIndex);
518         }
519         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
520 }
521
522 bool
523 AlbumListEditorForm::DeleteItem(int index, IconListViewItem* pItem)
524 {
525         AppLogDebug("ENTER");
526         delete pItem;
527         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
528
529         return true;
530 }
531
532 result
533 AlbumListEditorForm::DeleteFolder()
534 {
535         AppLogDebug("ENTER");
536         int maxCount = __pPresentationModel->GetFolderCount();
537         result r = E_FAILURE;
538
539         int checkedCount = 0;
540
541         for (int i = 0 ; i < maxCount; ++i)
542         {
543                 if (__pEditorFolderIconList->IsItemChecked(i) == true)
544                 {
545                         ++checkedCount;
546                         __pPresentationModel->DeleteContentInfoInDirectory(i, CONTENT_TYPE_ALL);
547                         if (i == 0)
548                         {
549                                 break;
550                         }
551                 }
552         }
553
554         if (checkedCount == 0)
555         {
556                 r = E_FAILURE;
557         }
558         else
559         {
560                 r = E_SUCCESS;
561                 __pAllCheckButton->SetSelected(true);
562                 __pAllCheckButton->RequestRedraw(true);
563         }
564
565         SetAllCheckState(false);
566         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
567         __pEditorFolderIconList->UpdateList();
568         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
569
570         return r;
571 }
572
573 void
574 AlbumListEditorForm::SetAllCheckState(bool state)
575 {
576         AppLogDebug("ENTER");
577         int maxCount = __pPresentationModel->GetFolderCount();
578         String tempString;
579
580         if (state == true)
581         {
582                 tempString.Format(FORMAT_BUFFER_SIZE, L"%ls (%d)",
583                                 ResourceManager::GetString(L"IDS_COM_BODY_SELECTED").GetPointer(), maxCount);
584         }
585         else
586         {
587                 tempString.Format(FORMAT_BUFFER_SIZE, L"%ls (%d)",
588                                 ResourceManager::GetString(L"IDS_COM_BODY_SELECTED").GetPointer(), 0);
589         }
590
591         for (int i = 0 ; i < maxCount; ++i)
592         {
593                 __pEditorFolderIconList->SetItemChecked(i, state);
594                 __pEditorFolderIconList->RefreshList(i, LIST_REFRESH_TYPE_ITEM_MODIFY);
595         }
596
597         __pEditorFolderIconList->Draw();
598         __pSelectCountLabel->SetText(tempString);
599         __pSelectCountLabel->RequestRedraw();
600         __checkedCount = GetCheckedFolder();
601
602         SetButtonState();
603         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
604 }
605
606 int
607 AlbumListEditorForm::GetCheckedFolder()
608 {
609         AppLogDebug("ENTER");
610         int maxCount = __pPresentationModel->GetFolderCount();
611         int count = 0;
612
613         for (int i = 0 ; i < maxCount; ++i)
614         {
615                 if (__pEditorFolderIconList->IsItemChecked (i))
616                 {
617                         count++;
618                 }
619         }
620         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
621
622         return count;
623 }
624
625 void
626 AlbumListEditorForm::OnActionPerformed(const Control& source, int actionId)
627 {
628         AppLogDebug("ENTER");
629         switch (actionId)
630         {
631         case ACTION_ID_CHECK_SELECT_ON:
632                 SetAllCheckState(true);
633                 break;
634         case ACTION_ID_CHECK_SELECT_OFF:
635                 SetAllCheckState(false);
636                 break;
637         case ACTION_ID_FOOTER_DELETE:
638                 if (__checkedCount > 0)
639                 {
640                         __pDeletePopup->SetShowState(true);
641                         __pDeletePopup->Show();
642                 }
643                 break;
644         case ACTION_ID_FOOTER_SHARE:
645                 __pShareContextMenu->SetShowState(true);
646                 __pShareContextMenu->Show();
647                 break;
648         case ACTION_ID_CONTEXT_MENU_MESSAGE:
649         {
650                 OnRequestMessage();
651                 break;
652         }
653         case ACTION_ID_CONTEXT_MENU_EMAIL:
654         {
655                 OnRequestEmail();
656                 break;
657         }
658         case ACTION_ID_DELETE_POPUP_DEL:
659         {
660                 __pDeletePopup->SetShowState(false);
661                 __pDeletePopup->Show();
662                 result r = DeleteFolder();
663                 AppLogDebug("CHECKBUTTONSTATE : R1");
664                 if (r == E_SUCCESS)
665                 {
666                         AppLogDebug("CHECKBUTTONSTATE : R2");
667                         SceneManager* pSceneManager = SceneManager::GetInstance();
668                         AppAssert(pSceneManager);
669                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
670                 }
671                 AppLogDebug("CHECKBUTTONSTATE : R3");
672                 break;
673         }
674         case ACTION_ID_DELETE_POPUP_CANCEL:
675         {
676                 __pDeletePopup->SetShowState(false);
677                 __pDeletePopup->Show();
678                 break;
679         }
680         default:
681                 break;
682         }
683         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
684 }
685
686 void
687 AlbumListEditorForm::OnFormBackRequested(Form& source)
688 {
689         AppLogDebug("ENTER");
690         SceneManager* pSceneManager = SceneManager::GetInstance();
691         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
692         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
693 }
694
695 void
696 AlbumListEditorForm::OnSceneActivatedN(const SceneId& previousSceneId,
697                 const SceneId& currentSceneId, IList* pArgs)
698 {
699         AppLogDebug("ENTER OnSceneActivatedN");
700         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
701         __pEditorFolderIconList->UpdateList();
702
703         __checkedCount = GetCheckedFolder();
704
705         String tempString;
706         tempString.Format(FORMAT_BUFFER_SIZE, L"%ls (%d)",
707                         ResourceManager::GetString(L"IDS_COM_BODY_SELECTED").GetPointer(), __checkedCount);
708         __pSelectCountLabel->SetText(tempString);
709         __pSelectCountLabel->RequestRedraw();
710
711         int maxCount = __pPresentationModel->GetFolderCount();
712         if (__checkedCount != 0 && __checkedCount == maxCount)
713         {
714                 __pAllCheckButton->SetSelected(true);
715         }
716         else
717         {
718                 __pAllCheckButton->SetSelected(false);
719         }
720
721         SetButtonState();
722         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
723 }
724
725 void
726 AlbumListEditorForm::OnSceneDeactivated(const SceneId& currentSceneId,
727                 const SceneId& nextSceneId)
728 {
729         AppLogDebug("ENTER");
730         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
731 }
732
733 void
734 AlbumListEditorForm::OnFileInfoChanged(const ContentType contentType)
735 {
736         AppLogDebug("ENTER");
737         Update();
738         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
739 }
740
741 void
742 AlbumListEditorForm::OnThumbnailDecoded(const int index)
743 {
744         AppLogDebug("ENTER : index(%d)", index);
745         __pEditorFolderIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
746         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
747 }
748
749 result
750 AlbumListEditorForm::Update(void)
751 {
752         AppLogDebug("ENTER");
753         result r = __pEditorFolderIconList->UpdateList();
754         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
755
756         return r;
757 }
758
759 void
760 AlbumListEditorForm::OnRequestMessage(void)
761 {
762         AppLogDebug("ENTER");
763
764         int checkCount = GetCheckedFolder();
765
766         if (checkCount <= 0)
767         {
768                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
769
770                 return;
771         }
772
773         String combineText;
774
775         IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
776
777         int maxCount = __pPresentationModel->GetFolderCount();
778         ContentManager contentManager;
779         result r = contentManager.Construct();
780         if (r == E_SUCCESS)
781         {
782                 if (maxCount <= 0)
783                 {
784                         AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
785
786                         return;
787                 }
788                 for (int i = 0 ; i < maxCount; ++i)
789                 {
790                         if (__pEditorFolderIconList->IsItemChecked (i))
791                         {
792                                 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(i));
793                                 IList* pContentIdList = pAlbumInfo->GetContentIdListN();
794                                 int loopCount = pContentIdList->GetCount();
795                                 for (int k = 0; k < loopCount; ++k)
796                                 {
797                                         ContentId* pContentId = static_cast<ContentId*>(pContentIdList->GetAt(k));
798                                         ContentInfo* pContentInfo = contentManager.GetContentInfoN(*pContentId);
799
800                                         if (pContentInfo == null)
801                                         {
802                                                 break;
803                                         }
804                                         String path = pContentInfo->GetContentPath();
805                                         if (combineText.CompareTo(EMPTY_SPACE) != 0)
806                                         {
807                                                 combineText.Append(L";");
808                                         }
809                                         combineText.Append(path);
810                                 }
811
812                                 if (i == 0)
813                                 {
814                                         break;
815                                 }
816                         }
817                 }
818
819                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
820                 pDataList->Construct();
821                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE),
822                                 new (std::nothrow) String(APPCONTROL_DATA_MMS));
823                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_ATTACHMENTS),
824                                 new (std::nothrow) String(combineText));
825
826                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_MESSAGE, APPCONTROL_OPERATION_ID_COMPOSE,
827                                 pDataList, null);
828         }
829         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
830 }
831
832 void
833 AlbumListEditorForm::OnRequestEmail(void)
834 {
835         AppLogDebug("ENTER");
836
837         int checkCount = GetCheckedFolder();
838
839         if (checkCount <= 0)
840         {
841                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
842
843                 return;
844         }
845
846         String combineText;
847
848         IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
849
850         int maxCount = __pPresentationModel->GetFolderCount();
851         ContentManager contentManager;
852         result r = contentManager.Construct();
853         if (r == E_SUCCESS)
854         {
855                 if (maxCount <= 0)
856                 {
857                         AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
858
859                         return;
860                 }
861                 for (int i = 0 ; i < maxCount; ++i)
862                 {
863                         if (__pEditorFolderIconList->IsItemChecked (i))
864                         {
865                                 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(i));
866                                 IList* pContentIdList = pAlbumInfo->GetContentIdListN();
867                                 int loopCount = pContentIdList->GetCount();
868                                 for (int k = 0; k < loopCount; ++k)
869                                 {
870                                         ContentId* pContentId = static_cast<ContentId*>(pContentIdList->GetAt(k));
871                                         ContentInfo* pContentInfo = contentManager.GetContentInfoN(*pContentId);
872
873                                         if (pContentInfo == null)
874                                         {
875                                                 break;
876                                         }
877                                         String path = pContentInfo->GetContentPath();
878                                         if (combineText.CompareTo(EMPTY_SPACE) != 0)
879                                         {
880                                                 combineText.Append(L";");
881                                         }
882                                         combineText.Append(path);
883                                 }
884
885                                 if (i == 0)
886                                 {
887                                         break;
888                                 }
889                         }
890                 }
891
892                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
893                 pDataList->Construct();
894                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_ATTACHMENTS),
895                                 new (std::nothrow) String(combineText));
896
897                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_EMAIL,
898                                 APPCONTROL_OPERATION_ID_COMPOSE, pDataList, null);
899         }
900         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
901 }
902
903 void
904 AlbumListEditorForm::SetFooterButtonsState(bool enableState)
905 {
906         AppLogDebug("ENTER");
907         Footer* pFooter = GetFooter();
908         AppAssert(pFooter);
909
910         if (enableState == true)
911         {
912                 pFooter->SetItemEnabled(0, true);
913                 pFooter->SetItemEnabled(1, true);
914         }
915         else
916         {
917                 pFooter->SetItemEnabled(0, false);
918                 pFooter->SetItemEnabled(1, false);
919         }
920
921         pFooter->RequestRedraw(true);
922         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
923 }
924
925 void
926 AlbumListEditorForm::SetButtonState(void)
927 {
928         AppLogDebug("ENTER");
929         if (GetCheckedFolder() > 0)
930         {
931                 AppLogDebug("BUTTONSTATE : Request Enable");
932                 SetFooterButtonsState(true);
933         }
934         else
935         {
936                 AppLogDebug("BUTTONSTATE : Request disable");
937                 SetFooterButtonsState(false);
938         }
939         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
940 }