Messagelib

composerviewbase.h
1 /*
2  SPDX-FileCopyrightText: 2010 Klaralvdalens Datakonsult AB, a KDAB Group company, [email protected]
3  SPDX-FileCopyrightText: 2010 Leo Franchi <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #ifndef MESSAGECOMPOSER_COMPOSER_VIEW_BASE_H
9 #define MESSAGECOMPOSER_COMPOSER_VIEW_BASE_H
10 
11 #include "messagecomposer_export.h"
12 #include "messagecomposer/messagesender.h"
13 #include "MessageComposer/Recipient"
14 #include <AkonadiCore/collection.h>
15 #include <AkonadiCore/Item>
16 #include <KMime/Message>
17 
18 #include <QObject>
19 #include <QVector>
20 #include <QUrl>
21 #include <Libkleo/Enum>
22 
23 class QTimer;
24 class KJob;
25 class QWidget;
26 
27 namespace Sonnet {
28 class DictionaryComboBox;
29 }
30 
31 namespace Akonadi {
32 class CollectionComboBox;
33 }
34 
35 namespace MailTransport {
36 class TransportComboBox;
37 class MessageQueueJob;
38 }
39 
40 namespace KIdentityManagement {
41 class IdentityCombo;
42 class Identity;
43 class IdentityManager;
44 }
45 
46 namespace Kleo {
47 class KeyResolver;
48 }
49 
50 namespace MessageComposer {
51 class RecipientsEditor;
52 class RichTextComposerNg;
53 class InfoPart;
54 class GlobalPart;
55 class Composer;
56 class AttachmentControllerBase;
57 class AttachmentModel;
58 class SignatureController;
59 class SendLaterInfo;
63 class MESSAGECOMPOSER_EXPORT ComposerViewBase : public QObject
64 {
65  Q_OBJECT
66 public:
67  explicit ComposerViewBase(QObject *parent = nullptr, QWidget *widget = nullptr);
68  ~ComposerViewBase() override;
69 
70  enum Confirmation {
71  LetUserConfirm, NoConfirmationNeeded
72  };
73  enum MissingAttachment {
74  NoMissingAttachmentFound, FoundMissingAttachmentAndSending, FoundMissingAttachmentAndAddedAttachment, FoundMissingAttachmentAndCancel
75  };
76 
77  enum FailedType {
78  Sending, AutoSave
79  };
80 
85  void setMessage(const KMime::Message::Ptr &newMsg, bool allowDecryption);
86 
87  void updateTemplate(const KMime::Message::Ptr &msg);
88 
92  void send(MessageComposer::MessageSender::SendMethod method, MessageComposer::MessageSender::SaveIn saveIn, bool checkMailDispatcher = true);
93 
97  Q_REQUIRED_RESULT bool isComposing() const;
98 
102  void addAttachment(const QUrl &url, const QString &comment, bool sync);
103  void addAttachment(const QString &name, const QString &filename, const QString &charset, const QByteArray &data, const QByteArray &mimeType);
104  void addAttachmentPart(KMime::Content *part);
105 
106  MessageComposer::Composer *createSimpleComposer();
107 
111  Q_REQUIRED_RESULT QString to() const;
112  Q_REQUIRED_RESULT QString cc() const;
113  Q_REQUIRED_RESULT QString bcc() const;
114  Q_REQUIRED_RESULT QString from() const;
115  Q_REQUIRED_RESULT QString replyTo() const;
116  Q_REQUIRED_RESULT QString subject() const;
117 
122  void setAttachmentModel(MessageComposer::AttachmentModel *model);
123  Q_REQUIRED_RESULT MessageComposer::AttachmentModel *attachmentModel();
124 
125  void setAttachmentController(MessageComposer::AttachmentControllerBase *controller);
126  Q_REQUIRED_RESULT MessageComposer::AttachmentControllerBase *attachmentController();
127 
128  void setRecipientsEditor(MessageComposer::RecipientsEditor *recEditor);
129  Q_REQUIRED_RESULT MessageComposer::RecipientsEditor *recipientsEditor();
130 
131  void setSignatureController(MessageComposer::SignatureController *sigController);
132  Q_REQUIRED_RESULT MessageComposer::SignatureController *signatureController();
133 
134  void setIdentityCombo(KIdentityManagement::IdentityCombo *identCombo);
135  Q_REQUIRED_RESULT KIdentityManagement::IdentityCombo *identityCombo();
136 
137  void setIdentityManager(KIdentityManagement::IdentityManager *identMan);
138  Q_REQUIRED_RESULT KIdentityManagement::IdentityManager *identityManager();
139 
140  void setEditor(MessageComposer::RichTextComposerNg *editor);
141  Q_REQUIRED_RESULT MessageComposer::RichTextComposerNg *editor() const;
142 
143  void setTransportCombo(MailTransport::TransportComboBox *transpCombo);
144  Q_REQUIRED_RESULT MailTransport::TransportComboBox *transportComboBox() const;
145 
146  void setFccCombo(Akonadi::CollectionComboBox *fcc);
147  Q_REQUIRED_RESULT Akonadi::CollectionComboBox *fccCombo() const;
148  void setFcc(const Akonadi::Collection &id);
149 
150  Q_REQUIRED_RESULT Sonnet::DictionaryComboBox *dictionary() const;
151  void setDictionary(Sonnet::DictionaryComboBox *dictionary);
152 
157  void setFrom(const QString &from);
158  void setSubject(const QString &subject);
159 
164  void setCryptoOptions(bool sign, bool encrypt, Kleo::CryptoMessageFormat format, bool neverEncryptDrafts = false);
165  void setCharsets(const QVector<QByteArray> &charsets);
166  void setMDNRequested(bool mdnRequested);
167  void setUrgent(bool urgent);
168 
169  void setAutoSaveInterval(int interval);
170  void setCustomHeader(const QMap<QByteArray, QString> &customHeader);
171 
176  void updateAutoSave();
177 
183  void setAutoSaveFileName(const QString &fileName);
184 
188  void cleanupAutoSave();
189 
190  void setParentWidgetForGui(QWidget *);
191 
201  Q_REQUIRED_RESULT ComposerViewBase::MissingAttachment checkForMissingAttachments(const QStringList &attachmentKeywords);
202 
203  Q_REQUIRED_RESULT bool hasMissingAttachments(const QStringList &attachmentKeywords);
204 
205  void setSendLaterInfo(SendLaterInfo *info);
206  Q_REQUIRED_RESULT SendLaterInfo *sendLaterInfo() const;
207  void saveMailSettings();
208 
209  Q_REQUIRED_RESULT QDate followUpDate() const;
210  void setFollowUpDate(const QDate &followUpDate);
211 
212  void clearFollowUp();
213 
214  Q_REQUIRED_RESULT Akonadi::Collection followUpCollection() const;
215  void setFollowUpCollection(const Akonadi::Collection &followUpCollection);
216 
217  Q_REQUIRED_RESULT KMime::Message::Ptr msg() const;
218 
219  Q_REQUIRED_RESULT bool requestDeleveryConfirmation() const;
220  void setRequestDeleveryConfirmation(bool requestDeleveryConfirmation);
221 
222 public Q_SLOTS:
223  void identityChanged(const KIdentityManagement::Identity &ident, const KIdentityManagement::Identity &oldIdent, bool msgCleared = false);
224 
228  void autoSaveMessage();
229 
230 Q_SIGNALS:
234  void sentSuccessfully(Akonadi::Item::Id id);
238  void failed(const QString &errorMessage, MessageComposer::ComposerViewBase::FailedType type = Sending);
239 
244  void modified(bool isModified);
245 
251  void disableHtml(MessageComposer::ComposerViewBase::Confirmation);
252  void enableHtml();
253 
254 private Q_SLOTS:
255  void slotEmailAddressResolved(KJob *);
256  void slotSendComposeResult(KJob *);
257  void slotQueueResult(KJob *job);
258  void slotCreateItemResult(KJob *);
259  void slotAutoSaveComposeResult(KJob *job);
260  void slotFccCollectionCheckResult(KJob *job);
261  void slotSaveMessage(KJob *job);
262 
263 private:
264  Akonadi::Collection defaultSpecialTarget() const;
269  void collectImages(KMime::Content *root);
270  bool inlineSigningEncryptionSelected();
276  void readyForSending();
277 
278  enum RecipientExpansion {
279  UseExpandedRecipients, UseUnExpandedRecipients
280  };
281  QVector< MessageComposer::Composer * > generateCryptoMessages(bool &wasCanceled);
282  void fillGlobalPart(MessageComposer::GlobalPart *globalPart);
283  void fillInfoPart(MessageComposer::InfoPart *part, RecipientExpansion expansion);
284  void queueMessage(const KMime::Message::Ptr &message, MessageComposer::Composer *composer);
285  void saveMessage(const KMime::Message::Ptr &message, MessageComposer::MessageSender::SaveIn saveIn);
286  void fillQueueJobHeaders(MailTransport::MessageQueueJob *qjob, KMime::Message::Ptr message, const MessageComposer::InfoPart *infoPart);
287  QStringList cleanEmailList(const QStringList &emails);
288  void saveRecentAddresses(const KMime::Message::Ptr &ptr);
289  void updateRecipients(const KIdentityManagement::Identity &ident, const KIdentityManagement::Identity &oldIdent, MessageComposer::Recipient::Type type);
290 
291  void markAllAttachmentsForSigning(bool sign);
292  void markAllAttachmentsForEncryption(bool encrypt);
293  bool determineWhetherToSign(bool doSignCompletely, Kleo::KeyResolver *keyResolver, bool signSomething, bool &result, bool &canceled);
294  bool determineWhetherToEncrypt(bool doEncryptCompletely, Kleo::KeyResolver *keyResolver, bool encryptSomething, bool signSomething, bool &result, bool &canceled);
295 
301  void writeAutoSaveToDisk(const KMime::Message::Ptr &message);
302 
306  int autoSaveInterval() const;
307 
311  void initAutoSave();
312  void addFollowupReminder(const QString &messageId);
313  void addSendLaterItem(const Akonadi::Item &item);
314 
315  KMime::Message::Ptr m_msg;
316  MessageComposer::AttachmentControllerBase *m_attachmentController = nullptr;
317  MessageComposer::AttachmentModel *m_attachmentModel = nullptr;
318  MessageComposer::SignatureController *m_signatureController = nullptr;
319  MessageComposer::RecipientsEditor *m_recipientsEditor = nullptr;
320  KIdentityManagement::IdentityCombo *m_identityCombo = nullptr;
321  KIdentityManagement::IdentityManager *m_identMan = nullptr;
322  MessageComposer::RichTextComposerNg *m_editor = nullptr;
323  MailTransport::TransportComboBox *m_transport = nullptr;
324  Sonnet::DictionaryComboBox *m_dictionary = nullptr;
325  Akonadi::CollectionComboBox *m_fccCombo = nullptr;
326  Akonadi::Collection m_fccCollection;
327  QWidget *m_parentWidget = nullptr;
328 
329  // List of active composer jobs. For example, saving as draft, autosaving and printing
330  // all create a composer, which is added to this list as long as it is active.
331  // Used mainly to prevent closing the window if a composer is active
333 
334  bool m_sign = false;
335  bool m_encrypt = false;
336  bool m_neverEncrypt = false;
337  bool m_mdnRequested = false;
338  bool m_urgent = false;
339  bool m_requestDeleveryConfirmation = false;
340  Kleo::CryptoMessageFormat m_cryptoMessageFormat;
341  QString mExpandedFrom;
342  QString m_from;
343  QString m_subject;
344  QStringList mExpandedTo, mExpandedCc, mExpandedBcc, mExpandedReplyTo;
345  QVector< QByteArray > m_charsets;
346  QMap<QByteArray, QString> m_customHeader;
347 
348  int m_pendingQueueJobs = 0;
349 
350  QTimer *m_autoSaveTimer = nullptr;
351  QString m_autoSaveUUID;
352  bool m_autoSaveErrorShown = false; // Stops an error message being shown every time autosave is executed.
353  int m_autoSaveInterval;
354 
355  MessageComposer::MessageSender::SendMethod mSendMethod;
356  MessageComposer::MessageSender::SaveIn mSaveIn;
357 
358  QDate mFollowUpDate;
359  Akonadi::Collection mFollowUpCollection;
360 
361  std::unique_ptr<SendLaterInfo> mSendLaterInfo;
362 };
363 } // namespace
364 
365 #endif
The RichTextComposerNg class.
Composer
The GlobalPart class.
Definition: globalpart.h:19
The Composer class.
Definition: composer.h:33
The AttachmentModel class.
Send later information.
Definition: sendlaterinfo.h:17
The SignatureController class Controls signature (the footer thing, not the crypto thing) operations ...
The ComposerViewBase class.
KCALUTILS_EXPORT QString errorMessage(const KCalendarCore::Exception &exception)
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
The InfoPart class.
Definition: infopart.h:20
The AttachmentControllerBase class.
The RecipientsEditor class.
A class to resolve signing/encryption keys w.r.t.
Definition: keyresolver.h:106
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jul 13 2020 23:13:03 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.