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    /// Asks the user for passwords and other information required to
15    /// mount a volume.
16    ///
17    /// [`MountOperation`][crate::MountOperation] is needed when mounting volumes:
18    /// It is an implementation of `GMountOperation` that can be used with
19    /// GIO functions for mounting volumes such as
20    /// [`FileExtManual::mount_enclosing_volume()`][crate::gio::prelude::FileExtManual::mount_enclosing_volume()],
21    /// [`FileExtManual::mount_mountable()`][crate::gio::prelude::FileExtManual::mount_mountable()],
22    /// `Gio::Volume::mount()`,
23    /// `Gio::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
275/// Trait containing all [`struct@MountOperation`] methods.
276///
277/// # Implementors
278///
279/// [`MountOperation`][struct@crate::MountOperation]
280pub trait GtkMountOperationExt: IsA<MountOperation> + 'static {
281    /// Gets the display on which windows of the [`MountOperation`][crate::MountOperation]
282    /// will be shown.
283    ///
284    /// # Returns
285    ///
286    /// the display on which windows of @self are shown
287    #[doc(alias = "gtk_mount_operation_get_display")]
288    #[doc(alias = "get_display")]
289    fn display(&self) -> gdk::Display {
290        unsafe {
291            from_glib_none(ffi::gtk_mount_operation_get_display(
292                self.as_ref().to_glib_none().0,
293            ))
294        }
295    }
296
297    /// Gets the transient parent used by the [`MountOperation`][crate::MountOperation].
298    ///
299    /// # Returns
300    ///
301    /// the transient parent for windows shown by @self
302    #[doc(alias = "gtk_mount_operation_get_parent")]
303    #[doc(alias = "get_parent")]
304    fn parent(&self) -> Option<Window> {
305        unsafe {
306            from_glib_none(ffi::gtk_mount_operation_get_parent(
307                self.as_ref().to_glib_none().0,
308            ))
309        }
310    }
311
312    /// Returns whether the [`MountOperation`][crate::MountOperation] is currently displaying
313    /// a window.
314    ///
315    /// # Returns
316    ///
317    /// [`true`] if @self is currently displaying a window
318    #[doc(alias = "gtk_mount_operation_is_showing")]
319    #[doc(alias = "is-showing")]
320    fn is_showing(&self) -> bool {
321        unsafe {
322            from_glib(ffi::gtk_mount_operation_is_showing(
323                self.as_ref().to_glib_none().0,
324            ))
325        }
326    }
327
328    /// Sets the display to show windows of the [`MountOperation`][crate::MountOperation] on.
329    /// ## `display`
330    /// a [`gdk::Display`][crate::gdk::Display]
331    #[doc(alias = "gtk_mount_operation_set_display")]
332    #[doc(alias = "display")]
333    fn set_display(&self, display: &impl IsA<gdk::Display>) {
334        unsafe {
335            ffi::gtk_mount_operation_set_display(
336                self.as_ref().to_glib_none().0,
337                display.as_ref().to_glib_none().0,
338            );
339        }
340    }
341
342    /// Sets the transient parent for windows shown by the
343    /// [`MountOperation`][crate::MountOperation].
344    /// ## `parent`
345    /// transient parent of the window
346    #[doc(alias = "gtk_mount_operation_set_parent")]
347    #[doc(alias = "parent")]
348    fn set_parent(&self, parent: Option<&impl IsA<Window>>) {
349        unsafe {
350            ffi::gtk_mount_operation_set_parent(
351                self.as_ref().to_glib_none().0,
352                parent.map(|p| p.as_ref()).to_glib_none().0,
353            );
354        }
355    }
356
357    #[doc(alias = "display")]
358    fn connect_display_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
359        unsafe extern "C" fn notify_display_trampoline<
360            P: IsA<MountOperation>,
361            F: Fn(&P) + 'static,
362        >(
363            this: *mut ffi::GtkMountOperation,
364            _param_spec: glib::ffi::gpointer,
365            f: glib::ffi::gpointer,
366        ) {
367            let f: &F = &*(f as *const F);
368            f(MountOperation::from_glib_borrow(this).unsafe_cast_ref())
369        }
370        unsafe {
371            let f: Box_<F> = Box_::new(f);
372            connect_raw(
373                self.as_ptr() as *mut _,
374                c"notify::display".as_ptr() as *const _,
375                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
376                    notify_display_trampoline::<Self, F> as *const (),
377                )),
378                Box_::into_raw(f),
379            )
380        }
381    }
382
383    #[doc(alias = "is-showing")]
384    fn connect_is_showing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
385        unsafe extern "C" fn notify_is_showing_trampoline<
386            P: IsA<MountOperation>,
387            F: Fn(&P) + 'static,
388        >(
389            this: *mut ffi::GtkMountOperation,
390            _param_spec: glib::ffi::gpointer,
391            f: glib::ffi::gpointer,
392        ) {
393            let f: &F = &*(f as *const F);
394            f(MountOperation::from_glib_borrow(this).unsafe_cast_ref())
395        }
396        unsafe {
397            let f: Box_<F> = Box_::new(f);
398            connect_raw(
399                self.as_ptr() as *mut _,
400                c"notify::is-showing".as_ptr() as *const _,
401                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
402                    notify_is_showing_trampoline::<Self, F> as *const (),
403                )),
404                Box_::into_raw(f),
405            )
406        }
407    }
408
409    #[doc(alias = "parent")]
410    fn connect_parent_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
411        unsafe extern "C" fn notify_parent_trampoline<
412            P: IsA<MountOperation>,
413            F: Fn(&P) + 'static,
414        >(
415            this: *mut ffi::GtkMountOperation,
416            _param_spec: glib::ffi::gpointer,
417            f: glib::ffi::gpointer,
418        ) {
419            let f: &F = &*(f as *const F);
420            f(MountOperation::from_glib_borrow(this).unsafe_cast_ref())
421        }
422        unsafe {
423            let f: Box_<F> = Box_::new(f);
424            connect_raw(
425                self.as_ptr() as *mut _,
426                c"notify::parent".as_ptr() as *const _,
427                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
428                    notify_parent_trampoline::<Self, F> as *const (),
429                )),
430                Box_::into_raw(f),
431            )
432        }
433    }
434}
435
436impl<O: IsA<MountOperation>> GtkMountOperationExt for O {}