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.IconIF;
30 public  import gio.MountOperation;
31 public  import gio.c.functions;
32 public  import gio.c.types;
33 public  import glib.ErrorG;
34 public  import glib.GException;
35 public  import glib.ListG;
36 public  import glib.Str;
37 public  import glib.c.functions;
38 public  import gobject.ObjectG;
39 public  import gobject.Signals;
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 potentially 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(bool transferOwnership = false)
75 	{
76 		if (transferOwnership)
77 			ownedRef = false;
78 		return cast(GDrive*)getStruct();
79 	}
80 
81 
82 	/**
83 	 * Checks if a drive can be ejected.
84 	 *
85 	 * Returns: %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 	 * Returns: %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 	 * Returns: %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 	 * Returns: %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 	 * Returns: %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 	 * Returns: %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 	 * Returns: %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 	 * Returns: a %NULL-terminated
239 	 *     array of strings containing kinds of identifiers. Use g_strfreev()
240 	 *     to free.
241 	 */
242 	public string[] enumerateIdentifiers()
243 	{
244 		auto retStr = g_drive_enumerate_identifiers(getDriveStruct());
245 
246 		scope(exit) Str.freeStringArray(retStr);
247 		return Str.toStringArray(retStr);
248 	}
249 
250 	/**
251 	 * Gets the icon for @drive.
252 	 *
253 	 * Returns: #GIcon for the @drive.
254 	 *     Free the returned object with g_object_unref().
255 	 */
256 	public IconIF getIcon()
257 	{
258 		auto __p = g_drive_get_icon(getDriveStruct());
259 
260 		if(__p is null)
261 		{
262 			return null;
263 		}
264 
265 		return ObjectG.getDObject!(IconIF)(cast(GIcon*) __p, true);
266 	}
267 
268 	/**
269 	 * Gets the identifier of the given kind for @drive. The only
270 	 * identifier currently available is
271 	 * #G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE.
272 	 *
273 	 * Params:
274 	 *     kind = the kind of identifier to return
275 	 *
276 	 * Returns: a newly allocated string containing the
277 	 *     requested identifier, or %NULL if the #GDrive
278 	 *     doesn't have this kind of identifier.
279 	 */
280 	public string getIdentifier(string kind)
281 	{
282 		auto retStr = g_drive_get_identifier(getDriveStruct(), Str.toStringz(kind));
283 
284 		scope(exit) Str.freeString(retStr);
285 		return Str.toString(retStr);
286 	}
287 
288 	/**
289 	 * Gets the name of @drive.
290 	 *
291 	 * Returns: a string containing @drive's name. The returned
292 	 *     string should be freed when no longer needed.
293 	 */
294 	public string getName()
295 	{
296 		auto retStr = g_drive_get_name(getDriveStruct());
297 
298 		scope(exit) Str.freeString(retStr);
299 		return Str.toString(retStr);
300 	}
301 
302 	/**
303 	 * Gets the sort key for @drive, if any.
304 	 *
305 	 * Returns: Sorting key for @drive or %NULL if no such key is available.
306 	 *
307 	 * Since: 2.32
308 	 */
309 	public string getSortKey()
310 	{
311 		return Str.toString(g_drive_get_sort_key(getDriveStruct()));
312 	}
313 
314 	/**
315 	 * Gets a hint about how a drive can be started/stopped.
316 	 *
317 	 * Returns: A value from the #GDriveStartStopType enumeration.
318 	 *
319 	 * Since: 2.22
320 	 */
321 	public GDriveStartStopType getStartStopType()
322 	{
323 		return g_drive_get_start_stop_type(getDriveStruct());
324 	}
325 
326 	/**
327 	 * Gets the icon for @drive.
328 	 *
329 	 * Returns: symbolic #GIcon for the @drive.
330 	 *     Free the returned object with g_object_unref().
331 	 *
332 	 * Since: 2.34
333 	 */
334 	public IconIF getSymbolicIcon()
335 	{
336 		auto __p = g_drive_get_symbolic_icon(getDriveStruct());
337 
338 		if(__p is null)
339 		{
340 			return null;
341 		}
342 
343 		return ObjectG.getDObject!(IconIF)(cast(GIcon*) __p, true);
344 	}
345 
346 	/**
347 	 * Get a list of mountable volumes for @drive.
348 	 *
349 	 * The returned list should be freed with g_list_free(), after
350 	 * its elements have been unreffed with g_object_unref().
351 	 *
352 	 * Returns: #GList containing any #GVolume objects on the given @drive.
353 	 */
354 	public ListG getVolumes()
355 	{
356 		auto __p = g_drive_get_volumes(getDriveStruct());
357 
358 		if(__p is null)
359 		{
360 			return null;
361 		}
362 
363 		return new ListG(cast(GList*) __p, true);
364 	}
365 
366 	/**
367 	 * Checks if the @drive has media. Note that the OS may not be polling
368 	 * the drive for media changes; see g_drive_is_media_check_automatic()
369 	 * for more details.
370 	 *
371 	 * Returns: %TRUE if @drive has media, %FALSE otherwise.
372 	 */
373 	public bool hasMedia()
374 	{
375 		return g_drive_has_media(getDriveStruct()) != 0;
376 	}
377 
378 	/**
379 	 * Check if @drive has any mountable volumes.
380 	 *
381 	 * Returns: %TRUE if the @drive contains volumes, %FALSE otherwise.
382 	 */
383 	public bool hasVolumes()
384 	{
385 		return g_drive_has_volumes(getDriveStruct()) != 0;
386 	}
387 
388 	/**
389 	 * Checks if @drive is capable of automatically detecting media changes.
390 	 *
391 	 * Returns: %TRUE if the @drive is capable of automatically detecting
392 	 *     media changes, %FALSE otherwise.
393 	 */
394 	public bool isMediaCheckAutomatic()
395 	{
396 		return g_drive_is_media_check_automatic(getDriveStruct()) != 0;
397 	}
398 
399 	/**
400 	 * Checks if the @drive supports removable media.
401 	 *
402 	 * Returns: %TRUE if @drive supports removable media, %FALSE otherwise.
403 	 */
404 	public bool isMediaRemovable()
405 	{
406 		return g_drive_is_media_removable(getDriveStruct()) != 0;
407 	}
408 
409 	/**
410 	 * Checks if the #GDrive and/or its media is considered removable by the user.
411 	 * See g_drive_is_media_removable().
412 	 *
413 	 * Returns: %TRUE if @drive and/or its media is considered removable, %FALSE otherwise.
414 	 *
415 	 * Since: 2.50
416 	 */
417 	public bool isRemovable()
418 	{
419 		return g_drive_is_removable(getDriveStruct()) != 0;
420 	}
421 
422 	/**
423 	 * Asynchronously polls @drive to see if media has been inserted or removed.
424 	 *
425 	 * When the operation is finished, @callback will be called.
426 	 * You can then call g_drive_poll_for_media_finish() to obtain the
427 	 * result of the operation.
428 	 *
429 	 * Params:
430 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
431 	 *     callback = a #GAsyncReadyCallback, or %NULL.
432 	 *     userData = user data to pass to @callback
433 	 */
434 	public void pollForMedia(Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
435 	{
436 		g_drive_poll_for_media(getDriveStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
437 	}
438 
439 	/**
440 	 * Finishes an operation started with g_drive_poll_for_media() on a drive.
441 	 *
442 	 * Params:
443 	 *     result = a #GAsyncResult.
444 	 *
445 	 * Returns: %TRUE if the drive has been poll_for_mediaed successfully,
446 	 *     %FALSE otherwise.
447 	 *
448 	 * Throws: GException on failure.
449 	 */
450 	public bool pollForMediaFinish(AsyncResultIF result)
451 	{
452 		GError* err = null;
453 
454 		auto __p = g_drive_poll_for_media_finish(getDriveStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
455 
456 		if (err !is null)
457 		{
458 			throw new GException( new ErrorG(err) );
459 		}
460 
461 		return __p;
462 	}
463 
464 	/**
465 	 * Asynchronously starts a drive.
466 	 *
467 	 * When the operation is finished, @callback will be called.
468 	 * You can then call g_drive_start_finish() to obtain the
469 	 * result of the operation.
470 	 *
471 	 * Params:
472 	 *     flags = flags affecting the start operation.
473 	 *     mountOperation = a #GMountOperation or %NULL to avoid
474 	 *         user interaction.
475 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
476 	 *     callback = a #GAsyncReadyCallback, or %NULL.
477 	 *     userData = user data to pass to @callback
478 	 *
479 	 * Since: 2.22
480 	 */
481 	public void start(GDriveStartFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
482 	{
483 		g_drive_start(getDriveStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
484 	}
485 
486 	/**
487 	 * Finishes starting a drive.
488 	 *
489 	 * Params:
490 	 *     result = a #GAsyncResult.
491 	 *
492 	 * Returns: %TRUE if the drive has been started successfully,
493 	 *     %FALSE otherwise.
494 	 *
495 	 * Since: 2.22
496 	 *
497 	 * Throws: GException on failure.
498 	 */
499 	public bool startFinish(AsyncResultIF result)
500 	{
501 		GError* err = null;
502 
503 		auto __p = g_drive_start_finish(getDriveStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
504 
505 		if (err !is null)
506 		{
507 			throw new GException( new ErrorG(err) );
508 		}
509 
510 		return __p;
511 	}
512 
513 	/**
514 	 * Asynchronously stops a drive.
515 	 *
516 	 * When the operation is finished, @callback will be called.
517 	 * You can then call g_drive_stop_finish() to obtain the
518 	 * result of the operation.
519 	 *
520 	 * Params:
521 	 *     flags = flags affecting the unmount if required for stopping.
522 	 *     mountOperation = a #GMountOperation or %NULL to avoid
523 	 *         user interaction.
524 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
525 	 *     callback = a #GAsyncReadyCallback, or %NULL.
526 	 *     userData = user data to pass to @callback
527 	 *
528 	 * Since: 2.22
529 	 */
530 	public void stop(GMountUnmountFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
531 	{
532 		g_drive_stop(getDriveStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
533 	}
534 
535 	/**
536 	 * Finishes stopping a drive.
537 	 *
538 	 * Params:
539 	 *     result = a #GAsyncResult.
540 	 *
541 	 * Returns: %TRUE if the drive has been stopped successfully,
542 	 *     %FALSE otherwise.
543 	 *
544 	 * Since: 2.22
545 	 *
546 	 * Throws: GException on failure.
547 	 */
548 	public bool stopFinish(AsyncResultIF result)
549 	{
550 		GError* err = null;
551 
552 		auto __p = g_drive_stop_finish(getDriveStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
553 
554 		if (err !is null)
555 		{
556 			throw new GException( new ErrorG(err) );
557 		}
558 
559 		return __p;
560 	}
561 
562 	/**
563 	 * Emitted when the drive's state has changed.
564 	 */
565 	gulong addOnChanged(void delegate(DriveIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
566 	{
567 		return Signals.connect(this, "changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
568 	}
569 
570 	/**
571 	 * This signal is emitted when the #GDrive have been
572 	 * disconnected. If the recipient is holding references to the
573 	 * object they should release them so the object can be
574 	 * finalized.
575 	 */
576 	gulong addOnDisconnected(void delegate(DriveIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
577 	{
578 		return Signals.connect(this, "disconnected", dlg, connectFlags ^ ConnectFlags.SWAPPED);
579 	}
580 
581 	/**
582 	 * Emitted when the physical eject button (if any) of a drive has
583 	 * been pressed.
584 	 */
585 	gulong addOnEjectButton(void delegate(DriveIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
586 	{
587 		return Signals.connect(this, "eject-button", dlg, connectFlags ^ ConnectFlags.SWAPPED);
588 	}
589 
590 	/**
591 	 * Emitted when the physical stop button (if any) of a drive has
592 	 * been pressed.
593 	 *
594 	 * Since: 2.22
595 	 */
596 	gulong addOnStopButton(void delegate(DriveIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
597 	{
598 		return Signals.connect(this, "stop-button", dlg, connectFlags ^ ConnectFlags.SWAPPED);
599 	}
600 }