1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
use crate::AsyncResult;
use crate::BusType;
use crate::Cancellable;
use crate::DBusConnection;
use crate::File;
use crate::IOErrorEnum;
use crate::IOStream;
use crate::Icon;
use crate::InputStream;
use crate::Resource;
use crate::ResourceLookupFlags;
use crate::SettingsBackend;
use glib::object::IsA;
use glib::translate::*;
use std::boxed::Box as Box_;
use std::mem;
use std::pin::Pin;
use std::ptr;
#[doc(alias = "g_bus_get")]
pub fn bus_get<P: FnOnce(Result<DBusConnection, glib::Error>) + 'static>(
bus_type: BusType,
cancellable: Option<&impl IsA<Cancellable>>,
callback: P,
) {
let main_context = glib::MainContext::ref_thread_default();
let is_main_context_owner = main_context.is_owner();
let has_acquired_main_context = (!is_main_context_owner)
.then(|| main_context.acquire().ok())
.flatten();
assert!(
is_main_context_owner || has_acquired_main_context.is_some(),
"Async operations only allowed if the thread is owning the MainContext"
);
let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
Box_::new(glib::thread_guard::ThreadGuard::new(callback));
unsafe extern "C" fn bus_get_trampoline<
P: FnOnce(Result<DBusConnection, glib::Error>) + 'static,
>(
_source_object: *mut glib::gobject_ffi::GObject,
res: *mut crate::ffi::GAsyncResult,
user_data: glib::ffi::gpointer,
) {
let mut error = ptr::null_mut();
let ret = ffi::g_bus_get_finish(res, &mut error);
let result = if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
};
let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
Box_::from_raw(user_data as *mut _);
let callback: P = callback.into_inner();
callback(result);
}
let callback = bus_get_trampoline::<P>;
unsafe {
ffi::g_bus_get(
bus_type.into_glib(),
cancellable.map(|p| p.as_ref()).to_glib_none().0,
Some(callback),
Box_::into_raw(user_data) as *mut _,
);
}
}
pub fn bus_get_future(
bus_type: BusType,
) -> Pin<Box_<dyn std::future::Future<Output = Result<DBusConnection, glib::Error>> + 'static>> {
Box_::pin(crate::GioFuture::new(
&(),
move |_obj, cancellable, send| {
bus_get(bus_type, Some(cancellable), move |res| {
send.resolve(res);
});
},
))
}
#[doc(alias = "g_bus_get_sync")]
pub fn bus_get_sync(
bus_type: BusType,
cancellable: Option<&impl IsA<Cancellable>>,
) -> Result<DBusConnection, glib::Error> {
unsafe {
let mut error = ptr::null_mut();
let ret = ffi::g_bus_get_sync(
bus_type.into_glib(),
cancellable.map(|p| p.as_ref()).to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
#[doc(alias = "g_content_type_can_be_executable")]
pub fn content_type_can_be_executable(type_: &str) -> bool {
unsafe {
from_glib(ffi::g_content_type_can_be_executable(
type_.to_glib_none().0,
))
}
}
#[doc(alias = "g_content_type_equals")]
pub fn content_type_equals(type1: &str, type2: &str) -> bool {
unsafe {
from_glib(ffi::g_content_type_equals(
type1.to_glib_none().0,
type2.to_glib_none().0,
))
}
}
#[doc(alias = "g_content_type_from_mime_type")]
pub fn content_type_from_mime_type(mime_type: &str) -> Option<glib::GString> {
unsafe {
from_glib_full(ffi::g_content_type_from_mime_type(
mime_type.to_glib_none().0,
))
}
}
#[doc(alias = "g_content_type_get_description")]
pub fn content_type_get_description(type_: &str) -> glib::GString {
unsafe { from_glib_full(ffi::g_content_type_get_description(type_.to_glib_none().0)) }
}
#[doc(alias = "g_content_type_get_generic_icon_name")]
pub fn content_type_get_generic_icon_name(type_: &str) -> Option<glib::GString> {
unsafe {
from_glib_full(ffi::g_content_type_get_generic_icon_name(
type_.to_glib_none().0,
))
}
}
#[doc(alias = "g_content_type_get_icon")]
pub fn content_type_get_icon(type_: &str) -> Icon {
unsafe { from_glib_full(ffi::g_content_type_get_icon(type_.to_glib_none().0)) }
}
#[cfg(any(feature = "v2_60", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_60")))]
#[doc(alias = "g_content_type_get_mime_dirs")]
pub fn content_type_get_mime_dirs() -> Vec<glib::GString> {
unsafe { FromGlibPtrContainer::from_glib_none(ffi::g_content_type_get_mime_dirs()) }
}
#[doc(alias = "g_content_type_get_mime_type")]
pub fn content_type_get_mime_type(type_: &str) -> Option<glib::GString> {
unsafe { from_glib_full(ffi::g_content_type_get_mime_type(type_.to_glib_none().0)) }
}
#[doc(alias = "g_content_type_get_symbolic_icon")]
pub fn content_type_get_symbolic_icon(type_: &str) -> Icon {
unsafe {
from_glib_full(ffi::g_content_type_get_symbolic_icon(
type_.to_glib_none().0,
))
}
}
#[doc(alias = "g_content_type_guess")]
pub fn content_type_guess(
filename: Option<impl AsRef<std::path::Path>>,
data: &[u8],
) -> (glib::GString, bool) {
let data_size = data.len() as usize;
unsafe {
let mut result_uncertain = mem::MaybeUninit::uninit();
let ret = from_glib_full(ffi::g_content_type_guess(
filename.as_ref().map(|p| p.as_ref()).to_glib_none().0,
data.to_glib_none().0,
data_size,
result_uncertain.as_mut_ptr(),
));
let result_uncertain = result_uncertain.assume_init();
(ret, from_glib(result_uncertain))
}
}
#[doc(alias = "g_content_type_guess_for_tree")]
pub fn content_type_guess_for_tree(root: &impl IsA<File>) -> Vec<glib::GString> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::g_content_type_guess_for_tree(
root.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "g_content_type_is_a")]
pub fn content_type_is_a(type_: &str, supertype: &str) -> bool {
unsafe {
from_glib(ffi::g_content_type_is_a(
type_.to_glib_none().0,
supertype.to_glib_none().0,
))
}
}
#[cfg(any(feature = "v2_52", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_52")))]
#[doc(alias = "g_content_type_is_mime_type")]
pub fn content_type_is_mime_type(type_: &str, mime_type: &str) -> bool {
unsafe {
from_glib(ffi::g_content_type_is_mime_type(
type_.to_glib_none().0,
mime_type.to_glib_none().0,
))
}
}
#[doc(alias = "g_content_type_is_unknown")]
pub fn content_type_is_unknown(type_: &str) -> bool {
unsafe { from_glib(ffi::g_content_type_is_unknown(type_.to_glib_none().0)) }
}
#[cfg(any(feature = "v2_60", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_60")))]
#[doc(alias = "g_content_type_set_mime_dirs")]
pub fn content_type_set_mime_dirs(dirs: &[&str]) {
unsafe {
ffi::g_content_type_set_mime_dirs(dirs.to_glib_none().0);
}
}
#[doc(alias = "g_content_types_get_registered")]
pub fn content_types_get_registered() -> Vec<glib::GString> {
unsafe { FromGlibPtrContainer::from_glib_full(ffi::g_content_types_get_registered()) }
}
#[doc(alias = "g_dbus_address_escape_value")]
pub fn dbus_address_escape_value(string: &str) -> glib::GString {
unsafe { from_glib_full(ffi::g_dbus_address_escape_value(string.to_glib_none().0)) }
}
#[doc(alias = "g_dbus_address_get_for_bus_sync")]
pub fn dbus_address_get_for_bus_sync(
bus_type: BusType,
cancellable: Option<&impl IsA<Cancellable>>,
) -> Result<glib::GString, glib::Error> {
unsafe {
let mut error = ptr::null_mut();
let ret = ffi::g_dbus_address_get_for_bus_sync(
bus_type.into_glib(),
cancellable.map(|p| p.as_ref()).to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
#[doc(alias = "g_dbus_address_get_stream")]
pub fn dbus_address_get_stream<
P: FnOnce(Result<(IOStream, Option<glib::GString>), glib::Error>) + 'static,
>(
address: &str,
cancellable: Option<&impl IsA<Cancellable>>,
callback: P,
) {
let main_context = glib::MainContext::ref_thread_default();
let is_main_context_owner = main_context.is_owner();
let has_acquired_main_context = (!is_main_context_owner)
.then(|| main_context.acquire().ok())
.flatten();
assert!(
is_main_context_owner || has_acquired_main_context.is_some(),
"Async operations only allowed if the thread is owning the MainContext"
);
let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
Box_::new(glib::thread_guard::ThreadGuard::new(callback));
unsafe extern "C" fn dbus_address_get_stream_trampoline<
P: FnOnce(Result<(IOStream, Option<glib::GString>), glib::Error>) + 'static,
>(
_source_object: *mut glib::gobject_ffi::GObject,
res: *mut crate::ffi::GAsyncResult,
user_data: glib::ffi::gpointer,
) {
let mut error = ptr::null_mut();
let mut out_guid = ptr::null_mut();
let ret = ffi::g_dbus_address_get_stream_finish(res, &mut out_guid, &mut error);
let result = if error.is_null() {
Ok((from_glib_full(ret), from_glib_full(out_guid)))
} else {
Err(from_glib_full(error))
};
let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
Box_::from_raw(user_data as *mut _);
let callback: P = callback.into_inner();
callback(result);
}
let callback = dbus_address_get_stream_trampoline::<P>;
unsafe {
ffi::g_dbus_address_get_stream(
address.to_glib_none().0,
cancellable.map(|p| p.as_ref()).to_glib_none().0,
Some(callback),
Box_::into_raw(user_data) as *mut _,
);
}
}
pub fn dbus_address_get_stream_future(
address: &str,
) -> Pin<
Box_<
dyn std::future::Future<Output = Result<(IOStream, Option<glib::GString>), glib::Error>>
+ 'static,
>,
> {
let address = String::from(address);
Box_::pin(crate::GioFuture::new(
&(),
move |_obj, cancellable, send| {
dbus_address_get_stream(&address, Some(cancellable), move |res| {
send.resolve(res);
});
},
))
}
#[doc(alias = "g_dbus_address_get_stream_sync")]
pub fn dbus_address_get_stream_sync(
address: &str,
cancellable: Option<&impl IsA<Cancellable>>,
) -> Result<(IOStream, Option<glib::GString>), glib::Error> {
unsafe {
let mut out_guid = ptr::null_mut();
let mut error = ptr::null_mut();
let ret = ffi::g_dbus_address_get_stream_sync(
address.to_glib_none().0,
&mut out_guid,
cancellable.map(|p| p.as_ref()).to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok((from_glib_full(ret), from_glib_full(out_guid)))
} else {
Err(from_glib_full(error))
}
}
}
#[cfg(any(feature = "v2_68", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_68")))]
#[doc(alias = "g_dbus_escape_object_path")]
pub fn dbus_escape_object_path(s: &str) -> glib::GString {
unsafe { from_glib_full(ffi::g_dbus_escape_object_path(s.to_glib_none().0)) }
}
#[doc(alias = "g_dbus_generate_guid")]
pub fn dbus_generate_guid() -> glib::GString {
unsafe { from_glib_full(ffi::g_dbus_generate_guid()) }
}
#[doc(alias = "g_dbus_gvalue_to_gvariant")]
pub fn dbus_gvalue_to_gvariant(gvalue: &glib::Value, type_: &glib::VariantTy) -> glib::Variant {
unsafe {
from_glib_full(ffi::g_dbus_gvalue_to_gvariant(
gvalue.to_glib_none().0,
type_.to_glib_none().0,
))
}
}
#[doc(alias = "g_dbus_gvariant_to_gvalue")]
pub fn dbus_gvariant_to_gvalue(value: &glib::Variant) -> glib::Value {
unsafe {
let mut out_gvalue = glib::Value::uninitialized();
ffi::g_dbus_gvariant_to_gvalue(value.to_glib_none().0, out_gvalue.to_glib_none_mut().0);
out_gvalue
}
}
#[doc(alias = "g_dbus_is_address")]
pub fn dbus_is_address(string: &str) -> bool {
unsafe { from_glib(ffi::g_dbus_is_address(string.to_glib_none().0)) }
}
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
#[doc(alias = "g_dbus_is_error_name")]
pub fn dbus_is_error_name(string: &str) -> bool {
unsafe { from_glib(ffi::g_dbus_is_error_name(string.to_glib_none().0)) }
}
#[doc(alias = "g_dbus_is_guid")]
pub fn dbus_is_guid(string: &str) -> bool {
unsafe { from_glib(ffi::g_dbus_is_guid(string.to_glib_none().0)) }
}
#[doc(alias = "g_dbus_is_interface_name")]
pub fn dbus_is_interface_name(string: &str) -> bool {
unsafe { from_glib(ffi::g_dbus_is_interface_name(string.to_glib_none().0)) }
}
#[doc(alias = "g_dbus_is_member_name")]
pub fn dbus_is_member_name(string: &str) -> bool {
unsafe { from_glib(ffi::g_dbus_is_member_name(string.to_glib_none().0)) }
}
#[doc(alias = "g_dbus_is_name")]
pub fn dbus_is_name(string: &str) -> bool {
unsafe { from_glib(ffi::g_dbus_is_name(string.to_glib_none().0)) }
}
#[doc(alias = "g_dbus_is_supported_address")]
pub fn dbus_is_supported_address(string: &str) -> Result<(), glib::Error> {
unsafe {
let mut error = ptr::null_mut();
let is_ok = ffi::g_dbus_is_supported_address(string.to_glib_none().0, &mut error);
assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
#[doc(alias = "g_dbus_is_unique_name")]
pub fn dbus_is_unique_name(string: &str) -> bool {
unsafe { from_glib(ffi::g_dbus_is_unique_name(string.to_glib_none().0)) }
}
#[doc(alias = "g_io_error_from_errno")]
pub fn io_error_from_errno(err_no: i32) -> IOErrorEnum {
unsafe { from_glib(ffi::g_io_error_from_errno(err_no)) }
}
#[doc(alias = "g_io_modules_scan_all_in_directory")]
pub fn io_modules_scan_all_in_directory(dirname: impl AsRef<std::path::Path>) {
unsafe {
ffi::g_io_modules_scan_all_in_directory(dirname.as_ref().to_glib_none().0);
}
}
#[doc(alias = "g_keyfile_settings_backend_new")]
pub fn keyfile_settings_backend_new(
filename: &str,
root_path: &str,
root_group: Option<&str>,
) -> SettingsBackend {
unsafe {
from_glib_full(ffi::g_keyfile_settings_backend_new(
filename.to_glib_none().0,
root_path.to_glib_none().0,
root_group.to_glib_none().0,
))
}
}
#[doc(alias = "g_memory_settings_backend_new")]
pub fn memory_settings_backend_new() -> SettingsBackend {
unsafe { from_glib_full(ffi::g_memory_settings_backend_new()) }
}
#[doc(alias = "g_null_settings_backend_new")]
pub fn null_settings_backend_new() -> SettingsBackend {
unsafe { from_glib_full(ffi::g_null_settings_backend_new()) }
}
#[doc(alias = "g_resources_enumerate_children")]
pub fn resources_enumerate_children(
path: &str,
lookup_flags: ResourceLookupFlags,
) -> Result<Vec<glib::GString>, glib::Error> {
unsafe {
let mut error = ptr::null_mut();
let ret = ffi::g_resources_enumerate_children(
path.to_glib_none().0,
lookup_flags.into_glib(),
&mut error,
);
if error.is_null() {
Ok(FromGlibPtrContainer::from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
#[doc(alias = "g_resources_get_info")]
pub fn resources_get_info(
path: &str,
lookup_flags: ResourceLookupFlags,
) -> Result<(usize, u32), glib::Error> {
unsafe {
let mut size = mem::MaybeUninit::uninit();
let mut flags = mem::MaybeUninit::uninit();
let mut error = ptr::null_mut();
let is_ok = ffi::g_resources_get_info(
path.to_glib_none().0,
lookup_flags.into_glib(),
size.as_mut_ptr(),
flags.as_mut_ptr(),
&mut error,
);
let size = size.assume_init();
let flags = flags.assume_init();
assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok((size, flags))
} else {
Err(from_glib_full(error))
}
}
}
#[doc(alias = "g_resources_lookup_data")]
pub fn resources_lookup_data(
path: &str,
lookup_flags: ResourceLookupFlags,
) -> Result<glib::Bytes, glib::Error> {
unsafe {
let mut error = ptr::null_mut();
let ret = ffi::g_resources_lookup_data(
path.to_glib_none().0,
lookup_flags.into_glib(),
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
#[doc(alias = "g_resources_open_stream")]
pub fn resources_open_stream(
path: &str,
lookup_flags: ResourceLookupFlags,
) -> Result<InputStream, glib::Error> {
unsafe {
let mut error = ptr::null_mut();
let ret = ffi::g_resources_open_stream(
path.to_glib_none().0,
lookup_flags.into_glib(),
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
#[doc(alias = "g_resources_register")]
pub fn resources_register(resource: &Resource) {
unsafe {
ffi::g_resources_register(resource.to_glib_none().0);
}
}
#[doc(alias = "g_resources_unregister")]
pub fn resources_unregister(resource: &Resource) {
unsafe {
ffi::g_resources_unregister(resource.to_glib_none().0);
}
}
#[cfg(any(unix, feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
#[doc(alias = "g_unix_is_mount_path_system_internal")]
pub fn unix_is_mount_path_system_internal(mount_path: impl AsRef<std::path::Path>) -> bool {
unsafe {
from_glib(ffi::g_unix_is_mount_path_system_internal(
mount_path.as_ref().to_glib_none().0,
))
}
}
#[cfg(any(unix, feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
#[cfg(any(feature = "v2_56", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_56")))]
#[doc(alias = "g_unix_is_system_device_path")]
pub fn unix_is_system_device_path(device_path: impl AsRef<std::path::Path>) -> bool {
unsafe {
from_glib(ffi::g_unix_is_system_device_path(
device_path.as_ref().to_glib_none().0,
))
}
}
#[cfg(any(unix, feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
#[cfg(any(feature = "v2_56", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_56")))]
#[doc(alias = "g_unix_is_system_fs_type")]
pub fn unix_is_system_fs_type(fs_type: &str) -> bool {
unsafe { from_glib(ffi::g_unix_is_system_fs_type(fs_type.to_glib_none().0)) }
}