Backport r950340 | aacid | 2009-04-06 23:21:18 +0200 (Mon, 06 Apr 2009) | 4 lines
[kdepim.git] / kmail / kmreaderwin.h
blobcc349584f43d0182295aed0b7d652364339f3dde
1 /* -*- mode: C++; c-file-style: "gnu" -*-
2 This file is part of KMail, the KDE mail client.
3 Copyright (c) 1997 Markus Wuebben <markus.wuebben@kde.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #ifndef KMREADERWIN_H
21 #define KMREADERWIN_H
23 #include <QWidget>
24 #include <QTimer>
25 #include <QStringList>
26 #include <QCloseEvent>
27 #include <QEvent>
28 #include <QList>
29 #include <QResizeEvent>
30 #include <kurl.h>
31 #include <kservice.h>
32 #include <messagestatus.h>
33 #include <kvbox.h>
34 using KPIM::MessageStatus;
35 #include "kmmimeparttree.h" // Needed for friend declaration.
36 #include "interfaces/observer.h"
38 class QSplitter;
39 class KHBox;
40 class QTreeWidgetItem;
41 class QString;
42 class QTextCodec;
45 class KActionCollection;
46 class KAction;
47 class KSelectAction;
48 class KToggleAction;
49 class KToggleAction;
50 class KHTMLPart;
51 class KUrl;
53 class KMFolder;
54 class KMMessage;
55 class KMMessagePart;
56 namespace KMail {
57 namespace Interface {
58 class Observable;
60 class ObjectTreeParser;
61 class AttachmentStrategy;
62 class HeaderStrategy;
63 class HeaderStyle;
64 class HtmlWriter;
65 class KHtmlPartHtmlWriter;
66 class HtmlStatusBar;
67 class CSSHelper;
70 class partNode; // might be removed when KMime is used instead of mimelib
71 // (khz, 29.11.2001)
73 namespace KParts {
74 struct BrowserArguments;
75 class OpenUrlArguments;
78 /**
79 This class implements a "reader window", that is a window
80 used for reading or viewing messages.
83 class KMReaderWin: public QWidget, public KMail::Interface::Observer {
84 Q_OBJECT
86 friend void KMMimePartTree::slotItemClicked( QTreeWidgetItem* );
87 friend void KMMimePartTree::slotContextMenuRequested( const QPoint & );
88 friend void KMMimePartTree::slotSaveAs();
89 friend void KMMimePartTree::startDrag( Qt::DropActions actions );
91 friend class KMail::ObjectTreeParser;
92 friend class KMail::KHtmlPartHtmlWriter;
94 public:
95 KMReaderWin( QWidget *parent, QWidget *mainWindow,
96 KActionCollection *actionCollection, Qt::WindowFlags f = 0 );
97 virtual ~KMReaderWin();
99 /**
100 \reimp from Interface::Observer
101 Updates the current message
103 void update( KMail::Interface::Observable * );
105 /** Read settings from app's config file. */
106 void readConfig();
108 /** Write settings to app's config file. Calls sync() if withSync is true. */
109 void writeConfig( bool withSync=true ) const;
111 const KMail::HeaderStyle * headerStyle() const {
112 return mHeaderStyle;
114 /** Set the header style and strategy. We only want them to be set
115 together. */
116 void setHeaderStyleAndStrategy( const KMail::HeaderStyle * style,
117 const KMail::HeaderStrategy * strategy );
119 /** Getthe message header strategy. */
120 const KMail::HeaderStrategy * headerStrategy() const {
121 return mHeaderStrategy;
124 /** Get/set the message attachment strategy. */
125 const KMail::AttachmentStrategy * attachmentStrategy() const {
126 return mAttachmentStrategy;
128 void setAttachmentStrategy( const KMail::AttachmentStrategy * strategy );
130 /** Get selected override character encoding.
131 @return The encoding selected by the user or an empty string if auto-detection
132 is selected. */
133 QString overrideEncoding() const { return mOverrideEncoding; }
135 /** Set the override character encoding. */
136 void setOverrideEncoding( const QString & encoding );
138 void setPrintFont( const QFont& font );
140 /** Get codec corresponding to the currently selected override character encoding.
141 @return The override codec or 0 if auto-detection is selected. */
142 const QTextCodec * overrideCodec() const;
144 /** Set printing mode */
145 virtual void setPrinting(bool enable) { mPrinting = enable; }
147 /** Set the message that shall be shown. If msg is 0, an empty page is
148 displayed. */
149 virtual void setMsg(KMMessage* msg, bool force = false);
151 /** Instead of settings a message to be shown sets a message part
152 to be shown */
153 void setMsgPart( KMMessagePart* aMsgPart, bool aHTML,
154 const QString& aFileName, const QString& pname );
156 void setMsgPart( partNode * node );
158 /** Show or hide the Mime Tree Viewer if configuration
159 is set to smart mode. */
160 void showHideMimeTree( bool isPlainTextTopLevel );
162 /** Store message id of last viewed message,
163 normally no need to call this function directly,
164 since correct value is set automatically in
165 parseMsg(KMMessage* aMsg, bool onlyProcessHeaders). */
166 void setIdOfLastViewedMessage( const QString & msgId )
167 { mIdOfLastViewedMessage = msgId; }
169 /** Clear the reader and discard the current message. */
170 void clear(bool force = false) { setMsg(0, force); }
172 /** Saves the relative position of the scroll view. Call this before calling update()
173 if you want to preserve the current view. */
174 void saveRelativePosition();
176 /** Re-parse the current message. */
177 void update(bool force = false);
179 /** Print message. */
180 virtual void printMsg( KMMessage* aMsg );
182 /** Return selected text */
183 QString copyText();
185 /** Get/set auto-delete msg flag. */
186 bool autoDelete(void) const { return mAutoDelete; }
187 void setAutoDelete(bool f) { mAutoDelete=f; }
189 /** Override default html mail setting */
190 bool htmlOverride() const { return mHtmlOverride; }
191 void setHtmlOverride( bool override );
193 /** Override default load external references setting */
194 bool htmlLoadExtOverride() const { return mHtmlLoadExtOverride; }
195 void setHtmlLoadExtOverride( bool override );
197 /** Is html mail to be supported? Takes into account override */
198 bool htmlMail();
200 /** Is loading ext. references to be supported? Takes into account override */
201 bool htmlLoadExternal();
203 /** Returns the MD5 hash for the list of new features */
204 static QString newFeaturesMD5();
206 /** Display a generic HTML splash page instead of a message */
207 void displaySplashPage( const QString &info );
209 /** Display the about page instead of a message */
210 void displayAboutPage();
212 /** Display the 'please wait' page instead of a message */
213 void displayBusyPage();
214 /** Display the 'we are currently in offline mode' page instead of a message */
215 void displayOfflinePage();
217 /** Enable the displaying of messages again after an URL was displayed */
218 void enableMsgDisplay();
220 /** View message part of type message/RFC822 in extra viewer window. */
221 void atmViewMsg(KMMessagePart* msgPart);
223 bool atBottom() const;
225 bool isFixedFont() { return mUseFixedFont; }
226 void setUseFixedFont( bool useFixedFont ) { mUseFixedFont = useFixedFont; }
228 /** Return the HtmlWriter connected to the KHTMLPart we use */
229 KMail::HtmlWriter * htmlWriter() { return mHtmlWriter; }
231 // Action to reply to a message
232 // but action( "some_name" ) some name could be used instead.
233 KToggleAction *toggleFixFontAction() { return mToggleFixFontAction; }
234 KAction *mailToComposeAction() { return mMailToComposeAction; }
235 KAction *mailToReplyAction() { return mMailToReplyAction; }
236 KAction *mailToForwardAction() { return mMailToForwardAction; }
237 KAction *addAddrBookAction() { return mAddAddrBookAction; }
238 KAction *openAddrBookAction() { return mOpenAddrBookAction; }
239 KAction *copyAction() { return mCopyAction; }
240 KAction *selectAllAction() { return mSelectAllAction; }
241 KAction *copyURLAction() { return mCopyURLAction; }
242 KAction *urlOpenAction() { return mUrlOpenAction; }
243 KAction *urlSaveAsAction() { return mUrlSaveAsAction; }
244 KAction *addBookmarksAction() { return mAddBookmarksAction;}
245 // This function returns the complete data that were in this
246 // message parts - *after* all encryption has been removed that
247 // could be removed.
248 // - This is used to store the message in decrypted form.
249 void objectTreeToDecryptedMsg( partNode* node,
250 QByteArray& resultingData,
251 KMMessage& theMessage,
252 bool weAreReplacingTheRootNode = false,
253 int recCount = 0 );
255 /** Returns message part from given URL or null if invalid. */
256 partNode* partNodeFromUrl(const KUrl &url);
258 partNode * partNodeForId( int id );
260 KUrl tempFileUrlFromPartNode( const partNode *node );
262 /** Returns id of message part from given URL or -1 if invalid. */
263 static int msgPartFromUrl(const KUrl &url);
265 void setUpdateAttachment( bool update = true ) { mAtmUpdate = update; }
267 /** Access to the KHTMLPart used for the viewer. Use with
268 care! */
269 KHTMLPart * htmlPart() const { return mViewer; }
271 /** Returns the current message or 0 if none. */
272 KMMessage* message(KMFolder** folder=0) const;
274 void openAttachment( int id, const QString & name );
276 void emitUrlClicked( const KUrl & url, int button ) {
277 emit urlClicked( url, button );
280 void emitPopupMenu( const KUrl & url, const QPoint & p ) {
281 if ( message() )
282 emit popupMenu( *message(), url, p );
286 * Sets the current attachment ID and the current attachment temporary filename
287 * to the given values.
288 * Call this so that slotHandleAttachment() knows which attachment to handle.
290 void prepareHandleAttachment( int id, const QString& fileName );
292 void showAttachmentPopup( int id, const QString & name, const QPoint & p );
294 /** Set the serial number of the message this reader window is currently
295 * waiting for. Used to discard updates for already deselected messages. */
296 void setWaitingForSerNum( unsigned long serNum ) { mWaitingForSerNum = serNum; }
298 QWidget* mainWindow() { return mMainWindow; }
300 /** Returns whether the message should be decryted. */
301 bool decryptMessage() const;
303 /** Enforce message decryption. */
304 void setDecryptMessageOverwrite( bool overwrite = true ) { mDecrytMessageOverwrite = overwrite; }
306 /** Show signature details. */
307 bool showSignatureDetails() const { return mShowSignatureDetails; }
309 /** Show signature details. */
310 void setShowSignatureDetails( bool showDetails = true ) { mShowSignatureDetails = showDetails; }
312 KMail::CSSHelper* cssHelper() const;
314 /* show or hide the list that points to the attachments */
315 bool showAttachmentQuicklist() const { return mShowAttachmentQuicklist; }
317 /* show or hide the list that points to the attachments */
318 void setShowAttachmentQuicklist( bool showAttachmentQuicklist = true ) { mShowAttachmentQuicklist = showAttachmentQuicklist; }
320 signals:
321 /** Emitted after parsing of a message to have it stored
322 in unencrypted state in it's folder. */
323 void replaceMsgByUnencryptedVersion();
325 /** The user presses the right mouse button. 'url' may be 0. */
326 void popupMenu(KMMessage &msg, const KUrl &url, const QPoint& mousePos);
328 /** The user has clicked onto an URL that is no attachment. */
329 void urlClicked(const KUrl &url, int button);
331 /** Pgp displays a password dialog */
332 void noDrag(void);
334 public slots:
336 /** Select message body. */
337 void selectAll();
339 /** Force update even if message is the same */
340 void clearCache();
342 /** Refresh the reader window */
343 void updateReaderWin();
345 /** HTML Widget scrollbar and layout handling. */
346 void slotScrollUp();
347 void slotScrollDown();
348 void slotScrollPrior();
349 void slotScrollNext();
350 void slotJumpDown();
351 void slotDocumentChanged();
352 void slotDocumentDone();
353 void slotTextSelected(bool);
355 /** An URL has been activate with a click. */
356 void slotUrlOpen(const KUrl &url, const KParts::OpenUrlArguments &, const KParts::BrowserArguments &);
358 /** The mouse has moved on or off an URL. */
359 void slotUrlOn(const QString &url);
361 /** The user presses the right mouse button on an URL. */
362 void slotUrlPopup(const QString &, const QPoint& mousePos);
364 /** The user selected "Find" from the menu. */
365 void slotFind();
367 /** The user toggled the "Fixed Font" flag from the view menu. */
368 void slotToggleFixedFont();
370 /** Copy the selected text to the clipboard */
371 void slotCopySelectedText();
373 void slotUrlClicked();
375 /** Operations on mailto: URLs. */
376 void slotMailtoReply();
377 void slotMailtoCompose();
378 void slotMailtoForward();
379 void slotMailtoAddAddrBook();
380 void slotMailtoOpenAddrBook();
381 /** Copy URL in mUrlCurrent to clipboard. Removes "mailto:" at
382 beginning of URL before copying. */
383 void slotUrlCopy();
384 void slotUrlOpen( const KUrl &url = KUrl() );
385 /** Save the page to a file */
386 void slotUrlSave();
387 void slotAddBookmarks();
388 void slotSaveMsg();
389 void slotSaveAttachments();
391 void slotMessageArrived( KMMessage *msg );
393 void slotLevelQuote( int l );
394 void slotTouchMessage();
396 void slotDeleteAttachment( partNode* node );
397 void slotEditAttachment( partNode* node );
400 * Does an action for the current attachment.
401 * The action is defined by the KMHandleAttachmentCommand::AttachmentAction
402 * enum.
403 * prepareHandleAttachment() needs to be called before calling this to set the
404 * correct attachment ID.
406 void slotHandleAttachment( int action );
408 protected slots:
409 void slotCycleHeaderStyles();
410 void slotBriefHeaders();
411 void slotFancyHeaders();
412 void slotEnterpriseHeaders();
413 void slotStandardHeaders();
414 void slotLongHeaders();
415 void slotAllHeaders();
417 void slotCycleAttachmentStrategy();
418 void slotIconicAttachments();
419 void slotSmartAttachments();
420 void slotInlineAttachments();
421 void slotHideAttachments();
423 /** Some attachment operations. */
424 void slotAtmView( int id, const QString& name );
425 void slotDelayedResize();
427 /** Print message. Called on as a response of finished() signal of mPartHtmlWriter
428 after rendering is finished.
429 In the very end it deletes the KMReaderWin window that was created
430 for the purpose of rendering. */
431 void slotPrintMsg();
433 protected:
434 /** reimplemented in order to update the frame width in case of a changed
435 GUI style */
436 void styleChange( QStyle& oldStyle );
438 /** Set the width of the frame to a reasonable value for the current GUI
439 style */
440 void setStyleDependantFrameWidth();
442 /** Watch for palette changes */
443 virtual bool event(QEvent *e);
445 /** Calculate the pixel size */
446 int pointsToPixel(int pointSize) const;
448 /** Feeds the HTML viewer with the contents of the given message.
449 HTML begin/end parts are written around the message. */
450 void displayMessage();
452 /** Parse given message and add it's contents to the reader window. */
453 virtual void parseMsg( KMMessage* msg );
455 /** Creates a nice mail header depending on the current selected
456 header style. */
457 QString writeMsgHeader( KMMessage* aMsg, bool hasVCard = false, bool topLevel = false );
459 /** Writes the given message part to a temporary file and returns the
460 name of this file or QString() if writing failed.
462 QString writeMessagePartToTempFile( KMMessagePart* msgPart, int partNumber );
465 Creates a temporary dir for saving attachments, etc.
466 Will be automatically deleted when another message is viewed.
467 @param param Optional part of the directory name.
469 QString createTempDir( const QString &param = QString() );
471 /** show window containing infos about a vCard. */
472 void showVCard(KMMessagePart *msgPart);
474 /** HTML initialization. */
475 virtual void initHtmlWidget(void);
477 /** Some necessary event handling. */
478 virtual void closeEvent(QCloseEvent *);
479 virtual void resizeEvent(QResizeEvent *);
481 /** Cleanup the attachment temp files */
482 virtual void removeTempFiles();
484 /** Event filter */
485 bool eventFilter( QObject *obj, QEvent *ev );
487 private slots:
488 void slotSetEncoding();
489 void injectAttachments();
491 private:
492 void adjustLayout();
493 void createWidgets();
494 void createActions();
495 void saveSplitterSizes( KConfigGroup & c ) const;
497 KToggleAction * actionForHeaderStyle( const KMail::HeaderStyle *,
498 const KMail::HeaderStrategy * );
499 KToggleAction * actionForAttachmentStrategy( const KMail::AttachmentStrategy * );
500 /** Read override codec from configuration */
501 void readGlobalOverrideCodec();
503 QString renderAttachments( partNode *node, const QColor &bgColor );
505 private:
506 bool mHtmlMail, mHtmlLoadExternal, mHtmlOverride, mHtmlLoadExtOverride;
507 int mAtmCurrent;
508 QString mAtmCurrentName;
509 KMMessage *mMessage;
510 // widgets:
511 QSplitter * mSplitter;
512 KHBox *mBox;
513 KMail::HtmlStatusBar *mColorBar;
514 KMMimePartTree* mMimePartTree;
515 KHTMLPart *mViewer;
517 const KMail::AttachmentStrategy * mAttachmentStrategy;
518 const KMail::HeaderStrategy * mHeaderStrategy;
519 const KMail::HeaderStyle * mHeaderStyle;
520 bool mAutoDelete;
521 /** where did the user save the attachment last time */
522 QString mSaveAttachDir;
523 static const int delay;
524 QTimer mUpdateReaderWinTimer;
525 QTimer mResizeTimer;
526 QTimer mDelayedMarkTimer;
527 QString mOverrideEncoding;
528 QString mOldGlobalOverrideEncoding; // used to detect changes of the global override character encoding
529 bool mMsgDisplay;
530 bool mNoMDNsWhenEncrypted;
531 unsigned long mLastSerNum;
532 MessageStatus mLastStatus;
534 KMail::CSSHelper * mCSSHelper;
535 bool mUseFixedFont;
536 bool mPrinting;
537 bool mShowColorbar;
538 //bool mShowCompleteMessage;
539 QStringList mTempFiles;
540 QStringList mTempDirs;
541 int mMimeTreeMode;
542 bool mMimeTreeAtBottom;
543 QList<int> mSplitterSizes;
544 partNode* mRootNode;
545 QString mIdOfLastViewedMessage;
546 QWidget *mMainWindow;
547 KActionCollection *mActionCollection;
548 KAction *mMailToComposeAction, *mMailToReplyAction, *mMailToForwardAction,
549 *mAddAddrBookAction, *mOpenAddrBookAction, *mCopyAction, *mCopyURLAction,
550 *mUrlOpenAction, *mUrlSaveAsAction, *mAddBookmarksAction, *mSelectAllAction,
551 *mScrollUpAction, *mScrollDownAction, *mScrollUpMoreAction, *mScrollDownMoreAction;
552 KSelectAction *mSelectEncodingAction;
553 KToggleAction *mToggleFixFontAction;
554 KUrl mUrlClicked;
555 KMail::HtmlWriter * mHtmlWriter;
556 /** Used only to be able to connect and disconnect finished() signal
557 in printMsg() and slotPrintMsg() since mHtmlWriter points only to abstract non-QObject class. */
558 QPointer<KMail::KHtmlPartHtmlWriter> mPartHtmlWriter;
560 // an attachment should be updated
561 bool mAtmUpdate;
562 int mChoice;
563 unsigned long mWaitingForSerNum;
564 float mSavedRelativePosition;
565 int mLevelQuote;
566 bool mDecrytMessageOverwrite;
567 bool mShowSignatureDetails;
568 bool mShowAttachmentQuicklist;
572 #endif