2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 using System.Runtime.InteropServices;
21 namespace Tizen.Content.MediaContent
24 /// The Content Filter API provides functions to manage media filters.
27 /// A Content filter is required for filtering information associated with Media Folder, Tag, Audio, MediaBookmark and Media Information on basis of details like offset, count, order and condition for searching.
28 /// It provide functionality to set properties associated with a given content filter.
29 /// Setting content filter properties helps to limit the number of filtered items as following:
31 /// <item><description>
32 /// Offset - Used to set starting position of the filter's search
33 /// </description></item>
34 /// <item><description>
35 /// Count - Used to set number of items to be searched from offset
36 /// </description></item>
37 /// <item><description>
38 /// Condition - Used to set keyword which user want to search
39 /// </description></item>
40 /// <item><description>
41 /// Order - Used to set type of media to be ordered by the filter
42 /// </description></item>
44 /// Searchable expression can use one of the following forms:
46 /// <item><description>
48 /// </description></item>
49 /// <item><description>
51 /// </description></item>
52 /// <item><description>
54 /// </description></item>
55 /// <item><description>
57 /// </description></item>
58 /// <item><description>
60 /// </description></item>
61 /// <item><description>
63 /// </description></item>
64 /// <item><description>
66 /// </description></item>
67 /// <item><description>
69 /// </description></item>
70 /// <item><description>
72 /// </description></item>
73 /// <item><description>
75 /// </description></item>
76 /// <item><description>
77 /// column IN(value-list)
78 /// </description></item>
79 /// <item><description>
80 /// column NOT IN(value)
81 /// </description></item>
82 /// <item><description>
83 /// column NOT IN(value-list)
84 /// </description></item>
85 /// <item><description>
87 /// </description></item>
88 /// <item><description>
89 /// expression1 AND expression2 OR expression3
90 /// </description></item>
92 /// Note that if you want to set qoutation(" ' " or " " ") as value of LIKE operator, you should use two times.(" '' " or " "" ") \n And the optional ESCAPE clause is supported. Both percent symbol("%") and underscore symbol("_") are used in the LIKE pattern.
93 /// If these characters are used as value of LIKE operation, then the expression following the ESCAPE caluse of sqlite.
95 public class ContentFilter : IDisposable
97 private IntPtr _filterHandle = IntPtr.Zero;
98 private bool _disposedValue = false;
99 private ContentCollation _conditionCollate = ContentCollation.Default;
100 private ContentCollation _orderCollate = ContentCollation.Default;
101 private ContentOrder _orderType = ContentOrder.Asc;
102 private string _orderKeyword = null;
103 private string _conditionMsg = null;
105 internal IntPtr Handle
109 if (_filterHandle == IntPtr.Zero)
111 throw new ObjectDisposedException(nameof(ContentFilter));
114 return _filterHandle;
118 /// The start position of the given filter Starting from zero.
119 /// Please note that count value has to be set properly for correct result.
121 /// <since_tizen> 3 </since_tizen>
128 MediaContentValidator.ThrowIfError(
129 Interop.Filter.GetOffset(Handle, out offset, out count), "Failed to get offset");
136 MediaContentValidator.ThrowIfError(
137 Interop.Filter.SetOffset(Handle, value, this.Count), "Failed to set offset");
141 public ContentFilter()
143 MediaContentValidator.ThrowIfError(
144 Interop.Filter.Create(out _filterHandle), "Failed to Create Filter handle.");
148 /// The number of items to be searched with respect to the offset
150 /// <since_tizen> 3 </since_tizen>
157 MediaContentValidator.ThrowIfError(
158 Interop.Filter.GetOffset(Handle, out offset, out count), "Failed to get count");
165 MediaContentValidator.ThrowIfError(
166 Interop.Filter.SetOffset(Handle, this.Offset, value), "Failed to set count");
171 /// Gets the media filter content order and order keyword.
173 /// <since_tizen> 3 </since_tizen>
174 public ContentOrder Order
183 if (_orderKeyword != null)
185 MediaContentValidator.ThrowIfError(
186 Interop.Filter.SetOrder(Handle, value, _orderKeyword, _orderCollate), "Failed to set order");
194 /// The search order keyword
196 /// <since_tizen> 3 </since_tizen>
197 public string OrderKey
202 IntPtr val = IntPtr.Zero;
203 ContentCollation type;
206 MediaContentValidator.ThrowIfError(
207 Interop.Filter.GetOrder(Handle, out order, out val, out type), "Failed to GetOrder for OrderKey");
209 return Marshal.PtrToStringAnsi(val);
213 Interop.Libc.Free(val);
219 MediaContentValidator.ThrowIfError(
220 Interop.Filter.SetOrder(Handle, _orderType, value, _orderCollate), "Failed to set OrderKey");
222 _orderKeyword = value;
227 /// The collate type for comparing two strings
229 /// <since_tizen> 3 </since_tizen>
230 public ContentCollation OrderCollationType
234 return _orderCollate;
239 if (_orderKeyword != null)
241 MediaContentValidator.ThrowIfError(
242 Interop.Filter.SetOrder(Handle, _orderType, _orderKeyword, value), "Failed to set collation");
245 _orderCollate = value;
250 /// Gets/Sets the condition for the given filter.
252 /// <since_tizen> 3 </since_tizen>
253 public string Condition
257 IntPtr val = IntPtr.Zero;
258 ContentCollation type;
261 MediaContentValidator.ThrowIfError(
262 Interop.Filter.GetCondition(Handle, out val, out type), "Failed to get condition");
264 return Marshal.PtrToStringAnsi(val);
268 Interop.Libc.Free(val);
274 MediaContentValidator.ThrowIfError(
275 Interop.Filter.SetCondition(Handle, value, _conditionCollate), "Failed to set condition");
277 _conditionMsg = value;
282 /// The collate type for comparing two strings
284 /// <since_tizen> 3 </since_tizen>
285 public ContentCollation ConditionCollationType
289 return _conditionCollate;
294 if (_conditionMsg != null)
296 MediaContentValidator.ThrowIfError(
297 Interop.Filter.SetCondition(Handle, _conditionMsg, value), "Failed to set collation");
300 _conditionCollate = value;
305 /// Sets the storage id for the given filter.
306 /// You can use this property when you want to search items only in the specific storage
308 /// <since_tizen> 3 </since_tizen>
309 public string StorageId
313 IntPtr val = IntPtr.Zero;
316 MediaContentValidator.ThrowIfError(
317 Interop.Filter.GetStorage(Handle, out val), "Failed to get condition");
319 return Marshal.PtrToStringAnsi(val);
323 Interop.Libc.Free(val);
329 MediaContentValidator.ThrowIfError(
330 Interop.Filter.SetStorage(Handle, value), "Failed to set condition");
335 /// The type of the media group
337 /// <since_tizen> 3 </since_tizen>
338 public MediaGroupType GroupType { get; set; }
341 /// Dispose API for closing the internal resources.
342 /// This function can be used to stop all effects started by Vibrate().
344 /// <since_tizen> 3 </since_tizen>
345 public void Dispose()
348 GC.SuppressFinalize(this);
351 protected virtual void Dispose(bool disposing)
355 if (_filterHandle != IntPtr.Zero)
357 Interop.Filter.Destroy(_filterHandle);
358 _filterHandle = IntPtr.Zero;
361 _disposedValue = true;