gtk/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
5use crate::{Buildable, FileFilterFlags, FileFilterInfo, ffi};
6use glib::translate::*;
7use std::boxed::Box as Box_;
8
9glib::wrapper! {
10 ///
11 /// ]|
12 ///
13 /// # Implements
14 ///
15 /// [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual]
16 #[doc(alias = "GtkFileFilter")]
17 pub struct FileFilter(Object<ffi::GtkFileFilter>) @implements Buildable;
18
19 match fn {
20 type_ => || ffi::gtk_file_filter_get_type(),
21 }
22}
23
24impl FileFilter {
25 ///
26 /// GtkFileFilter *filter = gtk_file_filter_new ();
27 /// gtk_file_filter_add_pattern (filter, "*");
28 /// ]|
29 ///
30 /// # Returns
31 ///
32 /// a new [`FileFilter`][crate::FileFilter]
33 #[doc(alias = "gtk_file_filter_new")]
34 pub fn new() -> FileFilter {
35 assert_initialized_main_thread!();
36 unsafe { from_glib_none(ffi::gtk_file_filter_new()) }
37 }
38
39 /// Deserialize a file filter from an a{sv} variant in
40 /// the format produced by [`to_gvariant()`][Self::to_gvariant()].
41 /// ## `variant`
42 /// an a{sv} [`glib::Variant`][struct@crate::glib::Variant]
43 ///
44 /// # Returns
45 ///
46 /// a new [`FileFilter`][crate::FileFilter] object
47 #[doc(alias = "gtk_file_filter_new_from_gvariant")]
48 #[doc(alias = "new_from_gvariant")]
49 pub fn from_gvariant(variant: &glib::Variant) -> FileFilter {
50 assert_initialized_main_thread!();
51 unsafe {
52 from_glib_full(ffi::gtk_file_filter_new_from_gvariant(
53 variant.to_glib_none().0,
54 ))
55 }
56 }
57
58 /// Adds rule to a filter that allows files based on a custom callback
59 /// function. The bitfield `needed` which is passed in provides information
60 /// about what sorts of information that the filter function needs;
61 /// this allows GTK+ to avoid retrieving expensive information when
62 /// it isn’t needed by the filter.
63 /// ## `needed`
64 /// bitfield of flags indicating the information that the custom
65 /// filter function needs.
66 /// ## `func`
67 /// callback function; if the function returns [`true`], then
68 /// the file will be displayed.
69 /// ## `notify`
70 /// function to call to free `data` when it is no longer needed.
71 #[doc(alias = "gtk_file_filter_add_custom")]
72 pub fn add_custom<P: Fn(&FileFilterInfo) -> bool + 'static>(
73 &self,
74 needed: FileFilterFlags,
75 func: P,
76 ) {
77 let func_data: Box_<P> = Box_::new(func);
78 unsafe extern "C" fn func_func<P: Fn(&FileFilterInfo) -> bool + 'static>(
79 filter_info: *const ffi::GtkFileFilterInfo,
80 data: glib::ffi::gpointer,
81 ) -> glib::ffi::gboolean {
82 unsafe {
83 let filter_info = from_glib_borrow(filter_info);
84 let callback = &*(data as *mut P);
85 (*callback)(&filter_info).into_glib()
86 }
87 }
88 let func = Some(func_func::<P> as _);
89 unsafe extern "C" fn notify_func<P: Fn(&FileFilterInfo) -> bool + 'static>(
90 data: glib::ffi::gpointer,
91 ) {
92 unsafe {
93 let _callback = Box_::from_raw(data as *mut P);
94 }
95 }
96 let destroy_call4 = Some(notify_func::<P> as _);
97 let super_callback0: Box_<P> = func_data;
98 unsafe {
99 ffi::gtk_file_filter_add_custom(
100 self.to_glib_none().0,
101 needed.into_glib(),
102 func,
103 Box_::into_raw(super_callback0) as *mut _,
104 destroy_call4,
105 );
106 }
107 }
108
109 /// Adds a rule allowing a given mime type to `self`.
110 /// ## `mime_type`
111 /// name of a MIME type
112 #[doc(alias = "gtk_file_filter_add_mime_type")]
113 pub fn add_mime_type(&self, mime_type: &str) {
114 unsafe {
115 ffi::gtk_file_filter_add_mime_type(self.to_glib_none().0, mime_type.to_glib_none().0);
116 }
117 }
118
119 /// Adds a rule allowing a shell style glob to a filter.
120 /// ## `pattern`
121 /// a shell style glob
122 #[doc(alias = "gtk_file_filter_add_pattern")]
123 pub fn add_pattern(&self, pattern: &str) {
124 unsafe {
125 ffi::gtk_file_filter_add_pattern(self.to_glib_none().0, pattern.to_glib_none().0);
126 }
127 }
128
129 /// Adds a rule allowing image files in the formats supported
130 /// by GdkPixbuf.
131 #[doc(alias = "gtk_file_filter_add_pixbuf_formats")]
132 pub fn add_pixbuf_formats(&self) {
133 unsafe {
134 ffi::gtk_file_filter_add_pixbuf_formats(self.to_glib_none().0);
135 }
136 }
137
138 /// Tests whether a file should be displayed according to `self`.
139 /// The [`FileFilterInfo`][crate::FileFilterInfo] `filter_info` should include
140 /// the fields returned from [`needed()`][Self::needed()].
141 ///
142 /// This function will not typically be used by applications; it
143 /// is intended principally for use in the implementation of
144 /// [`FileChooser`][crate::FileChooser].
145 /// ## `filter_info`
146 /// a [`FileFilterInfo`][crate::FileFilterInfo] containing information
147 /// about a file.
148 ///
149 /// # Returns
150 ///
151 /// [`true`] if the file should be displayed
152 #[doc(alias = "gtk_file_filter_filter")]
153 pub fn filter(&self, filter_info: &FileFilterInfo) -> bool {
154 unsafe {
155 from_glib(ffi::gtk_file_filter_filter(
156 self.to_glib_none().0,
157 filter_info.to_glib_none().0,
158 ))
159 }
160 }
161
162 /// Gets the human-readable name for the filter. See [`set_name()`][Self::set_name()].
163 ///
164 /// # Returns
165 ///
166 /// The human-readable name of the filter,
167 /// or [`None`]. This value is owned by GTK+ and must not
168 /// be modified or freed.
169 #[doc(alias = "gtk_file_filter_get_name")]
170 #[doc(alias = "get_name")]
171 pub fn name(&self) -> Option<glib::GString> {
172 unsafe { from_glib_none(ffi::gtk_file_filter_get_name(self.to_glib_none().0)) }
173 }
174
175 /// Gets the fields that need to be filled in for the [`FileFilterInfo`][crate::FileFilterInfo]
176 /// passed to [`filter()`][Self::filter()]
177 ///
178 /// This function will not typically be used by applications; it
179 /// is intended principally for use in the implementation of
180 /// [`FileChooser`][crate::FileChooser].
181 ///
182 /// # Returns
183 ///
184 /// bitfield of flags indicating needed fields when
185 /// calling [`filter()`][Self::filter()]
186 #[doc(alias = "gtk_file_filter_get_needed")]
187 #[doc(alias = "get_needed")]
188 pub fn needed(&self) -> FileFilterFlags {
189 unsafe { from_glib(ffi::gtk_file_filter_get_needed(self.to_glib_none().0)) }
190 }
191
192 /// Sets the human-readable name of the filter; this is the string
193 /// that will be displayed in the file selector user interface if
194 /// there is a selectable list of filters.
195 /// ## `name`
196 /// the human-readable-name for the filter, or [`None`]
197 /// to remove any existing name.
198 #[doc(alias = "gtk_file_filter_set_name")]
199 pub fn set_name(&self, name: Option<&str>) {
200 unsafe {
201 ffi::gtk_file_filter_set_name(self.to_glib_none().0, name.to_glib_none().0);
202 }
203 }
204
205 /// Serialize a file filter to an a{sv} variant.
206 ///
207 /// # Returns
208 ///
209 /// a new, floating, [`glib::Variant`][struct@crate::glib::Variant]
210 #[doc(alias = "gtk_file_filter_to_gvariant")]
211 pub fn to_gvariant(&self) -> Option<glib::Variant> {
212 unsafe { from_glib_none(ffi::gtk_file_filter_to_gvariant(self.to_glib_none().0)) }
213 }
214}
215
216impl Default for FileFilter {
217 fn default() -> Self {
218 Self::new()
219 }
220}