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