kmcomposerwin.h 21.7 KB
Newer Older
Volker Krause's avatar
Volker Krause committed
1
2
/*
 * This file is part of KMail.
3
 * SPDX-FileCopyrightText: 2011-2020 Laurent Montel <montel@kde.org>
Laurent Montel's avatar
Laurent Montel committed
4
 *
5
 * SPDX-FileCopyrightText: 2009 Constantin Berzan <exit3219@gmail.com>
Volker Krause's avatar
Volker Krause committed
6
7
 *
 * Based on KMail code by:
8
 * SPDX-FileCopyrightText: 1997 Markus Wuebben <markus.wuebben@kde.org>
Volker Krause's avatar
Volker Krause committed
9
 *
10
 * SPDX-License-Identifier: GPL-2.0-or-later
Volker Krause's avatar
Volker Krause committed
11
12
 */

Yuri Chornoivan's avatar
Yuri Chornoivan committed
13
14
#ifndef KMAIL_KMCOMPOSERWIN_H
#define KMAIL_KMCOMPOSERWIN_H
Volker Krause's avatar
Volker Krause committed
15
16

// KMail includes
Laurent Montel's avatar
Laurent Montel committed
17
#include "editor/composer.h"
Laurent Montel's avatar
Laurent Montel committed
18
#include <MessageComposer/RecipientsEditor>
Laurent Montel's avatar
Laurent Montel committed
19
#include <MessageComposer/PluginEditorConvertTextInterface>
Volker Krause's avatar
Volker Krause committed
20
21
22
// Qt includes
#include <QFont>
#include <QList>
Laurent Montel's avatar
Laurent Montel committed
23
#include <QVector>
Volker Krause's avatar
Volker Krause committed
24
25

// LIBKDEPIM includes
Laurent Montel's avatar
Laurent Montel committed
26
#include <MessageComposer/RichTextComposerNg>
Volker Krause's avatar
Volker Krause committed
27

Laurent Montel's avatar
Laurent Montel committed
28
#include <MessageComposer/MessageSender>
29

30
// KDEPIMLIBS includes
Laurent Montel's avatar
Laurent Montel committed
31
32
#include <kmime/kmime_message.h>
#include <kmime/kmime_headers.h>
33

Volker Krause's avatar
Volker Krause committed
34
// Other includes
Laurent Montel's avatar
Laurent Montel committed
35
#include <Libkleo/Enum>
36
#include <MessageComposer/ComposerViewBase>
Volker Krause's avatar
Volker Krause committed
37

Laurent Montel's avatar
Laurent Montel committed
38
39
class QUrl;

Volker Krause's avatar
Volker Krause committed
40
41
42
43
class QByteArray;
class QGridLayout;
class QLabel;
class QSplitter;
44
class KSplitterCollapserButton;
Volker Krause's avatar
Volker Krause committed
45
class CodecAction;
Laurent Montel's avatar
Laurent Montel committed
46
class KMComposerWin;
Volker Krause's avatar
Volker Krause committed
47
48
class KMComposerEditor;
class KSelectAction;
Laurent Montel's avatar
Laurent Montel committed
49
class QAction;
Volker Krause's avatar
Volker Krause committed
50
51
class KJob;
class KToggleAction;
Laurent Montel's avatar
KUrl--    
Laurent Montel committed
52
class QUrl;
Volker Krause's avatar
Volker Krause committed
53
class KRecentFilesAction;
54
class AttachmentMissingWarning;
55
class ExternalEditorWarning;
56
class CryptoStateIndicatorWidget;
Laurent Montel's avatar
Laurent Montel committed
57
class PotentialPhishingEmailWarning;
Laurent Montel's avatar
Laurent Montel committed
58
class KMComposerGlobalAction;
Laurent Montel's avatar
Laurent Montel committed
59
class KMailPluginEditorManagerInterface;
Laurent Montel's avatar
Laurent Montel committed
60
class KMailPluginEditorCheckBeforeSendManagerInterface;
Laurent Montel's avatar
Laurent Montel committed
61
class KMailPluginEditorInitManagerInterface;
62
class IncorrectIdentityFolderWarning;
Laurent Montel's avatar
Laurent Montel committed
63
class KMailPluginEditorConvertTextManagerInterface;
64
class KMailPluginGrammarEditorManagerInterface;
65
class AttachmentAddedFromExternalWarning;
Laurent Montel's avatar
Laurent Montel committed
66
namespace MailTransport {
67
68
class Transport;
}
69

Laurent Montel's avatar
Laurent Montel committed
70
namespace KIdentityManagement {
Laurent Montel's avatar
Laurent Montel committed
71
class Identity;
Volker Krause's avatar
Volker Krause committed
72
73
}

Laurent Montel's avatar
Laurent Montel committed
74
namespace KPIMTextEdit {
Laurent Montel's avatar
Laurent Montel committed
75
class RichTextEditorWidget;
Volker Krause's avatar
Volker Krause committed
76
77
}

Laurent Montel's avatar
Laurent Montel committed
78
namespace KIO {
Laurent Montel's avatar
Laurent Montel committed
79
class Job;
Volker Krause's avatar
Volker Krause committed
80
81
}

