/**************************************************************************** ** ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the Qt Mobility Components. ** ** $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 "qdocumentgallery.h" #include "qabstractgallery_p.h" #include "qgalleryitemrequest.h" #include "qgalleryqueryrequest.h" #include "qgallerytyperequest.h" #include "qgallerytrackerchangenotifier_p.h" #include "qgallerytrackereditableresultset_p.h" #include "qgallerytrackerschema_p.h" #include "qgallerytrackertyperesultset_p.h" #include #include Q_DECLARE_METATYPE(QVector) QTM_BEGIN_NAMESPACE class QDocumentGalleryPrivate : public QAbstractGalleryPrivate, public QGalleryDBusInterfaceFactory { public: QGalleryAbstractResponse *createItemResponse(QGalleryItemRequest *request); QGalleryAbstractResponse *createTypeResponse(QGalleryTypeRequest *request); QGalleryAbstractResponse *createFilterResponse(QGalleryQueryRequest *request); private: QGalleryDBusInterfacePointer daemonInterface(); QGalleryDBusInterfacePointer metaDataInterface(); QGalleryDBusInterfacePointer searchInterface(); QGalleryDBusInterfacePointer fileInterface(); QGalleryTrackerChangeNotifier *changeNotifier(); QGalleryAbstractResponse *createItemListResponse( QGalleryTrackerResultSetArguments *arguments, int offset, int limit, bool isItemType, bool autoUpdate); QGalleryDBusInterfacePointer daemonService; QGalleryDBusInterfacePointer metaDataService; QGalleryDBusInterfacePointer searchService; QGalleryDBusInterfacePointer fileService; QScopedPointer notifier; }; QGalleryDBusInterfacePointer QDocumentGalleryPrivate::daemonInterface() { if (!daemonService) { daemonService = new QGalleryTrackerDaemonDBusInterface( QLatin1String("org.freedesktop.Tracker"), QLatin1String("/org/freedesktop/Tracker"), "org.freedesktop.Tracker"); } return daemonService; } QGalleryDBusInterfacePointer QDocumentGalleryPrivate::metaDataInterface() { if (!metaDataService) { metaDataService = new QGalleryDBusInterface( QLatin1String("org.freedesktop.Tracker"), QLatin1String("/org/freedesktop/Tracker/Metadata"), "org.freedesktop.Tracker.Metadata"); } return metaDataService; } QGalleryDBusInterfacePointer QDocumentGalleryPrivate::searchInterface() { if (!searchService) { searchService = new QGalleryDBusInterface( QLatin1String("org.freedesktop.Tracker"), QLatin1String("/org/freedesktop/Tracker/Search"), "org.freedesktop.Tracker.Search"); } return searchService; } QGalleryDBusInterfacePointer QDocumentGalleryPrivate::fileInterface() { if (!fileService) { fileService = new QGalleryDBusInterface( QLatin1String("org.freedesktop.Tracker"), QLatin1String("/org/freedesktop/Tracker/Files"), "org.freedesktop.Tracker.Files"); } return fileService; } QGalleryTrackerChangeNotifier *QDocumentGalleryPrivate::changeNotifier() { if (!notifier) notifier.reset(new QGalleryTrackerChangeNotifier(daemonInterface())); return notifier.data(); } QGalleryAbstractResponse *QDocumentGalleryPrivate::createItemResponse(QGalleryItemRequest *request) { QGalleryTrackerSchema schema = QGalleryTrackerSchema::fromItemId(request->itemId().toString()); QGalleryTrackerResultSetArguments arguments; int error = schema.prepareItemResponse( &arguments, this, request->itemId().toString(), request->propertyNames()); if (error != QDocumentGallery::NoError) { return new QGalleryAbstractResponse(error); } else { return createItemListResponse(&arguments, 0, 1, schema.isItemType(), request->autoUpdate()); } } QGalleryAbstractResponse *QDocumentGalleryPrivate::createTypeResponse(QGalleryTypeRequest *request) { QGalleryTrackerSchema schema(request->itemType()); QGalleryTrackerTypeResultSetArguments arguments; int error = schema.prepareTypeResponse(&arguments, this); if (error != QDocumentGallery::NoError) { return new QGalleryAbstractResponse(error); } else { QGalleryTrackerTypeResultSet *response = new QGalleryTrackerTypeResultSet(arguments); if (request->autoUpdate()) { QObject::connect( changeNotifier(), SIGNAL(itemsChanged(int)), response, SLOT(refresh(int))); } return response; } } QGalleryAbstractResponse *QDocumentGalleryPrivate::createItemListResponse( QGalleryTrackerResultSetArguments *arguments, int offset, int limit, bool isItemType, bool autoUpdate) { QGalleryTrackerResultSet *response = 0; if (isItemType) { response = new QGalleryTrackerEditableResultSet( arguments, metaDataInterface(), autoUpdate, offset, limit); } else { response = new QGalleryTrackerResultSet(arguments, autoUpdate, offset, limit); } if (autoUpdate) { QObject::connect( changeNotifier(), SIGNAL(itemsChanged(int)), response, SLOT(refresh(int))); } QObject::connect( response, SIGNAL(itemEdited(QString)), changeNotifier(), SLOT(itemsEdited(QString))); return response; } QGalleryAbstractResponse *QDocumentGalleryPrivate::createFilterResponse( QGalleryQueryRequest *request) { QGalleryTrackerSchema schema(request->rootType()); QGalleryTrackerResultSetArguments arguments; int error = schema.prepareQueryResponse( &arguments, this, request->scope(), request->rootItem().toString(), request->filter(), request->propertyNames(), request->sortPropertyNames()); if (error != QDocumentGallery::NoError) { return new QGalleryAbstractResponse(error); } else { return createItemListResponse( &arguments, request->offset(), request->limit(), schema.isItemType(), request->autoUpdate()); } } QDocumentGallery::QDocumentGallery(QObject *parent) : QAbstractGallery(*new QDocumentGalleryPrivate, parent) { qDBusRegisterMetaType >(); } QDocumentGallery::~QDocumentGallery() { } bool QDocumentGallery::isRequestSupported(QGalleryAbstractRequest::RequestType type) const { switch (type) { case QGalleryAbstractRequest::QueryRequest: case QGalleryAbstractRequest::ItemRequest: case QGalleryAbstractRequest::TypeRequest: return true; default: return false; } } QStringList QDocumentGallery::itemTypePropertyNames(const QString &itemType) const { return QGalleryTrackerSchema(itemType).supportedPropertyNames(); } QGalleryProperty::Attributes QDocumentGallery::propertyAttributes( const QString &propertyName, const QString &itemType) const { return QGalleryTrackerSchema(itemType).propertyAttributes(propertyName); } QGalleryAbstractResponse *QDocumentGallery::createResponse(QGalleryAbstractRequest *request) { Q_D(QDocumentGallery); switch (request->type()) { case QGalleryAbstractRequest::QueryRequest: return d->createFilterResponse(static_cast(request)); case QGalleryAbstractRequest::ItemRequest: return d->createItemResponse(static_cast(request)); case QGalleryAbstractRequest::TypeRequest: return d->createTypeResponse(static_cast(request)); default: return 0; } } #include "moc_qdocumentgallery.cpp" QTM_END_NAMESPACE