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 gio.FileAttributeMatcher;
26 
27 private import gio.c.functions;
28 public  import gio.c.types;
29 private import glib.ConstructionException;
30 private import glib.Str;
31 private import gobject.ObjectG;
32 public  import gtkc.giotypes;
33 private import gtkd.Loader;
34 
35 
36 /**
37  * Determines if a string matches a file attribute.
38  */
39 public class FileAttributeMatcher
40 {
41 	/** the main Gtk struct */
42 	protected GFileAttributeMatcher* gFileAttributeMatcher;
43 	protected bool ownedRef;
44 
45 	/** Get the main Gtk struct */
46 	public GFileAttributeMatcher* getFileAttributeMatcherStruct(bool transferOwnership = false)
47 	{
48 		if (transferOwnership)
49 			ownedRef = false;
50 		return gFileAttributeMatcher;
51 	}
52 
53 	/** the main Gtk struct as a void* */
54 	protected void* getStruct()
55 	{
56 		return cast(void*)gFileAttributeMatcher;
57 	}
58 
59 	/**
60 	 * Sets our main struct and passes it to the parent class.
61 	 */
62 	public this (GFileAttributeMatcher* gFileAttributeMatcher, bool ownedRef = false)
63 	{
64 		this.gFileAttributeMatcher = gFileAttributeMatcher;
65 		this.ownedRef = ownedRef;
66 	}
67 
68 	~this ()
69 	{
70 		if ( Linker.isLoaded(LIBRARY_GIO) && ownedRef )
71 			g_file_attribute_matcher_unref(gFileAttributeMatcher);
72 	}
73 
74 
75 	/** */
76 	public static GType getType()
77 	{
78 		return g_file_attribute_matcher_get_type();
79 	}
80 
81 	/**
82 	 * Creates a new file attribute matcher, which matches attributes
83 	 * against a given string. #GFileAttributeMatchers are reference
84 	 * counted structures, and are created with a reference count of 1. If
85 	 * the number of references falls to 0, the #GFileAttributeMatcher is
86 	 * automatically destroyed.
87 	 *
88 	 * The @attribute string should be formatted with specific keys separated
89 	 * from namespaces with a double colon. Several "namespace::key" strings may be
90 	 * concatenated with a single comma (e.g. "standard::type,standard::is-hidden").
91 	 * The wildcard "*" may be used to match all keys and namespaces, or
92 	 * "namespace::*" will match all keys in a given namespace.
93 	 *
94 	 * ## Examples of file attribute matcher strings and results
95 	 *
96 	 * - `"*"`: matches all attributes.
97 	 * - `"standard::is-hidden"`: matches only the key is-hidden in the
98 	 * standard namespace.
99 	 * - `"standard::type,unix::*"`: matches the type key in the standard
100 	 * namespace and all keys in the unix namespace.
101 	 *
102 	 * Params:
103 	 *     attributes = an attribute string to match.
104 	 *
105 	 * Returns: a #GFileAttributeMatcher
106 	 *
107 	 * Throws: ConstructionException GTK+ fails to create the object.
108 	 */
109 	public this(string attributes)
110 	{
111 		auto p = g_file_attribute_matcher_new(Str.toStringz(attributes));
112 
113 		if(p is null)
114 		{
115 			throw new ConstructionException("null returned by new");
116 		}
117 
118 		this(cast(GFileAttributeMatcher*) p);
119 	}
120 
121 	/**
122 	 * Checks if the matcher will match all of the keys in a given namespace.
123 	 * This will always return %TRUE if a wildcard character is in use (e.g. if
124 	 * matcher was created with "standard::*" and @ns is "standard", or if matcher was created
125 	 * using "*" and namespace is anything.)
126 	 *
127 	 * TODO: this is awkwardly worded.
128 	 *
129 	 * Params:
130 	 *     ns = a string containing a file attribute namespace.
131 	 *
132 	 * Returns: %TRUE if the matcher matches all of the entries
133 	 *     in the given @ns, %FALSE otherwise.
134 	 */
135 	public bool enumerateNamespace(string ns)
136 	{
137 		return g_file_attribute_matcher_enumerate_namespace(gFileAttributeMatcher, Str.toStringz(ns)) != 0;
138 	}
139 
140 	/**
141 	 * Gets the next matched attribute from a #GFileAttributeMatcher.
142 	 *
143 	 * Returns: a string containing the next attribute or %NULL if
144 	 *     no more attribute exist.
145 	 */
146 	public string enumerateNext()
147 	{
148 		return Str.toString(g_file_attribute_matcher_enumerate_next(gFileAttributeMatcher));
149 	}
150 
151 	/**
152 	 * Checks if an attribute will be matched by an attribute matcher. If
153 	 * the matcher was created with the "*" matching string, this function
154 	 * will always return %TRUE.
155 	 *
156 	 * Params:
157 	 *     attribute = a file attribute key.
158 	 *
159 	 * Returns: %TRUE if @attribute matches @matcher. %FALSE otherwise.
160 	 */
161 	public bool matches(string attribute)
162 	{
163 		return g_file_attribute_matcher_matches(gFileAttributeMatcher, Str.toStringz(attribute)) != 0;
164 	}
165 
166 	/**
167 	 * Checks if a attribute matcher only matches a given attribute. Always
168 	 * returns %FALSE if "*" was used when creating the matcher.
169 	 *
170 	 * Params:
171 	 *     attribute = a file attribute key.
172 	 *
173 	 * Returns: %TRUE if the matcher only matches @attribute. %FALSE otherwise.
174 	 */
175 	public bool matchesOnly(string attribute)
176 	{
177 		return g_file_attribute_matcher_matches_only(gFileAttributeMatcher, Str.toStringz(attribute)) != 0;
178 	}
179 
180 	alias doref = ref_;
181 	/**
182 	 * References a file attribute matcher.
183 	 *
184 	 * Returns: a #GFileAttributeMatcher.
185 	 */
186 	public FileAttributeMatcher ref_()
187 	{
188 		auto p = g_file_attribute_matcher_ref(gFileAttributeMatcher);
189 
190 		if(p is null)
191 		{
192 			return null;
193 		}
194 
195 		return ObjectG.getDObject!(FileAttributeMatcher)(cast(GFileAttributeMatcher*) p, true);
196 	}
197 
198 	/**
199 	 * Subtracts all attributes of @subtract from @matcher and returns
200 	 * a matcher that supports those attributes.
201 	 *
202 	 * Note that currently it is not possible to remove a single
203 	 * attribute when the @matcher matches the whole namespace - or remove
204 	 * a namespace or attribute when the matcher matches everything. This
205 	 * is a limitation of the current implementation, but may be fixed
206 	 * in the future.
207 	 *
208 	 * Params:
209 	 *     subtract = The matcher to subtract
210 	 *
211 	 * Returns: A file attribute matcher matching all attributes of
212 	 *     @matcher that are not matched by @subtract
213 	 */
214 	public FileAttributeMatcher subtract(FileAttributeMatcher subtract)
215 	{
216 		auto p = g_file_attribute_matcher_subtract(gFileAttributeMatcher, (subtract is null) ? null : subtract.getFileAttributeMatcherStruct());
217 
218 		if(p is null)
219 		{
220 			return null;
221 		}
222 
223 		return ObjectG.getDObject!(FileAttributeMatcher)(cast(GFileAttributeMatcher*) p, true);
224 	}
225 
226 	/**
227 	 * Prints what the matcher is matching against. The format will be
228 	 * equal to the format passed to g_file_attribute_matcher_new().
229 	 * The output however, might not be identical, as the matcher may
230 	 * decide to use a different order or omit needless parts.
231 	 *
232 	 * Returns: a string describing the attributes the matcher matches
233 	 *     against or %NULL if @matcher was %NULL.
234 	 *
235 	 * Since: 2.32
236 	 */
237 	public override string toString()
238 	{
239 		auto retStr = g_file_attribute_matcher_to_string(gFileAttributeMatcher);
240 
241 		scope(exit) Str.freeString(retStr);
242 		return Str.toString(retStr);
243 	}
244 
245 	/**
246 	 * Unreferences @matcher. If the reference count falls below 1,
247 	 * the @matcher is automatically freed.
248 	 */
249 	public void unref()
250 	{
251 		g_file_attribute_matcher_unref(gFileAttributeMatcher);
252 	}
253 }