Laurent Montel's avatar
Laurent Montel committed
82
namespace MessageComposer {
Laurent Montel's avatar
Laurent Montel committed
83
84
class ComposerLineEdit;
class Composer;
85
class StatusBarLabelToggledState;
Volker Krause's avatar
Volker Krause committed
86
87
}

Laurent Montel's avatar
Laurent Montel committed
88
namespace MailCommon {
Laurent Montel's avatar
Laurent Montel committed
89
class FolderRequester;
Laurent Montel's avatar
Laurent Montel committed
90
class SnippetTreeView;
Laurent Montel's avatar
Laurent Montel committed
91
struct SnippetInfo;
92
}
Laurent Montel's avatar
Laurent Montel committed
93

Laurent Montel's avatar
Laurent Montel committed
94
namespace PimCommon {
Laurent Montel's avatar
Laurent Montel committed
95
class CustomToolsWidgetNg;
Laurent Montel's avatar
Laurent Montel committed
96
class LineEditWithAutoCorrection;
97
}
98

Laurent Montel's avatar
Laurent Montel committed
99
namespace GpgME {
100
101
102
103
104
class KeyListResult;
class Key;
class UserID;
}

Volker Krause's avatar
Volker Krause committed
105
//-----------------------------------------------------------------------------
Laurent Montel's avatar
Laurent Montel committed
106
class KMComposerWin : public KMail::Composer
Volker Krause's avatar
Volker Krause committed
107
{
Laurent Montel's avatar
Laurent Montel committed
108
109
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "org.kde.kmail.mailcomposer")
Volker Krause's avatar
Volker Krause committed
110

Laurent Montel's avatar
Laurent Montel committed
111
    friend class ::KMComposerEditor;
Volker Krause's avatar
Volker Krause committed
112

Laurent Montel's avatar
Laurent Montel committed
113
private: // mailserviceimpl, kmkernel, kmcommands, callback, kmmainwidget
Laurent Montel's avatar
Laurent Montel committed
114
    explicit KMComposerWin(const KMime::Message::Ptr &msg, bool lastSignState, bool lastEncryptState, TemplateContext context = NoTemplate, uint identity = 0, const QString &textSelection = QString(), const QString &customTemplate = QString());
Laurent Montel's avatar
Laurent Montel committed
115
    ~KMComposerWin() override;
Volker Krause's avatar
Volker Krause committed
116

Laurent Montel's avatar
Laurent Montel committed
117
public:
Laurent Montel's avatar
Laurent Montel committed
118
    static Composer *create(const KMime::Message::Ptr &msg, bool lastSignState, bool lastEncryptState, TemplateContext context = NoTemplate, uint identity = 0, const QString &textSelection = QString(), const QString &customTemplate = QString());
Volker Krause's avatar
Volker Krause committed
119

Laurent Montel's avatar
Laurent Montel committed
120
121
    Q_REQUIRED_RESULT QString dbusObjectPath() const override;
    Q_REQUIRED_RESULT QString smartQuote(const QString &msg);
Volker Krause's avatar
Volker Krause committed
122

Laurent Montel's avatar
Laurent Montel committed
123
    /**
Laurent Montel's avatar
Laurent Montel committed
124
125
126
    * Start of D-Bus callable stuff. The D-Bus methods need to be public slots,
    * otherwise they can't be accessed.
    */
Laurent Montel's avatar
Laurent Montel committed
127
public Q_SLOTS:
Volker Krause's avatar
Volker Krause committed
128

129
    Q_SCRIPTABLE void send(int how) override;
Laurent Montel's avatar
Laurent Montel committed
130
131
132
    /**
    * End of D-Bus callable stuff
    */
Volker Krause's avatar
Volker Krause committed
133

Laurent Montel's avatar
Laurent Montel committed
134
    void addAttachmentsAndSend(const QList<QUrl> &urls, const QString &comment, int how) override;
Volker Krause's avatar
Volker Krause committed
135

Laurent Montel's avatar
Laurent Montel committed
136
    void addAttachment(const QVector<KMail::Composer::AttachmentInfo> &infos, bool showWarning) override;
Volker Krause's avatar
Volker Krause committed
137

Laurent Montel's avatar
Laurent Montel committed
138
    void addAttachment(const QString &name, KMime::Headers::contentEncoding cte, const QString &charset, const QByteArray &data, const QByteArray &mimeType) override;
Volker Krause's avatar
Volker Krause committed
139

Laurent Montel's avatar
Laurent Montel committed
140
Q_SIGNALS:
Laurent Montel's avatar
Laurent Montel committed
141
    void identityChanged(const KIdentityManagement::Identity &identity);
Volker Krause's avatar
Volker Krause committed
142

Laurent Montel's avatar
Laurent Montel committed
143
public: // kmkernel, kmcommands, callback
Volker Krause's avatar
Volker Krause committed
144
145
146
147
    /**
     * Set the message the composer shall work with. This discards
     * previous messages without calling applyChanges() on them before.
     */
Laurent Montel's avatar
Laurent Montel committed
148
    void setMessage(const KMime::Message::Ptr &newMsg, bool lastSignState = false, bool lastEncryptState = false, bool mayAutoSign = true, bool allowDecryption = false, bool isModified = false) override;
