Commit ec4ada9f authored by Laurent Montel's avatar Laurent Montel 😁

Merge remote-tracking branch 'origin/Applications/17.08'

parents e86717e6 fc8db03b
......@@ -54,6 +54,7 @@ void MimeTypeCheckerTest::initTestCase()
const QLatin1String textPlain = QLatin1String("text/plain");
mEmptyChecker.addWantedMimeType(textPlain);
QVERIFY(!mEmptyChecker.wantedMimeTypes().isEmpty());
QVERIFY(mEmptyChecker.hasWantedMimeTypes());
const QLatin1String textCalendar = QLatin1String("text/calendar");
calendarChecker.addWantedMimeType(textCalendar);
......@@ -73,6 +74,7 @@ void MimeTypeCheckerTest::initTestCase()
mAliasChecker = aliasChecker;
QVERIFY(mEmptyChecker.wantedMimeTypes().isEmpty());
QVERIFY(!mEmptyChecker.hasWantedMimeTypes());
QCOMPARE(mCalendarChecker.wantedMimeTypes().count(), 1);
QCOMPARE(mCalendarChecker.wantedMimeTypes(), QStringList() << textCalendar);
......
......@@ -54,6 +54,11 @@ QStringList MimeTypeChecker::wantedMimeTypes() const
return d->mWantedMimeTypes.values();
}
bool MimeTypeChecker::hasWantedMimeTypes() const
{
return !d->mWantedMimeTypes.isEmpty();
}
void MimeTypeChecker::setWantedMimeTypes(const QStringList &mimeTypes)
{
d->mWantedMimeTypes = QSet<QString>::fromList(mimeTypes);
......
......@@ -135,10 +135,22 @@ public:
/**
* Returns the list of wanted MIME types this instance checks against.
*
* @see setWantedMimeTypes()
* @note Don't use this just to check whether there are any wanted mimetypes.
* It is much faster to call @c hasWantedMimeTypes() instead for that purpose.
*
* @see setWantedMimeTypes(), hasWantedMimeTypes()
*/
QStringList wantedMimeTypes() const;
/**
* Checks whether any wanted MIME types are set.
*
* @return @c true if any wanted MIME types are set, false otherwise.
*
* @since 5.6.43
*/
bool hasWantedMimeTypes() const;
/**
* Sets the list of wanted MIME types this instance checks against.
*
......
......@@ -471,7 +471,7 @@ void EntityTreeModelPrivate::collectionsFetched(const Akonadi::Collection::List
if (m_itemPopulation == EntityTreeModel::ImmediatePopulation) {
foreach (const Collection::Id &collectionId, collectionIt.value()) {
const auto col = m_collections.value(collectionId);
if (m_mimeChecker.wantedMimeTypes().isEmpty() || m_mimeChecker.isWantedCollection(col)) {
if (!m_mimeChecker.hasWantedMimeTypes() || m_mimeChecker.isWantedCollection(col)) {
fetchItems(m_collections.value(collectionId));
} else {
// Consider collections that don't contain relevant mimetypes to be populated
......@@ -521,8 +521,7 @@ void EntityTreeModelPrivate::itemsFetched(const Collection::Id collectionId, con
continue;
}
if ((m_mimeChecker.wantedMimeTypes().isEmpty() ||
m_mimeChecker.isWantedItem(item))) {
if ((!m_mimeChecker.hasWantedMimeTypes() || m_mimeChecker.isWantedItem(item))) {
// When listing virtual collections we might get results for items which are already in
// the model if their concrete collection has already been listed.
// In that case the collectionId should be different though.
......@@ -773,7 +772,7 @@ bool EntityTreeModelPrivate::shouldBePartOfModel(const Collection &collection) c
}
//We're explicitly monitoring collections, but didn't match the filter
if (m_mimeChecker.wantedMimeTypes().isEmpty() && !m_monitor->collectionsMonitored().isEmpty()) {
if (!m_mimeChecker.hasWantedMimeTypes() && !m_monitor->collectionsMonitored().isEmpty()) {
//The collection should be included if one of the parents is monitored
if (isAncestorMonitored(collection)) {
return true;
......@@ -783,8 +782,7 @@ bool EntityTreeModelPrivate::shouldBePartOfModel(const Collection &collection) c
// Some collection trees contain multiple mimetypes. Even though server side filtering ensures we
// only get the ones we're interested in from the job, we have to filter on collections received through signals too.
if (!m_mimeChecker.wantedMimeTypes().isEmpty() &&
!m_mimeChecker.isWantedCollection(collection)) {
if (m_mimeChecker.hasWantedMimeTypes() && !m_mimeChecker.isWantedCollection(collection)) {
return false;
}
......@@ -1081,8 +1079,7 @@ void EntityTreeModelPrivate::monitoredItemAdded(const Akonadi::Item &item, const
Q_ASSERT(m_collectionFetchStrategy != EntityTreeModel::InvisibleCollectionFetch ? m_collections.contains(collection.id()) : true);
if (!m_mimeChecker.wantedMimeTypes().isEmpty() &&
!m_mimeChecker.isWantedItem(item)) {
if (m_mimeChecker.hasWantedMimeTypes() && !m_mimeChecker.isWantedItem(item)) {
return;
}
......@@ -1271,8 +1268,7 @@ void EntityTreeModelPrivate::monitoredItemLinked(const Akonadi::Item &item, cons
Q_ASSERT(m_collections.contains(collectionId));
if (!m_mimeChecker.wantedMimeTypes().isEmpty() &&
!m_mimeChecker.isWantedItem(item)) {
if (m_mimeChecker.hasWantedMimeTypes() && !m_mimeChecker.isWantedItem(item)) {
return;
}
......@@ -1485,7 +1481,7 @@ void EntityTreeModelPrivate::startFirstListJob()
m_collections.insert(m_rootCollection.id(), m_rootCollection);
}
const bool noMimetypes = m_mimeChecker.wantedMimeTypes().isEmpty();
const bool noMimetypes = !m_mimeChecker.hasWantedMimeTypes();
const bool noResources = m_monitor->resourcesMonitored().isEmpty();
const bool multipleCollections = m_monitor->collectionsMonitored().size() > 1;
const bool generalPopulation = !noMimetypes || (noMimetypes && noResources);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment