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
28 #include "recipientseditor.h"
35 #include <kglobalsettings.h>
38 #include <messagecomposer/kmeditor.h>
40 #include "messagecomposer/messagesender.h"
42 // KDEPIMLIBS includes
43 #include <kmime/kmime_message.h>
44 #include <kmime/kmime_headers.h>
47 #include "kleo/enum.h"
48 #include <composerviewbase.h>
61 class KMComposerEditor
;
71 class KRecentFilesAction
;
75 template <typename T
> class shared_ptr
;
79 class DictionaryComboBox
;
82 namespace KPIMIdentities
{
87 class CollectionComboBox
;
92 class AttachmentController
;
101 class KMSubjectLineEdit
;
104 namespace MessageComposer
106 class ComposerLineEdit
;
109 //-----------------------------------------------------------------------------
110 class KMComposeWin
: public KMail::Composer
113 Q_CLASSINFO("D-Bus Interface", "org.kde.kmail.mailcomposer")
115 friend class ::KMComposerEditor
;
117 private: // mailserviceimpl, kmkernel, kmcommands, callback, kmmainwidget
118 explicit KMComposeWin( const KMime::Message::Ptr
&msg
= KMime::Message::Ptr(), TemplateContext context
= NoTemplate
,
119 uint identity
= 0, const QString
& textSelection
= QString(),
120 const QString
& customTemplate
= QString() );
124 static Composer
*create( const KMime::Message::Ptr
&msg
= KMime::Message::Ptr(), TemplateContext context
= NoTemplate
,
125 uint identity
= 0, const QString
& textSelection
= QString(),
126 const QString
& customTemplate
= QString() );
128 QString
dbusObjectPath() const;
129 QString
smartQuote( const QString
& msg
);
132 * Start of D-Bus callable stuff. The D-Bus methods need to be public slots,
133 * otherwise they can't be accessed.
135 // TODO clean-up dbus stuff; make the adaptor a friend; etc.
138 Q_SCRIPTABLE
void send( int how
);
140 Q_SCRIPTABLE
void addAttachmentsAndSend( const KUrl::List
& urls
,
141 const QString
& comment
,
144 Q_SCRIPTABLE
void addAttachment( const KUrl
& url
,
145 const QString
& comment
);
147 Q_SCRIPTABLE
void addAttachment( const QString
& name
,
148 KMime::Headers::contentEncoding cte
,
149 const QString
& charset
,
150 const QByteArray
& data
,
151 const QByteArray
& mimeType
);
154 * End of D-Bus callable stuff
158 void identityChanged( const KPIMIdentities::Identity
&identity
);
163 * Write settings to app's config file.
165 void writeConfig( void );
167 public: // kmkernel, kmcommands, callback
169 * Set the message the composer shall work with. This discards
170 * previous messages without calling applyChanges() on them before.
172 void setMsg( const KMime::Message::Ptr
&newMsg
, bool mayAutoSign
=true,
173 bool allowDecryption
=false, bool isModified
=false );
176 * Disables word wrap completely. No wrapping at all will occur, not even
177 * at the right end of the editor.
178 * This is useful when sending invitations.
180 void disableWordWrap();
183 * Disables HTML completely. It disables HTML at the point of calling this and disables it
184 * again when sending the message, to be sure. Useful when sending invitations.
185 * This will <b>not</b> remove the actions for activating HTML mode again, it is only
186 * meant for automatic invitation sending.
187 * Also calls @sa disableHtml() internally.
189 void forceDisableHtml();
192 * Returns @c true while the message composing is in progress.
194 bool isComposing() const { return mComposerBase
&& mComposerBase
->isComposing(); }
197 * Set the text selection the message is a response to.
199 void setTextSelection( const QString
& selection
);
202 * Set custom template to be used for the message.
204 void setCustomTemplate( const QString
& customTemplate
);
208 * Returns message of the composer. To apply the user changes to the
209 * message, call applyChanges() first.
211 KMime::Message::Ptr
msg() const { return mMsg
; }
215 * Returns true if the message was modified by the user.
217 bool isModified() const;
221 * If this folder is set, the original message is inserted back after
224 void setFolder(const Akonadi::Collection
&aFolder
) { mFolder
= aFolder
; }
228 * Sets the focus to the edit-widget.
230 void setReplyFocus( bool hasMessage
= true );
233 * Sets the focus to the subject line edit. For use when creating a
234 * message to a known recipient.
236 void setFocusToSubject();
240 * determines whether inline signing/encryption is selected
242 bool inlineSigningEncryptionSelected();
246 * Tries to find the given mimetype @p type in the KDE Mimetype registry.
247 * If found, returns its localized description, otherwise the @p type
250 static QString
prettyMimeType( const QString
&type
);
253 /** Disabled signing and encryption completely for this composer window. */
254 void setSigningAndEncryptionDisabled( bool v
)
256 mSigningAndEncryptionExplicitlyDisabled
= v
;
261 * Disables the HTML mode, by hiding the HTML toolbar and unchecking the
262 * "Formatting" action. Also, removes all rich-text formatting.
264 void disableHtml( Message::ComposerViewBase::Confirmation confirmation
);
266 * Enables HTML mode, by showing the HTML toolbar and checking the
267 * "Formatting" action
275 void slotInsertRecentFile( const KUrl
& );
276 void slotRecentListFileClear();
278 public slots
: // kmkernel, callback
282 void slotSendNowVia( QAction
* );
283 void slotSendLater();
284 void slotSendLaterVia( QAction
* );
285 void getTransportMenu();
288 * Returns true when saving was successful.
290 void slotSaveDraft();
291 void slotSaveTemplate();
292 void slotNewComposer();
293 void slotNewMailReader();
301 void slotPasteAsAttachment();
302 void slotFormatReset();
305 void slotFolderRemoved( const Akonadi::Collection
& );
306 void slotLanguageChanged( const QString
&language
);
308 void slotEditorTextChanged();
309 void slotOverwriteModeChanged();
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
);
322 * toggle fixed width font.
324 void slotUpdateFont();
327 * Open addressbook editor dialog.
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 );
350 void slotEditToolbars();
351 void slotUpdateToolbars();
355 * Read settings from app's config file.
357 void readConfig( bool reload
= false );
360 * Change window title to given string.
362 void slotUpdWinTitle();
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 );
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
);
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
* );
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;
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();
439 Kleo::CryptoMessageFormat
cryptoMessageFormat() const;
440 QString
overwriteModeStr() const;
444 * Install grid management and header fields. If fields exist that
445 * should not be there they are removed. Those that are needed are
446 * created if necessary.
448 void rethinkFields( bool fromslot
=false );
451 Connect signals for moving focus by arrow keys. Returns next edit.
453 QWidget
*connectFocusMoving( QWidget
*prev
, QWidget
*next
);
456 * Show or hide header lines
459 void rethinkHeaderLine( int aValue
, int aMask
, int &aRow
,
460 QLabel
*aLbl
, KLineEdit
*aEdt
,
461 QPushButton
*aBtn
= 0 );
463 void rethinkHeaderLine( int aValue
, int aMask
, int &aRow
,
464 QLabel
*aLbl
, Message::KMSubjectLineEdit
*aEdt
,
465 QPushButton
*aBtn
= 0 );
467 void rethinkHeaderLine( int value
, int mask
, int &row
,
468 QLabel
*lbl
, QComboBox
*cbx
, QCheckBox
*chk
); // krazy:exclude=qclasses
471 * Apply template to new or unmodified message.
473 void applyTemplate( uint uoid
);
476 * Set the quote prefix according to identity.
478 void setQuotePrefix( uint uoid
);
481 * Checks how many recipients are and warns if there are too many.
482 * @return true, if the user accepted the warning and the message should be sent
484 bool checkRecipientNumber() const;
486 bool checkTransport() const;
488 * Initialization methods
491 void setupStatusBar();
497 QString
subject() const;
498 QString
from() const;
499 QString
replyTo() const;
502 * Use the given folder as sent-mail folder if the given folder exists.
503 * Else show an error message and use the default sent-mail folder as
506 void setFcc( const QString
&idString
);
508 void setCharset( const QByteArray
&charset
);
509 void setAutoCharset();
512 * Ask for confirmation if the message was changed before close.
514 virtual bool queryClose();
517 * prevent kmail from exiting when last window is deleted (kernel rules)
519 virtual bool queryExit();
523 * Turn encryption on/off. If setByUser is true then a message box is shown
524 * in case encryption isn't possible.
526 void setEncryption( bool encrypt
, bool setByUser
= false );
529 * Turn signing on/off. If setByUser is true then a message box is shown
530 * in case signing isn't possible.
532 void setSigning( bool sign
, bool setByUser
= false );
535 Returns true if the user forgot to attach something.
537 bool userForgotAttachment();
540 * Decrypt an OpenPGP block or strip off the OpenPGP envelope of a text
541 * block with a clear text signature. This is only done if the given
542 * string contains exactly one OpenPGP block.
543 * This function is for example used to restore the unencrypted/unsigned
544 * message text for editting.
546 static void decryptOrStripOffCleartextSignature( QByteArray
& );
551 void doSend( MessageSender::SendMethod method
=MessageSender::SendDefault
,
552 MessageSender::SaveIn saveIn
= MessageSender::SaveInNone
);
554 void doDelayedSend( MessageSender::SendMethod method
, MessageSender::SaveIn saveIn
);
556 void changeCryptoAction();
557 void applyComposerSetting( Message::ComposerViewBase
* mComposerBase
);
561 void recipientEditorSizeHintChanged();
562 void setMaximumHeaderSize();
563 void slotDoDelayedSend( KJob
* );
566 QWidget
*mMainWidget
;
567 Sonnet::DictionaryComboBox
*mDictionaryCombo
;
568 Akonadi::CollectionComboBox
*mFcc
;
569 MessageComposer::ComposerLineEdit
*mEdtFrom
, *mEdtReplyTo
;
570 Message::KMSubjectLineEdit
*mEdtSubject
;
571 QLabel
*mLblIdentity
, *mLblTransport
, *mLblFcc
;
572 QLabel
*mLblFrom
, *mLblReplyTo
;
574 QLabel
*mDictionaryLabel
;
575 QCheckBox
*mBtnIdentity
, *mBtnDictionary
, *mBtnTransport
, *mBtnFcc
;
578 KMime::Message::Ptr mMsg
;
580 QString mTextSelection
;
581 QString mCustomTemplate
;
582 QAction
*mOpenId
, *mViewId
, *mRemoveId
, *mSaveAsId
, *mPropertiesId
,
583 *mEditAction
, *mEditWithAction
;
584 bool mLastSignActionState
, mLastEncryptActionState
, mSigningAndEncryptionExplicitlyDisabled
;
585 bool mLastIdentityHasSigningKey
, mLastIdentityHasEncryptionKey
;
586 Akonadi::Collection mFolder
;
589 bool mForceDisableHtml
; // Completely disable any HTML. Useful when sending invitations in the
592 QFont mBodyFont
, mFixedFont
;
594 TemplateContext mContext
;
596 KAction
*mCleanSpace
;
597 KRecentFilesAction
*mRecentAction
;
599 KToggleAction
*mSignAction
, *mEncryptAction
, *mRequestMDNAction
;
600 KToggleAction
*mUrgentAction
, *mAllFieldsAction
, *mFromAction
;
601 KToggleAction
*mReplyToAction
;
602 KToggleAction
*mSubjectAction
;
603 KToggleAction
*mIdentityAction
, *mTransportAction
, *mFccAction
;
604 KToggleAction
*mWordWrapAction
, *mFixedFontAction
, *mAutoSpellCheckingAction
;
605 KToggleAction
*mDictionaryAction
, *mSnippetAction
;
607 KToggleAction
*markupAction
;
608 KAction
*actionFormatReset
;
610 CodecAction
*mCodecAction
;
611 KSelectAction
*mCryptoModuleAction
;
613 KAction
*mFindText
, *mFindNextText
, *mReplaceText
, *mSelectAll
;
620 * Creates a simple composer that creates a KMime::Message out of the composer content.
621 * Crypto handling is not done, therefore the name "simple".
622 * This is used when autosaving or printing a message.
624 * The caller takes ownership of the composer.
626 Message::Composer
* createSimpleComposer();
628 bool canSignEncryptAttachments() const {
629 return cryptoMessageFormat() != Kleo::InlineOpenPGPFormat
;
632 QString
addQuotesToText( const QString
&inputText
) const;
633 // helper method for rethinkFields
634 int calcColumnWidth( int which
, long allShowing
, int width
) const;
637 /** Initialize header fields. Should be called on new messages
638 if they are not set manually. E.g. before composing. Calling
639 of setAutomaticFields(), see below, is still required. */
640 void initHeader( KMime::Message
*message
, uint identity
=0 );
643 * Helper methods to read from config various encryption settings
645 inline bool encryptToSelf();
646 inline bool showKeyApprovalDialog();
647 inline int encryptKeyNearExpiryWarningThresholdInDays();
648 inline int signingKeyNearExpiryWarningThresholdInDays();
649 inline int encryptRootCertNearExpiryWarningThresholdInDays();
650 inline int signingRootCertNearExpiryWarningThresholdInDays();
651 inline int encryptChainCertNearExpiryWarningThresholdInDays();
652 inline int signingChainCertNearExpiryWarningThresholdInDays();
655 void slotCompletionModeChanged( KGlobalSettings::Completion
);
656 void slotConfigChanged();
658 void slotPrintComposeResult( KJob
*job
);
660 void slotEncryptChiasmusToggled( bool );
662 void slotSendFailed( const QString
& msg
);
663 void slotSendSuccessful();
666 * toggle automatic spellchecking
668 void slotAutoSpellCheckingToggled( bool );
671 * Updates the visibility and text of the signature and encryption state indicators.
673 void slotUpdateSignatureAndEncrypionStateIndicators();
675 virtual void setAutoSaveFileName( const QString
& fileName
);
678 QSplitter
*mHeadersToEditorSplitter
;
679 QWidget
* mHeadersArea
;
680 QSplitter
*mSplitter
;
681 QSplitter
*mSnippetSplitter
;
682 QByteArray mOriginalPreferredCharset
;
684 KToggleAction
*mEncryptChiasmusAction
;
686 Message::Composer
*mDummyComposer
;
687 // used for auto saving, printing, etc. Not for sending, which happens in ComposerViewBase
688 QList
< Message::Composer
* > mMiscComposers
;
693 QMenu
*mActLaterMenu
;
695 QString mdbusObjectPath
;
696 static int s_composerNumber
;
698 Message::ComposerViewBase
* mComposerBase
;
701 SnippetWidget
*mSnippetWidget
;
703 QLabel
*mSignatureStateIndicator
;
704 QLabel
*mEncryptionStateIndicator
;
706 bool mPreventFccOverwrite
;
707 bool mCheckForForgottenAttachments
;
708 bool mIgnoreStickyFields
;