From 90dbf3c19474102f1d527a2b57cc45b1037107c8 Mon Sep 17 00:00:00 2001 From: Laurent Montel Date: Fri, 14 Dec 2018 08:50:29 +0100 Subject: [PATCH] Start to Reimplement quota info --- src/folder/foldertreewidget.cpp | 31 +++-------------------- src/folder/foldertreewidget.h | 3 --- src/folder/foldertreewidgetproxymodel.cpp | 29 +++++++++++++++++++++ src/folder/foldertreewidgetproxymodel.h | 1 + 4 files changed, 33 insertions(+), 31 deletions(-) diff --git a/src/folder/foldertreewidget.cpp b/src/folder/foldertreewidget.cpp index 51fa2ae..94fea7a 100644 --- a/src/folder/foldertreewidget.cpp +++ b/src/folder/foldertreewidget.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include #include @@ -64,7 +63,6 @@ public: QString oldFilterStr; Akonadi::StatisticsProxyModel *filterModel = nullptr; FolderTreeView *folderTreeView = nullptr; - Akonadi::QuotaColorProxyModel *quotaModel = nullptr; FolderTreeWidgetProxyModel *readableproxy = nullptr; EntityCollectionOrderProxyModel *entityOrderProxy = nullptr; QLineEdit *filterFolderLineEdit = nullptr; @@ -101,18 +99,14 @@ FolderTreeWidget::FolderTreeWidget( "Search")); lay->addWidget(d->filterFolderLineEdit); - // ... with statistics... - d->quotaModel = new Akonadi::QuotaColorProxyModel(this); - d->quotaModel->setSourceModel(KernelIf->collectionModel()); - if (!(options & HideStatistics)) { d->filterModel = new Akonadi::StatisticsProxyModel(this); - d->filterModel->setSourceModel(d->quotaModel); + d->filterModel->setSourceModel(KernelIf->collectionModel()); } d->readableproxy = new FolderTreeWidgetProxyModel(this, optReadableProxy); d->readableproxy->setSourceModel((options & HideStatistics) - ? static_cast(d->quotaModel) + ? static_cast(KernelIf->collectionModel()) : static_cast(d->filterModel)); d->readableproxy->addContentMimeTypeInclusionFilter(KMime::Message::mimeType()); @@ -271,6 +265,7 @@ void FolderTreeWidget::readConfig() d->folderTreeView->readConfig(); d->folderTreeView->setDropActionMenuEnabled(SettingsIf->showPopupAfterDnD()); + d->readableproxy->setWarningThreshold(SettingsIf->closeToQuotaThreshold()); d->readableproxy->readConfig(); KConfigGroup readerConfig(KernelIf->config(), "AccountOrder"); @@ -279,8 +274,6 @@ void FolderTreeWidget::readConfig() listOrder = readerConfig.readEntry("order", QStringList()); } d->entityOrderProxy->setTopLevelOrder(listOrder); - - readQuotaConfig(); } void FolderTreeWidget::restoreHeaderState(const QByteArray &data) @@ -310,24 +303,6 @@ void FolderTreeWidget::changeToolTipsPolicyConfig(ToolTipDisplayPolicy policy) d->folderTreeView->setTooltipsPolicy(policy); } -void FolderTreeWidget::quotaWarningParameters(const QColor &color, qreal threshold) -{ - d->quotaModel->setWarningThreshold(threshold); - d->quotaModel->setWarningColor(color); -} - -void FolderTreeWidget::readQuotaConfig() -{ - QColor quotaColor = MailCommon::Util::defaultQuotaColor(); - qreal threshold = 100; - if (!MessageCore::MessageCoreSettings::self()->useDefaultColors()) { - KConfigGroup readerConfig(KernelIf->config(), "Reader"); - quotaColor = readerConfig.readEntry("CloseToQuotaColor", quotaColor); - } - threshold = SettingsIf->closeToQuotaThreshold(); - quotaWarningParameters(quotaColor, threshold); -} - Akonadi::StatisticsProxyModel *FolderTreeWidget::statisticsProxyModel() const { return d->filterModel; diff --git a/src/folder/foldertreewidget.h b/src/folder/foldertreewidget.h index 048bf46..687dfd5 100644 --- a/src/folder/foldertreewidget.h +++ b/src/folder/foldertreewidget.h @@ -108,9 +108,6 @@ public: Q_REQUIRED_RESULT EntityCollectionOrderProxyModel *entityOrderProxy() const; - void quotaWarningParameters(const QColor &color, qreal threshold); - void readQuotaConfig(); - Q_REQUIRED_RESULT QLineEdit *filterFolderLineEdit() const; void applyFilter(const QString &); void clearFilter(); diff --git a/src/folder/foldertreewidgetproxymodel.cpp b/src/folder/foldertreewidgetproxymodel.cpp index b3a2001..ee8c4f8 100644 --- a/src/folder/foldertreewidgetproxymodel.cpp +++ b/src/folder/foldertreewidgetproxymodel.cpp @@ -32,6 +32,7 @@ #include #include +#include #include @@ -47,6 +48,7 @@ public: Akonadi::MimeTypeChecker checker; QColor brokenAccountColor; + qreal threshold = 0.0; bool enableCheck = false; bool hideVirtualFolder = false; bool hideSpecificFolder = false; @@ -77,6 +79,11 @@ FolderTreeWidgetProxyModel::~FolderTreeWidgetProxyModel() delete d; } +void FolderTreeWidgetProxyModel::setWarningThreshold(qreal threshold) +{ + d->threshold = threshold; +} + void FolderTreeWidgetProxyModel::readConfig() { invalidate(); @@ -224,6 +231,28 @@ QVariant FolderTreeWidgetProxyModel::data(const QModelIndex &index, int role) co return i18n("%1 (Offline)", Akonadi::EntityRightsFilterModel::data(index, role).toString()); } } + if (collection.parentCollection() == Akonadi::Collection::root()) { + if (index.model()->hasChildren(index)) { + const int rowCount = index.model()->rowCount(index); + for (int row = 0; row < rowCount; row++) { + const QModelIndex firstIndex = mapToSource(index.model()->index(row, 0, index)); + + const Akonadi::Collection collectionFirst + = sourceModel()->data( + firstIndex, Akonadi::EntityTreeModel::CollectionRole).value(); + if (collectionFirst.isValid() && collectionFirst.hasAttribute()) { + const Akonadi::CollectionQuotaAttribute *quota = collectionFirst.attribute(); + + if (quota->currentValue() > -1 && quota->maximumValue() > 0) { + const qreal percentage = (100.0 * quota->currentValue()) / quota->maximumValue(); + if (percentage >= d->threshold) { + return i18n("%1 (Reached %2% quota)", Akonadi::EntityRightsFilterModel::data(index, role).toString(), percentage); + } + } + } + } + } + } } } return Akonadi::EntityRightsFilterModel::data(index, role); diff --git a/src/folder/foldertreewidgetproxymodel.h b/src/folder/foldertreewidgetproxymodel.h index 361ccc0..ae007d9 100644 --- a/src/folder/foldertreewidgetproxymodel.h +++ b/src/folder/foldertreewidgetproxymodel.h @@ -63,6 +63,7 @@ public: void updatePalette(); void readConfig(); + void setWarningThreshold(qreal threshold); protected: bool acceptRow(int sourceRow, const QModelIndex &sourceParent) const override;