objc2_core_services/generated/Metadata/
MDQuery.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "dispatch2")]
8use dispatch2::*;
9#[cfg(feature = "objc2")]
10use objc2::__framework_prelude::*;
11use objc2_core_foundation::*;
12
13use crate::*;
14
15/// This is the type of a reference to MDQuerys.
16///
17/// See also [Apple's documentation](https://developer.apple.com/documentation/coreservices/mdquery?language=objc)
18#[repr(C)]
19pub struct MDQuery {
20    inner: [u8; 0],
21    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
22}
23
24cf_type!(
25    unsafe impl MDQuery {}
26);
27#[cfg(feature = "objc2")]
28cf_objc2_type!(
29    unsafe impl RefEncode<"__MDQuery"> for MDQuery {}
30);
31
32/// [Apple's documentation](https://developer.apple.com/documentation/coreservices/mdqueryoptionflags?language=objc)
33#[repr(transparent)]
34#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
35pub struct MDQueryOptionFlags(pub c_uint);
36impl MDQueryOptionFlags {
37    #[doc(alias = "kMDQuerySynchronous")]
38    pub const Synchronous: Self = Self(1);
39    #[doc(alias = "kMDQueryWantsUpdates")]
40    pub const WantsUpdates: Self = Self(4);
41    #[doc(alias = "kMDQueryAllowFSTranslation")]
42    pub const AllowFSTranslation: Self = Self(8);
43}
44
45#[cfg(feature = "objc2")]
46unsafe impl Encode for MDQueryOptionFlags {
47    const ENCODING: Encoding = c_uint::ENCODING;
48}
49
50#[cfg(feature = "objc2")]
51unsafe impl RefEncode for MDQueryOptionFlags {
52    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
53}
54
55unsafe impl ConcreteType for MDQuery {
56    /// Returns the type identifier of all MDQuery instances.
57    #[doc(alias = "MDQueryGetTypeID")]
58    #[inline]
59    fn type_id() -> CFTypeID {
60        extern "C-unwind" {
61            fn MDQueryGetTypeID() -> CFTypeID;
62        }
63        unsafe { MDQueryGetTypeID() }
64    }
65}
66
67impl MDQuery {
68    /// Creates a new query with the given query expression.
69    ///
70    /// Parameter `allocator`: The CFAllocator which should be used to allocate
71    /// memory for the query and its sub-storage. This
72    /// parameter may be NULL in which case the current default
73    /// CFAllocator is used.
74    ///
75    /// Parameter `queryString`: The query expression string for this query. The
76    /// syntax for query expressions is explained above in the
77    /// header overview documentation.
78    ///
79    /// Parameter `valueListAttrs`: An optional array of attribute names. The
80    /// query will collect the values of these attributes into
81    /// uniqued lists, which can be used or displayed to summarize
82    /// the results of the query, or allow a user to further
83    /// qualify the items for which they are searching. This
84    /// parameter may be NULL if no value lists are desired. Value
85    /// list collection increases CPU usage and significantly
86    /// increases the memory usage of an MDQuery. The attribute
87    /// names are CFStrings.
88    ///
89    /// Parameter `sortingAttrs`: An optional array of attribute names. The
90    /// query will results of the query based on the values of
91    /// these attributes. The first name in the array is used as
92    /// the primary sort key, the second as the secondary key, and
93    /// so on. The comparison of like-typed values is a simple,
94    /// literal comparison. This parameter may be NULL if no
95    /// sorting is desired. Sorting increases memory usage and
96    /// significantly increases the CPU usage of an MDQuery.
97    /// However, when possible, it is almost always cheaper to have
98    /// the MDQuery do the sorting, rather than you fetching all
99    /// the results and attributes from each of them and doing the
100    /// sorting yourself. The attribute names are CFStrings.
101    ///
102    /// Returns: An MDQueryRef, or NULL on failure. If the query string
103    /// is empty or malformed (invalid syntax), returns NULL.
104    #[doc(alias = "MDQueryCreate")]
105    #[inline]
106    pub unsafe fn new(
107        allocator: Option<&CFAllocator>,
108        query_string: Option<&CFString>,
109        value_list_attrs: Option<&CFArray>,
110        sorting_attrs: Option<&CFArray>,
111    ) -> Option<CFRetained<MDQuery>> {
112        extern "C-unwind" {
113            fn MDQueryCreate(
114                allocator: Option<&CFAllocator>,
115                query_string: Option<&CFString>,
116                value_list_attrs: Option<&CFArray>,
117                sorting_attrs: Option<&CFArray>,
118            ) -> Option<NonNull<MDQuery>>;
119        }
120        let ret =
121            unsafe { MDQueryCreate(allocator, query_string, value_list_attrs, sorting_attrs) };
122        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
123    }
124
125    /// Creates a new query, which is a subset of the given query. Only
126    /// results matched by the given query can be matched by the
127    /// query expression of this query.
128    ///
129    /// Parameter `allocator`: The CFAllocator which should be used to allocate
130    /// memory for the query and its sub-storage. This
131    /// parameter may be NULL in which case the current default
132    /// CFAllocator is used.
133    ///
134    /// Parameter `query`: The parent query of the new query.
135    ///
136    /// Parameter `queryString`: The query expression string for this query.
137    /// This expression in effect may further restrict the matches
138    /// found by the parent query. If the string is empty the
139    /// behavior is undefined.
140    ///
141    /// Parameter `valueListAttrs`: An optional array of attribute names. The
142    /// query will collect the values of these attributes into
143    /// uniqued lists, which can be used or displayed to summarize
144    /// the results of the query, or allow a user to further
145    /// qualify the items for which they are searching. This
146    /// parameter may be NULL if no value lists are desired. Value
147    /// list collection increases CPU usage and significantly
148    /// increases the memory usage of an MDQuery. The attribute
149    /// names are CFStrings.
150    ///
151    /// Parameter `sortingAttrs`: An optional array of attribute names. The
152    /// query will sort results of the query based on the values of
153    /// these attributes. The first name in the array is used as
154    /// the primary sort key, the second as the secondary key, and
155    /// so on. The comparison of like-typed values is a simple,
156    /// literal comparison. This parameter may be NULL if no
157    /// sorting is desired. Sorting increases memory usage and
158    /// significantly increases the CPU usage of an MDQuery.
159    /// However, when possible, it is almost always cheaper to have
160    /// the MDQuery do the sorting, rather than you fetching all
161    /// the results and attributes from each of them and doing the
162    /// sorting yourself. The attribute names are CFStrings.
163    ///
164    /// Returns: An MDQueryRef, or NULL on failure. If the query string
165    /// is empty or malformed (invalid syntax), returns NULL.
166    #[doc(alias = "MDQueryCreateSubset")]
167    #[inline]
168    pub unsafe fn new_subset(
169        allocator: Option<&CFAllocator>,
170        query: Option<&MDQuery>,
171        query_string: Option<&CFString>,
172        value_list_attrs: Option<&CFArray>,
173        sorting_attrs: Option<&CFArray>,
174    ) -> Option<CFRetained<MDQuery>> {
175        extern "C-unwind" {
176            fn MDQueryCreateSubset(
177                allocator: Option<&CFAllocator>,
178                query: Option<&MDQuery>,
179                query_string: Option<&CFString>,
180                value_list_attrs: Option<&CFArray>,
181                sorting_attrs: Option<&CFArray>,
182            ) -> Option<NonNull<MDQuery>>;
183        }
184        let ret = unsafe {
185            MDQueryCreateSubset(
186                allocator,
187                query,
188                query_string,
189                value_list_attrs,
190                sorting_attrs,
191            )
192        };
193        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
194    }
195
196    /// Creates a new query with the given query expression.
197    ///
198    /// Parameter `allocator`: The CFAllocator which should be used to allocate
199    /// memory for the query and its sub-storage. This
200    /// parameter may be NULL in which case the current default
201    /// CFAllocator is used.
202    ///
203    /// Parameter `queryString`: The query expression string for this query. The
204    /// syntax for query expressions is explained above in the
205    /// header overview documentation.
206    ///
207    /// Parameter `valueListAttrs`: An optional array of attribute names. The
208    /// query will collect the values of these attributes into
209    /// uniqued lists, which can be used or displayed to summarize
210    /// the results of the query, or allow a user to further
211    /// qualify the items for which they are searching. This
212    /// parameter may be NULL if no value lists are desired. Value
213    /// list collection increases CPU usage and significantly
214    /// increases the memory usage of an MDQuery. The attribute
215    /// names are CFStrings.
216    ///
217    /// Parameter `sortingAttrs`: An optional array of attribute names. The
218    /// query will results of the query based on the values of
219    /// these attributes. The first name in the array is used as
220    /// the primary sort key, the second as the secondary key, and
221    /// so on. The comparison of like-typed values is a simple,
222    /// literal comparison. This parameter may be NULL if no
223    /// sorting is desired. Sorting increases memory usage and
224    /// significantly increases the CPU usage of an MDQuery.
225    /// However, when possible, it is almost always cheaper to have
226    /// the MDQuery do the sorting, rather than you fetching all
227    /// the results and attributes from each of them and doing the
228    /// sorting yourself. The attribute names are CFStrings.
229    ///
230    /// Parameter `items`: An array of items. The query will only return results
231    /// in this set.
232    ///
233    /// Returns: An MDQueryRef, or NULL on failure. If the query string
234    /// is empty or malformed (invalid syntax), returns NULL.
235    #[doc(alias = "MDQueryCreateForItems")]
236    #[inline]
237    pub unsafe fn new_for_items(
238        allocator: Option<&CFAllocator>,
239        query_string: Option<&CFString>,
240        value_list_attrs: Option<&CFArray>,
241        sorting_attrs: Option<&CFArray>,
242        items: Option<&CFArray>,
243    ) -> Option<CFRetained<MDQuery>> {
244        extern "C-unwind" {
245            fn MDQueryCreateForItems(
246                allocator: Option<&CFAllocator>,
247                query_string: Option<&CFString>,
248                value_list_attrs: Option<&CFArray>,
249                sorting_attrs: Option<&CFArray>,
250                items: Option<&CFArray>,
251            ) -> Option<NonNull<MDQuery>>;
252        }
253        let ret = unsafe {
254            MDQueryCreateForItems(
255                allocator,
256                query_string,
257                value_list_attrs,
258                sorting_attrs,
259                items,
260            )
261        };
262        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
263    }
264
265    /// Returns the query string of the query.
266    ///
267    /// Parameter `query`: The query to be interrogated.
268    ///
269    /// Returns: The query string of the query.
270    #[doc(alias = "MDQueryCopyQueryString")]
271    #[inline]
272    pub unsafe fn query_string(self: &MDQuery) -> Option<CFRetained<CFString>> {
273        extern "C-unwind" {
274            fn MDQueryCopyQueryString(query: &MDQuery) -> Option<NonNull<CFString>>;
275        }
276        let ret = unsafe { MDQueryCopyQueryString(self) };
277        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
278    }
279
280    /// Returns the list of attribute names for which the query is
281    /// collecting the lists of values.
282    ///
283    /// Parameter `query`: The query to be interrogated.
284    ///
285    /// Returns: The list of value list attribute names of the query.
286    #[doc(alias = "MDQueryCopyValueListAttributes")]
287    #[inline]
288    pub unsafe fn value_list_attributes(self: &MDQuery) -> Option<CFRetained<CFArray>> {
289        extern "C-unwind" {
290            fn MDQueryCopyValueListAttributes(query: &MDQuery) -> Option<NonNull<CFArray>>;
291        }
292        let ret = unsafe { MDQueryCopyValueListAttributes(self) };
293        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
294    }
295
296    /// Returns the list of attribute names the query is using to sort
297    /// the results.
298    ///
299    /// Parameter `query`: The query to be interrogated.
300    ///
301    /// Returns: The list of sorting attribute names of the query.
302    #[doc(alias = "MDQueryCopySortingAttributes")]
303    #[inline]
304    pub unsafe fn sorting_attributes(self: &MDQuery) -> Option<CFRetained<CFArray>> {
305        extern "C-unwind" {
306            fn MDQueryCopySortingAttributes(query: &MDQuery) -> Option<NonNull<CFArray>>;
307        }
308        let ret = unsafe { MDQueryCopySortingAttributes(self) };
309        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
310    }
311}
312
313/// Structure containing the progress notification batching
314/// parameters of an MDQuery. The first notification can be
315/// triggered by the either first_max_num or first_max_ms limit
316/// being exceeded. Subsequent notifications are triggered by
317/// either the progress_max_num or progress_max_ms limit. The
318/// default batching parameters are undefined and subject to
319/// change.
320/// Field: first_max_num The maximum number of results that can
321/// accumulate before a progress notification is sent out
322/// by the MDQuery, for the first notification.
323/// Field: first_max_ms The maximum number of milliseconds that can
324/// pass before a progress notification is sent out. This
325/// value is advisory, in that the notification will be
326/// triggered "at some point after first_max_ms milliseconds
327/// have passed since the query began accumulating results",
328/// but generally not very long after, for the first
329/// progress notification.
330/// Field: progress_max_num The maximum number of results that can
331/// accumulate before a progress notification is sent out
332/// by the MDQuery, for notifications after the first,
333/// during the initial gathering phase of the query.
334/// Field: progress_max_ms The maximum number of milliseconds that can
335/// pass before a progress notification is sent out. This
336/// value is advisory, in that the notification will be
337/// triggered "at some point after first_max_ms milliseconds
338/// have passed since the query began accumulating results",
339/// but generally not very long after, for progress
340/// notifications after the first, during the initial
341/// gathering phase of the query.
342/// Field: update_max_num The maximum number of results that can
343/// accumulate before an update notification is sent out
344/// by the MDQuery, for notifications after the gathering
345/// phase of the query has finished.
346/// Field: update_max_ms The maximum number of milliseconds that can
347/// pass before a progress notification is sent out. This
348/// value is advisory, in that the notification will be
349/// triggered "at some point after first_max_ms milliseconds
350/// have passed since the query began accumulating results",
351/// but generally not very long after, for update notifications
352/// after the gathering phase of the query has finished.
353///
354/// See also [Apple's documentation](https://developer.apple.com/documentation/coreservices/mdquerybatchingparams?language=objc)
355#[repr(C)]
356#[derive(Clone, Copy, Debug, PartialEq)]
357pub struct MDQueryBatchingParams {
358    pub first_max_num: usize,
359    pub first_max_ms: usize,
360    pub progress_max_num: usize,
361    pub progress_max_ms: usize,
362    pub update_max_num: usize,
363    pub update_max_ms: usize,
364}
365
366#[cfg(feature = "objc2")]
367unsafe impl Encode for MDQueryBatchingParams {
368    const ENCODING: Encoding = Encoding::Struct(
369        "?",
370        &[
371            <usize>::ENCODING,
372            <usize>::ENCODING,
373            <usize>::ENCODING,
374            <usize>::ENCODING,
375            <usize>::ENCODING,
376            <usize>::ENCODING,
377        ],
378    );
379}
380
381#[cfg(feature = "objc2")]
382unsafe impl RefEncode for MDQueryBatchingParams {
383    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
384}
385
386impl MDQuery {
387    /// Returns the current parameters that control batching of progress
388    /// notifications.
389    ///
390    /// Parameter `query`: The query to be interrogated.
391    ///
392    /// Returns: An MDQueryBatchingParams structure with the current
393    /// batching parameters.
394    #[doc(alias = "MDQueryGetBatchingParameters")]
395    #[inline]
396    pub unsafe fn batching_parameters(self: &MDQuery) -> MDQueryBatchingParams {
397        extern "C-unwind" {
398            fn MDQueryGetBatchingParameters(query: &MDQuery) -> MDQueryBatchingParams;
399        }
400        unsafe { MDQueryGetBatchingParameters(self) }
401    }
402
403    /// Parameter `query`: The query whose batching parameters are to be set.
404    ///
405    /// Parameter `params`: An MDQueryBatchingParams structure with the batching
406    /// parameters to set.
407    #[doc(alias = "MDQuerySetBatchingParameters")]
408    #[inline]
409    pub unsafe fn set_batching_parameters(self: &MDQuery, params: MDQueryBatchingParams) {
410        extern "C-unwind" {
411            fn MDQuerySetBatchingParameters(query: &MDQuery, params: MDQueryBatchingParams);
412        }
413        unsafe { MDQuerySetBatchingParameters(self, params) }
414    }
415}
416
417/// Type of the callback function used to create the result objects
418/// stored and returned by an MDQuery. The function may
419/// hold onto the given MDItemRef in some other data
420/// structure, but must retain it for it to remain valid.
421/// The create-result function is called lazily as results
422/// are requested from a query, so it will not generally
423/// be called on all results, if in fact any. This avoids
424/// the cost of creating potentially hundreds of thousands
425/// of what might be temporary objects.
426///
427/// Parameter `query`: The MDQuery instance.
428///
429/// Parameter `item`: The default MDItemRef for the result.
430///
431/// Parameter `context`: The user-defined context parameter given to
432/// MDQuerySetCreateResultFunction().
433///
434/// Returns: The function must return a pointer-sized value that can
435/// be managed with the callbacks which were set at the same
436/// time the create function was given to the query. The
437/// value must be returned with a reference (such as if the
438/// retain callback had been called on it), as implied by the
439/// Create name. If this function doesn't wish to create a
440/// new object, it can return the given MDItemRef, but must
441/// also return it with a new retain, and the callbacks must
442/// be able to handle an MDItemRef as an input value. If
443/// this function returns NULL, NULL will be stored for the
444/// moment in the query, MDQueryGetResultAtIndex() may return
445/// NULL for that result, and the next time the query wants
446/// the result, it will call this function again.
447///
448/// See also [Apple's documentation](https://developer.apple.com/documentation/coreservices/mdquerycreateresultfunction?language=objc)
449#[cfg(feature = "MDItem")]
450pub type MDQueryCreateResultFunction =
451    Option<unsafe extern "C-unwind" fn(*mut MDQuery, *mut MDItem, *mut c_void) -> *const c_void>;
452
453impl MDQuery {
454    /// Sets the function used to create the result objects of the
455    /// MDQuery. If no create function is set on an MDQuery,
456    /// the default result objects are MDItemRefs. Results
457    /// created after a create function is set will be created
458    /// through the given create function, but values created
459    /// before the function was set (or after it is unset) are
460    /// not modified. Therefore it is not advisable to change
461    /// this function after MDQueryExecute() has been called
462    /// with the query. The create-result function is called
463    /// lazily as results are requested from a query, so it will
464    /// not generally be called on all results, if in fact any.
465    /// This avoids the cost of creating potentially hundreds
466    /// of thousands of what might be temporary objects.
467    ///
468    /// Parameter `query`: The query to whose result create function is to be set.
469    ///
470    /// Parameter `func`: The callback function the MDQuery will use to
471    /// create its results, such as those returned from
472    /// MDQueryGetResultAtIndex(). This parameter
473    /// may be NULL, in which case any previous result creation
474    /// settings are cancelled, and the MDQuery will subsequently
475    /// produce MDItemRefs. If the function (when the parameter is
476    /// not NULL) is not of type MDQueryCreateResultFunction or
477    /// does not behave as a MDQueryCreateResultFunction must,
478    /// the behavior is undefined.
479    ///
480    /// Parameter `context`: A pointer-sized user-defined value, which is
481    /// passed as the third parameter to the create function,
482    /// but is otherwise unused by MDQuery. The MDQuery does
483    /// not retain the context in any way, so it must remain
484    /// valid for at least the lifetime of the query. If the
485    /// context is not what is expected by the create function,
486    /// the behavior is undefined.
487    ///
488    /// Parameter `cb`: A pointer to a CFArrayCallBacks structure
489    /// initialized with the callbacks for the query to use to
490    /// manage the created result objects. A copy of the
491    /// contents of the callbacks structure is made, so that a
492    /// pointer to a structure on the stack can be passed in, or
493    /// can be reused for multiple query creations. Only version
494    /// 0 of the CFArrayCallBacks is supported. The retain field
495    /// may be NULL, in which case the MDQuery will do nothing to
496    /// add a retain to the created results for the query. The
497    /// release field may be NULL, in which case the MDQuery will
498    /// do nothing to remove the query's retain (such as the one
499    /// it gets from the create function) on the result objects
500    /// when the query is destroyed. If the copyDescription field
501    /// is NULL, the query will create a simple description for
502    /// the result objects. If the equal field is NULL, the query
503    /// will use pointer equality to test for equality of results.
504    /// This callbacks parameter itself may be NULL, which is
505    /// treated as if a valid structure of version 0 with all
506    /// fields NULL had been passed in. Otherwise, if any of the
507    /// fields are not valid pointers to functions of the correct
508    /// type, or this parameter is not a valid pointer to a
509    /// CFArrayCallBacks callbacks structure, the behavior is
510    /// undefined. If any of the value values returned from the
511    /// create function is not one understood by one or more of
512    /// the callback functions, the behavior when those callback
513    /// functions are used is undefined. For example, if the create
514    /// function can return NULL, then NULL must be understood by
515    /// the callback functions as a possible parameter. The retain
516    /// and release callbacks must be a matched set -- do not
517    /// assume that the retain function will be unused or that
518    /// additional reference counts will not be taken on the
519    /// created results.
520    #[doc(alias = "MDQuerySetCreateResultFunction")]
521    #[cfg(feature = "MDItem")]
522    #[inline]
523    pub unsafe fn set_create_result_function(
524        self: &MDQuery,
525        func: MDQueryCreateResultFunction,
526        context: *mut c_void,
527        cb: *const CFArrayCallBacks,
528    ) {
529        extern "C-unwind" {
530            fn MDQuerySetCreateResultFunction(
531                query: &MDQuery,
532                func: MDQueryCreateResultFunction,
533                context: *mut c_void,
534                cb: *const CFArrayCallBacks,
535            );
536        }
537        unsafe { MDQuerySetCreateResultFunction(self, func, context, cb) }
538    }
539}
540
541/// Type of the callback function used to create the value objects
542/// stored and returned by an MDQuery. The function may
543/// hold onto the given attribute name and/or value in some
544/// other data structure, but must retain them for them to
545/// remain valid.
546///
547/// Parameter `query`: The MDQuery instance.
548///
549/// Parameter `attrName`: The attribute name of the value.
550///
551/// Parameter `attrValue`: The default value of the value.
552///
553/// Parameter `context`: The user-defined context parameter given to
554/// MDQuerySetCreateValueFunction().
555///
556/// Returns: The function must return a pointer-sized value that can
557/// be managed with the callbacks which were set at the same
558/// time the create function was given to the query. The
559/// value must be returned with a reference (such as if the
560/// retain callback had been called on it), as implied by the
561/// Create name. If this function doesn't wish to create a
562/// new object, it can return the given CFTypeRef, but must
563/// also return it with a new retain, and the callbacks must
564/// be able to handle a CFTypeRef as an input value.
565///
566/// See also [Apple's documentation](https://developer.apple.com/documentation/coreservices/mdquerycreatevaluefunction?language=objc)
567pub type MDQueryCreateValueFunction = Option<
568    unsafe extern "C-unwind" fn(
569        *mut MDQuery,
570        *const CFString,
571        *const CFType,
572        *mut c_void,
573    ) -> *const c_void,
574>;
575
576impl MDQuery {
577    /// Sets the function used to create the value objects of the
578    /// MDQuery. These are the values of the value lists that
579    /// were requested when the query was created. If no create
580    /// function is set on an MDQuery, the default value objects
581    /// are the CFTypeRef values of the attributes. Values
582    /// created after a create function is set will be created
583    /// through the given create function, but values created
584    /// before the function was set (or after it is unset)
585    /// are not modified. Therefore it is not advisable to
586    /// change this function after MDQueryExecute() has been
587    /// called with the query.
588    ///
589    /// Parameter `query`: The query to whose value create function is to be set.
590    ///
591    /// Parameter `func`: The callback function the MDQuery will use to
592    /// create the value list values, such as those returned from
593    /// MDQueryCopyValuesOfAttribute(). This parameter
594    /// may be NULL, in which case any previous value creation
595    /// settings are cancelled, and the MDQuery will subsequently
596    /// produce the default CFTypeRefs. If the function (when the
597    /// parameter is not NULL) is not of type
598    /// MDQueryCreateValueFunction or does not behave as a
599    /// MDQueryCreateValueFunction must, the behavior is undefined.
600    ///
601    /// Parameter `context`: A pointer-sized user-defined value, which is
602    /// passed as the fourth parameter to the create function,
603    /// but is otherwise unused by MDQuery. The MDQuery does
604    /// not retain the context in any way, so it must remain
605    /// valid for at least the lifetime of the query. If the
606    /// context is not what is expected by the create function,
607    /// the behavior is undefined.
608    ///
609    /// Parameter `cb`: A pointer to a CFArrayCallBacks structure
610    /// initialized with the callbacks for the query to use to
611    /// manage the created value objects. A copy of the
612    /// contents of the callbacks structure is made, so that a
613    /// pointer to a structure on the stack can be passed in, or
614    /// can be reused for multiple query creations. Only version
615    /// 0 of the CFArrayCallBacks is supported. The retain field
616    /// may be NULL, in which case the MDQuery will do nothing to
617    /// add a retain to the created values for the query. The
618    /// release field may be NULL, in which case the MDQuery will
619    /// do nothing to remove the query's retain (such as the one
620    /// it gets from the create function) on the value objects
621    /// when the query is destroyed. If the copyDescription field
622    /// is NULL, the query will create a simple description for
623    /// the value objects. If the equal field is NULL, the query
624    /// will use pointer equality to test for equality of values.
625    /// This callbacks parameter itself may be NULL, which is
626    /// treated as if a valid structure of version 0 with all
627    /// fields NULL had been passed in. Otherwise, if any of the
628    /// fields are not valid pointers to functions of the correct
629    /// type, or this parameter is not a valid pointer to a
630    /// CFArrayCallBacks callbacks structure, the behavior is
631    /// undefined. If any of the value values returned from the
632    /// create function is not one understood by one or more of
633    /// the callback functions, the behavior when those callback
634    /// functions are used is undefined. For example, if the
635    /// create function can return NULL, then NULL must be
636    /// understood by the callback functions as a possible
637    /// parameter. The retain and release callbacks must be a
638    /// matched set -- do not assume that the retain function will
639    /// be unused or that additional reference counts will not be
640    /// taken on the created values.
641    #[doc(alias = "MDQuerySetCreateValueFunction")]
642    #[inline]
643    pub unsafe fn set_create_value_function(
644        self: &MDQuery,
645        func: MDQueryCreateValueFunction,
646        context: *mut c_void,
647        cb: *const CFArrayCallBacks,
648    ) {
649        extern "C-unwind" {
650            fn MDQuerySetCreateValueFunction(
651                query: &MDQuery,
652                func: MDQueryCreateValueFunction,
653                context: *mut c_void,
654                cb: *const CFArrayCallBacks,
655            );
656        }
657        unsafe { MDQuerySetCreateValueFunction(self, func, context, cb) }
658    }
659
660    /// Set the dispatch queue on which query results will be delivered
661    /// by MDQueryExecute. It is not advisable to change set
662    /// dispatch queue after MDQueryExecute() has been called with
663    /// the query. Setting the dispatch queue for a synchronous
664    /// query (kMDQuerySynchronous) has no effect.
665    ///
666    /// Parameter `query`: The query for which the dispatch queue should be set.
667    ///
668    /// Parameter `queue`: The dispatch queue on which results should be delivered.
669    #[doc(alias = "MDQuerySetDispatchQueue")]
670    #[cfg(feature = "dispatch2")]
671    #[inline]
672    pub unsafe fn set_dispatch_queue(self: &MDQuery, queue: Option<&DispatchQueue>) {
673        extern "C-unwind" {
674            fn MDQuerySetDispatchQueue(query: &MDQuery, queue: Option<&DispatchQueue>);
675        }
676        unsafe { MDQuerySetDispatchQueue(self, queue) }
677    }
678
679    /// Run the query, and populate the query with the results. Queries
680    /// only gather results or process updates while the current
681    /// thread's run loop is running. Queries normally operate
682    /// asynchronously, and send out progress and update
683    /// notifications to report changes to the list of results
684    /// that has been collected. Queries have two phases: the
685    /// initial gathering of all currently matching results, and
686    /// a second live-update phase where queries monitor the
687    /// state of the system and update themselves to external
688    /// changes in files or the operating environment (for example,
689    /// as time advances, files which did not match the query
690    /// when it was started may later match the query). Query
691    /// notifications are posted within the context of the same
692    /// thread which executes the query.
693    /// [[There are three operational modes: (1) synchronous static
694    /// queries, which collect the list of current results and then
695    /// do not watch for updates to the results, (2) asynchronous
696    /// static queries, which collect the results asychronously
697    /// after this function returns, and then do not watch for
698    /// updates to the results, and (3) asynchronous live queries
699    /// which collect the initial results asychronously after this
700    /// function returns, and then do watch for updates to the
701    /// results, until the query is destroyed. There is little
702    /// reason not to allow the fourth case, synchronous collection
703    /// of initial results, followed by asynchronous monitoring
704    /// for updates, so this may change in the future.]]
705    ///
706    /// Parameter `query`: The query to execute.
707    ///
708    /// Parameter `optionFlags`: Bitwise or of MDQueryOptionFlags
709    ///
710    /// Returns: Returns true if the query was started (executed in the case
711    /// of a synchronous query), false otherwise. Queries cannot be
712    /// executed more than once.
713    #[doc(alias = "MDQueryExecute")]
714    #[inline]
715    pub unsafe fn execute(self: &MDQuery, option_flags: CFOptionFlags) -> bool {
716        extern "C-unwind" {
717            fn MDQueryExecute(query: &MDQuery, option_flags: CFOptionFlags) -> Boolean;
718        }
719        let ret = unsafe { MDQueryExecute(self, option_flags) };
720        ret != 0
721    }
722
723    /// Stops the query from ever generating more results. Queries may be
724    /// executed only once, so a stopped query cannot be
725    /// restarted. The query will also not generate any result
726    /// updates. The query is static after this function returns.
727    /// The query will do final processing of results that have
728    /// come in but not yet been processed (because, say, the
729    /// batching parameters hasn't triggered that yet). That may
730    /// trigger a progress notification, so be aware of that if
731    /// you are stopping a query from within your progress note
732    /// handler; that is, during this function, a recursive
733    /// progress and/or finished notification might occur, which
734    /// might recursively call your notification handler. It is
735    /// safe to call this function recursively. You would call
736    /// this function to stop a query that is generating way too
737    /// many results to be useful, but still want to access the
738    /// results that have come in so far. If a query is stopped
739    /// before the gathering phase finishes, it will not report
740    /// itself as finished, nor will it send out a finished
741    /// notification.
742    ///
743    /// Parameter `query`: The query to stop.
744    #[doc(alias = "MDQueryStop")]
745    #[inline]
746    pub unsafe fn stop(self: &MDQuery) {
747        extern "C-unwind" {
748            fn MDQueryStop(query: &MDQuery);
749        }
750        unsafe { MDQueryStop(self) }
751    }
752
753    /// Disables updates to the query result list. This should be called
754    /// before iterating through the list of results to prevent
755    /// the result list from changing during the iteration. The
756    /// disabled state is a counter, and disabling can be done
757    /// recursively and from different threads.
758    ///
759    /// Parameter `query`: The query for which updates are to be disabled.
760    ///
761    /// Returns: The generation number of the query. This changes each time the query's
762    /// result set has changed.
763    #[doc(alias = "MDQueryDisableUpdates")]
764    #[inline]
765    pub unsafe fn disable_updates(self: &MDQuery) {
766        extern "C-unwind" {
767            fn MDQueryDisableUpdates(query: &MDQuery);
768        }
769        unsafe { MDQueryDisableUpdates(self) }
770    }
771
772    /// Re-enables updates to the query result list. This should be called
773    /// when finished iterating through the list of results, to
774    /// allow changes to the result list to occur. Changes will
775    /// be allowed when all the disables have been matched by a
776    /// corresponding enable.
777    ///
778    /// Parameter `query`: The query for which updates are to be enabled.
779    #[doc(alias = "MDQueryEnableUpdates")]
780    #[inline]
781    pub unsafe fn enable_updates(self: &MDQuery) {
782        extern "C-unwind" {
783            fn MDQueryEnableUpdates(query: &MDQuery);
784        }
785        unsafe { MDQueryEnableUpdates(self) }
786    }
787
788    /// Returns true if the first phase of a query, the initial result
789    /// gathering, has finished.
790    ///
791    /// Parameter `query`: The query to be interrogated.
792    ///
793    /// Returns: A boolean indicating whether or not the first phase
794    /// of a query has completed.
795    #[doc(alias = "MDQueryIsGatheringComplete")]
796    #[inline]
797    pub unsafe fn is_gathering_complete(self: &MDQuery) -> bool {
798        extern "C-unwind" {
799            fn MDQueryIsGatheringComplete(query: &MDQuery) -> Boolean;
800        }
801        let ret = unsafe { MDQueryIsGatheringComplete(self) };
802        ret != 0
803    }
804
805    /// Returns the number of results currently collected by the query.
806    /// Note that the number of results in a query will change
807    /// over time as the query's result list is updated.
808    ///
809    /// Parameter `query`: The query to be interrogated.
810    ///
811    /// Returns: The number of results in the query.
812    #[doc(alias = "MDQueryGetResultCount")]
813    #[inline]
814    pub unsafe fn result_count(self: &MDQuery) -> CFIndex {
815        extern "C-unwind" {
816            fn MDQueryGetResultCount(query: &MDQuery) -> CFIndex;
817        }
818        unsafe { MDQueryGetResultCount(self) }
819    }
820
821    /// Returns the current result at the given index. This function
822    /// causes the result object to be created if it hasn't
823    /// been created already. For performance reasons, it is
824    /// not advisable to ask for results that you don't need,
825    /// to avoid the cost of creating them. If possible, call
826    /// this function to fetch only the results you need to
827    /// display or otherwise process. Note that the index of
828    /// a particular result will change over time, as the
829    /// query's result list is updated.
830    ///
831    /// Parameter `query`: The query to be interrogated.
832    ///
833    /// Parameter `idx`: The index into the query's result list. If the index is
834    /// negative, or is equal to or larger than the current
835    /// number of results in the query, the behavior is undefined.
836    ///
837    /// Returns: Returns the MDItemRef currently at the given index, or
838    /// if a result-create function has been set, returns the
839    /// result returned by that function.
840    #[doc(alias = "MDQueryGetResultAtIndex")]
841    #[inline]
842    pub unsafe fn result_at_index(self: &MDQuery, idx: CFIndex) -> *const c_void {
843        extern "C-unwind" {
844            fn MDQueryGetResultAtIndex(query: &MDQuery, idx: CFIndex) -> *const c_void;
845        }
846        unsafe { MDQueryGetResultAtIndex(self, idx) }
847    }
848
849    /// Returns the current index of the given result. If a result-create
850    /// function has been set, and the equal callback is non-NULL,
851    /// it will be used to test the query's results against the
852    /// candidate result. Note that the index of a result will
853    /// change over time, as the query's result list is updated.
854    ///
855    /// Parameter `query`: The query to be interrogated.
856    ///
857    /// Parameter `result`: The candidate result object for which to search.
858    /// If a custom create-result function has been set, and this
859    /// parameter is not a valid result object that the provided
860    /// callbacks can handle, the behavior is undefined. If a custom
861    /// create-result function has not been set, this parameter
862    /// must be a valid MDItemRef.
863    ///
864    /// Returns: The index of the given result, or kCFNotFound if the
865    /// value is not one of the query's existing results. If
866    /// you provided a custom result creation function,
867    /// as well as a custom object comparator function,
868    /// result will be objects created by that function.
869    #[doc(alias = "MDQueryGetIndexOfResult")]
870    #[inline]
871    pub unsafe fn index_of_result(self: &MDQuery, result: *const c_void) -> CFIndex {
872        extern "C-unwind" {
873            fn MDQueryGetIndexOfResult(query: &MDQuery, result: *const c_void) -> CFIndex;
874        }
875        unsafe { MDQueryGetIndexOfResult(self, result) }
876    }
877
878    /// Returns the value of the named attribute for the result at
879    /// the given index.
880    ///
881    /// Parameter `query`: The query to be interrogated.
882    ///
883    /// Parameter `name`: The attribute name for which to return the values.
884    /// If the attribute is not one of those requested in the
885    /// valueListAttrs or sortingAttrs parameters to one of
886    /// the query creation functions, the result will be NULL.
887    ///
888    /// Parameter `idx`: The index into the query's result list. If the index is
889    /// negative, or is equal to or larger than the current
890    /// number of results in the query, the behavior is undefined.
891    ///
892    /// Returns: The value of the attribute, or NULL if the attribute
893    /// doesn't exist in the query on that result.
894    #[doc(alias = "MDQueryGetAttributeValueOfResultAtIndex")]
895    #[inline]
896    pub unsafe fn attribute_value_of_result_at_index(
897        self: &MDQuery,
898        name: Option<&CFString>,
899        idx: CFIndex,
900    ) -> *mut c_void {
901        extern "C-unwind" {
902            fn MDQueryGetAttributeValueOfResultAtIndex(
903                query: &MDQuery,
904                name: Option<&CFString>,
905                idx: CFIndex,
906            ) -> *mut c_void;
907        }
908        unsafe { MDQueryGetAttributeValueOfResultAtIndex(self, name, idx) }
909    }
910
911    /// Returns the list of values, from the results of the query, of the
912    /// named attribute. The list is not ordered in any way. The
913    /// list contains only one occurrence of each value. Note that
914    /// this list may change over time, as the query's result list
915    /// is updated.
916    ///
917    /// Parameter `query`: The query to be interrogated.
918    ///
919    /// Parameter `name`: The attribute name for which to return the values.
920    /// If the attribute is not one of those requested in the
921    /// valueListAttrs parameter to one of the query creation
922    /// functions, the behavior is undefined.
923    ///
924    /// Returns: A CFArray holding the value objects for that attribute.
925    #[doc(alias = "MDQueryCopyValuesOfAttribute")]
926    #[inline]
927    pub unsafe fn values_of_attribute(
928        self: &MDQuery,
929        name: Option<&CFString>,
930    ) -> Option<CFRetained<CFArray>> {
931        extern "C-unwind" {
932            fn MDQueryCopyValuesOfAttribute(
933                query: &MDQuery,
934                name: Option<&CFString>,
935            ) -> Option<NonNull<CFArray>>;
936        }
937        let ret = unsafe { MDQueryCopyValuesOfAttribute(self, name) };
938        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
939    }
940
941    /// Returns the number of results which have the given attribute and
942    /// attribute value. Note that this count may change over time,
943    /// as the query's result list is updated.
944    ///
945    /// Parameter `query`: The query to be interrogated.
946    ///
947    /// Parameter `name`: The attribute name for which to return the number
948    /// of results with the given value. If the attribute is not
949    /// one of those requested in the valueListAttrs parameter to
950    /// one of the query creation functions, the behavior is
951    /// undefined.
952    ///
953    /// Parameter `value`: The attribute value for which to return the number
954    /// of results with that value. This parameter may be NULL,
955    /// in which case the number of results that do not contain
956    /// the named attribute is returned.
957    ///
958    /// Returns: The number of results with that attribute and value.
959    #[doc(alias = "MDQueryGetCountOfResultsWithAttributeValue")]
960    #[inline]
961    pub unsafe fn count_of_results_with_attribute_value(
962        self: &MDQuery,
963        name: Option<&CFString>,
964        value: Option<&CFType>,
965    ) -> CFIndex {
966        extern "C-unwind" {
967            fn MDQueryGetCountOfResultsWithAttributeValue(
968                query: &MDQuery,
969                name: Option<&CFString>,
970                value: Option<&CFType>,
971            ) -> CFIndex;
972        }
973        unsafe { MDQueryGetCountOfResultsWithAttributeValue(self, name, value) }
974    }
975
976    /// Sets the sort order for a query.
977    ///
978    /// Parameter `query`: The query for which the sort order is to be set.
979    ///
980    /// Parameter `sortingAttrs`: An array of attribute names, as in MDQueryCreate.
981    /// The query's result set will be sorted according to the order of
982    /// these attributes. All names in the array have to have been passed
983    /// as sortingAttrs when the query was created. The attribute names
984    /// are CFStrings
985    ///
986    /// Returns: A boolean, true on success, false on failure.
987    #[doc(alias = "MDQuerySetSortOrder")]
988    #[inline]
989    pub unsafe fn set_sort_order(self: &MDQuery, sorting_attrs: Option<&CFArray>) -> bool {
990        extern "C-unwind" {
991            fn MDQuerySetSortOrder(query: &MDQuery, sorting_attrs: Option<&CFArray>) -> Boolean;
992        }
993        let ret = unsafe { MDQuerySetSortOrder(self, sorting_attrs) };
994        ret != 0
995    }
996}
997
998/// [Apple's documentation](https://developer.apple.com/documentation/coreservices/mdquerysortoptionflags?language=objc)
999#[repr(transparent)]
1000#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
1001pub struct MDQuerySortOptionFlags(pub c_uint);
1002impl MDQuerySortOptionFlags {
1003    #[doc(alias = "kMDQueryReverseSortOrderFlag")]
1004    pub const ReverseSortOrderFlag: Self = Self(1 << 0);
1005}
1006
1007#[cfg(feature = "objc2")]
1008unsafe impl Encode for MDQuerySortOptionFlags {
1009    const ENCODING: Encoding = c_uint::ENCODING;
1010}
1011
1012#[cfg(feature = "objc2")]
1013unsafe impl RefEncode for MDQuerySortOptionFlags {
1014    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
1015}
1016
1017impl MDQuery {
1018    /// Sets the sort flags for a query.
1019    ///
1020    /// Parameter `query`: The query for which the sort flags is to be set.
1021    ///
1022    /// Parameter `fieldName`: The attribute name for which sort option flags are to be set.
1023    /// The attribute name must have been part of the sortingFlags when the query was created.
1024    ///
1025    /// Parameter `flags`: A uint32_t containing MDQuerySortOptionFlags to be applied to the attibute
1026    ///
1027    /// Returns: A boolean, true on success, false on failure.
1028    #[doc(alias = "MDQuerySetSortOptionFlagsForAttribute")]
1029    #[inline]
1030    pub unsafe fn set_sort_option_flags_for_attribute(
1031        self: &MDQuery,
1032        field_name: Option<&CFString>,
1033        flags: u32,
1034    ) -> bool {
1035        extern "C-unwind" {
1036            fn MDQuerySetSortOptionFlagsForAttribute(
1037                query: &MDQuery,
1038                field_name: Option<&CFString>,
1039                flags: u32,
1040            ) -> Boolean;
1041        }
1042        let ret = unsafe { MDQuerySetSortOptionFlagsForAttribute(self, field_name, flags) };
1043        ret != 0
1044    }
1045
1046    /// Gets the sort option flags for a sorting attribute.
1047    ///
1048    /// Parameter `query`: The query for which fetch sort option flags.
1049    ///
1050    /// Parameter `fieldName`: The attribute name for which sort option flags are to be fetched.
1051    ///
1052    /// Returns: A uint32_t, with MDQuerySortOptionFlags set for the attribute.
1053    #[doc(alias = "MDQueryGetSortOptionFlagsForAttribute")]
1054    #[inline]
1055    pub unsafe fn sort_option_flags_for_attribute(
1056        self: &MDQuery,
1057        field_name: Option<&CFString>,
1058    ) -> u32 {
1059        extern "C-unwind" {
1060            fn MDQueryGetSortOptionFlagsForAttribute(
1061                query: &MDQuery,
1062                field_name: Option<&CFString>,
1063            ) -> u32;
1064        }
1065        unsafe { MDQueryGetSortOptionFlagsForAttribute(self, field_name) }
1066    }
1067}
1068
1069/// Type of the callback function used to sort the results of an
1070/// MDQuery.
1071///
1072/// Parameter `query`: The MDQuery instance.
1073///
1074/// Parameter `attrs1`: A C array of attribute values for a result. The
1075/// values occur in the array in the same order and position
1076/// that the attribute names were passed in the sortingAttrs
1077/// array when the query was created. The values of the
1078/// attributes might be NULL, if the attribute doesn't exist
1079/// on a result or if read access to that attribute is not
1080/// allowed.
1081///
1082/// Parameter `attrs2`: A C array of attribute values for a result. The
1083/// values occur in the array in the same order and position
1084/// that the attribute names were passed in the sortingAttrs
1085/// array when the query was created. The values of the
1086/// attributes might be NULL, if the attribute doesn't exist
1087/// on a result or if read access to that attribute is not
1088/// allowed.
1089///
1090/// Parameter `context`: The user-defined context parameter given to
1091/// MDQuerySetSortComparator().
1092///
1093/// Returns: The function must return one of the CFComparisonResults
1094/// kCFCompareLessThan, kCFCompareEqualTo, or
1095/// kCFCompareGreaterThan. There is no provision for unordered
1096/// results. The comparison must be a total order relation,
1097/// and additionally produce temporally identical results (that
1098/// is, produce the same results for the same inputs in the
1099/// future as now), for the sort results to be predictable.
1100///
1101/// See also [Apple's documentation](https://developer.apple.com/documentation/coreservices/mdquerysortcomparatorfunction?language=objc)
1102pub type MDQuerySortComparatorFunction = Option<
1103    unsafe extern "C-unwind" fn(
1104        *mut *const CFType,
1105        *mut *const CFType,
1106        *mut c_void,
1107    ) -> CFComparisonResult,
1108>;
1109
1110impl MDQuery {
1111    /// Sets the function used to sort the results of an MDQuery. You
1112    /// may set the comparator function as many times as you
1113    /// like, even while the query is executing. Whenever the
1114    /// comparator function is set, all results are re-sorted
1115    /// using the new comparator function before the function
1116    /// returns. The function pointer can be NULL to cancel
1117    /// custom sorting and revert to the default sorting.
1118    /// The default sort provided by MDQueryCreate()
1119    /// is a assending sort strings are compared using
1120    /// CFStringCompare() with the options kCFCompareNonliteral |
1121    /// kCFCompareLocalized | kCFCompareNumerically. CFDataRefs are
1122    /// compared by using memcmp() of the data pointers.
1123    ///
1124    /// Parameter `query`: The query to whose result sort function is to be set.
1125    ///
1126    /// Parameter `func`: The callback function the MDQuery will use to
1127    /// sort its results. If the function (when the parameter is
1128    /// not NULL) is not of type MDQuerySortComparatorFunction or
1129    /// does not behave as a MDQuerySortComparatorFunction must,
1130    /// the behavior is undefined. The function pointer may
1131    /// be NULL to cancel any custom comparator.
1132    ///
1133    /// Parameter `context`: A pointer-sized user-defined value, which is
1134    /// passed as the third parameter to the sort function,
1135    /// but is otherwise unused by MDQuery. The MDQuery does
1136    /// not retain the context in any way, so it must remain
1137    /// valid for the lifetime of the query or until the sort
1138    /// function is set again. If the context is not what is
1139    /// expected by the comparator, the behavior is undefined.
1140    #[doc(alias = "MDQuerySetSortComparator")]
1141    #[inline]
1142    pub unsafe fn set_sort_comparator(
1143        self: &MDQuery,
1144        comparator: MDQuerySortComparatorFunction,
1145        context: *mut c_void,
1146    ) {
1147        extern "C-unwind" {
1148            fn MDQuerySetSortComparator(
1149                query: &MDQuery,
1150                comparator: MDQuerySortComparatorFunction,
1151                context: *mut c_void,
1152            );
1153        }
1154        unsafe { MDQuerySetSortComparator(self, comparator, context) }
1155    }
1156
1157    #[doc(alias = "MDQuerySetSortComparatorBlock")]
1158    #[cfg(feature = "block2")]
1159    #[inline]
1160    pub unsafe fn set_sort_comparator_block(
1161        self: &MDQuery,
1162        comparator: Option<
1163            &block2::DynBlock<dyn Fn(*mut *const CFType, *mut *const CFType) -> CFComparisonResult>,
1164        >,
1165    ) {
1166        extern "C-unwind" {
1167            fn MDQuerySetSortComparatorBlock(
1168                query: &MDQuery,
1169                comparator: Option<
1170                    &block2::DynBlock<
1171                        dyn Fn(*mut *const CFType, *mut *const CFType) -> CFComparisonResult,
1172                    >,
1173                >,
1174            );
1175        }
1176        unsafe { MDQuerySetSortComparatorBlock(self, comparator) }
1177    }
1178}
1179
1180extern "C" {
1181    /// The name of the notification sent to indicate changes to the
1182    /// query's results list during the initial gathering phase
1183    /// of a query's execution. Mostly adds will occur during
1184    /// this phase, but removals and changes can also occur, as
1185    /// in any update. This info dictionary parameter of the
1186    /// notification can carry the kMDQueryUpdateChangedItems
1187    /// and kMDQueryUpdateRemovedItems keys. Note that these
1188    /// keys may be have empty arrays for values, or be missing,
1189    /// if there are no changes of that particular type. For
1190    /// performance reasons, added results are not indicated in
1191    /// progress notifications (to avoid the cost of creating
1192    /// the result objects). These notifications are sent out
1193    /// by a query before the kMDQueryDidFinishNotification.
1194    ///
1195    /// See also [Apple's documentation](https://developer.apple.com/documentation/coreservices/kmdqueryprogressnotification?language=objc)
1196    pub static kMDQueryProgressNotification: Option<&'static CFString>;
1197}
1198
1199extern "C" {
1200    /// The name of the notification sent to indicate that the query has
1201    /// finished with the initial result-gathering phase, and may
1202    /// now proceed into the live-update phase (if that option
1203    /// was chosen when the query was executed). This notification
1204    /// often shortly follows after the last progress notification.
1205    /// It is usually not necessary to update any displayed UI in
1206    /// response to this notification, since it doesn't indicate
1207    /// any change in the result list of a query.
1208    ///
1209    /// See also [Apple's documentation](https://developer.apple.com/documentation/coreservices/kmdquerydidfinishnotification?language=objc)
1210    pub static kMDQueryDidFinishNotification: Option<&'static CFString>;
1211}
1212
1213extern "C" {
1214    /// The name of the notification sent to indicate changes to the
1215    /// query's results list during the second, live-update, phase
1216    /// of a query's execution. This notification can carry the
1217    /// kMDQueryUpdateAddedItems, kMDQueryUpdateChangedItems,
1218    /// and kMDQueryUpdateRemovedItems keys in the info
1219    /// dictionary parameter of the notification. Note that these
1220    /// keys may be have empty arrays for values, or be missing,
1221    /// if there are no changes of that particular type. These
1222    /// notifications are sent out by a query after the
1223    /// kMDQueryDidUpdateNotification.
1224    ///
1225    /// See also [Apple's documentation](https://developer.apple.com/documentation/coreservices/kmdquerydidupdatenotification?language=objc)
1226    pub static kMDQueryDidUpdateNotification: Option<&'static CFString>;
1227}
1228
1229extern "C" {
1230    /// The name of the key in a query notification's info dictionary
1231    /// which identifies the list of added results. A result is
1232    /// added if the file contents or some metadata attribute
1233    /// of it is changed, and it now matches the query. Result
1234    /// objects are created for the newly added results, to be
1235    /// put in the list.
1236    ///
1237    /// See also [Apple's documentation](https://developer.apple.com/documentation/coreservices/kmdqueryupdateaddeditems?language=objc)
1238    pub static kMDQueryUpdateAddedItems: Option<&'static CFString>;
1239}
1240
1241extern "C" {
1242    /// The name of the key in a query notification's info dictionary
1243    /// which identifies the list of changed results. A result
1244    /// is changed if the file contents or some metadata
1245    /// attribute of it is changed, but it still matches the
1246    /// query. The list only contains result objects which have
1247    /// previously been created, and does not indicate results
1248    /// which have been changed for which result objects have
1249    /// not been created.
1250    /// [[This is for performance reasons, to avoid creating
1251    /// result objects just to represent a change of a result
1252    /// which has not been looked at, but this semantic may
1253    /// change.]]
1254    ///
1255    /// See also [Apple's documentation](https://developer.apple.com/documentation/coreservices/kmdqueryupdatechangeditems?language=objc)
1256    pub static kMDQueryUpdateChangedItems: Option<&'static CFString>;
1257}
1258
1259extern "C" {
1260    /// The name of the key in a query notification's info dictionary
1261    /// which identifies the list of removed results. A result
1262    /// can be removed if it no longer matches the query. The
1263    /// list only contains result objects which have previously
1264    /// been created, and does not indicate results which have
1265    /// been removed for which result objects have not been
1266    /// created.
1267    /// [[This is for performance reasons, to avoid creating
1268    /// temporary result objects just to represent the deletion
1269    /// of the result, but this semantic may change.]]
1270    ///
1271    /// See also [Apple's documentation](https://developer.apple.com/documentation/coreservices/kmdqueryupdateremoveditems?language=objc)
1272    pub static kMDQueryUpdateRemovedItems: Option<&'static CFString>;
1273}
1274
1275extern "C" {
1276    /// The name of a query-specific attribute for use in sorting.
1277    /// The relevance of an item is a CFNumberRef with a
1278    /// floating point value. This is the relevance for
1279    /// content searches.
1280    /// The maximum and minimum values for a particular
1281    /// search cannot be determined until all of the results
1282    /// have been returned.  If there are multiple
1283    /// kMDItemTextContent predicates in the query, no
1284    /// relevance is returned.
1285    /// This is an attribute of a result item that is
1286    /// specific to the item in the context of the query.
1287    /// Also, the relevance does not compare the result
1288    /// relative to the other results of a query, but is
1289    /// computed just on the result item itself. Finally,
1290    /// this is only the relevance value for content,
1291    /// not a relevance for the item as a whole. The
1292    /// relevance attribute may not even be computed for
1293    /// an item if the item is found to match the query
1294    /// through evaluation of other attributes of the
1295    /// item than its contents. If the value is not
1296    /// computed, it is treated as an attribute on the
1297    /// item which does not exist (for sorting purposes,
1298    /// for example).
1299    ///
1300    /// See also [Apple's documentation](https://developer.apple.com/documentation/coreservices/kmdqueryresultcontentrelevance?language=objc)
1301    pub static kMDQueryResultContentRelevance: Option<&'static CFString>;
1302}
1303
1304impl MDQuery {
1305    /// Use MDQuerySetSearchScope to limit the results
1306    /// returned by the query engine to those MDItemRefs that
1307    /// appear  within the specified directories.  This may be
1308    /// used to limit searching to particular volumes. Tilde
1309    /// paths, or environment variables are not expanded.
1310    /// Calling this multiple times will replace the previous
1311    /// options. This must be called before the query is executed.
1312    ///
1313    /// Parameter `query`: The query object to modify.
1314    ///
1315    /// Parameter `scopeDirectories`: a CFArray of CFStringRef or CFURLRef objects which
1316    /// specify where to search.  For conveinience, the kMDQueryScopeHome,
1317    /// kMDQueryScopeComputer and kMDQueryScopeNetwork constants may also
1318    /// be present in this array.
1319    ///
1320    /// Parameter `scopeOptions`: additional options for modifying the search.
1321    /// Currently, pass 0 (zero).
1322    #[doc(alias = "MDQuerySetSearchScope")]
1323    #[inline]
1324    pub unsafe fn set_search_scope(
1325        self: &MDQuery,
1326        scope_directories: Option<&CFArray>,
1327        scope_options: OptionBits,
1328    ) {
1329        extern "C-unwind" {
1330            fn MDQuerySetSearchScope(
1331                query: &MDQuery,
1332                scope_directories: Option<&CFArray>,
1333                scope_options: OptionBits,
1334            );
1335        }
1336        unsafe { MDQuerySetSearchScope(self, scope_directories, scope_options) }
1337    }
1338}
1339
1340extern "C" {
1341    /// A constant, which can be passed in the scopeDirectories array, to specify
1342    /// that the search should be restricted to the volume and directory that contains
1343    /// the current user's home directory
1344    ///
1345    /// See also [Apple's documentation](https://developer.apple.com/documentation/coreservices/kmdqueryscopehome?language=objc)
1346    pub static kMDQueryScopeHome: Option<&'static CFString>;
1347}
1348
1349extern "C" {
1350    /// A constant, which can be passed in the scopeDirectories array, to specify
1351    /// that the search should be restricted to all locally mounted volumes, plus the user's
1352    /// home directory (which may be on a remote volume).
1353    ///
1354    /// See also [Apple's documentation](https://developer.apple.com/documentation/coreservices/kmdqueryscopecomputer?language=objc)
1355    pub static kMDQueryScopeComputer: Option<&'static CFString>;
1356}
1357
1358extern "C" {
1359    /// A constant, which can be passed in the scopeDirectories array, to specify
1360    /// that the search should include all user mounted remote volumes.
1361    ///
1362    /// See also [Apple's documentation](https://developer.apple.com/documentation/coreservices/kmdqueryscopenetwork?language=objc)
1363    pub static kMDQueryScopeNetwork: Option<&'static CFString>;
1364}
1365
1366extern "C" {
1367    /// A constant, which can be passed in the scopeDirectories array, to specify
1368    /// that the search should be restricted to indexed, locally mounted volumes and
1369    /// indexed user mounted remote volumes, plus the user's home directory.
1370    ///
1371    /// See also [Apple's documentation](https://developer.apple.com/documentation/coreservices/kmdqueryscopeallindexed?language=objc)
1372    pub static kMDQueryScopeAllIndexed: Option<&'static CFString>;
1373}
1374
1375extern "C" {
1376    /// A constant, which can be passed in the scopeDirectories array, to specify
1377    /// that the search should be restricted to indexed, locally mounted volumes, plus the user's
1378    /// home directory (which may be on a remote volume).
1379    ///
1380    /// See also [Apple's documentation](https://developer.apple.com/documentation/coreservices/kmdqueryscopecomputerindexed?language=objc)
1381    pub static kMDQueryScopeComputerIndexed: Option<&'static CFString>;
1382}
1383
1384extern "C" {
1385    /// A constant, which can be passed in the scopeDirectories array, to specify
1386    /// that the search should include indexed user mounted remote volumes.
1387    ///
1388    /// See also [Apple's documentation](https://developer.apple.com/documentation/coreservices/kmdqueryscopenetworkindexed?language=objc)
1389    pub static kMDQueryScopeNetworkIndexed: Option<&'static CFString>;
1390}
1391
1392impl MDQuery {
1393    /// Use MDQuerySetMaxCount to limit the number of results
1394    /// returned by the query engine.  This must be called before the query is executed.
1395    ///
1396    /// Parameter `query`: The query object to modify.
1397    ///
1398    /// Parameter `size`: The maximum number of results desired.
1399    #[doc(alias = "MDQuerySetMaxCount")]
1400    #[inline]
1401    pub unsafe fn set_max_count(self: &MDQuery, size: CFIndex) {
1402        extern "C-unwind" {
1403            fn MDQuerySetMaxCount(query: &MDQuery, size: CFIndex);
1404        }
1405        unsafe { MDQuerySetMaxCount(self, size) }
1406    }
1407}
1408
1409#[deprecated = "renamed to `MDQuery::new`"]
1410#[inline]
1411pub unsafe extern "C-unwind" fn MDQueryCreate(
1412    allocator: Option<&CFAllocator>,
1413    query_string: Option<&CFString>,
1414    value_list_attrs: Option<&CFArray>,
1415    sorting_attrs: Option<&CFArray>,
1416) -> Option<CFRetained<MDQuery>> {
1417    extern "C-unwind" {
1418        fn MDQueryCreate(
1419            allocator: Option<&CFAllocator>,
1420            query_string: Option<&CFString>,
1421            value_list_attrs: Option<&CFArray>,
1422            sorting_attrs: Option<&CFArray>,
1423        ) -> Option<NonNull<MDQuery>>;
1424    }
1425    let ret = unsafe { MDQueryCreate(allocator, query_string, value_list_attrs, sorting_attrs) };
1426    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1427}
1428
1429#[deprecated = "renamed to `MDQuery::new_subset`"]
1430#[inline]
1431pub unsafe extern "C-unwind" fn MDQueryCreateSubset(
1432    allocator: Option<&CFAllocator>,
1433    query: Option<&MDQuery>,
1434    query_string: Option<&CFString>,
1435    value_list_attrs: Option<&CFArray>,
1436    sorting_attrs: Option<&CFArray>,
1437) -> Option<CFRetained<MDQuery>> {
1438    extern "C-unwind" {
1439        fn MDQueryCreateSubset(
1440            allocator: Option<&CFAllocator>,
1441            query: Option<&MDQuery>,
1442            query_string: Option<&CFString>,
1443            value_list_attrs: Option<&CFArray>,
1444            sorting_attrs: Option<&CFArray>,
1445        ) -> Option<NonNull<MDQuery>>;
1446    }
1447    let ret = unsafe {
1448        MDQueryCreateSubset(
1449            allocator,
1450            query,
1451            query_string,
1452            value_list_attrs,
1453            sorting_attrs,
1454        )
1455    };
1456    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1457}
1458
1459#[deprecated = "renamed to `MDQuery::new_for_items`"]
1460#[inline]
1461pub unsafe extern "C-unwind" fn MDQueryCreateForItems(
1462    allocator: Option<&CFAllocator>,
1463    query_string: Option<&CFString>,
1464    value_list_attrs: Option<&CFArray>,
1465    sorting_attrs: Option<&CFArray>,
1466    items: Option<&CFArray>,
1467) -> Option<CFRetained<MDQuery>> {
1468    extern "C-unwind" {
1469        fn MDQueryCreateForItems(
1470            allocator: Option<&CFAllocator>,
1471            query_string: Option<&CFString>,
1472            value_list_attrs: Option<&CFArray>,
1473            sorting_attrs: Option<&CFArray>,
1474            items: Option<&CFArray>,
1475        ) -> Option<NonNull<MDQuery>>;
1476    }
1477    let ret = unsafe {
1478        MDQueryCreateForItems(
1479            allocator,
1480            query_string,
1481            value_list_attrs,
1482            sorting_attrs,
1483            items,
1484        )
1485    };
1486    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1487}
1488
1489#[deprecated = "renamed to `MDQuery::query_string`"]
1490#[inline]
1491pub unsafe extern "C-unwind" fn MDQueryCopyQueryString(
1492    query: &MDQuery,
1493) -> Option<CFRetained<CFString>> {
1494    extern "C-unwind" {
1495        fn MDQueryCopyQueryString(query: &MDQuery) -> Option<NonNull<CFString>>;
1496    }
1497    let ret = unsafe { MDQueryCopyQueryString(query) };
1498    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1499}
1500
1501#[deprecated = "renamed to `MDQuery::value_list_attributes`"]
1502#[inline]
1503pub unsafe extern "C-unwind" fn MDQueryCopyValueListAttributes(
1504    query: &MDQuery,
1505) -> Option<CFRetained<CFArray>> {
1506    extern "C-unwind" {
1507        fn MDQueryCopyValueListAttributes(query: &MDQuery) -> Option<NonNull<CFArray>>;
1508    }
1509    let ret = unsafe { MDQueryCopyValueListAttributes(query) };
1510    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1511}
1512
1513#[deprecated = "renamed to `MDQuery::sorting_attributes`"]
1514#[inline]
1515pub unsafe extern "C-unwind" fn MDQueryCopySortingAttributes(
1516    query: &MDQuery,
1517) -> Option<CFRetained<CFArray>> {
1518    extern "C-unwind" {
1519        fn MDQueryCopySortingAttributes(query: &MDQuery) -> Option<NonNull<CFArray>>;
1520    }
1521    let ret = unsafe { MDQueryCopySortingAttributes(query) };
1522    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1523}
1524
1525extern "C-unwind" {
1526    #[deprecated = "renamed to `MDQuery::batching_parameters`"]
1527    pub fn MDQueryGetBatchingParameters(query: &MDQuery) -> MDQueryBatchingParams;
1528}
1529
1530extern "C-unwind" {
1531    #[deprecated = "renamed to `MDQuery::set_batching_parameters`"]
1532    pub fn MDQuerySetBatchingParameters(query: &MDQuery, params: MDQueryBatchingParams);
1533}
1534
1535extern "C-unwind" {
1536    #[cfg(feature = "MDItem")]
1537    #[deprecated = "renamed to `MDQuery::set_create_result_function`"]
1538    pub fn MDQuerySetCreateResultFunction(
1539        query: &MDQuery,
1540        func: MDQueryCreateResultFunction,
1541        context: *mut c_void,
1542        cb: *const CFArrayCallBacks,
1543    );
1544}
1545
1546extern "C-unwind" {
1547    #[deprecated = "renamed to `MDQuery::set_create_value_function`"]
1548    pub fn MDQuerySetCreateValueFunction(
1549        query: &MDQuery,
1550        func: MDQueryCreateValueFunction,
1551        context: *mut c_void,
1552        cb: *const CFArrayCallBacks,
1553    );
1554}
1555
1556extern "C-unwind" {
1557    #[cfg(feature = "dispatch2")]
1558    #[deprecated = "renamed to `MDQuery::set_dispatch_queue`"]
1559    pub fn MDQuerySetDispatchQueue(query: &MDQuery, queue: Option<&DispatchQueue>);
1560}
1561
1562#[deprecated = "renamed to `MDQuery::execute`"]
1563#[inline]
1564pub unsafe extern "C-unwind" fn MDQueryExecute(
1565    query: &MDQuery,
1566    option_flags: CFOptionFlags,
1567) -> bool {
1568    extern "C-unwind" {
1569        fn MDQueryExecute(query: &MDQuery, option_flags: CFOptionFlags) -> Boolean;
1570    }
1571    let ret = unsafe { MDQueryExecute(query, option_flags) };
1572    ret != 0
1573}
1574
1575extern "C-unwind" {
1576    #[deprecated = "renamed to `MDQuery::stop`"]
1577    pub fn MDQueryStop(query: &MDQuery);
1578}
1579
1580extern "C-unwind" {
1581    #[deprecated = "renamed to `MDQuery::disable_updates`"]
1582    pub fn MDQueryDisableUpdates(query: &MDQuery);
1583}
1584
1585extern "C-unwind" {
1586    #[deprecated = "renamed to `MDQuery::enable_updates`"]
1587    pub fn MDQueryEnableUpdates(query: &MDQuery);
1588}
1589
1590#[deprecated = "renamed to `MDQuery::is_gathering_complete`"]
1591#[inline]
1592pub unsafe extern "C-unwind" fn MDQueryIsGatheringComplete(query: &MDQuery) -> bool {
1593    extern "C-unwind" {
1594        fn MDQueryIsGatheringComplete(query: &MDQuery) -> Boolean;
1595    }
1596    let ret = unsafe { MDQueryIsGatheringComplete(query) };
1597    ret != 0
1598}
1599
1600extern "C-unwind" {
1601    #[deprecated = "renamed to `MDQuery::result_count`"]
1602    pub fn MDQueryGetResultCount(query: &MDQuery) -> CFIndex;
1603}
1604
1605extern "C-unwind" {
1606    #[deprecated = "renamed to `MDQuery::result_at_index`"]
1607    pub fn MDQueryGetResultAtIndex(query: &MDQuery, idx: CFIndex) -> *const c_void;
1608}
1609
1610extern "C-unwind" {
1611    #[deprecated = "renamed to `MDQuery::index_of_result`"]
1612    pub fn MDQueryGetIndexOfResult(query: &MDQuery, result: *const c_void) -> CFIndex;
1613}
1614
1615extern "C-unwind" {
1616    #[deprecated = "renamed to `MDQuery::attribute_value_of_result_at_index`"]
1617    pub fn MDQueryGetAttributeValueOfResultAtIndex(
1618        query: &MDQuery,
1619        name: Option<&CFString>,
1620        idx: CFIndex,
1621    ) -> *mut c_void;
1622}
1623
1624#[deprecated = "renamed to `MDQuery::values_of_attribute`"]
1625#[inline]
1626pub unsafe extern "C-unwind" fn MDQueryCopyValuesOfAttribute(
1627    query: &MDQuery,
1628    name: Option<&CFString>,
1629) -> Option<CFRetained<CFArray>> {
1630    extern "C-unwind" {
1631        fn MDQueryCopyValuesOfAttribute(
1632            query: &MDQuery,
1633            name: Option<&CFString>,
1634        ) -> Option<NonNull<CFArray>>;
1635    }
1636    let ret = unsafe { MDQueryCopyValuesOfAttribute(query, name) };
1637    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1638}
1639
1640extern "C-unwind" {
1641    #[deprecated = "renamed to `MDQuery::count_of_results_with_attribute_value`"]
1642    pub fn MDQueryGetCountOfResultsWithAttributeValue(
1643        query: &MDQuery,
1644        name: Option<&CFString>,
1645        value: Option<&CFType>,
1646    ) -> CFIndex;
1647}
1648
1649#[deprecated = "renamed to `MDQuery::set_sort_order`"]
1650#[inline]
1651pub unsafe extern "C-unwind" fn MDQuerySetSortOrder(
1652    query: &MDQuery,
1653    sorting_attrs: Option<&CFArray>,
1654) -> bool {
1655    extern "C-unwind" {
1656        fn MDQuerySetSortOrder(query: &MDQuery, sorting_attrs: Option<&CFArray>) -> Boolean;
1657    }
1658    let ret = unsafe { MDQuerySetSortOrder(query, sorting_attrs) };
1659    ret != 0
1660}
1661
1662#[deprecated = "renamed to `MDQuery::set_sort_option_flags_for_attribute`"]
1663#[inline]
1664pub unsafe extern "C-unwind" fn MDQuerySetSortOptionFlagsForAttribute(
1665    query: &MDQuery,
1666    field_name: Option<&CFString>,
1667    flags: u32,
1668) -> bool {
1669    extern "C-unwind" {
1670        fn MDQuerySetSortOptionFlagsForAttribute(
1671            query: &MDQuery,
1672            field_name: Option<&CFString>,
1673            flags: u32,
1674        ) -> Boolean;
1675    }
1676    let ret = unsafe { MDQuerySetSortOptionFlagsForAttribute(query, field_name, flags) };
1677    ret != 0
1678}
1679
1680extern "C-unwind" {
1681    #[deprecated = "renamed to `MDQuery::sort_option_flags_for_attribute`"]
1682    pub fn MDQueryGetSortOptionFlagsForAttribute(
1683        query: &MDQuery,
1684        field_name: Option<&CFString>,
1685    ) -> u32;
1686}
1687
1688extern "C-unwind" {
1689    #[deprecated = "renamed to `MDQuery::set_sort_comparator`"]
1690    pub fn MDQuerySetSortComparator(
1691        query: &MDQuery,
1692        comparator: MDQuerySortComparatorFunction,
1693        context: *mut c_void,
1694    );
1695}
1696
1697extern "C-unwind" {
1698    #[cfg(feature = "block2")]
1699    #[deprecated = "renamed to `MDQuery::set_sort_comparator_block`"]
1700    pub fn MDQuerySetSortComparatorBlock(
1701        query: &MDQuery,
1702        comparator: Option<
1703            &block2::DynBlock<dyn Fn(*mut *const CFType, *mut *const CFType) -> CFComparisonResult>,
1704        >,
1705    );
1706}
1707
1708extern "C-unwind" {
1709    #[deprecated = "renamed to `MDQuery::set_search_scope`"]
1710    pub fn MDQuerySetSearchScope(
1711        query: &MDQuery,
1712        scope_directories: Option<&CFArray>,
1713        scope_options: OptionBits,
1714    );
1715}
1716
1717extern "C-unwind" {
1718    #[deprecated = "renamed to `MDQuery::set_max_count`"]
1719    pub fn MDQuerySetMaxCount(query: &MDQuery, size: CFIndex);
1720}