kmail Library API Documentation

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 #include "secondarywindow.h"
00009 
00010 #include <qlabel.h>
00011 #include <qlistview.h>
00012 
00013 #include <qcheckbox.h>
00014 #include <qpushbutton.h>
00015 #include <qclipboard.h>
00016 #include <qpalette.h>
00017 #include <qfont.h>
00018 #include <qptrlist.h>
00019 #include <qvaluevector.h>
00020 
00021 #include <kio/job.h>
00022 #include <kglobalsettings.h>
00023 #include <kdeversion.h>
00024 #include <keditcl.h>
00025 
00026 #include "kmmsgpart.h"
00027 #include "kmmsgbase.h"
00028 #include "mailcomposerIface.h"
00029 
00030 #include <libkdepim/addresseelineedit.h>
00031 #include <mimelib/mediatyp.h>
00032 
00033 #include <kleo/enum.h>
00034 
00035 class _StringPair {
00036  public:
00037    QString name;
00038    QString value;
00039 };
00040 
00041 class QCloseEvent;
00042 class QComboBox;
00043 class QFrame;
00044 class QGridLayout;
00045 class QListView;
00046 class QPopupMenu;
00047 class QPushButton;
00048 class QCString;
00049 class KCompletion;
00050 class KEdit;
00051 class KMComposeWin;
00052 class KMFolderComboBox;
00053 class KMMessage;
00054 class KProcess;
00055 class KDirWatch;
00056 class KSelectAction;
00057 class KFontAction;
00058 class KFontSizeAction;
00059 class KSelectAction;
00060 class KSpell;
00061 class KSpellConfig;
00062 class KDictSpellingHighlighter;
00063 class KStatusBar;
00064 class KAction;
00065 class KToggleAction;
00066 class KTempFile;
00067 class KToolBar;
00068 class KToggleAction;
00069 class KSelectColorAction;
00070 class KURL;
00071 class SpellingFilter;
00072 class MessageComposer;
00073 
00074 namespace KPIM {
00075   class IdentityCombo;
00076   class Identity;
00077 }
00078 
00079 namespace KMail {
00080   class AttachmentListView;
00081   class DictionaryComboBox;
00082 }
00083 
00084 namespace GpgME {
00085   class Error;
00086 }
00087 
00088 
00089 //-----------------------------------------------------------------------------
00090 class KMEdit: public KEdit
00091 {
00092   Q_OBJECT
00093 public:
00094   KMEdit(QWidget *parent=0,KMComposeWin* composer=0,
00095          KSpellConfig* spellConfig = 0,
00096      const char *name=0);
00097   virtual ~KMEdit();
00098 
00102   void spellcheck();
00103 
00107   QString brokenText();
00108 
00112   int autoSpellChecking( bool );
00113 
00117   void setUseExternalEditor( bool use ) { mUseExtEditor = use; }
00118   void setExternalEditorPath( const QString & path ) { mExtEditor = path; }
00119 
00126   bool checkExternalEditorFinished();
00127 
00128   void setSpellCheckingActive(bool spellCheckingActive);
00129 
00131   void contentsDragEnterEvent(QDragEnterEvent *e);
00132   void contentsDragMoveEvent(QDragMoveEvent *e);
00133   void contentsDropEvent(QDropEvent *e);
00134 
00135   void initializeAutoSpellChecking( KSpellConfig* autoSpellConfig );
00136   void deleteAutoSpellChecking();
00137 
00138 signals:
00139   void spellcheck_done(int result);
00140 public slots:
00141   void slotSpellcheck2(KSpell*);
00142   void slotSpellResult(const QString&);
00143   void slotSpellDone();
00144   void slotExternalEditorDone(KProcess*);
00145   void slotMisspelling(const QString &, const QStringList &, unsigned int);
00146   void slotCorrected (const QString &, const QString &, unsigned int);
00147   void addSuggestion(const QString& text, const QStringList& lst, unsigned int );
00148   virtual void cut();
00149   virtual void clear();
00150   virtual void del();
00151 protected:
00155   virtual bool eventFilter(QObject*, QEvent*);
00156   virtual void keyPressEvent( QKeyEvent* );
00157 
00158   KMComposeWin* mComposer;
00159 
00160 private slots:
00161   void slotExternalEditorTempFileChanged( const QString & fileName );
00162 
00163 private:
00164   void killExternalEditor();
00165 
00166 private:
00167   KSpell *mKSpell;
00168   QMap<QString,QStringList> mReplacements;
00169   SpellingFilter* mSpellingFilter;
00170   KTempFile *mExtEditorTempFile;
00171   KDirWatch *mExtEditorTempFileWatcher;
00172   KProcess  *mExtEditorProcess;
00173   bool      mUseExtEditor;
00174   QString   mExtEditor;
00175   bool      mWasModifiedBeforeSpellCheck;
00176   KDictSpellingHighlighter *mSpellChecker;
00177   bool mSpellLineEdit;
00178 };
00179 
00180 
00181 //-----------------------------------------------------------------------------
00182 class KMLineEdit : public KPIM::AddresseeLineEdit
00183 {
00184     Q_OBJECT
00185 public:
00186     KMLineEdit(KMComposeWin* composer, bool useCompletion, QWidget *parent = 0,
00187                const char *name = 0);
00188 protected:
00189     // Inherited. Always called by the parent when this widget is created.
00190     virtual void loadContacts();
00191 
00192     virtual void keyPressEvent(QKeyEvent*);
00193 
00194     virtual QPopupMenu *createPopupMenu();
00195 
00196 private slots:
00197     void editRecentAddresses();
00198 
00199 private:
00200     KMComposeWin* mComposer;
00201 };
00202 
00203 
00204 class KMLineEditSpell : public KMLineEdit
00205 {
00206     Q_OBJECT
00207 public:
00208     KMLineEditSpell(KMComposeWin* composer, bool useCompletion, QWidget *parent = 0,
00209                const char *name = 0);
00210     void highLightWord( unsigned int length, unsigned int pos );
00211     void spellCheckDone( const QString &s );
00212     void spellCheckerMisspelling( const QString &text, const QStringList &, unsigned int pos);
00213     void spellCheckerCorrected( const QString &old, const QString &corr, unsigned int pos);
00214 
00215  signals:
00216   void subjectTextSpellChecked();
00217 };
00218 
00219 
00220 //-----------------------------------------------------------------------------
00221 class KMAtmListViewItem : public QObject, public QListViewItem
00222 {
00223   Q_OBJECT
00224   friend class KMComposeWin;
00225   friend class MessageComposer;
00226 
00227 public:
00228   KMAtmListViewItem(QListView * parent);
00229   virtual ~KMAtmListViewItem();
00230   virtual void paintCell( QPainter * p, const QColorGroup & cg,
00231                           int column, int width, int align );
00232 
00233 protected:
00234   void enableCryptoCBs(bool on);
00235   void setEncrypt(bool on);
00236   bool isEncrypt();
00237   void setSign(bool on);
00238   bool isSign();
00239 
00240 private:
00241   QListView* mListview;
00242   QCheckBox* mCBEncrypt;
00243   QCheckBox* mCBSign;
00244   bool mCBSignEnabled, mCBEncryptEnabled;
00245 };
00246 
00247 
00248 class KMHeaders;
00249 
00250 //-----------------------------------------------------------------------------
00251 class KMComposeWin : public KMail::SecondaryWindow, virtual public MailComposerIface
00252 {
00253   Q_OBJECT
00254   friend class KMHeaders;         // needed for the digest forward
00255   friend class MessageComposer;
00256 
00257 public:
00258   KMComposeWin( KMMessage* msg=0, uint identity=0 );
00259   ~KMComposeWin();
00260 
00264   void send(int how);
00265   void addAttachment(KURL url,QString comment);
00266   void addAttachment(const QString &name,
00267                     const QCString &cte,
00268                     const QByteArray &data,
00269                     const QCString &type,
00270                     const QCString &subType,
00271                     const QCString &paramAttr,
00272                     const QString &paramValue,
00273                     const QCString &contDisp);
00274   void setBody (QString body);
00275 
00279   virtual bool event(QEvent *e);
00280 
00284   void readColorConfig();
00285 
00289    void writeConfig(void);
00290 
00295    void verifyWordWrapLengthIsAdequate(const QString&);
00296 
00301    void setMsg(KMMessage* newMsg, bool mayAutoSign=TRUE,
00302            bool allowDecryption=FALSE, bool isModified=FALSE);
00303 
00308    KMMessage* msg(void) const { return mMsg; }
00309 
00314    inline void setAutoDelete(bool f) { mAutoDeleteMsg = f; }
00315 
00320   void setAutoDeleteWindow( bool f );
00321 
00326    void setFolder(KMFolder* aFolder) { mFolder = aFolder; }
00327 
00331    void setCharset(const QCString& aCharset, bool forceDefault = FALSE);
00332 
00338    void setReplyFocus( bool hasMessage = true );
00339 
00344    void setFocusToSubject();
00345 
00349    bool inlineSigningEncryptionSelected();
00350 
00356    static QString prettyMimeType( const QString& type );
00357     QString quotePrefixName() const;
00358 
00359     KMLineEditSpell *sujectLineWidget() const { return mEdtSubject;}
00360   void setSubjectTextWasSpellChecked( bool _spell ) {
00361     mSubjectTextWasSpellChecked = _spell;
00362   }
00363   bool subjectTextWasSpellChecked() const { return mSubjectTextWasSpellChecked; }
00364 
00365 
00367   void setSigningAndEncryptionDisabled( bool v )
00368   {
00369     mSigningAndEncryptionExplicitlyDisabled = v;
00370   }
00371 
00372 public: // kmkernel
00376   void setAutoSaveFilename( const QString & filename );
00377 
00378 
00379 public slots:
00383   void slotPrint();
00384   void slotAttachFile();
00385   void slotSendNow();
00386   void slotSendLater();
00390   void slotSaveDraft();
00391   void slotNewComposer();
00392   void slotNewMailReader();
00393   void slotClose();
00394   void slotHelp();
00395 
00396   void slotFind();
00397   void slotSearchAgain();
00398   void slotReplace();
00399   void slotUndo();
00400   void slotRedo();
00401   void slotCut();
00402   void slotCopy();
00403   void slotPaste();
00404   void slotPasteAsQuotation();
00405   void slotAddQuotes();
00406   void slotRemoveQuotes();
00407 
00408   void slotMarkAll();
00409 
00410   void slotFolderRemoved(KMFolder*);
00411 
00418   void slotSetAlwaysSend( bool bAlwaysSend );
00419 
00423   void slotUpdateFont();
00424 
00428   void slotAddrBook();
00432   void slotInsertFile();
00433 
00434   void slotSetCharset();
00438   void slotSpellcheck();
00439   void slotSpellcheckConfig();
00440   void slotSubjectTextSpellChecked();
00441 
00445   void slotMenuTextCompletion();
00446 
00447 
00451   void slotConfigureAddressCompletion();
00452 
00457   void slotSelectCryptoModule();
00458 
00462   void slotStatusMessage(const QString &message);
00463   void slotEditToolbars();
00464   void slotUpdateToolbars();
00465   void slotEditKeys();
00469   void readConfig(void);
00473   void slotUpdWinTitle(const QString& );
00474 
00479   void slotEncryptToggled(bool);
00480 
00484   void slotSignToggled(bool);
00485 
00489   void slotWordWrapToggled(bool);
00490 
00494   void slotAppendSignature();
00495 
00499   void slotPrependSignature();
00500 
00504   void slotInsertSignatureAtCursor();
00505 
00509   void slotInsertMyPublicKey();
00510 
00514   void slotInsertPublicKey();
00515 
00519   void slotUpdateAttachActions();
00520 
00524   void slotAttachPopupMenu(QListViewItem *, const QPoint &, int);
00525 
00530   int currentAttachmentNum();
00531 
00535   void slotAttachView();
00536   void slotAttachRemove();
00537   void slotAttachSave();
00538   void slotAttachProperties();
00539   void slotAttachOpen();
00540   void slotAttachOpenWith();
00541 
00542 
00547   void slotAddrBookTo();
00548   void slotAddrBookFrom();
00549   void slotAddrBookReplyTo();
00550 
00551   void slotCleanSpace();
00552 
00553   void slotToggleMarkup();
00554   void toggleMarkup(bool markup);
00555 
00556 //  void slotSpellConfigure();
00557   void slotSpellcheckDone(int result);
00558   void slotSpellcheckDoneClearStatus();
00559 
00560   void autoSaveMessage();
00561 
00562   void updateCursorPosition();
00563 
00564   void slotView();
00565 
00569   void focusNextPrevEdit(const QWidget* current, bool next);
00570 
00574   void slotIdentityChanged(uint);
00575 
00579   void slotAttachFileData(KIO::Job *, const QByteArray &);
00580   void slotAttachFileResult(KIO::Job *);
00581 
00582   void slotListAction(const QString &);
00583   void slotFontAction(const QString &);
00584   void slotSizeAction(int);
00585   void slotAlignLeft();
00586   void slotAlignCenter();
00587   void slotAlignRight();
00588   void slotTextBold();
00589   void slotTextItalic();
00590   void slotTextUnder();
00591   void slotFormatReset();
00592   void slotTextColor();
00593   void fontChanged( const QFont & );
00594   void alignmentChanged( int );
00595 
00596   void addAttach(const KURL url);
00597 
00601    void addAttach(const KMMessagePart* msgPart);
00602 
00603 public:
00604    const KPIM::Identity & identity() const;
00605    Kleo::CryptoMessageFormat cryptoMessageFormat() const;
00606    bool encryptToSelf() const;
00607 
00608 signals:
00612   void messageQueuedOrDrafted();
00613 
00614   void applyChangesDone( bool );
00615 
00616 protected:
00624   void applyChanges( bool dontSignNorEncrypt, bool dontDisable=false );
00625 
00631   void rethinkFields(bool fromslot=false);
00632 
00637   void rethinkHeaderLine( int aValue, int aMask, int& aRow,
00638                           const QString &aLabelStr, QLabel* aLbl,
00639                           QLineEdit* aEdt, QPushButton* aBtn = 0,
00640                           const QString &toolTip = QString::null,
00641                           const QString &whatsThis = QString::null );
00642 
00643   void rethinkHeaderLine( int value, int mask, int& row,
00644                           const QString& labelStr, QLabel* lbl,
00645                           QComboBox* cbx, QCheckBox *chk );
00646 
00650   void setupActions(int aCryptoMessageFormat=-1);
00651   void setupStatusBar();
00652   void setupEditor();
00653 
00654 
00658   QString subject() const;
00659   QString to() const;
00660   QString cc() const;
00661   QString bcc() const;
00662   QString from() const;
00663   QString replyTo() const;
00664 
00670   void setFcc( const QString &idString );
00671 
00675   virtual bool queryClose ();
00679   virtual bool queryExit ();
00680 
00684   void viewAttach( int index );
00685 
00689    void removeAttach(const QString &url);
00690    void removeAttach(int idx);
00691 
00695     void openAttach( int index, bool with );
00696 
00700    void msgPartToItem(const KMMessagePart* msgPart, KMAtmListViewItem *lvi);
00701 
00706   void addrBookSelInto();
00707 
00708 private:
00713   void setEncryption( bool encrypt, bool setByUser = false );
00714 
00719   void setSigning( bool sign, bool setByUser = false );
00720 
00724   bool userForgotAttachment();
00725 
00730   bool encryptFlagOfAttachment(int idx);
00731 
00736   bool signFlagOfAttachment(int idx);
00737 
00738 
00746    static void decryptOrStripOffCleartextSignature( QCString& );
00747 
00751   void doSend(int sendNow=-1, bool saveInDrafts = false);
00752 
00756   int autoSaveInterval() const;
00757 
00761   void initAutoSave();
00762 
00767   void updateAutoSave();
00768 
00772   void cleanupAutoSave();
00773 
00778   void insertSignature( bool append = true, int pos = 0 );
00779 
00780 
00781 protected:
00782   QWidget   *mMainWidget;
00783   QComboBox *mTransport;
00784   KMail::DictionaryComboBox *mDictionaryCombo;
00785   KPIM::IdentityCombo    *mIdentity;
00786   KMFolderComboBox *mFcc;
00787   KMLineEdit *mEdtFrom, *mEdtReplyTo, *mEdtTo, *mEdtCc, *mEdtBcc;
00788   KMLineEditSpell *mEdtSubject;
00789   QLabel    *mLblIdentity, *mLblTransport, *mLblFcc;
00790   QLabel    *mLblFrom, *mLblReplyTo, *mLblTo, *mLblCc, *mLblBcc, *mLblSubject;
00791   QLabel    *mDictionaryLabel;
00792   QCheckBox *mBtnIdentity, *mBtnTransport, *mBtnFcc;
00793   QPushButton *mBtnTo, *mBtnCc, *mBtnBcc, /* *mBtnFrom, */ *mBtnReplyTo;
00794   bool mSpellCheckInProgress;
00795   bool mDone;
00796   bool mAtmModified;
00797 
00798   KMEdit* mEditor;
00799   QGridLayout* mGrid;
00800   KMMessage *mMsg;
00801   QValueVector<KMMessage*> mComposedMessages;
00802   KMail::AttachmentListView* mAtmListView;
00803   int mAtmColEncrypt;
00804   int mAtmColSign;
00805   int mAtmEncryptColWidth;
00806   int mAtmSignColWidth;
00807   QPtrList<QListViewItem> mAtmItemList;
00808   QPtrList<KMMessagePart> mAtmList;
00809   QPopupMenu *mAttachMenu;
00810   int mOpenId, mOpenWithId, mViewId, mRemoveId, mSaveAsId, mPropertiesId;
00811   bool mAutoSign, mAutoPgpSign, mAutoPgpEncrypt, mAutoDeleteMsg;
00812   bool mNeverSignWhenSavingInDrafts, mNeverEncryptWhenSavingInDrafts;
00813   bool mSigningAndEncryptionExplicitlyDisabled;
00814   bool mAutoRequestMDN;
00815   bool mLastSignActionState, mLastEncryptActionState;
00816   bool mLastIdentityHasSigningKey, mLastIdentityHasEncryptionKey;
00817   KMFolder *mFolder;
00818   long mShowHeaders;
00819   QString mExtEditor;
00820   bool mUseHTMLEditor;
00821   bool mUseExtEditor;
00822   QPtrList<_StringPair> mCustHeaders;
00823   bool mConfirmSend;
00824   bool mDisableBreaking; // Move
00825   int mNumHeaders;
00826   int mLineBreak;
00827   int mWordWrap;
00828   bool mUseFixedFont;
00829   QFont mBodyFont, mFixedFont;
00830   //  QList<QLineEdit> mEdtList;
00831   QPtrList<QWidget> mEdtList;
00832   QPtrList<KTempFile> mAtmTempList;
00833   QPalette mPalette;
00834   uint mId;
00835   QString mOldSigText;
00836   QStringList mTransportHistory;
00837 
00838   KAction *mAttachPK, *mAttachMPK,
00839           *mAttachRemoveAction, *mAttachSaveAction, *mAttachPropertiesAction;
00840 
00841   KAction *mAppendSignatureAction, *mPrependSignatureAction, *mInsertSignatureAction;
00842 
00843   KToggleAction *mSignAction, *mEncryptAction, *mRequestMDNAction;
00844   KToggleAction *mUrgentAction, *mAllFieldsAction, *mFromAction;
00845   KToggleAction *mReplyToAction, *mToAction, *mCcAction, *mBccAction;
00846   KToggleAction *mSubjectAction;
00847   KToggleAction *mIdentityAction, *mTransportAction, *mFccAction;
00848   KToggleAction *mWordWrapAction, *mFixedFontAction, *mAutoSpellCheckingAction;
00849   KToggleAction *mDictionaryAction;
00850 
00851   KSelectAction *listAction;
00852   KFontAction *fontAction;
00853   KFontSizeAction *fontSizeAction;
00854   KToggleAction *alignLeftAction, *alignCenterAction, *alignRightAction;
00855   KToggleAction *textBoldAction, *textItalicAction, *textUnderAction;
00856   KToggleAction *plainTextAction, *markupAction;
00857   KAction *actionFormatColor, *actionFormatReset;
00858   KAction *mHtmlToolbar;
00859 
00860   KSelectAction *mEncodingAction;
00861   KSelectAction *mCryptoModuleAction;
00862 
00863   KSelectAction *mTextCompletionAction;
00864 
00865   QCString mCharset;
00866   QCString mDefCharset;
00867   QStringList mCharsets;
00868   bool mAutoCharset;
00869 
00870   bool mAlwaysSend;
00871   bool mOutlookCompatible;
00872 
00873   QStringList mFolderNames;
00874   QValueList<QGuardedPtr<KMFolder> > mFolderList;
00875 
00876 private:
00877   // helper method for slotInsert(My)PublicKey()
00878   void startPublicKeyExport();
00879   bool canSignEncryptAttachments() const {
00880     return cryptoMessageFormat() != Kleo::InlineOpenPGPFormat;
00881   }
00882 
00883   bool mSubjectTextWasSpellChecked;
00884 
00885 private slots:
00886   void slotCompletionModeChanged( KGlobalSettings::Completion );
00887   void slotConfigChanged();
00888 
00889   void slotComposerDone( bool );
00890 
00891   void slotContinueDoSend( bool );
00892   void slotContinuePrint( bool );
00893   void slotContinueAutoSave( bool );
00894 
00895   void slotEncryptBodyChiasmusToggled( bool );
00896   void slotEncryptChiasmusToggled( bool );
00897 
00898   void slotUpdateSignatureActions();
00899 
00904   void slotPublicKeyExportResult( const GpgME::Error & err, const QByteArray & keydata );
00905 
00909   void slotAutoSpellCheckingToggled(bool);
00910 
00911 private:
00912   QColor mForeColor,mBackColor;
00913   QFont mSaveFont;
00914   struct atmLoadData
00915   {
00916     KURL url;
00917     QByteArray data;
00918     bool insert;
00919     QCString encoding;
00920   };
00921   QMap<KIO::Job *, atmLoadData> mMapAtmLoadData;
00922   bool mForceReplyCharset;
00923 
00924   // These are for passing on methods over the applyChanges calls
00925   int mSendNow;
00926   bool mSaveInDrafts;
00927 
00928 #ifdef KLEO_CHIASMUS
00929   KToggleAction *mEncryptChiasmusAction;
00930   KToggleAction *mEncryptBodyChiasmusAction;
00931   bool mEncryptWithChiasmus;
00932   bool mEncryptBodyWithChiasmus;
00933   QString mChiasmusKey;
00934   QString mChiasmusOptions;
00935 #endif
00936 
00937   // This is the temporary object that constructs the message out of the
00938   // window
00939   MessageComposer* mComposer;
00940 
00941   // Temp var for slotPrint:
00942   bool mMessageWasModified;
00943 
00944   // Temp var for slotInsert(My)PublicKey():
00945   QString mFingerprint;
00946 
00947   QTimer *mAutoSaveTimer;
00948   QString mAutoSaveFilename;
00949   int mLastAutoSaveErrno; // holds the errno of the last try to autosave
00950 
00951 
00952 };
00953 
00954 #endif
00955 
KDE Logo
This file is part of the documentation for kmail Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu May 3 20:23:08 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003