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