00001
00002
00003
00004
00005 #ifndef __KMComposeWin
00006 #define __KMComposeWin
00007
00008 #ifndef KDE_USE_FINAL
00009 # ifndef REALLY_WANT_KMCOMPOSEWIN_H
00010 # error Do not include kmcomposewin.h anymore. Include composer.h instead.
00011 # endif
00012 #endif
00013
00014 #include "composer.h"
00015 #include "messagesender.h"
00016
00017 #include <set>
00018
00019 #include <qlabel.h>
00020 #include <qlistview.h>
00021
00022 #include <qcheckbox.h>
00023 #include <qpushbutton.h>
00024 #include <qclipboard.h>
00025 #include <qpalette.h>
00026 #include <qfont.h>
00027 #include <qptrlist.h>
00028 #include <qvaluevector.h>
00029 #include <qsplitter.h>
00030
00031 #include <kio/job.h>
00032 #include <kglobalsettings.h>
00033 #include <kdeversion.h>
00034 #include <keditcl.h>
00035 #include <ktempdir.h>
00036
00037 #include "mailcomposerIface.h"
00038
00039 #include <libkdepim/addresseelineedit.h>
00040 #include <mimelib/mediatyp.h>
00041
00042 #include <kleo/enum.h>
00043
00044 class QCloseEvent;
00045 class QComboBox;
00046 class QFrame;
00047 class QGridLayout;
00048 class QListView;
00049 class QPopupMenu;
00050 class QPushButton;
00051 class QCString;
00052 class KCompletion;
00053 class KMEdit;
00054 class KMComposeWin;
00055 class KMFolderComboBox;
00056 class KMFolder;
00057 class KMMessage;
00058 class KMMessagePart;
00059 class KProcess;
00060 class KDirWatch;
00061 class KSelectAction;
00062 class KFontAction;
00063 class KFontSizeAction;
00064 class KSelectAction;
00065 class KStatusBar;
00066 class KAction;
00067 class KToggleAction;
00068 class KTempFile;
00069 class KToolBar;
00070 class KToggleAction;
00071 class KSelectColorAction;
00072 class KURL;
00073 class KRecentFilesAction;
00074 class SpellingFilter;
00075 class MessageComposer;
00076 class RecipientsEditor;
00077 class KMLineEdit;
00078 class KMLineEditSpell;
00079 class KMAtmListViewItem;
00080 class SnippetWidget;
00081
00082 namespace KPIM {
00083 class IdentityCombo;
00084 class Identity;
00085 }
00086
00087 namespace KMail {
00088 class AttachmentListView;
00089 class DictionaryComboBox;
00090 class EditorWatcher;
00091 }
00092
00093 namespace GpgME {
00094 class Error;
00095 }
00096
00097
00098 class KMComposeWin : public KMail::Composer, virtual public MailComposerIface
00099 {
00100 Q_OBJECT
00101 friend class ::KMEdit;
00102 friend class ::MessageComposer;
00103
00104 private:
00105 KMComposeWin( KMMessage* msg=0, uint identity=0 );
00106 ~KMComposeWin();
00107 public:
00108 static Composer * create( KMMessage * msg = 0, uint identity = 0 );
00109
00110 MailComposerIface * asMailComposerIFace() { return this; }
00111 const MailComposerIface * asMailComposerIFace() const { return this; }
00112
00113 public:
00117 void send(int how);
00118 void addAttachmentsAndSend(const KURL::List &urls, const QString &comment, int how);
00119 void addAttachment(KURL url,QString comment);
00120 void addAttachment(const QString &name,
00121 const QCString &cte,
00122 const QByteArray &data,
00123 const QCString &type,
00124 const QCString &subType,
00125 const QCString ¶mAttr,
00126 const QString ¶mValue,
00127 const QCString &contDisp);
00128 public:
00129 void setBody (QString body);
00130
00131 private:
00135 virtual bool event(QEvent *e);
00136
00140 void readColorConfig();
00141
00145 void writeConfig(void);
00146
00151 void verifyWordWrapLengthIsAdequate(const QString&);
00152
00153 public:
00158 void setMsg(KMMessage* newMsg, bool mayAutoSign=TRUE,
00159 bool allowDecryption=FALSE, bool isModified=FALSE);
00160
00161 void disableWordWrap();
00162
00166 bool isComposing() const { return mComposer != 0; }
00167
00168 private:
00173 KMMessage* msg() const { return mMsg; }
00174
00175 public:
00179 void setAutoSaveFilename( const QString & filename );
00180
00181 private:
00185 bool isModified() const;
00186
00190 void setModified( bool modified );
00191
00192 public:
00197 inline void setAutoDelete(bool f) { mAutoDeleteMsg = f; }
00198
00203 void setAutoDeleteWindow( bool f );
00204
00205 public:
00210 void setFolder(KMFolder* aFolder) { mFolder = aFolder; }
00211 public:
00215 void setCharset(const QCString& aCharset, bool forceDefault = FALSE);
00216
00217 public:
00223 void setReplyFocus( bool hasMessage = true );
00224
00229 void setFocusToSubject();
00230
00231 private:
00235 bool inlineSigningEncryptionSelected();
00236
00242 static QString prettyMimeType( const QString& type );
00243 QString quotePrefixName() const;
00244
00245 private:
00246 KMLineEditSpell *sujectLineWidget() const { return mEdtSubject;}
00247 void setSubjectTextWasSpellChecked( bool _spell ) {
00248 mSubjectTextWasSpellChecked = _spell;
00249 }
00250 bool subjectTextWasSpellChecked() const { return mSubjectTextWasSpellChecked; }
00251
00252 void paste( QClipboard::Mode mode );
00253
00254 public:
00256 void setSigningAndEncryptionDisabled( bool v )
00257 {
00258 mSigningAndEncryptionExplicitlyDisabled = v;
00259 }
00260
00261 private slots:
00262 void polish();
00266 void slotPrint();
00267 void slotAttachFile();
00268 void slotInsertRecentFile(const KURL&);
00269 void slotAttachedFile(const KURL&);
00270 public slots:
00271 void slotSendNow();
00272 private slots:
00273 void slotSendNowVia( int item );
00274 void slotSendLater();
00275 void slotSendLaterVia( int item );
00276
00277 void getTransportMenu();
00278
00282 void slotSaveDraft();
00283 void slotSaveTemplate();
00284 void slotNewComposer();
00285 void slotNewMailReader();
00286 void slotClose();
00287 void slotHelp();
00288
00289 void slotFind();
00290 void slotSearchAgain();
00291 void slotReplace();
00292 void slotUndo();
00293 void slotRedo();
00294 void slotCut();
00295 void slotCopy();
00296 void slotPasteClipboard();
00297 void slotPasteClipboardAsQuotation();
00298 void slotPasteClipboardAsAttachment();
00299 void slotAddQuotes();
00300 void slotRemoveQuotes();
00301 void slotAttachPNGImageData(const QByteArray &image);
00302
00303 void slotMarkAll();
00304
00305 void slotFolderRemoved(KMFolder*);
00306
00307 void slotEditDone( KMail::EditorWatcher* watcher );
00308
00309 public slots:
00316 void slotSetAlwaysSend( bool bAlwaysSend );
00317 private slots:
00321 void slotUpdateFont();
00322
00326 void slotAddrBook();
00330 void slotInsertFile();
00331
00332 void slotSetCharset();
00336 void slotSpellcheck();
00337 void slotSpellcheckConfig();
00338 void slotSubjectTextSpellChecked();
00339
00344 void slotSelectCryptoModule( bool init = false );
00345
00349 void slotStatusMessage(const QString &message);
00350 void slotEditToolbars();
00351 void slotUpdateToolbars();
00352 void slotEditKeys();
00356 void readConfig( bool reload = false );
00360 void slotUpdWinTitle(const QString& );
00361
00366 void slotEncryptToggled(bool);
00367
00371 void slotSignToggled(bool);
00372
00373 public slots:
00377 void slotWordWrapToggled(bool);
00378
00379 private slots:
00383 void slotAppendSignature();
00384
00388 void slotPrependSignature();
00389
00393 void slotInsertSignatureAtCursor();
00394
00398 void slotInsertMyPublicKey();
00399
00403 void slotInsertPublicKey();
00404
00408 void slotUpdateAttachActions();
00409
00413 void slotAttachPopupMenu(QListViewItem *, const QPoint &, int);
00414
00419 int currentAttachmentNum();
00420
00424 void slotAttachOpen();
00425 void slotAttachView();
00426 void slotAttachRemove();
00427 void slotAttachSave();
00428 void slotAttachProperties();
00429 void slotAttachOpenWith();
00430 void slotAttachEdit();
00431 void slotAttachEditWith();
00432 void slotAttachmentDragStarted();
00433
00438 void slotAddrBookTo();
00439 void slotAddrBookFrom();
00440 void slotAddrBookReplyTo();
00441
00442 void slotCleanSpace();
00443
00444 void slotToggleMarkup();
00445 void toggleMarkup(bool markup);
00446 void htmlToolBarVisibilityChanged( bool visible );
00447
00448
00449 void slotSpellcheckDone(int result);
00450 void slotSpellcheckDoneClearStatus();
00451
00452 public slots:
00453 void autoSaveMessage();
00454
00455 private slots:
00456 void updateCursorPosition();
00457
00458 void slotView();
00459
00463 void slotIdentityChanged(uint);
00464
00468 void slotAttachFileData(KIO::Job *, const QByteArray &);
00469 void slotAttachFileResult(KIO::Job *);
00470
00471 void slotListAction(const QString &);
00472 void slotFontAction(const QString &);
00473 void slotSizeAction(int);
00474 void slotAlignLeft();
00475 void slotAlignCenter();
00476 void slotAlignRight();
00477 void slotTextBold();
00478 void slotTextItalic();
00479 void slotTextUnder();
00480 void slotFormatReset();
00481 void slotTextColor();
00482 void fontChanged( const QFont & );
00483 void alignmentChanged( int );
00484
00485 public:
00486 bool addAttach(const KURL url);
00487
00488 public:
00492 void addAttach(const KMMessagePart* msgPart);
00493
00494 private:
00495 const KPIM::Identity & identity() const;
00496 uint identityUid() const;
00497 Kleo::CryptoMessageFormat cryptoMessageFormat() const;
00498 bool encryptToSelf() const;
00499
00500 signals:
00501 void applyChangesDone( bool );
00502 void attachmentAdded( const KURL&, bool success );
00503
00504 private:
00512 void applyChanges( bool dontSignNorEncrypt, bool dontDisable=false );
00513
00519 void rethinkFields(bool fromslot=false);
00520
00524 QWidget *connectFocusMoving( QWidget *prev, QWidget *next );
00525
00530 void rethinkHeaderLine( int aValue, int aMask, int& aRow,
00531 const QString &aLabelStr, QLabel* aLbl,
00532 QLineEdit* aEdt, QPushButton* aBtn = 0,
00533 const QString &toolTip = QString::null,
00534 const QString &whatsThis = QString::null );
00535
00536 void rethinkHeaderLine( int value, int mask, int& row,
00537 const QString& labelStr, QLabel* lbl,
00538 QComboBox* cbx, QCheckBox *chk );
00539
00544 bool checkRecipientNumber() const;
00545
00549 void setupActions();
00550 void setupStatusBar();
00551 void setupEditor();
00552
00553
00557 QString subject() const;
00558 QString to() const;
00559 QString cc() const;
00560 QString bcc() const;
00561 QString from() const;
00562 QString replyTo() const;
00563
00569 void setFcc( const QString &idString );
00570
00574 virtual bool queryClose ();
00578 virtual bool queryExit ();
00579
00583 void openAttach( int index, bool with );
00584
00588 void viewAttach( int index );
00589
00593 void editAttach( int index, bool openWith );
00594
00598 void removeAttach(const QString &url);
00599 void removeAttach(int idx);
00600
00604 void msgPartToItem(const KMMessagePart* msgPart, KMAtmListViewItem *lvi,
00605 bool loadDefaults = true );
00606
00611 void addrBookSelInto();
00612
00613 void addrBookSelIntoOld();
00614 void addrBookSelIntoNew();
00615
00616 private:
00621 void setEncryption( bool encrypt, bool setByUser = false );
00622
00627 void setSigning( bool sign, bool setByUser = false );
00628
00632 bool userForgotAttachment();
00633
00638 bool encryptFlagOfAttachment(int idx);
00639
00644 bool signFlagOfAttachment(int idx);
00645
00646
00654 static void decryptOrStripOffCleartextSignature( QCString& );
00655
00659 bool saveDraftOrTemplate( const QString &folderName, KMMessage *msg );
00660
00664 enum SaveIn { None, Drafts, Templates };
00665 void doSend( KMail::MessageSender::SendMethod method=KMail::MessageSender::SendDefault,
00666 KMComposeWin::SaveIn saveIn = KMComposeWin::None );
00667
00671 int autoSaveInterval() const;
00672
00676 void initAutoSave();
00677
00682 void updateAutoSave();
00683
00687 void cleanupAutoSave();
00688
00694 static bool validateAddresses( QWidget * parent, const QString & addresses );
00695
00702 void setTransport( const QString & transport );
00703
00708 void insertSignature( bool append = true, int pos = 0 );
00709 private slots:
00713 void compressAttach(int idx);
00714 void uncompressAttach(int idx);
00715 void editorFocusChanged(bool gained);
00716 void recipientEditorSizeHintChanged();
00717 void setMaximumHeaderSize();
00718
00719 private:
00720 QWidget *mMainWidget;
00721 QComboBox *mTransport;
00722 KMail::DictionaryComboBox *mDictionaryCombo;
00723 KPIM::IdentityCombo *mIdentity;
00724 KMFolderComboBox *mFcc;
00725 KMLineEdit *mEdtFrom, *mEdtReplyTo, *mEdtTo, *mEdtCc, *mEdtBcc;
00726 KMLineEditSpell *mEdtSubject;
00727 QLabel *mLblIdentity, *mLblTransport, *mLblFcc;
00728 QLabel *mLblFrom, *mLblReplyTo, *mLblTo, *mLblCc, *mLblBcc, *mLblSubject;
00729 QLabel *mDictionaryLabel;
00730 QCheckBox *mBtnIdentity, *mBtnTransport, *mBtnFcc;
00731 QPushButton *mBtnTo, *mBtnCc, *mBtnBcc, *mBtnReplyTo;
00732 bool mSpellCheckInProgress;
00733 bool mDone;
00734 bool mAtmModified;
00735
00736 KMEdit* mEditor;
00737 QGridLayout* mGrid;
00738 KMMessage *mMsg;
00739 QValueVector<KMMessage*> mComposedMessages;
00740 KMail::AttachmentListView* mAtmListView;
00741 int mAtmColEncrypt;
00742 int mAtmColSign;
00743 int mAtmColCompress;
00744 int mAtmEncryptColWidth;
00745 int mAtmSignColWidth;
00746 int mAtmCompressColWidth;
00747 QPtrList<QListViewItem> mAtmItemList;
00748 QPtrList<KMMessagePart> mAtmList;
00749 QPopupMenu *mAttachMenu;
00750 int mOpenId, mOpenWithId, mViewId, mRemoveId, mSaveAsId, mPropertiesId, mEditId, mEditWithId;
00751 bool mAutoDeleteMsg;
00752 bool mSigningAndEncryptionExplicitlyDisabled;
00753 bool mLastSignActionState, mLastEncryptActionState;
00754 bool mLastIdentityHasSigningKey, mLastIdentityHasEncryptionKey;
00755 KMFolder *mFolder;
00756 long mShowHeaders;
00757 bool mConfirmSend;
00758 bool mDisableBreaking;
00759 int mNumHeaders;
00760 bool mUseHTMLEditor;
00761 bool mHtmlMarkup;
00762 QFont mBodyFont, mFixedFont;
00763 QPtrList<KTempFile> mAtmTempList;
00764 QPalette mPalette;
00765 uint mId;
00766 QString mOldSigText;
00767
00768 KAction *mAttachPK, *mAttachMPK,
00769 *mAttachRemoveAction, *mAttachSaveAction, *mAttachPropertiesAction,
00770 *mPasteQuotation, *mAddQuoteChars, *mRemQuoteChars;
00771 KRecentFilesAction *mRecentAction;
00772
00773 KAction *mAppendSignatureAction, *mPrependSignatureAction, *mInsertSignatureAction;
00774
00775 KToggleAction *mSignAction, *mEncryptAction, *mRequestMDNAction;
00776 KToggleAction *mUrgentAction, *mAllFieldsAction, *mFromAction;
00777 KToggleAction *mReplyToAction, *mToAction, *mCcAction, *mBccAction;
00778 KToggleAction *mSubjectAction;
00779 KToggleAction *mIdentityAction, *mTransportAction, *mFccAction;
00780 KToggleAction *mWordWrapAction, *mFixedFontAction, *mAutoSpellCheckingAction;
00781 KToggleAction *mDictionaryAction, *mSnippetAction;
00782
00783 KSelectAction *listAction;
00784 KFontAction *fontAction;
00785 KFontSizeAction *fontSizeAction;
00786 KToggleAction *alignLeftAction, *alignCenterAction, *alignRightAction;
00787 KToggleAction *textBoldAction, *textItalicAction, *textUnderAction;
00788 KToggleAction *plainTextAction, *markupAction;
00789 KAction *actionFormatColor, *actionFormatReset;
00790 KAction *mHtmlToolbar;
00791
00792 KSelectAction *mEncodingAction;
00793 KSelectAction *mCryptoModuleAction;
00794
00795 QCString mCharset;
00796 QCString mDefCharset;
00797 QStringList mCharsets;
00798 bool mAutoCharset;
00799
00800 bool mAlwaysSend;
00801
00802 QStringList mFolderNames;
00803 QValueList<QGuardedPtr<KMFolder> > mFolderList;
00804 QMap<KIO::Job*, KURL> mAttachJobs;
00805 KURL::List mAttachFilesPending;
00806 int mAttachFilesSend;
00807
00808 private:
00809
00810 void startPublicKeyExport();
00811 bool canSignEncryptAttachments() const {
00812 return cryptoMessageFormat() != Kleo::InlineOpenPGPFormat;
00813 }
00814
00815 bool mSubjectTextWasSpellChecked;
00816
00817 QString addQuotesToText( const QString &inputText );
00818 QString removeQuotesFromText( const QString &inputText );
00819
00820 int calcColumnWidth(int which, long allShowing, int width);
00821
00822 private slots:
00823 void slotCompletionModeChanged( KGlobalSettings::Completion );
00824 void slotConfigChanged();
00825
00826 void slotComposerDone( bool );
00827
00828 void slotContinueDoSend( bool );
00829 void slotContinuePrint( bool );
00830 void slotContinueAutoSave();
00831
00832 void slotEncryptChiasmusToggled( bool );
00833
00838 void slotPublicKeyExportResult( const GpgME::Error & err, const QByteArray & keydata );
00839
00843 void slotAutoSpellCheckingToggled(bool);
00844
00848 void slotUpdateSignatureActions();
00849
00853 void slotUpdateSignatureAndEncrypionStateIndicators();
00854 private:
00855 QColor mForeColor,mBackColor;
00856 QFont mSaveFont;
00857 QSplitter *mHeadersToEditorSplitter;
00858 QWidget* mHeadersArea;
00859 QSplitter *mSplitter;
00860 QSplitter *mSnippetSplitter;
00861 struct atmLoadData
00862 {
00863 KURL url;
00864 QByteArray data;
00865 bool insert;
00866 QCString encoding;
00867 };
00868 QMap<KIO::Job *, atmLoadData> mMapAtmLoadData;
00869
00870
00871 KMail::MessageSender::SendMethod mSendMethod;
00872 KMComposeWin::SaveIn mSaveIn;
00873
00874 KToggleAction *mEncryptChiasmusAction;
00875 bool mEncryptWithChiasmus;
00876
00877
00878
00879 MessageComposer* mComposer;
00880
00881
00882 bool mMessageWasModified;
00883
00884
00885 QString mFingerprint;
00886
00887
00888 KTempDir *mTempDir;
00889
00890 bool mClassicalRecipients;
00891
00892 RecipientsEditor *mRecipientsEditor;
00893 int mLabelWidth;
00894
00895 QTimer *mAutoSaveTimer;
00896 QString mAutoSaveFilename;
00897 int mLastAutoSaveErrno;
00898
00899 QPopupMenu *mActNowMenu;
00900 QPopupMenu *mActLaterMenu;
00901
00902 QMap<KMail::EditorWatcher*, KMMessagePart*> mEditorMap;
00903 QMap<KMail::EditorWatcher*, KTempFile*> mEditorTempFiles;
00904
00905 QLabel *mSignatureStateIndicator;
00906 QLabel *mEncryptionStateIndicator;
00907
00908 SnippetWidget *mSnippetWidget;
00909 std::set<KTempDir*> mTempDirs;
00910
00918 bool mPreserveUserCursorPosition;
00919
00920 bool mPreventFccOverwrite;
00921 };
00922
00923 #endif
00924