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 <tqwidget.h>
00009 #include <tqtimer.h>
00010 #include <tqstringlist.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 TQFrame;
00020 class TQSplitter;
00021 class TQHBox;
00022 class TQListViewItem;
00023 class TQScrollBar;
00024 class TQString;
00025 class TQTabDialog;
00026 class TQTextCodec;
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 TQByteArray (khz, 21.06.2002)
00066 
00067 namespace KParts {
00068   struct URLArgs;
00069 }
00070 
00076 class KMReaderWin: public TQWidget, public KMail::Interface::Observer {
00077   Q_OBJECT
00078 
00079   friend void KMMimePartTree::itemClicked( TQListViewItem* item );
00080   friend void KMMimePartTree::itemRightClicked( TQListViewItem* item, const TQPoint & );
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( TQWidget *parent,
00089            TQWidget *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   TQString overrideEncoding() const { return mOverrideEncoding; }
00130 
00132   void setOverrideEncoding( const TQString & encoding );
00133 
00134   void setPrintFont( const TQFont& font );
00135 
00138   const TQTextCodec * 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 TQString& aFileName, const TQString& pname );
00164 
00165   void setMsgPart( partNode * node );
00166 
00169   void showHideMimeTree( bool isPlainTextTopLevel );
00170 
00175   void setIdOfLastViewedMessage( const TQString & 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   TQString 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 TQString newFeaturesMD5();
00214 
00216   void displaySplashPage( const TQString &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 TQString & 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 TQPoint & p ) {
00296     if ( message() )
00297       emit popupMenu( *message(), url, p );
00298   }
00299 
00300   void showAttachmentPopup( int id, const TQString & name, const TQPoint & p );
00301 
00304   void setWaitingForSerNum( unsigned long serNum ) { mWaitingForSerNum = serNum; }
00305 
00306   TQWidget* 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 TQCString & 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 TQCString & 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 TQPoint& 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 TQString &url);
00387 
00389   void slotUrlPopup(const TQString &, const TQPoint& 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 TQString &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   void slotHeaderOnlyAttachments();
00457 
00459   void slotAtmView( int id, const TQString& name );
00460   void slotDelayedResize();
00461   void slotHandleAttachment( int );
00462 
00466   void disconnectMsgAdded();
00467   void msgAdded( TQListViewItem *item );
00468 
00469 protected:
00472   void styleChange( TQStyle& oldStyle );
00473 
00476   void setStyleDependantFrameWidth();
00477 
00479   virtual bool event(TQEvent *e);
00480 
00482   int pointsToPixel(int pointSize) const;
00483 
00486   void displayMessage();
00487 
00489   virtual void parseMsg( KMMessage* msg  );
00490 
00493   TQString writeMsgHeader(KMMessage* aMsg, partNode *vCardNode = 0, bool topLevel=false );
00494 
00498   TQString writeMessagePartToTempFile( KMMessagePart* msgPart, int partNumber );
00499 
00505   TQString createTempDir( const TQString &param = TQString() );
00506 
00508   void showVCard(KMMessagePart *msgPart);
00509 
00511   virtual void initHtmlWidget(void);
00512 
00514   virtual void closeEvent(TQCloseEvent *);
00515   virtual void resizeEvent(TQResizeEvent *);
00516 
00518   virtual void removeTempFiles();
00519 
00521   bool eventFilter( TQObject *obj, TQEvent *ev );
00522 
00523 private slots:
00524   void slotSetEncoding();
00525   void injectAttachments();
00526 
00527 private:
00528   void adjustLayout();
00529   void createWidgets();
00530   void createActions( KActionCollection * ac );
00531   void saveSplitterSizes( KConfigBase & c ) const;
00532 
00533   KRadioAction * actionForHeaderStyle( const KMail::HeaderStyle *,
00534                                        const KMail::HeaderStrategy * );
00535   KRadioAction * actionForAttachmentStrategy( const KMail::AttachmentStrategy * );
00537   void readGlobalOverrideCodec();
00538 
00539   TQString renderAttachments( partNode *node, const TQColor &bgColor );
00540 
00541 private:
00542   bool mHtmlMail, mHtmlLoadExternal, mHtmlOverride, mHtmlLoadExtOverride;
00543   int mAtmCurrent;
00544   TQString mAtmCurrentName;
00545   KMMessage *mMessage;
00546 
00547   // See setOriginalMsg() for an explaination for those two.
00548   unsigned long mSerNumOfOriginalMessage;
00549   int mNodeIdOffset;
00550 
00551   // widgets:
00552   TQSplitter * mSplitter;
00553   TQHBox *mBox;
00554   KMail::HtmlStatusBar *mColorBar;
00555   KMMimePartTree* mMimePartTree;
00556   KHTMLPart *mViewer;
00557 
00558   const KMail::AttachmentStrategy * mAttachmentStrategy;
00559   const KMail::HeaderStrategy * mHeaderStrategy;
00560   const KMail::HeaderStyle * mHeaderStyle;
00561   bool mAutoDelete;
00563   TQString mSaveAttachDir;
00564   static const int delay;
00565   TQTimer mUpdateReaderWinTimer;
00566   TQTimer mResizeTimer;
00567   TQTimer mDelayedMarkTimer;
00568   TQString mOverrideEncoding;
00569   TQString mOldGlobalOverrideEncoding; // used to detect changes of the global override character encoding
00570   bool mMsgDisplay;
00571   bool mNoMDNsWhenEncrypted;
00572   unsigned long mLastSerNum;
00573 
00574   KMail::CSSHelper * mCSSHelper;
00575   bool mUseFixedFont;
00576   bool mPrinting;
00577   bool mShowColorbar;
00578   //bool mShowCompleteMessage;
00579   TQStringList mTempFiles;
00580   TQStringList mTempDirs;
00581   int mMimeTreeMode;
00582   bool mMimeTreeAtBottom;
00583   TQValueList<int> mSplitterSizes;
00584   partNode* mRootNode;
00585   TQString mIdOfLastViewedMessage;
00586   TQWidget *mMainWindow;
00587   KActionCollection *mActionCollection;
00588   KAction *mMailToComposeAction, *mMailToReplyAction, *mMailToForwardAction,
00589       *mAddAddrBookAction, *mOpenAddrBookAction, *mCopyAction, *mCopyURLAction,
00590       *mUrlOpenAction, *mUrlSaveAsAction, *mAddBookmarksAction, *mStartIMChatAction, *mSelectAllAction;
00591   KToggleAction *mHeaderOnlyAttachmentsAction;
00592   KSelectAction *mSelectEncodingAction;
00593   KToggleAction *mToggleFixFontAction;
00594 
00595   KURL mHoveredUrl;
00596   KURL mClickedUrl;
00597   TQPoint mLastClickPosition;
00598   TQString mLastClickImagePath;
00599   bool mCanStartDrag;
00600 
00601   KMail::HtmlWriter * mHtmlWriter;
00602   std::map<TQCString,KMail::Interface::BodyPartMemento*> mBodyPartMementoMap;
00603   // an attachment should be updated
00604   bool mAtmUpdate;
00605   int mChoice;
00606   unsigned long mWaitingForSerNum;
00607   float mSavedRelativePosition;
00608   int mLevelQuote;
00609   bool mDecrytMessageOverwrite;
00610   bool mShowSignatureDetails;
00611   bool mShowAttachmentQuicklist;
00612   bool mShowRawToltecMail;
00613   bool mExternalWindow;
00614 };
00615 
00616 
00617 #endif
00618