diff --git a/src/core/collectionutils.h b/src/core/collectionutils.h index b6ce1e79f..0569c733f 100644 --- a/src/core/collectionutils.h +++ b/src/core/collectionutils.h @@ -1,140 +1,145 @@ /* Copyright (c) 2008 Tobias Koenig This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef AKONADI_COLLECTIONUTILS_P_H #define AKONADI_COLLECTIONUTILS_P_H #include #include "entitydisplayattribute.h" #include "collectionstatistics.h" #include "item.h" namespace Akonadi { /** * @internal */ namespace CollectionUtils { Q_REQUIRED_RESULT inline bool isVirtualParent(const Collection &collection) { return (collection.parentCollection() == Collection::root() && collection.isVirtual()); } Q_REQUIRED_RESULT inline bool isReadOnly(const Collection &collection) { return !(collection.rights() &Collection::CanCreateItem); } Q_REQUIRED_RESULT inline bool isRoot(const Collection &collection) { return (collection == Collection::root()); } Q_REQUIRED_RESULT inline bool isResource(const Collection &collection) { return (collection.parentCollection() == Collection::root()); } Q_REQUIRED_RESULT inline bool isStructural(const Collection &collection) { return collection.contentMimeTypes().isEmpty(); } Q_REQUIRED_RESULT inline bool isFolder(const Collection &collection) { return (!isRoot(collection) && !isResource(collection) && !isStructural(collection) && collection.resource() != QLatin1String("akonadi_search_resource")); } +Q_REQUIRED_RESULT inline bool isUnifiedMailbox(const Collection &collection) +{ + return collection.resource() == QLatin1String("akonadi_unifiedmailbox_agent"); +} + Q_REQUIRED_RESULT inline QString defaultIconName(const Collection &col) { if (CollectionUtils::isVirtualParent(col)) { return QStringLiteral("edit-find"); } if (col.isVirtual()) { return QStringLiteral("document-preview"); } if (CollectionUtils::isResource(col)) { return QStringLiteral("network-server"); } if (CollectionUtils::isStructural(col)) { return QStringLiteral("folder-grey"); } if (CollectionUtils::isReadOnly(col)) { return QStringLiteral("folder-grey"); } const QStringList content = col.contentMimeTypes(); if ((content.size() == 1) || (content.size() == 2 && content.contains(Collection::mimeType()))) { if (content.contains(QLatin1String("text/x-vcard")) || content.contains(QLatin1String("text/directory")) || content.contains(QLatin1String("text/vcard"))) { return QStringLiteral("x-office-address-book"); } // TODO: add all other content types and/or fix their mimetypes if (content.contains(QLatin1String("akonadi/event")) || content.contains(QLatin1String("text/ical"))) { return QStringLiteral("view-pim-calendar"); } if (content.contains(QLatin1String("akonadi/task"))) { return QStringLiteral("view-pim-tasks"); } } else if (content.isEmpty()) { return QStringLiteral("folder-grey"); } return QStringLiteral("folder"); } Q_REQUIRED_RESULT inline QString displayIconName(const Collection &col) { QString iconName = defaultIconName(col); if (col.hasAttribute() && !col.attribute()->iconName().isEmpty()) { if (!col.attribute()->activeIconName().isEmpty() && col.statistics().unreadCount() > 0) { iconName = col.attribute()->activeIconName(); } else { iconName = col.attribute()->iconName(); } } return iconName; } Q_REQUIRED_RESULT inline bool hasValidHierarchicalRID(const Collection &col) { if (col == Collection::root()) { return true; } if (col.remoteId().isEmpty()) { return false; } return hasValidHierarchicalRID(col.parentCollection()); } Q_REQUIRED_RESULT inline bool hasValidHierarchicalRID(const Item &item) { return !item.remoteId().isEmpty() && hasValidHierarchicalRID(item.parentCollection()); } } } #endif diff --git a/src/core/models/subscriptionmodel.cpp b/src/core/models/subscriptionmodel.cpp index 18609b9cf..963856692 100644 --- a/src/core/models/subscriptionmodel.cpp +++ b/src/core/models/subscriptionmodel.cpp @@ -1,198 +1,198 @@ /* Copyright (c) 2007 Volker Krause This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "subscriptionmodel_p.h" #include "collectionfetchjob.h" #include "collectionutils.h" #include "specialcollectionattribute.h" #include "entityhiddenattribute.h" #include "akonadicore_debug.h" #include using namespace Akonadi; /** * @internal */ class SubscriptionModel::Private { public: Private(SubscriptionModel *parent) : q(parent) {} SubscriptionModel *q; QHash subscriptions; QSet changes; bool showHiddenCollection = false; Collection::List changedSubscriptions(bool subscribed) { Collection::List list; for (Collection::Id id : qAsConst(changes)) { if (subscriptions.value(id) == subscribed) { list << Collection(id); } } return list; } void listResult(KJob *job) { if (job->error()) { // TODO qCWarning(AKONADICORE_LOG) << job->errorString(); return; } q->beginResetModel(); const Collection::List cols = static_cast(job)->collections(); for (const Collection &col : cols) { if (!CollectionUtils::isStructural(col)) { subscriptions[ col.id() ] = true; } } q->endResetModel(); emit q->loaded(); } bool isSubscribable(Collection::Id id) { Collection col = q->collectionForId(id); - if (CollectionUtils::isStructural(col) || col.isVirtual()) { + if (CollectionUtils::isStructural(col) || col.isVirtual() || CollectionUtils::isUnifiedMailbox(col)) { return false; } if (col.hasAttribute()) { return false; } if (col.contentMimeTypes().isEmpty()) { return false; } return true; } }; SubscriptionModel::SubscriptionModel(QObject *parent) : CollectionModel(parent), d(new Private(this)) { includeUnsubscribed(); CollectionFetchJob *job = new CollectionFetchJob(Collection::root(), CollectionFetchJob::Recursive, this); connect(job,&CollectionFetchJob::result, this, [this](KJob *job) { d->listResult(job); }); } SubscriptionModel::~SubscriptionModel() { delete d; } QVariant SubscriptionModel::data(const QModelIndex &index, int role) const { switch (role) { case Qt::CheckStateRole: { const Collection::Id col = index.data(CollectionIdRole).toLongLong(); if (!d->isSubscribable(col)) { return QVariant(); } if (d->subscriptions.value(col)) { return Qt::Checked; } return Qt::Unchecked; } case SubscriptionChangedRole: { const Collection::Id col = index.data(CollectionIdRole).toLongLong(); if (d->changes.contains(col)) { return true; } return false; } case Qt::FontRole: { const Collection::Id col = index.data(CollectionIdRole).toLongLong(); QFont font = CollectionModel::data(index, role).value(); font.setBold(d->changes.contains(col)); return font; } } if (role == CollectionIdRole) { return CollectionModel::data(index, CollectionIdRole); } else { const Collection::Id collectionId = index.data(CollectionIdRole).toLongLong(); const Collection collection = collectionForId(collectionId); if (collection.hasAttribute()) { if (d->showHiddenCollection) { return CollectionModel::data(index, role); } else { return QVariant(); } } else { return CollectionModel::data(index, role); } } } Qt::ItemFlags SubscriptionModel::flags(const QModelIndex &index) const { Qt::ItemFlags flags = CollectionModel::flags(index); if (d->isSubscribable(index.data(CollectionIdRole).toLongLong())) { return flags | Qt::ItemIsUserCheckable; } return flags; } bool SubscriptionModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (role == Qt::CheckStateRole) { const Collection::Id col = index.data(CollectionIdRole).toLongLong(); if (!d->isSubscribable(col)) { return true; //No change } if (d->subscriptions.contains(col) && d->subscriptions.value(col) == (value == Qt::Checked)) { return true; // no change } d->subscriptions[ col ] = value == Qt::Checked; if (d->changes.contains(col)) { d->changes.remove(col); } else { d->changes.insert(col); } emit dataChanged(index, index); return true; } return CollectionModel::setData(index, value, role); } Akonadi::Collection::List SubscriptionModel::subscribed() const { return d->changedSubscriptions(true); } Akonadi::Collection::List SubscriptionModel::unsubscribed() const { return d->changedSubscriptions(false); } void SubscriptionModel::showHiddenCollection(bool showHidden) { d->showHiddenCollection = showHidden; } #include "moc_subscriptionmodel_p.cpp"