tracker r1634 - in branches/xesam-support: . data data/services src/libtracker-common src/libtracker-db src/trackerd
- From: mottela svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r1634 - in branches/xesam-support: . data data/services src/libtracker-common src/libtracker-db src/trackerd
- Date: Wed, 11 Jun 2008 11:02:07 +0000 (UTC)
Author: mottela
Date: Wed Jun 11 11:02:07 2008
New Revision: 1634
URL: http://svn.gnome.org/viewvc/tracker?rev=1634&view=rev
Log:
Added framework for xesam field data handling.
Added:
branches/xesam-support/src/libtracker-common/tracker-xesam-field.c
branches/xesam-support/src/libtracker-common/tracker-xesam-field.h
branches/xesam-support/src/libtracker-common/tracker-xesam-ontology.c
branches/xesam-support/src/libtracker-common/tracker-xesam-ontology.h
Removed:
branches/xesam-support/src/trackerd/tracker-xesam-ontology.c
branches/xesam-support/src/trackerd/tracker-xesam-ontology.h
Modified:
branches/xesam-support/ChangeLog
branches/xesam-support/data/services/xesam-metadata.mmapping
branches/xesam-support/data/sqlite-stored-procs.sql
branches/xesam-support/src/libtracker-common/Makefile.am
branches/xesam-support/src/libtracker-db/tracker-db-manager.c
branches/xesam-support/src/trackerd/Makefile.am
branches/xesam-support/src/trackerd/tracker-main.c
branches/xesam-support/src/trackerd/tracker-xesam-live-search.c
Modified: branches/xesam-support/data/services/xesam-metadata.mmapping
==============================================================================
--- branches/xesam-support/data/services/xesam-metadata.mmapping (original)
+++ branches/xesam-support/data/services/xesam-metadata.mmapping Wed Jun 11 11:02:07 2008
@@ -765,7 +765,7 @@
[xesam:url]
-MetaName=
+MetaName=File:Name
[xesam:useCount]
Modified: branches/xesam-support/data/sqlite-stored-procs.sql
==============================================================================
--- branches/xesam-support/data/sqlite-stored-procs.sql (original)
+++ branches/xesam-support/data/sqlite-stored-procs.sql Wed Jun 11 11:02:07 2008
@@ -210,3 +210,5 @@
GetXesamMetaDataChildren SELECT Child FROM XesamMetaDataChildren WHERE Parent = ?;
GetXesamMetaDataMappings SELECT MetaName FROM XesamMetaDataMapping WHERE XesamMetaName = ?;
GetXesamMetaDataLookups SELECT DISTINCT MetaName FROM XesamMetaDataLookup WHERE XesamMetaName = ?;
+
+GetXesamMetadataTypes SELECT ID, MetaName, DataTypeID, Parents FROM XesamMetaDataTypes;
\ No newline at end of file
Modified: branches/xesam-support/src/libtracker-common/Makefile.am
==============================================================================
--- branches/xesam-support/src/libtracker-common/Makefile.am (original)
+++ branches/xesam-support/src/libtracker-common/Makefile.am Wed Jun 11 11:02:07 2008
@@ -53,7 +53,11 @@
tracker-type-utils.c \
tracker-type-utils.h \
tracker-utils.c \
- tracker-utils.h
+ tracker-utils.h \
+ tracker-xesam-field.c \
+ tracker-xesam-field.h \
+ tracker-xesam-ontology.c \
+ tracker-xesam-ontology.h
libtracker_common_la_LDFLAGS = -version-info 0:0:0
libtracker_common_la_LIBADD = \
Added: branches/xesam-support/src/libtracker-common/tracker-xesam-field.c
==============================================================================
--- (empty file)
+++ branches/xesam-support/src/libtracker-common/tracker-xesam-field.c Wed Jun 11 11:02:07 2008
@@ -0,0 +1,728 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia (urho konttori nokia com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <string.h>
+#include <stdlib.h>
+
+#include <glib.h>
+
+#include "tracker-xesam-field.h"
+
+#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_XESAM_FIELD, TrackerXesamFieldPriv))
+
+typedef struct _TrackerXesamFieldPriv TrackerXesamFieldPriv;
+
+struct _TrackerXesamFieldPriv {
+ gchar *id;
+ gchar *name;
+
+ TrackerXesamFieldType data_type;
+ gchar *field_name;
+ gint weight;
+ gboolean embedded;
+ gboolean multiple_values;
+ gboolean delimited;
+ gboolean filtered;
+ gboolean store_metadata;
+
+ GSList *child_ids;
+};
+
+static void field_finalize (GObject *object);
+static void field_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void field_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec);
+
+enum {
+ PROP_0,
+ PROP_ID,
+ PROP_NAME,
+ PROP_DATA_TYPE,
+ PROP_FIELD_NAME,
+ PROP_WEIGHT,
+ PROP_EMBEDDED,
+ PROP_MULTIPLE_VALUES,
+ PROP_DELIMITED,
+ PROP_FILTERED,
+ PROP_STORE_METADATA,
+ PROP_CHILD_IDS
+};
+
+GType
+tracker_xesam_field_type_get_type (void)
+{
+ static GType etype = 0;
+
+ if (etype == 0) {
+ static const GEnumValue values[] = {
+ { TRACKER_XESAM_FIELD_TYPE_KEYWORD,
+ "TRACKER_XESAM_FIELD_TYPE_KEYWORD",
+ "keyword" },
+ { TRACKER_XESAM_FIELD_TYPE_INDEX,
+ "TRACKER_XESAM_FIELD_TYPE_INDEX",
+ "index" },
+ { TRACKER_XESAM_FIELD_TYPE_FULLTEXT,
+ " TRACKER_XESAM_FIELD_TYPE_FULLTEXT",
+ "fulltext" },
+ { TRACKER_XESAM_FIELD_TYPE_STRING,
+ "TRACKER_XESAM_FIELD_TYPE_STRING",
+ "string" },
+ { TRACKER_XESAM_FIELD_TYPE_INTEGER,
+ "TRACKER_XESAM_FIELD_TYPE_INTEGER",
+ "integer" },
+ { TRACKER_XESAM_FIELD_TYPE_DOUBLE,
+ "TRACKER_XESAM_FIELD_TYPE_DOUBLE",
+ "double" },
+ { TRACKER_XESAM_FIELD_TYPE_DATE,
+ "TRACKER_XESAM_FIELD_TYPE_DATE",
+ "date" },
+ { TRACKER_XESAM_FIELD_TYPE_BLOB,
+ "TRACKER_XESAM_FIELD_TYPE_BLOB",
+ "blob" },
+ { TRACKER_XESAM_FIELD_TYPE_STRUCT,
+ "TRACKER_XESAM_FIELD_TYPE_STRUCT",
+ "struct" },
+ { TRACKER_XESAM_FIELD_TYPE_LINK,
+ "TRACKER_XESAM_FIELD_TYPE_LINK",
+ "link" },
+ { 0, NULL, NULL }
+ };
+
+ etype = g_enum_register_static ("TrackerXesamFieldType", values);
+ }
+
+ return etype;
+}
+
+G_DEFINE_TYPE (TrackerXesamField, tracker_xesam_field, G_TYPE_OBJECT);
+
+static void
+tracker_xesam_field_class_init (TrackerXesamFieldClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = field_finalize;
+ object_class->get_property = field_get_property;
+ object_class->set_property = field_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_ID,
+ g_param_spec_string ("id",
+ "id",
+ "Unique identifier for this field",
+ NULL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_NAME,
+ g_param_spec_string ("name",
+ "name",
+ "Field name",
+ NULL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_DATA_TYPE,
+ g_param_spec_enum ("data-type",
+ "data-type",
+ "Field data type",
+ tracker_xesam_field_type_get_type (),
+ TRACKER_XESAM_FIELD_TYPE_INDEX,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_FIELD_NAME,
+ g_param_spec_string ("field-name",
+ "field-name",
+ "Column in services table with the contents of this metadata",
+ NULL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_WEIGHT,
+ g_param_spec_int ("weight",
+ "weight",
+ "Boost to the score",
+ 0,
+ G_MAXINT,
+ 0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_EMBEDDED,
+ g_param_spec_boolean ("embedded",
+ "embedded",
+ "Embedded",
+ TRUE,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_MULTIPLE_VALUES,
+ g_param_spec_boolean ("multiple-values",
+ "multiple-values",
+ "Multiple values",
+ TRUE,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_DELIMITED,
+ g_param_spec_boolean ("delimited",
+ "delimited",
+ "Delimited",
+ FALSE,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_FILTERED,
+ g_param_spec_boolean ("filtered",
+ "filtered",
+ "Filtered",
+ FALSE,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_STORE_METADATA,
+ g_param_spec_boolean ("store-metadata",
+ "store-metadata",
+ "Store metadata",
+ FALSE,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class,
+ PROP_CHILD_IDS,
+ g_param_spec_pointer ("child-ids",
+ "child-ids",
+ "Child ids",
+ G_PARAM_READWRITE));
+
+ g_type_class_add_private (object_class, sizeof (TrackerXesamFieldPriv));
+}
+
+static void
+tracker_xesam_field_init (TrackerXesamField *field)
+{
+}
+
+static void
+field_finalize (GObject *object)
+{
+ TrackerXesamFieldPriv *priv;
+
+ priv = GET_PRIV (object);
+
+ g_free (priv->id);
+ g_free (priv->name);
+
+ if (priv->field_name) {
+ g_free (priv->field_name);
+ }
+
+ g_slist_foreach (priv->child_ids, (GFunc) g_free, NULL);
+ g_slist_free (priv->child_ids);
+
+ (G_OBJECT_CLASS (tracker_xesam_field_parent_class)->finalize) (object);
+}
+
+static void
+field_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerXesamFieldPriv *priv;
+
+ priv = GET_PRIV (object);
+
+ switch (param_id) {
+ case PROP_ID:
+ g_value_set_string (value, priv->id);
+ break;
+ case PROP_NAME:
+ g_value_set_string (value, priv->name);
+ break;
+ case PROP_DATA_TYPE:
+ g_value_set_enum (value, priv->data_type);
+ break;
+ case PROP_FIELD_NAME:
+ g_value_set_string (value, priv->field_name);
+ break;
+ case PROP_WEIGHT:
+ g_value_set_int (value, priv->weight);
+ break;
+ case PROP_EMBEDDED:
+ g_value_set_boolean (value, priv->embedded);
+ break;
+ case PROP_MULTIPLE_VALUES:
+ g_value_set_boolean (value, priv->multiple_values);
+ break;
+ case PROP_DELIMITED:
+ g_value_set_boolean (value, priv->delimited);
+ break;
+ case PROP_FILTERED:
+ g_value_set_boolean (value, priv->filtered);
+ break;
+ case PROP_STORE_METADATA:
+ g_value_set_boolean (value, priv->store_metadata);
+ break;
+ case PROP_CHILD_IDS:
+ g_value_set_pointer (value, priv->child_ids);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ };
+}
+
+static void
+field_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ switch (param_id) {
+ case PROP_ID:
+ tracker_xesam_field_set_id (TRACKER_XESAM_FIELD (object),
+ g_value_get_string (value));
+ break;
+ case PROP_NAME:
+ tracker_xesam_field_set_name (TRACKER_XESAM_FIELD (object),
+ g_value_get_string (value));
+ break;
+ case PROP_DATA_TYPE:
+ tracker_xesam_field_set_data_type (TRACKER_XESAM_FIELD (object),
+ g_value_get_enum (value));
+ break;
+ case PROP_FIELD_NAME:
+ tracker_xesam_field_set_field_name (TRACKER_XESAM_FIELD (object),
+ g_value_get_string (value));
+ break;
+ case PROP_WEIGHT:
+ tracker_xesam_field_set_weight (TRACKER_XESAM_FIELD (object),
+ g_value_get_int (value));
+ break;
+ case PROP_EMBEDDED:
+ tracker_xesam_field_set_embedded (TRACKER_XESAM_FIELD (object),
+ g_value_get_boolean (value));
+ break;
+ case PROP_MULTIPLE_VALUES:
+ tracker_xesam_field_set_multiple_values (TRACKER_XESAM_FIELD (object),
+ g_value_get_boolean (value));
+ break;
+ case PROP_DELIMITED:
+ tracker_xesam_field_set_delimited (TRACKER_XESAM_FIELD (object),
+ g_value_get_boolean (value));
+ break;
+ case PROP_FILTERED:
+ tracker_xesam_field_set_filtered (TRACKER_XESAM_FIELD (object),
+ g_value_get_boolean (value));
+ break;
+ case PROP_STORE_METADATA:
+ tracker_xesam_field_set_store_metadata (TRACKER_XESAM_FIELD (object),
+ g_value_get_boolean (value));
+ break;
+ case PROP_CHILD_IDS:
+ tracker_xesam_field_set_child_ids (TRACKER_XESAM_FIELD (object),
+ g_value_get_pointer (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ };
+}
+
+static gboolean
+field_int_validate (TrackerXesamField *field,
+ const gchar *property,
+ gint value)
+{
+#ifdef G_DISABLE_CHECKS
+ GParamSpec *spec;
+ GValue value = { 0 };
+ gboolean valid;
+
+ spec = g_object_class_find_property (G_OBJECT_CLASS (field), property);
+ g_return_val_if_fail (spec != NULL, FALSE);
+
+ g_value_init (&value, spec->value_type);
+ g_value_set_int (&value, verbosity);
+ valid = g_param_value_validate (spec, &value);
+ g_value_unset (&value);
+
+ g_return_val_if_fail (valid != TRUE, FALSE);
+#endif
+
+ return TRUE;
+}
+
+TrackerXesamField *
+tracker_xesam_field_new (void)
+{
+ TrackerXesamField *field;
+
+ field = g_object_new (TRACKER_TYPE_XESAM_FIELD, NULL);
+
+ return field;
+}
+
+const gchar *
+tracker_xesam_field_get_id (TrackerXesamField *field)
+{
+ TrackerXesamFieldPriv *priv;
+
+ g_return_val_if_fail (TRACKER_IS_XESAM_FIELD (field), NULL);
+
+ priv = GET_PRIV (field);
+
+ return priv->id;
+}
+
+const gchar *
+tracker_xesam_field_get_name (TrackerXesamField *field)
+{
+ TrackerXesamFieldPriv *priv;
+
+ g_return_val_if_fail (TRACKER_IS_XESAM_FIELD (field), NULL);
+
+ priv = GET_PRIV (field);
+
+ return priv->name;
+}
+
+TrackerXesamFieldType
+tracker_xesam_field_get_data_type (TrackerXesamField *field)
+{
+ TrackerXesamFieldPriv *priv;
+
+ g_return_val_if_fail (TRACKER_IS_XESAM_FIELD (field), TRACKER_XESAM_FIELD_TYPE_STRING); //FIXME
+
+ priv = GET_PRIV (field);
+
+ return priv->data_type;
+}
+
+const gchar *
+tracker_xesam_field_get_field_name (TrackerXesamField *field)
+{
+ TrackerXesamFieldPriv *priv;
+
+ g_return_val_if_fail (TRACKER_IS_XESAM_FIELD (field), NULL);
+
+ priv = GET_PRIV (field);
+
+ return priv->field_name;
+}
+
+gint
+tracker_xesam_field_get_weight (TrackerXesamField *field)
+{
+ TrackerXesamFieldPriv *priv;
+
+ g_return_val_if_fail (TRACKER_IS_XESAM_FIELD (field), -1);
+
+ priv = GET_PRIV (field);
+
+ return priv->weight;
+}
+
+
+gboolean
+tracker_xesam_field_get_embedded (TrackerXesamField *field)
+{
+ TrackerXesamFieldPriv *priv;
+
+ g_return_val_if_fail (TRACKER_IS_XESAM_FIELD (field), FALSE);
+
+ priv = GET_PRIV (field);
+
+ return priv->embedded;
+}
+
+
+gboolean
+tracker_xesam_field_get_multiple_values (TrackerXesamField *field)
+{
+ TrackerXesamFieldPriv *priv;
+
+ g_return_val_if_fail (TRACKER_IS_XESAM_FIELD (field), FALSE);
+
+ priv = GET_PRIV (field);
+
+ return priv->multiple_values;
+}
+
+gboolean
+tracker_xesam_field_get_delimited (TrackerXesamField *field)
+{
+ TrackerXesamFieldPriv *priv;
+
+ g_return_val_if_fail (TRACKER_IS_XESAM_FIELD (field), FALSE);
+
+ priv = GET_PRIV (field);
+
+ return priv->delimited;
+}
+
+gboolean
+tracker_xesam_field_get_filtered (TrackerXesamField *field)
+{
+ TrackerXesamFieldPriv *priv;
+
+ g_return_val_if_fail (TRACKER_IS_XESAM_FIELD (field), FALSE);
+
+ priv = GET_PRIV (field);
+
+ return priv->filtered;
+}
+
+gboolean
+tracker_xesam_field_get_store_metadata (TrackerXesamField *field)
+{
+ TrackerXesamFieldPriv *priv;
+
+ g_return_val_if_fail (TRACKER_IS_XESAM_FIELD (field), FALSE);
+
+ priv = GET_PRIV (field);
+
+ return priv->store_metadata;
+}
+
+
+const GSList *
+tracker_xesam_field_get_child_ids (TrackerXesamField *field)
+{
+ TrackerXesamFieldPriv *priv;
+
+ g_return_val_if_fail (TRACKER_IS_XESAM_FIELD (field), NULL);
+
+ priv = GET_PRIV (field);
+
+ return priv->child_ids;
+}
+
+
+void
+tracker_xesam_field_set_id (TrackerXesamField *field,
+ const gchar *value)
+{
+ TrackerXesamFieldPriv *priv;
+
+ g_return_if_fail (TRACKER_IS_XESAM_FIELD (field));
+
+ priv = GET_PRIV (field);
+
+ g_free (priv->id);
+
+ if (value) {
+ priv->id = g_strdup (value);
+ } else {
+ priv->id = NULL;
+ }
+
+ g_object_notify (G_OBJECT (field), "id");
+}
+
+void
+tracker_xesam_field_set_name (TrackerXesamField *field,
+ const gchar *value)
+{
+ TrackerXesamFieldPriv *priv;
+
+ g_return_if_fail (TRACKER_IS_XESAM_FIELD (field));
+
+ priv = GET_PRIV (field);
+
+ g_free (priv->name);
+
+ if (value) {
+ priv->name = g_strdup (value);
+ } else {
+ priv->name = NULL;
+ }
+
+ g_object_notify (G_OBJECT (field), "name");
+}
+
+void
+tracker_xesam_field_set_data_type (TrackerXesamField *field,
+ TrackerXesamFieldType value)
+{
+ TrackerXesamFieldPriv *priv;
+
+ g_return_if_fail (TRACKER_IS_XESAM_FIELD (field));
+
+ priv = GET_PRIV (field);
+
+ priv->data_type = value;
+ g_object_notify (G_OBJECT (field), "data-type");
+}
+
+void
+tracker_xesam_field_set_field_name (TrackerXesamField *field,
+ const gchar *value)
+{
+ TrackerXesamFieldPriv *priv;
+
+ g_return_if_fail (TRACKER_IS_XESAM_FIELD (field));
+
+ priv = GET_PRIV (field);
+
+ g_free (priv->field_name);
+
+ if (value) {
+ priv->field_name = g_strdup (value);
+ } else {
+ priv->field_name = NULL;
+ }
+
+ g_object_notify (G_OBJECT (field), "field-name");
+}
+
+void
+tracker_xesam_field_set_weight (TrackerXesamField *field,
+ gint value)
+{
+ TrackerXesamFieldPriv *priv;
+ g_return_if_fail (TRACKER_IS_XESAM_FIELD (field));
+
+ if (!field_int_validate (field, "weight", value)) {
+ return;
+ }
+
+ priv = GET_PRIV (field);
+
+ priv->weight = value;
+ g_object_notify (G_OBJECT (field), "weight");
+}
+
+void
+tracker_xesam_field_set_embedded (TrackerXesamField *field,
+ gboolean value)
+{
+ TrackerXesamFieldPriv *priv;
+
+ g_return_if_fail (TRACKER_IS_XESAM_FIELD (field));
+
+ priv = GET_PRIV (field);
+
+ priv->embedded = value;
+ g_object_notify (G_OBJECT (field), "embedded");
+}
+
+void
+tracker_xesam_field_set_multiple_values (TrackerXesamField *field,
+ gboolean value)
+{
+ TrackerXesamFieldPriv *priv;
+
+ g_return_if_fail (TRACKER_IS_XESAM_FIELD (field));
+
+ priv = GET_PRIV (field);
+
+ priv->multiple_values = value;
+ g_object_notify (G_OBJECT (field), "multiple-values");
+}
+
+void
+tracker_xesam_field_set_delimited (TrackerXesamField *field,
+ gboolean value)
+{
+ TrackerXesamFieldPriv *priv;
+
+ g_return_if_fail (TRACKER_IS_XESAM_FIELD (field));
+
+ priv = GET_PRIV (field);
+
+ priv->delimited = value;
+ g_object_notify (G_OBJECT (field), "delimited");
+}
+
+void
+tracker_xesam_field_set_filtered (TrackerXesamField *field,
+ gboolean value)
+{
+ TrackerXesamFieldPriv *priv;
+
+ g_return_if_fail (TRACKER_IS_XESAM_FIELD (field));
+
+ priv = GET_PRIV (field);
+
+ priv->filtered = value;
+ g_object_notify (G_OBJECT (field), "filtered");
+}
+
+void
+tracker_xesam_field_set_store_metadata (TrackerXesamField *field,
+ gboolean value)
+{
+ TrackerXesamFieldPriv *priv;
+
+ g_return_if_fail (TRACKER_IS_XESAM_FIELD (field));
+
+ priv = GET_PRIV (field);
+
+ priv->store_metadata = value;
+ g_object_notify (G_OBJECT (field), "store-metadata");
+}
+
+void
+tracker_xesam_field_set_child_ids (TrackerXesamField *field,
+ const GSList *value)
+{
+ TrackerXesamFieldPriv *priv;
+
+ g_return_if_fail (TRACKER_IS_XESAM_FIELD (field));
+
+ priv = GET_PRIV (field);
+
+ g_slist_foreach (priv->child_ids, (GFunc) g_free, NULL);
+ g_slist_free (priv->child_ids);
+
+ if (value) {
+ GSList *new_list;
+ const GSList *l;
+
+ new_list = NULL;
+
+ for (l = value; l; l = l->next) {
+ new_list = g_slist_prepend (new_list, g_strdup (l->data));
+ }
+
+ new_list = g_slist_reverse (new_list);
+ priv->child_ids = new_list;
+ } else {
+ priv->child_ids = NULL;
+ }
+
+ g_object_notify (G_OBJECT (field), "child-ids");
+}
+
+void
+tracker_xesam_field_append_child_id (TrackerXesamField *field,
+ const gchar *value)
+{
+ TrackerXesamFieldPriv *priv;
+
+ g_return_if_fail (TRACKER_IS_XESAM_FIELD (field));
+
+ priv = GET_PRIV (field);
+
+ if (value) {
+ priv->child_ids = g_slist_append (priv->child_ids, g_strdup (value));
+ }
+
+ g_object_notify (G_OBJECT (field), "child-ids");
+}
Added: branches/xesam-support/src/libtracker-common/tracker-xesam-field.h
==============================================================================
--- (empty file)
+++ branches/xesam-support/src/libtracker-common/tracker-xesam-field.h Wed Jun 11 11:02:07 2008
@@ -0,0 +1,107 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia (urho konttori nokia com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __TRACKER_XESAM_FIELD_H__
+#define __TRACKER_XESAM_FIELD_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+typedef enum {
+ TRACKER_XESAM_FIELD_TYPE_KEYWORD,
+ TRACKER_XESAM_FIELD_TYPE_INDEX,
+ TRACKER_XESAM_FIELD_TYPE_FULLTEXT,
+ TRACKER_XESAM_FIELD_TYPE_STRING,
+ TRACKER_XESAM_FIELD_TYPE_INTEGER,
+ TRACKER_XESAM_FIELD_TYPE_DOUBLE,
+ TRACKER_XESAM_FIELD_TYPE_DATE,
+ TRACKER_XESAM_FIELD_TYPE_BLOB,
+ TRACKER_XESAM_FIELD_TYPE_STRUCT,
+ TRACKER_XESAM_FIELD_TYPE_LINK
+} TrackerXesamFieldType;
+
+GType tracker_xesam_field_type_get_type (void) G_GNUC_CONST;
+
+#define TRACKER_TYPE_XESAM_FIELD (tracker_xesam_field_get_type ())
+#define TRACKER_TYPE_XESAM_FIELD_TYPE (tracker_xesam_field_type_get_type ())
+#define TRACKER_XESAM_FIELD(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_XESAM_FIELD, TrackerXesamField))
+#define TRACKER_XESAM_FIELD_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TRACKER_TYPE_XESAM_FIELD, TrackerXesamFieldClass))
+#define TRACKER_IS_XESAM_FIELD(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_XESAM_FIELD))
+#define TRACKER_IS_XESAM_FIELD_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TRACKER_TYPE_XESAM_FIELD))
+#define TRACKER_XESAM_FIELD_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_XESAM_FIELD, TrackerXesamFieldClass))
+
+typedef struct _TrackerXesamField TrackerXesamField;
+typedef struct _TrackerXesamFieldClass TrackerXesamFieldClass;
+
+struct _TrackerXesamField {
+ GObject parent;
+};
+
+struct _TrackerXesamFieldClass {
+ GObjectClass parent_class;
+};
+
+GType tracker_xesam_field_get_type (void) G_GNUC_CONST;
+
+TrackerXesamField * tracker_xesam_field_new (void);
+
+const gchar * tracker_xesam_field_get_id (TrackerXesamField *field);
+const gchar * tracker_xesam_field_get_name (TrackerXesamField *field);
+TrackerXesamFieldType tracker_xesam_field_get_data_type (TrackerXesamField *field);
+const gchar * tracker_xesam_field_get_field_name (TrackerXesamField *field);
+gint tracker_xesam_field_get_weight (TrackerXesamField *service);
+gboolean tracker_xesam_field_get_embedded (TrackerXesamField *field);
+gboolean tracker_xesam_field_get_multiple_values (TrackerXesamField *field);
+gboolean tracker_xesam_field_get_delimited (TrackerXesamField *field);
+gboolean tracker_xesam_field_get_filtered (TrackerXesamField *field);
+gboolean tracker_xesam_field_get_store_metadata (TrackerXesamField *field);
+const GSList * tracker_xesam_field_get_child_ids (TrackerXesamField *field);
+
+void tracker_xesam_field_set_id (TrackerXesamField *field,
+ const gchar *value);
+void tracker_xesam_field_set_name (TrackerXesamField *field,
+ const gchar *value);
+void tracker_xesam_field_set_data_type (TrackerXesamField *field,
+ TrackerXesamFieldType value);
+void tracker_xesam_field_set_field_name (TrackerXesamField *field,
+ const gchar *value);
+void tracker_xesam_field_set_weight (TrackerXesamField *field,
+ gint value);
+void tracker_xesam_field_set_embedded (TrackerXesamField *field,
+ gboolean value);
+void tracker_xesam_field_set_multiple_values (TrackerXesamField *field,
+ gboolean value);
+void tracker_xesam_field_set_delimited (TrackerXesamField *field,
+ gboolean value);
+void tracker_xesam_field_set_filtered (TrackerXesamField *field,
+ gboolean value);
+void tracker_xesam_field_set_store_metadata (TrackerXesamField *field,
+ gboolean value);
+void tracker_xesam_field_set_child_ids (TrackerXesamField *field,
+ const GSList *value);
+void tracker_xesam_field_append_child_id (TrackerXesamField *field,
+ const gchar *id);
+
+G_END_DECLS
+
+#endif /* __TRACKER_XESAM_FIELD_H__ */
+
Added: branches/xesam-support/src/libtracker-common/tracker-xesam-ontology.c
==============================================================================
--- (empty file)
+++ branches/xesam-support/src/libtracker-common/tracker-xesam-ontology.c Wed Jun 11 11:02:07 2008
@@ -0,0 +1,609 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia (urho konttori nokia com)
+ * Authors: Ottela Mikael (mikael ottela ixonos com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <string.h>
+#include <stdlib.h>
+
+#include <glib.h>
+
+#include <libtracker-common/tracker-field.h>
+
+#include "tracker-xesam-ontology.h"
+
+typedef struct {
+ gchar *prefix;
+ gint service;
+} ServiceMimePrefixes;
+
+/* Hash (gint service_type_id, TrackerService *service) */
+static GHashTable *service_id_table;
+
+/* Hash (gchar *service_name, TrackerService *service) */
+static GHashTable *service_table;
+
+/* Hash (gchar *mime, gint service_type_id) */
+static GHashTable *mime_service;
+
+/* List of ServiceMimePrefixes */
+static GSList *mime_prefix_service;
+
+/* The service directory table is used to store a ServiceInfo struct
+ * for a directory path - used for determining which service a uri
+ * belongs to for things like files, emails, conversations etc
+ */
+static GHashTable *service_directory_table;
+static GSList *service_directory_list;
+
+/* Field descriptions */
+static GHashTable *metadata_table;
+
+static void
+xesam_ontology_mime_prefix_foreach (gpointer data,
+ gpointer user_data)
+{
+ ServiceMimePrefixes *mime_prefix;
+
+ mime_prefix = (ServiceMimePrefixes*) data;
+
+ g_free (mime_prefix->prefix);
+ g_free (mime_prefix);
+}
+
+gpointer
+xesam_ontology_hash_lookup_by_str (GHashTable *hash_table,
+ const gchar *str)
+{
+ gpointer *data;
+ gchar *str_lower;
+
+ str_lower = g_utf8_strdown (str, -1);
+ data = g_hash_table_lookup (hash_table, str_lower);
+ g_free (str_lower);
+
+ return data;
+}
+
+gpointer
+xesam_ontology_hash_lookup_by_id (GHashTable *hash_table,
+ gint id)
+{
+ gpointer *data;
+ gchar *str;
+
+ str = g_strdup_printf ("%d", id);
+ data = g_hash_table_lookup (hash_table, str);
+ g_free (str);
+
+ return data;
+}
+
+void
+tracker_xesam_ontology_init (void)
+{
+ if (service_id_table ||
+ service_table ||
+ mime_service ||
+ service_directory_table ||
+ metadata_table) {
+ return;
+ }
+
+ service_id_table = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ g_object_unref);
+
+ service_table = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ g_object_unref);
+
+ mime_service = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ NULL,
+ NULL);
+
+ service_directory_table = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ g_free);
+
+ metadata_table = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ NULL,
+ g_object_unref);
+}
+
+void
+tracker_xesam_ontology_shutdown (void)
+{
+ g_hash_table_remove_all (service_directory_table);
+ g_hash_table_remove_all (service_id_table);
+ g_hash_table_remove_all (service_table);
+ g_hash_table_remove_all (mime_service);
+ g_hash_table_remove_all (metadata_table);
+
+ if (mime_prefix_service) {
+ g_slist_foreach (mime_prefix_service,
+ xesam_ontology_mime_prefix_foreach,
+ NULL);
+ g_slist_free (mime_prefix_service);
+ }
+}
+
+void
+tracker_xesam_ontology_add_service_type (TrackerService *service,
+ GSList *mimes,
+ GSList *mime_prefixes)
+{
+
+ GSList *mime, *prefix;
+ ServiceMimePrefixes *service_mime_prefix;
+ gint id;
+ const gchar *name;
+
+ g_return_if_fail (TRACKER_IS_SERVICE (service));
+
+ id = tracker_service_get_id (service);
+ name = tracker_service_get_name (service);
+
+ g_hash_table_insert (service_table,
+ g_utf8_strdown (name, -1),
+ g_object_ref (service));
+ g_hash_table_insert (service_id_table,
+ g_strdup_printf ("%d", id),
+ g_object_ref (service));
+
+ for (mime = mimes; mime != NULL && mime->data != NULL; mime = mime->next) {
+ g_hash_table_insert (mime_service,
+ mime->data,
+ GINT_TO_POINTER (id));
+ }
+
+ for (prefix = mime_prefixes; prefix != NULL; prefix = prefix->next) {
+ service_mime_prefix = g_new0 (ServiceMimePrefixes, 1);
+ service_mime_prefix->prefix = prefix->data;
+ service_mime_prefix->service = id;
+ mime_prefix_service = g_slist_prepend (mime_prefix_service,
+ service_mime_prefix);
+ }
+}
+
+TrackerService *
+tracker_xesam_ontology_get_service_type_by_name (const gchar *service_str)
+{
+ return xesam_ontology_hash_lookup_by_str (service_table, service_str);
+}
+
+gchar *
+tracker_xesam_ontology_get_service_type_by_id (gint id)
+{
+ TrackerService *service;
+
+ service = xesam_ontology_hash_lookup_by_id (service_id_table, id);
+
+ if (!service) {
+ return NULL;
+ }
+
+ return g_strdup (tracker_service_get_name (service));
+}
+
+gchar *
+tracker_xesam_ontology_get_service_type_for_mime (const gchar *mime)
+{
+ gpointer *id;
+ ServiceMimePrefixes *item;
+ GSList *prefix_service;
+
+ /* Try a complete mime */
+ id = g_hash_table_lookup (mime_service, mime);
+ if (id) {
+ return tracker_xesam_ontology_get_service_type_by_id (GPOINTER_TO_INT (id));
+ }
+
+ /* Try in prefixes */
+ for (prefix_service = mime_prefix_service;
+ prefix_service != NULL;
+ prefix_service = prefix_service->next) {
+ item = prefix_service->data;
+ if (g_str_has_prefix (mime, item->prefix)) {
+ return tracker_xesam_ontology_get_service_type_by_id (item->service);
+ }
+ }
+
+ /* Default option */
+ return g_strdup ("Other");
+}
+
+gint
+tracker_xesam_ontology_get_id_for_service_type (const char *service_str)
+{
+ TrackerService *service;
+
+ service = xesam_ontology_hash_lookup_by_str (service_table, service_str);
+
+ if (!service) {
+ return -1;
+ }
+
+ return tracker_service_get_id (service);
+}
+
+gchar *
+tracker_xesam_ontology_get_parent_service (const gchar *service_str)
+{
+ TrackerService *service;
+ const gchar *parent = NULL;
+
+ service = xesam_ontology_hash_lookup_by_str (service_table, service_str);
+
+ if (service) {
+ parent = tracker_service_get_parent (service);
+ }
+
+ return g_strdup (parent);
+}
+
+gchar *
+tracker_xesam_ontology_get_parent_service_by_id (gint id)
+{
+ TrackerService *service;
+
+ service = xesam_ontology_hash_lookup_by_id (service_id_table, id);
+
+ if (!service) {
+ return NULL;
+ }
+
+ return g_strdup (tracker_service_get_parent (service));
+}
+
+gint
+tracker_xesam_ontology_get_parent_id_for_service_id (gint id)
+{
+ TrackerService *service;
+ const gchar *parent = NULL;
+
+ service = xesam_ontology_hash_lookup_by_id (service_id_table, id);
+
+ if (service) {
+ parent = tracker_service_get_parent (service);
+ }
+
+ if (!parent) {
+ return -1;
+ }
+
+ service = xesam_ontology_hash_lookup_by_str (service_table, parent);
+
+ if (!service) {
+ return -1;
+ }
+
+ return tracker_service_get_id (service);
+}
+
+TrackerDBType
+tracker_xesam_ontology_get_db_for_service_type (const gchar *service_str)
+{
+ TrackerDBType type;
+ gchar *str;
+
+ type = TRACKER_DB_TYPE_DATA;
+ str = g_utf8_strdown (service_str, -1);
+
+ if (g_str_has_prefix (str, "emails") ||
+ g_str_has_prefix (str, "attachments")) {
+ type = TRACKER_DB_TYPE_EMAIL;
+ }
+
+ g_free (str);
+
+ return type;
+}
+
+gboolean
+tracker_xesam_ontology_service_type_has_embedded (const gchar *service_str)
+{
+ TrackerService *service;
+
+ service = xesam_ontology_hash_lookup_by_str (service_table, service_str);
+
+ if (!service) {
+ return FALSE;
+ }
+
+ return tracker_service_get_embedded (service);
+}
+
+gboolean
+tracker_xesam_ontology_is_valid_service_type (const gchar *service_str)
+{
+ return tracker_xesam_ontology_get_id_for_service_type (service_str) != -1;
+}
+
+gboolean
+tracker_xesam_ontology_service_type_has_metadata (const gchar *service_str)
+{
+ TrackerService *service;
+
+ service = xesam_ontology_hash_lookup_by_str (service_table, service_str);
+
+ if (!service) {
+ return FALSE;
+ }
+
+ return tracker_service_get_has_metadata (service);
+}
+
+gint
+tracker_xesam_ontology_metadata_key_in_service (const gchar *service_str,
+ const gchar *meta_name)
+{
+ TrackerService *service;
+ gint i;
+ const GSList *l;
+
+ service = xesam_ontology_hash_lookup_by_str (service_table, service_str);
+
+ if (!service) {
+ return 0;
+ }
+
+ for (l = tracker_service_get_key_metadata (service), i = 0;
+ l;
+ l = l->next, i++) {
+ if (!l->data) {
+ continue;
+ }
+
+ if (strcasecmp (l->data, meta_name) == 0) {
+ return i;
+ }
+ }
+
+ return 0;
+}
+
+gboolean
+tracker_xesam_ontology_show_service_directories (const gchar *service_str)
+{
+ TrackerService *service;
+
+ service = xesam_ontology_hash_lookup_by_str (service_table, service_str);
+
+ if (!service) {
+ return FALSE;
+ }
+
+ return tracker_service_get_show_service_directories (service);
+}
+
+gboolean
+tracker_xesam_ontology_show_service_files (const gchar *service_str)
+{
+ TrackerService *service;
+
+ service = xesam_ontology_hash_lookup_by_str (service_table, service_str);
+
+ if (!service) {
+ return FALSE;
+ }
+
+ return tracker_service_get_show_service_files (service);
+}
+
+/*
+ * Service directories
+ */
+GSList *
+tracker_xesam_ontology_get_dirs_for_service_type (const gchar *service)
+{
+ GSList *list = NULL;
+ GSList *l;
+
+ g_return_val_if_fail (service != NULL, NULL);
+
+ for (l = service_directory_list; l; l = l->next) {
+ gchar *str;
+
+ str = g_hash_table_lookup (service_directory_table, l->data);
+
+ if (strcasecmp (service, str) == 0) {
+ list = g_slist_prepend (list, l->data);
+ }
+ }
+
+ return list;
+}
+
+void
+tracker_xesam_ontology_add_dir_to_service_type (const gchar *service,
+ const gchar *path)
+{
+ g_return_if_fail (service != NULL);
+ g_return_if_fail (path != NULL);
+
+ g_debug ("Adding path:'%s' for service:'%s'", path, service);
+
+ service_directory_list = g_slist_prepend (service_directory_list,
+ g_strdup (path));
+
+ g_hash_table_insert (service_directory_table,
+ g_strdup (path),
+ g_strdup (service));
+}
+
+void
+tracker_xesam_ontology_remove_dir_to_service_type (const gchar *service,
+ const gchar *path)
+{
+ GSList *found;
+
+ g_return_if_fail (service != NULL);
+ g_return_if_fail (path != NULL);
+
+ g_debug ("Removing path:'%s' for service:'%s'", path, service);
+
+ found = g_slist_find_custom (service_directory_list,
+ path,
+ (GCompareFunc) strcmp);
+ if (found) {
+ service_directory_list = g_slist_remove_link (service_directory_list, found);
+ g_free (found->data);
+ g_slist_free (found);
+ }
+
+ g_hash_table_remove (service_directory_table, path);
+}
+
+gchar *
+tracker_xesam_ontology_get_service_type_for_dir (const gchar *path)
+{
+ GSList *l;
+
+ g_return_val_if_fail (path != NULL, g_strdup ("Files"));
+
+ /* Check service dir list to see if a prefix */
+ for (l = service_directory_list; l; l = l->next) {
+ const gchar *str;
+
+ if (!l->data || !g_str_has_prefix (path, l->data)) {
+ continue;
+ }
+
+ str = g_hash_table_lookup (service_directory_table, l->data);
+
+ return g_strdup (str);
+ }
+
+ return g_strdup ("Files");
+}
+
+/* Field Handling */
+void
+tracker_xesam_ontology_add_field (TrackerXesamField *field)
+{
+ g_return_if_fail (TRACKER_IS_XESAM_FIELD (field));
+ g_return_if_fail (tracker_xesam_field_get_name (field) != NULL);
+
+ g_hash_table_insert (metadata_table,
+ g_utf8_strdown (tracker_xesam_field_get_name (field), -1),
+ field);
+
+}
+
+gchar *
+tracker_xesam_ontology_get_field_column_in_services (TrackerXesamField *field,
+ const gchar *service_type)
+{
+ const gchar *field_name;
+ const gchar *meta_name;
+ gint key_field;
+
+ meta_name = tracker_xesam_field_get_name (field);
+ key_field = tracker_xesam_ontology_metadata_key_in_service (service_type,
+ meta_name);
+
+ if (key_field > 0) {
+ return g_strdup_printf ("KeyMetadata%d", key_field);
+
+ }
+
+ /* TODO do it using field_name in TrackerXesamField! */
+ field_name = tracker_xesam_field_get_field_name (field);
+ if (field_name) {
+ return g_strdup (field_name);
+ } else {
+ return NULL;
+ }
+}
+
+gchar *
+tracker_xesam_ontology_get_display_field (TrackerXesamField *field)
+{
+ TrackerXesamFieldType type;
+
+ type = tracker_xesam_field_get_data_type (field);
+
+ if (type == TRACKER_XESAM_FIELD_TYPE_INDEX ||
+ type == TRACKER_XESAM_FIELD_TYPE_STRING ||
+ type == TRACKER_XESAM_FIELD_TYPE_DOUBLE) {
+ return g_strdup ("MetaDataDisplay");
+ }
+
+ return g_strdup ("MetaDataValue");
+}
+
+gboolean
+tracker_xesam_ontology_field_is_child_of (const gchar *child,
+ const gchar *parent)
+{
+ TrackerXesamField *def_child;
+ TrackerXesamField *def_parent;
+ const GSList *tmp;
+
+ def_child = tracker_xesam_ontology_get_field_def (child);
+
+ if (!def_child) {
+ return FALSE;
+ }
+
+ def_parent = tracker_xesam_ontology_get_field_def (parent);
+
+ if (!def_parent) {
+ return FALSE;
+ }
+
+ for (tmp = tracker_xesam_field_get_child_ids (def_parent); tmp; tmp = tmp->next) {
+
+ if (!tmp->data) return FALSE;
+
+ if (strcmp (tracker_xesam_field_get_id (def_child), tmp->data) == 0) {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+TrackerXesamField *
+tracker_xesam_ontology_get_field_def (const gchar *name)
+{
+ return xesam_ontology_hash_lookup_by_str (metadata_table, name);
+}
+
+const gchar *
+tracker_xesam_ontology_get_field_id (const gchar *name)
+{
+ TrackerXesamField *field;
+
+ field = tracker_xesam_ontology_get_field_def (name);
+
+ if (field) {
+ return tracker_xesam_field_get_id (field);
+ }
+
+ return NULL;
+}
+
Added: branches/xesam-support/src/libtracker-common/tracker-xesam-ontology.h
==============================================================================
--- (empty file)
+++ branches/xesam-support/src/libtracker-common/tracker-xesam-ontology.h Wed Jun 11 11:02:07 2008
@@ -0,0 +1,71 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia (urho konttori nokia com)
+ * Authors: Ottela Mikael (mikael ottela ixonos com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __TRACKERD_XESAM_ONTOLOGY_H__
+#define __TRACKERD_XESAM_ONTOLOGY_H__
+
+#include <glib-object.h>
+
+#include <libtracker-common/tracker-xesam-field.h>
+#include <libtracker-common/tracker-field.h>
+#include <libtracker-common/tracker-service.h>
+
+G_BEGIN_DECLS
+
+void tracker_xesam_ontology_init (void);
+void tracker_xesam_ontology_shutdown (void);
+void tracker_xesam_ontology_add_service_type (TrackerService *service,
+ GSList *mimes,
+ GSList *mime_prefixes);
+TrackerService *tracker_xesam_ontology_get_service_type_by_name (const gchar *service_str);
+gchar * tracker_xesam_ontology_get_service_type_by_id (gint id);
+gint tracker_xesam_ontology_get_id_for_service_type (const gchar *service_str);
+gchar * tracker_xesam_ontology_get_parent_service (const gchar *service_str);
+gchar * tracker_xesam_ontology_get_parent_service_by_id (gint id);
+gint tracker_xesam_ontology_get_parent_id_for_service_id (gint id);
+TrackerDBType tracker_xesam_ontology_get_db_for_service_type (const gchar *service_str);
+gboolean tracker_xesam_ontology_is_valid_service_type (const gchar *service_str);
+gboolean tracker_xesam_ontology_show_service_directories (const gchar *service_str);
+gboolean tracker_xesam_ontology_show_service_files (const gchar *service_str);
+
+/* Service directories */
+GSList * tracker_xesam_ontology_get_dirs_for_service_type (const gchar *service);
+void tracker_xesam_ontology_add_dir_to_service_type (const gchar *service,
+ const gchar *path);
+void tracker_xesam_ontology_remove_dir_to_service_type (const gchar *service,
+ const gchar *path);
+gchar * tracker_xesam_ontology_get_service_type_for_dir (const gchar *path);
+
+/* Field handling */
+void tracker_xesam_ontology_add_field (TrackerXesamField *field);
+gchar * tracker_xesam_ontology_get_field_column_in_services (TrackerXesamField *field,
+ const gchar *service_type);
+gchar * tracker_xesam_ontology_get_display_field (TrackerXesamField *field);
+gboolean tracker_xesam_ontology_field_is_child_of (const gchar *child,
+ const gchar *parent);
+TrackerXesamField * tracker_xesam_ontology_get_field_def (const gchar *name);
+const gchar * tracker_xesam_ontology_get_field_id (const gchar *name);
+
+G_END_DECLS
+
+#endif /* __TRACKERD_XESAM_ONTOLOGY_H__ */
+
Modified: branches/xesam-support/src/libtracker-db/tracker-db-manager.c
==============================================================================
--- branches/xesam-support/src/libtracker-db/tracker-db-manager.c (original)
+++ branches/xesam-support/src/libtracker-db/tracker-db-manager.c Wed Jun 11 11:02:07 2008
@@ -26,8 +26,10 @@
#include <zlib.h>
#include <libtracker-common/tracker-field.h>
+#include <libtracker-common/tracker-xesam-field.h>
#include <libtracker-common/tracker-nfs-lock.h>
#include <libtracker-common/tracker-ontology.h>
+#include <libtracker-common/tracker-xesam-ontology.h>
#include <libtracker-common/tracker-type-utils.h>
#include <libtracker-common/tracker-utils.h>
@@ -944,6 +946,107 @@
return service;
}
+static TrackerXesamField *
+db_row_to_xesam_field_def (TrackerDBResultSet *result_set)
+{
+ TrackerXesamField *field_def;
+ TrackerFieldType field_type;
+ gchar *id_str, *name;
+ gint id;
+
+ field_def = tracker_xesam_field_new ();
+
+ tracker_db_result_set_get (result_set,
+ 0, &id,
+ 1, &name,
+ 2, &field_type,
+ -1);
+
+ id_str = tracker_int_to_string (id);
+
+ tracker_xesam_field_set_id (field_def, id_str);
+ tracker_xesam_field_set_name (field_def, name);
+ tracker_xesam_field_set_data_type (field_def, field_type);
+
+ g_free (id_str);
+ g_free (name);
+
+ return field_def;
+}
+
+static TrackerService *
+db_row_to_xesam_service (TrackerDBResultSet *result_set)
+{
+ TrackerService *service;
+ GSList *new_list = NULL;
+ gint id, i;
+ gchar *name, *parent, *content_metadata;
+ gboolean enabled, embedded, has_metadata, has_fulltext;
+ gboolean has_thumbs, show_service_files, show_service_directories;
+
+ service = tracker_service_new ();
+
+ tracker_db_result_set_get (result_set,
+ 0, &id,
+ 1, &name,
+ 2, &parent,
+ 3, &enabled,
+ 4, &embedded,
+ 5, &has_metadata,
+ 6, &has_fulltext,
+ 7, &has_thumbs,
+ 8, &content_metadata,
+ 10, &show_service_files,
+ 11, &show_service_directories,
+ -1);
+
+ tracker_service_set_id (service, id);
+ tracker_service_set_name (service, name);
+ tracker_service_set_parent (service, parent);
+ tracker_service_set_enabled (service, enabled);
+ tracker_service_set_embedded (service, embedded);
+ tracker_service_set_has_metadata (service, has_metadata);
+ tracker_service_set_has_full_text (service, has_fulltext);
+ tracker_service_set_has_thumbs (service, has_thumbs);
+ tracker_service_set_content_metadata (service, content_metadata);
+
+ tracker_service_set_show_service_files (service, show_service_files);
+ tracker_service_set_show_service_directories (service, show_service_directories);
+
+ for (i = 12; i < 23; i++) {
+ gchar *metadata;
+
+ tracker_db_result_set_get (result_set, i, &metadata, -1);
+
+ if (metadata) {
+ new_list = g_slist_prepend (new_list, metadata);
+ }
+ }
+
+ /* FIXME: is this necessary? */
+#if 0
+ /* Hack to prevent db change late in the cycle, check the
+ * service name matches "Applications", then add some voodoo.
+ */
+ if (strcmp (name, "Applications") == 0) {
+ /* These strings should be definitions at the top of
+ * this file somewhere really.
+ */
+ new_list = g_slist_prepend (new_list, g_strdup ("App:DisplayName"));
+ new_list = g_slist_prepend (new_list, g_strdup ("App:Exec"));
+ new_list = g_slist_prepend (new_list, g_strdup ("App:Icon"));
+ }
+#endif
+
+ new_list = g_slist_reverse (new_list);
+
+ tracker_service_set_key_metadata (service, new_list);
+ g_slist_foreach (new_list, (GFunc) g_free, NULL);
+ g_slist_free (new_list);
+
+ return service;
+}
+
static GSList *
db_mime_query (TrackerDBInterface *iface,
const gchar *stored_proc,
@@ -1493,6 +1596,84 @@
}
}
+static void
+db_get_static_xesam_data (TrackerDBInterface *iface)
+{
+ TrackerDBResultSet *result_set;
+
+ /* Get static xesam metadata info */
+ result_set = tracker_db_interface_execute_procedure (iface,
+ NULL,
+ "GetXesamMetadataTypes",
+ NULL);
+
+ if (result_set) {
+ gboolean valid = TRUE;
+
+ while (valid) {
+ TrackerXesamField *def;
+
+ def = db_row_to_xesam_field_def (result_set);
+
+ g_message ("Loading xesam metadata def:'%s' with type:%d",
+ tracker_xesam_field_get_name (def),
+ tracker_xesam_field_get_data_type (def));
+
+ tracker_xesam_ontology_add_field (def);
+
+ valid = tracker_db_result_set_iter_next (result_set);
+ }
+
+ g_object_unref (result_set);
+ }
+
+ /* Get static xesam service info */
+ result_set = tracker_db_interface_execute_procedure (iface,
+ NULL,
+ "GetAllServices",
+ NULL);
+
+ if (result_set) {
+ gboolean valid = TRUE;
+
+ while (valid) {
+ TrackerService *service;
+ GSList *mimes, *mime_prefixes;
+ const gchar *name;
+ gint id;
+
+ service = db_row_to_service (result_set);
+
+ if (!service) {
+ continue;
+ }
+
+ id = tracker_service_get_id (service);
+ name = tracker_service_get_name (service);
+
+ mimes = db_get_mimes_for_service_id (iface, id);
+ mime_prefixes = db_get_mime_prefixes_for_service_id (iface, id);
+
+ g_message ("Adding xesam service:'%s' with id:%d and mimes:%d",
+ name,
+ id,
+ g_slist_length (mimes));
+
+ tracker_xesam_ontology_add_service_type (service,
+ mimes,
+ mime_prefixes);
+
+ g_slist_free (mimes);
+ g_slist_free (mime_prefixes);
+ g_object_unref (service);
+
+ valid = tracker_db_result_set_iter_next (result_set);
+ }
+
+ g_object_unref (result_set);
+ }
+}
+
static const gchar *
db_type_to_string (TrackerDB db)
{
@@ -1935,6 +2116,9 @@
"ATTACH '%s' as 'cache'",
tracker_db_manager_get_file (TRACKER_DB_CACHE));
+ /* Load static xesam data */
+ db_get_static_xesam_data (iface);
+
return iface;
}
Modified: branches/xesam-support/src/trackerd/Makefile.am
==============================================================================
--- branches/xesam-support/src/trackerd/Makefile.am (original)
+++ branches/xesam-support/src/trackerd/Makefile.am Wed Jun 11 11:02:07 2008
@@ -110,8 +110,6 @@
tracker-watcher.h \
tracker-xesam.c \
tracker-xesam.h \
- tracker-xesam-ontology.c \
- tracker-xesam-ontology.h \
tracker-xesam-manager.c \
tracker-xesam-manager.h \
tracker-xesam-query.c \
Modified: branches/xesam-support/src/trackerd/tracker-main.c
==============================================================================
--- branches/xesam-support/src/trackerd/tracker-main.c (original)
+++ branches/xesam-support/src/trackerd/tracker-main.c Wed Jun 11 11:02:07 2008
@@ -812,6 +812,7 @@
tracker_nfs_lock_init (tracker_config_get_nfs_locking (tracker->config));
tracker_ontology_init ();
+ tracker_xesam_ontology_init ();
tracker_db_init ();
tracker_db_manager_init (FALSE, data_dir, user_data_dir, sys_tmp_dir); /* Using TRUE=broken */
tracker_xesam_manager_init ();
Modified: branches/xesam-support/src/trackerd/tracker-xesam-live-search.c
==============================================================================
--- branches/xesam-support/src/trackerd/tracker-xesam-live-search.c (original)
+++ branches/xesam-support/src/trackerd/tracker-xesam-live-search.c Wed Jun 11 11:02:07 2008
@@ -24,6 +24,8 @@
#include <dbus/dbus-glib-bindings.h>
#include "tracker-xesam-live-search.h"
+#include <libtracker-common/tracker-xesam-field.h>
+#include <libtracker-common/tracker-xesam-ontology.h>
#include "tracker-xesam.h"
#include "tracker-xesam-manager.h"
#include "tracker-xesam-query.h"
@@ -534,8 +536,10 @@
}
-// todo for ottela
-// You can of course replace this list with whatever is more convenient for you
+
+// todo pvanhoof
+// These values are not used, but rather values from libtracker-db/tracker-db-manager.c, where they are loaded. I didn't remove them yet, since they are used elsewhere.
+
typedef enum {
ARRAY_OF_INT,
ARRAY_OF_BOOLEAN,
@@ -548,9 +552,20 @@
} OntologyType;
static OntologyType
-get_type_for (TrackerXesamLiveSearch *self, gint column)
+get_type_for (TrackerXesamLiveSearch *self, gchar *field)
{
- // todo for ottela
+ TrackerXesamField *def;
+
+ g_debug ("get_type_for: %s", field);
+
+ def = tracker_xesam_ontology_get_field_def (field);
+
+ if (def) {
+ g_debug ("type for %s is %d", field, tracker_xesam_field_get_data_type (def));
+ }
+
+ // todo pvanhoof: I am just printing the value, nothing else. See the todo above.
+
return SANE_TYPE;
}
@@ -638,14 +653,17 @@
get_hit_data (TrackerXesamLiveSearch *self,
TrackerDBResultSet *result_set,
GPtrArray **hit_data,
- gint field_count)
+ GStrv fields)
{
GPtrArray *result = g_ptr_array_new ();
GPtrArray *rows = g_ptr_array_new ();
gboolean valid = TRUE;
+ guint field_count;
+
+ field_count = g_strv_length (fields);
while (valid) {
- gint column;
+ guint column;
GPtrArray *row;
GValue value_in = {0, };
gboolean insert = FALSE;
@@ -696,7 +714,7 @@
column,
&cur_value);
- switch (get_type_for (self, column)) {
+ switch (get_type_for (self, fields[column-1])) {
case ARRAY_OF_STRING: {
GValue *variant;
GPtrArray *my_array;
@@ -885,8 +903,8 @@
get_hit_data (self,
result_set,
- hits,
- g_strv_length(fields));
+ hits,
+ fields);
g_object_unref (result_set);
} else {
@@ -952,8 +970,8 @@
get_hit_data (self,
result_set,
- hits,
- g_strv_length(fields));
+ hits,
+ fields);
g_object_unref (result_set);
} else {
@@ -1027,8 +1045,8 @@
get_hit_data (self,
result_set,
- hit_data,
- g_strv_length (fields));
+ hit_data,
+ fields);
g_object_unref (result_set);
} else {
@@ -1072,8 +1090,8 @@
get_hit_data (self,
result_set,
- hit_data,
- g_strv_length(fields));
+ hit_data,
+ fields);
g_object_unref (result_set);
} else {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]