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 	/**
181 	 * References a file attribute matcher.
182 	 *
183 	 * Returns: a #GFileAttributeMatcher.
184 	 */
185 	public FileAttributeMatcher doref()
186 	{
187 		auto p = g_file_attribute_matcher_ref(gFileAttributeMatcher);
188 
189 		if(p is null)
190 		{
191 			return null;
192 		}
193 
194 		return ObjectG.getDObject!(FileAttributeMatcher)(cast(GFileAttributeMatcher*) p, true);
195 	}
196 
197 	/**
198 	 * Subtracts all attributes of @subtract from @matcher and returns
199 	 * a matcher that supports those attributes.
200 	 *
201 	 * Note that currently it is not possible to remove a single
202 	 * attribute when the @matcher matches the whole namespace - or remove
203 	 * a namespace or attribute when the matcher matches everything. This
204 	 * is a limitation of the current implementation, but may be fixed
205 	 * in the future.
206 	 *
207 	 * Params:
208 	 *     subtract = The matcher to subtract
209 	 *
210 	 * Returns: A file attribute matcher matching all attributes of
211 	 *     @matcher that are not matched by @subtract
212 	 */
213 	public FileAttributeMatcher subtract(FileAttributeMatcher subtract)
214 	{
215 		auto p = g_file_attribute_matcher_subtract(gFileAttributeMatcher, (subtract is null) ? null : subtract.getFileAttributeMatcherStruct());
216 
217 		if(p is null)
218 		{
219 			return null;
220 		}
221 
222 		return ObjectG.getDObject!(FileAttributeMatcher)(cast(GFileAttributeMatcher*) p, true);
223 	}
224 
225 	/**
226 	 * Prints what the matcher is matching against. The format will be
227 	 * equal to the format passed to g_file_attribute_matcher_new().
228 	 * The output however, might not be identical, as the matcher may
229 	 * decide to use a different order or omit needless parts.
230 	 *
231 	 * Returns: a string describing the attributes the matcher matches
232 	 *     against or %NULL if @matcher was %NULL.
233 	 *
234 	 * Since: 2.32
235 	 */
236 	public override string toString()
237 	{
238 		auto retStr = g_file_attribute_matcher_to_string(gFileAttributeMatcher);
239 
240 		scope(exit) Str.freeString(retStr);
241 		return Str.toString(retStr);
242 	}
243 
244 	/**
245 	 * Unreferences @matcher. If the reference count falls below 1,
246 	 * the @matcher is automatically freed.
247 	 */
248 	public void unref()
249 	{
250 		g_file_attribute_matcher_unref(gFileAttributeMatcher);
251 	}
252 }