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.
30 /// Setting content filter properties helps to limit the number of filtered items as following:
32 /// <item><description>
33 /// Offset - Used to set starting position of the filter's search
34 /// </description></item>
35 /// <item><description>
36 /// Count - Used to set number of items to be searched from offset
37 /// </description></item>
38 /// <item><description>
39 /// Condition - Used to set keyword which user want to search
40 /// </description></item>
41 /// <item><description>
42 /// Order - Used to set type of media to be ordered by the filter
43 /// </description></item>
46 /// Searchable expression can use one of the following forms:
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>
78 /// </description></item>
79 /// <item><description>
80 /// column IN(value-list)
81 /// </description></item>
82 /// <item><description>
83 /// column NOT IN(value)
84 /// </description></item>
85 /// <item><description>
86 /// column NOT IN(value-list)
87 /// </description></item>
88 /// <item><description>
90 /// </description></item>
91 /// <item><description>
92 /// expression1 AND expression2 OR expression3
93 /// </description></item>
97 /// 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.
98 /// If these characters are used as value of LIKE operation, then the expression following the ESCAPE caluse of sqlite.
100 public class ContentFilter : IDisposable
102 private IntPtr _filterHandle = IntPtr.Zero;
103 private bool _disposedValue = false;
104 private ContentCollation _conditionCollate = ContentCollation.Default;
105 private ContentCollation _orderCollate = ContentCollation.Default;
106 private ContentOrder _orderType = ContentOrder.Asc;
107 private string _orderKeyword = null;
108 private string _conditionMsg = null;
110 internal IntPtr Handle
114 if (_filterHandle == IntPtr.Zero)
116 throw new ObjectDisposedException(nameof(ContentFilter));
119 return _filterHandle;
123 /// The start position of the given filter Starting from zero.
124 /// Please note that count value has to be set properly for correct result.
132 MediaContentValidator.ThrowIfError(
133 Interop.Filter.GetOffset(Handle, out offset, out count), "Failed to get offset");
140 MediaContentValidator.ThrowIfError(
141 Interop.Filter.SetOffset(Handle, value, this.Count), "Failed to set offset");
145 public ContentFilter()
147 MediaContentValidator.ThrowIfError(
148 Interop.Filter.Create(out _filterHandle), "Failed to Create Filter handle.");
152 /// The number of items to be searched with respect to the offset
160 MediaContentValidator.ThrowIfError(
161 Interop.Filter.GetOffset(Handle, out offset, out count), "Failed to get count");
168 MediaContentValidator.ThrowIfError(
169 Interop.Filter.SetOffset(Handle, this.Offset, value), "Failed to set count");
174 /// Gets the media filter content order and order keyword.
176 public ContentOrder Order
185 if (_orderKeyword != null)
187 MediaContentValidator.ThrowIfError(
188 Interop.Filter.SetOrder(Handle, value, _orderKeyword, _orderCollate), "Failed to set order");
196 /// The search order keyword
198 public string OrderKey
203 IntPtr val = IntPtr.Zero;
204 ContentCollation type;
207 MediaContentValidator.ThrowIfError(
208 Interop.Filter.GetOrder(Handle, out order, out val, out type), "Failed to GetOrder for OrderKey");
210 return Marshal.PtrToStringAnsi(val);
214 Interop.Libc.Free(val);
220 MediaContentValidator.ThrowIfError(
221 Interop.Filter.SetOrder(Handle, _orderType, value, _orderCollate), "Failed to set OrderKey");
223 _orderKeyword = value;
228 /// The collate type for comparing two strings
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 public string Condition
256 IntPtr val = IntPtr.Zero;
257 ContentCollation type;
260 MediaContentValidator.ThrowIfError(
261 Interop.Filter.GetCondition(Handle, out val, out type), "Failed to get condition");
263 return Marshal.PtrToStringAnsi(val);
267 Interop.Libc.Free(val);
273 MediaContentValidator.ThrowIfError(
274 Interop.Filter.SetCondition(Handle, value, _conditionCollate), "Failed to set condition");
276 _conditionMsg = value;
281 /// The collate type for comparing two strings
283 public ContentCollation ConditionCollationType
287 return _conditionCollate;
292 if (_conditionMsg != null)
294 MediaContentValidator.ThrowIfError(
295 Interop.Filter.SetCondition(Handle, _conditionMsg, value), "Failed to set collation");
298 _conditionCollate = value;
303 /// Sets the storage id for the given filter.
304 /// You can use this property when you want to search items only in the specific storage
306 public string StorageId
310 IntPtr val = IntPtr.Zero;
313 MediaContentValidator.ThrowIfError(
314 Interop.Filter.GetStorage(Handle, out val), "Failed to get condition");
316 return Marshal.PtrToStringAnsi(val);
320 Interop.Libc.Free(val);
326 MediaContentValidator.ThrowIfError(
327 Interop.Filter.SetStorage(Handle, value), "Failed to set condition");
332 /// The type of the media group
334 public MediaGroupType GroupType { get; set; }
337 /// Dispose API for closing the internal resources.
338 /// This function can be used to stop all effects started by Vibrate().
340 public void Dispose()
343 GC.SuppressFinalize(this);
346 protected virtual void Dispose(bool disposing)
350 if (_filterHandle != IntPtr.Zero)
352 Interop.Filter.Destroy(_filterHandle);
353 _filterHandle = IntPtr.Zero;
356 _disposedValue = true;