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 KActionCollection;
32 class KAction;
33 class KActionMenu;
34 class KSelectAction;
35 class KRadioAction;
36 class KToggleAction;
37 class KConfigBase;
38 class KHTMLPart;
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  TQ_OBJECT
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  KActionCollection *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  KToggleAction *toggleFixFontAction() { return mToggleFixFontAction; }
248  KAction *mailToComposeAction() { return mMailToComposeAction; }
249  KAction *mailToReplyAction() { return mMailToReplyAction; }
250  KAction *mailToForwardAction() { return mMailToForwardAction; }
251  KAction *addAddrBookAction() { return mAddAddrBookAction; }
252  KAction *openAddrBookAction() { return mOpenAddrBookAction; }
253  KAction *copyAction() { return mCopyAction; }
254  KAction *selectAllAction() { return mSelectAllAction; }
255  KAction *copyURLAction() { return mCopyURLAction; }
256  KAction *urlOpenAction() { return mUrlOpenAction; }
257  KAction *urlSaveAsAction() { return mUrlSaveAsAction; }
258  KAction *addBookmarksAction() { return mAddBookmarksAction;}
259  KAction *startImChatAction() { return mStartIMChatAction; }
260  // This function returns the complete data that were in this
261  // message parts - *after* all encryption has been removed that
262  // could be removed.
263  // - This is used to store the message in decrypted form.
264  void objectTreeToDecryptedMsg( partNode* node,
265  NewByteArray& resultingData,
266  KMMessage& theMessage,
267  bool weAreReplacingTheRootNode = false,
268  int recCount = 0 );
269 
271  partNode* partNodeFromUrl(const KURL &url);
272 
273  partNode * partNodeForId( int id );
274 
275  KURL tempFileUrlFromPartNode( const partNode * node );
276 
278  static int msgPartFromUrl(const KURL &url);
279 
280  void setUpdateAttachment( bool update = true ) { mAtmUpdate = update; }
281 
284  KHTMLPart * htmlPart() const { return mViewer; }
285 
287  KMMessage* message(KMFolder** folder=0) const;
288 
289  void openAttachment( int id, const TQString & name );
290  void saveAttachment( const KURL &tempFileName );
291 
292  void emitUrlClicked( const KURL & url, int button ) {
293  emit urlClicked( url, button );
294  }
295 
296  void emitPopupMenu( const KURL & url, const TQPoint & p ) {
297  if ( message() )
298  emit popupMenu( *message(), url, p );
299  }
300 
301  void showAttachmentPopup( int id, const TQString & name, const TQPoint & p );
302 
305  void setWaitingForSerNum( unsigned long serNum ) { mWaitingForSerNum = serNum; }
306 
307  TQWidget* mainWindow() { return mMainWindow; }
308 
310  bool decryptMessage() const;
311 
313  void setDecryptMessageOverwrite( bool overwrite = true ) { mDecrytMessageOverwrite = overwrite; }
314 
316  bool showSignatureDetails() const { return mShowSignatureDetails; }
317 
319  void setShowSignatureDetails( bool showDetails = true ) { mShowSignatureDetails = showDetails; }
320 
321  /* show or hide the list that points to the attachments */
322  bool showAttachmentQuicklist() const { return mShowAttachmentQuicklist; }
323 
324  /* show or hide the list that points to the attachments */
325  void setShowAttachmentQuicklist( bool showAttachmentQuicklist = true ) { mShowAttachmentQuicklist = showAttachmentQuicklist; }
326 
327  // This controls whether a Toltec invitation is shown in its raw form or as a replacement text.
328  // This can be toggled with the "kmail:showRawToltecMail" link.
329  bool showRawToltecMail() const { return mShowRawToltecMail; }
330  void setShowRawToltecMail( bool showRawToltecMail ) { mShowRawToltecMail = showRawToltecMail; }
331 
332  /* retrieve BodyPartMemento of id \a which for partNode \a node */
333  KMail::Interface::BodyPartMemento * bodyPartMemento( const partNode * node, const TQCString & which ) const;
334 
335  /* set/replace BodyPartMemento \a memento of id \a which for
336  partNode \a node. If there was a BodyPartMemento registered
337  already, replaces (deletes) that one. */
338  void setBodyPartMemento( const partNode * node, const TQCString & which, KMail::Interface::BodyPartMemento * memento );
339 
341  void scrollToAttachment( const partNode *node );
342 
343 private:
344  /* deletes all BodyPartMementos. Use this when skipping to another
345  message (as opposed to re-loading the same one again). */
346  void clearBodyPartMementos();
347 
348 signals:
352 
354  void popupMenu(KMMessage &msg, const KURL &url, const TQPoint& mousePos);
355 
357  void urlClicked(const KURL &url, int button);
358 
360  void noDrag(void);
361 
362 public slots:
363 
365  void selectAll();
366 
368  void clearCache();
369 
371  void updateReaderWin();
372 
374  void slotScrollUp();
375  void slotScrollDown();
376  void slotScrollPrior();
377  void slotScrollNext();
378  void slotJumpDown();
379  void slotDocumentChanged();
380  void slotDocumentDone();
381  void slotTextSelected(bool);
382 
384  void slotUrlOpen(const KURL &url, const KParts::URLArgs &args);
385 
387  void slotUrlOn(const TQString &url);
388 
390  void slotUrlPopup(const TQString &, const TQPoint& mousePos);
391 
393  void slotFind();
395  void slotFindNext();
396 
398  void slotToggleFixedFont();
399 
401  void slotCopySelectedText();
402 
403  void slotUrlClicked();
404 
406  void slotMailtoReply();
407  void slotMailtoCompose();
408  void slotMailtoForward();
409  void slotMailtoAddAddrBook();
410  void slotMailtoOpenAddrBook();
413  void slotUrlCopy();
414  void slotUrlOpen( const KURL &url = KURL() );
416  void slotUrlSave();
417  void slotAddBookmarks();
418  void slotSaveMsg();
419  void slotSaveAttachments();
420 
421  void slotMessageArrived( KMMessage *msg );
423  void slotIMChat();
424  void contactStatusChanged( const TQString &uid);
425 
426  void slotLevelQuote( int l );
427  void slotTouchMessage();
428 
436  void fillCommandInfo( partNode *node, KMMessage **msg, int *nodeId );
437 
438  void slotDeleteAttachment( partNode* node );
439  void slotEditAttachment( partNode* node );
440 
441  KMail::CSSHelper* cssHelper();
442 
443 protected slots:
444  void slotCycleHeaderStyles();
445  void slotBriefHeaders();
446  void slotFancyHeaders();
447  void slotEnterpriseHeaders();
448  void slotStandardHeaders();
449  void slotLongHeaders();
450  void slotAllHeaders();
451 
452  void slotCycleAttachmentStrategy();
453  void slotIconicAttachments();
454  void slotSmartAttachments();
455  void slotInlineAttachments();
456  void slotHideAttachments();
457  void slotHeaderOnlyAttachments();
458 
460  void slotAtmView( int id, const TQString& name );
461  void slotDelayedResize();
462  void slotHandleAttachment( int );
463 
467  void disconnectMsgAdded();
468  void msgAdded( TQListViewItem *item );
469 
470 protected:
473  void styleChange( TQStyle& oldStyle );
474 
478 
480  virtual bool event(TQEvent *e);
481 
483  int pointsToPixel(int pointSize) const;
484 
487  void displayMessage();
488 
490  virtual void parseMsg( KMMessage* msg );
491 
494  TQString writeMsgHeader(KMMessage* aMsg, partNode *vCardNode = 0, bool topLevel=false );
495 
499  TQString writeMessagePartToTempFile( KMMessagePart* msgPart, int partNumber );
500 
506  TQString createTempDir( const TQString &param = TQString() );
507 
509  void showVCard(KMMessagePart *msgPart);
510 
512  virtual void initHtmlWidget(void);
513 
515  virtual void closeEvent(TQCloseEvent *);
516  virtual void resizeEvent(TQResizeEvent *);
517 
519  virtual void removeTempFiles();
520 
522  bool eventFilter( TQObject *obj, TQEvent *ev );
523 
524 private slots:
525  void slotSetEncoding();
526  void injectAttachments();
527 
528 private:
529  void adjustLayout();
530  void createWidgets();
531  void createActions( KActionCollection * ac );
532  void saveSplitterSizes( KConfigBase & c ) const;
533 
534  KRadioAction * actionForHeaderStyle( const KMail::HeaderStyle *,
535  const KMail::HeaderStrategy * );
536  KRadioAction * actionForAttachmentStrategy( const KMail::AttachmentStrategy * );
538  void readGlobalOverrideCodec();
539 
540  TQString renderAttachments( partNode *node, const TQColor &bgColor );
541 
542 private:
543  bool mHtmlMail, mHtmlLoadExternal, mHtmlOverride, mHtmlLoadExtOverride;
544  int mAtmCurrent;
545  TQString mAtmCurrentName;
546  KMMessage *mMessage;
547 
548  // See setOriginalMsg() for an explaination for those two.
549  unsigned long mSerNumOfOriginalMessage;
550  int mNodeIdOffset;
551 
552  // widgets:
553  TQSplitter * mSplitter;
554  TQHBox *mBox;
555  KMail::HtmlStatusBar *mColorBar;
556  KMMimePartTree* mMimePartTree;
557  KHTMLPart *mViewer;
558 
559  const KMail::AttachmentStrategy * mAttachmentStrategy;
560  const KMail::HeaderStrategy * mHeaderStrategy;
561  const KMail::HeaderStyle * mHeaderStyle;
562  bool mAutoDelete;
564  TQString mSaveAttachDir;
565  static const int delay;
566  TQTimer mUpdateReaderWinTimer;
567  TQTimer mResizeTimer;
568  TQTimer mDelayedMarkTimer;
569  TQString mOverrideEncoding;
570  TQString mOldGlobalOverrideEncoding; // used to detect changes of the global override character encoding
571  bool mMsgDisplay;
572  bool mNoMDNsWhenEncrypted;
573  unsigned long mLastSerNum;
574 
575  KMail::CSSHelper * mCSSHelper;
576  bool mUseFixedFont;
577  bool mPrinting;
578  bool mShowColorbar;
579  //bool mShowCompleteMessage;
580  TQStringList mTempFiles;
581  TQStringList mTempDirs;
582  int mMimeTreeMode;
583  bool mMimeTreeAtBottom;
584  TQValueList<int> mSplitterSizes;
585  partNode* mRootNode;
586  TQString mIdOfLastViewedMessage;
587  TQWidget *mMainWindow;
588  KActionCollection *mActionCollection;
589  KAction *mMailToComposeAction, *mMailToReplyAction, *mMailToForwardAction,
590  *mAddAddrBookAction, *mOpenAddrBookAction, *mCopyAction, *mCopyURLAction,
591  *mUrlOpenAction, *mUrlSaveAsAction, *mAddBookmarksAction, *mStartIMChatAction, *mSelectAllAction;
592  KToggleAction *mHeaderOnlyAttachmentsAction;
593  KSelectAction *mSelectEncodingAction;
594  KToggleAction *mToggleFixFontAction;
595 
596  KURL mHoveredUrl;
597  KURL mClickedUrl;
598  TQPoint mLastClickPosition;
599  TQString mLastClickImagePath;
600  bool mCanStartDrag;
601 
602  KMail::HtmlWriter * mHtmlWriter;
603  std::map<TQCString,KMail::Interface::BodyPartMemento*> mBodyPartMementoMap;
604  // an attachment should be updated
605  bool mAtmUpdate;
606  int mChoice;
607  unsigned long mWaitingForSerNum;
608  float mSavedRelativePosition;
609  int mLevelQuote;
610  bool mDecrytMessageOverwrite;
611  bool mShowSignatureDetails;
612  bool mShowAttachmentQuicklist;
613  bool mShowRawToltecMail;
614  bool mExternalWindow;
615 };
616 
617 
618 #endif
619