[tracker/class-signal: 29/50] tracker-writeback: Port tracker-writeback to libtracker-sparql
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/class-signal: 29/50] tracker-writeback: Port tracker-writeback to libtracker-sparql
- Date: Fri, 27 Aug 2010 11:50:29 +0000 (UTC)
commit cf93f259b00d4e61a21277fa65c9cd515e9a19ca
Author: Philip Van Hoof <philip codeminded be>
Date: Mon Aug 23 17:49:07 2010 +0200
tracker-writeback: Port tracker-writeback to libtracker-sparql
src/tracker-writeback/Makefile.am | 4 +-
src/tracker-writeback/tracker-writeback-consumer.c | 99 +++++++----
src/tracker-writeback/tracker-writeback-consumer.h | 2 +-
.../tracker-writeback-dispatcher.c | 1 -
.../tracker-writeback-dispatcher.h | 1 -
src/tracker-writeback/tracker-writeback-file.c | 14 +-
src/tracker-writeback/tracker-writeback-file.h | 10 +-
src/tracker-writeback/tracker-writeback-playlist.c | 96 +++++------
src/tracker-writeback/tracker-writeback-taglib.c | 122 +++++--------
src/tracker-writeback/tracker-writeback-xmp.c | 186 ++++++++------------
src/tracker-writeback/tracker-writeback.c | 8 +-
src/tracker-writeback/tracker-writeback.h | 16 +-
12 files changed, 257 insertions(+), 302 deletions(-)
---
diff --git a/src/tracker-writeback/Makefile.am b/src/tracker-writeback/Makefile.am
index 76e37c3..4e6bbfa 100644
--- a/src/tracker-writeback/Makefile.am
+++ b/src/tracker-writeback/Makefile.am
@@ -11,7 +11,7 @@ INCLUDES = \
-DWRITEBACK_MODULES_DIR=\""$(modulesdir)"\" \
-I$(top_srcdir)/src \
-I$(top_builddir)/src \
- -I$(top_builddir)/src/libtracker-client \
+ -I$(top_builddir)/src/libtracker-sparql \
$(TRACKER_APPS_CFLAGS) \
$(WARN_CFLAGS) \
$(GLIB2_CFLAGS) \
@@ -73,7 +73,7 @@ tracker_writeback_SOURCES = \
tracker-main.c
tracker_writeback_LDADD = \
- $(top_builddir)/src/libtracker-client/libtracker-client- TRACKER_API_VERSION@.la \
+ $(top_builddir)/src/libtracker-sparql/libtracker-sparql- TRACKER_API_VERSION@.la \
$(top_builddir)/src/libtracker-miner/libtracker-miner- TRACKER_API_VERSION@.la \
$(top_builddir)/src/libtracker-common/libtracker-common.la \
$(TRACKER_APPS_LIBS) \
diff --git a/src/tracker-writeback/tracker-writeback-consumer.c b/src/tracker-writeback/tracker-writeback-consumer.c
index 66a2b56..564e3bd 100644
--- a/src/tracker-writeback/tracker-writeback-consumer.c
+++ b/src/tracker-writeback/tracker-writeback-consumer.c
@@ -22,7 +22,7 @@
#include <stdlib.h>
#include <libtracker-common/tracker-dbus.h>
-#include <libtracker-client/tracker.h>
+#include <libtracker-sparql/tracker-sparql.h>
#include "tracker-writeback-consumer.h"
#include "tracker-writeback-dbus.h"
@@ -43,7 +43,7 @@ typedef struct {
typedef struct {
GHashTable *modules;
- TrackerClient *client;
+ TrackerSparqlConnection *connection;
TrackerMinerManager *manager;
GQueue *process_queue;
guint idle_id;
@@ -77,10 +77,19 @@ static void
tracker_writeback_consumer_init (TrackerWritebackConsumer *consumer)
{
TrackerWritebackConsumerPrivate *priv;
+ GError *error = NULL;
priv = TRACKER_WRITEBACK_CONSUMER_GET_PRIVATE (consumer);
- priv->client = tracker_client_new (TRACKER_CLIENT_ENABLE_WARNINGS, G_MAXINT);
+ priv->connection = tracker_sparql_connection_get (&error);
+
+ if (!priv->connection) {
+ g_printerr ("%s: %s\n",
+ _("Could not establish a connection to Tracker"),
+ error ? error->message : _("No error given"));
+ g_clear_error (&error);
+ }
+
priv->modules = g_hash_table_new_full (g_str_hash,
g_str_equal,
(GDestroyNotify) g_free,
@@ -98,8 +107,8 @@ tracker_writeback_consumer_finalize (GObject *object)
priv = TRACKER_WRITEBACK_CONSUMER_GET_PRIVATE (object);
- if (priv->client) {
- g_object_unref (priv->client);
+ if (priv->connection) {
+ g_object_unref (priv->connection);
}
g_object_unref (priv->manager);
@@ -157,50 +166,78 @@ sparql_rdf_types_match (const gchar * const *module_types,
}
static void
-sparql_query_cb (GPtrArray *result,
- GError *error,
- gpointer user_data)
+sparql_query_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
{
TrackerWritebackConsumerPrivate *priv;
TrackerWritebackConsumer *consumer;
QueryData *data;
+ GError *error = NULL;
+ TrackerSparqlCursor *cursor;
consumer = TRACKER_WRITEBACK_CONSUMER (user_data);
priv = TRACKER_WRITEBACK_CONSUMER_GET_PRIVATE (consumer);
data = g_queue_pop_head (priv->process_queue);
- if (!error && result && result->len > 0) {
- GHashTableIter iter;
- gpointer key, value;
- GStrv rdf_types;
+ cursor = tracker_sparql_connection_query_finish (TRACKER_SPARQL_CONNECTION (object), result, &error);
- rdf_types = data->rdf_types;
+ if (!error) {
+ GPtrArray *results = g_ptr_array_new ();
+ guint cols = tracker_sparql_cursor_get_n_columns (cursor);
+
+ while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
+ GStrv row = g_new0 (gchar*, cols);
+ guint i;
+ for (i = 0; i < cols; i++)
+ row[i] = g_strdup (tracker_sparql_cursor_get_string (cursor, i, NULL));
+ g_ptr_array_add (results, row);
+ }
- g_hash_table_iter_init (&iter, priv->modules);
+ if (results->len > 0) {
+ GHashTableIter iter;
+ gpointer key, value;
+ GStrv rdf_types;
- while (g_hash_table_iter_next (&iter, &key, &value)) {
- TrackerWritebackModule *module;
- const gchar * const *module_types;
+ rdf_types = data->rdf_types;
- module = value;
- module_types = tracker_writeback_module_get_rdf_types (module);
+ g_hash_table_iter_init (&iter, priv->modules);
- if (sparql_rdf_types_match (module_types, (const gchar * const *) rdf_types)) {
- TrackerWriteback *writeback;
+ while (g_hash_table_iter_next (&iter, &key, &value)) {
+ TrackerWritebackModule *module;
+ const gchar * const *module_types;
- g_message (" Updating metadata for subject:'%s' using module:'%s'",
- data->subject,
- module->name);
+ module = value;
+ module_types = tracker_writeback_module_get_rdf_types (module);
- writeback = tracker_writeback_module_create (module);
- tracker_writeback_update_metadata (writeback, result, priv->client);
- g_object_unref (writeback);
+ if (sparql_rdf_types_match (module_types, (const gchar * const *) rdf_types)) {
+ TrackerWriteback *writeback;
+
+ g_message (" Updating metadata for subject:'%s' using module:'%s'",
+ data->subject,
+ module->name);
+
+ writeback = tracker_writeback_module_create (module);
+ tracker_writeback_update_metadata (writeback, results, priv->connection);
+ g_object_unref (writeback);
+ }
}
+ g_ptr_array_foreach (results, (GFunc) g_strfreev, NULL);
+ } else {
+ g_message (" No files qualify for updates");
}
+ g_ptr_array_free (results, TRUE);
} else {
- g_message (" No files qualify for updates");
+ if (error != NULL) {
+ g_message (" No files qualify for updates (%s)", error->message);
+ g_error_free (error);
+ } else {
+ g_message (" No files qualify for updates");
+ }
}
+ g_object_unref (cursor);
+
g_free (data->subject);
g_strfreev (data->rdf_types);
g_slice_free (QueryData, data);
@@ -234,10 +271,8 @@ process_queue_cb (gpointer user_data)
"}",
data->subject, data->subject);
- tracker_resources_sparql_query_async (priv->client,
- query,
- sparql_query_cb,
- consumer);
+ tracker_sparql_connection_query_async (priv->connection, query, NULL,
+ sparql_query_cb, consumer);
g_free (query);
diff --git a/src/tracker-writeback/tracker-writeback-consumer.h b/src/tracker-writeback/tracker-writeback-consumer.h
index a1da2d4..d36c48b 100644
--- a/src/tracker-writeback/tracker-writeback-consumer.h
+++ b/src/tracker-writeback/tracker-writeback-consumer.h
@@ -23,7 +23,7 @@
#include <glib-object.h>
#include <gio/gio.h>
-#include <libtracker-client/tracker.h>
+#include <libtracker-sparql/tracker-sparql.h>
G_BEGIN_DECLS
diff --git a/src/tracker-writeback/tracker-writeback-dispatcher.c b/src/tracker-writeback/tracker-writeback-dispatcher.c
index 3321aef..2691d8c 100644
--- a/src/tracker-writeback/tracker-writeback-dispatcher.c
+++ b/src/tracker-writeback/tracker-writeback-dispatcher.c
@@ -18,7 +18,6 @@
*/
#include <libtracker-common/tracker-dbus.h>
-#include <libtracker-client/tracker.h>
#include "tracker-writeback-dispatcher.h"
#include "tracker-writeback-dbus.h"
diff --git a/src/tracker-writeback/tracker-writeback-dispatcher.h b/src/tracker-writeback/tracker-writeback-dispatcher.h
index cba5071..ec600ac 100644
--- a/src/tracker-writeback/tracker-writeback-dispatcher.h
+++ b/src/tracker-writeback/tracker-writeback-dispatcher.h
@@ -23,7 +23,6 @@
#include <glib-object.h>
#include <gio/gio.h>
-#include <libtracker-client/tracker.h>
G_BEGIN_DECLS
diff --git a/src/tracker-writeback/tracker-writeback-file.c b/src/tracker-writeback/tracker-writeback-file.c
index daa0933..7f699da 100644
--- a/src/tracker-writeback/tracker-writeback-file.c
+++ b/src/tracker-writeback/tracker-writeback-file.c
@@ -23,9 +23,9 @@
#include "tracker-writeback-file.h"
-static gboolean tracker_writeback_file_update_metadata (TrackerWriteback *writeback,
- GPtrArray *values,
- TrackerClient *client);
+static gboolean tracker_writeback_file_update_metadata (TrackerWriteback *writeback,
+ GPtrArray *values,
+ TrackerSparqlConnection *connection);
G_DEFINE_ABSTRACT_TYPE (TrackerWritebackFile, tracker_writeback_file, TRACKER_TYPE_WRITEBACK)
@@ -60,9 +60,9 @@ file_unlock_cb (gpointer user_data)
}
static gboolean
-tracker_writeback_file_update_metadata (TrackerWriteback *writeback,
- GPtrArray *values,
- TrackerClient *client)
+tracker_writeback_file_update_metadata (TrackerWriteback *writeback,
+ GPtrArray *values,
+ TrackerSparqlConnection *connection)
{
TrackerWritebackFileClass *writeback_file_class;
gboolean retval;
@@ -130,7 +130,7 @@ tracker_writeback_file_update_metadata (TrackerWriteback *writeback,
urls);
retval = (writeback_file_class->update_file_metadata) (TRACKER_WRITEBACK_FILE (writeback),
- file, values, client);
+ file, values, connection);
g_timeout_add_seconds (3, file_unlock_cb, g_object_ref (file));
}
diff --git a/src/tracker-writeback/tracker-writeback-file.h b/src/tracker-writeback/tracker-writeback-file.h
index 05da3b0..c3ffbc3 100644
--- a/src/tracker-writeback/tracker-writeback-file.h
+++ b/src/tracker-writeback/tracker-writeback-file.h
@@ -43,11 +43,11 @@ struct TrackerWritebackFile {
struct TrackerWritebackFileClass {
TrackerWritebackClass parent_class;
- gboolean (* update_file_metadata) (TrackerWritebackFile *writeback_file,
- GFile *file,
- GPtrArray *values,
- TrackerClient *client);
- const gchar * const * (* content_types) (TrackerWritebackFile *writeback_file);
+ gboolean (* update_file_metadata) (TrackerWritebackFile *writeback_file,
+ GFile *file,
+ GPtrArray *values,
+ TrackerSparqlConnection *connection);
+ const gchar * const * (* content_types) (TrackerWritebackFile *writeback_file);
};
diff --git a/src/tracker-writeback/tracker-writeback-playlist.c b/src/tracker-writeback/tracker-writeback-playlist.c
index 0266391..5116caa 100644
--- a/src/tracker-writeback/tracker-writeback-playlist.c
+++ b/src/tracker-writeback/tracker-writeback-playlist.c
@@ -1,4 +1,3 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2009, Nokia <ivan frade nokia com>
*
@@ -48,11 +47,11 @@ struct PlaylistMap {
};
static GType tracker_writeback_playlist_get_type (void) G_GNUC_CONST;
-static gboolean writeback_playlist_update_file_metadata (TrackerWritebackFile *wbf,
- GFile *file,
- GPtrArray *values,
- TrackerClient *client);
-static const gchar * const *writeback_playlist_content_types (TrackerWritebackFile *wbf);
+static gboolean writeback_playlist_update_file_metadata (TrackerWritebackFile *wbf,
+ GFile *file,
+ GPtrArray *values,
+ TrackerSparqlConnection *connection);
+static const gchar * const *writeback_playlist_content_types (TrackerWritebackFile *wbf);
G_DEFINE_DYNAMIC_TYPE (TrackerWritebackPlaylist, tracker_writeback_playlist, TRACKER_TYPE_WRITEBACK_FILE);
@@ -99,7 +98,7 @@ writeback_playlist_content_types (TrackerWritebackFile *wbf)
static gboolean
get_playlist_type (GFile *file,
- TotemPlParserType *type)
+ TotemPlParserType *type)
{
GFileInfo *file_info;
const gchar *mime_type;
@@ -139,13 +138,13 @@ get_playlist_type (GFile *file,
}
static void
-rewrite_playlist (TrackerClient *client,
- GFile *file,
- const gchar *subject)
+rewrite_playlist (TrackerSparqlConnection *connection,
+ GFile *file,
+ const gchar *subject)
{
TotemPlParserType type;
gchar *path;
- GPtrArray *array;
+ TrackerSparqlCursor *cursor;
GError *error = NULL;
gchar *query;
@@ -154,76 +153,65 @@ rewrite_playlist (TrackerClient *client,
}
path = g_file_get_path (file);
-
query = g_strdup_printf ("SELECT ?entry { ?unknown a nfo:MediaFileListEntry ; "
"nie:url '%s' ; "
"nfo:entryContent ?entry"
"}", subject);
-
- array = tracker_resources_sparql_query (client, query, &error);
-
+ cursor = tracker_sparql_connection_query (connection, query, NULL, &error);
g_free (query);
if (!error) {
- if (array && array->len > 0) {
- TotemPlParser *parser;
- TotemPlPlaylist *playlist;
- TotemPlPlaylistIter iter;
- guint i;
-
- parser = totem_pl_parser_new ();
- playlist = totem_pl_playlist_new ();
-
- for (i = 0; i < array->len; i++) {
- GStrv row;
-
- row = g_ptr_array_index (array, i);
-
- if (row && row[0]) {
- totem_pl_playlist_append (playlist, &iter);
- totem_pl_playlist_set (playlist, &iter,
- TOTEM_PL_PARSER_FIELD_URI, row[0],
- NULL);
- }
- }
+ TotemPlParser *parser;
+ TotemPlPlaylist *playlist;
+ TotemPlPlaylistIter iter;
+ guint amount = 0;
+
+ parser = totem_pl_parser_new ();
+ playlist = totem_pl_playlist_new ();
+
+ while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
+ totem_pl_playlist_append (playlist, &iter);
+ totem_pl_playlist_set (playlist, &iter,
+ TOTEM_PL_PARSER_FIELD_URI,
+ tracker_sparql_cursor_get_string (cursor, 0),
+ NULL);
+ amount++;
+ }
+ if (amount > 0) {
totem_pl_parser_save (parser, playlist, file, NULL, type, &error);
-
- if (error) {
- g_critical ("Could not save playlist: %s\n", error->message);
- g_error_free (error);
- }
-
- g_object_unref (playlist);
- g_object_unref (parser);
} else {
/* TODO: Empty the file in @path */
}
+ if (error) {
+ g_critical ("Could not save playlist: %s\n", error->message);
+ g_error_free (error);
+ }
+
+ g_object_unref (playlist);
+ g_object_unref (parser);
+ g_object_unref (cursor);
+
} else {
g_clear_error (&error);
}
- if (array) {
- g_ptr_array_foreach (array, (GFunc) g_strfreev, NULL);
- g_ptr_array_free (array, TRUE);
- }
-
g_free (path);
}
static gboolean
-writeback_playlist_update_file_metadata (TrackerWritebackFile *writeback_file,
- GFile *file,
- GPtrArray *values,
- TrackerClient *client)
+writeback_playlist_update_file_metadata (TrackerWritebackFile *writeback_file,
+ GFile *file,
+ GPtrArray *values,
+ TrackerSparqlConnection *connection)
{
guint n;
for (n = 0; n < values->len; n++) {
const GStrv row = g_ptr_array_index (values, n);
if (g_strcmp0 (row[2], TRACKER_NFO_PREFIX "entryCounter") == 0) {
- rewrite_playlist (client, file, row[0]);
+ rewrite_playlist (connection, file, row[0]);
break;
}
}
diff --git a/src/tracker-writeback/tracker-writeback-taglib.c b/src/tracker-writeback/tracker-writeback-taglib.c
index 20a78b5..6dd4077 100644
--- a/src/tracker-writeback/tracker-writeback-taglib.c
+++ b/src/tracker-writeback/tracker-writeback-taglib.c
@@ -42,15 +42,15 @@ struct TrackerWritebackTaglibClass {
};
static GType tracker_writeback_taglib_get_type (void) G_GNUC_CONST;
-static gboolean writeback_taglib_update_file_metadata (TrackerWritebackFile *wbf,
- GFile *file,
- GPtrArray *values,
- TrackerClient *client);
-static const gchar * const *writeback_taglib_content_types (TrackerWritebackFile *wbf);
-static gchar* writeback_taglib_get_artist_name (TrackerClient *client,
- const gchar *urn);
-static gchar* writeback_taglib_get_album_name (TrackerClient *client,
- const gchar *urn);
+static gboolean writeback_taglib_update_file_metadata (TrackerWritebackFile *wbf,
+ GFile *file,
+ GPtrArray *values,
+ TrackerSparqlConnection *connection);
+static const gchar * const *writeback_taglib_content_types (TrackerWritebackFile *wbf);
+static gchar* writeback_taglib_get_artist_name (TrackerSparqlConnection *connection,
+ const gchar *urn);
+static gchar* writeback_taglib_get_album_name (TrackerSparqlConnection *connection,
+ const gchar *urn);
G_DEFINE_DYNAMIC_TYPE (TrackerWritebackTaglib, tracker_writeback_taglib, TRACKER_TYPE_WRITEBACK_FILE);
@@ -129,10 +129,10 @@ writeback_taglib_content_types (TrackerWritebackFile *wbf)
}
static gboolean
-writeback_taglib_update_file_metadata (TrackerWritebackFile *writeback_file,
- GFile *file,
- GPtrArray *values,
- TrackerClient *client)
+writeback_taglib_update_file_metadata (TrackerWritebackFile *writeback_file,
+ GFile *file,
+ GPtrArray *values,
+ TrackerSparqlConnection *connection)
{
gboolean ret;
gchar *path;
@@ -158,7 +158,7 @@ writeback_taglib_update_file_metadata (TrackerWritebackFile *writeback_file,
}
if (g_strcmp0 (row[2], TRACKER_NMM_PREFIX "performer") == 0) {
- gchar *artist_name = writeback_taglib_get_artist_name (client, row[3]);
+ gchar *artist_name = writeback_taglib_get_artist_name (connection, row[3]);
if (artist_name) {
taglib_tag_set_artist (tag, artist_name);
@@ -167,7 +167,7 @@ writeback_taglib_update_file_metadata (TrackerWritebackFile *writeback_file,
}
if (g_strcmp0 (row[2], TRACKER_NMM_PREFIX "musicAlbum") == 0) {
- gchar *album_name = writeback_taglib_get_album_name (client, row[3]);
+ gchar *album_name = writeback_taglib_get_album_name (connection, row[3]);
if (album_name) {
taglib_tag_set_album (tag, album_name);
@@ -202,85 +202,61 @@ writeback_taglib_update_file_metadata (TrackerWritebackFile *writeback_file,
}
static gchar*
-writeback_taglib_get_artist_name (TrackerClient *client,
- const gchar *urn)
+writeback_taglib_get_from_query (TrackerSparqlConnection *connection,
+ const gchar *urn,
+ const gchar *query,
+ const gchar *errmsg)
{
gchar *query;
- GPtrArray *query_results;
+ TrackerSparqlCursor *cursor;
GError *error = NULL;
- GError *inner_error = NULL;
- gchar *artist_name;
-
- artist_name = NULL;
-
- query = g_strdup_printf ("SELECT ?artistName WHERE {<%s> nmm:artistName ?artistName}",
- urn);
+ GError *error = NULL;
+ gchar *value = NULL;
- query_results = tracker_resources_sparql_query (client,
- query,
- &inner_error);
+ cursor = tracker_sparql_connection_query (connection,
+ query,
+ NULL,
+ &error);
- if (error || query_results->len != 1) {
- g_warning ("Couldn't find artist name for artist with urn '%s', %s",
+ if (error || !tracker_sparql_cursor_next (cursor, NULL, NULL)) {
+ g_warning ("Couldn't find %s for artist with urn '%s', %s",
+ errmsg,
urn,
- error ? error->message : "no such artist was found");
+ error ? error->message : "no such was found");
if (error) {
g_error_free (error);
}
} else {
- gchar **data;
-
- data = g_ptr_array_index (query_results, 0);
- artist_name = g_strdup (data[0]);
+ value = g_strdup (tracker_sparql_cursor_get_string (cursor, 0));
}
- g_free (query);
- g_ptr_array_foreach (query_results, (GFunc) g_strfreev, NULL);
- g_ptr_array_free (query_results, TRUE);
-
- return artist_name;
+ return value;
}
+
static gchar*
-writeback_taglib_get_album_name (TrackerClient *client,
- const gchar *urn)
+writeback_taglib_get_artist_name (TrackerSparqlConnection *connection,
+ const gchar *urn)
{
- gchar *query;
- GPtrArray *query_results;
- GError *error = NULL;
- GError *inner_error = NULL;
- gchar *album_name;
-
- album_name = NULL;
+ gchar *val, *query;
+ query = g_strdup_printf ("SELECT ?artistName WHERE {<%s> nmm:artistName ?artistName}",
+ urn);
+ val = writeback_taglib_get_from_query (connection, urn, query, "artist name");
+ g_free (query);
+ return val;
+}
+static gchar*
+writeback_taglib_get_album_name (TrackerSparqlConnection *connection,
+ const gchar *urn)
+{
+ gchar *val, *query;
query = g_strdup_printf ("SELECT ?albumName WHERE {<%s> dc:title ?albumName}",
urn);
-
- query_results = tracker_resources_sparql_query (client,
- query,
- &inner_error);
-
- if (error || query_results->len != 1) {
- g_warning ("Couldn't find album name for album with urn '%s', %s",
- urn,
- error ? error->message : "no such album was found");
-
- if (error) {
- g_error_free (error);
- }
- } else {
- gchar **data;
-
- data = g_ptr_array_index (query_results, 0);
- album_name = g_strdup (data[0]);
- }
-
+ val = writeback_taglib_get_from_query (connection, urn, query, "album name");
g_free (query);
- g_ptr_array_foreach (query_results, (GFunc) g_strfreev, NULL);
- g_ptr_array_free (query_results, TRUE);
-
- return album_name;
+ return val;
}
TrackerWriteback *
diff --git a/src/tracker-writeback/tracker-writeback-xmp.c b/src/tracker-writeback/tracker-writeback-xmp.c
index 0e1ccb9..0b87291 100644
--- a/src/tracker-writeback/tracker-writeback-xmp.c
+++ b/src/tracker-writeback/tracker-writeback-xmp.c
@@ -49,11 +49,11 @@ struct TrackerWritebackXMPClass {
};
static GType tracker_writeback_xmp_get_type (void) G_GNUC_CONST;
-static gboolean writeback_xmp_update_file_metadata (TrackerWritebackFile *writeback_file,
- GFile *file,
- GPtrArray *values,
- TrackerClient *client);
-static const gchar * const *writeback_xmp_content_types (TrackerWritebackFile *writeback_file);
+static gboolean writeback_xmp_update_file_metadata (TrackerWritebackFile *writeback_file,
+ GFile *file,
+ GPtrArray *values,
+ TrackerSparqlConnection *connection);
+static const gchar * const *writeback_xmp_content_types (TrackerWritebackFile *writeback_file);
G_DEFINE_DYNAMIC_TYPE (TrackerWritebackXMP, tracker_writeback_xmp, TRACKER_TYPE_WRITEBACK_FILE);
@@ -105,10 +105,10 @@ writeback_xmp_content_types (TrackerWritebackFile *wbf)
}
static gboolean
-writeback_xmp_update_file_metadata (TrackerWritebackFile *wbf,
- GFile *file,
- GPtrArray *values,
- TrackerClient *client)
+writeback_xmp_update_file_metadata (TrackerWritebackFile *wbf,
+ GFile *file,
+ GPtrArray *values,
+ TrackerSparqlConnection *connection)
{
gchar *path;
guint n;
@@ -153,39 +153,28 @@ writeback_xmp_update_file_metadata (TrackerWritebackFile *wbf,
}
if (g_strcmp0 (row[2], TRACKER_NCO_PREFIX "creator") == 0) {
- GPtrArray *name_array;
+ TrackerSparqlCursor *cursor;
GError *error = NULL;
gchar *query;
query = g_strdup_printf ("SELECT ?fullname { "
" <%s> nco:fullname ?fullname "
"}", row[3]);
-
- name_array = tracker_resources_sparql_query (client, query, &error);
-
+ cursor = tracker_sparql_connection_query (connection, query, NULL, &error);
g_free (query);
-
- if (name_array && name_array->len > 0) {
- GStrv name_row;
-
- name_row = g_ptr_array_index (name_array, 0);
-
- if (name_row[0]) {
+ if (!error) {
+ while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
xmp_delete_property (xmp, NS_DC, "creator");
- xmp_set_property (xmp, NS_DC, "creator", name_row[0], 0);
+ xmp_set_property (xmp, NS_DC, "creator",
+ tracker_sparql_cursor_get_string (cursor, 0, NULL),
+ 0);
}
}
-
- if (name_array) {
- g_ptr_array_foreach (name_array, (GFunc) g_strfreev, NULL);
- g_ptr_array_free (name_array, TRUE);
- }
-
g_clear_error (&error);
}
if (g_strcmp0 (row[2], TRACKER_NCO_PREFIX "contributor") == 0) {
- GPtrArray *name_array;
+ TrackerSparqlCursor *cursor;
GError *error = NULL;
gchar *query;
@@ -193,26 +182,14 @@ writeback_xmp_update_file_metadata (TrackerWritebackFile *wbf,
" <%s> nco:fullname ?fullname "
"}", row[3]);
- name_array = tracker_resources_sparql_query (client, query, &error);
-
+ cursor = tracker_sparql_connection_query (connection, query, NULL, &error);
g_free (query);
-
- if (name_array && name_array->len > 0) {
- GStrv name_row;
-
- name_row = g_ptr_array_index (name_array, 0);
-
- if (name_row[0]) {
+ if (!error) {
+ while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
xmp_delete_property (xmp, NS_DC, "contributor");
- xmp_set_property (xmp, NS_DC, "contributor", name_row[0], 0);
+ xmp_set_property (xmp, NS_DC, "contributor", tracker_sparql_cursor_get_string (cursor, 0, NULL), 0);
}
}
-
- if (name_array) {
- g_ptr_array_foreach (name_array, (GFunc) g_strfreev, NULL);
- g_ptr_array_free (name_array, TRUE);
- }
-
g_clear_error (&error);
}
@@ -241,7 +218,7 @@ writeback_xmp_update_file_metadata (TrackerWritebackFile *wbf,
if (g_strcmp0 (row[2], TRACKER_NAO_PREFIX "hasTag") == 0) {
- GPtrArray *name_array;
+ TrackerSparqlCursor *cursor;
GError *error = NULL;
gchar *query;
@@ -249,29 +226,17 @@ writeback_xmp_update_file_metadata (TrackerWritebackFile *wbf,
" <%s> nao:prefLabel ?label "
"}", row[3]);
- name_array = tracker_resources_sparql_query (client, query, &error);
-
+ cursor = tracker_sparql_connection_query (connection, query, NULL, &error);
g_free (query);
-
- if (name_array && name_array->len > 0) {
- GStrv name_row;
-
- name_row = g_ptr_array_index (name_array, 0);
-
- if (name_row[0]) {
+ if (!error) {
+ while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
if (!keywords) {
- keywords = g_string_new (name_row[0]);
+ keywords = g_string_new (tracker_sparql_cursor_get_string (cursor, 0, NULL));
} else {
- g_string_append_printf (keywords, ", %s", name_row[0]);
+ g_string_append_printf (keywords, ", %s", tracker_sparql_cursor_get_string (cursor, 0, NULL));
}
}
}
-
- if (name_array) {
- g_ptr_array_foreach (name_array, (GFunc) g_strfreev, NULL);
- g_ptr_array_free (name_array, TRUE);
- }
-
g_clear_error (&error);
}
@@ -421,7 +386,7 @@ writeback_xmp_update_file_metadata (TrackerWritebackFile *wbf,
g_strcmp0 (row[2], TRACKER_MLO_PREFIX "state") == 0 ||
g_strcmp0 (row[2], TRACKER_MLO_PREFIX "address") == 0)
{
- GPtrArray *array;
+ TrackerSparqlCursor *cursor;
GError *error = NULL;
gchar *query;
@@ -430,62 +395,55 @@ writeback_xmp_update_file_metadata (TrackerWritebackFile *wbf,
" mlo:country (?location) "
"WHERE { <%s> mlo:location ?location }",
row[1]); /* The urn is at 1 */
-
- array = tracker_resources_sparql_query (client, query, &error);
-
+ cursor = tracker_sparql_connection_query (connection, query, NULL, &error);
g_free (query);
+ if (!error) {
+ if (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
+ const gchar *city, *subl, *country, *state;
+
+ city = tracker_sparql_cursor_get_string (cursor, 0, NULL);
+ state = tracker_sparql_cursor_get_string (cursor, 1, NULL);
+ subl = tracker_sparql_cursor_get_string (cursor, 2, NULL);
+ country = tracker_sparql_cursor_get_string (cursor, 3, NULL);
+
+ /* TODO: A lot of these location fields are pretty vague and ambigious.
+ * We should go through them one by one and ensure that all of them are
+ * used sanely */
+
+ if (!tracker_is_blank_string (city)) {
+ xmp_delete_property (xmp, NS_IPTC4XMP, "City");
+ xmp_set_property (xmp, NS_IPTC4XMP, "City", city, 0);
+ xmp_delete_property (xmp, NS_PHOTOSHOP, "City");
+ xmp_set_property (xmp, NS_PHOTOSHOP, "City", city, 0);
+ }
- if (array && array->len > 0) {
- GStrv qrow;
-
- qrow = g_ptr_array_index (array, 0);
-
- /* TODO: A lot of these location fields are pretty vague and ambigious.
- * We should go through them one by one and ensure that all of them are
- * used sanely */
+ if (!tracker_is_blank_string (state)) {
+ xmp_delete_property (xmp, NS_IPTC4XMP, "State");
+ xmp_set_property (xmp, NS_IPTC4XMP, "State", state, 0);
+ xmp_delete_property (xmp, NS_IPTC4XMP, "Province");
+ xmp_set_property (xmp, NS_IPTC4XMP, "Province", state, 0);
+ xmp_delete_property (xmp, NS_PHOTOSHOP, "State");
+ xmp_set_property (xmp, NS_PHOTOSHOP, "State", state, 0);
+ }
- if (!tracker_is_blank_string (qrow[0])) {
- xmp_delete_property (xmp, NS_IPTC4XMP, "City");
- xmp_set_property (xmp, NS_IPTC4XMP, "City", qrow[0], 0);
- xmp_delete_property (xmp, NS_PHOTOSHOP, "City");
- xmp_set_property (xmp, NS_PHOTOSHOP, "City", qrow[0], 0);
- }
- g_free (qrow[0]);
-
- if (!tracker_is_blank_string (qrow[1])) {
- xmp_delete_property (xmp, NS_IPTC4XMP, "State");
- xmp_set_property (xmp, NS_IPTC4XMP, "State", qrow[1], 0);
- xmp_delete_property (xmp, NS_IPTC4XMP, "Province");
- xmp_set_property (xmp, NS_IPTC4XMP, "Province", qrow[1], 0);
- xmp_delete_property (xmp, NS_PHOTOSHOP, "State");
- xmp_set_property (xmp, NS_PHOTOSHOP, "State", qrow[1], 0);
- }
- g_free (qrow[1]);
+ if (!tracker_is_blank_string (subl)) {
+ xmp_delete_property (xmp, NS_IPTC4XMP, "SubLocation");
+ xmp_set_property (xmp, NS_IPTC4XMP, "SubLocation", subl, 0);
+ xmp_delete_property (xmp, NS_PHOTOSHOP, "Location");
+ xmp_set_property (xmp, NS_PHOTOSHOP, "Location", subl, 0);
+ }
- if (!tracker_is_blank_string (qrow[2])) {
- xmp_delete_property (xmp, NS_IPTC4XMP, "SubLocation");
- xmp_set_property (xmp, NS_IPTC4XMP, "SubLocation", qrow[2], 0);
- xmp_delete_property (xmp, NS_PHOTOSHOP, "Location");
- xmp_set_property (xmp, NS_PHOTOSHOP, "Location", qrow[2], 0);
- }
- g_free (qrow[2]);
-
- if (!tracker_is_blank_string (qrow[3])) {
- xmp_delete_property (xmp, NS_PHOTOSHOP, "Country");
- xmp_set_property (xmp, NS_PHOTOSHOP, "Country", qrow[3], 0);
- xmp_delete_property (xmp, NS_IPTC4XMP, "Country");
- xmp_set_property (xmp, NS_IPTC4XMP, "Country", qrow[3], 0);
- xmp_delete_property (xmp, NS_IPTC4XMP, "PrimaryLocationName");
- xmp_set_property (xmp, NS_IPTC4XMP, "PrimaryLocationName", qrow[3], 0);
- xmp_delete_property (xmp, NS_IPTC4XMP, "CountryName");
- xmp_set_property (xmp, NS_IPTC4XMP, "CountryName", qrow[3], 0);
+ if (!tracker_is_blank_string (country)) {
+ xmp_delete_property (xmp, NS_PHOTOSHOP, "Country");
+ xmp_set_property (xmp, NS_PHOTOSHOP, "Country", country, 0);
+ xmp_delete_property (xmp, NS_IPTC4XMP, "Country");
+ xmp_set_property (xmp, NS_IPTC4XMP, "Country", country, 0);
+ xmp_delete_property (xmp, NS_IPTC4XMP, "PrimaryLocationName");
+ xmp_set_property (xmp, NS_IPTC4XMP, "PrimaryLocationName", country, 0);
+ xmp_delete_property (xmp, NS_IPTC4XMP, "CountryName");
+ xmp_set_property (xmp, NS_IPTC4XMP, "CountryName", country, 0);
+ }
}
- g_free (qrow[3]);
-
- }
-
- if (array) {
- g_ptr_array_free (array, TRUE);
}
g_clear_error (&error);
diff --git a/src/tracker-writeback/tracker-writeback.c b/src/tracker-writeback/tracker-writeback.c
index e356f76..6b26733 100644
--- a/src/tracker-writeback/tracker-writeback.c
+++ b/src/tracker-writeback/tracker-writeback.c
@@ -36,15 +36,15 @@ tracker_writeback_init (TrackerWriteback *writeback)
}
gboolean
-tracker_writeback_update_metadata (TrackerWriteback *writeback,
- GPtrArray *values,
- TrackerClient *client)
+tracker_writeback_update_metadata (TrackerWriteback *writeback,
+ GPtrArray *values,
+ TrackerSparqlConnection *connection)
{
g_return_val_if_fail (TRACKER_IS_WRITEBACK (writeback), FALSE);
g_return_val_if_fail (values != NULL, FALSE);
if (TRACKER_WRITEBACK_GET_CLASS (writeback)->update_metadata) {
- return TRACKER_WRITEBACK_GET_CLASS (writeback)->update_metadata (writeback, values, client);
+ return TRACKER_WRITEBACK_GET_CLASS (writeback)->update_metadata (writeback, values, connection);
}
return FALSE;
diff --git a/src/tracker-writeback/tracker-writeback.h b/src/tracker-writeback/tracker-writeback.h
index ab0e09e..c56d85e 100644
--- a/src/tracker-writeback/tracker-writeback.h
+++ b/src/tracker-writeback/tracker-writeback.h
@@ -23,7 +23,7 @@
#include <glib-object.h>
#include <libtracker-miner/tracker-miner.h>
-#include <libtracker-client/tracker.h>
+#include <libtracker-sparql/tracker-sparql.h>
G_BEGIN_DECLS
@@ -44,19 +44,19 @@ struct TrackerWriteback {
struct TrackerWritebackClass {
GObjectClass parent_class;
- gboolean (* update_metadata) (TrackerWriteback *writeback,
- GPtrArray *values,
- TrackerClient *client);
+ gboolean (* update_metadata) (TrackerWriteback *writeback,
+ GPtrArray *values,
+ TrackerSparqlConnection *connection);
};
GType tracker_writeback_get_type (void) G_GNUC_CONST;
-gboolean tracker_writeback_update_metadata (TrackerWriteback *writeback,
- GPtrArray *values,
- TrackerClient *client);
+gboolean tracker_writeback_update_metadata (TrackerWriteback *writeback,
+ GPtrArray *values,
+ TrackerSparqlConnection *connection);
TrackerMinerManager* tracker_writeback_get_miner_manager (void);
/* Entry functions to be defined by modules */
-TrackerWriteback * writeback_module_create (GTypeModule *module);
+TrackerWriteback * writeback_module_create (GTypeModule *module);
const gchar * const *writeback_module_get_rdf_types (void);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]