Commit e041843b authored by Alexander Larsson's avatar Alexander Larsson

Support resource:/// uris

parent 75439298
......@@ -385,6 +385,8 @@ libgio_2_0_la_SOURCES = \
gproxyresolver.c \
gresolver.c \
gresource.c \
gresourcefile.c \
gresourcefile.h \
gseekable.c \
gsimpleasyncresult.c \
gsimplepermission.c \
......
This diff is collapsed.
/* GIO - GLib Input, Output and Streaming Library
*
* Copyright (C) 2011 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: Alexander Larsson <alexl@redhat.com>
*/
#ifndef __G_RESOURCE_FILE_H__
#define __G_RESOURCE_FILE_H__
#include <gio/giotypes.h>
G_BEGIN_DECLS
#define G_TYPE_RESOURCE_FILE (_g_resource_file_get_type ())
#define G_RESOURCE_FILE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_RESOURCE_FILE, GResourceFile))
#define G_RESOURCE_FILE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_RESOURCE_FILE, GResourceFileClass))
#define G_IS_RESOURCE_FILE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_RESOURCE_FILE))
#define G_IS_RESOURCE_FILE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_RESOURCE_FILE))
#define G_RESOURCE_FILE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_TYPE_RESOURCE_FILE, GResourceFileClass))
typedef struct _GResourceFile GResourceFile;
typedef struct _GResourceFileClass GResourceFileClass;
struct _GResourceFileClass
{
GObjectClass parent_class;
};
GType _g_resource_file_get_type (void) G_GNUC_CONST;
GFile * _g_resource_file_new (const char *uri);
G_END_DECLS
#endif /* __G_RESOURCE_FILE_H__ */
......@@ -24,6 +24,7 @@
#include <string.h>
#include "gvfs.h"
#include "glocalvfs.h"
#include "gresourcefile.h"
#include "giomodule-priv.h"
#include "glibintl.h"
......@@ -119,6 +120,13 @@ g_vfs_get_file_for_uri (GVfs *vfs,
class = G_VFS_GET_CLASS (vfs);
/* This is an unfortunate placement, but we really
need to check this before chaining to the vfs,
because we want to support resource uris for
all vfs:es, even those that predate resources. */
if (g_str_has_prefix (uri, "resource:"))
return _g_resource_file_new (uri);
return (* class->get_file_for_uri) (vfs, uri);
}
......@@ -167,6 +175,9 @@ g_vfs_parse_name (GVfs *vfs,
class = G_VFS_GET_CLASS (vfs);
if (g_str_has_prefix (parse_name, "resource:"))
return _g_resource_file_new (parse_name);
return (* class->parse_name) (vfs, parse_name);
}
......
......@@ -412,6 +412,45 @@ test_resource_module (void)
}
}
static void
test_uri_query_info (void)
{
GResource *resource;
GError *error = NULL;
gboolean loaded_file;
char *content;
gsize content_size;
GBytes *data;
GFile *file;
GFileInfo *info;
const char *content_type;
loaded_file = g_file_get_contents ("test.gresource", &content, &content_size,
NULL);
g_assert (loaded_file);
data = g_bytes_new_take (content, content_size);
resource = g_resource_new_from_data (data, &error);
g_assert (resource != NULL);
g_assert_no_error (error);
g_resources_register (resource);
file = g_file_new_for_uri ("resource://" "/a_prefix/test2-alias.txt");
info = g_file_query_info (file, "*", 0, NULL, &error);
g_assert_no_error (error);
g_object_unref (file);
content_type = g_file_info_get_content_type (info);
g_assert (content_type);
g_assert_cmpstr (content_type, ==, "text/plain");
g_object_unref (info);
g_resources_unregister (resource);
g_resource_unref (resource);
}
int
main (int argc,
......@@ -431,6 +470,7 @@ main (int argc,
/* This only uses automatic resources too, so it tests the constructors and destructors */
g_test_add_func ("/resource/module", test_resource_module);
#endif
g_test_add_func ("/resource/uri/query-info", test_uri_query_info);
return g_test_run();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment