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
// 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 glib::translate::*; use glib::GString; use gtk_sys; use std::fmt; use Buildable; use RecentFilterFlags; glib_wrapper! { /// A `RecentFilter` can be used to restrict the files being shown /// in a `RecentChooser`. Files can be filtered based on their name /// (with `RecentFilter::add_pattern`), on their mime type (with /// `FileFilter::add_mime_type`), on the application that has /// registered them (with `RecentFilter::add_application`), or by /// a custom filter function (with `RecentFilter::add_custom`). /// /// Filtering by mime type 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 `RecentFilter` 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 `RecentChooser`, /// see `RecentChooser::add_filter`, but it is also possible to /// manually use a filter on a file with `RecentFilter::filter`. /// /// Recently used files are supported since GTK+ 2.10. /// /// ## `RecentFilter` as `Buildable` /// /// The `RecentFilter` implementation of the `Buildable` interface /// supports adding rules using the `<mime-types>`, `<patterns>` and /// `<applications>` elements and listing the rules within. Specifying /// a `<mime-type>`, `<pattern>` or `<application>` has the same effect as /// calling `RecentFilter::add_mime_type`, /// `RecentFilter::add_pattern` or `RecentFilter::add_application`. /// /// An example of a UI definition fragment specifying `RecentFilter` rules: /// /// ```text /// <object class="GtkRecentFilter"> /// <mime-types> /// <mime-type>text/plain</mime-type> /// <mime-type>image/png</mime-type> /// </mime-types> /// <patterns> /// <pattern>*.txt</pattern> /// <pattern>*.png</pattern> /// </patterns> /// <applications> /// <application>gimp</application> /// <application>gedit</application> /// <application>glade</application> /// </applications> /// </object> /// ``` /// /// # Implements /// /// [`glib::object::ObjectExt`](../glib/object/trait.ObjectExt.html), [`BuildableExt`](trait.BuildableExt.html), [`BuildableExtManual`](prelude/trait.BuildableExtManual.html) pub struct RecentFilter(Object<gtk_sys::GtkRecentFilter, RecentFilterClass>) @implements Buildable; match fn { get_type => || gtk_sys::gtk_recent_filter_get_type(), } } impl RecentFilter { /// Creates a new `RecentFilter` with no rules added to it. /// Such filter does not accept any recently used resources, so is not /// particularly useful until you add rules with /// `RecentFilter::add_pattern`, `RecentFilter::add_mime_type`, /// `RecentFilter::add_application`, `RecentFilter::add_age`. /// To create a filter that accepts any recently used resource, use: /// /// ```C /// GtkRecentFilter *filter = gtk_recent_filter_new (); /// gtk_recent_filter_add_pattern (filter, "*"); /// ``` /// /// # Returns /// /// a new `RecentFilter` pub fn new() -> RecentFilter { assert_initialized_main_thread!(); unsafe { from_glib_none(gtk_sys::gtk_recent_filter_new()) } } /// Adds a rule that allows resources based on their age - that is, the number /// of days elapsed since they were last modified. /// ## `days` /// number of days pub fn add_age(&self, days: i32) { unsafe { gtk_sys::gtk_recent_filter_add_age(self.to_glib_none().0, days); } } /// Adds a rule that allows resources based on the name of the application /// that has registered them. /// ## `application` /// an application name pub fn add_application(&self, application: &str) { unsafe { gtk_sys::gtk_recent_filter_add_application( self.to_glib_none().0, application.to_glib_none().0, ); } } //pub fn add_custom(&self, needed: RecentFilterFlags, func: /*Unimplemented*/Fn(/*Ignored*/RecentFilterInfo) -> bool, data: /*Unimplemented*/Option<Fundamental: Pointer>) { // unsafe { TODO: call gtk_sys:gtk_recent_filter_add_custom() } //} /// Adds a rule that allows resources based on the name of the group /// to which they belong /// ## `group` /// a group name pub fn add_group(&self, group: &str) { unsafe { gtk_sys::gtk_recent_filter_add_group(self.to_glib_none().0, group.to_glib_none().0); } } /// Adds a rule that allows resources based on their registered MIME type. /// ## `mime_type` /// a MIME type pub fn add_mime_type(&self, mime_type: &str) { unsafe { gtk_sys::gtk_recent_filter_add_mime_type( self.to_glib_none().0, mime_type.to_glib_none().0, ); } } /// Adds a rule that allows resources based on a pattern matching their /// display name. /// ## `pattern` /// a file pattern pub fn add_pattern(&self, pattern: &str) { unsafe { gtk_sys::gtk_recent_filter_add_pattern(self.to_glib_none().0, pattern.to_glib_none().0); } } /// Adds a rule allowing image files in the formats supported /// by `gdk_pixbuf::Pixbuf`. pub fn add_pixbuf_formats(&self) { unsafe { gtk_sys::gtk_recent_filter_add_pixbuf_formats(self.to_glib_none().0); } } //pub fn filter(&self, filter_info: /*Ignored*/&RecentFilterInfo) -> bool { // unsafe { TODO: call gtk_sys:gtk_recent_filter_filter() } //} /// Gets the human-readable name for the filter. /// See `RecentFilter::set_name`. /// /// # Returns /// /// the name of the filter, or `None`. The returned string /// is owned by the filter object and should not be freed. pub fn get_name(&self) -> Option<GString> { unsafe { from_glib_none(gtk_sys::gtk_recent_filter_get_name(self.to_glib_none().0)) } } /// Gets the fields that need to be filled in for the `RecentFilterInfo` /// passed to `RecentFilter::filter` /// /// This function will not typically be used by applications; it /// is intended principally for use in the implementation of /// `RecentChooser`. /// /// # Returns /// /// bitfield of flags indicating needed fields when /// calling `RecentFilter::filter` pub fn get_needed(&self) -> RecentFilterFlags { unsafe { from_glib(gtk_sys::gtk_recent_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 recently used resources selector /// user interface if there is a selectable list of filters. /// ## `name` /// then human readable name of `self` pub fn set_name(&self, name: &str) { unsafe { gtk_sys::gtk_recent_filter_set_name(self.to_glib_none().0, name.to_glib_none().0); } } } impl Default for RecentFilter { fn default() -> Self { Self::new() } } impl fmt::Display for RecentFilter { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "RecentFilter") } }