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
130mod sealed {
131 pub trait Sealed {}
132 impl<T: super::IsA<super::VolumeMonitor>> Sealed for T {}
133}
134
135pub trait VolumeMonitorExt: IsA<VolumeMonitor> + sealed::Sealed + 'static {
141 #[doc(alias = "g_volume_monitor_get_connected_drives")]
150 #[doc(alias = "get_connected_drives")]
151 fn connected_drives(&self) -> Vec<Drive> {
152 unsafe {
153 FromGlibPtrContainer::from_glib_full(ffi::g_volume_monitor_get_connected_drives(
154 self.as_ref().to_glib_none().0,
155 ))
156 }
157 }
158
159 #[doc(alias = "g_volume_monitor_get_mount_for_uuid")]
168 #[doc(alias = "get_mount_for_uuid")]
169 fn mount_for_uuid(&self, uuid: &str) -> Option<Mount> {
170 unsafe {
171 from_glib_full(ffi::g_volume_monitor_get_mount_for_uuid(
172 self.as_ref().to_glib_none().0,
173 uuid.to_glib_none().0,
174 ))
175 }
176 }
177
178 #[doc(alias = "g_volume_monitor_get_mounts")]
187 #[doc(alias = "get_mounts")]
188 fn mounts(&self) -> Vec<Mount> {
189 unsafe {
190 FromGlibPtrContainer::from_glib_full(ffi::g_volume_monitor_get_mounts(
191 self.as_ref().to_glib_none().0,
192 ))
193 }
194 }
195
196 #[doc(alias = "g_volume_monitor_get_volume_for_uuid")]
205 #[doc(alias = "get_volume_for_uuid")]
206 fn volume_for_uuid(&self, uuid: &str) -> Option<Volume> {
207 unsafe {
208 from_glib_full(ffi::g_volume_monitor_get_volume_for_uuid(
209 self.as_ref().to_glib_none().0,
210 uuid.to_glib_none().0,
211 ))
212 }
213 }
214
215 #[doc(alias = "g_volume_monitor_get_volumes")]
224 #[doc(alias = "get_volumes")]
225 fn volumes(&self) -> Vec<Volume> {
226 unsafe {
227 FromGlibPtrContainer::from_glib_full(ffi::g_volume_monitor_get_volumes(
228 self.as_ref().to_glib_none().0,
229 ))
230 }
231 }
232
233 #[doc(alias = "drive-changed")]
237 fn connect_drive_changed<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
238 unsafe extern "C" fn drive_changed_trampoline<
239 P: IsA<VolumeMonitor>,
240 F: Fn(&P, &Drive) + 'static,
241 >(
242 this: *mut ffi::GVolumeMonitor,
243 drive: *mut ffi::GDrive,
244 f: glib::ffi::gpointer,
245 ) {
246 let f: &F = &*(f as *const F);
247 f(
248 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
249 &from_glib_borrow(drive),
250 )
251 }
252 unsafe {
253 let f: Box_<F> = Box_::new(f);
254 connect_raw(
255 self.as_ptr() as *mut _,
256 b"drive-changed\0".as_ptr() as *const _,
257 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
258 drive_changed_trampoline::<Self, F> as *const (),
259 )),
260 Box_::into_raw(f),
261 )
262 }
263 }
264
265 #[doc(alias = "drive-connected")]
269 fn connect_drive_connected<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
270 unsafe extern "C" fn drive_connected_trampoline<
271 P: IsA<VolumeMonitor>,
272 F: Fn(&P, &Drive) + 'static,
273 >(
274 this: *mut ffi::GVolumeMonitor,
275 drive: *mut ffi::GDrive,
276 f: glib::ffi::gpointer,
277 ) {
278 let f: &F = &*(f as *const F);
279 f(
280 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
281 &from_glib_borrow(drive),
282 )
283 }
284 unsafe {
285 let f: Box_<F> = Box_::new(f);
286 connect_raw(
287 self.as_ptr() as *mut _,
288 b"drive-connected\0".as_ptr() as *const _,
289 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
290 drive_connected_trampoline::<Self, F> as *const (),
291 )),
292 Box_::into_raw(f),
293 )
294 }
295 }
296
297 #[doc(alias = "drive-disconnected")]
301 fn connect_drive_disconnected<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
302 unsafe extern "C" fn drive_disconnected_trampoline<
303 P: IsA<VolumeMonitor>,
304 F: Fn(&P, &Drive) + 'static,
305 >(
306 this: *mut ffi::GVolumeMonitor,
307 drive: *mut ffi::GDrive,
308 f: glib::ffi::gpointer,
309 ) {
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 unsafe {
317 let f: Box_<F> = Box_::new(f);
318 connect_raw(
319 self.as_ptr() as *mut _,
320 b"drive-disconnected\0".as_ptr() as *const _,
321 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
322 drive_disconnected_trampoline::<Self, F> as *const (),
323 )),
324 Box_::into_raw(f),
325 )
326 }
327 }
328
329 #[doc(alias = "drive-eject-button")]
333 fn connect_drive_eject_button<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
334 unsafe extern "C" fn drive_eject_button_trampoline<
335 P: IsA<VolumeMonitor>,
336 F: Fn(&P, &Drive) + 'static,
337 >(
338 this: *mut ffi::GVolumeMonitor,
339 drive: *mut ffi::GDrive,
340 f: glib::ffi::gpointer,
341 ) {
342 let f: &F = &*(f as *const F);
343 f(
344 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
345 &from_glib_borrow(drive),
346 )
347 }
348 unsafe {
349 let f: Box_<F> = Box_::new(f);
350 connect_raw(
351 self.as_ptr() as *mut _,
352 b"drive-eject-button\0".as_ptr() as *const _,
353 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
354 drive_eject_button_trampoline::<Self, F> as *const (),
355 )),
356 Box_::into_raw(f),
357 )
358 }
359 }
360
361 #[doc(alias = "drive-stop-button")]
365 fn connect_drive_stop_button<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
366 unsafe extern "C" fn drive_stop_button_trampoline<
367 P: IsA<VolumeMonitor>,
368 F: Fn(&P, &Drive) + 'static,
369 >(
370 this: *mut ffi::GVolumeMonitor,
371 drive: *mut ffi::GDrive,
372 f: glib::ffi::gpointer,
373 ) {
374 let f: &F = &*(f as *const F);
375 f(
376 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
377 &from_glib_borrow(drive),
378 )
379 }
380 unsafe {
381 let f: Box_<F> = Box_::new(f);
382 connect_raw(
383 self.as_ptr() as *mut _,
384 b"drive-stop-button\0".as_ptr() as *const _,
385 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
386 drive_stop_button_trampoline::<Self, F> as *const (),
387 )),
388 Box_::into_raw(f),
389 )
390 }
391 }
392
393 #[doc(alias = "mount-added")]
397 fn connect_mount_added<F: Fn(&Self, &Mount) + 'static>(&self, f: F) -> SignalHandlerId {
398 unsafe extern "C" fn mount_added_trampoline<
399 P: IsA<VolumeMonitor>,
400 F: Fn(&P, &Mount) + 'static,
401 >(
402 this: *mut ffi::GVolumeMonitor,
403 mount: *mut ffi::GMount,
404 f: glib::ffi::gpointer,
405 ) {
406 let f: &F = &*(f as *const F);
407 f(
408 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
409 &from_glib_borrow(mount),
410 )
411 }
412 unsafe {
413 let f: Box_<F> = Box_::new(f);
414 connect_raw(
415 self.as_ptr() as *mut _,
416 b"mount-added\0".as_ptr() as *const _,
417 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
418 mount_added_trampoline::<Self, F> as *const (),
419 )),
420 Box_::into_raw(f),
421 )
422 }
423 }
424
425 #[doc(alias = "mount-changed")]
429 fn connect_mount_changed<F: Fn(&Self, &Mount) + 'static>(&self, f: F) -> SignalHandlerId {
430 unsafe extern "C" fn mount_changed_trampoline<
431 P: IsA<VolumeMonitor>,
432 F: Fn(&P, &Mount) + 'static,
433 >(
434 this: *mut ffi::GVolumeMonitor,
435 mount: *mut ffi::GMount,
436 f: glib::ffi::gpointer,
437 ) {
438 let f: &F = &*(f as *const F);
439 f(
440 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
441 &from_glib_borrow(mount),
442 )
443 }
444 unsafe {
445 let f: Box_<F> = Box_::new(f);
446 connect_raw(
447 self.as_ptr() as *mut _,
448 b"mount-changed\0".as_ptr() as *const _,
449 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
450 mount_changed_trampoline::<Self, F> as *const (),
451 )),
452 Box_::into_raw(f),
453 )
454 }
455 }
456
457 #[doc(alias = "mount-pre-unmount")]
464 fn connect_mount_pre_unmount<F: Fn(&Self, &Mount) + 'static>(&self, f: F) -> SignalHandlerId {
465 unsafe extern "C" fn mount_pre_unmount_trampoline<
466 P: IsA<VolumeMonitor>,
467 F: Fn(&P, &Mount) + 'static,
468 >(
469 this: *mut ffi::GVolumeMonitor,
470 mount: *mut ffi::GMount,
471 f: glib::ffi::gpointer,
472 ) {
473 let f: &F = &*(f as *const F);
474 f(
475 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
476 &from_glib_borrow(mount),
477 )
478 }
479 unsafe {
480 let f: Box_<F> = Box_::new(f);
481 connect_raw(
482 self.as_ptr() as *mut _,
483 b"mount-pre-unmount\0".as_ptr() as *const _,
484 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
485 mount_pre_unmount_trampoline::<Self, F> as *const (),
486 )),
487 Box_::into_raw(f),
488 )
489 }
490 }
491
492 #[doc(alias = "mount-removed")]
496 fn connect_mount_removed<F: Fn(&Self, &Mount) + 'static>(&self, f: F) -> SignalHandlerId {
497 unsafe extern "C" fn mount_removed_trampoline<
498 P: IsA<VolumeMonitor>,
499 F: Fn(&P, &Mount) + 'static,
500 >(
501 this: *mut ffi::GVolumeMonitor,
502 mount: *mut ffi::GMount,
503 f: glib::ffi::gpointer,
504 ) {
505 let f: &F = &*(f as *const F);
506 f(
507 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
508 &from_glib_borrow(mount),
509 )
510 }
511 unsafe {
512 let f: Box_<F> = Box_::new(f);
513 connect_raw(
514 self.as_ptr() as *mut _,
515 b"mount-removed\0".as_ptr() as *const _,
516 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
517 mount_removed_trampoline::<Self, F> as *const (),
518 )),
519 Box_::into_raw(f),
520 )
521 }
522 }
523
524 #[doc(alias = "volume-added")]
528 fn connect_volume_added<F: Fn(&Self, &Volume) + 'static>(&self, f: F) -> SignalHandlerId {
529 unsafe extern "C" fn volume_added_trampoline<
530 P: IsA<VolumeMonitor>,
531 F: Fn(&P, &Volume) + 'static,
532 >(
533 this: *mut ffi::GVolumeMonitor,
534 volume: *mut ffi::GVolume,
535 f: glib::ffi::gpointer,
536 ) {
537 let f: &F = &*(f as *const F);
538 f(
539 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
540 &from_glib_borrow(volume),
541 )
542 }
543 unsafe {
544 let f: Box_<F> = Box_::new(f);
545 connect_raw(
546 self.as_ptr() as *mut _,
547 b"volume-added\0".as_ptr() as *const _,
548 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
549 volume_added_trampoline::<Self, F> as *const (),
550 )),
551 Box_::into_raw(f),
552 )
553 }
554 }
555
556 #[doc(alias = "volume-changed")]
560 fn connect_volume_changed<F: Fn(&Self, &Volume) + 'static>(&self, f: F) -> SignalHandlerId {
561 unsafe extern "C" fn volume_changed_trampoline<
562 P: IsA<VolumeMonitor>,
563 F: Fn(&P, &Volume) + 'static,
564 >(
565 this: *mut ffi::GVolumeMonitor,
566 volume: *mut ffi::GVolume,
567 f: glib::ffi::gpointer,
568 ) {
569 let f: &F = &*(f as *const F);
570 f(
571 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
572 &from_glib_borrow(volume),
573 )
574 }
575 unsafe {
576 let f: Box_<F> = Box_::new(f);
577 connect_raw(
578 self.as_ptr() as *mut _,
579 b"volume-changed\0".as_ptr() as *const _,
580 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
581 volume_changed_trampoline::<Self, F> as *const (),
582 )),
583 Box_::into_raw(f),
584 )
585 }
586 }
587
588 #[doc(alias = "volume-removed")]
592 fn connect_volume_removed<F: Fn(&Self, &Volume) + 'static>(&self, f: F) -> SignalHandlerId {
593 unsafe extern "C" fn volume_removed_trampoline<
594 P: IsA<VolumeMonitor>,
595 F: Fn(&P, &Volume) + 'static,
596 >(
597 this: *mut ffi::GVolumeMonitor,
598 volume: *mut ffi::GVolume,
599 f: glib::ffi::gpointer,
600 ) {
601 let f: &F = &*(f as *const F);
602 f(
603 VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
604 &from_glib_borrow(volume),
605 )
606 }
607 unsafe {
608 let f: Box_<F> = Box_::new(f);
609 connect_raw(
610 self.as_ptr() as *mut _,
611 b"volume-removed\0".as_ptr() as *const _,
612 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
613 volume_removed_trampoline::<Self, F> as *const (),
614 )),
615 Box_::into_raw(f),
616 )
617 }
618 }
619}
620
621impl<O: IsA<VolumeMonitor>> VolumeMonitorExt for O {}