objc2_core_services/generated/LaunchServices/
LSInfo.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ptr::NonNull;
4#[cfg(feature = "objc2")]
5use objc2::__framework_prelude::*;
6use objc2_core_foundation::*;
7
8use crate::*;
9
10/// [Apple's documentation](https://developer.apple.com/documentation/coreservices/lsacceptanceflags?language=objc)
11// NS_OPTIONS
12#[repr(transparent)]
13#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
14pub struct LSAcceptanceFlags(pub OptionBits);
15bitflags::bitflags! {
16    impl LSAcceptanceFlags: OptionBits {
17        #[doc(alias = "kLSAcceptDefault")]
18        const AcceptDefault = 0x00000001;
19        #[doc(alias = "kLSAcceptAllowLoginUI")]
20        const AcceptAllowLoginUI = 0x00000002;
21    }
22}
23
24#[cfg(feature = "objc2")]
25unsafe impl Encode for LSAcceptanceFlags {
26    const ENCODING: Encoding = OptionBits::ENCODING;
27}
28
29#[cfg(feature = "objc2")]
30unsafe impl RefEncode for LSAcceptanceFlags {
31    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
32}
33
34/// Return the application used to open an item.
35///
36///
37/// Consults the binding tables to return the application that would
38/// be used to open inURL if it were double-clicked in the
39/// Finder. This application will be the user-specified override if
40/// appropriate or the default otherwise.
41///
42///
43/// Parameter `inURL`: The URL of the item for which the application is requested.
44///
45///
46/// Parameter `inRoleMask`: Whether to return the editor or viewer for inURL. If you
47/// don't care which, use kLSRolesAll.
48///
49///
50/// Parameter `outError`: On failure, set to a CFError describing the problem. If you are
51/// not interested in this information, pass NULL. The caller is
52/// responsible for releasing this object.
53///
54///
55/// Returns: If an acceptable application is found, its URL is returned.
56/// If the URL is a file:// URL, the application bound to the specified
57/// file or directory's type is returned. If the URL's scheme is something
58/// else, its default scheme handler is returned. If no application could
59/// be found, NULL is returned and outError (if not NULL) is populated.
60/// with kLSApplicationNotFoundErr.
61/// The caller is responsible for releasing this URL.
62///
63/// # Safety
64///
65/// `out_error` must be a valid pointer or null.
66#[cfg(feature = "LSConstants")]
67#[deprecated = "Use -[NSWorkspace URLForApplicationToOpenURL:] instead."]
68#[inline]
69pub unsafe extern "C-unwind" fn LSCopyDefaultApplicationURLForURL(
70    in_url: &CFURL,
71    in_role_mask: LSRolesMask,
72    out_error: *mut *mut CFError,
73) -> Option<CFRetained<CFURL>> {
74    extern "C-unwind" {
75        fn LSCopyDefaultApplicationURLForURL(
76            in_url: &CFURL,
77            in_role_mask: LSRolesMask,
78            out_error: *mut *mut CFError,
79        ) -> Option<NonNull<CFURL>>;
80    }
81    let ret = unsafe { LSCopyDefaultApplicationURLForURL(in_url, in_role_mask, out_error) };
82    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
83}
84
85/// Return the application used to open a content type (UTI).
86///
87///
88/// Consults the binding tables to return the application that would
89/// be used to open a file of type inContentType if it were double-clicked
90/// in the Finder. This application will be the user-specified override if
91/// appropriate or the default otherwise.
92///
93///
94/// Parameter `inContentType`: The Uniform Type Identifier (UTI) of the item for which the
95/// application is requested.
96///
97///
98/// Parameter `inRoleMask`: Whether to return the editor or viewer for inContentType. If you
99/// don't care which, use kLSRolesAll.
100///
101///
102/// Parameter `outError`: On failure, set to a CFError describing the problem. If you are
103/// not interested in this information, pass NULL. The caller is
104/// responsible for releasing this object.
105///
106///
107/// Returns: If an acceptable application is found, its URL is returned.
108/// If no application could be found, NULL is returned and
109/// outError (if not NULL) is populated with kLSApplicationNotFoundErr.
110/// The caller is responsible for releasing this URL.
111///
112/// # Safety
113///
114/// `out_error` must be a valid pointer or null.
115#[cfg(feature = "LSConstants")]
116#[deprecated = "Use -[NSWorkspace URLForApplicationToOpenContentType:] instead."]
117#[inline]
118pub unsafe extern "C-unwind" fn LSCopyDefaultApplicationURLForContentType(
119    in_content_type: &CFString,
120    in_role_mask: LSRolesMask,
121    out_error: *mut *mut CFError,
122) -> Option<CFRetained<CFURL>> {
123    extern "C-unwind" {
124        fn LSCopyDefaultApplicationURLForContentType(
125            in_content_type: &CFString,
126            in_role_mask: LSRolesMask,
127            out_error: *mut *mut CFError,
128        ) -> Option<NonNull<CFURL>>;
129    }
130    let ret = unsafe {
131        LSCopyDefaultApplicationURLForContentType(in_content_type, in_role_mask, out_error)
132    };
133    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
134}
135
136/// Given a bundle identifier (such as com.apple.finder), find all URLs to the corresponding application.
137///
138///
139/// Returns zero or more URLs to applications that have the specified
140/// bundle identifier.
141///
142///
143/// Parameter `inBundleIdentifier`: The bundle identifier of interest, such as "com.apple.finder". Must
144/// not be NULL.
145///
146///
147/// Parameter `outError`: On failure, set to a CFError describing the problem. If you are
148/// not interested in this information, pass NULL. The caller is
149/// responsible for releasing this object.
150///
151///
152/// Returns: If any applications with the specified bundle identifier are found,
153/// their URLs are returned in a CFArray. If no application could be found,
154/// NULL is returned and outError (if not NULL) is populated with kLSApplicationNotFoundErr.
155/// In macOS 10.15 and later, the returned array is sorted with the first element containing the
156/// best available application with the specified bundle identifier. Prior to macOS 10.15, the
157/// order of elements in the array was undefined.
158///
159/// # Safety
160///
161/// `out_error` must be a valid pointer or null.
162#[deprecated = "Use -[NSWorkspace URLsForApplicationsWithBundleIdentifier:] instead."]
163#[inline]
164pub unsafe extern "C-unwind" fn LSCopyApplicationURLsForBundleIdentifier(
165    in_bundle_identifier: &CFString,
166    out_error: *mut *mut CFError,
167) -> Option<CFRetained<CFArray>> {
168    extern "C-unwind" {
169        fn LSCopyApplicationURLsForBundleIdentifier(
170            in_bundle_identifier: &CFString,
171            out_error: *mut *mut CFError,
172        ) -> Option<NonNull<CFArray>>;
173    }
174    let ret = unsafe { LSCopyApplicationURLsForBundleIdentifier(in_bundle_identifier, out_error) };
175    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
176}
177
178/// Returns an array of URLs to applications that offer the requested
179/// role(s) for the input item.
180///
181///
182/// Parameter `inURL`: The CFURLRef of the item for which all suitable applications
183/// are desired. If the URL is a file URL, it is treated as a
184/// document, and applications are selected based on the document's
185/// type information. Otherwise, applications are selected based on
186/// the URL's scheme.
187///
188///
189/// Parameter `inRoleMask`: The role(s) which must intersect with the role provided by an
190/// application for the specified item in order for the application
191/// to be included in the result. Pass kLSRolesAll if any role is
192/// acceptable.
193///
194///
195/// Returns: An array of CFURLRefs, one for each application which can open
196/// inURL with at least one of the roles in inRoleMask, or NULL if no
197/// applications can open the item. When an array is returned, you
198/// must eventually release it.
199///
200/// The order of the resulting array is undefined. If you need the
201/// default application for the specified URL, use LSCopyDefaultApplicationURLForURL.
202#[cfg(feature = "LSConstants")]
203#[deprecated = "Use -[NSWorkspace URLsForApplicationsToOpenURL:] instead."]
204#[inline]
205pub unsafe extern "C-unwind" fn LSCopyApplicationURLsForURL(
206    in_url: &CFURL,
207    in_role_mask: LSRolesMask,
208) -> Option<CFRetained<CFArray>> {
209    extern "C-unwind" {
210        fn LSCopyApplicationURLsForURL(
211            in_url: &CFURL,
212            in_role_mask: LSRolesMask,
213        ) -> Option<NonNull<CFArray>>;
214    }
215    let ret = unsafe { LSCopyApplicationURLsForURL(in_url, in_role_mask) };
216    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
217}
218
219extern "C-unwind" {
220    /// Determine whether an item can accept another item.
221    ///
222    ///
223    /// Returns in outAcceptsItem whether inTargetURL can accept
224    /// inItemURL as in a drag and drop operation. If inRoleMask is other
225    /// than kLSRolesAll then make sure inTargetRef claims to fulfill the
226    /// requested role.
227    ///
228    ///
229    /// Parameter `inItemURL`: CFURLRef of the item about which acceptance is requested.
230    ///
231    ///
232    /// Parameter `inTargetURL`: CFURLRef of the potential target.
233    ///
234    ///
235    /// Parameter `inRoleMask`: The role(s) the target must claim in order to consider
236    /// acceptance.
237    ///
238    ///
239    /// Parameter `inFlags`: Use kLSAcceptDefault.
240    ///
241    ///
242    /// Parameter `outAcceptsItem`: Filled in with result. Must not be NULL.
243    ///
244    /// # Safety
245    ///
246    /// `out_accepts_item` must be a valid pointer.
247    #[cfg(feature = "LSConstants")]
248    pub fn LSCanURLAcceptURL(
249        in_item_url: &CFURL,
250        in_target_url: &CFURL,
251        in_role_mask: LSRolesMask,
252        in_flags: LSAcceptanceFlags,
253        out_accepts_item: NonNull<Boolean>,
254    ) -> OSStatus;
255}
256
257/// If the specified URL refers to an application or other bundle
258/// claiming to handle documents or URLs, add the bundle's document
259/// and URL claims to the Launch Services database.
260///
261///
262/// Parameter `inURL`: The CFURLRef of the item (a directory or file) to be registered.
263///
264///
265/// Parameter `inUpdate`: When false, LSRegisterURL does not register the item if it has
266/// already been registered and the current modification date of
267/// the item has not changed from when it was last registered. When
268/// true, the item's registered info is updated, even if the
269/// modification has not changed.
270///
271///
272/// Returns: An OSStatus value: noErr - Success kLSNoRegistrationInfoErr - The
273/// item does not contain info requiring registration kLSDataErr -
274/// The item's property list info is malformed.
275#[inline]
276pub unsafe extern "C-unwind" fn LSRegisterURL(in_url: &CFURL, in_update: bool) -> OSStatus {
277    extern "C-unwind" {
278        fn LSRegisterURL(in_url: &CFURL, in_update: Boolean) -> OSStatus;
279    }
280    unsafe { LSRegisterURL(in_url, in_update as _) }
281}
282
283/// Returns the application bundle identifier of the default handler
284/// for the specified content type (UTI), in the specified role(s).
285/// For any role, specify kLSRolesAll. Returns NULL if no handler
286/// is available.
287///
288///
289/// Parameter `inContentType`: a string UTI type identifier
290///
291/// Parameter `inRole`: a LSRole
292///
293///
294/// Returns: an application bundle identifier which is the default handler for the given type and role, or NULL if there is no default handler
295#[cfg(feature = "LSConstants")]
296#[deprecated = "Use -[NSWorkspace URLForApplicationToOpenContentType:] instead."]
297#[inline]
298pub unsafe extern "C-unwind" fn LSCopyDefaultRoleHandlerForContentType(
299    in_content_type: &CFString,
300    in_role: LSRolesMask,
301) -> Option<CFRetained<CFString>> {
302    extern "C-unwind" {
303        fn LSCopyDefaultRoleHandlerForContentType(
304            in_content_type: &CFString,
305            in_role: LSRolesMask,
306        ) -> Option<NonNull<CFString>>;
307    }
308    let ret = unsafe { LSCopyDefaultRoleHandlerForContentType(in_content_type, in_role) };
309    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
310}
311
312/// Returns an array of application bundle identifiers for
313/// applications capable of handling the specified content type
314/// (UTI) with the specified role(s). Application content handling
315/// capabilities are determined according to the kCFBundleDocumentTypes
316/// listed in an application's Info.plist). For any role, specify kLSRolesAll.
317/// Returns NULL if no handlers are available.
318///
319///
320/// Parameter `inContentType`: a string UTI type identifier
321///
322/// Parameter `inRole`: a LSRole
323///
324///
325/// Returns: an array of of CFStringRef bundle identifiers, or NULL
326#[cfg(feature = "LSConstants")]
327#[deprecated = "Use -[NSWorkspace URLsForApplicationsToOpenContentType:] instead."]
328#[inline]
329pub unsafe extern "C-unwind" fn LSCopyAllRoleHandlersForContentType(
330    in_content_type: &CFString,
331    in_role: LSRolesMask,
332) -> Option<CFRetained<CFArray>> {
333    extern "C-unwind" {
334        fn LSCopyAllRoleHandlersForContentType(
335            in_content_type: &CFString,
336            in_role: LSRolesMask,
337        ) -> Option<NonNull<CFArray>>;
338    }
339    let ret = unsafe { LSCopyAllRoleHandlersForContentType(in_content_type, in_role) };
340    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
341}
342
343extern "C-unwind" {
344    /// Sets the user's preferred handler for the specified content
345    /// type (UTI) in the specified role(s). For all roles, specify
346    /// kLSRolesAll. The handler is specified as an application
347    /// bundle identifier.
348    ///
349    ///
350    /// Parameter `inContentType`: a string UTI type identifier
351    ///
352    /// Parameter `inRole`: the role type(s) to set
353    ///
354    /// Parameter `inHandlerBundleID`: the bundle identifier to set as the default handler for the given contet type and role(s)
355    ///
356    ///
357    /// Returns: noErr on success, or an error indicating why the call failed
358    #[cfg(feature = "LSConstants")]
359    #[deprecated = "Use -[NSWorkspace setDefaultApplicationAtURL:toOpenContentType:completionHandler:] instead."]
360    pub fn LSSetDefaultRoleHandlerForContentType(
361        in_content_type: &CFString,
362        in_role: LSRolesMask,
363        in_handler_bundle_id: &CFString,
364    ) -> OSStatus;
365}
366
367/// Returns the bundle identifier of the default handler for
368/// the specified URL scheme. Returns NULL if no handler
369/// is available.
370///
371///
372/// Parameter `inURLScheme`: the scheme to return the default handler bundle identifier for
373///
374///
375/// Returns: a CFStringRef bundle identifier of the default handler, or NULL if no handler is available
376#[deprecated = "Use -[NSWorkspace URLForApplicationToOpenURL:] instead."]
377#[inline]
378pub unsafe extern "C-unwind" fn LSCopyDefaultHandlerForURLScheme(
379    in_url_scheme: &CFString,
380) -> Option<CFRetained<CFString>> {
381    extern "C-unwind" {
382        fn LSCopyDefaultHandlerForURLScheme(in_url_scheme: &CFString) -> Option<NonNull<CFString>>;
383    }
384    let ret = unsafe { LSCopyDefaultHandlerForURLScheme(in_url_scheme) };
385    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
386}
387
388/// Returns an array of application bundle identifiers for
389/// applications capable of handling the specified URL scheme.
390/// URL handling capability is determined according to the
391/// kCFBundleURLTypes listed in an application's Info.plist).
392/// Returns NULL if no handlers are available.
393///
394///
395/// Parameter `inURLScheme`: the scheme to return an array of bundle identifiers for applications capable of handling the scheme
396///
397///
398/// Returns: An array of bundle identifier strings
399#[deprecated = "Use -[NSWorkspace URLsForApplicationsToOpenURL:] instead."]
400#[inline]
401pub unsafe extern "C-unwind" fn LSCopyAllHandlersForURLScheme(
402    in_url_scheme: &CFString,
403) -> Option<CFRetained<CFArray>> {
404    extern "C-unwind" {
405        fn LSCopyAllHandlersForURLScheme(in_url_scheme: &CFString) -> Option<NonNull<CFArray>>;
406    }
407    let ret = unsafe { LSCopyAllHandlersForURLScheme(in_url_scheme) };
408    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
409}
410
411extern "C-unwind" {
412    /// Sets the user's preferred handler for the specified URL
413    /// scheme. The handler is specified as an application
414    /// bundle identifier.
415    ///
416    ///
417    /// Parameter `inURLScheme`: the url scheme to set a default handler for
418    ///
419    /// Parameter `inHandlerBundleID`: the bundle identifier to be set as the default handler for the given scheme
420    #[deprecated = "Use -[NSWorkspace setDefaultApplicationAtURL:toOpenURLsWithScheme:completionHandler:] instead."]
421    pub fn LSSetDefaultHandlerForURLScheme(
422        in_url_scheme: &CFString,
423        in_handler_bundle_id: &CFString,
424    ) -> OSStatus;
425}