2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 * @file FCnt_ContentSearchImpl.cpp
18 * @brief This is the implementation file for the %_ContentSearchImpl class.
20 * This file contains implementation of the %_ContentSearchImpl class.
25 #include <FBaseSysLog.h>
26 #include <FBaseInteger.h>
27 #include <FBaseLongLong.h>
28 #include <FBaseFloat.h>
29 #include <FBaseColIList.h>
30 #include <FBaseUtilStringTokenizer.h>
31 #include <FCntContentSearch.h>
32 #include <FCntContentSearchResult.h>
33 #include <FSysEnvironment.h>
34 #include <FApp_AppInfo.h>
35 #include <FBase_StringConverter.h>
36 #include <FBase_LocalizedNumParser.h>
37 #include <FIo_FileImpl.h>
38 #include "FCnt_ContentUtility.h"
39 #include "FCnt_ContentSearchImpl.h"
40 #include "FCnt_ContentInfoImpl.h"
41 #include "FCnt_ImageContentInfoImpl.h"
42 #include "FCnt_AudioContentInfoImpl.h"
43 #include "FCnt_VideoContentInfoImpl.h"
44 #include "FCnt_OtherContentInfoImpl.h"
45 #include "FCnt_ContentInfoHelper.h"
47 using namespace Tizen::App;
48 using namespace Tizen::Base;
49 using namespace Tizen::Base::Collection;
50 using namespace Tizen::Base::Utility;
51 using namespace Tizen::Io;
52 using namespace Tizen::System;
54 namespace Tizen { namespace Content
57 static const int QUERY_LENGTH = 4096;
59 // Declaration for Callback function registered to each media info details
60 bool MediaItemCb(media_info_h media, void* pUserdata);
61 // Declaration for Callback function registered to each column details
62 bool GroupItemCb(const char* pGroupName, void* pUserdata);
63 // Declaration for Callback function registered to each album details
64 bool AlbumItemCb(media_album_h album, void* pUserdata);
66 // Default constructor
67 _ContentSearchImpl::_ContentSearchImpl(void)
68 : __contentType(CONTENT_TYPE_UNKNOWN)
69 , __pFinalOutList(NULL)
71 , __inputColumnName(L"")
72 , __inputSortOrder(SORT_ORDER_NONE)
73 , __pFilterHandle(NULL)
75 SysLog(NID_CNT, "Enter\n");
79 // Default destructor (disconnects the DB connection)
80 _ContentSearchImpl::~_ContentSearchImpl(void)
82 SysLog(NID_CNT, "Enter\n");
84 int ret = MEDIA_CONTENT_ERROR_NONE;
87 ret = media_content_disconnect();
88 r = MapCoreErrorToNativeResult(ret);
89 SysTryLog(NID_CNT, r == E_SUCCESS, "[%s] Propagated in ~_ContentSearchImpl", GetErrorMessage(r));
93 _ContentSearchImpl::GetInstance(ContentSearch& contentSearch)
95 return contentSearch.__pImpl;
98 const _ContentSearchImpl*
99 _ContentSearchImpl::GetInstance(const ContentSearch& contentSearch)
101 return contentSearch.__pImpl;
104 //make a connection to DB
106 _ContentSearchImpl::Construct(ContentType type)
108 SysLog(NID_CNT, "Enter\n");
110 result r = E_SUCCESS;
111 int ret = MEDIA_CONTENT_ERROR_NONE;
113 ret = media_content_connect();
114 SysTryReturnResult(NID_CNT, r == E_SUCCESS , E_SYSTEM, "Failed to perform media_content_connect operation.");
116 __contentType = type;
121 // Creates a filter for the input query string along with content type
122 // Initializes filter handle
123 // Image - MEDIA_TYPE=0
124 // Vide0 - MEDIA_TYPE=1
125 // Audio - MEDIA_TYPE=2 or MEDIA_TYPE=3
126 // Others - MEDIA_TYPE=4
128 // Appends MEDIA_TYPE with "AND" (if the input expression is not empty and content type is not ALL) and input expression
129 // Sets the condition and order.
130 // If any argument is not proper E_INVALID_ARG is returned
132 _ContentSearchImpl::CreateQueryFilter(bool isAndAppendReq) const
134 int ret = MEDIA_CONTENT_ERROR_NONE;
135 result r = E_SUCCESS;
137 std::unique_ptr<char[]> pInputCond;
138 std::unique_ptr<char[]> pSortCol;
140 String inputCondition;
143 filter_h tempFilter = NULL;
145 ret = media_filter_create(&tempFilter);
146 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "Failed to perform media_filter_create operation.");
148 std::unique_ptr<filter_s, SearchFilterHandleDeleter> pFilterHandle(tempFilter);
149 SysTryReturnResult(NID_CNT, pFilterHandle != null, E_OUT_OF_MEMORY, "pFilterHandle is null.");
151 switch (__contentType)
153 // Image-0,video-1,sound-2,music-3,other-4
154 case CONTENT_TYPE_OTHER:
155 inputCondition = "MEDIA_TYPE=4 ";
157 case CONTENT_TYPE_IMAGE:
158 inputCondition = "MEDIA_TYPE=0 ";
160 case CONTENT_TYPE_AUDIO:
161 inputCondition = "(MEDIA_TYPE=2 or MEDIA_TYPE=3) ";
163 case CONTENT_TYPE_VIDEO:
164 inputCondition = "MEDIA_TYPE=1 ";
166 case CONTENT_TYPE_ALL:
167 //If content type is CONTENT_TYPE_ALL, then MEDIA_TYPE is empty
173 if (!__inputExpr.IsEmpty())
175 if (isAndAppendReq && (!inputCondition.IsEmpty())) //For CONTENT_TYPE_ALL inputCondition is empty
177 r = inputCondition.Append("AND ");
178 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform append operation.");
181 r = inputCondition.Append(__inputExpr);
182 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform append operation.");
185 if (!inputCondition.IsEmpty())
187 //CopyToCharArrayN: utility function, converts a osp string to char*
188 pInputCond = std::unique_ptr<char[]>(_StringConverter::CopyToCharArrayN(inputCondition));
189 SysTryReturnResult(NID_CNT, pInputCond, E_OUT_OF_MEMORY, "pInputCond is NULL.");
191 SysLog(NID_CNT, "pInputCond = %s", pInputCond.get());
193 ret = media_filter_set_condition(pFilterHandle.get(), pInputCond.get(), MEDIA_CONTENT_COLLATE_DEFAULT);
194 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "Failed to perform media_filter_set_condition operation.");
197 if (!__inputColumnName.IsEmpty()) // SortColumn is optional in case of SearchN
199 //__inputColumnName (osp column name) is replaced with slpColumn (slp column name).
200 r = GetSlpColumnName(slpColumn);
201 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform GetSlpColumnName operation.");
203 //CopyToCharArrayN: utility function, converts a osp string to char*
205 pSortCol = std::unique_ptr<char[]>(_StringConverter::CopyToCharArrayN(slpColumn));
206 SysTryReturnResult(NID_CNT, pSortCol, E_OUT_OF_MEMORY, "pSortCol is NULL.");
208 if (__inputSortOrder == SORT_ORDER_ASCENDING)
210 ret = media_filter_set_order(pFilterHandle.get(), MEDIA_CONTENT_ORDER_ASC, pSortCol.get(), MEDIA_CONTENT_COLLATE_NOCASE);
211 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "Failed to perform media_filter_set_order operation.");
213 else if (__inputSortOrder == SORT_ORDER_DESCENDING)
215 ret = media_filter_set_order(pFilterHandle.get(), MEDIA_CONTENT_ORDER_DESC, pSortCol.get(), MEDIA_CONTENT_COLLATE_NOCASE);
216 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "Failed to perform media_filter_set_order operation.");
220 __pFilterHandle.reset(pFilterHandle.release());
225 // Osp column names are mapped with slp column names
226 // CONTENT_TYPE_OTHER and CONTENT_TYPE_IMAGE (0 - 13 ) are valid columns
227 // CONTENT_TYPE_VIDEO (0 - 16 ) are valid columns
228 // CONTENT_TYPE_ALL and CONTENT_TYPE_VIDEO (0 - 18 ) are valid columns
229 // if the given osp column is out of the specified range of the type, E_INVALID_ARG is retuned.
231 _ContentSearchImpl::GetSlpColumnName(String& inputCol) const
233 String ospColumnName(L"");
234 String slpColumnName(L"");
235 String columnName(__inputColumnName);
236 result r = E_SUCCESS;
238 switch (__contentType)
240 case CONTENT_TYPE_OTHER:
242 case CONTENT_TYPE_IMAGE:
243 maxCols = MAX_QUERY_COLUMNS_FOR_IMAGE_OTHERS;
245 case CONTENT_TYPE_VIDEO:
246 maxCols = MAX_QUERY_COLUMNS_FOR_VIDEO;
248 case CONTENT_TYPE_AUDIO:
250 case CONTENT_TYPE_ALL:
251 maxCols = MAX_QUERY_COLUMNS;
256 for (int colIndex = 0; colIndex < maxCols; colIndex++)
258 ospColumnName.Clear();
259 slpColumnName.Clear();
261 ospColumnName = dbfieldinfo[colIndex].dbFieldOspName ;
262 slpColumnName = dbfieldinfo[colIndex].dbFieldSlpName ;
264 ospColumnName.ToUpper();
265 columnName.ToUpper();
266 if (columnName == ospColumnName)
268 inputCol = slpColumnName;
272 return E_INVALID_ARG;
275 //If the input expression contains any osp column name, it will be replaced with slp column name.
276 // only CONTENT_TYPE_AUDIO and CONTENT_TYPE_ALL allowed to use all given columns
277 // so, check for invalid column for CONTENT_TYPE_OTHER,CONTENT_TYPE_IMAGE and CONTENT_TYPE_VIDEO.
278 // all the osp columns in the expression should be replaced with slp column names.
279 // ' is used as a delimeter in parsing user query. so, \\' is saved as a special@apostrophe string.
280 // \\' is replaced with '', which considers ' as normal character.
283 _ContentSearchImpl::ReplaceOspColumnNameWithSlp(void) const
285 String ospColumnName(L"");
286 String slpColumnName(L"");
287 String splApostrophe(L"special@apostrophe");
288 result r = E_SUCCESS;
293 String strToBeReplaced(L"\\'");
294 int strLen = strToBeReplaced.GetLength();
297 while(E_SUCCESS == __inputExpr.IndexOf(strToBeReplaced,startIndex,indexOf))
299 int lenAfterSubStr = indexOf + strLen;
300 while ((lenAfterSubStr < __inputExpr.GetLength()) && (__inputExpr[lenAfterSubStr] == ' '))
304 if ((lenAfterSubStr < __inputExpr.GetLength()) && ((__inputExpr[lenAfterSubStr] == '\'') ||
305 ((!__inputExpr.StartsWith(L"AND ", lenAfterSubStr)) && (!__inputExpr.StartsWith(L"OR ", lenAfterSubStr)))))
307 r = __inputExpr.Remove(indexOf,strLen);
308 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "Failed to perform Remove operation.");
309 r = __inputExpr.Insert(splApostrophe,indexOf);
310 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "Failed to perform Insert operation.");
311 startIndex = indexOf + splApostrophe.GetLength();
315 startIndex = lenAfterSubStr;
319 SysLog(NID_CNT, "__inputExpr after splApostrophe append = %ls", __inputExpr.GetPointer());
321 switch (__contentType)
323 case CONTENT_TYPE_OTHER:
325 case CONTENT_TYPE_IMAGE:
326 r = CheckInvalidColumnInQuery();
327 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_INVALID_ARG, "Invalid Column In QueryString.");
328 maxCols = MAX_QUERY_COLUMNS_FOR_IMAGE_OTHERS;
330 case CONTENT_TYPE_VIDEO:
331 r = CheckInvalidColumnInQuery();
332 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_INVALID_ARG, "Invalid Column In QueryString.");
333 maxCols = MAX_QUERY_COLUMNS_FOR_VIDEO;
335 case CONTENT_TYPE_AUDIO:
337 case CONTENT_TYPE_ALL:
338 maxCols = MAX_QUERY_COLUMNS;
343 for (int colIndex = 0; colIndex < maxCols; colIndex++)
345 ospColumnName.Clear();
346 slpColumnName.Clear();
348 ospColumnName = dbfieldinfo[colIndex].dbFieldOspName ;
349 slpColumnName = dbfieldinfo[colIndex].dbFieldSlpName ;
351 ReplaceString(ospColumnName,slpColumnName);
354 // Append ESCAPE '\' for LIKE query
355 r = AppendEscapeKeywordForLikeQuery();
356 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "AppendEscapeKeywordForLikeQuery failed.");
358 r = ReplaceDateTimeStringWithInt();
359 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_INVALID_ARG, "ReplaceDateTimeStringWithInt failed.");
361 // replace splApostrophe string with actual
362 r = __inputExpr.Replace(splApostrophe, "''");
363 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string Replace failed.");
368 //This function is to appened ESCAPE keyword for _ and % special characters in LIKE query.
371 _ContentSearchImpl::AppendEscapeKeywordForLikeQuery(void) const
373 String delim = L"'"; //Delimeters is ' .
374 result r = E_SUCCESS;
376 bool isAppendEscape = false;
379 String inputExpr = __inputExpr;
381 // Create a StringTokenizer instance
382 StringTokenizer strTok(inputExpr, delim);
386 while (strTok.HasMoreTokens())
388 r = strTok.GetNextToken(token);
389 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "GetNextToken failed.");
390 if (isCol) //column name
394 tokenUpper.ToUpper();
395 if (tokenUpper.Contains(" LIKE"))
397 isAppendEscape = true;
401 isAppendEscape = false;
403 r = inputExpr.Append(token);
404 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
406 else // value of the column
409 r = inputExpr.Append("'");
410 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
411 r = inputExpr.Append(token);
412 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
413 r = inputExpr.Append("'");
414 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
418 if (token.Contains("\\_") || token.Contains("\\%"))
420 r = inputExpr.Append("ESCAPE'\\' ");
421 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
428 r = __inputExpr.Insert(inputExpr, 0);
429 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string insert failed.");
434 //This function is to replace DateTime value(osp datetime type is string) which is string with int.(SLP dateTime column type is int)
437 _ContentSearchImpl::ReplaceDateTimeStringWithInt(void) const
439 String delim = L"'"; //Delimeters is ' .
440 result r = E_SUCCESS;
442 bool isConvertReq = false;
443 bool isBetweenExistsInDateTimeQuery = false;
446 String inputExpr = __inputExpr;
448 if(!inputExpr.Contains("MEDIA_ADDED_TIME"))
453 // Create a StringTokenizer instance
454 StringTokenizer strTok(inputExpr, delim);
458 while (strTok.HasMoreTokens())
460 r = strTok.GetNextToken(token);
461 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "GetNextToken failed.");
462 if (isCol) //column name
466 tokenUpper.ToUpper();
467 if(isBetweenExistsInDateTimeQuery)
469 isBetweenExistsInDateTimeQuery = false;
474 if (tokenUpper.Contains("MEDIA_ADDED_TIME"))
476 if (tokenUpper.Contains("BETWEEN"))
478 isBetweenExistsInDateTimeQuery = true;
484 isConvertReq = false;
488 r = inputExpr.Append(token);
489 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string append failed.");
491 else // value of the column
494 r = inputExpr.Append("'");
495 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string append failed.");
499 Tizen::Base::DateTime dt;
500 r = Tizen::Base::DateTime::Parse(token, dt);
501 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to parse DateTime.");
503 int year = dt.GetYear();
504 int month = dt.GetMonth();
505 int day = dt.GetDay();
506 int hour = dt.GetHour();
507 int minute = dt.GetMinute();
508 int second = dt.GetSecond();
514 timeInfo = localtime(&rawTime);
515 timeInfo->tm_year = year - 1900;
516 timeInfo->tm_mon = month - 1;
517 timeInfo->tm_mday = day;
518 timeInfo->tm_hour = hour;
519 timeInfo->tm_min = minute;
520 timeInfo->tm_sec = second;
522 time_t seconds = mktime(timeInfo);
523 SysTryReturnResult(NID_CNT, seconds != -1, E_INVALID_ARG, "Failed to convert DateTime to broken-down time.");
525 long long ticksInSeconds = (long long)seconds;
527 r = inputExpr.Append(ticksInSeconds);
528 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string append failed.");
532 r = inputExpr.Append(token);
533 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string append failed.");
536 r = inputExpr.Append("'");
537 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string append failed.");
542 r = __inputExpr.Insert(inputExpr, 0);
543 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string insert failed.");
548 // CONTENT_TYPE_OTHER and CONTENT_TYPE_IMAGE (0 - 13 ) are valid columns
549 // CONTENT_TYPE_VIDEO (0 - 16 ) are valid columns
550 // CONTENT_TYPE_ALL and CONTENT_TYPE_VIDEO (0 - 18 ) are valid columns
551 // This functions checks for invalid column in the given input string (only allowed columns should be used by content type other wise
552 // E_INVALID_ARG is returned)
553 // StringTokenizer is used to parse input expression, by using delimater "'", to differentiate column and value.
554 // As values may also contain column names
555 // Ex: 1. where author = syam_author_01 2. where album = jalsa_album_name_01.
558 _ContentSearchImpl::CheckInvalidColumnInQuery(void) const
560 result r = E_SUCCESS;
562 String delim = L"'"; //Delimeters is ' .
563 bool isColReplaceReq = true;
565 String inputExpr = __inputExpr;
567 // Create a StringTokenizer instance
568 StringTokenizer strTok(inputExpr, delim);
572 while (strTok.HasMoreTokens())
574 r = strTok.GetNextToken(token);
575 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "strTok GetNextToken failed.");
577 SysLog(NID_CNT, "In CheckInvalidColumnInQuery token[%d] = %ls", ++tokenNo, token.GetPointer());
581 isColReplaceReq = false;
582 r = inputExpr.Append(token);
583 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
585 switch (__contentType)
587 case CONTENT_TYPE_OTHER:
589 case CONTENT_TYPE_IMAGE:
590 if ((token.Contains("TITLE")) || (token.Contains("ARTIST")) || (token.Contains("GENRE")))
592 SysLog(NID_CNT, "Title or Artist or Genre are not valid cloumns for this content type");
593 return E_INVALID_ARG;
596 case CONTENT_TYPE_VIDEO:
597 if ((token.Contains("COMPOSER")) || (token.Contains("ALBUM")))
599 SysLog(NID_CNT, "Composer or Album are not valid cloumns for this content type");
600 return E_INVALID_ARG;
609 isColReplaceReq = true;
610 r = inputExpr.Append("'");
611 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
612 r = inputExpr.Append(token);
613 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
614 r = inputExpr.Append("'");
615 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
621 // It replaces native column name with core column name.
622 // StringTokenizer is used to parse input expression, by using delimiter "'", to differentiate column and value.
623 // As values may also contain column names
624 // Only column names are replaced but not values(values may contain column names)
625 // Ex: 1. where author = syam_author_01 2. where album = jalsa_album_name_01.
628 _ContentSearchImpl::ReplaceString(String ospColumnName, String slpColumnName) const
630 String delim = L"'"; //Delimiters is ' .
631 result r = E_SUCCESS;
632 bool isColReplaceReq = true;
634 String inputExpr = __inputExpr;
636 // Create a StringTokenizer instance
637 StringTokenizer strTok(inputExpr, delim);
641 while (strTok.HasMoreTokens())
643 r = strTok.GetNextToken(token); // Osp, StringTokenizer, Sample, code
644 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string GetNextToken() failed.");
645 if (isColReplaceReq) //column name
647 isColReplaceReq = false;
648 r = token.Replace(ospColumnName, slpColumnName);
649 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string replace() failed.");
650 r = inputExpr.Append(token);
651 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
653 else // value of the column
655 isColReplaceReq = true;
656 r = inputExpr.Append("'");
657 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
658 r = inputExpr.Append(token);
659 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
660 r = inputExpr.Append("'");
661 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
665 r = __inputExpr.Insert(inputExpr, 0);
666 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string insert() failed.");
671 // Returns list of search result for the given expression and content type.
673 _ContentSearchImpl::SearchN(int pageNo, int countPerPage, int& totalPageCount, int& totalCount, const String& whereExpr, const String& sortColumn, SortOrder sortOrder) const
675 SysLog(NID_CNT, "pageNo = %d, countPerPage = %d, whereExpr = %ls", pageNo, countPerPage, whereExpr.GetPointer());
679 result r = E_SUCCESS;
680 int ret = MEDIA_CONTENT_ERROR_NONE;
683 __inputColumnName.Clear();
685 __inputColumnName = sortColumn;
686 __inputSortOrder = sortOrder;
690 if (!whereExpr.IsEmpty()) // copy whereExpr if not empty to class variable __inputExpr
692 r = __inputExpr.Append(whereExpr);
693 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[%s] __inputExpr.Append Failed as whereExpr is not empty.", GetErrorMessage(r));
695 r = ReplaceOspColumnNameWithSlp();
696 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[%s] ReplaceOspColumnNameWithSlp for InputExpr Failed.", GetErrorMessage(r));
698 SysLog(NID_CNT, "After replace __inputExpr = %ls", __inputExpr.GetPointer());
700 if ((__inputColumnName.IsEmpty()) && ((__inputSortOrder == SORT_ORDER_ASCENDING) || (__inputSortOrder == SORT_ORDER_DESCENDING)))
702 SysLog(NID_CNT, "sort column name is empty and sort oder is not none. so,E_INVALID_ARG occured.");
703 SetLastResult(E_INVALID_ARG);
708 std::unique_ptr<ArrayList, AllElementsDeleter> pFinalOutList(new (std::nothrow) ArrayList());
709 SysTryReturn(NID_CNT, pFinalOutList.get() != null, NULL, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to construct ArrayList.");
711 r = pFinalOutList->Construct();
712 SysTryReturn(NID_CNT, !IsFailed(r), NULL, r, "[%s] Failed to construct ArrayList.", GetErrorMessage(r));
714 __pFinalOutList = std::move(pFinalOutList);
716 r = CreateQueryFilter(true);
717 SysTryReturn(NID_CNT, !IsFailed(r), NULL, r, "[%s] Failed to perform CreateQueryFilter operation.", GetErrorMessage(r));
719 ret = media_info_get_media_count_from_db(__pFilterHandle.get(), &totalCount);
720 r = MapCoreErrorToNativeResult(ret);
721 SysTryReturn(NID_CNT, r == E_SUCCESS , NULL, r, "[%s] Failed to perform media_info_get_media_count_from_db operation.", GetErrorMessage(r));
723 SysLog(NID_CNT, "totalCount is [%d] for media_info_get_media_count_from_db", totalCount);
727 if ((totalCount % countPerPage) == 0)
729 totalPageCount = totalCount / countPerPage;
733 totalPageCount = (totalCount / countPerPage) + 1;
736 SysTryReturn(NID_CNT, ((pageNo >= 1) && (pageNo <= totalPageCount)) , NULL, E_INVALID_ARG,
737 "[%s] Failed to perform SearchN operation. pageNo : %d, totalPageCount : %d.", GetErrorMessage(r), pageNo, totalPageCount);
739 offset = (pageNo * countPerPage) - countPerPage;
741 SysLog(NID_CNT, " SearchN totalCount [%d] totalPageCount[%d] __countPerPage[%d] __pageNo[%d] offset[%d]",
742 totalCount, totalPageCount, countPerPage, pageNo, offset);
744 ret = media_filter_set_offset(__pFilterHandle.get(), offset, countPerPage);
745 r = MapCoreErrorToNativeResult(ret);
746 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r,
747 "[%s] Failed to perform media_filter_set_offset operation.", GetErrorMessage(r));
749 r = ExecuteAndFillFinalOutList();
750 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, E_SYSTEM, "[E_SYSTEM] ExecuteAndFillFinalOutList Failed.");
754 SysLogException(NID_CNT, E_INVALID_ARG, "[%s] (pageNo > 1) and (totalcount = 0).", GetErrorMessage(E_INVALID_ARG));
760 return __pFinalOutList.release();
763 // Fills final result list
765 _ContentSearchImpl::ExecuteAndFillFinalOutList(void) const
767 SysLog(NID_CNT, "Enter\n");
769 int ret = MEDIA_CONTENT_ERROR_NONE;
770 result r = E_SUCCESS;
772 std::unique_ptr<GList, SearchGListDeleter> pItemList;
774 std::unique_ptr<media_info_s, SearchMediaHandleDeleter> pMediaHandle;
776 std::unique_ptr<ImageContentInfo> pImageContentInfo;
777 std::unique_ptr<AudioContentInfo> pAudioContentInfo;
778 std::unique_ptr<VideoContentInfo> pVideoContentInfo;
779 std::unique_ptr<OtherContentInfo> pOtherContentInfo;
781 _ImageContentInfoImpl* pImageContentInfoImpl = null;
782 _AudioContentInfoImpl* pAudioContentInfoImpl = null;
783 _VideoContentInfoImpl* pVideoContentInfoImpl = null;
784 _OtherContentInfoImpl* pOtherContentInfoImpl = null;
786 std::unique_ptr<ContentSearchResult> pContentSearchResult;
788 pTemp = pItemList.get();
790 ret = media_info_foreach_media_from_db(__pFilterHandle.get(), MediaItemCb, &pTemp);
791 r = MapCoreErrorToNativeResult(ret);
792 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform media_info_foreach_media_from_db operation.");
794 SysTryReturnResult(NID_CNT, pTemp != NULL, r, "media_info_foreach_media_from_db pTemp is null.");
796 media_content_type_e mediaType = MEDIA_CONTENT_TYPE_OTHERS;
798 for (int idx = 0; idx < (int)g_list_length(pTemp); idx++)
800 pMediaHandle.reset(static_cast<media_info_h>(g_list_nth_data(pTemp, idx)));
802 ret = media_info_get_media_type(pMediaHandle.get(), &mediaType);
803 r = MapCoreErrorToNativeResult(ret);
804 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform media_info_get_media_type.");
806 std::unique_ptr<char, UtilCharDeleter> pMediaPath;
807 char* pTempPath = null;
809 ret = media_info_get_file_path(pMediaHandle.get(), &pTempPath);
810 r = MapCoreErrorToNativeResult(ret);
811 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform media_info_get_file_path operation.");
813 pMediaPath.reset(pTempPath);
814 String contentPath(pMediaPath.get());
815 String changedPath(contentPath);
817 // If the api version is 2.0, the content path has to be changed.
818 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
820 r = _FileImpl::ConvertPhysicalToVirtualPath(contentPath, changedPath);
821 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG,
822 "[%s] Failed to convert physical path to virtual path.", GetErrorMessage(E_INVALID_ARG));
827 case MEDIA_CONTENT_TYPE_OTHERS:
828 pOtherContentInfo = std::unique_ptr<OtherContentInfo>(new (std::nothrow) OtherContentInfo);
829 SysTryReturnResult(NID_CNT, pOtherContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pOtherContentInfo.");
831 r = pOtherContentInfo->Construct(&changedPath);
832 r = ConvertErrorToResult(r);
833 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Construct operation to OtherContentInfo.");
835 pOtherContentInfoImpl = null;
836 pOtherContentInfoImpl = _OtherContentInfoImpl::GetInstance(*(pOtherContentInfo.get()));
837 SysTryReturnResult(NID_CNT, pOtherContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to assign operation to pOtherContentInfoImpl.");
839 r = _ContentUtility::FillContentData(pMediaHandle.get(), pOtherContentInfoImpl);
840 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
842 _ContentInfoHelper::SetContentInfoImpl(pOtherContentInfo.get(), pOtherContentInfoImpl);
844 pContentSearchResult = std::unique_ptr<ContentSearchResult>(new (std::nothrow) ContentSearchResult);
845 SysTryReturnResult(NID_CNT, pContentSearchResult.get() != null, E_OUT_OF_MEMORY, "Failed to create pContentSearchResult.");
847 pContentSearchResult->SetContentType(CONTENT_TYPE_OTHER);
848 pContentSearchResult->SetContentInfo(pOtherContentInfo.release());
850 // Shallow copy, adds just the pointer: not the element
851 r = __pFinalOutList->Add(*(pContentSearchResult.release()));
852 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation for ArrayList.");
855 case MEDIA_CONTENT_TYPE_IMAGE:
856 pImageContentInfo = std::unique_ptr<ImageContentInfo>(new (std::nothrow) ImageContentInfo);
857 SysTryReturnResult(NID_CNT, pImageContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pImageContentInfo.");
859 r = pImageContentInfo->Construct(&changedPath);
860 r = ConvertErrorToResult(r);
861 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Construct operation to ImageContentInfo.");
863 pImageContentInfoImpl = null;
864 pImageContentInfoImpl = _ImageContentInfoImpl::GetInstance(*(pImageContentInfo.get()));
865 SysTryReturnResult(NID_CNT, pImageContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to assign operation to pImageContentInfoImpl.");
867 r = _ContentUtility::FillContentData(pMediaHandle.get(), pImageContentInfoImpl);
868 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
870 r = _ContentUtility::FillImageContentData(pMediaHandle.get(), pImageContentInfoImpl);
871 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform GetDataFromImageTable operation.");
873 _ContentInfoHelper::SetContentInfoImpl(pImageContentInfo.get(), pImageContentInfoImpl);
875 pContentSearchResult = std::unique_ptr<ContentSearchResult>(new (std::nothrow) ContentSearchResult);
876 SysTryReturnResult(NID_CNT, pContentSearchResult.get() != null, E_OUT_OF_MEMORY, "Failed to create pContentSearchResult.");
878 pContentSearchResult->SetContentType(CONTENT_TYPE_IMAGE);
879 pContentSearchResult->SetContentInfo(pImageContentInfo.release());
881 // Shallow copy, adds just the pointer: not the element
882 r = __pFinalOutList->Add(*(pContentSearchResult.release()));
883 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation for ArrayList.");
886 case MEDIA_CONTENT_TYPE_MUSIC:
888 case MEDIA_CONTENT_TYPE_SOUND:
889 pAudioContentInfo = std::unique_ptr<AudioContentInfo>(new (std::nothrow) AudioContentInfo);
890 SysTryReturnResult(NID_CNT, pAudioContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pAudioContentInfo.");
892 r = pAudioContentInfo->Construct(&changedPath);
893 r = ConvertErrorToResult(r);
894 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Construct operation to AudioContentInfo.");
896 pAudioContentInfoImpl = null;
897 pAudioContentInfoImpl = _AudioContentInfoImpl::GetInstance(*(pAudioContentInfo.get()));
898 SysTryReturnResult(NID_CNT, pAudioContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to assign operation to pAudioContentInfoImpl.");
900 r = _ContentUtility::FillContentData(pMediaHandle.get(), pAudioContentInfoImpl);
901 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
903 r = _ContentUtility::FillAudioContentData(pMediaHandle.get(), pAudioContentInfoImpl);
904 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillAudioContentData operation.");
906 _ContentInfoHelper::SetContentInfoImpl(pAudioContentInfo.get(), pAudioContentInfoImpl);
908 pContentSearchResult = std::unique_ptr<ContentSearchResult>(new (std::nothrow) ContentSearchResult);
909 SysTryReturnResult(NID_CNT, pContentSearchResult.get() != null, E_OUT_OF_MEMORY, "Failed to create pContentSearchResult.");
911 pContentSearchResult->SetContentType(CONTENT_TYPE_AUDIO);
912 pContentSearchResult->SetContentInfo(pAudioContentInfo.release());
914 // Shallow copy, adds just the pointer: not the element
915 r = __pFinalOutList->Add(*(pContentSearchResult.release()));
916 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation for ArrayList.");
919 case MEDIA_CONTENT_TYPE_VIDEO:
920 pVideoContentInfo = std::unique_ptr<VideoContentInfo>(new (std::nothrow) VideoContentInfo);
921 SysTryReturnResult(NID_CNT, pVideoContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pVideoContentInfo.");
923 r = pVideoContentInfo->Construct(&changedPath);
924 r = ConvertErrorToResult(r);
925 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Construct operation to VideoContentInfo.");
927 pVideoContentInfoImpl = null;
928 pVideoContentInfoImpl = _VideoContentInfoImpl::GetInstance(*(pVideoContentInfo.get()));
929 SysTryReturnResult(NID_CNT, pVideoContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to assign operation to pVideoContentInfoImpl.");
931 r = _ContentUtility::FillContentData(pMediaHandle.get(), pVideoContentInfoImpl);
932 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
934 r = _ContentUtility::FillVideoContentData(pMediaHandle.get(), pVideoContentInfoImpl);
935 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillVideoContentData operation.");
937 _ContentInfoHelper::SetContentInfoImpl(pVideoContentInfo.get(), pVideoContentInfoImpl);
939 pContentSearchResult = std::unique_ptr<ContentSearchResult>(new (std::nothrow) ContentSearchResult);
940 SysTryReturnResult(NID_CNT, pContentSearchResult.get() != null, E_OUT_OF_MEMORY, "Failed to create pContentSearchResult.");
942 pContentSearchResult->SetContentType(CONTENT_TYPE_VIDEO);
943 pContentSearchResult->SetContentInfo(pVideoContentInfo.release());
945 // Shallow copy, adds just the pointer: not the element
946 r = __pFinalOutList->Add(*(pContentSearchResult.release()));
947 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation for ArrayList.");
957 // returns given column value list in the requested order
959 _ContentSearchImpl::GetValueListN(const String& sortColumn, SortOrder sortOrder)
961 SysLog(NID_CNT, "inputColumn = %ls", sortColumn.GetPointer());
964 result r = E_SUCCESS;
968 __inputColumnName.Clear();
971 __inputColumnName = sortColumn;
972 __inputSortOrder = sortOrder;
974 String ospColumnName(L"");
975 String slpColumnName(L"");
977 String columnName(__inputColumnName);
979 if ((__inputColumnName.IsEmpty()) && ((__inputSortOrder == SORT_ORDER_ASCENDING) || (__inputSortOrder == SORT_ORDER_DESCENDING)))
981 SysLog(NID_CNT, "sort column name is empty and sort oder is not none. so,E_INVALID_ARG occured.");
982 SetLastResult(E_INVALID_ARG);
987 std::unique_ptr<ArrayList, AllElementsDeleter> pFinalOutList(new (std::nothrow) ArrayList());
988 SysTryReturn(NID_CNT, pFinalOutList.get() != null, NULL, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to construct ArrayList.");
990 r = pFinalOutList->Construct();
991 SysTryReturn(NID_CNT, !IsFailed(r), NULL, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to construct ArrayList.");
993 __pFinalOutList = std::move(pFinalOutList);
995 switch (__contentType)
997 case CONTENT_TYPE_OTHER:
999 case CONTENT_TYPE_IMAGE:
1000 maxCols = MAX_QUERY_COLUMNS_FOR_IMAGE_OTHERS;
1002 case CONTENT_TYPE_VIDEO:
1003 maxCols = MAX_QUERY_COLUMNS_FOR_VIDEO;
1005 case CONTENT_TYPE_AUDIO:
1007 case CONTENT_TYPE_ALL:
1008 maxCols = MAX_QUERY_COLUMNS;
1014 for (colIndex = 0; colIndex < maxCols; colIndex++)
1016 ospColumnName.Clear();
1017 slpColumnName.Clear();
1019 ospColumnName = dbfieldinfo[colIndex].dbFieldOspName ;
1020 slpColumnName = dbfieldinfo[colIndex].dbFieldSlpName ;
1022 ospColumnName.ToUpper();
1023 columnName.ToUpper();
1024 if (columnName == ospColumnName)
1026 r = FillColumnsList(colIndex);
1027 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[%s] FillColumnsList Failed.", GetErrorMessage(r));
1031 if (colIndex == maxCols)
1033 SysLogException(NID_CNT, E_INVALID_ARG, "[%s] The column is invalid.", GetErrorMessage(E_INVALID_ARG));
1039 return __pFinalOutList.release();
1042 // returns given column value list in the requested order
1044 _ContentSearchImpl::GetValueListN(int pageNo, int countPerPage, int& totalPageCount, int& totalCount, const String& sortColumn, SortOrder sortOrder) const
1046 SysLog(NID_CNT, "pageNo = %d, countPerPage = %d, inputColumn = %ls", pageNo, countPerPage, sortColumn.GetPointer());
1050 result r = E_SUCCESS;
1054 __inputColumnName.Clear();
1055 __inputExpr.Clear();
1057 __inputColumnName = sortColumn;
1058 __inputSortOrder = sortOrder;
1060 String ospColumnName(L"");
1061 String slpColumnName(L"");
1063 String columnName(__inputColumnName);
1065 if ((__inputColumnName.IsEmpty()) && ((__inputSortOrder == SORT_ORDER_ASCENDING) || (__inputSortOrder == SORT_ORDER_DESCENDING)))
1067 SysLog(NID_CNT, "sort column name is empty and sort oder is not none. so,E_INVALID_ARG occured.");
1068 SetLastResult(E_INVALID_ARG);
1073 std::unique_ptr<ArrayList, AllElementsDeleter> pFinalOutList(new (std::nothrow) ArrayList());
1074 SysTryReturn(NID_CNT, pFinalOutList.get() != null, NULL, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to construct ArrayList.");
1076 r = pFinalOutList->Construct();
1077 SysTryReturn(NID_CNT, !IsFailed(r), NULL, r, "[%s] Failed to construct ArrayList.", GetErrorMessage(r));
1079 __pFinalOutList = std::move(pFinalOutList);
1081 switch (__contentType)
1083 case CONTENT_TYPE_OTHER:
1085 case CONTENT_TYPE_IMAGE:
1086 maxCols = MAX_QUERY_COLUMNS_FOR_IMAGE_OTHERS;
1088 case CONTENT_TYPE_VIDEO:
1089 maxCols = MAX_QUERY_COLUMNS_FOR_VIDEO;
1091 case CONTENT_TYPE_AUDIO:
1093 case CONTENT_TYPE_ALL:
1094 maxCols = MAX_QUERY_COLUMNS;
1100 for (colIndex = 0; colIndex < maxCols; colIndex++)
1102 ospColumnName.Clear();
1103 slpColumnName.Clear();
1105 ospColumnName = dbfieldinfo[colIndex].dbFieldOspName ;
1106 slpColumnName = dbfieldinfo[colIndex].dbFieldSlpName ;
1108 ospColumnName.ToUpper();
1109 columnName.ToUpper();
1110 if (columnName == ospColumnName)
1112 r = FillColumnsList(pageNo, countPerPage, totalPageCount, totalCount, colIndex);
1113 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[%s] FillColumnsList Failed.", GetErrorMessage(r));
1117 if (colIndex == maxCols)
1119 SysLogException(NID_CNT, E_INVALID_ARG, "[%s] The column is invalid.", GetErrorMessage(E_INVALID_ARG));
1125 return __pFinalOutList.release();
1128 // prepares query expression to be used in group api. colIndex is mapped to actual group value.
1130 _ContentSearchImpl::GetIndexAndCreateQueryExp(int colIndex) const
1132 media_group_e groupIndex = MEDIA_CONTENT_GROUP_DISPLAY_NAME;;
1135 case 0://"ContentType", "MEDIA_TYPE"
1136 groupIndex = MEDIA_CONTENT_GROUP_TYPE;
1137 __inputExpr = "MEDIA_TYPE IS NOT NULL";
1139 case 1://"ContentFileName", "MEDIA_DISPLAY_NAME"
1140 groupIndex = MEDIA_CONTENT_GROUP_DISPLAY_NAME;
1141 __inputExpr = "MEDIA_DISPLAY_NAME IS NOT NULL";
1143 case 2://"ContentName", "MEDIA_CONTENT_NAME"
1144 groupIndex = MEDIA_CONTENT_GROUP_CONTENT_NAME;
1145 __inputExpr = "MEDIA_CONTENT_NAME IS NOT NULL";
1147 case 3://"Category", "MEDIA_CATEGORY"
1148 groupIndex = MEDIA_CONTENT_GROUP_CATEGORY;
1149 __inputExpr = "MEDIA_CATEGORY IS NOT NULL";
1151 case 4://"Author", "MEDIA_AUTHOR"
1152 groupIndex = MEDIA_CONTENT_GROUP_AUTHOR;
1153 __inputExpr = "MEDIA_AUTHOR IS NOT NULL";
1155 case 5://"keyword", "MEDIA_KEYWORD"
1156 groupIndex = MEDIA_CONTENT_GROUP_KEYWORD;
1157 __inputExpr = "MEDIA_KEYWORD IS NOT NULL";
1159 case 6://"Provider", "MEDIA_PROVIDER"
1160 groupIndex = MEDIA_CONTENT_GROUP_PROVIDER;
1161 __inputExpr = "MEDIA_PROVIDER IS NOT NULL";
1163 case 7://"Rating", "MEDIA_AGE_RATING"
1164 groupIndex = MEDIA_CONTENT_GROUP_AGE_RATING;
1165 __inputExpr = "MEDIA_AGE_RATING IS NOT NULL";
1167 case 8://"LocationTag", "MEDIA_LOCATION_TAG"
1168 groupIndex = MEDIA_CONTENT_GROUP_LOCATION_TAG;
1169 __inputExpr = "MEDIA_LOCATION_TAG IS NOT NULL";
1171 case 9://"ContentSize", "MEDIA_SIZE"
1172 groupIndex = MEDIA_CONTENT_GROUP_SIZE;
1173 __inputExpr = "MEDIA_SIZE IS NOT NULL";
1175 case 10://"DateTime", "MEDIA_ADDED_TIME"
1176 groupIndex = MEDIA_CONTENT_GROUP_ADDED_TIME;
1177 __inputExpr = "MEDIA_ADDED_TIME IS NOT NULL";
1179 case 11://"Latitude", "MEDIA_LATITUDE"
1180 groupIndex = MEDIA_CONTENT_GROUP_LATITUDE;
1181 __inputExpr = "MEDIA_LATITUDE IS NOT NULL";
1183 case 12://"Longitude", "MEDIA_LONGITUDE"
1184 groupIndex = MEDIA_CONTENT_GROUP_LONGITUDE;
1185 __inputExpr = "MEDIA_LONGITUDE IS NOT NULL";
1187 case 13://"Altitude", "MEDIA_ALTITUDE"
1188 groupIndex = MEDIA_CONTENT_GROUP_ALTITUDE;
1189 __inputExpr = "MEDIA_ALTITUDE IS NOT NULL";
1191 case 14://"Title", "MEDIA_TITLE"
1192 groupIndex = MEDIA_CONTENT_GROUP_TITLE;
1193 __inputExpr = "MEDIA_TITLE IS NOT NULL";
1195 case 15://"Artist", "MEDIA_ARTIST"
1196 groupIndex = MEDIA_CONTENT_GROUP_ARTIST;
1197 __inputExpr = "MEDIA_ARTIST IS NOT NULL";
1199 case 16://"Genre", "MEDIA_GENRE"
1200 groupIndex = MEDIA_CONTENT_GROUP_GENRE;
1201 __inputExpr = "MEDIA_GENRE IS NOT NULL";
1203 case 17://"Year", "MEDIA_YEAR"
1204 groupIndex = MEDIA_CONTENT_GROUP_YEAR;
1205 __inputExpr = "MEDIA_YEAR IS NOT NULL";
1207 case 18://"Composer", "MEDIA_COMPOSER"
1208 groupIndex = MEDIA_CONTENT_GROUP_COMPOSER;
1209 __inputExpr = "MEDIA_COMPOSER IS NOT NULL";
1211 case 19://"Album", "MEDIA_ALBUM"
1212 __inputExpr = "MEDIA_ALBUM IS NOT NULL";
1220 // Fills given column value list and destroys filter handle
1222 _ContentSearchImpl::FillColumnsList(int colIndex) const
1224 result r = E_SUCCESS;
1225 int ret = MEDIA_CONTENT_ERROR_NONE;
1227 media_group_e groupIndex = GetIndexAndCreateQueryExp(colIndex);
1229 r = CreateQueryFilter(true);
1230 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "CreateQueryFilter Failed.");
1232 if (colIndex == ALBUM_COLUMN_NUM)
1234 ret = media_album_get_album_count_from_db(__pFilterHandle.get(), &totalCount);
1238 ret = media_group_get_group_count_from_db(__pFilterHandle.get(), groupIndex, &totalCount);
1240 r = MapCoreErrorToNativeResult(ret);
1241 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, r, "Failed to perform media_album/group count_from_db operation.");
1243 SysLog(NID_CNT, "totalCount = %d for media_album/group count_from_db", totalCount);
1247 if (colIndex == ALBUM_COLUMN_NUM)
1249 r = ExecuteAndFillAlbumValues();
1250 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "ExecuteAndFillAlbumValues Failed.");
1254 r = ExecuteAndFillGetValueListN(groupIndex, colIndex);
1255 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "ExecuteAndFillGetValueListN Failed.");
1261 // prepares input expression to be sent for create filter and fills given column value list
1263 _ContentSearchImpl::FillColumnsList(int pageNo, int countPerPage, int& totalPageCount, int& totalCount, int colIndex) const
1265 result r = E_SUCCESS;
1266 int ret = MEDIA_CONTENT_ERROR_NONE;
1270 media_group_e groupIndex = GetIndexAndCreateQueryExp(colIndex);
1272 r = CreateQueryFilter(true);
1273 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "CreateQueryFilter Failed.");
1275 if (colIndex == ALBUM_COLUMN_NUM)
1277 ret = media_album_get_album_count_from_db(__pFilterHandle.get(), &totalCount);
1281 ret = media_group_get_group_count_from_db(__pFilterHandle.get(), groupIndex, &totalCount);
1283 r = MapCoreErrorToNativeResult(ret);
1284 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, r, "Failed to perform media_album/group count_from_db operation.");
1286 SysLog(NID_CNT, "totalCount = %d for media_album/group count_from_db", totalCount);
1290 if ((totalCount % countPerPage) == 0)
1292 totalPageCount = totalCount / countPerPage;
1296 totalPageCount = (totalCount / countPerPage) + 1;
1299 SysTryReturnResult(NID_CNT, ((pageNo >= 1) && (pageNo <= totalPageCount)), E_INVALID_ARG,
1300 "Failed to perform FillColumnsList operation. pageNo : %d, totalPageCount : %d.", pageNo, totalPageCount);
1302 offset = (pageNo * countPerPage) - countPerPage;
1304 SysLog(NID_CNT, "GetValueListN totalCount [%d] totalPageCount[%d] __countPerPage[%d] __pageNo[%d] offset[%d]",
1305 totalCount, totalPageCount, countPerPage, pageNo, offset);
1307 ret = media_filter_set_offset(__pFilterHandle.get(),offset,countPerPage);
1308 r = MapCoreErrorToNativeResult(ret);
1309 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, r, "failed to perform media_filter_set_offset operation.");
1311 if (colIndex == ALBUM_COLUMN_NUM)
1313 r = ExecuteAndFillAlbumValues();
1314 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "ExecuteAndFillAlbumValues Failed.");
1318 r = ExecuteAndFillGetValueListN(groupIndex, colIndex);
1319 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "ExecuteAndFillGetValueListN Failed.");
1323 else if (pageNo > 1)
1325 SysLogException(NID_CNT, r = E_INVALID_ARG, "[%s] (pageNo > 1) and (totalcount = 0).", GetErrorMessage(E_INVALID_ARG));
1331 // fills given column value list for GetValuelistN api
1333 _ContentSearchImpl::ExecuteAndFillGetValueListN(media_group_e groupIndex, int colIndex) const
1335 SysLog(NID_CNT, "Enter\n");
1337 int ret = MEDIA_CONTENT_ERROR_NONE;
1338 result r = E_SUCCESS;
1339 result res = E_SUCCESS;
1340 std::unique_ptr<GList, SearchGListDeleter> pItemList;
1341 GList* pTemp = NULL;
1343 std::unique_ptr<Object> pValue;
1347 long long contentSize = 0;
1348 long long addedTime = 0;
1351 char *pColumnVal = null;
1352 int contentType = 0;
1354 pTemp = pItemList.get();
1356 ret = media_group_foreach_group_from_db(__pFilterHandle.get(), groupIndex, GroupItemCb, &pTemp);
1357 r = MapCoreErrorToNativeResult(ret);
1358 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform media_group_foreach_group_from_db operation.");
1360 SysTryReturnResult(NID_CNT, pTemp != NULL, r, "media_info_foreach_media_from_db pTemp is null.");
1362 for (int idx = 0; idx < (int)g_list_length(pTemp); idx++)
1364 SysLog(NID_CNT, "idx = %d and (int)g_list_length(pItemList) = %d", idx, (int)g_list_length(pTemp));
1366 pColumnVal = (char *)g_list_nth_data(pTemp, idx);
1368 String strColVal(pColumnVal);
1370 _ContentUtility::DoSafeFree(pColumnVal);
1372 SysLog(NID_CNT, "pColumnVal = %ls", strColVal.GetPointer());
1376 case 0://"ContentType", "MEDIA_TYPE"
1377 if ((strColVal.CompareTo(L"Unknown") != 0) && (!strColVal.IsEmpty()))
1379 res = Integer::Parse(strColVal, contentType);
1380 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] Integer parse failed.", GetErrorMessage(res));
1382 switch ((media_content_type_e)contentType)
1384 case MEDIA_CONTENT_TYPE_OTHERS:
1385 pValue.reset(new (std::nothrow) String(CONTENT_TYPE_OTHER));
1386 SysLog(NID_CNT, "mediaType = CONTENT_TYPE_OTHER");
1388 case MEDIA_CONTENT_TYPE_IMAGE:
1389 pValue.reset(new (std::nothrow) String(CONTENT_TYPE_IMAGE));
1390 SysLog(NID_CNT, "mediaType = CONTENT_TYPE_IMAGE");
1392 case MEDIA_CONTENT_TYPE_SOUND:
1394 case MEDIA_CONTENT_TYPE_MUSIC:
1395 pValue.reset(new (std::nothrow) String(CONTENT_TYPE_AUDIO));
1396 SysLog(NID_CNT, "mediaType = CONTENT_TYPE_AUDIO");
1398 case MEDIA_CONTENT_TYPE_VIDEO:
1399 pValue.reset(new (std::nothrow) String(CONTENT_TYPE_VIDEO));
1400 SysLog(NID_CNT, "mediaType = CONTENT_TYPE_VIDEO");
1406 case 1://"ContentFileName", "MEDIA_DISPLAY_NAME"
1408 case 2://"ContentName", "MEDIA_CONTENT_NAME"
1410 case 3://"Category", "MEDIA_CATEGORY"
1412 case 4://"Author", "MEDIA_AUTHOR"
1414 case 5://"keyword", "MEDIA_KEYWORD"
1416 case 6://"Provider", "MEDIA_PROVIDER"
1418 case 7://"Rating", "MEDIA_AGE_RATING"
1420 case 8://"LocationTag", "MEDIA_LOCATION_TAG"
1422 case 14://"Title", "MEDIA_TITLE"
1424 case 15://"Artist", "MEDIA_ARTIST"
1426 case 16://"Genre", "MEDIA_GENRE"
1428 case 17://"Year", "MEDIA_YEAR"
1430 case 18://"Composer", "MEDIA_COMPOSER"
1432 pValue.reset(new (std::nothrow) String(strColVal));
1435 case 9://"ContentSize", "MEDIA_SIZE"
1436 if ((strColVal.CompareTo(L"Unknown") != 0) && (!strColVal.IsEmpty()))
1438 res = LongLong::Parse(strColVal, contentSize);
1439 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] LongLong parse failed.", GetErrorMessage(res));
1442 pValue.reset(new (std::nothrow) LongLong(contentSize));
1444 case 10://"DateTime", "MEDIA_ADDED_TIME"
1445 if ((strColVal.CompareTo(L"Unknown") != 0) && (!strColVal.IsEmpty()))
1447 res = LongLong::Parse(strColVal, addedTime);
1448 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] LongLong parse failed.", GetErrorMessage(res));
1451 res = dateTime.SetValue(1970, 1, 1);
1452 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] dateTime.SetValue failed.", GetErrorMessage(res));
1454 res = dateTime.AddSeconds(addedTime);
1455 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] dateTime.AddSeconds failed.", GetErrorMessage(res));
1457 SysLog(NID_CNT, "DateTime : %ls", dateTime.ToString().GetPointer());
1459 pValue.reset(new (std::nothrow) DateTime(dateTime));
1462 case 11://"Latitude", "MEDIA_LATITUDE"
1464 case 12://"Longitude", "MEDIA_LONGITUDE"
1466 case 13://"Altitude", "MEDIA_ALTITUDE"
1467 if ((strColVal.CompareTo(L"Unknown") != 0) && (!strColVal.IsEmpty()))
1469 dVal = _LocalizedNumParser::ToDouble(strColVal, "C");
1470 r = GetLastResult();
1471 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform ToDouble operation.");
1473 pValue.reset(new (std::nothrow) Double(dVal));
1476 case 19://"Album", "MEDIA_ALBUM"
1481 if (pValue.get() != NULL)
1483 r = __pFinalOutList->Add(*(pValue.release()));
1484 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform arraylist Add operation.");
1492 _ContentSearchImpl::ExecuteAndFillAlbumValues(void) const
1494 int ret = MEDIA_CONTENT_ERROR_NONE;
1495 result r = E_SUCCESS;
1496 std::unique_ptr<GList, SearchGListDeleter> pItemList;
1497 GList* pTemp = NULL;
1498 std::unique_ptr<media_album_s, AlbumHandleDeleter> pAlbumHandle;
1499 std::unique_ptr<media_album_s, AlbumHandleDeleter> pTempAlbumHandle;
1502 std::unique_ptr<char, CharDeleter> pAlbumName;
1503 std::unique_ptr< String > pValue;
1506 pTemp = pItemList.get();
1508 ret = media_album_foreach_album_from_db(__pFilterHandle.get(), AlbumItemCb, &pTemp);
1509 r = MapCoreErrorToNativeResult(ret);
1510 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform media_album_foreach_album_from_db operation.");
1511 SysTryReturnResult(NID_CNT, pTemp != NULL, r, "media_info_foreach_media_from_db pTemp is null.");
1513 for (int idx = 0; idx < (int)g_list_length(pTemp); idx++)
1515 pAlbumHandle.reset(static_cast<media_album_h>(g_list_nth_data(pTemp, idx)));
1516 ret = media_album_get_name(pAlbumHandle.get(), &pName);
1517 r = MapCoreErrorToNativeResult(ret);
1518 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform media_album_get_name.");
1522 SysLog(NID_CNT, "pColumnVal = %s", pName);
1524 pAlbumName.reset(pName);
1525 pValue.reset(new (std::nothrow) String(pAlbumName.get()));
1526 SysTryReturnResult(NID_CNT, pValue != NULL, E_OUT_OF_MEMORY, "media_info_foreach_media_from_db pTemp is null.");
1530 r = __pFinalOutList->Add(pValue.get());
1531 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform arraylist Add operation.");
1536 String* pTempNameList(static_cast< String* >(__pFinalOutList->GetAt(lastIndex)));
1538 if (pValue->CompareTo(*pTempNameList) != 0)
1540 r = __pFinalOutList->Add(pValue.get());
1541 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform arraylist Add operation.");
1554 _ContentSearchImpl::MapCoreErrorToNativeResult(int reason) const
1556 result r = E_SUCCESS;
1560 case MEDIA_CONTENT_ERROR_NONE:
1564 case MEDIA_CONTENT_ERROR_INVALID_PARAMETER:
1566 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_INVALID_PARAMETER");
1569 case MEDIA_CONTENT_ERROR_DB_FAILED:
1571 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_DB_FAILED");
1574 case MEDIA_CONTENT_ERROR_OUT_OF_MEMORY:
1575 r = E_OUT_OF_MEMORY;
1576 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_OUT_OF_MEMORY");
1580 SysLog(NID_CNT, "default");
1588 _ContentSearchImpl::ConvertErrorToResult(result res) const
1590 result r = E_SUCCESS;
1594 case E_FILE_NOT_FOUND:
1595 // It is processed by normal case when the content exist in DB but the actual file doesn't exist.
1610 // Callback function registered to each media info details
1611 // all items are appended to the list
1613 MediaItemCb(media_info_h media, void* pUserdata)
1615 int ret = MEDIA_CONTENT_ERROR_NONE;
1616 media_info_h new_media = NULL;
1617 ret = media_info_clone(&new_media, media);
1618 SysTryLog(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, "[E_SYSTEM] Failed to perform media_info_clone");
1620 GList** pList = (GList**)pUserdata;
1621 *pList = g_list_append(*pList, new_media);
1626 // Callback function registered for column values
1627 // all items are appended to the list
1629 GroupItemCb(const char* pGroupName, void* pUserdata)
1631 char* pGrpName = strdup(pGroupName);
1632 GList** pList = (GList**)pUserdata;
1633 *pList = g_list_append(*pList, pGrpName);
1638 // Callback function registered to each media info details
1639 // all items are appended to the list
1641 AlbumItemCb(media_album_h album, void* pUserdata)
1643 int ret = MEDIA_CONTENT_ERROR_NONE;
1644 media_album_h new_album = NULL;
1645 ret = media_album_clone(&new_album, album);
1646 SysTryLog(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, "[E_SYSTEM] Failed to perform media_album_clone");
1648 GList** pList = (GList**)pUserdata;
1649 *pList = g_list_append(*pList, new_album);