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