1 // Copyright 2013-2019, The Gtk-rs Project Developers.
2 // See the COPYRIGHT file at the top-level directory of this distribution.
3 // Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT>
4 
5 use glib::translate::*;
6 use glib::GString;
7 use std::cmp;
8 use std::mem;
9 use Icon;
10 use UnixMountEntry;
11 
12 impl UnixMountEntry {
new_at<P: AsRef<std::path::Path>>(mount_path: P) -> (UnixMountEntry, u64)13     pub fn new_at<P: AsRef<std::path::Path>>(mount_path: P) -> (UnixMountEntry, u64) {
14         unsafe {
15             let mut time_read = mem::MaybeUninit::uninit();
16             let ret = from_glib_full(gio_sys::g_unix_mount_at(
17                 mount_path.as_ref().to_glib_none().0,
18                 time_read.as_mut_ptr(),
19             ));
20             let time_read = time_read.assume_init();
21             (ret, time_read)
22         }
23     }
24 
25     #[cfg(any(feature = "v2_52", feature = "dox"))]
new_for<P: AsRef<std::path::Path>>(file_path: P) -> (UnixMountEntry, u64)26     pub fn new_for<P: AsRef<std::path::Path>>(file_path: P) -> (UnixMountEntry, u64) {
27         unsafe {
28             let mut time_read = mem::MaybeUninit::uninit();
29             let ret = from_glib_full(gio_sys::g_unix_mount_for(
30                 file_path.as_ref().to_glib_none().0,
31                 time_read.as_mut_ptr(),
32             ));
33             let time_read = time_read.assume_init();
34             (ret, time_read)
35         }
36     }
37 
get_mounts() -> (Vec<UnixMountEntry>, u64)38     pub fn get_mounts() -> (Vec<UnixMountEntry>, u64) {
39         unsafe {
40             let mut time_read = mem::MaybeUninit::uninit();
41             let ret = FromGlibPtrContainer::from_glib_full(gio_sys::g_unix_mounts_get(
42                 time_read.as_mut_ptr(),
43             ));
44             let time_read = time_read.assume_init();
45             (ret, time_read)
46         }
47     }
48 
compare(&self, mount2: &UnixMountEntry) -> i3249     pub fn compare(&self, mount2: &UnixMountEntry) -> i32 {
50         unsafe {
51             gio_sys::g_unix_mount_compare(
52                 mut_override(self.to_glib_none().0),
53                 mut_override(mount2.to_glib_none().0),
54             )
55         }
56     }
57 
get_device_path(&self) -> Option<std::path::PathBuf>58     pub fn get_device_path(&self) -> Option<std::path::PathBuf> {
59         unsafe {
60             from_glib_none(gio_sys::g_unix_mount_get_device_path(mut_override(
61                 self.to_glib_none().0,
62             )))
63         }
64     }
65 
get_fs_type(&self) -> Option<GString>66     pub fn get_fs_type(&self) -> Option<GString> {
67         unsafe {
68             from_glib_none(gio_sys::g_unix_mount_get_fs_type(mut_override(
69                 self.to_glib_none().0,
70             )))
71         }
72     }
73 
unix_mount_get_mount_path(&self) -> Option<std::path::PathBuf>74     pub fn unix_mount_get_mount_path(&self) -> Option<std::path::PathBuf> {
75         unsafe {
76             from_glib_none(gio_sys::g_unix_mount_get_mount_path(mut_override(
77                 self.to_glib_none().0,
78             )))
79         }
80     }
81 
82     #[cfg(any(feature = "v2_58", feature = "dox"))]
get_options(&self) -> Option<GString>83     pub fn get_options(&self) -> Option<GString> {
84         unsafe {
85             from_glib_none(gio_sys::g_unix_mount_get_options(mut_override(
86                 self.to_glib_none().0,
87             )))
88         }
89     }
90 
91     #[cfg(any(feature = "v2_60", feature = "dox"))]
get_root_path(&self) -> Option<std::path::PathBuf>92     pub fn get_root_path(&self) -> Option<std::path::PathBuf> {
93         unsafe {
94             from_glib_none(gio_sys::g_unix_mount_get_root_path(mut_override(
95                 self.to_glib_none().0,
96             )))
97         }
98     }
99 
guess_can_eject(&self) -> bool100     pub fn guess_can_eject(&self) -> bool {
101         unsafe {
102             from_glib(gio_sys::g_unix_mount_guess_can_eject(mut_override(
103                 self.to_glib_none().0,
104             )))
105         }
106     }
107 
guess_icon(&self) -> Option<Icon>108     pub fn guess_icon(&self) -> Option<Icon> {
109         unsafe {
110             from_glib_full(gio_sys::g_unix_mount_guess_icon(mut_override(
111                 self.to_glib_none().0,
112             )))
113         }
114     }
115 
guess_name(&self) -> Option<GString>116     pub fn guess_name(&self) -> Option<GString> {
117         unsafe {
118             from_glib_full(gio_sys::g_unix_mount_guess_name(mut_override(
119                 self.to_glib_none().0,
120             )))
121         }
122     }
123 
guess_should_display(&self) -> bool124     pub fn guess_should_display(&self) -> bool {
125         unsafe {
126             from_glib(gio_sys::g_unix_mount_guess_should_display(mut_override(
127                 self.to_glib_none().0,
128             )))
129         }
130     }
131 
guess_symbolic_icon(&self) -> Option<Icon>132     pub fn guess_symbolic_icon(&self) -> Option<Icon> {
133         unsafe {
134             from_glib_full(gio_sys::g_unix_mount_guess_symbolic_icon(mut_override(
135                 self.to_glib_none().0,
136             )))
137         }
138     }
139 
is_readonly(&self) -> bool140     pub fn is_readonly(&self) -> bool {
141         unsafe {
142             from_glib(gio_sys::g_unix_mount_is_readonly(mut_override(
143                 self.to_glib_none().0,
144             )))
145         }
146     }
147 
is_system_internal(&self) -> bool148     pub fn is_system_internal(&self) -> bool {
149         unsafe {
150             from_glib(gio_sys::g_unix_mount_is_system_internal(mut_override(
151                 self.to_glib_none().0,
152             )))
153         }
154     }
155 
is_changed_since(time: u64) -> bool156     pub fn is_changed_since(time: u64) -> bool {
157         unsafe { from_glib(gio_sys::g_unix_mounts_changed_since(time)) }
158     }
159 }
160 
161 impl PartialEq for UnixMountEntry {
162     #[inline]
eq(&self, other: &Self) -> bool163     fn eq(&self, other: &Self) -> bool {
164         self.compare(other) == 0
165     }
166 }
167 
168 impl Eq for UnixMountEntry {}
169 
170 impl PartialOrd for UnixMountEntry {
171     #[inline]
partial_cmp(&self, other: &Self) -> Option<cmp::Ordering>172     fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
173         self.compare(other).partial_cmp(&0)
174     }
175 }
176 
177 impl Ord for UnixMountEntry {
178     #[inline]
cmp(&self, other: &Self) -> cmp::Ordering179     fn cmp(&self, other: &Self) -> cmp::Ordering {
180         self.compare(other).cmp(&0)
181     }
182 }
183