tracker-0.16.2/src/libtracker-data/tracker-namespace.c

No issues found

  1 /*
  2  * Copyright (C) 2008, Nokia <ivan.frade@nokia.com>
  3  *
  4  * This library is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU Lesser General Public
  6  * License as published by the Free Software Foundation; either
  7  * version 2.1 of the License, or (at your option) any later version.
  8  *
  9  * This library 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 GNU
 12  * Lesser General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU Lesser General Public
 15  * License along with this library; if not, write to the
 16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 17  * Boston, MA  02110-1301, USA.
 18  */
 19 
 20 #include "config.h"
 21 
 22 #include <string.h>
 23 #include <stdlib.h>
 24 
 25 #include <glib.h>
 26 
 27 #include "tracker-namespace.h"
 28 #include "tracker-ontologies.h"
 29 
 30 #define GET_PRIV(obj) (((TrackerNamespace*)obj)->priv)
 31 #define TRACKER_NAMESPACE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_NAMESPACE, TrackerNamespacePrivate))
 32 
 33 struct _TrackerNamespacePrivate {
 34 	gchar *uri;
 35 
 36 	gboolean use_gvdb;
 37 
 38 	gchar *prefix;
 39 	gboolean is_new;
 40 };
 41 
 42 static void namespace_finalize     (GObject      *object);
 43 
 44 G_DEFINE_TYPE (TrackerNamespace, tracker_namespace, G_TYPE_OBJECT);
 45 
 46 static void
 47 tracker_namespace_class_init (TrackerNamespaceClass *klass)
 48 {
 49 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
 50 
 51 	object_class->finalize     = namespace_finalize;
 52 
 53 	g_type_class_add_private (object_class, sizeof (TrackerNamespacePrivate));
 54 }
 55 
 56 static void
 57 tracker_namespace_init (TrackerNamespace *service)
 58 {
 59 	service->priv = TRACKER_NAMESPACE_GET_PRIVATE (service);
 60 }
 61 
 62 static void
 63 namespace_finalize (GObject *object)
 64 {
 65 	TrackerNamespacePrivate *priv;
 66 
 67 	priv = GET_PRIV (object);
 68 
 69 	g_free (priv->uri);
 70 	g_free (priv->prefix);
 71 
 72 	(G_OBJECT_CLASS (tracker_namespace_parent_class)->finalize) (object);
 73 }
 74 
 75 TrackerNamespace *
 76 tracker_namespace_new (gboolean use_gvdb)
 77 {
 78 	TrackerNamespace *namespace;
 79 	TrackerNamespacePrivate *priv;
 80 
 81 	namespace = g_object_new (TRACKER_TYPE_NAMESPACE, NULL);
 82 
 83 	if (use_gvdb) {
 84 		priv = GET_PRIV (namespace);
 85 		priv->use_gvdb = use_gvdb;
 86 	}
 87 
 88 	return namespace;
 89 }
 90 
 91 const gchar *
 92 tracker_namespace_get_uri (TrackerNamespace *namespace)
 93 {
 94 	TrackerNamespacePrivate *priv;
 95 
 96 	g_return_val_if_fail (TRACKER_IS_NAMESPACE (namespace), NULL);
 97 
 98 	priv = GET_PRIV (namespace);
 99 
100 	return priv->uri;
101 }
102 
103 const gchar *
104 tracker_namespace_get_prefix (TrackerNamespace *namespace)
105 {
106 	TrackerNamespacePrivate *priv;
107 
108 	g_return_val_if_fail (TRACKER_IS_NAMESPACE (namespace), NULL);
109 
110 	priv = GET_PRIV (namespace);
111 
112 	if (!priv->prefix && priv->use_gvdb) {
113 		priv->prefix = g_strdup (tracker_ontologies_get_namespace_string_gvdb (priv->uri, "prefix"));
114 	}
115 
116 	return priv->prefix;
117 }
118 
119 gboolean
120 tracker_namespace_get_is_new (TrackerNamespace *namespace)
121 {
122 	TrackerNamespacePrivate *priv;
123 
124 	g_return_val_if_fail (TRACKER_IS_NAMESPACE (namespace), FALSE);
125 
126 	priv = GET_PRIV (namespace);
127 
128 	return priv->is_new;
129 }
130 
131 void
132 tracker_namespace_set_uri (TrackerNamespace *namespace,
133                            const gchar    *value)
134 {
135 	TrackerNamespacePrivate *priv;
136 
137 	g_return_if_fail (TRACKER_IS_NAMESPACE (namespace));
138 
139 	priv = GET_PRIV (namespace);
140 
141 	g_free (priv->uri);
142 
143 	if (value) {
144 		priv->uri = g_strdup (value);
145 	} else {
146 		priv->uri = NULL;
147 	}
148 }
149 
150 void
151 tracker_namespace_set_prefix (TrackerNamespace *namespace,
152                               const gchar    *value)
153 {
154 	TrackerNamespacePrivate *priv;
155 
156 	g_return_if_fail (TRACKER_IS_NAMESPACE (namespace));
157 
158 	priv = GET_PRIV (namespace);
159 
160 	g_free (priv->prefix);
161 
162 	if (value) {
163 		priv->prefix = g_strdup (value);
164 	} else {
165 		priv->prefix = NULL;
166 	}
167 }
168 
169 void
170 tracker_namespace_set_is_new (TrackerNamespace *namespace,
171                               gboolean          value)
172 {
173 	TrackerNamespacePrivate *priv;
174 
175 	g_return_if_fail (TRACKER_IS_NAMESPACE (namespace));
176 
177 	priv = GET_PRIV (namespace);
178 
179 	priv->is_new = value;
180 }