kmail

kmreaderwin.h

Go to the documentation of this file.
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 class QFrame;
00018 class QSplitter;
00019 class QHBox;
00020 class QListViewItem;
00021 class QScrollBar;
00022 class QString;
00023 class QTabDialog;
00024 class QTextCodec;
00025 
00026 class DwHeaders;
00027 class DwMediaType;
00028 
00029 class KActionCollection;
00030 class KAction;
00031 class KActionMenu;
00032 class KSelectAction;
00033 class KRadioAction;
00034 class KToggleAction;
00035 class KConfigBase;
00036 class KHTMLPart;
00037 class KURL;
00038 
00039 class KMFolder;
00040 class KMMessage;
00041 class KMMessagePart;
00042 namespace KMail {
00043   namespace Interface {
00044     class Observable;
00045   }
00046   class PartMetaData;
00047   class ObjectTreeParser;
00048   class AttachmentStrategy;
00049   class HeaderStrategy;
00050   class HeaderStyle;
00051   class HtmlWriter;
00052   class KHtmlPartHtmlWriter;
00053   class ISubject;
00054   class HtmlStatusBar;
00055   class FolderJob;
00056   class CSSHelper;
00057 }
00058 
00059 class partNode; // might be removed when KMime is used instead of mimelib
00060                 //                                      (khz, 29.11.2001)
00061 
00062 class NewByteArray; // providing operator+ on a QByteArray (khz, 21.06.2002)
00063 
00064 namespace KParts {
00065   struct URLArgs;
00066 }
00067 
00073 class KMReaderWin: public QWidget, public KMail::Interface::Observer {
00074   Q_OBJECT
00075 
00076   friend void KMMimePartTree::itemClicked( QListViewItem* item );
00077   friend void KMMimePartTree::itemRightClicked( QListViewItem* item, const QPoint & );
00078   friend void KMMimePartTree::slotSaveAs();
00079   friend void KMMimePartTree::startDrag();
00080 
00081   friend class KMail::ObjectTreeParser;
00082   friend class KMail::KHtmlPartHtmlWriter;
00083 
00084 public:
00085   KMReaderWin( QWidget *parent,
00086            QWidget *mainWindow,
00087            KActionCollection *actionCollection,
00088                const char *name=0,
00089            int f=0 );
00090   virtual ~KMReaderWin();
00091 
00096   void update( KMail::Interface::Observable * );
00097 
00099   void readConfig();
00100 
00102   void writeConfig( bool withSync=true ) const;
00103 
00104   const KMail::HeaderStyle * headerStyle() const {
00105     return mHeaderStyle;
00106   }
00109   void setHeaderStyleAndStrategy( const KMail::HeaderStyle * style,
00110                   const KMail::HeaderStrategy * strategy );
00111 
00113   const KMail::HeaderStrategy * headerStrategy() const {
00114     return mHeaderStrategy;
00115   }
00116 
00118   const KMail::AttachmentStrategy * attachmentStrategy() const {
00119     return mAttachmentStrategy;
00120   }
00121   void setAttachmentStrategy( const KMail::AttachmentStrategy * strategy );
00122 
00126   QString overrideEncoding() const { return mOverrideEncoding; }
00127 
00129   void setOverrideEncoding( const QString & encoding );
00130 
00131   void setPrintFont( const QFont& font );
00132 
00135   const QTextCodec * overrideCodec() const;
00136 
00138   virtual void setPrinting(bool enable) { mPrinting = enable; }
00139 
00142   virtual void setMsg(KMMessage* msg, bool force = false);
00143 
00146   void setMsgPart( KMMessagePart* aMsgPart, bool aHTML,
00147            const QString& aFileName, const QString& pname );
00148 
00149   void setMsgPart( partNode * node );
00150 
00153   void showHideMimeTree( bool isPlainTextTopLevel );
00154 
00159   void setIdOfLastViewedMessage( const QString & msgId )
00160     { mIdOfLastViewedMessage = msgId; }
00161 
00163   void clear(bool force = false) { setMsg(0, force); }
00164 
00167   void saveRelativePosition();
00168 
00170   void update(bool force = false);
00171 
00173   virtual void printMsg(void);
00174 
00176   QString copyText();
00177 
00179   bool autoDelete(void) const { return mAutoDelete; }
00180   void setAutoDelete(bool f) { mAutoDelete=f; }
00181 
00183   bool htmlOverride() const { return mHtmlOverride; }
00184   void setHtmlOverride( bool override );
00185 
00187   bool htmlLoadExtOverride() const { return mHtmlLoadExtOverride; }
00188   void setHtmlLoadExtOverride( bool override );
00189 
00191   bool htmlMail();
00192 
00194   bool htmlLoadExternal();
00195 
00197   static QString newFeaturesMD5();
00198 
00200   void displaySplashPage( const QString &info );
00201 
00203   void displayAboutPage();
00204 
00206   void displayBusyPage();
00208   void displayOfflinePage();
00209 
00211   void enableMsgDisplay();
00212 
00214   void atmViewMsg(KMMessagePart* msgPart);
00215 
00216   bool atBottom() const;
00217 
00218   bool isFixedFont() { return mUseFixedFont; }
00219   void setUseFixedFont( bool useFixedFont ) { mUseFixedFont = useFixedFont; }
00220 
00222   KMail::HtmlWriter * htmlWriter() { return mHtmlWriter; }
00223 
00224   // Action to reply to a message
00225   // but action( "some_name" ) some name could be used instead.
00226   KToggleAction *toggleFixFontAction() { return mToggleFixFontAction; }
00227   KAction *mailToComposeAction() { return mMailToComposeAction; }
00228   KAction *mailToReplyAction() { return mMailToReplyAction; }
00229   KAction *mailToForwardAction() { return mMailToForwardAction; }
00230   KAction *addAddrBookAction() { return mAddAddrBookAction; }
00231   KAction *openAddrBookAction() { return mOpenAddrBookAction; }
00232   KAction *copyAction() { return mCopyAction; }
00233   KAction *selectAllAction() { return mSelectAllAction; }
00234   KAction *copyURLAction() { return mCopyURLAction; }
00235   KAction *urlOpenAction() { return mUrlOpenAction; }
00236   KAction *urlSaveAsAction() { return mUrlSaveAsAction; }
00237   KAction *addBookmarksAction() { return mAddBookmarksAction;}
00238   KAction *startImChatAction() { return mStartIMChatAction; }
00239   // This function returns the complete data that were in this
00240   // message parts - *after* all encryption has been removed that
00241   // could be removed.
00242   // - This is used to store the message in decrypted form.
00243   void objectTreeToDecryptedMsg( partNode* node,
00244                                  NewByteArray& resultingData,
00245                                  KMMessage& theMessage,
00246                                  bool weAreReplacingTheRootNode = false,
00247                                  int recCount = 0 );
00248 
00250   partNode* partNodeFromUrl(const KURL &url);
00251 
00252   partNode * partNodeForId( int id );
00253 
00254   KURL tempFileUrlFromPartNode( const partNode * node );
00255 
00257   static int msgPartFromUrl(const KURL &url);
00258 
00259   void setUpdateAttachment( bool update = true ) { mAtmUpdate = update; }
00260 
00263   KHTMLPart * htmlPart() const { return mViewer; }
00264 
00266   KMMessage* message(KMFolder** folder=0) const;
00267 
00268   void openAttachment( int id, const QString & name );
00269 
00270   void emitUrlClicked( const KURL & url, int button ) {
00271     emit urlClicked( url, button );
00272   }
00273 
00274   void emitPopupMenu( const KURL & url, const QPoint & p ) {
00275     if ( message() )
00276       emit popupMenu( *message(), url, p );
00277   }
00278 
00279   void showAttachmentPopup( int id, const QString & name, const QPoint & p );
00280 
00283   void setWaitingForSerNum( unsigned long serNum ) { mWaitingForSerNum = serNum; }
00284 
00285   QWidget* mainWindow() { return mMainWindow; }
00286 
00288   bool decryptMessage() const;
00289 
00291   void setDecryptMessageOverwrite( bool overwrite = true ) { mDecrytMessageOverwrite = overwrite; }
00292 
00294   bool showSignatureDetails() const { return mShowSignatureDetails; }
00295 
00297   void setShowSignatureDetails( bool showDetails = true ) { mShowSignatureDetails = showDetails; }
00298 
00299   /* show or hide the list that points to the attachments */
00300   bool showAttachmentQuicklist() const { return mShowAttachmentQuicklist; }
00301 
00302   /* show or hide the list that points to the attachments */
00303   void setShowAttachmentQuicklist( bool showAttachmentQuicklist = true ) { mShowAttachmentQuicklist = showAttachmentQuicklist; }
00304 
00305 signals:
00308   void replaceMsgByUnencryptedVersion();
00309 
00311   void popupMenu(KMMessage &msg, const KURL &url, const QPoint& mousePos);
00312 
00314   void urlClicked(const KURL &url, int button);
00315 
00317   void noDrag(void);
00318 
00319 public slots:
00320 
00322   void selectAll();
00323 
00325   void clearCache();
00326 
00328   void updateReaderWin();
00329 
00331   void slotScrollUp();
00332   void slotScrollDown();
00333   void slotScrollPrior();
00334   void slotScrollNext();
00335   void slotJumpDown();
00336   void slotDocumentChanged();
00337   void slotDocumentDone();
00338   void slotTextSelected(bool);
00339 
00341   void slotUrlOpen(const KURL &url, const KParts::URLArgs &args);
00342 
00344   void slotUrlOn(const QString &url);
00345 
00347   void slotUrlPopup(const QString &, const QPoint& mousePos);
00348 
00350   void slotFind();
00352   void slotFindNext();
00353 
00355   void slotToggleFixedFont();
00356 
00358   void slotCopySelectedText();
00359 
00360    void slotUrlClicked();
00361 
00363   void slotMailtoReply();
00364   void slotMailtoCompose();
00365   void slotMailtoForward();
00366   void slotMailtoAddAddrBook();
00367   void slotMailtoOpenAddrBook();
00370   void slotUrlCopy();
00371   void slotUrlOpen( const KURL &url = KURL() );
00373   void slotUrlSave();
00374   void slotAddBookmarks();
00375   void slotSaveMsg();
00376   void slotSaveAttachments();
00377 
00378   void slotMessageArrived( KMMessage *msg );
00380   void slotIMChat();
00381   void contactStatusChanged( const QString &uid);
00382 
00383   void slotLevelQuote( int l );
00384   void slotTouchMessage();
00385 
00386   void slotDeleteAttachment( partNode* node );
00387   void slotEditAttachment( partNode* node );
00388 
00389   KMail::CSSHelper* cssHelper();
00390 
00391 protected slots:
00392   void slotCycleHeaderStyles();
00393   void slotBriefHeaders();
00394   void slotFancyHeaders();
00395   void slotEnterpriseHeaders();
00396   void slotStandardHeaders();
00397   void slotLongHeaders();
00398   void slotAllHeaders();
00399 
00400   void slotCycleAttachmentStrategy();
00401   void slotIconicAttachments();
00402   void slotSmartAttachments();
00403   void slotInlineAttachments();
00404   void slotHideAttachments();
00405 
00407   void slotAtmView( int id, const QString& name );
00408   void slotDelayedResize();
00409   void slotHandleAttachment( int );
00410 
00411 protected:
00414   void styleChange( QStyle& oldStyle );
00415 
00418   void setStyleDependantFrameWidth();
00419 
00421   virtual bool event(QEvent *e);
00422 
00424   int pointsToPixel(int pointSize) const;
00425 
00428   void displayMessage();
00429 
00431   virtual void parseMsg( KMMessage* msg  );
00432 
00435   QString writeMsgHeader(KMMessage* aMsg, bool hasVCard=false, bool topLevel=false);
00436 
00440   QString writeMessagePartToTempFile( KMMessagePart* msgPart, int partNumber );
00441 
00447   QString createTempDir( const QString &param = QString() );
00448 
00450   void showVCard(KMMessagePart *msgPart);
00451 
00453   virtual void initHtmlWidget(void);
00454 
00456   virtual void closeEvent(QCloseEvent *);
00457   virtual void resizeEvent(QResizeEvent *);
00458 
00460   virtual void removeTempFiles();
00461 
00463   bool eventFilter( QObject *obj, QEvent *ev );
00464 
00465 private slots:
00466   void slotSetEncoding();
00467   void injectAttachments();
00468 
00469 private:
00470   void adjustLayout();
00471   void createWidgets();
00472   void createActions( KActionCollection * ac );
00473   void saveSplitterSizes( KConfigBase & c ) const;
00474 
00475   KRadioAction * actionForHeaderStyle( const KMail::HeaderStyle *,
00476                                        const KMail::HeaderStrategy * );
00477   KRadioAction * actionForAttachmentStrategy( const KMail::AttachmentStrategy * );
00479   void readGlobalOverrideCodec();
00480 
00481   QString renderAttachments( partNode *node, const QColor &bgColor );
00482 
00483 private:
00484   bool mHtmlMail, mHtmlLoadExternal, mHtmlOverride, mHtmlLoadExtOverride;
00485   int mAtmCurrent;
00486   QString mAtmCurrentName;
00487   KMMessage *mMessage;
00488   // widgets:
00489   QSplitter * mSplitter;
00490   QHBox *mBox;
00491   KMail::HtmlStatusBar *mColorBar;
00492   KMMimePartTree* mMimePartTree;
00493   KHTMLPart *mViewer;
00494 
00495   const KMail::AttachmentStrategy * mAttachmentStrategy;
00496   const KMail::HeaderStrategy * mHeaderStrategy;
00497   const KMail::HeaderStyle * mHeaderStyle;
00498   bool mAutoDelete;
00500   QString mSaveAttachDir;
00501   static const int delay;
00502   QTimer mUpdateReaderWinTimer;
00503   QTimer mResizeTimer;
00504   QTimer mDelayedMarkTimer;
00505   QString mOverrideEncoding;
00506   QString mOldGlobalOverrideEncoding; // used to detect changes of the global override character encoding
00507   bool mMsgDisplay;
00508   bool mNoMDNsWhenEncrypted;
00509   unsigned long mLastSerNum;
00510   KMMsgStatus mLastStatus;
00511 
00512   KMail::CSSHelper * mCSSHelper;
00513   bool mUseFixedFont;
00514   bool mPrinting;
00515   bool mShowColorbar;
00516   //bool mShowCompleteMessage;
00517   QStringList mTempFiles;
00518   QStringList mTempDirs;
00519   int mMimeTreeMode;
00520   bool mMimeTreeAtBottom;
00521   QValueList<int> mSplitterSizes;
00522   partNode* mRootNode;
00523   QString mIdOfLastViewedMessage;
00524   QWidget *mMainWindow;
00525   KActionCollection *mActionCollection;
00526   KAction *mMailToComposeAction, *mMailToReplyAction, *mMailToForwardAction,
00527       *mAddAddrBookAction, *mOpenAddrBookAction, *mCopyAction, *mCopyURLAction,
00528       *mUrlOpenAction, *mUrlSaveAsAction, *mAddBookmarksAction, *mStartIMChatAction, *mSelectAllAction;
00529   KSelectAction *mSelectEncodingAction;
00530   KToggleAction *mToggleFixFontAction;
00531   KURL mUrlClicked;
00532   KMail::HtmlWriter * mHtmlWriter;
00533   // an attachment should be updated
00534   bool mAtmUpdate;
00535   int mChoice;
00536   unsigned long mWaitingForSerNum;
00537   float mSavedRelativePosition;
00538     int mLevelQuote;
00539   bool mDecrytMessageOverwrite;
00540   bool mShowSignatureDetails;
00541   bool mShowAttachmentQuicklist;
00542 };
00543 
00544 
00545 #endif
00546