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.Permission;
26 
27 private import gio.AsyncResultIF;
28 private import gio.Cancellable;
29 private import glib.ErrorG;
30 private import glib.GException;
31 private import gobject.ObjectG;
32 private import gtkc.gio;
33 public  import gtkc.giotypes;
34 
35 
36 /**
37  * A #GPermission represents the status of the caller's permission to
38  * perform a certain action.
39  * 
40  * You can query if the action is currently allowed and if it is
41  * possible to acquire the permission so that the action will be allowed
42  * in the future.
43  * 
44  * There is also an API to actually acquire the permission and one to
45  * release it.
46  * 
47  * As an example, a #GPermission might represent the ability for the
48  * user to write to a #GSettings object.  This #GPermission object could
49  * then be used to decide if it is appropriate to show a "Click here to
50  * unlock" button in a dialog and to provide the mechanism to invoke
51  * when that button is clicked.
52  */
53 public class Permission : ObjectG
54 {
55 	/** the main Gtk struct */
56 	protected GPermission* gPermission;
57 
58 	/** Get the main Gtk struct */
59 	public GPermission* getPermissionStruct()
60 	{
61 		return gPermission;
62 	}
63 
64 	/** the main Gtk struct as a void* */
65 	protected override void* getStruct()
66 	{
67 		return cast(void*)gPermission;
68 	}
69 
70 	protected override void setStruct(GObject* obj)
71 	{
72 		gPermission = cast(GPermission*)obj;
73 		super.setStruct(obj);
74 	}
75 
76 	/**
77 	 * Sets our main struct and passes it to the parent class.
78 	 */
79 	public this (GPermission* gPermission, bool ownedRef = false)
80 	{
81 		this.gPermission = gPermission;
82 		super(cast(GObject*)gPermission, ownedRef);
83 	}
84 
85 
86 	/** */
87 	public static GType getType()
88 	{
89 		return g_permission_get_type();
90 	}
91 
92 	/**
93 	 * Attempts to acquire the permission represented by @permission.
94 	 *
95 	 * The precise method by which this happens depends on the permission
96 	 * and the underlying authentication mechanism.  A simple example is
97 	 * that a dialog may appear asking the user to enter their password.
98 	 *
99 	 * You should check with g_permission_get_can_acquire() before calling
100 	 * this function.
101 	 *
102 	 * If the permission is acquired then %TRUE is returned.  Otherwise,
103 	 * %FALSE is returned and @error is set appropriately.
104 	 *
105 	 * This call is blocking, likely for a very long time (in the case that
106 	 * user interaction is required).  See g_permission_acquire_async() for
107 	 * the non-blocking version.
108 	 *
109 	 * Params:
110 	 *     cancellable = a #GCancellable, or %NULL
111 	 *
112 	 * Return: %TRUE if the permission was successfully acquired
113 	 *
114 	 * Since: 2.26
115 	 *
116 	 * Throws: GException on failure.
117 	 */
118 	public bool acquire(Cancellable cancellable)
119 	{
120 		GError* err = null;
121 		
122 		auto p = g_permission_acquire(gPermission, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
123 		
124 		if (err !is null)
125 		{
126 			throw new GException( new ErrorG(err) );
127 		}
128 		
129 		return p;
130 	}
131 
132 	/**
133 	 * Attempts to acquire the permission represented by @permission.
134 	 *
135 	 * This is the first half of the asynchronous version of
136 	 * g_permission_acquire().
137 	 *
138 	 * Params:
139 	 *     cancellable = a #GCancellable, or %NULL
140 	 *     callback = the #GAsyncReadyCallback to call when done
141 	 *     userData = the user data to pass to @callback
142 	 *
143 	 * Since: 2.26
144 	 */
145 	public void acquireAsync(Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
146 	{
147 		g_permission_acquire_async(gPermission, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
148 	}
149 
150 	/**
151 	 * Collects the result of attempting to acquire the permission
152 	 * represented by @permission.
153 	 *
154 	 * This is the second half of the asynchronous version of
155 	 * g_permission_acquire().
156 	 *
157 	 * Params:
158 	 *     result = the #GAsyncResult given to the #GAsyncReadyCallback
159 	 *
160 	 * Return: %TRUE if the permission was successfully acquired
161 	 *
162 	 * Since: 2.26
163 	 *
164 	 * Throws: GException on failure.
165 	 */
166 	public bool acquireFinish(AsyncResultIF result)
167 	{
168 		GError* err = null;
169 		
170 		auto p = g_permission_acquire_finish(gPermission, (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
171 		
172 		if (err !is null)
173 		{
174 			throw new GException( new ErrorG(err) );
175 		}
176 		
177 		return p;
178 	}
179 
180 	/**
181 	 * Gets the value of the 'allowed' property.  This property is %TRUE if
182 	 * the caller currently has permission to perform the action that
183 	 * @permission represents the permission to perform.
184 	 *
185 	 * Return: the value of the 'allowed' property
186 	 *
187 	 * Since: 2.26
188 	 */
189 	public bool getAllowed()
190 	{
191 		return g_permission_get_allowed(gPermission) != 0;
192 	}
193 
194 	/**
195 	 * Gets the value of the 'can-acquire' property.  This property is %TRUE
196 	 * if it is generally possible to acquire the permission by calling
197 	 * g_permission_acquire().
198 	 *
199 	 * Return: the value of the 'can-acquire' property
200 	 *
201 	 * Since: 2.26
202 	 */
203 	public bool getCanAcquire()
204 	{
205 		return g_permission_get_can_acquire(gPermission) != 0;
206 	}
207 
208 	/**
209 	 * Gets the value of the 'can-release' property.  This property is %TRUE
210 	 * if it is generally possible to release the permission by calling
211 	 * g_permission_release().
212 	 *
213 	 * Return: the value of the 'can-release' property
214 	 *
215 	 * Since: 2.26
216 	 */
217 	public bool getCanRelease()
218 	{
219 		return g_permission_get_can_release(gPermission) != 0;
220 	}
221 
222 	/**
223 	 * This function is called by the #GPermission implementation to update
224 	 * the properties of the permission.  You should never call this
225 	 * function except from a #GPermission implementation.
226 	 *
227 	 * GObject notify signals are generated, as appropriate.
228 	 *
229 	 * Params:
230 	 *     allowed = the new value for the 'allowed' property
231 	 *     canAcquire = the new value for the 'can-acquire' property
232 	 *     canRelease = the new value for the 'can-release' property
233 	 *
234 	 * Since: 2.26
235 	 */
236 	public void implUpdate(bool allowed, bool canAcquire, bool canRelease)
237 	{
238 		g_permission_impl_update(gPermission, allowed, canAcquire, canRelease);
239 	}
240 
241 	/**
242 	 * Attempts to release the permission represented by @permission.
243 	 *
244 	 * The precise method by which this happens depends on the permission
245 	 * and the underlying authentication mechanism.  In most cases the
246 	 * permission will be dropped immediately without further action.
247 	 *
248 	 * You should check with g_permission_get_can_release() before calling
249 	 * this function.
250 	 *
251 	 * If the permission is released then %TRUE is returned.  Otherwise,
252 	 * %FALSE is returned and @error is set appropriately.
253 	 *
254 	 * This call is blocking, likely for a very long time (in the case that
255 	 * user interaction is required).  See g_permission_release_async() for
256 	 * the non-blocking version.
257 	 *
258 	 * Params:
259 	 *     cancellable = a #GCancellable, or %NULL
260 	 *
261 	 * Return: %TRUE if the permission was successfully released
262 	 *
263 	 * Since: 2.26
264 	 *
265 	 * Throws: GException on failure.
266 	 */
267 	public bool release(Cancellable cancellable)
268 	{
269 		GError* err = null;
270 		
271 		auto p = g_permission_release(gPermission, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
272 		
273 		if (err !is null)
274 		{
275 			throw new GException( new ErrorG(err) );
276 		}
277 		
278 		return p;
279 	}
280 
281 	/**
282 	 * Attempts to release the permission represented by @permission.
283 	 *
284 	 * This is the first half of the asynchronous version of
285 	 * g_permission_release().
286 	 *
287 	 * Params:
288 	 *     cancellable = a #GCancellable, or %NULL
289 	 *     callback = the #GAsyncReadyCallback to call when done
290 	 *     userData = the user data to pass to @callback
291 	 *
292 	 * Since: 2.26
293 	 */
294 	public void releaseAsync(Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
295 	{
296 		g_permission_release_async(gPermission, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
297 	}
298 
299 	/**
300 	 * Collects the result of attempting to release the permission
301 	 * represented by @permission.
302 	 *
303 	 * This is the second half of the asynchronous version of
304 	 * g_permission_release().
305 	 *
306 	 * Params:
307 	 *     result = the #GAsyncResult given to the #GAsyncReadyCallback
308 	 *
309 	 * Return: %TRUE if the permission was successfully released
310 	 *
311 	 * Since: 2.26
312 	 *
313 	 * Throws: GException on failure.
314 	 */
315 	public bool releaseFinish(AsyncResultIF result)
316 	{
317 		GError* err = null;
318 		
319 		auto p = g_permission_release_finish(gPermission, (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
320 		
321 		if (err !is null)
322 		{
323 			throw new GException( new ErrorG(err) );
324 		}
325 		
326 		return p;
327 	}
328 }