2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 * @file FCnt_ContentDirectoryImpl.cpp
19 * @brief This is the implementation file for the %_ContentDirectoryImpl class.
21 * This file contains implementation of the %_ContentDirectoryImpl class.
24 #include <FBaseSysLog.h>
25 #include <FBaseInteger.h>
26 #include <FBaseLongLong.h>
27 #include <FBaseFloat.h>
28 #include <FBaseColIList.h>
29 #include <FBaseColIEnumeratorT.h>
30 #include <FCntContentDirectory.h>
31 #include <FCntContentSearchResult.h>
32 #include <FSysEnvironment.h>
33 #include <FBase_StringConverter.h>
34 #include <FCnt_ContentUtility.h>
35 #include <FCnt_ContentDirectoryImpl.h>
37 using namespace Tizen::Base;
38 using namespace Tizen::Base::Collection;
39 using namespace Tizen::Io;
40 using namespace Tizen::System;
42 namespace Tizen { namespace Content
44 // Declaration for Callback function registered to each media info details
45 bool MediaFoldersCb(media_folder_h folder, void* pUserdata);
46 // Declaration for Callback function registered to each media info details
47 bool MediaFolderItemsCb(media_info_h media, void* pUserdata);
49 _ContentDirectoryImpl::_ContentDirectoryImpl(void)
51 , __pFilterHandle(null)
52 , __pFinalOutList(null)
53 , __contentType(CONTENT_TYPE_UNKNOWN)
54 , __isMultiContentType(false)
55 , __multiContentTypeExpr(L"")
60 // (disconnects the DB connection)
61 _ContentDirectoryImpl::~_ContentDirectoryImpl(void)
63 int ret = MEDIA_CONTENT_ERROR_NONE;
66 ret = media_content_disconnect();
67 r = MapCoreErrorToNativeResult(ret);
68 SysTryLog(NID_CNT, r == E_SUCCESS, "[%s] Propagating for media_content_disconnect.", GetErrorMessage(r));
71 _ContentDirectoryImpl*
72 _ContentDirectoryImpl::GetInstance(ContentDirectory& contentDirectory)
74 return (&contentDirectory != null) ? contentDirectory.__pImpl : null;
77 const _ContentDirectoryImpl*
78 _ContentDirectoryImpl::GetInstance(const ContentDirectory& contentDirectory)
80 return (&contentDirectory != null) ? contentDirectory.__pImpl : null;
83 //make a connection to DB
85 _ContentDirectoryImpl::Construct(ContentType type)
88 int ret = MEDIA_CONTENT_ERROR_NONE;
90 ret = media_content_connect();
91 r = MapCoreErrorToNativeResult(ret);
92 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Propagating for media_content_connect.");
95 __isMultiContentType = false;
96 __multiContentTypeExpr.Clear();
101 //make a connection to DB
103 _ContentDirectoryImpl::Construct(const Tizen::Base::Collection::IListT<ContentType>& contentTypeList)
105 result r = E_SUCCESS;
106 int ret = MEDIA_CONTENT_ERROR_NONE;
107 ContentType contentType = CONTENT_TYPE_UNKNOWN;
109 ret = media_content_connect();
110 r = MapCoreErrorToNativeResult(ret);
111 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Propagating for media_content_connect.");
113 __multiContentTypeExpr.Clear();
115 std::unique_ptr<IEnumeratorT<ContentType> > pEnum(contentTypeList.GetEnumeratorN());
117 while ((pEnum.get() != NULL) && (pEnum->MoveNext() == E_SUCCESS))
119 if (!__multiContentTypeExpr.IsEmpty())
121 r = __multiContentTypeExpr.Append("OR ");
122 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform Append operation.");
124 pEnum->GetCurrent(contentType);
127 // Image-0,video-1,sound-2,music-3,other-4
128 case CONTENT_TYPE_OTHER:
129 r = __multiContentTypeExpr.Append("MEDIA_TYPE=4 ");
130 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform Append operation.");
132 case CONTENT_TYPE_IMAGE:
133 r = __multiContentTypeExpr.Append("MEDIA_TYPE=0 ");
134 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform Append operation.");
136 case CONTENT_TYPE_AUDIO:
137 r = __multiContentTypeExpr.Append("(MEDIA_TYPE=2 or MEDIA_TYPE=3) ");
138 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform Append operation.");;
140 case CONTENT_TYPE_VIDEO:
141 r = __multiContentTypeExpr.Append("MEDIA_TYPE=1 ");
142 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform Append operation.");
144 case CONTENT_TYPE_ALL:
145 //If content type is CONTENT_TYPE_ALL, then MEDIA_TYPE is empty
152 r = __multiContentTypeExpr.Insert('(', 0);
153 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform Append operation.");
155 r = __multiContentTypeExpr.Insert(')', __multiContentTypeExpr.GetLength());
156 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform Append operation.");
158 __isMultiContentType = true;
164 _ContentDirectoryImpl::CreateFolderFilter(bool isMultiContentType, const Tizen::Base::String& inputFolderPath) const
166 result r = E_SUCCESS;
167 std::unique_ptr<filter_h, FilterHandleDeleter> pFilterHandle(new (std::nothrow) filter_h);
168 int ret = MEDIA_CONTENT_ERROR_NONE;
169 String inputCondition = L"";
170 String folderPath(inputFolderPath);
172 ret = media_filter_create(pFilterHandle.get());
173 r = MapCoreErrorToNativeResult(ret);
174 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, r, "Failed to perform media_filter_create operation.");
176 if (isMultiContentType)
178 r = inputCondition.Append(__multiContentTypeExpr);
179 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform Append operation.");
183 switch (__contentType)
185 // Image-0,video-1,sound-2,music-3,other-4
186 case CONTENT_TYPE_OTHER:
187 inputCondition = "MEDIA_TYPE=4 ";
189 case CONTENT_TYPE_IMAGE:
190 inputCondition = "MEDIA_TYPE=0 ";
192 case CONTENT_TYPE_AUDIO:
193 inputCondition = "(MEDIA_TYPE=2 or MEDIA_TYPE=3) ";
195 case CONTENT_TYPE_VIDEO:
196 inputCondition = "MEDIA_TYPE=1 ";
198 case CONTENT_TYPE_ALL:
199 //If content type is CONTENT_TYPE_ALL, then MEDIA_TYPE is empty
206 if (!folderPath.IsEmpty())
208 if (!inputCondition.IsEmpty()) //For CONTENT_TYPE_ALL inputCondition is empty
210 r = inputCondition.Append("AND FOLDER_PATH = ");
211 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform Append operation.");
215 r = inputCondition.Append("FOLDER_PATH = ");
216 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform Append operation.");
219 r = folderPath.Insert('"', 0);
220 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform Insert operation.");
221 r = folderPath.Insert('"', folderPath.GetLength());
222 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform Insert operation.");
224 r = inputCondition.Append(folderPath);
225 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform Append operation.");
228 if (!inputCondition.IsEmpty())
230 //CopyToCharArrayN: utility function, converts a osp string to char*
231 std::unique_ptr<char[]> pInputCond(_StringConverter::CopyToCharArrayN(inputCondition));
232 SysTryReturnResult(NID_CNT, (pInputCond.get())[0] != null, E_SYSTEM, "pInputCond is NULL.");
234 SysLog(NID_CNT, "pInputCond is [%s].", pInputCond.get());
236 if ((pInputCond.get())[0] != null)
238 ret = media_filter_set_condition(*(pFilterHandle.get()), pInputCond.get(), MEDIA_CONTENT_COLLATE_DEFAULT);
239 r = MapCoreErrorToNativeResult(ret);
240 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, r, "Failed to perform media_filter_set_condition operation.");
244 __pFilterHandle.reset(pFilterHandle.release());
250 _ContentDirectoryImpl::GetContentDirectoryCount(void) const
252 int directoryCount = 0;
253 result r = E_SUCCESS;
254 int ret = MEDIA_CONTENT_ERROR_NONE;
256 r = CreateFolderFilter(__isMultiContentType, L"");
257 SysTryReturnResult(NID_CNT, !IsFailed(r), E_SYSTEM, "Propagating for CreateFolderFilter.");
259 ret = media_folder_get_folder_count_from_db(*(__pFilterHandle.get()), &directoryCount);
260 r = MapCoreErrorToNativeResult(ret);
261 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, r, "Failed to perform media_folder_get_folder_count_from_db operation.");
263 SysLog(NID_CNT, "directoryCount is [%d].", directoryCount);
266 return directoryCount;
270 _ContentDirectoryImpl::GetContentDirectoryPathListN(Tizen::Base::SortOrder sortOrder) const
272 result r = E_SUCCESS;
273 int ret = MEDIA_CONTENT_ERROR_NONE;
274 std::unique_ptr<GList, GListDeleter> pItemList;
275 GList* pTempList = null;
276 std::unique_ptr<char> pFolderPath;
277 char* pTempFolderPath = null;
278 std::unique_ptr<media_folder_s, FolderHandleDeleter> pFolderHandle;
279 std::unique_ptr<Object> pValue;
281 __pFinalOutList = std::unique_ptr<ArrayList, AllElementsDeleter>(new (std::nothrow) ArrayList());
282 SysTryReturn(NID_CNT, __pFinalOutList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] FinalOutList is null.");
284 r = __pFinalOutList->Construct();
285 SysTryReturn(NID_CNT, r == E_SUCCESS, null, r, "[%s] Failed to construct __pFinalOutList ArrayList.", GetErrorMessage(r));
287 r = CreateFolderFilter(__isMultiContentType, L"");
288 SysTryReturn(NID_CNT, !IsFailed(r), null, E_SYSTEM, "[E_SYSTEM] Failed to perform CreateFolderFilter operation.");
290 if (sortOrder == SORT_ORDER_ASCENDING)
292 ret = media_filter_set_order(*(__pFilterHandle.get()), MEDIA_CONTENT_ORDER_ASC, MEDIA_PATH, MEDIA_CONTENT_COLLATE_DEFAULT);
293 r = MapCoreErrorToNativeResult(ret);
294 SysTryReturn(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, null, r,
295 "[%s] Failed to perform media_filter_set_order operation.", GetErrorMessage(r));
297 else if (sortOrder == SORT_ORDER_DESCENDING)
299 ret = media_filter_set_order(*(__pFilterHandle.get()), MEDIA_CONTENT_ORDER_DESC, MEDIA_PATH, MEDIA_CONTENT_COLLATE_DEFAULT);
300 r = MapCoreErrorToNativeResult(ret);
301 SysTryReturn(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, null, r,
302 "[%s] Failed to perform media_filter_set_order operation.", GetErrorMessage(r));
305 pTempList = pItemList.get();
306 ret = media_folder_foreach_folder_from_db(*(__pFilterHandle.get()), MediaFoldersCb, &pTempList);
307 r = MapCoreErrorToNativeResult(ret);
308 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] Failed to perform media_folder_foreach_folder_from_db operation.", GetErrorMessage(r));
310 SysTryReturn(NID_CNT, pTempList != NULL, null, r, "[%s] pItemList for media_folder_foreach_folder_from_db is null.", GetErrorMessage(r));
312 for (int idx = 0; idx < (int)g_list_length(pTempList); idx++)
314 pFolderHandle.reset(static_cast<media_folder_h>(g_list_nth_data(pTempList, idx)));
316 if (pFolderHandle.get() != NULL)
318 pTempFolderPath = pFolderPath.get();
319 ret = media_folder_get_path(pFolderHandle.get(), &pTempFolderPath);
320 r = MapCoreErrorToNativeResult(ret);
321 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] Failed to perform media_folder_get_path operation.", GetErrorMessage(r));
323 if (pTempFolderPath != NULL)
325 SysLog(NID_CNT, "pFolderPath is [%s].", pTempFolderPath);
327 pValue = std::unique_ptr<Object>(new (std::nothrow) String(pTempFolderPath));
331 r = __pFinalOutList->Add(*(pValue.release()));
332 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] Failed to perform Add operation to __pFinalOutList.", GetErrorMessage(r));
338 return __pFinalOutList.release();
342 _ContentDirectoryImpl::GetContentDirectoryItemCount(const Tizen::Base::String& contentDirectoryPath) const
344 SysLog(NID_CNT, "contentDirectoryPath is [%ls]", contentDirectoryPath.GetPointer());
346 int directoryItemCount = 0;
347 result r = E_SUCCESS;
348 int ret = MEDIA_CONTENT_ERROR_NONE;
349 GList* pItemList = NULL;
350 std::unique_ptr<char> pFolderId;
351 char* pTempFolderId = null;
352 std::unique_ptr<media_folder_s, FolderHandleDeleter> pFolderHandle;
354 SysTryReturn(NID_CNT, CheckMediaPath(contentDirectoryPath), directoryItemCount, E_INVALID_ARG,
355 "[E_INVALID_ARG] Failed to perform CheckMediaPath operation.");
357 r = CreateFolderFilter(__isMultiContentType, contentDirectoryPath);
358 SysTryReturn(NID_CNT, !IsFailed(r), directoryItemCount, E_SYSTEM, "[E_SYSTEM] Failed to perform CreateFolderFilter operation.");
360 ret = media_folder_foreach_folder_from_db(*(__pFilterHandle.get()), MediaFoldersCb, &pItemList);
361 r = MapCoreErrorToNativeResult(ret);
362 SysTryReturn(NID_CNT, r == E_SUCCESS, directoryItemCount, r,
363 "[%s] Failed to perform media_folder_foreach_folder_from_db operation.", GetErrorMessage(r));
365 SysTryReturn(NID_CNT, pItemList != NULL, directoryItemCount, r,
366 "[%s] pItemList for media_folder_foreach_folder_from_db is null.", GetErrorMessage(r));
368 for (int idx = 0; idx < (int)g_list_length(pItemList); idx++)
370 SysLog(NID_CNT, "idx is [%d] and (int)g_list_length(pItemList) is [%d].", idx, (int)g_list_length(pItemList));
372 pFolderHandle.reset(static_cast<media_folder_h>(g_list_nth_data(pItemList, idx)));
374 if (pFolderHandle.get() != NULL)
376 pTempFolderId = pFolderId.get();
377 ret = media_folder_get_folder_id(pFolderHandle.get(), &pTempFolderId);
378 r = MapCoreErrorToNativeResult(ret);
379 SysTryReturn(NID_CNT, !IsFailed(r), directoryItemCount, r,
380 "[%s] Failed to perform media_folder_get_folder_id operation.", GetErrorMessage(r));
385 SysTryReturn(NID_CNT, r != E_SUCCESS, directoryItemCount, r, "[E_SYSTEM] pFolderHandle is null.");
389 if (pTempFolderId != NULL)
391 r = CreateFolderFilter(__isMultiContentType, L"");
392 SysTryReturn(NID_CNT, !IsFailed(r), directoryItemCount, E_SYSTEM, "[E_SYSTEM] Failed to perform CreateFolderFilter operation.");
394 ret = media_folder_get_media_count_from_db(pTempFolderId, *(__pFilterHandle.get()), &directoryItemCount);
395 r = MapCoreErrorToNativeResult(ret);
396 SysTryReturn(NID_CNT, !IsFailed(r), directoryItemCount, r,
397 "[%s] Failed to perform media_folder_get_media_count_from_db operation.", GetErrorMessage(r));
400 SysLog(NID_CNT, "directoryItemCount is [%d].", directoryItemCount);
403 return directoryItemCount;
406 // Osp column names are mapped with slp column names
407 // CONTENT_TYPE_OTHER and CONTENT_TYPE_IMAGE (0 - 13 ) are valid columns
408 // CONTENT_TYPE_VIDEO (0 - 16 ) are valid columns
409 // CONTENT_TYPE_ALL and CONTENT_TYPE_VIDEO (0 - 18 ) are valid columns
410 // if the given osp column is out of the specified range of the type, E_INVALID_ARG is retuned.
412 _ContentDirectoryImpl::GetSlpColumnName(String& inputCol, String sortCol) const
414 String ospColumnName(L"");
415 String slpColumnName(L"");
416 String columnName(sortCol);
417 result r = E_SUCCESS;
418 int maxCols = MAX_QUERY_COLUMNS;
420 if(!__isMultiContentType)
422 switch (__contentType)
424 case CONTENT_TYPE_OTHER:
426 case CONTENT_TYPE_IMAGE:
427 maxCols = MAX_QUERY_COLUMNS_FOR_IMAGE_OTHERS;
429 case CONTENT_TYPE_VIDEO:
430 maxCols = MAX_QUERY_COLUMNS_FOR_VIDEO;
432 case CONTENT_TYPE_AUDIO:
434 case CONTENT_TYPE_ALL:
435 maxCols = MAX_QUERY_COLUMNS;
443 if(!__multiContentTypeExpr.IsEmpty())
445 if(__multiContentTypeExpr.Contains("MEDIA_TYPE=2"))
447 maxCols = MAX_QUERY_COLUMNS;
449 else if(__multiContentTypeExpr.Contains("MEDIA_TYPE=1"))
451 maxCols = MAX_QUERY_COLUMNS_FOR_VIDEO;
453 else if(__multiContentTypeExpr.Contains("MEDIA_TYPE=0"))
455 maxCols = MAX_QUERY_COLUMNS_FOR_IMAGE_OTHERS;
460 for (int colIndex=0; colIndex < maxCols; colIndex++)
462 ospColumnName.Clear();
463 slpColumnName.Clear();
465 ospColumnName = dbfieldinfo[colIndex].dbFieldOspName ;
466 slpColumnName = dbfieldinfo[colIndex].dbFieldSlpName ;
468 ospColumnName.ToUpper();
469 columnName.ToUpper();
471 if (columnName == ospColumnName)
473 inputCol = slpColumnName;
477 return E_INVALID_ARG;
481 _ContentDirectoryImpl::GetContentDirectoryItemListN(const Tizen::Base::String& contentDirectoryPath, int pageNo, int countPerPage,
482 const Tizen::Base::String& column, Tizen::Base::SortOrder sortOrder) const
484 SysLog(NID_CNT, "contentDirectoryPath is [%ls].", contentDirectoryPath.GetPointer());
486 result r = E_SUCCESS;
488 int totalPageCount = 0;
489 int ret = MEDIA_CONTENT_ERROR_NONE;
490 String slpColumn = L"";
491 std::unique_ptr<GList, GListDeleter> pItemList;
492 GList* pTempList = null;
493 std::unique_ptr<char> pFolderId;
494 char* pTempFolderId = null;
495 std::unique_ptr<media_folder_s, FolderHandleDeleter> pFolderHandle;
498 SysTryReturn(NID_CNT, CheckMediaPath(contentDirectoryPath), null, E_INVALID_ARG,
499 "[E_INVALID_ARG] Failed to perform CheckMediaPath operation.");
501 __pFinalOutList = std::unique_ptr<ArrayList, AllElementsDeleter>(new (std::nothrow) ArrayList());
502 SysTryReturn(NID_CNT, __pFinalOutList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] FinalOutList is null.");
504 r = __pFinalOutList->Construct();
505 SysTryReturn(NID_CNT, r == E_SUCCESS, null, r, "[%s] Failed to construct __pFinalOutList ArrayList.", GetErrorMessage(r));
507 r = CreateFolderFilter(__isMultiContentType, contentDirectoryPath);
508 SysTryReturn(NID_CNT, !IsFailed(r), null, E_SYSTEM, "[E_SYSTEM] Failed to perform CreateFolderFilter operation.");
510 if ((!column.IsEmpty()) && (sortOrder != SORT_ORDER_NONE))
512 //__inputColumnName (osp column name) is replaced with slpColumn (slp column name).
513 r = GetSlpColumnName(slpColumn, column);
514 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] Failed to perform GetSlpColumnName operation.", GetErrorMessage(r));
516 //CopyToCharArrayN: utility function, converts a osp string to char*
517 std::unique_ptr<char[]> pSortCol(_StringConverter::CopyToCharArrayN(slpColumn));
518 SysTryReturn(NID_CNT, pSortCol.get() != null, null, E_SYSTEM, "[E_SYSTEM] pFolderId is NULL.");
520 if (sortOrder == SORT_ORDER_ASCENDING)
522 ret = media_filter_set_order(*(__pFilterHandle.get()), MEDIA_CONTENT_ORDER_ASC, pSortCol.get(), MEDIA_CONTENT_COLLATE_DEFAULT);
523 r = MapCoreErrorToNativeResult(ret);
524 SysTryReturn(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, null, r,
525 "[%s] Failed to perform media_filter_set_order operation.", GetErrorMessage(r));
527 else if (sortOrder == SORT_ORDER_DESCENDING)
529 ret = media_filter_set_order(*(__pFilterHandle.get()), MEDIA_CONTENT_ORDER_DESC, pSortCol.get(), MEDIA_CONTENT_COLLATE_DEFAULT);
530 r = MapCoreErrorToNativeResult(ret);
531 SysTryReturn(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, null, r,
532 "[%s] Failed to perform media_filter_set_order operation.", GetErrorMessage(r));
536 pTempList = pItemList.get();
537 ret = media_folder_foreach_folder_from_db(*(__pFilterHandle.get()), MediaFoldersCb, &pTempList);
538 r = MapCoreErrorToNativeResult(ret);
539 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
540 "[%s] Failed to perform media_folder_foreach_folder_from_db operation.", GetErrorMessage(r));
542 if (pTempList != NULL)
544 for (int idx = 0; idx < (int)g_list_length(pTempList); idx++)
546 SysLog(NID_CNT, "idx is [%d] and (int)g_list_length(pItemList) is [%d].", idx, (int)g_list_length(pTempList));
548 pFolderHandle.reset(static_cast<media_folder_h>(g_list_nth_data(pTempList, idx)));
550 if (pFolderHandle.get() != NULL)
552 pTempFolderId = pFolderId.get();
553 ret = media_folder_get_folder_id(pFolderHandle.get(), &pTempFolderId);
554 r = MapCoreErrorToNativeResult(ret);
555 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
556 "[%s] Failed to perform media_folder_get_folder_id operation.", GetErrorMessage(r));
561 SysTryReturn(NID_CNT, r != E_SUCCESS, null, r, "[E_SYSTEM] pFolderHandle is null.");
566 if (pTempFolderId != NULL)
568 r = CreateFolderFilter(__isMultiContentType, L"");
569 SysTryReturn(NID_CNT, !IsFailed(r), null, E_SYSTEM, "[E_SYSTEM] Failed to perform CreateFolderFilter operation.");
571 ret = media_folder_get_media_count_from_db(pTempFolderId, *(__pFilterHandle.get()), &totalCount);
572 r = MapCoreErrorToNativeResult(ret);
573 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
574 "[%s] Failed to perform media_folder_get_media_count_from_db operation.", GetErrorMessage(r));
576 SysLog(NID_CNT, "totalCount is [%d].", totalCount);
581 if ((totalCount % countPerPage) == 0)
583 totalPageCount = totalCount / countPerPage;
587 totalPageCount = (totalCount / countPerPage) + 1;
590 SysTryReturn(NID_CNT, ((pageNo >= 1) && (pageNo <= totalPageCount)) , NULL, E_INVALID_ARG, "[E_INVALID_ARG] (pageNo < 1) || (pageNo > totalPageCount).");
592 offset = (pageNo * countPerPage) - countPerPage;
594 SysLog(NID_CNT, "totalCount [%d] totalPageCount[%d] __countPerPage[%d] __pageNo[%d] offset[%d]",
595 totalCount, totalPageCount, countPerPage, pageNo, offset);
597 ret = media_filter_set_offset(*(__pFilterHandle.get()),offset,countPerPage);
598 r = MapCoreErrorToNativeResult(ret);
599 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] Failed to perform media_filter_set_offset operation.", GetErrorMessage(r));
601 r = FillFinalOutList(pTempFolderId);
602 SysTryReturn(NID_CNT, !IsFailed(r), null, E_SYSTEM, "[E_SYSTEM] Failed to perform FillFinalOutList operation.");
607 SysTryReturn(NID_CNT, !(IsFailed(r)), null, r, "[E_INVALID_ARG] (pageNo > 1) and (totalcount = 0).");
611 return __pFinalOutList.release();
615 _ContentDirectoryImpl::FillFinalOutList(char* pFolderId) const
617 int ret = MEDIA_CONTENT_ERROR_NONE;
618 result r = E_SUCCESS;
619 std::unique_ptr<GList, GListDeleter> pItemList;
620 GList* pTempList = NULL;
621 std::unique_ptr<media_info_s, MediaHandleDeleter> pMediaHandle;
623 ContentInfo::_ContentData* pContentData = null;
624 ImageContentInfo::_ImageContentData* pImageContentData = null;
625 AudioContentInfo::_AudioContentData* pAudioContentData = null;
626 VideoContentInfo::_VideoContentData* pVideoContentData = null;
628 std::unique_ptr<ImageContentInfo> pImageContentInfo;
629 std::unique_ptr<AudioContentInfo> pAudioContentInfo;
630 std::unique_ptr<VideoContentInfo> pVideoContentInfo;
631 std::unique_ptr<OtherContentInfo> pOtherContentInfo;
633 pTempList = pItemList.get();
634 ret = media_folder_foreach_media_from_db(pFolderId, *(__pFilterHandle.get()), MediaFolderItemsCb, &pTempList);
635 r = MapCoreErrorToNativeResult(ret);
636 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform media_folder_foreach_media_from_db operation.");
638 SysTryReturnResult(NID_CNT, pTempList != NULL, r, "pItemList for media_info_foreach_media_from_db is null.");
640 media_content_type_e mediaType;
642 for (int idx = 0; idx < (int)g_list_length(pTempList); idx++)
644 pMediaHandle.reset(static_cast<media_info_h>(g_list_nth_data(pTempList, idx)));
646 ret = media_info_get_media_type(pMediaHandle.get(), &mediaType);
647 r = MapCoreErrorToNativeResult(ret);
648 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform media_info_get_media_type operation.");
652 case MEDIA_CONTENT_TYPE_OTHERS:
653 pOtherContentInfo = std::unique_ptr<OtherContentInfo>(new (std::nothrow) OtherContentInfo);
654 SysTryReturnResult(NID_CNT, pOtherContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pOtherContentInfo.");
656 pContentData = pOtherContentInfo->GetContentData();
657 SysTryReturnResult(NID_CNT, pContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
659 r = _ContentUtility::FillContentData(pMediaHandle.get(), pContentData);
660 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
662 // Shallow copy, adds just the pointer: not the element
663 r = __pFinalOutList->Add(*(pOtherContentInfo.release()));
664 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation to pFinalOutList.");
667 case MEDIA_CONTENT_TYPE_IMAGE:
668 pImageContentInfo = std::unique_ptr<ImageContentInfo>(new (std::nothrow) ImageContentInfo);
669 SysTryReturnResult(NID_CNT, pImageContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pImageContentInfo.");
671 pContentData = pImageContentInfo->GetContentData();
672 SysTryReturnResult(NID_CNT, pContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
674 pImageContentData = pImageContentInfo->GetImageContentData();
675 SysTryReturnResult(NID_CNT, pImageContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
677 r = _ContentUtility::FillContentData(pMediaHandle.get(), pContentData);
678 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
680 r = _ContentUtility::FillImageContentData(pMediaHandle.get(), pImageContentData);
681 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform GetDataFromImageTable operation.");
683 // Shallow copy, adds just the pointer: not the element
684 r = __pFinalOutList->Add(*(pImageContentInfo.release()));
685 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation to __pFinalOutList.");
688 case MEDIA_CONTENT_TYPE_MUSIC:
690 case MEDIA_CONTENT_TYPE_SOUND:
691 pAudioContentInfo = std::unique_ptr<AudioContentInfo>(new (std::nothrow) AudioContentInfo);
692 SysTryReturnResult(NID_CNT, pAudioContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pAudioContentInfo.");
694 pContentData = pAudioContentInfo->GetContentData();
695 SysTryReturnResult(NID_CNT, pContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
697 pAudioContentData = pAudioContentInfo->GetAudioContentData();
698 SysTryReturnResult(NID_CNT, pAudioContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
700 r = _ContentUtility::FillContentData(pMediaHandle.get(), pContentData);
701 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
703 r = _ContentUtility::FillAudioContentData(pMediaHandle.get(), pAudioContentData);
704 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillAudioContentData operation.");
706 // Shallow copy, adds just the pointer: not the element
707 r = __pFinalOutList->Add(*(pAudioContentInfo.release()));
708 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation to __pFinalOutList.");
711 case MEDIA_CONTENT_TYPE_VIDEO:
712 pVideoContentInfo = std::unique_ptr<VideoContentInfo>(new (std::nothrow) VideoContentInfo);
713 SysTryReturnResult(NID_CNT, pVideoContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pVideoContentInfo.");
715 pContentData = pVideoContentInfo->GetContentData();
716 SysTryReturnResult(NID_CNT, pContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
718 pVideoContentData = pVideoContentInfo->GetVideoContentData();
719 SysTryReturnResult(NID_CNT, pVideoContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
721 r = _ContentUtility::FillContentData(pMediaHandle.get(), pContentData);
722 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
724 r = _ContentUtility::FillVideoContentData(pMediaHandle.get(), pVideoContentData);
725 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillVideoContentData operation.");
727 // Shallow copy, adds just the pointer: not the element
728 r = __pFinalOutList->Add(*(pVideoContentInfo.release()));
729 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation to __pFinalOutList.");
741 _ContentDirectoryImpl::CheckMediaPath(const Tizen::Base::String& directoryPath) const
743 String phoneStr = Environment::GetMediaPath();
744 String mmcStr = Environment::GetExternalStoragePath();
746 if (!(directoryPath.StartsWith(phoneStr, 0) || directoryPath.StartsWith(mmcStr , 0)))
749 result r = phoneStr.SubString(0, (phoneStr.GetLength() - 1), checkPhone);
750 SysTryReturn(NID_CNT, !IsFailed(r), false, E_INVALID_ARG, "[E_INVALID_ARG] Failed to substring operation.");
753 r = mmcStr.SubString(0, (mmcStr.GetLength() - 1), checkMmc);
754 SysTryReturn(NID_CNT, !IsFailed(r), false, E_INVALID_ARG, "[E_INVALID_ARG] Failed to substring operation.");
756 SysTryReturn(NID_CNT, (directoryPath.Equals(checkPhone) || directoryPath.Equals(checkMmc)), false, E_INVALID_ARG,
757 "[E_INVALID_ARG] The contentDirectoryPath is not valid[%ls].", directoryPath.GetPointer());
764 _ContentDirectoryImpl::MapCoreErrorToNativeResult(int reason) const
766 result r = E_SUCCESS;
770 case MEDIA_CONTENT_ERROR_NONE:
774 case MEDIA_CONTENT_ERROR_DB_BUSY:
776 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_DB_BUSY");
779 case MEDIA_CONTENT_ERROR_DB_FAILED:
781 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_DB_FAILED");
784 case MEDIA_CONTENT_ERROR_OUT_OF_MEMORY:
786 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_OUT_OF_MEMORY");
790 SysLog(NID_CNT, "default");
797 // Callback function registered to each media info details
798 // all items are appended to the list
800 MediaFoldersCb(media_folder_h folder, void* pUserdata)
802 int ret = MEDIA_CONTENT_ERROR_NONE;
803 media_folder_h new_folder = NULL;
804 ret = media_folder_clone(&new_folder, folder);
805 SysTryLog(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, "[E_SYSTEM] Propagating for media_folder_clone.");
807 GList** pList = (GList**)pUserdata;
808 *pList = g_list_append(*pList, new_folder);
813 // Callback function registered to each media info details
814 // all items are appended to the list
816 MediaFolderItemsCb(media_info_h media, void* pUserdata)
818 int ret = MEDIA_CONTENT_ERROR_NONE;
819 media_info_h new_media = NULL;
820 ret = media_info_clone(&new_media, media);
821 SysTryLog(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, "[E_SYSTEM] Propagating for media_info_clone.");
823 GList** pList = (GList**)pUserdata;
824 *pList = g_list_append(*pList, new_media);