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