File indexing completed on 2024-05-12 05:11:12

0001 /*
0002   SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
0003   SPDX-FileContributor: Tobias Koenig <tokoe@kdab.com>
0004 
0005   SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #pragma once
0009 
0010 #include "akonadi-mime_export.h"
0011 
0012 #include <Akonadi/Attribute>
0013 #include <QList>
0014 #include <QSharedDataPointer>
0015 #include <QVariant>
0016 
0017 #include <memory>
0018 
0019 namespace Akonadi
0020 {
0021 class SentActionAttributePrivate;
0022 class SentActionAttributeActionPrivate;
0023 
0024 /**
0025  * @short An Attribute that stores the action to execute after sending.
0026  *
0027  * This attribute stores the action that will be executed by the mail dispatcher
0028  * after a mail has successfully be sent.
0029  *
0030  * @author Tobias Koenig <tokoe@kdab.com>
0031  * @since 4.6
0032  */
0033 class AKONADI_MIME_EXPORT SentActionAttribute : public Akonadi::Attribute
0034 {
0035 public:
0036     /**
0037      * @short A sent action.
0038      */
0039     class AKONADI_MIME_EXPORT Action
0040     {
0041     public:
0042         /**
0043          * Describes the action type.
0044          */
0045         enum Type {
0046             Invalid, ///< An invalid action.
0047             MarkAsReplied, ///< The message will be marked as replied.
0048             MarkAsForwarded ///< The message will be marked as forwarded.
0049         };
0050 
0051         /**
0052          * Describes a list of sent actions.
0053          */
0054         using List = QList<Action>;
0055 
0056         /**
0057          * Creates a new invalid action.
0058          */
0059         Action();
0060 
0061         /**
0062          * Creates a new action.
0063          *
0064          * @param type The type of action that shall be executed.
0065          * @param value The action specific argument.
0066          */
0067         Action(Type type, const QVariant &value);
0068 
0069         /**
0070          * Creates an action from an @p other action.
0071          */
0072         Action(const Action &other);
0073 
0074         /**
0075          * Destroys the action.
0076          */
0077         ~Action();
0078 
0079         /**
0080          * Returns the type of the action.
0081          */
0082         Type type() const;
0083 
0084         /**
0085          * Returns the argument value of the action.
0086          */
0087         QVariant value() const;
0088 
0089         /**
0090          * @internal
0091          */
0092         Action &operator=(const Action &other);
0093 
0094         /**
0095          * @internal
0096          */
0097         bool operator==(const Action &other) const;
0098 
0099     private:
0100         //@cond PRIVATE
0101         QSharedDataPointer<SentActionAttributeActionPrivate> d;
0102         //@endcond
0103     };
0104 
0105     /**
0106      * Creates a new sent action attribute.
0107      */
0108     explicit SentActionAttribute();
0109 
0110     /**
0111      * Destroys the sent action attribute.
0112      */
0113     ~SentActionAttribute() override;
0114 
0115     /**
0116      * Adds a new action to the attribute.
0117      *
0118      * @param type The type of the action that shall be executed.
0119      * @param value The action specific argument.
0120      */
0121     void addAction(Action::Type type, const QVariant &value);
0122 
0123     /**
0124      * Returns the list of actions.
0125      */
0126     Action::List actions() const;
0127 
0128     /* reimpl */
0129     SentActionAttribute *clone() const override;
0130     QByteArray type() const override;
0131     QByteArray serialized() const override;
0132     void deserialize(const QByteArray &data) override;
0133 
0134 private:
0135     //@cond PRIVATE
0136     std::unique_ptr<SentActionAttributePrivate> const d;
0137     //@endcond
0138 };
0139 }
0140 Q_DECLARE_TYPEINFO(Akonadi::SentActionAttribute::Action, Q_RELOCATABLE_TYPE);