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 TDEAction *mailToComposeAction() { return mMailToComposeAction; } 00249 TDEAction *mailToReplyAction() { return mMailToReplyAction; } 00250 TDEAction *mailToForwardAction() { return mMailToForwardAction; } 00251 TDEAction *addAddrBookAction() { return mAddAddrBookAction; } 00252 TDEAction *openAddrBookAction() { return mOpenAddrBookAction; } 00253 TDEAction *copyAction() { return mCopyAction; } 00254 TDEAction *selectAllAction() { return mSelectAllAction; } 00255 TDEAction *copyURLAction() { return mCopyURLAction; } 00256 TDEAction *urlOpenAction() { return mUrlOpenAction; } 00257 TDEAction *urlSaveAsAction() { return mUrlSaveAsAction; } 00258 TDEAction *addBookmarksAction() { return mAddBookmarksAction;} 00259 TDEAction *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 TDEHTMLPart * 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 void updateHeader(); 00383 00385 void slotUrlOpen(const KURL &url, const KParts::URLArgs &args); 00386 00388 void slotUrlOn(const TQString &url); 00389 00391 void slotUrlPopup(const TQString &, const TQPoint& mousePos); 00392 00394 void slotFind(); 00396 void slotFindNext(); 00397 00399 void slotToggleFixedFont(); 00400 00402 void slotCopySelectedText(); 00403 00404 void slotUrlClicked(); 00405 00407 void slotMailtoReply(); 00408 void slotMailtoCompose(); 00409 void slotMailtoForward(); 00410 void slotMailtoAddAddrBook(); 00411 void slotMailtoOpenAddrBook(); 00414 void slotUrlCopy(); 00415 void slotUrlOpen( const KURL &url = KURL() ); 00417 void slotUrlSave(); 00418 void slotAddBookmarks(); 00419 void slotSaveMsg(); 00420 void slotSaveAttachments(); 00421 00422 void slotMessageArrived( KMMessage *msg ); 00424 void slotIMChat(); 00425 void contactStatusChanged( const TQString &uid); 00426 00427 void slotLevelQuote( int l ); 00428 void slotTouchMessage(); 00429 00437 void fillCommandInfo( partNode *node, KMMessage **msg, int *nodeId ); 00438 00439 void slotDeleteAttachment( partNode* node ); 00440 void slotEditAttachment( partNode* node ); 00441 00442 KMail::CSSHelper* cssHelper(); 00443 00444 protected slots: 00445 void slotCycleHeaderStyles(); 00446 void slotBriefHeaders(); 00447 void slotFancyHeaders(); 00448 void slotEnterpriseHeaders(); 00449 void slotStandardHeaders(); 00450 void slotLongHeaders(); 00451 void slotAllHeaders(); 00452 00453 void slotCycleAttachmentStrategy(); 00454 void slotIconicAttachments(); 00455 void slotSmartAttachments(); 00456 void slotInlineAttachments(); 00457 void slotHideAttachments(); 00458 void slotHeaderOnlyAttachments(); 00459 00461 void slotAtmView( int id, const TQString& name ); 00462 void slotDelayedResize(); 00463 void slotHandleAttachment( int ); 00464 00468 void disconnectMsgAdded(); 00469 void msgAdded( TQListViewItem *item ); 00470 00471 protected: 00474 void styleChange( TQStyle& oldStyle ); 00475 00478 void setStyleDependantFrameWidth(); 00479 00481 virtual bool event(TQEvent *e); 00482 00484 int pointsToPixel(int pointSize) const; 00485 00488 void displayMessage(); 00489 00491 virtual void parseMsg( KMMessage* msg ); 00492 00495 TQString writeMsgHeader(KMMessage* aMsg, partNode *vCardNode = 0, bool topLevel=false ); 00496 00500 TQString writeMessagePartToTempFile( KMMessagePart* msgPart, int partNumber ); 00501 00507 TQString createTempDir( const TQString ¶m = TQString() ); 00508 00510 void showVCard(KMMessagePart *msgPart); 00511 00513 virtual void initHtmlWidget(void); 00514 00516 virtual void closeEvent(TQCloseEvent *); 00517 virtual void resizeEvent(TQResizeEvent *); 00518 00520 virtual void removeTempFiles(); 00521 00523 bool eventFilter( TQObject *obj, TQEvent *ev ); 00524 00525 private slots: 00526 void slotSetEncoding(); 00527 void injectAttachments(); 00528 00529 private: 00530 void adjustLayout(); 00531 void createWidgets(); 00532 void createActions( TDEActionCollection * ac ); 00533 void saveSplitterSizes( TDEConfigBase & c ) const; 00534 00535 TDERadioAction * actionForHeaderStyle( const KMail::HeaderStyle *, 00536 const KMail::HeaderStrategy * ); 00537 TDERadioAction * actionForAttachmentStrategy( const KMail::AttachmentStrategy * ); 00539 void readGlobalOverrideCodec(); 00540 00541 TQString renderAttachments( partNode *node, const TQColor &bgColor ); 00542 00543 private: 00544 bool mHtmlMail, mHtmlLoadExternal, mHtmlOverride, mHtmlLoadExtOverride; 00545 int mAtmCurrent; 00546 TQString mAtmCurrentName; 00547 KMMessage *mMessage; 00548 00549 // See setOriginalMsg() for an explaination for those two. 00550 unsigned long mSerNumOfOriginalMessage; 00551 int mNodeIdOffset; 00552 00553 // widgets: 00554 TQSplitter * mSplitter; 00555 TQHBox *mBox; 00556 KMail::HtmlStatusBar *mColorBar; 00557 KMMimePartTree* mMimePartTree; 00558 TDEHTMLPart *mViewer; 00559 00560 const KMail::AttachmentStrategy * mAttachmentStrategy; 00561 const KMail::HeaderStrategy * mHeaderStrategy; 00562 const KMail::HeaderStyle * mHeaderStyle; 00563 bool mAutoDelete; 00565 TQString mSaveAttachDir; 00566 static const int delay; 00567 TQTimer mUpdateReaderWinTimer; 00568 TQTimer mResizeTimer; 00569 TQTimer mDelayedMarkTimer; 00570 TQTimer mHeaderRefreshTimer; 00571 TQString mOverrideEncoding; 00572 TQString mOldGlobalOverrideEncoding; // used to detect changes of the global override character encoding 00573 bool mMsgDisplay; 00574 bool mNoMDNsWhenEncrypted; 00575 unsigned long mLastSerNum; 00576 00577 KMail::CSSHelper * mCSSHelper; 00578 bool mUseFixedFont; 00579 bool mPrinting; 00580 bool mShowColorbar; 00581 //bool mShowCompleteMessage; 00582 TQStringList mTempFiles; 00583 TQStringList mTempDirs; 00584 int mMimeTreeMode; 00585 bool mMimeTreeAtBottom; 00586 TQValueList<int> mSplitterSizes; 00587 partNode* mRootNode; 00588 TQString mIdOfLastViewedMessage; 00589 TQWidget *mMainWindow; 00590 TDEActionCollection *mActionCollection; 00591 TDEAction *mMailToComposeAction, *mMailToReplyAction, *mMailToForwardAction, 00592 *mAddAddrBookAction, *mOpenAddrBookAction, *mCopyAction, *mCopyURLAction, 00593 *mUrlOpenAction, *mUrlSaveAsAction, *mAddBookmarksAction, *mStartIMChatAction, *mSelectAllAction; 00594 TDEToggleAction *mHeaderOnlyAttachmentsAction; 00595 TDESelectAction *mSelectEncodingAction; 00596 TDEToggleAction *mToggleFixFontAction; 00597 00598 KURL mHoveredUrl; 00599 KURL mClickedUrl; 00600 TQPoint mLastClickPosition; 00601 TQString mLastClickImagePath; 00602 bool mCanStartDrag; 00603 00604 KMail::HtmlWriter * mHtmlWriter; 00605 std::map<TQCString,KMail::Interface::BodyPartMemento*> mBodyPartMementoMap; 00606 // an attachment should be updated 00607 bool mAtmUpdate; 00608 int mChoice; 00609 unsigned long mWaitingForSerNum; 00610 float mSavedRelativePosition; 00611 int mLevelQuote; 00612 bool mDecrytMessageOverwrite; 00613 bool mShowSignatureDetails; 00614 bool mShowAttachmentQuicklist; 00615 bool mShowRawToltecMail; 00616 bool mExternalWindow; 00617 }; 00618 00619 00620 #endif 00621