Make GSettingsSchemaKey public
[platform/upstream/glib.git] / gio / gvfs.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 <string.h>
25 #include "gvfs.h"
26 #include "glib-private.h"
27 #include "glocalvfs.h"
28 #include "gresourcefile.h"
29 #include "giomodule-priv.h"
30 #include "glibintl.h"
31
32
33 /**
34  * SECTION:gvfs
35  * @short_description: Virtual File System
36  * @include: gio/gio.h
37  *
38  * Entry point for using GIO functionality.
39  *
40  */
41
42 G_DEFINE_TYPE (GVfs, g_vfs, G_TYPE_OBJECT);
43
44 static void
45 g_vfs_class_init (GVfsClass *klass)
46 {
47 }
48
49 static void
50 g_vfs_init (GVfs *vfs)
51 {
52 }
53
54 /**
55  * g_vfs_is_active:
56  * @vfs: a #GVfs.
57  *
58  * Checks if the VFS is active.
59  *
60  * Returns: %TRUE if construction of the @vfs was successful
61  *     and it is now active.
62  */
63 gboolean
64 g_vfs_is_active (GVfs *vfs)
65 {
66   GVfsClass *class;
67
68   g_return_val_if_fail (G_IS_VFS (vfs), FALSE);
69
70   class = G_VFS_GET_CLASS (vfs);
71
72   return (* class->is_active) (vfs);
73 }
74
75
76 /**
77  * g_vfs_get_file_for_path:
78  * @vfs: a #GVfs.
79  * @path: a string containing a VFS path.
80  *
81  * Gets a #GFile for @path.
82  *
83  * Returns: (transfer full): a #GFile.
84  *     Free the returned object with g_object_unref().
85  */
86 GFile *
87 g_vfs_get_file_for_path (GVfs       *vfs,
88                          const char *path)
89 {
90   GVfsClass *class;
91  
92   g_return_val_if_fail (G_IS_VFS (vfs), NULL);
93   g_return_val_if_fail (path != NULL, NULL);
94
95   class = G_VFS_GET_CLASS (vfs);
96
97   return (* class->get_file_for_path) (vfs, path);
98 }
99
100 /**
101  * g_vfs_get_file_for_uri:
102  * @vfs: a#GVfs.
103  * @uri: a string containing a URI
104  *
105  * Gets a #GFile for @uri.
106  *
107  * This operation never fails, but the returned object
108  * might not support any I/O operation if the URI
109  * is malformed or if the URI scheme is not supported.
110  *
111  * Returns: (transfer full): a #GFile.
112  *     Free the returned object with g_object_unref().
113  */
114 GFile *
115 g_vfs_get_file_for_uri (GVfs       *vfs,
116                         const char *uri)
117 {
118   GVfsClass *class;
119  
120   g_return_val_if_fail (G_IS_VFS (vfs), NULL);
121   g_return_val_if_fail (uri != NULL, NULL);
122
123   class = G_VFS_GET_CLASS (vfs);
124
125   /* This is an unfortunate placement, but we really
126    * need to check this before chaining to the vfs,
127    * because we want to support resource uris for
128    * all vfs:es, even those that predate resources.
129    */
130   if (g_str_has_prefix (uri, "resource:"))
131     return _g_resource_file_new (uri);
132
133   return (* class->get_file_for_uri) (vfs, uri);
134 }
135
136 /**
137  * g_vfs_get_supported_uri_schemes:
138  * @vfs: a #GVfs.
139  *
140  * Gets a list of URI schemes supported by @vfs.
141  *
142  * Returns: (transfer none): a %NULL-terminated array of strings.
143  *     The returned array belongs to GIO and must
144  *     not be freed or modified.
145  */
146 const gchar * const *
147 g_vfs_get_supported_uri_schemes (GVfs *vfs)
148 {
149   GVfsClass *class;
150
151   g_return_val_if_fail (G_IS_VFS (vfs), NULL);
152
153   class = G_VFS_GET_CLASS (vfs);
154
155   return (* class->get_supported_uri_schemes) (vfs);
156 }
157
158 /**
159  * g_vfs_parse_name:
160  * @vfs: a #GVfs.
161  * @parse_name: a string to be parsed by the VFS module.
162  *
163  * This operation never fails, but the returned object might
164  * not support any I/O operations if the @parse_name cannot
165  * be parsed by the #GVfs module.
166  *
167  * Returns: (transfer full): a #GFile for the given @parse_name.
168  *     Free the returned object with g_object_unref().
169  */
170 GFile *
171 g_vfs_parse_name (GVfs       *vfs,
172                   const char *parse_name)
173 {
174   GVfsClass *class;
175
176   g_return_val_if_fail (G_IS_VFS (vfs), NULL);
177   g_return_val_if_fail (parse_name != NULL, NULL);
178
179   class = G_VFS_GET_CLASS (vfs);
180
181   if (g_str_has_prefix (parse_name, "resource:"))
182     return _g_resource_file_new (parse_name);
183
184   return (* class->parse_name) (vfs, parse_name);
185 }
186
187 /**
188  * g_vfs_get_default:
189  *
190  * Gets the default #GVfs for the system.
191  *
192  * Returns: (transfer none): a #GVfs.
193  */
194 GVfs *
195 g_vfs_get_default (void)
196 {
197   if (GLIB_PRIVATE_CALL (g_check_setuid) ())
198     return g_vfs_get_local ();
199   return _g_io_module_get_default (G_VFS_EXTENSION_POINT_NAME,
200                                    "GIO_USE_VFS",
201                                    (GIOModuleVerifyFunc)g_vfs_is_active);
202 }
203
204 /**
205  * g_vfs_get_local:
206  *
207  * Gets the local #GVfs for the system.
208  *
209  * Returns: (transfer none): a #GVfs.
210  */
211 GVfs *
212 g_vfs_get_local (void)
213 {
214   static gsize vfs = 0;
215
216   if (g_once_init_enter (&vfs))
217     g_once_init_leave (&vfs, (gsize)_g_local_vfs_new ());
218
219   return G_VFS (vfs);
220 }