Volker Krause's avatar
Volker Krause committed
149

150
    void setCurrentTransport(int transportId) override;
151

152
153
154
155
156
    /**
     * Use the given folder as sent-mail folder if the given folder exists.
     * Else show an error message and use the default sent-mail folder as
     * sent-mail folder.
     */
157
    void setFcc(const QString &idString) override;
158

Laurent Montel's avatar
Laurent Montel committed
159
    /**
Volker Krause's avatar
Volker Krause committed
160
161
162
163
      * Disables word wrap completely. No wrapping at all will occur, not even
      * at the right end of the editor.
      * This is useful when sending invitations.
      */
164
    void disableWordWrap() override;
Volker Krause's avatar
Volker Krause committed
165

Laurent Montel's avatar
Laurent Montel committed
166
    /**
Volker Krause's avatar
Volker Krause committed
167
168
169
170
171
172
      * Disables HTML completely. It disables HTML at the point of calling this and disables it
      * again when sending the message, to be sure. Useful when sending invitations.
      * This will <b>not</b> remove the actions for activating HTML mode again, it is only
      * meant for automatic invitation sending.
      * Also calls @sa disableHtml() internally.
      */
173
    void forceDisableHtml() override;
Volker Krause's avatar
Volker Krause committed
174

Laurent Montel's avatar
Laurent Montel committed
175
    /**
Volker Krause's avatar
Volker Krause committed
176
177
      * Returns @c true while the message composing is in progress.
      */
Laurent Montel's avatar
Laurent Montel committed
178
    Q_REQUIRED_RESULT bool isComposing() const override;
Volker Krause's avatar
Volker Krause committed
179

Laurent Montel's avatar
Laurent Montel committed
180
    /** Disabled signing and encryption completely for this composer window. */
181
    void setSigningAndEncryptionDisabled(bool v) override;
Volker Krause's avatar
Volker Krause committed
182
183
184
185
    /**
     * If this folder is set, the original message is inserted back after
     * canceling
     */
186
    void setFolder(const Akonadi::Collection &aFolder) override;
Volker Krause's avatar
Volker Krause committed
187
188
189
    /**
     * Sets the focus to the edit-widget.
     */
190
    void setFocusToEditor() override;
Volker Krause's avatar
Volker Krause committed
191
192
193
194
195

    /**
     * Sets the focus to the subject line edit. For use when creating a
     * message to a known recipient.
     */
196
    void setFocusToSubject() override;
Laurent Montel's avatar
Laurent Montel committed
197

Laurent Montel's avatar
Laurent Montel committed
198
    bool insertFromMimeData(const QMimeData *source, bool forceAttachment = false);
Volker Krause's avatar
Volker Krause committed
199

200
    void setCollectionForNewMessage(const Akonadi::Collection &folder) override;
201

202
    void addExtraCustomHeaders(const QMap<QByteArray, QString> &header) override;
203

Laurent Montel's avatar
Laurent Montel committed
204
205
    Q_REQUIRED_RESULT MessageComposer::PluginEditorConvertTextInterface::ConvertTextStatus convertPlainText(MessageComposer::TextPart *textPart);
    Q_REQUIRED_RESULT bool processModifyText(QKeyEvent *event);
Laurent Montel's avatar
Laurent Montel committed
206
207
private:
    /**
Laurent Montel's avatar
Laurent Montel committed
208
209
    * Write settings to app's config file.
    */
Laurent Montel's avatar
Laurent Montel committed
210
    void writeConfig();
Laurent Montel's avatar
Laurent Montel committed
211
212
213
214
215

    /**
     * Returns true if the message was modified by the user.
     */
    bool isModified() const;
216
    bool isComposerModified() const;
Laurent Montel's avatar
Laurent Montel committed
217
    void changeModifiedState(bool modified);
Volker Krause's avatar
Volker Krause committed
218

Laurent Montel's avatar
Laurent Montel committed
219
public Q_SLOTS: // kmkernel, callback
220
    void slotSendNow() override;
Laurent Montel's avatar
Laurent Montel committed
221
222
223
    /**
     * Switch wordWrap on/off
     */
224
    void slotWordWrapToggled(bool);
Laurent Montel's avatar
Laurent Montel committed
225
226

    void slotToggleMarkup();
Laurent Montel's avatar
Laurent Montel committed
227
    void slotTextModeChanged(MessageComposer::RichTextComposerNg::Mode mode);
Laurent Montel's avatar
Laurent Montel committed
228
    void htmlToolBarVisibilityChanged(bool visible);
Laurent Montel's avatar
Laurent Montel committed
229
    void slotSpellcheckDoneClearStatus();
230
    void autoSaveMessage(bool force = false) override;
Laurent Montel's avatar
Laurent Montel committed
231
232
233
    /**
     * Set whether the message should be treated as modified or not.
     */
234
    void setModified(bool modified) override;
Laurent Montel's avatar
Laurent Montel committed
235
    void slotFetchJob(KJob *);
Volker Krause's avatar
Volker Krause committed
236

