Fix confusing checkbox text due to class reuse
[kdepim.git] / kmail / kmcomposewin.h
blob33f6a1e229c4239547b94ae31175536016adf000
1 /*
2 * This file is part of KMail.
3 * Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
5 * Based on KMail code by:
6 * Copyright (c) 1997 Markus Wuebben <markus.wuebben@kde.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #ifndef __KMComposeWin
24 #define __KMComposeWin
26 // KMail includes
27 #include "composer.h"
28 #include "recipientseditor.h"
30 // Qt includes
31 #include <QFont>
32 #include <QList>
33 #include <QPalette>
35 // KDE includes
36 #include <kglobalsettings.h>
38 // LIBKDEPIM includes
39 #include <messagecomposer/kmeditor.h>
41 #include "messagecomposer/messagesender.h"
43 // KDEPIMLIBS includes
44 #include <kmime/kmime_message.h>
45 #include <kmime/kmime_headers.h>
47 // Other includes
48 #include "kleo/enum.h"
49 #include <composerviewbase.h>
51 class QByteArray;
52 class QCheckBox;
53 class QComboBox;
54 class QGridLayout;
55 class QLabel;
56 class QPushButton;
57 class QSplitter;
59 class CodecAction;
60 class KLineEdit;
61 class KMComposeWin;
62 class KMComposerEditor;
63 class KSelectAction;
64 class KSelectAction;
65 class KAction;
66 class KJob;
67 class KToggleAction;
68 class KTemporaryFile;
69 class KTempDir;
70 class KToggleAction;
71 class KUrl;
72 class KRecentFilesAction;
73 class SnippetWidget;
75 namespace boost {
76 template <typename T> class shared_ptr;
79 namespace Sonnet {
80 class DictionaryComboBox;
83 namespace KPIMIdentities {
84 class Identity;
87 namespace Akonadi {
88 class CollectionComboBox;
92 namespace KMail {
93 class AttachmentController;
94 class AttachmentView;
97 namespace KIO {
98 class Job;
101 namespace Message {
102 class Composer;
105 namespace MessageComposer
107 class ComposerLineEdit;
110 //-----------------------------------------------------------------------------
111 class KMComposeWin : public KMail::Composer
113 Q_OBJECT
114 Q_CLASSINFO("D-Bus Interface", "org.kde.kmail.mailcomposer")
116 friend class ::KMComposerEditor;
118 private: // mailserviceimpl, kmkernel, kmcommands, callback, kmmainwidget
119 explicit KMComposeWin( const KMime::Message::Ptr &msg = KMime::Message::Ptr(), TemplateContext context = NoTemplate,
120 uint identity = 0, const QString & textSelection = QString(),
121 const QString & customTemplate = QString() );
122 ~KMComposeWin();
124 public:
125 static Composer *create( const KMime::Message::Ptr &msg = KMime::Message::Ptr(), TemplateContext context = NoTemplate,
126 uint identity = 0, const QString & textSelection = QString(),
127 const QString & customTemplate = QString() );
129 QString dbusObjectPath() const;
130 QString smartQuote( const QString & msg );
133 * Start of D-Bus callable stuff. The D-Bus methods need to be public slots,
134 * otherwise they can't be accessed.
136 // TODO clean-up dbus stuff; make the adaptor a friend; etc.
137 public slots:
139 Q_SCRIPTABLE void send( int how );
141 Q_SCRIPTABLE void addAttachmentsAndSend( const KUrl::List & urls,
142 const QString & comment,
143 int how );
145 Q_SCRIPTABLE void addAttachment( const KUrl & url,
146 const QString & comment );
148 Q_SCRIPTABLE void addAttachment( const QString & name,
149 KMime::Headers::contentEncoding cte,
150 const QString& charset,
151 const QByteArray & data,
152 const QByteArray & mimeType );
155 * End of D-Bus callable stuff
158 signals:
159 void identityChanged( const KPIMIdentities::Identity &identity );
161 private:
164 * Write settings to app's config file.
166 void writeConfig( void );
168 public: // kmkernel, kmcommands, callback
170 * Set the message the composer shall work with. This discards
171 * previous messages without calling applyChanges() on them before.
173 void setMsg( const KMime::Message::Ptr &newMsg, bool mayAutoSign=true,
174 bool allowDecryption=false, bool isModified=false );
177 * Disables word wrap completely. No wrapping at all will occur, not even
178 * at the right end of the editor.
179 * This is useful when sending invitations.
181 void disableWordWrap();
184 * Disables HTML completely. It disables HTML at the point of calling this and disables it
185 * again when sending the message, to be sure. Useful when sending invitations.
186 * This will <b>not</b> remove the actions for activating HTML mode again, it is only
187 * meant for automatic invitation sending.
188 * Also calls @sa disableHtml() internally.
190 void forceDisableHtml();
193 * Returns @c true while the message composing is in progress.
195 bool isComposing() const { return mComposerBase && mComposerBase->isComposing(); }
198 * Set the text selection the message is a response to.
200 void setTextSelection( const QString& selection );
203 * Set custom template to be used for the message.
205 void setCustomTemplate( const QString& customTemplate );
207 private: // kmedit
209 * Returns message of the composer. To apply the user changes to the
210 * message, call applyChanges() first.
212 KMime::Message::Ptr msg() const { return mMsg; }
214 private:
216 * Returns true if the message was modified by the user.
218 bool isModified() const;
220 public: // kmcommand
222 * If this folder is set, the original message is inserted back after
223 * canceling
225 void setFolder(const Akonadi::Collection &aFolder ) { mFolder = aFolder; }
227 public: // kmcommand
229 * Sets the focus to the edit-widget.
231 void setReplyFocus( bool hasMessage = true );
234 * Sets the focus to the subject line edit. For use when creating a
235 * message to a known recipient.
237 void setFocusToSubject();
239 private:
241 * determines whether inline signing/encryption is selected
243 bool inlineSigningEncryptionSelected();
247 * Tries to find the given mimetype @p type in the KDE Mimetype registry.
248 * If found, returns its localized description, otherwise the @p type
249 * in lowercase.
251 static QString prettyMimeType( const QString &type );
253 public: // callback
254 /** Disabled signing and encryption completely for this composer window. */
255 void setSigningAndEncryptionDisabled( bool v )
257 mSigningAndEncryptionExplicitlyDisabled = v;
260 private slots:
262 * Disables the HTML mode, by hiding the HTML toolbar and unchecking the
263 * "Formatting" action. Also, removes all rich-text formatting.
265 void disableHtml( Message::ComposerViewBase::Confirmation confirmation );
267 * Enables HTML mode, by showing the HTML toolbar and checking the
268 * "Formatting" action
270 void enableHtml();
273 * Actions:
275 void slotPrint();
276 void slotInsertRecentFile( const KUrl & );
277 void slotRecentListFileClear();
279 public slots: // kmkernel, callback
280 void slotSendNow();
282 private slots:
283 void slotSendNowVia( QAction * );
284 void slotSendLater();
285 void slotSendLaterVia( QAction * );
286 void getTransportMenu();
289 * Returns true when saving was successful.
291 void slotSaveDraft();
292 void slotSaveTemplate();
293 void slotNewComposer();
294 void slotNewMailReader();
295 void slotClose();
296 void slotHelp();
297 void slotUndo();
298 void slotRedo();
299 void slotCut();
300 void slotCopy();
301 void slotPaste();
302 void slotPasteAsAttachment();
303 void slotFormatReset();
304 void slotMarkAll();
306 void slotFolderRemoved( const Akonadi::Collection& );
307 void slotLanguageChanged( const QString &language );
309 void slotEditorTextChanged();
311 public slots: // kmkernel
313 Tell the composer to always send the message, even if the user
314 hasn't changed the next. This is useful if a message is
315 autogenerated (e.g., via a D-Bus call), and the user should
316 simply be able to confirm the message and send it.
318 void slotSetAlwaysSend( bool bAlwaysSend );
320 private slots:
322 * toggle fixed width font.
324 void slotUpdateFont();
327 * Open addressbook editor dialog.
329 void slotAddrBook();
332 * Insert a file to the end of the text in the editor.
334 void slotInsertFile();
337 * Check spelling of text.
339 void slotSpellcheckConfig();
342 * Change crypto plugin to be used for signing/encrypting messages,
343 * or switch to built-in OpenPGP code.
345 void slotSelectCryptoModule( bool init = false );
348 * XML-GUI stuff
350 void slotEditToolbars();
351 void slotUpdateToolbars();
352 void slotEditKeys();
355 * Read settings from app's config file.
357 void readConfig( bool reload = false );
360 * Change window title to given string.
362 void slotUpdWinTitle( const QString & );
365 * Switch the icon to lock or unlock respectivly.
366 * Change states of all encrypt check boxes in the attachments listview
368 void slotEncryptToggled( bool );
371 * Change states of all sign check boxes in the attachments listview
373 void slotSignToggled( bool );
375 public slots: // kmkernel, callback
377 * Switch wordWrap on/off
379 void slotWordWrapToggled( bool );
381 private slots:
382 void slotToggleMarkup();
383 void slotTextModeChanged( KRichTextEdit::Mode );
384 void htmlToolBarVisibilityChanged( bool visible );
385 void slotSpellcheckDoneClearStatus();
387 public slots: // kmkernel
388 void autoSaveMessage();
391 * Set whether the message should be treated as modified or not.
393 void setModified( bool modified );
395 private slots:
397 void slotView();
400 * Update composer field to reflect new identity
401 * @param initalChange if true, don't apply the template. This is useful when calling
402 * this function from setMsg(), because there, the message already has the
403 * template, and we want to avoid calling the template parser unnecessarily.
405 void slotIdentityChanged( uint uoid, bool initalChange = false );
407 void slotCursorPositionChanged();
409 void slotSpellCheckingStatus( const QString & status );
411 void slotDelayedApplyTemplate( KJob* );
413 public: // kmcommand
414 // FIXME we need to remove these, but they're pure virtual in Composer.
415 void addAttach( KMime::Content *msgPart );
417 public: // AttachmentController
418 const KPIMIdentities::Identity &identity() const;
420 public:
421 /** Don't check if there are too many recipients for a mail, eg. when sending out invitations. */
422 virtual void disableRecipientNumberCheck();
424 /** Don't check for forgotten attachments for a mail, eg. when sending out invitations. */
425 void disableForgottenAttachmentsCheck();
428 * Ignore the "sticky" setting of the transport combo box and prefer the X-KMail-Transport
429 * header field of the message instead.
430 * Do the same for the identity combo box, don't obey the "sticky" setting but use the
431 * X-KMail-Identity header field instead.
433 * This is useful when sending out invitations, since you don't see the GUI and want the
434 * identity and transport to be set to the values stored in the messages.
436 void ignoreStickyFields();
438 private:
439 Kleo::CryptoMessageFormat cryptoMessageFormat() const;
441 private:
443 * Install grid management and header fields. If fields exist that
444 * should not be there they are removed. Those that are needed are
445 * created if necessary.
447 void rethinkFields( bool fromslot=false );
450 Connect signals for moving focus by arrow keys. Returns next edit.
452 QWidget *connectFocusMoving( QWidget *prev, QWidget *next );
455 * Show or hide header lines
458 void rethinkHeaderLine( int aValue, int aMask, int &aRow,
459 QLabel *aLbl, KLineEdit *aEdt,
460 QPushButton *aBtn = 0 );
462 void rethinkHeaderLine( int value, int mask, int &row,
463 QLabel *lbl, QComboBox *cbx, QCheckBox *chk ); // krazy:exclude=qclasses
466 * Apply template to new or unmodified message.
468 void applyTemplate( uint uoid );
471 * Set the quote prefix according to identity.
473 void setQuotePrefix( uint uoid );
476 * Checks how many recipients are and warns if there are too many.
477 * @return true, if the user accepted the warning and the message should be sent
479 bool checkRecipientNumber() const;
481 bool checkTransport() const;
483 * Initialization methods
485 void setupActions();
486 void setupStatusBar();
487 void setupEditor();
490 * Header fields.
492 QString subject() const;
493 QString from() const;
494 QString replyTo() const;
497 * Use the given folder as sent-mail folder if the given folder exists.
498 * Else show an error message and use the default sent-mail folder as
499 * sent-mail folder.
501 void setFcc( const QString &idString );
503 void setCharset( const QByteArray &charset );
504 void setAutoCharset();
507 * Ask for confirmation if the message was changed before close.
509 virtual bool queryClose();
512 * prevent kmail from exiting when last window is deleted (kernel rules)
514 virtual bool queryExit();
516 private:
518 * Turn encryption on/off. If setByUser is true then a message box is shown
519 * in case encryption isn't possible.
521 void setEncryption( bool encrypt, bool setByUser = false );
524 * Turn signing on/off. If setByUser is true then a message box is shown
525 * in case signing isn't possible.
527 void setSigning( bool sign, bool setByUser = false );
530 Returns true if the user forgot to attach something.
532 bool userForgotAttachment();
535 * Decrypt an OpenPGP block or strip off the OpenPGP envelope of a text
536 * block with a clear text signature. This is only done if the given
537 * string contains exactly one OpenPGP block.
538 * This function is for example used to restore the unencrypted/unsigned
539 * message text for editting.
541 static void decryptOrStripOffCleartextSignature( QByteArray & );
544 * Send the message.
546 void doSend( MessageSender::SendMethod method=MessageSender::SendDefault,
547 MessageSender::SaveIn saveIn = MessageSender::SaveInNone );
549 void doDelayedSend( MessageSender::SendMethod method, MessageSender::SaveIn saveIn );
551 void changeCryptoAction();
554 private slots:
555 void recipientEditorSizeHintChanged();
556 void setMaximumHeaderSize();
557 void slotDoDelayedSend( KJob* );
559 private:
560 QWidget *mMainWidget;
561 Sonnet::DictionaryComboBox *mDictionaryCombo;
562 Akonadi::CollectionComboBox *mFcc;
563 MessageComposer::ComposerLineEdit *mEdtFrom, *mEdtReplyTo;
564 MessageComposer::ComposerLineEdit *mEdtSubject;
565 QLabel *mLblIdentity, *mLblTransport, *mLblFcc;
566 QLabel *mLblFrom, *mLblReplyTo;
567 QLabel *mLblSubject;
568 QLabel *mDictionaryLabel;
569 QCheckBox *mBtnIdentity, *mBtnDictionary, *mBtnTransport, *mBtnFcc;
570 bool mDone;
572 KMime::Message::Ptr mMsg;
573 QGridLayout *mGrid;
574 QString mTextSelection;
575 QString mCustomTemplate;
576 QAction *mOpenId, *mViewId, *mRemoveId, *mSaveAsId, *mPropertiesId,
577 *mEditAction, *mEditWithAction;
578 bool mLastSignActionState, mLastEncryptActionState, mSigningAndEncryptionExplicitlyDisabled;
579 bool mLastIdentityHasSigningKey, mLastIdentityHasEncryptionKey;
580 Akonadi::Collection mFolder;
581 long mShowHeaders;
582 bool mConfirmSend;
583 //bool mDisableBreaking;
584 bool mForceDisableHtml; // Completely disable any HTML. Useful when sending invitations in the
585 // mail body.
586 int mNumHeaders;
587 QFont mBodyFont, mFixedFont;
588 QPalette mPalette;
589 uint mId;
590 TemplateContext mContext;
592 KAction *mCleanSpace;
593 KRecentFilesAction *mRecentAction;
595 KToggleAction *mSignAction, *mEncryptAction, *mRequestMDNAction;
596 KToggleAction *mUrgentAction, *mAllFieldsAction, *mFromAction;
597 KToggleAction *mReplyToAction;
598 KToggleAction *mSubjectAction;
599 KToggleAction *mIdentityAction, *mTransportAction, *mFccAction;
600 KToggleAction *mWordWrapAction, *mFixedFontAction, *mAutoSpellCheckingAction;
601 KToggleAction *mDictionaryAction, *mSnippetAction;
603 KToggleAction *markupAction;
604 KAction *actionFormatReset;
606 CodecAction *mCodecAction;
607 KSelectAction *mCryptoModuleAction;
609 KAction *mFindText, *mFindNextText, *mReplaceText, *mSelectAll;
611 bool mAlwaysSend;
613 QStringList mFolderNames;
615 private:
618 * Creates a simple composer that creates a KMime::Message out of the composer content.
619 * Crypto handling is not done, therefore the name "simple".
620 * This is used when autosaving or printing a message.
622 * The caller takes ownership of the composer.
624 Message::Composer* createSimpleComposer();
626 bool canSignEncryptAttachments() const {
627 return cryptoMessageFormat() != Kleo::InlineOpenPGPFormat;
630 QString addQuotesToText( const QString &inputText ) const;
631 // helper method for rethinkFields
632 int calcColumnWidth( int which, long allShowing, int width ) const;
635 /** Initialize header fields. Should be called on new messages
636 if they are not set manually. E.g. before composing. Calling
637 of setAutomaticFields(), see below, is still required. */
638 void initHeader( KMime::Message *message, uint identity=0 );
641 * Helper methods to read from config various encryption settings
643 inline bool encryptToSelf();
644 inline bool showKeyApprovalDialog();
645 inline int encryptKeyNearExpiryWarningThresholdInDays();
646 inline int signingKeyNearExpiryWarningThresholdInDays();
647 inline int encryptRootCertNearExpiryWarningThresholdInDays();
648 inline int signingRootCertNearExpiryWarningThresholdInDays();
649 inline int encryptChainCertNearExpiryWarningThresholdInDays();
650 inline int signingChainCertNearExpiryWarningThresholdInDays();
652 private slots:
653 void slotCompletionModeChanged( KGlobalSettings::Completion );
654 void slotConfigChanged();
656 void slotPrintComposeResult( KJob *job );
658 void slotEncryptChiasmusToggled( bool );
660 void slotSendFailed( const QString& msg );
661 void slotSendSuccessful();
664 * toggle automatic spellchecking
666 void slotAutoSpellCheckingToggled( bool );
669 * Updates the visibility and text of the signature and encryption state indicators.
671 void slotUpdateSignatureAndEncrypionStateIndicators();
673 virtual void setAutoSaveFileName( const QString& fileName );
674 private:
675 QFont mSaveFont;
676 QSplitter *mHeadersToEditorSplitter;
677 QWidget* mHeadersArea;
678 QSplitter *mSplitter;
679 QSplitter *mSnippetSplitter;
680 KMail::AttachmentView *mAttachmentView;
681 QByteArray mOriginalPreferredCharset;
683 // These are for passing on methods over the applyChanges calls
684 MessageSender::SendMethod mSendMethod;
685 MessageSender::SaveIn mSaveIn;
687 KToggleAction *mEncryptChiasmusAction;
688 bool mEncryptWithChiasmus;
690 Message::Composer *mDummyComposer;
691 int mPendingQueueJobs;
692 int mPendingCreateItemJobs;
693 // used for auto saving, printing, etc. Not for sending, which happens in ComposerViewBase
694 QList< Message::Composer* > mMiscComposers;
696 int mLabelWidth;
698 QMenu *mActNowMenu;
699 QMenu *mActLaterMenu;
701 QString mdbusObjectPath;
702 static int s_composerNumber;
704 Message::ComposerViewBase* mComposerBase;
707 SnippetWidget *mSnippetWidget;
708 QList<KTempDir*> mTempDirs;
710 QLabel *mSignatureStateIndicator;
711 QLabel *mEncryptionStateIndicator;
713 bool mPreventFccOverwrite;
714 bool mCheckForForgottenAttachments;
715 bool mIgnoreStickyFields;
718 #endif