Clean up some docs
[platform/upstream/glib.git] / gio / gvolume.c
1 /* GIO - GLib Input, Output and Streaming Library
2  * 
3  * Copyright (C) 2006-2007 Red Hat, Inc.
4  *
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.
9  *
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.
14  *
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.
19  *
20  * Author: Alexander Larsson <alexl@redhat.com>
21  */
22
23 #include <config.h>
24 #include "gvolume.h"
25 #include "gvolumeprivate.h"
26 #include "gsimpleasyncresult.h"
27 #include "glibintl.h"
28
29 /**
30  * SECTION:gvolume
31  * @short_description: mounted volume management
32  * 
33  * Class for managing mounted volumes.
34  * 
35  * Unmounting volumes is an asynchronous operation. For more information about
36  * asynchronous operations, see #GAsyncReady and #GSimpleAsyncReady. To unmount a volume, 
37  * first call g_volume_unmount() with (at least) the volume and a #GAsyncReadyCallback.
38  * The callback will be fired when the operation has resolved (either with success or failure), 
39  * and a #GAsyncReady structure will be passed to the callback. 
40  * That callback should then call g_volume_unmount_finish() with
41  * the volume and the #GAsyncReady data to see if the operation was completed successfully.
42  * If an @error is present when g_volume_unmount_finish() is called, then it will
43  * be filled with any error information.
44  * 
45  * Ejecting volumes is also an asynchronous operation. 
46  * To eject a volume, call g_volume_eject() with (at least) the volume to eject 
47  * and a #GAsyncReadyCallback. The callback will be fired when the eject operation
48  * has resolved (either with success or failure), and a #GAsyncReady structure will
49  * be passed to the callback. That callback should then call g_volume_eject_finish()
50  * with the volume and the #GAsyncReady data to determine if the operation was completed
51  * successfully. If an @error is present when g_volume_eject_finish() is called, then
52  * it will be filled with any error information. 
53  *
54  **/
55
56 static void g_volume_base_init (gpointer g_class);
57 static void g_volume_class_init (gpointer g_class,
58                                  gpointer class_data);
59
60 GType
61 g_volume_get_type (void)
62 {
63   static GType volume_type = 0;
64
65   if (! volume_type)
66     {
67       static const GTypeInfo volume_info =
68       {
69         sizeof (GVolumeIface), /* class_size */
70         g_volume_base_init,   /* base_init */
71         NULL,           /* base_finalize */
72         g_volume_class_init,
73         NULL,           /* class_finalize */
74         NULL,           /* class_data */
75         0,
76         0,              /* n_preallocs */
77         NULL
78       };
79
80       volume_type =
81         g_type_register_static (G_TYPE_INTERFACE, I_("GVolume"),
82                                 &volume_info, 0);
83
84       g_type_interface_add_prerequisite (volume_type, G_TYPE_OBJECT);
85     }
86
87   return volume_type;
88 }
89
90 static void
91 g_volume_class_init (gpointer g_class,
92                    gpointer class_data)
93 {
94 }
95
96 static void
97 g_volume_base_init (gpointer g_class)
98 {
99   static gboolean initialized = FALSE;
100
101   if (! initialized)
102     {
103      /**
104       * GVolume::changed:
105       * 
106       * Emitted when the volume has been changed.
107       **/
108       g_signal_new (I_("changed"),
109                     G_TYPE_VOLUME,
110                     G_SIGNAL_RUN_LAST,
111                     G_STRUCT_OFFSET (GVolumeIface, changed),
112                     NULL, NULL,
113                     g_cclosure_marshal_VOID__VOID,
114                     G_TYPE_NONE, 0);
115
116       initialized = TRUE;
117     }
118 }
119
120 /**
121  * g_volume_get_root:
122  * @volume: a #GVolume.
123  * 
124  * Gets the root directory on @volume.
125  * 
126  * Returns: a #GFile.
127  **/
128 GFile *
129 g_volume_get_root (GVolume *volume)
130 {
131   GVolumeIface *iface;
132
133   g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
134
135   iface = G_VOLUME_GET_IFACE (volume);
136
137   return (* iface->get_root) (volume);
138 }
139
140 /**
141  * g_volume_get_name:
142  * @volume: a #GVolume.
143  * 
144  * Gets the name of @volume.
145  * 
146  * Returns: the name for the given @volume. The returned string should 
147  * be freed when no longer needed.
148  **/
149 char *
150 g_volume_get_name (GVolume *volume)
151 {
152   GVolumeIface *iface;
153
154   g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
155
156   iface = G_VOLUME_GET_IFACE (volume);
157
158   return (* iface->get_name) (volume);
159 }
160
161 /**
162  * g_volume_get_icon:
163  * @volume: a #GVolume.
164  * 
165  * Gets the icon for @volume.
166  * 
167  * Returns: a #GIcon.
168  **/
169 GIcon *
170 g_volume_get_icon (GVolume *volume)
171 {
172   GVolumeIface *iface;
173
174   g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
175
176   iface = G_VOLUME_GET_IFACE (volume);
177
178   return (* iface->get_icon) (volume);
179 }
180   
181 /**
182  * g_volume_get_drive:
183  * @volume: a #GVolume.
184  * 
185  * Gets the drive for the @volume.
186  * 
187  * Returns: a #GDrive.
188  **/
189 GDrive *
190 g_volume_get_drive (GVolume *volume)
191 {
192   GVolumeIface *iface;
193
194   g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
195
196   iface = G_VOLUME_GET_IFACE (volume);
197
198   return (* iface->get_drive) (volume);
199 }
200
201 /**
202  * g_volume_can_unmount: 
203  * @volume: a #GVolume.
204  * 
205  * Checks if @volume can be mounted.
206  * 
207  * Returns: %TRUE if the @volume can be unmounted.
208  **/
209 gboolean
210 g_volume_can_unmount (GVolume *volume)
211 {
212   GVolumeIface *iface;
213
214   g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
215
216   iface = G_VOLUME_GET_IFACE (volume);
217
218   return (* iface->can_unmount) (volume);
219 }
220
221 /**
222  * g_volume_can_eject:
223  * @volume: a #GVolume.
224  * 
225  * Checks if @volume can be ejected.
226  * 
227  * Returns: %TRUE if the @volume can be ejected.
228  **/
229 gboolean
230 g_volume_can_eject (GVolume *volume)
231 {
232   GVolumeIface *iface;
233
234   g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
235
236   iface = G_VOLUME_GET_IFACE (volume);
237
238   return (* iface->can_eject) (volume);
239 }
240
241 /**
242  * g_volume_unmount:
243  * @volume: a #GVolume.
244  * @cancellable: optional #GCancellable object, %NULL to ignore.
245  * @callback: a #GAsyncReadyCallback.
246  * @user_data: user data passed to @callback.
247  * 
248  * Unmounts a volume. This is an asynchronous operation, and is finished by calling 
249  * g_volume_unmount_finish() with the @volume and #GAsyncResults data returned in the 
250  * @callback.
251  * 
252  **/
253 void
254 g_volume_unmount (GVolume *volume,
255                   GCancellable *cancellable,
256                   GAsyncReadyCallback callback,
257                   gpointer user_data)
258 {
259   GVolumeIface *iface;
260
261   g_return_if_fail (G_IS_VOLUME (volume));
262   
263   iface = G_VOLUME_GET_IFACE (volume);
264
265   if (iface->unmount == NULL)
266     {
267       g_simple_async_report_error_in_idle (G_OBJECT (volume),
268                                            callback, user_data,
269                                            G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
270                                            _("volume doesn't implement unmount"));
271       
272       return;
273     }
274   
275   (* iface->unmount) (volume, cancellable, callback, user_data);
276 }
277
278 /**
279  * g_volume_unmount_finish:
280  * @volume: a #GVolume.
281  * @result: a #GAsyncResult.
282  * @error: a #GError location to store the error occuring, or %NULL to 
283  * ignore.
284  * 
285  * Finishes unmounting a volume. If any errors occured during the operation, 
286  * @error will be set to contain the errors and %FALSE will be returned.
287  * 
288  * Returns: %TRUE if the volume was successfully unmounted. %FALSE otherwise.
289  **/
290 gboolean
291 g_volume_unmount_finish (GVolume              *volume,
292                          GAsyncResult         *result,
293                          GError              **error)
294 {
295   GVolumeIface *iface;
296
297   g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
298   g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
299
300   if (G_IS_SIMPLE_ASYNC_RESULT (result))
301     {
302       GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
303       if (g_simple_async_result_propagate_error (simple, error))
304         return FALSE;
305     }
306   
307   iface = G_VOLUME_GET_IFACE (volume);
308   return (* iface->unmount_finish) (volume, result, error);
309 }
310
311 /**
312  * g_volume_eject:
313  * @volume: a #GVolume.
314  * @cancellable: optional #GCancellable object, %NULL to ignore. 
315  * @callback: a #GAsyncReadyCallback.
316  * @user_data: user data passed to @callback.
317  * 
318  * Ejects a volume. This is an asynchronous operation, and is finished
319  * by calling g_volume_eject_finish() from the @callback with the @volume and 
320  * #GAsyncResults returned in the callback.
321  * 
322  **/
323 void
324 g_volume_eject (GVolume         *volume,
325                 GCancellable *cancellable,
326                 GAsyncReadyCallback  callback,
327                 gpointer         user_data)
328 {
329   GVolumeIface *iface;
330
331   g_return_if_fail (G_IS_VOLUME (volume));
332
333   iface = G_VOLUME_GET_IFACE (volume);
334
335   if (iface->eject == NULL)
336     {
337       g_simple_async_report_error_in_idle (G_OBJECT (volume),
338                                            callback, user_data,
339                                            G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
340                                            _("volume doesn't implement eject"));
341       
342       return;
343     }
344   
345   (* iface->eject) (volume, cancellable, callback, user_data);
346 }
347
348 /**
349  * g_volume_eject_finish:
350  * @volume: a #GVolume.
351  * @result: a #GAsyncResult.
352  * @error: a #GError location to store the error occuring, or %NULL to 
353  * ignore.
354  * 
355  * Finishes ejecting the volume. If any errors occured during the operation, 
356  * @error will be set to contain the errors and %FALSE will be returned.
357  * 
358  * Returns: %TRUE if the volume was successfully ejected. %FALSE otherwise.
359  **/
360 gboolean
361 g_volume_eject_finish (GVolume              *volume,
362                        GAsyncResult         *result,
363                        GError              **error)
364 {
365   GVolumeIface *iface;
366
367   g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
368   g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
369
370   if (G_IS_SIMPLE_ASYNC_RESULT (result))
371     {
372       GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
373       if (g_simple_async_result_propagate_error (simple, error))
374         return FALSE;
375     }
376   
377   iface = G_VOLUME_GET_IFACE (volume);
378   return (* iface->eject_finish) (volume, result, error);
379 }