1#[cfg(feature = "futures")]
6use futures::future;
7use gio_sys;
8use glib;
9use glib::object::IsA;
10use glib::translate::*;
11use glib::GString;
12use glib_sys;
13use gobject_sys;
14use std;
15#[cfg(feature = "futures")]
16use std::boxed::Box as Box_;
17use std::mem;
18use std::ptr;
19use Cancellable;
20use Error;
21use File;
22use IOErrorEnum;
23use IOStream;
24use Icon;
25use InputStream;
26use Resource;
27use ResourceLookupFlags;
28use SettingsBackend;
29
30pub fn bus_unown_name(owner_id: u32) {
75 unsafe {
76 gio_sys::g_bus_unown_name(owner_id);
77 }
78}
79
80pub fn bus_unwatch_name(watcher_id: u32) {
81 unsafe {
82 gio_sys::g_bus_unwatch_name(watcher_id);
83 }
84}
85
86pub fn content_type_can_be_executable(type_: &str) -> bool {
103 unsafe {
104 from_glib(gio_sys::g_content_type_can_be_executable(
105 type_.to_glib_none().0,
106 ))
107 }
108}
109
110pub fn content_type_equals(type1: &str, type2: &str) -> bool {
111 unsafe {
112 from_glib(gio_sys::g_content_type_equals(
113 type1.to_glib_none().0,
114 type2.to_glib_none().0,
115 ))
116 }
117}
118
119pub fn content_type_from_mime_type(mime_type: &str) -> Option<GString> {
120 unsafe {
121 from_glib_full(gio_sys::g_content_type_from_mime_type(
122 mime_type.to_glib_none().0,
123 ))
124 }
125}
126
127pub fn content_type_get_description(type_: &str) -> Option<GString> {
128 unsafe {
129 from_glib_full(gio_sys::g_content_type_get_description(
130 type_.to_glib_none().0,
131 ))
132 }
133}
134
135pub fn content_type_get_generic_icon_name(type_: &str) -> Option<GString> {
136 unsafe {
137 from_glib_full(gio_sys::g_content_type_get_generic_icon_name(
138 type_.to_glib_none().0,
139 ))
140 }
141}
142
143pub fn content_type_get_icon(type_: &str) -> Option<Icon> {
144 unsafe { from_glib_full(gio_sys::g_content_type_get_icon(type_.to_glib_none().0)) }
145}
146
147pub fn content_type_get_mime_type(type_: &str) -> Option<GString> {
148 unsafe {
149 from_glib_full(gio_sys::g_content_type_get_mime_type(
150 type_.to_glib_none().0,
151 ))
152 }
153}
154
155pub fn content_type_get_symbolic_icon(type_: &str) -> Option<Icon> {
156 unsafe {
157 from_glib_full(gio_sys::g_content_type_get_symbolic_icon(
158 type_.to_glib_none().0,
159 ))
160 }
161}
162
163pub fn content_type_guess(filename: Option<&str>, data: &[u8]) -> (GString, bool) {
164 let data_size = data.len() as usize;
165 unsafe {
166 let mut result_uncertain = mem::uninitialized();
167 let ret = from_glib_full(gio_sys::g_content_type_guess(
168 filename.to_glib_none().0,
169 data.to_glib_none().0,
170 data_size,
171 &mut result_uncertain,
172 ));
173 (ret, from_glib(result_uncertain))
174 }
175}
176
177pub fn content_type_guess_for_tree<P: IsA<File>>(root: &P) -> Vec<GString> {
178 unsafe {
179 FromGlibPtrContainer::from_glib_full(gio_sys::g_content_type_guess_for_tree(
180 root.as_ref().to_glib_none().0,
181 ))
182 }
183}
184
185pub fn content_type_is_a(type_: &str, supertype: &str) -> bool {
186 unsafe {
187 from_glib(gio_sys::g_content_type_is_a(
188 type_.to_glib_none().0,
189 supertype.to_glib_none().0,
190 ))
191 }
192}
193
194#[cfg(any(feature = "v2_52", feature = "dox"))]
195pub fn content_type_is_mime_type(type_: &str, mime_type: &str) -> bool {
196 unsafe {
197 from_glib(gio_sys::g_content_type_is_mime_type(
198 type_.to_glib_none().0,
199 mime_type.to_glib_none().0,
200 ))
201 }
202}
203
204pub fn content_type_is_unknown(type_: &str) -> bool {
205 unsafe { from_glib(gio_sys::g_content_type_is_unknown(type_.to_glib_none().0)) }
206}
207
208pub fn content_types_get_registered() -> Vec<GString> {
209 unsafe { FromGlibPtrContainer::from_glib_full(gio_sys::g_content_types_get_registered()) }
210}
211
212pub fn dbus_address_escape_value(string: &str) -> Option<GString> {
213 unsafe {
214 from_glib_full(gio_sys::g_dbus_address_escape_value(
215 string.to_glib_none().0,
216 ))
217 }
218}
219
220pub fn dbus_address_get_stream<
225 P: IsA<Cancellable>,
226 Q: FnOnce(Result<(IOStream, GString), Error>) + Send + 'static,
227>(
228 address: &str,
229 cancellable: Option<&P>,
230 callback: Q,
231) {
232 let user_data: Box<Q> = Box::new(callback);
233 unsafe extern "C" fn dbus_address_get_stream_trampoline<
234 Q: FnOnce(Result<(IOStream, GString), Error>) + Send + 'static,
235 >(
236 _source_object: *mut gobject_sys::GObject,
237 res: *mut gio_sys::GAsyncResult,
238 user_data: glib_sys::gpointer,
239 ) {
240 let mut error = ptr::null_mut();
241 let mut out_guid = ptr::null_mut();
242 let ret = gio_sys::g_dbus_address_get_stream_finish(res, &mut out_guid, &mut error);
243 let result = if error.is_null() {
244 Ok((from_glib_full(ret), from_glib_full(out_guid)))
245 } else {
246 Err(from_glib_full(error))
247 };
248 let callback: Box<Q> = Box::from_raw(user_data as *mut _);
249 callback(result);
250 }
251 let callback = dbus_address_get_stream_trampoline::<Q>;
252 unsafe {
253 gio_sys::g_dbus_address_get_stream(
254 address.to_glib_none().0,
255 cancellable.map(|p| p.as_ref()).to_glib_none().0,
256 Some(callback),
257 Box::into_raw(user_data) as *mut _,
258 );
259 }
260}
261
262#[cfg(feature = "futures")]
263pub fn dbus_address_get_stream_future(
264 address: &str,
265) -> Box_<dyn future::Future<Output = Result<(IOStream, GString), Error>> + std::marker::Unpin> {
266 use fragile::Fragile;
267 use GioFuture;
268
269 let address = String::from(address);
270 GioFuture::new(&(), move |_obj, send| {
271 let cancellable = Cancellable::new();
272 let send = Fragile::new(send);
273 dbus_address_get_stream(&address, Some(&cancellable), move |res| {
274 let _ = send.into_inner().send(res);
275 });
276
277 cancellable
278 })
279}
280
281pub fn dbus_address_get_stream_sync<P: IsA<Cancellable>>(
282 address: &str,
283 cancellable: Option<&P>,
284) -> Result<(IOStream, GString), Error> {
285 unsafe {
286 let mut out_guid = ptr::null_mut();
287 let mut error = ptr::null_mut();
288 let ret = gio_sys::g_dbus_address_get_stream_sync(
289 address.to_glib_none().0,
290 &mut out_guid,
291 cancellable.map(|p| p.as_ref()).to_glib_none().0,
292 &mut error,
293 );
294 if error.is_null() {
295 Ok((from_glib_full(ret), from_glib_full(out_guid)))
296 } else {
297 Err(from_glib_full(error))
298 }
299 }
300}
301
302pub fn dbus_generate_guid() -> Option<GString> {
303 unsafe { from_glib_full(gio_sys::g_dbus_generate_guid()) }
304}
305
306pub fn dbus_gvalue_to_gvariant(
307 gvalue: &glib::Value,
308 type_: &glib::VariantTy,
309) -> Option<glib::Variant> {
310 unsafe {
311 from_glib_full(gio_sys::g_dbus_gvalue_to_gvariant(
312 gvalue.to_glib_none().0,
313 type_.to_glib_none().0,
314 ))
315 }
316}
317
318pub fn dbus_gvariant_to_gvalue(value: &glib::Variant) -> glib::Value {
319 unsafe {
320 let mut out_gvalue = glib::Value::uninitialized();
321 gio_sys::g_dbus_gvariant_to_gvalue(value.to_glib_none().0, out_gvalue.to_glib_none_mut().0);
322 out_gvalue
323 }
324}
325
326pub fn dbus_is_address(string: &str) -> bool {
327 unsafe { from_glib(gio_sys::g_dbus_is_address(string.to_glib_none().0)) }
328}
329
330pub fn dbus_is_guid(string: &str) -> bool {
331 unsafe { from_glib(gio_sys::g_dbus_is_guid(string.to_glib_none().0)) }
332}
333
334pub fn dbus_is_interface_name(string: &str) -> bool {
335 unsafe { from_glib(gio_sys::g_dbus_is_interface_name(string.to_glib_none().0)) }
336}
337
338pub fn dbus_is_member_name(string: &str) -> bool {
339 unsafe { from_glib(gio_sys::g_dbus_is_member_name(string.to_glib_none().0)) }
340}
341
342pub fn dbus_is_name(string: &str) -> bool {
343 unsafe { from_glib(gio_sys::g_dbus_is_name(string.to_glib_none().0)) }
344}
345
346pub fn dbus_is_supported_address(string: &str) -> Result<(), Error> {
347 unsafe {
348 let mut error = ptr::null_mut();
349 let _ = gio_sys::g_dbus_is_supported_address(string.to_glib_none().0, &mut error);
350 if error.is_null() {
351 Ok(())
352 } else {
353 Err(from_glib_full(error))
354 }
355 }
356}
357
358pub fn dbus_is_unique_name(string: &str) -> bool {
359 unsafe { from_glib(gio_sys::g_dbus_is_unique_name(string.to_glib_none().0)) }
360}
361
362pub fn io_error_from_errno(err_no: i32) -> IOErrorEnum {
363 unsafe { from_glib(gio_sys::g_io_error_from_errno(err_no)) }
364}
365
366pub fn io_error_quark() -> glib::Quark {
367 unsafe { from_glib(gio_sys::g_io_error_quark()) }
368}
369
370pub fn io_modules_scan_all_in_directory<P: AsRef<std::path::Path>>(dirname: P) {
379 unsafe {
380 gio_sys::g_io_modules_scan_all_in_directory(dirname.as_ref().to_glib_none().0);
381 }
382}
383
384pub fn io_scheduler_cancel_all_jobs() {
389 unsafe {
390 gio_sys::g_io_scheduler_cancel_all_jobs();
391 }
392}
393
394pub fn keyfile_settings_backend_new(
399 filename: &str,
400 root_path: &str,
401 root_group: Option<&str>,
402) -> Option<SettingsBackend> {
403 unsafe {
404 from_glib_full(gio_sys::g_keyfile_settings_backend_new(
405 filename.to_glib_none().0,
406 root_path.to_glib_none().0,
407 root_group.to_glib_none().0,
408 ))
409 }
410}
411
412pub fn memory_settings_backend_new() -> Option<SettingsBackend> {
413 unsafe { from_glib_full(gio_sys::g_memory_settings_backend_new()) }
414}
415
416pub fn networking_init() {
417 unsafe {
418 gio_sys::g_networking_init();
419 }
420}
421
422pub fn null_settings_backend_new() -> Option<SettingsBackend> {
423 unsafe { from_glib_full(gio_sys::g_null_settings_backend_new()) }
424}
425
426pub fn resources_enumerate_children(
427 path: &str,
428 lookup_flags: ResourceLookupFlags,
429) -> Result<Vec<GString>, Error> {
430 unsafe {
431 let mut error = ptr::null_mut();
432 let ret = gio_sys::g_resources_enumerate_children(
433 path.to_glib_none().0,
434 lookup_flags.to_glib(),
435 &mut error,
436 );
437 if error.is_null() {
438 Ok(FromGlibPtrContainer::from_glib_full(ret))
439 } else {
440 Err(from_glib_full(error))
441 }
442 }
443}
444
445pub fn resources_get_info(
446 path: &str,
447 lookup_flags: ResourceLookupFlags,
448) -> Result<(usize, u32), Error> {
449 unsafe {
450 let mut size = mem::uninitialized();
451 let mut flags = mem::uninitialized();
452 let mut error = ptr::null_mut();
453 let _ = gio_sys::g_resources_get_info(
454 path.to_glib_none().0,
455 lookup_flags.to_glib(),
456 &mut size,
457 &mut flags,
458 &mut error,
459 );
460 if error.is_null() {
461 Ok((size, flags))
462 } else {
463 Err(from_glib_full(error))
464 }
465 }
466}
467
468pub fn resources_lookup_data(
469 path: &str,
470 lookup_flags: ResourceLookupFlags,
471) -> Result<glib::Bytes, Error> {
472 unsafe {
473 let mut error = ptr::null_mut();
474 let ret = gio_sys::g_resources_lookup_data(
475 path.to_glib_none().0,
476 lookup_flags.to_glib(),
477 &mut error,
478 );
479 if error.is_null() {
480 Ok(from_glib_full(ret))
481 } else {
482 Err(from_glib_full(error))
483 }
484 }
485}
486
487pub fn resources_open_stream(
488 path: &str,
489 lookup_flags: ResourceLookupFlags,
490) -> Result<InputStream, Error> {
491 unsafe {
492 let mut error = ptr::null_mut();
493 let ret = gio_sys::g_resources_open_stream(
494 path.to_glib_none().0,
495 lookup_flags.to_glib(),
496 &mut error,
497 );
498 if error.is_null() {
499 Ok(from_glib_full(ret))
500 } else {
501 Err(from_glib_full(error))
502 }
503 }
504}
505
506pub fn resources_register(resource: &Resource) {
507 unsafe {
508 gio_sys::g_resources_register(resource.to_glib_none().0);
509 }
510}
511
512pub fn resources_unregister(resource: &Resource) {
513 unsafe {
514 gio_sys::g_resources_unregister(resource.to_glib_none().0);
515 }
516}
517
518#[cfg(any(unix, feature = "dox"))]
534pub fn unix_is_mount_path_system_internal<P: AsRef<std::path::Path>>(mount_path: P) -> bool {
535 unsafe {
536 from_glib(gio_sys::g_unix_is_mount_path_system_internal(
537 mount_path.as_ref().to_glib_none().0,
538 ))
539 }
540}
541
542#[cfg(any(unix, feature = "dox"))]
543#[cfg(any(feature = "v2_56", feature = "dox"))]
544pub fn unix_is_system_device_path<P: AsRef<std::path::Path>>(device_path: P) -> bool {
545 unsafe {
546 from_glib(gio_sys::g_unix_is_system_device_path(
547 device_path.as_ref().to_glib_none().0,
548 ))
549 }
550}
551
552#[cfg(any(unix, feature = "dox"))]
553#[cfg(any(feature = "v2_56", feature = "dox"))]
554pub fn unix_is_system_fs_type(fs_type: &str) -> bool {
555 unsafe { from_glib(gio_sys::g_unix_is_system_fs_type(fs_type.to_glib_none().0)) }
556}
557
558#[cfg(any(unix, feature = "dox"))]
642pub fn unix_mount_points_changed_since(time: u64) -> bool {
643 unsafe { from_glib(gio_sys::g_unix_mount_points_changed_since(time)) }
644}
645
646#[cfg(any(unix, feature = "dox"))]
652pub fn unix_mounts_changed_since(time: u64) -> bool {
653 unsafe { from_glib(gio_sys::g_unix_mounts_changed_since(time)) }
654}
655
656