Skip to main content

gtk4/auto/
file_filter.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#![allow(deprecated)]
5
6use crate::{Buildable, Filter, ffi};
7use glib::{
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    ///
16    /// ```text
17    ///
18    ///
19    /// ## Properties
20    ///
21    ///
22    /// #### `mime-types`
23    ///  The MIME types that this filter matches.
24    ///
25    /// Writable | Construct Only
26    ///
27    ///
28    /// #### `name`
29    ///  The human-readable name of the filter.
30    ///
31    /// This is the string that will be displayed in the user interface
32    /// if there is a selectable list of filters.
33    ///
34    /// Readable | Writable
35    ///
36    ///
37    /// #### `patterns`
38    ///  The patterns that this filter matches.
39    ///
40    /// Writable | Construct Only
41    ///
42    ///
43    /// #### `suffixes`
44    ///  The suffixes that this filter matches.
45    ///
46    /// Writable | Construct Only
47    ///
48    /// # Implements
49    ///
50    /// [`FilterExt`][trait@crate::prelude::FilterExt], [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt]
51    #[doc(alias = "GtkFileFilter")]
52    pub struct FileFilter(Object<ffi::GtkFileFilter>) @extends Filter, @implements Buildable;
53
54    match fn {
55        type_ => || ffi::gtk_file_filter_get_type(),
56    }
57}
58
59impl FileFilter {
60    /// t accept any files, so is not
61    /// particularly useful until you add rules with
62    /// [`add_mime_type()`][Self::add_mime_type()],
63    /// [`add_pattern()`][Self::add_pattern()],
64    /// [`add_suffix()`][Self::add_suffix()] or
65    /// [`add_pixbuf_formats()`][Self::add_pixbuf_formats()].
66    ///
67    /// To create a filter that accepts any file, use:
68    /// **⚠️ The following code is in c ⚠️**
69    ///
70    /// ```c
71    /// GtkFileFilter *filter = gtk_file_filter_new ();
72    /// gtk_file_filter_add_pattern (filter, "*");
73    /// ```
74    ///
75    /// # Returns
76    ///
77    /// a new [`FileFilter`][crate::FileFilter]
78    #[doc(alias = "gtk_file_filter_new")]
79    pub fn new() -> FileFilter {
80        assert_initialized_main_thread!();
81        unsafe { from_glib_full(ffi::gtk_file_filter_new()) }
82    }
83
84    /// Deserialize a file filter from a `GVariant`.
85    ///
86    /// The variant must be in the format produced by
87    /// [`to_gvariant()`][Self::to_gvariant()].
88    /// ## `variant`
89    /// an `a{sv}` `GVariant`
90    ///
91    /// # Returns
92    ///
93    /// a new [`FileFilter`][crate::FileFilter] object
94    #[doc(alias = "gtk_file_filter_new_from_gvariant")]
95    #[doc(alias = "new_from_gvariant")]
96    pub fn from_gvariant(variant: &glib::Variant) -> FileFilter {
97        assert_initialized_main_thread!();
98        unsafe {
99            from_glib_full(ffi::gtk_file_filter_new_from_gvariant(
100                variant.to_glib_none().0,
101            ))
102        }
103    }
104
105    /// Adds a rule allowing a given mime type.
106    /// ## `mime_type`
107    /// name of a MIME type
108    #[doc(alias = "gtk_file_filter_add_mime_type")]
109    pub fn add_mime_type(&self, mime_type: &str) {
110        unsafe {
111            ffi::gtk_file_filter_add_mime_type(self.to_glib_none().0, mime_type.to_glib_none().0);
112        }
113    }
114
115    /// Adds a rule allowing a given array of mime types.
116    /// It can for example be used with
117    /// [Gly.Loader.get_mime_types](https://gnome.pages.gitlab.gnome.org/glycin/libglycin/type_func.Loader.get_mime_types.html).
118    ///
119    /// This is equivalent to calling [`add_mime_type()`][Self::add_mime_type()]
120    /// for all the supported mime types.
121    /// ## `mime_types`
122    /// a [`None`]-terminated array of mime types
123    #[cfg(feature = "v4_22")]
124    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
125    #[doc(alias = "gtk_file_filter_add_mime_types")]
126    pub fn add_mime_types(&self, mime_types: &[&str]) {
127        unsafe {
128            ffi::gtk_file_filter_add_mime_types(self.to_glib_none().0, mime_types.to_glib_none().0);
129        }
130    }
131
132    /// Adds a rule allowing a shell style glob pattern.
133    ///
134    /// Note that it depends on the platform whether pattern
135    /// matching ignores case or not. On Windows, it does, on
136    /// other platforms, it doesn't.
137    /// ## `pattern`
138    /// a shell style glob pattern
139    #[doc(alias = "gtk_file_filter_add_pattern")]
140    pub fn add_pattern(&self, pattern: &str) {
141        unsafe {
142            ffi::gtk_file_filter_add_pattern(self.to_glib_none().0, pattern.to_glib_none().0);
143        }
144    }
145
146    /// Adds a rule allowing image files in the formats supported by [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf].
147    ///
148    /// This is equivalent to calling [`add_mime_type()`][Self::add_mime_type()]
149    /// for all the supported mime types.
150    ///
151    /// # Deprecated since 4.20
152    ///
153    /// Use the api of your image loading framework (e.g. glycin)
154    ///   to enumerate supported formats
155    #[cfg_attr(feature = "v4_20", deprecated = "Since 4.20")]
156    #[allow(deprecated)]
157    #[doc(alias = "gtk_file_filter_add_pixbuf_formats")]
158    pub fn add_pixbuf_formats(&self) {
159        unsafe {
160            ffi::gtk_file_filter_add_pixbuf_formats(self.to_glib_none().0);
161        }
162    }
163
164    /// Adds a suffix match rule to a filter.
165    ///
166    /// This is similar to adding a match for the pattern "*.@suffix"
167    ///
168    /// An exaple to filter files with the suffix ".sub":
169    /// **⚠️ The following code is in c ⚠️**
170    ///
171    /// ```c
172    /// gtk_file_filter_add_suffix (filter, "sub");
173    /// ```
174    ///
175    /// Filters with multiple dots are allowed.
176    ///
177    /// In contrast to pattern matches, suffix matches
178    /// are *always* case-insensitive.
179    /// ## `suffix`
180    /// filename suffix to match
181    #[cfg(feature = "v4_4")]
182    #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
183    #[doc(alias = "gtk_file_filter_add_suffix")]
184    pub fn add_suffix(&self, suffix: &str) {
185        unsafe {
186            ffi::gtk_file_filter_add_suffix(self.to_glib_none().0, suffix.to_glib_none().0);
187        }
188    }
189
190    /// Gets the attributes that need to be filled in for the `GFileInfo`
191    /// passed to this filter.
192    ///
193    /// This function will not typically be used by applications;
194    /// it is intended for use in file chooser implementation.
195    ///
196    /// # Returns
197    ///
198    /// the attributes
199    #[doc(alias = "gtk_file_filter_get_attributes")]
200    #[doc(alias = "get_attributes")]
201    pub fn attributes(&self) -> Vec<glib::GString> {
202        unsafe {
203            FromGlibPtrContainer::from_glib_none(ffi::gtk_file_filter_get_attributes(
204                self.to_glib_none().0,
205            ))
206        }
207    }
208
209    /// Gets the human-readable name for the filter.
210    ///
211    /// See [`set_name()`][Self::set_name()].
212    ///
213    /// # Returns
214    ///
215    /// the human-readable name of the filter
216    #[doc(alias = "gtk_file_filter_get_name")]
217    #[doc(alias = "get_name")]
218    pub fn name(&self) -> Option<glib::GString> {
219        unsafe { from_glib_none(ffi::gtk_file_filter_get_name(self.to_glib_none().0)) }
220    }
221
222    /// Sets a human-readable name of the filter.
223    ///
224    /// This is the string that will be displayed in the user interface
225    /// if there is a selectable list of filters.
226    /// ## `name`
227    /// the human-readable name for the filter
228    #[doc(alias = "gtk_file_filter_set_name")]
229    #[doc(alias = "name")]
230    pub fn set_name(&self, name: Option<&str>) {
231        unsafe {
232            ffi::gtk_file_filter_set_name(self.to_glib_none().0, name.to_glib_none().0);
233        }
234    }
235
236    /// Serialize a file filter to an `a{sv}` variant.
237    ///
238    /// # Returns
239    ///
240    /// a new, floating, `GVariant`
241    #[doc(alias = "gtk_file_filter_to_gvariant")]
242    pub fn to_gvariant(&self) -> glib::Variant {
243        unsafe { from_glib_none(ffi::gtk_file_filter_to_gvariant(self.to_glib_none().0)) }
244    }
245
246    #[doc(alias = "name")]
247    pub fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
248        unsafe extern "C" fn notify_name_trampoline<F: Fn(&FileFilter) + 'static>(
249            this: *mut ffi::GtkFileFilter,
250            _param_spec: glib::ffi::gpointer,
251            f: glib::ffi::gpointer,
252        ) {
253            unsafe {
254                let f: &F = &*(f as *const F);
255                f(&from_glib_borrow(this))
256            }
257        }
258        unsafe {
259            let f: Box_<F> = Box_::new(f);
260            connect_raw(
261                self.as_ptr() as *mut _,
262                c"notify::name".as_ptr(),
263                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
264                    notify_name_trampoline::<F> as *const (),
265                )),
266                Box_::into_raw(f),
267            )
268        }
269    }
270}
271
272impl Default for FileFilter {
273    fn default() -> Self {
274        Self::new()
275    }
276}