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

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

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

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

Volker Krause's avatar
Volker Krause committed
33
// Other includes
Laurent Montel's avatar
Laurent Montel committed
34
#include <Libkleo/Enum>
Volker Krause's avatar
Volker Krause committed
35

Laurent Montel's avatar
Laurent Montel committed
36 37
class QUrl;

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

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

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

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

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

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

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

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

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

Laurent Montel's avatar
Laurent Montel committed
109
    friend class ::KMComposerEditor;
Volker Krause's avatar
Volker Krause committed
110

Laurent Montel's avatar
Laurent Montel committed
111
private: // mailserviceimpl, kmkernel, kmcommands, callback, kmmainwidget
Laurent Montel's avatar
Laurent Montel committed
112
    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
113
    ~KMComposerWin() override;
Volker Krause's avatar
Volker Krause committed
114

Laurent Montel's avatar
Laurent Montel committed
115
public:
Laurent Montel's avatar
Laurent Montel committed
116
    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
117

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

Laurent Montel's avatar
Laurent Montel committed
121
    /**
Laurent Montel's avatar
Laurent Montel committed
122 123 124
    * 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
125
public Q_SLOTS:
Volker Krause's avatar
Volker Krause committed
126

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

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

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

Laurent Montel's avatar
Laurent Montel committed
136
    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
137

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

Laurent Montel's avatar
Laurent Montel committed
141
public: // kmkernel, kmcommands, callback
Volker Krause's avatar
Volker Krause committed
142 143 144 145
    /**
     * 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
146
    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
147

148
    void setCurrentTransport(int transportId) override;
149

150 151 152 153 154
    /**
     * 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.
     */
155
    void setFcc(const QString &idString) override;
156

Laurent Montel's avatar
Laurent Montel committed
157
    /**
Volker Krause's avatar
Volker Krause committed
158 159 160 161
      * 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.
      */
162
    void disableWordWrap() override;
Volker Krause's avatar
Volker Krause committed
163

Laurent Montel's avatar
Laurent Montel committed
164
    /**
Volker Krause's avatar
Volker Krause committed
165 166 167 168 169 170
      * 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.
      */
171
    void forceDisableHtml() override;
Volker Krause's avatar
Volker Krause committed
172

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

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

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

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

198
    void setCollectionForNewMessage(const Akonadi::Collection &folder) override;
199

200
    void addExtraCustomHeaders(const QMap<QByteArray, QString> &header) override;
201

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

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

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

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

Laurent Montel's avatar
Laurent Montel committed
235
private Q_SLOTS:
Laurent Montel's avatar
Laurent Montel committed
236
    /**
237 238 239
      * 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
240
    void disableHtml(MessageComposer::ComposerViewBase::Confirmation confirmation);
241 242 243 244 245
    /**
     * Enables HTML mode, by showing the HTML toolbar and checking the
     * "Formatting" action
     */
    void enableHtml();
Volker Krause's avatar
Volker Krause committed
246 247 248 249 250

    /**
     * Actions:
     */
    void slotPrint();
251 252
    void slotPrintPreview();

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

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

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

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

    /**
     * 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.
     */
297
    void slotSelectCryptoModule(bool init);
Volker Krause's avatar
Volker Krause committed
298 299 300 301 302 303 304 305 306 307 308

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

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

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

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

Laurent Montel's avatar
Laurent Montel committed
322
    void slotUpdateView();
Volker Krause's avatar
Volker Krause committed
323 324 325

    /**
     * Update composer field to reflect new identity
Volker Krause's avatar
Volker Krause committed
326 327 328
     * @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
329
     */
Laurent Montel's avatar
Laurent Montel committed
330
    void slotIdentityChanged(uint uoid, bool initalChange = false);
Volker Krause's avatar
Volker Krause committed
331 332 333

    void slotCursorPositionChanged();

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

Laurent Montel's avatar
Laurent Montel committed
336
    void slotDelayedApplyTemplate(KJob *);
Laurent Montel's avatar
Laurent Montel committed
337

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

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

Laurent Montel's avatar
Laurent Montel committed
345 346
    void slotPrintComposeResult(KJob *job);

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

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

Laurent Montel's avatar
Laurent Montel committed
355 356
    void showAndActivateComposer() override;

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

362
    void slotAttachMissingFile();
