1use crate::{Drive, Mount, Volume, ffi};
6use glib::{
7 object::ObjectType as _,
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
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 unsafe {
242 let f: &F = &*(f as *const F);
243 f(
244 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
245 &from_glib_borrow(drive),
246 )
247 }
248 }
249 unsafe {
250 let f: Box_<F> = Box_::new(f);
251 connect_raw(
252 self.as_ptr() as *mut _,
253 c"drive-changed".as_ptr() as *const _,
254 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
255 drive_changed_trampoline::<Self, F> as *const (),
256 )),
257 Box_::into_raw(f),
258 )
259 }
260 }
261
262 #[doc(alias = "drive-connected")]
266 fn connect_drive_connected<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
267 unsafe extern "C" fn drive_connected_trampoline<
268 P: IsA<VolumeMonitor>,
269 F: Fn(&P, &Drive) + 'static,
270 >(
271 this: *mut ffi::GVolumeMonitor,
272 drive: *mut ffi::GDrive,
273 f: glib::ffi::gpointer,
274 ) {
275 unsafe {
276 let f: &F = &*(f as *const F);
277 f(
278 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
279 &from_glib_borrow(drive),
280 )
281 }
282 }
283 unsafe {
284 let f: Box_<F> = Box_::new(f);
285 connect_raw(
286 self.as_ptr() as *mut _,
287 c"drive-connected".as_ptr() as *const _,
288 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
289 drive_connected_trampoline::<Self, F> as *const (),
290 )),
291 Box_::into_raw(f),
292 )
293 }
294 }
295
296 #[doc(alias = "drive-disconnected")]
300 fn connect_drive_disconnected<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
301 unsafe extern "C" fn drive_disconnected_trampoline<
302 P: IsA<VolumeMonitor>,
303 F: Fn(&P, &Drive) + 'static,
304 >(
305 this: *mut ffi::GVolumeMonitor,
306 drive: *mut ffi::GDrive,
307 f: glib::ffi::gpointer,
308 ) {
309 unsafe {
310 let f: &F = &*(f as *const F);
311 f(
312 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
313 &from_glib_borrow(drive),
314 )
315 }
316 }
317 unsafe {
318 let f: Box_<F> = Box_::new(f);
319 connect_raw(
320 self.as_ptr() as *mut _,
321 c"drive-disconnected".as_ptr() as *const _,
322 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
323 drive_disconnected_trampoline::<Self, F> as *const (),
324 )),
325 Box_::into_raw(f),
326 )
327 }
328 }
329
330 #[doc(alias = "drive-eject-button")]
334 fn connect_drive_eject_button<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
335 unsafe extern "C" fn drive_eject_button_trampoline<
336 P: IsA<VolumeMonitor>,
337 F: Fn(&P, &Drive) + 'static,
338 >(
339 this: *mut ffi::GVolumeMonitor,
340 drive: *mut ffi::GDrive,
341 f: glib::ffi::gpointer,
342 ) {
343 unsafe {
344 let f: &F = &*(f as *const F);
345 f(
346 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
347 &from_glib_borrow(drive),
348 )
349 }
350 }
351 unsafe {
352 let f: Box_<F> = Box_::new(f);
353 connect_raw(
354 self.as_ptr() as *mut _,
355 c"drive-eject-button".as_ptr() as *const _,
356 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
357 drive_eject_button_trampoline::<Self, F> as *const (),
358 )),
359 Box_::into_raw(f),
360 )
361 }
362 }
363
364 #[doc(alias = "drive-stop-button")]
368 fn connect_drive_stop_button<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
369 unsafe extern "C" fn drive_stop_button_trampoline<
370 P: IsA<VolumeMonitor>,
371 F: Fn(&P, &Drive) + 'static,
372 >(
373 this: *mut ffi::GVolumeMonitor,
374 drive: *mut ffi::GDrive,
375 f: glib::ffi::gpointer,
376 ) {
377 unsafe {
378 let f: &F = &*(f as *const F);
379 f(
380 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
381 &from_glib_borrow(drive),
382 )
383 }
384 }
385 unsafe {
386 let f: Box_<F> = Box_::new(f);
387 connect_raw(
388 self.as_ptr() as *mut _,
389 c"drive-stop-button".as_ptr() as *const _,
390 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
391 drive_stop_button_trampoline::<Self, F> as *const (),
392 )),
393 Box_::into_raw(f),
394 )
395 }
396 }
397
398 #[doc(alias = "mount-added")]
402 fn connect_mount_added<F: Fn(&Self, &Mount) + 'static>(&self, f: F) -> SignalHandlerId {
403 unsafe extern "C" fn mount_added_trampoline<
404 P: IsA<VolumeMonitor>,
405 F: Fn(&P, &Mount) + 'static,
406 >(
407 this: *mut ffi::GVolumeMonitor,
408 mount: *mut ffi::GMount,
409 f: glib::ffi::gpointer,
410 ) {
411 unsafe {
412 let f: &F = &*(f as *const F);
413 f(
414 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
415 &from_glib_borrow(mount),
416 )
417 }
418 }
419 unsafe {
420 let f: Box_<F> = Box_::new(f);
421 connect_raw(
422 self.as_ptr() as *mut _,
423 c"mount-added".as_ptr() as *const _,
424 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
425 mount_added_trampoline::<Self, F> as *const (),
426 )),
427 Box_::into_raw(f),
428 )
429 }
430 }
431
432 #[doc(alias = "mount-changed")]
436 fn connect_mount_changed<F: Fn(&Self, &Mount) + 'static>(&self, f: F) -> SignalHandlerId {
437 unsafe extern "C" fn mount_changed_trampoline<
438 P: IsA<VolumeMonitor>,
439 F: Fn(&P, &Mount) + 'static,
440 >(
441 this: *mut ffi::GVolumeMonitor,
442 mount: *mut ffi::GMount,
443 f: glib::ffi::gpointer,
444 ) {
445 unsafe {
446 let f: &F = &*(f as *const F);
447 f(
448 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
449 &from_glib_borrow(mount),
450 )
451 }
452 }
453 unsafe {
454 let f: Box_<F> = Box_::new(f);
455 connect_raw(
456 self.as_ptr() as *mut _,
457 c"mount-changed".as_ptr() as *const _,
458 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
459 mount_changed_trampoline::<Self, F> as *const (),
460 )),
461 Box_::into_raw(f),
462 )
463 }
464 }
465
466 #[doc(alias = "mount-pre-unmount")]
473 fn connect_mount_pre_unmount<F: Fn(&Self, &Mount) + 'static>(&self, f: F) -> SignalHandlerId {
474 unsafe extern "C" fn mount_pre_unmount_trampoline<
475 P: IsA<VolumeMonitor>,
476 F: Fn(&P, &Mount) + 'static,
477 >(
478 this: *mut ffi::GVolumeMonitor,
479 mount: *mut ffi::GMount,
480 f: glib::ffi::gpointer,
481 ) {
482 unsafe {
483 let f: &F = &*(f as *const F);
484 f(
485 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
486 &from_glib_borrow(mount),
487 )
488 }
489 }
490 unsafe {
491 let f: Box_<F> = Box_::new(f);
492 connect_raw(
493 self.as_ptr() as *mut _,
494 c"mount-pre-unmount".as_ptr() as *const _,
495 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
496 mount_pre_unmount_trampoline::<Self, F> as *const (),
497 )),
498 Box_::into_raw(f),
499 )
500 }
501 }
502
503 #[doc(alias = "mount-removed")]
507 fn connect_mount_removed<F: Fn(&Self, &Mount) + 'static>(&self, f: F) -> SignalHandlerId {
508 unsafe extern "C" fn mount_removed_trampoline<
509 P: IsA<VolumeMonitor>,
510 F: Fn(&P, &Mount) + 'static,
511 >(
512 this: *mut ffi::GVolumeMonitor,
513 mount: *mut ffi::GMount,
514 f: glib::ffi::gpointer,
515 ) {
516 unsafe {
517 let f: &F = &*(f as *const F);
518 f(
519 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
520 &from_glib_borrow(mount),
521 )
522 }
523 }
524 unsafe {
525 let f: Box_<F> = Box_::new(f);
526 connect_raw(
527 self.as_ptr() as *mut _,
528 c"mount-removed".as_ptr() as *const _,
529 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
530 mount_removed_trampoline::<Self, F> as *const (),
531 )),
532 Box_::into_raw(f),
533 )
534 }
535 }
536
537 #[doc(alias = "volume-added")]
541 fn connect_volume_added<F: Fn(&Self, &Volume) + 'static>(&self, f: F) -> SignalHandlerId {
542 unsafe extern "C" fn volume_added_trampoline<
543 P: IsA<VolumeMonitor>,
544 F: Fn(&P, &Volume) + 'static,
545 >(
546 this: *mut ffi::GVolumeMonitor,
547 volume: *mut ffi::GVolume,
548 f: glib::ffi::gpointer,
549 ) {
550 unsafe {
551 let f: &F = &*(f as *const F);
552 f(
553 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
554 &from_glib_borrow(volume),
555 )
556 }
557 }
558 unsafe {
559 let f: Box_<F> = Box_::new(f);
560 connect_raw(
561 self.as_ptr() as *mut _,
562 c"volume-added".as_ptr() as *const _,
563 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
564 volume_added_trampoline::<Self, F> as *const (),
565 )),
566 Box_::into_raw(f),
567 )
568 }
569 }
570
571 #[doc(alias = "volume-changed")]
575 fn connect_volume_changed<F: Fn(&Self, &Volume) + 'static>(&self, f: F) -> SignalHandlerId {
576 unsafe extern "C" fn volume_changed_trampoline<
577 P: IsA<VolumeMonitor>,
578 F: Fn(&P, &Volume) + 'static,
579 >(
580 this: *mut ffi::GVolumeMonitor,
581 volume: *mut ffi::GVolume,
582 f: glib::ffi::gpointer,
583 ) {
584 unsafe {
585 let f: &F = &*(f as *const F);
586 f(
587 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
588 &from_glib_borrow(volume),
589 )
590 }
591 }
592 unsafe {
593 let f: Box_<F> = Box_::new(f);
594 connect_raw(
595 self.as_ptr() as *mut _,
596 c"volume-changed".as_ptr() as *const _,
597 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
598 volume_changed_trampoline::<Self, F> as *const (),
599 )),
600 Box_::into_raw(f),
601 )
602 }
603 }
604
605 #[doc(alias = "volume-removed")]
609 fn connect_volume_removed<F: Fn(&Self, &Volume) + 'static>(&self, f: F) -> SignalHandlerId {
610 unsafe extern "C" fn volume_removed_trampoline<
611 P: IsA<VolumeMonitor>,
612 F: Fn(&P, &Volume) + 'static,
613 >(
614 this: *mut ffi::GVolumeMonitor,
615 volume: *mut ffi::GVolume,
616 f: glib::ffi::gpointer,
617 ) {
618 unsafe {
619 let f: &F = &*(f as *const F);
620 f(
621 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
622 &from_glib_borrow(volume),
623 )
624 }
625 }
626 unsafe {
627 let f: Box_<F> = Box_::new(f);
628 connect_raw(
629 self.as_ptr() as *mut _,
630 c"volume-removed".as_ptr() as *const _,
631 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
632 volume_removed_trampoline::<Self, F> as *const (),
633 )),
634 Box_::into_raw(f),
635 )
636 }
637 }
638}
639
640impl<O: IsA<VolumeMonitor>> VolumeMonitorExt for O {}