2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
18 * @file GlAlbumListEditorForm.cpp
19 * @brief This is the implementation file for AlbumListEditorForm class.
23 #include "GlAlbumInfo.h"
24 #include "GlAlbumListEditorForm.h"
25 #include "GlAlbumListPresentationModel.h"
26 #include "GlResourceManager.h"
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;
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;
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;
52 static const int FORMAT_BUFFER_SIZE = 256;
54 static const int X_POSITION_SHARE_CONTEXTMENU = 300;
55 static const int Y_POSITION_SHARE_CONTEXTMENU = 1180;
57 static const Color COLOR_FOLDER_BITMAP_DIM(Color::GetColor(COLOR_ID_BLACK));
58 static const int ALPHA_FOLDER_BITMAP_DIM = 70;
60 AlbumListEditorForm::AlbumListEditorForm()
62 , __pSelectCountLabel(null)
63 , __pEditorFolderIconList(null)
64 , __pShareContextMenu(null)
65 , __pDeletePopup(null)
66 , __pPresentationModel(null)
70 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
73 AlbumListEditorForm::~AlbumListEditorForm()
76 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
80 AlbumListEditorForm::Initialize(void)
83 result r = Form::Construct(IDL_FORM_ALBUM_LIST_EDITOR);
84 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
90 AlbumListEditorForm::OnInitializing(void)
93 __pPresentationModel = AlbumListPresentationModel::GetInstance();
94 __pPresentationModel->ClearThumbnailRequests();
95 __pPresentationModel->AddPresentationModelListener(this);
97 SetFormBackEventListener(this);
98 GetHeader()->AddActionEventListener(*this);
99 GetFooter()->AddActionEventListener(*this);
101 result r = InitializeControl();
104 AppLogDebug("[%s] Unable to set InitializeControl.", GetErrorMessage(r));
107 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
113 AlbumListEditorForm::OnTerminating(void)
115 AppLogDebug("ENTER");
116 __pPresentationModel->RemovePresentationModelListener(*this);
118 if (__pDeletePopup != null)
120 delete __pDeletePopup;
121 __pDeletePopup = null;
123 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
129 AlbumListEditorForm::OnUpdateContentList()
131 AppLogDebug("ENTER");
132 SceneManager* pSceneManager = SceneManager::GetInstance();
133 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
134 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
138 AlbumListEditorForm::InitializeControl()
140 AppLogDebug("ENTER");
143 CreateIconListView();
144 __checkedCount = GetCheckedFolder();
146 __pSelectCountLabel = static_cast<Label*>(GetControl(L"IDC_LABEL_ALBUM_LIST_EDITOR_SELECTED"));
147 AppAssert(__pSelectCountLabel);
149 __pShareContextMenu = new ContextMenu();
150 __pShareContextMenu->Construct(Point(X_POSITION_SHARE_CONTEXTMENU, Y_POSITION_SHARE_CONTEXTMENU),
151 CONTEXT_MENU_STYLE_LIST);
152 __pShareContextMenu->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_MESSAGE"),
153 ACTION_ID_CONTEXT_MENU_MESSAGE);
154 __pShareContextMenu->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_EMAIL"), ACTION_ID_CONTEXT_MENU_EMAIL);
155 __pShareContextMenu->AddActionEventListener(*this);
158 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
164 AlbumListEditorForm::InitializePopup(void)
166 AppLogDebug("ENTER");
167 if (__pDeletePopup == null)
169 __pDeletePopup = new (std::nothrow) Popup();
170 __pDeletePopup->Construct(false, Dimension(W_DELETE_POPUP, H_DELETE_POPUP));
172 Rectangle popupClientBounds = __pDeletePopup->GetClientAreaBounds();
174 Label* pLabel = new (std::nothrow) Label();
175 pLabel->Construct(Rectangle(0, 0, popupClientBounds.width, H_DELETE_LABEL),
176 ResourceManager::GetString(L"IDS_COM_POP_DELETE_Q"));
178 Button* pDeleteButton = new (std::nothrow) Button();
179 pDeleteButton->Construct(
180 Rectangle(0, Y_DELETE_BUTTON, popupClientBounds.width / 2 - GAP_W_POPUP_ITEM, H_DELETE_BUTTON),
181 ResourceManager::GetString(L"IDS_COM_BODY_DELETE"));
182 pDeleteButton->SetColor(BUTTON_STATUS_NORMAL, COLOR_DELETE_BUTTON_NORMAL);
183 pDeleteButton->SetColor(BUTTON_STATUS_PRESSED, COLOR_DELETE_BUTTON_PRESSED);
184 pDeleteButton->SetTextColor(COLOR_DELETE_BUTTON_TEXT);
185 pDeleteButton->SetActionId(ACTION_ID_DELETE_POPUP_DEL);
186 pDeleteButton->AddActionEventListener(*this);
188 Button* pCancelButton = new (std::nothrow) Button();
189 pCancelButton->Construct(
190 Rectangle(popupClientBounds.width / 2 + GAP_W_POPUP_ITEM, Y_DELETE_BUTTON,
191 popupClientBounds.width / 2 - GAP_W_POPUP_ITEM, H_DELETE_BUTTON),
192 ResourceManager::GetString(L"IDS_COM_POP_CANCEL"));
193 pCancelButton->SetActionId(ACTION_ID_DELETE_POPUP_CANCEL);
194 pCancelButton->AddActionEventListener(*this);
196 __pDeletePopup->AddControl(*pLabel);
197 __pDeletePopup->AddControl(*pDeleteButton);
198 __pDeletePopup->AddControl(*pCancelButton);
202 __pDeletePopup->SetShowState(true);
203 __pDeletePopup->Show();
205 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
211 AlbumListEditorForm::CreateIconListView(void)
213 AppLogDebug("ENTER");
214 __pEditorFolderIconList = static_cast< IconListView* >(GetControl(L"IDC_ICONLISTVIEW_ALBUM_LIST_EDITOR"));
215 AppAssert(__pEditorFolderIconList);
217 __pEditorFolderIconList->SetItemProvider(*this);
218 __pEditorFolderIconList->AddIconListViewItemEventListener(*this);
219 __pEditorFolderIconList->SetShowState(true);
220 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
224 AlbumListEditorForm::GetItemCount(void)
226 AppLogDebug("ENTER");
227 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
229 return __pPresentationModel->GetFolderCount();
233 AlbumListEditorForm::CreateItem(int index)
235 AppLogDebug("ENTER : index(%d)", index);
236 Bitmap* pBitmap = null;
237 IconListViewItem* pIconListview = new IconListViewItem();
239 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
240 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
242 Bitmap* pAlbumBitmap = pAlbumInfo->GetFolderThumnailBitmap();
243 if (pAlbumBitmap == null)
245 __pPresentationModel->RequestThumbnail(index, 0);
248 pBitmap = __pPresentationModel->CreateMergeBitmapN(index);
250 if (__pEditorFolderIconList->IsItemChecked(index) == true)
254 BufferInfo bufferInfo;
255 pBitmap->Lock(bufferInfo, INFINITE);
257 Color dimColor(COLOR_FOLDER_BITMAP_DIM);
258 dimColor.SetAlpha(ALPHA_FOLDER_BITMAP_DIM);
260 canvas.Construct(bufferInfo);
261 canvas.FillRectangle(dimColor, canvas.GetBounds());
262 Bitmap* pSelectedBitmap = new (std::nothrow) Bitmap();
263 pSelectedBitmap->Construct(canvas, canvas.GetBounds());
264 pIconListview->Construct(*pBitmap, null, pSelectedBitmap);
265 delete pSelectedBitmap;
270 pIconListview->Construct(*pBitmap);
277 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
279 return pIconListview;
283 AlbumListEditorForm::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
285 AppLogDebug("ENTER");
287 if (status == ICON_LIST_VIEW_ITEM_CHECKED || status == ICON_LIST_VIEW_ITEM_UNCHECKED)
289 if (status == ICON_LIST_VIEW_ITEM_CHECKED)
293 else if (status == ICON_LIST_VIEW_ITEM_UNCHECKED)
299 if (__checkedCount == 0)
301 tempString = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
303 else if (__checkedCount == 1)
305 tempString = ResourceManager::GetString(L"IDS_VR_POP_1_ITEM_SELECTED");
309 tempString.Format(FORMAT_BUFFER_SIZE,
310 ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), __checkedCount);
313 __pSelectCountLabel->SetText(tempString);
314 __pSelectCountLabel->RequestRedraw();
315 __pEditorFolderIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
318 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
322 AlbumListEditorForm::OnIconListViewOverlayBitmapSelected (IconListView &iconListView, int index,
325 AppLogDebug("ENTER");
326 SceneManager* pSceneManager = SceneManager::GetInstance();
328 if (overlayBitmapId == ACTION_ID_EDITE_FOLDER)
330 ArrayList* pSelectedIndex = new (std::nothrow) ArrayList(SingleObjectDeleter);
331 pSelectedIndex->Construct();
332 pSelectedIndex->Add(new (std::nothrow) Integer(index));
334 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_NAME_EDITOR), pSelectedIndex);
336 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
340 AlbumListEditorForm::DeleteItem(int index, IconListViewItem* pItem)
342 AppLogDebug("ENTER");
344 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
350 AlbumListEditorForm::DeleteFolder()
352 AppLogDebug("ENTER");
353 int maxCount = __pPresentationModel->GetFolderCount();
354 result r = E_FAILURE;
356 int checkedCount = 0;
358 for (int i = 0 ; i < maxCount; ++i)
360 if (__pEditorFolderIconList->IsItemChecked(i) == true)
363 __pPresentationModel->DeleteContentInfoInDirectory(i, CONTENT_TYPE_ALL);
371 if (checkedCount == 0)
380 SetAllCheckState(false);
381 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
382 __pEditorFolderIconList->UpdateList();
383 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
389 AlbumListEditorForm::SetAllCheckState(bool state)
391 AppLogDebug("ENTER");
392 int maxCount = __pPresentationModel->GetFolderCount();
399 tempString = ResourceManager::GetString(L"IDS_VR_POP_1_ITEM_SELECTED;");
403 tempString.Format(FORMAT_BUFFER_SIZE,
404 ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), maxCount);
409 tempString = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
412 for (int i = 0 ; i < maxCount; ++i)
414 __pEditorFolderIconList->SetItemChecked(i, state);
415 __pEditorFolderIconList->RefreshList(i, LIST_REFRESH_TYPE_ITEM_MODIFY);
418 __pEditorFolderIconList->Draw();
419 __pSelectCountLabel->SetText(tempString);
420 __pSelectCountLabel->RequestRedraw();
421 __checkedCount = GetCheckedFolder();
424 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
428 AlbumListEditorForm::GetCheckedFolder()
430 AppLogDebug("ENTER");
431 int maxCount = __pPresentationModel->GetFolderCount();
434 for (int i = 0 ; i < maxCount; ++i)
436 if (__pEditorFolderIconList->IsItemChecked (i))
441 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
447 AlbumListEditorForm::OnActionPerformed(const Control& source, int actionId)
449 AppLogDebug("ENTER");
452 case ACTION_ID_ALBUM_LIST_SELECT_ALL:
453 if (__pPresentationModel->GetFolderCount() == GetCheckedFolder())
455 SetAllCheckState(false);
459 SetAllCheckState(true);
462 case ACTION_ID_FOOTER_DELETE:
463 if (__checkedCount > 0)
465 __pDeletePopup->SetShowState(true);
466 __pDeletePopup->Show();
469 case ACTION_ID_FOOTER_SHARE:
470 __pShareContextMenu->SetShowState(true);
471 __pShareContextMenu->Show();
473 case ACTION_ID_CONTEXT_MENU_MESSAGE:
478 case ACTION_ID_CONTEXT_MENU_EMAIL:
483 case ACTION_ID_DELETE_POPUP_DEL:
485 __pDeletePopup->SetShowState(false);
486 __pDeletePopup->Show();
487 result r = DeleteFolder();
488 AppLogDebug("CHECKBUTTONSTATE : R1");
491 AppLogDebug("CHECKBUTTONSTATE : R2");
492 SceneManager* pSceneManager = SceneManager::GetInstance();
493 AppAssert(pSceneManager);
494 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
496 AppLogDebug("CHECKBUTTONSTATE : R3");
499 case ACTION_ID_DELETE_POPUP_CANCEL:
501 __pDeletePopup->SetShowState(false);
502 __pDeletePopup->Show();
508 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
512 AlbumListEditorForm::OnFormBackRequested(Form& source)
514 AppLogDebug("ENTER");
515 SceneManager* pSceneManager = SceneManager::GetInstance();
516 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
517 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
521 AlbumListEditorForm::OnSceneActivatedN(const SceneId& previousSceneId,
522 const SceneId& currentSceneId, IList* pArgs)
524 AppLogDebug("ENTER OnSceneActivatedN");
525 __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_ALL);
526 __pEditorFolderIconList->UpdateList();
528 __checkedCount = GetCheckedFolder();
532 if (__checkedCount == 0)
534 tempString = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
536 else if (__checkedCount == 1)
538 tempString = ResourceManager::GetString(L"IDS_VR_POP_1_ITEM_SELECTED");
542 tempString.Format(FORMAT_BUFFER_SIZE,
543 ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), __checkedCount);
546 __pSelectCountLabel->SetText(tempString);
547 __pSelectCountLabel->RequestRedraw();
550 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
554 AlbumListEditorForm::OnSceneDeactivated(const SceneId& currentSceneId,
555 const SceneId& nextSceneId)
557 AppLogDebug("ENTER");
558 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
562 AlbumListEditorForm::OnFileInfoChanged(const ContentType contentType)
564 AppLogDebug("ENTER");
566 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
570 AlbumListEditorForm::OnThumbnailDecoded(const int index)
572 AppLogDebug("ENTER : index(%d)", index);
573 __pEditorFolderIconList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
574 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
578 AlbumListEditorForm::Update(void)
580 AppLogDebug("ENTER");
581 result r = __pEditorFolderIconList->UpdateList();
582 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
588 AlbumListEditorForm::OnRequestMessage(void)
590 AppLogDebug("ENTER");
592 int checkCount = GetCheckedFolder();
596 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
603 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
605 int maxCount = __pPresentationModel->GetFolderCount();
606 ContentManager contentManager;
607 result r = contentManager.Construct();
612 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
616 for (int i = 0 ; i < maxCount; ++i)
618 if (__pEditorFolderIconList->IsItemChecked (i))
620 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(i));
621 IList* pContentIdList = pAlbumInfo->GetContentIdListN();
622 int loopCount = pContentIdList->GetCount();
623 for (int k = 0; k < loopCount; ++k)
625 ContentId* pContentId = static_cast<ContentId*>(pContentIdList->GetAt(k));
626 ContentInfo* pContentInfo = contentManager.GetContentInfoN(*pContentId);
628 if (pContentInfo == null)
632 String path = pContentInfo->GetContentPath();
633 if (combineText.CompareTo(EMPTY_SPACE) != 0)
635 combineText.Append(L";");
637 combineText.Append(path);
647 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
648 pDataList->Construct();
649 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE),
650 new (std::nothrow) String(APPCONTROL_DATA_MMS));
651 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_ATTACHMENTS),
652 new (std::nothrow) String(combineText));
654 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_MESSAGE, APPCONTROL_OPERATION_ID_COMPOSE,
657 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
661 AlbumListEditorForm::OnRequestEmail(void)
663 AppLogDebug("ENTER");
665 int checkCount = GetCheckedFolder();
669 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
676 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
678 int maxCount = __pPresentationModel->GetFolderCount();
679 ContentManager contentManager;
680 result r = contentManager.Construct();
685 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
689 for (int i = 0 ; i < maxCount; ++i)
691 if (__pEditorFolderIconList->IsItemChecked (i))
693 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(i));
694 IList* pContentIdList = pAlbumInfo->GetContentIdListN();
695 int loopCount = pContentIdList->GetCount();
696 for (int k = 0; k < loopCount; ++k)
698 ContentId* pContentId = static_cast<ContentId*>(pContentIdList->GetAt(k));
699 ContentInfo* pContentInfo = contentManager.GetContentInfoN(*pContentId);
701 if (pContentInfo == null)
705 String path = pContentInfo->GetContentPath();
706 if (combineText.CompareTo(EMPTY_SPACE) != 0)
708 combineText.Append(L";");
710 combineText.Append(path);
720 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
721 pDataList->Construct();
722 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_ATTACHMENTS),
723 new (std::nothrow) String(combineText));
725 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_EMAIL,
726 APPCONTROL_OPERATION_ID_COMPOSE, pDataList, null);
728 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
732 AlbumListEditorForm::SetFooterButtonsState(bool enableState)
734 AppLogDebug("ENTER");
735 Footer* pFooter = GetFooter();
738 if (enableState == true)
740 pFooter->SetItemEnabled(0, true);
741 pFooter->SetItemEnabled(1, true);
745 pFooter->SetItemEnabled(0, false);
746 pFooter->SetItemEnabled(1, false);
749 pFooter->RequestRedraw(true);
750 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
754 AlbumListEditorForm::SetButtonState(void)
756 AppLogDebug("ENTER");
757 if (GetCheckedFolder() > 0)
759 AppLogDebug("BUTTONSTATE : Request Enable");
760 SetFooterButtonsState(true);
764 AppLogDebug("BUTTONSTATE : Request disable");
765 SetFooterButtonsState(false);
767 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));