[content] Fix compat TC fails
[platform/framework/native/content.git] / src / FCnt_ContentSearchImpl.cpp
index 0edb6ce..82e616d 100644 (file)
 #include <FBaseUtilStringTokenizer.h>
 #include <FCntContentSearch.h>
 #include <FCntContentSearchResult.h>
+#include <FSysEnvironment.h>
+#include <FApp_AppInfo.h>
 #include <FBase_StringConverter.h>
 #include <FBase_LocalizedNumParser.h>
+#include <FIo_FileImpl.h>
 #include "FCnt_ContentUtility.h"
 #include "FCnt_ContentSearchImpl.h"
 #include "FCnt_ContentInfoImpl.h"
 #include "FCnt_OtherContentInfoImpl.h"
 #include "FCnt_ContentInfoHelper.h"
 
+using namespace Tizen::App;
 using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
 using namespace Tizen::Base::Utility;
 using namespace Tizen::Io;
+using namespace Tizen::System;
 
 namespace Tizen { namespace Content
 {
@@ -284,7 +289,7 @@ _ContentSearchImpl::ReplaceOspColumnNameWithSlp(void) const
        int             maxCols = 0;
 
        int indexOf = 0;
-       
+
        String strToBeReplaced(L"\\'");
        int strLen = strToBeReplaced.GetLength();
        int startIndex = 0;
@@ -496,12 +501,12 @@ _ContentSearchImpl::ReplaceDateTimeStringWithInt(void) const
                                SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to parse DateTime.");
 
                                int year = dt.GetYear();
-                               int month = dt.GetMonth(); 
+                               int month = dt.GetMonth();
                                int day = dt.GetDay();
                                int hour = dt.GetHour();
-                               int minute = dt.GetMinute(); 
+                               int minute = dt.GetMinute();
                                int second = dt.GetSecond();
-                               
+
                                time_t rawTime;
                                struct tm* timeInfo;
 
@@ -806,6 +811,15 @@ _ContentSearchImpl::ExecuteAndFillFinalOutList(void) const
 
                pMediaPath.reset(pTempPath);
                String contentPath(pMediaPath.get());
+               String changedPath(contentPath);
+
+               // If the api version is 2.0, the content path has to be changed.
+               if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
+               {
+                       r = _FileImpl::ConvertPhysicalToVirtualPath(contentPath, changedPath);
+                       SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG,
+                                       "[%s] Failed to convert physical path to virtual path.", GetErrorMessage(E_INVALID_ARG));
+               }
 
                switch (mediaType)
                {
@@ -813,7 +827,7 @@ _ContentSearchImpl::ExecuteAndFillFinalOutList(void) const
                        pOtherContentInfo = std::unique_ptr<OtherContentInfo>(new (std::nothrow) OtherContentInfo);
                        SysTryReturnResult(NID_CNT, pOtherContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pOtherContentInfo.");
 
-                       r = pOtherContentInfo->Construct(&contentPath);
+                       r = pOtherContentInfo->Construct(&changedPath);
                        r = ConvertErrorToResult(r);
                        SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Construct operation to OtherContentInfo.");
 
@@ -841,7 +855,7 @@ _ContentSearchImpl::ExecuteAndFillFinalOutList(void) const
                        pImageContentInfo = std::unique_ptr<ImageContentInfo>(new (std::nothrow) ImageContentInfo);
                        SysTryReturnResult(NID_CNT, pImageContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pImageContentInfo.");
 
-                       r = pImageContentInfo->Construct(&contentPath);
+                       r = pImageContentInfo->Construct(&changedPath);
                        r = ConvertErrorToResult(r);
                        SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Construct operation to ImageContentInfo.");
 
@@ -874,7 +888,7 @@ _ContentSearchImpl::ExecuteAndFillFinalOutList(void) const
                        pAudioContentInfo = std::unique_ptr<AudioContentInfo>(new (std::nothrow) AudioContentInfo);
                        SysTryReturnResult(NID_CNT, pAudioContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pAudioContentInfo.");
 
-                       r = pAudioContentInfo->Construct(&contentPath);
+                       r = pAudioContentInfo->Construct(&changedPath);
                        r = ConvertErrorToResult(r);
                        SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Construct operation to AudioContentInfo.");
 
@@ -905,7 +919,7 @@ _ContentSearchImpl::ExecuteAndFillFinalOutList(void) const
                        pVideoContentInfo = std::unique_ptr<VideoContentInfo>(new (std::nothrow) VideoContentInfo);
                        SysTryReturnResult(NID_CNT, pVideoContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pVideoContentInfo.");
 
-                       r = pVideoContentInfo->Construct(&contentPath);
+                       r = pVideoContentInfo->Construct(&changedPath);
                        r = ConvertErrorToResult(r);
                        SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Construct operation to VideoContentInfo.");
 
@@ -1281,11 +1295,7 @@ _ContentSearchImpl::FillColumnsList(int pageNo, int countPerPage, int& totalPage
                        totalPageCount = (totalCount / countPerPage) + 1;
                }
 
-               if ((pageNo < 1) || (pageNo > totalPageCount))
-               {
-                       r = E_INVALID_ARG;
-                       SysTryReturnResult(NID_CNT, !IsFailed(r), r, "(pageNo < 1) || (pageNo > totalPageCount).");
-               }
+               SysTryReturnResult(NID_CNT, ((pageNo >= 1) && (pageNo <= totalPageCount)) , r, "(pageNo < 1) || (pageNo > totalPageCount).");
 
                offset = (pageNo * countPerPage) - countPerPage;