2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file FCnt_ContentSearchImpl.cpp
18 * @brief This is the implementation file for the %_ContentSearchImpl class.
20 * This file contains implementation of the %_ContentSearchImpl class.
25 #include <FBaseSysLog.h>
26 #include <FBaseInteger.h>
27 #include <FBaseLongLong.h>
28 #include <FBaseFloat.h>
29 #include <FBaseColIList.h>
30 #include <FBaseUtilStringTokenizer.h>
31 #include <FCntContentSearch.h>
32 #include <FCntContentSearchResult.h>
33 #include <FSysEnvironment.h>
34 #include <FApp_AppInfo.h>
35 #include <FBase_StringConverter.h>
36 #include <FBase_LocalizedNumParser.h>
37 #include <FIo_FileImpl.h>
38 #include "FCnt_ContentUtility.h"
39 #include "FCnt_ContentSearchImpl.h"
40 #include "FCnt_ContentInfoImpl.h"
41 #include "FCnt_ImageContentInfoImpl.h"
42 #include "FCnt_AudioContentInfoImpl.h"
43 #include "FCnt_VideoContentInfoImpl.h"
44 #include "FCnt_OtherContentInfoImpl.h"
45 #include "FCnt_ContentInfoHelper.h"
47 using namespace Tizen::App;
48 using namespace Tizen::Base;
49 using namespace Tizen::Base::Collection;
50 using namespace Tizen::Base::Utility;
51 using namespace Tizen::Io;
52 using namespace Tizen::System;
54 namespace Tizen { namespace Content
57 static const int QUERY_LENGTH = 4096;
59 // Declaration for Callback function registered to each media info details
60 bool MediaItemCb(media_info_h media, void* pUserdata);
61 // Declaration for Callback function registered to each column details
62 bool GroupItemCb(const char* pGroupName, void* pUserdata);
63 // Declaration for Callback function registered to each album details
64 bool AlbumItemCb(media_album_h album, void* pUserdata);
66 // Default constructor
67 _ContentSearchImpl::_ContentSearchImpl(void)
68 : __contentType(CONTENT_TYPE_UNKNOWN)
69 , __pFinalOutList(NULL)
71 , __inputColumnName(L"")
72 , __inputSortOrder(SORT_ORDER_NONE)
73 , __pFilterHandle(NULL)
75 SysLog(NID_CNT, "Enter\n");
79 // Default destructor (disconnects the DB connection)
80 _ContentSearchImpl::~_ContentSearchImpl(void)
82 SysLog(NID_CNT, "Enter\n");
84 int ret = MEDIA_CONTENT_ERROR_NONE;
87 ret = media_content_disconnect();
88 r = MapCoreErrorToNativeResult(ret);
89 SysTryLog(NID_CNT, r == E_SUCCESS, "[%s] Propagated in ~_ContentSearchImpl", GetErrorMessage(r));
93 _ContentSearchImpl::GetInstance(ContentSearch& contentSearch)
95 return contentSearch.__pImpl;
98 const _ContentSearchImpl*
99 _ContentSearchImpl::GetInstance(const ContentSearch& contentSearch)
101 return contentSearch.__pImpl;
104 //make a connection to DB
106 _ContentSearchImpl::Construct(ContentType type)
108 SysLog(NID_CNT, "Enter\n");
110 result r = E_SUCCESS;
111 int ret = MEDIA_CONTENT_ERROR_NONE;
113 ret = media_content_connect();
114 SysTryReturnResult(NID_CNT, r == E_SUCCESS , E_SYSTEM, "Failed to perform media_content_connect operation.");
116 __contentType = type;
121 // Creates a filter for the input query string along with content type
122 // Initializes filter handle
123 // Image - MEDIA_TYPE=0
124 // Vide0 - MEDIA_TYPE=1
125 // Audio - MEDIA_TYPE=2 or MEDIA_TYPE=3
126 // Others - MEDIA_TYPE=4
128 // Appends MEDIA_TYPE with "AND" (if the input expression is not empty and content type is not ALL) and input expression
129 // Sets the condition and order.
130 // If any argument is not proper E_INVALID_ARG is returned
132 _ContentSearchImpl::CreateQueryFilter(bool isAndAppendReq) const
134 int ret = MEDIA_CONTENT_ERROR_NONE;
135 result r = E_SUCCESS;
137 std::unique_ptr<char[]> pInputCond;
138 std::unique_ptr<char[]> pSortCol;
140 String inputCondition;
143 filter_h tempFilter = NULL;
145 ret = media_filter_create(&tempFilter);
146 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "Failed to perform media_filter_create operation.");
148 std::unique_ptr<filter_s, SearchFilterHandleDeleter> pFilterHandle(tempFilter);
149 SysTryReturnResult(NID_CNT, pFilterHandle != null, E_OUT_OF_MEMORY, "pFilterHandle is null.");
151 switch (__contentType)
153 // Image-0,video-1,sound-2,music-3,other-4
154 case CONTENT_TYPE_OTHER:
155 inputCondition = "MEDIA_TYPE=4 ";
157 case CONTENT_TYPE_IMAGE:
158 inputCondition = "MEDIA_TYPE=0 ";
160 case CONTENT_TYPE_AUDIO:
161 inputCondition = "(MEDIA_TYPE=2 or MEDIA_TYPE=3) ";
163 case CONTENT_TYPE_VIDEO:
164 inputCondition = "MEDIA_TYPE=1 ";
166 case CONTENT_TYPE_ALL:
167 //If content type is CONTENT_TYPE_ALL, then MEDIA_TYPE is empty
173 if (!__inputExpr.IsEmpty())
175 if (isAndAppendReq && (!inputCondition.IsEmpty())) //For CONTENT_TYPE_ALL inputCondition is empty
177 r = inputCondition.Append("AND ");
178 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform append operation.");
181 r = inputCondition.Append(__inputExpr);
182 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform append operation.");
185 if (!inputCondition.IsEmpty())
187 //CopyToCharArrayN: utility function, converts a osp string to char*
188 pInputCond = std::unique_ptr<char[]>(_StringConverter::CopyToCharArrayN(inputCondition));
189 SysTryReturnResult(NID_CNT, pInputCond, E_OUT_OF_MEMORY, "pInputCond is NULL.");
191 SysLog(NID_CNT, "pInputCond = %s", pInputCond.get());
193 ret = media_filter_set_condition(pFilterHandle.get(), pInputCond.get(), MEDIA_CONTENT_COLLATE_DEFAULT);
194 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "Failed to perform media_filter_set_condition operation.");
197 if (!__inputColumnName.IsEmpty()) // SortColumn is optional in case of SearchN
199 //__inputColumnName (osp column name) is replaced with slpColumn (slp column name).
200 r = GetSlpColumnName(slpColumn);
201 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform GetSlpColumnName operation.");
203 //CopyToCharArrayN: utility function, converts a osp string to char*
205 pSortCol = std::unique_ptr<char[]>(_StringConverter::CopyToCharArrayN(slpColumn));
206 SysTryReturnResult(NID_CNT, pSortCol, E_OUT_OF_MEMORY, "pSortCol is NULL.");
208 if (__inputSortOrder == SORT_ORDER_ASCENDING)
210 ret = media_filter_set_order(pFilterHandle.get(), MEDIA_CONTENT_ORDER_ASC, pSortCol.get(), MEDIA_CONTENT_COLLATE_NOCASE);
211 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "Failed to perform media_filter_set_order operation.");
213 else if (__inputSortOrder == SORT_ORDER_DESCENDING)
215 ret = media_filter_set_order(pFilterHandle.get(), MEDIA_CONTENT_ORDER_DESC, pSortCol.get(), MEDIA_CONTENT_COLLATE_NOCASE);
216 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "Failed to perform media_filter_set_order operation.");
220 __pFilterHandle.reset(pFilterHandle.release());
225 // Osp column names are mapped with slp column names
226 // CONTENT_TYPE_OTHER and CONTENT_TYPE_IMAGE (0 - 13 ) are valid columns
227 // CONTENT_TYPE_VIDEO (0 - 16 ) are valid columns
228 // CONTENT_TYPE_ALL and CONTENT_TYPE_VIDEO (0 - 18 ) are valid columns
229 // if the given osp column is out of the specified range of the type, E_INVALID_ARG is retuned.
231 _ContentSearchImpl::GetSlpColumnName(String& inputCol) const
233 String ospColumnName(L"");
234 String slpColumnName(L"");
235 String columnName(__inputColumnName);
236 result r = E_SUCCESS;
238 switch (__contentType)
240 case CONTENT_TYPE_OTHER:
242 case CONTENT_TYPE_IMAGE:
243 maxCols = MAX_QUERY_COLUMNS_FOR_IMAGE_OTHERS;
245 case CONTENT_TYPE_VIDEO:
246 maxCols = MAX_QUERY_COLUMNS_FOR_VIDEO;
248 case CONTENT_TYPE_AUDIO:
250 case CONTENT_TYPE_ALL:
251 maxCols = MAX_QUERY_COLUMNS;
256 for (int colIndex = 0; colIndex < maxCols; colIndex++)
258 ospColumnName.Clear();
259 slpColumnName.Clear();
261 ospColumnName = dbfieldinfo[colIndex].dbFieldOspName ;
262 slpColumnName = dbfieldinfo[colIndex].dbFieldSlpName ;
264 ospColumnName.ToUpper();
265 columnName.ToUpper();
266 if (columnName == ospColumnName)
268 inputCol = slpColumnName;
272 return E_INVALID_ARG;
275 //If the input expression contains any osp column name, it will be replaced with slp column name.
276 // only CONTENT_TYPE_AUDIO and CONTENT_TYPE_ALL allowed to use all given columns
277 // so, check for invalid column for CONTENT_TYPE_OTHER,CONTENT_TYPE_IMAGE and CONTENT_TYPE_VIDEO.
278 // all the osp columns in the expression should be replaced with slp column names.
279 // ' is used as a delimeter in parsing user query. so, \\' is saved as a special@apostrophe string.
280 // \\' is replaced with '', which considers ' as normal character.
283 _ContentSearchImpl::ReplaceOspColumnNameWithSlp(void) const
285 String ospColumnName(L"");
286 String slpColumnName(L"");
287 String splApostrophe(L"special@apostrophe");
288 result r = E_SUCCESS;
293 String strToBeReplaced(L"\\'");
294 int strLen = strToBeReplaced.GetLength();
297 while(E_SUCCESS == __inputExpr.IndexOf(strToBeReplaced,startIndex,indexOf))
299 int lenAfterSubStr = indexOf + strLen;
300 while ((lenAfterSubStr < __inputExpr.GetLength()) && (__inputExpr[lenAfterSubStr] == ' '))
304 if ((lenAfterSubStr < __inputExpr.GetLength()) && ((__inputExpr[lenAfterSubStr] == '\'') ||
305 ((!__inputExpr.StartsWith(L"AND ", lenAfterSubStr)) && (!__inputExpr.StartsWith(L"OR ", lenAfterSubStr)))))
307 r = __inputExpr.Remove(indexOf,strLen);
308 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "Failed to perform Remove operation.");
309 r = __inputExpr.Insert(splApostrophe,indexOf);
310 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "Failed to perform Insert operation.");
311 startIndex = indexOf + splApostrophe.GetLength();
315 startIndex = lenAfterSubStr;
319 SysLog(NID_CNT, "__inputExpr after splApostrophe append = %ls", __inputExpr.GetPointer());
321 switch (__contentType)
323 case CONTENT_TYPE_OTHER:
325 case CONTENT_TYPE_IMAGE:
326 r = CheckInvalidColumnInQuery();
327 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_INVALID_ARG, "Invalid Column In QueryString.");
328 maxCols = MAX_QUERY_COLUMNS_FOR_IMAGE_OTHERS;
330 case CONTENT_TYPE_VIDEO:
331 r = CheckInvalidColumnInQuery();
332 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_INVALID_ARG, "Invalid Column In QueryString.");
333 maxCols = MAX_QUERY_COLUMNS_FOR_VIDEO;
335 case CONTENT_TYPE_AUDIO:
337 case CONTENT_TYPE_ALL:
338 maxCols = MAX_QUERY_COLUMNS;
343 for (int colIndex = 0; colIndex < maxCols; colIndex++)
345 ospColumnName.Clear();
346 slpColumnName.Clear();
348 ospColumnName = dbfieldinfo[colIndex].dbFieldOspName ;
349 slpColumnName = dbfieldinfo[colIndex].dbFieldSlpName ;
351 ReplaceString(ospColumnName,slpColumnName);
354 // Append ESCAPE '\' for LIKE query
355 r = AppendEscapeKeywordForLikeQuery();
356 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "AppendEscapeKeywordForLikeQuery failed.");
358 r = ReplaceDateTimeStringWithInt();
359 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_INVALID_ARG, "ReplaceDateTimeStringWithInt failed.");
361 // replace splApostrophe string with actual
362 r = __inputExpr.Replace(splApostrophe, "''");
363 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string Replace failed.");
368 //This function is to appened ESCAPE keyword for _ and % special characters in LIKE query.
371 _ContentSearchImpl::AppendEscapeKeywordForLikeQuery(void) const
373 String delim = L"'"; //Delimeters is ' .
374 result r = E_SUCCESS;
376 bool isAppendEscape = false;
379 String inputExpr = __inputExpr;
381 // Create a StringTokenizer instance
382 StringTokenizer strTok(inputExpr, delim);
386 while (strTok.HasMoreTokens())
388 r = strTok.GetNextToken(token);
389 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "GetNextToken failed.");
390 if (isCol) //column name
394 tokenUpper.ToUpper();
395 if (tokenUpper.Contains(" LIKE"))
397 isAppendEscape = true;
401 isAppendEscape = false;
403 r = inputExpr.Append(token);
404 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
406 else // value of the column
409 r = inputExpr.Append("'");
410 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
411 r = inputExpr.Append(token);
412 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
413 r = inputExpr.Append("'");
414 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
418 if (token.Contains("\\_") || token.Contains("\\%"))
420 r = inputExpr.Append("ESCAPE'\\' ");
421 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
428 r = __inputExpr.Insert(inputExpr, 0);
429 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string insert failed.");
434 //This function is to replace DateTime value(osp datetime type is string) which is string with int.(SLP dateTime column type is int)
437 _ContentSearchImpl::ReplaceDateTimeStringWithInt(void) const
439 String delim = L"'"; //Delimeters is ' .
440 result r = E_SUCCESS;
442 bool isConvertReq = false;
443 bool isBetweenExistsInDateTimeQuery = false;
446 String inputExpr = __inputExpr;
448 if(!inputExpr.Contains("MEDIA_ADDED_TIME"))
453 // Create a StringTokenizer instance
454 StringTokenizer strTok(inputExpr, delim);
458 while (strTok.HasMoreTokens())
460 r = strTok.GetNextToken(token);
461 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "GetNextToken failed.");
462 if (isCol) //column name
466 tokenUpper.ToUpper();
467 if(isBetweenExistsInDateTimeQuery)
469 isBetweenExistsInDateTimeQuery = false;
474 if (tokenUpper.Contains("MEDIA_ADDED_TIME"))
476 if (tokenUpper.Contains("BETWEEN"))
478 isBetweenExistsInDateTimeQuery = true;
484 isConvertReq = false;
488 r = inputExpr.Append(token);
489 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string append failed.");
491 else // value of the column
494 r = inputExpr.Append("'");
495 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string append failed.");
499 Tizen::Base::DateTime dt;
500 r = Tizen::Base::DateTime::Parse(token, dt);
501 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to parse DateTime.");
503 int year = dt.GetYear();
504 int month = dt.GetMonth();
505 int day = dt.GetDay();
506 int hour = dt.GetHour();
507 int minute = dt.GetMinute();
508 int second = dt.GetSecond();
514 timeInfo = localtime(&rawTime);
515 timeInfo->tm_year = year - 1900;
516 timeInfo->tm_mon = month - 1;
517 timeInfo->tm_mday = day;
518 timeInfo->tm_hour = hour;
519 timeInfo->tm_min = minute;
520 timeInfo->tm_sec = second;
522 time_t seconds = mktime(timeInfo);
523 SysTryReturnResult(NID_CNT, seconds != -1, E_INVALID_ARG, "Failed to convert DateTime to broken-down time.");
525 long long ticksInSeconds = (long long)seconds;
527 r = inputExpr.Append(ticksInSeconds);
528 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string append failed.");
532 r = inputExpr.Append(token);
533 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string append failed.");
536 r = inputExpr.Append("'");
537 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string append failed.");
542 r = __inputExpr.Insert(inputExpr, 0);
543 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string insert failed.");
548 // CONTENT_TYPE_OTHER and CONTENT_TYPE_IMAGE (0 - 13 ) are valid columns
549 // CONTENT_TYPE_VIDEO (0 - 16 ) are valid columns
550 // CONTENT_TYPE_ALL and CONTENT_TYPE_VIDEO (0 - 18 ) are valid columns
551 // This functions checks for invalid column in the given input string (only allowed columns should be used by content type other wise
552 // E_INVALID_ARG is returned)
553 // StringTokenizer is used to parse input expression, by using delimater "'", to differentiate column and value.
554 // As values may also contain column names
555 // Ex: 1. where author = syam_author_01 2. where album = jalsa_album_name_01.
558 _ContentSearchImpl::CheckInvalidColumnInQuery(void) const
560 result r = E_SUCCESS;
562 String delim = L"'"; //Delimeters is ' .
563 bool isColReplaceReq = true;
565 String inputExpr = __inputExpr;
567 // Create a StringTokenizer instance
568 StringTokenizer strTok(inputExpr, delim);
572 while (strTok.HasMoreTokens())
574 r = strTok.GetNextToken(token);
575 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "strTok GetNextToken failed.");
577 SysLog(NID_CNT, "In CheckInvalidColumnInQuery token[%d] = %ls", ++tokenNo, token.GetPointer());
581 isColReplaceReq = false;
582 r = inputExpr.Append(token);
583 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
585 switch (__contentType)
587 case CONTENT_TYPE_OTHER:
589 case CONTENT_TYPE_IMAGE:
590 if ((token.Contains("TITLE")) || (token.Contains("ARTIST")) || (token.Contains("GENRE")))
592 SysLog(NID_CNT, "Title or Artist or Genre are not valid cloumns for this content type");
593 return E_INVALID_ARG;
596 case CONTENT_TYPE_VIDEO:
597 if ((token.Contains("COMPOSER")) || (token.Contains("ALBUM")))
599 SysLog(NID_CNT, "Composer or Album are not valid cloumns for this content type");
600 return E_INVALID_ARG;
609 isColReplaceReq = true;
610 r = inputExpr.Append("'");
611 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
612 r = inputExpr.Append(token);
613 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
614 r = inputExpr.Append("'");
615 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
621 // It replaces native column name with core column name.
622 // StringTokenizer is used to parse input expression, by using delimiter "'", to differentiate column and value.
623 // As values may also contain column names
624 // Only column names are replaced but not values(values may contain column names)
625 // Ex: 1. where author = syam_author_01 2. where album = jalsa_album_name_01.
628 _ContentSearchImpl::ReplaceString(String ospColumnName, String slpColumnName) const
630 String delim = L"'"; //Delimiters is ' .
631 result r = E_SUCCESS;
632 bool isColReplaceReq = true;
634 String inputExpr = __inputExpr;
636 // Create a StringTokenizer instance
637 StringTokenizer strTok(inputExpr, delim);
641 while (strTok.HasMoreTokens())
643 r = strTok.GetNextToken(token); // Osp, StringTokenizer, Sample, code
644 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string GetNextToken() failed.");
645 if (isColReplaceReq) //column name
647 isColReplaceReq = false;
648 r = token.Replace(ospColumnName, slpColumnName);
649 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string replace() failed.");
650 r = inputExpr.Append(token);
651 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
653 else // value of the column
655 isColReplaceReq = true;
656 r = inputExpr.Append("'");
657 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
658 r = inputExpr.Append(token);
659 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
660 r = inputExpr.Append("'");
661 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
665 r = __inputExpr.Insert(inputExpr, 0);
666 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string insert() failed.");
671 // Returns list of search result for the given expression and content type.
673 _ContentSearchImpl::SearchN(int pageNo, int countPerPage, int& totalPageCount, int& totalCount, const String& whereExpr, const String& sortColumn, SortOrder sortOrder) const
675 SysLog(NID_CNT, "pageNo = %d, countPerPage = %d, whereExpr = %ls", pageNo, countPerPage, whereExpr.GetPointer());
679 result r = E_SUCCESS;
680 int ret = MEDIA_CONTENT_ERROR_NONE;
683 __inputColumnName.Clear();
685 __inputColumnName = sortColumn;
686 __inputSortOrder = sortOrder;
690 if (!whereExpr.IsEmpty()) // copy whereExpr if not empty to class variable __inputExpr
692 r = __inputExpr.Append(whereExpr);
693 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[%s] __inputExpr.Append Failed as whereExpr is not empty.", GetErrorMessage(r));
695 r = ReplaceOspColumnNameWithSlp();
696 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[%s] ReplaceOspColumnNameWithSlp for InputExpr Failed.", GetErrorMessage(r));
698 SysLog(NID_CNT, "After replace __inputExpr = %ls", __inputExpr.GetPointer());
700 if ((__inputColumnName.IsEmpty()) && ((__inputSortOrder == SORT_ORDER_ASCENDING) || (__inputSortOrder == SORT_ORDER_DESCENDING)))
702 SysLog(NID_CNT, "sort column name is empty and sort oder is not none. so,E_INVALID_ARG occured.");
703 SetLastResult(E_INVALID_ARG);
708 std::unique_ptr<ArrayList, AllElementsDeleter> pFinalOutList(new (std::nothrow) ArrayList());
709 SysTryReturn(NID_CNT, pFinalOutList.get() != null, NULL, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to construct ArrayList.");
711 r = pFinalOutList->Construct();
712 SysTryReturn(NID_CNT, !IsFailed(r), NULL, r, "[%s] Failed to construct ArrayList.", GetErrorMessage(r));
714 __pFinalOutList = std::move(pFinalOutList);
716 r = CreateQueryFilter(true);
717 SysTryReturn(NID_CNT, !IsFailed(r), NULL, r, "[%s] Failed to perform CreateQueryFilter operation.", GetErrorMessage(r));
719 ret = media_info_get_media_count_from_db(__pFilterHandle.get(), &totalCount);
720 r = MapCoreErrorToNativeResult(ret);
721 SysTryReturn(NID_CNT, r == E_SUCCESS , NULL, r, "[%s] Failed to perform media_info_get_media_count_from_db operation.", GetErrorMessage(r));
723 SysLog(NID_CNT, "totalCount is [%d] for media_info_get_media_count_from_db", totalCount);
727 if ((totalCount % countPerPage) == 0)
729 totalPageCount = totalCount / countPerPage;
733 totalPageCount = (totalCount / countPerPage) + 1;
736 SysTryReturn(NID_CNT, ((pageNo >= 1) && (pageNo <= totalPageCount)) , NULL, E_INVALID_ARG, "[E_INVALID_ARG] (pageNo < 1) || (pageNo > totalPageCount).");
738 offset = (pageNo * countPerPage) - countPerPage;
740 SysLog(NID_CNT, " SearchN totalCount [%d] totalPageCount[%d] __countPerPage[%d] __pageNo[%d] offset[%d]",
741 totalCount, totalPageCount, countPerPage, pageNo, offset);
743 ret = media_filter_set_offset(__pFilterHandle.get(), offset, countPerPage);
744 r = MapCoreErrorToNativeResult(ret);
745 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r,
746 "[%s] Failed to perform media_filter_set_offset operation.", GetErrorMessage(r));
748 r = ExecuteAndFillFinalOutList();
749 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, E_SYSTEM, "[E_SYSTEM] ExecuteAndFillFinalOutList Failed.");
753 SysLogException(NID_CNT, E_INVALID_ARG, "[%s] (pageNo > 1) and (totalcount = 0).", GetErrorMessage(E_INVALID_ARG));
759 return __pFinalOutList.release();
762 // Fills final result list
764 _ContentSearchImpl::ExecuteAndFillFinalOutList(void) const
766 SysLog(NID_CNT, "Enter\n");
768 int ret = MEDIA_CONTENT_ERROR_NONE;
769 result r = E_SUCCESS;
771 std::unique_ptr<GList, SearchGListDeleter> pItemList;
773 std::unique_ptr<media_info_s, SearchMediaHandleDeleter> pMediaHandle;
775 std::unique_ptr<ImageContentInfo> pImageContentInfo;
776 std::unique_ptr<AudioContentInfo> pAudioContentInfo;
777 std::unique_ptr<VideoContentInfo> pVideoContentInfo;
778 std::unique_ptr<OtherContentInfo> pOtherContentInfo;
780 _ImageContentInfoImpl* pImageContentInfoImpl = null;
781 _AudioContentInfoImpl* pAudioContentInfoImpl = null;
782 _VideoContentInfoImpl* pVideoContentInfoImpl = null;
783 _OtherContentInfoImpl* pOtherContentInfoImpl = null;
785 std::unique_ptr<ContentSearchResult> pContentSearchResult;
787 pTemp = pItemList.get();
789 ret = media_info_foreach_media_from_db(__pFilterHandle.get(), MediaItemCb, &pTemp);
790 r = MapCoreErrorToNativeResult(ret);
791 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform media_info_foreach_media_from_db operation.");
793 SysTryReturnResult(NID_CNT, pTemp != NULL, r, "media_info_foreach_media_from_db pTemp is null.");
795 media_content_type_e mediaType = MEDIA_CONTENT_TYPE_OTHERS;
797 for (int idx = 0; idx < (int)g_list_length(pTemp); idx++)
799 pMediaHandle.reset(static_cast<media_info_h>(g_list_nth_data(pTemp, idx)));
801 ret = media_info_get_media_type(pMediaHandle.get(), &mediaType);
802 r = MapCoreErrorToNativeResult(ret);
803 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform media_info_get_media_type.");
805 std::unique_ptr<char, UtilCharDeleter> pMediaPath;
806 char* pTempPath = null;
808 ret = media_info_get_file_path(pMediaHandle.get(), &pTempPath);
809 r = MapCoreErrorToNativeResult(ret);
810 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform media_info_get_file_path operation.");
812 pMediaPath.reset(pTempPath);
813 String contentPath(pMediaPath.get());
814 String changedPath(contentPath);
816 // If the api version is 2.0, the content path has to be changed.
817 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
819 r = _FileImpl::ConvertPhysicalToVirtualPath(contentPath, changedPath);
820 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG,
821 "[%s] Failed to convert physical path to virtual path.", GetErrorMessage(E_INVALID_ARG));
826 case MEDIA_CONTENT_TYPE_OTHERS:
827 pOtherContentInfo = std::unique_ptr<OtherContentInfo>(new (std::nothrow) OtherContentInfo);
828 SysTryReturnResult(NID_CNT, pOtherContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pOtherContentInfo.");
830 r = pOtherContentInfo->Construct(&changedPath);
831 r = ConvertErrorToResult(r);
832 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Construct operation to OtherContentInfo.");
834 pOtherContentInfoImpl = null;
835 pOtherContentInfoImpl = _OtherContentInfoImpl::GetInstance(*(pOtherContentInfo.get()));
836 SysTryReturnResult(NID_CNT, pOtherContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to assign operation to pOtherContentInfoImpl.");
838 r = _ContentUtility::FillContentData(pMediaHandle.get(), pOtherContentInfoImpl);
839 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
841 _ContentInfoHelper::SetContentInfoImpl(pOtherContentInfo.get(), pOtherContentInfoImpl);
843 pContentSearchResult = std::unique_ptr<ContentSearchResult>(new (std::nothrow) ContentSearchResult);
844 SysTryReturnResult(NID_CNT, pContentSearchResult.get() != null, E_OUT_OF_MEMORY, "Failed to create pContentSearchResult.");
846 pContentSearchResult->SetContentType(CONTENT_TYPE_OTHER);
847 pContentSearchResult->SetContentInfo(pOtherContentInfo.release());
849 // Shallow copy, adds just the pointer: not the element
850 r = __pFinalOutList->Add(*(pContentSearchResult.release()));
851 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation for ArrayList.");
854 case MEDIA_CONTENT_TYPE_IMAGE:
855 pImageContentInfo = std::unique_ptr<ImageContentInfo>(new (std::nothrow) ImageContentInfo);
856 SysTryReturnResult(NID_CNT, pImageContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pImageContentInfo.");
858 r = pImageContentInfo->Construct(&changedPath);
859 r = ConvertErrorToResult(r);
860 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Construct operation to ImageContentInfo.");
862 pImageContentInfoImpl = null;
863 pImageContentInfoImpl = _ImageContentInfoImpl::GetInstance(*(pImageContentInfo.get()));
864 SysTryReturnResult(NID_CNT, pImageContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to assign operation to pImageContentInfoImpl.");
866 r = _ContentUtility::FillContentData(pMediaHandle.get(), pImageContentInfoImpl);
867 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
869 r = _ContentUtility::FillImageContentData(pMediaHandle.get(), pImageContentInfoImpl);
870 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform GetDataFromImageTable operation.");
872 _ContentInfoHelper::SetContentInfoImpl(pImageContentInfo.get(), pImageContentInfoImpl);
874 pContentSearchResult = std::unique_ptr<ContentSearchResult>(new (std::nothrow) ContentSearchResult);
875 SysTryReturnResult(NID_CNT, pContentSearchResult.get() != null, E_OUT_OF_MEMORY, "Failed to create pContentSearchResult.");
877 pContentSearchResult->SetContentType(CONTENT_TYPE_IMAGE);
878 pContentSearchResult->SetContentInfo(pImageContentInfo.release());
880 // Shallow copy, adds just the pointer: not the element
881 r = __pFinalOutList->Add(*(pContentSearchResult.release()));
882 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation for ArrayList.");
885 case MEDIA_CONTENT_TYPE_MUSIC:
887 case MEDIA_CONTENT_TYPE_SOUND:
888 pAudioContentInfo = std::unique_ptr<AudioContentInfo>(new (std::nothrow) AudioContentInfo);
889 SysTryReturnResult(NID_CNT, pAudioContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pAudioContentInfo.");
891 r = pAudioContentInfo->Construct(&changedPath);
892 r = ConvertErrorToResult(r);
893 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Construct operation to AudioContentInfo.");
895 pAudioContentInfoImpl = null;
896 pAudioContentInfoImpl = _AudioContentInfoImpl::GetInstance(*(pAudioContentInfo.get()));
897 SysTryReturnResult(NID_CNT, pAudioContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to assign operation to pAudioContentInfoImpl.");
899 r = _ContentUtility::FillContentData(pMediaHandle.get(), pAudioContentInfoImpl);
900 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
902 r = _ContentUtility::FillAudioContentData(pMediaHandle.get(), pAudioContentInfoImpl);
903 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillAudioContentData operation.");
905 _ContentInfoHelper::SetContentInfoImpl(pAudioContentInfo.get(), pAudioContentInfoImpl);
907 pContentSearchResult = std::unique_ptr<ContentSearchResult>(new (std::nothrow) ContentSearchResult);
908 SysTryReturnResult(NID_CNT, pContentSearchResult.get() != null, E_OUT_OF_MEMORY, "Failed to create pContentSearchResult.");
910 pContentSearchResult->SetContentType(CONTENT_TYPE_AUDIO);
911 pContentSearchResult->SetContentInfo(pAudioContentInfo.release());
913 // Shallow copy, adds just the pointer: not the element
914 r = __pFinalOutList->Add(*(pContentSearchResult.release()));
915 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation for ArrayList.");
918 case MEDIA_CONTENT_TYPE_VIDEO:
919 pVideoContentInfo = std::unique_ptr<VideoContentInfo>(new (std::nothrow) VideoContentInfo);
920 SysTryReturnResult(NID_CNT, pVideoContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pVideoContentInfo.");
922 r = pVideoContentInfo->Construct(&changedPath);
923 r = ConvertErrorToResult(r);
924 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Construct operation to VideoContentInfo.");
926 pVideoContentInfoImpl = null;
927 pVideoContentInfoImpl = _VideoContentInfoImpl::GetInstance(*(pVideoContentInfo.get()));
928 SysTryReturnResult(NID_CNT, pVideoContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to assign operation to pVideoContentInfoImpl.");
930 r = _ContentUtility::FillContentData(pMediaHandle.get(), pVideoContentInfoImpl);
931 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
933 r = _ContentUtility::FillVideoContentData(pMediaHandle.get(), pVideoContentInfoImpl);
934 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillVideoContentData operation.");
936 _ContentInfoHelper::SetContentInfoImpl(pVideoContentInfo.get(), pVideoContentInfoImpl);
938 pContentSearchResult = std::unique_ptr<ContentSearchResult>(new (std::nothrow) ContentSearchResult);
939 SysTryReturnResult(NID_CNT, pContentSearchResult.get() != null, E_OUT_OF_MEMORY, "Failed to create pContentSearchResult.");
941 pContentSearchResult->SetContentType(CONTENT_TYPE_VIDEO);
942 pContentSearchResult->SetContentInfo(pVideoContentInfo.release());
944 // Shallow copy, adds just the pointer: not the element
945 r = __pFinalOutList->Add(*(pContentSearchResult.release()));
946 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation for ArrayList.");
956 // returns given column value list in the requested order
958 _ContentSearchImpl::GetValueListN(const String& sortColumn, SortOrder sortOrder)
960 SysLog(NID_CNT, "inputColumn = %ls", sortColumn.GetPointer());
963 result r = E_SUCCESS;
967 __inputColumnName.Clear();
970 __inputColumnName = sortColumn;
971 __inputSortOrder = sortOrder;
973 String ospColumnName(L"");
974 String slpColumnName(L"");
976 String columnName(__inputColumnName);
978 if ((__inputColumnName.IsEmpty()) && ((__inputSortOrder == SORT_ORDER_ASCENDING) || (__inputSortOrder == SORT_ORDER_DESCENDING)))
980 SysLog(NID_CNT, "sort column name is empty and sort oder is not none. so,E_INVALID_ARG occured.");
981 SetLastResult(E_INVALID_ARG);
986 std::unique_ptr<ArrayList, AllElementsDeleter> pFinalOutList(new (std::nothrow) ArrayList());
987 SysTryReturn(NID_CNT, pFinalOutList.get() != null, NULL, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to construct ArrayList.");
989 r = pFinalOutList->Construct();
990 SysTryReturn(NID_CNT, !IsFailed(r), NULL, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to construct ArrayList.");
992 __pFinalOutList = std::move(pFinalOutList);
994 switch (__contentType)
996 case CONTENT_TYPE_OTHER:
998 case CONTENT_TYPE_IMAGE:
999 maxCols = MAX_QUERY_COLUMNS_FOR_IMAGE_OTHERS;
1001 case CONTENT_TYPE_VIDEO:
1002 maxCols = MAX_QUERY_COLUMNS_FOR_VIDEO;
1004 case CONTENT_TYPE_AUDIO:
1006 case CONTENT_TYPE_ALL:
1007 maxCols = MAX_QUERY_COLUMNS;
1013 for (colIndex = 0; colIndex < maxCols; colIndex++)
1015 ospColumnName.Clear();
1016 slpColumnName.Clear();
1018 ospColumnName = dbfieldinfo[colIndex].dbFieldOspName ;
1019 slpColumnName = dbfieldinfo[colIndex].dbFieldSlpName ;
1021 ospColumnName.ToUpper();
1022 columnName.ToUpper();
1023 if (columnName == ospColumnName)
1025 r = FillColumnsList(colIndex);
1026 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[%s] FillColumnsList Failed.", GetErrorMessage(r));
1030 if (colIndex == maxCols)
1032 SysLogException(NID_CNT, E_INVALID_ARG, "[%s] The column is invalid.", GetErrorMessage(E_INVALID_ARG));
1038 return __pFinalOutList.release();
1041 // returns given column value list in the requested order
1043 _ContentSearchImpl::GetValueListN(int pageNo, int countPerPage, int& totalPageCount, int& totalCount, const String& sortColumn, SortOrder sortOrder) const
1045 SysLog(NID_CNT, "pageNo = %d, countPerPage = %d, inputColumn = %ls", pageNo, countPerPage, sortColumn.GetPointer());
1049 result r = E_SUCCESS;
1053 __inputColumnName.Clear();
1054 __inputExpr.Clear();
1056 __inputColumnName = sortColumn;
1057 __inputSortOrder = sortOrder;
1059 String ospColumnName(L"");
1060 String slpColumnName(L"");
1062 String columnName(__inputColumnName);
1064 if ((__inputColumnName.IsEmpty()) && ((__inputSortOrder == SORT_ORDER_ASCENDING) || (__inputSortOrder == SORT_ORDER_DESCENDING)))
1066 SysLog(NID_CNT, "sort column name is empty and sort oder is not none. so,E_INVALID_ARG occured.");
1067 SetLastResult(E_INVALID_ARG);
1072 std::unique_ptr<ArrayList, AllElementsDeleter> pFinalOutList(new (std::nothrow) ArrayList());
1073 SysTryReturn(NID_CNT, pFinalOutList.get() != null, NULL, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to construct ArrayList.");
1075 r = pFinalOutList->Construct();
1076 SysTryReturn(NID_CNT, !IsFailed(r), NULL, r, "[%s] Failed to construct ArrayList.", GetErrorMessage(r));
1078 __pFinalOutList = std::move(pFinalOutList);
1080 switch (__contentType)
1082 case CONTENT_TYPE_OTHER:
1084 case CONTENT_TYPE_IMAGE:
1085 maxCols = MAX_QUERY_COLUMNS_FOR_IMAGE_OTHERS;
1087 case CONTENT_TYPE_VIDEO:
1088 maxCols = MAX_QUERY_COLUMNS_FOR_VIDEO;
1090 case CONTENT_TYPE_AUDIO:
1092 case CONTENT_TYPE_ALL:
1093 maxCols = MAX_QUERY_COLUMNS;
1099 for (colIndex = 0; colIndex < maxCols; colIndex++)
1101 ospColumnName.Clear();
1102 slpColumnName.Clear();
1104 ospColumnName = dbfieldinfo[colIndex].dbFieldOspName ;
1105 slpColumnName = dbfieldinfo[colIndex].dbFieldSlpName ;
1107 ospColumnName.ToUpper();
1108 columnName.ToUpper();
1109 if (columnName == ospColumnName)
1111 r = FillColumnsList(pageNo, countPerPage, totalPageCount, totalCount, colIndex);
1112 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[%s] FillColumnsList Failed.", GetErrorMessage(r));
1116 if (colIndex == maxCols)
1118 SysLogException(NID_CNT, E_INVALID_ARG, "[%s] The column is invalid.", GetErrorMessage(E_INVALID_ARG));
1124 return __pFinalOutList.release();
1127 // prepares query expression to be used in group api. colIndex is mapped to actual group value.
1129 _ContentSearchImpl::GetIndexAndCreateQueryExp(int colIndex) const
1131 media_group_e groupIndex = MEDIA_CONTENT_GROUP_DISPLAY_NAME;;
1134 case 0://"ContentType", "MEDIA_TYPE"
1135 groupIndex = MEDIA_CONTENT_GROUP_TYPE;
1136 __inputExpr = "MEDIA_TYPE IS NOT NULL";
1138 case 1://"ContentFileName", "MEDIA_DISPLAY_NAME"
1139 groupIndex = MEDIA_CONTENT_GROUP_DISPLAY_NAME;
1140 __inputExpr = "MEDIA_DISPLAY_NAME IS NOT NULL";
1142 case 2://"ContentName", "MEDIA_CONTENT_NAME"
1143 groupIndex = MEDIA_CONTENT_GROUP_CONTENT_NAME;
1144 __inputExpr = "MEDIA_CONTENT_NAME IS NOT NULL";
1146 case 3://"Category", "MEDIA_CATEGORY"
1147 groupIndex = MEDIA_CONTENT_GROUP_CATEGORY;
1148 __inputExpr = "MEDIA_CATEGORY IS NOT NULL";
1150 case 4://"Author", "MEDIA_AUTHOR"
1151 groupIndex = MEDIA_CONTENT_GROUP_AUTHOR;
1152 __inputExpr = "MEDIA_AUTHOR IS NOT NULL";
1154 case 5://"keyword", "MEDIA_KEYWORD"
1155 groupIndex = MEDIA_CONTENT_GROUP_KEYWORD;
1156 __inputExpr = "MEDIA_KEYWORD IS NOT NULL";
1158 case 6://"Provider", "MEDIA_PROVIDER"
1159 groupIndex = MEDIA_CONTENT_GROUP_PROVIDER;
1160 __inputExpr = "MEDIA_PROVIDER IS NOT NULL";
1162 case 7://"Rating", "MEDIA_AGE_RATING"
1163 groupIndex = MEDIA_CONTENT_GROUP_AGE_RATING;
1164 __inputExpr = "MEDIA_AGE_RATING IS NOT NULL";
1166 case 8://"LocationTag", "MEDIA_LOCATION_TAG"
1167 groupIndex = MEDIA_CONTENT_GROUP_LOCATION_TAG;
1168 __inputExpr = "MEDIA_LOCATION_TAG IS NOT NULL";
1170 case 9://"ContentSize", "MEDIA_SIZE"
1171 groupIndex = MEDIA_CONTENT_GROUP_SIZE;
1172 __inputExpr = "MEDIA_SIZE IS NOT NULL";
1174 case 10://"DateTime", "MEDIA_ADDED_TIME"
1175 groupIndex = MEDIA_CONTENT_GROUP_ADDED_TIME;
1176 __inputExpr = "MEDIA_ADDED_TIME IS NOT NULL";
1178 case 11://"Latitude", "MEDIA_LATITUDE"
1179 groupIndex = MEDIA_CONTENT_GROUP_LATITUDE;
1180 __inputExpr = "MEDIA_LATITUDE IS NOT NULL";
1182 case 12://"Longitude", "MEDIA_LONGITUDE"
1183 groupIndex = MEDIA_CONTENT_GROUP_LONGITUDE;
1184 __inputExpr = "MEDIA_LONGITUDE IS NOT NULL";
1186 case 13://"Altitude", "MEDIA_ALTITUDE"
1187 groupIndex = MEDIA_CONTENT_GROUP_ALTITUDE;
1188 __inputExpr = "MEDIA_ALTITUDE IS NOT NULL";
1190 case 14://"Title", "MEDIA_TITLE"
1191 groupIndex = MEDIA_CONTENT_GROUP_TITLE;
1192 __inputExpr = "MEDIA_TITLE IS NOT NULL";
1194 case 15://"Artist", "MEDIA_ARTIST"
1195 groupIndex = MEDIA_CONTENT_GROUP_ARTIST;
1196 __inputExpr = "MEDIA_ARTIST IS NOT NULL";
1198 case 16://"Genre", "MEDIA_GENRE"
1199 groupIndex = MEDIA_CONTENT_GROUP_GENRE;
1200 __inputExpr = "MEDIA_GENRE IS NOT NULL";
1202 case 17://"Year", "MEDIA_YEAR"
1203 groupIndex = MEDIA_CONTENT_GROUP_YEAR;
1204 __inputExpr = "MEDIA_YEAR IS NOT NULL";
1206 case 18://"Composer", "MEDIA_COMPOSER"
1207 groupIndex = MEDIA_CONTENT_GROUP_COMPOSER;
1208 __inputExpr = "MEDIA_COMPOSER IS NOT NULL";
1210 case 19://"Album", "MEDIA_ALBUM"
1211 __inputExpr = "MEDIA_ALBUM IS NOT NULL";
1219 // Fills given column value list and destroys filter handle
1221 _ContentSearchImpl::FillColumnsList(int colIndex) const
1223 result r = E_SUCCESS;
1224 int ret = MEDIA_CONTENT_ERROR_NONE;
1226 media_group_e groupIndex = GetIndexAndCreateQueryExp(colIndex);
1228 r = CreateQueryFilter(true);
1229 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "CreateQueryFilter Failed.");
1231 if (colIndex == ALBUM_COLUMN_NUM)
1233 ret = media_album_get_album_count_from_db(__pFilterHandle.get(), &totalCount);
1237 ret = media_group_get_group_count_from_db(__pFilterHandle.get(), groupIndex, &totalCount);
1239 r = MapCoreErrorToNativeResult(ret);
1240 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, r, "Failed to perform media_album/group count_from_db operation.");
1242 SysLog(NID_CNT, "totalCount = %d for media_album/group count_from_db", totalCount);
1246 if (colIndex == ALBUM_COLUMN_NUM)
1248 r = ExecuteAndFillAlbumValues();
1249 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "ExecuteAndFillAlbumValues Failed.");
1253 r = ExecuteAndFillGetValueListN(groupIndex, colIndex);
1254 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "ExecuteAndFillGetValueListN Failed.");
1260 // prepares input expression to be sent for create filter and fills given column value list
1262 _ContentSearchImpl::FillColumnsList(int pageNo, int countPerPage, int& totalPageCount, int& totalCount, int colIndex) const
1264 result r = E_SUCCESS;
1265 int ret = MEDIA_CONTENT_ERROR_NONE;
1269 media_group_e groupIndex = GetIndexAndCreateQueryExp(colIndex);
1271 r = CreateQueryFilter(true);
1272 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "CreateQueryFilter Failed.");
1274 if (colIndex == ALBUM_COLUMN_NUM)
1276 ret = media_album_get_album_count_from_db(__pFilterHandle.get(), &totalCount);
1280 ret = media_group_get_group_count_from_db(__pFilterHandle.get(), groupIndex, &totalCount);
1282 r = MapCoreErrorToNativeResult(ret);
1283 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, r, "Failed to perform media_album/group count_from_db operation.");
1285 SysLog(NID_CNT, "totalCount = %d for media_album/group count_from_db", totalCount);
1289 if ((totalCount % countPerPage) == 0)
1291 totalPageCount = totalCount / countPerPage;
1295 totalPageCount = (totalCount / countPerPage) + 1;
1298 SysTryReturnResult(NID_CNT, ((pageNo >= 1) && (pageNo <= totalPageCount)) , r, "(pageNo < 1) || (pageNo > totalPageCount).");
1300 offset = (pageNo * countPerPage) - countPerPage;
1302 SysLog(NID_CNT, "GetValueListN totalCount [%d] totalPageCount[%d] __countPerPage[%d] __pageNo[%d] offset[%d]",
1303 totalCount, totalPageCount, countPerPage, pageNo, offset);
1305 ret = media_filter_set_offset(__pFilterHandle.get(),offset,countPerPage);
1306 r = MapCoreErrorToNativeResult(ret);
1307 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, r, "failed to perform media_filter_set_offset operation.");
1309 if (colIndex == ALBUM_COLUMN_NUM)
1311 r = ExecuteAndFillAlbumValues();
1312 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "ExecuteAndFillAlbumValues Failed.");
1316 r = ExecuteAndFillGetValueListN(groupIndex, colIndex);
1317 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "ExecuteAndFillGetValueListN Failed.");
1321 else if (pageNo > 1)
1323 SysLogException(NID_CNT, r = E_INVALID_ARG, "[%s] (pageNo > 1) and (totalcount = 0).", GetErrorMessage(E_INVALID_ARG));
1329 // fills given column value list for GetValuelistN api
1331 _ContentSearchImpl::ExecuteAndFillGetValueListN(media_group_e groupIndex, int colIndex) const
1333 SysLog(NID_CNT, "Enter\n");
1335 int ret = MEDIA_CONTENT_ERROR_NONE;
1336 result r = E_SUCCESS;
1337 result res = E_SUCCESS;
1338 std::unique_ptr<GList, SearchGListDeleter> pItemList;
1339 GList* pTemp = NULL;
1341 std::unique_ptr<Object> pValue;
1345 long long contentSize = 0;
1346 long long addedTime = 0;
1349 char *pColumnVal = null;
1350 int contentType = 0;
1352 pTemp = pItemList.get();
1354 ret = media_group_foreach_group_from_db(__pFilterHandle.get(), groupIndex, GroupItemCb, &pTemp);
1355 r = MapCoreErrorToNativeResult(ret);
1356 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform media_group_foreach_group_from_db operation.");
1358 SysTryReturnResult(NID_CNT, pTemp != NULL, r, "media_info_foreach_media_from_db pTemp is null.");
1360 for (int idx = 0; idx < (int)g_list_length(pTemp); idx++)
1362 SysLog(NID_CNT, "idx = %d and (int)g_list_length(pItemList) = %d", idx, (int)g_list_length(pTemp));
1364 pColumnVal = (char *)g_list_nth_data(pTemp, idx);
1366 String strColVal(pColumnVal);
1368 _ContentUtility::DoSafeFree(pColumnVal);
1370 SysLog(NID_CNT, "pColumnVal = %ls", strColVal.GetPointer());
1374 case 0://"ContentType", "MEDIA_TYPE"
1375 if ((strColVal.CompareTo(L"Unknown") != 0) && (!strColVal.IsEmpty()))
1377 res = Integer::Parse(strColVal, contentType);
1378 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] Integer parse failed.", GetErrorMessage(res));
1380 switch ((media_content_type_e)contentType)
1382 case MEDIA_CONTENT_TYPE_OTHERS:
1383 pValue.reset(new (std::nothrow) String(CONTENT_TYPE_OTHER));
1384 SysLog(NID_CNT, "mediaType = CONTENT_TYPE_OTHER");
1386 case MEDIA_CONTENT_TYPE_IMAGE:
1387 pValue.reset(new (std::nothrow) String(CONTENT_TYPE_IMAGE));
1388 SysLog(NID_CNT, "mediaType = CONTENT_TYPE_IMAGE");
1390 case MEDIA_CONTENT_TYPE_SOUND:
1392 case MEDIA_CONTENT_TYPE_MUSIC:
1393 pValue.reset(new (std::nothrow) String(CONTENT_TYPE_AUDIO));
1394 SysLog(NID_CNT, "mediaType = CONTENT_TYPE_AUDIO");
1396 case MEDIA_CONTENT_TYPE_VIDEO:
1397 pValue.reset(new (std::nothrow) String(CONTENT_TYPE_VIDEO));
1398 SysLog(NID_CNT, "mediaType = CONTENT_TYPE_VIDEO");
1404 case 1://"ContentFileName", "MEDIA_DISPLAY_NAME"
1406 case 2://"ContentName", "MEDIA_CONTENT_NAME"
1408 case 3://"Category", "MEDIA_CATEGORY"
1410 case 4://"Author", "MEDIA_AUTHOR"
1412 case 5://"keyword", "MEDIA_KEYWORD"
1414 case 6://"Provider", "MEDIA_PROVIDER"
1416 case 7://"Rating", "MEDIA_AGE_RATING"
1418 case 8://"LocationTag", "MEDIA_LOCATION_TAG"
1420 case 14://"Title", "MEDIA_TITLE"
1422 case 15://"Artist", "MEDIA_ARTIST"
1424 case 16://"Genre", "MEDIA_GENRE"
1426 case 17://"Year", "MEDIA_YEAR"
1428 case 18://"Composer", "MEDIA_COMPOSER"
1430 pValue.reset(new (std::nothrow) String(strColVal));
1433 case 9://"ContentSize", "MEDIA_SIZE"
1434 if ((strColVal.CompareTo(L"Unknown") != 0) && (!strColVal.IsEmpty()))
1436 res = LongLong::Parse(strColVal, contentSize);
1437 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] LongLong parse failed.", GetErrorMessage(res));
1440 pValue.reset(new (std::nothrow) LongLong(contentSize));
1442 case 10://"DateTime", "MEDIA_ADDED_TIME"
1443 if ((strColVal.CompareTo(L"Unknown") != 0) && (!strColVal.IsEmpty()))
1445 res = LongLong::Parse(strColVal, addedTime);
1446 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] LongLong parse failed.", GetErrorMessage(res));
1449 res = dateTime.SetValue(1970, 1, 1);
1450 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] dateTime.SetValue failed.", GetErrorMessage(res));
1452 res = dateTime.AddSeconds(addedTime);
1453 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] dateTime.AddSeconds failed.", GetErrorMessage(res));
1455 SysLog(NID_CNT, "DateTime : %ls", dateTime.ToString().GetPointer());
1457 pValue.reset(new (std::nothrow) DateTime(dateTime));
1460 case 11://"Latitude", "MEDIA_LATITUDE"
1462 case 12://"Longitude", "MEDIA_LONGITUDE"
1464 case 13://"Altitude", "MEDIA_ALTITUDE"
1465 if ((strColVal.CompareTo(L"Unknown") != 0) && (!strColVal.IsEmpty()))
1467 dVal = _LocalizedNumParser::ToDouble(strColVal, "C");
1468 r = GetLastResult();
1469 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform ToDouble operation.");
1471 pValue.reset(new (std::nothrow) Double(dVal));
1474 case 19://"Album", "MEDIA_ALBUM"
1479 if (pValue.get() != NULL)
1481 r = __pFinalOutList->Add(*(pValue.release()));
1482 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform arraylist Add operation.");
1490 _ContentSearchImpl::ExecuteAndFillAlbumValues(void) const
1492 int ret = MEDIA_CONTENT_ERROR_NONE;
1493 result r = E_SUCCESS;
1494 std::unique_ptr<GList, SearchGListDeleter> pItemList;
1495 GList* pTemp = NULL;
1496 std::unique_ptr<media_album_s, AlbumHandleDeleter> pAlbumHandle;
1497 std::unique_ptr<media_album_s, AlbumHandleDeleter> pTempAlbumHandle;
1500 std::unique_ptr<char, CharDeleter> pAlbumName;
1501 std::unique_ptr< String > pValue;
1504 pTemp = pItemList.get();
1506 ret = media_album_foreach_album_from_db(__pFilterHandle.get(), AlbumItemCb, &pTemp);
1507 r = MapCoreErrorToNativeResult(ret);
1508 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform media_album_foreach_album_from_db operation.");
1509 SysTryReturnResult(NID_CNT, pTemp != NULL, r, "media_info_foreach_media_from_db pTemp is null.");
1511 for (int idx = 0; idx < (int)g_list_length(pTemp); idx++)
1513 pAlbumHandle.reset(static_cast<media_album_h>(g_list_nth_data(pTemp, idx)));
1514 ret = media_album_get_name(pAlbumHandle.get(), &pName);
1515 r = MapCoreErrorToNativeResult(ret);
1516 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform media_album_get_name.");
1520 SysLog(NID_CNT, "pColumnVal = %s", pName);
1522 pAlbumName.reset(pName);
1523 pValue.reset(new (std::nothrow) String(pAlbumName.get()));
1524 SysTryReturnResult(NID_CNT, pValue != NULL, E_OUT_OF_MEMORY, "media_info_foreach_media_from_db pTemp is null.");
1528 r = __pFinalOutList->Add(pValue.get());
1529 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform arraylist Add operation.");
1534 String* pTempNameList(static_cast< String* >(__pFinalOutList->GetAt(lastIndex)));
1536 if (pValue->CompareTo(*pTempNameList) != 0)
1538 r = __pFinalOutList->Add(pValue.get());
1539 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform arraylist Add operation.");
1552 _ContentSearchImpl::MapCoreErrorToNativeResult(int reason) const
1554 result r = E_SUCCESS;
1558 case MEDIA_CONTENT_ERROR_NONE:
1562 case MEDIA_CONTENT_ERROR_INVALID_PARAMETER:
1564 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_INVALID_PARAMETER");
1567 case MEDIA_CONTENT_ERROR_DB_FAILED:
1569 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_DB_FAILED");
1572 case MEDIA_CONTENT_ERROR_OUT_OF_MEMORY:
1573 r = E_OUT_OF_MEMORY;
1574 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_OUT_OF_MEMORY");
1578 SysLog(NID_CNT, "default");
1586 _ContentSearchImpl::ConvertErrorToResult(result res) const
1588 result r = E_SUCCESS;
1592 case E_FILE_NOT_FOUND:
1605 // Callback function registered to each media info details
1606 // all items are appended to the list
1608 MediaItemCb(media_info_h media, void* pUserdata)
1610 int ret = MEDIA_CONTENT_ERROR_NONE;
1611 media_info_h new_media = NULL;
1612 ret = media_info_clone(&new_media, media);
1613 SysTryLog(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, "[E_SYSTEM] Failed to perform media_info_clone");
1615 GList** pList = (GList**)pUserdata;
1616 *pList = g_list_append(*pList, new_media);
1621 // Callback function registered for column values
1622 // all items are appended to the list
1624 GroupItemCb(const char* pGroupName, void* pUserdata)
1626 char* pGrpName = strdup(pGroupName);
1627 GList** pList = (GList**)pUserdata;
1628 *pList = g_list_append(*pList, pGrpName);
1633 // Callback function registered to each media info details
1634 // all items are appended to the list
1636 AlbumItemCb(media_album_h album, void* pUserdata)
1638 int ret = MEDIA_CONTENT_ERROR_NONE;
1639 media_album_h new_album = NULL;
1640 ret = media_album_clone(&new_album, album);
1641 SysTryLog(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, "[E_SYSTEM] Failed to perform media_album_clone");
1643 GList** pList = (GList**)pUserdata;
1644 *pList = g_list_append(*pList, new_album);