1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::Buildable;
use crate::FileFilterFlags;
use glib::translate::*;
use std::fmt;

glib::wrapper! {
    /// A GtkFileFilter can be used to restrict the files being shown in a
    /// [`FileChooser`][crate::FileChooser]. Files can be filtered based on their name (with
    /// [`add_pattern()`][Self::add_pattern()]), on their mime type (with
    /// [`add_mime_type()`][Self::add_mime_type()]), or by a custom filter function
    /// (with `gtk_file_filter_add_custom()`).
    ///
    /// Filtering by mime types handles aliasing and subclassing of mime
    /// types; e.g. a filter for text/plain also matches a file with mime
    /// type application/rtf, since application/rtf is a subclass of
    /// text/plain. Note that [`FileFilter`][crate::FileFilter] allows wildcards for the
    /// subtype of a mime type, so you can e.g. filter for image/\*.
    ///
    /// Normally, filters are used by adding them to a [`FileChooser`][crate::FileChooser],
    /// see [`FileChooserExt::add_filter()`][crate::prelude::FileChooserExt::add_filter()], but it is also possible
    /// to manually use a filter on a file with `gtk_file_filter_filter()`.
    ///
    /// # GtkFileFilter as GtkBuildable
    ///
    /// The GtkFileFilter implementation of the GtkBuildable interface
    /// supports adding rules using the ``<mime-types>``, ``<patterns>`` and
    /// ``<applications>`` elements and listing the rules within. Specifying
    /// a ``<mime-type>`` or ``<pattern>`` has the same effect as as calling
    /// [`add_mime_type()`][Self::add_mime_type()] or [`add_pattern()`][Self::add_pattern()].
    ///
    /// An example of a UI definition fragment specifying GtkFileFilter
    /// rules:
    ///
    ///
    ///
    /// **⚠️ The following code is in xml ⚠️**
    ///
    /// ```xml
    /// <object class="GtkFileFilter">
    ///   <mime-types>
    ///     <mime-type>text/plain</mime-type>
    ///     <mime-type>image/ *</mime-type>
    ///   </mime-types>
    ///   <patterns>
    ///     <pattern>*.txt</pattern>
    ///     <pattern>*.png</pattern>
    ///   </patterns>
    /// </object>
    /// ```
    ///
    /// # Implements
    ///
    /// [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual]
    #[doc(alias = "GtkFileFilter")]
    pub struct FileFilter(Object<ffi::GtkFileFilter>) @implements Buildable;

    match fn {
        type_ => || ffi::gtk_file_filter_get_type(),
    }
}

impl FileFilter {
    /// Creates a new [`FileFilter`][crate::FileFilter] with no rules added to it.
    /// Such a filter doesn’t accept any files, so is not
    /// particularly useful until you add rules with
    /// [`add_mime_type()`][Self::add_mime_type()], [`add_pattern()`][Self::add_pattern()],
    /// or `gtk_file_filter_add_custom()`. To create a filter
    /// that accepts any file, use:
    ///
    ///
    /// **⚠️ The following code is in C ⚠️**
    ///
    /// ```C
    /// GtkFileFilter *filter = gtk_file_filter_new ();
    /// gtk_file_filter_add_pattern (filter, "*");
    /// ```
    ///
    /// # Returns
    ///
    /// a new [`FileFilter`][crate::FileFilter]
    #[doc(alias = "gtk_file_filter_new")]
    pub fn new() -> FileFilter {
        assert_initialized_main_thread!();
        unsafe { from_glib_none(ffi::gtk_file_filter_new()) }
    }

