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 		return Str.toStringArray(g_drive_enumerate_identifiers(getDriveStruct()));
243 	}
244 
245 	/**
246 	 * Gets the icon for @drive.
247 	 *
248 	 * Return: #GIcon for the @drive.
249 	 *     Free the returned object with g_object_unref().
250 	 */
251 	public IconIF getIcon()
252 	{
253 		auto p = g_drive_get_icon(getDriveStruct());
254 		
255 		if(p is null)
256 		{
257 			return null;
258 		}
259 		
260 		return ObjectG.getDObject!(Icon, IconIF)(cast(GIcon*) p);
261 	}
262 
263 	/**
264 	 * Gets the identifier of the given kind for @drive.
265 	 *
266 	 * Params:
267 	 *     kind = the kind of identifier to return
268 	 *
269 	 * Return: a newly allocated string containing the
270 	 *     requested identfier, or %NULL if the #GDrive
271 	 *     doesn't have this kind of identifier.
272 	 */
273 	public string getIdentifier(string kind)
274 	{
275 		return Str.toString(g_drive_get_identifier(getDriveStruct(), Str.toStringz(kind)));
276 	}
277 
278 	/**
279 	 * Gets the name of @drive.
280 	 *
281 	 * Return: a string containing @drive's name. The returned
282 	 *     string should be freed when no longer needed.
283 	 */
284 	public string getName()
285 	{
286 		return Str.toString(g_drive_get_name(getDriveStruct()));
287 	}
288 
289 	/**
290 	 * Gets the sort key for @drive, if any.
291 	 *
292 	 * Return: Sorting key for @drive or %NULL if no such key is available.
293 	 *
294 	 * Since: 2.32
295 	 */
296 	public string getSortKey()
297 	{
298 		return Str.toString(g_drive_get_sort_key(getDriveStruct()));
299 	}
300 
301 	/**
302 	 * Gets a hint about how a drive can be started/stopped.
303 	 *
304 	 * Return: A value from the #GDriveStartStopType enumeration.
305 	 *
306 	 * Since: 2.22
307 	 */
308 	public GDriveStartStopType getStartStopType()
309 	{
310 		return g_drive_get_start_stop_type(getDriveStruct());
311 	}
312 
313 	/**
314 	 * Gets the icon for @drive.
315 	 *
316 	 * Return: symbolic #GIcon for the @drive.
317 	 *     Free the returned object with g_object_unref().
318 	 *
319 	 * Since: 2.34
320 	 */
321 	public IconIF getSymbolicIcon()
322 	{
323 		auto p = g_drive_get_symbolic_icon(getDriveStruct());
324 		
325 		if(p is null)
326 		{
327 			return null;
328 		}
329 		
330 		return ObjectG.getDObject!(Icon, IconIF)(cast(GIcon*) p);
331 	}
332 
333 	/**
334 	 * Get a list of mountable volumes for @drive.
335 	 *
336 	 * The returned list should be freed with g_list_free(), after
337 	 * its elements have been unreffed with g_object_unref().
338 	 *
339 	 * Return: #GList containing any #GVolume objects on the given @drive.
340 	 */
341 	public ListG getVolumes()
342 	{
343 		auto p = g_drive_get_volumes(getDriveStruct());
344 		
345 		if(p is null)
346 		{
347 			return null;
348 		}
349 		
350 		return new ListG(cast(GList*) p);
351 	}
352 
353 	/**
354 	 * Checks if the @drive has media. Note that the OS may not be polling
355 	 * the drive for media changes; see g_drive_is_media_check_automatic()
356 	 * for more details.
357 	 *
358 	 * Return: %TRUE if @drive has media, %FALSE otherwise.
359 	 */
360 	public bool hasMedia()
361 	{
362 		return g_drive_has_media(getDriveStruct()) != 0;
363 	}
364 
365 	/**
366 	 * Check if @drive has any mountable volumes.
367 	 *
368 	 * Return: %TRUE if the @drive contains volumes, %FALSE otherwise.
369 	 */
370 	public bool hasVolumes()
371 	{
372 		return g_drive_has_volumes(getDriveStruct()) != 0;
373 	}
374 
375 	/**
376 	 * Checks if @drive is capabable of automatically detecting media changes.
377 	 *
378 	 * Return: %TRUE if the @drive is capabable of automatically detecting
379 	 *     media changes, %FALSE otherwise.
380 	 */
381 	public bool isMediaCheckAutomatic()
382 	{
383 		return g_drive_is_media_check_automatic(getDriveStruct()) != 0;
384 	}
385 
386 	/**
387 	 * Checks if the @drive supports removable media.
388 	 *
389 	 * Return: %TRUE if @drive supports removable media, %FALSE otherwise.
390 	 */
391 	public bool isMediaRemovable()
392 	{
393 		return g_drive_is_media_removable(getDriveStruct()) != 0;
394 	}
395 
396 	/**
397 	 * Asynchronously polls @drive to see if media has been inserted or removed.
398 	 *
399 	 * When the operation is finished, @callback will be called.
400 	 * You can then call g_drive_poll_for_media_finish() to obtain the
401 	 * result of the operation.
402 	 *
403 	 * Params:
404 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
405 	 *     callback = a #GAsyncReadyCallback, or %NULL.
406 	 *     userData = user data to pass to @callback
407 	 */
408 	public void pollForMedia(Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
409 	{
410 		g_drive_poll_for_media(getDriveStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
411 	}
412 
413 	/**
414 	 * Finishes an operation started with g_drive_poll_for_media() on a drive.
415 	 *
416 	 * Params:
417 	 *     result = a #GAsyncResult.
418 	 *
419 	 * Return: %TRUE if the drive has been poll_for_mediaed successfully,
420 	 *     %FALSE otherwise.
421 	 *
422 	 * Throws: GException on failure.
423 	 */
424 	public bool pollForMediaFinish(AsyncResultIF result)
425 	{
426 		GError* err = null;
427 		
428 		auto p = g_drive_poll_for_media_finish(getDriveStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
429 		
430 		if (err !is null)
431 		{
432 			throw new GException( new ErrorG(err) );
433 		}
434 		
435 		return p;
436 	}
437 
438 	/**
439 	 * Asynchronously starts a drive.
440 	 *
441 	 * When the operation is finished, @callback will be called.
442 	 * You can then call g_drive_start_finish() to obtain the
443 	 * result of the operation.
444 	 *
445 	 * Params:
446 	 *     flags = flags affecting the start operation.
447 	 *     mountOperation = a #GMountOperation or %NULL to avoid
448 	 *         user interaction.
449 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
450 	 *     callback = a #GAsyncReadyCallback, or %NULL.
451 	 *     userData = user data to pass to @callback
452 	 *
453 	 * Since: 2.22
454 	 */
455 	public void start(GDriveStartFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
456 	{
457 		g_drive_start(getDriveStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
458 	}
459 
460 	/**
461 	 * Finishes starting a drive.
462 	 *
463 	 * Params:
464 	 *     result = a #GAsyncResult.
465 	 *
466 	 * Return: %TRUE if the drive has been started successfully,
467 	 *     %FALSE otherwise.
468 	 *
469 	 * Since: 2.22
470 	 *
471 	 * Throws: GException on failure.
472 	 */
473 	public bool startFinish(AsyncResultIF result)
474 	{
475 		GError* err = null;
476 		
477 		auto p = g_drive_start_finish(getDriveStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
478 		
479 		if (err !is null)
480 		{
481 			throw new GException( new ErrorG(err) );
482 		}
483 		
484 		return p;
485 	}
486 
487 	/**
488 	 * Asynchronously stops a drive.
489 	 *
490 	 * When the operation is finished, @callback will be called.
491 	 * You can then call g_drive_stop_finish() to obtain the
492 	 * result of the operation.
493 	 *
494 	 * Params:
495 	 *     flags = flags affecting the unmount if required for stopping.
496 	 *     mountOperation = a #GMountOperation or %NULL to avoid
497 	 *         user interaction.
498 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
499 	 *     callback = a #GAsyncReadyCallback, or %NULL.
500 	 *     userData = user data to pass to @callback
501 	 *
502 	 * Since: 2.22
503 	 */
504 	public void stop(GMountUnmountFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
505 	{
506 		g_drive_stop(getDriveStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
507 	}
508 
509 	/**
510 	 * Finishes stopping a drive.
511 	 *
512 	 * Params:
513 	 *     result = a #GAsyncResult.
514 	 *
515 	 * Return: %TRUE if the drive has been stopped successfully,
516 	 *     %FALSE otherwise.
517 	 *
518 	 * Since: 2.22
519 	 *
520 	 * Throws: GException on failure.
521 	 */
522 	public bool stopFinish(AsyncResultIF result)
523 	{
524 		GError* err = null;
525 		
526 		auto p = g_drive_stop_finish(getDriveStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
527 		
528 		if (err !is null)
529 		{
530 			throw new GException( new ErrorG(err) );
531 		}
532 		
533 		return p;
534 	}
535 
536 	int[string] connectedSignals;
537 
538 	void delegate(DriveIF)[] _onChangedListeners;
539 	@property void delegate(DriveIF)[] onChangedListeners()
540 	{
541 		return _onChangedListeners;
542 	}
543 	/**
544 	 * Emitted when the drive's state has changed.
545 	 */
546 	void addOnChanged(void delegate(DriveIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
547 	{
548 		if ( "changed" !in connectedSignals )
549 		{
550 			Signals.connectData(
551 				this,
552 				"changed",
553 				cast(GCallback)&callBackChanged,
554 				cast(void*)cast(DriveIF)this,
555 				null,
556 				connectFlags);
557 			connectedSignals["changed"] = 1;
558 		}
559 		_onChangedListeners ~= dlg;
560 	}
561 	extern(C) static void callBackChanged(GDrive* driveStruct, DriveIF _drive)
562 	{
563 		foreach ( void delegate(DriveIF) dlg; _drive.onChangedListeners )
564 		{
565 			dlg(_drive);
566 		}
567 	}
568 
569 	void delegate(DriveIF)[] _onDisconnectedListeners;
570 	@property void delegate(DriveIF)[] onDisconnectedListeners()
571 	{
572 		return _onDisconnectedListeners;
573 	}
574 	/**
575 	 * This signal is emitted when the #GDrive have been
576 	 * disconnected. If the recipient is holding references to the
577 	 * object they should release them so the object can be
578 	 * finalized.
579 	 */
580 	void addOnDisconnected(void delegate(DriveIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
581 	{
582 		if ( "disconnected" !in connectedSignals )
583 		{
584 			Signals.connectData(
585 				this,
586 				"disconnected",
587 				cast(GCallback)&callBackDisconnected,
588 				cast(void*)cast(DriveIF)this,
589 				null,
590 				connectFlags);
591 			connectedSignals["disconnected"] = 1;
592 		}
593 		_onDisconnectedListeners ~= dlg;
594 	}
595 	extern(C) static void callBackDisconnected(GDrive* driveStruct, DriveIF _drive)
596 	{
597 		foreach ( void delegate(DriveIF) dlg; _drive.onDisconnectedListeners )
598 		{
599 			dlg(_drive);
600 		}
601 	}
602 
603 	void delegate(DriveIF)[] _onEjectButtonListeners;
604 	@property void delegate(DriveIF)[] onEjectButtonListeners()
605 	{
606 		return _onEjectButtonListeners;
607 	}
608 	/**
609 	 * Emitted when the physical eject button (if any) of a drive has
610 	 * been pressed.
611 	 */
612 	void addOnEjectButton(void delegate(DriveIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
613 	{
614 		if ( "eject-button" !in connectedSignals )
615 		{
616 			Signals.connectData(
617 				this,
618 				"eject-button",
619 				cast(GCallback)&callBackEjectButton,
620 				cast(void*)cast(DriveIF)this,
621 				null,
622 				connectFlags);
623 			connectedSignals["eject-button"] = 1;
624 		}
625 		_onEjectButtonListeners ~= dlg;
626 	}
627 	extern(C) static void callBackEjectButton(GDrive* driveStruct, DriveIF _drive)
628 	{
629 		foreach ( void delegate(DriveIF) dlg; _drive.onEjectButtonListeners )
630 		{
631 			dlg(_drive);
632 		}
633 	}
634 
635 	void delegate(DriveIF)[] _onStopButtonListeners;
636 	@property void delegate(DriveIF)[] onStopButtonListeners()
637 	{
638 		return _onStopButtonListeners;
639 	}
640 	/**
641 	 * Emitted when the physical stop button (if any) of a drive has
642 	 * been pressed.
643 	 *
644 	 * Since: 2.22
645 	 */
646 	void addOnStopButton(void delegate(DriveIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
647 	{
648 		if ( "stop-button" !in connectedSignals )
649 		{
650 			Signals.connectData(
651 				this,
652 				"stop-button",
653 				cast(GCallback)&callBackStopButton,
654 				cast(void*)cast(DriveIF)this,
655 				null,
656 				connectFlags);
657 			connectedSignals["stop-button"] = 1;
658 		}
659 		_onStopButtonListeners ~= dlg;
660 	}
661 	extern(C) static void callBackStopButton(GDrive* driveStruct, DriveIF _drive)
662 	{
663 		foreach ( void delegate(DriveIF) dlg; _drive.onStopButtonListeners )
664 		{
665 			dlg(_drive);
666 		}
667 	}
668 }