gtk4/auto/
mount_operation.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ffi, Window};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// [`MountOperation`][crate::MountOperation] is an implementation of `GMountOperation`.
15    ///
16    /// The functions and objects described here make working with GTK and
17    /// GIO more convenient.
18    ///
19    /// [`MountOperation`][crate::MountOperation] is needed when mounting volumes:
20    /// It is an implementation of `GMountOperation` that can be used with
21    /// GIO functions for mounting volumes such as
22    /// g_file_mount_enclosing_volume(), g_file_mount_mountable(),
23    /// g_volume_mount(), g_mount_unmount_with_operation() and others.
24    ///
25    /// When necessary, [`MountOperation`][crate::MountOperation] shows dialogs to let the user
26    /// enter passwords, ask questions or show processes blocking unmount.
27    ///
28    /// ## Properties
29    ///
30    ///
31    /// #### `display`
32    ///  The display where dialogs will be shown.
33    ///
34    /// Readable | Writeable
35    ///
36    ///
37    /// #### `is-showing`
38    ///  Whether a dialog is currently shown.
39    ///
40    /// Readable
41    ///
42    ///
43    /// #### `parent`
44    ///  The parent window.
45    ///
46    /// Readable | Writeable
47    /// <details><summary><h4>MountOperation</h4></summary>
48    ///
49    ///
50    /// #### `anonymous`
51    ///  Whether to use an anonymous user when authenticating.
52    ///
53    /// Readable | Writeable
54    ///
55    ///
56    /// #### `choice`
57    ///  The index of the user's choice when a question is asked during the
58    /// mount operation. See the #GMountOperation::ask-question signal.
59    ///
60    /// Readable | Writeable
61    ///
62    ///
63    /// #### `domain`
64    ///  The domain to use for the mount operation.
65    ///
66    /// Readable | Writeable
67    ///
68    ///
69    /// #### `is-tcrypt-hidden-volume`
70    ///  Whether the device to be unlocked is a TCRYPT hidden volume.
71    /// See [the VeraCrypt documentation](https://www.veracrypt.fr/en/Hidden`20Volume`).
72    ///
73    /// Readable | Writeable
74    ///
75    ///
76    /// #### `is-tcrypt-system-volume`
77    ///  Whether the device to be unlocked is a TCRYPT system volume.
78    /// In this context, a system volume is a volume with a bootloader
79    /// and operating system installed. This is only supported for Windows
80    /// operating systems. For further documentation, see
81    /// [the VeraCrypt documentation](https://www.veracrypt.fr/en/System`20Encryption`).
82    ///
83    /// Readable | Writeable
84    ///
85    ///
86    /// #### `password`
87    ///  The password that is used for authentication when carrying out
88    /// the mount operation.
89    ///
90    /// Readable | Writeable
91    ///
92    ///
93    /// #### `password-save`
94    ///  Determines if and how the password information should be saved.
95    ///
96    /// Readable | Writeable
97    ///
98    ///
99    /// #### `pim`
100    ///  The VeraCrypt PIM value, when unlocking a VeraCrypt volume. See
101    /// [the VeraCrypt documentation](https://www.veracrypt.fr/en/Personal`20Iterations``20Multiplier``20`(PIM).html).
102    ///
103    /// Readable | Writeable
104    ///
105    ///
106    /// #### `username`
107    ///  The user name that is used for authentication when carrying out
108    /// the mount operation.
109    ///
110    /// Readable | Writeable
111    /// </details>
112    ///
113    /// # Implements
114    ///
115    /// [`GtkMountOperationExt`][trait@crate::prelude::GtkMountOperationExt], [`trait@gio::prelude::MountOperationExt`], [`trait@glib::ObjectExt`]
116    #[doc(alias = "GtkMountOperation")]
117    pub struct MountOperation(Object<ffi::GtkMountOperation, ffi::GtkMountOperationClass>) @extends gio::MountOperation;
118
119    match fn {
120        type_ => || ffi::gtk_mount_operation_get_type(),
121    }
122}
123
124impl MountOperation {
125    pub const NONE: Option<&'static MountOperation> = None;
126
127    /// Creates a new [`MountOperation`][crate::MountOperation].
128    /// ## `parent`
129    /// transient parent of the window
130    ///
131    /// # Returns
132    ///
133    /// a new [`MountOperation`][crate::MountOperation]
134    #[doc(alias = "gtk_mount_operation_new")]
135    pub fn new(parent: Option<&impl IsA<Window>>) -> MountOperation {
136        assert_initialized_main_thread!();
137        unsafe {
138            gio::MountOperation::from_glib_full(ffi::gtk_mount_operation_new(
139                parent.map(|p| p.as_ref()).to_glib_none().0,
140            ))
141            .unsafe_cast()
142        }
143    }
144
145    // rustdoc-stripper-ignore-next
146    /// Creates a new builder-pattern struct instance to construct [`MountOperation`] objects.
147    ///
148    /// This method returns an instance of [`MountOperationBuilder`](crate::builders::MountOperationBuilder) which can be used to create [`MountOperation`] objects.
149    pub fn builder() -> MountOperationBuilder {
150        MountOperationBuilder::new()
151    }
152}
153
154impl Default for MountOperation {
155    fn default() -> Self {
156        glib::object::Object::new::<Self>()
157    }
158}
159
160// rustdoc-stripper-ignore-next
161/// A [builder-pattern] type to construct [`MountOperation`] objects.
162///
163/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
164#[must_use = "The builder must be built to be used"]
165pub struct MountOperationBuilder {
166    builder: glib::object::ObjectBuilder<'static, MountOperation>,
167}
168
169impl MountOperationBuilder {
170    fn new() -> Self {
171        Self {
172            builder: glib::object::Object::builder(),
173        }
174    }
175
176    /// The display where dialogs will be shown.
177    pub fn display(self, display: &impl IsA<gdk::Display>) -> Self {
178        Self {
179            builder: self.builder.property("display", display.clone().upcast()),
180        }
181    }
182
183    /// The parent window.
184    pub fn parent(self, parent: &impl IsA<Window>) -> Self {
185        Self {
186            builder: self.builder.property("parent", parent.clone().upcast()),
187        }
188    }
189
190    /// Whether to use an anonymous user when authenticating.
191    pub fn anonymous(self, anonymous: bool) -> Self {
192        Self {
193            builder: self.builder.property("anonymous", anonymous),
194        }
195    }
196
197    /// The index of the user's choice when a question is asked during the
198    /// mount operation. See the #GMountOperation::ask-question signal.
199    pub fn choice(self, choice: i32) -> Self {
200        Self {
201            builder: self.builder.property("choice", choice),
202        }
203    }
204
205    /// The domain to use for the mount operation.
206    pub fn domain(self, domain: impl Into<glib::GString>) -> Self {
207        Self {
208            builder: self.builder.property("domain", domain.into()),
209        }
210    }
211
212    /// Whether the device to be unlocked is a TCRYPT hidden volume.
213    /// See [the VeraCrypt documentation](https://www.veracrypt.fr/en/Hidden`20Volume`).
214    pub fn is_tcrypt_hidden_volume(self, is_tcrypt_hidden_volume: bool) -> Self {
215        Self {
216            builder: self
217                .builder
218                .property("is-tcrypt-hidden-volume", is_tcrypt_hidden_volume),
219        }
220    }
221
222    /// Whether the device to be unlocked is a TCRYPT system volume.
223    /// In this context, a system volume is a volume with a bootloader
224    /// and operating system installed. This is only supported for Windows
225    /// operating systems. For further documentation, see
226    /// [the VeraCrypt documentation](https://www.veracrypt.fr/en/System`20Encryption`).
227    pub fn is_tcrypt_system_volume(self, is_tcrypt_system_volume: bool) -> Self {
228        Self {
229            builder: self
230                .builder
231                .property("is-tcrypt-system-volume", is_tcrypt_system_volume),
232        }
233    }
234
235    /// The password that is used for authentication when carrying out
236    /// the mount operation.
237    pub fn password(self, password: impl Into<glib::GString>) -> Self {
238        Self {
239            builder: self.builder.property("password", password.into()),
240        }
241    }
242
243    /// Determines if and how the password information should be saved.
244    pub fn password_save(self, password_save: gio::PasswordSave) -> Self {
245        Self {
246            builder: self.builder.property("password-save", password_save),
247        }
248    }
249
250    /// The VeraCrypt PIM value, when unlocking a VeraCrypt volume. See
251    /// [the VeraCrypt documentation](https://www.veracrypt.fr/en/Personal`20Iterations``20Multiplier``20`(PIM).html).
252    pub fn pim(self, pim: u32) -> Self {
253        Self {
254            builder: self.builder.property("pim", pim),
255        }
256    }
257
258    /// The user name that is used for authentication when carrying out
259    /// the mount operation.
260    pub fn username(self, username: impl Into<glib::GString>) -> Self {
261        Self {
262            builder: self.builder.property("username", username.into()),
263        }
264    }
265
266    // rustdoc-stripper-ignore-next
267    /// Build the [`MountOperation`].
268    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
269    pub fn build(self) -> MountOperation {
270        assert_initialized_main_thread!();
271        self.builder.build()
272    }
273}
274
275mod sealed {
276    pub trait Sealed {}
277    impl<T: super::IsA<super::MountOperation>> Sealed for T {}
278}
279
280/// Trait containing all [`struct@MountOperation`] methods.
281///
282/// # Implementors
283///
284/// [`MountOperation`][struct@crate::MountOperation]
285pub trait GtkMountOperationExt: IsA<MountOperation> + sealed::Sealed + 'static {
286    /// Gets the display on which windows of the [`MountOperation`][crate::MountOperation]
287    /// will be shown.
288    ///
289    /// # Returns
290    ///
291    /// the display on which windows of @self are shown
292    #[doc(alias = "gtk_mount_operation_get_display")]
293    #[doc(alias = "get_display")]
294    fn display(&self) -> gdk::Display {
295        unsafe {
296            from_glib_none(ffi::gtk_mount_operation_get_display(
297                self.as_ref().to_glib_none().0,
298            ))
299        }
300    }
301
302    /// Gets the transient parent used by the [`MountOperation`][crate::MountOperation].
303    ///
304    /// # Returns
305    ///
306    /// the transient parent for windows shown by @self
307    #[doc(alias = "gtk_mount_operation_get_parent")]
308    #[doc(alias = "get_parent")]
309    fn parent(&self) -> Option<Window> {
310        unsafe {
311            from_glib_none(ffi::gtk_mount_operation_get_parent(
312                self.as_ref().to_glib_none().0,
313            ))
314        }
315    }
316
317    /// Returns whether the [`MountOperation`][crate::MountOperation] is currently displaying
318    /// a window.
319    ///
320    /// # Returns
321    ///
322    /// [`true`] if @self is currently displaying a window
323    #[doc(alias = "gtk_mount_operation_is_showing")]
324    #[doc(alias = "is-showing")]
325    fn is_showing(&self) -> bool {
326        unsafe {
327            from_glib(ffi::gtk_mount_operation_is_showing(
328                self.as_ref().to_glib_none().0,
329            ))
330        }
331    }
332
333    /// Sets the display to show windows of the [`MountOperation`][crate::MountOperation] on.
334    /// ## `display`
335    /// a [`gdk::Display`][crate::gdk::Display]
336    #[doc(alias = "gtk_mount_operation_set_display")]
337    #[doc(alias = "display")]
338    fn set_display(&self, display: &impl IsA<gdk::Display>) {
339        unsafe {
340            ffi::gtk_mount_operation_set_display(
341                self.as_ref().to_glib_none().0,
342                display.as_ref().to_glib_none().0,
343            );
344        }
345    }
346
347    /// Sets the transient parent for windows shown by the
348    /// [`MountOperation`][crate::MountOperation].
349    /// ## `parent`
350    /// transient parent of the window
351    #[doc(alias = "gtk_mount_operation_set_parent")]
352    #[doc(alias = "parent")]
353    fn set_parent(&self, parent: Option<&impl IsA<Window>>) {
354        unsafe {
355            ffi::gtk_mount_operation_set_parent(
356                self.as_ref().to_glib_none().0,
357                parent.map(|p| p.as_ref()).to_glib_none().0,
358            );
359        }
360    }
361
362    #[doc(alias = "display")]
363    fn connect_display_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
364        unsafe extern "C" fn notify_display_trampoline<
365            P: IsA<MountOperation>,
366            F: Fn(&P) + 'static,
367        >(
368            this: *mut ffi::GtkMountOperation,
369            _param_spec: glib::ffi::gpointer,
370            f: glib::ffi::gpointer,
371        ) {
372            let f: &F = &*(f as *const F);
373            f(MountOperation::from_glib_borrow(this).unsafe_cast_ref())
374        }
375        unsafe {
376            let f: Box_<F> = Box_::new(f);
377            connect_raw(
378                self.as_ptr() as *mut _,
379                b"notify::display\0".as_ptr() as *const _,
380                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
381                    notify_display_trampoline::<Self, F> as *const (),
382                )),
383                Box_::into_raw(f),
384            )
385        }
386    }
387
388    #[doc(alias = "is-showing")]
389    fn connect_is_showing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
390        unsafe extern "C" fn notify_is_showing_trampoline<
391            P: IsA<MountOperation>,
392            F: Fn(&P) + 'static,
393        >(
394            this: *mut ffi::GtkMountOperation,
395            _param_spec: glib::ffi::gpointer,
396            f: glib::ffi::gpointer,
397        ) {
398            let f: &F = &*(f as *const F);
399            f(MountOperation::from_glib_borrow(this).unsafe_cast_ref())
400        }
401        unsafe {
402            let f: Box_<F> = Box_::new(f);
403            connect_raw(
404                self.as_ptr() as *mut _,
405                b"notify::is-showing\0".as_ptr() as *const _,
406                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
407                    notify_is_showing_trampoline::<Self, F> as *const (),
408                )),
409                Box_::into_raw(f),
410            )
411        }
412    }
413
414    #[doc(alias = "parent")]
415    fn connect_parent_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
416        unsafe extern "C" fn notify_parent_trampoline<
417            P: IsA<MountOperation>,
418            F: Fn(&P) + 'static,
419        >(
420            this: *mut ffi::GtkMountOperation,
421            _param_spec: glib::ffi::gpointer,
422            f: glib::ffi::gpointer,
423        ) {
424            let f: &F = &*(f as *const F);
425            f(MountOperation::from_glib_borrow(this).unsafe_cast_ref())
426        }
427        unsafe {
428            let f: Box_<F> = Box_::new(f);
429            connect_raw(
430                self.as_ptr() as *mut _,
431                b"notify::parent\0".as_ptr() as *const _,
432                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
433                    notify_parent_trampoline::<Self, F> as *const (),
434                )),
435                Box_::into_raw(f),
436            )
437        }
438    }
439}
440
441impl<O: IsA<MountOperation>> GtkMountOperationExt for O {}