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 String detachedPath = contentDirectoryPath;
359 if (contentDirectoryPath.EndsWith(L"/"))
361 r = detachedPath.Remove(detachedPath.GetLength() - 1, 1);
362 SysTryReturn(NID_CNT, !IsFailed(r), directoryItemCount, E_INVALID_ARG, "[E_INVALID_ARG] Failed to remove the path string.");
365 r = CreateFolderFilter(__isMultiContentType, detachedPath);
366 SysTryReturn(NID_CNT, !IsFailed(r), directoryItemCount, E_SYSTEM, "[E_SYSTEM] Failed to perform CreateFolderFilter operation.");
368 ret = media_folder_foreach_folder_from_db(*(__pFilterHandle.get()), MediaFoldersCb, &pItemList);
369 r = MapCoreErrorToNativeResult(ret);
370 SysTryReturn(NID_CNT, r == E_SUCCESS, directoryItemCount, r,
371 "[%s] Failed to perform media_folder_foreach_folder_from_db operation.", GetErrorMessage(r));
373 SysTryReturn(NID_CNT, pItemList != NULL, directoryItemCount, r,
374 "[%s] pItemList for media_folder_foreach_folder_from_db is null.", GetErrorMessage(r));
376 for (int idx = 0; idx < (int)g_list_length(pItemList); idx++)
378 SysLog(NID_CNT, "idx is [%d] and (int)g_list_length(pItemList) is [%d].", idx, (int)g_list_length(pItemList));
380 pFolderHandle.reset(static_cast<media_folder_h>(g_list_nth_data(pItemList, idx)));
382 if (pFolderHandle.get() != NULL)
384 pTempFolderId = pFolderId.get();
385 ret = media_folder_get_folder_id(pFolderHandle.get(), &pTempFolderId);
386 r = MapCoreErrorToNativeResult(ret);
387 SysTryReturn(NID_CNT, !IsFailed(r), directoryItemCount, r,
388 "[%s] Failed to perform media_folder_get_folder_id operation.", GetErrorMessage(r));
393 SysTryReturn(NID_CNT, r != E_SUCCESS, directoryItemCount, r, "[E_SYSTEM] pFolderHandle is null.");
397 if (pTempFolderId != NULL)
399 r = CreateFolderFilter(__isMultiContentType, L"");
400 SysTryReturn(NID_CNT, !IsFailed(r), directoryItemCount, E_SYSTEM, "[E_SYSTEM] Failed to perform CreateFolderFilter operation.");
402 ret = media_folder_get_media_count_from_db(pTempFolderId, *(__pFilterHandle.get()), &directoryItemCount);
403 r = MapCoreErrorToNativeResult(ret);
404 SysTryReturn(NID_CNT, !IsFailed(r), directoryItemCount, r,
405 "[%s] Failed to perform media_folder_get_media_count_from_db operation.", GetErrorMessage(r));
408 SysLog(NID_CNT, "directoryItemCount is [%d].", directoryItemCount);
411 return directoryItemCount;
414 // Osp column names are mapped with slp column names
415 // CONTENT_TYPE_OTHER and CONTENT_TYPE_IMAGE (0 - 13 ) are valid columns
416 // CONTENT_TYPE_VIDEO (0 - 16 ) are valid columns
417 // CONTENT_TYPE_ALL and CONTENT_TYPE_VIDEO (0 - 18 ) are valid columns
418 // if the given osp column is out of the specified range of the type, E_INVALID_ARG is retuned.
420 _ContentDirectoryImpl::GetSlpColumnName(String& inputCol, String sortCol) const
422 String ospColumnName(L"");
423 String slpColumnName(L"");
424 String columnName(sortCol);
425 result r = E_SUCCESS;
426 int maxCols = MAX_QUERY_COLUMNS;
428 if(!__isMultiContentType)
430 switch (__contentType)
432 case CONTENT_TYPE_OTHER:
434 case CONTENT_TYPE_IMAGE:
435 maxCols = MAX_QUERY_COLUMNS_FOR_IMAGE_OTHERS;
437 case CONTENT_TYPE_VIDEO:
438 maxCols = MAX_QUERY_COLUMNS_FOR_VIDEO;
440 case CONTENT_TYPE_AUDIO:
442 case CONTENT_TYPE_ALL:
443 maxCols = MAX_QUERY_COLUMNS;
451 if(!__multiContentTypeExpr.IsEmpty())
453 if(__multiContentTypeExpr.Contains("MEDIA_TYPE=2"))
455 maxCols = MAX_QUERY_COLUMNS;
457 else if(__multiContentTypeExpr.Contains("MEDIA_TYPE=1"))
459 maxCols = MAX_QUERY_COLUMNS_FOR_VIDEO;
461 else if(__multiContentTypeExpr.Contains("MEDIA_TYPE=0"))
463 maxCols = MAX_QUERY_COLUMNS_FOR_IMAGE_OTHERS;
468 for (int colIndex=0; colIndex < maxCols; colIndex++)
470 ospColumnName.Clear();
471 slpColumnName.Clear();
473 ospColumnName = dbfieldinfo[colIndex].dbFieldOspName ;
474 slpColumnName = dbfieldinfo[colIndex].dbFieldSlpName ;
476 ospColumnName.ToUpper();
477 columnName.ToUpper();
479 if (columnName == ospColumnName)
481 inputCol = slpColumnName;
485 return E_INVALID_ARG;
489 _ContentDirectoryImpl::GetContentDirectoryItemListN(const Tizen::Base::String& contentDirectoryPath, int pageNo, int countPerPage,
490 const Tizen::Base::String& column, Tizen::Base::SortOrder sortOrder) const
492 SysLog(NID_CNT, "contentDirectoryPath is [%ls].", contentDirectoryPath.GetPointer());
494 result r = E_SUCCESS;
496 int totalPageCount = 0;
497 int ret = MEDIA_CONTENT_ERROR_NONE;
498 String slpColumn = L"";
499 std::unique_ptr<GList, GListDeleter> pItemList;
500 GList* pTempList = null;
501 std::unique_ptr<char> pFolderId;
502 char* pTempFolderId = null;
503 std::unique_ptr<media_folder_s, FolderHandleDeleter> pFolderHandle;
506 SysTryReturn(NID_CNT, CheckMediaPath(contentDirectoryPath), null, E_INVALID_ARG,
507 "[E_INVALID_ARG] Failed to perform CheckMediaPath operation.");
509 String detachedPath = contentDirectoryPath;
511 if (contentDirectoryPath.EndsWith(L"/"))
513 r = detachedPath.Remove(detachedPath.GetLength() - 1, 1);
514 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[E_INVALID_ARG] Failed to remove the path string.");
517 __pFinalOutList = std::unique_ptr<ArrayList, AllElementsDeleter>(new (std::nothrow) ArrayList());
518 SysTryReturn(NID_CNT, __pFinalOutList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] FinalOutList is null.");
520 r = __pFinalOutList->Construct();
521 SysTryReturn(NID_CNT, r == E_SUCCESS, null, r, "[%s] Failed to construct __pFinalOutList ArrayList.", GetErrorMessage(r));
523 r = CreateFolderFilter(__isMultiContentType, detachedPath);
524 SysTryReturn(NID_CNT, !IsFailed(r), null, E_SYSTEM, "[E_SYSTEM] Failed to perform CreateFolderFilter operation.");
526 if ((!column.IsEmpty()) && (sortOrder != SORT_ORDER_NONE))
528 //__inputColumnName (osp column name) is replaced with slpColumn (slp column name).
529 r = GetSlpColumnName(slpColumn, column);
530 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] Failed to perform GetSlpColumnName operation.", GetErrorMessage(r));
532 //CopyToCharArrayN: utility function, converts a osp string to char*
533 std::unique_ptr<char[]> pSortCol(_StringConverter::CopyToCharArrayN(slpColumn));
534 SysTryReturn(NID_CNT, pSortCol.get() != null, null, E_SYSTEM, "[E_SYSTEM] pFolderId is NULL.");
536 if (sortOrder == SORT_ORDER_ASCENDING)
538 ret = media_filter_set_order(*(__pFilterHandle.get()), MEDIA_CONTENT_ORDER_ASC, pSortCol.get(), MEDIA_CONTENT_COLLATE_DEFAULT);
539 r = MapCoreErrorToNativeResult(ret);
540 SysTryReturn(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, null, r,
541 "[%s] Failed to perform media_filter_set_order operation.", GetErrorMessage(r));
543 else if (sortOrder == SORT_ORDER_DESCENDING)
545 ret = media_filter_set_order(*(__pFilterHandle.get()), MEDIA_CONTENT_ORDER_DESC, pSortCol.get(), MEDIA_CONTENT_COLLATE_DEFAULT);
546 r = MapCoreErrorToNativeResult(ret);
547 SysTryReturn(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, null, r,
548 "[%s] Failed to perform media_filter_set_order operation.", GetErrorMessage(r));
552 pTempList = pItemList.get();
553 ret = media_folder_foreach_folder_from_db(*(__pFilterHandle.get()), MediaFoldersCb, &pTempList);
554 r = MapCoreErrorToNativeResult(ret);
555 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
556 "[%s] Failed to perform media_folder_foreach_folder_from_db operation.", GetErrorMessage(r));
558 if (pTempList != NULL)
560 for (int idx = 0; idx < (int)g_list_length(pTempList); idx++)
562 SysLog(NID_CNT, "idx is [%d] and (int)g_list_length(pItemList) is [%d].", idx, (int)g_list_length(pTempList));
564 pFolderHandle.reset(static_cast<media_folder_h>(g_list_nth_data(pTempList, idx)));
566 if (pFolderHandle.get() != NULL)
568 pTempFolderId = pFolderId.get();
569 ret = media_folder_get_folder_id(pFolderHandle.get(), &pTempFolderId);
570 r = MapCoreErrorToNativeResult(ret);
571 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
572 "[%s] Failed to perform media_folder_get_folder_id operation.", GetErrorMessage(r));
577 SysTryReturn(NID_CNT, r != E_SUCCESS, null, r, "[E_SYSTEM] pFolderHandle is null.");
582 if (pTempFolderId != NULL)
584 r = CreateFolderFilter(__isMultiContentType, L"");
585 SysTryReturn(NID_CNT, !IsFailed(r), null, E_SYSTEM, "[E_SYSTEM] Failed to perform CreateFolderFilter operation.");
587 ret = media_folder_get_media_count_from_db(pTempFolderId, *(__pFilterHandle.get()), &totalCount);
588 r = MapCoreErrorToNativeResult(ret);
589 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
590 "[%s] Failed to perform media_folder_get_media_count_from_db operation.", GetErrorMessage(r));
592 SysLog(NID_CNT, "totalCount is [%d].", totalCount);
597 if ((totalCount % countPerPage) == 0)
599 totalPageCount = totalCount / countPerPage;
603 totalPageCount = (totalCount / countPerPage) + 1;
606 SysTryReturn(NID_CNT, ((pageNo >= 1) && (pageNo <= totalPageCount)) , NULL, E_INVALID_ARG, "[E_INVALID_ARG] (pageNo < 1) || (pageNo > totalPageCount).");
608 offset = (pageNo * countPerPage) - countPerPage;
610 SysLog(NID_CNT, "totalCount [%d] totalPageCount[%d] __countPerPage[%d] __pageNo[%d] offset[%d]",
611 totalCount, totalPageCount, countPerPage, pageNo, offset);
613 ret = media_filter_set_offset(*(__pFilterHandle.get()),offset,countPerPage);
614 r = MapCoreErrorToNativeResult(ret);
615 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] Failed to perform media_filter_set_offset operation.", GetErrorMessage(r));
617 r = FillFinalOutList(pTempFolderId);
618 SysTryReturn(NID_CNT, !IsFailed(r), null, E_SYSTEM, "[E_SYSTEM] Failed to perform FillFinalOutList operation.");
623 SysTryReturn(NID_CNT, !(IsFailed(r)), null, r, "[E_INVALID_ARG] (pageNo > 1) and (totalcount = 0).");
627 return __pFinalOutList.release();
631 _ContentDirectoryImpl::FillFinalOutList(char* pFolderId) const
633 int ret = MEDIA_CONTENT_ERROR_NONE;
634 result r = E_SUCCESS;
635 std::unique_ptr<GList, GListDeleter> pItemList;
636 GList* pTempList = NULL;
637 std::unique_ptr<media_info_s, MediaHandleDeleter> pMediaHandle;
639 ContentInfo::_ContentData* pContentData = null;
640 ImageContentInfo::_ImageContentData* pImageContentData = null;
641 AudioContentInfo::_AudioContentData* pAudioContentData = null;
642 VideoContentInfo::_VideoContentData* pVideoContentData = null;
644 std::unique_ptr<ImageContentInfo> pImageContentInfo;
645 std::unique_ptr<AudioContentInfo> pAudioContentInfo;
646 std::unique_ptr<VideoContentInfo> pVideoContentInfo;
647 std::unique_ptr<OtherContentInfo> pOtherContentInfo;
649 pTempList = pItemList.get();
650 ret = media_folder_foreach_media_from_db(pFolderId, *(__pFilterHandle.get()), MediaFolderItemsCb, &pTempList);
651 r = MapCoreErrorToNativeResult(ret);
652 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform media_folder_foreach_media_from_db operation.");
654 SysTryReturnResult(NID_CNT, pTempList != NULL, r, "pItemList for media_info_foreach_media_from_db is null.");
656 media_content_type_e mediaType;
658 for (int idx = 0; idx < (int)g_list_length(pTempList); idx++)
660 pMediaHandle.reset(static_cast<media_info_h>(g_list_nth_data(pTempList, idx)));
662 ret = media_info_get_media_type(pMediaHandle.get(), &mediaType);
663 r = MapCoreErrorToNativeResult(ret);
664 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform media_info_get_media_type operation.");
668 case MEDIA_CONTENT_TYPE_OTHERS:
669 pOtherContentInfo = std::unique_ptr<OtherContentInfo>(new (std::nothrow) OtherContentInfo);
670 SysTryReturnResult(NID_CNT, pOtherContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pOtherContentInfo.");
672 pContentData = pOtherContentInfo->GetContentData();
673 SysTryReturnResult(NID_CNT, pContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
675 r = _ContentUtility::FillContentData(pMediaHandle.get(), pContentData);
676 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
678 // Shallow copy, adds just the pointer: not the element
679 r = __pFinalOutList->Add(*(pOtherContentInfo.release()));
680 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation to pFinalOutList.");
683 case MEDIA_CONTENT_TYPE_IMAGE:
684 pImageContentInfo = std::unique_ptr<ImageContentInfo>(new (std::nothrow) ImageContentInfo);
685 SysTryReturnResult(NID_CNT, pImageContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pImageContentInfo.");
687 pContentData = pImageContentInfo->GetContentData();
688 SysTryReturnResult(NID_CNT, pContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
690 pImageContentData = pImageContentInfo->GetImageContentData();
691 SysTryReturnResult(NID_CNT, pImageContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
693 r = _ContentUtility::FillContentData(pMediaHandle.get(), pContentData);
694 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
696 r = _ContentUtility::FillImageContentData(pMediaHandle.get(), pImageContentData);
697 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform GetDataFromImageTable operation.");
699 // Shallow copy, adds just the pointer: not the element
700 r = __pFinalOutList->Add(*(pImageContentInfo.release()));
701 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation to __pFinalOutList.");
704 case MEDIA_CONTENT_TYPE_MUSIC:
706 case MEDIA_CONTENT_TYPE_SOUND:
707 pAudioContentInfo = std::unique_ptr<AudioContentInfo>(new (std::nothrow) AudioContentInfo);
708 SysTryReturnResult(NID_CNT, pAudioContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pAudioContentInfo.");
710 pContentData = pAudioContentInfo->GetContentData();
711 SysTryReturnResult(NID_CNT, pContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
713 pAudioContentData = pAudioContentInfo->GetAudioContentData();
714 SysTryReturnResult(NID_CNT, pAudioContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
716 r = _ContentUtility::FillContentData(pMediaHandle.get(), pContentData);
717 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
719 r = _ContentUtility::FillAudioContentData(pMediaHandle.get(), pAudioContentData);
720 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillAudioContentData operation.");
722 // Shallow copy, adds just the pointer: not the element
723 r = __pFinalOutList->Add(*(pAudioContentInfo.release()));
724 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation to __pFinalOutList.");
727 case MEDIA_CONTENT_TYPE_VIDEO:
728 pVideoContentInfo = std::unique_ptr<VideoContentInfo>(new (std::nothrow) VideoContentInfo);
729 SysTryReturnResult(NID_CNT, pVideoContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pVideoContentInfo.");
731 pContentData = pVideoContentInfo->GetContentData();
732 SysTryReturnResult(NID_CNT, pContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
734 pVideoContentData = pVideoContentInfo->GetVideoContentData();
735 SysTryReturnResult(NID_CNT, pVideoContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
737 r = _ContentUtility::FillContentData(pMediaHandle.get(), pContentData);
738 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
740 r = _ContentUtility::FillVideoContentData(pMediaHandle.get(), pVideoContentData);
741 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillVideoContentData operation.");
743 // Shallow copy, adds just the pointer: not the element
744 r = __pFinalOutList->Add(*(pVideoContentInfo.release()));
745 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation to __pFinalOutList.");
757 _ContentDirectoryImpl::CheckMediaPath(const Tizen::Base::String& directoryPath) const
759 String phoneStr = Environment::GetMediaPath();
760 String mmcStr = Environment::GetExternalStoragePath();
762 if (!(directoryPath.StartsWith(phoneStr, 0) || directoryPath.StartsWith(mmcStr , 0)))
765 result r = phoneStr.SubString(0, (phoneStr.GetLength() - 1), checkPhone);
766 SysTryReturn(NID_CNT, !IsFailed(r), false, E_INVALID_ARG, "[E_INVALID_ARG] Failed to substring operation.");
769 r = mmcStr.SubString(0, (mmcStr.GetLength() - 1), checkMmc);
770 SysTryReturn(NID_CNT, !IsFailed(r), false, E_INVALID_ARG, "[E_INVALID_ARG] Failed to substring operation.");
772 SysTryReturn(NID_CNT, (directoryPath.Equals(checkPhone) || directoryPath.Equals(checkMmc)), false, E_INVALID_ARG,
773 "[E_INVALID_ARG] The contentDirectoryPath is not valid[%ls].", directoryPath.GetPointer());
780 _ContentDirectoryImpl::MapCoreErrorToNativeResult(int reason) const
782 result r = E_SUCCESS;
786 case MEDIA_CONTENT_ERROR_NONE:
790 case MEDIA_CONTENT_ERROR_DB_BUSY:
792 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_DB_BUSY");
795 case MEDIA_CONTENT_ERROR_DB_FAILED:
797 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_DB_FAILED");
800 case MEDIA_CONTENT_ERROR_OUT_OF_MEMORY:
802 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_OUT_OF_MEMORY");
806 SysLog(NID_CNT, "default");
813 // Callback function registered to each media info details
814 // all items are appended to the list
816 MediaFoldersCb(media_folder_h folder, void* pUserdata)
818 int ret = MEDIA_CONTENT_ERROR_NONE;
819 media_folder_h new_folder = NULL;
820 ret = media_folder_clone(&new_folder, folder);
821 SysTryLog(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, "[E_SYSTEM] Propagating for media_folder_clone.");
823 GList** pList = (GList**)pUserdata;
824 *pList = g_list_append(*pList, new_folder);
829 // Callback function registered to each media info details
830 // all items are appended to the list
832 MediaFolderItemsCb(media_info_h media, void* pUserdata)
834 int ret = MEDIA_CONTENT_ERROR_NONE;
835 media_info_h new_media = NULL;
836 ret = media_info_clone(&new_media, media);
837 SysTryLog(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, "[E_SYSTEM] Propagating for media_info_clone.");
839 GList** pList = (GList**)pUserdata;
840 *pList = g_list_append(*pList, new_media);