kmail

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 <qwidget.h>
00009 #include <qtimer.h>
00010 #include <qstringlist.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 class QFrame;
00018 class QSplitter;
00019 class QHBox;
00020 class QListViewItem;
00021 class QScrollBar;
00022 class QString;
00023 class QTabDialog;
00024 class QTextCodec;
00025 
00026 class DwHeaders;
00027 class DwMediaType;
00028 
00029 class KActionCollection;
00030 class KAction;
00031 class KActionMenu;
00032 class KSelectAction;
00033 class KRadioAction;
00034 class KToggleAction;
00035 class KConfigBase;
00036 class KHTMLPart;
00037 class KURL;
00038 
00039 class KMFolder;
00040 class KMMessage;
00041 class KMMessagePart;
00042 namespace KMail {
00043   namespace Interface {
00044     class Observable;
00045   }
00046   class PartMetaData;
00047   class ObjectTreeParser;
00048   class AttachmentStrategy;
00049   class HeaderStrategy;
00050   class HeaderStyle;
00051   class HtmlWriter;
00052   class KHtmlPartHtmlWriter;
00053   class ISubject;
00054   class HtmlStatusBar;
00055   class FolderJob;
00056   class CSSHelper;
00057 }
00058 
00059 class partNode; // might be removed when KMime is used instead of mimelib
00060                 //                                      (khz, 29.11.2001)
00061 
00062 class NewByteArray; // providing operator+ on a QByteArray (khz, 21.06.2002)
00063 
00064 namespace KParts {
00065   struct URLArgs;
00066 }
00067 
00073 class KMReaderWin: public QWidget, public KMail::Interface::Observer {
00074   Q_OBJECT
00075 
00076   friend void KMMimePartTree::itemClicked( QListViewItem* item );
00077   friend void KMMimePartTree::itemRightClicked( QListViewItem* item, const QPoint & );
00078   friend void KMMimePartTree::slotSaveAs();
00079   friend void KMMimePartTree::startDrag();
00080 
00081   friend class KMail::ObjectTreeParser;
00082   friend class KMail::KHtmlPartHtmlWriter;
00083 
00084 public:
00085   KMReaderWin( QWidget *parent,
00086            QWidget *mainWindow,
00087            KActionCollection *actionCollection,
00088                const char *name=0,
00089            int f=0 );
00090   virtual ~KMReaderWin();
00091 
00096   void update( KMail::Interface::Observable * );
00097 
00099   void readConfig();
00100 
00102   void writeConfig( bool withSync=true ) const;
00103 
00104   const KMail::HeaderStyle * headerStyle() const {
00105     return mHeaderStyle;
00106   }
00109   void setHeaderStyleAndStrategy( const KMail::HeaderStyle * style,
00110                   const KMail::HeaderStrategy * strategy );
00111 
00113   const KMail::HeaderStrategy * headerStrategy() const {
00114     return mHeaderStrategy;
00115   }
00116 
00118   const KMail::AttachmentStrategy * attachmentStrategy() const {
00119     return mAttachmentStrategy;
00120   }
00121   void setAttachmentStrategy( const KMail::AttachmentStrategy * strategy );
00122 
00126   QString overrideEncoding() const { return mOverrideEncoding; }
00127 
00129   void setOverrideEncoding( const QString & encoding );
00130 
00131   void setPrintFont( const QFont& font );
00132 
00135   const QTextCodec * overrideCodec() const;
00136 
00138   virtual void setPrinting(bool enable) { mPrinting = enable; }
00139 
00142   virtual void setMsg(KMMessage* msg, bool force = false);
00143 
00146   void setMsgPart( KMMessagePart* aMsgPart, bool aHTML,
00147            const QString& aFileName, const QString& pname );
00148 
00149   void setMsgPart( partNode * node );
00150 
00153   void showHideMimeTree( bool isPlainTextTopLevel );
00154 
00159   void setIdOfLastViewedMessage( const QString & msgId )
00160     { mIdOfLastViewedMessage = msgId; }
00161 
00163   void clear(bool force = false) { setMsg(0, force); }
00164 
00166   void update(bool force = false);
00167 
00169   virtual void printMsg(void);
00170 
00172   QString copyText();
00173 
00175   bool autoDelete(void) const { return mAutoDelete; }
00176   void setAutoDelete(bool f) { mAutoDelete=f; }
00177 
00179   bool htmlOverride() const { return mHtmlOverride; }
00180   void setHtmlOverride( bool override );
00181 
00183   bool htmlLoadExtOverride() const { return mHtmlLoadExtOverride; }
00184   void setHtmlLoadExtOverride( bool override );
00185 
00187   bool htmlMail();
00188 
00190   bool htmlLoadExternal();
00191 
00193   static QString newFeaturesMD5();
00194 
00196   void displaySplashPage( const QString &info );
00197 
00199   void displayAboutPage();
00200 
00202   void displayBusyPage();
00204   void displayOfflinePage();
00205 
00207   void enableMsgDisplay();
00208 
00210   void atmViewMsg(KMMessagePart* msgPart);
00211 
00212   bool atBottom() const;
00213 
00214   bool isFixedFont() { return mUseFixedFont; }
00215   void setUseFixedFont( bool useFixedFont ) { mUseFixedFont = useFixedFont; }
00216 
00218   KMail::HtmlWriter * htmlWriter() { return mHtmlWriter; }
00219 
00220   // Action to reply to a message
00221   // but action( "some_name" ) some name could be used instead.
00222   KToggleAction *toggleFixFontAction() { return mToggleFixFontAction; }
00223   KAction *mailToComposeAction() { return mMailToComposeAction; }
00224   KAction *mailToReplyAction() { return mMailToReplyAction; }
00225   KAction *mailToForwardAction() { return mMailToForwardAction; }
00226   KAction *addAddrBookAction() { return mAddAddrBookAction; }
00227   KAction *openAddrBookAction() { return mOpenAddrBookAction; }
00228   KAction *copyAction() { return mCopyAction; }
00229   KAction *selectAllAction() { return mSelectAllAction; }
00230   KAction *copyURLAction() { return mCopyURLAction; }
00231   KAction *urlOpenAction() { return mUrlOpenAction; }
00232   KAction *urlSaveAsAction() { return mUrlSaveAsAction; }
00233   KAction *addBookmarksAction() { return mAddBookmarksAction;}
00234   KAction *startImChatAction() { return mStartIMChatAction; }
00235   // This function returns the complete data that were in this
00236   // message parts - *after* all encryption has been removed that
00237   // could be removed.
00238   // - This is used to store the message in decrypted form.
00239   void objectTreeToDecryptedMsg( partNode* node,
00240                                  NewByteArray& resultingData,
00241                                  KMMessage& theMessage,
00242                                  bool weAreReplacingTheRootNode = false,
00243                                  int recCount = 0 );
00244 
00246   partNode* partNodeFromUrl(const KURL &url);
00247 
00248   partNode * partNodeForId( int id );
00249 
00250   KURL tempFileUrlFromPartNode( const partNode * node );
00251 
00253   static int msgPartFromUrl(const KURL &url);
00254 
00255   void setUpdateAttachment( bool update = true ) { mAtmUpdate = update; }
00256 
00259   KHTMLPart * htmlPart() const { return mViewer; }
00260 
00262   KMMessage* message(KMFolder** folder=0) const;
00263 
00264   void openAttachment( int id, const QString & name );
00265 
00266   void emitUrlClicked( const KURL & url, int button ) {
00267     emit urlClicked( url, button );
00268   }
00269 
00270   void emitPopupMenu( const KURL & url, const QPoint & p ) {
00271     if ( message() )
00272       emit popupMenu( *message(), url, p );
00273   }
00274 
00275   void showAttachmentPopup( int id, const QString & name, const QPoint & p );
00276 
00279   void setWaitingForSerNum( unsigned long serNum ) { mWaitingForSerNum = serNum; }
00280 
00281   QWidget* mainWindow() { return mMainWindow; }
00282 
00284   bool decryptMessage() const;
00285 
00287   void setDecryptMessageOverwrite( bool overwrite = true ) { mDecrytMessageOverwrite = overwrite; }
00288 
00290   bool showSignatureDetails() const { return mShowSignatureDetails; }
00291 
00293   void setShowSignatureDetails( bool showDetails = true ) { mShowSignatureDetails = showDetails; }
00294 
00295 signals:
00298   void replaceMsgByUnencryptedVersion();
00299 
00301   void popupMenu(KMMessage &msg, const KURL &url, const QPoint& mousePos);
00302 
00304   void urlClicked(const KURL &url, int button);
00305 
00307   void noDrag(void);
00308 
00309 public slots:
00310 
00312   void selectAll();
00313 
00315   void clearCache();
00316 
00318   void updateReaderWin();
00319 
00321   void slotScrollUp();
00322   void slotScrollDown();
00323   void slotScrollPrior();
00324   void slotScrollNext();
00325   void slotJumpDown();
00326   void slotDocumentChanged();
00327   void slotDocumentDone();
00328   void slotTextSelected(bool);
00329 
00331   void slotUrlOpen(const KURL &url, const KParts::URLArgs &args);
00332 
00334   void slotUrlOn(const QString &url);
00335 
00337   void slotUrlPopup(const QString &, const QPoint& mousePos);
00338 
00340   void slotFind();
00342   void slotFindNext();
00343 
00345   void slotToggleFixedFont();
00346 
00348   void slotCopySelectedText();
00349 
00350    void slotUrlClicked();
00351 
00353   void slotMailtoReply();
00354   void slotMailtoCompose();
00355   void slotMailtoForward();
00356   void slotMailtoAddAddrBook();
00357   void slotMailtoOpenAddrBook();
00360   void slotUrlCopy();
00361   void slotUrlOpen( const KURL &url = KURL() );
00363   void slotUrlSave();
00364   void slotAddBookmarks();
00365   void slotSaveMsg();
00366   void slotSaveAttachments();
00367 
00368   void slotMessageArrived( KMMessage *msg );
00370   void slotIMChat();
00371   void contactStatusChanged( const QString &uid);
00372 
00373   void slotLevelQuote( int l );
00374   void slotTouchMessage();
00375 
00376   void slotDeleteAttachment( partNode* node );
00377   void slotEditAttachment( partNode* node );
00378 
00379   KMail::CSSHelper* cssHelper();
00380 
00381 protected slots:
00382   void slotCycleHeaderStyles();
00383   void slotBriefHeaders();
00384   void slotFancyHeaders();
00385   void slotEnterpriseHeaders();
00386   void slotStandardHeaders();
00387   void slotLongHeaders();
00388   void slotAllHeaders();
00389 
00390   void slotCycleAttachmentStrategy();
00391   void slotIconicAttachments();
00392   void slotSmartAttachments();
00393   void slotInlineAttachments();
00394   void slotHideAttachments();
00395 
00397   void slotAtmView( int id, const QString& name );
00398   void slotDelayedResize();
00399   void slotHandleAttachment( int );
00400 
00401 protected:
00404   void styleChange( QStyle& oldStyle );
00405 
00408   void setStyleDependantFrameWidth();
00409 
00411   virtual bool event(QEvent *e);
00412 
00414   int pointsToPixel(int pointSize) const;
00415 
00418   void displayMessage();
00419 
00421   virtual void parseMsg( KMMessage* msg  );
00422 
00425   QString writeMsgHeader(KMMessage* aMsg, bool hasVCard=false, bool topLevel=false);
00426 
00430   QString writeMessagePartToTempFile( KMMessagePart* msgPart, int partNumber );
00431 
00437   QString createTempDir( const QString &param = QString() );
00438 
00440   void showVCard(KMMessagePart *msgPart);
00441 
00443   virtual void initHtmlWidget(void);
00444 
00446   virtual void closeEvent(QCloseEvent *);
00447   virtual void resizeEvent(QResizeEvent *);
00448 
00450   virtual void removeTempFiles();
00451 
00453   bool eventFilter( QObject *obj, QEvent *ev );
00454 
00455 private slots:
00456   void slotSetEncoding();
00457   void injectAttachments();
00458 
00459 private:
00460   void adjustLayout();
00461   void createWidgets();
00462   void createActions( KActionCollection * ac );
00463   void saveSplitterSizes( KConfigBase & c ) const;
00464 
00465   KRadioAction * actionForHeaderStyle( const KMail::HeaderStyle *,
00466                                        const KMail::HeaderStrategy * );
00467   KRadioAction * actionForAttachmentStrategy( const KMail::AttachmentStrategy * );
00469   void readGlobalOverrideCodec();
00470 
00471   QString renderAttachments( partNode *node, const QColor &bgColor );
00472 
00473 private:
00474   bool mHtmlMail, mHtmlLoadExternal, mHtmlOverride, mHtmlLoadExtOverride;
00475   int mAtmCurrent;
00476   QString mAtmCurrentName;
00477   KMMessage *mMessage;
00478   // widgets:
00479   QSplitter * mSplitter;
00480   QHBox *mBox;
00481   KMail::HtmlStatusBar *mColorBar;
00482   KMMimePartTree* mMimePartTree;
00483   KHTMLPart *mViewer;
00484 
00485   const KMail::AttachmentStrategy * mAttachmentStrategy;
00486   const KMail::HeaderStrategy * mHeaderStrategy;
00487   const KMail::HeaderStyle * mHeaderStyle;
00488   bool mAutoDelete;
00490   QString mSaveAttachDir;
00491   static const int delay;
00492   QTimer updateReaderWinTimer;
00493   QTimer mResizeTimer;
00494   QTimer mDelayedMarkTimer;
00495   QString mOverrideEncoding;
00496   QString mOldGlobalOverrideEncoding; // used to detect changes of the global override character encoding
00497   bool mMsgDisplay;
00498   bool mNoMDNsWhenEncrypted;
00499   unsigned long mLastSerNum;
00500   KMMsgStatus mLastStatus;
00501 
00502   KMail::CSSHelper * mCSSHelper;
00503   bool mUseFixedFont;
00504   bool mPrinting;
00505   bool mShowColorbar;
00506   //bool mShowCompleteMessage;
00507   QStringList mTempFiles;
00508   QStringList mTempDirs;
00509   int mMimeTreeMode;
00510   bool mMimeTreeAtBottom;
00511   QValueList<int> mSplitterSizes;
00512   partNode* mRootNode;
00513   QString mIdOfLastViewedMessage;
00514   QWidget *mMainWindow;
00515   KActionCollection *mActionCollection;
00516   KAction *mMailToComposeAction, *mMailToReplyAction, *mMailToForwardAction,
00517       *mAddAddrBookAction, *mOpenAddrBookAction, *mCopyAction, *mCopyURLAction,
00518       *mUrlOpenAction, *mUrlSaveAsAction, *mAddBookmarksAction, *mStartIMChatAction, *mSelectAllAction;
00519   KSelectAction *mSelectEncodingAction;
00520   KToggleAction *mToggleFixFontAction;
00521   KURL mUrlClicked;
00522   KMail::HtmlWriter * mHtmlWriter;
00523   // an attachment should be updated
00524   bool mAtmUpdate;
00525   int mChoice;
00526   unsigned long mWaitingForSerNum;
00527   float mSavedRelativePosition;
00528     int mLevelQuote;
00529   bool mDecrytMessageOverwrite;
00530   bool mShowSignatureDetails;
00531 };
00532 
00533 
00534 #endif
00535 
KDE Home | KDE Accessibility Home | Description of Access Keys