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, IOModule, IOModuleScope,
7 IOStream, Icon, 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/// argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
387///
388/// …
389///
390/// return g_test_run ();
391/// ]|
392/// ## `dirs`
393/// [`None`]-terminated list of
394/// directories to load MIME data from, including any `mime/` subdirectory,
395/// and with the first directory to try listed first
396#[cfg(feature = "v2_60")]
397#[cfg_attr(docsrs, doc(cfg(feature = "v2_60")))]
398#[doc(alias = "g_content_type_set_mime_dirs")]
399pub fn content_type_set_mime_dirs(dirs: &[&str]) {
400 unsafe {
401 ffi::g_content_type_set_mime_dirs(dirs.to_glib_none().0);
402 }
403}
404
405/// Gets a list of strings containing all the registered content types
406/// known to the system. The list and its data should be freed using
407/// `g_list_free_full (list, g_free)`.
408///
409/// # Returns
410///
411/// list of the registered
412/// content types
413#[doc(alias = "g_content_types_get_registered")]
414pub fn content_types_get_registered() -> Vec<glib::GString> {
415 unsafe { FromGlibPtrContainer::from_glib_full(ffi::g_content_types_get_registered()) }
416}
417
418/// Escape @string so it can appear in a D-Bus address as the value
419/// part of a key-value pair.
420///
421/// For instance, if @string is `/run/bus-for-:0`,
422/// this function would return `/run/bus-for-`3A0``,
423/// which could be used in a D-Bus address like
424/// `unix:nonce-tcp:host=127.0.0.1,port=42,noncefile=/run/bus-for-`3A0``.
425/// ## `string`
426/// an unescaped string to be included in a D-Bus address
427/// as the value in a key-value pair
428///
429/// # Returns
430///
431/// a copy of @string with all
432/// non-optionally-escaped bytes escaped
433#[doc(alias = "g_dbus_address_escape_value")]
434pub fn dbus_address_escape_value(string: &str) -> glib::GString {
435 unsafe { from_glib_full(ffi::g_dbus_address_escape_value(string.to_glib_none().0)) }
436}
437
438/// Synchronously looks up the D-Bus address for the well-known message
439/// bus instance specified by @bus_type. This may involve using various
440/// platform specific mechanisms.
441///
442/// The returned address will be in the
443/// [D-Bus address format](https://dbus.freedesktop.org/doc/dbus-specification.html#addresses).
444/// ## `bus_type`
445/// a #GBusType
446/// ## `cancellable`
447/// a #GCancellable or [`None`]
448///
449/// # Returns
450///
451/// a valid D-Bus address string for @bus_type or
452/// [`None`] if @error is set
453#[doc(alias = "g_dbus_address_get_for_bus_sync")]
454pub fn dbus_address_get_for_bus_sync(
455 bus_type: BusType,
456 cancellable: Option<&impl IsA<Cancellable>>,
457) -> Result<glib::GString, glib::Error> {
458 unsafe {
459 let mut error = std::ptr::null_mut();
460 let ret = ffi::g_dbus_address_get_for_bus_sync(
461 bus_type.into_glib(),
462 cancellable.map(|p| p.as_ref()).to_glib_none().0,
463 &mut error,
464 );
465 if error.is_null() {
466 Ok(from_glib_full(ret))
467 } else {
468 Err(from_glib_full(error))
469 }
470 }
471}
472
473/// Asynchronously connects to an endpoint specified by @address and
474/// sets up the connection so it is in a state to run the client-side
475/// of the D-Bus authentication conversation. @address must be in the
476/// [D-Bus address format](https://dbus.freedesktop.org/doc/dbus-specification.html#addresses).
477///
478/// When the operation is finished, @callback will be invoked. You can
479/// then call g_dbus_address_get_stream_finish() to get the result of
480/// the operation.
481///
482/// This is an asynchronous failable function. See
483/// g_dbus_address_get_stream_sync() for the synchronous version.
484/// ## `address`
485/// A valid D-Bus address.
486/// ## `cancellable`
487/// A #GCancellable or [`None`].
488/// ## `callback`
489/// A #GAsyncReadyCallback to call when the request is satisfied.
490#[doc(alias = "g_dbus_address_get_stream")]
491pub fn dbus_address_get_stream<
492 P: FnOnce(Result<(IOStream, Option<glib::GString>), glib::Error>) + 'static,
493>(
494 address: &str,
495 cancellable: Option<&impl IsA<Cancellable>>,
496 callback: P,
497) {
498 let main_context = glib::MainContext::ref_thread_default();
499 let is_main_context_owner = main_context.is_owner();
500 let has_acquired_main_context = (!is_main_context_owner)
501 .then(|| main_context.acquire().ok())
502 .flatten();
503 assert!(
504 is_main_context_owner || has_acquired_main_context.is_some(),
505 "Async operations only allowed if the thread is owning the MainContext"
506 );
507
508 let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
509 Box_::new(glib::thread_guard::ThreadGuard::new(callback));
510 unsafe extern "C" fn dbus_address_get_stream_trampoline<
511 P: FnOnce(Result<(IOStream, Option<glib::GString>), glib::Error>) + 'static,
512 >(
513 _source_object: *mut glib::gobject_ffi::GObject,
514 res: *mut crate::ffi::GAsyncResult,
515 user_data: glib::ffi::gpointer,
516 ) {
517 unsafe {
518 let mut error = std::ptr::null_mut();
519 let mut out_guid = std::ptr::null_mut();
520 let ret = ffi::g_dbus_address_get_stream_finish(res, &mut out_guid, &mut error);
521 let result = if error.is_null() {
522 Ok((from_glib_full(ret), from_glib_full(out_guid)))
523 } else {
524 Err(from_glib_full(error))
525 };
526 let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
527 Box_::from_raw(user_data as *mut _);
528 let callback: P = callback.into_inner();
529 callback(result);
530 }
531 }
532 let callback = dbus_address_get_stream_trampoline::<P>;
533 unsafe {
534 ffi::g_dbus_address_get_stream(
535 address.to_glib_none().0,
536 cancellable.map(|p| p.as_ref()).to_glib_none().0,
537 Some(callback),
538 Box_::into_raw(user_data) as *mut _,
539 );
540 }
541}
542
543pub fn dbus_address_get_stream_future(
544 address: &str,
545) -> Pin<
546 Box_<
547 dyn std::future::Future<Output = Result<(IOStream, Option<glib::GString>), glib::Error>>
548 + 'static,
549 >,
550> {
551 let address = String::from(address);
552 Box_::pin(crate::GioFuture::new(
553 &(),
554 move |_obj, cancellable, send| {
555 dbus_address_get_stream(&address, Some(cancellable), move |res| {
556 send.resolve(res);
557 });
558 },
559 ))
560}
561
562/// Synchronously connects to an endpoint specified by @address and
563/// sets up the connection so it is in a state to run the client-side
564/// of the D-Bus authentication conversation. @address must be in the
565/// [D-Bus address format](https://dbus.freedesktop.org/doc/dbus-specification.html#addresses).
566///
567/// A server is not required to set a GUID, so @out_guid may be set to [`None`]
568/// even on success.
569///
570/// This is a synchronous failable function. See
571/// g_dbus_address_get_stream() for the asynchronous version.
572/// ## `address`
573/// A valid D-Bus address.
574/// ## `cancellable`
575/// A #GCancellable or [`None`].
576///
577/// # Returns
578///
579/// A #GIOStream or [`None`] if @error is set.
580///
581/// ## `out_guid`
582/// [`None`] or return location to store the GUID extracted from @address, if any.
583#[doc(alias = "g_dbus_address_get_stream_sync")]
584pub fn dbus_address_get_stream_sync(
585 address: &str,
586 cancellable: Option<&impl IsA<Cancellable>>,
587) -> Result<(IOStream, Option<glib::GString>), glib::Error> {
588 unsafe {
589 let mut out_guid = std::ptr::null_mut();
590 let mut error = std::ptr::null_mut();
591 let ret = ffi::g_dbus_address_get_stream_sync(
592 address.to_glib_none().0,
593 &mut out_guid,
594 cancellable.map(|p| p.as_ref()).to_glib_none().0,
595 &mut error,
596 );
597 if error.is_null() {
598 Ok((from_glib_full(ret), from_glib_full(out_guid)))
599 } else {
600 Err(from_glib_full(error))
601 }
602 }
603}
604
605/// This is a language binding friendly version of g_dbus_escape_object_path_bytestring().
606/// ## `s`
607/// the string to escape
608///
609/// # Returns
610///
611/// an escaped version of @s. Free with g_free().
612#[cfg(feature = "v2_68")]
613#[cfg_attr(docsrs, doc(cfg(feature = "v2_68")))]
614#[doc(alias = "g_dbus_escape_object_path")]
615pub fn dbus_escape_object_path(s: &str) -> glib::GString {
616 unsafe { from_glib_full(ffi::g_dbus_escape_object_path(s.to_glib_none().0)) }
617}
618
619//#[cfg(feature = "v2_68")]
620//#[cfg_attr(docsrs, doc(cfg(feature = "v2_68")))]
621//#[doc(alias = "g_dbus_escape_object_path_bytestring")]
622//pub fn dbus_escape_object_path_bytestring(bytes: &[u8]) -> glib::GString {
623// unsafe { TODO: call ffi:g_dbus_escape_object_path_bytestring() }
624//}
625
626/// Generate a D-Bus GUID that can be used with
627/// e.g. g_dbus_connection_new().
628///
629/// See the
630/// [D-Bus specification](https://dbus.freedesktop.org/doc/dbus-specification.html#uuids)
631/// regarding what strings are valid D-Bus GUIDs. The specification refers to
632/// these as ‘UUIDs’ whereas GLib (for historical reasons) refers to them as
633/// ‘GUIDs’. The terms are interchangeable.
634///
635/// Note that D-Bus GUIDs do not follow
636/// [RFC 4122](https://datatracker.ietf.org/doc/html/rfc4122).
637///
638/// # Returns
639///
640/// A valid D-Bus GUID. Free with g_free().
641#[doc(alias = "g_dbus_generate_guid")]
642pub fn dbus_generate_guid() -> glib::GString {
643 unsafe { from_glib_full(ffi::g_dbus_generate_guid()) }
644}
645
646/// Converts a #GValue to a #GVariant of the type indicated by the @type_
647/// parameter.
648///
649/// The conversion is using the following rules:
650///
651/// - `G_TYPE_STRING`: 's', 'o', 'g' or 'ay'
652/// - `G_TYPE_STRV`: 'as', 'ao' or 'aay'
653/// - `G_TYPE_BOOLEAN`: 'b'
654/// - `G_TYPE_UCHAR`: 'y'
655/// - `G_TYPE_INT`: 'i', 'n'
656/// - `G_TYPE_UINT`: 'u', 'q'
657/// - `G_TYPE_INT64`: 'x'
658/// - `G_TYPE_UINT64`: 't'
659/// - `G_TYPE_DOUBLE`: 'd'
660/// - `G_TYPE_VARIANT`: Any #GVariantType
661///
662/// This can fail if e.g. @gvalue is of type `G_TYPE_STRING` and @type_
663/// is 'i', i.e. `G_VARIANT_TYPE_INT32`. It will also fail for any #GType
664/// (including e.g. `G_TYPE_OBJECT` and `G_TYPE_BOXED` derived-types) not
665/// in the table above.
666///
667/// Note that if @gvalue is of type `G_TYPE_VARIANT` and its value is
668/// [`None`], the empty #GVariant instance (never [`None`]) for @type_ is
669/// returned (e.g. 0 for scalar types, the empty string for string types,
670/// '/' for object path types, the empty array for any array type and so on).
671///
672/// See the g_dbus_gvariant_to_gvalue() function for how to convert a
673/// #GVariant to a #GValue.
674/// ## `gvalue`
675/// A #GValue to convert to a #GVariant
676/// ## `type_`
677/// A #GVariantType
678///
679/// # Returns
680///
681/// A #GVariant (never floating) of
682/// #GVariantType @type_ holding the data from @gvalue or an empty #GVariant
683/// in case of failure. Free with g_variant_unref().
684#[doc(alias = "g_dbus_gvalue_to_gvariant")]
685pub fn dbus_gvalue_to_gvariant(gvalue: &glib::Value, type_: &glib::VariantTy) -> glib::Variant {
686 unsafe {
687 from_glib_full(ffi::g_dbus_gvalue_to_gvariant(
688 gvalue.to_glib_none().0,
689 type_.to_glib_none().0,
690 ))
691 }
692}
693
694/// Converts a #GVariant to a #GValue. If @value is floating, it is consumed.
695///
696/// The rules specified in the g_dbus_gvalue_to_gvariant() function are
697/// used - this function is essentially its reverse form. So, a #GVariant
698/// containing any basic or string array type will be converted to a #GValue
699/// containing a basic value or string array. Any other #GVariant (handle,
700/// variant, tuple, dict entry) will be converted to a #GValue containing that
701/// #GVariant.
702///
703/// The conversion never fails - a valid #GValue is always returned in
704/// @out_gvalue.
705/// ## `value`
706/// A #GVariant.
707///
708/// # Returns
709///
710///
711/// ## `out_gvalue`
712/// Return location pointing to a zero-filled (uninitialized) #GValue.
713#[doc(alias = "g_dbus_gvariant_to_gvalue")]
714pub fn dbus_gvariant_to_gvalue(value: &glib::Variant) -> glib::Value {
715 unsafe {
716 let mut out_gvalue = glib::Value::uninitialized();
717 ffi::g_dbus_gvariant_to_gvalue(value.to_glib_none().0, out_gvalue.to_glib_none_mut().0);
718 out_gvalue
719 }
720}
721
722/// Checks if @string is a
723/// [D-Bus address](https://dbus.freedesktop.org/doc/dbus-specification.html#addresses).
724///
725/// This doesn't check if @string is actually supported by #GDBusServer
726/// or #GDBusConnection - use g_dbus_is_supported_address() to do more
727/// checks.
728/// ## `string`
729/// A string.
730///
731/// # Returns
732///
733/// [`true`] if @string is a valid D-Bus address, [`false`] otherwise.
734#[doc(alias = "g_dbus_is_address")]
735pub fn dbus_is_address(string: &str) -> bool {
736 unsafe { from_glib(ffi::g_dbus_is_address(string.to_glib_none().0)) }
737}
738
739/// Check whether @string is a valid D-Bus error name.
740///
741/// This function returns the same result as g_dbus_is_interface_name(),
742/// because D-Bus error names are defined to have exactly the
743/// same syntax as interface names.
744/// ## `string`
745/// The string to check.
746///
747/// # Returns
748///
749/// [`true`] if valid, [`false`] otherwise.
750#[cfg(feature = "v2_70")]
751#[cfg_attr(docsrs, doc(cfg(feature = "v2_70")))]
752#[doc(alias = "g_dbus_is_error_name")]
753pub fn dbus_is_error_name(string: &str) -> bool {
754 unsafe { from_glib(ffi::g_dbus_is_error_name(string.to_glib_none().0)) }
755}
756
757/// Checks if @string is a D-Bus GUID.
758///
759/// See the documentation for g_dbus_generate_guid() for more information about
760/// the format of a GUID.
761/// ## `string`
762/// The string to check.
763///
764/// # Returns
765///
766/// [`true`] if @string is a GUID, [`false`] otherwise.
767#[doc(alias = "g_dbus_is_guid")]
768pub fn dbus_is_guid(string: &str) -> bool {
769 unsafe { from_glib(ffi::g_dbus_is_guid(string.to_glib_none().0)) }
770}
771
772/// Checks if @string is a valid D-Bus interface name.
773/// ## `string`
774/// The string to check.
775///
776/// # Returns
777///
778/// [`true`] if valid, [`false`] otherwise.
779#[doc(alias = "g_dbus_is_interface_name")]
780pub fn dbus_is_interface_name(string: &str) -> bool {
781 unsafe { from_glib(ffi::g_dbus_is_interface_name(string.to_glib_none().0)) }
782}
783
784/// Checks if @string is a valid D-Bus member (e.g. signal or method) name.
785/// ## `string`
786/// The string to check.
787///
788/// # Returns
789///
790/// [`true`] if valid, [`false`] otherwise.
791#[doc(alias = "g_dbus_is_member_name")]
792pub fn dbus_is_member_name(string: &str) -> bool {
793 unsafe { from_glib(ffi::g_dbus_is_member_name(string.to_glib_none().0)) }
794}
795
796/// Checks if @string is a valid D-Bus bus name (either unique or well-known).
797/// ## `string`
798/// The string to check.
799///
800/// # Returns
801///
802/// [`true`] if valid, [`false`] otherwise.
803#[doc(alias = "g_dbus_is_name")]
804pub fn dbus_is_name(string: &str) -> bool {
805 unsafe { from_glib(ffi::g_dbus_is_name(string.to_glib_none().0)) }
806}
807
808/// Like g_dbus_is_address() but also checks if the library supports the
809/// transports in @string and that key/value pairs for each transport
810/// are valid. See the specification of the
811/// [D-Bus address format](https://dbus.freedesktop.org/doc/dbus-specification.html#addresses).
812/// ## `string`
813/// A string.
814///
815/// # Returns
816///
817/// [`true`] if @string is a valid D-Bus address that is
818/// supported by this library, [`false`] if @error is set.
819#[doc(alias = "g_dbus_is_supported_address")]
820pub fn dbus_is_supported_address(string: &str) -> Result<(), glib::Error> {
821 unsafe {
822 let mut error = std::ptr::null_mut();
823 let is_ok = ffi::g_dbus_is_supported_address(string.to_glib_none().0, &mut error);
824 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
825 if error.is_null() {
826 Ok(())
827 } else {
828 Err(from_glib_full(error))
829 }
830 }
831}
832
833/// Checks if @string is a valid D-Bus unique bus name.
834/// ## `string`
835/// The string to check.
836///
837/// # Returns
838///
839/// [`true`] if valid, [`false`] otherwise.
840#[doc(alias = "g_dbus_is_unique_name")]
841pub fn dbus_is_unique_name(string: &str) -> bool {
842 unsafe { from_glib(ffi::g_dbus_is_unique_name(string.to_glib_none().0)) }
843}
844
845///
846/// int saved_errno;
847///
848/// ret = read (blah);
849/// saved_errno = errno;
850///
851/// g_io_error_from_errno (saved_errno);
852/// ]|
853/// ## `err_no`
854/// Error number as defined in errno.h.
855///
856/// # Returns
857///
858/// #GIOErrorEnum value for the given `errno.h` error number
859#[doc(alias = "g_io_error_from_errno")]
860pub fn io_error_from_errno(err_no: i32) -> IOErrorEnum {
861 unsafe { from_glib(ffi::g_io_error_from_errno(err_no)) }
862}
863
864/// Loads all the modules in the specified directory.
865///
866/// If don't require all modules to be initialized (and thus registering
867/// all gtypes) then you can use g_io_modules_scan_all_in_directory()
868/// which allows delayed/lazy loading of modules.
869/// ## `dirname`
870/// pathname for a directory containing modules
871/// to load.
872///
873/// # Returns
874///
875/// a list of #GIOModules loaded
876/// from the directory,
877/// All the modules are loaded into memory, if you want to
878/// unload them (enabling on-demand loading) you must call
879/// g_type_module_unuse() on all the modules. Free the list
880/// with g_list_free().
881#[doc(alias = "g_io_modules_load_all_in_directory")]
882pub fn io_modules_load_all_in_directory(dirname: impl AsRef<std::path::Path>) -> Vec<IOModule> {
883 unsafe {
884 FromGlibPtrContainer::from_glib_full(ffi::g_io_modules_load_all_in_directory(
885 dirname.as_ref().to_glib_none().0,
886 ))
887 }
888}
889
890/// Loads all the modules in the specified directory.
891///
892/// If don't require all modules to be initialized (and thus registering
893/// all gtypes) then you can use g_io_modules_scan_all_in_directory()
894/// which allows delayed/lazy loading of modules.
895/// ## `dirname`
896/// pathname for a directory containing modules
897/// to load.
898/// ## `scope`
899/// a scope to use when scanning the modules.
900///
901/// # Returns
902///
903/// a list of #GIOModules loaded
904/// from the directory,
905/// All the modules are loaded into memory, if you want to
906/// unload them (enabling on-demand loading) you must call
907/// g_type_module_unuse() on all the modules. Free the list
908/// with g_list_free().
909#[doc(alias = "g_io_modules_load_all_in_directory_with_scope")]
910pub fn io_modules_load_all_in_directory_with_scope(
911 dirname: impl AsRef<std::path::Path>,
912 scope: &mut IOModuleScope,
913) -> Vec<IOModule> {
914 unsafe {
915 FromGlibPtrContainer::from_glib_full(ffi::g_io_modules_load_all_in_directory_with_scope(
916 dirname.as_ref().to_glib_none().0,
917 scope.to_glib_none_mut().0,
918 ))
919 }
920}
921
922/// Scans all the modules in the specified directory, ensuring that
923/// any extension point implemented by a module is registered.
924///
925/// This may not actually load and initialize all the types in each
926/// module, some modules may be lazily loaded and initialized when
927/// an extension point it implements is used with e.g.
928/// g_io_extension_point_get_extensions() or
929/// g_io_extension_point_get_extension_by_name().
930///
931/// If you need to guarantee that all types are loaded in all the modules,
932/// use g_io_modules_load_all_in_directory().
933/// ## `dirname`
934/// pathname for a directory containing modules
935/// to scan.
936#[doc(alias = "g_io_modules_scan_all_in_directory")]
937pub fn io_modules_scan_all_in_directory(dirname: impl AsRef<std::path::Path>) {
938 unsafe {
939 ffi::g_io_modules_scan_all_in_directory(dirname.as_ref().to_glib_none().0);
940 }
941}
942
943/// Scans all the modules in the specified directory, ensuring that
944/// any extension point implemented by a module is registered.
945///
946/// This may not actually load and initialize all the types in each
947/// module, some modules may be lazily loaded and initialized when
948/// an extension point it implements is used with e.g.
949/// g_io_extension_point_get_extensions() or
950/// g_io_extension_point_get_extension_by_name().
951///
952/// If you need to guarantee that all types are loaded in all the modules,
953/// use g_io_modules_load_all_in_directory().
954/// ## `dirname`
955/// pathname for a directory containing modules
956/// to scan.
957/// ## `scope`
958/// a scope to use when scanning the modules
959#[doc(alias = "g_io_modules_scan_all_in_directory_with_scope")]
960pub fn io_modules_scan_all_in_directory_with_scope(
961 dirname: impl AsRef<std::path::Path>,
962 scope: &mut IOModuleScope,
963) {
964 unsafe {
965 ffi::g_io_modules_scan_all_in_directory_with_scope(
966 dirname.as_ref().to_glib_none().0,
967 scope.to_glib_none_mut().0,
968 );
969 }
970}
971
972/// Creates a keyfile-backed [`SettingsBackend`][crate::SettingsBackend].
973///
974/// The filename of the keyfile to use is given by @filename.
975///
976/// All settings read to or written from the backend must fall under the
977/// path given in @root_path (which must start and end with a slash and
978/// not contain two consecutive slashes). @root_path may be `"/"`.
979///
980/// If @root_group is non-`NULL` then it specifies the name of the keyfile
981/// group used for keys that are written directly below @root_path. For
982/// example, if @root_path is `"/apps/example/"` and @root_group is
983/// `"toplevel"`, then setting the key `"/apps/example/enabled"` to true will
984/// cause the following to appear in the keyfile:
985///
986/// ```text
987/// [toplevel]
988/// enabled=true
989/// ```
990///
991/// If @root_group is `NULL` then it is not permitted to store keys
992/// directly below the @root_path.
993///
994/// For keys not stored directly below @root_path (ie: in a sub-path),
995/// the name of the subpath (with the final slash stripped) is used as
996/// the name of the keyfile group. To continue the example, if
997/// `"/apps/example/profiles/default/font-size"` were set to
998/// `12` then the following would appear in the keyfile:
999///
1000/// ```text
1001/// [profiles/default]
1002/// font-size=12
1003/// ```
1004///
1005/// The backend will refuse writes (and return writability as being
1006/// false) for keys outside of @root_path and, in the event that
1007/// @root_group is `NULL`, also for keys directly under @root_path.
1008/// Writes will also be refused if the backend detects that it has the
1009/// inability to rewrite the keyfile (ie: the containing directory is not
1010/// writable).
1011///
1012/// There is no checking done for your key namespace clashing with the
1013/// syntax of the key file format. For example, if you have `[` or `]`
1014/// characters in your path names or `=` in your key names you may be in
1015/// trouble.
1016///
1017/// The backend reads default values from a keyfile called `defaults` in
1018/// the directory specified by the `GKeyfileSettingsBackend:defaults-dir`
1019/// property, and a list of locked keys from a text file with the name `locks` in
1020/// the same location.
1021/// ## `filename`
1022/// the filename of the keyfile
1023/// ## `root_path`
1024/// the path under which all settings keys appear
1025/// ## `root_group`
1026/// the group name corresponding to @root_path, or
1027/// `NULL` to disallow storing keys directly beneath @root_path
1028///
1029/// # Returns
1030///
1031/// a keyfile-backed [`SettingsBackend`][crate::SettingsBackend]
1032#[doc(alias = "g_keyfile_settings_backend_new")]
1033pub fn keyfile_settings_backend_new(
1034 filename: &str,
1035 root_path: &str,
1036 root_group: Option<&str>,
1037) -> SettingsBackend {
1038 unsafe {
1039 from_glib_full(ffi::g_keyfile_settings_backend_new(
1040 filename.to_glib_none().0,
1041 root_path.to_glib_none().0,
1042 root_group.to_glib_none().0,
1043 ))
1044 }
1045}
1046
1047/// Creates a memory-backed #GSettingsBackend.
1048///
1049/// This backend allows changes to settings, but does not write them
1050/// to any backing storage, so the next time you run your application,
1051/// the memory backend will start out with the default values again.
1052///
1053/// # Returns
1054///
1055/// a newly created #GSettingsBackend
1056#[doc(alias = "g_memory_settings_backend_new")]
1057pub fn memory_settings_backend_new() -> SettingsBackend {
1058 unsafe { from_glib_full(ffi::g_memory_settings_backend_new()) }
1059}
1060
1061/// Creates a readonly #GSettingsBackend.
1062///
1063/// This backend does not allow changes to settings, so all settings
1064/// will always have their default values.
1065///
1066/// # Returns
1067///
1068/// a newly created #GSettingsBackend
1069#[doc(alias = "g_null_settings_backend_new")]
1070pub fn null_settings_backend_new() -> SettingsBackend {
1071 unsafe { from_glib_full(ffi::g_null_settings_backend_new()) }
1072}
1073
1074/// Returns all the names of children at the specified @path in the set of
1075/// globally registered resources.
1076///
1077/// The return result is a `NULL` terminated list of strings which should
1078/// be released with `strfreev()`.
1079///
1080/// @lookup_flags controls the behaviour of the lookup.
1081/// ## `path`
1082/// A path name inside the resource
1083/// ## `lookup_flags`
1084/// A [`ResourceLookupFlags`][crate::ResourceLookupFlags]
1085///
1086/// # Returns
1087///
1088/// an array of constant strings
1089#[doc(alias = "g_resources_enumerate_children")]
1090pub fn resources_enumerate_children(
1091 path: &str,
1092 lookup_flags: ResourceLookupFlags,
1093) -> Result<Vec<glib::GString>, glib::Error> {
1094 unsafe {
1095 let mut error = std::ptr::null_mut();
1096 let ret = ffi::g_resources_enumerate_children(
1097 path.to_glib_none().0,
1098 lookup_flags.into_glib(),
1099 &mut error,
1100 );
1101 if error.is_null() {
1102 Ok(FromGlibPtrContainer::from_glib_full(ret))
1103 } else {
1104 Err(from_glib_full(error))
1105 }
1106 }
1107}
1108
1109/// Looks for a file at the specified @path in the set of
1110/// globally registered resources and if found returns information about it.
1111///
1112/// @lookup_flags controls the behaviour of the lookup.
1113/// ## `path`
1114/// A path name inside the resource
1115/// ## `lookup_flags`
1116/// A [`ResourceLookupFlags`][crate::ResourceLookupFlags]
1117///
1118/// # Returns
1119///
1120/// `TRUE` if the file was found, `FALSE` if there were errors
1121///
1122/// ## `size`
1123/// a location to place the length of the contents of the file,
1124/// or `NULL` if the length is not needed
1125///
1126/// ## `flags`
1127/// a location to place the [`ResourceFlags`][crate::ResourceFlags] about the file,
1128/// or `NULL` if the flags are not needed
1129#[doc(alias = "g_resources_get_info")]
1130pub fn resources_get_info(
1131 path: &str,
1132 lookup_flags: ResourceLookupFlags,
1133) -> Result<(usize, u32), glib::Error> {
1134 unsafe {
1135 let mut size = std::mem::MaybeUninit::uninit();
1136 let mut flags = std::mem::MaybeUninit::uninit();
1137 let mut error = std::ptr::null_mut();
1138 let is_ok = ffi::g_resources_get_info(
1139 path.to_glib_none().0,
1140 lookup_flags.into_glib(),
1141 size.as_mut_ptr(),
1142 flags.as_mut_ptr(),
1143 &mut error,
1144 );
1145 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
1146 if error.is_null() {
1147 Ok((size.assume_init(), flags.assume_init()))
1148 } else {
1149 Err(from_glib_full(error))
1150 }
1151 }
1152}
1153
1154/// Returns whether the specified @path in the set of
1155/// globally registered resources has children.
1156/// ## `path`
1157/// A pathname
1158///
1159/// # Returns
1160///
1161/// [`true`] if @patch has children
1162#[cfg(feature = "v2_84")]
1163#[cfg_attr(docsrs, doc(cfg(feature = "v2_84")))]
1164#[doc(alias = "g_resources_has_children")]
1165pub fn resources_has_children(path: &str) -> bool {
1166 unsafe { from_glib(ffi::g_resources_has_children(path.to_glib_none().0)) }
1167}
1168
1169/// Looks for a file at the specified @path in the set of
1170/// globally registered resources and returns a [`glib::Bytes`][crate::glib::Bytes] that
1171/// lets you directly access the data in memory.
1172///
1173/// The data is always followed by a zero byte, so you
1174/// can safely use the data as a C string. However, that byte
1175/// is not included in the size of the [`glib::Bytes`][crate::glib::Bytes].
1176///
1177/// For uncompressed resource files this is a pointer directly into
1178/// the resource bundle, which is typically in some read-only data section
1179/// in the program binary. For compressed files we allocate memory on
1180/// the heap and automatically uncompress the data.
1181///
1182/// @lookup_flags controls the behaviour of the lookup.
1183/// ## `path`
1184/// A path name inside the resource
1185/// ## `lookup_flags`
1186/// A [`ResourceLookupFlags`][crate::ResourceLookupFlags]
1187///
1188/// # Returns
1189///
1190/// [`glib::Bytes`][crate::glib::Bytes] or `NULL` on error
1191#[doc(alias = "g_resources_lookup_data")]
1192pub fn resources_lookup_data(
1193 path: &str,
1194 lookup_flags: ResourceLookupFlags,
1195) -> Result<glib::Bytes, glib::Error> {
1196 unsafe {
1197 let mut error = std::ptr::null_mut();
1198 let ret = ffi::g_resources_lookup_data(
1199 path.to_glib_none().0,
1200 lookup_flags.into_glib(),
1201 &mut error,
1202 );
1203 if error.is_null() {
1204 Ok(from_glib_full(ret))
1205 } else {
1206 Err(from_glib_full(error))
1207 }
1208 }
1209}
1210
1211/// Looks for a file at the specified @path in the set of
1212/// globally registered resources and returns a [`InputStream`][crate::InputStream]
1213/// that lets you read the data.
1214///
1215/// @lookup_flags controls the behaviour of the lookup.
1216/// ## `path`
1217/// A path name inside the resource
1218/// ## `lookup_flags`
1219/// A [`ResourceLookupFlags`][crate::ResourceLookupFlags]
1220///
1221/// # Returns
1222///
1223/// [`InputStream`][crate::InputStream] or `NULL` on error
1224#[doc(alias = "g_resources_open_stream")]
1225pub fn resources_open_stream(
1226 path: &str,
1227 lookup_flags: ResourceLookupFlags,
1228) -> Result<InputStream, glib::Error> {
1229 unsafe {
1230 let mut error = std::ptr::null_mut();
1231 let ret = ffi::g_resources_open_stream(
1232 path.to_glib_none().0,
1233 lookup_flags.into_glib(),
1234 &mut error,
1235 );
1236 if error.is_null() {
1237 Ok(from_glib_full(ret))
1238 } else {
1239 Err(from_glib_full(error))
1240 }
1241 }
1242}
1243
1244/// Registers the resource with the process-global set of resources.
1245///
1246/// Once a resource is registered the files in it can be accessed
1247/// with the global resource lookup functions like
1248/// [`resources_lookup_data()`][crate::resources_lookup_data()].
1249/// ## `resource`
1250/// A [`Resource`][crate::Resource]
1251#[doc(alias = "g_resources_register")]
1252pub fn resources_register(resource: &Resource) {
1253 unsafe {
1254 ffi::g_resources_register(resource.to_glib_none().0);
1255 }
1256}
1257
1258/// Unregisters the resource from the process-global set of resources.
1259/// ## `resource`
1260/// A [`Resource`][crate::Resource]
1261#[doc(alias = "g_resources_unregister")]
1262pub fn resources_unregister(resource: &Resource) {
1263 unsafe {
1264 ffi::g_resources_unregister(resource.to_glib_none().0);
1265 }
1266}