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