kmail

kmcomposewin.h

00001 /* -*- mode: C++; c-file-style: "gnu" -*-
00002  * KMComposeWin Header File
00003  * Author: Markus Wuebben <markus.wuebben@kde.org>
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: // mailserviceimpl, kmkernel, kmcommands, callback, kmmainwidget
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: // mailserviceimpl
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 &paramAttr,
00126                     const QString &paramValue,
00127                     const QCString &contDisp);
00128 public: // kmcommand
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: // kmkernel, kmcommands, callback
00158    void setMsg(KMMessage* newMsg, bool mayAutoSign=TRUE,
00159            bool allowDecryption=FALSE, bool isModified=FALSE);
00160 
00161    void disableWordWrap();
00162 
00166   void disableRecipientNumberCheck();
00167 
00171   void disableForgottenAttachmentsCheck();
00172 
00182   void ignoreStickyFields();
00183 
00187    bool isComposing() const { return mComposer != 0; }
00188 
00189 private: // kmedit
00194    KMMessage* msg() const { return mMsg; }
00195 
00196 public: // kmkernel
00200   void setAutoSaveFilename( const QString & filename );
00201 
00202 private:
00206   bool isModified() const;
00207 
00211   void setModified( bool modified );
00212 
00213 public: // kmkernel, callback
00218    inline void setAutoDelete(bool f) { mAutoDeleteMsg = f; }
00219 
00224   void setAutoDeleteWindow( bool f );
00225 
00226 public: // kmcommand
00231    void setFolder(KMFolder* aFolder) { mFolder = aFolder; }
00232 public: // kmkernel, kmcommand, mailserviceimpl
00236    void setCharset(const QCString& aCharset, bool forceDefault = FALSE);
00237 
00238 public: // kmcommand
00244    void setReplyFocus( bool hasMessage = true );
00245 
00250    void setFocusToSubject();
00251 
00252 private:
00256    bool inlineSigningEncryptionSelected();
00257 
00263    static QString prettyMimeType( const QString& type );
00264     QString quotePrefixName() const;
00265 
00266 private: // kmedit:
00267   KMLineEditSpell *sujectLineWidget() const { return mEdtSubject;}
00268   void setSubjectTextWasSpellChecked( bool _spell ) {
00269     mSubjectTextWasSpellChecked = _spell;
00270   }
00271   bool subjectTextWasSpellChecked() const { return mSubjectTextWasSpellChecked; }
00272 
00273   void paste( QClipboard::Mode mode );
00274 
00275 public: // callback
00277   void setSigningAndEncryptionDisabled( bool v )
00278   {
00279     mSigningAndEncryptionExplicitlyDisabled = v;
00280   }
00281 
00282 private slots:
00283   void polish();
00287   void slotPrint();
00288   void slotAttachFile();
00289   void slotInsertRecentFile(const KURL&);
00290   void slotAttachedFile(const KURL&);
00291 public slots: // kmkernel, callback
00292   void slotSendNow();
00293 private slots:
00294   void slotSendNowVia( int item );
00295   void slotSendLater();
00296   void slotSendLaterVia( int item );
00297 
00298   void getTransportMenu();
00299 
00303   void slotSaveDraft();
00304   void slotSaveTemplate();
00305   void slotNewComposer();
00306   void slotNewMailReader();
00307   void slotClose();
00308   void slotHelp();
00309 
00310   void slotFind();
00311   void slotSearchAgain();
00312   void slotReplace();
00313   void slotUndo();
00314   void slotRedo();
00315   void slotCut();
00316   void slotCopy();
00317   void slotPasteClipboard();
00318   void slotPasteClipboardAsQuotation();
00319   void slotPasteClipboardAsAttachment();
00320   void slotAddQuotes();
00321   void slotRemoveQuotes();
00322   void slotAttachPNGImageData(const QByteArray &image);
00323 
00324   void slotMarkAll();
00325 
00326   void slotFolderRemoved(KMFolder*);
00327 
00328   void slotEditDone( KMail::EditorWatcher* watcher );
00329 
00330 public slots: // kmkernel
00337   void slotSetAlwaysSend( bool bAlwaysSend );
00338 private slots:
00342   void slotUpdateFont();
00343 
00347   void slotAddrBook();
00351   void slotInsertFile();
00352 
00353   void slotSetCharset();
00357   void slotSpellcheck();
00358   void slotSpellcheckConfig();
00359   void slotSubjectTextSpellChecked();
00360 
00365   void slotSelectCryptoModule( bool init = false );
00366 
00370   void slotStatusMessage(const QString &message);
00371   void slotEditToolbars();
00372   void slotUpdateToolbars();
00373   void slotEditKeys();
00377   void readConfig( bool reload = false );
00381   void slotUpdWinTitle(const QString& );
00382 
00387   void slotEncryptToggled(bool);
00388 
00392   void slotSignToggled(bool);
00393 
00394 public slots: // kmkernel, callback
00398   void slotWordWrapToggled(bool);
00399 
00400 private slots:
00404   void slotAppendSignature();
00405 
00409   void slotPrependSignature();
00410 
00414   void slotInsertSignatureAtCursor();
00415 
00419   void slotInsertMyPublicKey();
00420 
00424   void slotInsertPublicKey();
00425 
00429   void slotUpdateAttachActions();
00430 
00434   void slotAttachPopupMenu(QListViewItem *, const QPoint &, int);
00435 
00440   int currentAttachmentNum();
00441 
00445   void slotAttachOpen();
00446   void slotAttachView();
00447   void slotAttachRemove();
00448   void slotAttachSave();
00449   void slotAttachProperties();
00450   void slotAttachOpenWith();
00451   void slotAttachEdit();
00452   void slotAttachEditWith();
00453   void slotAttachmentDragStarted();
00454 
00459   void slotAddrBookTo();
00460   void slotAddrBookFrom();
00461   void slotAddrBookReplyTo();
00462 
00463   void slotCleanSpace();
00464 
00465   void slotToggleMarkup();
00466   void toggleMarkup(bool markup);
00467   void htmlToolBarVisibilityChanged( bool visible );
00468 
00469 //  void slotSpellConfigure();
00470   void slotSpellcheckDone(int result);
00471   void slotSpellcheckDoneClearStatus();
00472 
00473 public slots: // kmkernel
00474   void autoSaveMessage();
00475 
00476 private slots:
00477   void updateCursorPosition();
00478 
00479   void slotView();
00480 
00484   void slotIdentityChanged(uint);
00485 
00489   void slotAttachFileData(KIO::Job *, const QByteArray &);
00490   void slotAttachFileResult(KIO::Job *);
00491 
00492   void slotListAction(const QString &);
00493   void slotFontAction(const QString &);
00494   void slotSizeAction(int);
00495   void slotAlignLeft();
00496   void slotAlignCenter();
00497   void slotAlignRight();
00498   void slotTextBold();
00499   void slotTextItalic();
00500   void slotTextUnder();
00501   void slotFormatReset();
00502   void slotTextColor();
00503   void fontChanged( const QFont & );
00504   void alignmentChanged( int );
00505 
00506 public: // kmkernel, attachmentlistview
00507   bool addAttach(const KURL url);
00508 
00509 public: // kmcommand
00513   void addAttach(const KMMessagePart* msgPart);
00514 
00515 private:
00516   const KPIM::Identity & identity() const;
00517   uint identityUid() const;
00518   Kleo::CryptoMessageFormat cryptoMessageFormat() const;
00519   bool encryptToSelf() const;
00520 
00521 signals:
00522   void applyChangesDone( bool );
00523   void attachmentAdded( const KURL&, bool success );
00524 
00525 private:
00533   void applyChanges( bool dontSignNorEncrypt, bool dontDisable=false );
00534 
00540   void rethinkFields(bool fromslot=false);
00541 
00545   QWidget *connectFocusMoving( QWidget *prev, QWidget *next );
00546 
00551   void rethinkHeaderLine( int aValue, int aMask, int& aRow,
00552                           const QString &aLabelStr, QLabel* aLbl,
00553                           QLineEdit* aEdt, QPushButton* aBtn = 0,
00554                           const QString &toolTip = QString::null,
00555                           const QString &whatsThis = QString::null );
00556 
00557   void rethinkHeaderLine( int value, int mask, int& row,
00558                           const QString& labelStr, QLabel* lbl,
00559                           QComboBox* cbx, QCheckBox *chk );
00560 
00565   bool checkRecipientNumber() const;
00566 
00567 
00568   bool checkTransport() const;
00569 
00573   void setupActions();
00574   void setupStatusBar();
00575   void setupEditor();
00576 
00577 
00581   QString subject() const;
00582   QString to() const;
00583   QString cc() const;
00584   QString bcc() const;
00585   QString from() const;
00586   QString replyTo() const;
00587 
00593   void setFcc( const QString &idString );
00594 
00598   virtual bool queryClose ();
00602   virtual bool queryExit ();
00603 
00607   void openAttach( int index, bool with );
00608 
00612   void viewAttach( int index );
00613 
00617   void editAttach( int index, bool openWith );
00618 
00622    void removeAttach(const QString &url);
00623    void removeAttach(int idx);
00624 
00628    void msgPartToItem(const KMMessagePart* msgPart, KMAtmListViewItem *lvi,
00629         bool loadDefaults = true );
00630 
00635   void addrBookSelInto();
00636 
00637   void addrBookSelIntoOld();
00638   void addrBookSelIntoNew();
00639 
00640 private:
00645   void setEncryption( bool encrypt, bool setByUser = false );
00646 
00651   void setSigning( bool sign, bool setByUser = false );
00652 
00656   bool userForgotAttachment();
00657 
00662   bool encryptFlagOfAttachment(int idx);
00663 
00668   bool signFlagOfAttachment(int idx);
00669 
00670 
00678   static void decryptOrStripOffCleartextSignature( QCString& );
00679 
00683   bool saveDraftOrTemplate( const QString &folderName, KMMessage *msg );
00684 
00688   enum SaveIn { None, Drafts, Templates };
00689   void doSend( KMail::MessageSender::SendMethod method=KMail::MessageSender::SendDefault,
00690                KMComposeWin::SaveIn saveIn = KMComposeWin::None );
00691 
00695   int autoSaveInterval() const;
00696 
00700   void initAutoSave();
00701 
00706   void updateAutoSave();
00707 
00711   void cleanupAutoSave();
00712 
00718   static bool validateAddresses( QWidget * parent, const QString & addresses );
00719 
00726   void setTransport( const QString & transport );
00727 
00732   void insertSignature( bool append = true, int pos = 0 );
00733 private slots:
00737     void compressAttach(int idx);
00738     void uncompressAttach(int idx);
00739     void editorFocusChanged(bool gained);
00740     void recipientEditorSizeHintChanged();
00741     void setMaximumHeaderSize();
00742 
00743 private:
00744   QWidget   *mMainWidget;
00745   QComboBox *mTransport;
00746   KMail::DictionaryComboBox *mDictionaryCombo;
00747   KPIM::IdentityCombo    *mIdentity;
00748   KMFolderComboBox *mFcc;
00749   KMLineEdit *mEdtFrom, *mEdtReplyTo, *mEdtTo, *mEdtCc, *mEdtBcc;
00750   KMLineEditSpell *mEdtSubject;
00751   QLabel    *mLblIdentity, *mLblTransport, *mLblFcc;
00752   QLabel    *mLblFrom, *mLblReplyTo, *mLblTo, *mLblCc, *mLblBcc, *mLblSubject;
00753   QLabel    *mDictionaryLabel;
00754   QCheckBox *mBtnIdentity, *mBtnTransport, *mBtnFcc;
00755   QPushButton *mBtnTo, *mBtnCc, *mBtnBcc, /* *mBtnFrom, */ *mBtnReplyTo;
00756   bool mSpellCheckInProgress;
00757   bool mDone;
00758   bool mAtmModified;
00759 
00760   KMEdit* mEditor;
00761   QGridLayout* mGrid;
00762   KMMessage *mMsg;
00763   QValueVector<KMMessage*> mComposedMessages;
00764   KMail::AttachmentListView* mAtmListView;
00765   int mAtmColEncrypt;
00766   int mAtmColSign;
00767   int mAtmColCompress;
00768   int mAtmEncryptColWidth;
00769   int mAtmSignColWidth;
00770   int mAtmCompressColWidth;
00771   QPtrList<QListViewItem> mAtmItemList;
00772   QPtrList<KMMessagePart> mAtmList;
00773   QPopupMenu *mAttachMenu;
00774   int mOpenId, mOpenWithId, mViewId, mRemoveId, mSaveAsId, mPropertiesId, mEditId, mEditWithId;
00775   bool mAutoDeleteMsg;
00776   bool mSigningAndEncryptionExplicitlyDisabled;
00777   bool mLastSignActionState, mLastEncryptActionState;
00778   bool mLastIdentityHasSigningKey, mLastIdentityHasEncryptionKey;
00779   KMFolder *mFolder;
00780   long mShowHeaders;
00781   bool mConfirmSend;
00782   bool mDisableBreaking; // Move
00783   int mNumHeaders;
00784   bool mUseHTMLEditor;
00785   bool mHtmlMarkup;
00786   QFont mBodyFont, mFixedFont;
00787   QPtrList<KTempFile> mAtmTempList;
00788   QPalette mPalette;
00789   uint mId;
00790   QString mOldSigText;
00791 
00792   KAction *mAttachPK, *mAttachMPK,
00793           *mAttachRemoveAction, *mAttachSaveAction, *mAttachPropertiesAction,
00794           *mPasteQuotation, *mAddQuoteChars, *mRemQuoteChars;
00795   KRecentFilesAction *mRecentAction;
00796 
00797   KAction *mAppendSignatureAction, *mPrependSignatureAction, *mInsertSignatureAction;
00798 
00799   KToggleAction *mSignAction, *mEncryptAction, *mRequestMDNAction;
00800   KToggleAction *mUrgentAction, *mAllFieldsAction, *mFromAction;
00801   KToggleAction *mReplyToAction, *mToAction, *mCcAction, *mBccAction;
00802   KToggleAction *mSubjectAction;
00803   KToggleAction *mIdentityAction, *mTransportAction, *mFccAction;
00804   KToggleAction *mWordWrapAction, *mFixedFontAction, *mAutoSpellCheckingAction;
00805   KToggleAction *mDictionaryAction, *mSnippetAction;
00806 
00807   KSelectAction *listAction;
00808   KFontAction *fontAction;
00809   KFontSizeAction *fontSizeAction;
00810   KToggleAction *alignLeftAction, *alignCenterAction, *alignRightAction;
00811   KToggleAction *textBoldAction, *textItalicAction, *textUnderAction;
00812   KToggleAction *plainTextAction, *markupAction;
00813   KAction *actionFormatColor, *actionFormatReset;
00814   KAction *mHtmlToolbar;
00815 
00816   KSelectAction *mEncodingAction;
00817   KSelectAction *mCryptoModuleAction;
00818 
00819   QCString mCharset;
00820   QCString mDefCharset;
00821   QStringList mCharsets;
00822   bool mAutoCharset;
00823 
00824   bool mAlwaysSend;
00825 
00826   QStringList mFolderNames;
00827   QValueList<QGuardedPtr<KMFolder> > mFolderList;
00828   QMap<KIO::Job*, KURL> mAttachJobs;
00829   KURL::List mAttachFilesPending;
00830   int mAttachFilesSend;
00831 
00832 private:
00833   // helper method for slotInsert(My)PublicKey()
00834   void startPublicKeyExport();
00835   bool canSignEncryptAttachments() const {
00836     return cryptoMessageFormat() != Kleo::InlineOpenPGPFormat;
00837   }
00838 
00839   bool mSubjectTextWasSpellChecked;
00840 
00841   QString addQuotesToText( const QString &inputText );
00842   QString removeQuotesFromText( const QString &inputText );
00843   // helper method for rethinkFields
00844   int calcColumnWidth(int which, long allShowing, int width);
00845 
00846 private slots:
00847   void slotCompletionModeChanged( KGlobalSettings::Completion );
00848   void slotConfigChanged();
00849 
00850   void slotComposerDone( bool );
00851 
00852   void slotContinueDoSend( bool );
00853   void slotContinuePrint( bool );
00854   void slotContinueAutoSave();
00855 
00856   void slotEncryptChiasmusToggled( bool );
00857 
00862   void slotPublicKeyExportResult( const GpgME::Error & err, const QByteArray & keydata );
00863 
00867   void slotAutoSpellCheckingToggled(bool);
00868 
00872   void slotUpdateSignatureActions();
00873 
00877   void slotUpdateSignatureAndEncrypionStateIndicators();
00878 private:
00879   QColor mForeColor,mBackColor;
00880   QFont mSaveFont;
00881   QSplitter *mHeadersToEditorSplitter;
00882   QWidget* mHeadersArea;
00883   QSplitter *mSplitter;
00884   QSplitter *mSnippetSplitter;
00885   struct atmLoadData
00886   {
00887     KURL url;
00888     QByteArray data;
00889     bool insert;
00890     QCString encoding;
00891   };
00892   QMap<KIO::Job *, atmLoadData> mMapAtmLoadData;
00893 
00894   // These are for passing on methods over the applyChanges calls
00895   KMail::MessageSender::SendMethod mSendMethod;
00896   KMComposeWin::SaveIn mSaveIn;
00897 
00898   KToggleAction *mEncryptChiasmusAction;
00899   bool mEncryptWithChiasmus;
00900 
00901   // This is the temporary object that constructs the message out of the
00902   // window
00903   MessageComposer* mComposer;
00904 
00905   // Temp var for slotPrint:
00906   bool mMessageWasModified;
00907 
00908   // Temp var for slotInsert(My)PublicKey():
00909   QString mFingerprint;
00910 
00911   // Temp ptr for saving image from clipboard
00912   KTempDir *mTempDir;
00913 
00914   bool mClassicalRecipients;
00915 
00916   RecipientsEditor *mRecipientsEditor;
00917   int mLabelWidth;
00918 
00919   QTimer *mAutoSaveTimer;
00920   QString mAutoSaveFilename;
00921   int mLastAutoSaveErrno; // holds the errno of the last try to autosave
00922 
00923   QPopupMenu *mActNowMenu;
00924   QPopupMenu *mActLaterMenu;
00925 
00926   QMap<KMail::EditorWatcher*, KMMessagePart*> mEditorMap;
00927   QMap<KMail::EditorWatcher*, KTempFile*> mEditorTempFiles;
00928 
00929   QLabel *mSignatureStateIndicator;
00930   QLabel *mEncryptionStateIndicator;
00931 
00932   SnippetWidget *mSnippetWidget;
00933   std::set<KTempDir*> mTempDirs;
00934 
00942   bool mPreserveUserCursorPosition;
00943 
00944   bool mPreventFccOverwrite;
00945   bool mCheckForRecipients;
00946   bool mCheckForForgottenAttachments;
00947   bool mIgnoreStickyFields;
00948 };
00949 
00950 #endif
00951