Update German translation
[glib.git] / gio / gdrive.c
blob9720bf426250c54141e4735ba65e9eb296cbef81
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, see <http://www.gnu.org/licenses/>.
18 * Author: Alexander Larsson <alexl@redhat.com>
19 * David Zeuthen <davidz@redhat.com>
22 #include "config.h"
23 #include "gdrive.h"
24 #include "gtask.h"
25 #include "gthemedicon.h"
26 #include "gasyncresult.h"
27 #include "gioerror.h"
28 #include "glibintl.h"
31 /**
32 * SECTION:gdrive
33 * @short_description: Drive management
34 * @include: gio/gio.h
36 * #GDrive - this represent a piece of hardware connected to the machine.
37 * It's generally only created for removable hardware or hardware with
38 * removable media.
40 * #GDrive is a container class for #GVolume objects that stem from
41 * the same piece of media. As such, #GDrive abstracts a drive with
42 * (or without) removable media and provides operations for querying
43 * whether media is available, determining whether media change is
44 * automatically detected and ejecting the media.
46 * If the #GDrive reports that media isn't automatically detected, one
47 * can poll for media; typically one should not do this periodically
48 * as a poll for media operation is potententially expensive and may
49 * spin up the drive creating noise.
51 * #GDrive supports starting and stopping drives with authentication
52 * support for the former. This can be used to support a diverse set
53 * of use cases including connecting/disconnecting iSCSI devices,
54 * powering down external disk enclosures and starting/stopping
55 * multi-disk devices such as RAID devices. Note that the actual
56 * semantics and side-effects of starting/stopping a #GDrive may vary
57 * according to implementation. To choose the correct verbs in e.g. a
58 * file manager, use g_drive_get_start_stop_type().
60 * For porting from GnomeVFS note that there is no equivalent of
61 * #GDrive in that API.
62 **/
64 typedef GDriveIface GDriveInterface;
65 G_DEFINE_INTERFACE(GDrive, g_drive, G_TYPE_OBJECT)
67 static void
68 g_drive_default_init (GDriveInterface *iface)
70 /**
71 * GDrive::changed:
72 * @drive: a #GDrive.
74 * Emitted when the drive's state has changed.
75 **/
76 g_signal_new (I_("changed"),
77 G_TYPE_DRIVE,
78 G_SIGNAL_RUN_LAST,
79 G_STRUCT_OFFSET (GDriveIface, changed),
80 NULL, NULL,
81 g_cclosure_marshal_VOID__VOID,
82 G_TYPE_NONE, 0);
84 /**
85 * GDrive::disconnected:
86 * @drive: a #GDrive.
88 * This signal is emitted when the #GDrive have been
89 * disconnected. If the recipient is holding references to the
90 * object they should release them so the object can be
91 * finalized.
92 **/
93 g_signal_new (I_("disconnected"),
94 G_TYPE_DRIVE,
95 G_SIGNAL_RUN_LAST,
96 G_STRUCT_OFFSET (GDriveIface, disconnected),
97 NULL, NULL,
98 g_cclosure_marshal_VOID__VOID,
99 G_TYPE_NONE, 0);
102 * GDrive::eject-button:
103 * @drive: a #GDrive.
105 * Emitted when the physical eject button (if any) of a drive has
106 * been pressed.
108 g_signal_new (I_("eject-button"),
109 G_TYPE_DRIVE,
110 G_SIGNAL_RUN_LAST,
111 G_STRUCT_OFFSET (GDriveIface, eject_button),
112 NULL, NULL,
113 g_cclosure_marshal_VOID__VOID,
114 G_TYPE_NONE, 0);
117 * GDrive::stop-button:
118 * @drive: a #GDrive.
120 * Emitted when the physical stop button (if any) of a drive has
121 * been pressed.
123 * Since: 2.22
125 g_signal_new (I_("stop-button"),
126 G_TYPE_DRIVE,
127 G_SIGNAL_RUN_LAST,
128 G_STRUCT_OFFSET (GDriveIface, stop_button),
129 NULL, NULL,
130 g_cclosure_marshal_VOID__VOID,
131 G_TYPE_NONE, 0);
135 * g_drive_get_name:
136 * @drive: a #GDrive.
138 * Gets the name of @drive.
140 * Returns: a string containing @drive's name. The returned
141 * string should be freed when no longer needed.
143 char *
144 g_drive_get_name (GDrive *drive)
146 GDriveIface *iface;
148 g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
150 iface = G_DRIVE_GET_IFACE (drive);
152 return (* iface->get_name) (drive);
156 * g_drive_get_icon:
157 * @drive: a #GDrive.
159 * Gets the icon for @drive.
161 * Returns: (transfer full): #GIcon for the @drive.
162 * Free the returned object with g_object_unref().
164 GIcon *
165 g_drive_get_icon (GDrive *drive)
167 GDriveIface *iface;
169 g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
171 iface = G_DRIVE_GET_IFACE (drive);
173 return (* iface->get_icon) (drive);
177 * g_drive_get_symbolic_icon:
178 * @drive: a #GDrive.
180 * Gets the icon for @drive.
182 * Returns: (transfer full): symbolic #GIcon for the @drive.
183 * Free the returned object with g_object_unref().
185 * Since: 2.34
187 GIcon *
188 g_drive_get_symbolic_icon (GDrive *drive)
190 GDriveIface *iface;
191 GIcon *ret;
193 g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
195 iface = G_DRIVE_GET_IFACE (drive);
197 if (iface->get_symbolic_icon != NULL)
198 ret = iface->get_symbolic_icon (drive);
199 else
200 ret = g_themed_icon_new_with_default_fallbacks ("drive-removable-media-symbolic");
202 return ret;
206 * g_drive_has_volumes:
207 * @drive: a #GDrive.
209 * Check if @drive has any mountable volumes.
211 * Returns: %TRUE if the @drive contains volumes, %FALSE otherwise.
213 gboolean
214 g_drive_has_volumes (GDrive *drive)
216 GDriveIface *iface;
218 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
220 iface = G_DRIVE_GET_IFACE (drive);
222 return (* iface->has_volumes) (drive);
226 * g_drive_get_volumes:
227 * @drive: a #GDrive.
229 * Get a list of mountable volumes for @drive.
231 * The returned list should be freed with g_list_free(), after
232 * its elements have been unreffed with g_object_unref().
234 * Returns: (element-type GVolume) (transfer full): #GList containing any #GVolume objects on the given @drive.
236 GList *
237 g_drive_get_volumes (GDrive *drive)
239 GDriveIface *iface;
241 g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
243 iface = G_DRIVE_GET_IFACE (drive);
245 return (* iface->get_volumes) (drive);
249 * g_drive_is_media_check_automatic:
250 * @drive: a #GDrive.
252 * Checks if @drive is capabable of automatically detecting media changes.
254 * Returns: %TRUE if the @drive is capabable of automatically detecting
255 * media changes, %FALSE otherwise.
257 gboolean
258 g_drive_is_media_check_automatic (GDrive *drive)
260 GDriveIface *iface;
262 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
264 iface = G_DRIVE_GET_IFACE (drive);
266 return (* iface->is_media_check_automatic) (drive);
270 * g_drive_is_removable:
271 * @drive: a #GDrive.
273 * Checks if the #GDrive and/or its media is considered removable by the user.
274 * See g_drive_is_media_removable().
276 * Returns: %TRUE if @drive and/or its media is considered removable, %FALSE otherwise.
278 * Since: 2.50
280 gboolean
281 g_drive_is_removable (GDrive *drive)
283 GDriveIface *iface;
285 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
287 iface = G_DRIVE_GET_IFACE (drive);
288 if (iface->is_removable != NULL)
289 return iface->is_removable (drive);
291 return FALSE;
295 * g_drive_is_media_removable:
296 * @drive: a #GDrive.
298 * Checks if the @drive supports removable media.
300 * Returns: %TRUE if @drive supports removable media, %FALSE otherwise.
302 gboolean
303 g_drive_is_media_removable (GDrive *drive)
305 GDriveIface *iface;
307 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
309 iface = G_DRIVE_GET_IFACE (drive);
311 return (* iface->is_media_removable) (drive);
315 * g_drive_has_media:
316 * @drive: a #GDrive.
318 * Checks if the @drive has media. Note that the OS may not be polling
319 * the drive for media changes; see g_drive_is_media_check_automatic()
320 * for more details.
322 * Returns: %TRUE if @drive has media, %FALSE otherwise.
324 gboolean
325 g_drive_has_media (GDrive *drive)
327 GDriveIface *iface;
329 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
331 iface = G_DRIVE_GET_IFACE (drive);
333 return (* iface->has_media) (drive);
337 * g_drive_can_eject:
338 * @drive: a #GDrive.
340 * Checks if a drive can be ejected.
342 * Returns: %TRUE if the @drive can be ejected, %FALSE otherwise.
344 gboolean
345 g_drive_can_eject (GDrive *drive)
347 GDriveIface *iface;
349 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
351 iface = G_DRIVE_GET_IFACE (drive);
353 if (iface->can_eject == NULL)
354 return FALSE;
356 return (* iface->can_eject) (drive);
360 * g_drive_can_poll_for_media:
361 * @drive: a #GDrive.
363 * Checks if a drive can be polled for media changes.
365 * Returns: %TRUE if the @drive can be polled for media changes,
366 * %FALSE otherwise.
368 gboolean
369 g_drive_can_poll_for_media (GDrive *drive)
371 GDriveIface *iface;
373 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
375 iface = G_DRIVE_GET_IFACE (drive);
377 if (iface->poll_for_media == NULL)
378 return FALSE;
380 return (* iface->can_poll_for_media) (drive);
384 * g_drive_eject:
385 * @drive: a #GDrive.
386 * @flags: flags affecting the unmount if required for eject
387 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
388 * @callback: (nullable): a #GAsyncReadyCallback, or %NULL.
389 * @user_data: user data to pass to @callback
391 * Asynchronously ejects a drive.
393 * When the operation is finished, @callback will be called.
394 * You can then call g_drive_eject_finish() to obtain the
395 * result of the operation.
397 * Deprecated: 2.22: Use g_drive_eject_with_operation() instead.
399 void
400 g_drive_eject (GDrive *drive,
401 GMountUnmountFlags flags,
402 GCancellable *cancellable,
403 GAsyncReadyCallback callback,
404 gpointer user_data)
406 GDriveIface *iface;
408 g_return_if_fail (G_IS_DRIVE (drive));
410 iface = G_DRIVE_GET_IFACE (drive);
412 if (iface->eject == NULL)
414 g_task_report_new_error (drive, callback, user_data,
415 g_drive_eject_with_operation,
416 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
417 _("drive doesn’t implement eject"));
418 return;
421 (* iface->eject) (drive, flags, cancellable, callback, user_data);
425 * g_drive_eject_finish:
426 * @drive: a #GDrive.
427 * @result: a #GAsyncResult.
428 * @error: a #GError, or %NULL
430 * Finishes ejecting a drive.
432 * Returns: %TRUE if the drive has been ejected successfully,
433 * %FALSE otherwise.
435 * Deprecated: 2.22: Use g_drive_eject_with_operation_finish() instead.
437 gboolean
438 g_drive_eject_finish (GDrive *drive,
439 GAsyncResult *result,
440 GError **error)
442 GDriveIface *iface;
444 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
445 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
447 if (g_async_result_legacy_propagate_error (result, error))
448 return FALSE;
449 else if (g_async_result_is_tagged (result, g_drive_eject_with_operation))
450 return g_task_propagate_boolean (G_TASK (result), error);
452 iface = G_DRIVE_GET_IFACE (drive);
454 return (* iface->eject_finish) (drive, result, error);
458 * g_drive_eject_with_operation:
459 * @drive: a #GDrive.
460 * @flags: flags affecting the unmount if required for eject
461 * @mount_operation: (nullable): a #GMountOperation or %NULL to avoid
462 * user interaction.
463 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
464 * @callback: (nullable): a #GAsyncReadyCallback, or %NULL.
465 * @user_data: user data passed to @callback.
467 * Ejects a drive. This is an asynchronous operation, and is
468 * finished by calling g_drive_eject_with_operation_finish() with the @drive
469 * and #GAsyncResult data returned in the @callback.
471 * Since: 2.22
473 void
474 g_drive_eject_with_operation (GDrive *drive,
475 GMountUnmountFlags flags,
476 GMountOperation *mount_operation,
477 GCancellable *cancellable,
478 GAsyncReadyCallback callback,
479 gpointer user_data)
481 GDriveIface *iface;
483 g_return_if_fail (G_IS_DRIVE (drive));
485 iface = G_DRIVE_GET_IFACE (drive);
487 if (iface->eject == NULL && iface->eject_with_operation == NULL)
489 g_task_report_new_error (drive, callback, user_data,
490 g_drive_eject_with_operation,
491 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
492 /* Translators: This is an error
493 * message for drive objects that
494 * don't implement any of eject or eject_with_operation. */
495 _("drive doesn’t implement eject or eject_with_operation"));
496 return;
499 if (iface->eject_with_operation != NULL)
500 (* iface->eject_with_operation) (drive, flags, mount_operation, cancellable, callback, user_data);
501 else
502 (* iface->eject) (drive, flags, cancellable, callback, user_data);
506 * g_drive_eject_with_operation_finish:
507 * @drive: a #GDrive.
508 * @result: a #GAsyncResult.
509 * @error: a #GError location to store the error occurring, or %NULL to
510 * ignore.
512 * Finishes ejecting a drive. If any errors occurred during the operation,
513 * @error will be set to contain the errors and %FALSE will be returned.
515 * Returns: %TRUE if the drive was successfully ejected. %FALSE otherwise.
517 * Since: 2.22
519 gboolean
520 g_drive_eject_with_operation_finish (GDrive *drive,
521 GAsyncResult *result,
522 GError **error)
524 GDriveIface *iface;
526 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
527 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
529 if (g_async_result_legacy_propagate_error (result, error))
530 return FALSE;
531 else if (g_async_result_is_tagged (result, g_drive_eject_with_operation))
532 return g_task_propagate_boolean (G_TASK (result), error);
534 iface = G_DRIVE_GET_IFACE (drive);
535 if (iface->eject_with_operation_finish != NULL)
536 return (* iface->eject_with_operation_finish) (drive, result, error);
537 else
538 return (* iface->eject_finish) (drive, result, error);
542 * g_drive_poll_for_media:
543 * @drive: a #GDrive.
544 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
545 * @callback: (nullable): a #GAsyncReadyCallback, or %NULL.
546 * @user_data: user data to pass to @callback
548 * Asynchronously polls @drive to see if media has been inserted or removed.
550 * When the operation is finished, @callback will be called.
551 * You can then call g_drive_poll_for_media_finish() to obtain the
552 * result of the operation.
554 void
555 g_drive_poll_for_media (GDrive *drive,
556 GCancellable *cancellable,
557 GAsyncReadyCallback callback,
558 gpointer user_data)
560 GDriveIface *iface;
562 g_return_if_fail (G_IS_DRIVE (drive));
564 iface = G_DRIVE_GET_IFACE (drive);
566 if (iface->poll_for_media == NULL)
568 g_task_report_new_error (drive, callback, user_data,
569 g_drive_poll_for_media,
570 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
571 _("drive doesn’t implement polling for media"));
572 return;
575 (* iface->poll_for_media) (drive, cancellable, callback, user_data);
579 * g_drive_poll_for_media_finish:
580 * @drive: a #GDrive.
581 * @result: a #GAsyncResult.
582 * @error: a #GError, or %NULL
584 * Finishes an operation started with g_drive_poll_for_media() on a drive.
586 * Returns: %TRUE if the drive has been poll_for_mediaed successfully,
587 * %FALSE otherwise.
589 gboolean
590 g_drive_poll_for_media_finish (GDrive *drive,
591 GAsyncResult *result,
592 GError **error)
594 GDriveIface *iface;
596 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
597 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
599 if (g_async_result_legacy_propagate_error (result, error))
600 return FALSE;
601 else if (g_async_result_is_tagged (result, g_drive_poll_for_media))
602 return g_task_propagate_boolean (G_TASK (result), error);
604 iface = G_DRIVE_GET_IFACE (drive);
606 return (* iface->poll_for_media_finish) (drive, result, error);
610 * g_drive_get_identifier:
611 * @drive: a #GDrive
612 * @kind: the kind of identifier to return
614 * Gets the identifier of the given kind for @drive.
616 * Returns: a newly allocated string containing the
617 * requested identfier, or %NULL if the #GDrive
618 * doesn't have this kind of identifier.
620 char *
621 g_drive_get_identifier (GDrive *drive,
622 const char *kind)
624 GDriveIface *iface;
626 g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
627 g_return_val_if_fail (kind != NULL, NULL);
629 iface = G_DRIVE_GET_IFACE (drive);
631 if (iface->get_identifier == NULL)
632 return NULL;
634 return (* iface->get_identifier) (drive, kind);
638 * g_drive_enumerate_identifiers:
639 * @drive: a #GDrive
641 * Gets the kinds of identifiers that @drive has.
642 * Use g_drive_get_identifier() to obtain the identifiers
643 * themselves.
645 * Returns: (transfer full) (array zero-terminated=1): a %NULL-terminated
646 * array of strings containing kinds of identifiers. Use g_strfreev()
647 * to free.
649 char **
650 g_drive_enumerate_identifiers (GDrive *drive)
652 GDriveIface *iface;
654 g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
655 iface = G_DRIVE_GET_IFACE (drive);
657 if (iface->enumerate_identifiers == NULL)
658 return NULL;
660 return (* iface->enumerate_identifiers) (drive);
664 * g_drive_get_start_stop_type:
665 * @drive: a #GDrive.
667 * Gets a hint about how a drive can be started/stopped.
669 * Returns: A value from the #GDriveStartStopType enumeration.
671 * Since: 2.22
673 GDriveStartStopType
674 g_drive_get_start_stop_type (GDrive *drive)
676 GDriveIface *iface;
678 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
680 iface = G_DRIVE_GET_IFACE (drive);
682 if (iface->get_start_stop_type == NULL)
683 return G_DRIVE_START_STOP_TYPE_UNKNOWN;
685 return (* iface->get_start_stop_type) (drive);
690 * g_drive_can_start:
691 * @drive: a #GDrive.
693 * Checks if a drive can be started.
695 * Returns: %TRUE if the @drive can be started, %FALSE otherwise.
697 * Since: 2.22
699 gboolean
700 g_drive_can_start (GDrive *drive)
702 GDriveIface *iface;
704 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
706 iface = G_DRIVE_GET_IFACE (drive);
708 if (iface->can_start == NULL)
709 return FALSE;
711 return (* iface->can_start) (drive);
715 * g_drive_can_start_degraded:
716 * @drive: a #GDrive.
718 * Checks if a drive can be started degraded.
720 * Returns: %TRUE if the @drive can be started degraded, %FALSE otherwise.
722 * Since: 2.22
724 gboolean
725 g_drive_can_start_degraded (GDrive *drive)
727 GDriveIface *iface;
729 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
731 iface = G_DRIVE_GET_IFACE (drive);
733 if (iface->can_start_degraded == NULL)
734 return FALSE;
736 return (* iface->can_start_degraded) (drive);
740 * g_drive_start:
741 * @drive: a #GDrive.
742 * @flags: flags affecting the start operation.
743 * @mount_operation: (nullable): a #GMountOperation or %NULL to avoid
744 * user interaction.
745 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
746 * @callback: (nullable): a #GAsyncReadyCallback, or %NULL.
747 * @user_data: user data to pass to @callback
749 * Asynchronously starts a drive.
751 * When the operation is finished, @callback will be called.
752 * You can then call g_drive_start_finish() to obtain the
753 * result of the operation.
755 * Since: 2.22
757 void
758 g_drive_start (GDrive *drive,
759 GDriveStartFlags flags,
760 GMountOperation *mount_operation,
761 GCancellable *cancellable,
762 GAsyncReadyCallback callback,
763 gpointer user_data)
765 GDriveIface *iface;
767 g_return_if_fail (G_IS_DRIVE (drive));
769 iface = G_DRIVE_GET_IFACE (drive);
771 if (iface->start == NULL)
773 g_task_report_new_error (drive, callback, user_data,
774 g_drive_start,
775 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
776 _("drive doesn’t implement start"));
777 return;
780 (* iface->start) (drive, flags, mount_operation, cancellable, callback, user_data);
784 * g_drive_start_finish:
785 * @drive: a #GDrive.
786 * @result: a #GAsyncResult.
787 * @error: a #GError, or %NULL
789 * Finishes starting a drive.
791 * Returns: %TRUE if the drive has been started successfully,
792 * %FALSE otherwise.
794 * Since: 2.22
796 gboolean
797 g_drive_start_finish (GDrive *drive,
798 GAsyncResult *result,
799 GError **error)
801 GDriveIface *iface;
803 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
804 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
806 if (g_async_result_legacy_propagate_error (result, error))
807 return FALSE;
808 else if (g_async_result_is_tagged (result, g_drive_start))
809 return g_task_propagate_boolean (G_TASK (result), error);
811 iface = G_DRIVE_GET_IFACE (drive);
813 return (* iface->start_finish) (drive, result, error);
817 * g_drive_can_stop:
818 * @drive: a #GDrive.
820 * Checks if a drive can be stopped.
822 * Returns: %TRUE if the @drive can be stopped, %FALSE otherwise.
824 * Since: 2.22
826 gboolean
827 g_drive_can_stop (GDrive *drive)
829 GDriveIface *iface;
831 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
833 iface = G_DRIVE_GET_IFACE (drive);
835 if (iface->can_stop == NULL)
836 return FALSE;
838 return (* iface->can_stop) (drive);
842 * g_drive_stop:
843 * @drive: a #GDrive.
844 * @flags: flags affecting the unmount if required for stopping.
845 * @mount_operation: (nullable): a #GMountOperation or %NULL to avoid
846 * user interaction.
847 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
848 * @callback: (nullable): a #GAsyncReadyCallback, or %NULL.
849 * @user_data: user data to pass to @callback
851 * Asynchronously stops a drive.
853 * When the operation is finished, @callback will be called.
854 * You can then call g_drive_stop_finish() to obtain the
855 * result of the operation.
857 * Since: 2.22
859 void
860 g_drive_stop (GDrive *drive,
861 GMountUnmountFlags flags,
862 GMountOperation *mount_operation,
863 GCancellable *cancellable,
864 GAsyncReadyCallback callback,
865 gpointer user_data)
867 GDriveIface *iface;
869 g_return_if_fail (G_IS_DRIVE (drive));
871 iface = G_DRIVE_GET_IFACE (drive);
873 if (iface->stop == NULL)
875 g_task_report_new_error (drive, callback, user_data,
876 g_drive_start,
877 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
878 _("drive doesn’t implement stop"));
879 return;
882 (* iface->stop) (drive, flags, mount_operation, cancellable, callback, user_data);
886 * g_drive_stop_finish:
887 * @drive: a #GDrive.
888 * @result: a #GAsyncResult.
889 * @error: a #GError, or %NULL
891 * Finishes stopping a drive.
893 * Returns: %TRUE if the drive has been stopped successfully,
894 * %FALSE otherwise.
896 * Since: 2.22
898 gboolean
899 g_drive_stop_finish (GDrive *drive,
900 GAsyncResult *result,
901 GError **error)
903 GDriveIface *iface;
905 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
906 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
908 if (g_async_result_legacy_propagate_error (result, error))
909 return FALSE;
910 else if (g_async_result_is_tagged (result, g_drive_start))
911 return g_task_propagate_boolean (G_TASK (result), error);
913 iface = G_DRIVE_GET_IFACE (drive);
915 return (* iface->stop_finish) (drive, result, error);
919 * g_drive_get_sort_key:
920 * @drive: A #GDrive.
922 * Gets the sort key for @drive, if any.
924 * Returns: Sorting key for @drive or %NULL if no such key is available.
926 * Since: 2.32
928 const gchar *
929 g_drive_get_sort_key (GDrive *drive)
931 const gchar *ret = NULL;
932 GDriveIface *iface;
934 g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
936 iface = G_DRIVE_GET_IFACE (drive);
937 if (iface->get_sort_key != NULL)
938 ret = iface->get_sort_key (drive);
940 return ret;