[tracker/writeback: 12/23] Added filter for the list of rdf:type being passed vs. module to elect
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker/writeback: 12/23] Added filter for the list of rdf:type being passed vs. module to elect
- Date: Wed, 25 Nov 2009 10:04:12 +0000 (UTC)
commit 0a549b31d35dd7edb41f48d7d5176937889fb641
Author: Philip Van Hoof <philip codeminded be>
Date: Tue Nov 17 12:11:45 2009 +0100
Added filter for the list of rdf:type being passed vs. module to elect
.../tracker-writeback-dispatcher.c | 45 +++++++++++++++----
src/tracker-writeback/tracker-writeback-module.c | 10 ++++-
src/tracker-writeback/tracker-writeback-module.h | 4 +-
src/tracker-writeback/tracker-writeback-mp3.c | 37 +++++++++++++---
src/tracker-writeback/tracker-writeback.h | 2 +-
5 files changed, 78 insertions(+), 20 deletions(-)
---
diff --git a/src/tracker-writeback/tracker-writeback-dispatcher.c b/src/tracker-writeback/tracker-writeback-dispatcher.c
index 652ed81..b7782d3 100644
--- a/src/tracker-writeback/tracker-writeback-dispatcher.c
+++ b/src/tracker-writeback/tracker-writeback-dispatcher.c
@@ -40,6 +40,7 @@ typedef struct {
typedef struct {
TrackerWritebackDispatcher *dispatcher;
+ GStrv rdf_types;
} QueryData;
#define TRACKER_WRITEBACK_DISPATCHER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRACKER_TYPE_WRITEBACK_DISPATCHER, TrackerWritebackDispatcherPrivate))
@@ -253,6 +254,24 @@ tracker_writeback_dispatcher_new ()
return g_object_new (TRACKER_TYPE_WRITEBACK_DISPATCHER, NULL);
}
+static gboolean
+types_match (const gchar **module_types, gchar **rdf_types)
+{
+ guint n;
+
+ for (n = 0; rdf_types[n] != NULL; n++) {
+ guint i;
+
+ for (i = 0; module_types[i] != NULL; i++) {
+ if (g_strcmp0 (module_types[i], rdf_types[n]) == 0) {
+ return TRUE;
+ }
+ }
+ }
+
+ return FALSE;
+}
+
static void
on_sparql_result_received (GPtrArray *result,
GError *error,
@@ -260,28 +279,34 @@ on_sparql_result_received (GPtrArray *result,
{
TrackerWritebackDispatcherPrivate *priv;
TrackerWritebackModule *module;
- TrackerWriteback *writeback;
GHashTableIter iter;
gpointer key, value;
QueryData *data;
+ const gchar **module_types;
+ gchar **rdf_types;
data = user_data;
+ rdf_types = data->rdf_types;
priv = TRACKER_WRITEBACK_DISPATCHER_GET_PRIVATE (data->dispatcher);
- /* FIXME: Lookup module by mimetype */
g_hash_table_iter_init (&iter, priv->modules);
- if (!g_hash_table_iter_next (&iter, &key, &value)) {
- return;
- }
+ while (g_hash_table_iter_next (&iter, &key, &value)) {
+ module = value;
- module = value;
- writeback = tracker_writeback_module_create (module);
+ module_types = tracker_writeback_module_get_rdftypes (module);
- tracker_writeback_update_metadata (writeback, result);
+ if (types_match (module_types, rdf_types)) {
+ TrackerWriteback *writeback;
- g_object_unref (writeback);
+ writeback = tracker_writeback_module_create (module);
+ tracker_writeback_update_metadata (writeback, result);
+ g_object_unref (writeback);
+ }
+ }
+
+ g_strfreev (data->rdf_types);
g_slice_free (QueryData, data);
}
@@ -292,7 +317,6 @@ on_writeback_cb (DBusGProxy *proxy,
{
TrackerWritebackDispatcherPrivate *priv;
QueryData *data;
- guint n;
GHashTableIter iter;
gpointer key, value;
@@ -313,6 +337,7 @@ on_writeback_cb (DBusGProxy *proxy,
data = g_slice_new (QueryData);
data->dispatcher = object;
+ data->rdf_types = g_strdupv (rdf_types);
tracker_resources_sparql_query_async (priv->client,
query,
diff --git a/src/tracker-writeback/tracker-writeback-module.c b/src/tracker-writeback/tracker-writeback-module.c
index 22d4cdf..ee21b08 100644
--- a/src/tracker-writeback/tracker-writeback-module.c
+++ b/src/tracker-writeback/tracker-writeback-module.c
@@ -67,8 +67,8 @@ tracker_writeback_module_load (GTypeModule *module)
if (!g_module_symbol (writeback_module->module, "writeback_module_create",
(gpointer *) &writeback_module->create) ||
- !g_module_symbol (writeback_module->module, "writeback_module_get_mimetypes",
- (gpointer *) &writeback_module->get_mimetypes)) {
+ !g_module_symbol (writeback_module->module, "writeback_module_get_rdftypes",
+ (gpointer *) &writeback_module->get_rdftypes)) {
g_warning ("Could not load module symbols for '%s': %s",
writeback_module->name,
g_module_error ());
@@ -153,3 +153,9 @@ tracker_writeback_module_create (TrackerWritebackModule *module)
{
return (module->create) (G_TYPE_MODULE (module));
}
+
+const gchar**
+tracker_writeback_module_get_rdftypes (TrackerWritebackModule *module)
+{
+ return (module->get_rdftypes) ();
+}
diff --git a/src/tracker-writeback/tracker-writeback-module.h b/src/tracker-writeback/tracker-writeback-module.h
index 84796f0..7f40ec0 100644
--- a/src/tracker-writeback/tracker-writeback-module.h
+++ b/src/tracker-writeback/tracker-writeback-module.h
@@ -41,7 +41,7 @@ struct TrackerWritebackModule {
gchar *name;
TrackerWriteback * (* create) (GTypeModule *module);
- GStrv (* get_mimetypes) (void);
+ const gchar ** (* get_rdftypes) (void);
};
struct TrackerWritebackModuleClass {
@@ -54,6 +54,8 @@ GType tracker_writeback_module_get_type (void)
TrackerWritebackModule * tracker_writeback_module_get (const gchar *name);
TrackerWriteback * tracker_writeback_module_create (TrackerWritebackModule *module);
+const gchar** tracker_writeback_module_get_rdftypes (TrackerWritebackModule *module);
+
GList * tracker_writeback_modules_list (void);
diff --git a/src/tracker-writeback/tracker-writeback-mp3.c b/src/tracker-writeback/tracker-writeback-mp3.c
index 6bb78e7..ef4cb03 100644
--- a/src/tracker-writeback/tracker-writeback-mp3.c
+++ b/src/tracker-writeback/tracker-writeback-mp3.c
@@ -65,7 +65,7 @@ tracker_writeback_mp3_init (TrackerWritebackMP3 *mp3)
static gboolean
tracker_writeback_mp3_update_metadata (TrackerWriteback *writeback,
- GPtrArray *values)
+ GPtrArray *values)
{
guint n;
const gchar *uri = NULL;
@@ -76,9 +76,32 @@ tracker_writeback_mp3_update_metadata (TrackerWriteback *writeback,
const GStrv row = g_ptr_array_index (values, n);
if (uri == NULL) {
+ GFileInfo *file_info;
+ const gchar *mime_type;
+
uri = row[0];
file = g_file_new_for_uri (uri);
- path = g_file_get_path (file);
+
+ file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ NULL, NULL);
+
+ if (!file_info) {
+ g_object_unref (file);
+ return FALSE;
+ }
+
+ mime_type = g_file_info_get_content_type (file_info);
+
+ if (g_strcmp0 (mime_type, "audio/mpeg") == 0 ||
+ g_strcmp0 (mime_type, "audio/x-mp3") == 0) {
+ g_object_unref (file_info);
+ path = g_file_get_path (file);
+ } else {
+ g_object_unref (file);
+ g_object_unref (file_info);
+ return FALSE;
+ }
}
if (g_strcmp0 (row[1], TRACKER_NIE_PREFIX "title") == 0) {
@@ -123,10 +146,12 @@ writeback_module_create (GTypeModule *module)
return g_object_new (TRACKER_TYPE_WRITEBACK_MP3, NULL);
}
-const GStrv
-writeback_module_get_mimetypes (void)
+const gchar**
+writeback_module_get_rdftypes (void)
{
- static const gchar *mimetypes[] = { "*", NULL };
+ static const gchar *rdftypes[] = { TRACKER_NFO_PREFIX "Document",
+ TRACKER_NMM_PREFIX "MusicPiece",
+ NULL };
- return (GStrv) mimetypes;
+ return rdftypes;
}
diff --git a/src/tracker-writeback/tracker-writeback.h b/src/tracker-writeback/tracker-writeback.h
index ab3bd53..e971b39 100644
--- a/src/tracker-writeback/tracker-writeback.h
+++ b/src/tracker-writeback/tracker-writeback.h
@@ -51,7 +51,7 @@ GType tracker_writeback_get_type (void) G_GNUC_CONST;
/* Entry functions to be defined by modules */
TrackerWriteback * writeback_module_create (GTypeModule *module);
-const GStrv writeback_module_get_mimetypes (void);
+const gchar** writeback_module_get_rdftypes (void);
gboolean tracker_writeback_update_metadata (TrackerWriteback *writeback,
GPtrArray *values);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]