Laurent Montel's avatar
Laurent Montel committed
237
private Q_SLOTS:
Laurent Montel's avatar
Laurent Montel committed
238
    /**
239
240
241
      * Disables the HTML mode, by hiding the HTML toolbar and unchecking the
      * "Formatting" action. Also, removes all rich-text formatting.
      */
Laurent Montel's avatar
Laurent Montel committed
242
    void disableHtml(MessageComposer::ComposerViewBase::Confirmation confirmation);
243
244
245
246
247
    /**
     * Enables HTML mode, by showing the HTML toolbar and checking the
     * "Formatting" action
     */
    void enableHtml();
Volker Krause's avatar
Volker Krause committed
248
249
250
251
252

    /**
     * Actions:
     */
    void slotPrint();
253
254
    void slotPrintPreview();

Laurent Montel's avatar
Laurent Montel committed
255
    void slotInsertRecentFile(const QUrl &);
Volker Krause's avatar
Volker Krause committed
256
257
    void slotRecentListFileClear();

Laurent Montel's avatar
Laurent Montel committed
258
    void slotSendNowVia(MailTransport::Transport *transport);
Volker Krause's avatar
Volker Krause committed
259
    void slotSendLater();
Laurent Montel's avatar
Laurent Montel committed
260
    void slotSendLaterVia(MailTransport::Transport *transport);
Volker Krause's avatar
Volker Krause committed
261
262
263
264
265
266
267
268
269

    /**
     * Returns true when saving was successful.
     */
    void slotSaveDraft();
    void slotSaveTemplate();
    void slotNewComposer();
    void slotClose();
    void slotPasteAsAttachment();
Laurent Montel's avatar
Laurent Montel committed
270
    void slotFolderRemoved(const Akonadi::Collection &);
Laurent Montel's avatar
Laurent Montel committed
271
    void slotDictionaryLanguageChanged(const QString &language);
Laurent Montel's avatar
Laurent Montel committed
272
    void slotFccFolderChanged(const Akonadi::Collection &);
Allen Winter's avatar
Allen Winter committed
273
    void slotEditorTextChanged();
274
    void slotOverwriteModeChanged();
Volker Krause's avatar
Volker Krause committed
275
276
277
278
279
280
281
282
    /**
     * toggle fixed width font.
     */
    void slotUpdateFont();

    /**
     * Open addressbook editor dialog.
     */
Laurent Montel's avatar
Minor    
Laurent Montel committed
283
    void slotAddressBook();
Volker Krause's avatar
Volker Krause committed
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298

    /**
     * Insert a file to the end of the text in the editor.
     */
    void slotInsertFile();

    /**
     * Check spelling of text.
     */
    void slotSpellcheckConfig();

    /**
     * Change crypto plugin to be used for signing/encrypting messages,
     * or switch to built-in OpenPGP code.
     */
299
    void slotSelectCryptoModule(bool init);
Volker Krause's avatar
Volker Krause committed
300
301
302
303
304
305
306
307
308
309
310

    /**
     * XML-GUI stuff
     */
    void slotEditToolbars();
    void slotUpdateToolbars();
    void slotEditKeys();

    /**
     * Change window title to given string.
     */
Laurent Montel's avatar
Laurent Montel committed
311
    void slotUpdateWindowTitle();
Volker Krause's avatar
Volker Krause committed
312
313

    /**
Yuri Chornoivan's avatar
Yuri Chornoivan committed
314
     * Switch the icon to lock or unlock respectively.
Volker Krause's avatar
Volker Krause committed
315
316
     * Change states of all encrypt check boxes in the attachments listview
     */
Laurent Montel's avatar
Laurent Montel committed
317
    void slotEncryptToggled(bool);
Volker Krause's avatar
Volker Krause committed
318
319
320
321

    /**
     * Change states of all sign check boxes in the attachments listview
     */
Laurent Montel's avatar
Laurent Montel committed
322
    void slotSignToggled(bool);
Volker Krause's avatar
Volker Krause committed
323

Laurent Montel's avatar
Laurent Montel committed
324
    void slotUpdateView();
Volker Krause's avatar
Volker Krause committed
325
326
327

    /**
     * Update composer field to reflect new identity
Volker Krause's avatar
Volker Krause committed
328
329
330
     * @param initalChange if true, don't apply the template. This is useful when calling
     *                     this function from setMsg(), because there, the message already has the
     *                     template, and we want to avoid calling the template parser unnecessarily.
Volker Krause's avatar
Volker Krause committed
331
     */
Laurent Montel's avatar
Laurent Montel committed
332
    void slotIdentityChanged(uint uoid, bool initalChange = false);
Volker Krause's avatar
Volker Krause committed
333
334
335

    void slotCursorPositionChanged();

Laurent Montel's avatar
Laurent Montel committed
336
    void slotSpellCheckingStatus(const QString &status);
Volker Krause's avatar
Volker Krause committed
337

Laurent Montel's avatar
Laurent Montel committed
338
    void slotDelayedApplyTemplate(KJob *);
Laurent Montel's avatar
Laurent Montel committed
339

Laurent Montel's avatar
Laurent Montel committed
340
341
    void recipientEditorSizeHintChanged();
    void setMaximumHeaderSize();
