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.DriveT; 26 27 public import gio.AsyncResultIF; 28 public import gio.Cancellable; 29 public import gio.Icon; 30 public import gio.IconIF; 31 public import gio.MountOperation; 32 public import glib.ErrorG; 33 public import glib.GException; 34 public import glib.ListG; 35 public import glib.Str; 36 public import gobject.ObjectG; 37 public import gobject.Signals; 38 public import gtkc.gdktypes; 39 public import gtkc.gio; 40 public import gtkc.giotypes; 41 42 43 /** 44 * #GDrive - this represent a piece of hardware connected to the machine. 45 * It's generally only created for removable hardware or hardware with 46 * removable media. 47 * 48 * #GDrive is a container class for #GVolume objects that stem from 49 * the same piece of media. As such, #GDrive abstracts a drive with 50 * (or without) removable media and provides operations for querying 51 * whether media is available, determining whether media change is 52 * automatically detected and ejecting the media. 53 * 54 * If the #GDrive reports that media isn't automatically detected, one 55 * can poll for media; typically one should not do this periodically 56 * as a poll for media operation is potententially expensive and may 57 * spin up the drive creating noise. 58 * 59 * #GDrive supports starting and stopping drives with authentication 60 * support for the former. This can be used to support a diverse set 61 * of use cases including connecting/disconnecting iSCSI devices, 62 * powering down external disk enclosures and starting/stopping 63 * multi-disk devices such as RAID devices. Note that the actual 64 * semantics and side-effects of starting/stopping a #GDrive may vary 65 * according to implementation. To choose the correct verbs in e.g. a 66 * file manager, use g_drive_get_start_stop_type(). 67 * 68 * For porting from GnomeVFS note that there is no equivalent of 69 * #GDrive in that API. 70 */ 71 public template DriveT(TStruct) 72 { 73 /** Get the main Gtk struct */ 74 public GDrive* getDriveStruct() 75 { 76 return cast(GDrive*)getStruct(); 77 } 78 79 80 /** 81 * Checks if a drive can be ejected. 82 * 83 * Return: %TRUE if the @drive can be ejected, %FALSE otherwise. 84 */ 85 public bool canEject() 86 { 87 return g_drive_can_eject(getDriveStruct()) != 0; 88 } 89 90 /** 91 * Checks if a drive can be polled for media changes. 92 * 93 * Return: %TRUE if the @drive can be polled for media changes, 94 * %FALSE otherwise. 95 */ 96 public bool canPollForMedia() 97 { 98 return g_drive_can_poll_for_media(getDriveStruct()) != 0; 99 } 100 101 /** 102 * Checks if a drive can be started. 103 * 104 * Return: %TRUE if the @drive can be started, %FALSE otherwise. 105 * 106 * Since: 2.22 107 */ 108 public bool canStart() 109 { 110 return g_drive_can_start(getDriveStruct()) != 0; 111 } 112 113 /** 114 * Checks if a drive can be started degraded. 115 * 116 * Return: %TRUE if the @drive can be started degraded, %FALSE otherwise. 117 * 118 * Since: 2.22 119 */ 120 public bool canStartDegraded() 121 { 122 return g_drive_can_start_degraded(getDriveStruct()) != 0; 123 } 124 125 /** 126 * Checks if a drive can be stopped. 127 * 128 * Return: %TRUE if the @drive can be stopped, %FALSE otherwise. 129 * 130 * Since: 2.22 131 */ 132 public bool canStop() 133 { 134 return g_drive_can_stop(getDriveStruct()) != 0; 135 } 136 137 /** 138 * Asynchronously ejects a drive. 139 * 140 * When the operation is finished, @callback will be called. 141 * You can then call g_drive_eject_finish() to obtain the 142 * result of the operation. 143 * 144 * Deprecated: Use g_drive_eject_with_operation() instead. 145 * 146 * Params: 147 * flags = flags affecting the unmount if required for eject 148 * cancellable = optional #GCancellable object, %NULL to ignore. 149 * callback = a #GAsyncReadyCallback, or %NULL. 150 * userData = user data to pass to @callback 151 */ 152 public void eject(GMountUnmountFlags flags, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 153 { 154 g_drive_eject(getDriveStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 155 } 156 157 /** 158 * Finishes ejecting a drive. 159 * 160 * Deprecated: Use g_drive_eject_with_operation_finish() instead. 161 * 162 * Params: 163 * result = a #GAsyncResult. 164 * 165 * Return: %TRUE if the drive has been ejected successfully, 166 * %FALSE otherwise. 167 * 168 * Throws: GException on failure. 169 */ 170 public bool ejectFinish(AsyncResultIF result) 171 { 172 GError* err = null; 173 174 auto p = g_drive_eject_finish(getDriveStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 175 176 if (err !is null) 177 { 178 throw new GException( new ErrorG(err) ); 179 } 180 181 return p; 182 } 183 184 /** 185 * Ejects a drive. This is an asynchronous operation, and is 186 * finished by calling g_drive_eject_with_operation_finish() with the @drive 187 * and #GAsyncResult data returned in the @callback. 188 * 189 * Params: 190 * flags = flags affecting the unmount if required for eject 191 * mountOperation = a #GMountOperation or %NULL to avoid 192 * user interaction. 193 * cancellable = optional #GCancellable object, %NULL to ignore. 194 * callback = a #GAsyncReadyCallback, or %NULL. 195 * userData = user data passed to @callback. 196 * 197 * Since: 2.22 198 */ 199 public void ejectWithOperation(GMountUnmountFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 200 { 201 g_drive_eject_with_operation(getDriveStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 202 } 203 204 /** 205 * Finishes ejecting a drive. If any errors occurred during the operation, 206 * @error will be set to contain the errors and %FALSE will be returned. 207 * 208 * Params: 209 * result = a #GAsyncResult. 210 * 211 * Return: %TRUE if the drive was successfully ejected. %FALSE otherwise. 212 * 213 * Since: 2.22 214 * 215 * Throws: GException on failure. 216 */ 217 public bool ejectWithOperationFinish(AsyncResultIF result) 218 { 219 GError* err = null; 220 221 auto p = g_drive_eject_with_operation_finish(getDriveStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 222 223 if (err !is null) 224 { 225 throw new GException( new ErrorG(err) ); 226 } 227 228 return p; 229 } 230 231 /** 232 * Gets the kinds of identifiers that @drive has. 233 * Use g_drive_get_identifier() to obtain the identifiers 234 * themselves. 235 * 236 * Return: a %NULL-terminated 237 * array of strings containing kinds of identifiers. Use g_strfreev() 238 * to free. 239 */ 240 public string[] enumerateIdentifiers() 241 { 242 auto retStr = g_drive_enumerate_identifiers(getDriveStruct()); 243 244 scope(exit) Str.freeStringArray(retStr); 245 return Str.toStringArray(retStr); 246 } 247 248 /** 249 * Gets the icon for @drive. 250 * 251 * Return: #GIcon for the @drive. 252 * Free the returned object with g_object_unref(). 253 */ 254 public IconIF getIcon() 255 { 256 auto p = g_drive_get_icon(getDriveStruct()); 257 258 if(p is null) 259 { 260 return null; 261 } 262 263 return ObjectG.getDObject!(Icon, IconIF)(cast(GIcon*) p, true); 264 } 265 266 /** 267 * Gets the identifier of the given kind for @drive. 268 * 269 * Params: 270 * kind = the kind of identifier to return 271 * 272 * Return: a newly allocated string containing the 273 * requested identfier, or %NULL if the #GDrive 274 * doesn't have this kind of identifier. 275 */ 276 public string getIdentifier(string kind) 277 { 278 auto retStr = g_drive_get_identifier(getDriveStruct(), Str.toStringz(kind)); 279 280 scope(exit) Str.freeString(retStr); 281 return Str.toString(retStr); 282 } 283 284 /** 285 * Gets the name of @drive. 286 * 287 * Return: a string containing @drive's name. The returned 288 * string should be freed when no longer needed. 289 */ 290 public string getName() 291 { 292 auto retStr = g_drive_get_name(getDriveStruct()); 293 294 scope(exit) Str.freeString(retStr); 295 return Str.toString(retStr); 296 } 297 298 /** 299 * Gets the sort key for @drive, if any. 300 * 301 * Return: Sorting key for @drive or %NULL if no such key is available. 302 * 303 * Since: 2.32 304 */ 305 public string getSortKey() 306 { 307 return Str.toString(g_drive_get_sort_key(getDriveStruct())); 308 } 309 310 /** 311 * Gets a hint about how a drive can be started/stopped. 312 * 313 * Return: A value from the #GDriveStartStopType enumeration. 314 * 315 * Since: 2.22 316 */ 317 public GDriveStartStopType getStartStopType() 318 { 319 return g_drive_get_start_stop_type(getDriveStruct()); 320 } 321 322 /** 323 * Gets the icon for @drive. 324 * 325 * Return: symbolic #GIcon for the @drive. 326 * Free the returned object with g_object_unref(). 327 * 328 * Since: 2.34 329 */ 330 public IconIF getSymbolicIcon() 331 { 332 auto p = g_drive_get_symbolic_icon(getDriveStruct()); 333 334 if(p is null) 335 { 336 return null; 337 } 338 339 return ObjectG.getDObject!(Icon, IconIF)(cast(GIcon*) p, true); 340 } 341 342 /** 343 * Get a list of mountable volumes for @drive. 344 * 345 * The returned list should be freed with g_list_free(), after 346 * its elements have been unreffed with g_object_unref(). 347 * 348 * Return: #GList containing any #GVolume objects on the given @drive. 349 */ 350 public ListG getVolumes() 351 { 352 auto p = g_drive_get_volumes(getDriveStruct()); 353 354 if(p is null) 355 { 356 return null; 357 } 358 359 return new ListG(cast(GList*) p, true); 360 } 361 362 /** 363 * Checks if the @drive has media. Note that the OS may not be polling 364 * the drive for media changes; see g_drive_is_media_check_automatic() 365 * for more details. 366 * 367 * Return: %TRUE if @drive has media, %FALSE otherwise. 368 */ 369 public bool hasMedia() 370 { 371 return g_drive_has_media(getDriveStruct()) != 0; 372 } 373 374 /** 375 * Check if @drive has any mountable volumes. 376 * 377 * Return: %TRUE if the @drive contains volumes, %FALSE otherwise. 378 */ 379 public bool hasVolumes() 380 { 381 return g_drive_has_volumes(getDriveStruct()) != 0; 382 } 383 384 /** 385 * Checks if @drive is capabable of automatically detecting media changes. 386 * 387 * Return: %TRUE if the @drive is capabable of automatically detecting 388 * media changes, %FALSE otherwise. 389 */ 390 public bool isMediaCheckAutomatic() 391 { 392 return g_drive_is_media_check_automatic(getDriveStruct()) != 0; 393 } 394 395 /** 396 * Checks if the @drive supports removable media. 397 * 398 * Return: %TRUE if @drive supports removable media, %FALSE otherwise. 399 */ 400 public bool isMediaRemovable() 401 { 402 return g_drive_is_media_removable(getDriveStruct()) != 0; 403 } 404 405 /** 406 * Checks if the #GDrive and/or its media is considered removable by the user. 407 * See g_drive_is_media_removable(). 408 * 409 * Return: %TRUE if @drive and/or its media is considered removable, %FALSE otherwise. 410 * 411 * Since: 2.50 412 */ 413 public bool isRemovable() 414 { 415 return g_drive_is_removable(getDriveStruct()) != 0; 416 } 417 418 /** 419 * Asynchronously polls @drive to see if media has been inserted or removed. 420 * 421 * When the operation is finished, @callback will be called. 422 * You can then call g_drive_poll_for_media_finish() to obtain the 423 * result of the operation. 424 * 425 * Params: 426 * cancellable = optional #GCancellable object, %NULL to ignore. 427 * callback = a #GAsyncReadyCallback, or %NULL. 428 * userData = user data to pass to @callback 429 */ 430 public void pollForMedia(Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 431 { 432 g_drive_poll_for_media(getDriveStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 433 } 434 435 /** 436 * Finishes an operation started with g_drive_poll_for_media() on a drive. 437 * 438 * Params: 439 * result = a #GAsyncResult. 440 * 441 * Return: %TRUE if the drive has been poll_for_mediaed successfully, 442 * %FALSE otherwise. 443 * 444 * Throws: GException on failure. 445 */ 446 public bool pollForMediaFinish(AsyncResultIF result) 447 { 448 GError* err = null; 449 450 auto p = g_drive_poll_for_media_finish(getDriveStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 451 452 if (err !is null) 453 { 454 throw new GException( new ErrorG(err) ); 455 } 456 457 return p; 458 } 459 460 /** 461 * Asynchronously starts a drive. 462 * 463 * When the operation is finished, @callback will be called. 464 * You can then call g_drive_start_finish() to obtain the 465 * result of the operation. 466 * 467 * Params: 468 * flags = flags affecting the start operation. 469 * mountOperation = a #GMountOperation or %NULL to avoid 470 * user interaction. 471 * cancellable = optional #GCancellable object, %NULL to ignore. 472 * callback = a #GAsyncReadyCallback, or %NULL. 473 * userData = user data to pass to @callback 474 * 475 * Since: 2.22 476 */ 477 public void start(GDriveStartFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 478 { 479 g_drive_start(getDriveStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 480 } 481 482 /** 483 * Finishes starting a drive. 484 * 485 * Params: 486 * result = a #GAsyncResult. 487 * 488 * Return: %TRUE if the drive has been started successfully, 489 * %FALSE otherwise. 490 * 491 * Since: 2.22 492 * 493 * Throws: GException on failure. 494 */ 495 public bool startFinish(AsyncResultIF result) 496 { 497 GError* err = null; 498 499 auto p = g_drive_start_finish(getDriveStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 500 501 if (err !is null) 502 { 503 throw new GException( new ErrorG(err) ); 504 } 505 506 return p; 507 } 508 509 /** 510 * Asynchronously stops a drive. 511 * 512 * When the operation is finished, @callback will be called. 513 * You can then call g_drive_stop_finish() to obtain the 514 * result of the operation. 515 * 516 * Params: 517 * flags = flags affecting the unmount if required for stopping. 518 * mountOperation = a #GMountOperation or %NULL to avoid 519 * user interaction. 520 * cancellable = optional #GCancellable object, %NULL to ignore. 521 * callback = a #GAsyncReadyCallback, or %NULL. 522 * userData = user data to pass to @callback 523 * 524 * Since: 2.22 525 */ 526 public void stop(GMountUnmountFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 527 { 528 g_drive_stop(getDriveStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 529 } 530 531 /** 532 * Finishes stopping a drive. 533 * 534 * Params: 535 * result = a #GAsyncResult. 536 * 537 * Return: %TRUE if the drive has been stopped successfully, 538 * %FALSE otherwise. 539 * 540 * Since: 2.22 541 * 542 * Throws: GException on failure. 543 */ 544 public bool stopFinish(AsyncResultIF result) 545 { 546 GError* err = null; 547 548 auto p = g_drive_stop_finish(getDriveStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 549 550 if (err !is null) 551 { 552 throw new GException( new ErrorG(err) ); 553 } 554 555 return p; 556 } 557 558 int[string] connectedSignals; 559 560 void delegate(DriveIF)[] _onChangedListeners; 561 @property void delegate(DriveIF)[] onChangedListeners() 562 { 563 return _onChangedListeners; 564 } 565 /** 566 * Emitted when the drive's state has changed. 567 */ 568 void addOnChanged(void delegate(DriveIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 569 { 570 if ( "changed" !in connectedSignals ) 571 { 572 Signals.connectData( 573 this, 574 "changed", 575 cast(GCallback)&callBackChanged, 576 cast(void*)cast(DriveIF)this, 577 null, 578 connectFlags); 579 connectedSignals["changed"] = 1; 580 } 581 _onChangedListeners ~= dlg; 582 } 583 extern(C) static void callBackChanged(GDrive* driveStruct, DriveIF _drive) 584 { 585 foreach ( void delegate(DriveIF) dlg; _drive.onChangedListeners ) 586 { 587 dlg(_drive); 588 } 589 } 590 591 void delegate(DriveIF)[] _onDisconnectedListeners; 592 @property void delegate(DriveIF)[] onDisconnectedListeners() 593 { 594 return _onDisconnectedListeners; 595 } 596 /** 597 * This signal is emitted when the #GDrive have been 598 * disconnected. If the recipient is holding references to the 599 * object they should release them so the object can be 600 * finalized. 601 */ 602 void addOnDisconnected(void delegate(DriveIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 603 { 604 if ( "disconnected" !in connectedSignals ) 605 { 606 Signals.connectData( 607 this, 608 "disconnected", 609 cast(GCallback)&callBackDisconnected, 610 cast(void*)cast(DriveIF)this, 611 null, 612 connectFlags); 613 connectedSignals["disconnected"] = 1; 614 } 615 _onDisconnectedListeners ~= dlg; 616 } 617 extern(C) static void callBackDisconnected(GDrive* driveStruct, DriveIF _drive) 618 { 619 foreach ( void delegate(DriveIF) dlg; _drive.onDisconnectedListeners ) 620 { 621 dlg(_drive); 622 } 623 } 624 625 void delegate(DriveIF)[] _onEjectButtonListeners; 626 @property void delegate(DriveIF)[] onEjectButtonListeners() 627 { 628 return _onEjectButtonListeners; 629 } 630 /** 631 * Emitted when the physical eject button (if any) of a drive has 632 * been pressed. 633 */ 634 void addOnEjectButton(void delegate(DriveIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 635 { 636 if ( "eject-button" !in connectedSignals ) 637 { 638 Signals.connectData( 639 this, 640 "eject-button", 641 cast(GCallback)&callBackEjectButton, 642 cast(void*)cast(DriveIF)this, 643 null, 644 connectFlags); 645 connectedSignals["eject-button"] = 1; 646 } 647 _onEjectButtonListeners ~= dlg; 648 } 649 extern(C) static void callBackEjectButton(GDrive* driveStruct, DriveIF _drive) 650 { 651 foreach ( void delegate(DriveIF) dlg; _drive.onEjectButtonListeners ) 652 { 653 dlg(_drive); 654 } 655 } 656 657 void delegate(DriveIF)[] _onStopButtonListeners; 658 @property void delegate(DriveIF)[] onStopButtonListeners() 659 { 660 return _onStopButtonListeners; 661 } 662 /** 663 * Emitted when the physical stop button (if any) of a drive has 664 * been pressed. 665 * 666 * Since: 2.22 667 */ 668 void addOnStopButton(void delegate(DriveIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 669 { 670 if ( "stop-button" !in connectedSignals ) 671 { 672 Signals.connectData( 673 this, 674 "stop-button", 675 cast(GCallback)&callBackStopButton, 676 cast(void*)cast(DriveIF)this, 677 null, 678 connectFlags); 679 connectedSignals["stop-button"] = 1; 680 } 681 _onStopButtonListeners ~= dlg; 682 } 683 extern(C) static void callBackStopButton(GDrive* driveStruct, DriveIF _drive) 684 { 685 foreach ( void delegate(DriveIF) dlg; _drive.onStopButtonListeners ) 686 { 687 dlg(_drive); 688 } 689 } 690 }