363
    void slotExplicitClosedMissingAttachment();
364
    void slotVerifyMissingAttachmentTimeout();
365
    void slotCheckSendNow();
366

367 368
    void slotExternalEditorStarted();
    void slotExternalEditorClosed();
369

Laurent Montel's avatar
Laurent Montel committed
370 371
    void slotInsertShortUrl(const QString &url);

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

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

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

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

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

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

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

415 416 417
    void confirmBeforeSend();
    void sendNow(bool shortcutUsed);

418
    void updateSignature(uint uoid, uint uOldId);
Laurent Montel's avatar
Laurent Montel committed
419
    Q_REQUIRED_RESULT Kleo::CryptoMessageFormat cryptoMessageFormat() const;
Laurent Montel's avatar
Laurent Montel committed
420
    void printComposeResult(KJob *job, bool preview);
Laurent Montel's avatar
Laurent Montel committed
421
    void printComposer(bool preview);
Volker Krause's avatar
Volker Krause committed
422 423 424 425 426
    /**
     * 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.
     */
427
    void rethinkFields(bool fromslot = false, bool forceAllHeaders = false);
Volker Krause's avatar
Volker Krause committed
428 429 430 431

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

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

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

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

    /**
     * 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
453
    Q_REQUIRED_RESULT bool checkRecipientNumber() const;
Volker Krause's avatar
Volker Krause committed
454 455 456 457 458

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

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

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

    /**
     * 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
477
    void setEncryption(bool encrypt, bool setByUser = false);
Volker Krause's avatar
Volker Krause committed
478 479 480 481 482

    /**
     * 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
483
    void setSigning(bool sign, bool setByUser = false);
Volker Krause's avatar
Volker Krause committed
484

Laurent Montel's avatar
Laurent Montel committed
485
    Q_REQUIRED_RESULT MessageComposer::ComposerViewBase::MissingAttachment userForgotAttachment();
Volker Krause's avatar
Volker Krause committed
486
    /**
487
     * Send the message.
Volker Krause's avatar
Volker Krause committed
488
     */
Laurent Montel's avatar
Laurent Montel committed
489
    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
490

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

493
    void changeCryptoAction();
Laurent Montel's avatar
Laurent Montel committed
494
    void applyComposerSetting(MessageComposer::ComposerViewBase *mComposerBase);
Laurent Montel's avatar
Laurent Montel committed
495 496 497 498 499 500 501
    /**
     * 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
502
    Q_REQUIRED_RESULT MessageComposer::Composer *createSimpleComposer();
503

Laurent Montel's avatar
Laurent Montel committed
504
    bool canSignEncryptAttachments() const;
Laurent Montel's avatar
Laurent Montel committed
505 506

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

Laurent Montel's avatar
Laurent Montel committed
509
    inline bool encryptToSelf() const;
Volker Krause's avatar
Volker Krause committed
510

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

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

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

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

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

Laurent Montel's avatar
Laurent Montel committed
541 542 543 544 545 546 547 548 549 550 551 552
    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;
553
    bool mDone = false;
Volker Krause's avatar
Volker Krause committed
554

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

Laurent Montel's avatar
Laurent Montel committed
574 575 576 577 578
    KRecentFilesAction *mRecentAction = nullptr;

    KToggleAction *mSignAction = nullptr;
    KToggleAction *mEncryptAction = nullptr;
    KToggleAction *mRequestMDNAction = nullptr;
579
    KToggleAction *mRequestDeliveryConfirmation = nullptr;
Laurent Montel's avatar
Laurent Montel committed
580 581 582 583 584 585 586 587 588 589 590 591
    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;
592
    KToggleAction *mHideMenuBarAction = nullptr;
Laurent Montel's avatar
Laurent Montel committed
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
    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;
614
    // used for auto saving, printing, etc. Not for sending, which happens in ComposerViewBase
Laurent Montel's avatar
Laurent Montel committed
615
    QVector< MessageComposer::Composer * > mMiscComposers;
Volker Krause's avatar
Volker Krause committed
616

617
    int mLabelWidth = 0;
Volker Krause's avatar
Volker Krause committed
618 619 620

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

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

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

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

    AttachmentAddedFromExternalWarning *mAttachmentFromExternalMissing = nullptr;
Volker Krause's avatar
Volker Krause committed
653 654 655
};

#endif