Laurent Montel's avatar
Laurent Montel committed
342
    void slotDoDelayedSend(KJob *);
Laurent Montel's avatar
Laurent Montel committed
343

Laurent Montel's avatar
Laurent Montel committed
344
    void slotCompletionModeChanged(KCompletion::CompletionMode);
Laurent Montel's avatar
Laurent Montel committed
345
346
    void slotConfigChanged();

Laurent Montel's avatar
Laurent Montel committed
347
348
    void slotPrintComposeResult(KJob *job);

Laurent Montel's avatar
Laurent Montel committed
349
    void slotSendFailed(const QString &msg, MessageComposer::ComposerViewBase::FailedType type);
350
    void slotSendSuccessful(Akonadi::Item::Id id);
Laurent Montel's avatar
Laurent Montel committed
351
352
353
354

    /**
     *  toggle automatic spellchecking
     */
Laurent Montel's avatar
Laurent Montel committed
355
    void slotAutoSpellCheckingToggled(bool);
Laurent Montel's avatar
Laurent Montel committed
356

Laurent Montel's avatar
Laurent Montel committed
357
358
    void showAndActivateComposer() override;

359
    void setAutoSaveFileName(const QString &fileName) override;
Laurent Montel's avatar
Laurent Montel committed
360
    void slotSpellCheckingLanguage(const QString &language);
361
    void forceAutoSaveMessage();
362
    void slotSaveAsFile();
Tobias Koenig's avatar
Tobias Koenig committed
363

364
    void slotAttachMissingFile();
365
    void slotExplicitClosedMissingAttachment();
366
    void slotVerifyMissingAttachmentTimeout();
367
    void slotCheckSendNow();
368

369
370
    void slotExternalEditorStarted();
    void slotExternalEditorClosed();
371

Laurent Montel's avatar
Laurent Montel committed
372
373
    void slotInsertShortUrl(const QString &url);

Laurent Montel's avatar
Laurent Montel committed
374
    void slotTransportChanged();
375
    void slotFollowUpMail(bool toggled);
376
    void slotSendNowByShortcut();
Laurent Montel's avatar
Laurent Montel committed
377
    void slotSnippetWidgetVisibilityChanged(bool b);
378
    void slotOverwriteModeWasChanged(bool state);
Laurent Montel's avatar
Laurent Montel committed
379
    void slotExpandGroupResult(KJob *job);
Laurent Montel's avatar
Laurent Montel committed
380
381
    void slotCheckSendNowStep2();
    void slotPotentialPhishingEmailsFound(const QStringList &list);
Laurent Montel's avatar
Laurent Montel committed
382
    void slotInsertTextFile(KJob *job);
383
384
385
386
387

    void slotRecipientEditorLineAdded(KPIM::MultiplyingLine *line);
    void slotRecipientEditorFocusChanged();
    void slotRecipientAdded(MessageComposer::RecipientLineNG *line);
    void slotRecipientLineIconClicked(MessageComposer::RecipientLineNG *line);
388
    void slotRecipientFocusLost(MessageComposer::RecipientLineNG *line);
389
390
    void slotKeyForMailBoxResult(const GpgME::KeyListResult &result, const GpgME::Key &key, const GpgME::UserID &userID);

391
    void slotDelayedCheckSendNow();
Laurent Montel's avatar
Laurent Montel committed
392
    void slotUpdateComposer(const KIdentityManagement::Identity &ident, const KMime::Message::Ptr &msg, uint uoid, uint uoldId, bool wasModified);
Laurent Montel's avatar
Laurent Montel committed
393
public: // kmcommand
394
    void addAttach(KMime::Content *msgPart) override;
Laurent Montel's avatar
Laurent Montel committed
395

Laurent Montel's avatar
Laurent Montel committed
396
    const KIdentityManagement::Identity &identity() const;
Volker Krause's avatar
Volker Krause committed
397

398
    /** Don't check for forgotten attachments for a mail, eg. when sending out invitations. */
399
    void disableForgottenAttachmentsCheck() override;
400

Laurent Montel's avatar
Laurent Montel committed
401
    Q_REQUIRED_RESULT uint currentIdentity() const;
Laurent Montel's avatar
Laurent Montel committed
402
    QList<KToggleAction *> customToolsList() const;
Laurent Montel's avatar
Laurent Montel committed
403
    QList<QAction *> pluginToolsActionListForPopupMenu() const;
Laurent Montel's avatar
Laurent Montel committed
404
private:
405
    void enableDisablePluginActions(bool richText);
Laurent Montel's avatar
Laurent Montel committed
406
407
408
409
410
    /**
     * Read settings from app's config file.
     */
    void readConfig(bool reload = false);

Laurent Montel's avatar
Laurent Montel committed
411
    Q_REQUIRED_RESULT QUrl insertFile();
Laurent Montel's avatar
Laurent Montel committed
412
413
414
415
416
    /**
     * Updates the visibility and text of the signature and encryption state indicators.
     */
    void updateSignatureAndEncryptionStateIndicators();

417
418
419
    void confirmBeforeSend();
    void sendNow(bool shortcutUsed);

420
    void updateSignature(uint uoid, uint uOldId);
