merge with master
[platform/framework/native/content.git] / src / inc / FCnt_ContentDirectoryImpl.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_ContentDirectoryImpl.h
19  * @brief               This is the header file for the %_ContentDirectoryImpl class.
20  *
21  * This header file contains the declarations of the %_ContentDirectoryImpl class.
22  */
23
24 #ifndef _FCNT_INTERNAL_CONTENT_DIRECTORY_IMPL_H_
25 #define _FCNT_INTERNAL_CONTENT_DIRECTORY_IMPL_H_
26
27 #include <glib.h>
28 #include <unique_ptr.h>
29 #include <media_content.h>
30 #include <FBaseColIListT.h>
31 #include <FBaseColAllElementsDeleter.h>
32
33 namespace Tizen { namespace Content
34 {
35         static const int MAX_FIELD_LENGTH  = 32;
36         static const int MAX_QUERY_COLUMNS = 23;
37         static const int MAX_QUERY_COLUMNS_FOR_IMAGE_OTHERS = 14;
38         static const int MAX_QUERY_COLUMNS_FOR_VIDEO = 21;
39         static const int ALBUM_COLUMN_NUM = 22;
40
41         typedef struct
42         {
43                 char            dbFieldOspName[MAX_FIELD_LENGTH];
44                 char            dbFieldSlpName[MAX_FIELD_LENGTH];
45         }DatabaseFieldInfo;
46
47         const static DatabaseFieldInfo dbfieldinfo[MAX_QUERY_COLUMNS] =
48         {
49                 //for all types 0 -13
50                 {"ContentType", "MEDIA_TYPE"},
51                 {"ContentFileName", "MEDIA_DISPLAY_NAME"},
52                 {"ContentName", "MEDIA_CONTENT_NAME"},
53                 {"Category", "MEDIA_CATEGORY"},
54                 {"Author", "MEDIA_AUTHOR"},
55                 {"keyword", "MEDIA_KEYWORD"},
56                 {"Provider", "MEDIA_PROVIDER"},
57                 {"Rating", "MEDIA_AGE_RATING"},
58                 {"LocationTag", "MEDIA_LOCATION_TAG"},
59                 {"ContentSize", "MEDIA_SIZE"},
60                 {"DateTime", "MEDIA_ADDED_TIME"},
61                 {"Latitude", "MEDIA_LATITUDE"},
62                 {"Longitude", "MEDIA_LONGITUDE"},
63                 {"Altitude", "MEDIA_ALTITUDE"},
64                 //  for audio and video type 14 - 20
65                 {"Title", "MEDIA_TITLE"},
66                 {"Artist", "MEDIA_ARTIST"},
67                 {"Genre", "MEDIA_GENRE"},
68                 {"Year", "MEDIA_YEAR"},
69                 {"MostPlayed", "MEDIA_PLAYED_COUNT"},
70                 {"RecentlyAdded", "MEDIA_ADDED_TIME"},
71                 {"RecentlyPlayed", "MEDIA_LAST_PLAYED_TIME"},
72                 // for audio type 21 - 22
73                 {"Composer", "MEDIA_COMPOSER"},
74                 {"Album", "MEDIA_ALBUM"}
75         };
76
77 class ContentSearchResult;
78 class ContentDirectory;
79
80 struct GListDeleter
81 {
82         void operator()(GList* pGList)
83         {
84                 g_list_free(pGList);
85                 pGList = NULL;
86         }
87 };
88
89 struct FolderHandleDeleter
90 {
91         void operator()(media_folder_h folderHandle)
92         {
93                 media_folder_destroy(folderHandle);
94                 folderHandle = NULL;
95         }
96 };
97
98 struct MediaHandleDeleter
99 {
100         void operator()(media_info_h mediaHandle)
101         {
102                 media_info_destroy(mediaHandle);
103                 mediaHandle = NULL;
104         }
105 };
106
107 struct FilterHandleDeleter
108 {
109         void operator()(filter_h* pFilterHandle)
110         {
111                 media_filter_destroy(*pFilterHandle);
112         }
113 };
114
115 class _ContentDirectoryImpl
116         : public Tizen::Base::Object
117 {
118 public:
119
120         /**
121          * This is the default constructor for this class.
122          *
123          * @since 2.1
124          */
125         _ContentDirectoryImpl(void);
126
127         /**
128          * This is the destructor for this class.
129          *
130          * @since 2.1
131          */
132         virtual ~_ContentDirectoryImpl(void);
133
134         /**
135          * @see @ref Tizen::Content::ContentDirectory::Construct()
136          */
137         result Construct(ContentType type);
138
139         /**
140          * @see @ref Tizen::Content::ContentDirectory::Construct()
141          */
142         result Construct(const Tizen::Base::Collection::IListT<ContentType>& contentTypeList);
143
144         /**
145          * @see @ref Tizen::Content::ContentDirectory::GetContentDirectoryCount()
146          */
147         int GetContentDirectoryCount(void) const;
148
149         /**
150          * @see @ref Tizen::Content::ContentDirectory::GetContentDirectoryPathListN()
151          */
152         Tizen::Base::Collection::IList* GetContentDirectoryPathListN(Tizen::Base::SortOrder sortOrder) const;
153
154         /**
155          * @see @ref Tizen::Content::ContentDirectory::GetContentDirectoryItemCount()
156          */
157         int GetContentDirectoryItemCount(const Tizen::Base::String& contentDirectoryPath) const;
158
159         /**
160          * @see @ref Tizen::Content::ContentDirectory::GetContentDirectoryItemListN()
161          */
162         Tizen::Base::Collection::IList* GetContentDirectoryItemListN(const Tizen::Base::String& contentDirectoryPath, int pageNo, int countPerPage,
163                                                     const Tizen::Base::String& column, Tizen::Base::SortOrder sortOrder) const;
164
165         static _ContentDirectoryImpl* GetInstance(ContentDirectory& contentDirectory);
166
167         static const _ContentDirectoryImpl* GetInstance(const ContentDirectory& contentDirectory);
168
169 private:
170         _ContentDirectoryImpl(const _ContentDirectoryImpl& rhs);
171         _ContentDirectoryImpl& operator =(const _ContentDirectoryImpl& rhs);
172
173         result CreateFolderFilter(bool isMultiContentType, const Tizen::Base::String& folderPath) const;
174         result FillFinalOutList(char* pFolderId) const;
175         result GetSlpColumnName(Tizen::Base::String& inputCol, Tizen::Base::String sortCol) const;
176         result MapCoreErrorToNativeResult(int reason) const;
177         bool CheckMediaPath(const Tizen::Base::String& directoryPath) const;
178
179         mutable std::unique_ptr<filter_h, FilterHandleDeleter> __pFilterHandle;
180         mutable std::unique_ptr<Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter> __pFinalOutList;
181         ContentType     __contentType;
182         bool __isMultiContentType;
183         Tizen::Base::String __multiContentTypeExpr;
184
185
186 };      // class _ContentDirectoryImpl
187
188 }}      // Tizen::Content
189
190 #endif  // _FCNT_INTERNAL_CONTENT_DIRECTORY_IMPL_H_