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.VolumeT; 26 27 public import gio.AsyncResultIF; 28 public import gio.Cancellable; 29 public import gio.Drive; 30 public import gio.DriveIF; 31 public import gio.File; 32 public import gio.FileIF; 33 public import gio.Icon; 34 public import gio.IconIF; 35 public import gio.Mount; 36 public import gio.MountIF; 37 public import gio.MountOperation; 38 public import glib.ErrorG; 39 public import glib.GException; 40 public import glib.Str; 41 public import gobject.ObjectG; 42 public import gobject.Signals; 43 public import gtkc.gio; 44 public import gtkc.giotypes; 45 public import std.algorithm; 46 47 48 /** 49 * The #GVolume interface represents user-visible objects that can be 50 * mounted. Note, when porting from GnomeVFS, #GVolume is the moral 51 * equivalent of #GnomeVFSDrive. 52 * 53 * Mounting a #GVolume instance is an asynchronous operation. For more 54 * information about asynchronous operations, see #GAsyncResult and 55 * #GTask. To mount a #GVolume, first call g_volume_mount() with (at 56 * least) the #GVolume instance, optionally a #GMountOperation object 57 * and a #GAsyncReadyCallback. 58 * 59 * Typically, one will only want to pass %NULL for the 60 * #GMountOperation if automounting all volumes when a desktop session 61 * starts since it's not desirable to put up a lot of dialogs asking 62 * for credentials. 63 * 64 * The callback will be fired when the operation has resolved (either 65 * with success or failure), and a #GAsyncReady structure will be 66 * passed to the callback. That callback should then call 67 * g_volume_mount_finish() with the #GVolume instance and the 68 * #GAsyncReady data to see if the operation was completed 69 * successfully. If an @error is present when g_volume_mount_finish() 70 * is called, then it will be filled with any error information. 71 * 72 * ## Volume Identifiers # {#volume-identifier} 73 * 74 * It is sometimes necessary to directly access the underlying 75 * operating system object behind a volume (e.g. for passing a volume 76 * to an application via the commandline). For this purpose, GIO 77 * allows to obtain an 'identifier' for the volume. There can be 78 * different kinds of identifiers, such as Hal UDIs, filesystem labels, 79 * traditional Unix devices (e.g. `/dev/sda2`), UUIDs. GIO uses predefined 80 * strings as names for the different kinds of identifiers: 81 * #G_VOLUME_IDENTIFIER_KIND_HAL_UDI, #G_VOLUME_IDENTIFIER_KIND_LABEL, etc. 82 * Use g_volume_get_identifier() to obtain an identifier for a volume. 83 * 84 * 85 * Note that #G_VOLUME_IDENTIFIER_KIND_HAL_UDI will only be available 86 * when the gvfs hal volume monitor is in use. Other volume monitors 87 * will generally be able to provide the #G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE 88 * identifier, which can be used to obtain a hal device by means of 89 * libhal_manager_find_device_string_match(). 90 */ 91 public template VolumeT(TStruct) 92 { 93 /** Get the main Gtk struct */ 94 public GVolume* getVolumeStruct(bool transferOwnership = false) 95 { 96 if (transferOwnership) 97 ownedRef = false; 98 return cast(GVolume*)getStruct(); 99 } 100 101 102 /** 103 * Checks if a volume can be ejected. 104 * 105 * Returns: %TRUE if the @volume can be ejected. %FALSE otherwise 106 */ 107 public bool canEject() 108 { 109 return g_volume_can_eject(getVolumeStruct()) != 0; 110 } 111 112 /** 113 * Checks if a volume can be mounted. 114 * 115 * Returns: %TRUE if the @volume can be mounted. %FALSE otherwise 116 */ 117 public bool canMount() 118 { 119 return g_volume_can_mount(getVolumeStruct()) != 0; 120 } 121 122 /** 123 * Ejects a volume. This is an asynchronous operation, and is 124 * finished by calling g_volume_eject_finish() with the @volume 125 * and #GAsyncResult returned in the @callback. 126 * 127 * Deprecated: Use g_volume_eject_with_operation() instead. 128 * 129 * Params: 130 * flags = flags affecting the unmount if required for eject 131 * cancellable = optional #GCancellable object, %NULL to ignore 132 * callback = a #GAsyncReadyCallback, or %NULL 133 * userData = user data that gets passed to @callback 134 */ 135 public void eject(GMountUnmountFlags flags, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 136 { 137 g_volume_eject(getVolumeStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 138 } 139 140 /** 141 * Finishes ejecting a volume. If any errors occurred during the operation, 142 * @error will be set to contain the errors and %FALSE will be returned. 143 * 144 * Deprecated: Use g_volume_eject_with_operation_finish() instead. 145 * 146 * Params: 147 * result = a #GAsyncResult 148 * 149 * Returns: %TRUE, %FALSE if operation failed 150 * 151 * Throws: GException on failure. 152 */ 153 public bool ejectFinish(AsyncResultIF result) 154 { 155 GError* err = null; 156 157 auto p = g_volume_eject_finish(getVolumeStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 158 159 if (err !is null) 160 { 161 throw new GException( new ErrorG(err) ); 162 } 163 164 return p; 165 } 166 167 /** 168 * Ejects a volume. This is an asynchronous operation, and is 169 * finished by calling g_volume_eject_with_operation_finish() with the @volume 170 * and #GAsyncResult data returned in the @callback. 171 * 172 * Params: 173 * flags = flags affecting the unmount if required for eject 174 * mountOperation = a #GMountOperation or %NULL to 175 * avoid user interaction 176 * cancellable = optional #GCancellable object, %NULL to ignore 177 * callback = a #GAsyncReadyCallback, or %NULL 178 * userData = user data passed to @callback 179 * 180 * Since: 2.22 181 */ 182 public void ejectWithOperation(GMountUnmountFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 183 { 184 g_volume_eject_with_operation(getVolumeStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 185 } 186 187 /** 188 * Finishes ejecting a volume. If any errors occurred during the operation, 189 * @error will be set to contain the errors and %FALSE will be returned. 190 * 191 * Params: 192 * result = a #GAsyncResult 193 * 194 * Returns: %TRUE if the volume was successfully ejected. %FALSE otherwise 195 * 196 * Since: 2.22 197 * 198 * Throws: GException on failure. 199 */ 200 public bool ejectWithOperationFinish(AsyncResultIF result) 201 { 202 GError* err = null; 203 204 auto p = g_volume_eject_with_operation_finish(getVolumeStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 205 206 if (err !is null) 207 { 208 throw new GException( new ErrorG(err) ); 209 } 210 211 return p; 212 } 213 214 /** 215 * Gets the kinds of [identifiers][volume-identifier] that @volume has. 216 * Use g_volume_get_identifier() to obtain the identifiers themselves. 217 * 218 * Returns: a %NULL-terminated array 219 * of strings containing kinds of identifiers. Use g_strfreev() to free. 220 */ 221 public string[] enumerateIdentifiers() 222 { 223 auto retStr = g_volume_enumerate_identifiers(getVolumeStruct()); 224 225 scope(exit) Str.freeStringArray(retStr); 226 return Str.toStringArray(retStr); 227 } 228 229 /** 230 * Gets the activation root for a #GVolume if it is known ahead of 231 * mount time. Returns %NULL otherwise. If not %NULL and if @volume 232 * is mounted, then the result of g_mount_get_root() on the 233 * #GMount object obtained from g_volume_get_mount() will always 234 * either be equal or a prefix of what this function returns. In 235 * other words, in code 236 * 237 * |[<!-- language="C" --> 238 * GMount *mount; 239 * GFile *mount_root 240 * GFile *volume_activation_root; 241 * 242 * mount = g_volume_get_mount (volume); // mounted, so never NULL 243 * mount_root = g_mount_get_root (mount); 244 * volume_activation_root = g_volume_get_activation_root (volume); // assume not NULL 245 * ]| 246 * then the expression 247 * |[<!-- language="C" --> 248 * (g_file_has_prefix (volume_activation_root, mount_root) || 249 * g_file_equal (volume_activation_root, mount_root)) 250 * ]| 251 * will always be %TRUE. 252 * 253 * Activation roots are typically used in #GVolumeMonitor 254 * implementations to find the underlying mount to shadow, see 255 * g_mount_is_shadowed() for more details. 256 * 257 * Returns: the activation root of @volume 258 * or %NULL. Use g_object_unref() to free. 259 * 260 * Since: 2.18 261 */ 262 public FileIF getActivationRoot() 263 { 264 auto p = g_volume_get_activation_root(getVolumeStruct()); 265 266 if(p is null) 267 { 268 return null; 269 } 270 271 return ObjectG.getDObject!(File, FileIF)(cast(GFile*) p, true); 272 } 273 274 /** 275 * Gets the drive for the @volume. 276 * 277 * Returns: a #GDrive or %NULL if @volume is not 278 * associated with a drive. The returned object should be unreffed 279 * with g_object_unref() when no longer needed. 280 */ 281 public DriveIF getDrive() 282 { 283 auto p = g_volume_get_drive(getVolumeStruct()); 284 285 if(p is null) 286 { 287 return null; 288 } 289 290 return ObjectG.getDObject!(Drive, DriveIF)(cast(GDrive*) p, true); 291 } 292 293 /** 294 * Gets the icon for @volume. 295 * 296 * Returns: a #GIcon. 297 * The returned object should be unreffed with g_object_unref() 298 * when no longer needed. 299 */ 300 public IconIF getIcon() 301 { 302 auto p = g_volume_get_icon(getVolumeStruct()); 303 304 if(p is null) 305 { 306 return null; 307 } 308 309 return ObjectG.getDObject!(Icon, IconIF)(cast(GIcon*) p, true); 310 } 311 312 /** 313 * Gets the identifier of the given kind for @volume. 314 * See the [introduction][volume-identifier] for more 315 * information about volume identifiers. 316 * 317 * Params: 318 * kind = the kind of identifier to return 319 * 320 * Returns: a newly allocated string containing the 321 * requested identfier, or %NULL if the #GVolume 322 * doesn't have this kind of identifier 323 */ 324 public string getIdentifier(string kind) 325 { 326 auto retStr = g_volume_get_identifier(getVolumeStruct(), Str.toStringz(kind)); 327 328 scope(exit) Str.freeString(retStr); 329 return Str.toString(retStr); 330 } 331 332 /** 333 * Gets the mount for the @volume. 334 * 335 * Returns: a #GMount or %NULL if @volume isn't mounted. 336 * The returned object should be unreffed with g_object_unref() 337 * when no longer needed. 338 */ 339 public MountIF getMount() 340 { 341 auto p = g_volume_get_mount(getVolumeStruct()); 342 343 if(p is null) 344 { 345 return null; 346 } 347 348 return ObjectG.getDObject!(Mount, MountIF)(cast(GMount*) p, true); 349 } 350 351 /** 352 * Gets the name of @volume. 353 * 354 * Returns: the name for the given @volume. The returned string should 355 * be freed with g_free() when no longer needed. 356 */ 357 public string getName() 358 { 359 auto retStr = g_volume_get_name(getVolumeStruct()); 360 361 scope(exit) Str.freeString(retStr); 362 return Str.toString(retStr); 363 } 364 365 /** 366 * Gets the sort key for @volume, if any. 367 * 368 * Returns: Sorting key for @volume or %NULL if no such key is available 369 * 370 * Since: 2.32 371 */ 372 public string getSortKey() 373 { 374 return Str.toString(g_volume_get_sort_key(getVolumeStruct())); 375 } 376 377 /** 378 * Gets the symbolic icon for @volume. 379 * 380 * Returns: a #GIcon. 381 * The returned object should be unreffed with g_object_unref() 382 * when no longer needed. 383 * 384 * Since: 2.34 385 */ 386 public IconIF getSymbolicIcon() 387 { 388 auto p = g_volume_get_symbolic_icon(getVolumeStruct()); 389 390 if(p is null) 391 { 392 return null; 393 } 394 395 return ObjectG.getDObject!(Icon, IconIF)(cast(GIcon*) p, true); 396 } 397 398 /** 399 * Gets the UUID for the @volume. The reference is typically based on 400 * the file system UUID for the volume in question and should be 401 * considered an opaque string. Returns %NULL if there is no UUID 402 * available. 403 * 404 * Returns: the UUID for @volume or %NULL if no UUID can be computed. 405 * The returned string should be freed with g_free() 406 * when no longer needed. 407 */ 408 public string getUuid() 409 { 410 auto retStr = g_volume_get_uuid(getVolumeStruct()); 411 412 scope(exit) Str.freeString(retStr); 413 return Str.toString(retStr); 414 } 415 416 /** 417 * Mounts a volume. This is an asynchronous operation, and is 418 * finished by calling g_volume_mount_finish() with the @volume 419 * and #GAsyncResult returned in the @callback. 420 * 421 * Params: 422 * flags = flags affecting the operation 423 * mountOperation = a #GMountOperation or %NULL to avoid user interaction 424 * cancellable = optional #GCancellable object, %NULL to ignore 425 * callback = a #GAsyncReadyCallback, or %NULL 426 * userData = user data that gets passed to @callback 427 */ 428 public void mount(GMountMountFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 429 { 430 g_volume_mount(getVolumeStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 431 } 432 433 /** 434 * Finishes mounting a volume. If any errors occurred during the operation, 435 * @error will be set to contain the errors and %FALSE will be returned. 436 * 437 * If the mount operation succeeded, g_volume_get_mount() on @volume 438 * is guaranteed to return the mount right after calling this 439 * function; there's no need to listen for the 'mount-added' signal on 440 * #GVolumeMonitor. 441 * 442 * Params: 443 * result = a #GAsyncResult 444 * 445 * Returns: %TRUE, %FALSE if operation failed 446 * 447 * Throws: GException on failure. 448 */ 449 public bool mountFinish(AsyncResultIF result) 450 { 451 GError* err = null; 452 453 auto p = g_volume_mount_finish(getVolumeStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 454 455 if (err !is null) 456 { 457 throw new GException( new ErrorG(err) ); 458 } 459 460 return p; 461 } 462 463 /** 464 * Returns whether the volume should be automatically mounted. 465 * 466 * Returns: %TRUE if the volume should be automatically mounted 467 */ 468 public bool shouldAutomount() 469 { 470 return g_volume_should_automount(getVolumeStruct()) != 0; 471 } 472 473 protected class OnChangedDelegateWrapper 474 { 475 static OnChangedDelegateWrapper[] listeners; 476 void delegate(VolumeIF) dlg; 477 gulong handlerId; 478 479 this(void delegate(VolumeIF) dlg) 480 { 481 this.dlg = dlg; 482 this.listeners ~= this; 483 } 484 485 void remove(OnChangedDelegateWrapper source) 486 { 487 foreach(index, wrapper; listeners) 488 { 489 if (wrapper.handlerId == source.handlerId) 490 { 491 listeners[index] = null; 492 listeners = std.algorithm.remove(listeners, index); 493 break; 494 } 495 } 496 } 497 } 498 499 /** 500 * Emitted when the volume has been changed. 501 */ 502 gulong addOnChanged(void delegate(VolumeIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 503 { 504 auto wrapper = new OnChangedDelegateWrapper(dlg); 505 wrapper.handlerId = Signals.connectData( 506 this, 507 "changed", 508 cast(GCallback)&callBackChanged, 509 cast(void*)wrapper, 510 cast(GClosureNotify)&callBackChangedDestroy, 511 connectFlags); 512 return wrapper.handlerId; 513 } 514 515 extern(C) static void callBackChanged(GVolume* volumeStruct, OnChangedDelegateWrapper wrapper) 516 { 517 wrapper.dlg(wrapper.outer); 518 } 519 520 extern(C) static void callBackChangedDestroy(OnChangedDelegateWrapper wrapper, GClosure* closure) 521 { 522 wrapper.remove(wrapper); 523 } 524 525 protected class OnRemovedDelegateWrapper 526 { 527 static OnRemovedDelegateWrapper[] listeners; 528 void delegate(VolumeIF) dlg; 529 gulong handlerId; 530 531 this(void delegate(VolumeIF) dlg) 532 { 533 this.dlg = dlg; 534 this.listeners ~= this; 535 } 536 537 void remove(OnRemovedDelegateWrapper source) 538 { 539 foreach(index, wrapper; listeners) 540 { 541 if (wrapper.handlerId == source.handlerId) 542 { 543 listeners[index] = null; 544 listeners = std.algorithm.remove(listeners, index); 545 break; 546 } 547 } 548 } 549 } 550 551 /** 552 * This signal is emitted when the #GVolume have been removed. If 553 * the recipient is holding references to the object they should 554 * release them so the object can be finalized. 555 */ 556 gulong addOnRemoved(void delegate(VolumeIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 557 { 558 auto wrapper = new OnRemovedDelegateWrapper(dlg); 559 wrapper.handlerId = Signals.connectData( 560 this, 561 "removed", 562 cast(GCallback)&callBackRemoved, 563 cast(void*)wrapper, 564 cast(GClosureNotify)&callBackRemovedDestroy, 565 connectFlags); 566 return wrapper.handlerId; 567 } 568 569 extern(C) static void callBackRemoved(GVolume* volumeStruct, OnRemovedDelegateWrapper wrapper) 570 { 571 wrapper.dlg(wrapper.outer); 572 } 573 574 extern(C) static void callBackRemovedDestroy(OnRemovedDelegateWrapper wrapper, GClosure* closure) 575 { 576 wrapper.remove(wrapper); 577 } 578 }