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 <tqlabel.h>
00020 #include <tqlistview.h>
00021 
00022 #include <tqcheckbox.h>
00023 #include <tqpushbutton.h>
00024 #include <tqclipboard.h>
00025 #include <tqpalette.h>
00026 #include <tqfont.h>
00027 #include <tqptrlist.h>
00028 #include <tqvaluevector.h>
00029 #include <tqsplitter.h>
00030 
00031 #include <tdeio/job.h>
00032 #include <tdeglobalsettings.h>
00033 #include <tdeversion.h>
00034 #include <keditcl.h>
00035 #include <ktempdir.h>
00036 
00037 #include "mailcomposerIface.h"
00038 #include "accountmanager.h"
00039 
00040 #include <libtdepim/addresseelineedit.h>
00041 #include <mimelib/mediatyp.h>
00042 
00043 #include <kleo/enum.h>
00044 
00045 class TQCloseEvent;
00046 class TQComboBox;
00047 class TQFrame;
00048 class TQGridLayout;
00049 class TQListView;
00050 class TQPopupMenu;
00051 class TQPushButton;
00052 class TQCString;
00053 class TDECompletion;
00054 class KMEdit;
00055 class KMComposeWin;
00056 class KMFolderComboBox;
00057 class KMFolder;
00058 class KMMessage;
00059 class KMMessagePart;
00060 class TDEProcess;
00061 class KDirWatch;
00062 class TDESelectAction;
00063 class TDEFontAction;
00064 class TDEFontSizeAction;
00065 class TDESelectAction;
00066 class KStatusBar;
00067 class TDEAction;
00068 class TDEToggleAction;
00069 class KTempFile;
00070 class TDEToolBar;
00071 class TDEToggleAction;
00072 class TDESelectColorAction;
00073 class KURL;
00074 class TDERecentFilesAction;
00075 class SpellingFilter;
00076 class MessageComposer;
00077 class RecipientsEditor;
00078 class KMLineEdit;
00079 class KMLineEditSpell;
00080 class KMAtmListViewItem;
00081 class SnippetWidget;
00082 
00083 namespace KPIM {
00084   class IdentityCombo;
00085   class Identity;
00086 }
00087 
00088 namespace KMail {
00089   class AttachmentListView;
00090   class DictionaryComboBox;
00091   class EditorWatcher;
00092 }
00093 
00094 namespace GpgME {
00095   class Error;
00096 }
00097 
00098 //-----------------------------------------------------------------------------
00099 class KMComposeWin : public KMail::Composer, public MailComposerIface
00100 {
00101   Q_OBJECT
00102   
00103   friend class ::KMEdit;
00104   friend class ::MessageComposer;
00105 
00106 private: // mailserviceimpl, kmkernel, kmcommands, callback, kmmainwidget
00107   KMComposeWin( KMMessage* msg=0, uint identity=0 );
00108   ~KMComposeWin();
00109 public:
00110   static Composer * create( KMMessage * msg = 0, uint identity = 0 );
00111 
00112   MailComposerIface * asMailComposerIFace() { return this; }
00113   const MailComposerIface * asMailComposerIFace() const { return this; }
00114 
00115 public: // mailserviceimpl
00119   void send(int how);
00120   void addAttachmentsAndSend(const KURL::List &urls, const TQString &comment, int how);
00121   void addAttachment(KURL url,TQString comment);
00122   void addAttachment(const TQString &name,
00123                     const TQCString &cte,
00124                     const TQByteArray &data,
00125                     const TQCString &type,
00126                     const TQCString &subType,
00127                     const TQCString &paramAttr,
00128                     const TQString &paramValue,
00129                     const TQCString &contDisp);
00130 public: // kmcommand
00131   void setBody (TQString body);
00132 
00133 private:
00137   virtual bool event(TQEvent *e);
00138 
00142   void readColorConfig();
00143 
00147    void writeConfig(void);
00148 
00153    void verifyWordWrapLengthIsAdequate(const TQString&);
00154 
00155 public: // kmkernel, kmcommands, callback
00160    void setMsg(KMMessage* newMsg, bool mayAutoSign=TRUE,
00161            bool allowDecryption=FALSE, bool isModified=FALSE);
00162 
00163    void disableWordWrap();
00164 
00168   void disableRecipientNumberCheck();
00169 
00173   void disableForgottenAttachmentsCheck();
00174 
00184   void ignoreStickyFields();
00185 
00189    bool isComposing() const { return mComposer != 0; }
00190 
00191 private: // kmedit
00196    KMMessage* msg() const { return mMsg; }
00197 
00198 public: // kmkernel
00202   void setAutoSaveFilename( const TQString & filename );
00203 
00204 private:
00208   bool isModified() const;
00209 
00213   void setModified( bool modified );
00214 
00215 public: // kmkernel, callback
00220    inline void setAutoDelete(bool f) { mAutoDeleteMsg = f; }
00221 
00226   void setAutoDeleteWindow( bool f );
00227 
00228 public: // kmcommand
00233    void setFolder(KMFolder* aFolder) { mFolder = aFolder; }
00234 public: // kmkernel, kmcommand, mailserviceimpl
00238    void setCharset(const TQCString& aCharset, bool forceDefault = FALSE);
00239 
00240 public: // kmcommand
00246    void setReplyFocus( bool hasMessage = true );
00247 
00252    void setFocusToSubject();
00253 
00254 private:
00258    bool inlineSigningEncryptionSelected();
00259 
00265    static TQString prettyMimeType( const TQString& type );
00266     TQString quotePrefixName() const;
00267 
00268 private: // kmedit:
00269   KMLineEditSpell *sujectLineWidget() const { return mEdtSubject;}
00270   void setSubjectTextWasSpellChecked( bool _spell ) {
00271     mSubjectTextWasSpellChecked = _spell;
00272   }
00273   bool subjectTextWasSpellChecked() const { return mSubjectTextWasSpellChecked; }
00274 
00275   void paste( TQClipboard::Mode mode );
00276 
00277 public: // callback
00279   void setSigningAndEncryptionDisabled( bool v )
00280   {
00281     mSigningAndEncryptionExplicitlyDisabled = v;
00282   }
00283 
00284 private slots:
00285   void polish();
00289   void slotPrint();
00290   void slotAttachFile();
00291   void slotInsertRecentFile(const KURL&);
00292   void slotAttachedFile(const KURL&);
00293 public slots: // kmkernel, callback
00294   void slotSendNow();
00295 private slots:
00296   void slotSendNowVia( int item );
00297   void slotSendLater();
00298   void slotSendLaterVia( int item );
00299 
00300   void getTransportMenu();
00301 
00305   void slotSaveDraft();
00306   void slotSaveTemplate();
00307   void slotNewComposer();
00308   void slotNewMailReader();
00309   void slotClose();
00310   void slotHelp();
00311 
00312   void slotFind();
00313   void slotSearchAgain();
00314   void slotReplace();
00315   void slotUndo();
00316   void slotRedo();
00317   void slotCut();
00318   void slotCopy();
00319   void slotPasteClipboard();
00320   void slotPasteClipboardAsQuotation();
00321   void slotPasteClipboardAsAttachment();
00322   void slotAddQuotes();
00323   void slotRemoveQuotes();
00324   void slotAttachPNGImageData(const TQByteArray &image);
00325 
00326   void slotMarkAll();
00327 
00328   void slotFolderRemoved(KMFolder*);
00329 
00330   void slotEditDone( KMail::EditorWatcher* watcher );
00331 
00332 public slots: // kmkernel
00339   void slotSetAlwaysSend( bool bAlwaysSend );
00340 private slots:
00344   void slotUpdateFont();
00345 
00349   void slotAddrBook();
00353   void slotInsertFile();
00354 
00355   void slotSetCharset();
00359   void slotSpellcheck();
00360   void slotSpellcheckConfig();
00361   void slotSubjectTextSpellChecked();
00362 
00367   void slotSelectCryptoModule( bool init = false );
00368 
00372   void slotStatusMessage(const TQString &message);
00373   void slotEditToolbars();
00374   void slotUpdateToolbars();
00375   void slotEditKeys();
00379   void readConfig( bool reload = false );
00383   void slotUpdWinTitle(const TQString& );
00384 
00389   void slotEncryptToggled(bool);
00390 
00394   void slotSignToggled(bool);
00395 
00396 public slots: // kmkernel, callback
00400   void slotWordWrapToggled(bool);
00401 
00402 private slots:
00406   void slotAppendSignature();
00407 
00411   void slotPrependSignature();
00412 
00416   void slotInsertSignatureAtCursor();
00417 
00421   void slotInsertMyPublicKey();
00422 
00426   void slotInsertPublicKey();
00427 
00431   void slotUpdateAttachActions();
00432 
00436   void slotAttachPopupMenu(TQListViewItem *, const TQPoint &, int);
00437 
00442   int currentAttachmentNum();
00443 
00447   void slotAttachOpen();
00448   void slotAttachView();
00449   void slotAttachRemove();
00450   void slotAttachSave();
00451   void slotAttachProperties();
00452   void slotAttachOpenWith();
00453   void slotAttachEdit();
00454   void slotAttachEditWith();
00455   void slotAttachmentDragStarted();
00456 
00461   void slotAddrBookTo();
00462   void slotAddrBookFrom();
00463   void slotAddrBookReplyTo();
00464 
00465   void slotCleanSpace();
00466 
00467   void slotToggleMarkup();
00468   void toggleMarkup(bool markup);
00469   void htmlToolBarVisibilityChanged( bool visible );
00470 
00471 //  void slotSpellConfigure();
00472   void slotSpellcheckDone(int result);
00473   void slotSpellcheckDoneClearStatus();
00474 
00475 public slots: // kmkernel
00476   void autoSaveMessage();
00477 
00478 private slots:
00479   void updateCursorPosition();
00480 
00481   void slotView();
00482 
00486   void slotIdentityChanged(uint);
00487 
00491   void slotAttachFileData(TDEIO::Job *, const TQByteArray &);
00492   void slotAttachFileResult(TDEIO::Job *);
00493 
00494   void slotListAction(const TQString &);
00495   void slotFontAction(const TQString &);
00496   void slotSizeAction(int);
00497   void slotAlignLeft();
00498   void slotAlignCenter();
00499   void slotAlignRight();
00500   void slotTextBold();
00501   void slotTextItalic();
00502   void slotTextUnder();
00503   void slotFormatReset();
00504   void slotTextColor();
00505   void fontChanged( const TQFont & );
00506   void alignmentChanged( int );
00507 
00508 public: // kmkernel, attachmentlistview
00509   bool addAttach(const KURL url);
00510 
00511 public: // kmcommand
00515   void addAttach(const KMMessagePart* msgPart);
00516 
00517 private:
00518   const KPIM::Identity & identity() const;
00519   uint identityUid() const;
00520   Kleo::CryptoMessageFormat cryptoMessageFormat() const;
00521   bool encryptToSelf() const;
00522 
00523 signals:
00524   void applyChangesDone( bool );
00525   void attachmentAdded( const KURL&, bool success );
00526 
00527 private:
00535   void applyChanges( bool dontSignNorEncrypt, bool dontDisable=false );
00536 
00542   void rethinkFields(bool fromslot=false);
00543 
00547   TQWidget *connectFocusMoving( TQWidget *prev, TQWidget *next );
00548 
00553   void rethinkHeaderLine( int aValue, int aMask, int& aRow,
00554                           TQLabel* aLbl,
00555                           TQLineEdit* aEdt, TQPushButton* aBtn = 0,
00556                           const TQString &toolTip = TQString(),
00557                           const TQString &whatsThis = TQString() );
00558 
00559   void rethinkHeaderLine( int value, int mask, int& row,
00560                           TQLabel* lbl, TQComboBox* cbx, TQCheckBox *chk );
00561 
00566   bool checkRecipientNumber() const;
00567 
00568 
00569   bool checkTransport() const;
00570 
00574   void setupActions();
00575   void setupStatusBar();
00576   void setupEditor();
00577 
00578 
00582   TQString subject() const;
00583   TQString to() const;
00584   TQString cc() const;
00585   TQString bcc() const;
00586   TQString from() const;
00587   TQString replyTo() const;
00588 
00594   void setFcc( const TQString &idString );
00595 
00599   virtual bool queryClose ();
00603   virtual bool queryExit ();
00604 
00608   void openAttach( int index, bool with );
00609 
00613   void viewAttach( int index );
00614 
00618   void editAttach( int index, bool openWith );
00619 
00623    void removeAttach(const TQString &url);
00624    void removeAttach(int idx);
00625 
00629    void msgPartToItem(const KMMessagePart* msgPart, KMAtmListViewItem *lvi,
00630         bool loadDefaults = true );
00631 
00636   void addrBookSelInto();
00637 
00638   void addrBookSelIntoOld();
00639   void addrBookSelIntoNew();
00640 
00641 private:
00646   void setEncryption( bool encrypt, bool setByUser = false );
00647 
00652   void setSigning( bool sign, bool setByUser = false );
00653 
00657   bool userForgotAttachment();
00658 
00663   bool encryptFlagOfAttachment(int idx);
00664 
00669   bool signFlagOfAttachment(int idx);
00670 
00671 
00679   static void decryptOrStripOffCleartextSignature( TQCString& );
00680 
00684   bool saveDraftOrTemplate( const TQString &folderName, KMMessage *msg );
00685 
00689   enum SaveIn { None, Drafts, Templates };
00690   void doSend( KMail::MessageSender::SendMethod method=KMail::MessageSender::SendDefault,
00691                KMComposeWin::SaveIn saveIn = KMComposeWin::None );
00692 
00696   int autoSaveInterval() const;
00697 
00701   void initAutoSave();
00702 
00707   void updateAutoSave();
00708 
00712   void cleanupAutoSave();
00713 
00719   static bool validateAddresses( TQWidget * parent, const TQString & addresses );
00720 
00727   void setTransport( const TQString & transport );
00728 
00729   enum SignaturePlacement { Append, Prepend, AtCursor };
00730 
00735   void insertSignature( SignaturePlacement placement = Append );
00736 private slots:
00740     void compressAttach(int idx);
00741     void uncompressAttach(int idx);
00742     void editorFocusChanged(bool gained);
00743     void recipientEditorSizeHintChanged();
00744     void setMaximumHeaderSize();
00745 
00746 private:
00747   TQWidget   *mMainWidget;
00748   TQComboBox *mTransport;
00749   KMail::DictionaryComboBox *mDictionaryCombo;
00750   KPIM::IdentityCombo    *mIdentity;
00751   KMFolderComboBox *mFcc;
00752   KMLineEdit *mEdtFrom, *mEdtReplyTo, *mEdtTo, *mEdtCc, *mEdtBcc;
00753   KMLineEditSpell *mEdtSubject;
00754   TQLabel    *mLblIdentity, *mLblTransport, *mLblFcc;
00755   TQLabel    *mLblFrom, *mLblReplyTo, *mLblTo, *mLblCc, *mLblBcc, *mLblSubject;
00756   TQLabel    *mDictionaryLabel;
00757   TQCheckBox *mBtnIdentity, *mBtnDictionary, *mBtnTransport, *mBtnFcc;
00758   TQPushButton *mBtnTo, *mBtnCc, *mBtnBcc, /* *mBtnFrom, */ *mBtnReplyTo;
00759   bool mSpellCheckInProgress;
00760   bool mDone;
00761   bool mAtmModified;
00762   TQListViewItem *mAtmSelectNew;
00763 
00764   KMEdit* mEditor;
00765   TQGridLayout* mGrid;
00766   KMMessage *mMsg;
00767   TQValueVector<KMMessage*> mComposedMessages;
00768   KMail::AttachmentListView* mAtmListView;
00769   int mAtmColEncrypt;
00770   int mAtmColSign;
00771   int mAtmColCompress;
00772   int mAtmEncryptColWidth;
00773   int mAtmSignColWidth;
00774   int mAtmCompressColWidth;
00775   TQPtrList<TQListViewItem> mAtmItemList;
00776   TQPtrList<KMMessagePart> mAtmList;
00777   TQPopupMenu *mAttachMenu;
00778   int mOpenId, mOpenWithId, mViewId, mRemoveId, mSaveAsId, mPropertiesId, mEditId, mEditWithId;
00779   bool mAutoDeleteMsg;
00780   bool mSigningAndEncryptionExplicitlyDisabled;
00781   bool mLastSignActionState, mLastEncryptActionState;
00782   bool mLastIdentityHasSigningKey, mLastIdentityHasEncryptionKey;
00783   KMFolder *mFolder;
00784   long mShowHeaders;
00785   bool mConfirmSend;
00786   bool mDisableBreaking; // Move
00787   int mNumHeaders;
00788   bool mUseHTMLEditor;
00789   bool mHtmlMarkup;
00790   TQFont mBodyFont, mFixedFont;
00791   TQPtrList<KTempFile> mAtmTempList;
00792   TQPalette mPalette;
00793   uint mId;
00794   TQString mOldSigText;
00795 
00796   TDEAction *mAttachPK, *mAttachMPK,
00797           *mAttachRemoveAction, *mAttachSaveAction, *mAttachPropertiesAction,
00798           *mPasteQuotation, *mAddQuoteChars, *mRemQuoteChars;
00799   TDERecentFilesAction *mRecentAction;
00800 
00801   TDEAction *mAppendSignatureAction, *mPrependSignatureAction, *mInsertSignatureAction;
00802 
00803   TDEToggleAction *mSignAction, *mEncryptAction, *mRequestMDNAction;
00804   TDEToggleAction *mUrgentAction, *mAllFieldsAction, *mFromAction;
00805   TDEToggleAction *mReplyToAction, *mToAction, *mCcAction, *mBccAction;
00806   TDEToggleAction *mSubjectAction;
00807   TDEToggleAction *mIdentityAction, *mTransportAction, *mFccAction;
00808   TDEToggleAction *mWordWrapAction, *mFixedFontAction, *mAutoSpellCheckingAction;
00809   TDEToggleAction *mDictionaryAction, *mSnippetAction;
00810 
00811   TDESelectAction *listAction;
00812   TDEFontAction *fontAction;
00813   TDEFontSizeAction *fontSizeAction;
00814   TDEToggleAction *alignLeftAction, *alignCenterAction, *alignRightAction;
00815   TDEToggleAction *textBoldAction, *textItalicAction, *textUnderAction;
00816   TDEToggleAction *plainTextAction, *markupAction;
00817   TDEAction *actionFormatColor, *actionFormatReset;
00818   TDEAction *mHtmlToolbar;
00819 
00820   TDESelectAction *mEncodingAction;
00821   TDESelectAction *mCryptoModuleAction;
00822 
00823   TQCString mCharset;
00824   TQCString mDefCharset;
00825   TQStringList mCharsets;
00826   bool mAutoCharset;
00827 
00828   bool mAlwaysSend;
00829 
00830   TQStringList mFolderNames;
00831   TQValueList<TQGuardedPtr<KMFolder> > mFolderList;
00832   TQMap<TDEIO::Job*, KURL> mAttachJobs;
00833   KURL::List mAttachFilesPending;
00834   int mAttachFilesSend;
00835 
00836 private:
00837   // helper method for slotInsert(My)PublicKey()
00838   void startPublicKeyExport();
00839   bool canSignEncryptAttachments() const {
00840     return cryptoMessageFormat() != Kleo::InlineOpenPGPFormat;
00841   }
00842 
00843   bool mSubjectTextWasSpellChecked;
00844 
00845   TQString addQuotesToText( const TQString &inputText );
00846   TQString removeQuotesFromText( const TQString &inputText );
00847   // helper method for rethinkFields
00848   int calcColumnWidth(int which, long allShowing, int width);
00849 
00850 private slots:
00851   void slotCompletionModeChanged( TDEGlobalSettings::Completion );
00852   void slotConfigChanged();
00853 
00854   void slotComposerDone( bool );
00855 
00856   void slotContinueDoSend( bool );
00857   void slotContinuePrint( bool );
00858   void slotContinueAutoSave();
00859 
00860   void slotEncryptChiasmusToggled( bool );
00861 
00866   void slotPublicKeyExportResult( const GpgME::Error & err, const TQByteArray & keydata );
00867 
00871   void slotAutoSpellCheckingToggled(bool);
00872 
00876   void slotUpdateSignatureActions();
00877 
00881   void slotUpdateSignatureAndEncrypionStateIndicators();
00882 private:
00883   TQColor mForeColor,mBackColor;
00884   TQFont mSaveFont;
00885   TQSplitter *mHeadersToEditorSplitter;
00886   TQWidget* mHeadersArea;
00887   TQSplitter *mSplitter;
00888   TQSplitter *mSnippetSplitter;
00889   struct atmLoadData
00890   {
00891     KURL url;
00892     TQByteArray data;
00893     bool insert;
00894     TQCString encoding;
00895   };
00896   TQMap<TDEIO::Job *, atmLoadData> mMapAtmLoadData;
00897 
00898   // These are for passing on methods over the applyChanges calls
00899   KMail::MessageSender::SendMethod mSendMethod;
00900   KMComposeWin::SaveIn mSaveIn;
00901 
00902   TDEToggleAction *mEncryptChiasmusAction;
00903   bool mEncryptWithChiasmus;
00904 
00905   // This is the temporary object that constructs the message out of the
00906   // window
00907   MessageComposer* mComposer;
00908 
00909   // Temp var for slotPrint:
00910   bool mMessageWasModified;
00911 
00912   // Temp var for slotInsert(My)PublicKey():
00913   TQString mFingerprint;
00914 
00915   // Temp ptr for saving image from clipboard
00916   KTempDir *mTempDir;
00917 
00918   bool mClassicalRecipients;
00919 
00920   RecipientsEditor *mRecipientsEditor;
00921   int mLabelWidth;
00922 
00923   TQTimer *mAutoSaveTimer;
00924   TQString mAutoSaveFilename;
00925   int mLastAutoSaveErrno; // holds the errno of the last try to autosave
00926 
00927   TQPopupMenu *mActNowMenu;
00928   TQPopupMenu *mActLaterMenu;
00929 
00930   TQMap<KMail::EditorWatcher*, KMMessagePart*> mEditorMap;
00931   TQMap<KMail::EditorWatcher*, KTempFile*> mEditorTempFiles;
00932 
00933   TQLabel *mSignatureStateIndicator;
00934   TQLabel *mEncryptionStateIndicator;
00935 
00936   SnippetWidget *mSnippetWidget;
00937   std::set<KTempDir*> mTempDirs;
00938 
00946   bool mPreserveUserCursorPosition;
00947 
00948   bool mPreventFccOverwrite;
00949   bool mCheckForRecipients;
00950   bool mCheckForForgottenAttachments;
00951   bool mIgnoreStickyFields;
00952 };
00953 
00954 #endif
00955