Laurent Montel's avatar
Laurent Montel committed
421
    Q_REQUIRED_RESULT Kleo::CryptoMessageFormat cryptoMessageFormat() const;
Laurent Montel's avatar
Laurent Montel committed
422
    void printComposeResult(KJob *job, bool preview);
Laurent Montel's avatar
Laurent Montel committed
423
    void printComposer(bool preview);
Volker Krause's avatar
Volker Krause committed
424
425
426
427
428
    /**
     * Install grid management and header fields. If fields exist that
     * should not be there they are removed. Those that are needed are
     * created if necessary.
     */
429
    void rethinkFields(bool fromslot = false, bool forceAllHeaders = false);
Volker Krause's avatar
Volker Krause committed
430
431
432
433

    /**
      Connect signals for moving focus by arrow keys. Returns next edit.
    */
Laurent Montel's avatar
Laurent Montel committed
434
    QWidget *connectFocusMoving(QWidget *prev, QWidget *next);
Volker Krause's avatar
Volker Krause committed
435
436
437
438

    /**
     * Show or hide header lines
     */
Laurent Montel's avatar
Laurent Montel committed
439
    void rethinkHeaderLine(int value, int mask, int &row, QLabel *lbl, QWidget *cbx);
440

Volker Krause's avatar
Volker Krause committed
441
442
443
    /**
     * Apply template to new or unmodified message.
     */
Laurent Montel's avatar
Laurent Montel committed
444
    void applyTemplate(uint uoid, uint uOldId, const KIdentityManagement::Identity &ident, bool wasModified);
Volker Krause's avatar
Volker Krause committed
445
446
447
448

    /**
     * Set the quote prefix according to identity.
     */
Laurent Montel's avatar
Laurent Montel committed
449
    void setQuotePrefix(uint uoid);
Volker Krause's avatar
Volker Krause committed
450
451
452
453
454

    /**
     * Checks how many recipients are and warns if there are too many.
     * @return true, if the user accepted the warning and the message should be sent
    */
Laurent Montel's avatar
Laurent Montel committed
455
    Q_REQUIRED_RESULT bool checkRecipientNumber() const;
Volker Krause's avatar
Volker Krause committed
456
457
458
459
460

    /**
     * Initialization methods
     */
    void setupActions();
461
    void setupStatusBar(QWidget *w);
Volker Krause's avatar
Volker Krause committed
462
463
464
465
466
    void setupEditor();

    /**
     * Header fields.
     */
Laurent Montel's avatar
Laurent Montel committed
467
468
    Q_REQUIRED_RESULT QString subject() const;
    Q_REQUIRED_RESULT QString from() const;
Volker Krause's avatar
Volker Krause committed
469
470
471
472

    /**
     * Ask for confirmation if the message was changed before close.
     */
Laurent Montel's avatar
Laurent Montel committed
473
    Q_REQUIRED_RESULT bool queryClose() override;
Volker Krause's avatar
Volker Krause committed
474
475
476
477
478

    /**
     * Turn encryption on/off. If setByUser is true then a message box is shown
     * in case encryption isn't possible.
     */
Laurent Montel's avatar
Laurent Montel committed
479
    void setEncryption(bool encrypt, bool setByUser = false);
Volker Krause's avatar
Volker Krause committed
480
481
482
483
484

    /**
     * Turn signing on/off. If setByUser is true then a message box is shown
     * in case signing isn't possible.
     */
Laurent Montel's avatar
Laurent Montel committed
485
    void setSigning(bool sign, bool setByUser = false);
Volker Krause's avatar
Volker Krause committed
486

Laurent Montel's avatar
Laurent Montel committed
487
    Q_REQUIRED_RESULT MessageComposer::ComposerViewBase::MissingAttachment userForgotAttachment();
Volker Krause's avatar
Volker Krause committed
488
    /**
489
     * Send the message.
Volker Krause's avatar
Volker Krause committed
490
     */
Laurent Montel's avatar
Laurent Montel committed
491
    void doSend(MessageComposer::MessageSender::SendMethod method = MessageComposer::MessageSender::SendDefault, MessageComposer::MessageSender::SaveIn saveIn = MessageComposer::MessageSender::SaveInNone, bool willSendItWithoutReediting = false);
Volker Krause's avatar
Volker Krause committed
492

Laurent Montel's avatar
Laurent Montel committed
493
    void doDelayedSend(MessageComposer::MessageSender::SendMethod method, MessageComposer::MessageSender::SaveIn saveIn);
494

495
    void changeCryptoAction();
Laurent Montel's avatar
Laurent Montel committed
496
    void applyComposerSetting(MessageComposer::ComposerViewBase *mComposerBase);
Laurent Montel's avatar
Laurent Montel committed
497
498
499
500
501
502
503
    /**
     * Creates a simple composer that creates a KMime::Message out of the composer content.
     * Crypto handling is not done, therefore the name "simple".
     * This is used when autosaving or printing a message.
     *
     * The caller takes ownership of the composer.
     */
Laurent Montel's avatar
Laurent Montel committed
504
    Q_REQUIRED_RESULT MessageComposer::Composer *createSimpleComposer();
505

Laurent Montel's avatar
Laurent Montel committed
506
    bool canSignEncryptAttachments() const;
