kmail

kmreaderwin.h
1 // Header for kmreaderwin the kmail reader
2 // written by Markus Wuebben <markus.wuebben@kde.org>
3 
4 #ifndef KMREADERWIN_H
5 #define KMREADERWIN_H
6 
7 #include <tqwidget.h>
8 #include <tqtimer.h>
9 #include <tqstringlist.h>
10 #include <kurl.h>
11 #include <kservice.h>
12 #include "kmmsgbase.h"
13 #include "kmmimeparttree.h" // Needed for friend declaration.
14 #include "interfaces/observer.h"
15 
16 #include <map>
17 
18 class TQFrame;
19 class TQSplitter;
20 class TQHBox;
21 class TQListViewItem;
22 class TQScrollBar;
23 class TQString;
24 class TQTabDialog;
25 class TQTextCodec;
26 
27 class DwHeaders;
28 class DwMediaType;
29 
30 class TDEActionCollection;
31 class TDEAction;
32 class TDEActionMenu;
33 class TDESelectAction;
34 class TDERadioAction;
35 class TDEToggleAction;
36 class TDEConfigBase;
37 class TDEHTMLPart;
38 class KURL;
39 
40 class KMFolder;
41 class KMMessage;
42 class KMMessagePart;
43 namespace KMail {
44  namespace Interface {
45  class Observable;
46  class BodyPartMemento;
47  }
48  class PartMetaData;
49  class ObjectTreeParser;
50  class AttachmentStrategy;
51  class HeaderStrategy;
52  class HeaderStyle;
53  class HtmlWriter;
54  class KHtmlPartHtmlWriter;
55  class ISubject;
56  class HtmlStatusBar;
57  class FolderJob;
58  class CSSHelper;
59 }
60 
61 class partNode; // might be removed when KMime is used instead of mimelib
62  // (khz, 29.11.2001)
63 
64 class NewByteArray; // providing operator+ on a TQByteArray (khz, 21.06.2002)
65 
66 namespace KParts {
67  struct URLArgs;
68 }
69 
75 class KMReaderWin: public TQWidget, public KMail::Interface::Observer {
76  Q_OBJECT
77 
78 
79  friend void KMMimePartTree::itemClicked( TQListViewItem* item );
80  friend void KMMimePartTree::itemRightClicked( TQListViewItem* item, const TQPoint & );
81  friend void KMMimePartTree::slotSaveAs();
82  friend void KMMimePartTree::startDrag();
83 
84  friend class KMail::ObjectTreeParser;
85  friend class KMail::KHtmlPartHtmlWriter;
86 
87 public:
88  KMReaderWin( TQWidget *parent,
89  TQWidget *mainWindow,
90  TDEActionCollection *actionCollection,
91  const char *name=0,
92  int f=0 );
93  virtual ~KMReaderWin();
94 
100 
102  void readConfig();
103 
105  void writeConfig( bool withSync=true ) const;
106 
107  const KMail::HeaderStyle * headerStyle() const {
108  return mHeaderStyle;
109  }
112  void setHeaderStyleAndStrategy( const KMail::HeaderStyle * style,
113  const KMail::HeaderStrategy * strategy );
114 
116  const KMail::HeaderStrategy * headerStrategy() const {
117  return mHeaderStrategy;
118  }
119 
121  const KMail::AttachmentStrategy * attachmentStrategy() const {
122  return mAttachmentStrategy;
123  }
124  void setAttachmentStrategy( const KMail::AttachmentStrategy * strategy );
125 
129  TQString overrideEncoding() const { return mOverrideEncoding; }
130 
132  void setOverrideEncoding( const TQString & encoding );
133 
134  void setPrintFont( const TQFont& font );
135 
138  const TQTextCodec * overrideCodec() const;
139 
141  virtual void setPrinting(bool enable) { mPrinting = enable; }
142 
145  virtual void setMsg( KMMessage* msg, bool force = false, bool updateOnly = false );
146 
158  void setOriginalMsg( unsigned long serNumOfOriginalMessage, int nodeIdOffset );
159 
162  void setMsgPart( KMMessagePart* aMsgPart, bool aHTML,
163  const TQString& aFileName, const TQString& pname );
164 
165  void setMsgPart( partNode * node );
166 
169  void showHideMimeTree( bool isPlainTextTopLevel );
170 
175  void setIdOfLastViewedMessage( const TQString & msgId )
176  { mIdOfLastViewedMessage = msgId; }
177 
179  void clear(bool force = false) { setMsg(0, force); }
180 
183  void saveRelativePosition();
184 
186  void update(bool force = false);
187 
189  virtual void printMsg(void);
190 
192  TQString copyText();
193 
195  bool autoDelete(void) const { return mAutoDelete; }
196  void setAutoDelete(bool f) { mAutoDelete=f; }
197 
199  bool htmlOverride() const { return mHtmlOverride; }
200  void setHtmlOverride( bool override );
201 
203  bool htmlLoadExtOverride() const { return mHtmlLoadExtOverride; }
204  void setHtmlLoadExtOverride( bool override );
205 
207  bool htmlMail();
208 
210  bool htmlLoadExternal();
211 
213  static TQString newFeaturesMD5();
214 
216  void displaySplashPage( const TQString &info );
217 
219  void displayAboutPage();
220 
222  void displayBusyPage();
224  void displayOfflinePage();
225 
227  void enableMsgDisplay();
228 
234  void atmViewMsg( KMMessagePart* msgPart, int nodeId );
235 
236  bool atBottom() const;
237 
238  bool isFixedFont() { return mUseFixedFont; }
239  void setUseFixedFont( bool useFixedFont ) { mUseFixedFont = useFixedFont; }
240 
242  KMail::HtmlWriter * htmlWriter() { return mHtmlWriter; }
243 
244  // Action to reply to a message
245  // but action( "some_name" ) some name could be used instead.
246  TDEToggleAction *toggleFixFontAction() { return mToggleFixFontAction; }
247  TDEAction *mailToComposeAction() { return mMailToComposeAction; }
248  TDEAction *mailToReplyAction() { return mMailToReplyAction; }
249  TDEAction *mailToForwardAction() { return mMailToForwardAction; }
250  TDEAction *addAddrBookAction() { return mAddAddrBookAction; }
251  TDEAction *openAddrBookAction() { return mOpenAddrBookAction; }
252  TDEAction *copyAction() { return mCopyAction; }
253  TDEAction *selectAllAction() { return mSelectAllAction; }
254  TDEAction *copyURLAction() { return mCopyURLAction; }
255  TDEAction *urlOpenAction() { return mUrlOpenAction; }
256  TDEAction *urlSaveAsAction() { return mUrlSaveAsAction; }
257  TDEAction *addBookmarksAction() { return mAddBookmarksAction;}
258  TDEAction *startImChatAction() { return mStartIMChatAction; }
259  // This function returns the complete data that were in this
260  // message parts - *after* all encryption has been removed that
261  // could be removed.
262  // - This is used to store the message in decrypted form.
263  void objectTreeToDecryptedMsg( partNode* node,
264  NewByteArray& resultingData,
265  KMMessage& theMessage,
266  bool weAreReplacingTheRootNode = false,
267  int recCount = 0 );
268 
270  partNode* partNodeFromUrl(const KURL &url);
271 
272  partNode * partNodeForId( int id );
273 
274  KURL tempFileUrlFromPartNode( const partNode * node );
275 
277  static int msgPartFromUrl(const KURL &url);
278 
279  void setUpdateAttachment( bool update = true ) { mAtmUpdate = update; }
280 
283  TDEHTMLPart * htmlPart() const { return mViewer; }
284 
286  KMMessage* message(KMFolder** folder=0) const;
287 
288  void openAttachment( int id, const TQString & name );
289  void saveAttachment( const KURL &tempFileName );
290 
291  void emitUrlClicked( const KURL & url, int button ) {
292  emit urlClicked( url, button );
293  }
294 
295  void emitPopupMenu( const KURL & url, const TQPoint & p ) {
296  if ( message() )
297  emit popupMenu( *message(), url, p );
298  }
299 
300  void showAttachmentPopup( int id, const TQString & name, const TQPoint & p );
301 
304  void setWaitingForSerNum( unsigned long serNum ) { mWaitingForSerNum = serNum; }
305 
306  TQWidget* mainWindow() { return mMainWindow; }
307 
309  bool decryptMessage() const;
310 
312  void setDecryptMessageOverwrite( bool overwrite = true ) { mDecrytMessageOverwrite = overwrite; }
313 
315  bool showSignatureDetails() const { return mShowSignatureDetails; }
316 
318  void setShowSignatureDetails( bool showDetails = true ) { mShowSignatureDetails = showDetails; }
319 
320  /* show or hide the list that points to the attachments */
321  bool showAttachmentQuicklist() const { return mShowAttachmentQuicklist; }
322 
323  /* show or hide the list that points to the attachments */
324  void setShowAttachmentQuicklist( bool showAttachmentQuicklist = true ) { mShowAttachmentQuicklist = showAttachmentQuicklist; }
325 
326  // This controls whether a Toltec invitation is shown in its raw form or as a replacement text.
327  // This can be toggled with the "kmail:showRawToltecMail" link.
328  bool showRawToltecMail() const { return mShowRawToltecMail; }
329  void setShowRawToltecMail( bool showRawToltecMail ) { mShowRawToltecMail = showRawToltecMail; }
330 
331  /* retrieve BodyPartMemento of id \a which for partNode \a node */
332  KMail::Interface::BodyPartMemento * bodyPartMemento( const partNode * node, const TQCString & which ) const;
333 
334  /* set/replace BodyPartMemento \a memento of id \a which for
335  partNode \a node. If there was a BodyPartMemento registered
336  already, replaces (deletes) that one. */
337  void setBodyPartMemento( const partNode * node, const TQCString & which, KMail::Interface::BodyPartMemento * memento );
338 
340  void scrollToAttachment( const partNode *node );
341 
342 private:
343  /* deletes all BodyPartMementos. Use this when skipping to another
344  message (as opposed to re-loading the same one again). */
345  void clearBodyPartMementos();
346 
347 signals:
351 
353  void popupMenu(KMMessage &msg, const KURL &url, const TQPoint& mousePos);
354 
356  void urlClicked(const KURL &url, int button);
357 
359  void noDrag(void);
360 
361 public slots:
362 
364  void selectAll();
365 
367  void clearCache();
368 
370  void updateReaderWin();
371 
373  void slotScrollUp();
374  void slotScrollDown();
375  void slotScrollPrior();
376  void slotScrollNext();
377  void slotJumpDown();
378  void slotDocumentChanged();
379  void slotDocumentDone();
380  void slotTextSelected(bool);
381  void updateHeader();
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( TDEActionCollection * ac );
532  void saveSplitterSizes( TDEConfigBase & c ) const;
533 
534  TDERadioAction * actionForHeaderStyle( const KMail::HeaderStyle *,
535  const KMail::HeaderStrategy * );
536  TDERadioAction * 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  TDEHTMLPart *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  TQTimer mHeaderRefreshTimer;
570  TQString mOverrideEncoding;
571  TQString mOldGlobalOverrideEncoding; // used to detect changes of the global override character encoding
572  bool mMsgDisplay;
573  bool mNoMDNsWhenEncrypted;
574  unsigned long mLastSerNum;
575 
576  KMail::CSSHelper * mCSSHelper;
577  bool mUseFixedFont;
578  bool mPrinting;
579  bool mShowColorbar;
580  //bool mShowCompleteMessage;
581  TQStringList mTempFiles;
582  TQStringList mTempDirs;
583  int mMimeTreeMode;
584  bool mMimeTreeAtBottom;
585  TQValueList<int> mSplitterSizes;
586  partNode* mRootNode;
587  TQString mIdOfLastViewedMessage;
588  TQWidget *mMainWindow;
589  TDEActionCollection *mActionCollection;
590  TDEAction *mMailToComposeAction, *mMailToReplyAction, *mMailToForwardAction,
591  *mAddAddrBookAction, *mOpenAddrBookAction, *mCopyAction, *mCopyURLAction,
592  *mUrlOpenAction, *mUrlSaveAsAction, *mAddBookmarksAction, *mStartIMChatAction, *mSelectAllAction;
593  TDEToggleAction *mHeaderOnlyAttachmentsAction;
594  TDESelectAction *mSelectEncodingAction;
595  TDEToggleAction *mToggleFixFontAction;
596 
597  KURL mHoveredUrl;
598  KURL mClickedUrl;
599  TQPoint mLastClickPosition;
600  TQString mLastClickImagePath;
601  bool mCanStartDrag;
602 
603  KMail::HtmlWriter * mHtmlWriter;
604  std::map<TQCString,KMail::Interface::BodyPartMemento*> mBodyPartMementoMap;
605  // an attachment should be updated
606  bool mAtmUpdate;
607  int mChoice;
608  unsigned long mWaitingForSerNum;
609  float mSavedRelativePosition;
610  int mLevelQuote;
611  bool mDecrytMessageOverwrite;
612  bool mShowSignatureDetails;
613  bool mShowAttachmentQuicklist;
614  bool mShowRawToltecMail;
615  bool mExternalWindow;
616 };
617 
618 
619 #endif
620