Use GTestDBus in all GDBus unit tests
[glib.git] / gio / gvfs.c
blobdda8afb732865c8ad18dd6e401324d43b6fd4697
1 /* GIO - GLib Input, Output and Streaming Library
2 *
3 * Copyright (C) 2006-2007 Red Hat, Inc.
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.
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.
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.
20 * Author: Alexander Larsson <alexl@redhat.com>
23 #include "config.h"
24 #include <string.h>
25 #include "gvfs.h"
26 #include "glocalvfs.h"
27 #include "gresourcefile.h"
28 #include "giomodule-priv.h"
29 #include "glibintl.h"
32 /**
33 * SECTION:gvfs
34 * @short_description: Virtual File System
35 * @include: gio/gio.h
37 * Entry point for using GIO functionality.
39 **/
41 G_DEFINE_TYPE (GVfs, g_vfs, G_TYPE_OBJECT);
43 static void
44 g_vfs_class_init (GVfsClass *klass)
48 static void
49 g_vfs_init (GVfs *vfs)
53 /**
54 * g_vfs_is_active:
55 * @vfs: a #GVfs.
57 * Checks if the VFS is active.
59 * Returns: %TRUE if construction of the @vfs was successful and it is now active.
60 **/
61 gboolean
62 g_vfs_is_active (GVfs *vfs)
64 GVfsClass *class;
66 g_return_val_if_fail (G_IS_VFS (vfs), FALSE);
68 class = G_VFS_GET_CLASS (vfs);
70 return (* class->is_active) (vfs);
74 /**
75 * g_vfs_get_file_for_path:
76 * @vfs: a #GVfs.
77 * @path: a string containing a VFS path.
79 * Gets a #GFile for @path.
81 * Returns: (transfer full): a #GFile.
82 * Free the returned object with g_object_unref().
83 **/
84 GFile *
85 g_vfs_get_file_for_path (GVfs *vfs,
86 const char *path)
88 GVfsClass *class;
90 g_return_val_if_fail (G_IS_VFS (vfs), NULL);
91 g_return_val_if_fail (path != NULL, NULL);
93 class = G_VFS_GET_CLASS (vfs);
95 return (* class->get_file_for_path) (vfs, path);
98 /**
99 * g_vfs_get_file_for_uri:
100 * @vfs: a#GVfs.
101 * @uri: a string containing a URI
103 * Gets a #GFile for @uri.
105 * This operation never fails, but the returned object
106 * might not support any I/O operation if the URI
107 * is malformed or if the URI scheme is not supported.
109 * Returns: (transfer full): a #GFile.
110 * Free the returned object with g_object_unref().
112 GFile *
113 g_vfs_get_file_for_uri (GVfs *vfs,
114 const char *uri)
116 GVfsClass *class;
118 g_return_val_if_fail (G_IS_VFS (vfs), NULL);
119 g_return_val_if_fail (uri != NULL, NULL);
121 class = G_VFS_GET_CLASS (vfs);
123 /* This is an unfortunate placement, but we really
124 need to check this before chaining to the vfs,
125 because we want to support resource uris for
126 all vfs:es, even those that predate resources. */
127 if (g_str_has_prefix (uri, "resource:"))
128 return _g_resource_file_new (uri);
130 return (* class->get_file_for_uri) (vfs, uri);
134 * g_vfs_get_supported_uri_schemes:
135 * @vfs: a #GVfs.
137 * Gets a list of URI schemes supported by @vfs.
139 * Returns: (transfer none): a %NULL-terminated array of strings.
140 * The returned array belongs to GIO and must
141 * not be freed or modified.
143 const gchar * const *
144 g_vfs_get_supported_uri_schemes (GVfs *vfs)
146 GVfsClass *class;
148 g_return_val_if_fail (G_IS_VFS (vfs), NULL);
150 class = G_VFS_GET_CLASS (vfs);
152 return (* class->get_supported_uri_schemes) (vfs);
156 * g_vfs_parse_name:
157 * @vfs: a #GVfs.
158 * @parse_name: a string to be parsed by the VFS module.
160 * This operation never fails, but the returned object might
161 * not support any I/O operations if the @parse_name cannot
162 * be parsed by the #GVfs module.
164 * Returns: (transfer full): a #GFile for the given @parse_name.
165 * Free the returned object with g_object_unref().
167 GFile *
168 g_vfs_parse_name (GVfs *vfs,
169 const char *parse_name)
171 GVfsClass *class;
173 g_return_val_if_fail (G_IS_VFS (vfs), NULL);
174 g_return_val_if_fail (parse_name != NULL, NULL);
176 class = G_VFS_GET_CLASS (vfs);
178 if (g_str_has_prefix (parse_name, "resource:"))
179 return _g_resource_file_new (parse_name);
181 return (* class->parse_name) (vfs, parse_name);
185 * g_vfs_get_default:
187 * Gets the default #GVfs for the system.
189 * Returns: (transfer none): a #GVfs.
191 GVfs *
192 g_vfs_get_default (void)
194 return _g_io_module_get_default (G_VFS_EXTENSION_POINT_NAME,
195 "GIO_USE_VFS",
196 (GIOModuleVerifyFunc)g_vfs_is_active);
200 * g_vfs_get_local:
202 * Gets the local #GVfs for the system.
204 * Returns: (transfer none): a #GVfs.
206 GVfs *
207 g_vfs_get_local (void)
209 static gsize vfs = 0;
211 if (g_once_init_enter (&vfs))
212 g_once_init_leave (&vfs, (gsize)_g_local_vfs_new ());
214 return G_VFS (vfs);