[tracker/tracker-sparql-qt: 1/3] Add libtracker-sparql-qt



commit e6ab779cfd5b7307b19c54ef1218aba29d03bc92
Author: Adrien Bustany <abustany gnome org>
Date:   Sun Jan 16 10:01:51 2011 +0200

    Add libtracker-sparql-qt
    
    libtracker-sparql-qt is a simple QT wrapper for the sync API of
    libtracker-sparql. It is suitable for programs that needs a low-level
    access to Tracker (often for performance reasons). For a higher level
    API, consider using alternatives like QSParql.

 configure.ac                                 |   29 +++
 src/Makefile.am                              |    4 +
 src/libtracker-sparql-qt/Makefile.am         |   32 ++++
 src/libtracker-sparql-qt/common.h            |   14 ++
 src/libtracker-sparql-qt/connection.cpp      |  235 ++++++++++++++++++++++++++
 src/libtracker-sparql-qt/connection.h        |   63 +++++++
 src/libtracker-sparql-qt/cursor.cpp          |  185 ++++++++++++++++++++
 src/libtracker-sparql-qt/cursor.h            |   75 ++++++++
 src/libtracker-sparql-qt/error.cpp           |   90 ++++++++++
 src/libtracker-sparql-qt/error.h             |   49 ++++++
 src/libtracker-sparql-qt/tracker-sparql-qt.h |   26 +++
 11 files changed, 802 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 055f458..78268f5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -481,6 +481,14 @@ PKG_CHECK_MODULES(TRACKER_NAUTILUS_EXTENSION, [$TRACKER_NAUTILUS_EXTENSION_REQUI
                   [have_tracker_nautilus_extension=yes],
                   [have_tracker_nautilus_extension=no])
 
+# Check requirements for tracker-search-bar
+LIBTRACKER_SPARQL_QT_REQUIRED="glib-2.0   >= $GLIB_REQUIRED
+                               QtCore     >= $QT_REQUIRED"
+
+PKG_CHECK_MODULES(LIBTRACKER_SPARQL_QT, [$LIBTRACKER_SPARQL_QT_REQUIRED],
+                  [have_libtracker_sparql_qt=yes],
+                  [have_libtracker_sparql_qt=no])
+
 # Check for D-Bus requirements (for tests/examples only)
 PKG_CHECK_MODULES(TRACKER_DBUS,
                   [gio-unix-2.0 >= $GLIB_REQUIRED
@@ -1360,6 +1368,25 @@ fi
 
 AM_CONDITIONAL(HAVE_TRACKER_EXPLORER, test "$have_tracker_explorer" = "yes")
 
+##################################################################
+# Check for libtracker-sparql-qt
+##################################################################
+
+AC_ARG_ENABLE([libtracker-sparql-qt],
+              AS_HELP_STRING([--enable-libtracker-sparql-qt],
+                             [enable libtracker-sparql-qt[[default=auto]]]),,
+              [enable_libtracker_sparql_qt=auto])
+
+if test "x$enable_libtracker_sparql_qt" != "xno" ; then
+   if test "x$have_libtracker_sparql_qt" != "xyes"; then
+      AC_MSG_ERROR([Couldn't find libtracker-sparql-qt dependencies ($LIBTRACKER_SPARQL_QT_REQUIRED).])
+   fi
+else
+   have_libtracker_sparql_qt="no  (disabled)"
+fi
+
+AM_CONDITIONAL(HAVE_LIBTRACKER_SPARQL_QT, test "$have_libtracker_sparql_qt" = "yes")
+
 ####################################################################
 ####################################################################
 ####################################################################
@@ -2060,6 +2087,7 @@ AC_CONFIG_FILES([
 	src/libstemmer/Makefile
 	src/libtracker-common/Makefile
 	src/libtracker-sparql/Makefile
+	src/libtracker-sparql-qt/Makefile
 	src/libtracker-bus/Makefile
 	src/libtracker-direct/Makefile
 	src/libtracker-data/Makefile
@@ -2240,4 +2268,5 @@ Frameworks / Options:
 
 	Support Maemo                           $enable_maemo
         Support Guaranteed Metadata             $enable_guarantee_metadata (e.g. guess nie:title from files)
+	Build libtracker-sparql-qt              $have_libtracker_sparql_qt
 "
diff --git a/src/Makefile.am b/src/Makefile.am
index 53bb24e..fa56af3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -48,3 +48,7 @@ endif
 if HAVE_TRACKER_EXPLORER
 SUBDIRS += tracker-explorer
 endif
+
+if HAVE_LIBTRACKER_SPARQL_QT
+SUBDIRS += libtracker-sparql-qt
+endif
diff --git a/src/libtracker-sparql-qt/Makefile.am b/src/libtracker-sparql-qt/Makefile.am
new file mode 100644
index 0000000..c8bdae5
--- /dev/null
+++ b/src/libtracker-sparql-qt/Makefile.am
@@ -0,0 +1,32 @@
+include $(top_srcdir)/Makefile.decl
+
+lib_LTLIBRARIES = libtracker-sparql-qt- TRACKER_API_VERSION@.la
+
+AM_CPPFLAGS =                                          \
+	$(BUILD_CFLAGS)                                \
+	-I$(top_srcdir)/src                            \
+	-I$(top_srcdir)/src/libtracker-sparql          \
+	-I$(top_builddir)/src                          \
+	$(LIBTRACKER_SPARQL_QT_CFLAGS)
+
+libtracker_sparql_qtincludedir = $(includedir)/tracker-$(TRACKER_API_VERSION)/libtracker-sparql-qt
+
+libtracker_sparql_qt_ TRACKER_API_VERSION@_la_SOURCES =   \
+	connection.cpp                                 \
+	cursor.cpp                                     \
+	error.cpp
+
+libtracker_sparql_qt_ TRACKER_API_VERSION@_la_LIBADD =    \
+	$(BUILD_LIBS)                                  \
+	$(top_builddir)/src/libtracker-sparql/libtracker-sparql-$(TRACKER_API_VERSION).la \
+	$(LIBTRACKER_SPARQL_QT_LIBS)
+
+libtracker_sparql_qt_ TRACKER_API_VERSION@_la_LDFLAGS =   \
+	-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
+
+libtracker_sparql_qtinclude_HEADERS =                     \
+	connection.h                                   \
+	cursor.h                                       \
+	error.h                                        \
+	tracker-sparql-qt.h
+
diff --git a/src/libtracker-sparql-qt/common.h b/src/libtracker-sparql-qt/common.h
new file mode 100644
index 0000000..b3cfb72
--- /dev/null
+++ b/src/libtracker-sparql-qt/common.h
@@ -0,0 +1,14 @@
+#ifndef _TRACKER_SPARQL_QT_COMMON_H
+
+#include <QtGlobal>
+
+#define RETURN_VAL_IF_FAIL(assertion, message, value) \
+	if (not assertion) { \
+		qWarning("%s: %s", Q_FUNC_INFO, message); \
+		return value; \
+	}
+
+#define RETURN_IF_FAIL(assertion,message) \
+	RETURN_VAL_IF_FAIL(assertion,message,)
+
+#endif // _TRACKER_SPARQL_QT_COMMON_H
diff --git a/src/libtracker-sparql-qt/connection.cpp b/src/libtracker-sparql-qt/connection.cpp
new file mode 100644
index 0000000..16bef65
--- /dev/null
+++ b/src/libtracker-sparql-qt/connection.cpp
@@ -0,0 +1,235 @@
+/*
+ * Copyright (C) 2011, Adrien Bustany <abustany gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 <tracker-sparql.h>
+
+#include "connection.h"
+
+#include "common.h"
+#include "cursor.h"
+#include "error.h"
+
+namespace TrackerSparql {
+	class ConnectionPrivate : public QSharedData {
+	public:
+		ConnectionPrivate();
+		~ConnectionPrivate();
+
+		TrackerSparqlConnection *connection;
+		Error error;
+	};
+} // namespace TrackerSparql
+
+using namespace TrackerSparql;
+
+ConnectionPrivate::ConnectionPrivate()
+	: QSharedData()
+	, connection(0)
+{
+}
+
+ConnectionPrivate::~ConnectionPrivate()
+{
+	if (connection) {
+		g_object_unref(connection);
+	}
+}
+
+Connection *Connection::m_instance = 0;
+QMutex instanceMutex;
+
+Connection
+Connection::get()
+{
+	instanceMutex.lock();
+	if (m_instance == 0) {
+		g_type_init();
+		m_instance = new Connection();
+	}
+	instanceMutex.unlock();
+
+	return *m_instance;
+}
+
+Connection::Connection()
+	: d(new ConnectionPrivate)
+{
+	GError *error = 0;
+
+	d->connection = tracker_sparql_connection_get(0, &error);
+
+	if (error) {
+		d->error = Error(error);
+		g_error_free(error);
+	}
+}
+
+Connection::Connection(const Connection &other)
+	: d(other.d)
+{
+}
+
+Connection&
+Connection::operator=(const Connection &other)
+{
+	return d = other.d, *this;
+}
+
+Connection::~Connection()
+{
+}
+
+void
+Connection::load(const QFile &file)
+{
+	RETURN_IF_FAIL(valid(), "Connection is not valid");
+
+	GFile *gfile = g_file_new_for_path(file.fileName().toUtf8().constData());
+	GError *error = 0;
+
+	tracker_sparql_connection_load(d->connection, gfile, 0, &error);
+
+	if (error) {
+		d->error = Error(error);
+		g_error_free(error);
+	}
+}
+
+Cursor
+Connection::query(const QString &sparql)
+{
+	RETURN_VAL_IF_FAIL(valid(), "Connection is not valid", Cursor());
+
+	GError *error = 0;
+	TrackerSparqlCursor *cursor = tracker_sparql_connection_query(d->connection,
+	                                                              sparql.toUtf8().constData(),
+	                                                              0,
+	                                                              &error);
+
+	Cursor c(cursor, error);
+
+	if (error) {
+		g_error_free(error);
+	}
+
+	return c;
+}
+
+Cursor
+Connection::statistics()
+{
+	RETURN_VAL_IF_FAIL(valid(), "Connection is not valid", Cursor());
+
+	GError *error = 0;
+	TrackerSparqlCursor *cursor = tracker_sparql_connection_statistics(d->connection,
+	                                                                   0,
+	                                                                   &error);
+
+	Cursor c(cursor, error);
+
+	if (error) {
+		g_error_free(error);
+	}
+
+	return c;
+}
+
+void
+Connection::update(const QString &sparql, int priority)
+{
+	RETURN_IF_FAIL(valid(), "Connection is not valid");
+
+	GError *error = 0;
+	tracker_sparql_connection_update(d->connection,
+	                                 sparql.toUtf8().constData(),
+	                                 priority,
+	                                 0,
+	                                 &error);
+
+	if (error) {
+		d->error = Error(error);
+		g_error_free(error);
+	}
+}
+
+QList<QList<QHash<QString, QString> > >
+Connection::updateBlank(const QString &sparql, int priority)
+{
+	static const QList<QList<QHash<QString, QString> > > emptyResult;
+
+	RETURN_VAL_IF_FAIL(valid(), "Connection is not valid", emptyResult);
+
+	GError *error = 0;
+	GVariant *result = tracker_sparql_connection_update_blank(d->connection,
+	                                                          sparql.toUtf8().constData(),
+	                                                          priority,
+	                                                          0,
+	                                                          &error);
+	if (error) {
+		d->error = Error(error);
+		g_error_free(error);
+
+		return emptyResult;
+	}
+
+	QList<QList<QHash<QString, QString> > > results;
+	GVariantIter iter1, *iter2, *iter3;
+
+	const gchar *node;
+	const gchar *urn;
+
+	g_variant_iter_init (&iter1, result);
+	while (g_variant_iter_loop (&iter1, "aa{ss}", &iter2)) {
+		QList<QHash<QString, QString> > innerList;
+
+		while (g_variant_iter_loop (iter2, "a{ss}", &iter3)) {
+			QHash<QString, QString> hash;
+
+			while (g_variant_iter_loop (iter3, "{ss}", &node, &urn)) { /* {ss} */
+				hash.insert(QString::fromUtf8(node), QString::fromUtf8(urn));
+			}
+
+			innerList.append(hash);
+		}
+
+		results.append(innerList);
+	}
+
+	g_variant_unref (result);
+
+	return results;
+}
+
+bool
+Connection::valid() const
+{
+	return (d->connection != 0);
+}
+
+Error
+Connection::error() const
+{
+	return d->error;
+}
+
+const int Connection::HighPriority = G_PRIORITY_HIGH;
+const int Connection::DefaultPriority = G_PRIORITY_DEFAULT;
+const int Connection::HighIdlePriority = G_PRIORITY_HIGH_IDLE;
+const int Connection::DefaultIdlePriority = G_PRIORITY_DEFAULT_IDLE;
+const int Connection::LowPriority = G_PRIORITY_LOW;
diff --git a/src/libtracker-sparql-qt/connection.h b/src/libtracker-sparql-qt/connection.h
new file mode 100644
index 0000000..9285199
--- /dev/null
+++ b/src/libtracker-sparql-qt/connection.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2011, Adrien Bustany <abustany gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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_SPARQL_QT_CONNECTION_H
+
+#include <QtCore>
+
+namespace TrackerSparql {
+
+class ConnectionPrivate;
+class Cursor;
+class Error;
+
+class Connection {
+public:
+	static Connection get();
+
+	Connection(const Connection &other);
+	Connection& operator=(const Connection &other);
+
+	~Connection();
+
+	static const int HighPriority;
+	static const int DefaultPriority;
+	static const int HighIdlePriority;
+	static const int DefaultIdlePriority;
+	static const int LowPriority;
+
+	void load(const QFile &file);
+	Cursor query(const QString &sparql);
+	Cursor statistics();
+	void update(const QString &sparql, int priority = DefaultPriority);
+	QList<QList<QHash<QString, QString> > > updateBlank(const QString &sparql, int priority = DefaultPriority);
+
+	bool valid() const;
+	Error error() const;
+
+private:
+	Connection();
+
+	QExplicitlySharedDataPointer<ConnectionPrivate> d;
+	static Connection *m_instance;
+};
+
+} // namespace TrackerSparql
+
+#endif // _TRACKER_SPARQL_QT_CONNECTION_H
diff --git a/src/libtracker-sparql-qt/cursor.cpp b/src/libtracker-sparql-qt/cursor.cpp
new file mode 100644
index 0000000..25874f6
--- /dev/null
+++ b/src/libtracker-sparql-qt/cursor.cpp
@@ -0,0 +1,185 @@
+/*
+ * Copyright (C) 2011, Adrien Bustany <abustany gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 <tracker-sparql.h>
+
+#include "cursor.h"
+
+#include "common.h"
+#include "error.h"
+
+namespace TrackerSparql {
+	class CursorPrivate : public QSharedData {
+	public:
+		CursorPrivate(TrackerSparqlCursor *cursor, GError *error);
+		~CursorPrivate();
+
+		TrackerSparqlCursor *cursor;
+		Error error;
+	};
+} // namespace TrackerSparql
+
+using namespace TrackerSparql;
+
+CursorPrivate::CursorPrivate(TrackerSparqlCursor *cursor, GError *error)
+	: QSharedData()
+	, cursor(cursor)
+	, error(error)
+{
+}
+
+CursorPrivate::~CursorPrivate()
+{
+	if (cursor != 0) {
+		g_object_unref(cursor);
+	}
+}
+
+Cursor::Cursor()
+	: d(new CursorPrivate(0, 0))
+{
+}
+
+Cursor::Cursor(TrackerSparqlCursor *cursor, GError *error)
+	: d(new CursorPrivate(cursor, error))
+{
+}
+
+Cursor::Cursor(const Cursor &other)
+	: d(other.d)
+{
+}
+
+Cursor&
+Cursor::operator=(const Cursor &other)
+{
+	return d = other.d, *this;
+}
+
+Cursor::~Cursor()
+{
+}
+
+bool
+Cursor::getBoolean(int column) const
+{
+	RETURN_VAL_IF_FAIL(valid(), "Cursor not valid", 0);
+
+	return tracker_sparql_cursor_get_boolean(d->cursor, column);
+}
+
+double
+Cursor::getDouble(int column) const
+{
+	RETURN_VAL_IF_FAIL(valid(), "Cursor not valid", 0.);
+
+	return tracker_sparql_cursor_get_double(d->cursor, column);
+}
+
+qint64
+Cursor::getInteger(int column) const
+{
+	RETURN_VAL_IF_FAIL(valid(), "Cursor not valid", 0);
+
+	return tracker_sparql_cursor_get_integer(d->cursor, column);
+}
+
+QString
+Cursor::getString(int column) const
+{
+	static const QString nullString;
+
+	RETURN_VAL_IF_FAIL(valid(), "Cursor not valid", nullString);
+
+	long size = -1;
+	const gchar *data = tracker_sparql_cursor_get_string(d->cursor,
+	                                                     column,
+	                                                     &size);
+	return QString::fromUtf8(data, size);
+}
+
+Cursor::ValueType
+Cursor::getValueType(int column) const
+{
+	RETURN_VAL_IF_FAIL(valid(), "Cursor not valid", Unbound);
+
+	return (ValueType)tracker_sparql_cursor_get_value_type(d->cursor, column);
+}
+
+QString
+Cursor::getVariableName(int column) const
+{
+	RETURN_VAL_IF_FAIL(valid(), "Cursor not valid", 0);
+
+	return QString::fromUtf8(tracker_sparql_cursor_get_variable_name(d->cursor,
+	                                                                 column));
+}
+
+bool
+Cursor::isBound(int column) const
+{
+	RETURN_VAL_IF_FAIL(valid(), "Cursor not valid", 0);
+
+	return tracker_sparql_cursor_is_bound(d->cursor, column);
+}
+
+bool
+Cursor::next()
+{
+	RETURN_VAL_IF_FAIL(valid(), "Cursor not valid", 0);
+
+	GError *error = 0;
+
+	bool result = tracker_sparql_cursor_next(d->cursor, 0, &error);
+
+	if (error) {
+		d->error = Error(error);
+		g_error_free(error);
+	}
+
+	return result;
+}
+
+void
+Cursor::rewind()
+{
+	RETURN_IF_FAIL(valid(), "Cursor not valid");
+
+	return tracker_sparql_cursor_rewind(d->cursor);
+}
+
+int
+Cursor::nColumns() const
+{
+	RETURN_VAL_IF_FAIL(valid(), "Cursor not valid", -1);
+
+	return tracker_sparql_cursor_get_n_columns(d->cursor);
+}
+
+bool
+Cursor::valid() const
+{
+	return (d->cursor != 0);
+}
+
+Error
+Cursor::error() const
+{
+	return d->error;
+}
diff --git a/src/libtracker-sparql-qt/cursor.h b/src/libtracker-sparql-qt/cursor.h
new file mode 100644
index 0000000..5128b49
--- /dev/null
+++ b/src/libtracker-sparql-qt/cursor.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2011, Adrien Bustany <abustany gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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_SPARQL_QT_CURSOR_H
+
+#include <QtCore>
+
+typedef struct _TrackerSparqlCursor TrackerSparqlCursor;
+typedef struct _GError GError;
+
+namespace TrackerSparql {
+
+class Connection;
+class CursorPrivate;
+class Error;
+
+class Cursor {
+public:
+	enum ValueType {
+		Unbound,
+		Uri,
+		String,
+		Integer,
+		Double,
+		DateTime,
+		BlankNode,
+		Boolean
+	};
+
+	~Cursor();
+
+	Cursor(const Cursor &other);
+	Cursor& operator=(const Cursor &other);
+
+	bool getBoolean(int column) const;
+	double getDouble(int column) const;
+	qint64 getInteger(int column) const;
+	QString getString(int column) const;
+	ValueType getValueType(int column) const;
+	QString getVariableName(int column) const;
+	bool isBound(int column) const;
+	bool next();
+	void rewind();
+	int nColumns() const;
+
+	bool valid() const;
+	Error error() const;
+
+private:
+	friend class Connection;
+	Cursor();
+	Cursor(TrackerSparqlCursor *cursor, GError *error);
+
+	QExplicitlySharedDataPointer<CursorPrivate> d;
+};
+
+}
+
+#endif // _TRACKER_SPARQL_QT_CURSOR_H
diff --git a/src/libtracker-sparql-qt/error.cpp b/src/libtracker-sparql-qt/error.cpp
new file mode 100644
index 0000000..f48121c
--- /dev/null
+++ b/src/libtracker-sparql-qt/error.cpp
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2011, Adrien Bustany <abustany gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 "error.h"
+
+#include <glib.h>
+
+namespace TrackerSparql {
+	class ErrorPrivate : public QSharedData {
+	public:
+		ErrorPrivate();
+
+		int code;
+		QString message;
+	};
+} // namespace TrackerSparql
+
+using namespace TrackerSparql;
+
+ErrorPrivate::ErrorPrivate()
+	: QSharedData()
+	, code(-1)
+{
+}
+
+Error::Error()
+	: d(new ErrorPrivate)
+{
+}
+
+Error::Error(GError *error)
+	: d(new ErrorPrivate)
+{
+	if (error) {
+		d->code = error->code;
+		d->message = QString::fromUtf8(error->message);
+	}
+}
+
+Error::Error(const Error &other)
+	: d(new ErrorPrivate(*other.d))
+{
+}
+
+Error&
+Error::operator=(const Error &other)
+{
+	d = new ErrorPrivate(*other.d);
+
+	return *this;
+}
+
+Error::~Error()
+{
+}
+
+int
+Error::code() const
+{
+	return d->code;
+}
+
+QString
+Error::message() const
+{
+	return d->message;
+}
+
+bool
+Error::valid() const
+{
+	// Can we have GError with negative error code?
+	return (d->code != -1);
+}
diff --git a/src/libtracker-sparql-qt/error.h b/src/libtracker-sparql-qt/error.h
new file mode 100644
index 0000000..9204e02
--- /dev/null
+++ b/src/libtracker-sparql-qt/error.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2011, Adrien Bustany <abustany gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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_SPARQL_QT_ERROR_H
+
+#include <QtCore>
+
+typedef struct _GError GError;
+
+namespace TrackerSparql {
+
+class ErrorPrivate;
+
+class Error {
+public:
+	Error();
+	Error(GError *error);
+	Error(const Error &other);
+	Error& operator=(const Error &other);
+	~Error();
+
+	int code() const;
+	QString message() const;
+
+	bool valid() const;
+
+private:
+	QSharedDataPointer<ErrorPrivate> d;
+};
+
+} // namespace TrackerSparql
+
+#endif // _TRACKER_SPARQL_QT_ERROR_H
diff --git a/src/libtracker-sparql-qt/tracker-sparql-qt.h b/src/libtracker-sparql-qt/tracker-sparql-qt.h
new file mode 100644
index 0000000..0c4cc4c
--- /dev/null
+++ b/src/libtracker-sparql-qt/tracker-sparql-qt.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2011, Adrien Bustany <abustany gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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_SPARQL_QT_H
+
+#include <connection.h>
+#include <cursor.h>
+#include <error.h>
+
+#endif // _TRACKER_SPARQL_QT_H



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]