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 
00177   void ignoreStickyFields();
00178 
00182    bool isComposing() const { return mComposer != 0; }
00183 
00184 private: // kmedit
00189    KMMessage* msg() const { return mMsg; }
00190 
00191 public: // kmkernel
00195   void setAutoSaveFilename( const QString & filename );
00196 
00197 private:
00201   bool isModified() const;
00202 
00206   void setModified( bool modified );
00207 
00208 public: // kmkernel, callback
00213    inline void setAutoDelete(bool f) { mAutoDeleteMsg = f; }
00214 
00219   void setAutoDeleteWindow( bool f );
00220 
00221 public: // kmcommand
00226    void setFolder(KMFolder* aFolder) { mFolder = aFolder; }
00227 public: // kmkernel, kmcommand, mailserviceimpl
00231    void setCharset(const QCString& aCharset, bool forceDefault = FALSE);
00232 
00233 public: // kmcommand
00239    void setReplyFocus( bool hasMessage = true );
00240 
00245    void setFocusToSubject();
00246 
00247 private:
00251    bool inlineSigningEncryptionSelected();
00252 
00258    static QString prettyMimeType( const QString& type );
00259     QString quotePrefixName() const;
00260 
00261 private: // kmedit:
00262   KMLineEditSpell *sujectLineWidget() const { return mEdtSubject;}
00263   void setSubjectTextWasSpellChecked( bool _spell ) {
00264     mSubjectTextWasSpellChecked = _spell;
00265   }
00266   bool subjectTextWasSpellChecked() const { return mSubjectTextWasSpellChecked; }
00267 
00268   void paste( QClipboard::Mode mode );
00269 
00270 public: // callback
00272   void setSigningAndEncryptionDisabled( bool v )
00273   {
00274     mSigningAndEncryptionExplicitlyDisabled = v;
00275   }
00276 
00277 private slots:
00278   void polish();
00282   void slotPrint();
00283   void slotAttachFile();
00284   void slotInsertRecentFile(const KURL&);
00285   void slotAttachedFile(const KURL&);
00286 public slots: // kmkernel, callback
00287   void slotSendNow();
00288 private slots:
00289   void slotSendNowVia( int item );
00290   void slotSendLater();
00291   void slotSendLaterVia( int item );
00292 
00293   void getTransportMenu();
00294 
00298   void slotSaveDraft();
00299   void slotSaveTemplate();
00300   void slotNewComposer();
00301   void slotNewMailReader();
00302   void slotClose();
00303   void slotHelp();
00304 
00305   void slotFind();
00306   void slotSearchAgain();
00307   void slotReplace();
00308   void slotUndo();
00309   void slotRedo();
00310   void slotCut();
00311   void slotCopy();
00312   void slotPasteClipboard();
00313   void slotPasteClipboardAsQuotation();
00314   void slotPasteClipboardAsAttachment();
00315   void slotAddQuotes();
00316   void slotRemoveQuotes();
00317   void slotAttachPNGImageData(const QByteArray &image);
00318 
00319   void slotMarkAll();
00320 
00321   void slotFolderRemoved(KMFolder*);
00322 
00323   void slotEditDone( KMail::EditorWatcher* watcher );
00324 
00325 public slots: // kmkernel
00332   void slotSetAlwaysSend( bool bAlwaysSend );
00333 private slots:
00337   void slotUpdateFont();
00338 
00342   void slotAddrBook();
00346   void slotInsertFile();
00347 
00348   void slotSetCharset();
00352   void slotSpellcheck();
00353   void slotSpellcheckConfig();
00354   void slotSubjectTextSpellChecked();
00355 
00360   void slotSelectCryptoModule( bool init = false );
00361 
00365   void slotStatusMessage(const QString &message);
00366   void slotEditToolbars();
00367   void slotUpdateToolbars();
00368   void slotEditKeys();
00372   void readConfig( bool reload = false );
00376   void slotUpdWinTitle(const QString& );
00377 
00382   void slotEncryptToggled(bool);
00383 
00387   void slotSignToggled(bool);
00388 
00389 public slots: // kmkernel, callback
00393   void slotWordWrapToggled(bool);
00394 
00395 private slots:
00399   void slotAppendSignature();
00400 
00404   void slotPrependSignature();
00405 
00409   void slotInsertSignatureAtCursor();
00410 
00414   void slotInsertMyPublicKey();
00415 
00419   void slotInsertPublicKey();
00420 
00424   void slotUpdateAttachActions();
00425 
00429   void slotAttachPopupMenu(QListViewItem *, const QPoint &, int);
00430 
00435   int currentAttachmentNum();
00436 
00440   void slotAttachOpen();
00441   void slotAttachView();
00442   void slotAttachRemove();
00443   void slotAttachSave();
00444   void slotAttachProperties();
00445   void slotAttachOpenWith();
00446   void slotAttachEdit();
00447   void slotAttachEditWith();
00448   void slotAttachmentDragStarted();
00449 
00454   void slotAddrBookTo();
00455   void slotAddrBookFrom();
00456   void slotAddrBookReplyTo();
00457 
00458   void slotCleanSpace();
00459 
00460   void slotToggleMarkup();
00461   void toggleMarkup(bool markup);
00462   void htmlToolBarVisibilityChanged( bool visible );
00463 
00464 //  void slotSpellConfigure();
00465   void slotSpellcheckDone(int result);
00466   void slotSpellcheckDoneClearStatus();
00467 
00468 public slots: // kmkernel
00469   void autoSaveMessage();
00470 
00471 private slots:
00472   void updateCursorPosition();
00473 
00474   void slotView();
00475 
00479   void slotIdentityChanged(uint);
00480 
00484   void slotAttachFileData(KIO::Job *, const QByteArray &);
00485   void slotAttachFileResult(KIO::Job *);
00486 
00487   void slotListAction(const QString &);
00488   void slotFontAction(const QString &);
00489   void slotSizeAction(int);
00490   void slotAlignLeft();
00491   void slotAlignCenter();
00492   void slotAlignRight();
00493   void slotTextBold();
00494   void slotTextItalic();
00495   void slotTextUnder();
00496   void slotFormatReset();
00497   void slotTextColor();
00498   void fontChanged( const QFont & );
00499   void alignmentChanged( int );
00500 
00501 public: // kmkernel, attachmentlistview
00502   bool addAttach(const KURL url);
00503 
00504 public: // kmcommand
00508   void addAttach(const KMMessagePart* msgPart);
00509 
00510 private:
00511   const KPIM::Identity & identity() const;
00512   uint identityUid() const;
00513   Kleo::CryptoMessageFormat cryptoMessageFormat() const;
00514   bool encryptToSelf() const;
00515 
00516 signals:
00517   void applyChangesDone( bool );
00518   void attachmentAdded( const KURL&, bool success );
00519 
00520 private:
00528   void applyChanges( bool dontSignNorEncrypt, bool dontDisable=false );
00529 
00535   void rethinkFields(bool fromslot=false);
00536 
00540   QWidget *connectFocusMoving( QWidget *prev, QWidget *next );
00541 
00546   void rethinkHeaderLine( int aValue, int aMask, int& aRow,
00547                           const QString &aLabelStr, QLabel* aLbl,
00548                           QLineEdit* aEdt, QPushButton* aBtn = 0,
00549                           const QString &toolTip = QString::null,
00550                           const QString &whatsThis = QString::null );
00551 
00552   void rethinkHeaderLine( int value, int mask, int& row,
00553                           const QString& labelStr, QLabel* lbl,
00554                           QComboBox* cbx, QCheckBox *chk );
00555 
00560   bool checkRecipientNumber() const;
00561 
00562 
00563   bool checkTransport() const;
00564 
00568   void setupActions();
00569   void setupStatusBar();
00570   void setupEditor();
00571 
00572 
00576   QString subject() const;
00577   QString to() const;
00578   QString cc() const;
00579   QString bcc() const;
00580   QString from() const;
00581   QString replyTo() const;
00582 
00588   void setFcc( const QString &idString );
00589 
00593   virtual bool queryClose ();
00597   virtual bool queryExit ();
00598 
00602   void openAttach( int index, bool with );
00603 
00607   void viewAttach( int index );
00608 
00612   void editAttach( int index, bool openWith );
00613 
00617    void removeAttach(const QString &url);
00618    void removeAttach(int idx);
00619 
00623    void msgPartToItem(const KMMessagePart* msgPart, KMAtmListViewItem *lvi,
00624         bool loadDefaults = true );
00625 
00630   void addrBookSelInto();
00631 
00632   void addrBookSelIntoOld();
00633   void addrBookSelIntoNew();
00634 
00635 private:
00640   void setEncryption( bool encrypt, bool setByUser = false );
00641 
00646   void setSigning( bool sign, bool setByUser = false );
00647 
00651   bool userForgotAttachment();
00652 
00657   bool encryptFlagOfAttachment(int idx);
00658 
00663   bool signFlagOfAttachment(int idx);
00664 
00665 
00673   static void decryptOrStripOffCleartextSignature( QCString& );
00674 
00678   bool saveDraftOrTemplate( const QString &folderName, KMMessage *msg );
00679 
00683   enum SaveIn { None, Drafts, Templates };
00684   void doSend( KMail::MessageSender::SendMethod method=KMail::MessageSender::SendDefault,
00685                KMComposeWin::SaveIn saveIn = KMComposeWin::None );
00686 
00690   int autoSaveInterval() const;
00691 
00695   void initAutoSave();
00696 
00701   void updateAutoSave();
00702 
00706   void cleanupAutoSave();
00707 
00713   static bool validateAddresses( QWidget * parent, const QString & addresses );
00714 
00721   void setTransport( const QString & transport );
00722 
00727   void insertSignature( bool append = true, int pos = 0 );
00728 private slots:
00732     void compressAttach(int idx);
00733     void uncompressAttach(int idx);
00734     void editorFocusChanged(bool gained);
00735     void recipientEditorSizeHintChanged();
00736     void setMaximumHeaderSize();
00737 
00738 private:
00739   QWidget   *mMainWidget;
00740   QComboBox *mTransport;
00741   KMail::DictionaryComboBox *mDictionaryCombo;
00742   KPIM::IdentityCombo    *mIdentity;
00743   KMFolderComboBox *mFcc;
00744   KMLineEdit *mEdtFrom, *mEdtReplyTo, *mEdtTo, *mEdtCc, *mEdtBcc;
00745   KMLineEditSpell *mEdtSubject;
00746   QLabel    *mLblIdentity, *mLblTransport, *mLblFcc;
00747   QLabel    *mLblFrom, *mLblReplyTo, *mLblTo, *mLblCc, *mLblBcc, *mLblSubject;
00748   QLabel    *mDictionaryLabel;
00749   QCheckBox *mBtnIdentity, *mBtnTransport, *mBtnFcc;
00750   QPushButton *mBtnTo, *mBtnCc, *mBtnBcc, /* *mBtnFrom, */ *mBtnReplyTo;
00751   bool mSpellCheckInProgress;
00752   bool mDone;
00753   bool mAtmModified;
00754 
00755   KMEdit* mEditor;
00756   QGridLayout* mGrid;
00757   KMMessage *mMsg;
00758   QValueVector<KMMessage*> mComposedMessages;
00759   KMail::AttachmentListView* mAtmListView;
00760   int mAtmColEncrypt;
00761   int mAtmColSign;
00762   int mAtmColCompress;
00763   int mAtmEncryptColWidth;
00764   int mAtmSignColWidth;
00765   int mAtmCompressColWidth;
00766   QPtrList<QListViewItem> mAtmItemList;
00767   QPtrList<KMMessagePart> mAtmList;
00768   QPopupMenu *mAttachMenu;
00769   int mOpenId, mOpenWithId, mViewId, mRemoveId, mSaveAsId, mPropertiesId, mEditId, mEditWithId;
00770   bool mAutoDeleteMsg;
00771   bool mSigningAndEncryptionExplicitlyDisabled;
00772   bool mLastSignActionState, mLastEncryptActionState;
00773   bool mLastIdentityHasSigningKey, mLastIdentityHasEncryptionKey;
00774   KMFolder *mFolder;
00775   long mShowHeaders;
00776   bool mConfirmSend;
00777   bool mDisableBreaking; // Move
00778   int mNumHeaders;
00779   bool mUseHTMLEditor;
00780   bool mHtmlMarkup;
00781   QFont mBodyFont, mFixedFont;
00782   QPtrList<KTempFile> mAtmTempList;
00783   QPalette mPalette;
00784   uint mId;
00785   QString mOldSigText;
00786 
00787   KAction *mAttachPK, *mAttachMPK,
00788           *mAttachRemoveAction, *mAttachSaveAction, *mAttachPropertiesAction,
00789           *mPasteQuotation, *mAddQuoteChars, *mRemQuoteChars;
00790   KRecentFilesAction *mRecentAction;
00791 
00792   KAction *mAppendSignatureAction, *mPrependSignatureAction, *mInsertSignatureAction;
00793 
00794   KToggleAction *mSignAction, *mEncryptAction, *mRequestMDNAction;
00795   KToggleAction *mUrgentAction, *mAllFieldsAction, *mFromAction;
00796   KToggleAction *mReplyToAction, *mToAction, *mCcAction, *mBccAction;
00797   KToggleAction *mSubjectAction;
00798   KToggleAction *mIdentityAction, *mTransportAction, *mFccAction;
00799   KToggleAction *mWordWrapAction, *mFixedFontAction, *mAutoSpellCheckingAction;
00800   KToggleAction *mDictionaryAction, *mSnippetAction;
00801 
00802   KSelectAction *listAction;
00803   KFontAction *fontAction;
00804   KFontSizeAction *fontSizeAction;
00805   KToggleAction *alignLeftAction, *alignCenterAction, *alignRightAction;
00806   KToggleAction *textBoldAction, *textItalicAction, *textUnderAction;
00807   KToggleAction *plainTextAction, *markupAction;
00808   KAction *actionFormatColor, *actionFormatReset;
00809   KAction *mHtmlToolbar;
00810 
00811   KSelectAction *mEncodingAction;
00812   KSelectAction *mCryptoModuleAction;
00813 
00814   QCString mCharset;
00815   QCString mDefCharset;
00816   QStringList mCharsets;
00817   bool mAutoCharset;
00818 
00819   bool mAlwaysSend;
00820 
00821   QStringList mFolderNames;
00822   QValueList<QGuardedPtr<KMFolder> > mFolderList;
00823   QMap<KIO::Job*, KURL> mAttachJobs;
00824   KURL::List mAttachFilesPending;
00825   int mAttachFilesSend;
00826 
00827 private:
00828   // helper method for slotInsert(My)PublicKey()
00829   void startPublicKeyExport();
00830   bool canSignEncryptAttachments() const {
00831     return cryptoMessageFormat() != Kleo::InlineOpenPGPFormat;
00832   }
00833 
00834   bool mSubjectTextWasSpellChecked;
00835 
00836   QString addQuotesToText( const QString &inputText );
00837   QString removeQuotesFromText( const QString &inputText );
00838   // helper method for rethinkFields
00839   int calcColumnWidth(int which, long allShowing, int width);
00840 
00841 private slots:
00842   void slotCompletionModeChanged( KGlobalSettings::Completion );
00843   void slotConfigChanged();
00844 
00845   void slotComposerDone( bool );
00846 
00847   void slotContinueDoSend( bool );
00848   void slotContinuePrint( bool );
00849   void slotContinueAutoSave();
00850 
00851   void slotEncryptChiasmusToggled( bool );
00852 
00857   void slotPublicKeyExportResult( const GpgME::Error & err, const QByteArray & keydata );
00858 
00862   void slotAutoSpellCheckingToggled(bool);
00863 
00867   void slotUpdateSignatureActions();
00868 
00872   void slotUpdateSignatureAndEncrypionStateIndicators();
00873 private:
00874   QColor mForeColor,mBackColor;
00875   QFont mSaveFont;
00876   QSplitter *mHeadersToEditorSplitter;
00877   QWidget* mHeadersArea;
00878   QSplitter *mSplitter;
00879   QSplitter *mSnippetSplitter;
00880   struct atmLoadData
00881   {
00882     KURL url;
00883     QByteArray data;
00884     bool insert;
00885     QCString encoding;
00886   };
00887   QMap<KIO::Job *, atmLoadData> mMapAtmLoadData;
00888 
00889   // These are for passing on methods over the applyChanges calls
00890   KMail::MessageSender::SendMethod mSendMethod;
00891   KMComposeWin::SaveIn mSaveIn;
00892 
00893   KToggleAction *mEncryptChiasmusAction;
00894   bool mEncryptWithChiasmus;
00895 
00896   // This is the temporary object that constructs the message out of the
00897   // window
00898   MessageComposer* mComposer;
00899 
00900   // Temp var for slotPrint:
00901   bool mMessageWasModified;
00902 
00903   // Temp var for slotInsert(My)PublicKey():
00904   QString mFingerprint;
00905 
00906   // Temp ptr for saving image from clipboard
00907   KTempDir *mTempDir;
00908 
00909   bool mClassicalRecipients;
00910 
00911   RecipientsEditor *mRecipientsEditor;
00912   int mLabelWidth;
00913 
00914   QTimer *mAutoSaveTimer;
00915   QString mAutoSaveFilename;
00916   int mLastAutoSaveErrno; // holds the errno of the last try to autosave
00917 
00918   QPopupMenu *mActNowMenu;
00919   QPopupMenu *mActLaterMenu;
00920 
00921   QMap<KMail::EditorWatcher*, KMMessagePart*> mEditorMap;
00922   QMap<KMail::EditorWatcher*, KTempFile*> mEditorTempFiles;
00923 
00924   QLabel *mSignatureStateIndicator;
00925   QLabel *mEncryptionStateIndicator;
00926 
00927   SnippetWidget *mSnippetWidget;
00928   std::set<KTempDir*> mTempDirs;
00929 
00937   bool mPreserveUserCursorPosition;
00938 
00939   bool mPreventFccOverwrite;
00940   bool mCheckForRecipients;
00941   bool mIgnoreStickyFields;
00942 };
00943 
00944 #endif
00945 
KDE Home | KDE Accessibility Home | Description of Access Keys