Laurent Montel's avatar
Laurent Montel committed
507
508

    // helper method for rethinkFields
Laurent Montel's avatar
Laurent Montel committed
509
    int calcColumnWidth(int which, long allShowing, int width) const;
Laurent Montel's avatar
Laurent Montel committed
510

Laurent Montel's avatar
Laurent Montel committed
511
    inline bool encryptToSelf() const;
Volker Krause's avatar
Volker Krause committed
512

Laurent Montel's avatar
Laurent Montel committed
513
private:
514
515
516
517
518
519
    enum CryptoKeyState {
        NoState = 0,
        InProgress,
        KeyOk,
        NoKey
    };
520
521
    void slotToggleMenubar(bool dontShowWarning);

522
    void slotCryptoModuleSelected();
Laurent Montel's avatar
Laurent Montel committed
523
    void slotFccIsInvalid();
524
    void slotIdentityDeleted(uint uoid);
525
    void slotInvalidIdentity();
526
    void slotTransportRemoved(int id, const QString &name);
Laurent Montel's avatar
Laurent Montel committed
527

Laurent Montel's avatar
Laurent Montel committed
528
529
    void updateComposerAfterIdentityChanged(const KIdentityManagement::Identity &ident, uint uoid, bool wasModified);

Laurent Montel's avatar
Laurent Montel committed
530
    void insertUrls(const QMimeData *source, const QList<QUrl> &urlList);
Laurent Montel's avatar
Laurent Montel committed
531
    void initializePluginActions();
532
533
    bool showErrorMessage(KJob *job);
    Q_REQUIRED_RESULT int validateLineWrapWidth() const;
534
    void slotSelectionChanged();
Laurent Montel's avatar
Laurent Montel committed
535
    void slotMessage(const QString &str);
536
    void slotEditorPluginInsertText(const QString &str);
Laurent Montel's avatar
Laurent Montel committed
537
    void insertSnippetInfo(const MailCommon::SnippetInfo &info);
Laurent Montel's avatar
Laurent Montel committed
538
    Q_REQUIRED_RESULT bool sendLaterRegistered() const;
Laurent Montel's avatar
Laurent Montel committed
539

Laurent Montel's avatar
Minor    
Laurent Montel committed
540
541
542
    Akonadi::Collection mCollectionForNewMessage;
    QMap<QByteArray, QString> mExtraHeaders;

Laurent Montel's avatar
Laurent Montel committed
543
544
545
546
547
548
549
550
551
552
553
554
    QWidget *mMainWidget = nullptr;
    MessageComposer::ComposerLineEdit *mEdtFrom = nullptr;
    PimCommon::LineEditWithAutoCorrection *mEdtSubject = nullptr;
    QLabel *mLblIdentity = nullptr;
    QLabel *mLblTransport = nullptr;
    QLabel *mLblFcc = nullptr;
    QLabel *mLblFrom = nullptr;
    QLabel *mLblSubject = nullptr;
    QLabel *mDictionaryLabel = nullptr;
    QLabel *mCursorLineLabel = nullptr;
    QLabel *mCursorColumnLabel = nullptr;
    QLabel *mStatusbarLabel = nullptr;
555
    bool mDone = false;
Volker Krause's avatar
Volker Krause committed
556

557
    KMime::Message::Ptr mMsg;
Laurent Montel's avatar
Laurent Montel committed
558
    QGridLayout *mGrid = nullptr;
Laurent Montel's avatar
Laurent Montel committed
559
560
    const QString mTextSelection;
    const QString mCustomTemplate;
561
562
563
564
565
    bool mLastSignActionState = false;
    bool mLastEncryptActionState = false;
    bool mSigningAndEncryptionExplicitlyDisabled = false;
    bool mLastIdentityHasSigningKey = false;
    bool mLastIdentityHasEncryptionKey = false;
566
    Akonadi::Collection mFolder;
Laurent Montel's avatar
Laurent Montel committed
567
    long mShowHeaders = 0;
568
    bool mForceDisableHtml = false;     // Completely disable any HTML. Useful when sending invitations in the
Laurent Montel's avatar
Laurent Montel committed
569
    // mail body.
Laurent Montel's avatar
Laurent Montel committed
570
    int mNumHeaders = 0;
571
572
    QFont mBodyFont;
    QFont mFixedFont;
Laurent Montel's avatar
Laurent Montel committed
573
    uint mId = 0;
Laurent Montel's avatar
Laurent Montel committed
574
    const TemplateContext mContext = NoTemplate;
Volker Krause's avatar
Volker Krause committed
575

Laurent Montel's avatar
Laurent Montel committed
576
577
578
579
580
    KRecentFilesAction *mRecentAction = nullptr;

    KToggleAction *mSignAction = nullptr;
    KToggleAction *mEncryptAction = nullptr;
    KToggleAction *mRequestMDNAction = nullptr;
581
    KToggleAction *mRequestDeliveryConfirmation = nullptr;
