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 	 * Asynchronously polls @drive to see if media has been inserted or removed.
407 	 *
408 	 * When the operation is finished, @callback will be called.
409 	 * You can then call g_drive_poll_for_media_finish() to obtain the
410 	 * result of the operation.
411 	 *
412 	 * Params:
413 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
414 	 *     callback = a #GAsyncReadyCallback, or %NULL.
415 	 *     userData = user data to pass to @callback
416 	 */
417 	public void pollForMedia(Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
418 	{
419 		g_drive_poll_for_media(getDriveStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
420 	}
421 
422 	/**
423 	 * Finishes an operation started with g_drive_poll_for_media() on a drive.
424 	 *
425 	 * Params:
426 	 *     result = a #GAsyncResult.
427 	 *
428 	 * Return: %TRUE if the drive has been poll_for_mediaed successfully,
429 	 *     %FALSE otherwise.
430 	 *
431 	 * Throws: GException on failure.
432 	 */
433 	public bool pollForMediaFinish(AsyncResultIF result)
434 	{
435 		GError* err = null;
436 		
437 		auto p = g_drive_poll_for_media_finish(getDriveStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
438 		
439 		if (err !is null)
440 		{
441 			throw new GException( new ErrorG(err) );
442 		}
443 		
444 		return p;
445 	}
446 
447 	/**
448 	 * Asynchronously starts a drive.
449 	 *
450 	 * When the operation is finished, @callback will be called.
451 	 * You can then call g_drive_start_finish() to obtain the
452 	 * result of the operation.
453 	 *
454 	 * Params:
455 	 *     flags = flags affecting the start operation.
456 	 *     mountOperation = a #GMountOperation or %NULL to avoid
457 	 *         user interaction.
458 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
459 	 *     callback = a #GAsyncReadyCallback, or %NULL.
460 	 *     userData = user data to pass to @callback
461 	 *
462 	 * Since: 2.22
463 	 */
464 	public void start(GDriveStartFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
465 	{
466 		g_drive_start(getDriveStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
467 	}
468 
469 	/**
470 	 * Finishes starting a drive.
471 	 *
472 	 * Params:
473 	 *     result = a #GAsyncResult.
474 	 *
475 	 * Return: %TRUE if the drive has been started successfully,
476 	 *     %FALSE otherwise.
477 	 *
478 	 * Since: 2.22
479 	 *
480 	 * Throws: GException on failure.
481 	 */
482 	public bool startFinish(AsyncResultIF result)
483 	{
484 		GError* err = null;
485 		
486 		auto p = g_drive_start_finish(getDriveStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
487 		
488 		if (err !is null)
489 		{
490 			throw new GException( new ErrorG(err) );
491 		}
492 		
493 		return p;
494 	}
495 
496 	/**
497 	 * Asynchronously stops a drive.
498 	 *
499 	 * When the operation is finished, @callback will be called.
500 	 * You can then call g_drive_stop_finish() to obtain the
501 	 * result of the operation.
502 	 *
503 	 * Params:
504 	 *     flags = flags affecting the unmount if required for stopping.
505 	 *     mountOperation = a #GMountOperation or %NULL to avoid
506 	 *         user interaction.
507 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
508 	 *     callback = a #GAsyncReadyCallback, or %NULL.
509 	 *     userData = user data to pass to @callback
510 	 *
511 	 * Since: 2.22
512 	 */
513 	public void stop(GMountUnmountFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
514 	{
515 		g_drive_stop(getDriveStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
516 	}
517 
518 	/**
519 	 * Finishes stopping a drive.
520 	 *
521 	 * Params:
522 	 *     result = a #GAsyncResult.
523 	 *
524 	 * Return: %TRUE if the drive has been stopped successfully,
525 	 *     %FALSE otherwise.
526 	 *
527 	 * Since: 2.22
528 	 *
529 	 * Throws: GException on failure.
530 	 */
531 	public bool stopFinish(AsyncResultIF result)
532 	{
533 		GError* err = null;
534 		
535 		auto p = g_drive_stop_finish(getDriveStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
536 		
537 		if (err !is null)
538 		{
539 			throw new GException( new ErrorG(err) );
540 		}
541 		
542 		return p;
543 	}
544 
545 	int[string] connectedSignals;
546 
547 	void delegate(DriveIF)[] _onChangedListeners;
548 	@property void delegate(DriveIF)[] onChangedListeners()
549 	{
550 		return _onChangedListeners;
551 	}
552 	/**
553 	 * Emitted when the drive's state has changed.
554 	 */
555 	void addOnChanged(void delegate(DriveIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
556 	{
557 		if ( "changed" !in connectedSignals )
558 		{
559 			Signals.connectData(
560 				this,
561 				"changed",
562 				cast(GCallback)&callBackChanged,
563 				cast(void*)cast(DriveIF)this,
564 				null,
565 				connectFlags);
566 			connectedSignals["changed"] = 1;
567 		}
568 		_onChangedListeners ~= dlg;
569 	}
570 	extern(C) static void callBackChanged(GDrive* driveStruct, DriveIF _drive)
571 	{
572 		foreach ( void delegate(DriveIF) dlg; _drive.onChangedListeners )
573 		{
574 			dlg(_drive);
575 		}
576 	}
577 
578 	void delegate(DriveIF)[] _onDisconnectedListeners;
579 	@property void delegate(DriveIF)[] onDisconnectedListeners()
580 	{
581 		return _onDisconnectedListeners;
582 	}
583 	/**
584 	 * This signal is emitted when the #GDrive have been
585 	 * disconnected. If the recipient is holding references to the
586 	 * object they should release them so the object can be
587 	 * finalized.
588 	 */
589 	void addOnDisconnected(void delegate(DriveIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
590 	{
591 		if ( "disconnected" !in connectedSignals )
592 		{
593 			Signals.connectData(
594 				this,
595 				"disconnected",
596 				cast(GCallback)&callBackDisconnected,
597 				cast(void*)cast(DriveIF)this,
598 				null,
599 				connectFlags);
600 			connectedSignals["disconnected"] = 1;
601 		}
602 		_onDisconnectedListeners ~= dlg;
603 	}
604 	extern(C) static void callBackDisconnected(GDrive* driveStruct, DriveIF _drive)
605 	{
606 		foreach ( void delegate(DriveIF) dlg; _drive.onDisconnectedListeners )
607 		{
608 			dlg(_drive);
609 		}
610 	}
611 
612 	void delegate(DriveIF)[] _onEjectButtonListeners;
613 	@property void delegate(DriveIF)[] onEjectButtonListeners()
614 	{
615 		return _onEjectButtonListeners;
616 	}
617 	/**
618 	 * Emitted when the physical eject button (if any) of a drive has
619 	 * been pressed.
620 	 */
621 	void addOnEjectButton(void delegate(DriveIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
622 	{
623 		if ( "eject-button" !in connectedSignals )
624 		{
625 			Signals.connectData(
626 				this,
627 				"eject-button",
628 				cast(GCallback)&callBackEjectButton,
629 				cast(void*)cast(DriveIF)this,
630 				null,
631 				connectFlags);
632 			connectedSignals["eject-button"] = 1;
633 		}
634 		_onEjectButtonListeners ~= dlg;
635 	}
636 	extern(C) static void callBackEjectButton(GDrive* driveStruct, DriveIF _drive)
637 	{
638 		foreach ( void delegate(DriveIF) dlg; _drive.onEjectButtonListeners )
639 		{
640 			dlg(_drive);
641 		}
642 	}
643 
644 	void delegate(DriveIF)[] _onStopButtonListeners;
645 	@property void delegate(DriveIF)[] onStopButtonListeners()
646 	{
647 		return _onStopButtonListeners;
648 	}
649 	/**
650 	 * Emitted when the physical stop button (if any) of a drive has
651 	 * been pressed.
652 	 *
653 	 * Since: 2.22
654 	 */
655 	void addOnStopButton(void delegate(DriveIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
656 	{
657 		if ( "stop-button" !in connectedSignals )
658 		{
659 			Signals.connectData(
660 				this,
661 				"stop-button",
662 				cast(GCallback)&callBackStopButton,
663 				cast(void*)cast(DriveIF)this,
664 				null,
665 				connectFlags);
666 			connectedSignals["stop-button"] = 1;
667 		}
668 		_onStopButtonListeners ~= dlg;
669 	}
670 	extern(C) static void callBackStopButton(GDrive* driveStruct, DriveIF _drive)
671 	{
672 		foreach ( void delegate(DriveIF) dlg; _drive.onStopButtonListeners )
673 		{
674 			dlg(_drive);
675 		}
676 	}
677 }