1 /* GIO - GLib Input, Output and Streaming Library
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>
25 #include "gvolumeprivate.h"
26 #include "gsimpleasyncresult.h"
29 static void g_volume_base_init (gpointer g_class);
30 static void g_volume_class_init (gpointer g_class,
34 g_volume_get_type (void)
36 static GType volume_type = 0;
40 static const GTypeInfo volume_info =
42 sizeof (GVolumeIface), /* class_size */
43 g_volume_base_init, /* base_init */
44 NULL, /* base_finalize */
46 NULL, /* class_finalize */
47 NULL, /* class_data */
54 g_type_register_static (G_TYPE_INTERFACE, I_("GVolume"),
57 g_type_interface_add_prerequisite (volume_type, G_TYPE_OBJECT);
64 g_volume_class_init (gpointer g_class,
70 g_volume_base_init (gpointer g_class)
72 static gboolean initialized = FALSE;
76 g_signal_new (I_("changed"),
79 G_STRUCT_OFFSET (GVolumeIface, changed),
81 g_cclosure_marshal_VOID__VOID,
90 * @volume: a #GVolume.
96 g_volume_get_root (GVolume *volume)
100 g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
102 iface = G_VOLUME_GET_IFACE (volume);
104 return (* iface->get_root) (volume);
109 * @volume: a #GVolume.
111 * Returns the name for the given @volume.
113 * The returned string should be freed when no longer needed.
117 g_volume_get_name (GVolume *volume)
121 g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
123 iface = G_VOLUME_GET_IFACE (volume);
125 return (* iface->get_name) (volume);
132 * Returns the #GIcon for the given @volume.
136 g_volume_get_icon (GVolume *volume)
140 g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
142 iface = G_VOLUME_GET_IFACE (volume);
144 return (* iface->get_icon) (volume);
148 * g_volume_get_drive:
151 * Returns the #GDrive for the given @volume.
155 g_volume_get_drive (GVolume *volume)
159 g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
161 iface = G_VOLUME_GET_IFACE (volume);
163 return (* iface->get_drive) (volume);
167 * g_volume_can_unmount:
170 * Returns %TRUE if the @volume can be unmounted.
173 g_volume_can_unmount (GVolume *volume)
177 g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
179 iface = G_VOLUME_GET_IFACE (volume);
181 return (* iface->can_unmount) (volume);
185 * g_volume_can_eject:
188 * Returns %TRUE if the @volume can be ejected.
192 g_volume_can_eject (GVolume *volume)
196 g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
198 iface = G_VOLUME_GET_IFACE (volume);
200 return (* iface->can_eject) (volume);
212 g_volume_unmount (GVolume *volume,
213 GCancellable *cancellable,
214 GAsyncReadyCallback callback,
219 g_return_if_fail (G_IS_VOLUME (volume));
221 iface = G_VOLUME_GET_IFACE (volume);
223 if (iface->unmount == NULL)
225 g_simple_async_report_error_in_idle (G_OBJECT (volume),
227 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
228 _("volume doesn't implement unmount"));
233 (* iface->unmount) (volume, cancellable, callback, user_data);
237 * g_volume_unmount_finish:
240 * @error: a #GError location to store the error occuring, or %NULL to
246 g_volume_unmount_finish (GVolume *volume,
247 GAsyncResult *result,
252 g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
253 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
255 if (G_IS_SIMPLE_ASYNC_RESULT (result))
257 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
258 if (g_simple_async_result_propagate_error (simple, error))
262 iface = G_VOLUME_GET_IFACE (volume);
263 return (* iface->unmount_finish) (volume, result, error);
274 g_volume_eject (GVolume *volume,
275 GCancellable *cancellable,
276 GAsyncReadyCallback callback,
281 g_return_if_fail (G_IS_VOLUME (volume));
283 iface = G_VOLUME_GET_IFACE (volume);
285 if (iface->eject == NULL)
287 g_simple_async_report_error_in_idle (G_OBJECT (volume),
289 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
290 _("volume doesn't implement eject"));
295 (* iface->eject) (volume, cancellable, callback, user_data);
299 * g_volume_eject_finish:
302 * @error: a #GError location to store the error occuring, or %NULL to
308 g_volume_eject_finish (GVolume *volume,
309 GAsyncResult *result,
314 g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
315 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
317 if (G_IS_SIMPLE_ASYNC_RESULT (result))
319 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
320 if (g_simple_async_result_propagate_error (simple, error))
324 iface = G_VOLUME_GET_IFACE (volume);
325 return (* iface->eject_finish) (volume, result, error);