File indexing completed on 2024-11-10 04:40:27

0001 /*
0002     SPDX-FileCopyrightText: 2009 Kevin Ottens <ervin@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "akonadicore_export.h"
0010 #include "attribute.h"
0011 
0012 #include <memory>
0013 
0014 namespace Akonadi
0015 {
0016 class CollectionQuotaAttributePrivate;
0017 
0018 /**
0019  * @short Attribute that provides quota information for a collection.
0020  *
0021  * This attribute class provides quota information (e.g. current fill value
0022  * and maximum fill value) for an Akonadi collection.
0023  *
0024  * Example:
0025  *
0026  * @code
0027  *
0028  * using namespace Akonadi;
0029  *
0030  * const Collection collection = collectionFetchJob->collections().at(0);
0031  * if ( collection.hasAttribute<CollectionQuotaAttribute>() ) {
0032  *   const CollectionQuotaAttribute *attribute = collection.attribute<CollectionQuotaAttribute>();
0033  *   qDebug() << "current value" << attribute->currentValue();
0034  * }
0035  *
0036  * @endcode
0037  *
0038  * @author Kevin Ottens <ervin@kde.org>
0039  * @since 4.4
0040  */
0041 class AKONADICORE_EXPORT CollectionQuotaAttribute : public Akonadi::Attribute
0042 {
0043 public:
0044     /**
0045      * Creates a new collection quota attribute.
0046      */
0047     explicit CollectionQuotaAttribute();
0048 
0049     /**
0050      * Creates a new collection quota attribute with initial values.
0051      *
0052      * @param currentValue The current quota value in bytes.
0053      * @param maxValue The maximum quota value in bytes.
0054      */
0055     CollectionQuotaAttribute(qint64 currentValue, qint64 maxValue);
0056 
0057     /**
0058      * Destroys the collection quota attribute.
0059      */
0060     ~CollectionQuotaAttribute() override;
0061 
0062     /**
0063      * Sets the current quota @p value for the collection.
0064      *
0065      * @param value The current quota value in bytes.
0066      */
0067     void setCurrentValue(qint64 value);
0068 
0069     /**
0070      * Sets the maximum quota @p value for the collection.
0071      *
0072      * @param value The maximum quota value in bytes.
0073      */
0074     void setMaximumValue(qint64 value);
0075 
0076     /**
0077      * Returns the current quota value in bytes.
0078      */
0079     [[nodiscard]] qint64 currentValue() const;
0080 
0081     /**
0082      * Returns the maximum quota value in bytes.
0083      */
0084     [[nodiscard]] qint64 maximumValue() const;
0085 
0086     QByteArray type() const override;
0087     Attribute *clone() const override;
0088     [[nodiscard]] QByteArray serialized() const override;
0089     void deserialize(const QByteArray &data) override;
0090 
0091 private:
0092     /// @cond PRIVATE
0093     const std::unique_ptr<CollectionQuotaAttributePrivate> d;
0094     /// @endcond
0095 };
0096 
0097 } // namespace Akonadi