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.MountT; 26 27 public import gio.AsyncResultIF; 28 public import gio.Cancellable; 29 public import gio.DriveIF; 30 public import gio.FileIF; 31 public import gio.IconIF; 32 public import gio.MountOperation; 33 public import gio.VolumeIF; 34 public import gio.c.functions; 35 public import gio.c.types; 36 public import glib.ErrorG; 37 public import glib.GException; 38 public import glib.Str; 39 public import gobject.ObjectG; 40 public import gobject.Signals; 41 public import gtkc.giotypes; 42 public import std.algorithm; 43 44 45 /** 46 * The #GMount interface represents user-visible mounts. Note, when 47 * porting from GnomeVFS, #GMount is the moral equivalent of #GnomeVFSVolume. 48 * 49 * #GMount is a "mounted" filesystem that you can access. Mounted is in 50 * quotes because it's not the same as a unix mount, it might be a gvfs 51 * mount, but you can still access the files on it if you use GIO. Might or 52 * might not be related to a volume object. 53 * 54 * Unmounting a #GMount instance is an asynchronous operation. For 55 * more information about asynchronous operations, see #GAsyncResult 56 * and #GTask. To unmount a #GMount instance, first call 57 * g_mount_unmount_with_operation() with (at least) the #GMount instance and a 58 * #GAsyncReadyCallback. The callback will be fired when the 59 * operation has resolved (either with success or failure), and a 60 * #GAsyncResult structure will be passed to the callback. That 61 * callback should then call g_mount_unmount_with_operation_finish() with the #GMount 62 * and the #GAsyncResult data to see if the operation was completed 63 * successfully. If an @error is present when g_mount_unmount_with_operation_finish() 64 * is called, then it will be filled with any error information. 65 */ 66 public template MountT(TStruct) 67 { 68 /** Get the main Gtk struct */ 69 public GMount* getMountStruct(bool transferOwnership = false) 70 { 71 if (transferOwnership) 72 ownedRef = false; 73 return cast(GMount*)getStruct(); 74 } 75 76 77 /** 78 * Checks if @mount can be ejected. 79 * 80 * Returns: %TRUE if the @mount can be ejected. 81 */ 82 public bool canEject() 83 { 84 return g_mount_can_eject(getMountStruct()) != 0; 85 } 86 87 /** 88 * Checks if @mount can be unmounted. 89 * 90 * Returns: %TRUE if the @mount can be unmounted. 91 */ 92 public bool canUnmount() 93 { 94 return g_mount_can_unmount(getMountStruct()) != 0; 95 } 96 97 /** 98 * Ejects a mount. This is an asynchronous operation, and is 99 * finished by calling g_mount_eject_finish() with the @mount 100 * and #GAsyncResult data returned in the @callback. 101 * 102 * Deprecated: Use g_mount_eject_with_operation() instead. 103 * 104 * Params: 105 * flags = flags affecting the unmount if required for eject 106 * cancellable = optional #GCancellable object, %NULL to ignore. 107 * callback = a #GAsyncReadyCallback, or %NULL. 108 * userData = user data passed to @callback. 109 */ 110 public void eject(GMountUnmountFlags flags, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 111 { 112 g_mount_eject(getMountStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 113 } 114 115 /** 116 * Finishes ejecting a mount. If any errors occurred during the operation, 117 * @error will be set to contain the errors and %FALSE will be returned. 118 * 119 * Deprecated: Use g_mount_eject_with_operation_finish() instead. 120 * 121 * Params: 122 * result = a #GAsyncResult. 123 * 124 * Returns: %TRUE if the mount was successfully ejected. %FALSE otherwise. 125 * 126 * Throws: GException on failure. 127 */ 128 public bool ejectFinish(AsyncResultIF result) 129 { 130 GError* err = null; 131 132 auto p = g_mount_eject_finish(getMountStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 133 134 if (err !is null) 135 { 136 throw new GException( new ErrorG(err) ); 137 } 138 139 return p; 140 } 141 142 /** 143 * Ejects a mount. This is an asynchronous operation, and is 144 * finished by calling g_mount_eject_with_operation_finish() with the @mount 145 * and #GAsyncResult data returned in the @callback. 146 * 147 * Params: 148 * flags = flags affecting the unmount if required for eject 149 * mountOperation = a #GMountOperation or %NULL to avoid 150 * user interaction. 151 * cancellable = optional #GCancellable object, %NULL to ignore. 152 * callback = a #GAsyncReadyCallback, or %NULL. 153 * userData = user data passed to @callback. 154 * 155 * Since: 2.22 156 */ 157 public void ejectWithOperation(GMountUnmountFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 158 { 159 g_mount_eject_with_operation(getMountStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 160 } 161 162 /** 163 * Finishes ejecting a mount. If any errors occurred during the operation, 164 * @error will be set to contain the errors and %FALSE will be returned. 165 * 166 * Params: 167 * result = a #GAsyncResult. 168 * 169 * Returns: %TRUE if the mount was successfully ejected. %FALSE otherwise. 170 * 171 * Since: 2.22 172 * 173 * Throws: GException on failure. 174 */ 175 public bool ejectWithOperationFinish(AsyncResultIF result) 176 { 177 GError* err = null; 178 179 auto p = g_mount_eject_with_operation_finish(getMountStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 180 181 if (err !is null) 182 { 183 throw new GException( new ErrorG(err) ); 184 } 185 186 return p; 187 } 188 189 /** 190 * Gets the default location of @mount. The default location of the given 191 * @mount is a path that reflects the main entry point for the user (e.g. 192 * the home directory, or the root of the volume). 193 * 194 * Returns: a #GFile. 195 * The returned object should be unreffed with 196 * g_object_unref() when no longer needed. 197 */ 198 public FileIF getDefaultLocation() 199 { 200 auto p = g_mount_get_default_location(getMountStruct()); 201 202 if(p is null) 203 { 204 return null; 205 } 206 207 return ObjectG.getDObject!(FileIF)(cast(GFile*) p, true); 208 } 209 210 /** 211 * Gets the drive for the @mount. 212 * 213 * This is a convenience method for getting the #GVolume and then 214 * using that object to get the #GDrive. 215 * 216 * Returns: a #GDrive or %NULL if @mount is not associated with a volume or a drive. 217 * The returned object should be unreffed with 218 * g_object_unref() when no longer needed. 219 */ 220 public DriveIF getDrive() 221 { 222 auto p = g_mount_get_drive(getMountStruct()); 223 224 if(p is null) 225 { 226 return null; 227 } 228 229 return ObjectG.getDObject!(DriveIF)(cast(GDrive*) p, true); 230 } 231 232 /** 233 * Gets the icon for @mount. 234 * 235 * Returns: a #GIcon. 236 * The returned object should be unreffed with 237 * g_object_unref() when no longer needed. 238 */ 239 public IconIF getIcon() 240 { 241 auto p = g_mount_get_icon(getMountStruct()); 242 243 if(p is null) 244 { 245 return null; 246 } 247 248 return ObjectG.getDObject!(IconIF)(cast(GIcon*) p, true); 249 } 250 251 /** 252 * Gets the name of @mount. 253 * 254 * Returns: the name for the given @mount. 255 * The returned string should be freed with g_free() 256 * when no longer needed. 257 */ 258 public string getName() 259 { 260 auto retStr = g_mount_get_name(getMountStruct()); 261 262 scope(exit) Str.freeString(retStr); 263 return Str.toString(retStr); 264 } 265 266 /** 267 * Gets the root directory on @mount. 268 * 269 * Returns: a #GFile. 270 * The returned object should be unreffed with 271 * g_object_unref() when no longer needed. 272 */ 273 public FileIF getRoot() 274 { 275 auto p = g_mount_get_root(getMountStruct()); 276 277 if(p is null) 278 { 279 return null; 280 } 281 282 return ObjectG.getDObject!(FileIF)(cast(GFile*) p, true); 283 } 284 285 /** 286 * Gets the sort key for @mount, if any. 287 * 288 * Returns: Sorting key for @mount or %NULL if no such key is available. 289 * 290 * Since: 2.32 291 */ 292 public string getSortKey() 293 { 294 return Str.toString(g_mount_get_sort_key(getMountStruct())); 295 } 296 297 /** 298 * Gets the symbolic icon for @mount. 299 * 300 * Returns: a #GIcon. 301 * The returned object should be unreffed with 302 * g_object_unref() when no longer needed. 303 * 304 * Since: 2.34 305 */ 306 public IconIF getSymbolicIcon() 307 { 308 auto p = g_mount_get_symbolic_icon(getMountStruct()); 309 310 if(p is null) 311 { 312 return null; 313 } 314 315 return ObjectG.getDObject!(IconIF)(cast(GIcon*) p, true); 316 } 317 318 /** 319 * Gets the UUID for the @mount. The reference is typically based on 320 * the file system UUID for the mount in question and should be 321 * considered an opaque string. Returns %NULL if there is no UUID 322 * available. 323 * 324 * Returns: the UUID for @mount or %NULL if no UUID can be computed. 325 * The returned string should be freed with g_free() 326 * when no longer needed. 327 */ 328 public string getUuid() 329 { 330 auto retStr = g_mount_get_uuid(getMountStruct()); 331 332 scope(exit) Str.freeString(retStr); 333 return Str.toString(retStr); 334 } 335 336 /** 337 * Gets the volume for the @mount. 338 * 339 * Returns: a #GVolume or %NULL if @mount is not associated with a volume. 340 * The returned object should be unreffed with 341 * g_object_unref() when no longer needed. 342 */ 343 public VolumeIF getVolume() 344 { 345 auto p = g_mount_get_volume(getMountStruct()); 346 347 if(p is null) 348 { 349 return null; 350 } 351 352 return ObjectG.getDObject!(VolumeIF)(cast(GVolume*) p, true); 353 } 354 355 /** 356 * Tries to guess the type of content stored on @mount. Returns one or 357 * more textual identifiers of well-known content types (typically 358 * prefixed with "x-content/"), e.g. x-content/image-dcf for camera 359 * memory cards. See the 360 * [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec) 361 * specification for more on x-content types. 362 * 363 * This is an asynchronous operation (see 364 * g_mount_guess_content_type_sync() for the synchronous version), and 365 * is finished by calling g_mount_guess_content_type_finish() with the 366 * @mount and #GAsyncResult data returned in the @callback. 367 * 368 * Params: 369 * forceRescan = Whether to force a rescan of the content. 370 * Otherwise a cached result will be used if available 371 * cancellable = optional #GCancellable object, %NULL to ignore 372 * callback = a #GAsyncReadyCallback 373 * userData = user data passed to @callback 374 * 375 * Since: 2.18 376 */ 377 public void guessContentType(bool forceRescan, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 378 { 379 g_mount_guess_content_type(getMountStruct(), forceRescan, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 380 } 381 382 /** 383 * Finishes guessing content types of @mount. If any errors occurred 384 * during the operation, @error will be set to contain the errors and 385 * %FALSE will be returned. In particular, you may get an 386 * %G_IO_ERROR_NOT_SUPPORTED if the mount does not support content 387 * guessing. 388 * 389 * Params: 390 * result = a #GAsyncResult 391 * 392 * Returns: a %NULL-terminated array of content types or %NULL on error. 393 * Caller should free this array with g_strfreev() when done with it. 394 * 395 * Since: 2.18 396 * 397 * Throws: GException on failure. 398 */ 399 public string[] guessContentTypeFinish(AsyncResultIF result) 400 { 401 GError* err = null; 402 403 auto retStr = g_mount_guess_content_type_finish(getMountStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err); 404 405 if (err !is null) 406 { 407 throw new GException( new ErrorG(err) ); 408 } 409 410 scope(exit) Str.freeStringArray(retStr); 411 return Str.toStringArray(retStr); 412 } 413 414 /** 415 * Tries to guess the type of content stored on @mount. Returns one or 416 * more textual identifiers of well-known content types (typically 417 * prefixed with "x-content/"), e.g. x-content/image-dcf for camera 418 * memory cards. See the 419 * [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec) 420 * specification for more on x-content types. 421 * 422 * This is an synchronous operation and as such may block doing IO; 423 * see g_mount_guess_content_type() for the asynchronous version. 424 * 425 * Params: 426 * forceRescan = Whether to force a rescan of the content. 427 * Otherwise a cached result will be used if available 428 * cancellable = optional #GCancellable object, %NULL to ignore 429 * 430 * Returns: a %NULL-terminated array of content types or %NULL on error. 431 * Caller should free this array with g_strfreev() when done with it. 432 * 433 * Since: 2.18 434 * 435 * Throws: GException on failure. 436 */ 437 public string[] guessContentTypeSync(bool forceRescan, Cancellable cancellable) 438 { 439 GError* err = null; 440 441 auto retStr = g_mount_guess_content_type_sync(getMountStruct(), forceRescan, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 442 443 if (err !is null) 444 { 445 throw new GException( new ErrorG(err) ); 446 } 447 448 scope(exit) Str.freeStringArray(retStr); 449 return Str.toStringArray(retStr); 450 } 451 452 /** 453 * Determines if @mount is shadowed. Applications or libraries should 454 * avoid displaying @mount in the user interface if it is shadowed. 455 * 456 * A mount is said to be shadowed if there exists one or more user 457 * visible objects (currently #GMount objects) with a root that is 458 * inside the root of @mount. 459 * 460 * One application of shadow mounts is when exposing a single file 461 * system that is used to address several logical volumes. In this 462 * situation, a #GVolumeMonitor implementation would create two 463 * #GVolume objects (for example, one for the camera functionality of 464 * the device and one for a SD card reader on the device) with 465 * activation URIs `gphoto2://[usb:001,002]/store1/` 466 * and `gphoto2://[usb:001,002]/store2/`. When the 467 * underlying mount (with root 468 * `gphoto2://[usb:001,002]/`) is mounted, said 469 * #GVolumeMonitor implementation would create two #GMount objects 470 * (each with their root matching the corresponding volume activation 471 * root) that would shadow the original mount. 472 * 473 * The proxy monitor in GVfs 2.26 and later, automatically creates and 474 * manage shadow mounts (and shadows the underlying mount) if the 475 * activation root on a #GVolume is set. 476 * 477 * Returns: %TRUE if @mount is shadowed. 478 * 479 * Since: 2.20 480 */ 481 public bool isShadowed() 482 { 483 return g_mount_is_shadowed(getMountStruct()) != 0; 484 } 485 486 /** 487 * Remounts a mount. This is an asynchronous operation, and is 488 * finished by calling g_mount_remount_finish() with the @mount 489 * and #GAsyncResults data returned in the @callback. 490 * 491 * Remounting is useful when some setting affecting the operation 492 * of the volume has been changed, as these may need a remount to 493 * take affect. While this is semantically equivalent with unmounting 494 * and then remounting not all backends might need to actually be 495 * unmounted. 496 * 497 * Params: 498 * flags = flags affecting the operation 499 * mountOperation = a #GMountOperation or %NULL to avoid 500 * user interaction. 501 * cancellable = optional #GCancellable object, %NULL to ignore. 502 * callback = a #GAsyncReadyCallback, or %NULL. 503 * userData = user data passed to @callback. 504 */ 505 public void remount(GMountMountFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 506 { 507 g_mount_remount(getMountStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 508 } 509 510 /** 511 * Finishes remounting a mount. If any errors occurred during the operation, 512 * @error will be set to contain the errors and %FALSE will be returned. 513 * 514 * Params: 515 * result = a #GAsyncResult. 516 * 517 * Returns: %TRUE if the mount was successfully remounted. %FALSE otherwise. 518 * 519 * Throws: GException on failure. 520 */ 521 public bool remountFinish(AsyncResultIF result) 522 { 523 GError* err = null; 524 525 auto p = g_mount_remount_finish(getMountStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 526 527 if (err !is null) 528 { 529 throw new GException( new ErrorG(err) ); 530 } 531 532 return p; 533 } 534 535 /** 536 * Increments the shadow count on @mount. Usually used by 537 * #GVolumeMonitor implementations when creating a shadow mount for 538 * @mount, see g_mount_is_shadowed() for more information. The caller 539 * will need to emit the #GMount::changed signal on @mount manually. 540 * 541 * Since: 2.20 542 */ 543 public void shadow() 544 { 545 g_mount_shadow(getMountStruct()); 546 } 547 548 /** 549 * Unmounts a mount. This is an asynchronous operation, and is 550 * finished by calling g_mount_unmount_finish() with the @mount 551 * and #GAsyncResult data returned in the @callback. 552 * 553 * Deprecated: Use g_mount_unmount_with_operation() instead. 554 * 555 * Params: 556 * flags = flags affecting the operation 557 * cancellable = optional #GCancellable object, %NULL to ignore. 558 * callback = a #GAsyncReadyCallback, or %NULL. 559 * userData = user data passed to @callback. 560 */ 561 public void unmount(GMountUnmountFlags flags, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 562 { 563 g_mount_unmount(getMountStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 564 } 565 566 /** 567 * Finishes unmounting a mount. If any errors occurred during the operation, 568 * @error will be set to contain the errors and %FALSE will be returned. 569 * 570 * Deprecated: Use g_mount_unmount_with_operation_finish() instead. 571 * 572 * Params: 573 * result = a #GAsyncResult. 574 * 575 * Returns: %TRUE if the mount was successfully unmounted. %FALSE otherwise. 576 * 577 * Throws: GException on failure. 578 */ 579 public bool unmountFinish(AsyncResultIF result) 580 { 581 GError* err = null; 582 583 auto p = g_mount_unmount_finish(getMountStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 584 585 if (err !is null) 586 { 587 throw new GException( new ErrorG(err) ); 588 } 589 590 return p; 591 } 592 593 /** 594 * Unmounts a mount. This is an asynchronous operation, and is 595 * finished by calling g_mount_unmount_with_operation_finish() with the @mount 596 * and #GAsyncResult data returned in the @callback. 597 * 598 * Params: 599 * flags = flags affecting the operation 600 * mountOperation = a #GMountOperation or %NULL to avoid 601 * user interaction. 602 * cancellable = optional #GCancellable object, %NULL to ignore. 603 * callback = a #GAsyncReadyCallback, or %NULL. 604 * userData = user data passed to @callback. 605 * 606 * Since: 2.22 607 */ 608 public void unmountWithOperation(GMountUnmountFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 609 { 610 g_mount_unmount_with_operation(getMountStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 611 } 612 613 /** 614 * Finishes unmounting a mount. If any errors occurred during the operation, 615 * @error will be set to contain the errors and %FALSE will be returned. 616 * 617 * Params: 618 * result = a #GAsyncResult. 619 * 620 * Returns: %TRUE if the mount was successfully unmounted. %FALSE otherwise. 621 * 622 * Since: 2.22 623 * 624 * Throws: GException on failure. 625 */ 626 public bool unmountWithOperationFinish(AsyncResultIF result) 627 { 628 GError* err = null; 629 630 auto p = g_mount_unmount_with_operation_finish(getMountStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 631 632 if (err !is null) 633 { 634 throw new GException( new ErrorG(err) ); 635 } 636 637 return p; 638 } 639 640 /** 641 * Decrements the shadow count on @mount. Usually used by 642 * #GVolumeMonitor implementations when destroying a shadow mount for 643 * @mount, see g_mount_is_shadowed() for more information. The caller 644 * will need to emit the #GMount::changed signal on @mount manually. 645 * 646 * Since: 2.20 647 */ 648 public void unshadow() 649 { 650 g_mount_unshadow(getMountStruct()); 651 } 652 653 /** 654 * Emitted when the mount has been changed. 655 */ 656 gulong addOnChanged(void delegate(MountIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 657 { 658 return Signals.connect(this, "changed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 659 } 660 661 /** 662 * This signal may be emitted when the #GMount is about to be 663 * unmounted. 664 * 665 * This signal depends on the backend and is only emitted if 666 * GIO was used to unmount. 667 * 668 * Since: 2.22 669 */ 670 gulong addOnPreUnmount(void delegate(MountIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 671 { 672 return Signals.connect(this, "pre-unmount", dlg, connectFlags ^ ConnectFlags.SWAPPED); 673 } 674 675 /** 676 * This signal is emitted when the #GMount have been 677 * unmounted. If the recipient is holding references to the 678 * object they should release them so the object can be 679 * finalized. 680 */ 681 gulong addOnUnmounted(void delegate(MountIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 682 { 683 return Signals.connect(this, "unmounted", dlg, connectFlags ^ ConnectFlags.SWAPPED); 684 } 685 }