Another round of trivial doc fixes
[platform/upstream/glib.git] / gio / gdrive.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 "gdrive.h"
25 #include "gsimpleasyncresult.h"
26 #include "glibintl.h"
27
28 /**
29  * SECTION:gdrive
30  * @short_description: Virtual File System drive management
31  * @include: gio/gdrive.h
32  * 
33  * #GDrive manages drive operations from GVFS, including volume mounting
34  * and ejecting, and getting the drive's name and icon. 
35  * 
36  **/
37
38 static void g_drive_base_init (gpointer g_class);
39 static void g_drive_class_init (gpointer g_class,
40                                  gpointer class_data);
41
42 GType
43 g_drive_get_type (void)
44 {
45   static GType drive_type = 0;
46
47   if (! drive_type)
48     {
49       static const GTypeInfo drive_info =
50       {
51         sizeof (GDriveIface), /* class_size */
52         g_drive_base_init,   /* base_init */
53         NULL,           /* base_finalize */
54         g_drive_class_init,
55         NULL,           /* class_finalize */
56         NULL,           /* class_data */
57         0,
58         0,              /* n_preallocs */
59         NULL
60       };
61
62       drive_type =
63         g_type_register_static (G_TYPE_INTERFACE, I_("GDrive"),
64                                 &drive_info, 0);
65
66       g_type_interface_add_prerequisite (drive_type, G_TYPE_OBJECT);
67     }
68
69   return drive_type;
70 }
71
72 static void
73 g_drive_class_init (gpointer g_class,
74                    gpointer class_data)
75 {
76 }
77
78 static void
79 g_drive_base_init (gpointer g_class)
80 {
81   static gboolean initialized = FALSE;
82
83   if (! initialized)
84     {
85       /**
86       * GDrive::changed:
87       * @volume: a #GVolume.
88       * 
89       * Emitted when the drive's state has changed.
90       * 
91       **/
92       g_signal_new (I_("changed"),
93                     G_TYPE_DRIVE,
94                     G_SIGNAL_RUN_LAST,
95                     G_STRUCT_OFFSET (GDriveIface, changed),
96                     NULL, NULL,
97                     g_cclosure_marshal_VOID__VOID,
98                     G_TYPE_NONE, 0);
99
100       initialized = TRUE;
101     }
102 }
103
104 /**
105  * g_drive_get_name:
106  * @drive: a #GDrive.
107  * 
108  * Gets the name of @drive.
109  *
110  * Returns: a string containing @drive's name. The returned 
111  *     string should be freed when no longer needed.
112  **/
113 char *
114 g_drive_get_name (GDrive *drive)
115 {
116   GDriveIface *iface;
117
118   g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
119
120   iface = G_DRIVE_GET_IFACE (drive);
121
122   return (* iface->get_name) (drive);
123 }
124
125 /**
126  * g_drive_get_icon:
127  * @drive: a #GDrive.
128  * 
129  * Gets the icon for @drive.
130  * 
131  * Returns: #GIcon for the @drive.
132  **/
133 GIcon *
134 g_drive_get_icon (GDrive *drive)
135 {
136   GDriveIface *iface;
137   
138   g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
139
140   iface = G_DRIVE_GET_IFACE (drive);
141
142   return (* iface->get_icon) (drive);
143 }
144
145 /**
146  * g_drive_has_volumes:
147  * @drive: a #GDrive.
148  * 
149  * Checks if a drive has any volumes.
150  * 
151  * Returns: %TRUE if @drive contains volumes, %FALSE otherwise.
152  **/
153 gboolean
154 g_drive_has_volumes (GDrive *drive)
155 {
156   GDriveIface *iface;
157
158   g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
159
160   iface = G_DRIVE_GET_IFACE (drive);
161
162   return (* iface->has_volumes) (drive);
163 }
164
165 /**
166  * g_drive_get_volumes:
167  * @drive: a #GDrive.
168  * 
169  * Gets a list of volumes for a drive.
170  * 
171  * Returns: #GList containing any #GVolume<!---->s on the given @drive.
172  * NOTE: Fact-check this.
173  **/
174 GList *
175 g_drive_get_volumes (GDrive *drive)
176 {
177   GDriveIface *iface;
178
179   g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
180
181   iface = G_DRIVE_GET_IFACE (drive);
182
183   return (* iface->get_volumes) (drive);
184 }
185
186 /**
187  * g_drive_is_automounted:
188  * @drive: a #GDrive.
189  * 
190  * Checks if a drive was automatically mounted, e.g. by HAL.
191  * 
192  * Returns: %TRUE if the drive was automounted. %FALSE otherwise.
193  **/
194 gboolean
195 g_drive_is_automounted (GDrive *drive)
196 {
197   GDriveIface *iface;
198
199   g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
200
201   iface = G_DRIVE_GET_IFACE (drive);
202
203   return (* iface->is_automounted) (drive);
204 }
205
206 /**
207  * g_drive_can_mount:
208  * @drive: a #GDrive.
209  * 
210  * Checks if a drive can be mounted.
211  * 
212  * Returns: %TRUE if the @drive can be mounted. %FALSE otherwise.
213  **/
214 gboolean
215 g_drive_can_mount (GDrive *drive)
216 {
217   GDriveIface *iface;
218
219   g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
220
221   iface = G_DRIVE_GET_IFACE (drive);
222
223   if (iface->can_mount == NULL)
224     return FALSE;
225
226   return (* iface->can_mount) (drive);
227 }
228
229 /**
230  * g_drive_can_eject:
231  * @drive: pointer to a #GDrive.
232  * 
233  * Checks if a drive can be ejected.
234  * 
235  * Returns: %TRUE if the @drive can be ejected. %FALSE otherwise.
236  **/
237 gboolean
238 g_drive_can_eject (GDrive *drive)
239 {
240   GDriveIface *iface;
241
242   g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
243
244   iface = G_DRIVE_GET_IFACE (drive);
245
246   if (iface->can_eject == NULL)
247     return FALSE;
248
249   return (* iface->can_eject) (drive);
250 }
251
252 /**
253  * g_drive_mount:
254  * @drive: a #GDrive.
255  * @mount_operation: a #GMountOperation.
256  * @cancellable: optional #GCancellable object, %NULL to ignore.
257  * @callback: a #GAsyncReadyCallback.
258  * @user_data: a #gpointer.
259  * 
260  * Mounts a drive.
261  * 
262  **/
263 void
264 g_drive_mount (GDrive         *drive,
265                GMountOperation *mount_operation,
266                GCancellable *cancellable,
267                GAsyncReadyCallback callback,
268                gpointer         user_data)
269 {
270   GDriveIface *iface;
271
272   g_return_if_fail (G_IS_DRIVE (drive));
273   g_return_if_fail (G_IS_MOUNT_OPERATION (mount_operation));
274
275   iface = G_DRIVE_GET_IFACE (drive);
276
277   if (iface->mount == NULL)
278     {
279       g_simple_async_report_error_in_idle (G_OBJECT (drive), callback, user_data,
280                                            G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
281                                            _("drive doesn't implement mount"));
282       
283       return;
284     }
285   
286   (* iface->mount) (drive, mount_operation, cancellable, callback, user_data);
287 }
288
289 /**
290  * g_drive_mount_finish:
291  * @drive: pointer to a #GDrive.
292  * @result: a #GAsyncResult.
293  * @error: a #GError.
294  * 
295  * Finishes mounting a drive.
296  * 
297  * Returns: %TRUE, %FALSE if operation failed.
298  **/
299 gboolean
300 g_drive_mount_finish (GDrive               *drive,
301                       GAsyncResult         *result,
302                       GError              **error)
303 {
304   GDriveIface *iface;
305
306   g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
307   g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
308
309   if (G_IS_SIMPLE_ASYNC_RESULT (result))
310     {
311       GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
312       if (g_simple_async_result_propagate_error (simple, error))
313         return FALSE;
314     }
315   
316   iface = G_DRIVE_GET_IFACE (drive);
317   return (* iface->mount_finish) (drive, result, error);
318 }
319
320 /**
321  * g_drive_eject:
322  * @drive: a #GDrive.
323  * @cancellable: optional #GCancellable object, %NULL to ignore.
324  * @callback: a #GAsyncReadyCallback.
325  * @user_data: a #gpointer.
326  * 
327  * Ejects a drive.
328  * 
329  **/
330 void
331 g_drive_eject (GDrive         *drive,
332                GCancellable *cancellable,
333                GAsyncReadyCallback  callback,
334                gpointer         user_data)
335 {
336   GDriveIface *iface;
337
338   g_return_if_fail (G_IS_DRIVE (drive));
339
340   iface = G_DRIVE_GET_IFACE (drive);
341
342   if (iface->eject == NULL)
343     {
344       g_simple_async_report_error_in_idle (G_OBJECT (drive), callback, user_data,
345                                            G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
346                                            _("drive doesn't implement eject"));
347       
348       return;
349     }
350   
351   (* iface->eject) (drive, cancellable, callback, user_data);
352 }
353
354 /**
355  * g_drive_eject_finish
356  * @drive: a #GDrive.
357  * @result: a #GAsyncResult.
358  * @error: a #GError.
359  * 
360  * Finishes ejecting a drive.
361  * 
362  * Returns: %TRUE if the drive has been ejected successfully,
363  * %FALSE otherwise.
364  **/
365 gboolean
366 g_drive_eject_finish (GDrive               *drive,
367                       GAsyncResult         *result,
368                       GError              **error)
369 {
370   GDriveIface *iface;
371
372   g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
373   g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
374
375   if (G_IS_SIMPLE_ASYNC_RESULT (result))
376     {
377       GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
378       if (g_simple_async_result_propagate_error (simple, error))
379         return FALSE;
380     }
381   
382   iface = G_DRIVE_GET_IFACE (drive);
383   
384   return (* iface->mount_finish) (drive, result, error);
385 }