merge with master
[platform/framework/native/content.git] / src / inc / FCnt_ContentSearchImpl.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file                FCnt_ContentSearchImpl.h
19  * @brief               This is the header file for the %_ContentSearchImpl class.
20  *
21  * This header file contains the declarations of the %_ContentSearchImpl class.
22  */
23
24 #ifndef _FCNT_INTERNAL_CONTENT_SEARCH_IMPL_H_
25 #define _FCNT_INTERNAL_CONTENT_SEARCH_IMPL_H_
26
27 #include <glib.h>
28 #include <unique_ptr.h>
29 #include <FBaseColAllElementsDeleter.h>
30 #include <media_content.h>
31
32 namespace Tizen { namespace Content
33 {
34         static const int MAX_FIELD_LENGTH  = 32;
35         static const int MAX_QUERY_COLUMNS = 20;
36         static const int MAX_QUERY_COLUMNS_FOR_IMAGE_OTHERS = 14;
37         static const int MAX_QUERY_COLUMNS_FOR_VIDEO = 18;
38         static const int ALBUM_COLUMN_NUM = 19;
39
40         typedef struct
41         {
42                 char            dbFieldOspName[MAX_FIELD_LENGTH];
43                 char            dbFieldSlpName[MAX_FIELD_LENGTH];
44         }DatabaseFieldInfo;
45
46         const static DatabaseFieldInfo dbfieldinfo[MAX_QUERY_COLUMNS] =
47         {
48                 //for all types 0 -13
49                 {"ContentType", "MEDIA_TYPE"},
50                 {"ContentFileName", "MEDIA_DISPLAY_NAME"},
51                 {"ContentName", "MEDIA_CONTENT_NAME"},
52                 {"Category", "MEDIA_CATEGORY"},
53                 {"Author", "MEDIA_AUTHOR"},
54                 {"keyword", "MEDIA_KEYWORD"},
55                 {"Provider", "MEDIA_PROVIDER"},
56                 {"Rating", "MEDIA_AGE_RATING"},
57                 {"LocationTag", "MEDIA_LOCATION_TAG"},
58                 {"ContentSize", "MEDIA_SIZE"},
59                 {"DateTime", "MEDIA_ADDED_TIME"},
60                 {"Latitude", "MEDIA_LATITUDE"},
61                 {"Longitude", "MEDIA_LONGITUDE"},
62                 {"Altitude", "MEDIA_ALTITUDE"},
63                 //  for audio and video type 14 - 17
64                 {"Title", "MEDIA_TITLE"},
65                 {"Artist", "MEDIA_ARTIST"},
66                 {"Genre", "MEDIA_GENRE"},
67                 {"Year", "MEDIA_YEAR"},
68                 // for audio type 18 - 19
69                 {"Composer", "MEDIA_COMPOSER"},
70                 {"Album", "MEDIA_ALBUM"}
71         };
72
73 // forward declaration
74 class ContentSearchResult;
75 class ContentSearch;
76
77 struct SearchMediaHandleDeleter
78 {
79         void operator()(media_info_h mediaHandle)
80         {
81                 media_info_destroy(mediaHandle);
82                 mediaHandle = NULL;
83         }
84 };
85
86 struct SearchGListDeleter
87 {
88         void operator()(GList* pGList)
89         {
90                 g_list_free(pGList);
91                 pGList = NULL;
92         }
93 };
94
95 struct SearchFilterHandleDeleter
96 {
97         void operator()(filter_h* pFilterHandle)
98         {
99                 media_filter_destroy(*pFilterHandle);
100         }
101 };
102 struct AlbumHandleDeleter
103 {
104         void operator()(media_album_h albumHandle)
105         {
106                 media_album_destroy(albumHandle);
107                 albumHandle = NULL;
108         }
109 };
110 struct CharDeleter
111 {
112         void operator()(char* pChar)
113         {
114                 free(pChar);
115                 pChar = null;
116         }
117 };
118
119 class _ContentSearchImpl
120         : public Tizen::Base::Object
121 {
122 public:
123
124         /**
125          * This is the default constructor for this class.
126          *
127          * @since 2.1
128          */
129         _ContentSearchImpl(void);
130
131         /**
132          * This is the destructor for this class.
133          *
134          * @since 2.1
135          */
136         virtual ~_ContentSearchImpl(void);
137
138         /**
139          * @see @ref Tizen::Content::ContentSearch::Construct()
140          */
141         result Construct(ContentType type);
142
143         /**
144          * @see @ref Tizen::Content::ContentSearch::SearchN()
145          */
146         Tizen::Base::Collection::IList* SearchN(int pageNo, int countPerPage, int& totalPageCount, int& totalCount,
147 const Tizen::Base::String& whereExpr, const Tizen::Base::String& sortColumn, Tizen::Base::SortOrder sortOrder) const;
148
149         Tizen::Base::Collection::IList* GetValueListN(const Tizen::Base::String& sortColumn, Tizen::Base::SortOrder sortOrder);
150
151         /**
152          * @see @ref Tizen::Content::ContentManager::GetValueListN()
153          */
154         Tizen::Base::Collection::IList* GetValueListN(int pageNo, int countPerPage, int& totalPageCount, int& totalCount,
155 const Tizen::Base::String& sortColumn, Tizen::Base::SortOrder sortOrder) const;
156
157         static _ContentSearchImpl* GetInstance(ContentSearch& contentSearch);
158
159         static const _ContentSearchImpl* GetInstance(const ContentSearch& contentSearch);
160
161 private:
162         _ContentSearchImpl(const _ContentSearchImpl& rhs);
163         _ContentSearchImpl& operator =(const _ContentSearchImpl& rhs);
164
165         result ReplaceString(Tizen::Base::String ospColumnName, Tizen::Base::String slpColumnName) const;
166         result ReplaceOspColumnNameWithSlp(void) const;
167
168         result CreateQueryFilter(bool isAndAppendReq) const;
169
170         result GetSlpColumnName(Tizen::Base::String& inputCol) const;
171
172         result ExecuteAndFillFinalOutList(void) const;
173
174         result ExecuteAndFillGetValueListN(media_group_e groupIndex, int colIndex) const;
175
176         result FillColumnsList(int pageNo, int countPerPage, int& totalPageCount, int& totalCount, int colIndex) const;
177         result FillColumnsList(int colIndex) const;
178
179         result CheckInvalidColumnInQuery(void) const;
180
181         media_group_e GetIndexAndCreateQueryExp(int colIndex) const;
182
183         result AppendEscapeKeywordForLikeQuery(void) const;
184
185         result ReplaceDateTimeStringWithInt(void) const;
186
187         result ExecuteAndFillAlbumValues(void) const;
188
189         result MapCoreErrorToNativeResult(int reason) const;
190
191         ContentType                                                     __contentType;
192         mutable std::unique_ptr<Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter> __pFinalOutList;
193         mutable Tizen::Base::String                                     __inputExpr;
194         mutable Tizen::Base::String                                     __inputColumnName;
195         mutable Tizen::Base::SortOrder                                  __inputSortOrder;
196         mutable std::unique_ptr<filter_h, SearchFilterHandleDeleter>    __pFilterHandle;
197
198 };      // class _ContentSearchImpl
199
200 }}      // Tizen::Content
201
202 #endif  // _FCNT_INTERNAL_CONTENT_SEARCH_IMPL_H_