kmail

kmreaderwin.h
1 // -*- mode: C++; c-file-style: "gnu" -*-
2 // Header for kmreaderwin the kmail reader
3 // written by Markus Wuebben <markus.wuebben@kde.org>
4 
5 #ifndef KMREADERWIN_H
6 #define KMREADERWIN_H
7 
8 #include <tqwidget.h>
9 #include <tqtimer.h>
10 #include <tqstringlist.h>
11 #include <kurl.h>
12 #include <kservice.h>
13 #include "kmmsgbase.h"
14 #include "kmmimeparttree.h" // Needed for friend declaration.
15 #include "interfaces/observer.h"
16 
17 #include <map>
18 
19 class TQFrame;
20 class TQSplitter;
21 class TQHBox;
22 class TQListViewItem;
23 class TQScrollBar;
24 class TQString;
25 class TQTabDialog;
26 class TQTextCodec;
27 
28 class DwHeaders;
29 class DwMediaType;
30 
31 class TDEActionCollection;
32 class TDEAction;
33 class TDEActionMenu;
34 class TDESelectAction;
35 class TDERadioAction;
36 class TDEToggleAction;
37 class TDEConfigBase;
38 class TDEHTMLPart;
39 class KURL;
40 
41 class KMFolder;
42 class KMMessage;
43 class KMMessagePart;
44 namespace KMail {
45  namespace Interface {
46  class Observable;
47  class BodyPartMemento;
48  }
49  class PartMetaData;
50  class ObjectTreeParser;
51  class AttachmentStrategy;
52  class HeaderStrategy;
53  class HeaderStyle;
54  class HtmlWriter;
55  class KHtmlPartHtmlWriter;
56  class ISubject;
57  class HtmlStatusBar;
58  class FolderJob;
59  class CSSHelper;
60 }
61 
62 class partNode; // might be removed when KMime is used instead of mimelib
63  // (khz, 29.11.2001)
64 
65 class NewByteArray; // providing operator+ on a TQByteArray (khz, 21.06.2002)
66 
67 namespace KParts {
68  struct URLArgs;
69 }
70 
76 class KMReaderWin: public TQWidget, public KMail::Interface::Observer {
77  Q_OBJECT
78 
79 
80  friend void KMMimePartTree::itemClicked( TQListViewItem* item );
81  friend void KMMimePartTree::itemRightClicked( TQListViewItem* item, const TQPoint & );
82  friend void KMMimePartTree::slotSaveAs();
83  friend void KMMimePartTree::startDrag();
84 
85  friend class KMail::ObjectTreeParser;
86  friend class KMail::KHtmlPartHtmlWriter;
87 
88 public:
89  KMReaderWin( TQWidget *parent,
90  TQWidget *mainWindow,
91  TDEActionCollection *actionCollection,
92  const char *name=0,
93  int f=0 );
94  virtual ~KMReaderWin();
95 
101 
103  void readConfig();
104 
106  void writeConfig( bool withSync=true ) const;
107 
108  const KMail::HeaderStyle * headerStyle() const {
109  return mHeaderStyle;
110  }
113  void setHeaderStyleAndStrategy( const KMail::HeaderStyle * style,
114  const KMail::HeaderStrategy * strategy );
115 
117  const KMail::HeaderStrategy * headerStrategy() const {
118  return mHeaderStrategy;
119  }
120 
122  const KMail::AttachmentStrategy * attachmentStrategy() const {
123  return mAttachmentStrategy;
124  }
125  void setAttachmentStrategy( const KMail::AttachmentStrategy * strategy );
126 
130  TQString overrideEncoding() const { return mOverrideEncoding; }
131 
133  void setOverrideEncoding( const TQString & encoding );
134 
135  void setPrintFont( const TQFont& font );
136 
139  const TQTextCodec * overrideCodec() const;
140 
142  virtual void setPrinting(bool enable) { mPrinting = enable; }
143 
146  virtual void setMsg( KMMessage* msg, bool force = false, bool updateOnly = false );
147 
159  void setOriginalMsg( unsigned long serNumOfOriginalMessage, int nodeIdOffset );
160 
163  void setMsgPart( KMMessagePart* aMsgPart, bool aHTML,
164  const TQString& aFileName, const TQString& pname );
165 
166  void setMsgPart( partNode * node );
167 
170  void showHideMimeTree( bool isPlainTextTopLevel );
171 
176  void setIdOfLastViewedMessage( const TQString & msgId )
177  { mIdOfLastViewedMessage = msgId; }
178 
180  void clear(bool force = false) { setMsg(0, force); }
181 
184  void saveRelativePosition();
185 
187  void update(bool force = false);
188 
190  virtual void printMsg(void);
191 
193  TQString copyText();
194 
196  bool autoDelete(void) const { return mAutoDelete; }
197  void setAutoDelete(bool f) { mAutoDelete=f; }
198 
200  bool htmlOverride() const { return mHtmlOverride; }
201  void setHtmlOverride( bool override );
202 
204  bool htmlLoadExtOverride() const { return mHtmlLoadExtOverride; }
205  void setHtmlLoadExtOverride( bool override );
206 
208  bool htmlMail();
209 
211  bool htmlLoadExternal();
212 
214  static TQString newFeaturesMD5();
215 
217  void displaySplashPage( const TQString &info );
218 
220  void displayAboutPage();
221 
223  void displayBusyPage();
225  void displayOfflinePage();
226 
228  void enableMsgDisplay();
229 
235  void atmViewMsg( KMMessagePart* msgPart, int nodeId );
236 
237  bool atBottom() const;
238 
239  bool isFixedFont() { return mUseFixedFont; }
240  void setUseFixedFont( bool useFixedFont ) { mUseFixedFont = useFixedFont; }
241 
243  KMail::HtmlWriter * htmlWriter() { return mHtmlWriter; }
244 
245  // Action to reply to a message
246  // but action( "some_name" ) some name could be used instead.
247  TDEToggleAction *toggleFixFontAction() { return mToggleFixFontAction; }
248  TDEToggleAction *toggleMimePartTreeAction() { return mToggleMimePartTreeAction; }
249  TDEAction *mailToComposeAction() { return mMailToComposeAction; }
250  TDEAction *mailToReplyAction() { return mMailToReplyAction; }
251  TDEAction *mailToForwardAction() { return mMailToForwardAction; }
252  TDEAction *addAddrBookAction() { return mAddAddrBookAction; }
253  TDEAction *openAddrBookAction() { return mOpenAddrBookAction; }
254  TDEAction *copyAction() { return mCopyAction; }
255  TDEAction *selectAllAction() { return mSelectAllAction; }
256  TDEAction *copyURLAction() { return mCopyURLAction; }
257  TDEAction *urlOpenAction() { return mUrlOpenAction; }
258  TDEAction *urlSaveAsAction() { return mUrlSaveAsAction; }
259  TDEAction *addBookmarksAction() { return mAddBookmarksAction;}
260  TDEAction *startImChatAction() { return mStartIMChatAction; }
261  // This function returns the complete data that were in this
262  // message parts - *after* all encryption has been removed that
263  // could be removed.
264  // - This is used to store the message in decrypted form.
265  void objectTreeToDecryptedMsg( partNode* node,
266  NewByteArray& resultingData,
267  KMMessage& theMessage,
268  bool weAreReplacingTheRootNode = false,
269  int recCount = 0 );
270 
272  partNode* partNodeFromUrl(const KURL &url);
273 
274  partNode * partNodeForId( int id );
275 
276  KURL tempFileUrlFromPartNode( const partNode * node );
277 
279  static int msgPartFromUrl(const KURL &url);
280 
281  void setUpdateAttachment( bool update = true ) { mAtmUpdate = update; }
282 
285  TDEHTMLPart * htmlPart() const { return mViewer; }
286 
288  KMMessage* message(KMFolder** folder=0) const;
289 
290  void openAttachment( int id, const TQString & name );
291  void saveAttachment( const KURL &tempFileName );
292 
293  void emitUrlClicked( const KURL & url, int button ) {
294  emit urlClicked( url, button );
295  }
296 
297  void emitPopupMenu( const KURL & url, const TQPoint & p ) {
298  if ( message() )
299  emit popupMenu( *message(), url, p );
300  }
301 
302  void showAttachmentPopup( int id, const TQString & name, const TQPoint & p );
303 
306  void setWaitingForSerNum( unsigned long serNum ) { mWaitingForSerNum = serNum; }
307 
308  TQWidget* mainWindow() { return mMainWindow; }
309 
311  bool decryptMessage() const;
312 
314  void setDecryptMessageOverwrite( bool overwrite = true ) { mDecrytMessageOverwrite = overwrite; }
315 
317  bool showSignatureDetails() const { return mShowSignatureDetails; }
318 
320  void setShowSignatureDetails( bool showDetails = true ) { mShowSignatureDetails = showDetails; }
321 
322  /* show or hide the list that points to the attachments */
323  bool showAttachmentQuicklist() const { return mShowAttachmentQuicklist; }
324 
325  /* show or hide the list that points to the attachments */
326  void setShowAttachmentQuicklist( bool showAttachmentQuicklist = true ) { mShowAttachmentQuicklist = showAttachmentQuicklist; }
327 
328  // This controls whether a Toltec invitation is shown in its raw form or as a replacement text.
329  // This can be toggled with the "kmail:showRawToltecMail" link.
330  bool showRawToltecMail() const { return mShowRawToltecMail; }
331  void setShowRawToltecMail( bool showRawToltecMail ) { mShowRawToltecMail = showRawToltecMail; }
332 
333  /* retrieve BodyPartMemento of id \a which for partNode \a node */
334  KMail::Interface::BodyPartMemento * bodyPartMemento( const partNode * node, const TQCString & which ) const;
335 
336  /* set/replace BodyPartMemento \a memento of id \a which for
337  partNode \a node. If there was a BodyPartMemento registered
338  already, replaces (deletes) that one. */
339  void setBodyPartMemento( const partNode * node, const TQCString & which, KMail::Interface::BodyPartMemento * memento );
340 
342  void scrollToAttachment( const partNode *node );
343 
344 private:
345  /* deletes all BodyPartMementos. Use this when skipping to another
346  message (as opposed to re-loading the same one again). */
347  void clearBodyPartMementos();
348 
349 signals:
353 
355  void popupMenu(KMMessage &msg, const KURL &url, const TQPoint& mousePos);
356 
358  void urlClicked(const KURL &url, int button);
359 
361  void noDrag(void);
362 
363 public slots:
364 
366  void selectAll();
367 
369  void clearCache();
370 
372  void updateReaderWin();
373 
375  void slotScrollUp();
376  void slotScrollDown();
377  void slotScrollPrior();
378  void slotScrollNext();
379  void slotJumpDown();
380  void slotDocumentChanged();
381  void slotDocumentDone();
382  void slotTextSelected(bool);
383  void updateHeader();
384 
386  void slotUrlOpen(const KURL &url, const KParts::URLArgs &args);
387 
389  void slotUrlOn(const TQString &url);
390 
392  void slotUrlPopup(const TQString &, const TQPoint& mousePos);
393 
395  void slotFind();
397  void slotFindNext();
398 
400  void slotToggleFixedFont();
401 
403  void slotToggleMimePartTree();
404 
406  void slotCopySelectedText();
407 
408  void slotUrlClicked();
409 
411  void slotMailtoReply();
412  void slotMailtoCompose();
413  void slotMailtoForward();
414  void slotMailtoAddAddrBook();
415  void slotMailtoOpenAddrBook();
418  void slotUrlCopy();
419  void slotUrlOpen( const KURL &url = KURL() );
421  void slotUrlSave();
422  void slotAddBookmarks();
423  void slotSaveMsg();
424  void slotSaveAttachments();
425 
426  void slotMessageArrived( KMMessage *msg );
428  void slotIMChat();
429  void contactStatusChanged( const TQString &uid);
430 
431  void slotLevelQuote( int l );
432  void slotTouchMessage();
433 
441  void fillCommandInfo( partNode *node, KMMessage **msg, int *nodeId );
442 
443  void slotDeleteAttachment( partNode* node );
444  void slotEditAttachment( partNode* node );
445 
446  KMail::CSSHelper* cssHelper();
447 
448 protected slots:
449  void slotCycleHeaderStyles();
450  void slotBriefHeaders();
451  void slotFancyHeaders();
452  void slotEnterpriseHeaders();
453  void slotStandardHeaders();
454  void slotLongHeaders();
455  void slotAllHeaders();
456 
457  void slotCycleAttachmentStrategy();
458  void slotIconicAttachments();
459  void slotSmartAttachments();
460  void slotInlineAttachments();
461  void slotHideAttachments();
462  void slotHeaderOnlyAttachments();
463 
465  void slotAtmView( int id, const TQString& name );
466  void slotDelayedResize();
467  void slotHandleAttachment( int );
468 
472  void disconnectMsgAdded();
473  void msgAdded( TQListViewItem *item );
474 
475 protected:
478  void styleChange( TQStyle& oldStyle );
479 
483 
485  virtual bool event(TQEvent *e);
486 
488  int pointsToPixel(int pointSize) const;
489 
492  void displayMessage();
493 
495  virtual void parseMsg( KMMessage* msg );
496 
499  TQString writeMsgHeader(KMMessage* aMsg, partNode *vCardNode = 0, bool topLevel=false );
500 
504  TQString writeMessagePartToTempFile( KMMessagePart* msgPart, int partNumber );
505 
511  TQString createTempDir( const TQString &param = TQString() );
512 
514  void showVCard(KMMessagePart *msgPart);
515 
517  virtual void initHtmlWidget(void);
518 
520  virtual void closeEvent(TQCloseEvent *);
521  virtual void resizeEvent(TQResizeEvent *);
522 
524  virtual void removeTempFiles();
525 
527  bool eventFilter( TQObject *obj, TQEvent *ev );
528 
529 private slots:
530  void slotSetEncoding();
531  void injectAttachments();
532 
533 private:
534  void adjustLayout();
535  void createWidgets();
536  void createActions( TDEActionCollection * ac );
537  void saveSplitterSizes( TDEConfigBase & c ) const;
538 
539  TDERadioAction * actionForHeaderStyle( const KMail::HeaderStyle *,
540  const KMail::HeaderStrategy * );
541  TDERadioAction * actionForAttachmentStrategy( const KMail::AttachmentStrategy * );
543  void readGlobalOverrideCodec();
544 
545  TQString renderAttachments( partNode *node, const TQColor &bgColor );
546 
547 private:
548  bool mHtmlMail, mHtmlLoadExternal, mHtmlOverride, mHtmlLoadExtOverride;
549  int mAtmCurrent;
550  TQString mAtmCurrentName;
551  KMMessage *mMessage;
552 
553  // See setOriginalMsg() for an explaination for those two.
554  unsigned long mSerNumOfOriginalMessage;
555  int mNodeIdOffset;
556 
557  // widgets:
558  TQSplitter * mSplitter;
559  TQHBox *mBox;
560  KMail::HtmlStatusBar *mColorBar;
561  KMMimePartTree* mMimePartTree;
562  TDEHTMLPart *mViewer;
563 
564  const KMail::AttachmentStrategy * mAttachmentStrategy;
565  const KMail::HeaderStrategy * mHeaderStrategy;
566  const KMail::HeaderStyle * mHeaderStyle;
567  bool mAutoDelete;
569  TQString mSaveAttachDir;
570  static const int delay;
571  TQTimer mUpdateReaderWinTimer;
572  TQTimer mResizeTimer;
573  TQTimer mDelayedMarkTimer;
574  TQTimer mHeaderRefreshTimer;
575  TQString mOverrideEncoding;
576  TQString mOldGlobalOverrideEncoding; // used to detect changes of the global override character encoding
577  bool mMsgDisplay;
578  bool mNoMDNsWhenEncrypted;
579  unsigned long mLastSerNum;
580 
581  KMail::CSSHelper * mCSSHelper;
582  bool mUseFixedFont;
583  bool mPrinting;
584  bool mShowColorbar;
585  //bool mShowCompleteMessage;
586  TQStringList mTempFiles;
587  TQStringList mTempDirs;
588  int mMimeTreeMode;
589  int mMimeTreeModeOverride;
590  bool mMimeTreeAtBottom;
591  TQValueList<int> mSplitterSizes;
592  partNode* mRootNode;
593  TQString mIdOfLastViewedMessage;
594  TQWidget *mMainWindow;
595  TDEActionCollection *mActionCollection;
596  TDEAction *mMailToComposeAction, *mMailToReplyAction, *mMailToForwardAction,
597  *mAddAddrBookAction, *mOpenAddrBookAction, *mCopyAction, *mCopyURLAction,
598  *mUrlOpenAction, *mUrlSaveAsAction, *mAddBookmarksAction, *mStartIMChatAction, *mSelectAllAction;
599  TDEToggleAction *mHeaderOnlyAttachmentsAction;
600  TDESelectAction *mSelectEncodingAction;
601  TDEToggleAction *mToggleFixFontAction;
602  TDEToggleAction *mToggleMimePartTreeAction;
603 
604  KURL mHoveredUrl;
605  KURL mClickedUrl;
606  TQPoint mLastClickPosition;
607  TQString mLastClickImagePath;
608  bool mCanStartDrag;
609 
610  KMail::HtmlWriter * mHtmlWriter;
611  std::map<TQCString,KMail::Interface::BodyPartMemento*> mBodyPartMementoMap;
612  // an attachment should be updated
613  bool mAtmUpdate;
614  int mChoice;
615  unsigned long mWaitingForSerNum;
616  float mSavedRelativePosition;
617  int mLevelQuote;
618  bool mDecrytMessageOverwrite;
619  bool mShowSignatureDetails;
620  bool mShowAttachmentQuicklist;
621  bool mShowRawToltecMail;
622  bool mExternalWindow;
623 };
624 
625 
626 #endif
627