gio/auto/
functions.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{
6    AsyncResult, BusType, Cancellable, DBusConnection, File, IOErrorEnum, IOStream, Icon,
7    InputStream, Resource, ResourceLookupFlags, SettingsBackend, ffi,
8};
9use glib::{prelude::*, translate::*};
10use std::{boxed::Box as Box_, pin::Pin};
11
12/// Asynchronously connects to the message bus specified by @bus_type.
13///
14/// When the operation is finished, @callback will be invoked. You can
15/// then call g_bus_get_finish() to get the result of the operation.
16///
17/// This is an asynchronous failable function. See g_bus_get_sync() for
18/// the synchronous version.
19/// ## `bus_type`
20/// a #GBusType
21/// ## `cancellable`
22/// a #GCancellable or [`None`]
23/// ## `callback`
24/// a #GAsyncReadyCallback to call when the request is satisfied
25#[doc(alias = "g_bus_get")]
26pub fn bus_get<P: FnOnce(Result<DBusConnection, glib::Error>) + 'static>(
27    bus_type: BusType,
28    cancellable: Option<&impl IsA<Cancellable>>,
29    callback: P,
30) {
31    let main_context = glib::MainContext::ref_thread_default();
32    let is_main_context_owner = main_context.is_owner();
33    let has_acquired_main_context = (!is_main_context_owner)
34        .then(|| main_context.acquire().ok())
35        .flatten();
36    assert!(
37        is_main_context_owner || has_acquired_main_context.is_some(),
38        "Async operations only allowed if the thread is owning the MainContext"
39    );
40
41    let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
42        Box_::new(glib::thread_guard::ThreadGuard::new(callback));
43    unsafe extern "C" fn bus_get_trampoline<
44        P: FnOnce(Result<DBusConnection, glib::Error>) + 'static,
45    >(
46        _source_object: *mut glib::gobject_ffi::GObject,
47        res: *mut crate::ffi::GAsyncResult,
48        user_data: glib::ffi::gpointer,
49    ) {
50        unsafe {
51            let mut error = std::ptr::null_mut();
52            let ret = ffi::g_bus_get_finish(res, &mut error);
53            let result = if error.is_null() {
54                Ok(from_glib_full(ret))
55            } else {
56                Err(from_glib_full(error))
57            };
58            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
59                Box_::from_raw(user_data as *mut _);
60            let callback: P = callback.into_inner();
61            callback(result);
62        }
63    }
64    let callback = bus_get_trampoline::<P>;
65    unsafe {
66        ffi::g_bus_get(
67            bus_type.into_glib(),
68            cancellable.map(|p| p.as_ref()).to_glib_none().0,
69            Some(callback),
70            Box_::into_raw(user_data) as *mut _,
71        );
72    }
73}
74
75pub fn bus_get_future(
76    bus_type: BusType,
77) -> Pin<Box_<dyn std::future::Future<Output = Result<DBusConnection, glib::Error>> + 'static>> {
78    Box_::pin(crate::GioFuture::new(
79        &(),
80        move |_obj, cancellable, send| {
81            bus_get(bus_type, Some(cancellable), move |res| {
82                send.resolve(res);
83            });
84        },
85    ))
86}
87
88/// Synchronously connects to the message bus specified by @bus_type.
89/// Note that the returned object may shared with other callers,
90/// e.g. if two separate parts of a process calls this function with
91/// the same @bus_type, they will share the same object.
92///
93/// This is a synchronous failable function. See g_bus_get() and
94/// g_bus_get_finish() for the asynchronous version.
95///
96/// The returned object is a singleton, that is, shared with other
97/// callers of g_bus_get() and g_bus_get_sync() for @bus_type. In the
98/// event that you need a private message bus connection, use
99/// g_dbus_address_get_for_bus_sync() and
100/// g_dbus_connection_new_for_address() with
101/// G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT and
102/// G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION flags.
103///
104/// Note that the returned #GDBusConnection object will (usually) have
105/// the #GDBusConnection:exit-on-close property set to [`true`].
106/// ## `bus_type`
107/// a #GBusType
108/// ## `cancellable`
109/// a #GCancellable or [`None`]
110///
111/// # Returns
112///
113/// a #GDBusConnection or [`None`] if @error is set.
114///     Free with g_object_unref().
115#[doc(alias = "g_bus_get_sync")]
116pub fn bus_get_sync(
117    bus_type: BusType,
118    cancellable: Option<&impl IsA<Cancellable>>,
119) -> Result<DBusConnection, glib::Error> {
120    unsafe {
121        let mut error = std::ptr::null_mut();
122        let ret = ffi::g_bus_get_sync(
123            bus_type.into_glib(),
124            cancellable.map(|p| p.as_ref()).to_glib_none().0,
125            &mut error,
126        );
127        if error.is_null() {
128            Ok(from_glib_full(ret))
129        } else {
130            Err(from_glib_full(error))
131        }
132    }
133}
134
135//#[doc(alias = "g_bus_own_name")]
136//pub fn bus_own_name(bus_type: BusType, name: &str, flags: BusNameOwnerFlags, bus_acquired_handler: Option<Box_<dyn Fn(&DBusConnection, &str) + 'static>>, name_acquired_handler: Option<Box_<dyn Fn(&DBusConnection, &str) + 'static>>, name_lost_handler: Option<Box_<dyn Fn(&DBusConnection, &str) + 'static>>) -> u32 {
137//    unsafe { TODO: call ffi:g_bus_own_name() }
138//}
139
140//#[doc(alias = "g_bus_own_name_on_connection")]
141//pub fn bus_own_name_on_connection(connection: &DBusConnection, name: &str, flags: BusNameOwnerFlags, name_acquired_handler: Option<Box_<dyn Fn(&DBusConnection, &str) + 'static>>, name_lost_handler: Option<Box_<dyn Fn(&DBusConnection, &str) + 'static>>) -> u32 {
142//    unsafe { TODO: call ffi:g_bus_own_name_on_connection() }
143//}
144
145//#[doc(alias = "g_bus_watch_name")]
146//pub fn bus_watch_name(bus_type: BusType, name: &str, flags: BusNameWatcherFlags, name_appeared_handler: Option<Box_<dyn Fn(&DBusConnection, &str, &str) + 'static>>, name_vanished_handler: Option<Box_<dyn Fn(&DBusConnection, &str) + 'static>>) -> u32 {
147//    unsafe { TODO: call ffi:g_bus_watch_name() }
148//}
149
150//#[doc(alias = "g_bus_watch_name_on_connection")]
151//pub fn bus_watch_name_on_connection(connection: &DBusConnection, name: &str, flags: BusNameWatcherFlags, name_appeared_handler: Option<Box_<dyn Fn(&DBusConnection, &str, &str) + 'static>>, name_vanished_handler: Option<Box_<dyn Fn(&DBusConnection, &str) + 'static>>) -> u32 {
152//    unsafe { TODO: call ffi:g_bus_watch_name_on_connection() }
153//}
154
155/// Checks if a content type can be executable. Note that for instance
156/// things like text files can be executables (i.e. scripts and batch files).
157/// ## `type_`
158/// a content type string
159///
160/// # Returns
161///
162/// [`true`] if the file type corresponds to a type that
163///     can be executable, [`false`] otherwise.
164#[doc(alias = "g_content_type_can_be_executable")]
165pub fn content_type_can_be_executable(type_: &str) -> bool {
166    unsafe {
167        from_glib(ffi::g_content_type_can_be_executable(
168            type_.to_glib_none().0,
169        ))
170    }
171}
172
173/// Compares two content types for equality.
174/// ## `type1`
175/// a content type string
176/// ## `type2`
177/// a content type string
178///
179/// # Returns
180///
181/// [`true`] if the two strings are identical or equivalent,
182///     [`false`] otherwise.
183#[doc(alias = "g_content_type_equals")]
184pub fn content_type_equals(type1: &str, type2: &str) -> bool {
185    unsafe {
186        from_glib(ffi::g_content_type_equals(
187            type1.to_glib_none().0,
188            type2.to_glib_none().0,
189        ))
190    }
191}
192
193/// Tries to find a content type based on the mime type name.
194/// ## `mime_type`
195/// a mime type string
196///
197/// # Returns
198///
199/// Newly allocated string with content type or
200///     [`None`]. Free with g_free()
201#[doc(alias = "g_content_type_from_mime_type")]
202pub fn content_type_from_mime_type(mime_type: &str) -> Option<glib::GString> {
203    unsafe {
204        from_glib_full(ffi::g_content_type_from_mime_type(
205            mime_type.to_glib_none().0,
206        ))
207    }
208}
209
210/// Gets the human readable description of the content type.
211/// ## `type_`
212/// a content type string
213///
214/// # Returns
215///
216/// a short description of the content type @type_. Free the
217///     returned string with g_free()
218#[doc(alias = "g_content_type_get_description")]
219pub fn content_type_get_description(type_: &str) -> glib::GString {
220    unsafe { from_glib_full(ffi::g_content_type_get_description(type_.to_glib_none().0)) }
221}
222
223/// Gets the generic icon name for a content type.
224///
225/// See the
226/// [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec)
227/// specification for more on the generic icon name.
228/// ## `type_`
229/// a content type string
230///
231/// # Returns
232///
233/// the registered generic icon name for the given @type_,
234///     or [`None`] if unknown. Free with g_free()
235#[doc(alias = "g_content_type_get_generic_icon_name")]
236pub fn content_type_get_generic_icon_name(type_: &str) -> Option<glib::GString> {
237    unsafe {
238        from_glib_full(ffi::g_content_type_get_generic_icon_name(
239            type_.to_glib_none().0,
240        ))
241    }
242}
243
244/// Gets the icon for a content type.
245/// ## `type_`
246/// a content type string
247///
248/// # Returns
249///
250/// #GIcon corresponding to the content type. Free the returned
251///     object with g_object_unref()
252#[doc(alias = "g_content_type_get_icon")]
253pub fn content_type_get_icon(type_: &str) -> Icon {
254    unsafe { from_glib_full(ffi::g_content_type_get_icon(type_.to_glib_none().0)) }
255}
256
257/// Get the list of directories which MIME data is loaded from. See
258/// g_content_type_set_mime_dirs() for details.
259///
260/// # Returns
261///
262/// [`None`]-terminated list of
263///    directories to load MIME data from, including any `mime/` subdirectory,
264///    and with the first directory to try listed first
265#[cfg(feature = "v2_60")]
266#[cfg_attr(docsrs, doc(cfg(feature = "v2_60")))]
267#[doc(alias = "g_content_type_get_mime_dirs")]
268pub fn content_type_get_mime_dirs() -> Vec<glib::GString> {
269    unsafe { FromGlibPtrContainer::from_glib_none(ffi::g_content_type_get_mime_dirs()) }
270}
271
272/// Gets the mime type for the content type, if one is registered.
273/// ## `type_`
274/// a content type string
275///
276/// # Returns
277///
278/// the registered mime type for the
279///     given @type_, or [`None`] if unknown; free with g_free().
280#[doc(alias = "g_content_type_get_mime_type")]
281pub fn content_type_get_mime_type(type_: &str) -> Option<glib::GString> {
282    unsafe { from_glib_full(ffi::g_content_type_get_mime_type(type_.to_glib_none().0)) }
283}
284
285/// Gets the symbolic icon for a content type.
286/// ## `type_`
287/// a content type string
288///
289/// # Returns
290///
291/// symbolic #GIcon corresponding to the content type.
292///     Free the returned object with g_object_unref()
293#[doc(alias = "g_content_type_get_symbolic_icon")]
294pub fn content_type_get_symbolic_icon(type_: &str) -> Icon {
295    unsafe {
296        from_glib_full(ffi::g_content_type_get_symbolic_icon(
297            type_.to_glib_none().0,
298        ))
299    }
300}
301
302/// Tries to guess the type of the tree with root @root, by
303/// looking at the files it contains. The result is an array
304/// of content types, with the best guess coming first.
305///
306/// The types returned all have the form x-content/foo, e.g.
307/// x-content/audio-cdda (for audio CDs) or x-content/image-dcf
308/// (for a camera memory card). See the
309/// [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec)
310/// specification for more on x-content types.
311///
312/// This function is useful in the implementation of
313/// g_mount_guess_content_type().
314/// ## `root`
315/// the root of the tree to guess a type for
316///
317/// # Returns
318///
319/// an [`None`]-terminated
320///     array of zero or more content types. Free with g_strfreev()
321#[doc(alias = "g_content_type_guess_for_tree")]
322pub fn content_type_guess_for_tree(root: &impl IsA<File>) -> Vec<glib::GString> {
323    unsafe {
324        FromGlibPtrContainer::from_glib_full(ffi::g_content_type_guess_for_tree(
325            root.as_ref().to_glib_none().0,
326        ))
327    }
328}
329
330/// Determines if @type_ is a subset of @supertype.
331/// ## `type_`
332/// a content type string
333/// ## `supertype`
334/// a content type string
335///
336/// # Returns
337///
338/// [`true`] if @type_ is a kind of @supertype,
339///     [`false`] otherwise.
340#[doc(alias = "g_content_type_is_a")]
341pub fn content_type_is_a(type_: &str, supertype: &str) -> bool {
342    unsafe {
343        from_glib(ffi::g_content_type_is_a(
344            type_.to_glib_none().0,
345            supertype.to_glib_none().0,
346        ))
347    }
348}
349
350/// Determines if @type_ is a subset of @mime_type.
351/// Convenience wrapper around g_content_type_is_a().
352/// ## `type_`
353/// a content type string
354/// ## `mime_type`
355/// a mime type string
356///
357/// # Returns
358///
359/// [`true`] if @type_ is a kind of @mime_type,
360///     [`false`] otherwise.
361#[doc(alias = "g_content_type_is_mime_type")]
362pub fn content_type_is_mime_type(type_: &str, mime_type: &str) -> bool {
363    unsafe {
364        from_glib(ffi::g_content_type_is_mime_type(
365            type_.to_glib_none().0,
366            mime_type.to_glib_none().0,
367        ))
368    }
369}
370
371/// Checks if the content type is the generic "unknown" type.
372/// On UNIX this is the "application/octet-stream" mimetype,
373/// while on win32 it is "*" and on OSX it is a dynamic type
374/// or octet-stream.
375/// ## `type_`
376/// a content type string
377///
378/// # Returns
379///
380/// [`true`] if the type is the unknown type.
381#[doc(alias = "g_content_type_is_unknown")]
382pub fn content_type_is_unknown(type_: &str) -> bool {
383    unsafe { from_glib(ffi::g_content_type_is_unknown(type_.to_glib_none().0)) }
384}
385
386/// Set the list of directories used by GIO to load the MIME database.
387/// If @dirs is [`None`], the directories used are the default:
388///
389///  - the `mime` subdirectory of the directory in `$XDG_DATA_HOME`
390///  - the `mime` subdirectory of every directory in `$XDG_DATA_DIRS`
391///
392/// This function is intended to be used when writing tests that depend on
393/// information stored in the MIME database, in order to control the data.
394///
395/// Typically, in case your tests use `G_TEST_OPTION_ISOLATE_DIRS`, but they
396/// depend on the system’s MIME database, you should call this function
397/// with @dirs set to [`None`] before calling g_test_init(), for instance:
398///
399///
400///
401/// **⚠️ The following code is in C ⚠️**
402///
403/// ```C
404///   // Load MIME data from the system
405///   g_content_type_set_mime_dirs (NULL);
406///   // Isolate the environment
407///   g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
408///
409///   …
410///
411///   return g_test_run ();
412/// ```
413/// ## `dirs`
414/// [`None`]-terminated list of
415///    directories to load MIME data from, including any `mime/` subdirectory,
416///    and with the first directory to try listed first
417#[cfg(feature = "v2_60")]
418#[cfg_attr(docsrs, doc(cfg(feature = "v2_60")))]
419#[doc(alias = "g_content_type_set_mime_dirs")]
420pub fn content_type_set_mime_dirs(dirs: &[&str]) {
421    unsafe {
422        ffi::g_content_type_set_mime_dirs(dirs.to_glib_none().0);
423    }
424}
425
426/// Gets a list of strings containing all the registered content types
427/// known to the system. The list and its data should be freed using
428/// `g_list_free_full (list, g_free)`.
429///
430/// # Returns
431///
432/// list of the registered
433///     content types
434#[doc(alias = "g_content_types_get_registered")]
435pub fn content_types_get_registered() -> Vec<glib::GString> {
436    unsafe { FromGlibPtrContainer::from_glib_full(ffi::g_content_types_get_registered()) }
437}
438
439/// Escape @string so it can appear in a D-Bus address as the value
440/// part of a key-value pair.
441///
442/// For instance, if @string is `/run/bus-for-:0`,
443/// this function would return `/run/bus-for-`3A0``,
444/// which could be used in a D-Bus address like
445/// `unix:nonce-tcp:host=127.0.0.1,port=42,noncefile=/run/bus-for-`3A0``.
446/// ## `string`
447/// an unescaped string to be included in a D-Bus address
448///     as the value in a key-value pair
449///
450/// # Returns
451///
452/// a copy of @string with all
453///     non-optionally-escaped bytes escaped
454#[doc(alias = "g_dbus_address_escape_value")]
455pub fn dbus_address_escape_value(string: &str) -> glib::GString {
456    unsafe { from_glib_full(ffi::g_dbus_address_escape_value(string.to_glib_none().0)) }
457}
458
459/// Synchronously looks up the D-Bus address for the well-known message
460/// bus instance specified by @bus_type. This may involve using various
461/// platform specific mechanisms.
462///
463/// The returned address will be in the
464/// [D-Bus address format](https://dbus.freedesktop.org/doc/dbus-specification.html#addresses).
465/// ## `bus_type`
466/// a #GBusType
467/// ## `cancellable`
468/// a #GCancellable or [`None`]
469///
470/// # Returns
471///
472/// a valid D-Bus address string for @bus_type or
473///     [`None`] if @error is set
474#[doc(alias = "g_dbus_address_get_for_bus_sync")]
475pub fn dbus_address_get_for_bus_sync(
476    bus_type: BusType,
477    cancellable: Option<&impl IsA<Cancellable>>,
478) -> Result<glib::GString, glib::Error> {
479    unsafe {
480        let mut error = std::ptr::null_mut();
481        let ret = ffi::g_dbus_address_get_for_bus_sync(
482            bus_type.into_glib(),
483            cancellable.map(|p| p.as_ref()).to_glib_none().0,
484            &mut error,
485        );
486        if error.is_null() {
487            Ok(from_glib_full(ret))
488        } else {
489            Err(from_glib_full(error))
490        }
491    }
492}
493
494/// Asynchronously connects to an endpoint specified by @address and
495/// sets up the connection so it is in a state to run the client-side
496/// of the D-Bus authentication conversation. @address must be in the
497/// [D-Bus address format](https://dbus.freedesktop.org/doc/dbus-specification.html#addresses).
498///
499/// When the operation is finished, @callback will be invoked. You can
500/// then call g_dbus_address_get_stream_finish() to get the result of
501/// the operation.
502///
503/// This is an asynchronous failable function. See
504/// g_dbus_address_get_stream_sync() for the synchronous version.
505/// ## `address`
506/// A valid D-Bus address.
507/// ## `cancellable`
508/// A #GCancellable or [`None`].
509/// ## `callback`
510/// A #GAsyncReadyCallback to call when the request is satisfied.
511#[doc(alias = "g_dbus_address_get_stream")]
512pub fn dbus_address_get_stream<
513    P: FnOnce(Result<(IOStream, Option<glib::GString>), glib::Error>) + 'static,
514>(
515    address: &str,
516    cancellable: Option<&impl IsA<Cancellable>>,
517    callback: P,
518) {
519    let main_context = glib::MainContext::ref_thread_default();
520    let is_main_context_owner = main_context.is_owner();
521    let has_acquired_main_context = (!is_main_context_owner)
522        .then(|| main_context.acquire().ok())
523        .flatten();
524    assert!(
525        is_main_context_owner || has_acquired_main_context.is_some(),
526        "Async operations only allowed if the thread is owning the MainContext"
527    );
528
529    let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
530        Box_::new(glib::thread_guard::ThreadGuard::new(callback));
531    unsafe extern "C" fn dbus_address_get_stream_trampoline<
532        P: FnOnce(Result<(IOStream, Option<glib::GString>), glib::Error>) + 'static,
533    >(
534        _source_object: *mut glib::gobject_ffi::GObject,
535        res: *mut crate::ffi::GAsyncResult,
536        user_data: glib::ffi::gpointer,
537    ) {
538        unsafe {
539            let mut error = std::ptr::null_mut();
540            let mut out_guid = std::ptr::null_mut();
541            let ret = ffi::g_dbus_address_get_stream_finish(res, &mut out_guid, &mut error);
542            let result = if error.is_null() {
543                Ok((from_glib_full(ret), from_glib_full(out_guid)))
544            } else {
545                Err(from_glib_full(error))
546            };
547            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
548                Box_::from_raw(user_data as *mut _);
549            let callback: P = callback.into_inner();
550            callback(result);
551        }
552    }
553    let callback = dbus_address_get_stream_trampoline::<P>;
554    unsafe {
555        ffi::g_dbus_address_get_stream(
556            address.to_glib_none().0,
557            cancellable.map(|p| p.as_ref()).to_glib_none().0,
558            Some(callback),
559            Box_::into_raw(user_data) as *mut _,
560        );
561    }
562}
563
564pub fn dbus_address_get_stream_future(
565    address: &str,
566) -> Pin<
567    Box_<
568        dyn std::future::Future<Output = Result<(IOStream, Option<glib::GString>), glib::Error>>
569            + 'static,
570    >,
571> {
572    let address = String::from(address);
573    Box_::pin(crate::GioFuture::new(
574        &(),
575        move |_obj, cancellable, send| {
576            dbus_address_get_stream(&address, Some(cancellable), move |res| {
577                send.resolve(res);
578            });
579        },
580    ))
581}
582
583/// Synchronously connects to an endpoint specified by @address and
584/// sets up the connection so it is in a state to run the client-side
585/// of the D-Bus authentication conversation. @address must be in the
586/// [D-Bus address format](https://dbus.freedesktop.org/doc/dbus-specification.html#addresses).
587///
588/// A server is not required to set a GUID, so @out_guid may be set to [`None`]
589/// even on success.
590///
591/// This is a synchronous failable function. See
592/// g_dbus_address_get_stream() for the asynchronous version.
593/// ## `address`
594/// A valid D-Bus address.
595/// ## `cancellable`
596/// A #GCancellable or [`None`].
597///
598/// # Returns
599///
600/// A #GIOStream or [`None`] if @error is set.
601///
602/// ## `out_guid`
603/// [`None`] or return location to store the GUID extracted from @address, if any.
604#[doc(alias = "g_dbus_address_get_stream_sync")]
605pub fn dbus_address_get_stream_sync(
606    address: &str,
607    cancellable: Option<&impl IsA<Cancellable>>,
608) -> Result<(IOStream, Option<glib::GString>), glib::Error> {
609    unsafe {
610        let mut out_guid = std::ptr::null_mut();
611        let mut error = std::ptr::null_mut();
612        let ret = ffi::g_dbus_address_get_stream_sync(
613            address.to_glib_none().0,
614            &mut out_guid,
615            cancellable.map(|p| p.as_ref()).to_glib_none().0,
616            &mut error,
617        );
618        if error.is_null() {
619            Ok((from_glib_full(ret), from_glib_full(out_guid)))
620        } else {
621            Err(from_glib_full(error))
622        }
623    }
624}
625
626/// This is a language binding friendly version of g_dbus_escape_object_path_bytestring().
627/// ## `s`
628/// the string to escape
629///
630/// # Returns
631///
632/// an escaped version of @s. Free with g_free().
633#[cfg(feature = "v2_68")]
634#[cfg_attr(docsrs, doc(cfg(feature = "v2_68")))]
635#[doc(alias = "g_dbus_escape_object_path")]
636pub fn dbus_escape_object_path(s: &str) -> glib::GString {
637    unsafe { from_glib_full(ffi::g_dbus_escape_object_path(s.to_glib_none().0)) }
638}
639
640//#[cfg(feature = "v2_68")]
641//#[cfg_attr(docsrs, doc(cfg(feature = "v2_68")))]
642//#[doc(alias = "g_dbus_escape_object_path_bytestring")]
643//pub fn dbus_escape_object_path_bytestring(bytes: &[u8]) -> glib::GString {
644//    unsafe { TODO: call ffi:g_dbus_escape_object_path_bytestring() }
645//}
646
647/// Generate a D-Bus GUID that can be used with
648/// e.g. g_dbus_connection_new().
649///
650/// See the
651/// [D-Bus specification](https://dbus.freedesktop.org/doc/dbus-specification.html#uuids)
652/// regarding what strings are valid D-Bus GUIDs. The specification refers to
653/// these as ‘UUIDs’ whereas GLib (for historical reasons) refers to them as
654/// ‘GUIDs’. The terms are interchangeable.
655///
656/// Note that D-Bus GUIDs do not follow
657/// [RFC 4122](https://datatracker.ietf.org/doc/html/rfc4122).
658///
659/// # Returns
660///
661/// A valid D-Bus GUID. Free with g_free().
662#[doc(alias = "g_dbus_generate_guid")]
663pub fn dbus_generate_guid() -> glib::GString {
664    unsafe { from_glib_full(ffi::g_dbus_generate_guid()) }
665}
666
667/// Converts a #GValue to a #GVariant of the type indicated by the @type_
668/// parameter.
669///
670/// The conversion is using the following rules:
671///
672/// - `G_TYPE_STRING`: 's', 'o', 'g' or 'ay'
673/// - `G_TYPE_STRV`: 'as', 'ao' or 'aay'
674/// - `G_TYPE_BOOLEAN`: 'b'
675/// - `G_TYPE_UCHAR`: 'y'
676/// - `G_TYPE_INT`: 'i', 'n'
677/// - `G_TYPE_UINT`: 'u', 'q'
678/// - `G_TYPE_INT64`: 'x'
679/// - `G_TYPE_UINT64`: 't'
680/// - `G_TYPE_DOUBLE`: 'd'
681/// - `G_TYPE_VARIANT`: Any #GVariantType
682///
683/// This can fail if e.g. @gvalue is of type `G_TYPE_STRING` and @type_
684/// is 'i', i.e. `G_VARIANT_TYPE_INT32`. It will also fail for any #GType
685/// (including e.g. `G_TYPE_OBJECT` and `G_TYPE_BOXED` derived-types) not
686/// in the table above.
687///
688/// Note that if @gvalue is of type `G_TYPE_VARIANT` and its value is
689/// [`None`], the empty #GVariant instance (never [`None`]) for @type_ is
690/// returned (e.g. 0 for scalar types, the empty string for string types,
691/// '/' for object path types, the empty array for any array type and so on).
692///
693/// See the g_dbus_gvariant_to_gvalue() function for how to convert a
694/// #GVariant to a #GValue.
695/// ## `gvalue`
696/// A #GValue to convert to a #GVariant
697/// ## `type_`
698/// A #GVariantType
699///
700/// # Returns
701///
702/// A #GVariant (never floating) of
703///     #GVariantType @type_ holding the data from @gvalue or an empty #GVariant
704///     in case of failure. Free with g_variant_unref().
705#[doc(alias = "g_dbus_gvalue_to_gvariant")]
706pub fn dbus_gvalue_to_gvariant(gvalue: &glib::Value, type_: &glib::VariantTy) -> glib::Variant {
707    unsafe {
708        from_glib_full(ffi::g_dbus_gvalue_to_gvariant(
709            gvalue.to_glib_none().0,
710            type_.to_glib_none().0,
711        ))
712    }
713}
714
715/// Converts a #GVariant to a #GValue. If @value is floating, it is consumed.
716///
717/// The rules specified in the g_dbus_gvalue_to_gvariant() function are
718/// used - this function is essentially its reverse form. So, a #GVariant
719/// containing any basic or string array type will be converted to a #GValue
720/// containing a basic value or string array. Any other #GVariant (handle,
721/// variant, tuple, dict entry) will be converted to a #GValue containing that
722/// #GVariant.
723///
724/// The conversion never fails - a valid #GValue is always returned in
725/// @out_gvalue.
726/// ## `value`
727/// A #GVariant.
728///
729/// # Returns
730///
731///
732/// ## `out_gvalue`
733/// Return location pointing to a zero-filled (uninitialized) #GValue.
734#[doc(alias = "g_dbus_gvariant_to_gvalue")]
735pub fn dbus_gvariant_to_gvalue(value: &glib::Variant) -> glib::Value {
736    unsafe {
737        let mut out_gvalue = glib::Value::uninitialized();
738        ffi::g_dbus_gvariant_to_gvalue(value.to_glib_none().0, out_gvalue.to_glib_none_mut().0);
739        out_gvalue
740    }
741}
742
743/// Checks if @string is a
744/// [D-Bus address](https://dbus.freedesktop.org/doc/dbus-specification.html#addresses).
745///
746/// This doesn't check if @string is actually supported by #GDBusServer
747/// or #GDBusConnection - use g_dbus_is_supported_address() to do more
748/// checks.
749/// ## `string`
750/// A string.
751///
752/// # Returns
753///
754/// [`true`] if @string is a valid D-Bus address, [`false`] otherwise.
755#[doc(alias = "g_dbus_is_address")]
756pub fn dbus_is_address(string: &str) -> bool {
757    unsafe { from_glib(ffi::g_dbus_is_address(string.to_glib_none().0)) }
758}
759
760/// Check whether @string is a valid D-Bus error name.
761///
762/// This function returns the same result as g_dbus_is_interface_name(),
763/// because D-Bus error names are defined to have exactly the
764/// same syntax as interface names.
765/// ## `string`
766/// The string to check.
767///
768/// # Returns
769///
770/// [`true`] if valid, [`false`] otherwise.
771#[cfg(feature = "v2_70")]
772#[cfg_attr(docsrs, doc(cfg(feature = "v2_70")))]
773#[doc(alias = "g_dbus_is_error_name")]
774pub fn dbus_is_error_name(string: &str) -> bool {
775    unsafe { from_glib(ffi::g_dbus_is_error_name(string.to_glib_none().0)) }
776}
777
778/// Checks if @string is a D-Bus GUID.
779///
780/// See the documentation for g_dbus_generate_guid() for more information about
781/// the format of a GUID.
782/// ## `string`
783/// The string to check.
784///
785/// # Returns
786///
787/// [`true`] if @string is a GUID, [`false`] otherwise.
788#[doc(alias = "g_dbus_is_guid")]
789pub fn dbus_is_guid(string: &str) -> bool {
790    unsafe { from_glib(ffi::g_dbus_is_guid(string.to_glib_none().0)) }
791}
792
793/// Checks if @string is a valid D-Bus interface name.
794/// ## `string`
795/// The string to check.
796///
797/// # Returns
798///
799/// [`true`] if valid, [`false`] otherwise.
800#[doc(alias = "g_dbus_is_interface_name")]
801pub fn dbus_is_interface_name(string: &str) -> bool {
802    unsafe { from_glib(ffi::g_dbus_is_interface_name(string.to_glib_none().0)) }
803}
804
805/// Checks if @string is a valid D-Bus member (e.g. signal or method) name.
806/// ## `string`
807/// The string to check.
808///
809/// # Returns
810///
811/// [`true`] if valid, [`false`] otherwise.
812#[doc(alias = "g_dbus_is_member_name")]
813pub fn dbus_is_member_name(string: &str) -> bool {
814    unsafe { from_glib(ffi::g_dbus_is_member_name(string.to_glib_none().0)) }
815}
816
817/// Checks if @string is a valid D-Bus bus name (either unique or well-known).
818/// ## `string`
819/// The string to check.
820///
821/// # Returns
822///
823/// [`true`] if valid, [`false`] otherwise.
824#[doc(alias = "g_dbus_is_name")]
825pub fn dbus_is_name(string: &str) -> bool {
826    unsafe { from_glib(ffi::g_dbus_is_name(string.to_glib_none().0)) }
827}
828
829/// Like g_dbus_is_address() but also checks if the library supports the
830/// transports in @string and that key/value pairs for each transport
831/// are valid. See the specification of the
832/// [D-Bus address format](https://dbus.freedesktop.org/doc/dbus-specification.html#addresses).
833/// ## `string`
834/// A string.
835///
836/// # Returns
837///
838/// [`true`] if @string is a valid D-Bus address that is
839/// supported by this library, [`false`] if @error is set.
840#[doc(alias = "g_dbus_is_supported_address")]
841pub fn dbus_is_supported_address(string: &str) -> Result<(), glib::Error> {
842    unsafe {
843        let mut error = std::ptr::null_mut();
844        let is_ok = ffi::g_dbus_is_supported_address(string.to_glib_none().0, &mut error);
845        debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
846        if error.is_null() {
847            Ok(())
848        } else {
849            Err(from_glib_full(error))
850        }
851    }
852}
853
854/// Checks if @string is a valid D-Bus unique bus name.
855/// ## `string`
856/// The string to check.
857///
858/// # Returns
859///
860/// [`true`] if valid, [`false`] otherwise.
861#[doc(alias = "g_dbus_is_unique_name")]
862pub fn dbus_is_unique_name(string: &str) -> bool {
863    unsafe { from_glib(ffi::g_dbus_is_unique_name(string.to_glib_none().0)) }
864}
865
866/// Converts `errno.h` error codes into GIO error codes.
867///
868/// The fallback value [`IOErrorEnum::Failed`][crate::IOErrorEnum::Failed] is returned for error codes not
869/// currently handled (but note that future GLib releases may return a more
870/// specific value instead).
871///
872/// As `errno` is global and may be modified by intermediate function
873/// calls, you should save its value immediately after the call returns,
874/// and use the saved value instead of `errno`:
875///
876///
877///
878///
879/// **⚠️ The following code is in C ⚠️**
880///
881/// ```C
882///   int saved_errno;
883///
884///   ret = read (blah);
885///   saved_errno = errno;
886///
887///   g_io_error_from_errno (saved_errno);
888/// ```
889/// ## `err_no`
890/// Error number as defined in errno.h.
891///
892/// # Returns
893///
894/// #GIOErrorEnum value for the given `errno.h` error number
895#[doc(alias = "g_io_error_from_errno")]
896pub fn io_error_from_errno(err_no: i32) -> IOErrorEnum {
897    unsafe { from_glib(ffi::g_io_error_from_errno(err_no)) }
898}
899
900//#[doc(alias = "g_io_modules_load_all_in_directory")]
901//pub fn io_modules_load_all_in_directory(dirname: impl AsRef<std::path::Path>) -> /*Ignored*/Vec<IOModule> {
902//    unsafe { TODO: call ffi:g_io_modules_load_all_in_directory() }
903//}
904
905//#[doc(alias = "g_io_modules_load_all_in_directory_with_scope")]
906//pub fn io_modules_load_all_in_directory_with_scope(dirname: impl AsRef<std::path::Path>, scope: /*Ignored*/&mut IOModuleScope) -> /*Ignored*/Vec<IOModule> {
907//    unsafe { TODO: call ffi:g_io_modules_load_all_in_directory_with_scope() }
908//}
909
910/// Scans all the modules in the specified directory, ensuring that
911/// any extension point implemented by a module is registered.
912///
913/// This may not actually load and initialize all the types in each
914/// module, some modules may be lazily loaded and initialized when
915/// an extension point it implements is used with e.g.
916/// g_io_extension_point_get_extensions() or
917/// g_io_extension_point_get_extension_by_name().
918///
919/// If you need to guarantee that all types are loaded in all the modules,
920/// use g_io_modules_load_all_in_directory().
921/// ## `dirname`
922/// pathname for a directory containing modules
923///     to scan.
924#[doc(alias = "g_io_modules_scan_all_in_directory")]
925pub fn io_modules_scan_all_in_directory(dirname: impl AsRef<std::path::Path>) {
926    unsafe {
927        ffi::g_io_modules_scan_all_in_directory(dirname.as_ref().to_glib_none().0);
928    }
929}
930
931//#[doc(alias = "g_io_modules_scan_all_in_directory_with_scope")]
932//pub fn io_modules_scan_all_in_directory_with_scope(dirname: impl AsRef<std::path::Path>, scope: /*Ignored*/&mut IOModuleScope) {
933//    unsafe { TODO: call ffi:g_io_modules_scan_all_in_directory_with_scope() }
934//}
935
936/// Creates a keyfile-backed [`SettingsBackend`][crate::SettingsBackend].
937///
938/// The filename of the keyfile to use is given by @filename.
939///
940/// All settings read to or written from the backend must fall under the
941/// path given in @root_path (which must start and end with a slash and
942/// not contain two consecutive slashes).  @root_path may be `"/"`.
943///
944/// If @root_group is non-`NULL` then it specifies the name of the keyfile
945/// group used for keys that are written directly below @root_path.  For
946/// example, if @root_path is `"/apps/example/"` and @root_group is
947/// `"toplevel"`, then setting the key `"/apps/example/enabled"` to true will
948/// cause the following to appear in the keyfile:
949///
950/// ```text
951/// [toplevel]
952/// enabled=true
953/// ```
954///
955/// If @root_group is `NULL` then it is not permitted to store keys
956/// directly below the @root_path.
957///
958/// For keys not stored directly below @root_path (ie: in a sub-path),
959/// the name of the subpath (with the final slash stripped) is used as
960/// the name of the keyfile group.  To continue the example, if
961/// `"/apps/example/profiles/default/font-size"` were set to
962/// `12` then the following would appear in the keyfile:
963///
964/// ```text
965/// [profiles/default]
966/// font-size=12
967/// ```
968///
969/// The backend will refuse writes (and return writability as being
970/// false) for keys outside of @root_path and, in the event that
971/// @root_group is `NULL`, also for keys directly under @root_path.
972/// Writes will also be refused if the backend detects that it has the
973/// inability to rewrite the keyfile (ie: the containing directory is not
974/// writable).
975///
976/// There is no checking done for your key namespace clashing with the
977/// syntax of the key file format.  For example, if you have `[` or `]`
978/// characters in your path names or `=` in your key names you may be in
979/// trouble.
980///
981/// The backend reads default values from a keyfile called `defaults` in
982/// the directory specified by the `GKeyfileSettingsBackend:defaults-dir`
983/// property, and a list of locked keys from a text file with the name `locks` in
984/// the same location.
985/// ## `filename`
986/// the filename of the keyfile
987/// ## `root_path`
988/// the path under which all settings keys appear
989/// ## `root_group`
990/// the group name corresponding to @root_path, or
991///    `NULL` to disallow storing keys directly beneath @root_path
992///
993/// # Returns
994///
995/// a keyfile-backed [`SettingsBackend`][crate::SettingsBackend]
996#[doc(alias = "g_keyfile_settings_backend_new")]
997pub fn keyfile_settings_backend_new(
998    filename: &str,
999    root_path: &str,
1000    root_group: Option<&str>,
1001) -> SettingsBackend {
1002    unsafe {
1003        from_glib_full(ffi::g_keyfile_settings_backend_new(
1004            filename.to_glib_none().0,
1005            root_path.to_glib_none().0,
1006            root_group.to_glib_none().0,
1007        ))
1008    }
1009}
1010
1011/// Creates a memory-backed #GSettingsBackend.
1012///
1013/// This backend allows changes to settings, but does not write them
1014/// to any backing storage, so the next time you run your application,
1015/// the memory backend will start out with the default values again.
1016///
1017/// # Returns
1018///
1019/// a newly created #GSettingsBackend
1020#[doc(alias = "g_memory_settings_backend_new")]
1021pub fn memory_settings_backend_new() -> SettingsBackend {
1022    unsafe { from_glib_full(ffi::g_memory_settings_backend_new()) }
1023}
1024
1025/// Creates a readonly #GSettingsBackend.
1026///
1027/// This backend does not allow changes to settings, so all settings
1028/// will always have their default values.
1029///
1030/// # Returns
1031///
1032/// a newly created #GSettingsBackend
1033#[doc(alias = "g_null_settings_backend_new")]
1034pub fn null_settings_backend_new() -> SettingsBackend {
1035    unsafe { from_glib_full(ffi::g_null_settings_backend_new()) }
1036}
1037
1038/// Returns all the names of children at the specified @path in the set of
1039/// globally registered resources.
1040///
1041/// The return result is a `NULL` terminated list of strings which should
1042/// be released with `strfreev()`.
1043///
1044/// @lookup_flags controls the behaviour of the lookup.
1045/// ## `path`
1046/// A path name inside the resource
1047/// ## `lookup_flags`
1048/// A [`ResourceLookupFlags`][crate::ResourceLookupFlags]
1049///
1050/// # Returns
1051///
1052/// an array of constant strings
1053#[doc(alias = "g_resources_enumerate_children")]
1054pub fn resources_enumerate_children(
1055    path: &str,
1056    lookup_flags: ResourceLookupFlags,
1057) -> Result<Vec<glib::GString>, glib::Error> {
1058    unsafe {
1059        let mut error = std::ptr::null_mut();
1060        let ret = ffi::g_resources_enumerate_children(
1061            path.to_glib_none().0,
1062            lookup_flags.into_glib(),
1063            &mut error,
1064        );
1065        if error.is_null() {
1066            Ok(FromGlibPtrContainer::from_glib_full(ret))
1067        } else {
1068            Err(from_glib_full(error))
1069        }
1070    }
1071}
1072
1073/// Looks for a file at the specified @path in the set of
1074/// globally registered resources and if found returns information about it.
1075///
1076/// @lookup_flags controls the behaviour of the lookup.
1077/// ## `path`
1078/// A path name inside the resource
1079/// ## `lookup_flags`
1080/// A [`ResourceLookupFlags`][crate::ResourceLookupFlags]
1081///
1082/// # Returns
1083///
1084/// `TRUE` if the file was found, `FALSE` if there were errors
1085///
1086/// ## `size`
1087/// a location to place the length of the contents of the file,
1088///    or `NULL` if the length is not needed
1089///
1090/// ## `flags`
1091/// a location to place the [`ResourceFlags`][crate::ResourceFlags] about the file,
1092///    or `NULL` if the flags are not needed
1093#[doc(alias = "g_resources_get_info")]
1094pub fn resources_get_info(
1095    path: &str,
1096    lookup_flags: ResourceLookupFlags,
1097) -> Result<(usize, u32), glib::Error> {
1098    unsafe {
1099        let mut size = std::mem::MaybeUninit::uninit();
1100        let mut flags = std::mem::MaybeUninit::uninit();
1101        let mut error = std::ptr::null_mut();
1102        let is_ok = ffi::g_resources_get_info(
1103            path.to_glib_none().0,
1104            lookup_flags.into_glib(),
1105            size.as_mut_ptr(),
1106            flags.as_mut_ptr(),
1107            &mut error,
1108        );
1109        debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
1110        if error.is_null() {
1111            Ok((size.assume_init(), flags.assume_init()))
1112        } else {
1113            Err(from_glib_full(error))
1114        }
1115    }
1116}
1117
1118/// Returns whether the specified @path in the set of
1119/// globally registered resources has children.
1120/// ## `path`
1121/// A pathname
1122///
1123/// # Returns
1124///
1125/// [`true`] if @patch has children
1126#[cfg(feature = "v2_84")]
1127#[cfg_attr(docsrs, doc(cfg(feature = "v2_84")))]
1128#[doc(alias = "g_resources_has_children")]
1129pub fn resources_has_children(path: &str) -> bool {
1130    unsafe { from_glib(ffi::g_resources_has_children(path.to_glib_none().0)) }
1131}
1132
1133/// Looks for a file at the specified @path in the set of
1134/// globally registered resources and returns a [`glib::Bytes`][crate::glib::Bytes] that
1135/// lets you directly access the data in memory.
1136///
1137/// The data is always followed by a zero byte, so you
1138/// can safely use the data as a C string. However, that byte
1139/// is not included in the size of the [`glib::Bytes`][crate::glib::Bytes].
1140///
1141/// For uncompressed resource files this is a pointer directly into
1142/// the resource bundle, which is typically in some read-only data section
1143/// in the program binary. For compressed files we allocate memory on
1144/// the heap and automatically uncompress the data.
1145///
1146/// @lookup_flags controls the behaviour of the lookup.
1147/// ## `path`
1148/// A path name inside the resource
1149/// ## `lookup_flags`
1150/// A [`ResourceLookupFlags`][crate::ResourceLookupFlags]
1151///
1152/// # Returns
1153///
1154/// [`glib::Bytes`][crate::glib::Bytes] or `NULL` on error
1155#[doc(alias = "g_resources_lookup_data")]
1156pub fn resources_lookup_data(
1157    path: &str,
1158    lookup_flags: ResourceLookupFlags,
1159) -> Result<glib::Bytes, glib::Error> {
1160    unsafe {
1161        let mut error = std::ptr::null_mut();
1162        let ret = ffi::g_resources_lookup_data(
1163            path.to_glib_none().0,
1164            lookup_flags.into_glib(),
1165            &mut error,
1166        );
1167        if error.is_null() {
1168            Ok(from_glib_full(ret))
1169        } else {
1170            Err(from_glib_full(error))
1171        }
1172    }
1173}
1174
1175/// Looks for a file at the specified @path in the set of
1176/// globally registered resources and returns a [`InputStream`][crate::InputStream]
1177/// that lets you read the data.
1178///
1179/// @lookup_flags controls the behaviour of the lookup.
1180/// ## `path`
1181/// A path name inside the resource
1182/// ## `lookup_flags`
1183/// A [`ResourceLookupFlags`][crate::ResourceLookupFlags]
1184///
1185/// # Returns
1186///
1187/// [`InputStream`][crate::InputStream] or `NULL` on error
1188#[doc(alias = "g_resources_open_stream")]
1189pub fn resources_open_stream(
1190    path: &str,
1191    lookup_flags: ResourceLookupFlags,
1192) -> Result<InputStream, glib::Error> {
1193    unsafe {
1194        let mut error = std::ptr::null_mut();
1195        let ret = ffi::g_resources_open_stream(
1196            path.to_glib_none().0,
1197            lookup_flags.into_glib(),
1198            &mut error,
1199        );
1200        if error.is_null() {
1201            Ok(from_glib_full(ret))
1202        } else {
1203            Err(from_glib_full(error))
1204        }
1205    }
1206}
1207
1208/// Registers the resource with the process-global set of resources.
1209///
1210/// Once a resource is registered the files in it can be accessed
1211/// with the global resource lookup functions like
1212/// [`resources_lookup_data()`][crate::resources_lookup_data()].
1213/// ## `resource`
1214/// A [`Resource`][crate::Resource]
1215#[doc(alias = "g_resources_register")]
1216pub fn resources_register(resource: &Resource) {
1217    unsafe {
1218        ffi::g_resources_register(resource.to_glib_none().0);
1219    }
1220}
1221
1222/// Unregisters the resource from the process-global set of resources.
1223/// ## `resource`
1224/// A [`Resource`][crate::Resource]
1225#[doc(alias = "g_resources_unregister")]
1226pub fn resources_unregister(resource: &Resource) {
1227    unsafe {
1228        ffi::g_resources_unregister(resource.to_glib_none().0);
1229    }
1230}