Laurent Montel's avatar
Laurent Montel committed
582
583
584
585
586
587
588
589
590
591
592
593
    KToggleAction *mUrgentAction = nullptr;
    KToggleAction *mAllFieldsAction = nullptr;
    KToggleAction *mFromAction = nullptr;
    KToggleAction *mSubjectAction = nullptr;
    KToggleAction *mIdentityAction = nullptr;
    KToggleAction *mTransportAction = nullptr;
    KToggleAction *mFccAction = nullptr;
    KToggleAction *mWordWrapAction = nullptr;
    KToggleAction *mFixedFontAction = nullptr;
    KToggleAction *mAutoSpellCheckingAction = nullptr;
    KToggleAction *mDictionaryAction = nullptr;
    KToggleAction *mSnippetAction = nullptr;
594
    KToggleAction *mHideMenuBarAction = nullptr;
Laurent Montel's avatar
Laurent Montel committed
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
    QAction *mAppendSignature = nullptr;
    QAction *mPrependSignature = nullptr;
    QAction *mInsertSignatureAtCursorPosition = nullptr;

    KToggleAction *mMarkupAction = nullptr;

    CodecAction *mCodecAction = nullptr;
    KSelectAction *mCryptoModuleAction = nullptr;

    QAction *mFindText = nullptr;
    QAction *mFindNextText = nullptr;
    QAction *mReplaceText = nullptr;
    QAction *mSelectAll = nullptr;

    QSplitter *mHeadersToEditorSplitter = nullptr;
    QWidget *mHeadersArea = nullptr;
    QSplitter *mSplitter = nullptr;
    QSplitter *mSnippetSplitter = nullptr;
    QByteArray mOriginalPreferredCharset = nullptr;

    MessageComposer::Composer *mDummyComposer = nullptr;
616
    // used for auto saving, printing, etc. Not for sending, which happens in ComposerViewBase
Laurent Montel's avatar
Laurent Montel committed
617
    QVector< MessageComposer::Composer * > mMiscComposers;
Volker Krause's avatar
Volker Krause committed
618

619
    int mLabelWidth = 0;
Volker Krause's avatar
Volker Krause committed
620
621
622

    QString mdbusObjectPath;
    static int s_composerNumber;
Laurent Montel's avatar
Laurent Montel committed
623
    QMetaObject::Connection mIdentityConnection;
624
    QMetaObject::Connection mUpdateWindowTitleConnection;
Volker Krause's avatar
Volker Krause committed
625

Laurent Montel's avatar
Laurent Montel committed
626
    MessageComposer::ComposerViewBase *mComposerBase = nullptr;
Volker Krause's avatar
Volker Krause committed
627

Laurent Montel's avatar
Laurent Montel committed
628
    MailCommon::SnippetTreeView *mSnippetWidget = nullptr;
Laurent Montel's avatar
Laurent Montel committed
629
630
631
632
633
    PimCommon::CustomToolsWidgetNg *mCustomToolsWidget = nullptr;
    AttachmentMissingWarning *mAttachmentMissing = nullptr;
    ExternalEditorWarning *mExternalEditorWarning = nullptr;
    QTimer *mVerifyMissingAttachment = nullptr;
    MailCommon::FolderRequester *mFccFolder = nullptr;
634
    bool mPreventFccOverwrite = false;
635
    bool mCheckForForgottenAttachments = true;
636
    bool mWasModified = false;
Laurent Montel's avatar
Laurent Montel committed
637
    CryptoStateIndicatorWidget *mCryptoStateIndicatorWidget = nullptr;
638
    bool mSendNowByShortcutUsed = false;
Laurent Montel's avatar
Laurent Montel committed
639
640
    KSplitterCollapserButton *mSnippetSplitterCollapser = nullptr;
    KToggleAction *mFollowUpToggleAction = nullptr;
641
642
    MessageComposer::StatusBarLabelToggledState *mStatusBarLabelToggledOverrideMode = nullptr;
    MessageComposer::StatusBarLabelToggledState *mStatusBarLabelSpellCheckingChangeMode = nullptr;
Laurent Montel's avatar
Laurent Montel committed
643
    PotentialPhishingEmailWarning *mPotentialPhishingEmailWarning = nullptr;
644
    IncorrectIdentityFolderWarning *mIncorrectIdentityFolderWarning = nullptr;
Laurent Montel's avatar
Laurent Montel committed
645
646
647
648
649
650
    KMComposerGlobalAction *mGlobalAction = nullptr;
    KPIMTextEdit::RichTextEditorWidget *mRichTextEditorwidget = nullptr;

    KMailPluginEditorManagerInterface *mPluginEditorManagerInterface = nullptr;
    KMailPluginEditorCheckBeforeSendManagerInterface *mPluginEditorCheckBeforeSendManagerInterface = nullptr;
    KMailPluginEditorInitManagerInterface *mPluginEditorInitManagerInterface = nullptr;
Laurent Montel's avatar
Laurent Montel committed
651
    KMailPluginEditorConvertTextManagerInterface *mPluginEditorConvertTextManagerInterface = nullptr;
652
    KMailPluginGrammarEditorManagerInterface *mPluginEditorGrammarManagerInterface = nullptr;
653
654

    AttachmentAddedFromExternalWarning *mAttachmentFromExternalMissing = nullptr;
Volker Krause's avatar
Volker Krause committed
655
656
657
};

#endif