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