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