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.FileFilter;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import glib.Variant;
30 private import glib.c.functions;
31 private import gobject.ObjectG;
32 private import gtk.BuildableIF;
33 private import gtk.BuildableT;
34 private import gtk.Filter;
35 private import gtk.c.functions;
36 public  import gtk.c.types;
37 
38 
39 /**
40  * `GtkFileFilter` filters files by name or mime type.
41  * 
42  * `GtkFileFilter` can be used to restrict the files being shown in a
43  * `GtkFileChooser`. Files can be filtered based on their name (with
44  * [method@Gtk.FileFilter.add_pattern]) or on their mime type (with
45  * [method@Gtk.FileFilter.add_mime_type]).
46  * 
47  * Filtering by mime types handles aliasing and subclassing of mime
48  * types; e.g. a filter for text/plain also matches a file with mime
49  * type application/rtf, since application/rtf is a subclass of
50  * text/plain. Note that `GtkFileFilter` allows wildcards for the
51  * subtype of a mime type, so you can e.g. filter for image/\*.
52  * 
53  * Normally, file filters are used by adding them to a `GtkFileChooser`
54  * (see [method@Gtk.FileChooser.add_filter]), but it is also possible to
55  * manually use a file filter on any [class@Gtk.FilterListModel] containing
56  * `GFileInfo` objects.
57  * 
58  * # GtkFileFilter as GtkBuildable
59  * 
60  * The `GtkFileFilter` implementation of the `GtkBuildable` interface
61  * supports adding rules using the <mime-types> and <patterns>
62  * elements and listing the rules within. Specifying a <mime-type>
63  * or <pattern> has the same effect as as calling
64  * [method@Gtk.FileFilter.add_mime_type] or
65  * [method@Gtk.FileFilter.add_pattern].
66  * 
67  * An example of a UI definition fragment specifying `GtkFileFilter`
68  * rules:
69  * ```xml
70  * <object class="GtkFileFilter">
71  * <property name="name" translatable="yes">Text and Images</property>
72  * <mime-types>
73  * <mime-type>text/plain</mime-type>
74  * <mime-type>image/ *</mime-type>
75  * </mime-types>
76  * <patterns>
77  * <pattern>*.txt</pattern>
78  * <pattern>*.png</pattern>
79  * </patterns>
80  * </object>
81  * ```
82  */
83 public class FileFilter : Filter, BuildableIF
84 {
85 	/** the main Gtk struct */
86 	protected GtkFileFilter* gtkFileFilter;
87 
88 	/** Get the main Gtk struct */
89 	public GtkFileFilter* getFileFilterStruct(bool transferOwnership = false)
90 	{
91 		if (transferOwnership)
92 			ownedRef = false;
93 		return gtkFileFilter;
94 	}
95 
96 	/** the main Gtk struct as a void* */
97 	protected override void* getStruct()
98 	{
99 		return cast(void*)gtkFileFilter;
100 	}
101 
102 	/**
103 	 * Sets our main struct and passes it to the parent class.
104 	 */
105 	public this (GtkFileFilter* gtkFileFilter, bool ownedRef = false)
106 	{
107 		this.gtkFileFilter = gtkFileFilter;
108 		super(cast(GtkFilter*)gtkFileFilter, ownedRef);
109 	}
110 
111 	// add the Buildable capabilities
112 	mixin BuildableT!(GtkFileFilter);
113 
114 
115 	/** */
116 	public static GType getType()
117 	{
118 		return gtk_file_filter_get_type();
119 	}
120 
121 	/**
122 	 * Creates a new `GtkFileFilter` with no rules added to it.
123 	 *
124 	 * Such a filter doesn’t accept any files, so is not
125 	 * particularly useful until you add rules with
126 	 * [method@Gtk.FileFilter.add_mime_type],
127 	 * [method@Gtk.FileFilter.add_pattern], or
128 	 * [method@Gtk.FileFilter.add_pixbuf_formats].
129 	 *
130 	 * To create a filter that accepts any file, use:
131 	 * ```c
132 	 * GtkFileFilter *filter = gtk_file_filter_new ();
133 	 * gtk_file_filter_add_pattern (filter, "*");
134 	 * ```
135 	 *
136 	 * Returns: a new `GtkFileFilter`
137 	 *
138 	 * Throws: ConstructionException GTK+ fails to create the object.
139 	 */
140 	public this()
141 	{
142 		auto __p = gtk_file_filter_new();
143 
144 		if(__p is null)
145 		{
146 			throw new ConstructionException("null returned by new");
147 		}
148 
149 		this(cast(GtkFileFilter*) __p, true);
150 	}
151 
152 	/**
153 	 * Deserialize a file filter from a `GVariant`.
154 	 *
155 	 * The variant must be in the format produced by
156 	 * [method@Gtk.FileFilter.to_gvariant].
157 	 *
158 	 * Params:
159 	 *     variant = an `a{sv}` `GVariant`
160 	 *
161 	 * Returns: a new `GtkFileFilter` object
162 	 *
163 	 * Throws: ConstructionException GTK+ fails to create the object.
164 	 */
165 	public this(Variant variant)
166 	{
167 		auto __p = gtk_file_filter_new_from_gvariant((variant is null) ? null : variant.getVariantStruct());
168 
169 		if(__p is null)
170 		{
171 			throw new ConstructionException("null returned by new_from_gvariant");
172 		}
173 
174 		this(cast(GtkFileFilter*) __p, true);
175 	}
176 
177 	/**
178 	 * Adds a rule allowing a given mime type to @filter.
179 	 *
180 	 * Params:
181 	 *     mimeType = name of a MIME type
182 	 */
183 	public void addMimeType(string mimeType)
184 	{
185 		gtk_file_filter_add_mime_type(gtkFileFilter, Str.toStringz(mimeType));
186 	}
187 
188 	/**
189 	 * Adds a rule allowing a shell style glob to a filter.
190 	 *
191 	 * Params:
192 	 *     pattern = a shell style glob
193 	 */
194 	public void addPattern(string pattern)
195 	{
196 		gtk_file_filter_add_pattern(gtkFileFilter, Str.toStringz(pattern));
197 	}
198 
199 	/**
200 	 * Adds a rule allowing image files in the formats supported
201 	 * by GdkPixbuf.
202 	 *
203 	 * This is equivalent to calling [method@Gtk.FileFilter.add_mime_type]
204 	 * for all the supported mime types.
205 	 */
206 	public void addPixbufFormats()
207 	{
208 		gtk_file_filter_add_pixbuf_formats(gtkFileFilter);
209 	}
210 
211 	/**
212 	 * Gets the attributes that need to be filled in for the `GFileInfo`
213 	 * passed to this filter.
214 	 *
215 	 * This function will not typically be used by applications;
216 	 * it is intended principally for use in the implementation
217 	 * of `GtkFileChooser`.
218 	 *
219 	 * Returns: the attributes
220 	 */
221 	public string[] getAttributes()
222 	{
223 		return Str.toStringArray(gtk_file_filter_get_attributes(gtkFileFilter));
224 	}
225 
226 	/**
227 	 * Gets the human-readable name for the filter.
228 	 *
229 	 * See [method@Gtk.FileFilter.set_name].
230 	 *
231 	 * Returns: The human-readable name of the filter,
232 	 *     or %NULL. This value is owned by GTK and must not
233 	 *     be modified or freed.
234 	 */
235 	public string getName()
236 	{
237 		return Str.toString(gtk_file_filter_get_name(gtkFileFilter));
238 	}
239 
240 	/**
241 	 * Sets a human-readable name of the filter.
242 	 *
243 	 * This is the string that will be displayed in the file chooser
244 	 * if there is a selectable list of filters.
245 	 *
246 	 * Params:
247 	 *     name = the human-readable-name for the filter, or %NULL
248 	 *         to remove any existing name.
249 	 */
250 	public void setName(string name)
251 	{
252 		gtk_file_filter_set_name(gtkFileFilter, Str.toStringz(name));
253 	}
254 
255 	/**
256 	 * Serialize a file filter to an `a{sv}` variant.
257 	 *
258 	 * Returns: a new, floating, `GVariant`
259 	 */
260 	public Variant toGvariant()
261 	{
262 		auto __p = gtk_file_filter_to_gvariant(gtkFileFilter);
263 
264 		if(__p is null)
265 		{
266 			return null;
267 		}
268 
269 		return new Variant(cast(GVariant*) __p);
270 	}
271 }