    /// Deserialize a file filter from an a{sv} variant in
    /// the format produced by [`to_gvariant()`][Self::to_gvariant()].
    /// ## `variant`
    /// an a{sv} [`glib::Variant`][struct@crate::glib::Variant]
    ///
    /// # Returns
    ///
    /// a new [`FileFilter`][crate::FileFilter] object
    #[cfg(any(feature = "v3_22", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_22")))]
    #[doc(alias = "gtk_file_filter_new_from_gvariant")]
    #[doc(alias = "new_from_gvariant")]
    pub fn from_gvariant(variant: &glib::Variant) -> FileFilter {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::gtk_file_filter_new_from_gvariant(
                variant.to_glib_none().0,
            ))
        }
    }

    //#[doc(alias = "gtk_file_filter_add_custom")]
    //pub fn add_custom(&self, needed: FileFilterFlags, func: /*Unimplemented*/Fn(/*Ignored*/FileFilterInfo) -> bool, data: /*Unimplemented*/Option<Fundamental: Pointer>) {
    //    unsafe { TODO: call ffi:gtk_file_filter_add_custom() }
    //}

    /// Adds a rule allowing a given mime type to `self`.
    /// ## `mime_type`
    /// name of a MIME type
    #[doc(alias = "gtk_file_filter_add_mime_type")]
    pub fn add_mime_type(&self, mime_type: &str) {
        unsafe {
            ffi::gtk_file_filter_add_mime_type(self.to_glib_none().0, mime_type.to_glib_none().0);
        }
    }

    /// Adds a rule allowing a shell style glob to a filter.
    /// ## `pattern`
    /// a shell style glob
    #[doc(alias = "gtk_file_filter_add_pattern")]
    pub fn add_pattern(&self, pattern: &str) {
        unsafe {
            ffi::gtk_file_filter_add_pattern(self.to_glib_none().0, pattern.to_glib_none().0);
        }
    }

    /// Adds a rule allowing image files in the formats supported
    /// by GdkPixbuf.
    #[doc(alias = "gtk_file_filter_add_pixbuf_formats")]
    pub fn add_pixbuf_formats(&self) {
        unsafe {
            ffi::gtk_file_filter_add_pixbuf_formats(self.to_glib_none().0);
        }
    }

    //#[doc(alias = "gtk_file_filter_filter")]
    //pub fn filter(&self, filter_info: /*Ignored*/&FileFilterInfo) -> bool {
    //    unsafe { TODO: call ffi:gtk_file_filter_filter() }
    //}

    /// Gets the human-readable name for the filter. See [`set_name()`][Self::set_name()].
    ///
    /// # Returns
    ///
    /// The human-readable name of the filter,
    ///  or [`None`]. This value is owned by GTK+ and must not
    ///  be modified or freed.
    #[doc(alias = "gtk_file_filter_get_name")]
    #[doc(alias = "get_name")]
    pub fn name(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::gtk_file_filter_get_name(self.to_glib_none().0)) }
    }

    /// Gets the fields that need to be filled in for the `GtkFileFilterInfo`
    /// passed to `gtk_file_filter_filter()`
    ///
    /// This function will not typically be used by applications; it
    /// is intended principally for use in the implementation of
    /// [`FileChooser`][crate::FileChooser].
    ///
    /// # Returns
    ///
    /// bitfield of flags indicating needed fields when
    ///  calling `gtk_file_filter_filter()`
    #[doc(alias = "gtk_file_filter_get_needed")]
    #[doc(alias = "get_needed")]
    pub fn needed(&self) -> FileFilterFlags {
        unsafe { from_glib(ffi::gtk_file_filter_get_needed(self.to_glib_none().0)) }
    }

    /// Sets the human-readable name of the filter; this is the string
    /// that will be displayed in the file selector user interface if
    /// there is a selectable list of filters.
    /// ## `name`
    /// the human-readable-name for the filter, or [`None`]
    ///  to remove any existing name.
    #[doc(alias = "gtk_file_filter_set_name")]
    pub fn set_name(&self, name: Option<&str>) {
        unsafe {
            ffi::gtk_file_filter_set_name(self.to_glib_none().0, name.to_glib_none().0);
        }
    }

    /// Serialize a file filter to an a{sv} variant.
    ///
    /// # Returns
    ///
    /// a new, floating, [`glib::Variant`][struct@crate::glib::Variant]
    #[cfg(any(feature = "v3_22", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_22")))]
    #[doc(alias = "gtk_file_filter_to_gvariant")]
    pub fn to_gvariant(&self) -> Option<glib::Variant> {
        unsafe { from_glib_none(ffi::gtk_file_filter_to_gvariant(self.to_glib_none().0)) }
    }
}

impl Default for FileFilter {
    fn default() -> Self {
        Self::new()
    }
}

impl fmt::Display for FileFilter {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("FileFilter")
    }
}