diff --git a/src/akonadi/CMakeLists.txt b/src/akonadi/CMakeLists.txt --- a/src/akonadi/CMakeLists.txt +++ b/src/akonadi/CMakeLists.txt @@ -1,7 +1,6 @@ set(akonadi_SRCS akonadiapplicationselectedattribute.cpp akonadicollectionfetchjobinterface.cpp - akonadicollectionsearchjobinterface.cpp akonadiconfigdialog.cpp akonadicontextqueries.cpp akonadicontextrepository.cpp diff --git a/src/akonadi/akonadicollectionfetchjobinterface.h b/src/akonadi/akonadicollectionfetchjobinterface.h --- a/src/akonadi/akonadicollectionfetchjobinterface.h +++ b/src/akonadi/akonadicollectionfetchjobinterface.h @@ -40,7 +40,6 @@ virtual Collection::List collections() const = 0; virtual void setResource(const QString &resource) = 0; - virtual void setFiltered(bool filter) = 0; }; } diff --git a/src/akonadi/akonadicollectionsearchjobinterface.h b/src/akonadi/akonadicollectionsearchjobinterface.h deleted file mode 100644 --- a/src/akonadi/akonadicollectionsearchjobinterface.h +++ /dev/null @@ -1,46 +0,0 @@ -/* This file is part of Zanshin - - Copyright 2014 Mario Bensi - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License or (at your option) version 3 or any later version - accepted by the membership of KDE e.V. (or its successor approved - by the membership of KDE e.V.), which shall act as a proxy - defined in Section 14 of version 3 of the license. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - USA. -*/ - -#ifndef AKONADI_COLLECTIONSEARCHJOBINTERFACE_H -#define AKONADI_COLLECTIONSEARCHJOBINTERFACE_H - -#include - -class KJob; - -namespace Akonadi { - -class CollectionSearchJobInterface -{ -public: - CollectionSearchJobInterface(); - virtual ~CollectionSearchJobInterface(); - - KJob *kjob(); - - virtual Collection::List collections() const = 0; -}; - -} - -#endif // AKONADI_COLLECTIONSEARCHJOBINTERFACE_H diff --git a/src/akonadi/akonadicollectionsearchjobinterface.cpp b/src/akonadi/akonadicollectionsearchjobinterface.cpp deleted file mode 100644 --- a/src/akonadi/akonadicollectionsearchjobinterface.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* This file is part of Zanshin - - Copyright 2014 Mario Bensi - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License or (at your option) version 3 or any later version - accepted by the membership of KDE e.V. (or its successor approved - by the membership of KDE e.V.), which shall act as a proxy - defined in Section 14 of version 3 of the license. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - USA. -*/ - - -#include "akonadicollectionsearchjobinterface.h" - -#include - -using namespace Akonadi; - -CollectionSearchJobInterface::CollectionSearchJobInterface() -{ -} - -CollectionSearchJobInterface::~CollectionSearchJobInterface() -{ -} - -KJob *CollectionSearchJobInterface::kjob() -{ - KJob *job = dynamic_cast(this); - Q_ASSERT(job); - return job; -} diff --git a/src/akonadi/akonadidatasourcequeries.h b/src/akonadi/akonadidatasourcequeries.h --- a/src/akonadi/akonadidatasourcequeries.h +++ b/src/akonadi/akonadidatasourcequeries.h @@ -54,25 +54,16 @@ DataSourceResult::Ptr findTopLevel() const Q_DECL_OVERRIDE; DataSourceResult::Ptr findChildren(Domain::DataSource::Ptr source) const Q_DECL_OVERRIDE; - QString searchTerm() const Q_DECL_OVERRIDE; - void setSearchTerm(const QString &term) Q_DECL_OVERRIDE; - DataSourceResult::Ptr findSearchTopLevel() const Q_DECL_OVERRIDE; - DataSourceResult::Ptr findSearchChildren(Domain::DataSource::Ptr source) const Q_DECL_OVERRIDE; - private: CollectionInputQuery::PredicateFunction createFetchPredicate(const Collection &root) const; - CollectionInputQuery::PredicateFunction createSearchPredicate(const Collection &root) const; StorageInterface::FetchContentTypes m_contentTypes; SerializerInterface::Ptr m_serializer; LiveQueryHelpers::Ptr m_helpers; LiveQueryIntegrator::Ptr m_integrator; mutable DataSourceQueryOutput::Ptr m_findTopLevel; mutable QHash m_findChildren; - QString m_searchTerm; - mutable DataSourceQueryOutput::Ptr m_findSearchTopLevel; - mutable QHash m_findSearchChildren; }; } diff --git a/src/akonadi/akonadidatasourcequeries.cpp b/src/akonadi/akonadidatasourcequeries.cpp --- a/src/akonadi/akonadidatasourcequeries.cpp +++ b/src/akonadi/akonadidatasourcequeries.cpp @@ -39,7 +39,6 @@ { m_integrator->addRemoveHandler([this] (const Collection &collection) { m_findChildren.remove(collection.id()); - m_findSearchChildren.remove(collection.id()); }); } @@ -82,55 +81,10 @@ return query->result(); } -QString DataSourceQueries::searchTerm() const -{ - return m_searchTerm; -} - -void DataSourceQueries::setSearchTerm(const QString &term) -{ - if (m_searchTerm == term) - return; - - m_searchTerm = term; - if (m_findSearchTopLevel) { - m_findSearchTopLevel->reset(); - } - foreach (auto query, m_findSearchChildren) - query->reset(); -} - -DataSourceQueries::DataSourceResult::Ptr DataSourceQueries::findSearchTopLevel() const -{ - auto fetch = m_helpers->searchCollections(Collection::root(), &m_searchTerm, m_contentTypes); - auto predicate = createSearchPredicate(Collection::root()); - m_integrator->bind("DataSourceQueries::findSearchTopLevel", m_findSearchTopLevel, fetch, predicate); - return m_findSearchTopLevel->result(); -} - -DataSourceQueries::DataSourceResult::Ptr DataSourceQueries::findSearchChildren(Domain::DataSource::Ptr source) const -{ - Collection root = m_serializer->createCollectionFromDataSource(source); - auto &query = m_findSearchChildren[root.id()]; - auto fetch = m_helpers->searchCollections(root, &m_searchTerm, m_contentTypes); - auto predicate = createSearchPredicate(root); - m_integrator->bind("DataSourceQueries::findSearchChildren", query, fetch, predicate); - return query->result(); -} - DataSourceQueries::CollectionInputQuery::PredicateFunction DataSourceQueries::createFetchPredicate(const Collection &root) const { return [this, root] (const Collection &collection) { return collection.isValid() - && collection.parentCollection() == root - && m_serializer->isListedCollection(collection); - }; -} - -DataSourceQueries::CollectionInputQuery::PredicateFunction DataSourceQueries::createSearchPredicate(const Collection &root) const -{ - return [root] (const Collection &collection) { - return collection.isValid() && collection.parentCollection() == root; }; } diff --git a/src/akonadi/akonadilivequeryhelpers.h b/src/akonadi/akonadilivequeryhelpers.h --- a/src/akonadi/akonadilivequeryhelpers.h +++ b/src/akonadi/akonadilivequeryhelpers.h @@ -45,8 +45,6 @@ CollectionFetchFunction fetchAllCollections(StorageInterface::FetchContentTypes contentTypes) const; CollectionFetchFunction fetchCollections(const Collection &root, StorageInterface::FetchContentTypes contentTypes) const; - CollectionFetchFunction searchCollections(const Collection &root, const QString *searchTerm, - StorageInterface::FetchContentTypes contentTypes) const; ItemFetchFunction fetchItems(StorageInterface::FetchContentTypes contentTypes) const; ItemFetchFunction fetchItems(const Tag &tag) const; diff --git a/src/akonadi/akonadilivequeryhelpers.cpp b/src/akonadi/akonadilivequeryhelpers.cpp --- a/src/akonadi/akonadilivequeryhelpers.cpp +++ b/src/akonadi/akonadilivequeryhelpers.cpp @@ -25,7 +25,6 @@ #include "akonadilivequeryhelpers.h" #include "akonadi/akonadicollectionfetchjobinterface.h" -#include "akonadi/akonadicollectionsearchjobinterface.h" #include "akonadi/akonadiitemfetchjobinterface.h" #include "akonadi/akonaditagfetchjobinterface.h" @@ -79,36 +78,6 @@ }; } -LiveQueryHelpers::CollectionFetchFunction LiveQueryHelpers::searchCollections(const Collection &root, const QString *searchTerm, - StorageInterface::FetchContentTypes contentTypes) const -{ - auto storage = m_storage; - return [storage, contentTypes, searchTerm, root] (const Domain::LiveQueryInput::AddFunction &add) { - if (searchTerm->isEmpty()) - return; - - auto job = storage->searchCollections(*searchTerm, contentTypes); - Utils::JobHandler::install(job->kjob(), [root, job, add] { - if (job->kjob()->error()) - return; - - auto directChildren = QHash(); - foreach (const auto &collection, job->collections()) { - auto directChild = collection; - while (directChild.parentCollection() != root && directChild.parentCollection().isValid()) - directChild = directChild.parentCollection(); - if (directChild.parentCollection() != root) - continue; - if (!directChildren.contains(directChild.id())) - directChildren[directChild.id()] = directChild; - } - - foreach (const auto &directChild, directChildren) - add(directChild); - }); - }; -} - LiveQueryHelpers::ItemFetchFunction LiveQueryHelpers::fetchItems(StorageInterface::FetchContentTypes contentTypes) const { auto serializer = m_serializer; diff --git a/src/akonadi/akonadiserializer.h b/src/akonadi/akonadiserializer.h --- a/src/akonadi/akonadiserializer.h +++ b/src/akonadi/akonadiserializer.h @@ -47,7 +47,6 @@ Domain::DataSource::Ptr createDataSourceFromCollection(Akonadi::Collection collection, DataSourceNameScheme naming) Q_DECL_OVERRIDE; void updateDataSourceFromCollection(Domain::DataSource::Ptr dataSource, Akonadi::Collection collection, DataSourceNameScheme naming) Q_DECL_OVERRIDE; virtual Akonadi::Collection createCollectionFromDataSource(Domain::DataSource::Ptr dataSource) Q_DECL_OVERRIDE; - bool isListedCollection(Akonadi::Collection collection) Q_DECL_OVERRIDE; virtual bool isSelectedCollection(Akonadi::Collection collection) Q_DECL_OVERRIDE; virtual bool isNoteCollection(Akonadi::Collection collection) Q_DECL_OVERRIDE; virtual bool isTaskCollection(Akonadi::Collection collection) Q_DECL_OVERRIDE; diff --git a/src/akonadi/akonadiserializer.cpp b/src/akonadi/akonadiserializer.cpp --- a/src/akonadi/akonadiserializer.cpp +++ b/src/akonadi/akonadiserializer.cpp @@ -116,13 +116,6 @@ dataSource->setSelected(isSelected); } - if (collection.enabled()) - dataSource->setListStatus(Domain::DataSource::Bookmarked); - else if (collection.referenced()) - dataSource->setListStatus(Domain::DataSource::Listed); - else - dataSource->setListStatus(Domain::DataSource::Unlisted); - dataSource->setProperty("collectionId", collection.id()); } @@ -136,37 +129,11 @@ auto selectedAttribute = collection.attribute(Akonadi::Collection::AddIfMissing); selectedAttribute->setSelected(dataSource->isSelected()); - switch (dataSource->listStatus()) { - case Domain::DataSource::Unlisted: - collection.setReferenced(false); - collection.setEnabled(false); - break; - case Domain::DataSource::Listed: - collection.setReferenced(true); - collection.setEnabled(false); - break; - case Domain::DataSource::Bookmarked: - collection.setReferenced(false); - collection.setEnabled(true); - break; - default: - qFatal("Shouldn't happen"); - break; - } - return collection; } -bool Serializer::isListedCollection(Collection collection) -{ - return collection.enabled() || collection.referenced(); -} - bool Serializer::isSelectedCollection(Collection collection) { - if (!isListedCollection(collection)) - return false; - if (!isNoteCollection(collection) && !isTaskCollection(collection)) return false; diff --git a/src/akonadi/akonadiserializerinterface.h b/src/akonadi/akonadiserializerinterface.h --- a/src/akonadi/akonadiserializerinterface.h +++ b/src/akonadi/akonadiserializerinterface.h @@ -62,7 +62,6 @@ virtual Domain::DataSource::Ptr createDataSourceFromCollection(Akonadi::Collection collection, DataSourceNameScheme naming) = 0; virtual void updateDataSourceFromCollection(Domain::DataSource::Ptr dataSource, Akonadi::Collection collection, DataSourceNameScheme naming) = 0; virtual Akonadi::Collection createCollectionFromDataSource(Domain::DataSource::Ptr dataSource) = 0; - virtual bool isListedCollection(Akonadi::Collection collection) = 0; virtual bool isSelectedCollection(Akonadi::Collection collection) = 0; virtual bool isNoteCollection(Akonadi::Collection collection) = 0; virtual bool isTaskCollection(Akonadi::Collection collection) = 0; diff --git a/src/akonadi/akonadistorage.h b/src/akonadi/akonadistorage.h --- a/src/akonadi/akonadistorage.h +++ b/src/akonadi/akonadistorage.h @@ -58,7 +58,6 @@ KJob *removeTag(Akonadi::Tag tag) Q_DECL_OVERRIDE; CollectionFetchJobInterface *fetchCollections(Akonadi::Collection collection, FetchDepth depth, FetchContentTypes types) Q_DECL_OVERRIDE; - CollectionSearchJobInterface *searchCollections(QString collectionName, FetchContentTypes types) Q_DECL_OVERRIDE; ItemFetchJobInterface *fetchItems(Akonadi::Collection collection) Q_DECL_OVERRIDE; ItemFetchJobInterface *fetchItem(Akonadi::Item item) Q_DECL_OVERRIDE; ItemFetchJobInterface *fetchTagItems(Akonadi::Tag tag) Q_DECL_OVERRIDE; diff --git a/src/akonadi/akonadistorage.cpp b/src/akonadi/akonadistorage.cpp --- a/src/akonadi/akonadistorage.cpp +++ b/src/akonadi/akonadistorage.cpp @@ -47,7 +47,6 @@ #include #include #include "akonadi/akonadicollectionfetchjobinterface.h" -#include "akonadi/akonadicollectionsearchjobinterface.h" #include "akonadi/akonadiitemfetchjobinterface.h" #include "akonadi/akonaditagfetchjobinterface.h" #include "akonadi/akonadistoragesettings.h" @@ -119,79 +118,11 @@ fetchScope().setResource(resource); } - void setFiltered(bool filter) Q_DECL_OVERRIDE - { - fetchScope().setListFilter(filter ? Akonadi::CollectionFetchScope::Display - : Akonadi::CollectionFetchScope::NoFilter); - } - private: const Collection m_collection; const Type m_type; }; -class CollectionSearchJob : public CollectionFetchJob, public CollectionSearchJobInterface -{ - Q_OBJECT -public: - CollectionSearchJob(const QString &collectionName, QObject *parent = Q_NULLPTR) - : CollectionFetchJob(Akonadi::Collection::root(), - CollectionJob::Recursive, - parent), - m_collectionName(collectionName) - { - } - - Collection::List collections() const Q_DECL_OVERRIDE - { - auto collections = CollectionFetchJob::collections(); - - // Memorize them to reconstruct the ancestor chain later - QMap collectionsMap; - collectionsMap[Akonadi::Collection::root().id()] = Akonadi::Collection::root(); - foreach (const auto &collection, collections) { - collectionsMap[collection.id()] = collection; - } - - // Why the hell isn't fetchScope() const and returning a reference??? - auto self = const_cast(this); - const auto allowedMimeTypes = self->fetchScope().contentMimeTypes().toSet(); - - collections.erase(std::remove_if(collections.begin(), collections.end(), - [allowedMimeTypes, this] (const Collection &collection) { - auto mimeTypes = collection.contentMimeTypes().toSet(); - return mimeTypes.intersect(allowedMimeTypes).isEmpty() - || !collection.displayName().contains(m_collectionName, Qt::CaseInsensitive); - }), - collections.end()); - - // Replace the dummy parents in the ancestor chain with proper ones - // full of juicy data - std::function reconstructAncestors = - [collectionsMap, &reconstructAncestors, this] (const Collection &collection) -> Collection { - Q_ASSERT(collection.isValid()); - - if (collection == Akonadi::Collection::root()) - return collection; - - auto parent = collection.parentCollection(); - auto reconstructedParent = reconstructAncestors(collectionsMap[parent.id()]); - - auto result = collection; - result.setParentCollection(reconstructedParent); - return result; - }; - - std::transform(collections.begin(), collections.end(), - collections.begin(), reconstructAncestors); - - return collections; - } - -private: - QString m_collectionName; -}; - class ItemJob : public ItemFetchJob, public ItemFetchJobInterface { Q_OBJECT @@ -318,27 +249,6 @@ return job; } -CollectionSearchJobInterface *Storage::searchCollections(QString collectionName, FetchContentTypes types) -{ - QStringList contentMimeTypes; - if (types & Notes) - contentMimeTypes << NoteUtils::noteMimeType(); - if (types & Tasks) - contentMimeTypes << KCalCore::Todo::todoMimeType(); - - auto job = new CollectionSearchJob(collectionName); - - auto scope = job->fetchScope(); - scope.setContentMimeTypes(contentMimeTypes); - scope.setIncludeStatistics(true); - scope.setAncestorRetrieval(CollectionFetchScope::All); - scope.setListFilter(Akonadi::CollectionFetchScope::NoFilter); - job->setFetchScope(scope); - - return job; -} - - ItemFetchJobInterface *Storage::fetchItems(Collection collection) { auto job = new ItemJob(collection); diff --git a/src/akonadi/akonadistorageinterface.h b/src/akonadi/akonadistorageinterface.h --- a/src/akonadi/akonadistorageinterface.h +++ b/src/akonadi/akonadistorageinterface.h @@ -36,7 +36,6 @@ class Collection; class CollectionFetchJobInterface; -class CollectionSearchJobInterface; class ItemFetchJobInterface; class TagFetchJobInterface; @@ -83,7 +82,6 @@ virtual KJob *removeTag(Akonadi::Tag tag) = 0; virtual CollectionFetchJobInterface *fetchCollections(Akonadi::Collection collection, FetchDepth depth, FetchContentTypes types) = 0; - virtual CollectionSearchJobInterface *searchCollections(QString collectionName, FetchContentTypes types) = 0; virtual ItemFetchJobInterface *fetchItems(Akonadi::Collection collection) = 0; virtual ItemFetchJobInterface *fetchItem(Akonadi::Item item) = 0; virtual ItemFetchJobInterface *fetchTagItems(Akonadi::Tag tag) = 0; diff --git a/src/domain/datasource.h b/src/domain/datasource.h --- a/src/domain/datasource.h +++ b/src/domain/datasource.h @@ -36,11 +36,10 @@ class DataSource : public QObject { Q_OBJECT - Q_ENUMS(ContentType ListStatus) + Q_ENUMS(ContentType) Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) Q_PROPERTY(QString iconName READ iconName WRITE setIconName NOTIFY iconNameChanged) Q_PROPERTY(Domain::DataSource::ContentTypes contentTypes READ contentTypes WRITE setContentTypes NOTIFY contentTypesChanged) - Q_PROPERTY(Domain::DataSource::ListStatus listStatus READ listStatus WRITE setListStatus NOTIFY listStatusChanged) Q_PROPERTY(bool selected READ isSelected WRITE setSelected NOTIFY selectedChanged) public: typedef QSharedPointer Ptr; @@ -53,48 +52,37 @@ }; Q_DECLARE_FLAGS(ContentTypes, ContentType) - enum ListStatus { - Unlisted = 0, - Listed = 1, - Bookmarked = 3 - }; - explicit DataSource(QObject *parent = Q_NULLPTR); virtual ~DataSource(); QString name() const; QString iconName() const; ContentTypes contentTypes() const; - ListStatus listStatus() const; bool isSelected() const; public slots: void setName(const QString &name); void setIconName(const QString &iconName); void setContentTypes(Domain::DataSource::ContentTypes types); - void setListStatus(Domain::DataSource::ListStatus status); void setSelected(bool selected); signals: void nameChanged(const QString &name); void iconNameChanged(const QString &iconName); void contentTypesChanged(Domain::DataSource::ContentTypes types); - void listStatusChanged(Domain::DataSource::ListStatus status); void selectedChanged(bool selected); private: QString m_name; QString m_iconName; ContentTypes m_contentTypes; - ListStatus m_listStatus; bool m_selected; }; } Q_DECLARE_METATYPE(Domain::DataSource::Ptr) Q_DECLARE_METATYPE(Domain::DataSource::ContentTypes) Q_DECLARE_OPERATORS_FOR_FLAGS(Domain::DataSource::ContentTypes) -Q_DECLARE_METATYPE(Domain::DataSource::ListStatus) #endif // DOMAIN_DATASOURCE_H diff --git a/src/domain/datasource.cpp b/src/domain/datasource.cpp --- a/src/domain/datasource.cpp +++ b/src/domain/datasource.cpp @@ -29,7 +29,6 @@ DataSource::DataSource(QObject *parent) : QObject(parent), m_contentTypes(NoContent), - m_listStatus(Unlisted), m_selected(false) { } @@ -53,11 +52,6 @@ return m_contentTypes; } -DataSource::ListStatus DataSource::listStatus() const -{ - return m_listStatus; -} - bool DataSource::isSelected() const { return m_selected; @@ -90,15 +84,6 @@ emit contentTypesChanged(types); } -void DataSource::setListStatus(ListStatus status) -{ - if (m_listStatus == status) - return; - - m_listStatus = status; - emit listStatusChanged(status); -} - void DataSource::setSelected(bool selected) { if (m_selected == selected) diff --git a/src/domain/datasourcequeries.h b/src/domain/datasourcequeries.h --- a/src/domain/datasourcequeries.h +++ b/src/domain/datasourcequeries.h @@ -67,11 +67,6 @@ public: virtual QueryResult::Ptr findTopLevel() const = 0; virtual QueryResult::Ptr findChildren(DataSource::Ptr source) const = 0; - - virtual QString searchTerm() const = 0; - virtual void setSearchTerm(const QString &term) = 0; - virtual QueryResult::Ptr findSearchTopLevel() const = 0; - virtual QueryResult::Ptr findSearchChildren(DataSource::Ptr source) const = 0; }; } diff --git a/src/presentation/availablesourcesmodel.h b/src/presentation/availablesourcesmodel.h --- a/src/presentation/availablesourcesmodel.h +++ b/src/presentation/availablesourcesmodel.h @@ -41,29 +41,16 @@ { Q_OBJECT Q_PROPERTY(QAbstractItemModel* sourceListModel READ sourceListModel) - Q_PROPERTY(QAbstractItemModel* searchListModel READ searchListModel) - Q_PROPERTY(QString searchTerm READ searchTerm WRITE setSearchTerm NOTIFY searchTermChanged) public: explicit AvailableSourcesModel(const Domain::DataSourceQueries::Ptr &dataSourceQueries, const Domain::DataSourceRepository::Ptr &dataSourceRepository, QObject *parent = Q_NULLPTR); QAbstractItemModel *sourceListModel(); - QAbstractItemModel *searchListModel(); - - QString searchTerm() const; - void setSearchTerm(const QString &term); - -signals: - void searchTermChanged(const QString &term); public slots: void setDefaultItem(const QModelIndex &index); - void listSource(const Domain::DataSource::Ptr &source); - void unlistSource(const Domain::DataSource::Ptr &source); - void bookmarkSource(const Domain::DataSource::Ptr &source); - void showConfigDialog(); private slots: @@ -73,10 +60,8 @@ void emitDefaultSourceChanged(const QModelIndex &root); QAbstractItemModel *createSourceListModel(); - QAbstractItemModel *createSearchListModel(); QAbstractItemModel *m_sourceListModel; - QAbstractItemModel *m_searchListModel; Domain::DataSourceQueries::Ptr m_dataSourceQueries; Domain::DataSourceRepository::Ptr m_dataSourceRepository; diff --git a/src/presentation/availablesourcesmodel.cpp b/src/presentation/availablesourcesmodel.cpp --- a/src/presentation/availablesourcesmodel.cpp +++ b/src/presentation/availablesourcesmodel.cpp @@ -38,7 +38,6 @@ QObject *parent) : QObject(parent), m_sourceListModel(Q_NULLPTR), - m_searchListModel(Q_NULLPTR), m_dataSourceQueries(dataSourceQueries), m_dataSourceRepository(dataSourceRepository) { @@ -51,42 +50,6 @@ return m_sourceListModel; } -QAbstractItemModel *AvailableSourcesModel::searchListModel() -{ - if (!m_searchListModel) - m_searchListModel = createSearchListModel(); - return m_searchListModel; -} - -void AvailableSourcesModel::listSource(const Domain::DataSource::Ptr &source) -{ - Q_ASSERT(source); - source->setSelected(true); - source->setListStatus(Domain::DataSource::Listed); - const auto job = m_dataSourceRepository->update(source); - installHandler(job, tr("Cannot modify source %1").arg(source->name())); -} - -void AvailableSourcesModel::unlistSource(const Domain::DataSource::Ptr &source) -{ - Q_ASSERT(source); - source->setSelected(false); - source->setListStatus(Domain::DataSource::Unlisted); - const auto job = m_dataSourceRepository->update(source); - installHandler(job, tr("Cannot modify source %1").arg(source->name())); -} - -void AvailableSourcesModel::bookmarkSource(const Domain::DataSource::Ptr &source) -{ - Q_ASSERT(source); - if (source->listStatus() == Domain::DataSource::Bookmarked) - source->setListStatus(Domain::DataSource::Listed); - else - source->setListStatus(Domain::DataSource::Bookmarked); - const auto job = m_dataSourceRepository->update(source); - installHandler(job, tr("Cannot modify source %1").arg(source->name())); -} - void AvailableSourcesModel::showConfigDialog() { m_dataSourceRepository->showConfigDialog(); @@ -168,76 +131,6 @@ return new QueryTreeModel(query, flags, data, setData, drop, drag, this); } -QAbstractItemModel *AvailableSourcesModel::createSearchListModel() -{ - auto query = [this] (const Domain::DataSource::Ptr &source) { - if (!source) - return m_dataSourceQueries->findSearchTopLevel(); - else - return m_dataSourceQueries->findSearchChildren(source); - }; - - auto flags = [] (const Domain::DataSource::Ptr &source) { - Q_UNUSED(source) - return Qt::ItemIsSelectable | Qt::ItemIsEnabled; - }; - - auto data = [] (const Domain::DataSource::Ptr &source, int role) -> QVariant { - if (role != Qt::DisplayRole - && role != Qt::EditRole - && role != Qt::DecorationRole - && role != QueryTreeModelBase::IconNameRole) { - return QVariant(); - } - - if (role == Qt::DisplayRole || role == Qt::EditRole) { - return source->name(); - } else if (role == Qt::DecorationRole || role == QueryTreeModelBase::IconNameRole) { - const QString iconName = source->iconName().isEmpty() ? QStringLiteral("folder") : source->iconName(); - - if (role == Qt::DecorationRole) - return QVariant::fromValue(QIcon::fromTheme(iconName)); - else - return iconName; - } else { - return QVariant(); - } - }; - - auto setData = [this] (const Domain::DataSource::Ptr &source, const QVariant &value, int role) { - Q_UNUSED(source) - Q_UNUSED(value) - Q_UNUSED(role) - return false; - }; - - auto drop = [] (const QMimeData *mimeData, Qt::DropAction, const Domain::DataSource::Ptr &source) { - Q_UNUSED(mimeData) - Q_UNUSED(source) - return false; - }; - - auto drag = [](const Domain::DataSource::List &) -> QMimeData* { - return Q_NULLPTR; - }; - - return new QueryTreeModel(query, flags, data, setData, drop, drag, this); -} - -QString AvailableSourcesModel::searchTerm() const -{ - return m_dataSourceQueries->searchTerm(); -} - -void AvailableSourcesModel::setSearchTerm(const QString &term) -{ - if (term == searchTerm()) - return; - - m_dataSourceQueries->setSearchTerm(term); - emit searchTermChanged(term); -} - void AvailableSourcesModel::setDefaultItem(const QModelIndex &index) { auto source = index.data(QueryTreeModelBase::ObjectRole).value(); diff --git a/src/widgets/availablesourcesview.h b/src/widgets/availablesourcesview.h --- a/src/widgets/availablesourcesview.h +++ b/src/widgets/availablesourcesview.h @@ -54,8 +54,6 @@ void onSelectionChanged(); void onSettingsTriggered(); void onDefaultTriggered(); - void onActionTriggered(const Domain::DataSource::Ptr &source, int action); - void onSearchTextChanged(const QString &text); private: QHash m_actions; diff --git a/src/widgets/availablesourcesview.cpp b/src/widgets/availablesourcesview.cpp --- a/src/widgets/availablesourcesview.cpp +++ b/src/widgets/availablesourcesview.cpp @@ -53,15 +53,6 @@ m_sortProxy->setDynamicSortFilter(true); m_sortProxy->sort(0); - auto searchEdit = new KLineEdit(this); - searchEdit->setObjectName(QStringLiteral("searchEdit")); - searchEdit->setClearButtonShown(true); - searchEdit->setPlaceholderText(tr("Search...")); - connect(searchEdit, &QLineEdit::textChanged, this, &AvailableSourcesView::onSearchTextChanged); -#ifndef ZANSHIN_HIDING_SOURCES_ENABLED - searchEdit->hide(); -#endif - m_sourcesView->setObjectName(QStringLiteral("sourcesView")); m_sourcesView->header()->hide(); m_sourcesView->setModel(m_sortProxy); @@ -72,10 +63,6 @@ connect(m_sourcesView->model(), &QAbstractItemModel::modelReset, m_sourcesView, &QTreeView::expandAll); auto delegate = new DataSourceDelegate(m_sourcesView); -#ifndef ZANSHIN_HIDING_SOURCES_ENABLED - delegate->setActionsEnabled(false); -#endif - connect(delegate, &DataSourceDelegate::actionTriggered, this, &AvailableSourcesView::onActionTriggered); m_sourcesView->setItemDelegate(delegate); auto actionBar = new QToolBar(this); @@ -89,7 +76,6 @@ actionBar->addAction(m_defaultAction); auto layout = new QVBoxLayout; - layout->addWidget(searchEdit); layout->addWidget(m_sourcesView); auto actionBarLayout = new QHBoxLayout; @@ -169,41 +155,9 @@ Q_ARG(QModelIndex, index)); } -void AvailableSourcesView::onActionTriggered(const Domain::DataSource::Ptr &source, int action) -{ - switch (action) { - case DataSourceDelegate::AddToList: - QMetaObject::invokeMethod(m_model, "listSource", - Q_ARG(Domain::DataSource::Ptr, source)); - break; - case DataSourceDelegate::RemoveFromList: - QMetaObject::invokeMethod(m_model, "unlistSource", - Q_ARG(Domain::DataSource::Ptr, source)); - break; - case DataSourceDelegate::Bookmark: - QMetaObject::invokeMethod(m_model, "bookmarkSource", - Q_ARG(Domain::DataSource::Ptr, source)); - break; - default: - qFatal("Shouldn't happen"); - break; - } -} - void AvailableSourcesView::setSourceModel(const QByteArray &propertyName) { QVariant modelProperty = m_model->property(propertyName); if (modelProperty.canConvert()) m_sortProxy->setSourceModel(modelProperty.value()); } - -void AvailableSourcesView::onSearchTextChanged(const QString &text) -{ - if (text.size() <= 2) { - m_model->setProperty("searchTerm", QString()); - setSourceModel("sourceListModel"); - } else { - m_model->setProperty("searchTerm", text); - setSourceModel("searchListModel"); - } -} diff --git a/src/widgets/datasourcedelegate.h b/src/widgets/datasourcedelegate.h --- a/src/widgets/datasourcedelegate.h +++ b/src/widgets/datasourcedelegate.h @@ -36,32 +36,11 @@ class DataSourceDelegate : public QStyledItemDelegate { Q_OBJECT - Q_ENUMS(Action) public: - enum Action { - AddToList = 0, - RemoveFromList, - Bookmark - }; - explicit DataSourceDelegate(QObject *parent = Q_NULLPTR); - bool isActionsEnabled() const; - void setActionsEnabled(bool isActionsEnabled); - void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE; QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE; - -signals: - void actionTriggered(const Domain::DataSource::Ptr &source, int action); - -protected: - bool editorEvent(QEvent *event, QAbstractItemModel *model, - const QStyleOptionViewItem &option, const QModelIndex &index) Q_DECL_OVERRIDE; - -private: - bool m_actionsEnabled; - QHash m_pixmaps; }; } diff --git a/src/widgets/datasourcedelegate.cpp b/src/widgets/datasourcedelegate.cpp --- a/src/widgets/datasourcedelegate.cpp +++ b/src/widgets/datasourcedelegate.cpp @@ -35,163 +35,27 @@ const int DELEGATE_HEIGHT = 16; DataSourceDelegate::DataSourceDelegate(QObject *parent) - : QStyledItemDelegate(parent), - m_actionsEnabled(true) + : QStyledItemDelegate(parent) { - m_pixmaps[AddToList] = QIcon::fromTheme(QStringLiteral("list-add")).pixmap(DELEGATE_HEIGHT); - m_pixmaps[RemoveFromList] = QIcon::fromTheme(QStringLiteral("list-remove")).pixmap(DELEGATE_HEIGHT); - m_pixmaps[Bookmark] = QIcon::fromTheme(QStringLiteral("bookmarks")).pixmap(DELEGATE_HEIGHT); -} - - -bool DataSourceDelegate::isActionsEnabled() const -{ - return m_actionsEnabled; -} - -void DataSourceDelegate::setActionsEnabled(bool actionsEnabled) -{ - m_actionsEnabled = actionsEnabled; -} - -static QRect createButtonRect(const QRect &itemRect, int position) -{ - static const int border = 2; - const int side = itemRect.height() - (2 * border); - const int offset = side * (position + 1) + border * (position + 2); - return itemRect.adjusted(itemRect.width() - (offset + side), border, -offset, -border); -} - -static QStyle *currentStyle(const QStyleOptionViewItem &option) -{ - QWidget const *widget = option.widget; - QStyle *style = widget ? widget->style() : QApplication::style(); - return style; -} - -static QStyleOptionButton createButtonOption(const QStyleOptionViewItem &itemOption, const QPixmap &pixmap, int position) -{ - const QRect itemRect = itemOption.rect; - const QRect buttonRect = createButtonRect(itemRect, position); - - QStyleOptionButton buttonOption; - buttonOption.state = QStyle::State_Active | QStyle::State_Enabled; - buttonOption.icon = pixmap; - buttonOption.rect = buttonRect; - buttonOption.iconSize = pixmap.size(); - return buttonOption; -} - -static QList actionsForSource(const Domain::DataSource::Ptr &source, bool isHovered, bool enabled) -{ - auto actions = QList(); - - if (!enabled) - return actions; - - if (source->contentTypes() == Domain::DataSource::NoContent) - return actions; - - if (source->listStatus() == Domain::DataSource::Unlisted) { - actions << DataSourceDelegate::AddToList; - } else { - actions << DataSourceDelegate::Bookmark; - if (isHovered) - actions << DataSourceDelegate::RemoveFromList; - } - - return actions; -} - -static Domain::DataSource::Ptr sourceForIndex(const QModelIndex &index) -{ - const auto data = index.data(Presentation::QueryTreeModel::ObjectRole); - const auto source = data.value(); - Q_ASSERT(source); - return source; } void DataSourceDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opt, const QModelIndex &index) const { Q_ASSERT(index.isValid()); - const auto source = sourceForIndex(index); - const auto isHovered = bool(opt.state & QStyle::State_MouseOver); const auto isDefault = index.data(Presentation::QueryTreeModel::IsDefaultRole).toBool(); QStyleOptionViewItem option = opt; initStyleOption(&option, index); option.font.setBold(isDefault); - QStyle *s = currentStyle(opt); - - int position = 0; - foreach (Action action, actionsForSource(source, isHovered, m_actionsEnabled)) { - QStyleOptionButton buttonOption = createButtonOption(option, m_pixmaps[action], position); - if (action == Bookmark - && source->listStatus() != Domain::DataSource::Bookmarked) { - buttonOption.state &= ~QStyle::State_Enabled; - } - s->drawControl(QStyle::CE_PushButton, &buttonOption, painter, Q_NULLPTR); - position++; - } - - if (position != 0) { - const auto firstButtonLeft = createButtonRect(option.rect, position - 1).left(); - option.rect.setRight(firstButtonLeft); - } QStyledItemDelegate::paint(painter, option, index); } -bool DataSourceDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, - const QStyleOptionViewItem &option, const QModelIndex &index) -{ - Q_ASSERT(event); - Q_ASSERT(model); - - int button = -1; - - switch (event->type()) { - case QEvent::MouseButtonRelease: - { - QMouseEvent *mouseEvent = static_cast(event); - - for (int position = 0; position < 4; position++) { - if (createButtonRect(option.rect, position).contains(mouseEvent->pos())) { - button = position; - break; - } - } - - if (mouseEvent->button() != Qt::LeftButton || button < 0) { - return QStyledItemDelegate::editorEvent(event, model, option, index); - } - } - break; - - default: - return QStyledItemDelegate::editorEvent(event, model, option, index); - } - - Q_ASSERT(button >= 0); - QStyleOptionViewItem opt = option; - opt.state |= QStyle::State_MouseOver; - - const auto source = sourceForIndex(index); - auto actions = actionsForSource(source, true, m_actionsEnabled); - if (actions.count() > button) { - const Action a = actions.at(button); - emit actionTriggered(source, a); - return true; - } - - return QStyledItemDelegate::editorEvent(event, model, option, index); -} - QSize DataSourceDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { QSize size = QStyledItemDelegate::sizeHint(option, index); - // Make sure we got a constant height suitable for the buttons + // Make sure we got a constant height size.setHeight(DELEGATE_HEIGHT + 4); return size; } diff --git a/tests/testlib/akonadifakejobs.h b/tests/testlib/akonadifakejobs.h --- a/tests/testlib/akonadifakejobs.h +++ b/tests/testlib/akonadifakejobs.h @@ -26,7 +26,6 @@ #include "fakejob.h" #include "akonadi/akonadicollectionfetchjobinterface.h" -#include "akonadi/akonadicollectionsearchjobinterface.h" #include "akonadi/akonadiitemfetchjobinterface.h" #include "akonadi/akonaditagfetchjobinterface.h" @@ -46,26 +45,9 @@ QString resource() const; void setResource(const QString &resource) Q_DECL_OVERRIDE; - bool filtered() const; - void setFiltered(bool filter) Q_DECL_OVERRIDE; - private: Akonadi::Collection::List m_collections; QString m_resource; - bool m_filter; -}; - -class AkonadiFakeCollectionSearchJob : public FakeJob, public Akonadi::CollectionSearchJobInterface -{ - Q_OBJECT -public: - using FakeJob::FakeJob; - - void setCollections(const Akonadi::Collection::List &collections); - Akonadi::Collection::List collections() const Q_DECL_OVERRIDE; - -private: - Akonadi::Collection::List m_collections; }; class AkonadiFakeItemFetchJob : public FakeJob, public Akonadi::ItemFetchJobInterface diff --git a/tests/testlib/akonadifakejobs.cpp b/tests/testlib/akonadifakejobs.cpp --- a/tests/testlib/akonadifakejobs.cpp +++ b/tests/testlib/akonadifakejobs.cpp @@ -47,26 +47,6 @@ m_resource = resource; } -bool AkonadiFakeCollectionFetchJob::filtered() const -{ - return m_filter; -} - -void AkonadiFakeCollectionFetchJob::setFiltered(bool filter) -{ - m_filter = filter; -} - -void AkonadiFakeCollectionSearchJob::setCollections(const Akonadi::Collection::List &collections) -{ - m_collections = collections; -} - -Akonadi::Collection::List AkonadiFakeCollectionSearchJob::collections() const -{ - return isDone() ? m_collections : Akonadi::Collection::List(); -} - void AkonadiFakeItemFetchJob::setItems(const Akonadi::Item::List &items) { m_items = items; diff --git a/tests/testlib/akonadifakestorage.h b/tests/testlib/akonadifakestorage.h --- a/tests/testlib/akonadifakestorage.h +++ b/tests/testlib/akonadifakestorage.h @@ -56,7 +56,6 @@ KJob *removeTag(Akonadi::Tag tag) Q_DECL_OVERRIDE; Akonadi::CollectionFetchJobInterface *fetchCollections(Akonadi::Collection collection, FetchDepth depth, FetchContentTypes types) Q_DECL_OVERRIDE; - Akonadi::CollectionSearchJobInterface *searchCollections(QString collectionName, FetchContentTypes types) Q_DECL_OVERRIDE; Akonadi::ItemFetchJobInterface *fetchItems(Akonadi::Collection collection) Q_DECL_OVERRIDE; Akonadi::ItemFetchJobInterface *fetchItem(Akonadi::Item item) Q_DECL_OVERRIDE; Akonadi::ItemFetchJobInterface *fetchTagItems(Akonadi::Tag tag) Q_DECL_OVERRIDE; diff --git a/tests/testlib/akonadifakestorage.cpp b/tests/testlib/akonadifakestorage.cpp --- a/tests/testlib/akonadifakestorage.cpp +++ b/tests/testlib/akonadifakestorage.cpp @@ -389,43 +389,6 @@ return job; } -Akonadi::CollectionSearchJobInterface *AkonadiFakeStorage::searchCollections(QString collectionName, FetchContentTypes types) -{ - auto job = new AkonadiFakeCollectionSearchJob; - const auto allCollections = m_data->collections(); - auto foundCollections = Akonadi::Collection::List(); - - std::copy_if(allCollections.constBegin(), allCollections.constEnd(), - std::back_inserter(foundCollections), - [collectionName, types] (const Akonadi::Collection &col) { - const auto mime = col.contentMimeTypes().toSet(); - auto contentMimeTypes = QSet(); - if (types & Notes) - contentMimeTypes << Akonadi::NoteUtils::noteMimeType(); - if (types & Tasks) - contentMimeTypes << KCalCore::Todo::todoMimeType(); - - const bool supportedType = contentMimeTypes.isEmpty() - || !(mime & contentMimeTypes).isEmpty(); - return supportedType && col.displayName().contains(collectionName, Qt::CaseInsensitive); - }); - - // Replace the dummy parents in the ancestor chain with proper ones - // full of juicy data - using namespace std::placeholders; - auto reconstructCollection = std::bind(&AkonadiFakeData::reconstructAncestors, - m_data, _1, Akonadi::Collection::root()); - std::transform(foundCollections.begin(), foundCollections.end(), - foundCollections.begin(), reconstructCollection); - - const auto behavior = m_data->storageBehavior().searchCollectionsBehavior(collectionName); - if (behavior == AkonadiFakeStorageBehavior::NormalFetch) - job->setCollections(foundCollections); - job->setExpectedError(m_data->storageBehavior().searchCollectionsErrorCode(collectionName)); - Utils::JobHandler::install(job, noop); - return job; -} - Akonadi::ItemFetchJobInterface *AkonadiFakeStorage::fetchItems(Akonadi::Collection collection) { auto items = m_data->childItems(findId(collection)); diff --git a/tests/testlib/akonadistoragetestbase.h b/tests/testlib/akonadistoragetestbase.h --- a/tests/testlib/akonadistoragetestbase.h +++ b/tests/testlib/akonadistoragetestbase.h @@ -88,12 +88,6 @@ void shouldNotifyCollectionTimestampChanges(); void shouldNotifyCollectionSelectionChanges(); void shouldNotNotifyCollectionSelectionChangesForIrrelevantCollections(); - void shouldNotifyCollectionSubscriptionChanges_data(); - void shouldNotifyCollectionSubscriptionChanges(); - void shouldFindCollectionsByName_data(); - void shouldFindCollectionsByName(); - void shouldFindCollectionsByNameIncludingTheirAncestors_data(); - void shouldFindCollectionsByNameIncludingTheirAncestors(); private: Akonadi::Item fetchItemByRID(const QString &remoteId, const Akonadi::Collection &collection); diff --git a/tests/testlib/akonadistoragetestbase.cpp b/tests/testlib/akonadistoragetestbase.cpp --- a/tests/testlib/akonadistoragetestbase.cpp +++ b/tests/testlib/akonadistoragetestbase.cpp @@ -41,7 +41,6 @@ #include "akonadi/akonadiapplicationselectedattribute.h" #include "akonadi/akonadicollectionfetchjobinterface.h" -#include "akonadi/akonadicollectionsearchjobinterface.h" #include "akonadi/akonadiitemfetchjobinterface.h" #include "akonadi/akonadimonitorimpl.h" #include "akonadi/akonadistorage.h" @@ -77,62 +76,36 @@ QTest::addColumn("expectedNames"); QTest::addColumn("depth"); QTest::addColumn("contentTypes"); - QTest::addColumn("referenceCalendar1"); - QTest::addColumn("enableCalendar1"); QTest::newRow("all") << Akonadi::Collection::root() << QStringList({ "Calendar1", "Calendar2", "Calendar3", "Change me!", "Destroy me!", "Notes" }) << Akonadi::Storage::Recursive - << int(Akonadi::StorageInterface::Notes|Akonadi::StorageInterface::Tasks) - << false << true; - - QTest::newRow("include referenced") << Akonadi::Collection::root() - << QStringList({ "Calendar1", "Calendar2", "Calendar3", "Change me!", "Destroy me!", "Notes" }) - << Akonadi::Storage::Recursive - << int(Akonadi::StorageInterface::Notes|Akonadi::StorageInterface::Tasks) - << true << false; - - QTest::newRow("include referenced + enabled") << Akonadi::Collection::root() - << QStringList({ "Calendar1", "Calendar2", "Calendar3", "Change me!", "Destroy me!", "Notes" }) - << Akonadi::Storage::Recursive - << int(Akonadi::StorageInterface::Notes|Akonadi::StorageInterface::Tasks) - << true << true; - - QTest::newRow("exclude !referenced + !enabled") << Akonadi::Collection::root() - << QStringList({ "Calendar2", "Calendar3", "Change me!", "Destroy me!", "Notes" }) - << Akonadi::Storage::Recursive - << int(Akonadi::StorageInterface::Notes|Akonadi::StorageInterface::Tasks) - << false << false; + << int(Akonadi::StorageInterface::Notes|Akonadi::StorageInterface::Tasks); QTest::newRow("notes") << Akonadi::Collection::root() << QStringList({ "Notes" }) << Akonadi::Storage::Recursive - << int(Akonadi::StorageInterface::Notes) - << false << true; + << int(Akonadi::StorageInterface::Notes); QTest::newRow("tasks") << Akonadi::Collection::root() << QStringList({ "Calendar1", "Calendar2", "Calendar3", "Change me!", "Destroy me!" }) << Akonadi::Storage::Recursive - << int(Akonadi::StorageInterface::Tasks) - << false << true; + << int(Akonadi::StorageInterface::Tasks); QTest::newRow("base type") << calendar2() << QStringList({"Calendar2"}) << Akonadi::Storage::Base - << int(Akonadi::StorageInterface::Tasks) - << false << true; + << int(Akonadi::StorageInterface::Tasks); QTest::newRow("firstLevel type") << calendar1() << QStringList({"Calendar2"}) << Akonadi::Storage::FirstLevel - << int(Akonadi::StorageInterface::Tasks) - << false << true; + << int(Akonadi::StorageInterface::Tasks); QTest::newRow("recursive type") << calendar1() << QStringList({"Calendar2", "Calendar3"}) << Akonadi::Storage::Recursive - << int(Akonadi::StorageInterface::Tasks) - << false << true; + << int(Akonadi::StorageInterface::Tasks); } void AkonadiStorageTestBase::shouldListCollections() @@ -142,22 +115,9 @@ QFETCH(QStringList, expectedNames); QFETCH(Akonadi::StorageInterface::FetchDepth, depth); QFETCH(int, contentTypes); - QFETCH(bool, referenceCalendar1); - QFETCH(bool, enableCalendar1); auto storage = createStorage(); - // Default is not referenced and enabled - // no need to feedle with the collection in that case - if (referenceCalendar1 || !enableCalendar1) { - Akonadi::Collection cal1 = calendar1(); - cal1.setReferenced(referenceCalendar1); - cal1.setEnabled(enableCalendar1); - auto update = storage->updateCollection(cal1); - AKVERIFYEXEC(update); - } - - // WHEN auto job = storage->fetchCollections(collection, depth, Akonadi::StorageInterface::FetchContentTypes(contentTypes)); @@ -172,15 +132,6 @@ } collectionNames.sort(); - // Restore proper DB state - if (referenceCalendar1 || !enableCalendar1) { - Akonadi::Collection cal1 = calendar1(); - cal1.setReferenced(false); - cal1.setEnabled(true); - auto update = storage->updateCollection(cal1); - AKVERIFYEXEC(update); - } - QCOMPARE(collectionNames, expectedNames); } @@ -1229,175 +1180,6 @@ QVERIFY(selectionSpy.isEmpty()); } -void AkonadiStorageTestBase::shouldNotifyCollectionSubscriptionChanges_data() -{ - QTest::addColumn("isEnabled"); - QTest::addColumn("isReferenced"); - - QTest::newRow("enabled and !referenced") << true << false; - // Fails randomly due to an akonadi bug... - //QTest::newRow("!enabled and referenced") << false << true; - QTest::newRow("!enabled and !referenced") << false << false; - QTest::newRow("!enabled and referenced (again)") << false << true; - QTest::newRow("enabled and !referenced (again)") << true << false; -} - -void AkonadiStorageTestBase::shouldNotifyCollectionSubscriptionChanges() -{ - // GIVEN - QFETCH(bool, isEnabled); - QFETCH(bool, isReferenced); - - // A storage implementation - auto storage = createStorage(); - - // An existing collection - Akonadi::Collection collection(calendar2().id()); - - // A spied monitor - auto monitor = createMonitor(); - QSignalSpy changeSpy(monitor.data(), &Akonadi::MonitorInterface::collectionChanged); - MonitorSpy monitorSpy(monitor.data()); - - // WHEN - static int run = 1; - collection.attribute(Akonadi::Collection::AddIfMissing) - ->setIconName(QStringLiteral("folder-%1").arg(run++)); - collection.setEnabled(isEnabled); - collection.setReferenced(isReferenced); - auto job = storage->updateCollection(collection); - AKVERIFYEXEC(job); - monitorSpy.waitForStableState(); - QTRY_VERIFY(!changeSpy.isEmpty()); - - // THEN - QCOMPARE(changeSpy.size(), 1); - - auto notifiedCollection = changeSpy.takeFirst().at(0).value(); - QCOMPARE(notifiedCollection.id(), collection.id()); - QCOMPARE(notifiedCollection.enabled(), isEnabled); - QCOMPARE(notifiedCollection.referenced(), isReferenced); -} - -void AkonadiStorageTestBase::shouldFindCollectionsByName_data() -{ - QTest::addColumn("name"); - QTest::addColumn("contentType"); - QTest::addColumn("expectedResults"); - QTest::addColumn("referenceCalendar1"); - QTest::addColumn("enableCalendar1"); - - QStringList expectedResults; - expectedResults << QStringLiteral("Calendar1"); - QTest::newRow("get a collection") << "Calendar1" << int(Akonadi::StorageInterface::Tasks) << expectedResults << false << true; - - expectedResults.clear(); - QTest::newRow("try with wrong type") << "Calendar1" << int(Akonadi::StorageInterface::Notes) << expectedResults << false << true; - - expectedResults << QStringLiteral("Notes"); - QTest::newRow("get a note collection") << "Not" << int(Akonadi::StorageInterface::Notes) << expectedResults << false << true; - - expectedResults.clear(); - QTest::newRow("try with unknown name") << "toto" << int(Akonadi::StorageInterface::Tasks) << expectedResults << false << true; - - expectedResults << QStringLiteral("Calendar3") << QStringLiteral("Calendar2") << QStringLiteral("Calendar1"); - QTest::newRow("try with a part of a name") << "Calendar" << int(Akonadi::StorageInterface::Tasks) << expectedResults << false << true; - - expectedResults.clear(); - expectedResults << QStringLiteral("Calendar2"); - QTest::newRow("make sure it is case insensitive") << "calendar2" << int(Akonadi::StorageInterface::Tasks) << expectedResults << false << true; - - expectedResults.clear(); - expectedResults << QStringLiteral("Calendar1"); - QTest::newRow("include referenced") << "Calendar1" << int(Akonadi::StorageInterface::Tasks) << expectedResults << true << false; - QTest::newRow("include referenced + enabled") << "Calendar1" << int(Akonadi::StorageInterface::Tasks) << expectedResults << true << true; - QTest::newRow("include !referenced + !enabled") << "Calendar1" << int(Akonadi::StorageInterface::Tasks) << expectedResults << false << false; -} - -void AkonadiStorageTestBase::shouldFindCollectionsByName() -{ - // GIVEN - auto storage = createStorage(); - - QFETCH(QString, name); - QFETCH(int, contentType); - QFETCH(QStringList, expectedResults); - QFETCH(bool, referenceCalendar1); - QFETCH(bool, enableCalendar1); - - // A spied monitor - auto monitor = createMonitor(); - MonitorSpy monitorSpy(monitor.data()); - - // Default is not referenced and enabled - // no need to feedle with the collection in that case - if (referenceCalendar1 || !enableCalendar1) { - Akonadi::Collection cal1 = calendar1(); - cal1.setReferenced(referenceCalendar1); - cal1.setEnabled(enableCalendar1); - auto update = storage->updateCollection(cal1); - AKVERIFYEXEC(update); - monitorSpy.waitForStableState(); - } - - // WHEN - auto job = storage->searchCollections(name, Akonadi::StorageInterface::FetchContentType(contentType)); - AKVERIFYEXEC(job->kjob()); - - // THEN - auto collections = job->collections(); - - // Restore proper DB state - if (referenceCalendar1 || !enableCalendar1) { - Akonadi::Collection cal1 = calendar1(); - cal1.setReferenced(false); - cal1.setEnabled(true); - auto update = storage->updateCollection(cal1); - AKVERIFYEXEC(update); - monitorSpy.waitForStableState(); - } - - auto collectionNames = QStringList(); - std::transform(collections.constBegin(), collections.constEnd(), - std::back_inserter(collectionNames), - Utils::mem_fn(&Akonadi::Collection::name)); - QCOMPARE(collectionNames.toSet(), expectedResults.toSet()); -} - -void AkonadiStorageTestBase::shouldFindCollectionsByNameIncludingTheirAncestors_data() -{ - QTest::addColumn("searchTerm"); - QTest::addColumn("contentType"); - - QTest::newRow("task search") << "Calendar3" << int(Akonadi::StorageInterface::Tasks); - QTest::newRow("note search") << "Notes" << int(Akonadi::StorageInterface::Notes); -} - -void AkonadiStorageTestBase::shouldFindCollectionsByNameIncludingTheirAncestors() -{ - // GIVEN - auto storage = createStorage(); - - // WHEN - QFETCH(QString, searchTerm); - QFETCH(int, contentType); - auto job = storage->searchCollections(searchTerm, Akonadi::StorageInterface::FetchContentType(contentType)); - AKVERIFYEXEC(job->kjob()); - - // THEN - auto collections = job->collections(); - foreach (const auto &collection, collections) { - auto parent = collection.parentCollection(); - while (parent != Akonadi::Collection::root()) { - QVERIFY(parent.isValid()); - QVERIFY(!parent.displayName().isEmpty()); - parent = parent.parentCollection(); - } - } -} - - - Akonadi::Item AkonadiStorageTestBase::fetchItemByRID(const QString &remoteId, const Akonadi::Collection &collection) { Akonadi::Item item; @@ -1425,7 +1207,6 @@ auto job = createStorage()->fetchCollections(collection, Akonadi::StorageInterface::Base, Akonadi::StorageInterface::AllContent); job->setResource(QStringLiteral("akonadi_knut_resource_0")); - job->setFiltered(false); if (!job->kjob()->exec()) { qWarning() << job->kjob()->errorString() << remoteId; return Akonadi::Collection(); diff --git a/tests/testlib/gencollection.h b/tests/testlib/gencollection.h --- a/tests/testlib/gencollection.h +++ b/tests/testlib/gencollection.h @@ -42,8 +42,6 @@ GenCollection &withRootAsParent(); GenCollection &withName(const QString &name); GenCollection &withIcon(const QString &iconName); - GenCollection &referenced(bool value = true); - GenCollection &enabled(bool value = true); GenCollection &selected(bool value = true); GenCollection &withTaskContent(bool value = true); GenCollection &withNoteContent(bool value = true); diff --git a/tests/testlib/gencollection.cpp b/tests/testlib/gencollection.cpp --- a/tests/testlib/gencollection.cpp +++ b/tests/testlib/gencollection.cpp @@ -73,18 +73,6 @@ return *this; } -GenCollection &GenCollection::referenced(bool value) -{ - m_collection.setReferenced(value); - return *this; -} - -GenCollection &GenCollection::enabled(bool value) -{ - m_collection.setEnabled(value); - return *this; -} - GenCollection &GenCollection::selected(bool value) { if (!value) { diff --git a/tests/units/akonadi/akonadidatasourcequeriestest.cpp b/tests/units/akonadi/akonadidatasourcequeriestest.cpp --- a/tests/units/akonadi/akonadidatasourcequeriestest.cpp +++ b/tests/units/akonadi/akonadidatasourcequeriestest.cpp @@ -305,33 +305,6 @@ QVERIFY(replaceHandlerCalled); } - void shouldRemoveUnlistedCollectionFromTopLevelTasks() - { - // GIVEN - AkonadiFakeData data; - - // Two top level collections and one child collection - data.createCollection(GenCollection().withId(42).withName(QStringLiteral("42Task")).withRootAsParent().withTaskContent()); - data.createCollection(GenCollection().withId(43).withName(QStringLiteral("43Note")).withRootAsParent().withNoteContent()); - data.createCollection(GenCollection().withId(44).withName(QStringLiteral("44NoteChild")).withParent(43).withNoteContent()); - - QScopedPointer queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Tasks | Akonadi::StorageInterface::Notes, - Akonadi::StorageInterface::Ptr(data.createStorage()), - Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer), - Akonadi::MonitorInterface::Ptr(data.createMonitor()))); - - Domain::QueryResult::Ptr result = queries->findTopLevel(); - TestHelpers::waitForEmptyJobQueue(); - QCOMPARE(result->data().size(), 2); - - // WHEN - data.modifyCollection(GenCollection(data.collection(43)).referenced(false).enabled(false)); // datasource unlisted now - - // THEN - QCOMPARE(result->data().size(), 1); - QCOMPARE(result->data().first()->name(), QStringLiteral("42Task")); - } - void shouldNotCrashDuringFindTopLevelWhenFetchJobFailedOrEmpty_data() { QTest::addColumn("colErrorCode"); @@ -550,37 +523,6 @@ QVERIFY(replaceHandlerCalled); } - void shouldRemoveUnlistedCollectionsFromChildSources() - { - // GIVEN - AkonadiFakeData data; - - // One top level collection with two children - data.createCollection(GenCollection().withId(42).withName(QStringLiteral("42Task")).withRootAsParent().withTaskContent()); - data.createCollection(GenCollection().withId(43).withName(QStringLiteral("43TaskFirstChild")).withParent(42).withTaskContent()); - data.createCollection(GenCollection().withId(44).withName(QStringLiteral("44NoteSecondChild")).withParent(42).withNoteContent()); - - // Serializer - auto serializer = Akonadi::Serializer::Ptr(new Akonadi::Serializer); - Domain::DataSource::Ptr topLevelDataSource = serializer->createDataSourceFromCollection(data.collection(42), Akonadi::SerializerInterface::BaseName); - - QScopedPointer queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Tasks | Akonadi::StorageInterface::Notes, - Akonadi::StorageInterface::Ptr(data.createStorage()), - serializer, - Akonadi::MonitorInterface::Ptr(data.createMonitor()))); - - Domain::QueryResult::Ptr result = queries->findChildren(topLevelDataSource); - TestHelpers::waitForEmptyJobQueue(); - QCOMPARE(result->data().size(), 2); - - // WHEN - data.modifyCollection(GenCollection(data.collection(43)).referenced(false).enabled(false)); // unlist the child collection - - // THEN - QCOMPARE(result->data().size(), 1); - QCOMPARE(result->data().first()->name(), QStringLiteral("44NoteSecondChild")); - } - void shouldNotCrashDuringFindChildrenWhenFetchJobFailedOrEmpty_data() { QTest::addColumn("colErrorCode"); @@ -643,566 +585,6 @@ TestHelpers::waitForEmptyJobQueue(); QCOMPARE(result->data().size(), 0); } - - void shouldLookInAllReportedForSearchTopLevelSources_data() - { - QTest::addColumn("contentTypes"); - QTest::addColumn("expectedColNames"); - QTest::addColumn("expectedTitiNames"); - - auto expectedColNames = QStringList(); - auto expectedTitiNames = QStringList(); - expectedColNames << QStringLiteral("TaskToto") << QStringLiteral("NoteCol"); - expectedTitiNames << QStringLiteral("NoteTiti") << QStringLiteral("TaskTiti"); - QTest::newRow("tasks and notes") << int(Akonadi::StorageInterface::Tasks | Akonadi::StorageInterface::Notes) - << expectedColNames << expectedTitiNames; - - expectedColNames.clear(); - expectedTitiNames.clear(); - expectedColNames << QStringLiteral("TaskToto"); - expectedTitiNames << QStringLiteral("TaskTiti"); - QTest::newRow("tasks") << int(Akonadi::StorageInterface::Tasks) - << expectedColNames << expectedTitiNames; - - expectedColNames.clear(); - expectedTitiNames.clear(); - expectedColNames << QStringLiteral("NoteCol"); - expectedTitiNames << QStringLiteral("NoteTiti"); - QTest::newRow("notes") << int(Akonadi::StorageInterface::Notes) - << expectedColNames << expectedTitiNames; - } - - void shouldLookInAllReportedForSearchTopLevelSources() - { - // GIVEN - AkonadiFakeData data; - - // Four top level collections, two with tasks, two with notes - data.createCollection(GenCollection().withId(42).withName(QStringLiteral("TaskToto")).withRootAsParent().withTaskContent()); - data.createCollection(GenCollection().withId(43).withName(QStringLiteral("NoteTiti")).withRootAsParent().withNoteContent()); - data.createCollection(GenCollection().withId(44).withName(QStringLiteral("TaskTiti")).withRootAsParent().withTaskContent()); - data.createCollection(GenCollection().withId(46).withName(QStringLiteral("NoteCol")).withRootAsParent().withNoteContent()); - data.createCollection(GenCollection().withId(47).withName(QStringLiteral("NoCol")).withRootAsParent()); - - // One child collection with tasks - data.createCollection(GenCollection().withId(45).withName(QStringLiteral("TaskTotoCol")).withParent(42).withTaskContent()); - - QString searchTerm(QStringLiteral("Col")); - - // WHEN - QFETCH(int, contentTypes); - QScopedPointer queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::FetchContentTypes(contentTypes), - Akonadi::StorageInterface::Ptr(data.createStorage()), - Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer), - Akonadi::MonitorInterface::Ptr(data.createMonitor()))); - - queries->setSearchTerm(searchTerm); - Domain::QueryResult::Ptr result = queries->findSearchTopLevel(); - result->data(); - result = queries->findSearchTopLevel(); // Should not cause any problem or wrong data - - // THEN - QVERIFY(result->data().isEmpty()); - TestHelpers::waitForEmptyJobQueue(); - - auto sources = result->data(); - auto actualNames = QStringList(); - std::transform(sources.constBegin(), sources.constEnd(), - std::back_inserter(actualNames), - [] (const Domain::DataSource::Ptr &source) { return source->name(); }); - actualNames.sort(); - - QFETCH(QStringList, expectedColNames); - expectedColNames.sort(); - QCOMPARE(actualNames, expectedColNames); - - // WHEN - QString searchTerm2(QStringLiteral("Titi")); - queries->setSearchTerm(searchTerm2); - - // THEN - TestHelpers::waitForEmptyJobQueue(); - - sources = result->data(); - actualNames.clear(); - std::transform(sources.constBegin(), sources.constEnd(), - std::back_inserter(actualNames), - [] (const Domain::DataSource::Ptr &source) { return source->name(); }); - actualNames.sort(); - - QFETCH(QStringList, expectedTitiNames); - expectedTitiNames.sort(); - QCOMPARE(actualNames, expectedTitiNames); - } - - void shouldReactToCollectionAddsForSearchTopLevelSources() - { - // GIVEN - AkonadiFakeData data; - - QString searchTerm(QStringLiteral("col")); - - QScopedPointer queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Tasks | Akonadi::StorageInterface::Notes, - Akonadi::StorageInterface::Ptr(data.createStorage()), - Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer), - Akonadi::MonitorInterface::Ptr(data.createMonitor()))); - queries->setSearchTerm(searchTerm); - Domain::QueryResult::Ptr result = queries->findSearchTopLevel(); - TestHelpers::waitForEmptyJobQueue(); - QVERIFY(result->data().isEmpty()); - - // WHEN - data.createCollection(GenCollection().withId(42).withName(QStringLiteral("42Task")).withRootAsParent().withTaskContent()); - - // THEN - QCOMPARE(result->data().size(), 1); - QCOMPARE(result->data().first()->name(), QStringLiteral("42Task")); - } - - void shouldReactToCollectionRemovesForSearchTopLevelSources() - { - // GIVEN - AkonadiFakeData data; - - // Two top level collections - data.createCollection(GenCollection().withId(42).withName(QStringLiteral("TaskToto")).withRootAsParent().withTaskContent()); - data.createCollection(GenCollection().withId(43).withName(QStringLiteral("NoteToto")).withRootAsParent().withNoteContent()); - - QString searchTerm(QStringLiteral("Toto")); - - QScopedPointer queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Tasks | Akonadi::StorageInterface::Notes, - Akonadi::StorageInterface::Ptr(data.createStorage()), - Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer), - Akonadi::MonitorInterface::Ptr(data.createMonitor()))); - queries->setSearchTerm(searchTerm); - Domain::QueryResult::Ptr result = queries->findSearchTopLevel(); - TestHelpers::waitForEmptyJobQueue(); - QCOMPARE(result->data().size(), 2); - - // WHEN - data.removeCollection(Akonadi::Collection(42)); - - // THEN - QCOMPARE(result->data().size(), 1); - QCOMPARE(result->data().first()->name(), QStringLiteral("NoteToto")); - } - - void shouldReactToItemChangesForSearchTopLevelTasks() - { - // GIVEN - AkonadiFakeData data; - - // Two top level collections - data.createCollection(GenCollection().withId(42).withName(QStringLiteral("TaskCol1")).withRootAsParent().withTaskContent()); - data.createCollection(GenCollection().withId(43).withName(QStringLiteral("NoteCol2")).withRootAsParent().withNoteContent()); - - // One child collection - data.createCollection(GenCollection().withId(44).withName(QStringLiteral("NoteCol2Child")).withParent(43).withNoteContent()); - - QString searchTerm(QStringLiteral("Col")); - - // WHEN - QScopedPointer queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Tasks | Akonadi::StorageInterface::Notes, - Akonadi::StorageInterface::Ptr(data.createStorage()), - Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer), - Akonadi::MonitorInterface::Ptr(data.createMonitor()))); - queries->setSearchTerm(searchTerm); - Domain::QueryResult::Ptr result = queries->findSearchTopLevel(); - bool replaceHandlerCalled = false; - result->addPostReplaceHandler([&replaceHandlerCalled](const Domain::DataSource::Ptr &, int) { - replaceHandlerCalled = true; - }); - TestHelpers::waitForEmptyJobQueue(); - QCOMPARE(result->data().size(), 2); - - // WHEN - data.modifyCollection(GenCollection(data.collection(43)).withName(QStringLiteral("NoteCol2Bis"))); - data.modifyCollection(GenCollection(data.collection(44)).withName(QStringLiteral("NoteCol2ChildBis"))); - - // THEN - QCOMPARE(result->data().size(), 2); - QCOMPARE(result->data().at(0)->name(), QStringLiteral("TaskCol1")); - QCOMPARE(result->data().at(1)->name(), QStringLiteral("NoteCol2Bis")); - QVERIFY(replaceHandlerCalled); - } - - void shouldNotCrashDuringFindSearchTopLevelWhenFetchJobFailedOrEmpty_data() - { - QTest::addColumn("colErrorCode"); - QTest::addColumn("colFetchBehavior"); - QTest::addColumn("deleteQuery"); - - QTest::newRow("No error with empty collection list") << int(KJob::NoError) << int(AkonadiFakeStorageBehavior::EmptyFetch) - << false; - - QTest::newRow("No error with empty collection list (+ query delete)") << int(KJob::NoError) << int(AkonadiFakeStorageBehavior::EmptyFetch) - << true; - - QTest::newRow("Error with empty collection list") << int(KJob::KilledJobError) << int(AkonadiFakeStorageBehavior::EmptyFetch) - << false; - - QTest::newRow("Error with empty collection list (+ query delete)") << int(KJob::KilledJobError) << int(AkonadiFakeStorageBehavior::EmptyFetch) - << true; - - QTest::newRow("Error with collection list") << int(KJob::KilledJobError) << int(AkonadiFakeStorageBehavior::NormalFetch) - << false; - - QTest::newRow("Error with collection list (+ query delete)") << int(KJob::KilledJobError) << int(AkonadiFakeStorageBehavior::NormalFetch) - << true; - } - - void shouldNotCrashDuringFindSearchTopLevelWhenFetchJobFailedOrEmpty() - { - // GIVEN - AkonadiFakeData data; - - // Two top level collections - data.createCollection(GenCollection().withId(42).withRootAsParent().withTaskContent()); - data.createCollection(GenCollection().withId(43).withRootAsParent().withNoteContent()); - - - auto storage = Akonadi::StorageInterface::Ptr(data.createStorage()); - auto serializer = Akonadi::Serializer::Ptr(new Akonadi::Serializer); - auto monitor = Akonadi::MonitorInterface::Ptr(data.createMonitor()); - - QScopedPointer queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Tasks | Akonadi::StorageInterface::Notes, - storage, - serializer, - monitor)); - - QFETCH(bool, deleteQuery); - QFETCH(int, colErrorCode); - QFETCH(int, colFetchBehavior); - data.storageBehavior().setFetchCollectionsErrorCode(Akonadi::Collection::root().id(), colErrorCode); - data.storageBehavior().setFetchCollectionsBehavior(Akonadi::Collection::root().id(), - AkonadiFakeStorageBehavior::FetchBehavior(colFetchBehavior)); - - // WHEN - Domain::QueryResult::Ptr result = queries->findSearchTopLevel(); - - if (deleteQuery) - delete queries.take(); - - // THEN - QVERIFY(result->data().isEmpty()); - TestHelpers::waitForEmptyJobQueue(); - QCOMPARE(result->data().size(), 0); - } - - void shouldNotStartJobDuringFindSearchTopLevelWhenSearchTermIsEmpty() - { - // GIVEN - AkonadiFakeData data; - - // one top level collection - data.createCollection(GenCollection().withId(42).withRootAsParent().withName(QStringLiteral("parent"))); - - // WHEN - QScopedPointer queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Tasks | Akonadi::StorageInterface::Notes, - Akonadi::StorageInterface::Ptr(data.createStorage()), - Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer), - Akonadi::MonitorInterface::Ptr(data.createMonitor()))); - - Domain::QueryResult::Ptr result = queries->findSearchTopLevel(); - result->data(); - result = queries->findSearchTopLevel(); // Should not cause any problem or wrong data - - // THEN - QVERIFY(result->data().isEmpty()); - QCOMPARE(Utils::JobHandler::jobCount(), 0); - } - - void shouldLookInAllReportedForSearchChildSources_data() - { - QTest::addColumn("contentTypes"); - QTest::addColumn("expectedColNames"); - QTest::addColumn("expectedTotoNames"); - - auto expectedColNames = QStringList(); - auto expectedTotoNames = QStringList(); - expectedColNames << QStringLiteral("NoteCol1"); - expectedTotoNames << QStringLiteral("TaskToto"); - QTest::newRow("tasks and notes") << int(Akonadi::StorageInterface::Tasks | Akonadi::StorageInterface::Notes) - << expectedColNames << expectedTotoNames; - - expectedColNames.clear(); - expectedTotoNames.clear(); - expectedColNames << QStringLiteral("NoteCol1"); - expectedTotoNames << QStringLiteral("TaskToto"); - QTest::newRow("tasks") << int(Akonadi::StorageInterface::Tasks) - << expectedColNames << expectedTotoNames; - - expectedColNames.clear(); - expectedTotoNames.clear(); - expectedColNames << QStringLiteral("NoteCol1"); - QTest::newRow("notes") << int(Akonadi::StorageInterface::Notes) - << expectedColNames << expectedTotoNames; - } - - void shouldLookInAllReportedForSearchChildSources() - { - // GIVEN - AkonadiFakeData data; - - // Two top level collections - data.createCollection(GenCollection().withId(42).withName(QStringLiteral("parent")).withRootAsParent().withTaskContent()); - data.createCollection(GenCollection().withId(46).withName(QStringLiteral("Col46")).withRootAsParent().withNoteContent()); - - // two child of parent - data.createCollection(GenCollection().withId(43).withName(QStringLiteral("NoteCol1")).withParent(42).withNoteContent()); - data.createCollection(GenCollection().withId(44).withName(QStringLiteral("TaskToto")).withParent(42).withTaskContent()); - data.createCollection(GenCollection().withId(47).withName(QStringLiteral("NoCol")).withParent(42)); - - // One child of the first child - data.createCollection(GenCollection().withId(45).withName(QStringLiteral("TaskCol43Child")).withParent(43).withTaskContent()); - - QString searchTerm(QStringLiteral("Col")); - - auto serializer = Akonadi::Serializer::Ptr(new Akonadi::Serializer); - Domain::DataSource::Ptr parentSource = serializer->createDataSourceFromCollection(data.collection(42), Akonadi::SerializerInterface::BaseName); - - // WHEN - QFETCH(int, contentTypes); - QScopedPointer queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::FetchContentTypes(contentTypes), - Akonadi::StorageInterface::Ptr(data.createStorage()), - serializer, - Akonadi::MonitorInterface::Ptr(data.createMonitor()))); - - queries->setSearchTerm(searchTerm); - Domain::QueryResult::Ptr result = queries->findSearchChildren(parentSource); - result->data(); - result = queries->findSearchChildren(parentSource); // Should not cause any problem or wrong data - - // THEN - QVERIFY(result->data().isEmpty()); - TestHelpers::waitForEmptyJobQueue(); - - auto sources = result->data(); - auto actualNames = QStringList(); - std::transform(sources.constBegin(), sources.constEnd(), - std::back_inserter(actualNames), - [] (const Domain::DataSource::Ptr &source) { return source->name(); }); - actualNames.sort(); - - QFETCH(QStringList, expectedColNames); - expectedColNames.sort(); - QCOMPARE(actualNames, expectedColNames); - - // WHEN - QString searchTerm2(QStringLiteral("toto")); - queries->setSearchTerm(searchTerm2); - - // THEN - TestHelpers::waitForEmptyJobQueue(); - - sources = result->data(); - actualNames.clear(); - std::transform(sources.constBegin(), sources.constEnd(), - std::back_inserter(actualNames), - [] (const Domain::DataSource::Ptr &source) { return source->name(); }); - actualNames.sort(); - - QFETCH(QStringList, expectedTotoNames); - expectedTotoNames.sort(); - QCOMPARE(actualNames, expectedTotoNames); - } - - void shouldReactToCollectionAddsForSearchChildSources() - { - // GIVEN - AkonadiFakeData data; - - // One top level collections - data.createCollection(GenCollection().withId(42).withName(QStringLiteral("Col1")).withRootAsParent().withTaskContent()); - - QString searchTerm(QStringLiteral("Col")); - - // Serializer - auto serializer = Akonadi::Serializer::Ptr(new Akonadi::Serializer); - Domain::DataSource::Ptr parentSource = serializer->createDataSourceFromCollection(data.collection(42), Akonadi::SerializerInterface::BaseName); - - QScopedPointer queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Tasks | Akonadi::StorageInterface::Notes, - Akonadi::StorageInterface::Ptr(data.createStorage()), - serializer, - Akonadi::MonitorInterface::Ptr(data.createMonitor()))); - - queries->setSearchTerm(searchTerm); - Domain::QueryResult::Ptr result = queries->findSearchChildren(parentSource); - TestHelpers::waitForEmptyJobQueue(); - QVERIFY(result->data().isEmpty()); - - // WHEN - data.createCollection(GenCollection().withId(43).withName(QStringLiteral("Col2")).withParent(42).withNoteContent()); - - // THEN - QCOMPARE(result->data().size(), 1); - QCOMPARE(result->data().first()->name(), QStringLiteral("Col2")); - } - - void shouldReactToCollectionRemovesForSearchChildSources() - { - // GIVEN - AkonadiFakeData data; - - // One top level collection - data.createCollection(GenCollection().withId(42).withName(QStringLiteral("parent")).withRootAsParent().withTaskContent()); - - // two children of parent - data.createCollection(GenCollection().withId(43).withName(QStringLiteral("NoteCol1")).withParent(42).withNoteContent()); - data.createCollection(GenCollection().withId(44).withName(QStringLiteral("TaskCol2")).withParent(42).withTaskContent()); - - QString searchTerm(QStringLiteral("Col")); - - auto serializer = Akonadi::Serializer::Ptr(new Akonadi::Serializer); - Domain::DataSource::Ptr parentSource = serializer->createDataSourceFromCollection(data.collection(42), Akonadi::SerializerInterface::BaseName); - - QScopedPointer queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Tasks | Akonadi::StorageInterface::Notes, - Akonadi::StorageInterface::Ptr(data.createStorage()), - serializer, - Akonadi::MonitorInterface::Ptr(data.createMonitor()))); - - queries->setSearchTerm(searchTerm); - Domain::QueryResult::Ptr result = queries->findSearchChildren(parentSource); - TestHelpers::waitForEmptyJobQueue(); - QCOMPARE(result->data().size(), 2); - - // WHEN - data.removeCollection(Akonadi::Collection(43)); - - // THEN - QCOMPARE(result->data().size(), 1); - QCOMPARE(result->data().first()->name(), QStringLiteral("TaskCol2")); - } - - void shouldReactToCollectionChangesForSearchChildSources() - { - // GIVEN - AkonadiFakeData data; - - // One top level collection - data.createCollection(GenCollection().withId(42).withName(QStringLiteral("parent")).withRootAsParent().withTaskContent()); - - // two children - data.createCollection(GenCollection().withId(43).withName(QStringLiteral("NoteCol1")).withParent(42).withNoteContent()); - data.createCollection(GenCollection().withId(44).withName(QStringLiteral("TaskCol2")).withParent(42).withTaskContent()); - - QString searchTerm(QStringLiteral("Col")); - - auto serializer = Akonadi::Serializer::Ptr(new Akonadi::Serializer); - Domain::DataSource::Ptr parentSource = serializer->createDataSourceFromCollection(data.collection(42), Akonadi::SerializerInterface::BaseName); - - // WHEN - QScopedPointer queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Tasks | Akonadi::StorageInterface::Notes, - Akonadi::StorageInterface::Ptr(data.createStorage()), - serializer, - Akonadi::MonitorInterface::Ptr(data.createMonitor()))); - queries->setSearchTerm(searchTerm); - Domain::QueryResult::Ptr result = queries->findSearchChildren(parentSource); - bool replaceHandlerCalled = false; - result->addPostReplaceHandler([&replaceHandlerCalled](const Domain::DataSource::Ptr &, int) { - replaceHandlerCalled = true; - }); - - TestHelpers::waitForEmptyJobQueue(); - QCOMPARE(result->data().size(), 2); - - // WHEN - data.modifyCollection(GenCollection(data.collection(43)).withName(QStringLiteral("NoteCol1Bis"))); - - // THEN - QCOMPARE(result->data().size(), 2); - QCOMPARE(result->data().at(0)->name(), QStringLiteral("NoteCol1Bis")); - QCOMPARE(result->data().at(1)->name(), QStringLiteral("TaskCol2")); - QVERIFY(replaceHandlerCalled); - } - - void shouldNotCrashDuringFindSearchChildrenWhenFetchJobFailedOrEmpty_data() - { - QTest::addColumn("colErrorCode"); - QTest::addColumn("colFetchBehavior"); - QTest::addColumn("deleteQuery"); - - QTest::newRow("No error with empty collection list") << int(KJob::NoError) << int(AkonadiFakeStorageBehavior::EmptyFetch) - << false; - - QTest::newRow("No error with empty collection list (+ query delete)") << int(KJob::NoError) << int(AkonadiFakeStorageBehavior::EmptyFetch) - << true; - - QTest::newRow("Error with empty collection list") << int(KJob::KilledJobError) << int(AkonadiFakeStorageBehavior::EmptyFetch) - << false; - - QTest::newRow("Error with empty collection list (+ query delete)") << int(KJob::KilledJobError) << int(AkonadiFakeStorageBehavior::EmptyFetch) - << true; - - QTest::newRow("Error with collection list") << int(KJob::KilledJobError) << int(AkonadiFakeStorageBehavior::NormalFetch) - << false; - - QTest::newRow("Error with collection list (+ query delete)") << int(KJob::KilledJobError) << int(AkonadiFakeStorageBehavior::NormalFetch) - << true; - } - - void shouldNotCrashDuringFindSearchChildrenWhenFetchJobFailedOrEmpty() - { - // GIVEN - AkonadiFakeData data; - - // One top level collection with two children - data.createCollection(GenCollection().withId(42).withName(QStringLiteral("parent")).withRootAsParent().withTaskContent()); - data.createCollection(GenCollection().withId(43).withName(QStringLiteral("TaskChild")).withParent(42).withTaskContent()); - data.createCollection(GenCollection().withId(44).withName(QStringLiteral("TaskChild")).withParent(42).withNoteContent()); - - auto serializer = Akonadi::Serializer::Ptr(new Akonadi::Serializer); - Domain::DataSource::Ptr parentSource = serializer->createDataSourceFromCollection(data.collection(42), Akonadi::SerializerInterface::BaseName); - - QFETCH(bool, deleteQuery); - QFETCH(int, colErrorCode); - QFETCH(int, colFetchBehavior); - data.storageBehavior().setFetchCollectionsErrorCode(data.collection(42).id(), colErrorCode); - data.storageBehavior().setFetchCollectionsBehavior(data.collection(42).id(), - AkonadiFakeStorageBehavior::FetchBehavior(colFetchBehavior)); - - QScopedPointer queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Tasks | Akonadi::StorageInterface::Notes, - Akonadi::StorageInterface::Ptr(data.createStorage()), - serializer, - Akonadi::MonitorInterface::Ptr(data.createMonitor()))); - - Domain::QueryResult::Ptr result = queries->findSearchChildren(parentSource); - - if (deleteQuery) - delete queries.take(); - - // THEN - QVERIFY(result->data().isEmpty()); - TestHelpers::waitForEmptyJobQueue(); - QCOMPARE(result->data().size(), 0); - } - - void shouldNotStartJobDuringFindSearchChildrenWhenSearchTermIsEmpty() - { - // GIVEN - AkonadiFakeData data; - - // One top level collection and its child - data.createCollection(GenCollection().withId(42).withName(QStringLiteral("parent")).withRootAsParent().withTaskContent()); - data.createCollection(GenCollection().withId(43).withName(QStringLiteral("child")).withParent(42).withTaskContent()); - - auto serializer = Akonadi::Serializer::Ptr(new Akonadi::Serializer); - Domain::DataSource::Ptr parentSource = serializer->createDataSourceFromCollection(data.collection(42), Akonadi::SerializerInterface::BaseName); - - // WHEN - QScopedPointer queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Tasks | Akonadi::StorageInterface::Notes, - Akonadi::StorageInterface::Ptr(data.createStorage()), - serializer, - Akonadi::MonitorInterface::Ptr(data.createMonitor()))); - - Domain::QueryResult::Ptr result = queries->findSearchChildren(parentSource); - - // THEN - QVERIFY(result->data().isEmpty()); - TestHelpers::waitForEmptyJobQueue(); - - QVERIFY(result->data().isEmpty()); - } }; ZANSHIN_TEST_MAIN(AkonadiDataSourceQueriesTest) diff --git a/tests/units/akonadi/akonadilivequeryhelperstest.cpp b/tests/units/akonadi/akonadilivequeryhelperstest.cpp --- a/tests/units/akonadi/akonadilivequeryhelperstest.cpp +++ b/tests/units/akonadi/akonadilivequeryhelperstest.cpp @@ -292,240 +292,6 @@ QCOMPARE(result, expected); } - void shouldSearchCollectionsForRootAndTerm_data() - { - QTest::addColumn("root"); - - QTest::newRow("search from root") << Akonadi::Collection::root(); - QTest::newRow("search from no content branch") << Akonadi::Collection(42); - QTest::newRow("search from in branch") << Akonadi::Collection(43); - QTest::newRow("search from ex branch") << Akonadi::Collection(44); - } - - void shouldSearchCollectionsForRootAndTerm() - { - // GIVEN - auto data = AkonadiFakeData(); - auto helpers = createHelpers(data); - - // Three top level collections (any content, tasks and notes) - data.createCollection(GenCollection().withId(42).withRootAsParent().withName(QStringLiteral("42in"))); - data.createCollection(GenCollection().withId(43).withRootAsParent().withName(QStringLiteral("43in")).withTaskContent()); - data.createCollection(GenCollection().withId(44).withRootAsParent().withName(QStringLiteral("44ex")).withNoteContent()); - - // Three children under each of the top level for each content type - data.createCollection(GenCollection().withId(45).withParent(42).withName(QStringLiteral("45in"))); - data.createCollection(GenCollection().withId(46).withParent(42).withName(QStringLiteral("46in")).withNoteContent()); - data.createCollection(GenCollection().withId(47).withParent(42).withName(QStringLiteral("47ex")).withTaskContent()); - data.createCollection(GenCollection().withId(48).withParent(43).withName(QStringLiteral("48in"))); - data.createCollection(GenCollection().withId(49).withParent(43).withName(QStringLiteral("49in")).withTaskContent()); - data.createCollection(GenCollection().withId(50).withParent(43).withName(QStringLiteral("50ex")).withNoteContent()); - data.createCollection(GenCollection().withId(51).withParent(44).withName(QStringLiteral("51in"))); - data.createCollection(GenCollection().withId(52).withParent(44).withName(QStringLiteral("52in")).withTaskContent()); - data.createCollection(GenCollection().withId(53).withParent(44).withName(QStringLiteral("53ex")).withNoteContent()); - - // The list which will be filled by the fetch function - auto collections = Akonadi::Collection::List(); - auto add = [&collections] (const Akonadi::Collection &collection) { - collections.append(collection); - }; - - // WHEN (no search term) - QFETCH(Akonadi::Collection, root); - auto term = QString(); - auto fetch = helpers->searchCollections(root, &term, Akonadi::StorageInterface::Tasks | Akonadi::StorageInterface::Notes); - fetch(add); - TestHelpers::waitForEmptyJobQueue(); - - auto result = QStringList(); - std::transform(collections.constBegin(), collections.constEnd(), - std::back_inserter(result), - std::bind(&Akonadi::Collection::displayName, _1)); - result.sort(); - - // THEN - auto expected = QStringList(); - QCOMPARE(result, expected); - - - // WHEN ("in" search term) - collections.clear(); - result.clear(); - expected.clear(); - - term = QStringLiteral("in"); - fetch(add); - TestHelpers::waitForEmptyJobQueue(); - - std::transform(collections.constBegin(), collections.constEnd(), - std::back_inserter(result), - std::bind(&Akonadi::Collection::displayName, _1)); - result.sort(); - - // THEN - if (root == Akonadi::Collection::root()) { - expected << QStringLiteral("42in") << QStringLiteral("43in") << QStringLiteral("44ex"); - } else { - switch (root.id()) { - case 42: - expected << QStringLiteral("46in"); - break; - case 43: - expected << QStringLiteral("49in"); - break; - case 44: - expected << QStringLiteral("52in"); - break; - } - - QVERIFY(!expected.isEmpty()); - } - - expected.sort(); - QCOMPARE(result, expected); - - - // WHEN ("ex" search term) - collections.clear(); - result.clear(); - expected.clear(); - - term = QStringLiteral("ex"); - fetch(add); - TestHelpers::waitForEmptyJobQueue(); - - std::transform(collections.constBegin(), collections.constEnd(), - std::back_inserter(result), - std::bind(&Akonadi::Collection::displayName, _1)); - result.sort(); - - // THEN - if (root == Akonadi::Collection::root()) { - expected << QStringLiteral("42in") << QStringLiteral("43in") << QStringLiteral("44ex"); - } else { - switch (root.id()) { - case 42: - expected << QStringLiteral("47ex"); - break; - case 43: - expected << QStringLiteral("50ex"); - break; - case 44: - expected << QStringLiteral("53ex"); - break; - } - - QVERIFY(!expected.isEmpty()); - } - - expected.sort(); - QCOMPARE(result, expected); - - // WHEN (should not crash when the helpers object is deleted) - helpers.clear(); - collections.clear(); - fetch(add); - TestHelpers::waitForEmptyJobQueue(); - - // THEN - result.clear(); - std::transform(collections.constBegin(), collections.constEnd(), - std::back_inserter(result), - std::bind(&Akonadi::Collection::displayName, _1)); - result.sort(); - QCOMPARE(result, expected); - } - - void shouldSearchCollectionsForContentTypes_data() - { - QTest::addColumn("contentTypes"); - QTest::addColumn("expected"); - - auto expected = QStringList(); - expected << QStringLiteral("42-foo-all") << QStringLiteral("43-foo-task") << QStringLiteral("44-foo-note"); - QTest::newRow("all") << int(Akonadi::StorageInterface::AllContent) << expected; - - expected.clear(); - expected << QStringLiteral("43-foo-task") << QStringLiteral("44-foo-note"); - QTest::newRow("task + note") << int(Akonadi::StorageInterface::Tasks | Akonadi::StorageInterface::Notes) << expected; - - expected.clear(); - expected << QStringLiteral("43-foo-task"); - QTest::newRow("task") << int(Akonadi::StorageInterface::Tasks) << expected; - - expected.clear(); - expected << QStringLiteral("44-foo-note"); - QTest::newRow("note") << int(Akonadi::StorageInterface::Notes) << expected; - } - - void shouldSearchCollectionsForContentTypes() - { - // GIVEN - auto data = AkonadiFakeData(); - auto helpers = createHelpers(data); - - // Three top level collections (any content, tasks and notes) - data.createCollection(GenCollection().withId(42).withRootAsParent().withName(QStringLiteral("42-foo-all"))); - data.createCollection(GenCollection().withId(43).withRootAsParent().withName(QStringLiteral("43-foo-task")).withTaskContent()); - data.createCollection(GenCollection().withId(44).withRootAsParent().withName(QStringLiteral("44-foo-note")).withNoteContent()); - - // The list which will be filled by the fetch function - auto collections = Akonadi::Collection::List(); - auto add = [&collections] (const Akonadi::Collection &collection) { - collections.append(collection); - }; - - // WHEN (no search term) - QFETCH(int, contentTypes); - auto term = QString(); - auto fetch = helpers->searchCollections(Akonadi::Collection::root(), &term, - Akonadi::StorageInterface::FetchContentTypes(contentTypes)); - fetch(add); - TestHelpers::waitForEmptyJobQueue(); - - auto result = QStringList(); - std::transform(collections.constBegin(), collections.constEnd(), - std::back_inserter(result), - std::bind(&Akonadi::Collection::displayName, _1)); - result.sort(); - - // THEN - QCOMPARE(result, QStringList()); - - - // WHEN ("foo" search term) - collections.clear(); - result.clear(); - - term = QStringLiteral("foo"); - fetch(add); - TestHelpers::waitForEmptyJobQueue(); - - std::transform(collections.constBegin(), collections.constEnd(), - std::back_inserter(result), - std::bind(&Akonadi::Collection::displayName, _1)); - result.sort(); - - // THEN - QFETCH(QStringList, expected); - expected.sort(); - QCOMPARE(result, expected); - - // WHEN (should not crash when the helpers object is deleted) - helpers.clear(); - collections.clear(); - fetch(add); - TestHelpers::waitForEmptyJobQueue(); - - // THEN - result.clear(); - std::transform(collections.constBegin(), collections.constEnd(), - std::back_inserter(result), - std::bind(&Akonadi::Collection::displayName, _1)); - result.sort(); - QCOMPARE(result, expected); - } - void shouldFetchItemsByContentTypes_data() { QTest::addColumn("contentTypes"); diff --git a/tests/units/akonadi/akonadinotequeriestest.cpp b/tests/units/akonadi/akonadinotequeriestest.cpp --- a/tests/units/akonadi/akonadinotequeriestest.cpp +++ b/tests/units/akonadi/akonadinotequeriestest.cpp @@ -204,7 +204,7 @@ // Three top level collections data.createCollection(GenCollection().withId(42).withRootAsParent().withNoteContent()); data.createCollection(GenCollection().withId(43).withRootAsParent().withNoteContent()); - data.createCollection(GenCollection().withId(44).withRootAsParent().withNoteContent().enabled(false)); + data.createCollection(GenCollection().withId(44).withRootAsParent().withNoteContent().selected(false)); // One note in the first collection data.createItem(GenNote().withId(42).withParent(42).withTitle(QStringLiteral("42"))); diff --git a/tests/units/akonadi/akonadiserializertest.cpp b/tests/units/akonadi/akonadiserializertest.cpp --- a/tests/units/akonadi/akonadiserializertest.cpp +++ b/tests/units/akonadi/akonadiserializertest.cpp @@ -139,30 +139,23 @@ QTest::addColumn("mimeTypes"); QTest::addColumn("hasSelectedAttribute"); QTest::addColumn("isSelected"); - QTest::addColumn("isReferenced"); - QTest::addColumn("isEnabled"); const auto noteMimeTypes = QStringList() << QStringLiteral("text/x-vnd.akonadi.note"); const auto taskMimeTypes = QStringList() << QStringLiteral("application/x-vnd.akonadi.calendar.todo"); const auto bogusMimeTypes = QStringList() << QStringLiteral("foo/bar"); const auto allMimeTypes = noteMimeTypes + taskMimeTypes + bogusMimeTypes; - QTest::newRow("nominal case") << "name" << "icon" << allMimeTypes << true << false << false << true; + QTest::newRow("nominal case") << "name" << "icon" << allMimeTypes << true << false; - QTest::newRow("only notes") << "name" << "icon" << noteMimeTypes << true << false << false << true; - QTest::newRow("only tasks") << "name" << "icon" << taskMimeTypes << true << false << false << true; - QTest::newRow("only bogus") << "name" << "icon" << bogusMimeTypes << true << false << false << true; + QTest::newRow("only notes") << "name" << "icon" << noteMimeTypes << true << false; + QTest::newRow("only tasks") << "name" << "icon" << taskMimeTypes << true << false; + QTest::newRow("only bogus") << "name" << "icon" << bogusMimeTypes << true << false; - QTest::newRow("no selected attribute") << "name" << "icon" << allMimeTypes << false << false << false << true; - QTest::newRow("selected attribute (false)") << "name" << "icon" << allMimeTypes << true << false << false << true; - QTest::newRow("selected attribute (true)") << "name" << "icon" << allMimeTypes << true << true << false << true; + QTest::newRow("no selected attribute") << "name" << "icon" << allMimeTypes << false << false; + QTest::newRow("selected attribute (false)") << "name" << "icon" << allMimeTypes << true << false; + QTest::newRow("selected attribute (true)") << "name" << "icon" << allMimeTypes << true << true; - QTest::newRow("enabled and referenced") << "name" << "icon" << allMimeTypes << true << false << true << true; - QTest::newRow("enabled and !referenced") << "name" << "icon" << allMimeTypes << true << false << true << false; - QTest::newRow("!enabled and referenced") << "name" << "icon" << allMimeTypes << true << false << false << true; - QTest::newRow("!enabled and !referenced") << "name" << "icon" << allMimeTypes << true << false << false << false; - - QTest::newRow("empty case") << QString() << QString() << QStringList() << false << false << false << true; + QTest::newRow("empty case") << QString() << QString() << QStringList() << false << false; } void shouldCreateDataSourceFromCollection() @@ -175,8 +168,6 @@ QFETCH(QStringList, mimeTypes); QFETCH(bool, hasSelectedAttribute); QFETCH(bool, isSelected); - QFETCH(bool, isReferenced); - QFETCH(bool, isEnabled); Domain::DataSource::ContentTypes expectedContentTypes; if (mimeTypes.contains(QStringLiteral("text/x-vnd.akonadi.note"))) { @@ -190,8 +181,6 @@ Akonadi::Collection collection(42); collection.setContentMimeTypes(mimeTypes); collection.setName(name); - collection.setReferenced(isReferenced); - collection.setEnabled(isEnabled); auto displayAttribute = new Akonadi::EntityDisplayAttribute; displayAttribute->setIconName(iconName); collection.addAttribute(displayAttribute); @@ -211,8 +200,6 @@ QCOMPARE(dataSource->contentTypes(), expectedContentTypes); QCOMPARE(dataSource->isSelected(), !hasSelectedAttribute || isSelected); QCOMPARE(dataSource->property("collectionId").value(), collection.id()); - QCOMPARE((dataSource->listStatus() & Domain::DataSource::Listed) != 0, isReferenced || isEnabled); - QCOMPARE((dataSource->listStatus() == Domain::DataSource::Bookmarked), isEnabled); } void shouldCreateNullDataSourceFromInvalidCollection() @@ -329,31 +316,22 @@ QTest::addColumn("iconName"); QTest::addColumn("contentTypes"); QTest::addColumn("isSelected"); - QTest::addColumn("listStatus"); const auto noType = Domain::DataSource::ContentTypes(Domain::DataSource::NoContent); const auto taskType = Domain::DataSource::ContentTypes(Domain::DataSource::Tasks); const auto noteType = Domain::DataSource::ContentTypes(Domain::DataSource::Notes); const auto allTypes = taskType | noteType; - const auto unlisted = Domain::DataSource::Unlisted; - const auto listed = Domain::DataSource::Listed; - const auto bookmarked = Domain::DataSource::Bookmarked; - - QTest::newRow("nominal case") << "name" << "icon-name" << allTypes << true << unlisted; - - QTest::newRow("only notes") << "name" << "icon-name" << noteType << true << unlisted; - QTest::newRow("only tasks") << "name" << "icon-name" << taskType << true << unlisted; - QTest::newRow("only nothing ;)") << "name" << "icon-name" << noType << true << unlisted; + QTest::newRow("nominal case") << "name" << "icon-name" << allTypes << true; - QTest::newRow("not selected") << "name" << "icon-name" << allTypes << false << unlisted; - QTest::newRow("selected") << "name" << "icon-name" << allTypes << true << unlisted; + QTest::newRow("only notes") << "name" << "icon-name" << noteType << true; + QTest::newRow("only tasks") << "name" << "icon-name" << taskType << true; + QTest::newRow("only nothing ;)") << "name" << "icon-name" << noType << true; - QTest::newRow("unlisted") << "name" << "icon-name" << allTypes << true << unlisted; - QTest::newRow("listed") << "name" << "icon-name" << allTypes << true << listed; - QTest::newRow("bookmarked") << "name" << "icon-name" << allTypes << true << bookmarked; + QTest::newRow("not selected") << "name" << "icon-name" << allTypes << false; + QTest::newRow("selected") << "name" << "icon-name" << allTypes << true; - QTest::newRow("empty case") << QString() << QString() << noType << true << unlisted; + QTest::newRow("empty case") << QString() << QString() << noType << true; } void shouldCreateCollectionFromDataSource() @@ -366,7 +344,6 @@ QFETCH(QString, iconName); QFETCH(Domain::DataSource::ContentTypes, contentTypes); QFETCH(bool, isSelected); - QFETCH(Domain::DataSource::ListStatus, listStatus); QStringList mimeTypes; if (contentTypes & Domain::DataSource::Tasks) @@ -380,7 +357,6 @@ source->setName(name); source->setIconName(iconName); source->setContentTypes(contentTypes); - source->setListStatus(listStatus); source->setSelected(isSelected); source->setProperty("collectionId", 42); @@ -394,105 +370,43 @@ QCOMPARE(collection.attribute()->isSelected(), isSelected); QVERIFY(collection.hasAttribute()); QVERIFY(collection.attribute()->timestamp() >= timestamp); - - switch (listStatus) { - case Domain::DataSource::Unlisted: - QVERIFY(!collection.referenced()); - QVERIFY(!collection.enabled()); - break; - case Domain::DataSource::Listed: - QVERIFY(collection.referenced()); - QVERIFY(!collection.enabled()); - break; - case Domain::DataSource::Bookmarked: - QVERIFY(collection.enabled()); - break; - default: - qFatal("Shouldn't happen"); - break; - } - } - - void shouldVerifyIfCollectionIsListed_data() - { - QTest::addColumn("isEnabled"); - QTest::addColumn("isReferenced"); - QTest::addColumn("expectedListed"); - - QTest::newRow("enabled and referenced") << true << true << true; - QTest::newRow("enabled and !referenced") << true << false << true; - QTest::newRow("!enabled and referenced") << false << true << true; - QTest::newRow("!enabled and !referenced") << false << false << false; - } - - void shouldVerifyIfCollectionIsListed() - { - // GIVEN - QFETCH(bool, isEnabled); - QFETCH(bool, isReferenced); - - // ... stored in a collection - Akonadi::Collection collection(42); - collection.setReferenced(isReferenced); - collection.setEnabled(isEnabled); - - // WHEN - Akonadi::Serializer serializer; - - // THEN - QFETCH(bool, expectedListed); - QCOMPARE(serializer.isListedCollection(collection), expectedListed); } void shouldVerifyIfCollectionIsSelected_data() { QTest::addColumn("mimeTypes"); QTest::addColumn("hasSelectedAttribute"); QTest::addColumn("isSelected"); - QTest::addColumn("isReferenced"); - QTest::addColumn("isEnabled"); QTest::addColumn("expectedSelected"); const auto noteMimeTypes = QStringList() << QStringLiteral("text/x-vnd.akonadi.note"); const auto taskMimeTypes = QStringList() << QStringLiteral("application/x-vnd.akonadi.calendar.todo"); const auto bogusMimeTypes = QStringList() << QStringLiteral("foo/bar"); const auto allMimeTypes = noteMimeTypes + taskMimeTypes + bogusMimeTypes; - QTest::newRow("nominal case") << allMimeTypes << true << false << false << true << false; - - QTest::newRow("only notes") << noteMimeTypes << true << false << false << true << false; - QTest::newRow("only tasks") << taskMimeTypes << true << false << false << true << false; - QTest::newRow("only bogus") << bogusMimeTypes << true << false << false << true << false; - - QTest::newRow("selected, only notes") << noteMimeTypes << true << true << false << true << true; - QTest::newRow("selected, only tasks") << taskMimeTypes << true << true << false << true << true; - QTest::newRow("selected, only bogus") << bogusMimeTypes << true << true << false << true << false; + QTest::newRow("nominal case") << allMimeTypes << true << false << false; - QTest::newRow("no selected attribute") << allMimeTypes << false << false << false << true << true; - QTest::newRow("selected attribute (false)") << allMimeTypes << true << false << false << true << false; - QTest::newRow("selected attribute (true)") << allMimeTypes << true << true << false << true << true; + QTest::newRow("only notes") << noteMimeTypes << true << false << false; + QTest::newRow("only tasks") << taskMimeTypes << true << false << false; + QTest::newRow("only bogus") << bogusMimeTypes << true << false << false; - QTest::newRow("enabled and referenced") << allMimeTypes << true << false << true << true << false; - QTest::newRow("enabled and !referenced") << allMimeTypes << true << false << true << false << false; - QTest::newRow("!enabled and referenced") << allMimeTypes << true << false << false << true << false; - QTest::newRow("!enabled and !referenced") << allMimeTypes << true << false << false << false << false; + QTest::newRow("selected, only notes") << noteMimeTypes << true << true << true; + QTest::newRow("selected, only tasks") << taskMimeTypes << true << true << true; + QTest::newRow("selected, only bogus") << bogusMimeTypes << true << true << false; - QTest::newRow("selected, enabled and referenced") << allMimeTypes << true << true << true << true << true; - QTest::newRow("selected, enabled and !referenced") << allMimeTypes << true << true << true << false << true; - QTest::newRow("selected, !enabled and referenced") << allMimeTypes << true << true << false << true << true; - QTest::newRow("selected, !enabled and !referenced") << allMimeTypes << true << true << false << false << false; + QTest::newRow("no selected attribute") << allMimeTypes << false << false << true; + QTest::newRow("selected attribute (false)") << allMimeTypes << true << false << false; + QTest::newRow("selected attribute (true)") << allMimeTypes << true << true << true; - QTest::newRow("empty case") << QStringList() << false << false << false << true << false; + QTest::newRow("empty case") << QStringList() << false << false << false; } void shouldVerifyIfCollectionIsSelected() { // GIVEN QFETCH(QStringList, mimeTypes); QFETCH(bool, hasSelectedAttribute); QFETCH(bool, isSelected); - QFETCH(bool, isReferenced); - QFETCH(bool, isEnabled); Domain::DataSource::ContentTypes expectedContentTypes; if (mimeTypes.contains(QStringLiteral("text/x-vnd.akonadi.note"))) { @@ -505,8 +419,6 @@ // ... stored in a collection Akonadi::Collection collection(42); collection.setContentMimeTypes(mimeTypes); - collection.setReferenced(isReferenced); - collection.setEnabled(isEnabled); if (hasSelectedAttribute) { auto selectedAttribute = new Akonadi::ApplicationSelectedAttribute; selectedAttribute->setSelected(isSelected); diff --git a/tests/units/akonadi/akonaditaskqueriestest.cpp b/tests/units/akonadi/akonaditaskqueriestest.cpp --- a/tests/units/akonadi/akonaditaskqueriestest.cpp +++ b/tests/units/akonadi/akonaditaskqueriestest.cpp @@ -1042,7 +1042,7 @@ // Three top level collections data.createCollection(GenCollection().withId(42).withRootAsParent().withNoteContent()); data.createCollection(GenCollection().withId(43).withRootAsParent().withTaskContent()); - data.createCollection(GenCollection().withId(44).withRootAsParent().withTaskContent().enabled(false)); + data.createCollection(GenCollection().withId(44).withRootAsParent().withTaskContent().selected(false)); // One note in the first collection data.createItem(GenNote().withId(42).withParent(42).withTitle(QStringLiteral("42"))); diff --git a/tests/units/domain/datasourcetest.cpp b/tests/units/domain/datasourcetest.cpp --- a/tests/units/domain/datasourcetest.cpp +++ b/tests/units/domain/datasourcetest.cpp @@ -35,7 +35,6 @@ : QObject(parent) { qRegisterMetaType(); - qRegisterMetaType(); } private slots: @@ -45,7 +44,6 @@ QCOMPARE(ds.name(), QString()); QCOMPARE(ds.iconName(), QString()); QCOMPARE(ds.contentTypes(), DataSource::NoContent); - QCOMPARE(ds.listStatus(), DataSource::Unlisted); QVERIFY(!ds.isSelected()); } @@ -121,24 +119,6 @@ ds.setSelected(true); QCOMPARE(spy.count(), 0); } - - void shouldNotifyListStatusChanges() - { - DataSource ds; - QSignalSpy spy(&ds, &DataSource::listStatusChanged); - ds.setListStatus(DataSource::Bookmarked); - QCOMPARE(spy.count(), 1); - QCOMPARE(spy.first().first().value(), DataSource::Bookmarked); - } - - void shouldNotNotifyIdenticalListStatusChanges() - { - DataSource ds; - ds.setListStatus(DataSource::Bookmarked); - QSignalSpy spy(&ds, &DataSource::listStatusChanged); - ds.setListStatus(DataSource::Bookmarked); - QCOMPARE(spy.count(), 0); - } }; ZANSHIN_TEST_MAIN(DataSourceTest) diff --git a/tests/units/presentation/availablesourcesmodeltest.cpp b/tests/units/presentation/availablesourcesmodeltest.cpp --- a/tests/units/presentation/availablesourcesmodeltest.cpp +++ b/tests/units/presentation/availablesourcesmodeltest.cpp @@ -212,310 +212,6 @@ QVERIFY(sourceQueriesMock(&Domain::DataSourceQueries::changeDefaultSource).when(source4).exactly(1)); } - void shouldListAvailableSearchSources() - { - // GIVEN - - // Two top level sources - auto source1 = Domain::DataSource::Ptr::create(); - source1->setName(QStringLiteral("Source 1")); - source1->setIconName(QStringLiteral("foo-icon")); - source1->setSelected(true); - auto source2 = Domain::DataSource::Ptr::create(); - source2->setName(QStringLiteral("Source 2")); - source2->setSelected(false); - source2->setContentTypes(Domain::DataSource::Tasks); - auto topLevelProvider = Domain::QueryResultProvider::Ptr::create(); - auto topLevelResult = Domain::QueryResult::create(topLevelProvider); - topLevelProvider->append(source1); - topLevelProvider->append(source2); - - // Two other sources under source1 - auto source3 = Domain::DataSource::Ptr::create(); - source3->setName(QStringLiteral("Source 3")); - source3->setSelected(false); - source3->setContentTypes(Domain::DataSource::Notes); - auto source4 = Domain::DataSource::Ptr::create(); - source4->setSelected(true); - source4->setName(QStringLiteral("Source 4")); - source4->setContentTypes(Domain::DataSource::Notes | Domain::DataSource::Tasks); - auto source1Provider = Domain::QueryResultProvider::Ptr::create(); - auto source1Result = Domain::QueryResult::create(source1Provider); - source1Provider->append(source3); - source1Provider->append(source4); - - // Nothing under source2, source3 or source4 - auto source2Provider = Domain::QueryResultProvider::Ptr::create(); - auto source2Result = Domain::QueryResult::create(source2Provider); - auto source3Provider = Domain::QueryResultProvider::Ptr::create(); - auto source3Result = Domain::QueryResult::create(source3Provider); - auto source4Provider = Domain::QueryResultProvider::Ptr::create(); - auto source4Result = Domain::QueryResult::create(source4Provider); - - Utils::MockObject sourceQueriesMock; - sourceQueriesMock(&Domain::DataSourceQueries::findSearchTopLevel).when().thenReturn(topLevelResult); - sourceQueriesMock(&Domain::DataSourceQueries::findSearchChildren).when(source1).thenReturn(source1Result); - sourceQueriesMock(&Domain::DataSourceQueries::findSearchChildren).when(source2).thenReturn(source2Result); - sourceQueriesMock(&Domain::DataSourceQueries::findSearchChildren).when(source3).thenReturn(source3Result); - sourceQueriesMock(&Domain::DataSourceQueries::findSearchChildren).when(source4).thenReturn(source4Result); - - Utils::MockObject sourceRepositoryMock; - - Presentation::AvailableSourcesModel sources(sourceQueriesMock.getInstance(), - sourceRepositoryMock.getInstance(), - Q_NULLPTR); - - // WHEN - QAbstractItemModel *model = sources.searchListModel(); - - // THEN - const QModelIndex source1Index = model->index(0, 0); - const QModelIndex source2Index = model->index(1, 0); - const QModelIndex source3Index = model->index(0, 0, source1Index); - const QModelIndex source4Index = model->index(1, 0, source1Index); - - QCOMPARE(model->rowCount(), 2); - QCOMPARE(model->rowCount(source1Index), 2); - QCOMPARE(model->rowCount(source2Index), 0); - QCOMPARE(model->rowCount(source3Index), 0); - QCOMPARE(model->rowCount(source4Index), 0); - - const Qt::ItemFlags defaultFlags = Qt::ItemIsSelectable - | Qt::ItemIsEnabled; - QCOMPARE(model->flags(source1Index), defaultFlags); - QCOMPARE(model->flags(source2Index), defaultFlags); - QCOMPARE(model->flags(source3Index), defaultFlags); - QCOMPARE(model->flags(source4Index), defaultFlags); - - QCOMPARE(model->data(source1Index).toString(), source1->name()); - QCOMPARE(model->data(source2Index).toString(), source2->name()); - QCOMPARE(model->data(source3Index).toString(), source3->name()); - QCOMPARE(model->data(source4Index).toString(), source4->name()); - - QCOMPARE(model->data(source1Index, Qt::EditRole).toString(), source1->name()); - QCOMPARE(model->data(source2Index, Qt::EditRole).toString(), source2->name()); - QCOMPARE(model->data(source3Index, Qt::EditRole).toString(), source3->name()); - QCOMPARE(model->data(source4Index, Qt::EditRole).toString(), source4->name()); - - QVERIFY(!model->data(source1Index, Qt::CheckStateRole).isValid()); - QVERIFY(!model->data(source2Index, Qt::CheckStateRole).isValid()); - QVERIFY(!model->data(source3Index, Qt::CheckStateRole).isValid()); - QVERIFY(!model->data(source4Index, Qt::CheckStateRole).isValid()); - - QCOMPARE(model->data(source1Index, Presentation::QueryTreeModelBase::IconNameRole).toString(), source1->iconName()); - QCOMPARE(model->data(source2Index, Presentation::QueryTreeModelBase::IconNameRole).toString(), QStringLiteral("folder")); - QCOMPARE(model->data(source3Index, Presentation::QueryTreeModelBase::IconNameRole).toString(), QStringLiteral("folder")); - QCOMPARE(model->data(source4Index, Presentation::QueryTreeModelBase::IconNameRole).toString(), QStringLiteral("folder")); - - QVERIFY(!model->setData(source1Index, Qt::Unchecked, Qt::CheckStateRole)); - QVERIFY(!model->setData(source2Index, Qt::Checked, Qt::CheckStateRole)); - QVERIFY(!model->setData(source4Index, Qt::Unchecked, Qt::CheckStateRole)); - } - - void shouldChangeSourceToListed() - { - // GIVEN - - auto source = Domain::DataSource::Ptr::create(); - source->setName(QStringLiteral("Source")); - source->setIconName(QStringLiteral("folder")); - source->setContentTypes(Domain::DataSource::Tasks); - source->setSelected(false); - source->setListStatus(Domain::DataSource::Unlisted); - - - Utils::MockObject sourceQueriesMock; - - Utils::MockObject sourceRepositoryMock; - sourceRepositoryMock(&Domain::DataSourceRepository::update).when(source).thenReturn(new FakeJob(this)); - - Presentation::AvailableSourcesModel sources(sourceQueriesMock.getInstance(), - sourceRepositoryMock.getInstance()); - - // WHEN - sources.listSource(source); - - // THEN - QVERIFY(sourceRepositoryMock(&Domain::DataSourceRepository::update).when(source).exactly(1)); - QVERIFY(source->isSelected()); - QCOMPARE(source->listStatus(), Domain::DataSource::Listed); - } - - void shouldChangeSourceToUnlisted() - { - // GIVEN - - auto source = Domain::DataSource::Ptr::create(); - source->setName(QStringLiteral("Source")); - source->setIconName(QStringLiteral("folder")); - source->setContentTypes(Domain::DataSource::Tasks); - source->setSelected(true); - source->setListStatus(Domain::DataSource::Bookmarked); - - - Utils::MockObject sourceQueriesMock; - - Utils::MockObject sourceRepositoryMock; - sourceRepositoryMock(&Domain::DataSourceRepository::update).when(source).thenReturn(new FakeJob(this)); - - Presentation::AvailableSourcesModel sources(sourceQueriesMock.getInstance(), - sourceRepositoryMock.getInstance()); - - // WHEN - sources.unlistSource(source); - - // THEN - QVERIFY(sourceRepositoryMock(&Domain::DataSourceRepository::update).when(source).exactly(1)); - QVERIFY(!source->isSelected()); - QCOMPARE(source->listStatus(), Domain::DataSource::Unlisted); - } - - void shouldToggleSourceToBookmarkStatus_data() - { - QTest::addColumn("wasSelected"); - QTest::addColumn("wasBookmarked"); - QTest::newRow("unselected, not bookmarked") << false << false; - QTest::newRow("selected, not bookmarked") << true << false; - QTest::newRow("unselected, bookmarked") << false << true; - QTest::newRow("selected, bookmarked") << true << true; - } - - void shouldToggleSourceToBookmarkStatus() - { - // GIVEN - QFETCH(bool, wasSelected); - QFETCH(bool, wasBookmarked); - - auto source = Domain::DataSource::Ptr::create(); - source->setName(QStringLiteral("Source")); - source->setIconName(QStringLiteral("folder")); - source->setContentTypes(Domain::DataSource::Tasks); - source->setSelected(wasSelected); - if (wasBookmarked) - source->setListStatus(Domain::DataSource::Bookmarked); - else - source->setListStatus(Domain::DataSource::Listed); - - - Utils::MockObject sourceQueriesMock; - - Utils::MockObject sourceRepositoryMock; - sourceRepositoryMock(&Domain::DataSourceRepository::update).when(source).thenReturn(new FakeJob(this)); - - Presentation::AvailableSourcesModel sources(sourceQueriesMock.getInstance(), - sourceRepositoryMock.getInstance()); - - // WHEN - sources.bookmarkSource(source); - - // THEN - QVERIFY(sourceRepositoryMock(&Domain::DataSourceRepository::update).when(source).exactly(1)); - QCOMPARE(source->isSelected(), wasSelected); - if (wasBookmarked) - QCOMPARE(source->listStatus(), Domain::DataSource::Listed); - else - QCOMPARE(source->listStatus(), Domain::DataSource::Bookmarked); - } - - void shouldGetAnErrorMessageWhenListSourceFailed() - { - // GIVEN - - auto source = Domain::DataSource::Ptr::create(); - source->setName(QStringLiteral("Source")); - source->setIconName(QStringLiteral("folder")); - source->setContentTypes(Domain::DataSource::Tasks); - source->setSelected(false); - source->setListStatus(Domain::DataSource::Unlisted); - - - Utils::MockObject sourceQueriesMock; - - Utils::MockObject sourceRepositoryMock; - - auto job = new FakeJob(this); - job->setExpectedError(KJob::KilledJobError, QStringLiteral("Foo")); - sourceRepositoryMock(&Domain::DataSourceRepository::update).when(source).thenReturn(job); - - Presentation::AvailableSourcesModel sources(sourceQueriesMock.getInstance(), - sourceRepositoryMock.getInstance()); - FakeErrorHandler errorHandler; - sources.setErrorHandler(&errorHandler); - - // WHEN - sources.listSource(source); - - // THEN - QTest::qWait(150); - QCOMPARE(errorHandler.m_message, QStringLiteral("Cannot modify source Source: Foo")); - } - - void shouldGetAnErrorMessageWhenUnlistSourceFailed() - { - // GIVEN - - auto source = Domain::DataSource::Ptr::create(); - source->setName(QStringLiteral("Source")); - source->setIconName(QStringLiteral("folder")); - source->setContentTypes(Domain::DataSource::Tasks); - source->setSelected(false); - source->setListStatus(Domain::DataSource::Unlisted); - - - Utils::MockObject sourceQueriesMock; - - Utils::MockObject sourceRepositoryMock; - - auto job = new FakeJob(this); - job->setExpectedError(KJob::KilledJobError, QStringLiteral("Foo")); - sourceRepositoryMock(&Domain::DataSourceRepository::update).when(source).thenReturn(job); - - Presentation::AvailableSourcesModel sources(sourceQueriesMock.getInstance(), - sourceRepositoryMock.getInstance()); - FakeErrorHandler errorHandler; - sources.setErrorHandler(&errorHandler); - - // WHEN - sources.unlistSource(source); - - // THEN - QTest::qWait(150); - QCOMPARE(errorHandler.m_message, QStringLiteral("Cannot modify source Source: Foo")); - } - - void shouldGetAnErrorMessageWhenBookmarkSourceFailed() - { - // GIVEN - - auto source = Domain::DataSource::Ptr::create(); - source->setName(QStringLiteral("Source")); - source->setIconName(QStringLiteral("folder")); - source->setContentTypes(Domain::DataSource::Tasks); - source->setSelected(false); - source->setListStatus(Domain::DataSource::Unlisted); - - - Utils::MockObject sourceQueriesMock; - - Utils::MockObject sourceRepositoryMock; - - auto job = new FakeJob(this); - job->setExpectedError(KJob::KilledJobError, QStringLiteral("Foo")); - sourceRepositoryMock(&Domain::DataSourceRepository::update).when(source).thenReturn(job); - - Presentation::AvailableSourcesModel sources(sourceQueriesMock.getInstance(), - sourceRepositoryMock.getInstance()); - FakeErrorHandler errorHandler; - sources.setErrorHandler(&errorHandler); - - // WHEN - sources.bookmarkSource(source); - - // THEN - QTest::qWait(150); - QCOMPARE(errorHandler.m_message, QStringLiteral("Cannot modify source Source: Foo")); - } - void shouldGetAnErrorMessageWhenSetDataSourceFailed() { // GIVEN diff --git a/tests/units/testlib/gencollectiontest.cpp b/tests/units/testlib/gencollectiontest.cpp --- a/tests/units/testlib/gencollectiontest.cpp +++ b/tests/units/testlib/gencollectiontest.cpp @@ -92,36 +92,6 @@ QCOMPARE(col.attribute()->iconName(), QStringLiteral("42")); } - void shouldAllowToSetReferenced() - { - // GIVEN - Akonadi::Collection col = GenCollection().referenced(); - - // THEN - QCOMPARE(col.referenced(), true); - - // WHEN - col = GenCollection(col).referenced(false); - - // THEN - QCOMPARE(col.referenced(), false); - } - - void shouldAllowToSetEnabled() - { - // GIVEN - Akonadi::Collection col = GenCollection().enabled(); - - // THEN - QCOMPARE(col.enabled(), true); - - // WHEN - col = GenCollection(col).enabled(false); - - // THEN - QCOMPARE(col.enabled(), false); - } - void shouldAllowToSetSelected() { // GIVEN diff --git a/tests/units/widgets/CMakeLists.txt b/tests/units/widgets/CMakeLists.txt --- a/tests/units/widgets/CMakeLists.txt +++ b/tests/units/widgets/CMakeLists.txt @@ -2,7 +2,6 @@ applicationcomponentstest availablepagesviewtest availablesourcesviewtest - datasourcedelegatetest editorviewtest filterwidgettest newprojectdialogtest diff --git a/tests/units/widgets/availablesourcesviewtest.cpp b/tests/units/widgets/availablesourcesviewtest.cpp --- a/tests/units/widgets/availablesourcesviewtest.cpp +++ b/tests/units/widgets/availablesourcesviewtest.cpp @@ -42,19 +42,13 @@ class AvailableSourcesModelStub : public QObject { Q_OBJECT - Q_PROPERTY(QString searchTerm READ searchTerm WRITE setSearchTerm) public: explicit AvailableSourcesModelStub(QObject *parent = Q_NULLPTR) : QObject(parent), settingsCalled(false) { } - QString searchTerm() const - { - return m_searchTerm; - } - public slots: void showConfigDialog() { @@ -66,35 +60,9 @@ defaultIndex = index; } - void setSearchTerm(const QString &term) - { - m_searchTerm = term; - } - - void listSource(const Domain::DataSource::Ptr &source) - { - listedSources << source; - } - - void unlistSource(const Domain::DataSource::Ptr &source) - { - unlistedSources << source; - } - - void bookmarkSource(const Domain::DataSource::Ptr &source) - { - bookmarkedSources << source; - } - public: bool settingsCalled; - QList listedSources; - QList unlistedSources; - QList bookmarkedSources; QPersistentModelIndex defaultIndex; - -private: - QString m_searchTerm; }; @@ -113,21 +81,7 @@ QVERIFY(sourcesView->isVisibleTo(&available)); QVERIFY(!sourcesView->header()->isVisibleTo(&available)); auto delegate = qobject_cast(sourcesView->itemDelegate()); -#ifdef ZANSHIN_HIDING_SOURCES_ENABLED - QVERIFY(delegate->actionsEnabled()); -#else - QVERIFY(!delegate->isActionsEnabled()); -#endif - - auto searchEdit = available.findChild(QStringLiteral("searchEdit")); - QVERIFY(searchEdit); -#ifdef ZANSHIN_HIDING_SOURCES_ENABLED - QVERIFY(searchEdit->isVisibleTo(&available)); -#else - QVERIFY(!searchEdit->isVisibleTo(&available)); -#endif - QVERIFY(searchEdit->isClearButtonShown()); - QCOMPARE(searchEdit->placeholderText(), tr("Search...")); + QVERIFY(delegate); auto proxy = qobject_cast(sourcesView->model()); QVERIFY(proxy); @@ -280,138 +234,6 @@ // THEN QVERIFY(stubSourcesModel.settingsCalled); } - - void shouldListASourceWhenTheDelegateButtonIsClicked() - { - // GIVEN - auto source = Domain::DataSource::Ptr::create(); - - QStringListModel model(QStringList() << QStringLiteral("A") << QStringLiteral("B") << QStringLiteral("C") ); - AvailableSourcesModelStub stubPagesModel; - stubPagesModel.setProperty("sourceListModel", QVariant::fromValue(static_cast(&model))); - - Widgets::AvailableSourcesView available; - auto sourcesDelegate = available.findChild(); - QVERIFY(sourcesDelegate); - available.setModel(&stubPagesModel); - QTest::qWait(10); - - // WHEN - QVERIFY(QMetaObject::invokeMethod(sourcesDelegate, "actionTriggered", - Q_ARG(Domain::DataSource::Ptr, source), - Q_ARG(int, Widgets::DataSourceDelegate::AddToList))); - - // THEN - QCOMPARE(stubPagesModel.listedSources.size(), 1); - QCOMPARE(stubPagesModel.listedSources.first(), source); - } - - void shouldUnlistASourceWhenTheDelegateButtonIsClicked() - { - // GIVEN - auto source = Domain::DataSource::Ptr::create(); - - QStringListModel model(QStringList() << QStringLiteral("A") << QStringLiteral("B") << QStringLiteral("C") ); - AvailableSourcesModelStub stubPagesModel; - stubPagesModel.setProperty("sourceListModel", QVariant::fromValue(static_cast(&model))); - - Widgets::AvailableSourcesView available; - auto sourcesDelegate = available.findChild(); - QVERIFY(sourcesDelegate); - available.setModel(&stubPagesModel); - QTest::qWait(10); - - // WHEN - QVERIFY(QMetaObject::invokeMethod(sourcesDelegate, "actionTriggered", - Q_ARG(Domain::DataSource::Ptr, source), - Q_ARG(int, Widgets::DataSourceDelegate::RemoveFromList))); - - // THEN - QCOMPARE(stubPagesModel.unlistedSources.size(), 1); - QCOMPARE(stubPagesModel.unlistedSources.first(), source); - } - - void shouldBookmarkASourceWhenTheDelegateButtonIsClicked() - { - // GIVEN - auto source = Domain::DataSource::Ptr::create(); - - QStringListModel model(QStringList() << QStringLiteral("A") << QStringLiteral("B") << QStringLiteral("C") ); - AvailableSourcesModelStub stubPagesModel; - stubPagesModel.setProperty("sourceListModel", QVariant::fromValue(static_cast(&model))); - - Widgets::AvailableSourcesView available; - auto sourcesDelegate = available.findChild(); - QVERIFY(sourcesDelegate); - available.setModel(&stubPagesModel); - QTest::qWait(10); - - // WHEN - QVERIFY(QMetaObject::invokeMethod(sourcesDelegate, "actionTriggered", - Q_ARG(Domain::DataSource::Ptr, source), - Q_ARG(int, Widgets::DataSourceDelegate::Bookmark))); - - // THEN - QCOMPARE(stubPagesModel.bookmarkedSources.size(), 1); - QCOMPARE(stubPagesModel.bookmarkedSources.first(), source); - } - - void shouldSwitchToSearchListWhenASearchTermIsGiven() - { - // GIVEN - QStringListModel sourceModel(QStringList() << QStringLiteral("A") << QStringLiteral("B") << QStringLiteral("C") ); - QStringListModel searchModel(QStringList() << QStringLiteral("D") << QStringLiteral("E") << QStringLiteral("F") ); - - AvailableSourcesModelStub stubPagesModel; - stubPagesModel.setProperty("sourceListModel", QVariant::fromValue(static_cast(&sourceModel))); - stubPagesModel.setProperty("searchListModel", QVariant::fromValue(static_cast(&searchModel))); - - Widgets::AvailableSourcesView available; - auto sourcesView = available.findChild(QStringLiteral("sourcesView")); - QVERIFY(sourcesView); - auto proxy = qobject_cast(sourcesView->model()); - QVERIFY(proxy); - available.setModel(&stubPagesModel); - QCOMPARE(proxy->sourceModel(), &sourceModel); - - auto searchEdit = available.findChild(QStringLiteral("searchEdit")); - QVERIFY(searchEdit); - - // WHEN - QTest::keyClick(searchEdit, 'm'); - - // THEN - QCOMPARE(proxy->sourceModel(), &sourceModel); - QVERIFY(stubPagesModel.searchTerm().isEmpty()); - - // WHEN - QTest::keyClick(searchEdit, 'y'); - - // THEN - QCOMPARE(proxy->sourceModel(), &sourceModel); - QVERIFY(stubPagesModel.searchTerm().isEmpty()); - - // WHEN - QTest::keyClick(searchEdit, ' '); - - // THEN - QCOMPARE(proxy->sourceModel(), &searchModel); - QCOMPARE(stubPagesModel.searchTerm(), QStringLiteral("my ")); - - // WHEN - QTest::keyClicks(searchEdit, QStringLiteral("term")); - - // THEN - QCOMPARE(proxy->sourceModel(), &searchModel); - QCOMPARE(stubPagesModel.searchTerm(), QStringLiteral("my term")); - - // WHEN - searchEdit->clear(); - - // THEN - QCOMPARE(proxy->sourceModel(), &sourceModel); - QVERIFY(stubPagesModel.searchTerm().isEmpty()); - } }; ZANSHIN_TEST_MAIN(AvailableSourcesViewTest) diff --git a/tests/units/widgets/datasourcedelegatetest.cpp b/tests/units/widgets/datasourcedelegatetest.cpp deleted file mode 100644 --- a/tests/units/widgets/datasourcedelegatetest.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* This file is part of Zanshin - - Copyright 2014 Kevin Ottens - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License or (at your option) version 3 or any later version - accepted by the membership of KDE e.V. (or its successor approved - by the membership of KDE e.V.), which shall act as a proxy - defined in Section 14 of version 3 of the license. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - USA. -*/ - -#include - -#include -#include -#include -#include - -#include "domain/datasource.h" - -#include "presentation/querytreemodelbase.h" - -#include "widgets/datasourcedelegate.h" - -Q_DECLARE_METATYPE(QList) - -class DataSourceDelegateTest : public QObject -{ - Q_OBJECT -public: - explicit DataSourceDelegateTest(QObject *parent = Q_NULLPTR) - : QObject(parent) - { - qRegisterMetaType(); - } - - QStandardItem *itemFromSource(const Domain::DataSource::Ptr &source) - { - auto item = new QStandardItem; - item->setText(source->name()); - item->setIcon(QIcon::fromTheme(source->iconName())); - item->setData(QVariant::fromValue(source), - Presentation::QueryTreeModelBase::ObjectRole); - return item; - } - -private slots: - void shouldHandleClickOnButtons_data() - { - QTest::addColumn("actionsEnabled"); - QTest::addColumn("source"); - QTest::addColumn>("expectedActions"); - - QList actions; - auto source = Domain::DataSource::Ptr::create(); - source->setName(QStringLiteral("No Content")); - source->setIconName(QStringLiteral("folder")); - source->setListStatus(Domain::DataSource::Bookmarked); - QTest::newRow("no content") << true << source << actions; - - actions.clear(); - actions << Widgets::DataSourceDelegate::AddToList; - source = Domain::DataSource::Ptr::create(); - source->setName(QStringLiteral("Not listed")); - source->setIconName(QStringLiteral("folder")); - source->setContentTypes(Domain::DataSource::Tasks); - source->setListStatus(Domain::DataSource::Unlisted); - QTest::newRow("not listed") << true << source << actions; - - actions.clear(); - actions << Widgets::DataSourceDelegate::Bookmark << Widgets::DataSourceDelegate::RemoveFromList; - source = Domain::DataSource::Ptr::create(); - source->setName(QStringLiteral("Listed")); - source->setIconName(QStringLiteral("folder")); - source->setContentTypes(Domain::DataSource::Tasks); - source->setListStatus(Domain::DataSource::Listed); - QTest::newRow("listed") << true << source << actions; - - actions.clear(); - actions << Widgets::DataSourceDelegate::Bookmark << Widgets::DataSourceDelegate::RemoveFromList; - source = Domain::DataSource::Ptr::create(); - source->setName(QStringLiteral("Bookmarked")); - source->setIconName(QStringLiteral("folder")); - source->setContentTypes(Domain::DataSource::Tasks); - source->setListStatus(Domain::DataSource::Bookmarked); - QTest::newRow("bookmarked") << true << source << actions; - - actions.clear(); - source = Domain::DataSource::Ptr::create(); - source->setName(QStringLiteral("Listed")); - source->setIconName(QStringLiteral("folder")); - source->setContentTypes(Domain::DataSource::Tasks); - source->setListStatus(Domain::DataSource::Listed); - QTest::newRow("actions disabled") << false << source << actions; - } - - void shouldHandleClickOnButtons() - { - // GIVEN - QFETCH(bool, actionsEnabled); - QFETCH(Domain::DataSource::Ptr, source); - QFETCH(QList, expectedActions); - - Widgets::DataSourceDelegate delegate; - delegate.setActionsEnabled(actionsEnabled); - QSignalSpy spy(&delegate, &Widgets::DataSourceDelegate::actionTriggered); - - QStandardItemModel model; - model.appendRow(itemFromSource(source)); - - QTreeView view; - view.header()->hide(); - view.setItemDelegate(&delegate); - view.setModel(&model); - view.show(); - QTest::qWaitForWindowShown(&view); - - // WHEN - QPoint clickPoint = view.rect().topRight() + QPoint(-30, 10); - for (int i = 0; i < 5; i++) { - QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, clickPoint); - clickPoint += QPoint(-20, 0); - } - - // THEN - QList actions; - while (!spy.isEmpty()) { - auto parameters = spy.takeFirst(); - QCOMPARE(parameters.first().value(), source); - actions << parameters.last().toInt(); - } - QCOMPARE(actions, expectedActions); - } -}; - -ZANSHIN_TEST_MAIN(DataSourceDelegateTest) - -#include "datasourcedelegatetest.moc"