Fix AKS -> ASK typo
[platform/upstream/glib.git] / gio / gmount.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  *         David Zeuthen <davidz@redhat.com>
22  */
23
24 #include <config.h>
25 #include "gmount.h"
26 #include "gmountprivate.h"
27 #include "gsimpleasyncresult.h"
28 #include "glibintl.h"
29
30 #include "gioalias.h"
31
32 /**
33  * SECTION:gmount
34  * @short_description: mount management
35  * 
36  * The #GMount interface represents user-visible mounts. Note, when
37  * porting from GnomeVFS, #GMount is the moral equivalent of
38  * #GnomeVFSVolume.
39  * 
40  * Unmounting a #GMount instance is an asynchronous operation. For
41  * more information about asynchronous operations, see #GAsyncReady
42  * and #GSimpleAsyncReady. To unmount a #GMount instance, first call
43  * g_mount_unmount() with (at least) the #GMount instance and a
44  * #GAsyncReadyCallback.  The callback will be fired when the
45  * operation has resolved (either with success or failure), and a
46  * #GAsyncReady structure will be passed to the callback.  That
47  * callback should then call g_mount_unmount_finish() with the #GMount
48  * and the #GAsyncReady data to see if the operation was completed
49  * successfully.  If an @error is present when
50  * g_mount_unmount_finish() is called, then it will be filled with any
51  * error information.
52  **/
53
54 static void g_mount_base_init (gpointer g_class);
55 static void g_mount_class_init (gpointer g_class,
56                                 gpointer class_data);
57
58 GType
59 g_mount_get_type (void)
60 {
61   static GType mount_type = 0;
62
63   if (! mount_type)
64     {
65       static const GTypeInfo mount_info =
66       {
67         sizeof (GMountIface), /* class_size */
68         g_mount_base_init,   /* base_init */
69         NULL,           /* base_finalize */
70         g_mount_class_init,
71         NULL,           /* class_finalize */
72         NULL,           /* class_data */
73         0,
74         0,              /* n_preallocs */
75         NULL
76       };
77
78       mount_type =
79         g_type_register_static (G_TYPE_INTERFACE, I_("GMount"),
80                                 &mount_info, 0);
81
82       g_type_interface_add_prerequisite (mount_type, G_TYPE_OBJECT);
83     }
84
85   return mount_type;
86 }
87
88 static void
89 g_mount_class_init (gpointer g_class,
90                     gpointer class_data)
91 {
92 }
93
94 static void
95 g_mount_base_init (gpointer g_class)
96 {
97   static gboolean initialized = FALSE;
98
99   if (! initialized)
100     {
101      /**
102       * GMount::changed:
103       * 
104       * Emitted when the mount has been changed.
105       **/
106       g_signal_new (I_("changed"),
107                     G_TYPE_MOUNT,
108                     G_SIGNAL_RUN_LAST,
109                     G_STRUCT_OFFSET (GMountIface, changed),
110                     NULL, NULL,
111                     g_cclosure_marshal_VOID__VOID,
112                     G_TYPE_NONE, 0);
113
114       initialized = TRUE;
115     }
116 }
117
118 /**
119  * g_mount_get_root:
120  * @mount: a #GMount.
121  * 
122  * Gets the root directory on @mount.
123  * 
124  * Returns: a #GFile.
125  **/
126 GFile *
127 g_mount_get_root (GMount *mount)
128 {
129   GMountIface *iface;
130
131   g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
132
133   iface = G_MOUNT_GET_IFACE (mount);
134
135   return (* iface->get_root) (mount);
136 }
137
138 /**
139  * g_mount_get_name:
140  * @mount: a #GMount.
141  * 
142  * Gets the name of @mount.
143  * 
144  * Returns: the name for the given @mount. The returned string should 
145  * be freed when no longer needed.
146  **/
147 char *
148 g_mount_get_name (GMount *mount)
149 {
150   GMountIface *iface;
151
152   g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
153
154   iface = G_MOUNT_GET_IFACE (mount);
155
156   return (* iface->get_name) (mount);
157 }
158
159 /**
160  * g_mount_get_icon:
161  * @mount: a #GMount.
162  * 
163  * Gets the icon for @mount.
164  * 
165  * Returns: a #GIcon.
166  **/
167 GIcon *
168 g_mount_get_icon (GMount *mount)
169 {
170   GMountIface *iface;
171
172   g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
173
174   iface = G_MOUNT_GET_IFACE (mount);
175
176   return (* iface->get_icon) (mount);
177 }
178   
179 /**
180  * g_mount_get_volume:
181  * @mount: a #GMount.
182  * 
183  * Gets the volume for the @mount.
184  * 
185  * Returns: a #GVolume or %NULL if @mount is not associated with a volume.
186  **/
187 GVolume *
188 g_mount_get_volume (GMount *mount)
189 {
190   GMountIface *iface;
191
192   g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
193
194   iface = G_MOUNT_GET_IFACE (mount);
195
196   return (* iface->get_volume) (mount);
197 }
198
199 /**
200  * g_mount_get_drive:
201  * @mount: a #GMount.
202  * 
203  * Gets the drive for the @mount.
204  *
205  * This is a convenience method for getting the #GVolume and then
206  * using that object to get the #GDrive.
207  * 
208  * Returns: a #GDrive or %NULL if @mount is not associated with a volume or a drive.
209  **/
210 GDrive *
211 g_mount_get_drive (GMount *mount)
212 {
213   GMountIface *iface;
214
215   g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
216
217   iface = G_MOUNT_GET_IFACE (mount);
218
219   return (* iface->get_drive) (mount);
220 }
221
222 /**
223  * g_mount_can_unmount: 
224  * @mount: a #GMount.
225  * 
226  * Checks if @mount can be mounted.
227  * 
228  * Returns: %TRUE if the @mount can be unmounted.
229  **/
230 gboolean
231 g_mount_can_unmount (GMount *mount)
232 {
233   GMountIface *iface;
234
235   g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
236
237   iface = G_MOUNT_GET_IFACE (mount);
238
239   return (* iface->can_unmount) (mount);
240 }
241
242 /**
243  * g_mount_unmount:
244  * @mount: a #GMount.
245  * @cancellable: optional #GCancellable object, %NULL to ignore.
246  * @callback: a #GAsyncReadyCallback.
247  * @user_data: user data passed to @callback.
248  * 
249  * Unmounts a mount. This is an asynchronous operation, and is 
250  * finished by calling g_mount_unmount_finish() with the @mount 
251  * and #GAsyncResults data returned in the @callback.
252  **/
253 void
254 g_mount_unmount (GMount             *mount,
255                  GCancellable        *cancellable,
256                  GAsyncReadyCallback  callback,
257                  gpointer             user_data)
258 {
259   GMountIface *iface;
260
261   g_return_if_fail (G_IS_MOUNT (mount));
262   
263   iface = G_MOUNT_GET_IFACE (mount);
264
265   if (iface->unmount == NULL)
266     {
267       g_simple_async_report_error_in_idle (G_OBJECT (mount),
268                                            callback, user_data,
269                                            G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
270                                            _("mount doesn't implement unmount"));
271       
272       return;
273     }
274   
275   (* iface->unmount) (mount, cancellable, callback, user_data);
276 }
277
278 /**
279  * g_mount_unmount_finish:
280  * @mount: a #GMount.
281  * @result: a #GAsyncResult.
282  * @error: a #GError location to store the error occuring, or %NULL to 
283  * ignore.
284  * 
285  * Finishes unmounting a mount. 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 mount was successfully unmounted. %FALSE otherwise.
289  **/
290 gboolean
291 g_mount_unmount_finish (GMount       *mount,
292                         GAsyncResult  *result,
293                         GError       **error)
294 {
295   GMountIface *iface;
296
297   g_return_val_if_fail (G_IS_MOUNT (mount), 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_MOUNT_GET_IFACE (mount);
308   return (* iface->unmount_finish) (mount, result, error);
309 }
310
311 #define __G_MOUNT_C__
312 #include "gioaliasdef.c"