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 TDEActionCollection;
00032 class TDEAction;
00033 class TDEActionMenu;
00034 class TDESelectAction;
00035 class TDERadioAction;
00036 class TDEToggleAction;
00037 class TDEConfigBase;
00038 class TDEHTMLPart;
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 
00080   friend void KMMimePartTree::itemClicked( TQListViewItem* item );
00081   friend void KMMimePartTree::itemRightClicked( TQListViewItem* item, const TQPoint & );
00082   friend void KMMimePartTree::slotSaveAs();
00083   friend void KMMimePartTree::startDrag();
00084 
00085   friend class KMail::ObjectTreeParser;
00086   friend class KMail::KHtmlPartHtmlWriter;
00087 
00088 public:
00089   KMReaderWin( TQWidget *parent,
00090            TQWidget *mainWindow,
00091            TDEActionCollection *actionCollection,
00092                const char *name=0,
00093            int f=0 );
00094   virtual ~KMReaderWin();
00095 
00100   void update( KMail::Interface::Observable * );
00101 
00103   void readConfig();
00104 
00106   void writeConfig( bool withSync=true ) const;
00107 
00108   const KMail::HeaderStyle * headerStyle() const {
00109     return mHeaderStyle;
00110   }
00113   void setHeaderStyleAndStrategy( const KMail::HeaderStyle * style,
00114                   const KMail::HeaderStrategy * strategy );
00115 
00117   const KMail::HeaderStrategy * headerStrategy() const {
00118     return mHeaderStrategy;
00119   }
00120 
00122   const KMail::AttachmentStrategy * attachmentStrategy() const {
00123     return mAttachmentStrategy;
00124   }
00125   void setAttachmentStrategy( const KMail::AttachmentStrategy * strategy );
00126 
00130   TQString overrideEncoding() const { return mOverrideEncoding; }
00131 
00133   void setOverrideEncoding( const TQString & encoding );
00134 
00135   void setPrintFont( const TQFont& font );
00136 
00139   const TQTextCodec * overrideCodec() const;
00140 
00142   virtual void setPrinting(bool enable) { mPrinting = enable; }
00143 
00146   virtual void setMsg( KMMessage* msg, bool force = false, bool updateOnly = false );
00147 
00159   void setOriginalMsg( unsigned long serNumOfOriginalMessage, int nodeIdOffset );
00160 
00163   void setMsgPart( KMMessagePart* aMsgPart, bool aHTML,
00164            const TQString& aFileName, const TQString& pname );
00165 
00166   void setMsgPart( partNode * node );
00167 
00170   void showHideMimeTree( bool isPlainTextTopLevel );
00171 
00176   void setIdOfLastViewedMessage( const TQString & msgId )
00177     { mIdOfLastViewedMessage = msgId; }
00178 
00180   void clear(bool force = false) { setMsg(0, force); }
00181 
00184   void saveRelativePosition();
00185 
00187   void update(bool force = false);
00188 
00190   virtual void printMsg(void);
00191 
00193   TQString copyText();
00194 
00196   bool autoDelete(void) const { return mAutoDelete; }
00197   void setAutoDelete(bool f) { mAutoDelete=f; }
00198 
00200   bool htmlOverride() const { return mHtmlOverride; }
00201   void setHtmlOverride( bool override );
00202 
00204   bool htmlLoadExtOverride() const { return mHtmlLoadExtOverride; }
00205   void setHtmlLoadExtOverride( bool override );
00206 
00208   bool htmlMail();
00209 
00211   bool htmlLoadExternal();
00212 
00214   static TQString newFeaturesMD5();
00215 
00217   void displaySplashPage( const TQString &info );
00218 
00220   void displayAboutPage();
00221 
00223   void displayBusyPage();
00225   void displayOfflinePage();
00226 
00228   void enableMsgDisplay();
00229 
00235   void atmViewMsg( KMMessagePart* msgPart, int nodeId );
00236 
00237   bool atBottom() const;
00238 
00239   bool isFixedFont() { return mUseFixedFont; }
00240   void setUseFixedFont( bool useFixedFont ) { mUseFixedFont = useFixedFont; }
00241 
00243   KMail::HtmlWriter * htmlWriter() { return mHtmlWriter; }
00244 
00245   // Action to reply to a message
00246   // but action( "some_name" ) some name could be used instead.
00247   TDEToggleAction *toggleFixFontAction() { return mToggleFixFontAction; }
00248   TDEToggleAction *toggleMimePartTreeAction() { return mToggleMimePartTreeAction; }
00249   TDEAction *mailToComposeAction() { return mMailToComposeAction; }
00250   TDEAction *mailToReplyAction() { return mMailToReplyAction; }
00251   TDEAction *mailToForwardAction() { return mMailToForwardAction; }
00252   TDEAction *addAddrBookAction() { return mAddAddrBookAction; }
00253   TDEAction *openAddrBookAction() { return mOpenAddrBookAction; }
00254   TDEAction *copyAction() { return mCopyAction; }
00255   TDEAction *selectAllAction() { return mSelectAllAction; }
00256   TDEAction *copyURLAction() { return mCopyURLAction; }
00257   TDEAction *urlOpenAction() { return mUrlOpenAction; }
00258   TDEAction *urlSaveAsAction() { return mUrlSaveAsAction; }
00259   TDEAction *addBookmarksAction() { return mAddBookmarksAction;}
00260   TDEAction *startImChatAction() { return mStartIMChatAction; }
00261   // This function returns the complete data that were in this
00262   // message parts - *after* all encryption has been removed that
00263   // could be removed.
00264   // - This is used to store the message in decrypted form.
00265   void objectTreeToDecryptedMsg( partNode* node,
00266                                  NewByteArray& resultingData,
00267                                  KMMessage& theMessage,
00268                                  bool weAreReplacingTheRootNode = false,
00269                                  int recCount = 0 );
00270 
00272   partNode* partNodeFromUrl(const KURL &url);
00273 
00274   partNode * partNodeForId( int id );
00275 
00276   KURL tempFileUrlFromPartNode( const partNode * node );
00277 
00279   static int msgPartFromUrl(const KURL &url);
00280 
00281   void setUpdateAttachment( bool update = true ) { mAtmUpdate = update; }
00282 
00285   TDEHTMLPart * htmlPart() const { return mViewer; }
00286 
00288   KMMessage* message(KMFolder** folder=0) const;
00289 
00290   void openAttachment( int id, const TQString & name );
00291   void saveAttachment( const KURL &tempFileName );
00292 
00293   void emitUrlClicked( const KURL & url, int button ) {
00294     emit urlClicked( url, button );
00295   }
00296 
00297   void emitPopupMenu( const KURL & url, const TQPoint & p ) {
00298     if ( message() )
00299       emit popupMenu( *message(), url, p );
00300   }
00301 
00302   void showAttachmentPopup( int id, const TQString & name, const TQPoint & p );
00303 
00306   void setWaitingForSerNum( unsigned long serNum ) { mWaitingForSerNum = serNum; }
00307 
00308   TQWidget* mainWindow() { return mMainWindow; }
00309 
00311   bool decryptMessage() const;
00312 
00314   void setDecryptMessageOverwrite( bool overwrite = true ) { mDecrytMessageOverwrite = overwrite; }
00315 
00317   bool showSignatureDetails() const { return mShowSignatureDetails; }
00318 
00320   void setShowSignatureDetails( bool showDetails = true ) { mShowSignatureDetails = showDetails; }
00321 
00322   /* show or hide the list that points to the attachments */
00323   bool showAttachmentQuicklist() const { return mShowAttachmentQuicklist; }
00324 
00325   /* show or hide the list that points to the attachments */
00326   void setShowAttachmentQuicklist( bool showAttachmentQuicklist = true ) { mShowAttachmentQuicklist = showAttachmentQuicklist; }
00327 
00328   // This controls whether a Toltec invitation is shown in its raw form or as a replacement text.
00329   // This can be toggled with the "kmail:showRawToltecMail" link.
00330   bool showRawToltecMail() const { return mShowRawToltecMail; }
00331   void setShowRawToltecMail( bool showRawToltecMail ) { mShowRawToltecMail = showRawToltecMail; }
00332 
00333   /* retrieve BodyPartMemento of id \a which for partNode \a node */
00334   KMail::Interface::BodyPartMemento * bodyPartMemento( const partNode * node, const TQCString & which ) const;
00335 
00336   /* set/replace BodyPartMemento \a memento of id \a which for
00337      partNode \a node. If there was a BodyPartMemento registered
00338      already, replaces (deletes) that one. */
00339   void setBodyPartMemento( const partNode * node, const TQCString & which, KMail::Interface::BodyPartMemento * memento );
00340 
00342   void scrollToAttachment( const partNode *node );
00343 
00344 private:
00345   /* deletes all BodyPartMementos. Use this when skipping to another
00346      message (as opposed to re-loading the same one again). */
00347   void clearBodyPartMementos();
00348 
00349 signals:
00352   void replaceMsgByUnencryptedVersion();
00353 
00355   void popupMenu(KMMessage &msg, const KURL &url, const TQPoint& mousePos);
00356 
00358   void urlClicked(const KURL &url, int button);
00359 
00361   void noDrag(void);
00362 
00363 public slots:
00364 
00366   void selectAll();
00367 
00369   void clearCache();
00370 
00372   void updateReaderWin();
00373 
00375   void slotScrollUp();
00376   void slotScrollDown();
00377   void slotScrollPrior();
00378   void slotScrollNext();
00379   void slotJumpDown();
00380   void slotDocumentChanged();
00381   void slotDocumentDone();
00382   void slotTextSelected(bool);
00383   void updateHeader();
00384 
00386   void slotUrlOpen(const KURL &url, const KParts::URLArgs &args);
00387 
00389   void slotUrlOn(const TQString &url);
00390 
00392   void slotUrlPopup(const TQString &, const TQPoint& mousePos);
00393 
00395   void slotFind();
00397   void slotFindNext();
00398 
00400   void slotToggleFixedFont();
00401 
00403   void slotToggleMimePartTree();
00404 
00406   void slotCopySelectedText();
00407 
00408   void slotUrlClicked();
00409 
00411   void slotMailtoReply();
00412   void slotMailtoCompose();
00413   void slotMailtoForward();
00414   void slotMailtoAddAddrBook();
00415   void slotMailtoOpenAddrBook();
00418   void slotUrlCopy();
00419   void slotUrlOpen( const KURL &url = KURL() );
00421   void slotUrlSave();
00422   void slotAddBookmarks();
00423   void slotSaveMsg();
00424   void slotSaveAttachments();
00425 
00426   void slotMessageArrived( KMMessage *msg );
00428   void slotIMChat();
00429   void contactStatusChanged( const TQString &uid);
00430 
00431   void slotLevelQuote( int l );
00432   void slotTouchMessage();
00433 
00441   void fillCommandInfo( partNode *node, KMMessage **msg, int *nodeId );
00442 
00443   void slotDeleteAttachment( partNode* node );
00444   void slotEditAttachment( partNode* node );
00445 
00446   KMail::CSSHelper* cssHelper();
00447 
00448 protected slots:
00449   void slotCycleHeaderStyles();
00450   void slotBriefHeaders();
00451   void slotFancyHeaders();
00452   void slotEnterpriseHeaders();
00453   void slotStandardHeaders();
00454   void slotLongHeaders();
00455   void slotAllHeaders();
00456 
00457   void slotCycleAttachmentStrategy();
00458   void slotIconicAttachments();
00459   void slotSmartAttachments();
00460   void slotInlineAttachments();
00461   void slotHideAttachments();
00462   void slotHeaderOnlyAttachments();
00463 
00465   void slotAtmView( int id, const TQString& name );
00466   void slotDelayedResize();
00467   void slotHandleAttachment( int );
00468 
00472   void disconnectMsgAdded();
00473   void msgAdded( TQListViewItem *item );
00474 
00475 protected:
00478   void styleChange( TQStyle& oldStyle );
00479 
00482   void setStyleDependantFrameWidth();
00483 
00485   virtual bool event(TQEvent *e);
00486 
00488   int pointsToPixel(int pointSize) const;
00489 
00492   void displayMessage();
00493 
00495   virtual void parseMsg( KMMessage* msg  );
00496 
00499   TQString writeMsgHeader(KMMessage* aMsg, partNode *vCardNode = 0, bool topLevel=false );
00500 
00504   TQString writeMessagePartToTempFile( KMMessagePart* msgPart, int partNumber );
00505 
00511   TQString createTempDir( const TQString &param = TQString() );
00512 
00514   void showVCard(KMMessagePart *msgPart);
00515 
00517   virtual void initHtmlWidget(void);
00518 
00520   virtual void closeEvent(TQCloseEvent *);
00521   virtual void resizeEvent(TQResizeEvent *);
00522 
00524   virtual void removeTempFiles();
00525 
00527   bool eventFilter( TQObject *obj, TQEvent *ev );
00528 
00529 private slots:
00530   void slotSetEncoding();
00531   void injectAttachments();
00532 
00533 private:
00534   void adjustLayout();
00535   void createWidgets();
00536   void createActions( TDEActionCollection * ac );
00537   void saveSplitterSizes( TDEConfigBase & c ) const;
00538 
00539   TDERadioAction * actionForHeaderStyle( const KMail::HeaderStyle *,
00540                                        const KMail::HeaderStrategy * );
00541   TDERadioAction * actionForAttachmentStrategy( const KMail::AttachmentStrategy * );
00543   void readGlobalOverrideCodec();
00544 
00545   TQString renderAttachments( partNode *node, const TQColor &bgColor );
00546 
00547 private:
00548   bool mHtmlMail, mHtmlLoadExternal, mHtmlOverride, mHtmlLoadExtOverride;
00549   int mAtmCurrent;
00550   TQString mAtmCurrentName;
00551   KMMessage *mMessage;
00552 
00553   // See setOriginalMsg() for an explaination for those two.
00554   unsigned long mSerNumOfOriginalMessage;
00555   int mNodeIdOffset;
00556 
00557   // widgets:
00558   TQSplitter * mSplitter;
00559   TQHBox *mBox;
00560   KMail::HtmlStatusBar *mColorBar;
00561   KMMimePartTree* mMimePartTree;
00562   TDEHTMLPart *mViewer;
00563 
00564   const KMail::AttachmentStrategy * mAttachmentStrategy;
00565   const KMail::HeaderStrategy * mHeaderStrategy;
00566   const KMail::HeaderStyle * mHeaderStyle;
00567   bool mAutoDelete;
00569   TQString mSaveAttachDir;
00570   static const int delay;
00571   TQTimer mUpdateReaderWinTimer;
00572   TQTimer mResizeTimer;
00573   TQTimer mDelayedMarkTimer;
00574   TQTimer mHeaderRefreshTimer;
00575   TQString mOverrideEncoding;
00576   TQString mOldGlobalOverrideEncoding; // used to detect changes of the global override character encoding
00577   bool mMsgDisplay;
00578   bool mNoMDNsWhenEncrypted;
00579   unsigned long mLastSerNum;
00580 
00581   KMail::CSSHelper * mCSSHelper;
00582   bool mUseFixedFont;
00583   bool mPrinting;
00584   bool mShowColorbar;
00585   //bool mShowCompleteMessage;
00586   TQStringList mTempFiles;
00587   TQStringList mTempDirs;
00588   int mMimeTreeMode;
00589   int mMimeTreeModeOverride;
00590   bool mMimeTreeAtBottom;
00591   TQValueList<int> mSplitterSizes;
00592   partNode* mRootNode;
00593   TQString mIdOfLastViewedMessage;
00594   TQWidget *mMainWindow;
00595   TDEActionCollection *mActionCollection;
00596   TDEAction *mMailToComposeAction, *mMailToReplyAction, *mMailToForwardAction,
00597       *mAddAddrBookAction, *mOpenAddrBookAction, *mCopyAction, *mCopyURLAction,
00598       *mUrlOpenAction, *mUrlSaveAsAction, *mAddBookmarksAction, *mStartIMChatAction, *mSelectAllAction;
00599   TDEToggleAction *mHeaderOnlyAttachmentsAction;
00600   TDESelectAction *mSelectEncodingAction;
00601   TDEToggleAction *mToggleFixFontAction;
00602   TDEToggleAction *mToggleMimePartTreeAction;
00603 
00604   KURL mHoveredUrl;
00605   KURL mClickedUrl;
00606   TQPoint mLastClickPosition;
00607   TQString mLastClickImagePath;
00608   bool mCanStartDrag;
00609 
00610   KMail::HtmlWriter * mHtmlWriter;
00611   std::map<TQCString,KMail::Interface::BodyPartMemento*> mBodyPartMementoMap;
00612   // an attachment should be updated
00613   bool mAtmUpdate;
00614   int mChoice;
00615   unsigned long mWaitingForSerNum;
00616   float mSavedRelativePosition;
00617   int mLevelQuote;
00618   bool mDecrytMessageOverwrite;
00619   bool mShowSignatureDetails;
00620   bool mShowAttachmentQuicklist;
00621   bool mShowRawToltecMail;
00622   bool mExternalWindow;
00623 };
00624 
00625 
00626 #endif
00627