File indexing completed on 2024-12-22 05:01:00

0001 /*
0002  *
0003  * SPDX-FileCopyrightText: 2006 Till Adam <adam@kde.org>
0004  * SPDX-FileCopyrightText: 2009-2024 Laurent Montel <montel@kde.org>
0005  *
0006  * SPDX-License-Identifier: GPL-2.0-only
0007  */
0008 
0009 #include "collectionquotapage.h"
0010 #include "collectionquotawidget.h"
0011 #include <Akonadi/Collection>
0012 #include <Akonadi/CollectionQuotaAttribute>
0013 
0014 #include <KLocalizedString>
0015 #include <QVBoxLayout>
0016 CollectionQuotaPage::CollectionQuotaPage(QWidget *parent)
0017     : CollectionPropertiesPage(parent)
0018     , mQuotaWidget(new CollectionQuotaWidget(this))
0019 {
0020     setObjectName(QLatin1StringView("KMail::CollectionQuotaPage"));
0021     setPageTitle(i18n("Quota"));
0022     init();
0023 }
0024 
0025 bool CollectionQuotaPage::canHandle(const Akonadi::Collection &collection) const
0026 {
0027     const bool hasQuotaAttribute = collection.hasAttribute<Akonadi::CollectionQuotaAttribute>();
0028     if (hasQuotaAttribute) {
0029         if (collection.attribute<Akonadi::CollectionQuotaAttribute>()->maximumValue() <= 0) {
0030             return false;
0031         }
0032     }
0033     return hasQuotaAttribute;
0034 }
0035 
0036 void CollectionQuotaPage::init()
0037 {
0038     auto topLayout = new QVBoxLayout(this);
0039     topLayout->addWidget(mQuotaWidget);
0040 }
0041 
0042 void CollectionQuotaPage::load(const Akonadi::Collection &col)
0043 {
0044     if (col.hasAttribute<Akonadi::CollectionQuotaAttribute>()) {
0045         const qint64 currentValue = col.attribute<Akonadi::CollectionQuotaAttribute>()->currentValue();
0046 
0047         const qint64 maximumValue = col.attribute<Akonadi::CollectionQuotaAttribute>()->maximumValue();
0048         // Test over quota.
0049         mQuotaWidget->setQuotaInfo(qMin(currentValue, maximumValue), maximumValue);
0050     }
0051 }
0052 
0053 void CollectionQuotaPage::save(Akonadi::Collection &)
0054 {
0055     // nothing to do, we are read-only
0056 }
0057 
0058 #include "moc_collectionquotapage.cpp"