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