74749da6360019fcda18126fe96b295a65291bac
[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_DELETE_BUTTON_NORMAL = Color32<208, 82, 82>::Value;
42 static const unsigned int COLOR_DELETE_BUTTON_PRESSED = Color32<194, 71, 71>::Value;
43 static const unsigned int COLOR_DELETE_BUTTON_TEXT = Color32<248, 246, 239>::Value;
44
45 static const int GAP_W_POPUP_ITEM = 5;
46 static const int W_DELETE_POPUP = 600;
47 static const int H_DELETE_POPUP = 300;
48 static const int H_DELETE_LABEL = 180;
49 static const int Y_DELETE_BUTTON = 180;
50 static const int H_DELETE_BUTTON = 80;
51
52 static const int FORMAT_BUFFER_SIZE = 256;
53
54 static const int X_POSITION_SHARE_CONTEXTMENU = 280;
55 static const int Y_POSITION_SHARE_CONTEXTMENU = 1150;
56
57 static const Color COLOR_FOLDER_BITMAP_DIM(Color::GetColor(COLOR_ID_BLACK));
58 static const int ALPHA_FOLDER_BITMAP_DIM = 70;
59
60 static const int IDA_ALBUM_EDIT = 503 ;
61
62 AlbumListEditorForm::AlbumListEditorForm()
63         : __checkedCount(0)
64         , __pSelectCountLabel(null)
65         , __pEditorFolderIconList(null)
66         , __pShareContextMenu(null)
67         , __pDeletePopup(null)
68         , __pPresentationModel(null)
69 {
70         AppLogDebug("ENTER");
71         __overlayMsg = false;
72         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
73 }
74
75 AlbumListEditorForm::~AlbumListEditorForm()
76 {
77         AppLogDebug("ENTER");
78         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
79 }
80
81 result
82 AlbumListEditorForm::Initialize(void)
83 {
84         AppLogDebug("ENTER");
85         result r = Form::Construct(IDL_FORM_ALBUM_LIST_EDITOR);
86         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
87
88         return r;
89 }
90
91 result
92 AlbumListEditorForm::OnInitializing(void)
93 {
94         AppLogDebug("ENTER");
95         __pPresentationModel = AlbumListPresentationModel::GetInstance();
96         __pPresentationModel->ClearThumbnailRequests();
97         __pPresentationModel->AddPresentationModelListener(this);
98         __pPresentationModel->AddContentEventListener(this);
99
100         SetFormBackEventListener(this);
101         GetHeader()->AddActionEventListener(*this);
102         GetFooter()->AddActionEventListener(*this);
103
104         result r = InitializeControl();
105         if (r != E_SUCCESS)
106         {
107                 AppLogDebug("[%s] Unable to set InitializeControl.", GetErrorMessage(r));
108         }
109
110         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
111
112         return r;
113 }
114
115 result
116 AlbumListEditorForm::OnTerminating(void)
117 {
118         AppLogDebug("ENTER");
119         __pPresentationModel->RemovePresentationModelListener(*this);
120         __pPresentationModel->RemoveContentEventListener(*this);
121
122         if (__pDeletePopup != null)
123         {
124                 delete __pDeletePopup;
125                 __pDeletePopup = null;
126         }
127         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
128
129         return E_SUCCESS;
130 }
131
132 void
133 AlbumListEditorForm::OnContentUpdated()
134 {
135         AppLogDebug("ENTER");
136         SceneManager* pSceneManager = SceneManager::GetInstance();
137         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
138         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
139 }
140
141 result
142 AlbumListEditorForm::InitializeControl()
143 {
144         AppLogDebug("ENTER");
145         String tempString;
146
147         CreateIconListView();
148         __checkedCount = GetCheckedFolder();
149
150         __pSelectCountLabel = static_cast<Label*>(GetControl(L"IDC_LABEL_ALBUM_LIST_EDITOR_SELECTED"));
151         AppAssert(__pSelectCountLabel);
152
153         __pShareContextMenu = new ContextMenu();
154         __pShareContextMenu->Construct(Point(X_POSITION_SHARE_CONTEXTMENU, Y_POSITION_SHARE_CONTEXTMENU),
155                         CONTEXT_MENU_STYLE_LIST);
156         __pShareContextMenu->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_MESSAGE"),
157                         ACTION_ID_CONTEXT_MENU_MESSAGE);
158         __pShareContextMenu->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_EMAIL"), ACTION_ID_CONTEXT_MENU_EMAIL);
159         __pShareContextMenu->AddActionEventListener(*this);
160
161         InitializePopup();
162         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
163
164         return E_SUCCESS;
165 }
166
167 result
168 AlbumListEditorForm::InitializePopup(void)
169 {
170         AppLogDebug("ENTER");
171         if (__pDeletePopup == null)
172         {
173                 __pDeletePopup = new (std::nothrow) Popup();
174                 __pDeletePopup->Construct(false, Dimension(W_DELETE_POPUP, H_DELETE_POPUP));
175
176                 Rectangle popupClientBounds = __pDeletePopup->GetClientAreaBounds();
177
178                 Label* pLabel = new (std::nothrow) Label();
179                 pLabel->Construct(Rectangle(0, 0, popupClientBounds.width, H_DELETE_LABEL),
180                                 ResourceManager::GetString(L"IDS_COM_POP_DELETE_Q"));
181
182                 Button* pDeleteButton = new (std::nothrow) Button();
183                 pDeleteButton->Construct(
184                                 Rectangle(0, Y_DELETE_BUTTON, popupClientBounds.width / 2 - GAP_W_POPUP_ITEM, H_DELETE_BUTTON),
185                                 ResourceManager::GetString(L"IDS_COM_BODY_DELETE"));
186                 pDeleteButton->SetColor(BUTTON_STATUS_NORMAL, COLOR_DELETE_BUTTON_NORMAL);
187                 pDeleteButton->SetColor(BUTTON_STATUS_PRESSED, COLOR_DELETE_BUTTON_PRESSED);
188                 pDeleteButton->SetTextColor(COLOR_DELETE_BUTTON_TEXT);
189                 pDeleteButton->SetActionId(ACTION_ID_DELETE_POPUP_DEL);
190                 pDeleteButton->AddActionEventListener(*this);
191
192                 Button* pCancelButton = new (std::nothrow) Button();
193                 pCancelButton->Construct(
194                                 Rectangle(popupClientBounds.width / 2 + GAP_W_POPUP_ITEM, Y_DELETE_BUTTON,
195                                                 popupClientBounds.width / 2 - GAP_W_POPUP_ITEM, H_DELETE_BUTTON),
196                                                 ResourceManager::GetString(L"IDS_COM_POP_CANCEL"));
197                 pCancelButton->SetActionId(ACTION_ID_DELETE_POPUP_CANCEL);
198                 pCancelButton->AddActionEventListener(*this);
199
200                 __pDeletePopup->AddControl(*pLabel);
201                 __pDeletePopup->AddControl(*pDeleteButton);
202                 __pDeletePopup->AddControl(*pCancelButton);
203         }
204         else
205         {
206                 __pDeletePopup->SetShowState(true);
207                 __pDeletePopup->Show();
208         }
209         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
210
211         return E_SUCCESS;
212 }
213
214 void
215 AlbumListEditorForm::CreateIconListView(void)
216 {
217         AppLogDebug("ENTER");
218         __pEditorFolderIconList = static_cast< IconListView* >(GetControl(L"IDC_ICONLISTVIEW_ALBUM_LIST_EDITOR"));
219         AppAssert(__pEditorFolderIconList);
220
221         __pEditorFolderIconList->SetItemProvider(*this);
222         __pEditorFolderIconList->AddIconListViewItemEventListener(*this);
223         __pEditorFolderIconList->SetShowState(true);
224         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
225 }
226
227 int
228 AlbumListEditorForm::GetItemCount(void)
229 {
230         AppLogDebug("ENTER");
231         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
232
233         return __pPresentationModel->GetFolderCount();
234 }
235
236 IconListViewItem*
237 AlbumListEditorForm::CreateItem(int index)
238 {
239         AppLogDebug("ENTER : index(%d)", index);
240         Bitmap* pBitmap = null;
241         Canvas* pEditAlbumCanvas = null;
242         Bitmap* pEditAlbumBitmap = null;
243         Bitmap* pBitmapRenameBg = null;
244         Bitmap* pBitmapRename = null;
245         String albumName ;
246         int canvasWidth = 64;
247         int canvasHeight = 64;
248
249         IconListViewItem* pIconListviewItem = new IconListViewItem();
250
251         IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
252         AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
253
254         Bitmap* pAlbumBitmap = pAlbumInfo->GetFolderThumnailBitmap();
255         if (pAlbumBitmap == null)
256         {
257                 __pPresentationModel->RequestThumbnail(index, 0);
258         }
259
260         pBitmap = __pPresentationModel->CreateMergeBitmapN(index);
261
262         if (__pEditorFolderIconList->IsItemChecked(index) == true)
263         {
264                 if (pBitmap != null)
265                 {
266                         BufferInfo bufferInfo;
267                         pBitmap->Lock(bufferInfo, INFINITE);
268                         pBitmap->Unlock();
269                         Color dimColor(COLOR_FOLDER_BITMAP_DIM);
270                         dimColor.SetAlpha(ALPHA_FOLDER_BITMAP_DIM);
271                         Canvas canvas;
272                         canvas.Construct(bufferInfo);
273                         canvas.FillRectangle(dimColor, canvas.GetBounds());
274                         Bitmap* pSelectedBitmap = new (std::nothrow) Bitmap();
275                         pSelectedBitmap->Construct(canvas, canvas.GetBounds());
276                         pIconListviewItem->Construct(*pBitmap, null, pSelectedBitmap);
277                         delete pSelectedBitmap;
278                 }
279         }
280         else
281         {
282                 pIconListviewItem->Construct(*pBitmap);
283         }
284
285         if (pBitmap != null)
286         {
287                 delete pBitmap;
288         }
289
290         pBitmapRenameBg = ResourceManager::GetBitmapN(IDB_ALBUM_EDIT_RENAME_BG);
291         pBitmapRename = ResourceManager::GetBitmapN(IDB_ALBUM_EDIT_RENAME);
292
293         if (pBitmapRenameBg != null &&  pBitmapRename != null)
294         {
295
296                 pEditAlbumCanvas = new (std::nothrow) Canvas();
297                 pEditAlbumCanvas->Construct(Rectangle(0,0,canvasWidth,canvasHeight));
298                 pEditAlbumCanvas->DrawBitmap(Point(0,0),*pBitmapRenameBg);
299                 pEditAlbumCanvas->DrawBitmap(Point(0,0),*pBitmapRename);
300
301
302                 pEditAlbumBitmap = new (std::nothrow) Bitmap();
303
304                 if (pEditAlbumBitmap != NULL)
305                 {
306                         pEditAlbumBitmap->Construct(*pEditAlbumCanvas,Rectangle(0,0,canvasWidth,canvasHeight));
307                         delete pEditAlbumCanvas;
308                 }
309
310                 albumName = pAlbumInfo->GetAlbumName();
311                 String reservedCameraName = ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB");
312
313                 if (index == 0  || reservedCameraName.Equals(albumName,true))
314                 {
315                         // rename disabled
316                 }
317                 else
318                 {
319                         pIconListviewItem->SetOverlayBitmap(IDA_ALBUM_EDIT, pEditAlbumBitmap, ALIGNMENT_RIGHT, ALIGNMENT_TOP);
320                 }
321         }
322
323
324         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
325
326         return pIconListviewItem;
327 }
328
329 void
330 AlbumListEditorForm::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
331 {
332         AppLogDebug("ENTER");
333
334         if (status == ICON_LIST_VIEW_ITEM_CHECKED || status == ICON_LIST_VIEW_ITEM_UNCHECKED)
335         {
336                 if (status == ICON_LIST_VIEW_ITEM_CHECKED)
337                 {
338                         ++__checkedCount;
339                 }
340                 else if (status == ICON_LIST_VIEW_ITEM_UNCHECKED)
341                 {
342                         --__checkedCount;
343                 }
344
345                 String tempString;
346                 if (__checkedCount == 0)
347                 {
348                         tempString = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
349                 }
350                 else if (__checkedCount == 1)
351                 {
352                         tempString = ResourceManager::GetString(L"IDS_VR_POP_1_ITEM_SELECTED");
353                 }
354                 else
355                 {
356                         tempString.Format(FORMAT_BUFFER_SIZE,
357                                         ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), __checkedCount);
358                 }
359
360                 __pSelectCountLabel->SetText(tempString);
361                 __pSelectCountLabel->RequestRedraw();
362                 __pEditorFolderIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
363         }
364         SetButtonState();
365         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
366 }
367
368 void
369 AlbumListEditorForm::OnIconListViewOverlayBitmapSelected (IconListView &iconListView, int index,
370                 int overlayBitmapId)
371 {
372         AppLogDebug("ENTER");
373         SceneManager* pSceneManager = SceneManager::GetInstance();
374
375         ArrayList* pSelectedIndex = new (std::nothrow) ArrayList(SingleObjectDeleter);
376         pSelectedIndex->Construct();
377         //Adding the Action Type
378         pSelectedIndex->Add(new (std::nothrow) Integer(ALBUM_RENAME));
379         pSelectedIndex->Add(new (std::nothrow) Integer(index));
380
381         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_NAME_EDITOR), pSelectedIndex);
382         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
383 }
384
385 bool
386 AlbumListEditorForm::DeleteItem(int index, IconListViewItem* pItem)
387 {
388         AppLogDebug("ENTER");
389         delete pItem;
390         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
391
392         return true;
393 }
394
395 result
396 AlbumListEditorForm::DeleteFolder()
397 {
398         AppLogDebug("ENTER");
399         int maxCount = __pPresentationModel->GetFolderCount();
400         result r = E_FAILURE;
401
402         int checkedCount = 0;
403
404         for (int i = 0 ; i < maxCount; ++i)
405         {
406                 if (__pEditorFolderIconList->IsItemChecked(i) == true)
407                 {
408                         ++checkedCount;
409                         __pPresentationModel->DeleteContentInfoInDirectory(i, CONTENT_TYPE_ALL);
410                         if (i == 0)
411                         {
412                                 break;
413                         }
414                 }
415         }
416
417         if (checkedCount == 0)
418         {
419                 r = E_FAILURE;
420         }
421         else
422         {
423                 r = E_SUCCESS;
424         }
425
426         SetAllCheckState(false);
427         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
428         __pEditorFolderIconList->UpdateList();
429         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
430
431         return r;
432 }
433
434 void
435 AlbumListEditorForm::SetAllCheckState(bool state)
436 {
437         AppLogDebug("ENTER");
438         int maxCount = __pPresentationModel->GetFolderCount();
439         String tempString;
440
441         if (state == true)
442         {
443                 if (maxCount == 1)
444                 {
445                         tempString = ResourceManager::GetString(L"IDS_VR_POP_1_ITEM_SELECTED;");
446                 }
447                 else
448                 {
449                         tempString.Format(FORMAT_BUFFER_SIZE,
450                                         ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), maxCount);
451                 }
452         }
453         else
454         {
455                 tempString = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
456         }
457
458         for (int i = 0 ; i < maxCount; ++i)
459         {
460                 __pEditorFolderIconList->SetItemChecked(i, state);
461                 __pEditorFolderIconList->RefreshList(i, LIST_REFRESH_TYPE_ITEM_MODIFY);
462         }
463
464         __pEditorFolderIconList->Draw();
465         __pSelectCountLabel->SetText(tempString);
466         __pSelectCountLabel->RequestRedraw();
467         __checkedCount = GetCheckedFolder();
468
469         SetButtonState();
470         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
471 }
472
473 int
474 AlbumListEditorForm::GetCheckedFolder()
475 {
476         AppLogDebug("ENTER");
477         int maxCount = __pPresentationModel->GetFolderCount();
478         int count = 0;
479
480         for (int i = 0 ; i < maxCount; ++i)
481         {
482                 if (__pEditorFolderIconList->IsItemChecked (i))
483                 {
484                         count++;
485                 }
486         }
487         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
488
489         return count;
490 }
491
492 void
493 AlbumListEditorForm::OnActionPerformed(const Control& source, int actionId)
494 {
495         AppLogDebug("ENTER");
496         switch (actionId)
497         {
498         case ACTION_ID_ALBUM_LIST_SELECT_ALL:
499                 if (__pPresentationModel->GetFolderCount() == GetCheckedFolder())
500                 {
501                         SetAllCheckState(false);
502                 }
503                 else
504                 {
505                         SetAllCheckState(true);
506                 }
507                 break;
508         case ACTION_ID_FOOTER_DELETE:
509         {
510                 __pDeletePopup->SetShowState(true);
511                 __pDeletePopup->Show();
512         }
513         break;
514         case ACTION_ID_FOOTER_SHARE:
515                 __pShareContextMenu->SetShowState(true);
516                 __pShareContextMenu->Show();
517                 break;
518         case ACTION_ID_CONTEXT_MENU_MESSAGE:
519         {
520                 OnRequestMessage();
521                 break;
522         }
523         case ACTION_ID_CONTEXT_MENU_EMAIL:
524         {
525                 OnRequestEmail();
526                 break;
527         }
528         case ACTION_ID_DELETE_POPUP_DEL:
529         {
530                 __pDeletePopup->SetShowState(false);
531                 __pDeletePopup->Show();
532                 result r = DeleteFolder();
533                 AppLogDebug("CHECKBUTTONSTATE : R1");
534                 if (r == E_SUCCESS)
535                 {
536                         AppLogDebug("CHECKBUTTONSTATE : R2");
537                         SceneManager* pSceneManager = SceneManager::GetInstance();
538                         AppAssert(pSceneManager);
539                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
540                 }
541                 AppLogDebug("CHECKBUTTONSTATE : R3");
542                 break;
543         }
544         case ACTION_ID_DELETE_POPUP_CANCEL:
545         {
546                 __pDeletePopup->SetShowState(false);
547                 __pDeletePopup->Show();
548                 break;
549         }
550         default:
551                 break;
552         }
553         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
554 }
555
556 void
557 AlbumListEditorForm::OnFormBackRequested(Form& source)
558 {
559         AppLogDebug("ENTER");
560         SceneManager* pSceneManager = SceneManager::GetInstance();
561         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
562         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
563 }
564
565 void
566 AlbumListEditorForm::OnSceneActivatedN(const SceneId& previousSceneId,
567                 const SceneId& currentSceneId, IList* pArgs)
568 {
569         AppLogDebug("ENTER OnSceneActivatedN");
570         __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
571         __pEditorFolderIconList->UpdateList();
572
573         __checkedCount = GetCheckedFolder();
574
575         String tempString;
576
577         if (__checkedCount == 0)
578         {
579                 tempString = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
580         }
581         else if (__checkedCount == 1)
582         {
583                 tempString = ResourceManager::GetString(L"IDS_VR_POP_1_ITEM_SELECTED");
584         }
585         else
586         {
587                 tempString.Format(FORMAT_BUFFER_SIZE,
588                                 ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), __checkedCount);
589         }
590
591         __pSelectCountLabel->SetText(tempString);
592         __pSelectCountLabel->RequestRedraw();
593
594         SetButtonState();
595         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
596 }
597
598 void
599 AlbumListEditorForm::OnSceneDeactivated(const SceneId& currentSceneId,
600                 const SceneId& nextSceneId)
601 {
602         AppLogDebug("ENTER");
603         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
604 }
605
606 void
607 AlbumListEditorForm::OnFileInfoChanged(const ContentType contentType)
608 {
609         AppLogDebug("ENTER");
610         Update();
611         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
612 }
613
614 void
615 AlbumListEditorForm::OnThumbnailDecoded(const int index)
616 {
617         AppLogDebug("ENTER : index(%d)", index);
618         __pEditorFolderIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
619         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
620 }
621
622 result
623 AlbumListEditorForm::Update(void)
624 {
625         AppLogDebug("ENTER");
626         result r = __pEditorFolderIconList->UpdateList();
627         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
628
629         return r;
630 }
631
632 void
633 AlbumListEditorForm::OnRequestMessage(void)
634 {
635         AppLogDebug("ENTER");
636
637         int checkCount = GetCheckedFolder();
638
639         if (checkCount <= 0)
640         {
641                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
642
643                 return;
644         }
645
646         IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
647
648         int maxCount = __pPresentationModel->GetFolderCount();
649         ContentManager contentManager;
650         result r = contentManager.Construct();
651         if (r == E_SUCCESS)
652         {
653                 if (maxCount <= 0)
654                 {
655                         AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
656                         return;
657                 }
658
659                 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
660                 pArrayList->Construct();
661                 for (int i = 0 ; i < maxCount; ++i)
662                 {
663                         if (__pEditorFolderIconList->IsItemChecked (i))
664                         {
665                                 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(i));
666                                 IList* pContentIdList = pAlbumInfo->GetContentIdListN();
667                                 int loopCount = pContentIdList->GetCount();
668                                 for (int k = 0; k < loopCount; ++k)
669                                 {
670                                         ContentId* pContentId = static_cast<ContentId*>(pContentIdList->GetAt(k));
671                                         ContentInfo* pContentInfo = contentManager.GetContentInfoN(*pContentId);
672
673                                         if (pContentInfo == null)
674                                         {
675                                                 break;
676                                         }
677                                         pArrayList->Add(new (std::nothrow) String(pContentInfo->GetContentPath()));
678                                 }
679
680                                 if (i == 0)
681                                 {
682                                         break;
683                                 }
684                         }
685                 }
686
687                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
688                 pDataList->Construct();
689                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_MESSAGE_TYPE), new (std::nothrow) String(APPCONTROL_DATA_MMS));
690                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
691
692                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_MESSAGE, APPCONTROL_OPERATION_ID_COMPOSE,
693                                 null, null, pDataList, null);
694         }
695         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
696 }
697
698 void
699 AlbumListEditorForm::OnRequestEmail(void)
700 {
701         AppLogDebug("ENTER");
702
703         int checkCount = GetCheckedFolder();
704
705         if (checkCount <= 0)
706         {
707                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
708
709                 return;
710         }
711
712         IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
713
714         int maxCount = __pPresentationModel->GetFolderCount();
715         ContentManager contentManager;
716         result r = contentManager.Construct();
717         if (r == E_SUCCESS)
718         {
719                 if (maxCount <= 0)
720                 {
721                         AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
722                         return;
723                 }
724
725                 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
726                 pArrayList->Construct();
727                 for (int i = 0 ; i < maxCount; ++i)
728                 {
729                         if (__pEditorFolderIconList->IsItemChecked (i))
730                         {
731                                 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(i));
732                                 IList* pContentIdList = pAlbumInfo->GetContentIdListN();
733                                 int loopCount = pContentIdList->GetCount();
734                                 for (int k = 0; k < loopCount; ++k)
735                                 {
736                                         ContentId* pContentId = static_cast<ContentId*>(pContentIdList->GetAt(k));
737                                         ContentInfo* pContentInfo = contentManager.GetContentInfoN(*pContentId);
738
739                                         if (pContentInfo == null)
740                                         {
741                                                 break;
742                                         }
743                                         pArrayList->Add(new (std::nothrow) String(pContentInfo->GetContentPath()));
744                                 }
745
746                                 if (i == 0)
747                                 {
748                                         break;
749                                 }
750                         }
751                 }
752
753                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
754                 pDataList->Construct();
755                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
756
757                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_EMAIL, APPCONTROL_OPERATION_ID_COMPOSE,
758                                 new (std::nothrow) String(APPCONTROL_URI_MAIL_TO), null, pDataList, null);
759         }
760         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
761 }
762
763 void
764 AlbumListEditorForm::SetFooterButtonsState(bool enableState)
765 {
766         AppLogDebug("ENTER");
767         Footer* pFooter = GetFooter();
768         AppAssert(pFooter);
769
770         if (enableState == true)
771         {
772                 pFooter->SetItemEnabled(0, true);
773                 pFooter->SetItemEnabled(1, true);
774         }
775         else
776         {
777                 pFooter->SetItemEnabled(0, false);
778                 pFooter->SetItemEnabled(1, false);
779         }
780
781         pFooter->RequestRedraw(true);
782         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
783 }
784
785 void
786 AlbumListEditorForm::SetButtonState(void)
787 {
788         AppLogDebug("ENTER");
789         if (GetCheckedFolder() > 0)
790         {
791                 AppLogDebug("BUTTONSTATE : Request Enable");
792                 SetFooterButtonsState(true);
793         }
794         else
795         {
796                 AppLogDebug("BUTTONSTATE : Request disable");
797                 SetFooterButtonsState(false);
798         }
799         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
800 }