[tracker/ontology-cache: 2/5] libtracker-data: Add function to write ontologies to gvdb file
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/ontology-cache: 2/5] libtracker-data: Add function to write ontologies to gvdb file
- Date: Wed, 1 Dec 2010 15:55:37 +0000 (UTC)
commit 6917796aff18da56c736fc015b37db083a2436ca
Author: Jürg Billeter <j bitron ch>
Date: Wed Dec 1 14:08:06 2010 +0100
libtracker-data: Add function to write ontologies to gvdb file
src/libtracker-data/Makefile.am | 1 +
src/libtracker-data/tracker-ontologies.c | 54 ++++++++++++++++++++++++++++++
src/libtracker-data/tracker-ontologies.h | 3 ++
3 files changed, 58 insertions(+), 0 deletions(-)
---
diff --git a/src/libtracker-data/Makefile.am b/src/libtracker-data/Makefile.am
index 3283232..6729047 100644
--- a/src/libtracker-data/Makefile.am
+++ b/src/libtracker-data/Makefile.am
@@ -46,6 +46,7 @@ libtracker_data_la_SOURCES = \
tracker-property.c
libtracker_data_la_LIBADD = \
+ $(top_builddir)/src/gvdb/libgvdb.la \
$(top_builddir)/src/libtracker-common/libtracker-common.la \
$(top_builddir)/src/libtracker-sparql/libtracker-sparql- TRACKER_API_VERSION@.la \
$(BUILD_LIBS) \
diff --git a/src/libtracker-data/tracker-ontologies.c b/src/libtracker-data/tracker-ontologies.c
index cdde80c..8f46dae 100644
--- a/src/libtracker-data/tracker-ontologies.c
+++ b/src/libtracker-data/tracker-ontologies.c
@@ -25,6 +25,7 @@
#include <glib.h>
+#include <gvdb/gvdb-builder.h>
#include <libtracker-common/tracker-ontologies.h>
#include "tracker-ontologies.h"
@@ -336,3 +337,56 @@ tracker_ontologies_get_ontology_by_uri (const gchar *uri)
return g_hash_table_lookup (ontology_uris, uri);
}
+
+void
+tracker_ontologies_write_gvdb (const gchar *filename,
+ GError **error)
+{
+ GHashTable *table, *subtable;
+ gint i;
+
+ table = gvdb_hash_table_new (NULL, NULL);
+
+ subtable = gvdb_hash_table_new (table, "namespaces");
+ for (i = 0; i < namespaces->len; i++) {
+ TrackerNamespace *namespace;
+ GHashTable *nstable;
+
+ namespace = namespaces->pdata[i];
+ nstable = gvdb_hash_table_new (subtable, tracker_namespace_get_uri (namespace));
+
+ gvdb_hash_table_insert_string (nstable, "prefix", tracker_namespace_get_prefix (namespace));
+ }
+
+ subtable = gvdb_hash_table_new (table, "classes");
+ for (i = 0; i < classes->len; i++) {
+ TrackerClass *class;
+ GHashTable *classtable;
+
+ class = classes->pdata[i];
+ classtable = gvdb_hash_table_new (subtable, tracker_class_get_uri (class));
+
+ gvdb_hash_table_insert_string (classtable, "name", tracker_class_get_name (class));
+ }
+
+ subtable = gvdb_hash_table_new (table, "properties");
+ for (i = 0; i < properties->len; i++) {
+ TrackerProperty *property;
+ GHashTable *proptable;
+
+ property = properties->pdata[i];
+ proptable = gvdb_hash_table_new (subtable, tracker_property_get_uri (property));
+
+ gvdb_hash_table_insert_string (proptable, "name", tracker_property_get_name (property));
+ gvdb_hash_table_insert_string (proptable, "domain", tracker_class_get_uri (tracker_property_get_domain (property)));
+ gvdb_hash_table_insert_string (proptable, "range", tracker_class_get_uri (tracker_property_get_range (property)));
+
+ if (!tracker_property_get_multiple_values (property)) {
+ gvdb_item_set_value (gvdb_hash_table_insert (proptable, "max-cardinality"), g_variant_new_int32 (1));
+ }
+ }
+
+ gvdb_table_write_contents (table, filename, FALSE, error);
+
+ g_hash_table_unref (table);
+}
diff --git a/src/libtracker-data/tracker-ontologies.h b/src/libtracker-data/tracker-ontologies.h
index 278a79d..b4a5a71 100644
--- a/src/libtracker-data/tracker-ontologies.h
+++ b/src/libtracker-data/tracker-ontologies.h
@@ -59,6 +59,9 @@ const gchar* tracker_ontologies_get_uri_by_id (gint id
void tracker_ontologies_add_id_uri_pair (gint id,
const gchar *uri);
+void tracker_ontologies_write_gvdb (const gchar *filename,
+ GError **error);
+
G_END_DECLS
#endif /* __LIBTRACKER_DATA_ONTOLOGY_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]