2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (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 GlImageListEditorPanel.cpp
19 * @brief This is the implementation file for ImageListEditorPanel class.
24 #include "GlAlbumInfo.h"
25 #include "GlCommonUtil.h"
26 #include "GlFileListPresentationModel.h"
27 #include "GlGalleryApp.h"
28 #include "GlImageListEditorPanel.h"
29 #include "GlResourceManager.h"
31 #include "GlFileUpdateTimer.h"
32 #include "GlFileListEditorForm.h"
34 using namespace Tizen::App;
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Content;
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Media;
40 using namespace Tizen::Ui;
41 using namespace Tizen::Ui::Controls;
42 using namespace Tizen::Ui::Scenes;
44 static const int H_SELECTALL_REGION = 112;
45 static const int COUNT_LABEL_FONT_SIZE = 33;
46 static const unsigned int COLOR_COUNT_LABEL = Color32<68, 68, 68>::Value;
47 static const unsigned int COLOR_SELECT_COUNT_FONT = Color32<255, 255, 255>::Value;
48 static const Color COLOR_THUMBNAIL_DIM (Color::GetColor(COLOR_ID_BLACK));
49 static const float H_COUNT_LABEL = 48.0f;
50 static const int LENGTH_COUNT_LABEL = 256;
51 static const int ALPHA_THUMBNAIL_DIM = 70;
52 static const Rectangle RECT_INITIAL (0, 0, 10, 10);
54 ImageListEditorPanel::ImageListEditorPanel(void)
56 , __pContentIconListView(null)
57 , __pCheckButton(null)
58 , __pLabelSelectCnt(null)
59 , __pPresentationModel(null)
60 , __pFileListEditorForm(null)
63 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
66 ImageListEditorPanel::~ImageListEditorPanel(void)
69 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
73 ImageListEditorPanel::Initialize(void)
76 result r = Construct(RECT_INITIAL);
77 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
83 ImageListEditorPanel::OnInitializing(void)
86 const Form* pForm = dynamic_cast<Form*>(GetParent());
87 TryReturn(pForm != null, E_FAILURE, "[%s] fail to get the form.", GetErrorMessage(GetLastResult()));
89 __pPresentationModel = FileListPresentationModel::GetInstance();
90 __pPresentationModel->ClearThumbnailRequests();
91 __pPresentationModel->AddPresentationModelListener(this);
94 FloatRectangle clientAreaBounds = pForm->GetClientAreaBoundsF();
95 SetBounds(0.0f, 0.0f, clientAreaBounds.width, clientAreaBounds.height);
97 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
99 __pContentIconListView = new (std::nothrow) IconListView();
101 if (__pPresentationModel->GetAppControlSelectionMode() == APPCONTROL_SELECTION_MODE_MULTIPLE)
103 __pContentIconListView->Construct(Rectangle(0, 0, clientAreaBounds.width, clientAreaBounds.height - H_COUNT_LABEL),
104 DIMENSION_DEFAULT_THUMBNAIL, ICON_LIST_VIEW_STYLE_MARK,
105 ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
106 Bitmap* pBitmapEmpty = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
107 if (pBitmapEmpty != null)
109 __pContentIconListView->SetBitmapOfEmptyList(pBitmapEmpty);
112 __pContentIconListView->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
113 __pContentIconListView->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
114 __pContentIconListView->SetItemProvider(*this);
115 __pContentIconListView->SetCheckBoxPosition(ICON_LIST_VIEW_CHECK_BOX_POSITION_TOP_RIGHT);
116 __pContentIconListView->AddIconListViewItemEventListener(*this);
117 __pContentIconListView->SetTouchAnimationEnabled(false);
118 AddControl(__pContentIconListView);
119 __pContentIconListView->SetShowState(true);
121 __pLabelSelectCnt = new (std::nothrow) Label();
123 __pLabelSelectCnt->Construct(FloatRectangle(0, clientAreaBounds.height - H_COUNT_LABEL,
124 clientAreaBounds.width, H_COUNT_LABEL), ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED"));
125 __pLabelSelectCnt->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
126 __pLabelSelectCnt->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
127 __pLabelSelectCnt->SetBackgroundColor(COLOR_COUNT_LABEL);
128 __pLabelSelectCnt->SetTextColor(Color(COLOR_SELECT_COUNT_FONT));
129 __pLabelSelectCnt->SetTextConfig(COUNT_LABEL_FONT_SIZE, LABEL_TEXT_STYLE_BOLD);
130 AddControl(__pLabelSelectCnt);
134 __pContentIconListView->Construct(Rectangle(0, 0, clientAreaBounds.width, clientAreaBounds.height),
135 DIMENSION_DEFAULT_THUMBNAIL, ICON_LIST_VIEW_STYLE_NORMAL,
136 ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
137 Bitmap* pBitmapEmpty = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
138 if (pBitmapEmpty != null)
140 __pContentIconListView->SetBitmapOfEmptyList(pBitmapEmpty);
143 __pContentIconListView->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
144 __pContentIconListView->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
145 __pContentIconListView->SetItemProvider(*this);
146 __pContentIconListView->SetCheckBoxPosition(ICON_LIST_VIEW_CHECK_BOX_POSITION_TOP_RIGHT);
147 __pContentIconListView->AddIconListViewItemEventListener(*this);
148 __pContentIconListView->SetTouchAnimationEnabled(false);
149 AddControl(__pContentIconListView);
150 __pContentIconListView->SetShowState(true);
155 __pContentIconListView = new (std::nothrow) IconListView();
156 __pContentIconListView->Construct(Rectangle(0, H_SELECTALL_REGION, clientAreaBounds.width,
157 clientAreaBounds.height - H_SELECTALL_REGION), DIMENSION_DEFAULT_THUMBNAIL,
158 ICON_LIST_VIEW_STYLE_MARK, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
159 Bitmap* pBitmapEmpty = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
160 if (pBitmapEmpty != null)
162 __pContentIconListView->SetBitmapOfEmptyList(pBitmapEmpty);
165 __pContentIconListView->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
166 __pContentIconListView->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
167 __pContentIconListView->SetItemProvider(*this);
168 __pContentIconListView->SetCheckBoxPosition(ICON_LIST_VIEW_CHECK_BOX_POSITION_TOP_RIGHT);
169 __pContentIconListView->AddIconListViewItemEventListener(*this);
170 __pContentIconListView->SetTouchAnimationEnabled(false);
171 AddControl(__pContentIconListView);
172 __pContentIconListView->SetShowState(true);
174 __pLabelSelectCnt = new (std::nothrow) Label();
175 __pLabelSelectCnt->Construct(
176 Rectangle(0, clientAreaBounds.height - H_COUNT_LABEL, clientAreaBounds.width, H_COUNT_LABEL),
177 ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED"));
178 __pLabelSelectCnt->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
179 __pLabelSelectCnt->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
180 __pLabelSelectCnt->SetBackgroundColor(COLOR_COUNT_LABEL);
181 __pLabelSelectCnt->SetTextColor(Color(COLOR_SELECT_COUNT_FONT));
182 AddControl(__pLabelSelectCnt);
184 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
190 ImageListEditorPanel::OnTerminating(void)
192 AppLogDebug("ENTER");
193 __pPresentationModel->RemovePresentationModelListener(*this);
194 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
200 ImageListEditorPanel::GetItemCount(void)
202 AppLogDebug("ENTER");
203 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
209 ImageListEditorPanel::CreateItem(int index)
211 AppLogDebug("ENTER : index(%d)", index);
212 IconListViewItem* pIconListviewItem = new (std::nothrow) IconListViewItem();
213 Bitmap* pBitmap = null;
214 String* pItemText = null;
216 result r = __pPresentationModel->GetThumbnailInSyncCacheN(index, pItemText, pBitmap);
217 if (pBitmap == null || r == E_FAILURE)
219 __pPresentationModel->RequestThumbnail(index);
220 pBitmap = CommonUtil::GetEmptyThumbnailN();
223 if (pItemText == null)
225 pItemText = new (std::nothrow) String(ResourceManager::GetString(L"EMPTY_SPACE"));
227 else if ((*pItemText) != ResourceManager::GetString(L"EMPTY_SPACE"))
230 pItemText = new (std::nothrow) String(ResourceManager::GetString(L"EMPTY_SPACE"));
233 if (__pContentIconListView->IsItemChecked(index) == true)
237 BufferInfo bufferInfo;
238 pBitmap->Lock(bufferInfo, INFINITE);
240 Color dimColor(COLOR_THUMBNAIL_DIM);
241 dimColor.SetAlpha(ALPHA_THUMBNAIL_DIM);
244 canvas.Construct(bufferInfo);
245 canvas.FillRectangle(dimColor, canvas.GetBounds());
247 Bitmap* pSelectedBitmap = new (std::nothrow) Bitmap();
248 pSelectedBitmap->Construct(canvas, canvas.GetBounds());
249 pIconListviewItem->Construct(*pBitmap, pItemText, pSelectedBitmap);
250 delete pSelectedBitmap;
254 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
255 delete pIconListviewItem;
262 pIconListviewItem->Construct(*pBitmap, pItemText);
269 if (pItemText != null)
273 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
275 return pIconListviewItem;
279 ImageListEditorPanel::DeleteItem(int index, IconListViewItem* pItem)
281 AppLogDebug("ENTER");
283 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
289 ImageListEditorPanel::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
291 AppLogDebug("ENTER");
293 if (status == ICON_LIST_VIEW_ITEM_CHECKED || status == ICON_LIST_VIEW_ITEM_UNCHECKED)
295 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
297 if (__pPresentationModel->GetAppControlSelectionMode() == APPCONTROL_SELECTION_MODE_MULTIPLE)
299 int checkedCount = GetItemCheckedCount();
301 if (checkedCount == 0)
303 strTmp = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
305 else if (checkedCount == 1)
307 strTmp = ResourceManager::GetString(L"IDS_VR_POP_1_ITEM_SELECTED");
311 strTmp.Format(LENGTH_COUNT_LABEL,
312 ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), checkedCount);
315 __pLabelSelectCnt->SetText(strTmp);
316 __pLabelSelectCnt->RequestRedraw(true);
317 __pContentIconListView->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
322 int checkedCount = GetItemCheckedCount();
324 if (checkedCount == 0)
326 strTmp = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
328 else if (checkedCount == 1)
330 strTmp = ResourceManager::GetString(L"IDS_VR_POP_1_ITEM_SELECTED");
334 strTmp.Format(LENGTH_COUNT_LABEL,
335 ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), checkedCount);
338 __pLabelSelectCnt->SetText(strTmp);
339 __pLabelSelectCnt->RequestRedraw(true);
340 if (__pCheckButton->IsSelected())
342 __pCheckButton->SetSelected(false);
344 __pContentIconListView->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
348 if ( __pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK
349 && __pPresentationModel->GetAppControlSelectionMode() == APPCONTROL_SELECTION_MODE_SINGLE)
351 if (status == ICON_LIST_VIEW_ITEM_SELECTED)
353 HashMap* pMap = new (std::nothrow) HashMap(SingleObjectDeleter);
354 result r = pMap->Construct();
357 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
358 r = pArrayList->Construct();
362 pArrayList->Add(new (std::nothrow) String(__pPresentationModel->GetContentFilePath(index)));
363 pMap->Add(new (std::nothrow) String(APPCONTROL_KEY_DATA_SELECTED), (Object*)pArrayList);
365 GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
368 pApp->SendAppControlResult(APP_CTRL_RESULT_SUCCEEDED, pMap);
390 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
394 ImageListEditorPanel::OnFileInfoChanged(const ContentType contentType)
396 AppLogDebug("ENTER");
397 if (contentType == CONTENT_TYPE_IMAGE)
399 __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_IMAGE);
400 __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
401 __pContentIconListView->UpdateList();
403 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
407 ImageListEditorPanel::OnThumbnailDecoded(const int index)
409 AppLogDebug("ENTER : index(%d)",index);
412 __pContentIconListView->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
414 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
418 ImageListEditorPanel::OnSceneActivatedN(const SceneId& previousSceneId,
419 const SceneId& currentSceneId, IList* pArgs)
421 AppLogDebug("ENTER");
425 SceneManager* pSceneManager = SceneManager::GetInstance();
426 __pFileListEditorForm = dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
428 __pPresentationModel = FileListPresentationModel::GetInstance();
430 if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
432 if (currentSceneId == IDSCN_IMAGE_LIST_EDITOR)
434 if (previousSceneId == IDSCN_ALBUM_LIST)
436 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pArgs->GetAt(0));
437 if (pAlbumInfo == null)
439 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
444 IList* pDirectoryList = pAlbumInfo->GetDirectoryListN();
445 __pPresentationModel->SetCurrentAlbumInfo(pAlbumInfo->GetAlbumName(), *pDirectoryList);
447 if (pDirectoryList != null)
449 delete pDirectoryList;
453 __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
454 __pContentIconListView->UpdateList();
460 __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
461 __pContentIconListView->RequestRedraw(true);
463 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
467 ImageListEditorPanel::OnSceneDeactivated(const SceneId& currentSceneId,
468 const SceneId& nextSceneId)
470 AppLogDebug("ENTER");
471 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
475 ImageListEditorPanel::GetItemCheckedCount(void) const
477 AppLogDebug("ENTER");
479 if (__pContentIconListView != null)
481 int loopCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
482 for (int i = 0; i < loopCount; ++i)
484 if (__pContentIconListView->IsItemChecked(i))
490 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
496 ImageListEditorPanel::GetItemCheckedIndexListN(void) const
498 AppLogDebug("ENTER");
499 IList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
500 Integer* pIndex = null;
502 if (__pContentIconListView != null)
504 int loopCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
505 AppLogDebug("ENTER loopCount(%d)", loopCount);
506 for (int i = 0; i < loopCount; ++i)
508 if (__pContentIconListView->IsItemChecked(i))
510 pIndex = new (std::nothrow) Integer(i);
511 AppLogDebug("ENTER loopCount(%d)", loopCount);
512 AppLogDebug("ENTER loopCount(%d)", pIndex->ToInt());
517 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
522 void ImageListEditorPanel::OnFileOpInvalidate(enum FileActionMode actionId)
524 SceneManager* pSceneManager = SceneManager::GetInstance();
525 FileListEditorForm* pFileListEditorForm =
526 dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
527 TryReturnVoid(pFileListEditorForm != null, "[%s] fail to get SceneManager.",
528 GetErrorMessage(GetLastResult()));
529 pFileListEditorForm->Invalidate(true);
532 void ImageListEditorPanel::OnFileOpComplete(enum FileActionMode actionId, enum FileActionCompleteRes res)
537 ImageListEditorPanel::OnRequestAppExitWithMultipleSelectionAppControlResult(void)
539 AppLogDebug("ENTER");
540 IList* pIndexList = GetItemCheckedIndexListN();
542 if (pIndexList->GetCount() <= 0)
545 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
549 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
550 pArrayList->Construct();
551 int loopCount = pIndexList->GetCount();
552 Integer* pTemp = null;
553 for (int i = 0; i < loopCount; ++i)
555 pTemp = static_cast<Integer*>(pIndexList->GetAt(i));
556 pArrayList->Add(new (std::nothrow) String(__pPresentationModel->GetContentFilePath(pTemp->ToInt())));
559 HashMap* pMap = new (std::nothrow) HashMap(SingleObjectDeleter);
561 pMap->Add(new (std::nothrow) String(APPCONTROL_KEY_DATA_SELECTED), pArrayList);
563 GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
566 pApp->SendAppControlResult(APP_CTRL_RESULT_SUCCEEDED, pMap);
571 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
575 ImageListEditorPanel::OnSelectAllPressed(void)
577 bool needToSelectAll = true;
578 int checkedCount = GetItemCheckedCount();
579 int totalFileCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
580 if (checkedCount == totalFileCount)
582 needToSelectAll = false;
585 if (needToSelectAll == true)
587 for (int i = 0; i < totalFileCount; ++i)
589 if (__pContentIconListView->IsItemChecked(i) == false)
591 __pContentIconListView->SetItemChecked(i, true);
592 __pContentIconListView->RefreshList(i, LIST_REFRESH_TYPE_ITEM_MODIFY);
594 __pFileListEditorForm->SetFooterButtonsState(true);
599 for (int i = 0; i < totalFileCount; ++i)
601 if (__pContentIconListView->IsItemChecked(i) == true)
603 __pContentIconListView->SetItemChecked(i, false);
604 __pContentIconListView->RefreshList(i, LIST_REFRESH_TYPE_ITEM_MODIFY);
606 __pFileListEditorForm->SetFooterButtonsState(false);
611 if (needToSelectAll == true)
613 tempString.Format(LENGTH_COUNT_LABEL,
614 ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), totalFileCount);
618 tempString = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
621 __pLabelSelectCnt->SetText(tempString);
622 __pLabelSelectCnt->RequestRedraw(true);
626 ImageListEditorPanel::SetButtonState(void)
628 AppLogDebug("ENTER");
629 SceneManager* pSceneManager = SceneManager::GetInstance();
630 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
632 if (GetItemCheckedCount() > 0)
634 AppLogDebug("BUTTONSTATE : Request Enable");
635 __pFileListEditorForm->SetFooterButtonsState(true);
639 AppLogDebug("BUTTONSTATE : Request disable");
640 __pFileListEditorForm->SetFooterButtonsState(false);
642 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
646 ImageListEditorPanel::ChangeOrientation(void)
648 AppLogDebug("ENTER");
649 SceneManager* pSceneManager = SceneManager::GetInstance();
650 const Form* pForm = dynamic_cast<Form*>(pSceneManager->GetCurrentScene()->GetForm());
651 TryReturn(pForm != null,, "[%s] fail to get the form.", GetErrorMessage(GetLastResult()));
653 FloatRectangle clientAreaBounds = pForm->GetClientAreaBoundsF();
654 SetBounds(0.0f, 0.0f, clientAreaBounds.width, clientAreaBounds.height);
655 if (__pLabelSelectCnt != NULL)
657 __pLabelSelectCnt->SetBounds(0.0f, clientAreaBounds.height - H_COUNT_LABEL, clientAreaBounds.width, H_COUNT_LABEL);
659 __pContentIconListView->SetBounds(0.0f, 0.0f, clientAreaBounds.width, clientAreaBounds.height -H_COUNT_LABEL);