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>
59 class KMComposerEditor
;
65 class KRecentFilesAction
;
67 class SelectSpecialChar
;
68 class AttachmentMissingWarning
;
69 class ExternalEditorWarning
;
72 template <typename T
> class shared_ptr
;
76 class DictionaryComboBox
;
79 namespace KPIMIdentities
{
83 namespace KPIMTextEdit
{
84 class SelectSpecialChar
;
96 class SpellCheckLineEdit
;
99 namespace MessageComposer
{
100 class ComposerLineEdit
;
102 namespace MailCommon
{
103 class FolderRequester
;
106 namespace PimCommon
{
107 class TranslatorWidget
;
110 //-----------------------------------------------------------------------------
111 class KMComposeWin
: public KMail::Composer
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
, bool lastSignState
, bool lastEncryptState
, TemplateContext context
= NoTemplate
,
120 uint identity
= 0, const QString
& textSelection
= QString(),
121 const QString
& customTemplate
= QString() );
125 static Composer
*create( const KMime::Message::Ptr
&msg
, bool lastSignState
, bool lastEncryptState
, 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.
139 Q_SCRIPTABLE
void send( int how
);
141 Q_SCRIPTABLE
void addAttachmentsAndSend( const KUrl::List
& urls
,
142 const QString
& comment
,
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
159 void identityChanged( const KPIMIdentities::Identity
&identity
);
162 public: // kmkernel, kmcommands, callback
164 * Set the message the composer shall work with. This discards
165 * previous messages without calling applyChanges() on them before.
167 void setMessage( const KMime::Message::Ptr
&newMsg
, bool lastSignState
= false, bool lastEncryptState
= false,
168 bool mayAutoSign
=true, bool allowDecryption
=false, bool isModified
=false );
170 void setCurrentTransport( int transportId
);
173 * Use the given folder as sent-mail folder if the given folder exists.
174 * Else show an error message and use the default sent-mail folder as
177 void setFcc( const QString
&idString
);
180 * Disables word wrap completely. No wrapping at all will occur, not even
181 * at the right end of the editor.
182 * This is useful when sending invitations.
184 void disableWordWrap();
187 * Disables HTML completely. It disables HTML at the point of calling this and disables it
188 * again when sending the message, to be sure. Useful when sending invitations.
189 * This will <b>not</b> remove the actions for activating HTML mode again, it is only
190 * meant for automatic invitation sending.
191 * Also calls @sa disableHtml() internally.
193 void forceDisableHtml();
196 * Returns @c true while the message composing is in progress.
198 bool isComposing() const { return mComposerBase
&& mComposerBase
->isComposing(); }
201 * Set the text selection the message is a response to.
203 void setTextSelection( const QString
& selection
);
206 * Set custom template to be used for the message.
208 void setCustomTemplate( const QString
& customTemplate
);
210 /** Disabled signing and encryption completely for this composer window. */
211 void setSigningAndEncryptionDisabled( bool v
)
213 mSigningAndEncryptionExplicitlyDisabled
= v
;
216 * If this folder is set, the original message is inserted back after
219 void setFolder(const Akonadi::Collection
&aFolder
) { mFolder
= aFolder
; }
221 * Sets the focus to the edit-widget.
223 void setReplyFocus( bool hasMessage
= true );
226 * Sets the focus to the subject line edit. For use when creating a
227 * message to a known recipient.
229 void setFocusToSubject();
231 bool insertFromMimeData( const QMimeData
*source
, bool forceAttachment
= false );
233 void setCurrentReplyTo(const QString
&);
234 void setCollectionForNewMessage( const Akonadi::Collection
& folder
);
236 void addExtraCustomHeaders( const QMap
<QByteArray
, QString
> &header
);
240 * Write settings to app's config file.
242 void writeConfig( void );
246 * Returns message of the composer. To apply the user changes to the
247 * message, call applyChanges() first.
249 KMime::Message::Ptr
msg() const { return mMsg
; }
251 * Returns true if the message was modified by the user.
253 bool isModified() const;
254 bool isComposerModified() const;
255 void changeModifiedState( bool modified
);
260 * determines whether inline signing/encryption is selected
262 bool inlineSigningEncryptionSelected();
266 * Tries to find the given mimetype @p type in the KDE Mimetype registry.
267 * If found, returns its localized description, otherwise the @p type
270 static QString
prettyMimeType( const QString
&type
);
272 public slots
: // kmkernel, callback
275 * Switch wordWrap on/off
277 void slotWordWrapToggled( bool );
279 void slotToggleMarkup();
280 void slotTextModeChanged( KRichTextEdit::Mode
);
281 void htmlToolBarVisibilityChanged( bool visible
);
282 void slotSpellcheckDoneClearStatus();
283 void autoSaveMessage(bool force
= false);
285 * Set whether the message should be treated as modified or not.
287 void setModified( bool modified
);
288 void slotFetchJob(KJob
*);
292 * Disables the HTML mode, by hiding the HTML toolbar and unchecking the
293 * "Formatting" action. Also, removes all rich-text formatting.
295 void disableHtml( Message::ComposerViewBase::Confirmation confirmation
);
297 * Enables HTML mode, by showing the HTML toolbar and checking the
298 * "Formatting" action
306 void slotPrintPreview();
308 void slotInsertRecentFile( const KUrl
& );
309 void slotRecentListFileClear();
311 void slotSendNowVia( QAction
* );
312 void slotSendLater();
313 void slotSendLaterVia( QAction
* );
314 void getTransportMenu();
317 * Returns true when saving was successful.
319 void slotSaveDraft();
320 void slotSaveTemplate();
321 void slotNewComposer();
322 void slotNewMailReader();
330 void slotPasteAsAttachment();
332 void slotTranslatorWasClosed();
334 void slotFolderRemoved( const Akonadi::Collection
& );
335 void slotLanguageChanged( const QString
&language
);
336 void slotFccFolderChanged(const Akonadi::Collection
&);
337 void slotEditorTextChanged();
338 void slotOverwriteModeChanged();
340 * toggle fixed width font.
342 void slotUpdateFont();
345 * Open addressbook editor dialog.
350 * Insert a file to the end of the text in the editor.
352 void slotInsertFile();
355 * Check spelling of text.
357 void slotSpellcheckConfig();
360 * Change crypto plugin to be used for signing/encrypting messages,
361 * or switch to built-in OpenPGP code.
363 void slotSelectCryptoModule( bool init
= false );
368 void slotEditToolbars();
369 void slotUpdateToolbars();
373 * Read settings from app's config file.
375 void readConfig( bool reload
= false );
378 * Change window title to given string.
380 void slotUpdWinTitle();
383 * Switch the icon to lock or unlock respectivly.
384 * Change states of all encrypt check boxes in the attachments listview
386 void slotEncryptToggled( bool );
389 * Change states of all sign check boxes in the attachments listview
391 void slotSignToggled( bool );
396 * Update composer field to reflect new identity
397 * @param initalChange if true, don't apply the template. This is useful when calling
398 * this function from setMsg(), because there, the message already has the
399 * template, and we want to avoid calling the template parser unnecessarily.
401 void slotIdentityChanged( uint uoid
, bool initalChange
= false );
403 void slotCursorPositionChanged();
405 void slotSpellCheckingStatus( const QString
& status
);
407 void slotDelayedApplyTemplate( KJob
* );
409 void recipientEditorSizeHintChanged();
410 void setMaximumHeaderSize();
411 void slotDoDelayedSend( KJob
* );
413 void slotCompletionModeChanged( KGlobalSettings::Completion
);
414 void slotConfigChanged();
416 void slotPrintComposeResult( KJob
*job
);
418 //void slotEncryptChiasmusToggled( bool );
420 void slotSendFailed(const QString
& msg
, Message::ComposerViewBase::FailedType type
);
421 void slotSendSuccessful();
424 * toggle automatic spellchecking
426 void slotAutoSpellCheckingToggled( bool );
429 * Updates the visibility and text of the signature and encryption state indicators.
431 void slotUpdateSignatureAndEncrypionStateIndicators();
433 virtual void setAutoSaveFileName( const QString
& fileName
);
434 void slotSpellCheckingLanguage(const QString
& language
);
435 void forceAutoSaveMessage();
436 void insertSpecialCharacter();
437 void charSelected(const QChar
& c
);
438 void slotSaveAsFile();
439 void slotCreateAddressBookContact();
441 void slotAttachMissingFile();
442 void slotCloseAttachMissingFile();
443 void slotVerifyMissingAttachmentTimeout();
444 void slotCheckSendNow();
446 void slotUpperCase();
447 void slotLowerCase();
451 // FIXME we need to remove these, but they're pure virtual in Composer.
452 void addAttach( KMime::Content
*msgPart
);
454 const KPIMIdentities::Identity
&identity() const;
456 /** Don't check for forgotten attachments for a mail, eg. when sending out invitations. */
457 void disableForgottenAttachmentsCheck();
460 * Ignore the "sticky" setting of the transport combo box and prefer the X-KMail-Transport
461 * header field of the message instead.
462 * Do the same for the identity combo box, don't obey the "sticky" setting but use the
463 * X-KMail-Identity header field instead.
465 * This is useful when sending out invitations, since you don't see the GUI and want the
466 * identity and transport to be set to the values stored in the messages.
468 void ignoreStickyFields();
471 void updateSignature(uint uoid
, uint uOldId
);
472 Kleo::CryptoMessageFormat
cryptoMessageFormat() const;
473 QString
overwriteModeStr() const;
474 void printComposeResult( KJob
*job
, bool preview
);
475 void printComposer(bool preview
);
477 * Install grid management and header fields. If fields exist that
478 * should not be there they are removed. Those that are needed are
479 * created if necessary.
481 void rethinkFields( bool fromslot
=false );
484 Connect signals for moving focus by arrow keys. Returns next edit.
486 QWidget
*connectFocusMoving( QWidget
*prev
, QWidget
*next
);
489 * Show or hide header lines
491 void rethinkHeaderLine( int aValue
, int aMask
, int &aRow
,
492 QLabel
*aLbl
, QWidget
*aEdt
,
493 QPushButton
*aBtn
= 0 );
495 void rethinkHeaderLine( int value
, int mask
, int &row
,
496 QLabel
*lbl
, QWidget
*cbx
, QCheckBox
*chk
); // krazy:exclude=qclasses
500 * Apply template to new or unmodified message.
502 void applyTemplate(uint uoid
, uint uOldId
);
505 * Set the quote prefix according to identity.
507 void setQuotePrefix( uint uoid
);
510 * Checks how many recipients are and warns if there are too many.
511 * @return true, if the user accepted the warning and the message should be sent
513 bool checkRecipientNumber() const;
515 bool checkTransport() const;
517 * Initialization methods
520 void setupStatusBar(QWidget
*w
);
526 QString
subject() const;
527 QString
from() const;
528 QString
replyTo() const;
530 void setCharset( const QByteArray
&charset
);
531 void setAutoCharset();
534 * Ask for confirmation if the message was changed before close.
536 virtual bool queryClose();
539 * Turn encryption on/off. If setByUser is true then a message box is shown
540 * in case encryption isn't possible.
542 void setEncryption( bool encrypt
, bool setByUser
= false );
545 * Turn signing on/off. If setByUser is true then a message box is shown
546 * in case signing isn't possible.
548 void setSigning( bool sign
, bool setByUser
= false );
550 Message::ComposerViewBase::MissingAttachment
userForgotAttachment();
553 * Decrypt an OpenPGP block or strip off the OpenPGP envelope of a text
554 * block with a clear text signature. This is only done if the given
555 * string contains exactly one OpenPGP block.
556 * This function is for example used to restore the unencrypted/unsigned
557 * message text for editting.
559 static void decryptOrStripOffCleartextSignature( QByteArray
& );
564 void doSend( MessageSender::SendMethod method
=MessageSender::SendDefault
,
565 MessageSender::SaveIn saveIn
= MessageSender::SaveInNone
);
567 void doDelayedSend( MessageSender::SendMethod method
, MessageSender::SaveIn saveIn
);
569 void changeCryptoAction();
570 void applyComposerSetting( Message::ComposerViewBase
* mComposerBase
);
572 * Creates a simple composer that creates a KMime::Message out of the composer content.
573 * Crypto handling is not done, therefore the name "simple".
574 * This is used when autosaving or printing a message.
576 * The caller takes ownership of the composer.
578 Message::Composer
* createSimpleComposer();
580 bool canSignEncryptAttachments() const {
581 return cryptoMessageFormat() != Kleo::InlineOpenPGPFormat
;
584 QString
addQuotesToText( const QString
&inputText
) const;
585 // helper method for rethinkFields
586 int calcColumnWidth( int which
, long allShowing
, int width
) const;
589 /** Initialize header fields. Should be called on new messages
590 if they are not set manually. E.g. before composing. Calling
591 of setAutomaticFields(), see below, is still required. */
592 void initHeader( KMime::Message
*message
, uint identity
=0 );
594 inline bool encryptToSelf();
597 QWidget
*mMainWidget
;
598 Sonnet::DictionaryComboBox
*mDictionaryCombo
;
599 MessageComposer::ComposerLineEdit
*mEdtFrom
, *mEdtReplyTo
;
600 KPIM::SpellCheckLineEdit
*mEdtSubject
;
601 QLabel
*mLblIdentity
, *mLblTransport
, *mLblFcc
;
602 QLabel
*mLblFrom
, *mLblReplyTo
;
604 QLabel
*mDictionaryLabel
;
605 QCheckBox
*mBtnIdentity
, *mBtnDictionary
, *mBtnTransport
, *mBtnFcc
;
608 KMime::Message::Ptr mMsg
;
610 QString mTextSelection
;
611 QString mCustomTemplate
;
612 bool mLastSignActionState
, mLastEncryptActionState
, mSigningAndEncryptionExplicitlyDisabled
;
613 bool mLastIdentityHasSigningKey
, mLastIdentityHasEncryptionKey
;
614 Akonadi::Collection mFolder
;
616 bool mForceDisableHtml
; // Completely disable any HTML. Useful when sending invitations in the
619 QFont mBodyFont
, mFixedFont
;
621 TemplateContext mContext
;
623 KAction
*mCleanSpace
;
624 KRecentFilesAction
*mRecentAction
;
626 KToggleAction
*mSignAction
, *mEncryptAction
, *mRequestMDNAction
;
627 KToggleAction
*mUrgentAction
, *mAllFieldsAction
, *mFromAction
;
628 KToggleAction
*mReplyToAction
;
629 KToggleAction
*mSubjectAction
;
630 KToggleAction
*mIdentityAction
, *mTransportAction
, *mFccAction
;
631 KToggleAction
*mWordWrapAction
, *mFixedFontAction
, *mAutoSpellCheckingAction
;
632 KToggleAction
*mDictionaryAction
, *mSnippetAction
, *mTranslateAction
;
634 KToggleAction
*markupAction
;
636 CodecAction
*mCodecAction
;
637 KSelectAction
*mCryptoModuleAction
;
639 KAction
*mFindText
, *mFindNextText
, *mReplaceText
, *mSelectAll
;
641 QSplitter
*mHeadersToEditorSplitter
;
642 QWidget
* mHeadersArea
;
643 QSplitter
*mSplitter
;
644 QSplitter
*mSnippetSplitter
;
645 QByteArray mOriginalPreferredCharset
;
647 //KToggleAction *mEncryptChiasmusAction;
649 Message::Composer
*mDummyComposer
;
650 // used for auto saving, printing, etc. Not for sending, which happens in ComposerViewBase
651 QList
< Message::Composer
* > mMiscComposers
;
656 QMenu
*mActLaterMenu
;
658 QString mdbusObjectPath
;
659 static int s_composerNumber
;
661 Message::ComposerViewBase
* mComposerBase
;
664 SnippetWidget
*mSnippetWidget
;
665 PimCommon::TranslatorWidget
*mTranslatorWidget
;
666 QPointer
<KPIMTextEdit::SelectSpecialChar
> mSelectSpecialChar
;
667 AttachmentMissingWarning
*mAttachmentMissing
;
668 ExternalEditorWarning
*mExternalEditorWarning
;
669 QTimer
*m_verifyMissingAttachment
;
670 QLabel
*mSignatureStateIndicator
;
671 QLabel
*mEncryptionStateIndicator
;
672 MailCommon::FolderRequester
*mFccFolder
;
673 bool mPreventFccOverwrite
;
674 bool mCheckForForgottenAttachments
;
675 bool mIgnoreStickyFields
;
677 Akonadi::Collection mCollectionForNewMessage
;
678 QMap
<QByteArray
, QString
> mExtraHeaders
;