Fix : Search APIs don't return exception despite the content in DB doesn't match...
[platform/framework/native/content.git] / src / inc / FCnt_ContentDirectoryImpl.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16 /**
17  * @file                FCnt_ContentDirectoryImpl.h
18  * @brief               This is the header file for the %_ContentDirectoryImpl class.
19  *
20  * This header file contains the declarations of the %_ContentDirectoryImpl class.
21  */
22
23 #ifndef _FCNT_INTERNAL_CONTENT_DIRECTORY_IMPL_H_
24 #define _FCNT_INTERNAL_CONTENT_DIRECTORY_IMPL_H_
25
26 #include <glib.h>
27 #include <unique_ptr.h>
28 #include <media_content.h>
29 #include <FBaseColIListT.h>
30 #include <FBaseColAllElementsDeleter.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 class ContentSearchResult;
74 class ContentDirectory;
75
76 struct GListDeleter
77 {
78         void operator()(GList* pGList)
79         {
80                 g_list_free(pGList);
81         }
82 };
83
84 struct FolderHandleDeleter
85 {
86         void operator()(media_folder_h folderHandle)
87         {
88                 media_folder_destroy(folderHandle);
89         }
90 };
91
92 struct MediaHandleDeleter
93 {
94         void operator()(media_info_h mediaHandle)
95         {
96                 media_info_destroy(mediaHandle);
97         }
98 };
99
100 struct FilterHandleDeleter
101 {
102         void operator()(filter_h filterHandle)
103         {
104                 media_filter_destroy(filterHandle);
105         }
106 };
107
108 struct CharDeleter
109 {
110         void operator()(char* character)
111         {
112                 free(character);
113         }
114 };
115
116 class _ContentDirectoryImpl
117         : public Tizen::Base::Object
118 {
119 public:
120
121         /**
122          * This is the default constructor for this class.
123          *
124          * @since 2.1
125          */
126         _ContentDirectoryImpl(void);
127
128         /**
129          * This is the destructor for this class.
130          *
131          * @since 2.1
132          */
133         virtual ~_ContentDirectoryImpl(void);
134
135         /**
136          * @see @ref Tizen::Content::ContentDirectory::Construct()
137          */
138         result Construct(ContentType type);
139
140         /**
141          * @see @ref Tizen::Content::ContentDirectory::Construct()
142          */
143         result Construct(const Tizen::Base::Collection::IListT<ContentType>& contentTypeList);
144
145         /**
146          * @see @ref Tizen::Content::ContentDirectory::GetContentDirectoryCount()
147          */
148         int GetContentDirectoryCount(void) const;
149
150         /**
151          * @see @ref Tizen::Content::ContentDirectory::GetContentDirectoryPathListN()
152          */
153         Tizen::Base::Collection::IList* GetContentDirectoryPathListN(Tizen::Base::SortOrder sortOrder) const;
154
155         /**
156          * @see @ref Tizen::Content::ContentDirectory::GetContentDirectoryItemCount()
157          */
158         int GetContentDirectoryItemCount(const Tizen::Base::String& contentDirectoryPath) const;
159
160         /**
161          * @see @ref Tizen::Content::ContentDirectory::GetContentDirectoryItemListN()
162          */
163         Tizen::Base::Collection::IList* GetContentDirectoryItemListN(const Tizen::Base::String& contentDirectoryPath, int pageNo, int countPerPage,
164                                                     const Tizen::Base::String& column, Tizen::Base::SortOrder sortOrder) const;
165
166         static _ContentDirectoryImpl* GetInstance(ContentDirectory& contentDirectory);
167
168         static const _ContentDirectoryImpl* GetInstance(const ContentDirectory& contentDirectory);
169
170 private:
171         _ContentDirectoryImpl(const _ContentDirectoryImpl& rhs);
172         _ContentDirectoryImpl& operator =(const _ContentDirectoryImpl& rhs);
173
174         result CreateFolderFilter(bool isMultiContentType, const Tizen::Base::String& folderPath) const;
175         result FillFinalOutList(char* pFolderId) const;
176         result GetSlpColumnName(Tizen::Base::String& inputCol, Tizen::Base::String sortCol) const;
177         result MapCoreErrorToNativeResult(int reason) const;
178         result MapCoreErrorToDirectoryCountNativeResult(int reason) const;
179         result ConvertErrorToResult(result res) const;
180         bool CheckMediaPath(const Tizen::Base::String& directoryPath) const;
181
182         mutable std::unique_ptr<filter_s, FilterHandleDeleter> __pFilterHandle;
183         mutable std::unique_ptr<Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter> __pFinalOutList;
184         ContentType     __contentType;
185         bool __isMultiContentType;
186         Tizen::Base::String __multiContentTypeExpr;
187
188
189 };      // class _ContentDirectoryImpl
190
191 }}      // Tizen::Content
192
193 #endif  // _FCNT_INTERNAL_CONTENT_DIRECTORY_IMPL_H_