gtk/auto/recent_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, RecentFilterFlags, ffi};
6use glib::translate::*;
7
8glib::wrapper! {
9 /// A [`RecentFilter`][crate::RecentFilter] can be used to restrict the files being shown
10 /// in a [`RecentChooser`][crate::RecentChooser]. Files can be filtered based on their name
11 /// (with [`add_pattern()`][Self::add_pattern()]), on their mime type (with
12 /// [`FileFilter::add_mime_type()`][crate::FileFilter::add_mime_type()]), on the application that has
13 /// registered them (with [`add_application()`][Self::add_application()]), or by
14 /// a custom filter function (with `gtk_recent_filter_add_custom()`).
15 ///
16 /// Filtering by mime type handles aliasing and subclassing of mime
17 /// types; e.g. a filter for text/plain also matches a file with mime
18 /// type application/rtf, since application/rtf is a subclass of text/plain.
19 /// Note that [`RecentFilter`][crate::RecentFilter] allows wildcards for the subtype of a
20 /// mime type, so you can e.g. filter for image/\*.
21 ///
22 /// Normally, filters are used by adding them to a [`RecentChooser`][crate::RecentChooser],
23 /// see [`RecentChooserExt::add_filter()`][crate::prelude::RecentChooserExt::add_filter()], but it is also possible to
24 /// manually use a filter on a file with `gtk_recent_filter_filter()`.
25 ///
26 /// Recently used files are supported since GTK+ 2.10.
27 ///
28 /// ## GtkRecentFilter as GtkBuildable
29 ///
30 /// The GtkRecentFilter implementation of the GtkBuildable interface
31 /// supports adding rules using the ``<mime-types>``, ``<patterns>`` and
32 /// ``<applications>`` elements and listing the rules within. Specifying
33 /// a ``<mime-type>``, ``<pattern>`` or ``<application>`` has the same effect as
34 /// calling [`add_mime_type()`][Self::add_mime_type()],
35 /// [`add_pattern()`][Self::add_pattern()] or [`add_application()`][Self::add_application()].
36 ///
37 /// An example of a UI definition fragment specifying [`RecentFilter`][crate::RecentFilter]
38 /// rules:
39 ///
40 ///
41 ///
42 /// **⚠️ The following code is in xml ⚠️**
43 ///
44 /// ```xml
45 /// <object class="GtkRecentFilter">
46 /// <mime-types>
47 /// <mime-type>text/plain</mime-type>
48 /// <mime-type>image/png</mime-type>
49 /// </mime-types>
50 /// <patterns>
51 /// <pattern>*.txt</pattern>
52 /// <pattern>*.png</pattern>
53 /// </patterns>
54 /// <applications>
55 /// <application>gimp</application>
56 /// <application>gedit</application>
57 /// <application>glade</application>
58 /// </applications>
59 /// </object>
60 /// ```
61 ///
62 /// # Implements
63 ///
64 /// [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual]
65 #[doc(alias = "GtkRecentFilter")]
66 pub struct RecentFilter(Object<ffi::GtkRecentFilter>) @implements Buildable;
67
68 match fn {
69 type_ => || ffi::gtk_recent_filter_get_type(),
70 }
71}
72
73impl RecentFilter {
74 /// Creates a new [`RecentFilter`][crate::RecentFilter] with no rules added to it.
75 /// Such filter does not accept any recently used resources, so is not
76 /// particularly useful until you add rules with
77 /// [`add_pattern()`][Self::add_pattern()], [`add_mime_type()`][Self::add_mime_type()],
78 /// [`add_application()`][Self::add_application()], [`add_age()`][Self::add_age()].
79 /// To create a filter that accepts any recently used resource, use:
80 ///
81 ///
82 /// **⚠️ The following code is in C ⚠️**
83 ///
84 /// ```C
85 /// GtkRecentFilter *filter = gtk_recent_filter_new ();
86 /// gtk_recent_filter_add_pattern (filter, "*");
87 /// ```
88 ///
89 /// # Returns
90 ///
91 /// a new [`RecentFilter`][crate::RecentFilter]
92 #[doc(alias = "gtk_recent_filter_new")]
93 pub fn new() -> RecentFilter {
94 assert_initialized_main_thread!();
95 unsafe { from_glib_none(ffi::gtk_recent_filter_new()) }
96 }
97
98 /// Adds a rule that allows resources based on their age - that is, the number
99 /// of days elapsed since they were last modified.
100 /// ## `days`
101 /// number of days
102 #[doc(alias = "gtk_recent_filter_add_age")]
103 pub fn add_age(&self, days: i32) {
104 unsafe {
105 ffi::gtk_recent_filter_add_age(self.to_glib_none().0, days);
106 }
107 }
108
109 /// Adds a rule that allows resources based on the name of the application
110 /// that has registered them.
111 /// ## `application`
112 /// an application name
113 #[doc(alias = "gtk_recent_filter_add_application")]
114 pub fn add_application(&self, application: &str) {
115 unsafe {
116 ffi::gtk_recent_filter_add_application(
117 self.to_glib_none().0,
118 application.to_glib_none().0,
119 );
120 }
121 }
122
123 //#[doc(alias = "gtk_recent_filter_add_custom")]
124 //pub fn add_custom(&self, needed: RecentFilterFlags, func: /*Unimplemented*/Fn(/*Ignored*/RecentFilterInfo) -> bool, data: /*Unimplemented*/Option<Basic: Pointer>) {
125 // unsafe { TODO: call ffi:gtk_recent_filter_add_custom() }
126 //}
127
128 /// Adds a rule that allows resources based on the name of the group
129 /// to which they belong
130 /// ## `group`
131 /// a group name
132 #[doc(alias = "gtk_recent_filter_add_group")]
133 pub fn add_group(&self, group: &str) {
134 unsafe {
135 ffi::gtk_recent_filter_add_group(self.to_glib_none().0, group.to_glib_none().0);
136 }
137 }
138
139 /// Adds a rule that allows resources based on their registered MIME type.
140 /// ## `mime_type`
141 /// a MIME type
142 #[doc(alias = "gtk_recent_filter_add_mime_type")]
143 pub fn add_mime_type(&self, mime_type: &str) {
144 unsafe {
145 ffi::gtk_recent_filter_add_mime_type(self.to_glib_none().0, mime_type.to_glib_none().0);
146 }
147 }
148
149 /// Adds a rule that allows resources based on a pattern matching their
150 /// display name.
151 /// ## `pattern`
152 /// a file pattern
153 #[doc(alias = "gtk_recent_filter_add_pattern")]
154 pub fn add_pattern(&self, pattern: &str) {
155 unsafe {
156 ffi::gtk_recent_filter_add_pattern(self.to_glib_none().0, pattern.to_glib_none().0);
157 }
158 }
159
160 /// Adds a rule allowing image files in the formats supported
161 /// by GdkPixbuf.
162 #[doc(alias = "gtk_recent_filter_add_pixbuf_formats")]
163 pub fn add_pixbuf_formats(&self) {
164 unsafe {
165 ffi::gtk_recent_filter_add_pixbuf_formats(self.to_glib_none().0);
166 }
167 }
168
169 /// Gets the human-readable name for the filter.
170 /// See [`set_name()`][Self::set_name()].
171 ///
172 /// # Returns
173 ///
174 /// the name of the filter, or [`None`]. The returned string
175 /// is owned by the filter object and should not be freed.
176 #[doc(alias = "gtk_recent_filter_get_name")]
177 #[doc(alias = "get_name")]
178 pub fn name(&self) -> Option<glib::GString> {
179 unsafe { from_glib_none(ffi::gtk_recent_filter_get_name(self.to_glib_none().0)) }
180 }
181
182 /// Gets the fields that need to be filled in for the `GtkRecentFilterInfo`
183 /// passed to `gtk_recent_filter_filter()`
184 ///
185 /// This function will not typically be used by applications; it
186 /// is intended principally for use in the implementation of
187 /// [`RecentChooser`][crate::RecentChooser].
188 ///
189 /// # Returns
190 ///
191 /// bitfield of flags indicating needed fields when
192 /// calling `gtk_recent_filter_filter()`
193 #[doc(alias = "gtk_recent_filter_get_needed")]
194 #[doc(alias = "get_needed")]
195 pub fn needed(&self) -> RecentFilterFlags {
196 unsafe { from_glib(ffi::gtk_recent_filter_get_needed(self.to_glib_none().0)) }
197 }
198
199 /// Sets the human-readable name of the filter; this is the string
200 /// that will be displayed in the recently used resources selector
201 /// user interface if there is a selectable list of filters.
202 /// ## `name`
203 /// then human readable name of `self`
204 #[doc(alias = "gtk_recent_filter_set_name")]
205 pub fn set_name(&self, name: &str) {
206 unsafe {
207 ffi::gtk_recent_filter_set_name(self.to_glib_none().0, name.to_glib_none().0);
208 }
209 }
210}
211
212impl Default for RecentFilter {
213 fn default() -> Self {
214 Self::new()
215 }
216}