diff options
author | Andrew den Exter <andrew.den.exter@jollamobile.com> | 2014-02-21 04:39:44 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-04-16 09:07:36 +0200 |
commit | f6640180b90d791492a3cff0f80c09d5a853d683 (patch) | |
tree | 692df4f047b37b4bf5297e75f3ac698bb96fa724 | |
parent | 4707f2e634f0d379810998a28138b96c1b916258 (diff) |
Remove separate result set for Type requests.
Because results are now filtered by the tracker:available flag the
sparql query path is always used for type queries and
QGalleryTrackerResultSet is sufficient for those so take the opportunity
to shed some unneeded code.
Change-Id: Ib44dbcffeeaa2be8015ca6a727a45e19234f5782
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
-rw-r--r-- | src/gallery/tracker/qdocumentgallery_tracker.cpp | 33 | ||||
-rw-r--r-- | src/gallery/tracker/qgallerydbusinterface_p.h | 22 | ||||
-rw-r--r-- | src/gallery/tracker/qgallerytrackerchangenotifier.cpp | 8 | ||||
-rw-r--r-- | src/gallery/tracker/qgallerytrackerresultset.cpp | 2 | ||||
-rw-r--r-- | src/gallery/tracker/qgallerytrackerresultset_p.h | 1 | ||||
-rw-r--r-- | src/gallery/tracker/qgallerytrackerresultset_p_p.h | 8 | ||||
-rw-r--r-- | src/gallery/tracker/qgallerytrackerschema.cpp | 81 | ||||
-rw-r--r-- | src/gallery/tracker/qgallerytrackerschema_p.h | 7 | ||||
-rw-r--r-- | src/gallery/tracker/qgallerytrackertyperesultset.cpp | 348 | ||||
-rw-r--r-- | src/gallery/tracker/qgallerytrackertyperesultset_p.h | 116 | ||||
-rw-r--r-- | src/gallery/tracker/tracker.pri | 6 | ||||
-rw-r--r-- | tests/auto/qgallerytrackerschema_tracker/tst_qgallerytrackerschema.cpp | 122 |
12 files changed, 99 insertions, 655 deletions
diff --git a/src/gallery/tracker/qdocumentgallery_tracker.cpp b/src/gallery/tracker/qdocumentgallery_tracker.cpp index 993e3b6..3b1153f 100644 --- a/src/gallery/tracker/qdocumentgallery_tracker.cpp +++ b/src/gallery/tracker/qdocumentgallery_tracker.cpp @@ -52,7 +52,6 @@ #include "qgallerytrackerchangenotifier_p.h" #include "qgallerytrackerschema_p.h" #include "qgallerytrackereditableresultset_p.h" -#include "qgallerytrackertyperesultset_p.h" #include "qgallerydbusinterface_p.h" #include <QtCore/qmetaobject.h> @@ -83,7 +82,7 @@ Q_DECLARE_METATYPE(QVector<QGalleryTrackerGraphUpdate>) QT_BEGIN_NAMESPACE_DOCGALLERY -class QDocumentGalleryPrivate : public QAbstractGalleryPrivate, public QGalleryDBusInterfaceFactory +class QDocumentGalleryPrivate : public QAbstractGalleryPrivate { public: QDocumentGalleryPrivate() @@ -118,7 +117,6 @@ public: TrackerSparqlConnection *connection; QGalleryDBusInterfacePointer metaDataService; - QGalleryDBusInterfacePointer statisticsService; QScopedPointer<QGalleryTrackerChangeNotifier> fileNotifier; QScopedPointer<QGalleryTrackerChangeNotifier> audioNotifier; QScopedPointer<QGalleryTrackerChangeNotifier> artistNotifier; @@ -141,17 +139,6 @@ QGalleryDBusInterfacePointer QDocumentGalleryPrivate::metaDataInterface() return metaDataService; } -QGalleryDBusInterfacePointer QDocumentGalleryPrivate::statisticsInterface() -{ - if (!statisticsService) { - statisticsService = new QGalleryDBusInterface( - QLatin1String("org.freedesktop.Tracker1"), - QLatin1String("/org/freedesktop/Tracker1/Statistics"), - "org.freedesktop.Tracker1.Statistics"); - } - return statisticsService; -} - QGalleryTrackerChangeNotifier *QDocumentGalleryPrivate::createChangeNotifier( QScopedPointer<QGalleryTrackerChangeNotifier> ¬ifier, const QString &serviceId) { @@ -221,7 +208,7 @@ QGalleryAbstractResponse *QDocumentGalleryPrivate::createItemResponse(QGalleryIt QGalleryTrackerResultSetArguments arguments; int error = schema.prepareItemResponse( - &arguments, this, request->itemId().toString(), request->propertyNames()); + &arguments, request->itemId().toString(), request->propertyNames()); if (error != QDocumentGallery::NoError) { return new QGalleryAbstractResponse(error); @@ -263,21 +250,19 @@ QGalleryAbstractResponse *QDocumentGalleryPrivate::createTypeResponse(QGalleryTy { QGalleryTrackerSchema schema(request->itemType()); - QGalleryTrackerTypeResultSetArguments arguments; + QGalleryTrackerResultSetArguments arguments; - int error = schema.prepareTypeResponse(&arguments, this); + int error = schema.prepareTypeResponse(&arguments); if (error != QDocumentGallery::NoError) { return new QGalleryAbstractResponse(error); } else { - QGalleryTrackerTypeResultSet *response = new QGalleryTrackerTypeResultSet(arguments); + QGalleryTrackerResultSet *response = new QGalleryTrackerResultSet(connection, &arguments, request->autoUpdate()); if (request->autoUpdate()) { - QGalleryTrackerChangeNotifier * notifier = getChangeNotifier( request->itemType() ); - if ( notifier ) - QObject::connect( - notifier, SIGNAL(itemsChanged(int)), - response, SLOT(refresh(int))); + QGalleryTrackerChangeNotifier *notifier = getChangeNotifier(request->itemType()); + if (notifier) + QObject::connect(notifier, SIGNAL(itemsChanged(int)), response, SLOT(refresh(int))); } return response; @@ -318,7 +303,6 @@ QGalleryAbstractResponse *QDocumentGalleryPrivate::createFilterResponse( int error = schema.prepareQueryResponse( &arguments, - this, request->scope(), request->rootItem().toString(), request->filter(), @@ -353,6 +337,7 @@ QDocumentGallery::QDocumentGallery(QObject *parent) QDocumentGallery::~QDocumentGallery() { Q_D(QDocumentGallery); + if (d->connection) g_object_unref(d->connection); } diff --git a/src/gallery/tracker/qgallerydbusinterface_p.h b/src/gallery/tracker/qgallerydbusinterface_p.h index bd61a2f..9d0262d 100644 --- a/src/gallery/tracker/qgallerydbusinterface_p.h +++ b/src/gallery/tracker/qgallerydbusinterface_p.h @@ -89,28 +89,6 @@ Q_SIGNALS: typedef QExplicitlySharedDataPointer<QGalleryDBusInterface> QGalleryDBusInterfacePointer; -class QGalleryTrackerDaemonDBusInterface : public QGalleryDBusInterface -{ - Q_OBJECT -public: - QGalleryTrackerDaemonDBusInterface( - const QString &service, - const QString &path, - const char *interface, - const QDBusConnection &connection = QDBusConnection::sessionBus(), - QObject *parent = 0) - : QGalleryDBusInterface(service, path, interface, connection, parent) {} - -}; - -class QGalleryDBusInterfaceFactory -{ -public: - virtual ~QGalleryDBusInterfaceFactory() {} - - virtual QGalleryDBusInterfacePointer metaDataInterface() = 0; - virtual QGalleryDBusInterfacePointer statisticsInterface() = 0; -}; QT_END_NAMESPACE_DOCGALLERY diff --git a/src/gallery/tracker/qgallerytrackerchangenotifier.cpp b/src/gallery/tracker/qgallerytrackerchangenotifier.cpp index 610be79..6e04ca6 100644 --- a/src/gallery/tracker/qgallerytrackerchangenotifier.cpp +++ b/src/gallery/tracker/qgallerytrackerchangenotifier.cpp @@ -74,10 +74,10 @@ void QGalleryTrackerChangeNotifier::graphUpdated( QString identifier(m_service); identifier.replace(QLatin1Char(':'), QLatin1Char('#')); if (className.endsWith(identifier) - || (m_service == QLatin1String("nfo:FileDataObject") && className.contains(QLatin1String("/nfo#"))) - || (m_service == QLatin1String("nmm:Artist") && className.endsWith("nfo#Audio")) - || (m_service == QLatin1String("nmm:Photo") && className.endsWith("nmm#ImageList")) - || (m_service == QLatin1String("nfo:Audio") && className.endsWith("nmm#Playlist"))) { + || (m_service == QLatin1String("nfo:FileDataObject") && className.contains(QStringLiteral("/nfo#"))) + || (m_service == QLatin1String("nmm:Artist") && className.endsWith(QStringLiteral("nfo#Audio"))) + || (m_service == QLatin1String("nmm:Photo") && className.endsWith(QStringLiteral("nmm#ImageList"))) + || (m_service == QLatin1String("nfo:Audio") && className.endsWith(QStringLiteral("nmm#Playlist")))) { emit itemsChanged(QGalleryTrackerSchema::serviceUpdateId(m_service)); } } diff --git a/src/gallery/tracker/qgallerytrackerresultset.cpp b/src/gallery/tracker/qgallerytrackerresultset.cpp index 69b63f5..d056421 100644 --- a/src/gallery/tracker/qgallerytrackerresultset.cpp +++ b/src/gallery/tracker/qgallerytrackerresultset.cpp @@ -429,6 +429,8 @@ QGalleryTrackerResultSet::QGalleryTrackerResultSet( { Q_D(QGalleryTrackerResultSet); + g_object_ref(G_OBJECT(d->connection)); + connect(&d->parserThread, SIGNAL(finished()), this, SLOT(_q_parseFinished())); d_func()->query(); diff --git a/src/gallery/tracker/qgallerytrackerresultset_p.h b/src/gallery/tracker/qgallerytrackerresultset_p.h index 2d3e669..58f954b 100644 --- a/src/gallery/tracker/qgallerytrackerresultset_p.h +++ b/src/gallery/tracker/qgallerytrackerresultset_p.h @@ -104,7 +104,6 @@ struct QGalleryTrackerResultSetArguments int tableWidth; int valueOffset; int compositeOffset; - QGalleryDBusInterfacePointer queryInterface; QString sparql; QStringList propertyNames; QStringList fieldNames; diff --git a/src/gallery/tracker/qgallerytrackerresultset_p_p.h b/src/gallery/tracker/qgallerytrackerresultset_p_p.h index 47a552a..10ba19f 100644 --- a/src/gallery/tracker/qgallerytrackerresultset_p_p.h +++ b/src/gallery/tracker/qgallerytrackerresultset_p_p.h @@ -192,9 +192,9 @@ public: const Row &operator *() const { return row = Row(begin, begin + width); } bool isEqual(const row_iterator &other, int count) const { - return qEqual(begin, begin + count, other.begin); } + return std::equal(begin, begin + count, other.begin); } bool isEqual(const row_iterator &other, int index, int count) { - return qEqual(begin + index, begin + count, other.begin + index); } + return std::equal(begin + index, begin + count, other.begin + index); } const QVariant &operator[] (int column) const { return *(begin + column); } @@ -227,9 +227,9 @@ public: const_row_iterator &operator +=(int span) { begin += span * width; return *this; } bool isEqual(const const_row_iterator &other, int count) const { - return qEqual(begin, begin + count, other.begin); } + return std::equal(begin, begin + count, other.begin); } bool isEqual(const const_row_iterator &other, int index, int count) { - return qEqual(begin + index, begin + count, other.begin + index); } + return std::equal(begin + index, begin + count, other.begin + index); } QVector<QVariant>::const_iterator begin; int width; diff --git a/src/gallery/tracker/qgallerytrackerschema.cpp b/src/gallery/tracker/qgallerytrackerschema.cpp index a258c69..b439c86 100644 --- a/src/gallery/tracker/qgallerytrackerschema.cpp +++ b/src/gallery/tracker/qgallerytrackerschema.cpp @@ -44,10 +44,8 @@ #include "qgallerytrackerschema_p.h" #include "qgalleryabstractrequest.h" -#include "qgallerydbusinterface_p.h" #include "qgallerytrackerresultset_p.h" #include "qgallerytrackerlistcolumn_p.h" -#include "qgallerytrackertyperesultset_p.h" #include <QtCore/qdatetime.h> #include <QtCore/qdir.h> @@ -1172,7 +1170,6 @@ QGalleryProperty::Attributes QGalleryTrackerSchema::propertyAttributes( QDocumentGallery::Error QGalleryTrackerSchema::prepareItemResponse( QGalleryTrackerResultSetArguments *arguments, - QGalleryDBusInterfaceFactory *dbus, const QString &itemId, const QStringList &propertyNames) const { @@ -1181,7 +1178,7 @@ QDocumentGallery::Error QGalleryTrackerSchema::prepareItemResponse( = QLatin1String(" FILTER(?x=<") + qt_galleryItemTypeList[m_itemIndex].prefix.strip(itemId).toString() + QLatin1String(">)"); - populateItemArguments(arguments, dbus, query, QString(), QString(), propertyNames, QStringList(), 0, 0); + populateItemArguments(arguments, query, QString(), QString(), propertyNames, QStringList(), 0, 0); return QDocumentGallery::NoError; } @@ -1191,7 +1188,6 @@ QDocumentGallery::Error QGalleryTrackerSchema::prepareItemResponse( QDocumentGallery::Error QGalleryTrackerSchema::prepareQueryResponse( QGalleryTrackerResultSetArguments *arguments, - QGalleryDBusInterfaceFactory *dbus, QGalleryQueryRequest::Scope scope, const QString &rootItemId, const QGalleryFilter &filter, @@ -1213,7 +1209,7 @@ QDocumentGallery::Error QGalleryTrackerSchema::prepareQueryResponse( return error; } else { populateItemArguments( - arguments, dbus, query, join, optionalJoin, propertyNames, sortPropertyNames, offset, limit); + arguments, query, join, optionalJoin, propertyNames, sortPropertyNames, offset, limit); return QDocumentGallery::NoError; } @@ -1221,43 +1217,48 @@ QDocumentGallery::Error QGalleryTrackerSchema::prepareQueryResponse( } QDocumentGallery::Error QGalleryTrackerSchema::prepareTypeResponse( - QGalleryTrackerTypeResultSetArguments *arguments, QGalleryDBusInterfaceFactory *dbus) const + QGalleryTrackerResultSetArguments *arguments) const { - if (m_itemIndex >= 0) { - arguments->service = qt_galleryItemTypeList[m_itemIndex].service; - arguments->accumulative = false; - arguments->updateMask = qt_galleryItemTypeList[m_itemIndex].updateMask; - - if (qt_galleryItemTypeList[m_itemIndex].filterFragment) { - arguments->queryInterface = dbus->metaDataInterface(); - arguments->queryMethod = QLatin1String("SparqlQuery"); - arguments->queryArguments = QVariantList() - << QString(QString::fromUtf8("SELECT COUNT(DISTINCT ") - + qt_galleryItemTypeList[m_itemIndex].identity - + QLatin1String(") WHERE {") - + qt_galleryItemTypeList[m_itemIndex].typeFragment - + QLatin1String(" FILTER(") - + QLatin1String(qt_galleryItemTypeList[m_itemIndex].filterFragment) - + QLatin1String(")}")); - } else if (QString(qt_galleryItemTypeList[m_itemIndex].typeFragment).contains(QLatin1Char('.'))) { - arguments->queryInterface = dbus->metaDataInterface(); - arguments->queryMethod = QLatin1String("SparqlQuery"); - arguments->queryArguments = QVariantList() - << QString(QString::fromUtf8("SELECT COUNT(DISTINCT ") - + qt_galleryItemTypeList[m_itemIndex].identity - + QLatin1String(") WHERE {") - + qt_galleryItemTypeList[m_itemIndex].typeFragment - + QLatin1String("}")); - } else { - arguments->queryInterface = dbus->statisticsInterface(); - arguments->queryMethod = QLatin1String("Get"); - arguments->queryArguments = QVariantList(); - } + if (m_itemIndex < 0) + return QDocumentGallery::ItemTypeError; - return QDocumentGallery::NoError; + arguments->valueOffset = 1; // identity + arguments->idColumn.reset(new QGalleryTrackerStaticColumn(QVariant())); + arguments->urlColumn.reset(new QGalleryTrackerStaticColumn(QVariant())); + arguments->typeColumn.reset( + new QGalleryTrackerStaticColumn(qt_galleryItemTypeList[m_itemIndex].itemType)); + arguments->valueColumns = QVector<QGalleryTrackerValueColumn *>() + << new QGalleryTrackerStringColumn + << new QGalleryTrackerIntegerColumn; + + arguments->service = qt_galleryItemTypeList[m_itemIndex].service; + arguments->updateMask = qt_galleryItemTypeList[m_itemIndex].updateMask; + arguments->identityWidth = 1; + arguments->tableWidth = 2; + arguments->compositeOffset = 2; + arguments->propertyNames << QStringLiteral("count"); + arguments->propertyAttributes << QGalleryProperty::CanRead; + arguments->propertyTypes << QVariant::Int; + + if (qt_galleryItemTypeList[m_itemIndex].filterFragment) { + arguments->sparql + = QLatin1String("SELECT 'identity' COUNT(DISTINCT ") + + qt_galleryItemTypeList[m_itemIndex].identity + + QLatin1String(") WHERE {") + + qt_galleryItemTypeList[m_itemIndex].typeFragment + + QLatin1String(" FILTER(") + + QLatin1String(qt_galleryItemTypeList[m_itemIndex].filterFragment) + + QLatin1String(")}"); } else { - return QDocumentGallery::ItemTypeError; + arguments->sparql + = QLatin1String("SELECT 'identity' COUNT(DISTINCT ") + + qt_galleryItemTypeList[m_itemIndex].identity + + QLatin1String(") WHERE {") + + qt_galleryItemTypeList[m_itemIndex].typeFragment + + QLatin1String("}"); } + + return QDocumentGallery::NoError; } QDocumentGallery::Error QGalleryTrackerSchema::buildFilterQuery( @@ -1479,7 +1480,6 @@ static QString qt_writeSorting( void QGalleryTrackerSchema::populateItemArguments( QGalleryTrackerResultSetArguments *arguments, - QGalleryDBusInterfaceFactory *dbus, const QString &query, const QString &join, const QString &optionalJoin, @@ -1612,7 +1612,6 @@ void QGalleryTrackerSchema::populateItemArguments( arguments->identityWidth = 1; arguments->tableWidth = arguments->valueOffset + arguments->fieldNames.count(); arguments->compositeOffset = arguments->valueOffset + valueNames.count(); - arguments->queryInterface = dbus->metaDataInterface(); arguments->sparql = QLatin1String("SELECT ") + fieldNames.join(QLatin1String(" ")) diff --git a/src/gallery/tracker/qgallerytrackerschema_p.h b/src/gallery/tracker/qgallerytrackerschema_p.h index 07300ce..c866cf3 100644 --- a/src/gallery/tracker/qgallerytrackerschema_p.h +++ b/src/gallery/tracker/qgallerytrackerschema_p.h @@ -69,7 +69,6 @@ class QGalleryTrackerImageColumn; class QGalleryTrackerValueColumn; struct QGalleryTrackerResultSetArguments; -struct QGalleryTrackerTypeResultSetArguments; class Q_GALLERY_EXPORT QGalleryTrackerSchema { @@ -91,13 +90,11 @@ public: QDocumentGallery::Error prepareItemResponse( QGalleryTrackerResultSetArguments *arguments, - QGalleryDBusInterfaceFactory *dbus, const QString &itemId, const QStringList &propertyNames) const; QDocumentGallery::Error prepareQueryResponse( QGalleryTrackerResultSetArguments *arguments, - QGalleryDBusInterfaceFactory *dbus, QGalleryQueryRequest::Scope scope, const QString &rootItem, const QGalleryFilter &filter, @@ -107,8 +104,7 @@ public: int limit) const; QDocumentGallery::Error prepareTypeResponse( - QGalleryTrackerTypeResultSetArguments *arguments, - QGalleryDBusInterfaceFactory *dbus) const; + QGalleryTrackerResultSetArguments *arguments) const; private: QGalleryTrackerSchema(int itemIndex) : m_itemIndex(itemIndex) {} @@ -123,7 +119,6 @@ private: void populateItemArguments( QGalleryTrackerResultSetArguments *arguments, - QGalleryDBusInterfaceFactory *dbus, const QString &query, const QString &join, const QString &optionalJoin, diff --git a/src/gallery/tracker/qgallerytrackertyperesultset.cpp b/src/gallery/tracker/qgallerytrackertyperesultset.cpp deleted file mode 100644 index 5157c6a..0000000 --- a/src/gallery/tracker/qgallerytrackertyperesultset.cpp +++ /dev/null @@ -1,348 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtDocGallery module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgallerytrackertyperesultset_p.h" - -#include "qgallerytrackerschema_p.h" - -#include <QtCore/qdatetime.h> -#include <QtCore/QDebug> -#include <QtDBus/qdbuspendingreply.h> - -#include "qdocumentgallery.h" - -#include "qgalleryresultset_p.h" - -Q_DECLARE_METATYPE(QVector<QStringList>) - -QT_BEGIN_NAMESPACE_DOCGALLERY - -class QGalleryTrackerTypeResultSetPrivate : public QGalleryResultSetPrivate -{ - Q_DECLARE_PUBLIC(QGalleryTrackerTypeResultSet) -public: - QGalleryTrackerTypeResultSetPrivate(const QGalleryTrackerTypeResultSetArguments &arguments) - : accumulative(arguments.accumulative) - , cancelled(false) - , refresh(false) - , updateMask(arguments.updateMask) - , currentIndex(-1) - , count(0) - , workingCount(0) - , currentOffset(0) - , queryWatcher(0) - , queryInterface(arguments.queryInterface) - , queryMethod(arguments.queryMethod) - , queryArguments(arguments.queryArguments) - , service( arguments.service ) - { - } - - void _q_queryFinished(QDBusPendingCallWatcher *watcher); - void queryFinished(const QDBusPendingCall &call); - - void queryCount(); - - const bool accumulative; - bool cancelled; - bool refresh; - const int updateMask; - int currentIndex; - int count; - int workingCount; - int currentOffset; - QDBusPendingCallWatcher *queryWatcher; - const QGalleryDBusInterfacePointer queryInterface; - const QString queryMethod; - const QVariantList queryArguments; - const QString service; -}; - -void QGalleryTrackerTypeResultSetPrivate::_q_queryFinished(QDBusPendingCallWatcher *watcher) -{ - if (queryWatcher == watcher) { - queryWatcher->deleteLater(); - queryWatcher = 0; - - watcher->deleteLater(); - - queryFinished(*watcher); - } -} - -class QGalleryTrackerType : public QString -{ -public: - QGalleryTrackerType(const QString& type ) : QString(type) {} -}; - -static bool operator ==(const QStringList &statistic, const QGalleryTrackerType &type) -{ - return statistic.first() == type; -} - -void QGalleryTrackerTypeResultSetPrivate::queryFinished(const QDBusPendingCall &call) -{ - const int oldCount = count; - - if (call.isError()) { - q_func()->finish(QDocumentGallery::ConnectionError); - - return; - } else if (!accumulative) { - QDBusPendingReply<QVector<QStringList> > reply(call); - - if (queryMethod == QLatin1String("SparqlQuery")) { - QVector<QStringList> v = reply.value(); - count = v[0].first().toInt(); - } else { - /* - * Process reply to org.freedesktop.Tracker.Statistics.Get -method. Value is a list of list of two strings: - * type1 count1 - * type2 count2 - * ... - * where typeX corresponds to the service name ( i.e. ontology class name, e.g. "nfo:FileDataObject" ). - * Search through the list and find the requested service and extract the count from the second string. - */ - QVector<QStringList> v = reply.value(); - QVector<QStringList>::const_iterator pos = qFind( - v, QGalleryTrackerType(service )); - if (pos != v.constEnd()) - count = (*pos).last().toInt(); - - // TODO Do we need this? - if (refresh) { - refresh = false; - queryCount(); - } - } - } else { - QDBusPendingReply<QVector<QStringList> > reply(call); - - const QVector<QStringList> counts = reply.value(); - - typedef QVector<QStringList>::const_iterator iterator; - for (iterator it = counts.begin(), end = counts.end(); it != end; ++it) - workingCount += it->value(1).toInt(); - - if (refresh) { - refresh = false; - - currentOffset = 0; - workingCount = 0; - - queryCount(); - } else { - currentOffset += counts.count(); - - if (counts.count() != 0) { - if (count > workingCount) - count = workingCount; - - if (cancelled) - q_func()->QGalleryAbstractResponse::cancel(); - else - queryCount(); - } else { - count = workingCount; - } - } - } - - if (count != oldCount) - emit q_func()->metaDataChanged(0, 1, QList<int>() << 0); - - if (!queryWatcher) - q_func()->finish(); -} - -void QGalleryTrackerTypeResultSetPrivate::queryCount() -{ - QVariantList arguments = queryArguments; - - if (accumulative) - arguments << currentOffset << int(0); - - QDBusPendingCall call = queryInterface->asyncCallWithArgumentList(queryMethod, arguments); - - if (call.isFinished()) { - queryFinished(call); - } else { - queryWatcher = new QDBusPendingCallWatcher(call, q_func()); - - QObject::connect(queryWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), - q_func(), SLOT(_q_queryFinished(QDBusPendingCallWatcher*))); - } -} - -QGalleryTrackerTypeResultSet::QGalleryTrackerTypeResultSet( - const QGalleryTrackerTypeResultSetArguments &arguments, - QObject *parent) - : QGalleryResultSet(*new QGalleryTrackerTypeResultSetPrivate(arguments), parent) - -{ - Q_D(QGalleryTrackerTypeResultSet); - - d->queryCount(); -} - -QGalleryTrackerTypeResultSet::~QGalleryTrackerTypeResultSet() -{ -} - -int QGalleryTrackerTypeResultSet::propertyKey(const QString &property) const -{ - return property == QLatin1String("count") ? 0 : -1; -} - -QGalleryProperty::Attributes QGalleryTrackerTypeResultSet::propertyAttributes(int key) const -{ - return key == 0 ? QGalleryProperty::CanRead : QGalleryProperty::Attributes(); -} - -QVariant::Type QGalleryTrackerTypeResultSet::propertyType(int key) const -{ - return key == 0 ? QVariant::Int : QVariant::Invalid; -} - -int QGalleryTrackerTypeResultSet::itemCount() const -{ - return 1; -} - -QVariant QGalleryTrackerTypeResultSet::itemId() const -{ - return QVariant(); -} - -QUrl QGalleryTrackerTypeResultSet::itemUrl() const -{ - return QUrl(); -} - -QString QGalleryTrackerTypeResultSet::itemType() const -{ - return QString(); -} - -QVariant QGalleryTrackerTypeResultSet::metaData(int key) const -{ - return d_func()->currentIndex == 0 && key == 0 - ? d_func()->count - : 0; -} - -bool QGalleryTrackerTypeResultSet::setMetaData(int, const QVariant &) -{ - return false; -} - -int QGalleryTrackerTypeResultSet::currentIndex() const -{ - return d_func()->currentIndex; -} - -bool QGalleryTrackerTypeResultSet::fetch(int index) -{ - if (index != d_func()->currentIndex) { - bool itemChanged = index == 0 || d_func()->currentIndex == 0; - - d_func()->currentIndex = index; - - emit currentIndexChanged(index); - - if (itemChanged) - emit currentItemChanged(); - } - return d_func()->currentIndex == 0; -} - -void QGalleryTrackerTypeResultSet::cancel() -{ - d_func()->cancelled = true; - d_func()->refresh = false; - - if (!d_func()->queryWatcher) - QGalleryAbstractResponse::cancel(); -} - -bool QGalleryTrackerTypeResultSet::waitForFinished(int msecs) -{ - Q_D(QGalleryTrackerTypeResultSet); - - QTime timer; - timer.start(); - do { - if (QDBusPendingCallWatcher *watcher = d->queryWatcher) { - d->queryWatcher = 0; - - watcher->waitForFinished(); - - d->queryFinished(*watcher); - - delete watcher; - - if (d->state != QGalleryAbstractRequest::Active) - return true; - } else { - return true; - } - } while ((msecs -= timer.restart()) > 0); - - return false; -} - -void QGalleryTrackerTypeResultSet::refresh(int serviceId) -{ - Q_D(QGalleryTrackerTypeResultSet); - - if (!d->cancelled && (d->updateMask & serviceId)) { - d->refresh = true; - - if (!d->queryWatcher) - d->queryCount(); - - } -} - -QT_END_NAMESPACE_DOCGALLERY - -#include "moc_qgallerytrackertyperesultset_p.cpp" diff --git a/src/gallery/tracker/qgallerytrackertyperesultset_p.h b/src/gallery/tracker/qgallerytrackertyperesultset_p.h deleted file mode 100644 index f555305..0000000 --- a/src/gallery/tracker/qgallerytrackertyperesultset_p.h +++ /dev/null @@ -1,116 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtDocGallery module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#ifndef QGALLERYTRACKERTYPERESULTSET_P_H -#define QGALLERYTRACKERTYPERESULTSET_P_H - -#include "qgalleryresultset.h" - -#include "qgallerydbusinterface_p.h" - -#include <QtDBus/qdbusinterface.h> -#include <QtDBus/qdbuspendingcall.h> - -QT_BEGIN_NAMESPACE_DOCGALLERY - -struct QGalleryTrackerTypeResultSetArguments -{ - QGalleryTrackerTypeResultSetArguments() : accumulative(false), updateMask(0) {} - - bool accumulative; - int updateMask; - QGalleryDBusInterfacePointer queryInterface; - QString queryMethod; - QVariantList queryArguments; - QString service; -}; - -class QGalleryTrackerTypeResultSetPrivate; - -class QGalleryTrackerTypeResultSet : public QGalleryResultSet -{ - Q_OBJECT -public: - QGalleryTrackerTypeResultSet( - const QGalleryTrackerTypeResultSetArguments &arguments, QObject *parent = 0); - ~QGalleryTrackerTypeResultSet(); - - int propertyKey(const QString &property) const; - QGalleryProperty::Attributes propertyAttributes(int key) const; - QVariant::Type propertyType(int key) const; - - int itemCount() const; - - QVariant itemId() const; - QUrl itemUrl() const; - QString itemType() const; - - QVariant metaData(int key) const; - bool setMetaData(int key, const QVariant &value); - - int currentIndex() const; - bool fetch(int index); - - bool waitForFinished(int msecs); - - void cancel(); - -public Q_SLOTS: - void refresh(int serviceId = -1); - -private: - Q_DECLARE_PRIVATE(QGalleryTrackerTypeResultSet) -}; - -QT_END_NAMESPACE_DOCGALLERY - -#endif diff --git a/src/gallery/tracker/tracker.pri b/src/gallery/tracker/tracker.pri index bf85332..ae56bab 100644 --- a/src/gallery/tracker/tracker.pri +++ b/src/gallery/tracker/tracker.pri @@ -13,8 +13,7 @@ PRIVATE_HEADERS += \ $$PWD/qgallerytrackermetadataedit_p.h \ $$PWD/qgallerytrackerresultset_p.h \ $$PWD/qgallerytrackerresultset_p_p.h \ - $$PWD/qgallerytrackerschema_p.h \ - $$PWD/qgallerytrackertyperesultset_p.h + $$PWD/qgallerytrackerschema_p.h SOURCES += \ $$PWD/qgallerydbusinterface.cpp \ @@ -24,5 +23,4 @@ SOURCES += \ $$PWD/qgallerytrackerlistcolumn.cpp \ $$PWD/qgallerytrackermetadataedit.cpp \ $$PWD/qgallerytrackerresultset.cpp \ - $$PWD/qgallerytrackerschema.cpp \ - $$PWD/qgallerytrackertyperesultset.cpp + $$PWD/qgallerytrackerschema.cpp diff --git a/tests/auto/qgallerytrackerschema_tracker/tst_qgallerytrackerschema.cpp b/tests/auto/qgallerytrackerschema_tracker/tst_qgallerytrackerschema.cpp index fb768dd..bdccc50 100644 --- a/tests/auto/qgallerytrackerschema_tracker/tst_qgallerytrackerschema.cpp +++ b/tests/auto/qgallerytrackerschema_tracker/tst_qgallerytrackerschema.cpp @@ -46,7 +46,6 @@ #include <qdocumentgallery.h> #include <private/qgallerytrackerlistcolumn_p.h> #include <private/qgallerytrackerresultset_p.h> -#include <private/qgallerytrackertyperesultset_p.h> #include <QtTest/QtTest> @@ -71,7 +70,7 @@ QT_USE_DOCGALLERY_NAMESPACE #define QT_AGGREGATE_QUERY_SERVICE_POSITION 0 #define QT_AGGREGATE_QUERY_STRING_POSITION 2 -class tst_QGalleryTrackerSchema : public QObject, public QGalleryDBusInterfaceFactory +class tst_QGalleryTrackerSchema : public QObject { Q_OBJECT private Q_SLOTS: @@ -115,21 +114,6 @@ private Q_SLOTS: void prepareInvalidQueryResponse(); void serviceForType_data(); void serviceForType(); - -private: - QGalleryDBusInterfacePointer daemonInterface() { return m_daemonInterface; } - QGalleryDBusInterfacePointer metaDataInterface() { return m_metaDataInterface; } - QGalleryDBusInterfacePointer searchInterface() { return m_searchInterface; } - QGalleryDBusInterfacePointer fileInterface() { return m_fileInterface; } - QGalleryDBusInterfacePointer statisticsInterface() { return m_statisticsInterface; } - QGalleryDBusInterfacePointer resourcesClassInterface( const QString &) { return m_resourcesClassInterface; } - - QGalleryDBusInterfacePointer m_daemonInterface; - QGalleryDBusInterfacePointer m_metaDataInterface; - QGalleryDBusInterfacePointer m_searchInterface; - QGalleryDBusInterfacePointer m_fileInterface; - QGalleryDBusInterfacePointer m_statisticsInterface; - QGalleryDBusInterfacePointer m_resourcesClassInterface; }; void tst_QGalleryTrackerSchema::initTestCase() @@ -405,82 +389,63 @@ void tst_QGalleryTrackerSchema::prepareValidTypeResponse_data() { QTest::addColumn<QString>("itemType"); QTest::addColumn<int>("updateMask"); - QTest::addColumn<QGalleryDBusInterfacePointer>("queryInterface"); - QTest::addColumn<QString>("queryMethod"); - QTest::addColumn<QVariantList>("queryArguments"); + QTest::addColumn<QString>("sparql"); QTest::newRow("File") << "File" << 0xFF - << m_metaDataInterface - << "SparqlQuery" - << (QVariantList() << QLatin1String( - "SELECT COUNT(DISTINCT ?x) " - "WHERE {" - "?x a nfo:FileDataObject . " - "?x tracker:available true" - "}")); + << "SELECT 'identity' COUNT(DISTINCT ?x) " + "WHERE {" + "?x a nfo:FileDataObject . " + "?x tracker:available true" + "}"; QTest::newRow("Artist") << QString::fromLatin1("Artist") << 0x0100 - << m_metaDataInterface - << "SparqlQuery" - << (QVariantList() << QLatin1String( - "SELECT COUNT(DISTINCT ?x) " - "WHERE {" - "?x a nmm:Artist . " - "?track a nmm:MusicPiece . " - "?track nmm:performer ?x . " - "?track tracker:available true" - "}")); + << "SELECT 'identity' COUNT(DISTINCT ?x) " + "WHERE {" + "?x a nmm:Artist . " + "?track a nmm:MusicPiece . " + "?track nmm:performer ?x . " + "?track tracker:available true" + "}"; QTest::newRow("Album") << QString::fromLatin1("Album") << 0x0200 - << m_metaDataInterface - << "SparqlQuery" - << (QVariantList() << QLatin1String( - "SELECT COUNT(DISTINCT ?x) " - "WHERE {" - "?x a nmm:MusicAlbum . " - "?track a nmm:MusicPiece . " - "?track nmm:musicAlbum ?x . " - "?track tracker:available true" - "}")); + << "SELECT 'identity' COUNT(DISTINCT ?x) " + "WHERE {" + "?x a nmm:MusicAlbum . " + "?track a nmm:MusicPiece . " + "?track nmm:musicAlbum ?x . " + "?track tracker:available true" + "}"; QTest::newRow("AudioGenre") << "AudioGenre" << 0x08 - << m_metaDataInterface - << "SparqlQuery" - << (QVariantList() << QLatin1String( - "SELECT COUNT(DISTINCT nfo:genre(?x)) " - "WHERE {" - "?x a nmm:MusicPiece . " - "?x tracker:available true " - "FILTER(nfo:genre(?x)!='')" - "}")); + << "SELECT 'identity' COUNT(DISTINCT nfo:genre(?x)) " + "WHERE {" + "?x a nmm:MusicPiece . " + "?x tracker:available true " + "FILTER(nfo:genre(?x)!='')" + "}"; } void tst_QGalleryTrackerSchema::prepareValidTypeResponse() { QFETCH(QString, itemType); QFETCH(int, updateMask); - QFETCH(QGalleryDBusInterfacePointer, queryInterface); - QFETCH(QString, queryMethod); - QFETCH(QVariantList, queryArguments); + QFETCH(QString, sparql); - QGalleryTrackerTypeResultSetArguments arguments; + QGalleryTrackerResultSetArguments arguments; QGalleryTrackerSchema schema(itemType); - QCOMPARE(schema.prepareTypeResponse(&arguments, this), QDocumentGallery::NoError); + QCOMPARE(schema.prepareTypeResponse(&arguments), QDocumentGallery::NoError); - QCOMPARE(arguments.accumulative, false); QCOMPARE(arguments.updateMask, updateMask); - QCOMPARE(arguments.queryInterface, queryInterface); - QCOMPARE(arguments.queryMethod, queryMethod); - QCOMPARE(arguments.queryArguments, queryArguments); + QCOMPARE(arguments.sparql, sparql); } void tst_QGalleryTrackerSchema::prepareInvalidTypeResponse_data() @@ -498,10 +463,10 @@ void tst_QGalleryTrackerSchema::prepareInvalidTypeResponse() QFETCH(QString, itemType); QFETCH(QDocumentGallery::Error, error); - QGalleryTrackerTypeResultSetArguments arguments; + QGalleryTrackerResultSetArguments arguments; QGalleryTrackerSchema schema(itemType); - QCOMPARE(schema.prepareTypeResponse(&arguments, this), error); + QCOMPARE(schema.prepareTypeResponse(&arguments), error); } void tst_QGalleryTrackerSchema::prepareValidItemResponse_data() @@ -516,7 +481,7 @@ void tst_QGalleryTrackerSchema::prepareValidItemResponse_data() QTest::addColumn<int>("tableWidth"); QTest::addColumn<int>("valueOffset"); QTest::addColumn<int>("compositeOffset"); - QTest::addColumn<QGalleryDBusInterfacePointer>("queryInterface"); + QTest::addColumn<QString>("sparql"); QTest::newRow("file:://path/to/file.ext") @@ -533,7 +498,6 @@ void tst_QGalleryTrackerSchema::prepareValidItemResponse_data() << 3 << 3 << 3 - << m_metaDataInterface << "SELECT ?x nie:url(?x) rdf:type(?x) " "WHERE {" "?x a nfo:FileDataObject . " @@ -556,7 +520,6 @@ void tst_QGalleryTrackerSchema::prepareValidItemResponse_data() << 1 << 1 << 1 - << m_metaDataInterface << "SELECT ?x " "WHERE {" "?x a nmm:MusicAlbum . " @@ -580,14 +543,13 @@ void tst_QGalleryTrackerSchema::prepareValidItemResponse() QFETCH(int, tableWidth); QFETCH(int, valueOffset); QFETCH(int, compositeOffset); - QFETCH(QGalleryDBusInterfacePointer, queryInterface); QFETCH(QString, sparql); QGalleryTrackerResultSetArguments arguments; QGalleryTrackerSchema schema = QGalleryTrackerSchema::fromItemId(itemId.toString()); QCOMPARE( - schema.prepareItemResponse(&arguments, this, itemId.toString(), propertyNames), + schema.prepareItemResponse(&arguments, itemId.toString(), propertyNames), QDocumentGallery::NoError); QVERIFY(arguments.idColumn != 0); @@ -605,7 +567,6 @@ void tst_QGalleryTrackerSchema::prepareValidItemResponse() QCOMPARE(arguments.valueOffset, valueOffset); QCOMPARE(arguments.compositeOffset, compositeOffset); - QCOMPARE(arguments.queryInterface, queryInterface); QCOMPARE(arguments.sparql, sparql); } @@ -630,7 +591,7 @@ void tst_QGalleryTrackerSchema::prepareInvalidItemResponse() QGalleryTrackerResultSetArguments arguments; QGalleryTrackerSchema schema = QGalleryTrackerSchema::fromItemId(itemId); - QCOMPARE(schema.prepareItemResponse(&arguments, this, itemId, propertyNames), error); + QCOMPARE(schema.prepareItemResponse(&arguments, itemId, propertyNames), error); } void tst_QGalleryTrackerSchema::queryResponseRootType_data() @@ -770,7 +731,6 @@ void tst_QGalleryTrackerSchema::queryResponseRootType() QCOMPARE( schema.prepareQueryResponse( &arguments, - this, QGalleryQueryRequest::AllDescendants, QString(), QGalleryFilter(), @@ -780,7 +740,6 @@ void tst_QGalleryTrackerSchema::queryResponseRootType() 0), QDocumentGallery::NoError); - QCOMPARE(arguments.queryInterface, m_metaDataInterface); QCOMPARE(arguments.sparql, sparql); QCOMPARE(arguments.updateMask, updateMask); @@ -1361,7 +1320,6 @@ void tst_QGalleryTrackerSchema::queryResponseFilePropertyNames() QCOMPARE( schema.prepareQueryResponse( &arguments, - this, QGalleryQueryRequest::AllDescendants, QString(), QGalleryFilter(), @@ -1767,7 +1725,6 @@ void tst_QGalleryTrackerSchema::queryResponseRootItem() QCOMPARE( schema.prepareQueryResponse( &arguments, - this, scope, rootItem, QGalleryFilter(), @@ -2515,7 +2472,6 @@ void tst_QGalleryTrackerSchema::queryResponseFilter() QCOMPARE( schema.prepareQueryResponse( &arguments, - this, scope, rootItem, filter, @@ -2559,7 +2515,6 @@ void tst_QGalleryTrackerSchema::queryResponseItemUrl() QCOMPARE( schema.prepareQueryResponse( &arguments, - this, QGalleryQueryRequest::AllDescendants, QString(), QGalleryFilter(), @@ -2694,7 +2649,6 @@ void tst_QGalleryTrackerSchema::queryResponseValueColumnToVariant() QCOMPARE( schema.prepareQueryResponse( &arguments, - this, QGalleryQueryRequest::AllDescendants, QString(), QGalleryFilter(), @@ -2823,7 +2777,6 @@ void tst_QGalleryTrackerSchema::queryResponseValueColumnToString() QCOMPARE( schema.prepareQueryResponse( &arguments, - this, QGalleryQueryRequest::AllDescendants, QString(), QGalleryFilter(), @@ -2905,7 +2858,6 @@ void tst_QGalleryTrackerSchema::queryResponseCompositeColumn() QCOMPARE( schema.prepareQueryResponse( &arguments, - this, QGalleryQueryRequest::AllDescendants, QString(), QGalleryFilter(), @@ -3139,7 +3091,7 @@ void tst_QGalleryTrackerSchema::prepareInvalidQueryResponse() QCOMPARE( schema.prepareQueryResponse( - &arguments, this, scope, rootItem, filter, propertyNames, sortPropertyNames, 0, 0), + &arguments, scope, rootItem, filter, propertyNames, sortPropertyNames, 0, 0), error); } |