gio/ docs/reference/gio Merged gio-standalone into glib.
[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 static void g_volume_base_init (gpointer g_class);
30 static void g_volume_class_init (gpointer g_class,
31                                  gpointer class_data);
32
33 GType
34 g_volume_get_type (void)
35 {
36   static GType volume_type = 0;
37
38   if (! volume_type)
39     {
40       static const GTypeInfo volume_info =
41       {
42         sizeof (GVolumeIface), /* class_size */
43         g_volume_base_init,   /* base_init */
44         NULL,           /* base_finalize */
45         g_volume_class_init,
46         NULL,           /* class_finalize */
47         NULL,           /* class_data */
48         0,
49         0,              /* n_preallocs */
50         NULL
51       };
52
53       volume_type =
54         g_type_register_static (G_TYPE_INTERFACE, I_("GVolume"),
55                                 &volume_info, 0);
56
57       g_type_interface_add_prerequisite (volume_type, G_TYPE_OBJECT);
58     }
59
60   return volume_type;
61 }
62
63 static void
64 g_volume_class_init (gpointer g_class,
65                    gpointer class_data)
66 {
67 }
68
69 static void
70 g_volume_base_init (gpointer g_class)
71 {
72   static gboolean initialized = FALSE;
73
74   if (! initialized)
75     {
76       g_signal_new (I_("changed"),
77                     G_TYPE_VOLUME,
78                     G_SIGNAL_RUN_LAST,
79                     G_STRUCT_OFFSET (GVolumeIface, changed),
80                     NULL, NULL,
81                     g_cclosure_marshal_VOID__VOID,
82                     G_TYPE_NONE, 0);
83
84       initialized = TRUE;
85     }
86 }
87
88 /**
89  * g_volume_get_root:
90  * @volume: a #GVolume.
91  * 
92  * Returns a #GFile.
93  * 
94  **/
95 GFile *
96 g_volume_get_root (GVolume *volume)
97 {
98   GVolumeIface *iface;
99
100   g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
101
102   iface = G_VOLUME_GET_IFACE (volume);
103
104   return (* iface->get_root) (volume);
105 }
106
107 /**
108  * g_volume_get_name:
109  * @volume: a #GVolume.
110  * 
111  * Returns the name for the given @volume. 
112  * 
113  * The returned string should be freed when no longer needed.
114  * 
115  **/
116 char *
117 g_volume_get_name (GVolume *volume)
118 {
119   GVolumeIface *iface;
120
121   g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
122
123   iface = G_VOLUME_GET_IFACE (volume);
124
125   return (* iface->get_name) (volume);
126 }
127
128 /**
129  * g_volume_get_icon:
130  * @volume:
131  * 
132  * Returns the #GIcon for the given @volume.
133  * 
134  **/
135 GIcon *
136 g_volume_get_icon (GVolume *volume)
137 {
138   GVolumeIface *iface;
139
140   g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
141
142   iface = G_VOLUME_GET_IFACE (volume);
143
144   return (* iface->get_icon) (volume);
145 }
146   
147 /**
148  * g_volume_get_drive:
149  * @volume:
150  * 
151  * Returns the #GDrive for the given @volume.
152  * 
153  **/
154 GDrive *
155 g_volume_get_drive (GVolume *volume)
156 {
157   GVolumeIface *iface;
158
159   g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
160
161   iface = G_VOLUME_GET_IFACE (volume);
162
163   return (* iface->get_drive) (volume);
164 }
165
166 /**
167  * g_volume_can_unmount: 
168  * @volume:
169  * 
170  * Returns %TRUE if the @volume can be unmounted.
171  **/
172 gboolean
173 g_volume_can_unmount (GVolume *volume)
174 {
175   GVolumeIface *iface;
176
177   g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
178
179   iface = G_VOLUME_GET_IFACE (volume);
180
181   return (* iface->can_unmount) (volume);
182 }
183
184 /**
185  * g_volume_can_eject:
186  * @volume:
187  * 
188  * Returns %TRUE if the @volume can be ejected.
189  * 
190  **/
191 gboolean
192 g_volume_can_eject (GVolume *volume)
193 {
194   GVolumeIface *iface;
195
196   g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
197
198   iface = G_VOLUME_GET_IFACE (volume);
199
200   return (* iface->can_eject) (volume);
201 }
202
203 /**
204  * g_volume_unmount:
205  * @volume:
206  * @callback:
207  * @user_data:
208  * 
209  * 
210  **/
211 void
212 g_volume_unmount (GVolume *volume,
213                   GCancellable *cancellable,
214                   GAsyncReadyCallback callback,
215                   gpointer user_data)
216 {
217   GVolumeIface *iface;
218
219   g_return_if_fail (G_IS_VOLUME (volume));
220   
221   iface = G_VOLUME_GET_IFACE (volume);
222
223   if (iface->unmount == NULL)
224     {
225       g_simple_async_report_error_in_idle (G_OBJECT (volume),
226                                            callback, user_data,
227                                            G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
228                                            _("volume doesn't implement unmount"));
229       
230       return;
231     }
232   
233   (* iface->unmount) (volume, cancellable, callback, user_data);
234 }
235
236 /**
237  * g_volume_unmount_finish:
238  * @volume:
239  * @result:
240  * @error: a #GError location to store the error occuring, or %NULL to 
241  * ignore.
242  * Return:
243  * 
244  **/
245 gboolean
246 g_volume_unmount_finish (GVolume              *volume,
247                          GAsyncResult         *result,
248                          GError              **error)
249 {
250   GVolumeIface *iface;
251
252   g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
253   g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
254
255   if (G_IS_SIMPLE_ASYNC_RESULT (result))
256     {
257       GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
258       if (g_simple_async_result_propagate_error (simple, error))
259         return FALSE;
260     }
261   
262   iface = G_VOLUME_GET_IFACE (volume);
263   return (* iface->unmount_finish) (volume, result, error);
264 }
265
266 /**
267  * g_volume_eject:
268  * @volume:
269  * @callback:
270  * @user_data:
271  * 
272  **/
273 void
274 g_volume_eject (GVolume         *volume,
275                 GCancellable *cancellable,
276                 GAsyncReadyCallback  callback,
277                 gpointer         user_data)
278 {
279   GVolumeIface *iface;
280
281   g_return_if_fail (G_IS_VOLUME (volume));
282
283   iface = G_VOLUME_GET_IFACE (volume);
284
285   if (iface->eject == NULL)
286     {
287       g_simple_async_report_error_in_idle (G_OBJECT (volume),
288                                            callback, user_data,
289                                            G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
290                                            _("volume doesn't implement eject"));
291       
292       return;
293     }
294   
295   (* iface->eject) (volume, cancellable, callback, user_data);
296 }
297
298 /**
299  * g_volume_eject_finish:
300  * @volume:
301  * @result:
302  * @error: a #GError location to store the error occuring, or %NULL to 
303  * ignore.
304  * Returns: 
305  * 
306  **/
307 gboolean
308 g_volume_eject_finish (GVolume              *volume,
309                        GAsyncResult         *result,
310                        GError              **error)
311 {
312   GVolumeIface *iface;
313
314   g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
315   g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
316
317   if (G_IS_SIMPLE_ASYNC_RESULT (result))
318     {
319       GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
320       if (g_simple_async_result_propagate_error (simple, error))
321         return FALSE;
322     }
323   
324   iface = G_VOLUME_GET_IFACE (volume);
325   return (* iface->eject_finish) (volume, result, error);
326 }