3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
\r
5 // Licensed under the Flora License, Version 1.0 (the License);
\r
6 // you may not use this file except in compliance with the License.
\r
7 // You may obtain a copy of the License at
\r
9 // http://www.tizenopensource.org/license
\r
11 // Unless required by applicable law or agreed to in writing, software
\r
12 // distributed under the License is distributed on an AS IS BASIS,
\r
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
14 // See the License for the specific language governing permissions and
\r
15 // limitations under the License.
\r
18 #include "ContentSearchSampleImpl.h"
\r
20 using namespace Osp::Base;
\r
21 using namespace Osp::Base::Collection;
\r
22 using namespace Osp::App;
\r
23 using namespace Osp::Content;
\r
25 static const int MAX_CONTENTSEARCH_COUNTPERPAGE = 100;
\r
26 static const int STRING_CAPACITY = 1024;
\r
28 ContentSearchSampleImpl::ContentSearchSampleImpl(void)
\r
29 : __contentType(CONTENT_TYPE_ALL)
\r
30 , __pSearchResultList(null)
\r
34 ContentSearchSampleImpl::~ContentSearchSampleImpl(void)
\r
40 ContentSearchSampleImpl::initResultList(void)
\r
42 if (__pSearchResultList != null)
\r
44 __pSearchResultList->RemoveAll(true);
\r
45 delete __pSearchResultList;
\r
46 __pSearchResultList = null;
\r
51 ContentSearchSampleImpl::makeQuery(const String& queryString)
\r
56 strTemp = queryString;
\r
57 // set capacity for query string
\r
58 strQuery.SetCapacity(STRING_CAPACITY);
\r
59 strTemp.SetCapacity(STRING_CAPACITY);
\r
61 // get query string from EditBox
\r
62 if (!strTemp.IsEmpty())
\r
64 strQuery.Append(L"ContentFileName");
\r
65 strQuery.Append(L" LIKE '%");
\r
67 // convert special character for like query
\r
68 strTemp.Replace(L"\\", L"\\\\");
\r
69 strTemp.Replace(L"_", L"\\_");
\r
70 strTemp.Replace(L"%", L"\\%");
\r
71 strTemp.Replace(L"'", L"\\'");
\r
73 strQuery.Append(strTemp);
\r
74 strQuery.Append(L"%'");
\r
81 ContentSearchSampleImpl::SearchContent(ContentType contentType, const String& query)
\r
83 result r = E_SUCCESS;
\r
84 ContentSearch contentSearch;
\r
85 String sortColumn = L"";
\r
91 // Clear the previous result
\r
94 __contentType = contentType;
\r
95 __queryString = query;
\r
97 r = contentSearch.Construct(__contentType);
\r
98 TryReturn(E_SUCCESS == r, r, "Construct() failed by %s.", GetErrorMessage(r));
\r
100 strQuery = makeQuery(query);
\r
103 __pSearchResultList = contentSearch.SearchN(page, MAX_CONTENTSEARCH_COUNTPERPAGE, totalPage, totalCount, strQuery, sortColumn, SORT_ORDER_NONE);
\r
104 r = GetLastResult();
\r
105 TryReturn(__pSearchResultList != null, r, "ContentSearch.SearchN() failed by %s.", GetErrorMessage(r));
\r
109 ContentSearchSampleImpl::RefreshSearchContent(void)
\r
111 return SearchContent(__contentType, __queryString);
\r
115 ContentSearchSampleImpl::GetSearchResultCount() const
\r
119 if (__pSearchResultList != null)
\r
121 count = __pSearchResultList->GetCount();
\r
128 ContentSearchSampleImpl::GetContentFileName(int index) const
\r
130 String contentFullPath;
\r
131 String contentFileName;
\r
132 String delimeter = L"/";
\r
133 int filenamePos = 0;
\r
134 ContentSearchResult* pInfo = null;
\r
135 result r = E_SUCCESS;
\r
137 contentFileName.Clear();
\r
139 TryReturn(__pSearchResultList != null, contentFileName, "No search result");
\r
141 pInfo = (ContentSearchResult*)__pSearchResultList->GetAt(index);
\r
142 contentFullPath = ((ContentInfo*)pInfo->GetContentInfo())->GetContentPath();
\r
143 if (contentFullPath.IsEmpty() == false)
\r
145 // eliminate a directory name from the ContentPath
\r
146 r = contentFullPath.LastIndexOf(delimeter, contentFullPath.GetLength() - 1, filenamePos);
\r
147 if (r == E_SUCCESS && filenamePos > 0)
\r
149 r = contentFullPath.SubString(filenamePos + 1, contentFileName);
\r
150 if (r != E_SUCCESS)
\r
152 contentFileName = contentFullPath;
\r
157 contentFileName = contentFullPath;
\r
161 return contentFileName;
\r
164 ContentSearchResult*
\r
165 ContentSearchSampleImpl::GetSearchResultItem(int index) const
\r
167 ContentSearchResult* pSearchItem = null;
\r
169 if (__pSearchResultList)
\r
171 pSearchItem = (ContentSearchResult*)__pSearchResultList->GetAt(index);
\r
174 return pSearchItem;
\r