1use crate::{ffi, Drive, Mount, Volume};
6use glib::{
7 object::ObjectType as _,
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "GVolumeMonitor")]
108 pub struct VolumeMonitor(Object<ffi::GVolumeMonitor, ffi::GVolumeMonitorClass>);
109
110 match fn {
111 type_ => || ffi::g_volume_monitor_get_type(),
112 }
113}
114
115impl VolumeMonitor {
116 pub const NONE: Option<&'static VolumeMonitor> = None;
117
118 #[doc(alias = "g_volume_monitor_get")]
125 pub fn get() -> VolumeMonitor {
126 unsafe { from_glib_full(ffi::g_volume_monitor_get()) }
127 }
128}
129
130pub trait VolumeMonitorExt: IsA<VolumeMonitor> + 'static {
136 #[doc(alias = "g_volume_monitor_get_connected_drives")]
145 #[doc(alias = "get_connected_drives")]
146 fn connected_drives(&self) -> Vec<Drive> {
147 unsafe {
148 FromGlibPtrContainer::from_glib_full(ffi::g_volume_monitor_get_connected_drives(
149 self.as_ref().to_glib_none().0,
150 ))
151 }
152 }
153
154 #[doc(alias = "g_volume_monitor_get_mount_for_uuid")]
163 #[doc(alias = "get_mount_for_uuid")]
164 fn mount_for_uuid(&self, uuid: &str) -> Option<Mount> {
165 unsafe {
166 from_glib_full(ffi::g_volume_monitor_get_mount_for_uuid(
167 self.as_ref().to_glib_none().0,
168 uuid.to_glib_none().0,
169 ))
170 }
171 }
172
173 #[doc(alias = "g_volume_monitor_get_mounts")]
182 #[doc(alias = "get_mounts")]
183 fn mounts(&self) -> Vec<Mount> {
184 unsafe {
185 FromGlibPtrContainer::from_glib_full(ffi::g_volume_monitor_get_mounts(
186 self.as_ref().to_glib_none().0,
187 ))
188 }
189 }
190
191 #[doc(alias = "g_volume_monitor_get_volume_for_uuid")]
200 #[doc(alias = "get_volume_for_uuid")]
201 fn volume_for_uuid(&self, uuid: &str) -> Option<Volume> {
202 unsafe {
203 from_glib_full(ffi::g_volume_monitor_get_volume_for_uuid(
204 self.as_ref().to_glib_none().0,
205 uuid.to_glib_none().0,
206 ))
207 }
208 }
209
210 #[doc(alias = "g_volume_monitor_get_volumes")]
219 #[doc(alias = "get_volumes")]
220 fn volumes(&self) -> Vec<Volume> {
221 unsafe {
222 FromGlibPtrContainer::from_glib_full(ffi::g_volume_monitor_get_volumes(
223 self.as_ref().to_glib_none().0,
224 ))
225 }
226 }
227
228 #[doc(alias = "drive-changed")]
232 fn connect_drive_changed<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
233 unsafe extern "C" fn drive_changed_trampoline<
234 P: IsA<VolumeMonitor>,
235 F: Fn(&P, &Drive) + 'static,
236 >(
237 this: *mut ffi::GVolumeMonitor,
238 drive: *mut ffi::GDrive,
239 f: glib::ffi::gpointer,
240 ) {
241 let f: &F = &*(f as *const F);
242 f(
243 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
244 &from_glib_borrow(drive),
245 )
246 }
247 unsafe {
248 let f: Box_<F> = Box_::new(f);
249 connect_raw(
250 self.as_ptr() as *mut _,
251 c"drive-changed".as_ptr() as *const _,
252 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
253 drive_changed_trampoline::<Self, F> as *const (),
254 )),
255 Box_::into_raw(f),
256 )
257 }
258 }
259
260 #[doc(alias = "drive-connected")]
264 fn connect_drive_connected<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
265 unsafe extern "C" fn drive_connected_trampoline<
266 P: IsA<VolumeMonitor>,
267 F: Fn(&P, &Drive) + 'static,
268 >(
269 this: *mut ffi::GVolumeMonitor,
270 drive: *mut ffi::GDrive,
271 f: glib::ffi::gpointer,
272 ) {
273 let f: &F = &*(f as *const F);
274 f(
275 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
276 &from_glib_borrow(drive),
277 )
278 }
279 unsafe {
280 let f: Box_<F> = Box_::new(f);
281 connect_raw(
282 self.as_ptr() as *mut _,
283 c"drive-connected".as_ptr() as *const _,
284 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
285 drive_connected_trampoline::<Self, F> as *const (),
286 )),
287 Box_::into_raw(f),
288 )
289 }
290 }
291
292 #[doc(alias = "drive-disconnected")]
296 fn connect_drive_disconnected<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
297 unsafe extern "C" fn drive_disconnected_trampoline<
298 P: IsA<VolumeMonitor>,
299 F: Fn(&P, &Drive) + 'static,
300 >(
301 this: *mut ffi::GVolumeMonitor,
302 drive: *mut ffi::GDrive,
303 f: glib::ffi::gpointer,
304 ) {
305 let f: &F = &*(f as *const F);
306 f(
307 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
308 &from_glib_borrow(drive),
309 )
310 }
311 unsafe {
312 let f: Box_<F> = Box_::new(f);
313 connect_raw(
314 self.as_ptr() as *mut _,
315 c"drive-disconnected".as_ptr() as *const _,
316 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
317 drive_disconnected_trampoline::<Self, F> as *const (),
318 )),
319 Box_::into_raw(f),
320 )
321 }
322 }
323
324 #[doc(alias = "drive-eject-button")]
328 fn connect_drive_eject_button<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
329 unsafe extern "C" fn drive_eject_button_trampoline<
330 P: IsA<VolumeMonitor>,
331 F: Fn(&P, &Drive) + 'static,
332 >(
333 this: *mut ffi::GVolumeMonitor,
334 drive: *mut ffi::GDrive,
335 f: glib::ffi::gpointer,
336 ) {
337 let f: &F = &*(f as *const F);
338 f(
339 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
340 &from_glib_borrow(drive),
341 )
342 }
343 unsafe {
344 let f: Box_<F> = Box_::new(f);
345 connect_raw(
346 self.as_ptr() as *mut _,
347 c"drive-eject-button".as_ptr() as *const _,
348 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
349 drive_eject_button_trampoline::<Self, F> as *const (),
350 )),
351 Box_::into_raw(f),
352 )
353 }
354 }
355
356 #[doc(alias = "drive-stop-button")]
360 fn connect_drive_stop_button<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
361 unsafe extern "C" fn drive_stop_button_trampoline<
362 P: IsA<VolumeMonitor>,
363 F: Fn(&P, &Drive) + 'static,
364 >(
365 this: *mut ffi::GVolumeMonitor,
366 drive: *mut ffi::GDrive,
367 f: glib::ffi::gpointer,
368 ) {
369 let f: &F = &*(f as *const F);
370 f(
371 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
372 &from_glib_borrow(drive),
373 )
374 }
375 unsafe {
376 let f: Box_<F> = Box_::new(f);
377 connect_raw(
378 self.as_ptr() as *mut _,
379 c"drive-stop-button".as_ptr() as *const _,
380 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
381 drive_stop_button_trampoline::<Self, F> as *const (),
382 )),
383 Box_::into_raw(f),
384 )
385 }
386 }
387
388 #[doc(alias = "mount-added")]
392 fn connect_mount_added<F: Fn(&Self, &Mount) + 'static>(&self, f: F) -> SignalHandlerId {
393 unsafe extern "C" fn mount_added_trampoline<
394 P: IsA<VolumeMonitor>,
395 F: Fn(&P, &Mount) + 'static,
396 >(
397 this: *mut ffi::GVolumeMonitor,
398 mount: *mut ffi::GMount,
399 f: glib::ffi::gpointer,
400 ) {
401 let f: &F = &*(f as *const F);
402 f(
403 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
404 &from_glib_borrow(mount),
405 )
406 }
407 unsafe {
408 let f: Box_<F> = Box_::new(f);
409 connect_raw(
410 self.as_ptr() as *mut _,
411 c"mount-added".as_ptr() as *const _,
412 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
413 mount_added_trampoline::<Self, F> as *const (),
414 )),
415 Box_::into_raw(f),
416 )
417 }
418 }
419
420 #[doc(alias = "mount-changed")]
424 fn connect_mount_changed<F: Fn(&Self, &Mount) + 'static>(&self, f: F) -> SignalHandlerId {
425 unsafe extern "C" fn mount_changed_trampoline<
426 P: IsA<VolumeMonitor>,
427 F: Fn(&P, &Mount) + 'static,
428 >(
429 this: *mut ffi::GVolumeMonitor,
430 mount: *mut ffi::GMount,
431 f: glib::ffi::gpointer,
432 ) {
433 let f: &F = &*(f as *const F);
434 f(
435 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
436 &from_glib_borrow(mount),
437 )
438 }
439 unsafe {
440 let f: Box_<F> = Box_::new(f);
441 connect_raw(
442 self.as_ptr() as *mut _,
443 c"mount-changed".as_ptr() as *const _,
444 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
445 mount_changed_trampoline::<Self, F> as *const (),
446 )),
447 Box_::into_raw(f),
448 )
449 }
450 }
451
452 #[doc(alias = "mount-pre-unmount")]
459 fn connect_mount_pre_unmount<F: Fn(&Self, &Mount) + 'static>(&self, f: F) -> SignalHandlerId {
460 unsafe extern "C" fn mount_pre_unmount_trampoline<
461 P: IsA<VolumeMonitor>,
462 F: Fn(&P, &Mount) + 'static,
463 >(
464 this: *mut ffi::GVolumeMonitor,
465 mount: *mut ffi::GMount,
466 f: glib::ffi::gpointer,
467 ) {
468 let f: &F = &*(f as *const F);
469 f(
470 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
471 &from_glib_borrow(mount),
472 )
473 }
474 unsafe {
475 let f: Box_<F> = Box_::new(f);
476 connect_raw(
477 self.as_ptr() as *mut _,
478 c"mount-pre-unmount".as_ptr() as *const _,
479 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
480 mount_pre_unmount_trampoline::<Self, F> as *const (),
481 )),
482 Box_::into_raw(f),
483 )
484 }
485 }
486
487 #[doc(alias = "mount-removed")]
491 fn connect_mount_removed<F: Fn(&Self, &Mount) + 'static>(&self, f: F) -> SignalHandlerId {
492 unsafe extern "C" fn mount_removed_trampoline<
493 P: IsA<VolumeMonitor>,
494 F: Fn(&P, &Mount) + 'static,
495 >(
496 this: *mut ffi::GVolumeMonitor,
497 mount: *mut ffi::GMount,
498 f: glib::ffi::gpointer,
499 ) {
500 let f: &F = &*(f as *const F);
501 f(
502 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
503 &from_glib_borrow(mount),
504 )
505 }
506 unsafe {
507 let f: Box_<F> = Box_::new(f);
508 connect_raw(
509 self.as_ptr() as *mut _,
510 c"mount-removed".as_ptr() as *const _,
511 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
512 mount_removed_trampoline::<Self, F> as *const (),
513 )),
514 Box_::into_raw(f),
515 )
516 }
517 }
518
519 #[doc(alias = "volume-added")]
523 fn connect_volume_added<F: Fn(&Self, &Volume) + 'static>(&self, f: F) -> SignalHandlerId {
524 unsafe extern "C" fn volume_added_trampoline<
525 P: IsA<VolumeMonitor>,
526 F: Fn(&P, &Volume) + 'static,
527 >(
528 this: *mut ffi::GVolumeMonitor,
529 volume: *mut ffi::GVolume,
530 f: glib::ffi::gpointer,
531 ) {
532 let f: &F = &*(f as *const F);
533 f(
534 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
535 &from_glib_borrow(volume),
536 )
537 }
538 unsafe {
539 let f: Box_<F> = Box_::new(f);
540 connect_raw(
541 self.as_ptr() as *mut _,
542 c"volume-added".as_ptr() as *const _,
543 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
544 volume_added_trampoline::<Self, F> as *const (),
545 )),
546 Box_::into_raw(f),
547 )
548 }
549 }
550
551 #[doc(alias = "volume-changed")]
555 fn connect_volume_changed<F: Fn(&Self, &Volume) + 'static>(&self, f: F) -> SignalHandlerId {
556 unsafe extern "C" fn volume_changed_trampoline<
557 P: IsA<VolumeMonitor>,
558 F: Fn(&P, &Volume) + 'static,
559 >(
560 this: *mut ffi::GVolumeMonitor,
561 volume: *mut ffi::GVolume,
562 f: glib::ffi::gpointer,
563 ) {
564 let f: &F = &*(f as *const F);
565 f(
566 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
567 &from_glib_borrow(volume),
568 )
569 }
570 unsafe {
571 let f: Box_<F> = Box_::new(f);
572 connect_raw(
573 self.as_ptr() as *mut _,
574 c"volume-changed".as_ptr() as *const _,
575 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
576 volume_changed_trampoline::<Self, F> as *const (),
577 )),
578 Box_::into_raw(f),
579 )
580 }
581 }
582
583 #[doc(alias = "volume-removed")]
587 fn connect_volume_removed<F: Fn(&Self, &Volume) + 'static>(&self, f: F) -> SignalHandlerId {
588 unsafe extern "C" fn volume_removed_trampoline<
589 P: IsA<VolumeMonitor>,
590 F: Fn(&P, &Volume) + 'static,
591 >(
592 this: *mut ffi::GVolumeMonitor,
593 volume: *mut ffi::GVolume,
594 f: glib::ffi::gpointer,
595 ) {
596 let f: &F = &*(f as *const F);
597 f(
598 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
599 &from_glib_borrow(volume),
600 )
601 }
602 unsafe {
603 let f: Box_<F> = Box_::new(f);
604 connect_raw(
605 self.as_ptr() as *mut _,
606 c"volume-removed".as_ptr() as *const _,
607 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
608 volume_removed_trampoline::<Self, F> as *const (),
609 )),
610 Box_::into_raw(f),
611 )
612 }
613 }
614}
615
616impl<O: IsA<VolumeMonitor>> VolumeMonitorExt for O {}