Improvde #include order consistency
[glib.git] / gio / gdrive.c
blob32f7848992edcc18a9fa3189b7d79b79aa68b29c
1 /* GIO - GLib Input, Output and Streaming Library
2 *
3 * Copyright (C) 2006-2007 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library 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 GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Alexander Larsson <alexl@redhat.com>
21 * David Zeuthen <davidz@redhat.com>
24 #include "config.h"
25 #include "gdrive.h"
26 #include "gtask.h"
27 #include "gthemedicon.h"
28 #include "gasyncresult.h"
29 #include "gioerror.h"
30 #include "glibintl.h"
33 /**
34 * SECTION:gdrive
35 * @short_description: Drive management
36 * @include: gio/gio.h
38 * #GDrive - this represent a piece of hardware connected to the machine.
39 * It's generally only created for removable hardware or hardware with
40 * removable media.
42 * #GDrive is a container class for #GVolume objects that stem from
43 * the same piece of media. As such, #GDrive abstracts a drive with
44 * (or without) removable media and provides operations for querying
45 * whether media is available, determining whether media change is
46 * automatically detected and ejecting the media.
48 * If the #GDrive reports that media isn't automatically detected, one
49 * can poll for media; typically one should not do this periodically
50 * as a poll for media operation is potententially expensive and may
51 * spin up the drive creating noise.
53 * #GDrive supports starting and stopping drives with authentication
54 * support for the former. This can be used to support a diverse set
55 * of use cases including connecting/disconnecting iSCSI devices,
56 * powering down external disk enclosures and starting/stopping
57 * multi-disk devices such as RAID devices. Note that the actual
58 * semantics and side-effects of starting/stopping a #GDrive may vary
59 * according to implementation. To choose the correct verbs in e.g. a
60 * file manager, use g_drive_get_start_stop_type().
62 * For porting from GnomeVFS note that there is no equivalent of
63 * #GDrive in that API.
64 **/
66 typedef GDriveIface GDriveInterface;
67 G_DEFINE_INTERFACE(GDrive, g_drive, G_TYPE_OBJECT)
69 static void
70 g_drive_default_init (GDriveInterface *iface)
72 /**
73 * GDrive::changed:
74 * @drive: a #GDrive.
76 * Emitted when the drive's state has changed.
77 **/
78 g_signal_new (I_("changed"),
79 G_TYPE_DRIVE,
80 G_SIGNAL_RUN_LAST,
81 G_STRUCT_OFFSET (GDriveIface, changed),
82 NULL, NULL,
83 g_cclosure_marshal_VOID__VOID,
84 G_TYPE_NONE, 0);
86 /**
87 * GDrive::disconnected:
88 * @drive: a #GDrive.
90 * This signal is emitted when the #GDrive have been
91 * disconnected. If the recipient is holding references to the
92 * object they should release them so the object can be
93 * finalized.
94 **/
95 g_signal_new (I_("disconnected"),
96 G_TYPE_DRIVE,
97 G_SIGNAL_RUN_LAST,
98 G_STRUCT_OFFSET (GDriveIface, disconnected),
99 NULL, NULL,
100 g_cclosure_marshal_VOID__VOID,
101 G_TYPE_NONE, 0);
104 * GDrive::eject-button:
105 * @drive: a #GDrive.
107 * Emitted when the physical eject button (if any) of a drive has
108 * been pressed.
110 g_signal_new (I_("eject-button"),
111 G_TYPE_DRIVE,
112 G_SIGNAL_RUN_LAST,
113 G_STRUCT_OFFSET (GDriveIface, eject_button),
114 NULL, NULL,
115 g_cclosure_marshal_VOID__VOID,
116 G_TYPE_NONE, 0);
119 * GDrive::stop-button:
120 * @drive: a #GDrive.
122 * Emitted when the physical stop button (if any) of a drive has
123 * been pressed.
125 * Since: 2.22
127 g_signal_new (I_("stop-button"),
128 G_TYPE_DRIVE,
129 G_SIGNAL_RUN_LAST,
130 G_STRUCT_OFFSET (GDriveIface, stop_button),
131 NULL, NULL,
132 g_cclosure_marshal_VOID__VOID,
133 G_TYPE_NONE, 0);
137 * g_drive_get_name:
138 * @drive: a #GDrive.
140 * Gets the name of @drive.
142 * Returns: a string containing @drive's name. The returned
143 * string should be freed when no longer needed.
145 char *
146 g_drive_get_name (GDrive *drive)
148 GDriveIface *iface;
150 g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
152 iface = G_DRIVE_GET_IFACE (drive);
154 return (* iface->get_name) (drive);
158 * g_drive_get_icon:
159 * @drive: a #GDrive.
161 * Gets the icon for @drive.
163 * Returns: (transfer full): #GIcon for the @drive.
164 * Free the returned object with g_object_unref().
166 GIcon *
167 g_drive_get_icon (GDrive *drive)
169 GDriveIface *iface;
171 g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
173 iface = G_DRIVE_GET_IFACE (drive);
175 return (* iface->get_icon) (drive);
179 * g_drive_get_symbolic_icon:
180 * @drive: a #GDrive.
182 * Gets the icon for @drive.
184 * Returns: (transfer full): symbolic #GIcon for the @drive.
185 * Free the returned object with g_object_unref().
187 * Since: 2.34
189 GIcon *
190 g_drive_get_symbolic_icon (GDrive *drive)
192 GDriveIface *iface;
193 GIcon *ret;
195 g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
197 iface = G_DRIVE_GET_IFACE (drive);
199 if (iface->get_symbolic_icon != NULL)
200 ret = iface->get_symbolic_icon (drive);
201 else
202 ret = g_themed_icon_new_with_default_fallbacks ("drive-removable-media-symbolic");
204 return ret;
208 * g_drive_has_volumes:
209 * @drive: a #GDrive.
211 * Check if @drive has any mountable volumes.
213 * Returns: %TRUE if the @drive contains volumes, %FALSE otherwise.
215 gboolean
216 g_drive_has_volumes (GDrive *drive)
218 GDriveIface *iface;
220 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
222 iface = G_DRIVE_GET_IFACE (drive);
224 return (* iface->has_volumes) (drive);
228 * g_drive_get_volumes:
229 * @drive: a #GDrive.
231 * Get a list of mountable volumes for @drive.
233 * The returned list should be freed with g_list_free(), after
234 * its elements have been unreffed with g_object_unref().
236 * Returns: (element-type GVolume) (transfer full): #GList containing any #GVolume objects on the given @drive.
238 GList *
239 g_drive_get_volumes (GDrive *drive)
241 GDriveIface *iface;
243 g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
245 iface = G_DRIVE_GET_IFACE (drive);
247 return (* iface->get_volumes) (drive);
251 * g_drive_is_media_check_automatic:
252 * @drive: a #GDrive.
254 * Checks if @drive is capabable of automatically detecting media changes.
256 * Returns: %TRUE if the @drive is capabable of automatically detecting
257 * media changes, %FALSE otherwise.
259 gboolean
260 g_drive_is_media_check_automatic (GDrive *drive)
262 GDriveIface *iface;
264 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
266 iface = G_DRIVE_GET_IFACE (drive);
268 return (* iface->is_media_check_automatic) (drive);
272 * g_drive_is_media_removable:
273 * @drive: a #GDrive.
275 * Checks if the @drive supports removable media.
277 * Returns: %TRUE if @drive supports removable media, %FALSE otherwise.
279 gboolean
280 g_drive_is_media_removable (GDrive *drive)
282 GDriveIface *iface;
284 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
286 iface = G_DRIVE_GET_IFACE (drive);
288 return (* iface->is_media_removable) (drive);
292 * g_drive_has_media:
293 * @drive: a #GDrive.
295 * Checks if the @drive has media. Note that the OS may not be polling
296 * the drive for media changes; see g_drive_is_media_check_automatic()
297 * for more details.
299 * Returns: %TRUE if @drive has media, %FALSE otherwise.
301 gboolean
302 g_drive_has_media (GDrive *drive)
304 GDriveIface *iface;
306 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
308 iface = G_DRIVE_GET_IFACE (drive);
310 return (* iface->has_media) (drive);
314 * g_drive_can_eject:
315 * @drive: a #GDrive.
317 * Checks if a drive can be ejected.
319 * Returns: %TRUE if the @drive can be ejected, %FALSE otherwise.
321 gboolean
322 g_drive_can_eject (GDrive *drive)
324 GDriveIface *iface;
326 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
328 iface = G_DRIVE_GET_IFACE (drive);
330 if (iface->can_eject == NULL)
331 return FALSE;
333 return (* iface->can_eject) (drive);
337 * g_drive_can_poll_for_media:
338 * @drive: a #GDrive.
340 * Checks if a drive can be polled for media changes.
342 * Returns: %TRUE if the @drive can be polled for media changes,
343 * %FALSE otherwise.
345 gboolean
346 g_drive_can_poll_for_media (GDrive *drive)
348 GDriveIface *iface;
350 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
352 iface = G_DRIVE_GET_IFACE (drive);
354 if (iface->poll_for_media == NULL)
355 return FALSE;
357 return (* iface->can_poll_for_media) (drive);
361 * g_drive_eject:
362 * @drive: a #GDrive.
363 * @flags: flags affecting the unmount if required for eject
364 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
365 * @callback: (allow-none): a #GAsyncReadyCallback, or %NULL.
366 * @user_data: user data to pass to @callback
368 * Asynchronously ejects a drive.
370 * When the operation is finished, @callback will be called.
371 * You can then call g_drive_eject_finish() to obtain the
372 * result of the operation.
374 * Deprecated: 2.22: Use g_drive_eject_with_operation() instead.
376 void
377 g_drive_eject (GDrive *drive,
378 GMountUnmountFlags flags,
379 GCancellable *cancellable,
380 GAsyncReadyCallback callback,
381 gpointer user_data)
383 GDriveIface *iface;
385 g_return_if_fail (G_IS_DRIVE (drive));
387 iface = G_DRIVE_GET_IFACE (drive);
389 if (iface->eject == NULL)
391 g_task_report_new_error (drive, callback, user_data,
392 g_drive_eject_with_operation,
393 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
394 _("drive doesn't implement eject"));
395 return;
398 (* iface->eject) (drive, flags, cancellable, callback, user_data);
402 * g_drive_eject_finish:
403 * @drive: a #GDrive.
404 * @result: a #GAsyncResult.
405 * @error: a #GError, or %NULL
407 * Finishes ejecting a drive.
409 * Returns: %TRUE if the drive has been ejected successfully,
410 * %FALSE otherwise.
412 * Deprecated: 2.22: Use g_drive_eject_with_operation_finish() instead.
414 gboolean
415 g_drive_eject_finish (GDrive *drive,
416 GAsyncResult *result,
417 GError **error)
419 GDriveIface *iface;
421 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
422 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
424 if (g_async_result_legacy_propagate_error (result, error))
425 return FALSE;
426 else if (g_async_result_is_tagged (result, g_drive_eject_with_operation))
427 return g_task_propagate_boolean (G_TASK (result), error);
429 iface = G_DRIVE_GET_IFACE (drive);
431 return (* iface->eject_finish) (drive, result, error);
435 * g_drive_eject_with_operation:
436 * @drive: a #GDrive.
437 * @flags: flags affecting the unmount if required for eject
438 * @mount_operation: (allow-none): a #GMountOperation or %NULL to avoid
439 * user interaction.
440 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
441 * @callback: (allow-none): a #GAsyncReadyCallback, or %NULL.
442 * @user_data: user data passed to @callback.
444 * Ejects a drive. This is an asynchronous operation, and is
445 * finished by calling g_drive_eject_with_operation_finish() with the @drive
446 * and #GAsyncResult data returned in the @callback.
448 * Since: 2.22
450 void
451 g_drive_eject_with_operation (GDrive *drive,
452 GMountUnmountFlags flags,
453 GMountOperation *mount_operation,
454 GCancellable *cancellable,
455 GAsyncReadyCallback callback,
456 gpointer user_data)
458 GDriveIface *iface;
460 g_return_if_fail (G_IS_DRIVE (drive));
462 iface = G_DRIVE_GET_IFACE (drive);
464 if (iface->eject == NULL && iface->eject_with_operation == NULL)
466 g_task_report_new_error (drive, callback, user_data,
467 g_drive_eject_with_operation,
468 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
469 /* Translators: This is an error
470 * message for drive objects that
471 * don't implement any of eject or eject_with_operation. */
472 _("drive doesn't implement eject or eject_with_operation"));
473 return;
476 if (iface->eject_with_operation != NULL)
477 (* iface->eject_with_operation) (drive, flags, mount_operation, cancellable, callback, user_data);
478 else
479 (* iface->eject) (drive, flags, cancellable, callback, user_data);
483 * g_drive_eject_with_operation_finish:
484 * @drive: a #GDrive.
485 * @result: a #GAsyncResult.
486 * @error: a #GError location to store the error occurring, or %NULL to
487 * ignore.
489 * Finishes ejecting a drive. If any errors occurred during the operation,
490 * @error will be set to contain the errors and %FALSE will be returned.
492 * Returns: %TRUE if the drive was successfully ejected. %FALSE otherwise.
494 * Since: 2.22
496 gboolean
497 g_drive_eject_with_operation_finish (GDrive *drive,
498 GAsyncResult *result,
499 GError **error)
501 GDriveIface *iface;
503 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
504 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
506 if (g_async_result_legacy_propagate_error (result, error))
507 return FALSE;
508 else if (g_async_result_is_tagged (result, g_drive_eject_with_operation))
509 return g_task_propagate_boolean (G_TASK (result), error);
511 iface = G_DRIVE_GET_IFACE (drive);
512 if (iface->eject_with_operation_finish != NULL)
513 return (* iface->eject_with_operation_finish) (drive, result, error);
514 else
515 return (* iface->eject_finish) (drive, result, error);
519 * g_drive_poll_for_media:
520 * @drive: a #GDrive.
521 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
522 * @callback: (allow-none): a #GAsyncReadyCallback, or %NULL.
523 * @user_data: user data to pass to @callback
525 * Asynchronously polls @drive to see if media has been inserted or removed.
527 * When the operation is finished, @callback will be called.
528 * You can then call g_drive_poll_for_media_finish() to obtain the
529 * result of the operation.
531 void
532 g_drive_poll_for_media (GDrive *drive,
533 GCancellable *cancellable,
534 GAsyncReadyCallback callback,
535 gpointer user_data)
537 GDriveIface *iface;
539 g_return_if_fail (G_IS_DRIVE (drive));
541 iface = G_DRIVE_GET_IFACE (drive);
543 if (iface->poll_for_media == NULL)
545 g_task_report_new_error (drive, callback, user_data,
546 g_drive_poll_for_media,
547 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
548 _("drive doesn't implement polling for media"));
549 return;
552 (* iface->poll_for_media) (drive, cancellable, callback, user_data);
556 * g_drive_poll_for_media_finish:
557 * @drive: a #GDrive.
558 * @result: a #GAsyncResult.
559 * @error: a #GError, or %NULL
561 * Finishes an operation started with g_drive_poll_for_media() on a drive.
563 * Returns: %TRUE if the drive has been poll_for_mediaed successfully,
564 * %FALSE otherwise.
566 gboolean
567 g_drive_poll_for_media_finish (GDrive *drive,
568 GAsyncResult *result,
569 GError **error)
571 GDriveIface *iface;
573 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
574 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
576 if (g_async_result_legacy_propagate_error (result, error))
577 return FALSE;
578 else if (g_async_result_is_tagged (result, g_drive_poll_for_media))
579 return g_task_propagate_boolean (G_TASK (result), error);
581 iface = G_DRIVE_GET_IFACE (drive);
583 return (* iface->poll_for_media_finish) (drive, result, error);
587 * g_drive_get_identifier:
588 * @drive: a #GDrive
589 * @kind: the kind of identifier to return
591 * Gets the identifier of the given kind for @drive.
593 * Returns: a newly allocated string containing the
594 * requested identfier, or %NULL if the #GDrive
595 * doesn't have this kind of identifier.
597 char *
598 g_drive_get_identifier (GDrive *drive,
599 const char *kind)
601 GDriveIface *iface;
603 g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
604 g_return_val_if_fail (kind != NULL, NULL);
606 iface = G_DRIVE_GET_IFACE (drive);
608 if (iface->get_identifier == NULL)
609 return NULL;
611 return (* iface->get_identifier) (drive, kind);
615 * g_drive_enumerate_identifiers:
616 * @drive: a #GDrive
618 * Gets the kinds of identifiers that @drive has.
619 * Use g_drive_get_identifier() to obtain the identifiers
620 * themselves.
622 * Returns: (transfer full) (array zero-terminated=1): a %NULL-terminated
623 * array of strings containing kinds of identifiers. Use g_strfreev()
624 * to free.
626 char **
627 g_drive_enumerate_identifiers (GDrive *drive)
629 GDriveIface *iface;
631 g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
632 iface = G_DRIVE_GET_IFACE (drive);
634 if (iface->enumerate_identifiers == NULL)
635 return NULL;
637 return (* iface->enumerate_identifiers) (drive);
641 * g_drive_get_start_stop_type:
642 * @drive: a #GDrive.
644 * Gets a hint about how a drive can be started/stopped.
646 * Returns: A value from the #GDriveStartStopType enumeration.
648 * Since: 2.22
650 GDriveStartStopType
651 g_drive_get_start_stop_type (GDrive *drive)
653 GDriveIface *iface;
655 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
657 iface = G_DRIVE_GET_IFACE (drive);
659 if (iface->get_start_stop_type == NULL)
660 return G_DRIVE_START_STOP_TYPE_UNKNOWN;
662 return (* iface->get_start_stop_type) (drive);
667 * g_drive_can_start:
668 * @drive: a #GDrive.
670 * Checks if a drive can be started.
672 * Returns: %TRUE if the @drive can be started, %FALSE otherwise.
674 * Since: 2.22
676 gboolean
677 g_drive_can_start (GDrive *drive)
679 GDriveIface *iface;
681 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
683 iface = G_DRIVE_GET_IFACE (drive);
685 if (iface->can_start == NULL)
686 return FALSE;
688 return (* iface->can_start) (drive);
692 * g_drive_can_start_degraded:
693 * @drive: a #GDrive.
695 * Checks if a drive can be started degraded.
697 * Returns: %TRUE if the @drive can be started degraded, %FALSE otherwise.
699 * Since: 2.22
701 gboolean
702 g_drive_can_start_degraded (GDrive *drive)
704 GDriveIface *iface;
706 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
708 iface = G_DRIVE_GET_IFACE (drive);
710 if (iface->can_start_degraded == NULL)
711 return FALSE;
713 return (* iface->can_start_degraded) (drive);
717 * g_drive_start:
718 * @drive: a #GDrive.
719 * @flags: flags affecting the start operation.
720 * @mount_operation: (allow-none): a #GMountOperation or %NULL to avoid
721 * user interaction.
722 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
723 * @callback: (allow-none): a #GAsyncReadyCallback, or %NULL.
724 * @user_data: user data to pass to @callback
726 * Asynchronously starts a drive.
728 * When the operation is finished, @callback will be called.
729 * You can then call g_drive_start_finish() to obtain the
730 * result of the operation.
732 * Since: 2.22
734 void
735 g_drive_start (GDrive *drive,
736 GDriveStartFlags flags,
737 GMountOperation *mount_operation,
738 GCancellable *cancellable,
739 GAsyncReadyCallback callback,
740 gpointer user_data)
742 GDriveIface *iface;
744 g_return_if_fail (G_IS_DRIVE (drive));
746 iface = G_DRIVE_GET_IFACE (drive);
748 if (iface->start == NULL)
750 g_task_report_new_error (drive, callback, user_data,
751 g_drive_start,
752 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
753 _("drive doesn't implement start"));
754 return;
757 (* iface->start) (drive, flags, mount_operation, cancellable, callback, user_data);
761 * g_drive_start_finish:
762 * @drive: a #GDrive.
763 * @result: a #GAsyncResult.
764 * @error: a #GError, or %NULL
766 * Finishes starting a drive.
768 * Returns: %TRUE if the drive has been started successfully,
769 * %FALSE otherwise.
771 * Since: 2.22
773 gboolean
774 g_drive_start_finish (GDrive *drive,
775 GAsyncResult *result,
776 GError **error)
778 GDriveIface *iface;
780 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
781 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
783 if (g_async_result_legacy_propagate_error (result, error))
784 return FALSE;
785 else if (g_async_result_is_tagged (result, g_drive_start))
786 return g_task_propagate_boolean (G_TASK (result), error);
788 iface = G_DRIVE_GET_IFACE (drive);
790 return (* iface->start_finish) (drive, result, error);
794 * g_drive_can_stop:
795 * @drive: a #GDrive.
797 * Checks if a drive can be stopped.
799 * Returns: %TRUE if the @drive can be stopped, %FALSE otherwise.
801 * Since: 2.22
803 gboolean
804 g_drive_can_stop (GDrive *drive)
806 GDriveIface *iface;
808 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
810 iface = G_DRIVE_GET_IFACE (drive);
812 if (iface->can_stop == NULL)
813 return FALSE;
815 return (* iface->can_stop) (drive);
819 * g_drive_stop:
820 * @drive: a #GDrive.
821 * @flags: flags affecting the unmount if required for stopping.
822 * @mount_operation: (allow-none): a #GMountOperation or %NULL to avoid
823 * user interaction.
824 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
825 * @callback: (allow-none): a #GAsyncReadyCallback, or %NULL.
826 * @user_data: user data to pass to @callback
828 * Asynchronously stops a drive.
830 * When the operation is finished, @callback will be called.
831 * You can then call g_drive_stop_finish() to obtain the
832 * result of the operation.
834 * Since: 2.22
836 void
837 g_drive_stop (GDrive *drive,
838 GMountUnmountFlags flags,
839 GMountOperation *mount_operation,
840 GCancellable *cancellable,
841 GAsyncReadyCallback callback,
842 gpointer user_data)
844 GDriveIface *iface;
846 g_return_if_fail (G_IS_DRIVE (drive));
848 iface = G_DRIVE_GET_IFACE (drive);
850 if (iface->stop == NULL)
852 g_task_report_new_error (drive, callback, user_data,
853 g_drive_start,
854 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
855 _("drive doesn't implement stop"));
856 return;
859 (* iface->stop) (drive, flags, mount_operation, cancellable, callback, user_data);
863 * g_drive_stop_finish:
864 * @drive: a #GDrive.
865 * @result: a #GAsyncResult.
866 * @error: a #GError, or %NULL
868 * Finishes stopping a drive.
870 * Returns: %TRUE if the drive has been stopped successfully,
871 * %FALSE otherwise.
873 * Since: 2.22
875 gboolean
876 g_drive_stop_finish (GDrive *drive,
877 GAsyncResult *result,
878 GError **error)
880 GDriveIface *iface;
882 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
883 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
885 if (g_async_result_legacy_propagate_error (result, error))
886 return FALSE;
887 else if (g_async_result_is_tagged (result, g_drive_start))
888 return g_task_propagate_boolean (G_TASK (result), error);
890 iface = G_DRIVE_GET_IFACE (drive);
892 return (* iface->stop_finish) (drive, result, error);
896 * g_drive_get_sort_key:
897 * @drive: A #GDrive.
899 * Gets the sort key for @drive, if any.
901 * Returns: Sorting key for @drive or %NULL if no such key is available.
903 * Since: 2.32
905 const gchar *
906 g_drive_get_sort_key (GDrive *drive)
908 const gchar *ret = NULL;
909 GDriveIface *iface;
911 g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
913 iface = G_DRIVE_GET_IFACE (drive);
914 if (iface->get_sort_key != NULL)
915 ret = iface->get_sort_key (drive);
917 return ret;