Start to Reimplement quota info

wilder
Laurent Montel 7 years ago
parent 4fd2913106
commit 90dbf3c194
  1. 31
      src/folder/foldertreewidget.cpp
  2. 3
      src/folder/foldertreewidget.h
  3. 29
      src/folder/foldertreewidgetproxymodel.cpp
  4. 1
      src/folder/foldertreewidgetproxymodel.h

@ -33,7 +33,6 @@
#include <AkonadiCore/EntityMimeTypeFilterModel>
#include <AkonadiCore/EntityTreeModel>
#include <AkonadiCore/ItemFetchScope>
#include <AkonadiCore/QuotaColorProxyModel>
#include <AkonadiCore/StatisticsProxyModel>
#include <AkonadiWidgets/EntityTreeView>
@ -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<QAbstractItemModel *>(d->quotaModel)
? static_cast<QAbstractItemModel *>(KernelIf->collectionModel())
: static_cast<QAbstractItemModel *>(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;

@ -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();

@ -32,6 +32,7 @@
#include <KColorScheme>
#include <KLocalizedString>
#include <collectionquotaattribute.h>
#include <QPalette>
@ -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<Akonadi::Collection>();
if (collectionFirst.isValid() && collectionFirst.hasAttribute<Akonadi::CollectionQuotaAttribute>()) {
const Akonadi::CollectionQuotaAttribute *quota = collectionFirst.attribute<Akonadi::CollectionQuotaAttribute>();
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);

@ -63,6 +63,7 @@ public:
void updatePalette();
void readConfig();
void setWarningThreshold(qreal threshold);
protected:
bool acceptRow(int sourceRow, const QModelIndex &sourceParent) const override;

Loading…
Cancel
Save