File indexing completed on 2025-02-16 04:49:24

0001 /*
0002    SPDX-FileCopyrightText: 2021-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 #include "kmailconfirmbeforedeleting_export.h"
0009 #include <Akonadi/Item>
0010 #include <KConfigGroup>
0011 #include <KMime/Message>
0012 #include <QDebug>
0013 #include <QString>
0014 class KMAILCONFIRMBEFOREDELETING_EXPORT ConfirmBeforeDeletingRule
0015 {
0016     Q_GADGET
0017 public:
0018     enum RuleType {
0019         Unknown = 0,
0020         Body,
0021         Subject,
0022         To,
0023         Cc,
0024         Bcc,
0025         Unread,
0026         Important,
0027     };
0028     Q_ENUM(RuleType)
0029 
0030     ConfirmBeforeDeletingRule();
0031     ~ConfirmBeforeDeletingRule();
0032 
0033     [[nodiscard]] const QString &pattern() const;
0034     void setPattern(const QString &newPattern);
0035 
0036     [[nodiscard]] RuleType ruleType() const;
0037     void setRuleType(RuleType newRuleType);
0038 
0039     [[nodiscard]] bool deletingNeedToConfirm(const Akonadi::Item &item, QString &checkFoundInfo) const;
0040 
0041     void save(KConfigGroup &group) const;
0042     void load(const KConfigGroup &group);
0043 
0044     [[nodiscard]] bool isValid() const;
0045     [[nodiscard]] static QString ruleTypeToString(ConfirmBeforeDeletingRule::RuleType r);
0046     [[nodiscard]] static ConfirmBeforeDeletingRule::RuleType stringToRuleType(const QString &str);
0047 
0048     [[nodiscard]] bool operator==(const ConfirmBeforeDeletingRule &other) const;
0049 
0050 private:
0051     void generateConfirmMessageInfo(const KMime::Message::Ptr &msg, QString &checkFoundInfo) const;
0052     void generateConfirmMessageInfoFromStatus(const KMime::Message::Ptr &msg, QString &checkFoundInfo, const QString &statusStr) const;
0053     QString mPattern;
0054     RuleType mRuleType = RuleType::Unknown;
0055 };
0056 Q_DECLARE_TYPEINFO(ConfirmBeforeDeletingRule, Q_RELOCATABLE_TYPE);
0057 KMAILCONFIRMBEFOREDELETING_EXPORT QDebug operator<<(QDebug d, const ConfirmBeforeDeletingRule &t);