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