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   TQ_OBJECT
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            KActionCollection *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   KToggleAction *toggleFixFontAction() { return mToggleFixFontAction; }
00248   KAction *mailToComposeAction() { return mMailToComposeAction; }
00249   KAction *mailToReplyAction() { return mMailToReplyAction; }
00250   KAction *mailToForwardAction() { return mMailToForwardAction; }
00251   KAction *addAddrBookAction() { return mAddAddrBookAction; }
00252   KAction *openAddrBookAction() { return mOpenAddrBookAction; }
00253   KAction *copyAction() { return mCopyAction; }
00254   KAction *selectAllAction() { return mSelectAllAction; }
00255   KAction *copyURLAction() { return mCopyURLAction; }
00256   KAction *urlOpenAction() { return mUrlOpenAction; }
00257   KAction *urlSaveAsAction() { return mUrlSaveAsAction; }
00258   KAction *addBookmarksAction() { return mAddBookmarksAction;}
00259   KAction *startImChatAction() { return mStartIMChatAction; }
00260   // This function returns the complete data that were in this
00261   // message parts - *after* all encryption has been removed that
00262   // could be removed.
00263   // - This is used to store the message in decrypted form.
00264   void objectTreeToDecryptedMsg( partNode* node,
00265                                  NewByteArray& resultingData,
00266                                  KMMessage& theMessage,
00267                                  bool weAreReplacingTheRootNode = false,
00268                                  int recCount = 0 );
00269 
00271   partNode* partNodeFromUrl(const KURL &url);
00272 
00273   partNode * partNodeForId( int id );
00274 
00275   KURL tempFileUrlFromPartNode( const partNode * node );
00276 
00278   static int msgPartFromUrl(const KURL &url);
00279 
00280   void setUpdateAttachment( bool update = true ) { mAtmUpdate = update; }
00281 
00284   KHTMLPart * htmlPart() const { return mViewer; }
00285 
00287   KMMessage* message(KMFolder** folder=0) const;
00288 
00289   void openAttachment( int id, const TQString & name );
00290   void saveAttachment( const KURL &tempFileName );
00291 
00292   void emitUrlClicked( const KURL & url, int button ) {
00293     emit urlClicked( url, button );
00294   }
00295 
00296   void emitPopupMenu( const KURL & url, const TQPoint & p ) {
00297     if ( message() )
00298       emit popupMenu( *message(), url, p );
00299   }
00300 
00301   void showAttachmentPopup( int id, const TQString & name, const TQPoint & p );
00302 
00305   void setWaitingForSerNum( unsigned long serNum ) { mWaitingForSerNum = serNum; }
00306 
00307   TQWidget* mainWindow() { return mMainWindow; }
00308 
00310   bool decryptMessage() const;
00311 
00313   void setDecryptMessageOverwrite( bool overwrite = true ) { mDecrytMessageOverwrite = overwrite; }
00314 
00316   bool showSignatureDetails() const { return mShowSignatureDetails; }
00317 
00319   void setShowSignatureDetails( bool showDetails = true ) { mShowSignatureDetails = showDetails; }
00320 
00321   /* show or hide the list that points to the attachments */
00322   bool showAttachmentQuicklist() const { return mShowAttachmentQuicklist; }
00323 
00324   /* show or hide the list that points to the attachments */
00325   void setShowAttachmentQuicklist( bool showAttachmentQuicklist = true ) { mShowAttachmentQuicklist = showAttachmentQuicklist; }
00326 
00327   // This controls whether a Toltec invitation is shown in its raw form or as a replacement text.
00328   // This can be toggled with the "kmail:showRawToltecMail" link.
00329   bool showRawToltecMail() const { return mShowRawToltecMail; }
00330   void setShowRawToltecMail( bool showRawToltecMail ) { mShowRawToltecMail = showRawToltecMail; }
00331 
00332   /* retrieve BodyPartMemento of id \a which for partNode \a node */
00333   KMail::Interface::BodyPartMemento * bodyPartMemento( const partNode * node, const TQCString & which ) const;
00334 
00335   /* set/replace BodyPartMemento \a memento of id \a which for
00336      partNode \a node. If there was a BodyPartMemento registered
00337      already, replaces (deletes) that one. */
00338   void setBodyPartMemento( const partNode * node, const TQCString & which, KMail::Interface::BodyPartMemento * memento );
00339 
00341   void scrollToAttachment( const partNode *node );
00342 
00343 private:
00344   /* deletes all BodyPartMementos. Use this when skipping to another
00345      message (as opposed to re-loading the same one again). */
00346   void clearBodyPartMementos();
00347 
00348 signals:
00351   void replaceMsgByUnencryptedVersion();
00352 
00354   void popupMenu(KMMessage &msg, const KURL &url, const TQPoint& mousePos);
00355 
00357   void urlClicked(const KURL &url, int button);
00358 
00360   void noDrag(void);
00361 
00362 public slots:
00363 
00365   void selectAll();
00366 
00368   void clearCache();
00369 
00371   void updateReaderWin();
00372 
00374   void slotScrollUp();
00375   void slotScrollDown();
00376   void slotScrollPrior();
00377   void slotScrollNext();
00378   void slotJumpDown();
00379   void slotDocumentChanged();
00380   void slotDocumentDone();
00381   void slotTextSelected(bool);
00382 
00384   void slotUrlOpen(const KURL &url, const KParts::URLArgs &args);
00385 
00387   void slotUrlOn(const TQString &url);
00388 
00390   void slotUrlPopup(const TQString &, const TQPoint& mousePos);
00391 
00393   void slotFind();
00395   void slotFindNext();
00396 
00398   void slotToggleFixedFont();
00399 
00401   void slotCopySelectedText();
00402 
00403    void slotUrlClicked();
00404 
00406   void slotMailtoReply();
00407   void slotMailtoCompose();
00408   void slotMailtoForward();
00409   void slotMailtoAddAddrBook();
00410   void slotMailtoOpenAddrBook();
00413   void slotUrlCopy();
00414   void slotUrlOpen( const KURL &url = KURL() );
00416   void slotUrlSave();
00417   void slotAddBookmarks();
00418   void slotSaveMsg();
00419   void slotSaveAttachments();
00420 
00421   void slotMessageArrived( KMMessage *msg );
00423   void slotIMChat();
00424   void contactStatusChanged( const TQString &uid);
00425 
00426   void slotLevelQuote( int l );
00427   void slotTouchMessage();
00428 
00436   void fillCommandInfo( partNode *node, KMMessage **msg, int *nodeId );
00437 
00438   void slotDeleteAttachment( partNode* node );
00439   void slotEditAttachment( partNode* node );
00440 
00441   KMail::CSSHelper* cssHelper();
00442 
00443 protected slots:
00444   void slotCycleHeaderStyles();
00445   void slotBriefHeaders();
00446   void slotFancyHeaders();
00447   void slotEnterpriseHeaders();
00448   void slotStandardHeaders();
00449   void slotLongHeaders();
00450   void slotAllHeaders();
00451 
00452   void slotCycleAttachmentStrategy();
00453   void slotIconicAttachments();
00454   void slotSmartAttachments();
00455   void slotInlineAttachments();
00456   void slotHideAttachments();
00457   void slotHeaderOnlyAttachments();
00458 
00460   void slotAtmView( int id, const TQString& name );
00461   void slotDelayedResize();
00462   void slotHandleAttachment( int );
00463 
00467   void disconnectMsgAdded();
00468   void msgAdded( TQListViewItem *item );
00469 
00470 protected:
00473   void styleChange( TQStyle& oldStyle );
00474 
00477   void setStyleDependantFrameWidth();
00478 
00480   virtual bool event(TQEvent *e);
00481 
00483   int pointsToPixel(int pointSize) const;
00484 
00487   void displayMessage();
00488 
00490   virtual void parseMsg( KMMessage* msg  );
00491 
00494   TQString writeMsgHeader(KMMessage* aMsg, partNode *vCardNode = 0, bool topLevel=false );
00495 
00499   TQString writeMessagePartToTempFile( KMMessagePart* msgPart, int partNumber );
00500 
00506   TQString createTempDir( const TQString &param = TQString() );
00507 
00509   void showVCard(KMMessagePart *msgPart);
00510 
00512   virtual void initHtmlWidget(void);
00513 
00515   virtual void closeEvent(TQCloseEvent *);
00516   virtual void resizeEvent(TQResizeEvent *);
00517 
00519   virtual void removeTempFiles();
00520 
00522   bool eventFilter( TQObject *obj, TQEvent *ev );
00523 
00524 private slots:
00525   void slotSetEncoding();
00526   void injectAttachments();
00527 
00528 private:
00529   void adjustLayout();
00530   void createWidgets();
00531   void createActions( KActionCollection * ac );
00532   void saveSplitterSizes( KConfigBase & c ) const;
00533 
00534   KRadioAction * actionForHeaderStyle( const KMail::HeaderStyle *,
00535                                        const KMail::HeaderStrategy * );
00536   KRadioAction * actionForAttachmentStrategy( const KMail::AttachmentStrategy * );
00538   void readGlobalOverrideCodec();
00539 
00540   TQString renderAttachments( partNode *node, const TQColor &bgColor );
00541 
00542 private:
00543   bool mHtmlMail, mHtmlLoadExternal, mHtmlOverride, mHtmlLoadExtOverride;
00544   int mAtmCurrent;
00545   TQString mAtmCurrentName;
00546   KMMessage *mMessage;
00547 
00548   // See setOriginalMsg() for an explaination for those two.
00549   unsigned long mSerNumOfOriginalMessage;
00550   int mNodeIdOffset;
00551 
00552   // widgets:
00553   TQSplitter * mSplitter;
00554   TQHBox *mBox;
00555   KMail::HtmlStatusBar *mColorBar;
00556   KMMimePartTree* mMimePartTree;
00557   KHTMLPart *mViewer;
00558 
00559   const KMail::AttachmentStrategy * mAttachmentStrategy;
00560   const KMail::HeaderStrategy * mHeaderStrategy;
00561   const KMail::HeaderStyle * mHeaderStyle;
00562   bool mAutoDelete;
00564   TQString mSaveAttachDir;
00565   static const int delay;
00566   TQTimer mUpdateReaderWinTimer;
00567   TQTimer mResizeTimer;
00568   TQTimer mDelayedMarkTimer;
00569   TQString mOverrideEncoding;
00570   TQString mOldGlobalOverrideEncoding; // used to detect changes of the global override character encoding
00571   bool mMsgDisplay;
00572   bool mNoMDNsWhenEncrypted;
00573   unsigned long mLastSerNum;
00574 
00575   KMail::CSSHelper * mCSSHelper;
00576   bool mUseFixedFont;
00577   bool mPrinting;
00578   bool mShowColorbar;
00579   //bool mShowCompleteMessage;
00580   TQStringList mTempFiles;
00581   TQStringList mTempDirs;
00582   int mMimeTreeMode;
00583   bool mMimeTreeAtBottom;
00584   TQValueList<int> mSplitterSizes;
00585   partNode* mRootNode;
00586   TQString mIdOfLastViewedMessage;
00587   TQWidget *mMainWindow;
00588   KActionCollection *mActionCollection;
00589   KAction *mMailToComposeAction, *mMailToReplyAction, *mMailToForwardAction,
00590       *mAddAddrBookAction, *mOpenAddrBookAction, *mCopyAction, *mCopyURLAction,
00591       *mUrlOpenAction, *mUrlSaveAsAction, *mAddBookmarksAction, *mStartIMChatAction, *mSelectAllAction;
00592   KToggleAction *mHeaderOnlyAttachmentsAction;
00593   KSelectAction *mSelectEncodingAction;
00594   KToggleAction *mToggleFixFontAction;
00595 
00596   KURL mHoveredUrl;
00597   KURL mClickedUrl;
00598   TQPoint mLastClickPosition;
00599   TQString mLastClickImagePath;
00600   bool mCanStartDrag;
00601 
00602   KMail::HtmlWriter * mHtmlWriter;
00603   std::map<TQCString,KMail::Interface::BodyPartMemento*> mBodyPartMementoMap;
00604   // an attachment should be updated
00605   bool mAtmUpdate;
00606   int mChoice;
00607   unsigned long mWaitingForSerNum;
00608   float mSavedRelativePosition;
00609   int mLevelQuote;
00610   bool mDecrytMessageOverwrite;
00611   bool mShowSignatureDetails;
00612   bool mShowAttachmentQuicklist;
00613   bool mShowRawToltecMail;
00614   bool mExternalWindow;
00615 };
00616 
00617 
00618 #endif
00619