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.");
749 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[E_INVALID_ARG] (pageNo > 1) and (totalcount = 0).");
753 return __pFinalOutList.release();
756 // Fills final result list
758 _ContentSearchImpl::ExecuteAndFillFinalOutList(void) const
760 SysLog(NID_CNT, "Enter\n");
762 int ret = MEDIA_CONTENT_ERROR_NONE;
763 result r = E_SUCCESS;
765 std::unique_ptr<GList, SearchGListDeleter> pItemList;
767 std::unique_ptr<media_info_s, SearchMediaHandleDeleter> pMediaHandle;
769 std::unique_ptr<ImageContentInfo> pImageContentInfo;
770 std::unique_ptr<AudioContentInfo> pAudioContentInfo;
771 std::unique_ptr<VideoContentInfo> pVideoContentInfo;
772 std::unique_ptr<OtherContentInfo> pOtherContentInfo;
774 _ImageContentInfoImpl* pImageContentInfoImpl = null;
775 _AudioContentInfoImpl* pAudioContentInfoImpl = null;
776 _VideoContentInfoImpl* pVideoContentInfoImpl = null;
777 _OtherContentInfoImpl* pOtherContentInfoImpl = null;
779 std::unique_ptr<ContentSearchResult> pContentSearchResult;
781 pTemp = pItemList.get();
783 ret = media_info_foreach_media_from_db(__pFilterHandle.get(), MediaItemCb, &pTemp);
784 r = MapCoreErrorToNativeResult(ret);
785 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform media_info_foreach_media_from_db operation.");
787 SysTryReturnResult(NID_CNT, pTemp != NULL, r, "media_info_foreach_media_from_db pTemp is null.");
789 media_content_type_e mediaType = MEDIA_CONTENT_TYPE_OTHERS;
791 for (int idx = 0; idx < (int)g_list_length(pTemp); idx++)
793 pMediaHandle.reset(static_cast<media_info_h>(g_list_nth_data(pTemp, idx)));
795 ret = media_info_get_media_type(pMediaHandle.get(), &mediaType);
796 r = MapCoreErrorToNativeResult(ret);
797 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform media_info_get_media_type.");
799 std::unique_ptr<char, UtilCharDeleter> pMediaPath;
800 char* pTempPath = null;
802 ret = media_info_get_file_path(pMediaHandle.get(), &pTempPath);
803 r = MapCoreErrorToNativeResult(ret);
804 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform media_info_get_file_path operation.");
806 pMediaPath.reset(pTempPath);
807 String contentPath(pMediaPath.get());
811 case MEDIA_CONTENT_TYPE_OTHERS:
812 pOtherContentInfo = std::unique_ptr<OtherContentInfo>(new (std::nothrow) OtherContentInfo);
813 SysTryReturnResult(NID_CNT, pOtherContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pOtherContentInfo.");
815 r = pOtherContentInfo->Construct(&contentPath);
816 r = ConvertErrorToResult(r);
817 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Construct operation to OtherContentInfo.");
819 pOtherContentInfoImpl = null;
820 pOtherContentInfoImpl = _OtherContentInfoImpl::GetInstance(*(pOtherContentInfo.get()));
821 SysTryReturnResult(NID_CNT, pOtherContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to assign operation to pOtherContentInfoImpl.");
823 r = _ContentUtility::FillContentData(pMediaHandle.get(), pOtherContentInfoImpl);
824 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
826 _ContentInfoHelper::SetContentInfoImpl(pOtherContentInfo.get(), pOtherContentInfoImpl);
828 pContentSearchResult = std::unique_ptr<ContentSearchResult>(new (std::nothrow) ContentSearchResult);
829 SysTryReturnResult(NID_CNT, pContentSearchResult.get() != null, E_OUT_OF_MEMORY, "Failed to create pContentSearchResult.");
831 pContentSearchResult->SetContentType(CONTENT_TYPE_OTHER);
832 pContentSearchResult->SetContentInfo(pOtherContentInfo.release());
834 // Shallow copy, adds just the pointer: not the element
835 r = __pFinalOutList->Add(*(pContentSearchResult.release()));
836 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation for ArrayList.");
839 case MEDIA_CONTENT_TYPE_IMAGE:
840 pImageContentInfo = std::unique_ptr<ImageContentInfo>(new (std::nothrow) ImageContentInfo);
841 SysTryReturnResult(NID_CNT, pImageContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pImageContentInfo.");
843 r = pImageContentInfo->Construct(&contentPath);
844 r = ConvertErrorToResult(r);
845 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Construct operation to ImageContentInfo.");
847 pImageContentInfoImpl = null;
848 pImageContentInfoImpl = _ImageContentInfoImpl::GetInstance(*(pImageContentInfo.get()));
849 SysTryReturnResult(NID_CNT, pImageContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to assign operation to pImageContentInfoImpl.");
851 r = _ContentUtility::FillContentData(pMediaHandle.get(), pImageContentInfoImpl);
852 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
854 r = _ContentUtility::FillImageContentData(pMediaHandle.get(), pImageContentInfoImpl);
855 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform GetDataFromImageTable operation.");
857 _ContentInfoHelper::SetContentInfoImpl(pImageContentInfo.get(), pImageContentInfoImpl);
859 pContentSearchResult = std::unique_ptr<ContentSearchResult>(new (std::nothrow) ContentSearchResult);
860 SysTryReturnResult(NID_CNT, pContentSearchResult.get() != null, E_OUT_OF_MEMORY, "Failed to create pContentSearchResult.");
862 pContentSearchResult->SetContentType(CONTENT_TYPE_IMAGE);
863 pContentSearchResult->SetContentInfo(pImageContentInfo.release());
865 // Shallow copy, adds just the pointer: not the element
866 r = __pFinalOutList->Add(*(pContentSearchResult.release()));
867 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation for ArrayList.");
870 case MEDIA_CONTENT_TYPE_MUSIC:
872 case MEDIA_CONTENT_TYPE_SOUND:
873 pAudioContentInfo = std::unique_ptr<AudioContentInfo>(new (std::nothrow) AudioContentInfo);
874 SysTryReturnResult(NID_CNT, pAudioContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pAudioContentInfo.");
876 r = pAudioContentInfo->Construct(&contentPath);
877 r = ConvertErrorToResult(r);
878 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Construct operation to AudioContentInfo.");
880 pAudioContentInfoImpl = null;
881 pAudioContentInfoImpl = _AudioContentInfoImpl::GetInstance(*(pAudioContentInfo.get()));
882 SysTryReturnResult(NID_CNT, pAudioContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to assign operation to pAudioContentInfoImpl.");
884 r = _ContentUtility::FillContentData(pMediaHandle.get(), pAudioContentInfoImpl);
885 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
887 r = _ContentUtility::FillAudioContentData(pMediaHandle.get(), pAudioContentInfoImpl);
888 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillAudioContentData operation.");
890 _ContentInfoHelper::SetContentInfoImpl(pAudioContentInfo.get(), pAudioContentInfoImpl);
892 pContentSearchResult = std::unique_ptr<ContentSearchResult>(new (std::nothrow) ContentSearchResult);
893 SysTryReturnResult(NID_CNT, pContentSearchResult.get() != null, E_OUT_OF_MEMORY, "Failed to create pContentSearchResult.");
895 pContentSearchResult->SetContentType(CONTENT_TYPE_AUDIO);
896 pContentSearchResult->SetContentInfo(pAudioContentInfo.release());
898 // Shallow copy, adds just the pointer: not the element
899 r = __pFinalOutList->Add(*(pContentSearchResult.release()));
900 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation for ArrayList.");
903 case MEDIA_CONTENT_TYPE_VIDEO:
904 pVideoContentInfo = std::unique_ptr<VideoContentInfo>(new (std::nothrow) VideoContentInfo);
905 SysTryReturnResult(NID_CNT, pVideoContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pVideoContentInfo.");
907 r = pVideoContentInfo->Construct(&contentPath);
908 r = ConvertErrorToResult(r);
909 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Construct operation to VideoContentInfo.");
911 pVideoContentInfoImpl = null;
912 pVideoContentInfoImpl = _VideoContentInfoImpl::GetInstance(*(pVideoContentInfo.get()));
913 SysTryReturnResult(NID_CNT, pVideoContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to assign operation to pVideoContentInfoImpl.");
915 r = _ContentUtility::FillContentData(pMediaHandle.get(), pVideoContentInfoImpl);
916 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
918 r = _ContentUtility::FillVideoContentData(pMediaHandle.get(), pVideoContentInfoImpl);
919 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillVideoContentData operation.");
921 _ContentInfoHelper::SetContentInfoImpl(pVideoContentInfo.get(), pVideoContentInfoImpl);
923 pContentSearchResult = std::unique_ptr<ContentSearchResult>(new (std::nothrow) ContentSearchResult);
924 SysTryReturnResult(NID_CNT, pContentSearchResult.get() != null, E_OUT_OF_MEMORY, "Failed to create pContentSearchResult.");
926 pContentSearchResult->SetContentType(CONTENT_TYPE_VIDEO);
927 pContentSearchResult->SetContentInfo(pVideoContentInfo.release());
929 // Shallow copy, adds just the pointer: not the element
930 r = __pFinalOutList->Add(*(pContentSearchResult.release()));
931 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation for ArrayList.");
941 // returns given column value list in the requested order
943 _ContentSearchImpl::GetValueListN(const String& sortColumn, SortOrder sortOrder)
945 SysLog(NID_CNT, "inputColumn = %ls", sortColumn.GetPointer());
948 result r = E_SUCCESS;
952 __inputColumnName.Clear();
955 __inputColumnName = sortColumn;
956 __inputSortOrder = sortOrder;
958 String ospColumnName(L"");
959 String slpColumnName(L"");
961 String columnName(__inputColumnName);
963 if ((__inputColumnName.IsEmpty()) && ((__inputSortOrder == SORT_ORDER_ASCENDING) || (__inputSortOrder == SORT_ORDER_DESCENDING)))
965 SysLog(NID_CNT, "sort column name is empty and sort oder is not none. so,E_INVALID_ARG occured.");
966 SetLastResult(E_INVALID_ARG);
971 std::unique_ptr<ArrayList, AllElementsDeleter> pFinalOutList(new (std::nothrow) ArrayList());
972 SysTryReturn(NID_CNT, pFinalOutList.get() != null, NULL, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to construct ArrayList.");
974 r = pFinalOutList->Construct();
975 SysTryReturn(NID_CNT, !IsFailed(r), NULL, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to construct ArrayList.");
977 __pFinalOutList = std::move(pFinalOutList);
979 switch (__contentType)
981 case CONTENT_TYPE_OTHER:
983 case CONTENT_TYPE_IMAGE:
984 maxCols = MAX_QUERY_COLUMNS_FOR_IMAGE_OTHERS;
986 case CONTENT_TYPE_VIDEO:
987 maxCols = MAX_QUERY_COLUMNS_FOR_VIDEO;
989 case CONTENT_TYPE_AUDIO:
991 case CONTENT_TYPE_ALL:
992 maxCols = MAX_QUERY_COLUMNS;
998 for (colIndex = 0; colIndex < maxCols; colIndex++)
1000 ospColumnName.Clear();
1001 slpColumnName.Clear();
1003 ospColumnName = dbfieldinfo[colIndex].dbFieldOspName ;
1004 slpColumnName = dbfieldinfo[colIndex].dbFieldSlpName ;
1006 ospColumnName.ToUpper();
1007 columnName.ToUpper();
1008 if (columnName == ospColumnName)
1010 r = FillColumnsList(colIndex);
1011 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[%s] FillColumnsList Failed.", GetErrorMessage(r));
1015 if (colIndex == maxCols)
1018 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[E_INVALID_ARG] invalid column.");
1022 return __pFinalOutList.release();
1025 // returns given column value list in the requested order
1027 _ContentSearchImpl::GetValueListN(int pageNo, int countPerPage, int& totalPageCount, int& totalCount, const String& sortColumn, SortOrder sortOrder) const
1029 SysLog(NID_CNT, "pageNo = %d, countPerPage = %d, inputColumn = %ls", pageNo, countPerPage, sortColumn.GetPointer());
1033 result r = E_SUCCESS;
1037 __inputColumnName.Clear();
1038 __inputExpr.Clear();
1040 __inputColumnName = sortColumn;
1041 __inputSortOrder = sortOrder;
1043 String ospColumnName(L"");
1044 String slpColumnName(L"");
1046 String columnName(__inputColumnName);
1048 if ((__inputColumnName.IsEmpty()) && ((__inputSortOrder == SORT_ORDER_ASCENDING) || (__inputSortOrder == SORT_ORDER_DESCENDING)))
1050 SysLog(NID_CNT, "sort column name is empty and sort oder is not none. so,E_INVALID_ARG occured.");
1051 SetLastResult(E_INVALID_ARG);
1056 std::unique_ptr<ArrayList, AllElementsDeleter> pFinalOutList(new (std::nothrow) ArrayList());
1057 SysTryReturn(NID_CNT, pFinalOutList.get() != null, NULL, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to construct ArrayList.");
1059 r = pFinalOutList->Construct();
1060 SysTryReturn(NID_CNT, !IsFailed(r), NULL, r, "[%s] Failed to construct ArrayList.", GetErrorMessage(r));
1062 __pFinalOutList = std::move(pFinalOutList);
1064 switch (__contentType)
1066 case CONTENT_TYPE_OTHER:
1068 case CONTENT_TYPE_IMAGE:
1069 maxCols = MAX_QUERY_COLUMNS_FOR_IMAGE_OTHERS;
1071 case CONTENT_TYPE_VIDEO:
1072 maxCols = MAX_QUERY_COLUMNS_FOR_VIDEO;
1074 case CONTENT_TYPE_AUDIO:
1076 case CONTENT_TYPE_ALL:
1077 maxCols = MAX_QUERY_COLUMNS;
1083 for (colIndex = 0; colIndex < maxCols; colIndex++)
1085 ospColumnName.Clear();
1086 slpColumnName.Clear();
1088 ospColumnName = dbfieldinfo[colIndex].dbFieldOspName ;
1089 slpColumnName = dbfieldinfo[colIndex].dbFieldSlpName ;
1091 ospColumnName.ToUpper();
1092 columnName.ToUpper();
1093 if (columnName == ospColumnName)
1095 r = FillColumnsList(pageNo, countPerPage, totalPageCount, totalCount, colIndex);
1096 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[%s] FillColumnsList Failed.", GetErrorMessage(r));
1100 if (colIndex == maxCols)
1103 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[E_INVALID_ARG] invalid column.");
1107 return __pFinalOutList.release();
1110 // prepares query expression to be used in group api. colIndex is mapped to actual group value.
1112 _ContentSearchImpl::GetIndexAndCreateQueryExp(int colIndex) const
1114 media_group_e groupIndex = MEDIA_CONTENT_GROUP_DISPLAY_NAME;;
1117 case 0://"ContentType", "MEDIA_TYPE"
1118 groupIndex = MEDIA_CONTENT_GROUP_TYPE;
1119 __inputExpr = "MEDIA_TYPE IS NOT NULL";
1121 case 1://"ContentFileName", "MEDIA_DISPLAY_NAME"
1122 groupIndex = MEDIA_CONTENT_GROUP_DISPLAY_NAME;
1123 __inputExpr = "MEDIA_DISPLAY_NAME IS NOT NULL";
1125 case 2://"ContentName", "MEDIA_CONTENT_NAME"
1126 groupIndex = MEDIA_CONTENT_GROUP_CONTENT_NAME;
1127 __inputExpr = "MEDIA_CONTENT_NAME IS NOT NULL";
1129 case 3://"Category", "MEDIA_CATEGORY"
1130 groupIndex = MEDIA_CONTENT_GROUP_CATEGORY;
1131 __inputExpr = "MEDIA_CATEGORY IS NOT NULL";
1133 case 4://"Author", "MEDIA_AUTHOR"
1134 groupIndex = MEDIA_CONTENT_GROUP_AUTHOR;
1135 __inputExpr = "MEDIA_AUTHOR IS NOT NULL";
1137 case 5://"keyword", "MEDIA_KEYWORD"
1138 groupIndex = MEDIA_CONTENT_GROUP_KEYWORD;
1139 __inputExpr = "MEDIA_KEYWORD IS NOT NULL";
1141 case 6://"Provider", "MEDIA_PROVIDER"
1142 groupIndex = MEDIA_CONTENT_GROUP_PROVIDER;
1143 __inputExpr = "MEDIA_PROVIDER IS NOT NULL";
1145 case 7://"Rating", "MEDIA_AGE_RATING"
1146 groupIndex = MEDIA_CONTENT_GROUP_AGE_RATING;
1147 __inputExpr = "MEDIA_AGE_RATING IS NOT NULL";
1149 case 8://"LocationTag", "MEDIA_LOCATION_TAG"
1150 groupIndex = MEDIA_CONTENT_GROUP_LOCATION_TAG;
1151 __inputExpr = "MEDIA_LOCATION_TAG IS NOT NULL";
1153 case 9://"ContentSize", "MEDIA_SIZE"
1154 groupIndex = MEDIA_CONTENT_GROUP_SIZE;
1155 __inputExpr = "MEDIA_SIZE IS NOT NULL";
1157 case 10://"DateTime", "MEDIA_ADDED_TIME"
1158 groupIndex = MEDIA_CONTENT_GROUP_ADDED_TIME;
1159 __inputExpr = "MEDIA_ADDED_TIME IS NOT NULL";
1161 case 11://"Latitude", "MEDIA_LATITUDE"
1162 groupIndex = MEDIA_CONTENT_GROUP_LATITUDE;
1163 __inputExpr = "MEDIA_LATITUDE IS NOT NULL";
1165 case 12://"Longitude", "MEDIA_LONGITUDE"
1166 groupIndex = MEDIA_CONTENT_GROUP_LONGITUDE;
1167 __inputExpr = "MEDIA_LONGITUDE IS NOT NULL";
1169 case 13://"Altitude", "MEDIA_ALTITUDE"
1170 groupIndex = MEDIA_CONTENT_GROUP_ALTITUDE;
1171 __inputExpr = "MEDIA_ALTITUDE IS NOT NULL";
1173 case 14://"Title", "MEDIA_TITLE"
1174 groupIndex = MEDIA_CONTENT_GROUP_TITLE;
1175 __inputExpr = "MEDIA_TITLE IS NOT NULL";
1177 case 15://"Artist", "MEDIA_ARTIST"
1178 groupIndex = MEDIA_CONTENT_GROUP_ARTIST;
1179 __inputExpr = "MEDIA_ARTIST IS NOT NULL";
1181 case 16://"Genre", "MEDIA_GENRE"
1182 groupIndex = MEDIA_CONTENT_GROUP_GENRE;
1183 __inputExpr = "MEDIA_GENRE IS NOT NULL";
1185 case 17://"Year", "MEDIA_YEAR"
1186 groupIndex = MEDIA_CONTENT_GROUP_YEAR;
1187 __inputExpr = "MEDIA_YEAR IS NOT NULL";
1189 case 18://"Composer", "MEDIA_COMPOSER"
1190 groupIndex = MEDIA_CONTENT_GROUP_COMPOSER;
1191 __inputExpr = "MEDIA_COMPOSER IS NOT NULL";
1193 case 19://"Album", "MEDIA_ALBUM"
1194 __inputExpr = "MEDIA_ALBUM IS NOT NULL";
1202 // Fills given column value list and destroys filter handle
1204 _ContentSearchImpl::FillColumnsList(int colIndex) const
1206 result r = E_SUCCESS;
1207 int ret = MEDIA_CONTENT_ERROR_NONE;
1209 media_group_e groupIndex = GetIndexAndCreateQueryExp(colIndex);
1211 r = CreateQueryFilter(true);
1212 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "CreateQueryFilter Failed.");
1214 if (colIndex == ALBUM_COLUMN_NUM)
1216 ret = media_album_get_album_count_from_db(__pFilterHandle.get(), &totalCount);
1220 ret = media_group_get_group_count_from_db(__pFilterHandle.get(), groupIndex, &totalCount);
1222 r = MapCoreErrorToNativeResult(ret);
1223 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, r, "Failed to perform media_album/group count_from_db operation.");
1225 SysLog(NID_CNT, "totalCount = %d for media_album/group count_from_db", totalCount);
1229 if (colIndex == ALBUM_COLUMN_NUM)
1231 r = ExecuteAndFillAlbumValues();
1232 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "ExecuteAndFillAlbumValues Failed.");
1236 r = ExecuteAndFillGetValueListN(groupIndex, colIndex);
1237 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "ExecuteAndFillGetValueListN Failed.");
1243 // prepares input expression to be sent for create filter and fills given column value list
1245 _ContentSearchImpl::FillColumnsList(int pageNo, int countPerPage, int& totalPageCount, int& totalCount, int colIndex) const
1247 result r = E_SUCCESS;
1248 int ret = MEDIA_CONTENT_ERROR_NONE;
1252 media_group_e groupIndex = GetIndexAndCreateQueryExp(colIndex);
1254 r = CreateQueryFilter(true);
1255 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "CreateQueryFilter Failed.");
1257 if (colIndex == ALBUM_COLUMN_NUM)
1259 ret = media_album_get_album_count_from_db(__pFilterHandle.get(), &totalCount);
1263 ret = media_group_get_group_count_from_db(__pFilterHandle.get(), groupIndex, &totalCount);
1265 r = MapCoreErrorToNativeResult(ret);
1266 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, r, "Failed to perform media_album/group count_from_db operation.");
1268 SysLog(NID_CNT, "totalCount = %d for media_album/group count_from_db", totalCount);
1272 if ((totalCount % countPerPage) == 0)
1274 totalPageCount = totalCount / countPerPage;
1278 totalPageCount = (totalCount / countPerPage) + 1;
1281 if ((pageNo < 1) || (pageNo > totalPageCount))
1284 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "(pageNo < 1) || (pageNo > totalPageCount).");
1287 offset = (pageNo * countPerPage) - countPerPage;
1289 SysLog(NID_CNT, "GetValueListN totalCount [%d] totalPageCount[%d] __countPerPage[%d] __pageNo[%d] offset[%d]",
1290 totalCount, totalPageCount, countPerPage, pageNo, offset);
1292 ret = media_filter_set_offset(__pFilterHandle.get(),offset,countPerPage);
1293 r = MapCoreErrorToNativeResult(ret);
1294 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, r, "failed to perform media_filter_set_offset operation.");
1296 if (colIndex == ALBUM_COLUMN_NUM)
1298 r = ExecuteAndFillAlbumValues();
1299 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "ExecuteAndFillAlbumValues Failed.");
1303 r = ExecuteAndFillGetValueListN(groupIndex, colIndex);
1304 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "ExecuteAndFillGetValueListN Failed.");
1308 else if (pageNo > 1)
1311 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "(pageNo > 1) and (totalcount = 0).");
1317 // fills given column value list for GetValuelistN api
1319 _ContentSearchImpl::ExecuteAndFillGetValueListN(media_group_e groupIndex, int colIndex) const
1321 SysLog(NID_CNT, "Enter\n");
1323 int ret = MEDIA_CONTENT_ERROR_NONE;
1324 result r = E_SUCCESS;
1325 result res = E_SUCCESS;
1326 std::unique_ptr<GList, SearchGListDeleter> pItemList;
1327 GList* pTemp = NULL;
1329 std::unique_ptr<Object> pValue;
1333 long long contentSize = 0;
1334 long long addedTime = 0;
1337 char *pColumnVal = null;
1338 int contentType = 0;
1340 pTemp = pItemList.get();
1342 ret = media_group_foreach_group_from_db(__pFilterHandle.get(), groupIndex, GroupItemCb, &pTemp);
1343 r = MapCoreErrorToNativeResult(ret);
1344 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform media_group_foreach_group_from_db operation.");
1346 SysTryReturnResult(NID_CNT, pTemp != NULL, r, "media_info_foreach_media_from_db pTemp is null.");
1348 for (int idx = 0; idx < (int)g_list_length(pTemp); idx++)
1350 SysLog(NID_CNT, "idx = %d and (int)g_list_length(pItemList) = %d", idx, (int)g_list_length(pTemp));
1352 pColumnVal = (char *)g_list_nth_data(pTemp, idx);
1354 String strColVal(pColumnVal);
1356 _ContentUtility::DoSafeFree(pColumnVal);
1358 SysLog(NID_CNT, "pColumnVal = %ls", strColVal.GetPointer());
1362 case 0://"ContentType", "MEDIA_TYPE"
1363 if ((strColVal.CompareTo(L"Unknown") != 0) && (!strColVal.IsEmpty()))
1365 res = Integer::Parse(strColVal, contentType);
1366 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] Integer parse failed.", GetErrorMessage(res));
1368 switch ((media_content_type_e)contentType)
1370 case MEDIA_CONTENT_TYPE_OTHERS:
1371 pValue.reset(new (std::nothrow) String(CONTENT_TYPE_OTHER));
1372 SysLog(NID_CNT, "mediaType = CONTENT_TYPE_OTHER");
1374 case MEDIA_CONTENT_TYPE_IMAGE:
1375 pValue.reset(new (std::nothrow) String(CONTENT_TYPE_IMAGE));
1376 SysLog(NID_CNT, "mediaType = CONTENT_TYPE_IMAGE");
1378 case MEDIA_CONTENT_TYPE_SOUND:
1380 case MEDIA_CONTENT_TYPE_MUSIC:
1381 pValue.reset(new (std::nothrow) String(CONTENT_TYPE_AUDIO));
1382 SysLog(NID_CNT, "mediaType = CONTENT_TYPE_AUDIO");
1384 case MEDIA_CONTENT_TYPE_VIDEO:
1385 pValue.reset(new (std::nothrow) String(CONTENT_TYPE_VIDEO));
1386 SysLog(NID_CNT, "mediaType = CONTENT_TYPE_VIDEO");
1392 case 1://"ContentFileName", "MEDIA_DISPLAY_NAME"
1394 case 2://"ContentName", "MEDIA_CONTENT_NAME"
1396 case 3://"Category", "MEDIA_CATEGORY"
1398 case 4://"Author", "MEDIA_AUTHOR"
1400 case 5://"keyword", "MEDIA_KEYWORD"
1402 case 6://"Provider", "MEDIA_PROVIDER"
1404 case 7://"Rating", "MEDIA_AGE_RATING"
1406 case 8://"LocationTag", "MEDIA_LOCATION_TAG"
1408 case 14://"Title", "MEDIA_TITLE"
1410 case 15://"Artist", "MEDIA_ARTIST"
1412 case 16://"Genre", "MEDIA_GENRE"
1414 case 17://"Year", "MEDIA_YEAR"
1416 case 18://"Composer", "MEDIA_COMPOSER"
1418 pValue.reset(new (std::nothrow) String(strColVal));
1421 case 9://"ContentSize", "MEDIA_SIZE"
1422 if ((strColVal.CompareTo(L"Unknown") != 0) && (!strColVal.IsEmpty()))
1424 res = LongLong::Parse(strColVal, contentSize);
1425 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] LongLong parse failed.", GetErrorMessage(res));
1428 pValue.reset(new (std::nothrow) LongLong(contentSize));
1430 case 10://"DateTime", "MEDIA_ADDED_TIME"
1431 if ((strColVal.CompareTo(L"Unknown") != 0) && (!strColVal.IsEmpty()))
1433 res = LongLong::Parse(strColVal, addedTime);
1434 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] LongLong parse failed.", GetErrorMessage(res));
1437 res = dateTime.SetValue(1970, 1, 1);
1438 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] dateTime.SetValue failed.", GetErrorMessage(res));
1440 res = dateTime.AddSeconds(addedTime);
1441 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] dateTime.AddSeconds failed.", GetErrorMessage(res));
1443 SysLog(NID_CNT, "DateTime : %ls", dateTime.ToString().GetPointer());
1445 pValue.reset(new (std::nothrow) DateTime(dateTime));
1448 case 11://"Latitude", "MEDIA_LATITUDE"
1450 case 12://"Longitude", "MEDIA_LONGITUDE"
1452 case 13://"Altitude", "MEDIA_ALTITUDE"
1453 if ((strColVal.CompareTo(L"Unknown") != 0) && (!strColVal.IsEmpty()))
1455 dVal = _LocalizedNumParser::ToDouble(strColVal, "C");
1456 r = GetLastResult();
1457 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform ToDouble operation.");
1459 pValue.reset(new (std::nothrow) Double(dVal));
1462 case 19://"Album", "MEDIA_ALBUM"
1467 if (pValue.get() != NULL)
1469 r = __pFinalOutList->Add(*(pValue.release()));
1470 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform arraylist Add operation.");
1478 _ContentSearchImpl::ExecuteAndFillAlbumValues(void) const
1480 int ret = MEDIA_CONTENT_ERROR_NONE;
1481 result r = E_SUCCESS;
1482 std::unique_ptr<GList, SearchGListDeleter> pItemList;
1483 GList* pTemp = NULL;
1484 std::unique_ptr<media_album_s, AlbumHandleDeleter> pAlbumHandle;
1485 std::unique_ptr<media_album_s, AlbumHandleDeleter> pTempAlbumHandle;
1488 std::unique_ptr<char, CharDeleter> pAlbumName;
1489 std::unique_ptr< String > pValue;
1492 pTemp = pItemList.get();
1494 ret = media_album_foreach_album_from_db(__pFilterHandle.get(), AlbumItemCb, &pTemp);
1495 r = MapCoreErrorToNativeResult(ret);
1496 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform media_album_foreach_album_from_db operation.");
1497 SysTryReturnResult(NID_CNT, pTemp != NULL, r, "media_info_foreach_media_from_db pTemp is null.");
1499 for (int idx = 0; idx < (int)g_list_length(pTemp); idx++)
1501 pAlbumHandle.reset(static_cast<media_album_h>(g_list_nth_data(pTemp, idx)));
1502 ret = media_album_get_name(pAlbumHandle.get(), &pName);
1503 r = MapCoreErrorToNativeResult(ret);
1504 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform media_album_get_name.");
1508 SysLog(NID_CNT, "pColumnVal = %s", pName);
1510 pAlbumName.reset(pName);
1511 pValue.reset(new (std::nothrow) String(pAlbumName.get()));
1512 SysTryReturnResult(NID_CNT, pValue != NULL, E_OUT_OF_MEMORY, "media_info_foreach_media_from_db pTemp is null.");
1516 r = __pFinalOutList->Add(pValue.get());
1517 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform arraylist Add operation.");
1522 String* pTempNameList(static_cast< String* >(__pFinalOutList->GetAt(lastIndex)));
1524 if (pValue->CompareTo(*pTempNameList) != 0)
1526 r = __pFinalOutList->Add(pValue.get());
1527 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform arraylist Add operation.");
1540 _ContentSearchImpl::MapCoreErrorToNativeResult(int reason) const
1542 result r = E_SUCCESS;
1546 case MEDIA_CONTENT_ERROR_NONE:
1550 case MEDIA_CONTENT_ERROR_INVALID_PARAMETER:
1552 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_INVALID_PARAMETER");
1555 case MEDIA_CONTENT_ERROR_DB_FAILED:
1557 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_DB_FAILED");
1560 case MEDIA_CONTENT_ERROR_OUT_OF_MEMORY:
1561 r = E_OUT_OF_MEMORY;
1562 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_OUT_OF_MEMORY");
1566 SysLog(NID_CNT, "default");
1574 _ContentSearchImpl::ConvertErrorToResult(result res) const
1576 result r = E_SUCCESS;
1580 case E_FILE_NOT_FOUND:
1593 // Callback function registered to each media info details
1594 // all items are appended to the list
1596 MediaItemCb(media_info_h media, void* pUserdata)
1598 int ret = MEDIA_CONTENT_ERROR_NONE;
1599 media_info_h new_media = NULL;
1600 ret = media_info_clone(&new_media, media);
1601 SysTryLog(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, "[E_SYSTEM] Failed to perform media_info_clone");
1603 GList** pList = (GList**)pUserdata;
1604 *pList = g_list_append(*pList, new_media);
1609 // Callback function registered for column values
1610 // all items are appended to the list
1612 GroupItemCb(const char* pGroupName, void* pUserdata)
1614 char* pGrpName = strdup(pGroupName);
1615 GList** pList = (GList**)pUserdata;
1616 *pList = g_list_append(*pList, pGrpName);
1621 // Callback function registered to each media info details
1622 // all items are appended to the list
1624 AlbumItemCb(media_album_h album, void* pUserdata)
1626 int ret = MEDIA_CONTENT_ERROR_NONE;
1627 media_album_h new_album = NULL;
1628 ret = media_album_clone(&new_album, album);
1629 SysTryLog(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, "[E_SYSTEM] Failed to perform media_album_clone");
1631 GList** pList = (GList**)pUserdata;
1632 *pList = g_list_append(*pList, new_album);