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 <FBase_StringConverter.h>
34 #include <FBase_LocalizedNumParser.h>
35 #include "FCnt_ContentUtility.h"
36 #include "FCnt_ContentSearchImpl.h"
37 #include "FCnt_ContentInfoImpl.h"
38 #include "FCnt_ImageContentInfoImpl.h"
39 #include "FCnt_AudioContentInfoImpl.h"
40 #include "FCnt_VideoContentInfoImpl.h"
41 #include "FCnt_OtherContentInfoImpl.h"
42 #include "FCnt_ContentInfoHelper.h"
44 using namespace Tizen::Base;
45 using namespace Tizen::Base::Collection;
46 using namespace Tizen::Base::Utility;
47 using namespace Tizen::Io;
49 namespace Tizen { namespace Content
52 static const int QUERY_LENGTH = 4096;
54 // Declaration for Callback function registered to each media info details
55 bool MediaItemCb(media_info_h media, void* pUserdata);
56 // Declaration for Callback function registered to each column details
57 bool GroupItemCb(const char* pGroupName, void* pUserdata);
58 // Declaration for Callback function registered to each album details
59 bool AlbumItemCb(media_album_h album, void* pUserdata);
61 // Default constructor
62 _ContentSearchImpl::_ContentSearchImpl(void)
63 : __contentType(CONTENT_TYPE_UNKNOWN)
64 , __pFinalOutList(NULL)
66 , __inputColumnName(L"")
67 , __inputSortOrder(SORT_ORDER_NONE)
68 , __pFilterHandle(NULL)
70 SysLog(NID_CNT, "Enter\n");
74 // Default destructor (disconnects the DB connection)
75 _ContentSearchImpl::~_ContentSearchImpl(void)
77 SysLog(NID_CNT, "Enter\n");
79 int ret = MEDIA_CONTENT_ERROR_NONE;
82 ret = media_content_disconnect();
83 r = MapCoreErrorToNativeResult(ret);
84 SysTryLog(NID_CNT, r == E_SUCCESS, "[%s] Propagated in ~_ContentSearchImpl", GetErrorMessage(r));
88 _ContentSearchImpl::GetInstance(ContentSearch& contentSearch)
90 return contentSearch.__pImpl;
93 const _ContentSearchImpl*
94 _ContentSearchImpl::GetInstance(const ContentSearch& contentSearch)
96 return contentSearch.__pImpl;
99 //make a connection to DB
101 _ContentSearchImpl::Construct(ContentType type)
103 SysLog(NID_CNT, "Enter\n");
105 result r = E_SUCCESS;
106 int ret = MEDIA_CONTENT_ERROR_NONE;
108 ret = media_content_connect();
109 SysTryReturnResult(NID_CNT, r == E_SUCCESS , E_SYSTEM, "Failed to perform media_content_connect operation.");
111 __contentType = type;
116 // Creates a filter for the input query string along with content type
117 // Initializes filter handle
118 // Image - MEDIA_TYPE=0
119 // Vide0 - MEDIA_TYPE=1
120 // Audio - MEDIA_TYPE=2 or MEDIA_TYPE=3
121 // Others - MEDIA_TYPE=4
123 // Appends MEDIA_TYPE with "AND" (if the input expression is not empty and content type is not ALL) and input expression
124 // Sets the condition and order.
125 // If any argument is not proper E_INVALID_ARG is returned
127 _ContentSearchImpl::CreateQueryFilter(bool isAndAppendReq) const
129 int ret = MEDIA_CONTENT_ERROR_NONE;
130 result r = E_SUCCESS;
132 std::unique_ptr<char[]> pInputCond;
133 std::unique_ptr<char[]> pSortCol;
135 String inputCondition;
138 filter_h tempFilter = NULL;
140 ret = media_filter_create(&tempFilter);
141 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "Failed to perform media_filter_create operation.");
143 std::unique_ptr<filter_s, SearchFilterHandleDeleter> pFilterHandle(tempFilter);
144 SysTryReturnResult(NID_CNT, pFilterHandle != null, E_OUT_OF_MEMORY, "pFilterHandle is null.");
146 switch (__contentType)
148 // Image-0,video-1,sound-2,music-3,other-4
149 case CONTENT_TYPE_OTHER:
150 inputCondition = "MEDIA_TYPE=4 ";
152 case CONTENT_TYPE_IMAGE:
153 inputCondition = "MEDIA_TYPE=0 ";
155 case CONTENT_TYPE_AUDIO:
156 inputCondition = "(MEDIA_TYPE=2 or MEDIA_TYPE=3) ";
158 case CONTENT_TYPE_VIDEO:
159 inputCondition = "MEDIA_TYPE=1 ";
161 case CONTENT_TYPE_ALL:
162 //If content type is CONTENT_TYPE_ALL, then MEDIA_TYPE is empty
168 if (!__inputExpr.IsEmpty())
170 if (isAndAppendReq && (!inputCondition.IsEmpty())) //For CONTENT_TYPE_ALL inputCondition is empty
172 r = inputCondition.Append("AND ");
173 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform append operation.");
176 r = inputCondition.Append(__inputExpr);
177 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform append operation.");
180 if (!inputCondition.IsEmpty())
182 //CopyToCharArrayN: utility function, converts a osp string to char*
183 pInputCond = std::unique_ptr<char[]>(_StringConverter::CopyToCharArrayN(inputCondition));
184 SysTryReturnResult(NID_CNT, pInputCond, E_OUT_OF_MEMORY, "pInputCond is NULL.");
186 SysLog(NID_CNT, "pInputCond = %s", pInputCond.get());
188 ret = media_filter_set_condition(pFilterHandle.get(), pInputCond.get(), MEDIA_CONTENT_COLLATE_DEFAULT);
189 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "Failed to perform media_filter_set_condition operation.");
192 if (!__inputColumnName.IsEmpty()) // SortColumn is optional in case of SearchN
194 //__inputColumnName (osp column name) is replaced with slpColumn (slp column name).
195 r = GetSlpColumnName(slpColumn);
196 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform GetSlpColumnName operation.");
198 //CopyToCharArrayN: utility function, converts a osp string to char*
200 pSortCol = std::unique_ptr<char[]>(_StringConverter::CopyToCharArrayN(slpColumn));
201 SysTryReturnResult(NID_CNT, pSortCol, E_OUT_OF_MEMORY, "pSortCol is NULL.");
203 if (__inputSortOrder == SORT_ORDER_ASCENDING)
205 ret = media_filter_set_order(pFilterHandle.get(), MEDIA_CONTENT_ORDER_ASC, pSortCol.get(), MEDIA_CONTENT_COLLATE_NOCASE);
206 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "Failed to perform media_filter_set_order operation.");
208 else if (__inputSortOrder == SORT_ORDER_DESCENDING)
210 ret = media_filter_set_order(pFilterHandle.get(), MEDIA_CONTENT_ORDER_DESC, 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.");
215 __pFilterHandle.reset(pFilterHandle.release());
220 // Osp column names are mapped with slp column names
221 // CONTENT_TYPE_OTHER and CONTENT_TYPE_IMAGE (0 - 13 ) are valid columns
222 // CONTENT_TYPE_VIDEO (0 - 16 ) are valid columns
223 // CONTENT_TYPE_ALL and CONTENT_TYPE_VIDEO (0 - 18 ) are valid columns
224 // if the given osp column is out of the specified range of the type, E_INVALID_ARG is retuned.
226 _ContentSearchImpl::GetSlpColumnName(String& inputCol) const
228 String ospColumnName(L"");
229 String slpColumnName(L"");
230 String columnName(__inputColumnName);
231 result r = E_SUCCESS;
233 switch (__contentType)
235 case CONTENT_TYPE_OTHER:
237 case CONTENT_TYPE_IMAGE:
238 maxCols = MAX_QUERY_COLUMNS_FOR_IMAGE_OTHERS;
240 case CONTENT_TYPE_VIDEO:
241 maxCols = MAX_QUERY_COLUMNS_FOR_VIDEO;
243 case CONTENT_TYPE_AUDIO:
245 case CONTENT_TYPE_ALL:
246 maxCols = MAX_QUERY_COLUMNS;
251 for (int colIndex = 0; colIndex < maxCols; colIndex++)
253 ospColumnName.Clear();
254 slpColumnName.Clear();
256 ospColumnName = dbfieldinfo[colIndex].dbFieldOspName ;
257 slpColumnName = dbfieldinfo[colIndex].dbFieldSlpName ;
259 ospColumnName.ToUpper();
260 columnName.ToUpper();
261 if (columnName == ospColumnName)
263 inputCol = slpColumnName;
267 return E_INVALID_ARG;
270 //If the input expression contains any osp column name, it will be replaced with slp column name.
271 // only CONTENT_TYPE_AUDIO and CONTENT_TYPE_ALL allowed to use all given columns
272 // so, check for invalid column for CONTENT_TYPE_OTHER,CONTENT_TYPE_IMAGE and CONTENT_TYPE_VIDEO.
273 // all the osp columns in the expression should be replaced with slp column names.
274 // ' is used as a delimeter in parsing user query. so, \\' is saved as a special@apostrophe string.
275 // \\' is replaced with '', which considers ' as normal character.
278 _ContentSearchImpl::ReplaceOspColumnNameWithSlp(void) const
280 String ospColumnName(L"");
281 String slpColumnName(L"");
282 String splApostrophe(L"special@apostrophe");
283 result r = E_SUCCESS;
288 String strToBeReplaced(L"\\'");
289 int strLen = strToBeReplaced.GetLength();
292 while(E_SUCCESS == __inputExpr.IndexOf(strToBeReplaced,startIndex,indexOf))
294 int lenAfterSubStr = indexOf + strLen;
295 while ((lenAfterSubStr < __inputExpr.GetLength()) && (__inputExpr[lenAfterSubStr] == ' '))
299 if ((lenAfterSubStr < __inputExpr.GetLength()) && ((__inputExpr[lenAfterSubStr] == '\'') ||
300 ((!__inputExpr.StartsWith(L"AND ", lenAfterSubStr)) && (!__inputExpr.StartsWith(L"OR ", lenAfterSubStr)))))
302 r = __inputExpr.Remove(indexOf,strLen);
303 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "Failed to perform Remove operation.");
304 r = __inputExpr.Insert(splApostrophe,indexOf);
305 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "Failed to perform Insert operation.");
306 startIndex = indexOf + splApostrophe.GetLength();
310 startIndex = lenAfterSubStr;
314 SysLog(NID_CNT, "__inputExpr after splApostrophe append = %ls", __inputExpr.GetPointer());
316 switch (__contentType)
318 case CONTENT_TYPE_OTHER:
320 case CONTENT_TYPE_IMAGE:
321 r = CheckInvalidColumnInQuery();
322 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_INVALID_ARG, "Invalid Column In QueryString.");
323 maxCols = MAX_QUERY_COLUMNS_FOR_IMAGE_OTHERS;
325 case CONTENT_TYPE_VIDEO:
326 r = CheckInvalidColumnInQuery();
327 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_INVALID_ARG, "Invalid Column In QueryString.");
328 maxCols = MAX_QUERY_COLUMNS_FOR_VIDEO;
330 case CONTENT_TYPE_AUDIO:
332 case CONTENT_TYPE_ALL:
333 maxCols = MAX_QUERY_COLUMNS;
338 for (int colIndex = 0; colIndex < maxCols; colIndex++)
340 ospColumnName.Clear();
341 slpColumnName.Clear();
343 ospColumnName = dbfieldinfo[colIndex].dbFieldOspName ;
344 slpColumnName = dbfieldinfo[colIndex].dbFieldSlpName ;
346 ReplaceString(ospColumnName,slpColumnName);
349 // Append ESCAPE '\' for LIKE query
350 r = AppendEscapeKeywordForLikeQuery();
351 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "AppendEscapeKeywordForLikeQuery failed.");
353 r = ReplaceDateTimeStringWithInt();
354 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_INVALID_ARG, "ReplaceDateTimeStringWithInt failed.");
356 // replace splApostrophe string with actual
357 r = __inputExpr.Replace(splApostrophe, "''");
358 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string Replace failed.");
363 //This function is to appened ESCAPE keyword for _ and % special characters in LIKE query.
366 _ContentSearchImpl::AppendEscapeKeywordForLikeQuery(void) const
368 String delim = L"'"; //Delimeters is ' .
369 result r = E_SUCCESS;
371 bool isAppendEscape = false;
374 String inputExpr = __inputExpr;
376 // Create a StringTokenizer instance
377 StringTokenizer strTok(inputExpr, delim);
381 while (strTok.HasMoreTokens())
383 r = strTok.GetNextToken(token);
384 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "GetNextToken failed.");
385 if (isCol) //column name
389 tokenUpper.ToUpper();
390 if (tokenUpper.Contains(" LIKE"))
392 isAppendEscape = true;
396 isAppendEscape = false;
398 r = inputExpr.Append(token);
399 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
401 else // value of the column
404 r = inputExpr.Append("'");
405 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
406 r = inputExpr.Append(token);
407 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
408 r = inputExpr.Append("'");
409 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
413 if (token.Contains("\\_") || token.Contains("\\%"))
415 r = inputExpr.Append("ESCAPE'\\' ");
416 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
423 r = __inputExpr.Insert(inputExpr, 0);
424 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string insert failed.");
429 //This function is to replace DateTime value(osp datetime type is string) which is string with int.(SLP dateTime column type is int)
432 _ContentSearchImpl::ReplaceDateTimeStringWithInt(void) const
434 String delim = L"'"; //Delimeters is ' .
435 result r = E_SUCCESS;
437 bool isConvertReq = false;
438 bool isBetweenExistsInDateTimeQuery = false;
441 String inputExpr = __inputExpr;
443 if(!inputExpr.Contains("MEDIA_ADDED_TIME"))
448 // Create a StringTokenizer instance
449 StringTokenizer strTok(inputExpr, delim);
453 while (strTok.HasMoreTokens())
455 r = strTok.GetNextToken(token);
456 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "GetNextToken failed.");
457 if (isCol) //column name
461 tokenUpper.ToUpper();
462 if(isBetweenExistsInDateTimeQuery)
464 isBetweenExistsInDateTimeQuery = false;
469 if (tokenUpper.Contains("MEDIA_ADDED_TIME"))
471 if (tokenUpper.Contains("BETWEEN"))
473 isBetweenExistsInDateTimeQuery = true;
479 isConvertReq = false;
483 r = inputExpr.Append(token);
484 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string append failed.");
486 else // value of the column
489 r = inputExpr.Append("'");
490 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string append failed.");
494 Tizen::Base::DateTime dt;
495 r = Tizen::Base::DateTime::Parse(token, dt);
496 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to parse DateTime.");
498 int year = dt.GetYear();
499 int month = dt.GetMonth();
500 int day = dt.GetDay();
501 int hour = dt.GetHour();
502 int minute = dt.GetMinute();
503 int second = dt.GetSecond();
509 timeInfo = localtime(&rawTime);
510 timeInfo->tm_year = year - 1900;
511 timeInfo->tm_mon = month - 1;
512 timeInfo->tm_mday = day;
513 timeInfo->tm_hour = hour;
514 timeInfo->tm_min = minute;
515 timeInfo->tm_sec = second;
517 time_t seconds = mktime(timeInfo);
518 SysTryReturnResult(NID_CNT, seconds != -1, E_INVALID_ARG, "Failed to convert DateTime to broken-down time.");
520 long long ticksInSeconds = (long long)seconds;
522 r = inputExpr.Append(ticksInSeconds);
523 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string append failed.");
527 r = inputExpr.Append(token);
528 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string append failed.");
531 r = inputExpr.Append("'");
532 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string append failed.");
537 r = __inputExpr.Insert(inputExpr, 0);
538 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string insert failed.");
543 // CONTENT_TYPE_OTHER and CONTENT_TYPE_IMAGE (0 - 13 ) are valid columns
544 // CONTENT_TYPE_VIDEO (0 - 16 ) are valid columns
545 // CONTENT_TYPE_ALL and CONTENT_TYPE_VIDEO (0 - 18 ) are valid columns
546 // This functions checks for invalid column in the given input string (only allowed columns should be used by content type other wise
547 // E_INVALID_ARG is returned)
548 // StringTokenizer is used to parse input expression, by using delimater "'", to differentiate column and value.
549 // As values may also contain column names
550 // Ex: 1. where author = syam_author_01 2. where album = jalsa_album_name_01.
553 _ContentSearchImpl::CheckInvalidColumnInQuery(void) const
555 result r = E_SUCCESS;
557 String delim = L"'"; //Delimeters is ' .
558 bool isColReplaceReq = true;
560 String inputExpr = __inputExpr;
562 // Create a StringTokenizer instance
563 StringTokenizer strTok(inputExpr, delim);
567 while (strTok.HasMoreTokens())
569 r = strTok.GetNextToken(token);
570 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "strTok GetNextToken failed.");
572 SysLog(NID_CNT, "In CheckInvalidColumnInQuery token[%d] = %ls", ++tokenNo, token.GetPointer());
576 isColReplaceReq = false;
577 r = inputExpr.Append(token);
578 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
580 switch (__contentType)
582 case CONTENT_TYPE_OTHER:
584 case CONTENT_TYPE_IMAGE:
585 if ((token.Contains("TITLE")) || (token.Contains("ARTIST")) || (token.Contains("GENRE")))
587 SysLog(NID_CNT, "Title or Artist or Genre are not valid cloumns for this content type");
588 return E_INVALID_ARG;
591 case CONTENT_TYPE_VIDEO:
592 if ((token.Contains("COMPOSER")) || (token.Contains("ALBUM")))
594 SysLog(NID_CNT, "Composer or Album are not valid cloumns for this content type");
595 return E_INVALID_ARG;
604 isColReplaceReq = true;
605 r = inputExpr.Append("'");
606 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
607 r = inputExpr.Append(token);
608 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
609 r = inputExpr.Append("'");
610 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
616 // It replaces native column name with core column name.
617 // StringTokenizer is used to parse input expression, by using delimiter "'", to differentiate column and value.
618 // As values may also contain column names
619 // Only column names are replaced but not values(values may contain column names)
620 // Ex: 1. where author = syam_author_01 2. where album = jalsa_album_name_01.
623 _ContentSearchImpl::ReplaceString(String ospColumnName, String slpColumnName) const
625 String delim = L"'"; //Delimiters is ' .
626 result r = E_SUCCESS;
627 bool isColReplaceReq = true;
629 String inputExpr = __inputExpr;
631 // Create a StringTokenizer instance
632 StringTokenizer strTok(inputExpr, delim);
636 while (strTok.HasMoreTokens())
638 r = strTok.GetNextToken(token); // Osp, StringTokenizer, Sample, code
639 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string GetNextToken() failed.");
640 if (isColReplaceReq) //column name
642 isColReplaceReq = false;
643 r = token.Replace(ospColumnName, slpColumnName);
644 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string replace() failed.");
645 r = inputExpr.Append(token);
646 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
648 else // value of the column
650 isColReplaceReq = true;
651 r = inputExpr.Append("'");
652 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
653 r = inputExpr.Append(token);
654 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
655 r = inputExpr.Append("'");
656 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
660 r = __inputExpr.Insert(inputExpr, 0);
661 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string insert() failed.");
666 // Returns list of search result for the given expression and content type.
668 _ContentSearchImpl::SearchN(int pageNo, int countPerPage, int& totalPageCount, int& totalCount, const String& whereExpr, const String& sortColumn, SortOrder sortOrder) const
670 SysLog(NID_CNT, "pageNo = %d, countPerPage = %d, whereExpr = %ls", pageNo, countPerPage, whereExpr.GetPointer());
674 result r = E_SUCCESS;
675 int ret = MEDIA_CONTENT_ERROR_NONE;
678 __inputColumnName.Clear();
680 __inputColumnName = sortColumn;
681 __inputSortOrder = sortOrder;
685 if (!whereExpr.IsEmpty()) // copy whereExpr if not empty to class variable __inputExpr
687 r = __inputExpr.Append(whereExpr);
688 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[%s] __inputExpr.Append Failed as whereExpr is not empty.", GetErrorMessage(r));
690 r = ReplaceOspColumnNameWithSlp();
691 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[%s] ReplaceOspColumnNameWithSlp for InputExpr Failed.", GetErrorMessage(r));
693 SysLog(NID_CNT, "After replace __inputExpr = %ls", __inputExpr.GetPointer());
695 if ((__inputColumnName.IsEmpty()) && ((__inputSortOrder == SORT_ORDER_ASCENDING) || (__inputSortOrder == SORT_ORDER_DESCENDING)))
697 SysLog(NID_CNT, "sort column name is empty and sort oder is not none. so,E_INVALID_ARG occured.");
698 SetLastResult(E_INVALID_ARG);
703 std::unique_ptr<ArrayList, AllElementsDeleter> pFinalOutList(new (std::nothrow) ArrayList());
704 SysTryReturn(NID_CNT, pFinalOutList.get() != null, NULL, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to construct ArrayList.");
706 r = pFinalOutList->Construct();
707 SysTryReturn(NID_CNT, !IsFailed(r), NULL, r, "[%s] Failed to construct ArrayList.", GetErrorMessage(r));
709 __pFinalOutList = std::move(pFinalOutList);
711 r = CreateQueryFilter(true);
712 SysTryReturn(NID_CNT, !IsFailed(r), NULL, r, "[%s] Failed to perform CreateQueryFilter operation.", GetErrorMessage(r));
714 ret = media_info_get_media_count_from_db(__pFilterHandle.get(), &totalCount);
715 r = MapCoreErrorToNativeResult(ret);
716 SysTryReturn(NID_CNT, r == E_SUCCESS , NULL, r, "[%s] Failed to perform media_info_get_media_count_from_db operation.", GetErrorMessage(r));
718 SysLog(NID_CNT, "totalCount is [%d] for media_info_get_media_count_from_db", totalCount);
722 if ((totalCount % countPerPage) == 0)
724 totalPageCount = totalCount / countPerPage;
728 totalPageCount = (totalCount / countPerPage) + 1;
731 SysTryReturn(NID_CNT, ((pageNo >= 1) && (pageNo <= totalPageCount)) , NULL, E_INVALID_ARG, "[E_INVALID_ARG] (pageNo < 1) || (pageNo > totalPageCount).");
733 offset = (pageNo * countPerPage) - countPerPage;
735 SysLog(NID_CNT, " SearchN totalCount [%d] totalPageCount[%d] __countPerPage[%d] __pageNo[%d] offset[%d]",
736 totalCount, totalPageCount, countPerPage, pageNo, offset);
738 ret = media_filter_set_offset(__pFilterHandle.get(), offset, countPerPage);
739 r = MapCoreErrorToNativeResult(ret);
740 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r,
741 "[%s] Failed to perform media_filter_set_offset operation.", GetErrorMessage(r));
743 r = ExecuteAndFillFinalOutList();
744 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, E_SYSTEM, "[E_SYSTEM] ExecuteAndFillFinalOutList Failed.");
748 SysLogException(NID_CNT, E_INVALID_ARG, "[%s] (pageNo > 1) and (totalcount = 0).", GetErrorMessage(E_INVALID_ARG));
754 return __pFinalOutList.release();
757 // Fills final result list
759 _ContentSearchImpl::ExecuteAndFillFinalOutList(void) const
761 SysLog(NID_CNT, "Enter\n");
763 int ret = MEDIA_CONTENT_ERROR_NONE;
764 result r = E_SUCCESS;
766 std::unique_ptr<GList, SearchGListDeleter> pItemList;
768 std::unique_ptr<media_info_s, SearchMediaHandleDeleter> pMediaHandle;
770 std::unique_ptr<ImageContentInfo> pImageContentInfo;
771 std::unique_ptr<AudioContentInfo> pAudioContentInfo;
772 std::unique_ptr<VideoContentInfo> pVideoContentInfo;
773 std::unique_ptr<OtherContentInfo> pOtherContentInfo;
775 _ImageContentInfoImpl* pImageContentInfoImpl = null;
776 _AudioContentInfoImpl* pAudioContentInfoImpl = null;
777 _VideoContentInfoImpl* pVideoContentInfoImpl = null;
778 _OtherContentInfoImpl* pOtherContentInfoImpl = null;
780 std::unique_ptr<ContentSearchResult> pContentSearchResult;
782 pTemp = pItemList.get();
784 ret = media_info_foreach_media_from_db(__pFilterHandle.get(), MediaItemCb, &pTemp);
785 r = MapCoreErrorToNativeResult(ret);
786 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform media_info_foreach_media_from_db operation.");
788 SysTryReturnResult(NID_CNT, pTemp != NULL, r, "media_info_foreach_media_from_db pTemp is null.");
790 media_content_type_e mediaType = MEDIA_CONTENT_TYPE_OTHERS;
792 for (int idx = 0; idx < (int)g_list_length(pTemp); idx++)
794 pMediaHandle.reset(static_cast<media_info_h>(g_list_nth_data(pTemp, idx)));
796 ret = media_info_get_media_type(pMediaHandle.get(), &mediaType);
797 r = MapCoreErrorToNativeResult(ret);
798 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform media_info_get_media_type.");
800 std::unique_ptr<char, UtilCharDeleter> pMediaPath;
801 char* pTempPath = null;
803 ret = media_info_get_file_path(pMediaHandle.get(), &pTempPath);
804 r = MapCoreErrorToNativeResult(ret);
805 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform media_info_get_file_path operation.");
807 pMediaPath.reset(pTempPath);
808 String contentPath(pMediaPath.get());
812 case MEDIA_CONTENT_TYPE_OTHERS:
813 pOtherContentInfo = std::unique_ptr<OtherContentInfo>(new (std::nothrow) OtherContentInfo);
814 SysTryReturnResult(NID_CNT, pOtherContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pOtherContentInfo.");
816 r = pOtherContentInfo->Construct(&contentPath);
817 r = ConvertErrorToResult(r);
818 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Construct operation to OtherContentInfo.");
820 pOtherContentInfoImpl = null;
821 pOtherContentInfoImpl = _OtherContentInfoImpl::GetInstance(*(pOtherContentInfo.get()));
822 SysTryReturnResult(NID_CNT, pOtherContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to assign operation to pOtherContentInfoImpl.");
824 r = _ContentUtility::FillContentData(pMediaHandle.get(), pOtherContentInfoImpl);
825 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
827 _ContentInfoHelper::SetContentInfoImpl(pOtherContentInfo.get(), pOtherContentInfoImpl);
829 pContentSearchResult = std::unique_ptr<ContentSearchResult>(new (std::nothrow) ContentSearchResult);
830 SysTryReturnResult(NID_CNT, pContentSearchResult.get() != null, E_OUT_OF_MEMORY, "Failed to create pContentSearchResult.");
832 pContentSearchResult->SetContentType(CONTENT_TYPE_OTHER);
833 pContentSearchResult->SetContentInfo(pOtherContentInfo.release());
835 // Shallow copy, adds just the pointer: not the element
836 r = __pFinalOutList->Add(*(pContentSearchResult.release()));
837 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation for ArrayList.");
840 case MEDIA_CONTENT_TYPE_IMAGE:
841 pImageContentInfo = std::unique_ptr<ImageContentInfo>(new (std::nothrow) ImageContentInfo);
842 SysTryReturnResult(NID_CNT, pImageContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pImageContentInfo.");
844 r = pImageContentInfo->Construct(&contentPath);
845 r = ConvertErrorToResult(r);
846 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Construct operation to ImageContentInfo.");
848 pImageContentInfoImpl = null;
849 pImageContentInfoImpl = _ImageContentInfoImpl::GetInstance(*(pImageContentInfo.get()));
850 SysTryReturnResult(NID_CNT, pImageContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to assign operation to pImageContentInfoImpl.");
852 r = _ContentUtility::FillContentData(pMediaHandle.get(), pImageContentInfoImpl);
853 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
855 r = _ContentUtility::FillImageContentData(pMediaHandle.get(), pImageContentInfoImpl);
856 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform GetDataFromImageTable operation.");
858 _ContentInfoHelper::SetContentInfoImpl(pImageContentInfo.get(), pImageContentInfoImpl);
860 pContentSearchResult = std::unique_ptr<ContentSearchResult>(new (std::nothrow) ContentSearchResult);
861 SysTryReturnResult(NID_CNT, pContentSearchResult.get() != null, E_OUT_OF_MEMORY, "Failed to create pContentSearchResult.");
863 pContentSearchResult->SetContentType(CONTENT_TYPE_IMAGE);
864 pContentSearchResult->SetContentInfo(pImageContentInfo.release());
866 // Shallow copy, adds just the pointer: not the element
867 r = __pFinalOutList->Add(*(pContentSearchResult.release()));
868 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation for ArrayList.");
871 case MEDIA_CONTENT_TYPE_MUSIC:
873 case MEDIA_CONTENT_TYPE_SOUND:
874 pAudioContentInfo = std::unique_ptr<AudioContentInfo>(new (std::nothrow) AudioContentInfo);
875 SysTryReturnResult(NID_CNT, pAudioContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pAudioContentInfo.");
877 r = pAudioContentInfo->Construct(&contentPath);
878 r = ConvertErrorToResult(r);
879 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Construct operation to AudioContentInfo.");
881 pAudioContentInfoImpl = null;
882 pAudioContentInfoImpl = _AudioContentInfoImpl::GetInstance(*(pAudioContentInfo.get()));
883 SysTryReturnResult(NID_CNT, pAudioContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to assign operation to pAudioContentInfoImpl.");
885 r = _ContentUtility::FillContentData(pMediaHandle.get(), pAudioContentInfoImpl);
886 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
888 r = _ContentUtility::FillAudioContentData(pMediaHandle.get(), pAudioContentInfoImpl);
889 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillAudioContentData operation.");
891 _ContentInfoHelper::SetContentInfoImpl(pAudioContentInfo.get(), pAudioContentInfoImpl);
893 pContentSearchResult = std::unique_ptr<ContentSearchResult>(new (std::nothrow) ContentSearchResult);
894 SysTryReturnResult(NID_CNT, pContentSearchResult.get() != null, E_OUT_OF_MEMORY, "Failed to create pContentSearchResult.");
896 pContentSearchResult->SetContentType(CONTENT_TYPE_AUDIO);
897 pContentSearchResult->SetContentInfo(pAudioContentInfo.release());
899 // Shallow copy, adds just the pointer: not the element
900 r = __pFinalOutList->Add(*(pContentSearchResult.release()));
901 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation for ArrayList.");
904 case MEDIA_CONTENT_TYPE_VIDEO:
905 pVideoContentInfo = std::unique_ptr<VideoContentInfo>(new (std::nothrow) VideoContentInfo);
906 SysTryReturnResult(NID_CNT, pVideoContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pVideoContentInfo.");
908 r = pVideoContentInfo->Construct(&contentPath);
909 r = ConvertErrorToResult(r);
910 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Construct operation to VideoContentInfo.");
912 pVideoContentInfoImpl = null;
913 pVideoContentInfoImpl = _VideoContentInfoImpl::GetInstance(*(pVideoContentInfo.get()));
914 SysTryReturnResult(NID_CNT, pVideoContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to assign operation to pVideoContentInfoImpl.");
916 r = _ContentUtility::FillContentData(pMediaHandle.get(), pVideoContentInfoImpl);
917 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
919 r = _ContentUtility::FillVideoContentData(pMediaHandle.get(), pVideoContentInfoImpl);
920 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillVideoContentData operation.");
922 _ContentInfoHelper::SetContentInfoImpl(pVideoContentInfo.get(), pVideoContentInfoImpl);
924 pContentSearchResult = std::unique_ptr<ContentSearchResult>(new (std::nothrow) ContentSearchResult);
925 SysTryReturnResult(NID_CNT, pContentSearchResult.get() != null, E_OUT_OF_MEMORY, "Failed to create pContentSearchResult.");
927 pContentSearchResult->SetContentType(CONTENT_TYPE_VIDEO);
928 pContentSearchResult->SetContentInfo(pVideoContentInfo.release());
930 // Shallow copy, adds just the pointer: not the element
931 r = __pFinalOutList->Add(*(pContentSearchResult.release()));
932 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation for ArrayList.");
942 // returns given column value list in the requested order
944 _ContentSearchImpl::GetValueListN(const String& sortColumn, SortOrder sortOrder)
946 SysLog(NID_CNT, "inputColumn = %ls", sortColumn.GetPointer());
949 result r = E_SUCCESS;
953 __inputColumnName.Clear();
956 __inputColumnName = sortColumn;
957 __inputSortOrder = sortOrder;
959 String ospColumnName(L"");
960 String slpColumnName(L"");
962 String columnName(__inputColumnName);
964 if ((__inputColumnName.IsEmpty()) && ((__inputSortOrder == SORT_ORDER_ASCENDING) || (__inputSortOrder == SORT_ORDER_DESCENDING)))
966 SysLog(NID_CNT, "sort column name is empty and sort oder is not none. so,E_INVALID_ARG occured.");
967 SetLastResult(E_INVALID_ARG);
972 std::unique_ptr<ArrayList, AllElementsDeleter> pFinalOutList(new (std::nothrow) ArrayList());
973 SysTryReturn(NID_CNT, pFinalOutList.get() != null, NULL, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to construct ArrayList.");
975 r = pFinalOutList->Construct();
976 SysTryReturn(NID_CNT, !IsFailed(r), NULL, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to construct ArrayList.");
978 __pFinalOutList = std::move(pFinalOutList);
980 switch (__contentType)
982 case CONTENT_TYPE_OTHER:
984 case CONTENT_TYPE_IMAGE:
985 maxCols = MAX_QUERY_COLUMNS_FOR_IMAGE_OTHERS;
987 case CONTENT_TYPE_VIDEO:
988 maxCols = MAX_QUERY_COLUMNS_FOR_VIDEO;
990 case CONTENT_TYPE_AUDIO:
992 case CONTENT_TYPE_ALL:
993 maxCols = MAX_QUERY_COLUMNS;
999 for (colIndex = 0; colIndex < maxCols; colIndex++)
1001 ospColumnName.Clear();
1002 slpColumnName.Clear();
1004 ospColumnName = dbfieldinfo[colIndex].dbFieldOspName ;
1005 slpColumnName = dbfieldinfo[colIndex].dbFieldSlpName ;
1007 ospColumnName.ToUpper();
1008 columnName.ToUpper();
1009 if (columnName == ospColumnName)
1011 r = FillColumnsList(colIndex);
1012 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[%s] FillColumnsList Failed.", GetErrorMessage(r));
1016 if (colIndex == maxCols)
1018 SysLogException(NID_CNT, E_INVALID_ARG, "[%s] The column is invalid.", GetErrorMessage(E_INVALID_ARG));
1024 return __pFinalOutList.release();
1027 // returns given column value list in the requested order
1029 _ContentSearchImpl::GetValueListN(int pageNo, int countPerPage, int& totalPageCount, int& totalCount, const String& sortColumn, SortOrder sortOrder) const
1031 SysLog(NID_CNT, "pageNo = %d, countPerPage = %d, inputColumn = %ls", pageNo, countPerPage, sortColumn.GetPointer());
1035 result r = E_SUCCESS;
1039 __inputColumnName.Clear();
1040 __inputExpr.Clear();
1042 __inputColumnName = sortColumn;
1043 __inputSortOrder = sortOrder;
1045 String ospColumnName(L"");
1046 String slpColumnName(L"");
1048 String columnName(__inputColumnName);
1050 if ((__inputColumnName.IsEmpty()) && ((__inputSortOrder == SORT_ORDER_ASCENDING) || (__inputSortOrder == SORT_ORDER_DESCENDING)))
1052 SysLog(NID_CNT, "sort column name is empty and sort oder is not none. so,E_INVALID_ARG occured.");
1053 SetLastResult(E_INVALID_ARG);
1058 std::unique_ptr<ArrayList, AllElementsDeleter> pFinalOutList(new (std::nothrow) ArrayList());
1059 SysTryReturn(NID_CNT, pFinalOutList.get() != null, NULL, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to construct ArrayList.");
1061 r = pFinalOutList->Construct();
1062 SysTryReturn(NID_CNT, !IsFailed(r), NULL, r, "[%s] Failed to construct ArrayList.", GetErrorMessage(r));
1064 __pFinalOutList = std::move(pFinalOutList);
1066 switch (__contentType)
1068 case CONTENT_TYPE_OTHER:
1070 case CONTENT_TYPE_IMAGE:
1071 maxCols = MAX_QUERY_COLUMNS_FOR_IMAGE_OTHERS;
1073 case CONTENT_TYPE_VIDEO:
1074 maxCols = MAX_QUERY_COLUMNS_FOR_VIDEO;
1076 case CONTENT_TYPE_AUDIO:
1078 case CONTENT_TYPE_ALL:
1079 maxCols = MAX_QUERY_COLUMNS;
1085 for (colIndex = 0; colIndex < maxCols; colIndex++)
1087 ospColumnName.Clear();
1088 slpColumnName.Clear();
1090 ospColumnName = dbfieldinfo[colIndex].dbFieldOspName ;
1091 slpColumnName = dbfieldinfo[colIndex].dbFieldSlpName ;
1093 ospColumnName.ToUpper();
1094 columnName.ToUpper();
1095 if (columnName == ospColumnName)
1097 r = FillColumnsList(pageNo, countPerPage, totalPageCount, totalCount, colIndex);
1098 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[%s] FillColumnsList Failed.", GetErrorMessage(r));
1102 if (colIndex == maxCols)
1104 SysLogException(NID_CNT, E_INVALID_ARG, "[%s] The column is invalid.", GetErrorMessage(E_INVALID_ARG));
1110 return __pFinalOutList.release();
1113 // prepares query expression to be used in group api. colIndex is mapped to actual group value.
1115 _ContentSearchImpl::GetIndexAndCreateQueryExp(int colIndex) const
1117 media_group_e groupIndex = MEDIA_CONTENT_GROUP_DISPLAY_NAME;;
1120 case 0://"ContentType", "MEDIA_TYPE"
1121 groupIndex = MEDIA_CONTENT_GROUP_TYPE;
1122 __inputExpr = "MEDIA_TYPE IS NOT NULL";
1124 case 1://"ContentFileName", "MEDIA_DISPLAY_NAME"
1125 groupIndex = MEDIA_CONTENT_GROUP_DISPLAY_NAME;
1126 __inputExpr = "MEDIA_DISPLAY_NAME IS NOT NULL";
1128 case 2://"ContentName", "MEDIA_CONTENT_NAME"
1129 groupIndex = MEDIA_CONTENT_GROUP_CONTENT_NAME;
1130 __inputExpr = "MEDIA_CONTENT_NAME IS NOT NULL";
1132 case 3://"Category", "MEDIA_CATEGORY"
1133 groupIndex = MEDIA_CONTENT_GROUP_CATEGORY;
1134 __inputExpr = "MEDIA_CATEGORY IS NOT NULL";
1136 case 4://"Author", "MEDIA_AUTHOR"
1137 groupIndex = MEDIA_CONTENT_GROUP_AUTHOR;
1138 __inputExpr = "MEDIA_AUTHOR IS NOT NULL";
1140 case 5://"keyword", "MEDIA_KEYWORD"
1141 groupIndex = MEDIA_CONTENT_GROUP_KEYWORD;
1142 __inputExpr = "MEDIA_KEYWORD IS NOT NULL";
1144 case 6://"Provider", "MEDIA_PROVIDER"
1145 groupIndex = MEDIA_CONTENT_GROUP_PROVIDER;
1146 __inputExpr = "MEDIA_PROVIDER IS NOT NULL";
1148 case 7://"Rating", "MEDIA_AGE_RATING"
1149 groupIndex = MEDIA_CONTENT_GROUP_AGE_RATING;
1150 __inputExpr = "MEDIA_AGE_RATING IS NOT NULL";
1152 case 8://"LocationTag", "MEDIA_LOCATION_TAG"
1153 groupIndex = MEDIA_CONTENT_GROUP_LOCATION_TAG;
1154 __inputExpr = "MEDIA_LOCATION_TAG IS NOT NULL";
1156 case 9://"ContentSize", "MEDIA_SIZE"
1157 groupIndex = MEDIA_CONTENT_GROUP_SIZE;
1158 __inputExpr = "MEDIA_SIZE IS NOT NULL";
1160 case 10://"DateTime", "MEDIA_ADDED_TIME"
1161 groupIndex = MEDIA_CONTENT_GROUP_ADDED_TIME;
1162 __inputExpr = "MEDIA_ADDED_TIME IS NOT NULL";
1164 case 11://"Latitude", "MEDIA_LATITUDE"
1165 groupIndex = MEDIA_CONTENT_GROUP_LATITUDE;
1166 __inputExpr = "MEDIA_LATITUDE IS NOT NULL";
1168 case 12://"Longitude", "MEDIA_LONGITUDE"
1169 groupIndex = MEDIA_CONTENT_GROUP_LONGITUDE;
1170 __inputExpr = "MEDIA_LONGITUDE IS NOT NULL";
1172 case 13://"Altitude", "MEDIA_ALTITUDE"
1173 groupIndex = MEDIA_CONTENT_GROUP_ALTITUDE;
1174 __inputExpr = "MEDIA_ALTITUDE IS NOT NULL";
1176 case 14://"Title", "MEDIA_TITLE"
1177 groupIndex = MEDIA_CONTENT_GROUP_TITLE;
1178 __inputExpr = "MEDIA_TITLE IS NOT NULL";
1180 case 15://"Artist", "MEDIA_ARTIST"
1181 groupIndex = MEDIA_CONTENT_GROUP_ARTIST;
1182 __inputExpr = "MEDIA_ARTIST IS NOT NULL";
1184 case 16://"Genre", "MEDIA_GENRE"
1185 groupIndex = MEDIA_CONTENT_GROUP_GENRE;
1186 __inputExpr = "MEDIA_GENRE IS NOT NULL";
1188 case 17://"Year", "MEDIA_YEAR"
1189 groupIndex = MEDIA_CONTENT_GROUP_YEAR;
1190 __inputExpr = "MEDIA_YEAR IS NOT NULL";
1192 case 18://"Composer", "MEDIA_COMPOSER"
1193 groupIndex = MEDIA_CONTENT_GROUP_COMPOSER;
1194 __inputExpr = "MEDIA_COMPOSER IS NOT NULL";
1196 case 19://"Album", "MEDIA_ALBUM"
1197 __inputExpr = "MEDIA_ALBUM IS NOT NULL";
1205 // Fills given column value list and destroys filter handle
1207 _ContentSearchImpl::FillColumnsList(int colIndex) const
1209 result r = E_SUCCESS;
1210 int ret = MEDIA_CONTENT_ERROR_NONE;
1212 media_group_e groupIndex = GetIndexAndCreateQueryExp(colIndex);
1214 r = CreateQueryFilter(true);
1215 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "CreateQueryFilter Failed.");
1217 if (colIndex == ALBUM_COLUMN_NUM)
1219 ret = media_album_get_album_count_from_db(__pFilterHandle.get(), &totalCount);
1223 ret = media_group_get_group_count_from_db(__pFilterHandle.get(), groupIndex, &totalCount);
1225 r = MapCoreErrorToNativeResult(ret);
1226 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, r, "Failed to perform media_album/group count_from_db operation.");
1228 SysLog(NID_CNT, "totalCount = %d for media_album/group count_from_db", totalCount);
1232 if (colIndex == ALBUM_COLUMN_NUM)
1234 r = ExecuteAndFillAlbumValues();
1235 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "ExecuteAndFillAlbumValues Failed.");
1239 r = ExecuteAndFillGetValueListN(groupIndex, colIndex);
1240 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "ExecuteAndFillGetValueListN Failed.");
1246 // prepares input expression to be sent for create filter and fills given column value list
1248 _ContentSearchImpl::FillColumnsList(int pageNo, int countPerPage, int& totalPageCount, int& totalCount, int colIndex) const
1250 result r = E_SUCCESS;
1251 int ret = MEDIA_CONTENT_ERROR_NONE;
1255 media_group_e groupIndex = GetIndexAndCreateQueryExp(colIndex);
1257 r = CreateQueryFilter(true);
1258 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "CreateQueryFilter Failed.");
1260 if (colIndex == ALBUM_COLUMN_NUM)
1262 ret = media_album_get_album_count_from_db(__pFilterHandle.get(), &totalCount);
1266 ret = media_group_get_group_count_from_db(__pFilterHandle.get(), groupIndex, &totalCount);
1268 r = MapCoreErrorToNativeResult(ret);
1269 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, r, "Failed to perform media_album/group count_from_db operation.");
1271 SysLog(NID_CNT, "totalCount = %d for media_album/group count_from_db", totalCount);
1275 if ((totalCount % countPerPage) == 0)
1277 totalPageCount = totalCount / countPerPage;
1281 totalPageCount = (totalCount / countPerPage) + 1;
1284 if ((pageNo < 1) || (pageNo > totalPageCount))
1287 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "(pageNo < 1) || (pageNo > totalPageCount).");
1290 offset = (pageNo * countPerPage) - countPerPage;
1292 SysLog(NID_CNT, "GetValueListN totalCount [%d] totalPageCount[%d] __countPerPage[%d] __pageNo[%d] offset[%d]",
1293 totalCount, totalPageCount, countPerPage, pageNo, offset);
1295 ret = media_filter_set_offset(__pFilterHandle.get(),offset,countPerPage);
1296 r = MapCoreErrorToNativeResult(ret);
1297 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, r, "failed to perform media_filter_set_offset operation.");
1299 if (colIndex == ALBUM_COLUMN_NUM)
1301 r = ExecuteAndFillAlbumValues();
1302 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "ExecuteAndFillAlbumValues Failed.");
1306 r = ExecuteAndFillGetValueListN(groupIndex, colIndex);
1307 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "ExecuteAndFillGetValueListN Failed.");
1311 else if (pageNo > 1)
1313 SysLogException(NID_CNT, r = E_INVALID_ARG, "[%s] (pageNo > 1) and (totalcount = 0).", GetErrorMessage(E_INVALID_ARG));
1319 // fills given column value list for GetValuelistN api
1321 _ContentSearchImpl::ExecuteAndFillGetValueListN(media_group_e groupIndex, int colIndex) const
1323 SysLog(NID_CNT, "Enter\n");
1325 int ret = MEDIA_CONTENT_ERROR_NONE;
1326 result r = E_SUCCESS;
1327 result res = E_SUCCESS;
1328 std::unique_ptr<GList, SearchGListDeleter> pItemList;
1329 GList* pTemp = NULL;
1331 std::unique_ptr<Object> pValue;
1335 long long contentSize = 0;
1336 long long addedTime = 0;
1339 char *pColumnVal = null;
1340 int contentType = 0;
1342 pTemp = pItemList.get();
1344 ret = media_group_foreach_group_from_db(__pFilterHandle.get(), groupIndex, GroupItemCb, &pTemp);
1345 r = MapCoreErrorToNativeResult(ret);
1346 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform media_group_foreach_group_from_db operation.");
1348 SysTryReturnResult(NID_CNT, pTemp != NULL, r, "media_info_foreach_media_from_db pTemp is null.");
1350 for (int idx = 0; idx < (int)g_list_length(pTemp); idx++)
1352 SysLog(NID_CNT, "idx = %d and (int)g_list_length(pItemList) = %d", idx, (int)g_list_length(pTemp));
1354 pColumnVal = (char *)g_list_nth_data(pTemp, idx);
1356 String strColVal(pColumnVal);
1358 _ContentUtility::DoSafeFree(pColumnVal);
1360 SysLog(NID_CNT, "pColumnVal = %ls", strColVal.GetPointer());
1364 case 0://"ContentType", "MEDIA_TYPE"
1365 if ((strColVal.CompareTo(L"Unknown") != 0) && (!strColVal.IsEmpty()))
1367 res = Integer::Parse(strColVal, contentType);
1368 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] Integer parse failed.", GetErrorMessage(res));
1370 switch ((media_content_type_e)contentType)
1372 case MEDIA_CONTENT_TYPE_OTHERS:
1373 pValue.reset(new (std::nothrow) String(CONTENT_TYPE_OTHER));
1374 SysLog(NID_CNT, "mediaType = CONTENT_TYPE_OTHER");
1376 case MEDIA_CONTENT_TYPE_IMAGE:
1377 pValue.reset(new (std::nothrow) String(CONTENT_TYPE_IMAGE));
1378 SysLog(NID_CNT, "mediaType = CONTENT_TYPE_IMAGE");
1380 case MEDIA_CONTENT_TYPE_SOUND:
1382 case MEDIA_CONTENT_TYPE_MUSIC:
1383 pValue.reset(new (std::nothrow) String(CONTENT_TYPE_AUDIO));
1384 SysLog(NID_CNT, "mediaType = CONTENT_TYPE_AUDIO");
1386 case MEDIA_CONTENT_TYPE_VIDEO:
1387 pValue.reset(new (std::nothrow) String(CONTENT_TYPE_VIDEO));
1388 SysLog(NID_CNT, "mediaType = CONTENT_TYPE_VIDEO");
1394 case 1://"ContentFileName", "MEDIA_DISPLAY_NAME"
1396 case 2://"ContentName", "MEDIA_CONTENT_NAME"
1398 case 3://"Category", "MEDIA_CATEGORY"
1400 case 4://"Author", "MEDIA_AUTHOR"
1402 case 5://"keyword", "MEDIA_KEYWORD"
1404 case 6://"Provider", "MEDIA_PROVIDER"
1406 case 7://"Rating", "MEDIA_AGE_RATING"
1408 case 8://"LocationTag", "MEDIA_LOCATION_TAG"
1410 case 14://"Title", "MEDIA_TITLE"
1412 case 15://"Artist", "MEDIA_ARTIST"
1414 case 16://"Genre", "MEDIA_GENRE"
1416 case 17://"Year", "MEDIA_YEAR"
1418 case 18://"Composer", "MEDIA_COMPOSER"
1420 pValue.reset(new (std::nothrow) String(strColVal));
1423 case 9://"ContentSize", "MEDIA_SIZE"
1424 if ((strColVal.CompareTo(L"Unknown") != 0) && (!strColVal.IsEmpty()))
1426 res = LongLong::Parse(strColVal, contentSize);
1427 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] LongLong parse failed.", GetErrorMessage(res));
1430 pValue.reset(new (std::nothrow) LongLong(contentSize));
1432 case 10://"DateTime", "MEDIA_ADDED_TIME"
1433 if ((strColVal.CompareTo(L"Unknown") != 0) && (!strColVal.IsEmpty()))
1435 res = LongLong::Parse(strColVal, addedTime);
1436 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] LongLong parse failed.", GetErrorMessage(res));
1439 res = dateTime.SetValue(1970, 1, 1);
1440 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] dateTime.SetValue failed.", GetErrorMessage(res));
1442 res = dateTime.AddSeconds(addedTime);
1443 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] dateTime.AddSeconds failed.", GetErrorMessage(res));
1445 SysLog(NID_CNT, "DateTime : %ls", dateTime.ToString().GetPointer());
1447 pValue.reset(new (std::nothrow) DateTime(dateTime));
1450 case 11://"Latitude", "MEDIA_LATITUDE"
1452 case 12://"Longitude", "MEDIA_LONGITUDE"
1454 case 13://"Altitude", "MEDIA_ALTITUDE"
1455 if ((strColVal.CompareTo(L"Unknown") != 0) && (!strColVal.IsEmpty()))
1457 dVal = _LocalizedNumParser::ToDouble(strColVal, "C");
1458 r = GetLastResult();
1459 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform ToDouble operation.");
1461 pValue.reset(new (std::nothrow) Double(dVal));
1464 case 19://"Album", "MEDIA_ALBUM"
1469 if (pValue.get() != NULL)
1471 r = __pFinalOutList->Add(*(pValue.release()));
1472 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform arraylist Add operation.");
1480 _ContentSearchImpl::ExecuteAndFillAlbumValues(void) const
1482 int ret = MEDIA_CONTENT_ERROR_NONE;
1483 result r = E_SUCCESS;
1484 std::unique_ptr<GList, SearchGListDeleter> pItemList;
1485 GList* pTemp = NULL;
1486 std::unique_ptr<media_album_s, AlbumHandleDeleter> pAlbumHandle;
1487 std::unique_ptr<media_album_s, AlbumHandleDeleter> pTempAlbumHandle;
1490 std::unique_ptr<char, CharDeleter> pAlbumName;
1491 std::unique_ptr< String > pValue;
1494 pTemp = pItemList.get();
1496 ret = media_album_foreach_album_from_db(__pFilterHandle.get(), AlbumItemCb, &pTemp);
1497 r = MapCoreErrorToNativeResult(ret);
1498 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform media_album_foreach_album_from_db operation.");
1499 SysTryReturnResult(NID_CNT, pTemp != NULL, r, "media_info_foreach_media_from_db pTemp is null.");
1501 for (int idx = 0; idx < (int)g_list_length(pTemp); idx++)
1503 pAlbumHandle.reset(static_cast<media_album_h>(g_list_nth_data(pTemp, idx)));
1504 ret = media_album_get_name(pAlbumHandle.get(), &pName);
1505 r = MapCoreErrorToNativeResult(ret);
1506 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform media_album_get_name.");
1510 SysLog(NID_CNT, "pColumnVal = %s", pName);
1512 pAlbumName.reset(pName);
1513 pValue.reset(new (std::nothrow) String(pAlbumName.get()));
1514 SysTryReturnResult(NID_CNT, pValue != NULL, E_OUT_OF_MEMORY, "media_info_foreach_media_from_db pTemp is null.");
1518 r = __pFinalOutList->Add(pValue.get());
1519 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform arraylist Add operation.");
1524 String* pTempNameList(static_cast< String* >(__pFinalOutList->GetAt(lastIndex)));
1526 if (pValue->CompareTo(*pTempNameList) != 0)
1528 r = __pFinalOutList->Add(pValue.get());
1529 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform arraylist Add operation.");
1542 _ContentSearchImpl::MapCoreErrorToNativeResult(int reason) const
1544 result r = E_SUCCESS;
1548 case MEDIA_CONTENT_ERROR_NONE:
1552 case MEDIA_CONTENT_ERROR_INVALID_PARAMETER:
1554 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_INVALID_PARAMETER");
1557 case MEDIA_CONTENT_ERROR_DB_FAILED:
1559 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_DB_FAILED");
1562 case MEDIA_CONTENT_ERROR_OUT_OF_MEMORY:
1563 r = E_OUT_OF_MEMORY;
1564 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_OUT_OF_MEMORY");
1568 SysLog(NID_CNT, "default");
1576 _ContentSearchImpl::ConvertErrorToResult(result res) const
1578 result r = E_SUCCESS;
1582 case E_FILE_NOT_FOUND:
1595 // Callback function registered to each media info details
1596 // all items are appended to the list
1598 MediaItemCb(media_info_h media, void* pUserdata)
1600 int ret = MEDIA_CONTENT_ERROR_NONE;
1601 media_info_h new_media = NULL;
1602 ret = media_info_clone(&new_media, media);
1603 SysTryLog(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, "[E_SYSTEM] Failed to perform media_info_clone");
1605 GList** pList = (GList**)pUserdata;
1606 *pList = g_list_append(*pList, new_media);
1611 // Callback function registered for column values
1612 // all items are appended to the list
1614 GroupItemCb(const char* pGroupName, void* pUserdata)
1616 char* pGrpName = strdup(pGroupName);
1617 GList** pList = (GList**)pUserdata;
1618 *pList = g_list_append(*pList, pGrpName);
1623 // Callback function registered to each media info details
1624 // all items are appended to the list
1626 AlbumItemCb(media_album_h album, void* pUserdata)
1628 int ret = MEDIA_CONTENT_ERROR_NONE;
1629 media_album_h new_album = NULL;
1630 ret = media_album_clone(&new_album, album);
1631 SysTryLog(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, "[E_SYSTEM] Failed to perform media_album_clone");
1633 GList** pList = (GList**)pUserdata;
1634 *pList = g_list_append(*pList, new_album);