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