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