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: MfBaseItemProvider.cpp
19 * @brief: This file contains implementation of BaseItemProvider class, which acts as a common item provider for all
23 #include "MfBaseItemProvider.h"
25 using namespace Tizen::App;
26 using namespace Tizen::Base;
27 using namespace Tizen::Base::Collection;
28 using namespace Tizen::Content;
29 using namespace Tizen::Graphics;
30 using namespace Tizen::Io;
31 using namespace Tizen::Locales;
32 using namespace Tizen::Ui;
33 using namespace Tizen::Ui::Controls;
34 using namespace Tizen::Base::Utility;
36 BaseItemProvider::BaseItemProvider(void)
37 : __pFolderEntryPM(null)
38 , __pThumbnailManager(null)
40 , __pListViewItemStateChangeListener(null)
43 , __pFolderBitmap(null)
44 , __pSecondaryBitmap(null)
45 , __pSecondaryBitmapPressed(null)
46 , __pItemContext(null)
48 //empty implementation
49 __flagViewAsStatus = 0;
50 __sourceInfo = CREATE_ITEM_SOURCE_NONE;
54 BaseItemProvider::Construct(void)
56 // int currentStorageType = MEMORY_TYPE_PHONE;
58 String detailButtonText;
59 String deleteButtonText;
60 String renameButtonText;
62 Bitmap* pDeleteNormalBmp = null;
63 Bitmap* pDeletePressBmp = null;
65 AppResource* pAppResource = null;
68 pAppResource = Application::GetInstance()->GetAppResource();
69 TryCatch(pAppResource != null, , "MfMyFilesApp::Resource manager not found!");
71 pAppResource->GetString(L"IDS_COM_BODY_SELECT_ALL", __selectAll);
72 pAppResource->GetString(L"IDS_MF_SK_DETAILS", detailButtonText);
73 pAppResource->GetString(L"IDS_MF_BODY_RENAME_ABB", renameButtonText);
74 pAppResource->GetString(L"IDS_MF_SK3_DELETE", deleteButtonText);
75 pAppResource->GetString(L"IDS_MF_OPT_SHOW_FILE_EXTENSION", __showExtension);
76 pAppResource->GetString(L"IDS_MF_OPT_HIDE_FILE_EXTENSION_ABB", __hideExtension);
77 __extensionKeyName = fileExtenstionKeyName;
79 pDeleteNormalBmp = MfUtility::GetNinepatchedBitmapN(IDB_CONTEXT_DELETE_NORMAL, 150, 72);
80 pDeletePressBmp = MfUtility::GetNinepatchedBitmapN(IDB_CONTEXT_DELETE_PRESS, 150, 72);
82 __pDummyImage = pAppResource->GetBitmapN(IDB_DUMMY_IMG, BITMAP_PIXEL_FORMAT_ARGB8888);
84 __pThumbnailManager = ThumbnailManager::GetInstance();
85 TryCatch(__pThumbnailManager != null, , "Failed to fetch instance of ThumbnailManager");
87 __pItemContext = new (std::nothrow) ListContextItem();
89 r = __pItemContext->Construct();
90 TryCatch(r == E_SUCCESS, , "Failed to construct pitemcontext");
92 __pItemContext->AddElement(IDA_CONTEXT_RENAME, renameButtonText);
93 __pItemContext->AddElement(IDA_CONTEXT_DETAIL, detailButtonText);
95 if (pDeleteNormalBmp != null && pDeletePressBmp != null)
97 __pItemContext->AddElement(IDA_CONTEXT_DELETE,
104 delete pDeleteNormalBmp;
105 pDeleteNormalBmp = null;
107 delete pDeletePressBmp;
108 pDeletePressBmp = null;
115 if (__pItemContext != null)
117 delete __pItemContext;
118 __pItemContext = null;
121 if (pDeleteNormalBmp != null)
123 delete pDeleteNormalBmp;
124 pDeleteNormalBmp = null;
127 if (pDeletePressBmp != null)
129 delete pDeletePressBmp;
130 pDeletePressBmp = null;
133 if (__pFolderBitmap != null)
135 delete __pFolderBitmap;
138 if (__pDummyImage != null)
140 delete __pDummyImage;
144 BaseItemProvider::~BaseItemProvider(void)
146 if (__pSecondaryBitmap != null)
148 delete __pSecondaryBitmap;
151 if (__pSecondaryBitmapPressed != null)
153 delete __pSecondaryBitmapPressed;
156 if (__pFolderBitmap != null)
158 delete __pFolderBitmap;
161 if (__pDummyImage != null)
163 delete __pDummyImage;
166 if (__pItemContext != null)
168 delete __pItemContext;
173 BaseItemProvider::operator =(const BaseItemProvider& baseItemProvider)
178 BaseItemProvider::BaseItemProvider(const BaseItemProvider& baseItemProvider)
184 BaseItemProvider::GetItemCount(void)
186 AppLogDebug("Enter");
188 result r = E_SUCCESS;
189 String viewStyleKeyName(L"ListDisplayType");
190 int listViewDisplayType = VIEW_TYPE_AS_NORMAL_LIST;
191 AppRegistry* pAppRegistry = null;
195 pAppRegistry = UiApp::App::GetInstance()->GetAppRegistry();
197 if (__sourceInfo != CREATE_ITEM_SOURCE_SPLIT_PANEL_DIR_TREE)
199 r = pAppRegistry->Get(viewStyleKeyName, listViewDisplayType);
201 __flagViewAsStatus = listViewDisplayType;
203 __pFileNames = __pFolderEntryPM->GetFolderEntryList();
205 if (__pFileNames != null)
207 itemCount = __pFileNames->GetCount();
214 if (__sourceInfo == CREATE_ITEM_SOURCE_TOP_MOST_FILE_LIST || __sourceInfo == CREATE_ITEM_SOURCE_SUB_FOLDER_FILE_LIST)
216 if (__pFileNames != null)
218 if (__pFileNames->GetCount() == 0)
220 __pListViewItemStateChangeListener->OnFooterStateChangeNotify();
225 if (__sourceInfo == CREATE_ITEM_SOURCE_SHARE_FORM)
227 __pFolderEntryPM->GetFolderEntryCount(FolderNavigationPresentationModel::GetCurrentPath(), dirCount, fileCount);
228 itemCount = fileCount;
235 Tizen::Ui::Controls::ListItemBase*
236 BaseItemProvider::CreateItem(int index, int itemWidth)
238 AppLogDebug("ENTER");
240 ContentListItem* pMyCustomItem = null;
242 //Else switch the flag status in order to Update the list accordingly.
243 switch (__flagViewAsStatus)
245 case VIEW_TYPE_AS_NORMAL_LIST:
247 pMyCustomItem = CreateNormalListViewItem(index, itemWidth);
248 TryCatch(pMyCustomItem != null, , "CustomItem is Null");
249 return pMyCustomItem;
253 case VIEW_TYPE_AS_DETAILED_LIST:
255 if (__sourceInfo == CREATE_ITEM_SOURCE_FILE_MANAGE_FORM || __sourceInfo == CREATE_ITEM_SOURCE_SPLIT_PANEL_FILE_MANAGE_FORM
256 || __sourceInfo == CREATE_ITEM_SOURCE_SHARE_FORM)
258 pMyCustomItem = CreateNormalListViewItem(index, itemWidth);
262 pMyCustomItem = CreateDetailedListViewItem(index, itemWidth);
263 TryCatch(pMyCustomItem != null, , "CustomItem is Null");
265 return pMyCustomItem;
282 BaseItemProvider::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
284 AppLogDebug("Enter");
294 BaseItemProvider::CreateNormalListViewItem(int listItemIndex, int listItemWidth)
296 AppLogDebug("ENTER");
297 result r = E_SUCCESS;
304 int tempIndex = null;
307 String folderIconPath;
308 String imageIconPath;
311 String fileExtension;
313 String searchedString;
316 String cacheImagePath;
318 AnnexStyle annexStyle = ANNEX_STYLE_NORMAL;
319 HashMap* pCacheList = null;
320 Bitmap* pFetchedCacheImage = null;
321 Bitmap* pThumbnailImage = null;
323 DateTime dateCreated;
324 Dimension thumbnailDimension(H_LISTVIEW_ITEM_BITMAP, W_LISTVIEW_ITEM_BITMAP);
325 Dimension textDimension(listItemWidth - W_LISTVIEW_ITEM_BITMAP, H_ITEM_LISTVIEW);
327 DirectoryEntry* pFileDetails = null;
329 ContentListItem* pCustomItem = null;
330 ContentType contentType = CONTENT_TYPE_UNKNOWN;
332 AppRegistry* pAppRegistry = null;
333 pAppRegistry = UiApp::App::GetInstance()->GetAppRegistry();
335 __pFolderEntryPM->GetFolderEntryCount(FolderNavigationPresentationModel::GetCurrentPath(), dirCount, fileCount);
337 TryCatch(__pFileNames != null, , "MfMyFilesApp::Filename list if empty!");
338 TryCatch(__pFileNames->GetCount() != 0, , "MfMyFilesApp::Filename count is Zero!");
340 pCustomItem = new (std::nothrow) ContentListItem(listItemWidth, H_ITEM_LISTVIEW);
341 TryCatch(pCustomItem != null, , "MfMyFilesApp::Failed to allocate Memory to pCustomItem");
344 if (__sourceInfo == CREATE_ITEM_SOURCE_SHARE_FORM)
346 tempIndex = dirCount + listItemIndex;
347 listItemIndex = tempIndex;
350 //Get the Directory Entry for the element at index from the Filenames list.
352 pFileDetails = static_cast< DirectoryEntry* >(__pFileNames->GetAt(listItemIndex));
353 TryCatch(pFileDetails != null, , "MfMyFilesApp::Failed to fetch FileDetails from __pFileNames!");
355 r = pAppRegistry->Get(__extensionKeyName, fileExtension);
357 pCacheList = CacheManager::GetInstance()->GetCacheHashMap();
359 //Set the filename of the element at index index
360 filename = pFileDetails->GetFileName();
361 fullFilePath = pFileDetails->GetFullFilePath();
363 //If the registry key value is set for show extension append the extension of the filename else do not.
364 if (fileExtension == __showExtension && !pFileDetails->IsDirectory())
366 if (!pFileDetails->GetFileExtension().IsEmpty())
368 filename = filename + "." + pFileDetails->GetFileExtension();
372 if (pFileDetails->IsDirectory())
374 if (__sourceInfo != CREATE_ITEM_SOURCE_SHARE_FORM)
376 pCustomItem->SetThumbnail(__pFolderBitmap);
381 if (__sourceInfo == CREATE_ITEM_SOURCE_SUB_BASE_MOVE_COPY)
383 pCustomItem->SetDescColor(Color::GetColor(COLOR_ID_GREY));
386 contentType = ContentManagerUtil::CheckContentType(fullFilePath);
388 if (pFileDetails->GetBitmap() == null && pFileDetails->IstDummy())
390 if (pCacheList != null && (contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO))
392 if (pFileDetails != null)
394 cacheImagePath = pFileDetails->GetFullFilePath();
395 AppLogDebug("cache path is %S",cacheImagePath.GetPointer());
398 if ((pCacheList->GetValue(cacheImagePath)) != null)
400 pFetchedCacheImage = static_cast< Bitmap* >(pCacheList->GetValue(cacheImagePath));
404 if (pFetchedCacheImage != null)
406 AppLogDebug("image taken from cachemanager");
407 pThumbnailImage = CacheManager::GetInstance()->GetCacheBitmapN(cacheImagePath);
408 pCustomItem->SetThumbnail(pThumbnailImage);
412 pFileDetails->SetDummy(true);
413 pCustomItem->SetThumbnail(__pDummyImage);
414 AppLogDebug("call to thumbnail manager");
419 AppLogDebug("BITMAP FOUND : NOT NEED TO DO GETTHUMBNAIL");
420 pCustomItem->SetThumbnail(pFileDetails->GetBitmap());
425 if (__sourceInfo == CREATE_ITEM_SOURCE_FILE_MANAGE_FORM || __sourceInfo == CREATE_ITEM_SOURCE_SPLIT_PANEL_FILE_MANAGE_FORM)
427 imageIconPath = pFileDetails->GetFullFilePath();
428 dateCreated = GetFileCreationTime(imageIconPath);
429 creationDate = MfUtility::ConvertDateTimeToString(dateCreated);
431 pCustomItem->SetTitle(filename, searchedString);
433 pCustomItem->SetRenameBitmap(__pSecondaryBitmap, __pSecondaryBitmapPressed);
434 pCustomItem->MakeFileManageFormListItem();
436 else if(__sourceInfo == CREATE_ITEM_SOURCE_CATEGORY_SEARCH_FORM)
438 annexStyle = ANNEX_STYLE_DETAILED;
440 pCustomItem->SetTitle(filename, searchedText);
441 GetParentFolderPath(&fullFilePath);
442 pCustomItem->SetFilepath(fullFilePath);
443 pCustomItem->SetListAnnexStyle(annexStyle);
444 pCustomItem->MakeSearchFormListItem();
445 if (__pItemContext != null)
447 pCustomItem->SetContextItem(__pItemContext);
450 else if(__sourceInfo == CREATE_ITEM_SOURCE_SHARE_FORM)
452 annexStyle = ANNEX_STYLE_MARK;
453 pCustomItem->SetListAnnexStyle(annexStyle);
455 pCustomItem->SetTitle(filename, searchedText);
456 pCustomItem->MakeAppControlFormListItem();
460 //Call the SetTitle function to set the title of the list item.
461 pCustomItem->SetTitle(filename, searchedText);
462 //Call the Make Function which adds the elements to the custom Item.
463 if (__sourceInfo == CREATE_ITEM_SOURCE_SPLIT_PANEL_DIR_TREE)
465 pCustomItem->Make(pFileDetails->GetDirectoryDepth());
471 //Set the context item of the list itemm.
472 if (__sourceInfo != CREATE_ITEM_SOURCE_SUB_FOLDER_MOVE_COPY && __sourceInfo != CREATE_ITEM_SOURCE_TOP_MOST_MOVE_COPY
473 && __sourceInfo != CREATE_ITEM_SOURCE_SUB_BASE_MOVE_COPY && __sourceInfo != CREATE_ITEM_SOURCE_SPLIT_PANEL_DIR_TREE)
476 if (__pItemContext != null)
478 pCustomItem->SetContextItem(__pItemContext);
481 AppLogDebug("EXIT: r = %s", GetErrorMessage(GetLastResult()));
486 if (pCustomItem != null)
495 BaseItemProvider::CreateDetailedListViewItem(int listItemIndex, int listItemWidth)
498 AppLogDebug("ENTER");
499 result r = E_SUCCESS;
505 String imageIconPath;
508 String fileExtension;
510 String descriptionText;
512 String itemCountDisplay;
513 String searchedString;
514 String cacheImagePath;
516 DateTime dateCreated;
518 Dimension thumbnailDimension(W_LISTVIEW_ITEM_BITMAP, H_LISTVIEW_ITEM_BITMAP);
519 Dimension textDimension((listItemWidth - W_LISTVIEW_ITEM_BITMAP) / 2, H_DETAIL_LISTVIEW);
521 DirectoryEntry* pFileDetails = null;
522 ContentListItem* pContentListItem = null;
524 Bitmap* pFetchedCacheImage = null;
525 Bitmap* pThumbnailImage = null;
526 HashMap* pCacheList = null;
527 ContentType contentType = CONTENT_TYPE_UNKNOWN;
529 AppResource* pAppResource = null;
530 AppRegistry* pAppRegistry = null;
531 pAppRegistry = UiApp::App::GetInstance()->GetAppRegistry();
535 long long int fileSize;
537 TryCatch(__pFileNames != null, , "Filename list if empty!");
538 TryCatch(__pFileNames->GetCount() != 0, , "Filename count is Zero!");
540 pAppResource = Application::GetInstance()->GetAppResource();
541 TryCatch(pAppResource != null, , "Resource manager not found!");
543 pAppResource->GetString(L"IDS_ITEM_COUNT", itemCountDisplay);
545 //Get the entry at index from the Filenames ArrayList.
546 pFileDetails = static_cast< DirectoryEntry* >(__pFileNames->GetAt(listItemIndex));
547 TryCatch(pFileDetails != null, , "MfMyFilesApp::Failed to fetch FileDetails from __pFilenames!");
549 //Create a new ContentListItem.
550 pContentListItem = new (std::nothrow) ContentListItem(listItemWidth, H_DETAIL_LISTVIEW);
551 TryCatch(pContentListItem != null, , "Failed to allocate Memory to pCustomItem");
553 //Get the key value for the file extension visibility.
554 r = pAppRegistry->Get(__extensionKeyName, fileExtension);
555 pCacheList = CacheManager::GetInstance()->GetCacheHashMap();
557 //Assign the filename to the one retrieved from __fileNames.
558 filename = pFileDetails->GetFileName();
559 if (fileExtension == __showExtension && !pFileDetails->IsDirectory())
561 if (!pFileDetails->GetFileExtension().IsEmpty())
563 filename = filename + "." + pFileDetails->GetFileExtension();
567 if (pFileDetails->IsDirectory())
569 folderPath = pFileDetails->GetFullFilePath();
571 pContentListItem->SetThumbnail(__pFolderBitmap);
573 dateCreated = GetFileCreationTime(folderPath);
574 creationDate = MfUtility::ConvertDateTimeToString(dateCreated);
576 filesCount = pFileDetails->GetFilecount() + pFileDetails->GetDirectoryCount();
577 descriptionText.Append(filesCount);
578 descriptionText.Append(itemCountDisplay);
582 imageIconPath = pFileDetails->GetFullFilePath();
583 if (__sourceInfo == CREATE_ITEM_SOURCE_SUB_BASE_MOVE_COPY)
585 pContentListItem->SetDescColor(Color::GetColor(COLOR_ID_GREY));
588 contentType = ContentManagerUtil::CheckContentType(imageIconPath);
590 if (pFileDetails->GetBitmap() == null && pFileDetails->IstDummy())
592 if (pCacheList != null && (contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO))
594 if (pFileDetails != null)
596 cacheImagePath = pFileDetails->GetFullFilePath();
597 AppLogDebug("cache path is %S",cacheImagePath.GetPointer());
600 if ((pCacheList->GetValue(cacheImagePath)) != null)
602 pFetchedCacheImage = static_cast< Bitmap* >(pCacheList->GetValue(cacheImagePath));
606 if (pFetchedCacheImage != null)
608 pThumbnailImage = CacheManager::GetInstance()->GetCacheBitmapN(cacheImagePath);
609 pContentListItem->SetThumbnail(pThumbnailImage);
613 pFileDetails->SetDummy(true);
614 pContentListItem->SetThumbnail(__pDummyImage);
619 pContentListItem->SetThumbnail(pFileDetails->GetBitmap());
622 fileSize = GetFileSize(imageIconPath);
623 dateCreated = GetFileCreationTime(imageIconPath);
624 creationDate = MfUtility::ConvertDateTimeToString(dateCreated);
625 descriptionText = MfUtility::ConvertFileSizeToString(fileSize);
628 pContentListItem->SetTitle(filename, searchedText);
629 pContentListItem->SetDescription(descriptionText);
630 pContentListItem->SetDate(creationDate);
632 if (__sourceInfo == CREATE_ITEM_SOURCE_CATEGORY_SEARCH_FORM)
634 pContentListItem->SetRenameBitmap(__pSecondaryBitmap, __pSecondaryBitmapPressed);
637 pContentListItem->MakeDetailedListItem();
639 if (__sourceInfo != CREATE_ITEM_SOURCE_SUB_FOLDER_MOVE_COPY && __sourceInfo != CREATE_ITEM_SOURCE_TOP_MOST_MOVE_COPY
640 && __sourceInfo != CREATE_ITEM_SOURCE_SUB_BASE_MOVE_COPY && __sourceInfo != CREATE_ITEM_SOURCE_SPLIT_PANEL_DIR_TREE)
642 if (__pItemContext != null)
644 pContentListItem->SetContextItem(__pItemContext);
648 AppLogDebug("EXIT: r = %s", GetErrorMessage(GetLastResult()));
650 return pContentListItem;
657 BaseItemProvider::SetSourceForm(CreateItemSource sourceInfo)
659 AppLogDebug("Enter");
661 __sourceInfo = sourceInfo;
662 int currentStorageType = MEMORY_TYPE_PHONE;
663 AppResource* pAppResource = null;
665 pAppResource = Application::GetInstance()->GetAppResource();
666 TryCatch(pAppResource != null, , "MfMyFilesApp::Resource manager not found!");
668 currentStorageType = FolderNavigationPresentationModel::GetStorageType();
670 switch (currentStorageType)
672 case MEMORY_TYPE_PHONE:
674 __pFolderBitmap = pAppResource->GetBitmapN(IDB_FOLDER, BITMAP_PIXEL_FORMAT_ARGB8888);
678 case MEMORY_TYPE_SD_CARD:
680 __pFolderBitmap = pAppResource->GetBitmapN(IDB_SDCARD_ICON, BITMAP_PIXEL_FORMAT_ARGB8888);
685 case MEMORY_TYPE_EXTERNAL:
687 __pFolderBitmap = pAppResource->GetBitmapN(IDB_EXTERNAL_ICON, BITMAP_PIXEL_FORMAT_ARGB8888);
694 if (__sourceInfo == CREATE_ITEM_SOURCE_FILE_MANAGE_FORM || __sourceInfo == CREATE_ITEM_SOURCE_SPLIT_PANEL_FILE_MANAGE_FORM)
696 if (__pSecondaryBitmap == null)
698 __pSecondaryBitmap = MfUtility::MergeBitmapN(IDB_RENAME_OUTER_CIRCLE, IDB_RENAME, W_RENAME_ICON, W_RENAME_ICON);
700 if (__pSecondaryBitmapPressed == null)
702 __pSecondaryBitmapPressed = MfUtility::MergeBitmapN(IDB_RENAME_PRESSED_CIRCLE, IDB_RENAME, W_RENAME_ICON, W_RENAME_ICON);
712 BaseItemProvider::SetFolderEntryProvider(IFolderEntryProviderListener* pProvider)
714 __pProviderPM = pProvider;
715 __pFolderEntryPM = __pProviderPM->GetFolderEntryPresentationModel();
719 BaseItemProvider::SetFooterItemStateChangeListener(IListViewStateChangeListener* listener)
721 result r = E_SUCCESS;
722 __pListViewItemStateChangeListener = listener;
728 BaseItemProvider::GetParentFolderPath(Tizen::Base::String* filePath)
734 StringTokenizer tokenizer(*filePath, delim);
738 //Use a string tokenizer to get the filepath until it's the last token, break the loop when
739 //it is the last token
740 while (tokenizer.HasMoreTokens())
742 if (tokenizer.GetTokenCount() != 1)
744 filePath->Append(L"/");
745 tokenizer.GetNextToken(token);
746 filePath->Append(token);
754 filePath->Append(L"/");
756 if (filePath->StartsWith(BasePresentationModel::GetMediaPath(),0))
758 filePath->Replace(BasePresentationModel::GetMediaPath(),"Phone/",0);
760 else if(filePath->StartsWith(BasePresentationModel::GetSdCardPath(),0))
762 filePath->Replace(BasePresentationModel::GetSdCardPath(),"Memory Card/",0);
766 Tizen::Base::DateTime
767 BaseItemProvider::GetFileCreationTime(String filePath)
769 AppLogDebug("Entry");
771 DateTime fileCreationTime;
772 FileAttributes fileAttrib;
774 File::GetAttributes(filePath, fileAttrib);
775 fileCreationTime = fileAttrib.GetDateTime();
777 return fileCreationTime;
781 BaseItemProvider::GetFileSize(String filePath)
783 AppLogDebug("Entry");
785 long long int fileSize = 0;
786 FileAttributes fileAttrib;
788 File::GetAttributes(filePath, fileAttrib);
789 fileSize = fileAttrib.GetFileSize();