NABI_SE issues, inernal GUI changes, Prevent issue fixes
[apps/osp/MyFiles.git] / src / MfBaseItemProvider.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: MfBaseItemProvider.cpp
19  * @brief: This file contains implementation of BaseItemProvider class, which acts as a common item provider for all
20  * ListViews.
21  */
22
23 #include "MfBaseItemProvider.h"
24
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;
35
36 BaseItemProvider::BaseItemProvider(void)
37 : __pFolderEntryPM(null)
38 , __pThumbnailManager(null)
39 , __pProviderPM(null)
40 , __pListViewItemStateChangeListener(null)
41 , __pFileNames(null)
42 , __pDummyImage(null)
43 , __pFolderBitmap(null)
44 , __pSecondaryBitmap(null)
45 , __pSecondaryBitmapPressed(null)
46 , __pItemContext(null)
47 {
48         //empty implementation
49         __flagViewAsStatus = 0;
50         __sourceInfo = CREATE_ITEM_SOURCE_NONE;
51 }
52
53 void
54 BaseItemProvider::Construct(void)
55 {
56 //      int currentStorageType = MEMORY_TYPE_PHONE;
57
58         String detailButtonText;
59         String deleteButtonText;
60         String renameButtonText;
61
62         Bitmap* pDeleteNormalBmp = null;
63         Bitmap* pDeletePressBmp = null;
64
65         AppResource* pAppResource = null;
66         result r = E_SUCCESS;
67
68         pAppResource = Application::GetInstance()->GetAppResource();
69         TryCatch(pAppResource != null, , "MfMyFilesApp::Resource manager not found!");
70
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;
78
79         pDeleteNormalBmp = MfUtility::GetNinepatchedBitmapN(IDB_CONTEXT_DELETE_NORMAL, 150, 72);
80         pDeletePressBmp = MfUtility::GetNinepatchedBitmapN(IDB_CONTEXT_DELETE_PRESS, 150, 72);
81
82         __pDummyImage = pAppResource->GetBitmapN(IDB_DUMMY_IMG, BITMAP_PIXEL_FORMAT_ARGB8888);
83
84         __pThumbnailManager = ThumbnailManager::GetInstance();
85         TryCatch(__pThumbnailManager != null, , "Failed to fetch instance of ThumbnailManager");
86
87         __pItemContext = new (std::nothrow) ListContextItem();
88
89         r = __pItemContext->Construct();
90         TryCatch(r == E_SUCCESS, , "Failed to construct pitemcontext");
91
92         __pItemContext->AddElement(IDA_CONTEXT_RENAME, renameButtonText);
93         __pItemContext->AddElement(IDA_CONTEXT_DETAIL, detailButtonText);
94
95         if (pDeleteNormalBmp != null && pDeletePressBmp != null)
96         {
97                 __pItemContext->AddElement(IDA_CONTEXT_DELETE,
98                                 deleteButtonText,
99                                 *pDeleteNormalBmp,
100                                 *pDeletePressBmp,
101                                 null,
102                                 true);
103
104                 delete pDeleteNormalBmp;
105                 pDeleteNormalBmp = null;
106
107                 delete pDeletePressBmp;
108                 pDeletePressBmp = null;
109
110         }
111
112         return;
113
114 CATCH:
115         if (__pItemContext != null)
116         {
117                 delete __pItemContext;
118                 __pItemContext = null;
119         }
120
121         if (pDeleteNormalBmp != null)
122         {
123                 delete pDeleteNormalBmp;
124                 pDeleteNormalBmp = null;
125         }
126
127         if (pDeletePressBmp != null)
128         {
129                 delete pDeletePressBmp;
130                 pDeletePressBmp = null;
131         }
132
133         if (__pFolderBitmap != null)
134         {
135                 delete __pFolderBitmap;
136         }
137
138         if (__pDummyImage != null)
139         {
140                 delete __pDummyImage;
141         }
142 }
143
144 BaseItemProvider::~BaseItemProvider(void)
145 {
146         if (__pSecondaryBitmap != null)
147         {
148                 delete __pSecondaryBitmap;
149         }
150
151         if (__pSecondaryBitmapPressed != null)
152         {
153                 delete __pSecondaryBitmapPressed;
154         }
155
156         if (__pFolderBitmap != null)
157         {
158                 delete __pFolderBitmap;
159         }
160
161         if (__pDummyImage != null)
162         {
163                 delete __pDummyImage;
164         }
165
166         if (__pItemContext != null)
167         {
168                 delete __pItemContext;
169         }
170 }
171
172 BaseItemProvider&
173 BaseItemProvider::operator =(const BaseItemProvider& baseItemProvider)
174 {
175         return *this;
176 }
177
178 BaseItemProvider::BaseItemProvider(const BaseItemProvider& baseItemProvider)
179 {
180         //Do Nothing
181 }
182
183 int
184 BaseItemProvider::GetItemCount(void)
185 {
186         AppLogDebug("Enter");
187         int itemCount = 0;
188         result r = E_SUCCESS;
189         String viewStyleKeyName(L"ListDisplayType");
190         int listViewDisplayType = VIEW_TYPE_AS_NORMAL_LIST;
191         AppRegistry* pAppRegistry = null;
192         int dirCount = 0;
193         int fileCount = 0;
194
195         pAppRegistry = UiApp::App::GetInstance()->GetAppRegistry();
196
197         if (__sourceInfo != CREATE_ITEM_SOURCE_SPLIT_PANEL_DIR_TREE)
198         {
199                 r = pAppRegistry->Get(viewStyleKeyName, listViewDisplayType);
200         }
201         __flagViewAsStatus = listViewDisplayType;
202
203         __pFileNames = __pFolderEntryPM->GetFolderEntryList();
204
205         if (__pFileNames != null)
206         {
207                 itemCount = __pFileNames->GetCount();
208         }
209         else
210         {
211                 itemCount = 0;
212         }
213
214         if (__sourceInfo == CREATE_ITEM_SOURCE_TOP_MOST_FILE_LIST || __sourceInfo == CREATE_ITEM_SOURCE_SUB_FOLDER_FILE_LIST)
215         {
216                 if (__pFileNames != null)
217                 {
218                         if (__pFileNames->GetCount() == 0)
219                         {
220                                 __pListViewItemStateChangeListener->OnFooterStateChangeNotify();
221                         }
222                 }
223         }
224
225         if (__sourceInfo == CREATE_ITEM_SOURCE_SHARE_FORM)
226         {
227                 __pFolderEntryPM->GetFolderEntryCount(FolderNavigationPresentationModel::GetCurrentPath(), dirCount, fileCount);
228                 itemCount = fileCount;
229         }
230         AppLogDebug("Exit");
231         return itemCount;
232
233 }
234
235 Tizen::Ui::Controls::ListItemBase*
236 BaseItemProvider::CreateItem(int index, int itemWidth)
237 {
238         AppLogDebug("ENTER");
239
240         ContentListItem* pMyCustomItem = null;
241
242         //Else switch the flag status in order to Update the list accordingly.
243         switch (__flagViewAsStatus)
244         {
245         case VIEW_TYPE_AS_NORMAL_LIST:
246         {
247                 pMyCustomItem = CreateNormalListViewItem(index, itemWidth);
248                 TryCatch(pMyCustomItem != null, , "CustomItem is Null");
249                 return pMyCustomItem;
250         }
251         break;
252
253         case VIEW_TYPE_AS_DETAILED_LIST:
254         {
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)
257                 {
258                         pMyCustomItem = CreateNormalListViewItem(index, itemWidth);
259                 }
260                 else
261                 {
262                         pMyCustomItem = CreateDetailedListViewItem(index, itemWidth);
263                         TryCatch(pMyCustomItem != null, , "CustomItem is Null");
264                 }
265                 return pMyCustomItem;
266         }
267         break;
268
269         default:
270         {
271                 return null;
272                 //Do Nothing.
273         }
274         break;
275         }
276
277 CATCH:
278         return null;
279 }
280
281 bool
282 BaseItemProvider::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
283 {
284         AppLogDebug("Enter");
285         if (pItem != null)
286         {
287                 delete pItem;
288                 pItem = null;
289         }
290         return true;
291 }
292
293 ContentListItem*
294 BaseItemProvider::CreateNormalListViewItem(int listItemIndex, int listItemWidth)
295 {
296         AppLogDebug("ENTER");
297         result r = E_SUCCESS;
298
299         Font font;
300
301         int dirCount = 0;
302         int fileCount = 0;
303
304         int tempIndex = null;
305
306         String filename;
307         String folderIconPath;
308         String imageIconPath;
309         String fontName;
310         String searchedText;
311         String fileExtension;
312         String creationDate;
313         String searchedString;
314         String selectAll;
315         String fullFilePath;
316         String cacheImagePath;
317
318         AnnexStyle annexStyle = ANNEX_STYLE_NORMAL;
319         HashMap* pCacheList = null;
320         Bitmap* pFetchedCacheImage = null;
321         Bitmap* pThumbnailImage = null;
322
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);
326
327         DirectoryEntry* pFileDetails = null;
328
329         ContentListItem* pCustomItem = null;
330         ContentType contentType = CONTENT_TYPE_UNKNOWN;
331
332         AppRegistry* pAppRegistry = null;
333         pAppRegistry = UiApp::App::GetInstance()->GetAppRegistry();
334
335         __pFolderEntryPM->GetFolderEntryCount(FolderNavigationPresentationModel::GetCurrentPath(), dirCount, fileCount);
336
337         TryCatch(__pFileNames != null, , "MfMyFilesApp::Filename list if empty!");
338         TryCatch(__pFileNames->GetCount() != 0, , "MfMyFilesApp::Filename count is Zero!");
339
340         pCustomItem = new (std::nothrow) ContentListItem(listItemWidth, H_ITEM_LISTVIEW);
341         TryCatch(pCustomItem != null, , "MfMyFilesApp::Failed to allocate Memory to pCustomItem");
342
343
344         if (__sourceInfo == CREATE_ITEM_SOURCE_SHARE_FORM)
345         {
346                 tempIndex = dirCount + listItemIndex;
347                 listItemIndex = tempIndex;
348         }
349
350         //Get the Directory Entry for the element at index from the Filenames list.
351
352         pFileDetails = static_cast< DirectoryEntry* >(__pFileNames->GetAt(listItemIndex));
353         TryCatch(pFileDetails != null, , "MfMyFilesApp::Failed to fetch FileDetails from __pFileNames!");
354
355         r = pAppRegistry->Get(__extensionKeyName, fileExtension);
356
357         pCacheList = CacheManager::GetInstance()->GetCacheHashMap();
358
359         //Set the filename of the element at index index
360         filename = pFileDetails->GetFileName();
361         fullFilePath = pFileDetails->GetFullFilePath();
362
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())
365         {
366                 if (!pFileDetails->GetFileExtension().IsEmpty())
367                 {
368                         filename = filename + "." + pFileDetails->GetFileExtension();
369                 }
370         }
371
372         if (pFileDetails->IsDirectory())
373         {
374                 if (__sourceInfo != CREATE_ITEM_SOURCE_SHARE_FORM)
375                 {
376                         pCustomItem->SetThumbnail(__pFolderBitmap);
377                 }
378         }
379         else
380         {
381                 if (__sourceInfo == CREATE_ITEM_SOURCE_SUB_BASE_MOVE_COPY)
382                 {
383                         pCustomItem->SetDescColor(Color::GetColor(COLOR_ID_GREY));
384                 }
385
386                 contentType = ContentManagerUtil::CheckContentType(fullFilePath);
387
388                 if (pFileDetails->GetBitmap() == null && pFileDetails->IstDummy())
389                 {
390                         if (pCacheList != null && (contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO))
391                         {
392                                 if (pFileDetails != null)
393                                 {
394                                         cacheImagePath = pFileDetails->GetFullFilePath();
395                                         AppLogDebug("cache path is %S",cacheImagePath.GetPointer());
396                                 }
397
398                                 if ((pCacheList->GetValue(cacheImagePath)) != null)
399                                 {
400                                         pFetchedCacheImage = static_cast< Bitmap* >(pCacheList->GetValue(cacheImagePath));
401                                 }
402                         }
403
404                         if (pFetchedCacheImage != null)
405                         {
406                                 AppLogDebug("image taken from cachemanager");
407                                 pThumbnailImage = CacheManager::GetInstance()->GetCacheBitmapN(cacheImagePath);
408                                 pCustomItem->SetThumbnail(pThumbnailImage);
409                         }
410                         else
411                         {
412                                 pFileDetails->SetDummy(true);
413                                 pCustomItem->SetThumbnail(__pDummyImage);
414                                 AppLogDebug("call to thumbnail manager");
415                         }
416                 }
417                 else
418                 {
419                         AppLogDebug("BITMAP FOUND : NOT NEED TO DO GETTHUMBNAIL");
420                         pCustomItem->SetThumbnail(pFileDetails->GetBitmap());
421                 }
422         }
423
424
425         if (__sourceInfo == CREATE_ITEM_SOURCE_FILE_MANAGE_FORM || __sourceInfo == CREATE_ITEM_SOURCE_SPLIT_PANEL_FILE_MANAGE_FORM)
426         {
427                 imageIconPath = pFileDetails->GetFullFilePath();
428                 dateCreated = GetFileCreationTime(imageIconPath);
429                 creationDate = MfUtility::ConvertDateTimeToString(dateCreated);
430
431                 pCustomItem->SetTitle(filename, searchedString);
432                 //Rename Bitmap
433                 pCustomItem->SetRenameBitmap(__pSecondaryBitmap, __pSecondaryBitmapPressed);
434                 pCustomItem->MakeFileManageFormListItem();
435         }
436         else if(__sourceInfo == CREATE_ITEM_SOURCE_CATEGORY_SEARCH_FORM)
437         {
438                 annexStyle = ANNEX_STYLE_DETAILED;
439
440                 pCustomItem->SetTitle(filename, searchedText);
441                 GetParentFolderPath(&fullFilePath);
442                 pCustomItem->SetFilepath(fullFilePath);
443                 pCustomItem->SetListAnnexStyle(annexStyle);
444                 pCustomItem->MakeSearchFormListItem();
445                 if (__pItemContext != null)
446                 {
447                         pCustomItem->SetContextItem(__pItemContext);
448                 }
449         }
450         else if(__sourceInfo == CREATE_ITEM_SOURCE_SHARE_FORM)
451         {
452                 annexStyle = ANNEX_STYLE_MARK;
453                 pCustomItem->SetListAnnexStyle(annexStyle);
454
455                 pCustomItem->SetTitle(filename, searchedText);
456                 pCustomItem->MakeAppControlFormListItem();
457         }
458         else
459         {
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)
464                 {
465                         pCustomItem->Make(pFileDetails->GetDirectoryDepth());
466                 }
467                 else
468                 {
469                         pCustomItem->Make();
470                 }
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)
474                 {
475
476                         if (__pItemContext != null)
477                         {
478                                 pCustomItem->SetContextItem(__pItemContext);
479                         }
480                 }
481                 AppLogDebug("EXIT: r = %s", GetErrorMessage(GetLastResult()));
482         }
483         return pCustomItem;
484
485 CATCH:
486         if (pCustomItem != null)
487         {
488                 delete pCustomItem;
489                 pCustomItem = null;
490         }
491         return null;
492 }
493
494 ContentListItem*
495 BaseItemProvider::CreateDetailedListViewItem(int listItemIndex, int listItemWidth)
496 {
497
498         AppLogDebug("ENTER");
499         result r = E_SUCCESS;
500
501         Font font;
502
503         String filename;
504         String folderPath;
505         String imageIconPath;
506         String fontName;
507
508         String fileExtension;
509         String searchedText;
510         String descriptionText;
511         String creationDate;
512         String itemCountDisplay;
513         String searchedString;
514         String cacheImagePath;
515
516         DateTime dateCreated;
517
518         Dimension thumbnailDimension(W_LISTVIEW_ITEM_BITMAP, H_LISTVIEW_ITEM_BITMAP);
519         Dimension textDimension((listItemWidth - W_LISTVIEW_ITEM_BITMAP) / 2, H_DETAIL_LISTVIEW);
520
521         DirectoryEntry* pFileDetails = null;
522         ContentListItem* pContentListItem = null;
523
524         Bitmap* pFetchedCacheImage = null;
525         Bitmap* pThumbnailImage = null;
526         HashMap* pCacheList = null;
527         ContentType contentType = CONTENT_TYPE_UNKNOWN;
528
529         AppResource* pAppResource = null;
530         AppRegistry* pAppRegistry = null;
531         pAppRegistry = UiApp::App::GetInstance()->GetAppRegistry();
532
533
534         int filesCount = 0;
535         long long int fileSize;
536
537         TryCatch(__pFileNames != null, , "Filename list if empty!");
538         TryCatch(__pFileNames->GetCount() != 0, , "Filename count is Zero!");
539
540         pAppResource = Application::GetInstance()->GetAppResource();
541         TryCatch(pAppResource != null, , "Resource manager not found!");
542
543         pAppResource->GetString(L"IDS_ITEM_COUNT", itemCountDisplay);
544
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!");
548
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");
552
553         //Get the key value for the file extension visibility.
554         r = pAppRegistry->Get(__extensionKeyName, fileExtension);
555         pCacheList = CacheManager::GetInstance()->GetCacheHashMap();
556
557         //Assign the filename to the one retrieved from __fileNames.
558         filename = pFileDetails->GetFileName();
559         if (fileExtension == __showExtension && !pFileDetails->IsDirectory())
560         {
561                 if (!pFileDetails->GetFileExtension().IsEmpty())
562                 {
563                         filename = filename + "." + pFileDetails->GetFileExtension();
564                 }
565         }
566
567         if (pFileDetails->IsDirectory())
568         {
569                 folderPath = pFileDetails->GetFullFilePath();
570
571                 pContentListItem->SetThumbnail(__pFolderBitmap);
572
573                 dateCreated = GetFileCreationTime(folderPath);
574                 creationDate = MfUtility::ConvertDateTimeToString(dateCreated);
575
576                 filesCount = pFileDetails->GetFilecount() + pFileDetails->GetDirectoryCount();
577                 descriptionText.Append(filesCount);
578                 descriptionText.Append(itemCountDisplay);
579         }
580         else
581         {
582                 imageIconPath = pFileDetails->GetFullFilePath();
583                 if (__sourceInfo == CREATE_ITEM_SOURCE_SUB_BASE_MOVE_COPY)
584                 {
585                         pContentListItem->SetDescColor(Color::GetColor(COLOR_ID_GREY));
586                 }
587
588                 contentType = ContentManagerUtil::CheckContentType(imageIconPath);
589
590                 if (pFileDetails->GetBitmap() == null && pFileDetails->IstDummy())
591                 {
592                         if (pCacheList != null && (contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO))
593                         {
594                                 if (pFileDetails != null)
595                                 {
596                                         cacheImagePath = pFileDetails->GetFullFilePath();
597                                         AppLogDebug("cache path is %S",cacheImagePath.GetPointer());
598                                 }
599
600                                 if ((pCacheList->GetValue(cacheImagePath)) != null)
601                                 {
602                                         pFetchedCacheImage = static_cast< Bitmap* >(pCacheList->GetValue(cacheImagePath));
603                                 }
604                         }
605
606                         if (pFetchedCacheImage != null)
607                         {
608                                 pThumbnailImage = CacheManager::GetInstance()->GetCacheBitmapN(cacheImagePath);
609                                 pContentListItem->SetThumbnail(pThumbnailImage);
610                         }
611                         else
612                         {
613                                 pFileDetails->SetDummy(true);
614                                 pContentListItem->SetThumbnail(__pDummyImage);
615                         }
616                 }
617                 else
618                 {
619                         pContentListItem->SetThumbnail(pFileDetails->GetBitmap());
620                 }
621
622                 fileSize = GetFileSize(imageIconPath);
623                 dateCreated = GetFileCreationTime(imageIconPath);
624                 creationDate = MfUtility::ConvertDateTimeToString(dateCreated);
625                 descriptionText = MfUtility::ConvertFileSizeToString(fileSize);
626         }
627
628         pContentListItem->SetTitle(filename, searchedText);
629         pContentListItem->SetDescription(descriptionText);
630         pContentListItem->SetDate(creationDate);
631
632         if (__sourceInfo == CREATE_ITEM_SOURCE_CATEGORY_SEARCH_FORM)
633         {
634                 pContentListItem->SetRenameBitmap(__pSecondaryBitmap, __pSecondaryBitmapPressed);
635         }
636
637         pContentListItem->MakeDetailedListItem();
638
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)
641         {
642                 if (__pItemContext != null)
643                 {
644                         pContentListItem->SetContextItem(__pItemContext);
645                 }
646         }
647
648         AppLogDebug("EXIT: r = %s", GetErrorMessage(GetLastResult()));
649
650         return pContentListItem;
651 CATCH:
652
653         return null;
654 }
655
656 void
657 BaseItemProvider::SetSourceForm(CreateItemSource sourceInfo)
658 {
659         AppLogDebug("Enter");
660
661         __sourceInfo = sourceInfo;
662         int currentStorageType = MEMORY_TYPE_PHONE;
663         AppResource* pAppResource = null;
664
665         pAppResource = Application::GetInstance()->GetAppResource();
666         TryCatch(pAppResource != null, , "MfMyFilesApp::Resource manager not found!");
667
668         currentStorageType = FolderNavigationPresentationModel::GetStorageType();
669
670         switch (currentStorageType)
671         {
672         case MEMORY_TYPE_PHONE:
673         {
674                 __pFolderBitmap = pAppResource->GetBitmapN(IDB_FOLDER, BITMAP_PIXEL_FORMAT_ARGB8888);
675         }
676                 break;
677
678         case MEMORY_TYPE_SD_CARD:
679         {
680                 __pFolderBitmap = pAppResource->GetBitmapN(IDB_SDCARD_ICON, BITMAP_PIXEL_FORMAT_ARGB8888);
681
682         }
683                 break;
684
685         case MEMORY_TYPE_EXTERNAL:
686         {
687                 __pFolderBitmap = pAppResource->GetBitmapN(IDB_EXTERNAL_ICON, BITMAP_PIXEL_FORMAT_ARGB8888);
688         }
689                 break;
690         default:
691                 break;
692         }
693
694         if (__sourceInfo == CREATE_ITEM_SOURCE_FILE_MANAGE_FORM || __sourceInfo == CREATE_ITEM_SOURCE_SPLIT_PANEL_FILE_MANAGE_FORM)
695         {
696                 if (__pSecondaryBitmap == null)
697                 {
698                         __pSecondaryBitmap = MfUtility::MergeBitmapN(IDB_RENAME_OUTER_CIRCLE, IDB_RENAME, W_RENAME_ICON, W_RENAME_ICON);
699                 }
700                 if (__pSecondaryBitmapPressed == null)
701                 {
702                         __pSecondaryBitmapPressed = MfUtility::MergeBitmapN(IDB_RENAME_PRESSED_CIRCLE, IDB_RENAME, W_RENAME_ICON, W_RENAME_ICON);
703                 }
704         }
705
706 return;
707 CATCH:
708         return;
709 }
710
711 void
712 BaseItemProvider::SetFolderEntryProvider(IFolderEntryProviderListener* pProvider)
713 {
714         __pProviderPM = pProvider;
715         __pFolderEntryPM = __pProviderPM->GetFolderEntryPresentationModel();
716 }
717
718 result
719 BaseItemProvider::SetFooterItemStateChangeListener(IListViewStateChangeListener* listener)
720 {
721         result r = E_SUCCESS;
722         __pListViewItemStateChangeListener = listener;
723
724         return r;
725 }
726
727 void
728 BaseItemProvider::GetParentFolderPath(Tizen::Base::String* filePath)
729 {
730         String displayPath;
731         String delim(L"/");
732         String token;
733
734         StringTokenizer tokenizer(*filePath, delim);
735
736         filePath->Clear();
737
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())
741         {
742                 if (tokenizer.GetTokenCount() != 1)
743                 {
744                         filePath->Append(L"/");
745                         tokenizer.GetNextToken(token);
746                         filePath->Append(token);
747                 }
748                 else
749                 {
750                         break;
751                 }
752         }
753
754         filePath->Append(L"/");
755
756         if (filePath->StartsWith(BasePresentationModel::GetMediaPath(),0))
757         {
758                 filePath->Replace(BasePresentationModel::GetMediaPath(),"Phone/",0);
759         }
760         else if(filePath->StartsWith(BasePresentationModel::GetSdCardPath(),0))
761         {
762                 filePath->Replace(BasePresentationModel::GetSdCardPath(),"Memory Card/",0);
763         }
764 }
765
766 Tizen::Base::DateTime
767 BaseItemProvider::GetFileCreationTime(String filePath)
768 {
769         AppLogDebug("Entry");
770
771         DateTime fileCreationTime;
772         FileAttributes fileAttrib;
773
774         File::GetAttributes(filePath, fileAttrib);
775         fileCreationTime = fileAttrib.GetDateTime();
776
777         return fileCreationTime;
778 }
779
780 long long int
781 BaseItemProvider::GetFileSize(String filePath)
782 {
783         AppLogDebug("Entry");
784
785         long long int fileSize = 0;
786         FileAttributes fileAttrib;
787
788         File::GetAttributes(filePath, fileAttrib);
789         fileSize = fileAttrib.GetFileSize();
790
791         return fileSize;
792 }