Merge " Fixed rotate issue when image files after video files" into tizen_2.1
[apps/osp/Gallery.git] / src / GlFileListPresentationModel.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                GlFileListPresentationModel.cpp
19  * @brief               This is the implementation file for FileListPresentationModel class.
20  */
21
22 #include <cstdlib>
23 #include <FMedia.h>
24 #include <FSystem.h>
25 #include "GlCommonUtil.h"
26 #include "GlFileListPresentationModel.h"
27 #include "GlContentUpdateEventListener.h"
28 #include "GlGalleryApp.h"
29 #include "GlThumbnailEvent.h"
30 #include "GlThumbnailEventArg.h"
31 #include "GlThumbnailProvider.h"
32 #include "GlTypes.h"
33
34 using namespace Tizen::App;
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Base::Runtime;
38 using namespace Tizen::Base::Utility;
39 using namespace Tizen::Content;
40 using namespace Tizen::Graphics;
41 using namespace Tizen::Io;
42 using namespace Tizen::Media;
43 using namespace Tizen::System;
44
45 static const String CONTENT_INFO_ORDER = L"ContentFileName";
46
47 static const int SIZE_PAGE_NO = 1;
48 static const int SIZE_CONUNT_PER_PAGE = 3000;
49 static const int SIZE_ICON_LIST_CACHE = 50;
50 static const int W_DURATION_TEXT = 44;
51 static const int H_DURATION_TEXT = 4;
52 static const int W_DURATION = 171;
53 static const int H_DURATION = 32;
54 static const int W_DEFAULT_THUMBNAIL = 171;
55 static const int H_DEFAULT_THUMBNAIL = 127;
56 static const int W_WIDE_THUMBNAIL = 171;
57 static const int H_WIDE_THUMBNAIL = 127;
58 static const int W_PLAY_FG = 64;
59 static const int H_PLAY_FG = 64;
60 static const int GAP_W_PLAY_FG = (W_DEFAULT_THUMBNAIL -W_PLAY_FG)/2 ;
61 static const int GAP_H_PLAY_FG = (H_DEFAULT_THUMBNAIL - H_PLAY_FG)/2;
62 static const int GAP_H_DURATION = H_DEFAULT_THUMBNAIL - H_DURATION;
63 static const int ALPHA_DURATION = 70;
64 static const int FONT_SIZE_DURATION = 24;
65 static const Dimension DIMENSION_REAL_ICON (171,127);
66 static const Rectangle RECTANGLE_THUMBNAIL_OFFSET_POSION (1, 1, 171, 127);
67 static const Rectangle RECTANGLE_VIDEO_THUMBNAIL_OFFSET_POSION (1, 1, 171, 127);
68 static const Color COLOR_DURATION_BG (Color::GetColor(COLOR_ID_BLACK));
69 static const Color COLOR_TEXT_OUTLINE (Color::GetColor(COLOR_ID_WHITE));
70
71 static const String RESERVED_CAMERA_PATH = Environment::GetMediaPath() + L"Camera";
72 static const String RESERVED_CAMERA_PATH_EXT = Environment::GetExternalStoragePath() + L"Camera";
73 static const String RESERVED_DOWNLOAD_PATH = Environment::GetMediaPath() + L"Downloads";
74
75 FileListPresentationModel* FileListPresentationModel::__pPresentationModelInstance = null;
76 ThumbnailProvider* FileListPresentationModel::__pThumbnailProvider = null;
77 ThumbnailEvent* FileListPresentationModel::__pThumbnailEvent = null;
78 ArrayList* FileListPresentationModel::__pPresentationModelListener = null;
79 ArrayList* FileListPresentationModel::__pContentEventListener = null;
80 ArrayList* FileListPresentationModel::__pIconListViewCache = null;
81 IList* FileListPresentationModel::__pDirectoryList = null;
82 IList* FileListPresentationModel::__pContentInfoList = null;
83
84 FileListPresentationModel::FileListPresentationModel(void)
85         : __pContentManager(null)
86         , __albumContentType(CONTENT_TYPE_ALL)
87         , __appControlMode(APPCONTROL_MODE_MAIN)
88         , __appControlMediaType(APPCONTROL_MEDIA_TYPE_IMAGE)
89         , __appControlSelectionMode(APPCONTROL_SELECTION_MODE_SINGLE)
90         , __pContentIdList(null)
91         , __updateProgressStatus(false)
92 {
93         AppLogDebug("ENTER");
94         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
95 }
96
97 FileListPresentationModel::~FileListPresentationModel(void)
98 {
99         AppLogDebug("ENTER");
100         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
101 }
102
103 FileListPresentationModel*
104 FileListPresentationModel::GetInstance(void)
105 {
106         AppLogDebug("ENTER");
107         if (__pPresentationModelInstance == null)
108         {
109                 CreateInstance();
110         }
111         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
112
113         return __pPresentationModelInstance;
114 }
115
116 result
117 FileListPresentationModel::Construct(void)
118 {
119         AppLogDebug("ENTER");
120
121         IThumbnailEventListener* pThumbnailEventListener = static_cast<IThumbnailEventListener*>(this);
122         __pThumbnailEvent = new (std::nothrow) ThumbnailEvent();
123         __pThumbnailEvent->AddListener(*pThumbnailEventListener, true);
124
125         DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
126
127         ContentUpdateEventListener::GetInstance();
128         __pContentManager = new (std::nothrow) ContentManager();
129         __pContentManager->Construct();
130
131         if (__pIconListViewCache != null)
132         {
133                 delete __pIconListViewCache;
134         }
135         __pIconListViewCache = new (std::nothrow) ArrayList(SingleObjectDeleter);
136         __pIconListViewCache->Construct(SIZE_ICON_LIST_CACHE);
137
138         if (__pDirectoryList != null)
139         {
140                 delete __pDirectoryList;
141         }
142         __pDirectoryList = new (std::nothrow) ArrayList(SingleObjectDeleter);
143
144         if (__pContentInfoList != null)
145         {
146                 delete __pContentInfoList;
147         }
148         __pContentInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
149
150         __pPresentationModelListener = new (std::nothrow) ArrayList();
151         __pPresentationModelListener->Construct();
152
153         __pContentEventListener = new (std::nothrow) ArrayList();
154         __pContentEventListener->Construct();
155
156         __pThumbnailProvider = ThumbnailProvider::GetInstance();
157
158         GalleryApp* pApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
159         const IMap* pArguments = pApp->GetAppControlArguments();
160         String operationId = pApp->GetAppControlOperationId();
161
162         if (operationId.CompareTo(APPCONTROL_OPERATION_ID_MAIN) == 0)
163         {
164                 __appControlMode = APPCONTROL_MODE_MAIN;
165         }
166         else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_PICK) == 0)
167         {
168                 __appControlMode = APPCONTROL_MODE_PICK;
169
170                 if (pArguments != null)
171                 {
172                         const String* selectionMode = static_cast<const String*>(pArguments->GetValue(String(APPCONTROL_KEY_SELECTION_MODE)));
173
174                         if (pApp->GetMimeType().StartsWith(APPCONTROL_DATA_VIDEO, 0) == true)
175                         {
176                                 __appControlMediaType = APPCONTROL_MEDIA_TYPE_VIDEO;
177                         }
178
179                         if (selectionMode != null && selectionMode->CompareTo(APPCONTROL_DATA_MULTIPLE) == 0)
180                         {
181                                 __appControlSelectionMode = APPCONTROL_SELECTION_MODE_MULTIPLE;
182                         }
183                 }
184         }
185         else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_CONFIGURE) == 0)
186         {
187                 __appControlMode = APPCONTROL_MODE_SETTING;
188         }
189
190         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
191
192         return E_SUCCESS;
193 }
194
195 void
196 FileListPresentationModel::CreateInstance(void)
197 {
198         AppLogDebug("ENTER");
199         __pPresentationModelInstance = new (std::nothrow) FileListPresentationModel();
200         result r = __pPresentationModelInstance->Construct();
201         if (IsFailed(r) == true)
202         {
203                 delete __pPresentationModelInstance;
204                 __pPresentationModelInstance = null;
205                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
206
207                 return;
208         }
209
210         std::atexit(DestroyInstance);
211         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
212 }
213
214 void
215 FileListPresentationModel::DestroyInstance(void)
216 {
217         AppLogDebug("ENTER");
218
219         delete __pThumbnailEvent;
220         __pIconListViewCache = null;
221
222         if (__pIconListViewCache != null)
223         {
224                 delete __pIconListViewCache;
225                 __pIconListViewCache = null;
226         }
227
228         if (__pDirectoryList != null)
229         {
230                 delete __pDirectoryList;
231                 __pDirectoryList = null;
232         }
233
234         if (__pContentInfoList != null)
235         {
236                 delete __pContentInfoList;
237                 __pContentInfoList = null;
238         }
239
240         if (__pPresentationModelListener != null)
241         {
242                 delete __pPresentationModelListener;
243                 __pPresentationModelListener = null;
244         }
245
246         if (__pContentEventListener != null)
247         {
248                 delete __pContentEventListener;
249                 __pContentEventListener = null;
250         }
251
252         delete __pPresentationModelInstance;
253         __pPresentationModelInstance = null;
254
255         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
256 }
257
258 String
259 FileListPresentationModel::GetFileNameFromFullPath(const String& fullPath, const bool withExt) const
260 {
261         AppLogDebug("ENTER");
262         if (fullPath.CompareTo(EMPTY_SPACE) == 0)
263         {
264                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
265
266                 return EMPTY_SPACE;
267         }
268
269         String delim(DIRECTORY_SEPARATOR);
270         StringTokenizer st(fullPath,delim);
271         String token;
272         while (st.HasMoreTokens())
273         {
274                 st.GetNextToken(token);
275         }
276
277         if (withExt == true)
278         {
279                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
280
281                 return token;
282         }
283         else
284         {
285                 String subDelim(FILE_EXT_SEPARATOR);
286                 StringTokenizer subSt(token, subDelim);
287                 String subToken;
288                 subSt.GetNextToken(subToken);
289                 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
290
291                 return subToken;
292         }
293 }
294
295 String
296 FileListPresentationModel::GetDirecotyNameFromFullPath(const String& fullPath)const
297 {
298         AppLogDebug("ENTER");
299         if (fullPath == null)
300         {
301                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
302
303                 return null;
304         }
305         String delim(DIRECTORY_SEPARATOR);
306         StringTokenizer st(fullPath,delim);
307         String token;
308         while (st.HasMoreTokens())
309         {
310                 st.GetNextToken(token);
311         }
312         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
313
314         return token;
315 }
316
317 bool
318 FileListPresentationModel::IsContainContentInDirectory(const String& directoryPath, ContentType contentType) const
319 {
320         AppLogDebug("ENTER");
321         IListT<ContentType>* pContentTypeList = new (std::nothrow) ArrayListT<ContentType>();
322         if (&directoryPath == null || pContentTypeList == null)
323         {
324                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
325
326                 return false;
327         }
328
329         if (contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_ALL)
330         {
331                 pContentTypeList->Add(CONTENT_TYPE_IMAGE);
332         }
333         if (contentType == CONTENT_TYPE_VIDEO || contentType == CONTENT_TYPE_ALL)
334         {
335                 pContentTypeList->Add(CONTENT_TYPE_VIDEO);
336         }
337
338         ContentDirectory contentDirectory;
339         result r = contentDirectory.Construct(*pContentTypeList);
340         if (pContentTypeList != null)
341         {
342                 delete pContentTypeList;
343         }
344         TryReturn(r == E_SUCCESS, false, "[%s] Unable to construct ContentDirectory", GetErrorMessage(r));
345
346         bool returnValue = false;
347         int pageNo = SIZE_PAGE_NO;
348         int countPerPage = SIZE_CONUNT_PER_PAGE;
349
350         IList* pContentList = contentDirectory.GetContentDirectoryItemListN(directoryPath, pageNo, countPerPage,
351                         CONTENT_INFO_ORDER, SORT_ORDER_ASCENDING);
352
353         if (pContentList == null || pContentList->GetCount() <= 0)
354         {
355                 returnValue = false;
356         }
357         else
358         {
359                 returnValue = true;
360         }
361
362         if (pContentList != null)
363         {
364                 delete pContentList;
365         }
366         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
367
368         return returnValue;
369 }
370
371 result
372 FileListPresentationModel::GetThumbnailInSyncCacheN(const int index, String*& pName, Bitmap*& pThumbnail)
373 {
374         AppLogDebug("ENTER : index(%d)", index);
375         Bitmap* pOriginalBitmap = null;
376         Bitmap* pDestinationBitmap = null;
377         ContentInfo* pContentInfo = null;
378
379         if (__pContentInfoList != null && index < __pContentInfoList->GetCount())
380         {
381                 pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
382                 if (pContentInfo == null)
383                 {
384                         AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
385
386                         return E_FAILURE;
387                 }
388         }
389         else
390         {
391                 AppLogDebug("EXIT 2 __pContentInfoList(%x) index(%d)", __pContentInfoList, index);
392                 return E_FAILURE;
393         }
394
395         ThumbnailInfo* pThumbnailInfo = GetThumbnailInfoFromInternalBufferN(pContentInfo->GetContentId());
396         if (pThumbnailInfo != null)
397         {
398                 pName = new (std::nothrow) String(pThumbnailInfo->GetFilePath());
399                 pOriginalBitmap = pThumbnailInfo->GetBitmapN();
400         }
401
402         if ((pThumbnailInfo != null)&&(pThumbnailInfo->GetContentType() == CONTENT_TYPE_VIDEO))
403         {
404                 if (pOriginalBitmap != null)
405                 {
406                         pDestinationBitmap = CoverVideoOverlayedImageOnThumbnailN(*pOriginalBitmap, *pThumbnailInfo);
407                         delete pOriginalBitmap;
408                 }
409         }
410         else
411         {
412                 pDestinationBitmap = pOriginalBitmap;
413         }
414
415         if (pDestinationBitmap != null)
416         {
417                 Bitmap* pThumbnailBgBitmap = ResourceManager::GetBitmapN(IDB_VIDEOTHUMBNAIL_BG);
418                 Rectangle thumbnailRect(RECTANGLE_THUMBNAIL_OFFSET_POSION);
419                 pDestinationBitmap->Scale(Dimension(RECTANGLE_THUMBNAIL_OFFSET_POSION.width - RECTANGLE_THUMBNAIL_OFFSET_POSION.x
420                                 , RECTANGLE_THUMBNAIL_OFFSET_POSION.height - RECTANGLE_THUMBNAIL_OFFSET_POSION.y));
421                 if (pThumbnailBgBitmap != null)
422                 {
423                         pThumbnailBgBitmap->Scale(DIMENSION_REAL_ICON);
424                         pThumbnail = GetShadedBackgroundBitmapN(*pThumbnailBgBitmap, *pDestinationBitmap, thumbnailRect);
425                         delete pThumbnailBgBitmap;
426                         delete pDestinationBitmap;
427                 }
428                 else
429                 {
430                         pThumbnail = pDestinationBitmap;
431                 }
432         }
433         else
434         {
435                 pThumbnail = null;
436         }
437
438         if (pThumbnailInfo != null)
439         {
440                 delete pThumbnailInfo;
441         }
442         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
443
444         return E_SUCCESS;
445 }
446
447 result
448 FileListPresentationModel::GetThumbnailVideoInSyncCacheN(const int index,
449                 String*& pName, Bitmap*& pThumbnail, String*& pDuration) const
450 {
451         AppLogDebug("ENTER : index(%d)", index);
452         ContentInfo* pContentInfo = null;
453         Bitmap* pOriginalBitmap = null;
454
455         if (__pContentInfoList != null && index < __pContentInfoList->GetCount())
456         {
457                 pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
458                 if (pContentInfo == null)
459                 {
460                         AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
461                         return E_FAILURE;
462                 }
463         }
464         else
465         {
466                 AppLogDebug("EXIT 2 __pContentInfoList(%x) index(%d)", __pContentInfoList, index);
467                 return E_FAILURE;
468         }
469
470         ThumbnailInfo* pThumbnailInfo = GetThumbnailInfoFromInternalBufferN(pContentInfo->GetContentId());
471         if (pThumbnailInfo != null)
472         {
473                 pName = new (std::nothrow) String(pThumbnailInfo->GetFilePath());
474                 pOriginalBitmap = pThumbnailInfo->GetBitmapN();
475                 pDuration = new (std::nothrow) String(CommonUtil::DurationToTimeString(pThumbnailInfo->GetDuration()));
476         }
477         else
478         {
479                 pName = new (std::nothrow) String(EMPTY_SPACE);
480                 pDuration = new (std::nothrow) String(CommonUtil::DurationToTimeString(0));
481         }
482
483         if (pOriginalBitmap != null)
484         {
485                 Bitmap* pThumbnailBgBitmap = ResourceManager::GetBitmapN(IDB_VIDEOTHUMBNAIL_BG);
486                 Rectangle thumbnailRect(RECTANGLE_VIDEO_THUMBNAIL_OFFSET_POSION);
487                 pOriginalBitmap->Scale(Dimension(RECTANGLE_VIDEO_THUMBNAIL_OFFSET_POSION.width - RECTANGLE_VIDEO_THUMBNAIL_OFFSET_POSION.x
488                                 , RECTANGLE_VIDEO_THUMBNAIL_OFFSET_POSION.height - RECTANGLE_VIDEO_THUMBNAIL_OFFSET_POSION.y));
489                 if (pThumbnailBgBitmap != null)
490                 {
491                         pThumbnailBgBitmap->Scale(Dimension(W_WIDE_THUMBNAIL, H_WIDE_THUMBNAIL));
492                         pThumbnail = GetShadedBackgroundBitmapN(*pThumbnailBgBitmap, *pOriginalBitmap, thumbnailRect);
493                         delete pThumbnailBgBitmap;
494                 }
495                 delete pOriginalBitmap;
496         }
497         else
498         {
499                 pThumbnail = null;
500         }
501
502         if (pThumbnail != null)
503         {
504                 pThumbnail->Scale(Dimension(W_WIDE_THUMBNAIL, H_WIDE_THUMBNAIL));
505         }
506
507         if (pThumbnailInfo != null)
508         {
509                 delete pThumbnailInfo;
510         }
511         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
512
513         return E_SUCCESS;
514 }
515
516 void
517 FileListPresentationModel::RequestThumbnail(const int index)
518 {
519         AppLogDebug("ENTER : index(%d)", index);
520         ContentInfo* pContentInfo = null;
521
522         if (__pContentInfoList != null && index < __pContentInfoList->GetCount())
523         {
524                 pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
525                 if (pContentInfo == null)
526                 {
527                         AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
528                         return;
529                 }
530         }
531         else
532         {
533                 AppLogDebug("EXIT 2 __pContentInfoList(%x) index(%d)", __pContentInfoList, index);
534
535                 return;
536         }
537
538         __pThumbnailProvider->RequestThumbnail(pContentInfo->GetContentId(), __pThumbnailEvent);
539         AppLogDebug("EXIT");
540 }
541
542 void
543 FileListPresentationModel::ClearThumbnailRequests(const bool appTerminating)
544 {
545         AppLogDebug("ENTER");
546
547         if (__pThumbnailProvider != null)
548         {
549                 __pThumbnailProvider->ClearThumbnailRequests(appTerminating);
550         }
551
552         AppLogDebug("EXIT");
553 }
554
555 void
556 FileListPresentationModel::OnThumbnailReceivedN(IEventArg& eventArg)
557 {
558         AppLogDebug("ENTER");
559
560         if (&eventArg != null)
561         {
562                 ThumbnailEventArg* pThumbnailEventArg = static_cast<ThumbnailEventArg*>(&eventArg);
563                 if (pThumbnailEventArg == null)
564                 {
565                         AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
566
567                         return;
568                 }               
569                 ThumbnailInfo* pThumbnailInfo = pThumbnailEventArg->GetThumbnailInfoN();
570                 if (pThumbnailInfo == null)
571                 {
572                         AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
573
574                         return;
575                 }
576
577                 bool isMatch = false;
578                 ContentId contentId = pThumbnailInfo->GetContentId();
579
580                 if (__pIconListViewCache != null)
581                 {
582                         IEnumerator* pEnum = __pIconListViewCache->GetEnumeratorN();
583                         Bitmap* pBitmap = null;
584                         while (pEnum->MoveNext() == E_SUCCESS)
585                         {
586                                 ThumbnailInfo* pTempThumbnailInfo = static_cast<ThumbnailInfo*>(pEnum->GetCurrent());
587
588                                 if (contentId == pTempThumbnailInfo->GetContentId())
589                                 {
590                                         AppLogDebug("[CHASEFIRE] PM receive (%ls)", pThumbnailInfo->GetFilePath().GetPointer());
591                                         pBitmap = pThumbnailInfo->GetBitmapN();
592                                         pTempThumbnailInfo->SetBitmap(*pBitmap);
593                                         delete pBitmap;
594
595                                         pTempThumbnailInfo->SetContentType(pThumbnailInfo->GetContentType());
596                                         pTempThumbnailInfo->SetDuration(pThumbnailInfo->GetDuration());
597                                         delete pThumbnailInfo;
598                                         isMatch = true;
599                                         break;
600                                 }
601                         }
602
603                         if (isMatch == false)
604                         {
605                                 if (SIZE_ICON_LIST_CACHE <= __pIconListViewCache->GetCount())
606                                 {
607                                         __pIconListViewCache->RemoveAt(0, true);
608                                 }
609                                 AppLogDebug("[CHASEFIRE] (all:%d) Add Thumbail(%ls)", __pIconListViewCache->GetCount(),
610                                                 pThumbnailInfo->GetFilePath().GetPointer());
611                                 __pIconListViewCache->Add(pThumbnailInfo);
612                         }
613                 }
614
615                 int index = -1;
616                 int loopCount = __pContentInfoList->GetCount();
617                 for (int i = 0; i < loopCount; ++i)
618                 {
619                         if (contentId == (static_cast<ContentInfo*>(__pContentInfoList->GetAt(i)))->GetContentId())
620                         {
621                                 index = i;
622                                 break;
623                         }
624                 }
625
626                 IAlbumEventListener* pInterface = null;
627                 IEnumerator* pEventEnum = __pPresentationModelListener->GetEnumeratorN();
628                 while (pEventEnum->MoveNext() == E_SUCCESS)
629                 {
630                         pInterface = static_cast<IAlbumEventListener*>(pEventEnum->GetCurrent());
631                         pInterface->OnThumbnailDecoded(index);
632                 }
633                 delete pEventEnum;
634         }
635         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
636 }
637
638 void
639 FileListPresentationModel::OnContentCreated(void)
640 {
641         AppLogDebug("ENTER");
642         if (__updateProgressStatus == true)
643         {
644                 AppLogDebug("EXIT update in application");
645                 return;
646         }
647         IFormContentUpdateEventListener* pInterface = null;
648         if (__pContentEventListener == null)
649         {
650                 AppLogDebug("EXIT");
651                 return;
652         }
653         IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
654         while (pEventEnum->MoveNext() == E_SUCCESS)
655         {
656                 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
657                 if (pInterface != null)
658                 {
659                         pInterface->OnContentUpdated();
660                 }
661         }
662         delete pEventEnum;
663         AppLogDebug("EXIT");
664 }
665
666 void
667 FileListPresentationModel::OnContentUpdated(void)
668 {
669         AppLogDebug("ENTER");
670         if (__updateProgressStatus == true)
671         {
672                 AppLogDebug("EXIT update in application");
673                 return;
674         }
675         IFormContentUpdateEventListener* pInterface = null;
676         if (__pContentEventListener == null)
677         {
678                 AppLogDebug("EXIT");
679                 return;
680         }
681         IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
682         while (pEventEnum->MoveNext() == E_SUCCESS)
683         {
684                 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
685                 pInterface->OnContentUpdated();
686         }
687         delete pEventEnum;
688         AppLogDebug("EXIT");
689 }
690
691 void
692 FileListPresentationModel::OnContentDeleted(void)
693 {
694         AppLogDebug("ENTER");
695         if (__updateProgressStatus == true)
696         {
697                 AppLogDebug("EXIT update in application");
698                 return;
699         }
700         IFormContentUpdateEventListener* pInterface = null;
701         if (__pContentEventListener == null)
702         {
703                 AppLogDebug("EXIT");
704                 return;
705         }
706         IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
707         while (pEventEnum->MoveNext() == E_SUCCESS)
708         {
709                 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
710                 pInterface->OnContentUpdated();
711         }
712         delete pEventEnum;
713         AppLogDebug("EXIT");
714 }
715
716 void
717 FileListPresentationModel::AddPresentationModelListener(const IAlbumEventListener* listener)
718 {
719         AppLogDebug("ENTER");
720         __pPresentationModelListener->Add((Object*)listener);
721         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
722 }
723
724 void
725 FileListPresentationModel::RemovePresentationModelListener(const IAlbumEventListener& listener)
726 {
727         AppLogDebug("ENTER");
728         __pPresentationModelListener->Remove(listener);
729         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
730 }
731
732 void
733 FileListPresentationModel::AddContentEventListener(const IFormContentUpdateEventListener* listener)
734 {
735         AppLogDebug("ENTER");
736         if (__pContentEventListener != null)
737         {
738                 __pContentEventListener->RemoveAll();
739                 __pContentEventListener->Add((Object*)listener);
740                 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
741         }
742 }
743
744 void
745 FileListPresentationModel::RemoveContentEventListener(const IFormContentUpdateEventListener* listener)
746 {
747         AppLogDebug("ENTER");
748         __pContentEventListener->Remove(*listener);
749         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
750 }
751
752 ThumbnailInfo*
753 FileListPresentationModel::GetThumbnailInfoFromInternalBufferN(const ContentId& contentId) const
754 {
755         AppLogDebug("ENTER");
756         ThumbnailInfo* pThumbnailInfo = null;
757         ThumbnailInfo* pTempThumbnailInfo = null;
758         if (__pIconListViewCache != null)
759         {
760                 int loopCount = __pIconListViewCache->GetCount();
761                 for (int i = 0; i < loopCount; ++i)
762                 {
763                         pTempThumbnailInfo = static_cast<ThumbnailInfo*>(__pIconListViewCache->GetAt(i));
764                         if (contentId == pTempThumbnailInfo->GetContentId())
765                         {
766
767                                 pThumbnailInfo = new (std::nothrow) ThumbnailInfo();
768                                 Bitmap* pBitmap = pTempThumbnailInfo->GetBitmapN();
769                                 pThumbnailInfo->Construct(pTempThumbnailInfo->GetContentId(), pTempThumbnailInfo->GetFilePath(),
770                                                 *pBitmap, pTempThumbnailInfo->GetContentType(), pTempThumbnailInfo->GetDuration());
771                                 delete pBitmap;
772                                 break;
773                         }
774                 }
775         }
776         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
777
778         return pThumbnailInfo;
779 }
780
781 result
782 FileListPresentationModel::DeleteContentFileList(const IList& contentIndexList)
783 {
784         AppLogDebug("ENTER");
785         if (&contentIndexList == null || contentIndexList.GetCount() <= 0)
786         {
787                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
788
789                 return E_SUCCESS;
790         }
791
792         IList * pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
793         int loopCount = contentIndexList.GetCount();
794         for (int i = 0; i < loopCount; ++i)
795         {
796                 const Integer* pIndex = static_cast<const Integer*>(contentIndexList.GetAt(i));
797
798                 if ((pIndex != null) && (pIndex->ToInt())>=0 && __pContentInfoList->GetCount() > pIndex->ToInt())
799                 {
800                         pContentIdList->Add(new (std::nothrow) ContentId((static_cast<ContentInfo*>
801                                         (__pContentInfoList->GetAt(pIndex->ToInt())))->GetContentId()));
802                 }
803         }
804
805         loopCount = pContentIdList->GetCount();
806         for (int i = 0; i < loopCount; ++i)
807         {
808                 ContentId* pContentId = static_cast<ContentId*>(pContentIdList->GetAt(i));
809                 if (pContentId != null)
810                 {
811                         DeleteContentFile(*pContentId);
812                 }
813         }
814         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
815
816         return E_SUCCESS;
817 }
818
819 IList*
820 FileListPresentationModel::GetCollisionIndexListN(const IList& contentIndexList, const String& destDirectory)
821 {
822         AppLogDebug("ENTER");
823         if (&contentIndexList == null || contentIndexList.GetCount() <= 0 || &destDirectory == null
824                         || destDirectory.IsEmpty() == true)
825         {
826                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
827
828                 return null;
829         }
830
831         if (File::IsFileExist(destDirectory) == false)
832         {
833                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
834
835                 return null;
836         }
837
838         IList * pCollisionInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
839         ContentInfo* pContentInfo = null;
840         int loopCount = contentIndexList.GetCount();
841         for (int i = 0; i < loopCount; ++i)
842         {
843                 const Integer* pIndex = static_cast<const Integer*>(contentIndexList.GetAt(i));
844
845                 if ((pIndex != null) && (pIndex->ToInt()) >= 0 && __pContentInfoList->GetCount() > pIndex->ToInt())
846                 {
847                         pContentInfo = const_cast<ContentInfo*>(static_cast<const ContentInfo*>(__pContentInfoList->GetAt(pIndex->ToInt())));
848                         String filePath = pContentInfo->GetContentPath();
849                         String fileName = GetFileNameFromFullPath(filePath, true);
850
851                         String destPath;
852                         if (destDirectory.EndsWith(DIRECTORY_SEPARATOR) == true)
853                         {
854                                 destPath.Append(destDirectory);
855                                 destPath.Append(fileName);
856                         }
857                         else
858                         {
859                                 destPath.Append(destDirectory);
860                                 destPath.Append(DIRECTORY_SEPARATOR);
861                                 destPath.Append(fileName);
862                         }
863
864                         if (File::IsFileExist(destPath) == true)
865                         {
866                                 pCollisionInfoList->Add(*(new (std::nothrow) String(pIndex->ToString() + MULTI_ITEM_SEPARATOR + fileName)));
867                         }
868                 }
869         }
870         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
871
872         return pCollisionInfoList;
873 }
874
875 result
876 FileListPresentationModel::MoveToContentFileList(const IList& contentIndexList, const String& destDirectory)
877 {
878         AppLogDebug("ENTER");
879         result r = E_SUCCESS;
880         if (&contentIndexList == null || contentIndexList.GetCount() <= 0 || &destDirectory == null || destDirectory.IsEmpty() == true)
881         {
882                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
883
884                 return r;
885         }
886
887         if (File::IsFileExist(destDirectory) == false)
888         {
889                 Directory::Create(destDirectory, true);
890         }
891
892         delete __pContentIdList;
893         __pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
894         int loopCount = contentIndexList.GetCount();
895         for (int i = 0; i < loopCount; ++i)
896         {
897                 const Integer* pIndex = static_cast<const Integer*>(contentIndexList.GetAt(i));
898
899                 if ((pIndex != null) && (pIndex->ToInt())>=0 && __pContentInfoList->GetCount() > pIndex->ToInt())
900                 {
901                         __pContentIdList->Add(new (std::nothrow) ContentId((static_cast<ContentInfo*>(__pContentInfoList->GetAt(pIndex->ToInt())))->GetContentId()));
902                 }
903         }
904
905
906         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
907
908         return E_SUCCESS;
909 }
910
911 result
912 FileListPresentationModel::DeleteContentFile(const ContentId& contentId)
913 {
914         AppLogDebug("ENTER");
915         if (&contentId == null)
916         {
917                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
918
919                 return E_SUCCESS;
920         }
921         result r = __pContentManager->DeleteContent(contentId);
922
923         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
924
925         return r;
926 }
927
928 result
929 FileListPresentationModel::MoveToContentFile(const ContentId& contentId, const String& destDirectory, const bool isCopyOperation)
930 {
931         AppLogDebug("ENTER");
932         if (contentId.ToString().IsEmpty() == true || destDirectory.IsEmpty() == true)
933         {
934                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
935                 return E_FAILURE;
936         }
937         result r = E_SUCCESS;
938         ContentInfo* pContentInfo = __pContentManager->GetContentInfoN(contentId);
939         if (pContentInfo == null)
940         {
941                 AppLogDebug("Santhosh %s", destDirectory.GetPointer());
942                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
943                 return E_FAILURE;
944         }
945
946         String filePath = pContentInfo->GetContentPath();
947         if (filePath.GetLength() < 4)
948         {
949                 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
950                 return E_SUCCESS;
951         }
952
953         String destPath;
954         if (destDirectory.EndsWith(DIRECTORY_SEPARATOR) == true)
955         {
956                 destPath.Append(destDirectory);
957                 destPath.Append(GetFileNameFromFullPath(filePath, true));
958         }
959         else
960         {
961                 destPath.Append(destDirectory);
962                 destPath.Append(DIRECTORY_SEPARATOR);
963                 destPath.Append(GetFileNameFromFullPath(filePath, true));
964         }
965
966         if (destPath.CompareTo(filePath) == 0)
967         {
968                 AppLogDebug("EXIT 4(%s)", GetErrorMessage(GetLastResult()));
969                 return E_SUCCESS;
970         }
971
972         if (File::IsFileExist(destPath) == true)
973         {
974                 File::Remove(destPath);
975         }
976
977         if (pContentInfo->GetContentType() == CONTENT_TYPE_IMAGE)
978         {
979                 r = File::Copy(filePath, destPath, false);
980                 if (r == E_SUCCESS)
981                 {
982                         if (r == E_SUCCESS)
983                         {
984                                 ImageContentInfo contentInfo;
985                                 r = contentInfo.Construct(&destPath);
986                                 if (r == E_SUCCESS)
987                                 {
988                                         __pContentManager->CreateContent(contentInfo);
989                                         r = GetLastResult();
990                                         TryCatch(!IsFailed(r),,"CreateContent::the value is %s", GetErrorMessage(r));
991                                         if (!isCopyOperation)
992                                         {
993                                                 r = __pContentManager->DeleteContent(contentId);
994                                                 TryCatch(!IsFailed(r),,"DeleteContent::the value is %s", GetErrorMessage(r));
995                                         }
996                                 }
997                         }
998                 }
999         }
1000         else if (pContentInfo->GetContentType() == CONTENT_TYPE_VIDEO)
1001         {
1002                 r = File::Copy(filePath, destPath, false);
1003                 if (r == E_SUCCESS)
1004                 {
1005                         VideoContentInfo contentInfo;
1006                         r = contentInfo.Construct(&destPath);
1007                         {
1008                                 __pContentManager->CreateContent(contentInfo);
1009                                 r = GetLastResult();
1010                                 TryCatch(!IsFailed(r),,"CreateContent::the value is %s", GetErrorMessage(r));
1011                                 if (!isCopyOperation)
1012                                 {
1013                                         r = __pContentManager->DeleteContent(contentId);
1014                                         TryCatch(!IsFailed(r),,"DeleteContent::the value is %s", GetErrorMessage(r));
1015                                 }
1016                         }
1017                 }
1018         }
1019         CATCH:
1020         delete pContentInfo;
1021
1022         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1023
1024         return r;
1025 }
1026
1027 result
1028 FileListPresentationModel::StartAppControl(const String& providerId, const String& operationId,
1029                 const String* pUriData, const Tizen::Base::String* pMimeType, const HashMap* pDataList,
1030                 IAppControlResponseListener* pListener)
1031 {
1032         AppLogDebug("ENTER");
1033         AppControl* pAc = AppManager::FindAppControlN(providerId, operationId);
1034         __providerId.Clear();\r
1035         __providerId.Append(providerId);\r
1036 \r
1037         if (pAc == null)
1038         {
1039                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1040                 return E_FAILURE;
1041         }
1042         result r = pAc->Start(pUriData, pMimeType, pDataList, pListener);
1043
1044         if (r == E_SUCCESS)
1045         {
1046                 GalleryApp* pGalleryApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
1047                 pGalleryApp->SetFrameEnabled(false);
1048         }
1049
1050         delete pAc;
1051
1052         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1053
1054         return r;
1055 }
1056
1057 result
1058 FileListPresentationModel::SetCurrentAlbumInfo(const String& albumName, const IList& directoryList)
1059 {
1060         AppLogDebug("ENTER");
1061
1062         if (&directoryList != null)
1063         {
1064                 if (__pDirectoryList != null && __pDirectoryList->GetCount() > 0)
1065                 {
1066                         bool isMatched = false;
1067                         int outterLoopCount = __pDirectoryList->GetCount();
1068                         int innerLoopCount = 0;
1069                         for (int i = 0; i < outterLoopCount ; ++i)
1070                         {
1071                                 isMatched = false;
1072                                 innerLoopCount = directoryList.GetCount();
1073                                 for (int j = 0; j < innerLoopCount; ++j)
1074                                 {
1075                                         if (static_cast<String*>(__pDirectoryList->GetAt(i))->CompareTo(
1076                                                         *(const_cast<String*>(static_cast<const String*>(directoryList.GetAt(j))))) == 0)
1077                                         {
1078                                                 isMatched = true;
1079                                                 break;
1080                                         }
1081                                 }
1082                         }
1083
1084                         outterLoopCount = directoryList.GetCount();
1085                         for (int i = 0; i < outterLoopCount; ++i)
1086                         {
1087                                 isMatched = false;
1088                                 innerLoopCount = __pDirectoryList->GetCount();
1089                                 for (int j = 0; j < innerLoopCount; ++j)
1090                                 {
1091                                         if (const_cast<String*>(static_cast<const String*>(directoryList.GetAt(i)))->CompareTo(
1092                                                         *(static_cast<String*>(__pDirectoryList->GetAt(j)))) == 0)
1093                                         {
1094                                                 isMatched = true;
1095                                                 break;
1096                                         }
1097                                 }
1098                         }
1099                 }
1100         }
1101
1102         __albumName = albumName;
1103         __providerId.Clear();\r
1104
1105         if (__pDirectoryList != null)
1106         {
1107                 delete __pDirectoryList;
1108         }
1109         __pDirectoryList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1110
1111         int loopCount = directoryList.GetCount();
1112         for (int i = 0; i < loopCount; ++i)
1113         {
1114                 __pDirectoryList->Add(new (std::nothrow) String(*(const_cast<String*>
1115                         (static_cast<const String*>(directoryList.GetAt(i))))));
1116         }
1117
1118         if (__pContentInfoList != null)
1119         {
1120                 delete __pContentInfoList;
1121                 __pContentInfoList = null;
1122         }
1123
1124         if (GetAppControlMode() == APPCONTROL_MODE_PICK)
1125         {
1126                 AppControlMediaType appControlMediaType = GetAppControlMediaType();
1127                 if (appControlMediaType == APPCONTROL_MEDIA_TYPE_IMAGE)
1128                 {
1129                         __albumContentType = CONTENT_TYPE_IMAGE;
1130                 }
1131                 else if (appControlMediaType == APPCONTROL_MEDIA_TYPE_VIDEO)
1132                 {
1133                         __albumContentType = CONTENT_TYPE_VIDEO;
1134                 }
1135         }
1136         __pContentInfoList = GetContentInfoListInDirectoryListN(*__pDirectoryList, __albumContentType);
1137         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1138
1139         return E_SUCCESS;
1140 }
1141
1142 result
1143 FileListPresentationModel::RefreshCurrentAlbumContentInfoList(const ContentType contentType)
1144 {
1145         AppLogDebug("ENTER");
1146         result r = RefreshContentInfoList(contentType);
1147         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1148
1149         return r;
1150 }
1151
1152 result
1153 FileListPresentationModel::RefreshContentInfoList(const ContentType contentType)
1154 {
1155         AppLogDebug("ENTER");
1156         if ((contentType != CONTENT_TYPE_ALL) && (contentType != CONTENT_TYPE_IMAGE) && (contentType != CONTENT_TYPE_VIDEO))
1157         {
1158                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1159
1160                 return E_FAILURE;
1161         }
1162
1163         if ((__pDirectoryList == null) || (__pDirectoryList->GetCount() <= 0))
1164         {
1165                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1166
1167                 return E_SUCCESS;
1168         }
1169
1170         __albumContentType = contentType;
1171
1172         if (__pContentInfoList != null)
1173         {
1174                 delete __pContentInfoList;
1175                 __pContentInfoList = null;
1176         }
1177         __pContentInfoList = GetContentInfoListInDirectoryListN(*__pDirectoryList, __albumContentType);
1178         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1179
1180         return E_SUCCESS;
1181 }
1182
1183 String
1184 FileListPresentationModel::GetCurrentAlbumName(void) const
1185 {
1186         AppLogDebug("ENTER");
1187         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1188
1189         return __albumName;
1190 }
1191
1192 void
1193 FileListPresentationModel::SetCurrentAlbumName(const String& albumName)
1194 {
1195         AppLogDebug("ENTER");
1196         if (&albumName == null)
1197         {
1198                 __albumName = EMPTY_SPACE;
1199         }
1200         else
1201         {
1202                 __albumName = albumName;
1203         }
1204         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1205 }
1206
1207 ContentType
1208 FileListPresentationModel::GetCurrentAlbumContentType(void) const
1209 {
1210         AppLogDebug("ENTER");
1211         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1212
1213         return __albumContentType;
1214 }
1215
1216 void
1217 FileListPresentationModel::SetCurrentAlbumContentType(const ContentType contentType)
1218 {
1219         AppLogDebug("ENTER");
1220         __albumContentType = contentType;
1221         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1222 }
1223
1224 IList*
1225 FileListPresentationModel::GetAlbumDirectoryListN(void) const
1226 {
1227         AppLogDebug("ENTER");
1228         IList* pAlbumDirectoryList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1229         if (__pDirectoryList == null)
1230         {
1231                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1232
1233                 return pAlbumDirectoryList;
1234         }
1235
1236         String* pDirectory = null;
1237         int loopCount = __pDirectoryList->GetCount();
1238         for (int i = 0; i < loopCount; ++i)
1239         {
1240                 pDirectory = static_cast<String*>(__pDirectoryList->GetAt(i));
1241                 pAlbumDirectoryList->Add(new (std::nothrow) String(*pDirectory));
1242         }
1243         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1244
1245         return pAlbumDirectoryList;
1246 }
1247
1248 IList*
1249 FileListPresentationModel::GetAlbumContentInfoList(void) const
1250 {
1251         AppLogDebug("ENTER");
1252         IList* pContentList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1253         if (__pContentInfoList == null)
1254         {
1255                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1256
1257                 return pContentList;
1258         }
1259
1260         ContentInfo* pContentInfo = null;
1261         int loopCount = __pContentInfoList->GetCount();
1262         for (int i = 0; i < loopCount; ++i)
1263         {
1264                 pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(i));
1265                 pContentList->Add(pContentInfo);
1266         }
1267         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1268
1269         return pContentList;
1270 }
1271
1272 ContentInfo*
1273 FileListPresentationModel::GetContentInfo(const int index) const
1274 {
1275         AppLogDebug("ENTER");
1276         if (__pContentInfoList == null || __pContentInfoList->GetCount() == 0)
1277         {
1278                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1279
1280                 return null;
1281         }
1282
1283         if (index < 0 || index >= __pContentInfoList->GetCount())
1284         {
1285                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1286
1287                 return null;
1288         }
1289         ContentInfo* pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
1290         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1291
1292         return pContentInfo;
1293 }
1294
1295 IList* FileListPresentationModel::GetContentIdListAtIndexN(const IList& indexList) const
1296 {
1297         IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1298         int loopCount = indexList.GetCount();
1299         for (int i = 0; i < loopCount; ++i)
1300         {
1301                 const Integer* pIndex = static_cast<const Integer*>(indexList.GetAt(i));
1302
1303                 if ((pIndex != null) && (pIndex->ToInt())>=0 && __pContentInfoList->GetCount() > pIndex->ToInt())
1304                 {
1305                         pContentIdList->Add(new (std::nothrow) ContentId((static_cast<ContentInfo*>(__pContentInfoList->GetAt(pIndex->ToInt())))->GetContentId()));
1306                 }
1307         }
1308
1309         return pContentIdList;
1310 }
1311
1312 int
1313 FileListPresentationModel::GetCurrentAlbumContentInfoCount(void) const
1314 {
1315         AppLogDebug("ENTER");
1316         if (__pContentInfoList == null)
1317         {
1318                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1319
1320                 return 0;
1321         }
1322         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1323
1324         return __pContentInfoList->GetCount();
1325 }
1326
1327 ContentId
1328 FileListPresentationModel::GetContentInfoIndex(const int index) const
1329 {
1330         AppLogDebug("ENTER");
1331         if (__pContentInfoList == null || __pContentInfoList->GetCount() == 0)
1332         {
1333                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1334
1335                 return 0;
1336         }
1337
1338         if (index < 0 || index >= __pContentInfoList->GetCount())
1339         {
1340                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1341
1342                 return 0;
1343         }
1344         ContentInfo* pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
1345         ContentId contentId = pContentInfo->GetContentId();
1346         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1347
1348         return contentId;
1349 }
1350
1351 String
1352 FileListPresentationModel::GetContentFilePath(const int index) const
1353 {
1354         AppLogDebug("ENTER index(%d)", index);
1355         if (__pContentInfoList == null || __pContentInfoList->GetCount() == 0)
1356         {
1357                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1358
1359                 return EMPTY_SPACE;
1360         }
1361
1362         if (index < 0 || index >= __pContentInfoList->GetCount())
1363         {
1364                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1365
1366                 return EMPTY_SPACE;
1367         }
1368
1369         ContentInfo* pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
1370         String contentPath = pContentInfo->GetContentPath();
1371         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1372
1373         return contentPath;
1374 }
1375
1376 Bitmap*
1377 FileListPresentationModel::CoverVideoOverlayedImageOnThumbnailN(Bitmap& thumbnail,
1378                 const ThumbnailInfo& thumbmailInfo)
1379 {
1380         AppLogDebug("ENTER");
1381         Bitmap* pOverlayedImage = null;
1382
1383         if (&thumbmailInfo != null)
1384         {
1385                 long duration = thumbmailInfo.GetDuration();
1386
1387                 Canvas mainCanvas;
1388                 if (&thumbnail != null)
1389                 {
1390                         BufferInfo bufferInfo;
1391                         thumbnail.Lock(bufferInfo, INFINITE);
1392                         thumbnail.Unlock();
1393                         mainCanvas.Construct(bufferInfo);
1394                 }
1395                 else
1396                 {
1397                         Rectangle mainRect(0, 0, W_DEFAULT_THUMBNAIL, H_DEFAULT_THUMBNAIL);
1398                         mainCanvas.Construct(mainRect);
1399                         mainCanvas.FillRectangle(Color::GetColor(COLOR_ID_BLACK), mainRect);
1400                 }
1401
1402                 Rectangle playRect(GAP_W_PLAY_FG, GAP_H_PLAY_FG, W_PLAY_FG, H_PLAY_FG);
1403                 Bitmap* playBitmap = ResourceManager::GetBitmapN(IDB_VIDEOTHUMBNAIL_PLAY);
1404                 if (playBitmap != null)
1405                 {
1406                         mainCanvas.DrawBitmap(playRect, *playBitmap);
1407                         delete playBitmap;
1408                 }
1409
1410                 Canvas durCanvas;
1411                 Rectangle durSize(0, 0, W_DURATION, H_DURATION);
1412                 Rectangle durRect(0, GAP_H_DURATION, W_DURATION, H_DURATION);
1413                 Color durColor(COLOR_DURATION_BG);
1414                 durColor.SetAlpha(ALPHA_DURATION);
1415                 durCanvas.Construct(durSize);
1416                 durCanvas.FillRectangle(durColor, durSize);
1417                 Font durFont;
1418                 durFont.Construct(FONT_STYLE_PLAIN, FONT_SIZE_DURATION);
1419                 durCanvas.SetFont(durFont);
1420                 durCanvas.DrawText(Point(W_DURATION_TEXT, H_DURATION_TEXT),
1421                                 CommonUtil::DurationToTimeString(duration), COLOR_TEXT_OUTLINE);
1422                 Bitmap durBitmap;
1423                 durBitmap.Construct(durCanvas, durCanvas.GetBounds());
1424                 mainCanvas.DrawBitmap(durRect, durBitmap);
1425
1426                 pOverlayedImage = new (std::nothrow) Bitmap();
1427                 pOverlayedImage->Construct(mainCanvas, mainCanvas.GetBounds());
1428         }
1429         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1430
1431         return pOverlayedImage;
1432 }
1433
1434 Bitmap*
1435 FileListPresentationModel::GetShadedBackgroundBitmapN(Bitmap& bgBitmap,
1436                 const Bitmap& originalBitmap, const Rectangle& originalBitmapPosition) const
1437 {
1438         AppLogDebug("ENTER");
1439         if (&originalBitmap == null || &originalBitmap == null)
1440         {
1441                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1442
1443                 return null;
1444         }
1445
1446         BufferInfo bufferInfo;
1447         bgBitmap.Lock(bufferInfo, INFINITE);
1448         bgBitmap.Unlock();
1449         Canvas mainCanvas;
1450         mainCanvas.Construct(bufferInfo);
1451         mainCanvas.Clear();
1452         mainCanvas.DrawBitmap(originalBitmapPosition, originalBitmap);
1453
1454         Bitmap* pMainImage = new (std::nothrow) Bitmap();
1455         pMainImage->Construct(mainCanvas,mainCanvas.GetBounds());
1456         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1457
1458         return pMainImage;
1459 }
1460
1461 IList*
1462 FileListPresentationModel::GetContentInfoListInDirectoryListN(const IList& contentDirectoryList,
1463                 ContentType contentType)const
1464 {
1465         AppLogDebug("ENTER");
1466         IList* pContentList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1467
1468         if ((&contentDirectoryList == null) || (contentDirectoryList.GetCount() == 0)
1469                         || ((contentType != CONTENT_TYPE_IMAGE) && (contentType != CONTENT_TYPE_VIDEO) && (contentType != CONTENT_TYPE_ALL)))
1470         {
1471                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1472                 return pContentList;
1473         }
1474
1475         ContentDirectory contentDirectory;
1476         IListT<ContentType>* pContentTypeList = new (std::nothrow) ArrayListT<ContentType>();
1477         if (contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_ALL)
1478         {
1479                 pContentTypeList->Add(CONTENT_TYPE_IMAGE);
1480         }
1481         if (contentType == CONTENT_TYPE_VIDEO || contentType == CONTENT_TYPE_ALL)
1482         {
1483                 pContentTypeList->Add(CONTENT_TYPE_VIDEO);
1484         }
1485         result r = contentDirectory.Construct(*pContentTypeList);
1486         delete pContentTypeList;
1487
1488         if (r == E_SUCCESS)
1489         {
1490                 int pageNo = SIZE_PAGE_NO;
1491                 int countPerPage = SIZE_CONUNT_PER_PAGE;
1492                 String* pContentDirectory = null;
1493
1494                 int loopCount = contentDirectoryList.GetCount();
1495                 for (int i = 0; i < loopCount; ++i)
1496                 {
1497                         IList* pIList = null;
1498                         pContentDirectory = const_cast<String*>(static_cast<const String*>(contentDirectoryList.GetAt(i)));
1499                         if (pContentDirectory != null)
1500                         {
1501                                 pIList = contentDirectory.GetContentDirectoryItemListN(*pContentDirectory, pageNo, countPerPage,
1502                                                 CONTENT_INFO_ORDER, SORT_ORDER_NONE);
1503
1504                                 if (pIList != null)
1505                                 {
1506                                         pContentList->AddItems(*pIList);
1507                                 }
1508                         }
1509                 }
1510         }
1511         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1512
1513         return pContentList;
1514 }
1515
1516 String
1517 FileListPresentationModel::ConvertToAlbumName(const String& targetPath)const
1518 {
1519         AppLogDebug("ENTER");
1520         String albumName;
1521         if (&targetPath == null || targetPath.GetLength() == 0)
1522         {
1523                 return albumName;
1524         }
1525
1526         if (targetPath == RESERVED_CAMERA_PATH || targetPath == RESERVED_CAMERA_PATH_EXT)
1527         {
1528                 albumName = ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB");
1529         }
1530         else if (targetPath == RESERVED_DOWNLOAD_PATH)
1531         {
1532                 albumName = ResourceManager::GetString(L"IDS_COM_BODY_DOWNLOADS");
1533         }
1534         else
1535         {
1536                 String directoryName = GetDirecotyNameFromFullPath(targetPath);
1537                 albumName = directoryName;
1538         }
1539
1540         return albumName;
1541 }
1542
1543 AppControlMode
1544 FileListPresentationModel::GetAppControlMode(void) const
1545 {
1546         AppLogDebug("Enter");
1547         AppLogDebug("Exit");
1548
1549         return __appControlMode;
1550 }
1551
1552 AppControlMediaType
1553 FileListPresentationModel::GetAppControlMediaType(void) const
1554 {
1555         AppLogDebug("Enter");
1556         AppLogDebug("Exit");
1557
1558         return __appControlMediaType;
1559 }
1560
1561 AppControlSelectionMode
1562 FileListPresentationModel::GetAppControlSelectionMode(void) const
1563 {
1564         AppLogDebug("Enter");
1565         AppLogDebug("Exit");
1566
1567         return __appControlSelectionMode;
1568 }
1569
1570 void
1571 FileListPresentationModel::SetUpdateProgressStatus(const bool status)
1572 {
1573         AppLogDebug("ENTER status = %d",status);
1574         __updateProgressStatus = status;
1575         AppLogDebug("EXIT");
1576 }
1577
1578 result
1579 FileListPresentationModel::RotateImage(int index, RotateMode rotateMode)
1580 {
1581         result r = E_SUCCESS;
1582         ImageBuffer rotateBuffer;
1583         ImageBuffer* pRotatedBuffer = null;
1584         ImageFormat imageFormat;
1585         Image img;
1586         String filePath = GetContentFilePath(index);
1587         r = img.Construct();
1588
1589
1590         if (r == E_SUCCESS)
1591         {
1592                 imageFormat = img.GetImageFormat(filePath);
1593         }
1594
1595         r = rotateBuffer.Construct(filePath);
1596         if (r == E_SUCCESS)
1597         {
1598                 if (rotateMode == ROTATE_MODE_RIGHT)
1599                 {
1600                         pRotatedBuffer = rotateBuffer.RotateN(IMAGE_ROTATION_90);
1601                 }
1602                 else
1603                 {
1604                         pRotatedBuffer = rotateBuffer.RotateN(IMAGE_ROTATION_270);
1605                 }
1606         }
1607
1608         if (pRotatedBuffer != null)
1609         {
1610                 r = pRotatedBuffer->EncodeToFile(filePath, imageFormat, true, 100);
1611                 delete pRotatedBuffer;
1612         }
1613
1614         ContentManager::ScanFile(filePath);
1615         return r;
1616 }\r
1617 \r
1618 void\r
1619 FileListPresentationModel::ClearImageCache(void)\r
1620 {\r
1621         AppLogDebug("FileListPresentationModel::ClearImageCache ++");\r
1622 \r
1623         if(__pIconListViewCache != null && __providerId.Equals(APPCONTROL_PROVIDER_ID_IMAGE, false) == true)\r
1624         {\r
1625                 bool clearThumbnailReq = true;\r
1626                 while(__pIconListViewCache->GetCount() != 0)\r
1627                 {\r
1628                         //This is to Clear the Thumbnail Reuqests only Once\r
1629                         if(clearThumbnailReq == true)\r
1630                         {\r
1631                                 ClearThumbnailRequests();\r
1632                                 clearThumbnailReq = false;\r
1633                         }\r
1634                         __pIconListViewCache->RemoveAt(0, true);\r
1635                 }\r
1636         }\r
1637         AppLogDebug("FileListPresentationModel::ClearImageCache --");\r
1638 }
1639
1640 void
1641 FileListPresentationModel::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
1642 {
1643         AppLogDebug("ENTER");
1644         if (deviceType == DEVICE_TYPE_STORAGE_CARD && state == DEVICE_STORAGE_CARD_UNMOUNTED)
1645         {
1646                 IFormContentUpdateEventListener* pInterface = null;
1647                 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1648                 while (pEventEnum->MoveNext() == E_SUCCESS)
1649                 {
1650                         pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1651                         pInterface->OnContentUpdated();
1652                 }
1653                 delete pEventEnum;
1654         }
1655         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1656 }