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.gio;
39 public  import gtkc.giotypes;
40 public  import std.algorithm;
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 	 * Returns: %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 	 * Returns: %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 	 * Returns: %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 	 * Returns: %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 	 * Returns: %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 	 * Returns: %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 	 * Returns: %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 	 * Returns: 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 	 * Returns: #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 	 * Returns: 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 	 * Returns: 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 	 * Returns: 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 	 * Returns: 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 	 * Returns: 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 	 * Returns: #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 	 * Returns: %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 	 * Returns: %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 	 * Returns: %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 	 * Returns: %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 	 * Returns: %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 	 * Returns: %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 	 * Returns: %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 	 * Returns: %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 	protected class OnChangedDelegateWrapper
559 	{
560 		static OnChangedDelegateWrapper[] listeners;
561 		void delegate(DriveIF) dlg;
562 		gulong handlerId;
563 		
564 		this(void delegate(DriveIF) dlg)
565 		{
566 			this.dlg = dlg;
567 			this.listeners ~= this;
568 		}
569 		
570 		void remove(OnChangedDelegateWrapper source)
571 		{
572 			foreach(index, wrapper; listeners)
573 			{
574 				if (wrapper.handlerId == source.handlerId)
575 				{
576 					listeners[index] = null;
577 					listeners = std.algorithm.remove(listeners, index);
578 					break;
579 				}
580 			}
581 		}
582 	}
583 
584 	/**
585 	 * Emitted when the drive's state has changed.
586 	 */
587 	gulong addOnChanged(void delegate(DriveIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
588 	{
589 		auto wrapper = new OnChangedDelegateWrapper(dlg);
590 		wrapper.handlerId = Signals.connectData(
591 			this,
592 			"changed",
593 			cast(GCallback)&callBackChanged,
594 			cast(void*)wrapper,
595 			cast(GClosureNotify)&callBackChangedDestroy,
596 			connectFlags);
597 		return wrapper.handlerId;
598 	}
599 	
600 	extern(C) static void callBackChanged(GDrive* driveStruct, OnChangedDelegateWrapper wrapper)
601 	{
602 		wrapper.dlg(wrapper.outer);
603 	}
604 	
605 	extern(C) static void callBackChangedDestroy(OnChangedDelegateWrapper wrapper, GClosure* closure)
606 	{
607 		wrapper.remove(wrapper);
608 	}
609 
610 	protected class OnDisconnectedDelegateWrapper
611 	{
612 		static OnDisconnectedDelegateWrapper[] listeners;
613 		void delegate(DriveIF) dlg;
614 		gulong handlerId;
615 		
616 		this(void delegate(DriveIF) dlg)
617 		{
618 			this.dlg = dlg;
619 			this.listeners ~= this;
620 		}
621 		
622 		void remove(OnDisconnectedDelegateWrapper source)
623 		{
624 			foreach(index, wrapper; listeners)
625 			{
626 				if (wrapper.handlerId == source.handlerId)
627 				{
628 					listeners[index] = null;
629 					listeners = std.algorithm.remove(listeners, index);
630 					break;
631 				}
632 			}
633 		}
634 	}
635 
636 	/**
637 	 * This signal is emitted when the #GDrive have been
638 	 * disconnected. If the recipient is holding references to the
639 	 * object they should release them so the object can be
640 	 * finalized.
641 	 */
642 	gulong addOnDisconnected(void delegate(DriveIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
643 	{
644 		auto wrapper = new OnDisconnectedDelegateWrapper(dlg);
645 		wrapper.handlerId = Signals.connectData(
646 			this,
647 			"disconnected",
648 			cast(GCallback)&callBackDisconnected,
649 			cast(void*)wrapper,
650 			cast(GClosureNotify)&callBackDisconnectedDestroy,
651 			connectFlags);
652 		return wrapper.handlerId;
653 	}
654 	
655 	extern(C) static void callBackDisconnected(GDrive* driveStruct, OnDisconnectedDelegateWrapper wrapper)
656 	{
657 		wrapper.dlg(wrapper.outer);
658 	}
659 	
660 	extern(C) static void callBackDisconnectedDestroy(OnDisconnectedDelegateWrapper wrapper, GClosure* closure)
661 	{
662 		wrapper.remove(wrapper);
663 	}
664 
665 	protected class OnEjectButtonDelegateWrapper
666 	{
667 		static OnEjectButtonDelegateWrapper[] listeners;
668 		void delegate(DriveIF) dlg;
669 		gulong handlerId;
670 		
671 		this(void delegate(DriveIF) dlg)
672 		{
673 			this.dlg = dlg;
674 			this.listeners ~= this;
675 		}
676 		
677 		void remove(OnEjectButtonDelegateWrapper source)
678 		{
679 			foreach(index, wrapper; listeners)
680 			{
681 				if (wrapper.handlerId == source.handlerId)
682 				{
683 					listeners[index] = null;
684 					listeners = std.algorithm.remove(listeners, index);
685 					break;
686 				}
687 			}
688 		}
689 	}
690 
691 	/**
692 	 * Emitted when the physical eject button (if any) of a drive has
693 	 * been pressed.
694 	 */
695 	gulong addOnEjectButton(void delegate(DriveIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
696 	{
697 		auto wrapper = new OnEjectButtonDelegateWrapper(dlg);
698 		wrapper.handlerId = Signals.connectData(
699 			this,
700 			"eject-button",
701 			cast(GCallback)&callBackEjectButton,
702 			cast(void*)wrapper,
703 			cast(GClosureNotify)&callBackEjectButtonDestroy,
704 			connectFlags);
705 		return wrapper.handlerId;
706 	}
707 	
708 	extern(C) static void callBackEjectButton(GDrive* driveStruct, OnEjectButtonDelegateWrapper wrapper)
709 	{
710 		wrapper.dlg(wrapper.outer);
711 	}
712 	
713 	extern(C) static void callBackEjectButtonDestroy(OnEjectButtonDelegateWrapper wrapper, GClosure* closure)
714 	{
715 		wrapper.remove(wrapper);
716 	}
717 
718 	protected class OnStopButtonDelegateWrapper
719 	{
720 		static OnStopButtonDelegateWrapper[] listeners;
721 		void delegate(DriveIF) dlg;
722 		gulong handlerId;
723 		
724 		this(void delegate(DriveIF) dlg)
725 		{
726 			this.dlg = dlg;
727 			this.listeners ~= this;
728 		}
729 		
730 		void remove(OnStopButtonDelegateWrapper source)
731 		{
732 			foreach(index, wrapper; listeners)
733 			{
734 				if (wrapper.handlerId == source.handlerId)
735 				{
736 					listeners[index] = null;
737 					listeners = std.algorithm.remove(listeners, index);
738 					break;
739 				}
740 			}
741 		}
742 	}
743 
744 	/**
745 	 * Emitted when the physical stop button (if any) of a drive has
746 	 * been pressed.
747 	 *
748 	 * Since: 2.22
749 	 */
750 	gulong addOnStopButton(void delegate(DriveIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
751 	{
752 		auto wrapper = new OnStopButtonDelegateWrapper(dlg);
753 		wrapper.handlerId = Signals.connectData(
754 			this,
755 			"stop-button",
756 			cast(GCallback)&callBackStopButton,
757 			cast(void*)wrapper,
758 			cast(GClosureNotify)&callBackStopButtonDestroy,
759 			connectFlags);
760 		return wrapper.handlerId;
761 	}
762 	
763 	extern(C) static void callBackStopButton(GDrive* driveStruct, OnStopButtonDelegateWrapper wrapper)
764 	{
765 		wrapper.dlg(wrapper.outer);
766 	}
767 	
768 	extern(C) static void callBackStopButtonDestroy(OnStopButtonDelegateWrapper wrapper, GClosure* closure)
769 	{
770 		wrapper.remove(wrapper);
771 	}
772 }