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