File indexing completed on 2025-01-05 04:54:58
0001 /* 0002 Copyright (c) 2016 Michael Bohlender <michael.bohlender@kdemail.net> 0003 Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com> 0004 0005 This library is free software; you can redistribute it and/or modify it 0006 under the terms of the GNU Library General Public License as published by 0007 the Free Software Foundation; either version 2 of the License, or (at your 0008 option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, but WITHOUT 0011 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0012 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 0013 License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to the 0017 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0018 02110-1301, USA. 0019 */ 0020 0021 #pragma once 0022 #include "kube_export.h" 0023 #include <QObject> 0024 #include <QString> 0025 #include <QVariant> 0026 #include <QStandardItemModel> 0027 #include <sink/applicationdomaintype.h> 0028 #include <KMime/Message> 0029 #include <mime/mailcrypto.h> 0030 0031 #include "completer.h" 0032 #include "selector.h" 0033 #include "controller.h" 0034 0035 inline bool operator !=(const KMime::Types::Mailbox &l, const KMime::Types::Mailbox &r) 0036 { 0037 return !(l.prettyAddress() == r.prettyAddress()); 0038 } 0039 0040 Q_DECLARE_METATYPE(KMime::Types::Mailbox); 0041 0042 0043 namespace KMime { 0044 class Message; 0045 } 0046 0047 class AddresseeModel; 0048 0049 class KUBE_EXPORT ComposerController : public Kube::Controller 0050 { 0051 Q_OBJECT 0052 0053 //Interface properties 0054 KUBE_CONTROLLER_PROPERTY(QString, Subject, subject) 0055 KUBE_CONTROLLER_PROPERTY(QString, Body, body) 0056 KUBE_CONTROLLER_PROPERTY(bool, HtmlBody, htmlBody) 0057 KUBE_CONTROLLER_PROPERTY(bool, Encrypt, encrypt) 0058 KUBE_CONTROLLER_PROPERTY(bool, Sign, sign) 0059 0060 //Set by identitySelector 0061 KUBE_CONTROLLER_PROPERTY(KMime::Types::Mailbox, Identity, identity) 0062 KUBE_CONTROLLER_PROPERTY(QString, AccountId, accountId) 0063 0064 //Set by loadMessage 0065 KUBE_CONTROLLER_PROPERTY(KMime::Message::Ptr, ExistingMessage, existingMessage) 0066 KUBE_CONTROLLER_PROPERTY(Sink::ApplicationDomain::Mail, ExistingMail, existingMail) 0067 KUBE_CONTROLLER_PROPERTY(bool, Loading, loading) 0068 0069 KUBE_CONTROLLER_PROPERTY(/*std::vector<Crypto::Key>*/QVariant, PersonalKeys, personalKeys) 0070 KUBE_CONTROLLER_PROPERTY(bool, FoundPersonalKeys, foundPersonalKeys) 0071 0072 KUBE_CONTROLLER_LISTCONTROLLER(to) 0073 KUBE_CONTROLLER_LISTCONTROLLER(cc) 0074 KUBE_CONTROLLER_LISTCONTROLLER(bcc) 0075 KUBE_CONTROLLER_LISTCONTROLLER(attachments) 0076 0077 Q_PROPERTY (Completer* recipientCompleter READ recipientCompleter CONSTANT) 0078 Q_PROPERTY (Selector* identitySelector READ identitySelector CONSTANT) 0079 0080 KUBE_CONTROLLER_ACTION(send) 0081 KUBE_CONTROLLER_ACTION(saveAsDraft) 0082 0083 public: 0084 enum LoadType { 0085 Draft, 0086 Reply, 0087 Forward, 0088 }; 0089 Q_ENUMS(LoadType); 0090 0091 explicit ComposerController(); 0092 0093 Completer *recipientCompleter() const; 0094 Selector *identitySelector() const; 0095 0096 Q_INVOKABLE void loadDraft(const QVariant &message); 0097 Q_INVOKABLE void loadReply(const QVariant &message); 0098 Q_INVOKABLE void loadForward(const QVariant &message); 0099 0100 signals: 0101 void messageLoaded(const QString &body); 0102 0103 public slots: 0104 virtual void clear() Q_DECL_OVERRIDE; 0105 0106 private slots: 0107 void findPersonalKey(); 0108 0109 private: 0110 void loadMessage(const QVariant &message, std::function<void(const KMime::Message::Ptr&)> callback); 0111 0112 void recordForAutocompletion(const QByteArray &addrSpec, const QByteArray &displayName); 0113 void setMessage(const QSharedPointer<KMime::Message> &msg); 0114 void addAttachmentPart(KMime::Content *partToAttach); 0115 void selectIdentityFromMailboxes(const KMime::Types::Mailbox::List &mailboxes, const QVector<QString> &meStrings); 0116 0117 KMime::Message::Ptr assembleMessage(); 0118 std::vector<Crypto::Key> getRecipientKeys(); 0119 0120 QScopedPointer<Completer> mRecipientCompleter; 0121 QScopedPointer<Selector> mIdentitySelector; 0122 bool mRemoveDraft = false; 0123 };