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, bool updateOnly = false );
00146 
00158   void setOriginalMsg( unsigned long serNumOfOriginalMessage, int nodeIdOffset );
00159 
00162   void setMsgPart( KMMessagePart* aMsgPart, bool aHTML,
00163            const QString& aFileName, const QString& pname );
00164 
00165   void setMsgPart( partNode * node );
00166 
00169   void showHideMimeTree( bool isPlainTextTopLevel );
00170 
00175   void setIdOfLastViewedMessage( const QString & msgId )
00176     { mIdOfLastViewedMessage = msgId; }
00177 
00179   void clear(bool force = false) { setMsg(0, force); }
00180 
00183   void saveRelativePosition();
00184 
00186   void update(bool force = false);
00187 
00189   virtual void printMsg(void);
00190 
00192   QString copyText();
00193 
00195   bool autoDelete(void) const { return mAutoDelete; }
00196   void setAutoDelete(bool f) { mAutoDelete=f; }
00197 
00199   bool htmlOverride() const { return mHtmlOverride; }
00200   void setHtmlOverride( bool override );
00201 
00203   bool htmlLoadExtOverride() const { return mHtmlLoadExtOverride; }
00204   void setHtmlLoadExtOverride( bool override );
00205 
00207   bool htmlMail();
00208 
00210   bool htmlLoadExternal();
00211 
00213   static QString newFeaturesMD5();
00214 
00216   void displaySplashPage( const QString &info );
00217 
00219   void displayAboutPage();
00220 
00222   void displayBusyPage();
00224   void displayOfflinePage();
00225 
00227   void enableMsgDisplay();
00228 
00234   void atmViewMsg( KMMessagePart* msgPart, int nodeId );
00235 
00236   bool atBottom() const;
00237 
00238   bool isFixedFont() { return mUseFixedFont; }
00239   void setUseFixedFont( bool useFixedFont ) { mUseFixedFont = useFixedFont; }
00240 
00242   KMail::HtmlWriter * htmlWriter() { return mHtmlWriter; }
00243 
00244   // Action to reply to a message
00245   // but action( "some_name" ) some name could be used instead.
00246   KToggleAction *toggleFixFontAction() { return mToggleFixFontAction; }
00247   KAction *mailToComposeAction() { return mMailToComposeAction; }
00248   KAction *mailToReplyAction() { return mMailToReplyAction; }
00249   KAction *mailToForwardAction() { return mMailToForwardAction; }
00250   KAction *addAddrBookAction() { return mAddAddrBookAction; }
00251   KAction *openAddrBookAction() { return mOpenAddrBookAction; }
00252   KAction *copyAction() { return mCopyAction; }
00253   KAction *selectAllAction() { return mSelectAllAction; }
00254   KAction *copyURLAction() { return mCopyURLAction; }
00255   KAction *urlOpenAction() { return mUrlOpenAction; }
00256   KAction *urlSaveAsAction() { return mUrlSaveAsAction; }
00257   KAction *addBookmarksAction() { return mAddBookmarksAction;}
00258   KAction *startImChatAction() { return mStartIMChatAction; }
00259   // This function returns the complete data that were in this
00260   // message parts - *after* all encryption has been removed that
00261   // could be removed.
00262   // - This is used to store the message in decrypted form.
00263   void objectTreeToDecryptedMsg( partNode* node,
00264                                  NewByteArray& resultingData,
00265                                  KMMessage& theMessage,
00266                                  bool weAreReplacingTheRootNode = false,
00267                                  int recCount = 0 );
00268 
00270   partNode* partNodeFromUrl(const KURL &url);
00271 
00272   partNode * partNodeForId( int id );
00273 
00274   KURL tempFileUrlFromPartNode( const partNode * node );
00275 
00277   static int msgPartFromUrl(const KURL &url);
00278 
00279   void setUpdateAttachment( bool update = true ) { mAtmUpdate = update; }
00280 
00283   KHTMLPart * htmlPart() const { return mViewer; }
00284 
00286   KMMessage* message(KMFolder** folder=0) const;
00287 
00288   void openAttachment( int id, const QString & name );
00289   void saveAttachment( const KURL &tempFileName );
00290 
00291   void emitUrlClicked( const KURL & url, int button ) {
00292     emit urlClicked( url, button );
00293   }
00294 
00295   void emitPopupMenu( const KURL & url, const QPoint & p ) {
00296     if ( message() )
00297       emit popupMenu( *message(), url, p );
00298   }
00299 
00300   void showAttachmentPopup( int id, const QString & name, const QPoint & p );
00301 
00304   void setWaitingForSerNum( unsigned long serNum ) { mWaitingForSerNum = serNum; }
00305 
00306   QWidget* mainWindow() { return mMainWindow; }
00307 
00309   bool decryptMessage() const;
00310 
00312   void setDecryptMessageOverwrite( bool overwrite = true ) { mDecrytMessageOverwrite = overwrite; }
00313 
00315   bool showSignatureDetails() const { return mShowSignatureDetails; }
00316 
00318   void setShowSignatureDetails( bool showDetails = true ) { mShowSignatureDetails = showDetails; }
00319 
00320   /* show or hide the list that points to the attachments */
00321   bool showAttachmentQuicklist() const { return mShowAttachmentQuicklist; }
00322 
00323   /* show or hide the list that points to the attachments */
00324   void setShowAttachmentQuicklist( bool showAttachmentQuicklist = true ) { mShowAttachmentQuicklist = showAttachmentQuicklist; }
00325 
00326   // This controls whether a Toltec invitation is shown in its raw form or as a replacement text.
00327   // This can be toggled with the "kmail:showRawToltecMail" link.
00328   bool showRawToltecMail() const { return mShowRawToltecMail; }
00329   void setShowRawToltecMail( bool showRawToltecMail ) { mShowRawToltecMail = showRawToltecMail; }
00330 
00331   /* retrieve BodyPartMemento of id \a which for partNode \a node */
00332   KMail::Interface::BodyPartMemento * bodyPartMemento( const partNode * node, const QCString & which ) const;
00333 
00334   /* set/replace BodyPartMemento \a memento of id \a which for
00335      partNode \a node. If there was a BodyPartMemento registered
00336      already, replaces (deletes) that one. */
00337   void setBodyPartMemento( const partNode * node, const QCString & which, KMail::Interface::BodyPartMemento * memento );
00338 
00340   void scrollToAttachment( const partNode *node );
00341 
00342 private:
00343   /* deletes all BodyPartMementos. Use this when skipping to another
00344      message (as opposed to re-loading the same one again). */
00345   void clearBodyPartMementos();
00346 
00347 signals:
00350   void replaceMsgByUnencryptedVersion();
00351 
00353   void popupMenu(KMMessage &msg, const KURL &url, const QPoint& mousePos);
00354 
00356   void urlClicked(const KURL &url, int button);
00357 
00359   void noDrag(void);
00360 
00361 public slots:
00362 
00364   void selectAll();
00365 
00367   void clearCache();
00368 
00370   void updateReaderWin();
00371 
00373   void slotScrollUp();
00374   void slotScrollDown();
00375   void slotScrollPrior();
00376   void slotScrollNext();
00377   void slotJumpDown();
00378   void slotDocumentChanged();
00379   void slotDocumentDone();
00380   void slotTextSelected(bool);
00381 
00383   void slotUrlOpen(const KURL &url, const KParts::URLArgs &args);
00384 
00386   void slotUrlOn(const QString &url);
00387 
00389   void slotUrlPopup(const QString &, const QPoint& mousePos);
00390 
00392   void slotFind();
00394   void slotFindNext();
00395 
00397   void slotToggleFixedFont();
00398 
00400   void slotCopySelectedText();
00401 
00402    void slotUrlClicked();
00403 
00405   void slotMailtoReply();
00406   void slotMailtoCompose();
00407   void slotMailtoForward();
00408   void slotMailtoAddAddrBook();
00409   void slotMailtoOpenAddrBook();
00412   void slotUrlCopy();
00413   void slotUrlOpen( const KURL &url = KURL() );
00415   void slotUrlSave();
00416   void slotAddBookmarks();
00417   void slotSaveMsg();
00418   void slotSaveAttachments();
00419 
00420   void slotMessageArrived( KMMessage *msg );
00422   void slotIMChat();
00423   void contactStatusChanged( const QString &uid);
00424 
00425   void slotLevelQuote( int l );
00426   void slotTouchMessage();
00427 
00435   void fillCommandInfo( partNode *node, KMMessage **msg, int *nodeId );
00436 
00437   void slotDeleteAttachment( partNode* node );
00438   void slotEditAttachment( partNode* node );
00439 
00440   KMail::CSSHelper* cssHelper();
00441 
00442 protected slots:
00443   void slotCycleHeaderStyles();
00444   void slotBriefHeaders();
00445   void slotFancyHeaders();
00446   void slotEnterpriseHeaders();
00447   void slotStandardHeaders();
00448   void slotLongHeaders();
00449   void slotAllHeaders();
00450 
00451   void slotCycleAttachmentStrategy();
00452   void slotIconicAttachments();
00453   void slotSmartAttachments();
00454   void slotInlineAttachments();
00455   void slotHideAttachments();
00456 
00458   void slotAtmView( int id, const QString& name );
00459   void slotDelayedResize();
00460   void slotHandleAttachment( int );
00461 
00465   void disconnectMsgAdded();
00466   void msgAdded( QListViewItem *item );
00467 
00468 protected:
00471   void styleChange( QStyle& oldStyle );
00472 
00475   void setStyleDependantFrameWidth();
00476 
00478   virtual bool event(QEvent *e);
00479 
00481   int pointsToPixel(int pointSize) const;
00482 
00485   void displayMessage();
00486 
00488   virtual void parseMsg( KMMessage* msg  );
00489 
00492   QString writeMsgHeader(KMMessage* aMsg, partNode *vCardNode = 0, bool topLevel=false );
00493 
00497   QString writeMessagePartToTempFile( KMMessagePart* msgPart, int partNumber );
00498 
00504   QString createTempDir( const QString &param = QString() );
00505 
00507   void showVCard(KMMessagePart *msgPart);
00508 
00510   virtual void initHtmlWidget(void);
00511 
00513   virtual void closeEvent(QCloseEvent *);
00514   virtual void resizeEvent(QResizeEvent *);
00515 
00517   virtual void removeTempFiles();
00518 
00520   bool eventFilter( QObject *obj, QEvent *ev );
00521 
00522 private slots:
00523   void slotSetEncoding();
00524   void injectAttachments();
00525 
00526 private:
00527   void adjustLayout();
00528   void createWidgets();
00529   void createActions( KActionCollection * ac );
00530   void saveSplitterSizes( KConfigBase & c ) const;
00531 
00532   KRadioAction * actionForHeaderStyle( const KMail::HeaderStyle *,
00533                                        const KMail::HeaderStrategy * );
00534   KRadioAction * actionForAttachmentStrategy( const KMail::AttachmentStrategy * );
00536   void readGlobalOverrideCodec();
00537 
00538   QString renderAttachments( partNode *node, const QColor &bgColor );
00539 
00540 private:
00541   bool mHtmlMail, mHtmlLoadExternal, mHtmlOverride, mHtmlLoadExtOverride;
00542   int mAtmCurrent;
00543   QString mAtmCurrentName;
00544   KMMessage *mMessage;
00545 
00546   // See setOriginalMsg() for an explaination for those two.
00547   unsigned long mSerNumOfOriginalMessage;
00548   int mNodeIdOffset;
00549 
00550   // widgets:
00551   QSplitter * mSplitter;
00552   QHBox *mBox;
00553   KMail::HtmlStatusBar *mColorBar;
00554   KMMimePartTree* mMimePartTree;
00555   KHTMLPart *mViewer;
00556 
00557   const KMail::AttachmentStrategy * mAttachmentStrategy;
00558   const KMail::HeaderStrategy * mHeaderStrategy;
00559   const KMail::HeaderStyle * mHeaderStyle;
00560   bool mAutoDelete;
00562   QString mSaveAttachDir;
00563   static const int delay;
00564   QTimer mUpdateReaderWinTimer;
00565   QTimer mResizeTimer;
00566   QTimer mDelayedMarkTimer;
00567   QString mOverrideEncoding;
00568   QString mOldGlobalOverrideEncoding; // used to detect changes of the global override character encoding
00569   bool mMsgDisplay;
00570   bool mNoMDNsWhenEncrypted;
00571   unsigned long mLastSerNum;
00572 
00573   KMail::CSSHelper * mCSSHelper;
00574   bool mUseFixedFont;
00575   bool mPrinting;
00576   bool mShowColorbar;
00577   //bool mShowCompleteMessage;
00578   QStringList mTempFiles;
00579   QStringList mTempDirs;
00580   int mMimeTreeMode;
00581   bool mMimeTreeAtBottom;
00582   QValueList<int> mSplitterSizes;
00583   partNode* mRootNode;
00584   QString mIdOfLastViewedMessage;
00585   QWidget *mMainWindow;
00586   KActionCollection *mActionCollection;
00587   KAction *mMailToComposeAction, *mMailToReplyAction, *mMailToForwardAction,
00588       *mAddAddrBookAction, *mOpenAddrBookAction, *mCopyAction, *mCopyURLAction,
00589       *mUrlOpenAction, *mUrlSaveAsAction, *mAddBookmarksAction, *mStartIMChatAction, *mSelectAllAction;
00590   KSelectAction *mSelectEncodingAction;
00591   KToggleAction *mToggleFixFontAction;
00592 
00593   KURL mHoveredUrl;
00594   KURL mClickedUrl;
00595   QPoint mLastClickPosition;
00596   bool mCanStartDrag;
00597 
00598   KMail::HtmlWriter * mHtmlWriter;
00599   std::map<QCString,KMail::Interface::BodyPartMemento*> mBodyPartMementoMap;
00600   // an attachment should be updated
00601   bool mAtmUpdate;
00602   int mChoice;
00603   unsigned long mWaitingForSerNum;
00604   float mSavedRelativePosition;
00605   int mLevelQuote;
00606   bool mDecrytMessageOverwrite;
00607   bool mShowSignatureDetails;
00608   bool mShowAttachmentQuicklist;
00609   bool mShowRawToltecMail;
00610   bool mExternalWindow;
00611 };
00612 
00613 
00614 #endif
00615 
KDE Home | KDE Accessibility Home | Description of Access Keys