kmail

kmreaderwin.h

00001 // -*- mode: C++; c-file-style: "gnu" -*-
00002 // Header for kmreaderwin the kmail reader
00003 // written by Markus Wuebben <markus.wuebben@kde.org>
00004 
00005 #ifndef KMREADERWIN_H
00006 #define KMREADERWIN_H
00007 
00008 #include <qwidget.h>
00009 #include <qtimer.h>
00010 #include <qstringlist.h>
00011 #include <kurl.h>
00012 #include <kservice.h>
00013 #include "kmmsgbase.h"
00014 #include "kmmimeparttree.h" // Needed for friend declaration.
00015 #include "interfaces/observer.h"
00016 
00017 #include <map>
00018 
00019 class QFrame;
00020 class QSplitter;
00021 class QHBox;
00022 class QListViewItem;
00023 class QScrollBar;
00024 class QString;
00025 class QTabDialog;
00026 class QTextCodec;
00027 
00028 class DwHeaders;
00029 class DwMediaType;
00030 
00031 class KActionCollection;
00032 class KAction;
00033 class KActionMenu;
00034 class KSelectAction;
00035 class KRadioAction;
00036 class KToggleAction;
00037 class KConfigBase;
00038 class KHTMLPart;
00039 class KURL;
00040 
00041 class KMFolder;
00042 class KMMessage;
00043 class KMMessagePart;
00044 namespace KMail {
00045   namespace Interface {
00046     class Observable;
00047     class BodyPartMemento;
00048   }
00049   class PartMetaData;
00050   class ObjectTreeParser;
00051   class AttachmentStrategy;
00052   class HeaderStrategy;
00053   class HeaderStyle;
00054   class HtmlWriter;
00055   class KHtmlPartHtmlWriter;
00056   class ISubject;
00057   class HtmlStatusBar;
00058   class FolderJob;
00059   class CSSHelper;
00060 }
00061 
00062 class partNode; // might be removed when KMime is used instead of mimelib
00063                 //                                      (khz, 29.11.2001)
00064 
00065 class NewByteArray; // providing operator+ on a QByteArray (khz, 21.06.2002)
00066 
00067 namespace KParts {
00068   struct URLArgs;
00069 }
00070 
00076 class KMReaderWin: public QWidget, public KMail::Interface::Observer {
00077   Q_OBJECT
00078 
00079   friend void KMMimePartTree::itemClicked( QListViewItem* item );
00080   friend void KMMimePartTree::itemRightClicked( QListViewItem* item, const QPoint & );
00081   friend void KMMimePartTree::slotSaveAs();
00082   friend void KMMimePartTree::startDrag();
00083 
00084   friend class KMail::ObjectTreeParser;
00085   friend class KMail::KHtmlPartHtmlWriter;
00086 
00087 public:
00088   KMReaderWin( QWidget *parent,
00089            QWidget *mainWindow,
00090            KActionCollection *actionCollection,
00091                const char *name=0,
00092            int f=0 );
00093   virtual ~KMReaderWin();
00094 
00099   void update( KMail::Interface::Observable * );
00100 
00102   void readConfig();
00103 
00105   void writeConfig( bool withSync=true ) const;
00106 
00107   const KMail::HeaderStyle * headerStyle() const {
00108     return mHeaderStyle;
00109   }
00112   void setHeaderStyleAndStrategy( const KMail::HeaderStyle * style,
00113                   const KMail::HeaderStrategy * strategy );
00114 
00116   const KMail::HeaderStrategy * headerStrategy() const {
00117     return mHeaderStrategy;
00118   }
00119 
00121   const KMail::AttachmentStrategy * attachmentStrategy() const {
00122     return mAttachmentStrategy;
00123   }
00124   void setAttachmentStrategy( const KMail::AttachmentStrategy * strategy );
00125 
00129   QString overrideEncoding() const { return mOverrideEncoding; }
00130 
00132   void setOverrideEncoding( const QString & encoding );
00133 
00134   void setPrintFont( const QFont& font );
00135 
00138   const QTextCodec * overrideCodec() const;
00139 
00141   virtual void setPrinting(bool enable) { mPrinting = enable; }
00142 
00145   virtual void setMsg(KMMessage* msg, bool force = false);
00146 
00149   void setMsgPart( KMMessagePart* aMsgPart, bool aHTML,
00150            const QString& aFileName, const QString& pname );
00151 
00152   void setMsgPart( partNode * node );
00153 
00156   void showHideMimeTree( bool isPlainTextTopLevel );
00157 
00162   void setIdOfLastViewedMessage( const QString & msgId )
00163     { mIdOfLastViewedMessage = msgId; }
00164 
00166   void clear(bool force = false) { setMsg(0, force); }
00167 
00170   void saveRelativePosition();
00171 
00173   void update(bool force = false);
00174 
00176   virtual void printMsg(void);
00177 
00179   QString copyText();
00180 
00182   bool autoDelete(void) const { return mAutoDelete; }
00183   void setAutoDelete(bool f) { mAutoDelete=f; }
00184 
00186   bool htmlOverride() const { return mHtmlOverride; }
00187   void setHtmlOverride( bool override );
00188 
00190   bool htmlLoadExtOverride() const { return mHtmlLoadExtOverride; }
00191   void setHtmlLoadExtOverride( bool override );
00192 
00194   bool htmlMail();
00195 
00197   bool htmlLoadExternal();
00198 
00200   static QString newFeaturesMD5();
00201 
00203   void displaySplashPage( const QString &info );
00204 
00206   void displayAboutPage();
00207 
00209   void displayBusyPage();
00211   void displayOfflinePage();
00212 
00214   void enableMsgDisplay();
00215 
00217   void atmViewMsg(KMMessagePart* msgPart);
00218 
00219   bool atBottom() const;
00220 
00221   bool isFixedFont() { return mUseFixedFont; }
00222   void setUseFixedFont( bool useFixedFont ) { mUseFixedFont = useFixedFont; }
00223 
00225   KMail::HtmlWriter * htmlWriter() { return mHtmlWriter; }
00226 
00227   // Action to reply to a message
00228   // but action( "some_name" ) some name could be used instead.
00229   KToggleAction *toggleFixFontAction() { return mToggleFixFontAction; }
00230   KAction *mailToComposeAction() { return mMailToComposeAction; }
00231   KAction *mailToReplyAction() { return mMailToReplyAction; }
00232   KAction *mailToForwardAction() { return mMailToForwardAction; }
00233   KAction *addAddrBookAction() { return mAddAddrBookAction; }
00234   KAction *openAddrBookAction() { return mOpenAddrBookAction; }
00235   KAction *copyAction() { return mCopyAction; }
00236   KAction *selectAllAction() { return mSelectAllAction; }
00237   KAction *copyURLAction() { return mCopyURLAction; }
00238   KAction *urlOpenAction() { return mUrlOpenAction; }
00239   KAction *urlSaveAsAction() { return mUrlSaveAsAction; }
00240   KAction *addBookmarksAction() { return mAddBookmarksAction;}
00241   KAction *startImChatAction() { return mStartIMChatAction; }
00242   // This function returns the complete data that were in this
00243   // message parts - *after* all encryption has been removed that
00244   // could be removed.
00245   // - This is used to store the message in decrypted form.
00246   void objectTreeToDecryptedMsg( partNode* node,
00247                                  NewByteArray& resultingData,
00248                                  KMMessage& theMessage,
00249                                  bool weAreReplacingTheRootNode = false,
00250                                  int recCount = 0 );
00251 
00253   partNode* partNodeFromUrl(const KURL &url);
00254 
00255   partNode * partNodeForId( int id );
00256 
00257   KURL tempFileUrlFromPartNode( const partNode * node );
00258 
00260   static int msgPartFromUrl(const KURL &url);
00261 
00262   void setUpdateAttachment( bool update = true ) { mAtmUpdate = update; }
00263 
00266   KHTMLPart * htmlPart() const { return mViewer; }
00267 
00269   KMMessage* message(KMFolder** folder=0) const;
00270 
00271   void openAttachment( int id, const QString & name );
00272 
00273   void emitUrlClicked( const KURL & url, int button ) {
00274     emit urlClicked( url, button );
00275   }
00276 
00277   void emitPopupMenu( const KURL & url, const QPoint & p ) {
00278     if ( message() )
00279       emit popupMenu( *message(), url, p );
00280   }
00281 
00282   void showAttachmentPopup( int id, const QString & name, const QPoint & p );
00283 
00286   void setWaitingForSerNum( unsigned long serNum ) { mWaitingForSerNum = serNum; }
00287 
00288   QWidget* mainWindow() { return mMainWindow; }
00289 
00291   bool decryptMessage() const;
00292 
00294   void setDecryptMessageOverwrite( bool overwrite = true ) { mDecrytMessageOverwrite = overwrite; }
00295 
00297   bool showSignatureDetails() const { return mShowSignatureDetails; }
00298 
00300   void setShowSignatureDetails( bool showDetails = true ) { mShowSignatureDetails = showDetails; }
00301 
00302   /* show or hide the list that points to the attachments */
00303   bool showAttachmentQuicklist() const { return mShowAttachmentQuicklist; }
00304 
00305   /* show or hide the list that points to the attachments */
00306   void setShowAttachmentQuicklist( bool showAttachmentQuicklist = true ) { mShowAttachmentQuicklist = showAttachmentQuicklist; }
00307 
00308   /* retrieve BodyPartMemento of id \a which for partNode \a node */
00309   KMail::Interface::BodyPartMemento * bodyPartMemento( const partNode * node, const QCString & which ) const;
00310 
00311   /* set/replace BodyPartMemento \a memento of id \a which for
00312      partNode \a node. If there was a BodyPartMemento registered
00313      already, replaces (deletes) that one. */
00314   void setBodyPartMemento( const partNode * node, const QCString & which, KMail::Interface::BodyPartMemento * memento );
00315 
00316 private:
00317   /* deletes all BodyPartMementos. Use this when skipping to another
00318      message (as opposed to re-loading the same one again). */
00319   void clearBodyPartMementos();
00320 
00321 signals:
00324   void replaceMsgByUnencryptedVersion();
00325 
00327   void popupMenu(KMMessage &msg, const KURL &url, const QPoint& mousePos);
00328 
00330   void urlClicked(const KURL &url, int button);
00331 
00333   void noDrag(void);
00334 
00335 public slots:
00336 
00338   void selectAll();
00339 
00341   void clearCache();
00342 
00344   void updateReaderWin();
00345 
00347   void slotScrollUp();
00348   void slotScrollDown();
00349   void slotScrollPrior();
00350   void slotScrollNext();
00351   void slotJumpDown();
00352   void slotDocumentChanged();
00353   void slotDocumentDone();
00354   void slotTextSelected(bool);
00355 
00357   void slotUrlOpen(const KURL &url, const KParts::URLArgs &args);
00358 
00360   void slotUrlOn(const QString &url);
00361 
00363   void slotUrlPopup(const QString &, const QPoint& mousePos);
00364 
00366   void slotFind();
00368   void slotFindNext();
00369 
00371   void slotToggleFixedFont();
00372 
00374   void slotCopySelectedText();
00375 
00376    void slotUrlClicked();
00377 
00379   void slotMailtoReply();
00380   void slotMailtoCompose();
00381   void slotMailtoForward();
00382   void slotMailtoAddAddrBook();
00383   void slotMailtoOpenAddrBook();
00386   void slotUrlCopy();
00387   void slotUrlOpen( const KURL &url = KURL() );
00389   void slotUrlSave();
00390   void slotAddBookmarks();
00391   void slotSaveMsg();
00392   void slotSaveAttachments();
00393 
00394   void slotMessageArrived( KMMessage *msg );
00396   void slotIMChat();
00397   void contactStatusChanged( const QString &uid);
00398 
00399   void slotLevelQuote( int l );
00400   void slotTouchMessage();
00401 
00402   void slotDeleteAttachment( partNode* node );
00403   void slotEditAttachment( partNode* node );
00404 
00405   KMail::CSSHelper* cssHelper();
00406 
00407 protected slots:
00408   void slotCycleHeaderStyles();
00409   void slotBriefHeaders();
00410   void slotFancyHeaders();
00411   void slotEnterpriseHeaders();
00412   void slotStandardHeaders();
00413   void slotLongHeaders();
00414   void slotAllHeaders();
00415 
00416   void slotCycleAttachmentStrategy();
00417   void slotIconicAttachments();
00418   void slotSmartAttachments();
00419   void slotInlineAttachments();
00420   void slotHideAttachments();
00421 
00423   void slotAtmView( int id, const QString& name );
00424   void slotDelayedResize();
00425   void slotHandleAttachment( int );
00426 
00427 protected:
00430   void styleChange( QStyle& oldStyle );
00431 
00434   void setStyleDependantFrameWidth();
00435 
00437   virtual bool event(QEvent *e);
00438 
00440   int pointsToPixel(int pointSize) const;
00441 
00444   void displayMessage();
00445 
00447   virtual void parseMsg( KMMessage* msg  );
00448 
00451   QString writeMsgHeader(KMMessage* aMsg, bool hasVCard=false, bool topLevel=false);
00452 
00456   QString writeMessagePartToTempFile( KMMessagePart* msgPart, int partNumber );
00457 
00463   QString createTempDir( const QString &param = QString() );
00464 
00466   void showVCard(KMMessagePart *msgPart);
00467 
00469   virtual void initHtmlWidget(void);
00470 
00472   virtual void closeEvent(QCloseEvent *);
00473   virtual void resizeEvent(QResizeEvent *);
00474 
00476   virtual void removeTempFiles();
00477 
00479   bool eventFilter( QObject *obj, QEvent *ev );
00480 
00481 private slots:
00482   void slotSetEncoding();
00483   void injectAttachments();
00484 
00485 private:
00486   void adjustLayout();
00487   void createWidgets();
00488   void createActions( KActionCollection * ac );
00489   void saveSplitterSizes( KConfigBase & c ) const;
00490 
00491   KRadioAction * actionForHeaderStyle( const KMail::HeaderStyle *,
00492                                        const KMail::HeaderStrategy * );
00493   KRadioAction * actionForAttachmentStrategy( const KMail::AttachmentStrategy * );
00495   void readGlobalOverrideCodec();
00496 
00497   QString renderAttachments( partNode *node, const QColor &bgColor );
00498 
00499 private:
00500   bool mHtmlMail, mHtmlLoadExternal, mHtmlOverride, mHtmlLoadExtOverride;
00501   int mAtmCurrent;
00502   QString mAtmCurrentName;
00503   KMMessage *mMessage;
00504   // widgets:
00505   QSplitter * mSplitter;
00506   QHBox *mBox;
00507   KMail::HtmlStatusBar *mColorBar;
00508   KMMimePartTree* mMimePartTree;
00509   KHTMLPart *mViewer;
00510 
00511   const KMail::AttachmentStrategy * mAttachmentStrategy;
00512   const KMail::HeaderStrategy * mHeaderStrategy;
00513   const KMail::HeaderStyle * mHeaderStyle;
00514   bool mAutoDelete;
00516   QString mSaveAttachDir;
00517   static const int delay;
00518   QTimer mUpdateReaderWinTimer;
00519   QTimer mResizeTimer;
00520   QTimer mDelayedMarkTimer;
00521   QString mOverrideEncoding;
00522   QString mOldGlobalOverrideEncoding; // used to detect changes of the global override character encoding
00523   bool mMsgDisplay;
00524   bool mNoMDNsWhenEncrypted;
00525   unsigned long mLastSerNum;
00526   KMMsgStatus mLastStatus;
00527 
00528   KMail::CSSHelper * mCSSHelper;
00529   bool mUseFixedFont;
00530   bool mPrinting;
00531   bool mShowColorbar;
00532   //bool mShowCompleteMessage;
00533   QStringList mTempFiles;
00534   QStringList mTempDirs;
00535   int mMimeTreeMode;
00536   bool mMimeTreeAtBottom;
00537   QValueList<int> mSplitterSizes;
00538   partNode* mRootNode;
00539   QString mIdOfLastViewedMessage;
00540   QWidget *mMainWindow;
00541   KActionCollection *mActionCollection;
00542   KAction *mMailToComposeAction, *mMailToReplyAction, *mMailToForwardAction,
00543       *mAddAddrBookAction, *mOpenAddrBookAction, *mCopyAction, *mCopyURLAction,
00544       *mUrlOpenAction, *mUrlSaveAsAction, *mAddBookmarksAction, *mStartIMChatAction, *mSelectAllAction;
00545   KSelectAction *mSelectEncodingAction;
00546   KToggleAction *mToggleFixFontAction;
00547   KURL mUrlClicked;
00548   KMail::HtmlWriter * mHtmlWriter;
00549   std::map<QCString,KMail::Interface::BodyPartMemento*> mBodyPartMementoMap;
00550   // an attachment should be updated
00551   bool mAtmUpdate;
00552   int mChoice;
00553   unsigned long mWaitingForSerNum;
00554   float mSavedRelativePosition;
00555   int mLevelQuote;
00556   bool mDecrytMessageOverwrite;
00557   bool mShowSignatureDetails;
00558   bool mShowAttachmentQuicklist;
00559   bool mExternalWindow;
00560 };
00561 
00562 
00563 #endif
00564 
KDE Home | KDE Accessibility Home | Description of Access Keys