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"
36 #include <kglobalsettings.h>
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>
48 #include "kleo/enum.h"
49 #include <composerviewbase.h>
62 class KMComposerEditor
;
72 class KRecentFilesAction
;
76 template <typename T
> class shared_ptr
;
80 class DictionaryComboBox
;
83 namespace KPIMIdentities
{
88 class CollectionComboBox
;
93 class AttachmentController
;
105 namespace MessageComposer
107 class ComposerLineEdit
;
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
= KMime::Message::Ptr(), 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
= 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.
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
);
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
);
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
; }
216 * Returns true if the message was modified by the user.
218 bool isModified() const;
222 * If this folder is set, the original message is inserted back after
225 void setFolder(const Akonadi::Collection
&aFolder
) { mFolder
= aFolder
; }
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();
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
251 static QString
prettyMimeType( const QString
&type
);
254 /** Disabled signing and encryption completely for this composer window. */
255 void setSigningAndEncryptionDisabled( bool v
)
257 mSigningAndEncryptionExplicitlyDisabled
= v
;
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
276 void slotInsertRecentFile( const KUrl
& );
277 void slotRecentListFileClear();
279 public slots
: // kmkernel, callback
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();
302 void slotPasteAsAttachment();
303 void slotFormatReset();
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
);
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( 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 );
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;
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
486 void setupStatusBar();
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
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();
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
& );
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();
555 void recipientEditorSizeHintChanged();
556 void setMaximumHeaderSize();
557 void slotDoDelayedSend( KJob
* );
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
;
568 QLabel
*mDictionaryLabel
;
569 QCheckBox
*mBtnIdentity
, *mBtnDictionary
, *mBtnTransport
, *mBtnFcc
;
572 KMime::Message::Ptr mMsg
;
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
;
583 //bool mDisableBreaking;
584 bool mForceDisableHtml
; // Completely disable any HTML. Useful when sending invitations in the
587 QFont mBodyFont
, mFixedFont
;
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
;
613 QStringList mFolderNames
;
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();
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
);
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
;
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
;