File indexing completed on 2024-06-23 05:18:26

0001 /*
0002   SPDX-FileCopyrightText: 2009 Constantin Berzan <exit3219@gmail.com>
0003 
0004   SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "MessageComposer/JobBase"
0010 #include <Libkleo/Enum>
0011 
0012 #include "messagecomposer_export.h"
0013 #include <QList>
0014 #include <QStringList>
0015 
0016 #include <KMime/KMimeMessage>
0017 
0018 #include <MessageCore/AttachmentPart>
0019 
0020 #include <gpgme++/key.h>
0021 #include <vector>
0022 
0023 namespace MessageComposer
0024 {
0025 class ComposerPrivate;
0026 class GlobalPart;
0027 class InfoPart;
0028 class TextPart;
0029 class ItipPart;
0030 
0031 /**
0032  * @brief The Composer class
0033  */
0034 class MESSAGECOMPOSER_EXPORT Composer : public JobBase
0035 {
0036     Q_OBJECT
0037 
0038 public:
0039     explicit Composer(QObject *parent = nullptr);
0040     ~Composer() override;
0041 
0042     [[nodiscard]] QList<KMime::Message::Ptr> resultMessages() const;
0043 
0044     [[nodiscard]] GlobalPart *globalPart() const;
0045     [[nodiscard]] InfoPart *infoPart() const;
0046     [[nodiscard]] TextPart *textPart() const;
0047     [[nodiscard]] ItipPart *itipPart() const;
0048     void clearTextPart();
0049     void clearItipPart();
0050     [[nodiscard]] MessageCore::AttachmentPart::List attachmentParts() const;
0051     void addAttachmentPart(MessageCore::AttachmentPart::Ptr part, bool autoresizeImage = false);
0052     void addAttachmentParts(const MessageCore::AttachmentPart::List &parts, bool autoresizeImage = false);
0053     void removeAttachmentPart(MessageCore::AttachmentPart::Ptr part);
0054 
0055     // if the message and attachments should not be encrypted regardless of settings
0056     void setNoCrypto(bool noCrypto);
0057     void setSignAndEncrypt(const bool doSign, const bool doEncrypt);
0058     void setMessageCryptoFormat(Kleo::CryptoMessageFormat format);
0059     void setSigningKeys(const std::vector<GpgME::Key> &signers);
0060     void setEncryptionKeys(const QList<QPair<QStringList, std::vector<GpgME::Key>>> &data);
0061 
0062     void setAutocryptEnabled(bool autocryptEnabled);
0063     void setSenderEncryptionKey(const GpgME::Key &senderKey);
0064 
0065     void setGnupgHome(const QString &path);
0066     [[nodiscard]] QString gnupgHome() const;
0067 
0068     /// Sets if this message being composed is an auto-saved message
0069     ///  if so, might need different handling, such as no crypto attachments.
0070     void setAutoSave(bool isAutoSave);
0071     [[nodiscard]] bool autoSave() const;
0072 
0073     [[nodiscard]] bool finished() const;
0074 
0075 public Q_SLOTS:
0076     void start() override;
0077 
0078 protected Q_SLOTS:
0079     void slotResult(KJob *job) override;
0080 
0081 private:
0082     Q_DECLARE_PRIVATE(Composer)
0083 
0084     Q_PRIVATE_SLOT(d_func(), void doStart())
0085     Q_PRIVATE_SLOT(d_func(), void contentJobFinished(KJob *))
0086     Q_PRIVATE_SLOT(d_func(), void attachmentsFinished(KJob *))
0087 };
0088 }