1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.RecentFilter; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import gobject.ObjectG; 30 private import gtk.BuildableIF; 31 private import gtk.BuildableT; 32 private import gtkc.gtk; 33 public import gtkc.gtktypes; 34 35 36 /** 37 * A #GtkRecentFilter can be used to restrict the files being shown 38 * in a #GtkRecentChooser. Files can be filtered based on their name 39 * (with gtk_recent_filter_add_pattern()), on their mime type (with 40 * gtk_file_filter_add_mime_type()), on the application that has 41 * registered them (with gtk_recent_filter_add_application()), or by 42 * a custom filter function (with gtk_recent_filter_add_custom()). 43 * 44 * Filtering by mime type handles aliasing and subclassing of mime 45 * types; e.g. a filter for text/plain also matches a file with mime 46 * type application/rtf, since application/rtf is a subclass of text/plain. 47 * Note that #GtkRecentFilter allows wildcards for the subtype of a 48 * mime type, so you can e.g. filter for image/\*. 49 * 50 * Normally, filters are used by adding them to a #GtkRecentChooser, 51 * see gtk_recent_chooser_add_filter(), but it is also possible to 52 * manually use a filter on a file with gtk_recent_filter_filter(). 53 * 54 * Recently used files are supported since GTK+ 2.10. 55 * 56 * ## GtkRecentFilter as GtkBuildable 57 * 58 * The GtkRecentFilter implementation of the GtkBuildable interface 59 * supports adding rules using the <mime-types>, <patterns> and 60 * <applications> elements and listing the rules within. Specifying 61 * a <mime-type>, <pattern> or <application> has the same effect as 62 * calling gtk_recent_filter_add_mime_type(), 63 * gtk_recent_filter_add_pattern() or gtk_recent_filter_add_application(). 64 * 65 * An example of a UI definition fragment specifying GtkRecentFilter rules: 66 * |[ 67 * <object class="GtkRecentFilter"> 68 * <mime-types> 69 * <mime-type>text/plain</mime-type> 70 * <mime-type>image/png</mime-type> 71 * </mime-types> 72 * <patterns> 73 * <pattern>*.txt</pattern> 74 * <pattern>*.png</pattern> 75 * </patterns> 76 * <applications> 77 * <application>gimp</application> 78 * <application>gedit</application> 79 * <application>glade</application> 80 * </applications> 81 * </object> 82 * ]| 83 */ 84 public class RecentFilter : ObjectG, BuildableIF 85 { 86 /** the main Gtk struct */ 87 protected GtkRecentFilter* gtkRecentFilter; 88 89 /** Get the main Gtk struct */ 90 public GtkRecentFilter* getRecentFilterStruct(bool transferOwnership = false) 91 { 92 if (transferOwnership) 93 ownedRef = false; 94 return gtkRecentFilter; 95 } 96 97 /** the main Gtk struct as a void* */ 98 protected override void* getStruct() 99 { 100 return cast(void*)gtkRecentFilter; 101 } 102 103 protected override void setStruct(GObject* obj) 104 { 105 gtkRecentFilter = cast(GtkRecentFilter*)obj; 106 super.setStruct(obj); 107 } 108 109 /** 110 * Sets our main struct and passes it to the parent class. 111 */ 112 public this (GtkRecentFilter* gtkRecentFilter, bool ownedRef = false) 113 { 114 this.gtkRecentFilter = gtkRecentFilter; 115 super(cast(GObject*)gtkRecentFilter, ownedRef); 116 } 117 118 // add the Buildable capabilities 119 mixin BuildableT!(GtkRecentFilter); 120 121 122 /** */ 123 public static GType getType() 124 { 125 return gtk_recent_filter_get_type(); 126 } 127 128 /** 129 * Creates a new #GtkRecentFilter with no rules added to it. 130 * Such filter does not accept any recently used resources, so is not 131 * particularly useful until you add rules with 132 * gtk_recent_filter_add_pattern(), gtk_recent_filter_add_mime_type(), 133 * gtk_recent_filter_add_application(), gtk_recent_filter_add_age(). 134 * To create a filter that accepts any recently used resource, use: 135 * |[<!-- language="C" --> 136 * GtkRecentFilter *filter = gtk_recent_filter_new (); 137 * gtk_recent_filter_add_pattern (filter, "*"); 138 * ]| 139 * 140 * Returns: a new #GtkRecentFilter 141 * 142 * Since: 2.10 143 * 144 * Throws: ConstructionException GTK+ fails to create the object. 145 */ 146 public this() 147 { 148 auto p = gtk_recent_filter_new(); 149 150 if(p is null) 151 { 152 throw new ConstructionException("null returned by new"); 153 } 154 155 this(cast(GtkRecentFilter*) p); 156 } 157 158 /** 159 * Adds a rule that allows resources based on their age - that is, the number 160 * of days elapsed since they were last modified. 161 * 162 * Params: 163 * days = number of days 164 * 165 * Since: 2.10 166 */ 167 public void addAge(int days) 168 { 169 gtk_recent_filter_add_age(gtkRecentFilter, days); 170 } 171 172 /** 173 * Adds a rule that allows resources based on the name of the application 174 * that has registered them. 175 * 176 * Params: 177 * application = an application name 178 * 179 * Since: 2.10 180 */ 181 public void addApplication(string application) 182 { 183 gtk_recent_filter_add_application(gtkRecentFilter, Str.toStringz(application)); 184 } 185 186 /** 187 * Adds a rule to a filter that allows resources based on a custom callback 188 * function. The bitfield @needed which is passed in provides information 189 * about what sorts of information that the filter function needs; 190 * this allows GTK+ to avoid retrieving expensive information when 191 * it isn’t needed by the filter. 192 * 193 * Params: 194 * needed = bitfield of flags indicating the information that the custom 195 * filter function needs. 196 * func = callback function; if the function returns %TRUE, then 197 * the file will be displayed. 198 * data = data to pass to @func 199 * dataDestroy = function to call to free @data when it is no longer needed. 200 * 201 * Since: 2.10 202 */ 203 public void addCustom(GtkRecentFilterFlags needed, GtkRecentFilterFunc func, void* data, GDestroyNotify dataDestroy) 204 { 205 gtk_recent_filter_add_custom(gtkRecentFilter, needed, func, data, dataDestroy); 206 } 207 208 /** 209 * Adds a rule that allows resources based on the name of the group 210 * to which they belong 211 * 212 * Params: 213 * group = a group name 214 * 215 * Since: 2.10 216 */ 217 public void addGroup(string group) 218 { 219 gtk_recent_filter_add_group(gtkRecentFilter, Str.toStringz(group)); 220 } 221 222 /** 223 * Adds a rule that allows resources based on their registered MIME type. 224 * 225 * Params: 226 * mimeType = a MIME type 227 * 228 * Since: 2.10 229 */ 230 public void addMimeType(string mimeType) 231 { 232 gtk_recent_filter_add_mime_type(gtkRecentFilter, Str.toStringz(mimeType)); 233 } 234 235 /** 236 * Adds a rule that allows resources based on a pattern matching their 237 * display name. 238 * 239 * Params: 240 * pattern = a file pattern 241 * 242 * Since: 2.10 243 */ 244 public void addPattern(string pattern) 245 { 246 gtk_recent_filter_add_pattern(gtkRecentFilter, Str.toStringz(pattern)); 247 } 248 249 /** 250 * Adds a rule allowing image files in the formats supported 251 * by GdkPixbuf. 252 * 253 * Since: 2.10 254 */ 255 public void addPixbufFormats() 256 { 257 gtk_recent_filter_add_pixbuf_formats(gtkRecentFilter); 258 } 259 260 /** 261 * Tests whether a file should be displayed according to @filter. 262 * The #GtkRecentFilterInfo @filter_info should include 263 * the fields returned from gtk_recent_filter_get_needed(), and 264 * must set the #GtkRecentFilterInfo.contains field of @filter_info 265 * to indicate which fields have been set. 266 * 267 * This function will not typically be used by applications; it 268 * is intended principally for use in the implementation of 269 * #GtkRecentChooser. 270 * 271 * Params: 272 * filterInfo = a #GtkRecentFilterInfo containing information 273 * about a recently used resource 274 * 275 * Returns: %TRUE if the file should be displayed 276 * 277 * Since: 2.10 278 */ 279 public bool filter(GtkRecentFilterInfo* filterInfo) 280 { 281 return gtk_recent_filter_filter(gtkRecentFilter, filterInfo) != 0; 282 } 283 284 /** 285 * Gets the human-readable name for the filter. 286 * See gtk_recent_filter_set_name(). 287 * 288 * Returns: the name of the filter, or %NULL. The returned string 289 * is owned by the filter object and should not be freed. 290 * 291 * Since: 2.10 292 */ 293 public string getName() 294 { 295 return Str.toString(gtk_recent_filter_get_name(gtkRecentFilter)); 296 } 297 298 /** 299 * Gets the fields that need to be filled in for the #GtkRecentFilterInfo 300 * passed to gtk_recent_filter_filter() 301 * 302 * This function will not typically be used by applications; it 303 * is intended principally for use in the implementation of 304 * #GtkRecentChooser. 305 * 306 * Returns: bitfield of flags indicating needed fields when 307 * calling gtk_recent_filter_filter() 308 * 309 * Since: 2.10 310 */ 311 public GtkRecentFilterFlags getNeeded() 312 { 313 return gtk_recent_filter_get_needed(gtkRecentFilter); 314 } 315 316 /** 317 * Sets the human-readable name of the filter; this is the string 318 * that will be displayed in the recently used resources selector 319 * user interface if there is a selectable list of filters. 320 * 321 * Params: 322 * name = then human readable name of @filter 323 * 324 * Since: 2.10 325 */ 326 public void setName(string name) 327 { 328 gtk_recent_filter_set_name(gtkRecentFilter, Str.toStringz(name)); 329 } 330 }