2 * Copyright (C) 2007 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <atompub/atom.h>
23 #include <atompub/atom-glib.h>
27 gio_id_to_file (AtomCtx *ctx, AtomID *id)
29 gchar *root = atom_config_get_str (ctx, "gio", "root");
30 gchar *path = atom_id_string (id);
31 gchar *filename = g_build_filename (root, path, NULL);
32 GFile *file = g_file_new_for_path (filename);
39 gio_file_to_atom (AtomCtx *ctx, GFile *file)
46 if (!g_file_load_contents (file, NULL, &data, &len, NULL, &error))
48 AtomError *aerr = atom_error_new_from_gerror (error);
49 atom_error_set (ctx, aerr);
53 atom = atom_entry_new_data_len (data, len);
59 gio_atom_retrieve_entry (AtomCtx *ctx, AtomID *id)
63 file = gio_id_to_file (ctx, id);
64 atom = gio_file_to_atom (ctx, file);
65 g_object_unref (file);
70 gio_enumerate_entries (AtomCtx *ctx, AtomEntry ***entries, size_t *len)
73 GFileEnumerator *enumerator;
81 root = atom_config_get_str (ctx, "gio", "root");
82 dir = g_file_new_for_path (root);
84 enumerator = g_file_enumerate_children (dir, G_FILE_ATTRIBUTE_STANDARD_NAME,
85 G_FILE_QUERY_INFO_NONE, NULL, &error);
86 if (enumerator == NULL)
88 AtomError *aerr = atom_error_new_from_gerror (error);
89 atom_error_set (ctx, aerr);
93 array = g_ptr_array_new ();
94 while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL)
96 name = g_file_info_get_name (info);
97 filename = g_build_filename (root, name, NULL);
98 g_object_unref (info);
99 file = g_file_new_for_path (filename);
100 g_ptr_array_add (array, gio_file_to_atom (ctx, file));
101 g_object_unref (file);
104 g_object_unref (enumerator);
105 g_object_unref (dir);
108 *entries = array->pdata;
111 g_ptr_array_free (array, FALSE);
115 gio_atom_is_feed (AtomCtx *ctx, AtomID *id)
117 return (!strcmp (atom_id_string (id), "/"));
123 AtomBackend *backend;
124 backend = atom_backend_new ();
125 atom_backend_retrieve_entry_set (backend, gio_atom_retrieve_entry);
126 atom_backend_enumerate_entries_set (backend, gio_enumerate_entries);
127 atom_backend_is_feed_set (backend, gio_atom_is_feed);