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 #include <map>
00018 
00019 class QFrame;
00020 class QSplitter;
00021 class QHBox;
00022 class QListViewItem;
00023 class QScrollBar;
00024 class QString;
00025 class QTabDialog;
00026 class QTextCodec;
00027 
00028 class DwHeaders;
00029 class DwMediaType;
00030 
00031 class KActionCollection;
00032 class KAction;
00033 class KActionMenu;
00034 class KSelectAction;
00035 class KRadioAction;
00036 class KToggleAction;
00037 class KConfigBase;
00038 class KHTMLPart;
00039 class KURL;
00040 
00041 class KMFolder;
00042 class KMMessage;
00043 class KMMessagePart;
00044 namespace KMail {
00045   namespace Interface {
00046     class Observable;
00047     class BodyPartMemento;
00048   }
00049   class PartMetaData;
00050   class ObjectTreeParser;
00051   class AttachmentStrategy;
00052   class HeaderStrategy;
00053   class HeaderStyle;
00054   class HtmlWriter;
00055   class KHtmlPartHtmlWriter;
00056   class ISubject;
00057   class HtmlStatusBar;
00058   class FolderJob;
00059   class CSSHelper;
00060 }
00061 
00062 class partNode; // might be removed when KMime is used instead of mimelib
00063                 //                                      (khz, 29.11.2001)
00064 
00065 class NewByteArray; // providing operator+ on a QByteArray (khz, 21.06.2002)
00066 
00067 class DwMessage;
00068 
00069 namespace KParts {
00070   struct URLArgs;
00071 }
00072 
00078 class KMReaderWin: public QWidget, public KMail::Interface::Observer {
00079   Q_OBJECT
00080 
00081   friend void KMMimePartTree::itemClicked( QListViewItem* item );
00082   friend void KMMimePartTree::itemRightClicked( QListViewItem* item, const QPoint & );
00083   friend void KMMimePartTree::slotSaveAs();
00084   friend void KMMimePartTree::startDrag();
00085 
00086   friend class KMail::ObjectTreeParser;
00087   friend class KMail::KHtmlPartHtmlWriter;
00088 
00089 public:
00090   KMReaderWin( QWidget *parent,
00091            QWidget *mainWindow,
00092            KActionCollection *actionCollection,
00093                const char *name=0,
00094            int f=0 );
00095   virtual ~KMReaderWin();
00096 
00101   void update( KMail::Interface::Observable * );
00102 
00104   void readConfig();
00105 
00107   void writeConfig( bool withSync=true ) const;
00108 
00109   const KMail::HeaderStyle * headerStyle() const {
00110     return mHeaderStyle;
00111   }
00114   void setHeaderStyleAndStrategy( const KMail::HeaderStyle * style,
00115                   const KMail::HeaderStrategy * strategy );
00116 
00118   const KMail::HeaderStrategy * headerStrategy() const {
00119     return mHeaderStrategy;
00120   }
00121 
00123   const KMail::AttachmentStrategy * attachmentStrategy() const {
00124     return mAttachmentStrategy;
00125   }
00126   void setAttachmentStrategy( const KMail::AttachmentStrategy * strategy );
00127 
00131   QString overrideEncoding() const { return mOverrideEncoding; }
00132 
00134   void setOverrideEncoding( const QString & encoding );
00135 
00136   void setPrintFont( const QFont& font );
00137 
00140   const QTextCodec * overrideCodec() const;
00141 
00143   virtual void setPrinting(bool enable) { mPrinting = enable; }
00144 
00147   virtual void setMsg( KMMessage* msg, bool force = false, bool updateOnly = false );
00148 
00160   void setOriginalMsg( unsigned long serNumOfOriginalMessage, int nodeIdOffset );
00161 
00164   void setMsgPart( KMMessagePart* aMsgPart, bool aHTML,
00165            const QString& aFileName, const QString& pname );
00166 
00167   void setMsgPart( partNode * node );
00168 
00171   void showHideMimeTree( bool isPlainTextTopLevel );
00172 
00177   void setIdOfLastViewedMessage( const QString & msgId )
00178     { mIdOfLastViewedMessage = msgId; }
00179 
00181   void clear(bool force = false) { setMsg(0, force); }
00182 
00185   void saveRelativePosition();
00186 
00188   void update(bool force = false);
00189 
00191   virtual void printMsg(void);
00192 
00194   QString copyText();
00195 
00197   bool autoDelete(void) const { return mAutoDelete; }
00198   void setAutoDelete(bool f) { mAutoDelete=f; }
00199 
00201   bool htmlOverride() const { return mHtmlOverride; }
00202   void setHtmlOverride( bool override );
00203 
00205   bool htmlLoadExtOverride() const { return mHtmlLoadExtOverride; }
00206   void setHtmlLoadExtOverride( bool override );
00207 
00209   bool htmlMail();
00210 
00212   bool htmlLoadExternal();
00213 
00215   static QString newFeaturesMD5();
00216 
00218   void displaySplashPage( const QString &info );
00219 
00221   void displayAboutPage();
00222 
00224   void displayBusyPage();
00226   void displayOfflinePage();
00227 
00229   void enableMsgDisplay();
00230 
00236   void atmViewMsg( KMMessagePart* msgPart, int nodeId );
00237 
00238   bool atBottom() const;
00239 
00240   bool isFixedFont() { return mUseFixedFont; }
00241   void setUseFixedFont( bool useFixedFont ) { mUseFixedFont = useFixedFont; }
00242 
00244   KMail::HtmlWriter * htmlWriter() { return mHtmlWriter; }
00245 
00246   // Action to reply to a message
00247   // but action( "some_name" ) some name could be used instead.
00248   KToggleAction *toggleFixFontAction() { return mToggleFixFontAction; }
00249   KAction *mailToComposeAction() { return mMailToComposeAction; }
00250   KAction *mailToReplyAction() { return mMailToReplyAction; }
00251   KAction *mailToForwardAction() { return mMailToForwardAction; }
00252   KAction *addAddrBookAction() { return mAddAddrBookAction; }
00253   KAction *openAddrBookAction() { return mOpenAddrBookAction; }
00254   KAction *copyAction() { return mCopyAction; }
00255   KAction *selectAllAction() { return mSelectAllAction; }
00256   KAction *copyURLAction() { return mCopyURLAction; }
00257   KAction *urlOpenAction() { return mUrlOpenAction; }
00258   KAction *urlSaveAsAction() { return mUrlSaveAsAction; }
00259   KAction *addBookmarksAction() { return mAddBookmarksAction;}
00260   KAction *startImChatAction() { return mStartIMChatAction; }
00261   // This function returns the complete data that were in this
00262   // message parts - *after* all encryption has been removed that
00263   // could be removed.
00264   // - This is used to store the message in decrypted form.
00265   void objectTreeToDecryptedMsg( partNode* node,
00266                                  NewByteArray& resultingData,
00267                                  DwMessage *currentDwMessage,
00268                                  bool weAreReplacingTheRootNode = false,
00269                                  int recCount = 0 );
00270 
00272   partNode* partNodeFromUrl(const KURL &url);
00273 
00274   partNode * partNodeForId( int id );
00275 
00276   KURL tempFileUrlFromPartNode( const partNode * node );
00277 
00279   static int msgPartFromUrl(const KURL &url);
00280 
00281   void setUpdateAttachment( bool update = true ) { mAtmUpdate = update; }
00282 
00285   KHTMLPart * htmlPart() const { return mViewer; }
00286 
00288   KMMessage* message(KMFolder** folder=0) const;
00289 
00290   void openAttachment( int id, const QString & name );
00291   void saveAttachment( const KURL &tempFileName );
00292 
00293   void emitUrlClicked( const KURL & url, int button ) {
00294     emit urlClicked( url, button );
00295   }
00296 
00297   void emitPopupMenu( const KURL & url, const QPoint & p ) {
00298     if ( message() )
00299       emit popupMenu( *message(), url, p );
00300   }
00301 
00302   void showAttachmentPopup( int id, const QString & name, const QPoint & p );
00303 
00306   void setWaitingForSerNum( unsigned long serNum ) { mWaitingForSerNum = serNum; }
00307 
00308   QWidget* mainWindow() { return mMainWindow; }
00309 
00311   bool decryptMessage() const;
00312 
00314   void setDecryptMessageOverwrite( bool overwrite = true ) { mDecrytMessageOverwrite = overwrite; }
00315 
00317   bool showSignatureDetails() const { return mShowSignatureDetails; }
00318 
00320   void setShowSignatureDetails( bool showDetails = true ) { mShowSignatureDetails = showDetails; }
00321 
00322   /* show or hide the list that points to the attachments */
00323   bool showAttachmentQuicklist() const { return mShowAttachmentQuicklist; }
00324 
00325   /* show or hide the list that points to the attachments */
00326   void setShowAttachmentQuicklist( bool showAttachmentQuicklist = true ) { mShowAttachmentQuicklist = showAttachmentQuicklist; }
00327 
00328   // This controls whether a Toltec invitation is shown in its raw form or as a replacement text.
00329   // This can be toggled with the "kmail:showRawToltecMail" link.
00330   bool showRawToltecMail() const { return mShowRawToltecMail; }
00331   void setShowRawToltecMail( bool showRawToltecMail ) { mShowRawToltecMail = showRawToltecMail; }
00332 
00333   /* retrieve BodyPartMemento of id \a which for partNode \a node */
00334   KMail::Interface::BodyPartMemento * bodyPartMemento( const partNode * node, const QCString & which ) const;
00335 
00336   /* set/replace BodyPartMemento \a memento of id \a which for
00337      partNode \a node. If there was a BodyPartMemento registered
00338      already, replaces (deletes) that one. */
00339   void setBodyPartMemento( const partNode * node, const QCString & which, KMail::Interface::BodyPartMemento * memento );
00340 
00342   void scrollToAttachment( const partNode *node );
00343 
00344 private:
00345   /* deletes all BodyPartMementos. Use this when skipping to another
00346      message (as opposed to re-loading the same one again). */
00347   void clearBodyPartMementos();
00348 
00352   bool saveDecryptedMessage( KMMessage* aMsg, KMail::ObjectTreeParser *otp,
00353                              KMMsgEncryptionState encryptionState );
00354 
00355 signals:
00358   void replaceMsgByUnencryptedVersion();
00359 
00361   void popupMenu(KMMessage &msg, const KURL &url, const QPoint& mousePos);
00362 
00364   void urlClicked(const KURL &url, int button);
00365 
00367   void noDrag(void);
00368 
00369 public slots:
00370 
00372   void selectAll();
00373 
00375   void clearCache();
00376 
00378   void updateReaderWin();
00379 
00381   void slotScrollUp();
00382   void slotScrollDown();
00383   void slotScrollPrior();
00384   void slotScrollNext();
00385   void slotJumpDown();
00386   void slotDocumentChanged();
00387   void slotDocumentDone();
00388   void slotTextSelected(bool);
00389 
00391   void slotUrlOpen(const KURL &url, const KParts::URLArgs &args);
00392 
00394   void slotUrlOn(const QString &url);
00395 
00397   void slotUrlPopup(const QString &, const QPoint& mousePos);
00398 
00400   void slotFind();
00402   void slotFindNext();
00403 
00405   void slotToggleFixedFont();
00406 
00408   void slotCopySelectedText();
00409 
00410    void slotUrlClicked();
00411 
00413   void slotMailtoReply();
00414   void slotMailtoCompose();
00415   void slotMailtoForward();
00416   void slotMailtoAddAddrBook();
00417   void slotMailtoOpenAddrBook();
00420   void slotUrlCopy();
00421   void slotUrlOpen( const KURL &url = KURL() );
00423   void slotUrlSave();
00424   void slotAddBookmarks();
00425   void slotSaveMsg();
00426   void slotSaveAttachments();
00427 
00428   void slotMessageArrived( KMMessage *msg );
00430   void slotIMChat();
00431   void contactStatusChanged( const QString &uid);
00432 
00433   void slotLevelQuote( int l );
00434   void slotTouchMessage();
00435 
00443   void fillCommandInfo( partNode *node, KMMessage **msg, int *nodeId );
00444 
00445   void slotDeleteAttachment( partNode* node );
00446   void slotEditAttachment( partNode* node );
00447 
00448   KMail::CSSHelper* cssHelper();
00449 
00450 protected slots:
00451   void slotCycleHeaderStyles();
00452   void slotBriefHeaders();
00453   void slotFancyHeaders();
00454   void slotEnterpriseHeaders();
00455   void slotStandardHeaders();
00456   void slotLongHeaders();
00457   void slotAllHeaders();
00458 
00459   void slotCycleAttachmentStrategy();
00460   void slotIconicAttachments();
00461   void slotSmartAttachments();
00462   void slotInlineAttachments();
00463   void slotHideAttachments();
00464   void slotHeaderOnlyAttachments();
00465 
00467   void slotAtmView( int id, const QString& name );
00468   void slotDelayedResize();
00469   void slotHandleAttachment( int );
00470 
00474   void disconnectMsgAdded();
00475   void msgAdded( QListViewItem *item );
00476 
00477 protected:
00480   void styleChange( QStyle& oldStyle );
00481 
00484   void setStyleDependantFrameWidth();
00485 
00487   virtual bool event(QEvent *e);
00488 
00490   int pointsToPixel(int pointSize) const;
00491 
00494   void displayMessage();
00495 
00497   virtual void parseMsg( KMMessage* msg  );
00498 
00501   QString writeMsgHeader(KMMessage* aMsg, partNode *vCardNode = 0, bool topLevel=false );
00502 
00506   QString writeMessagePartToTempFile( KMMessagePart* msgPart, int partNumber );
00507 
00513   QString createTempDir( const QString &param = QString() );
00514 
00516   void showVCard(KMMessagePart *msgPart);
00517 
00519   virtual void initHtmlWidget(void);
00520 
00522   virtual void closeEvent(QCloseEvent *);
00523   virtual void resizeEvent(QResizeEvent *);
00524 
00526   virtual void removeTempFiles();
00527 
00529   bool eventFilter( QObject *obj, QEvent *ev );
00530 
00531 private slots:
00532   void slotSetEncoding();
00533   void injectAttachments();
00534 
00535 private:
00536   void adjustLayout();
00537   void createWidgets();
00538   void createActions( KActionCollection * ac );
00539   void saveSplitterSizes( KConfigBase & c ) const;
00540 
00541   KRadioAction * actionForHeaderStyle( const KMail::HeaderStyle *,
00542                                        const KMail::HeaderStrategy * );
00543   KRadioAction * actionForAttachmentStrategy( const KMail::AttachmentStrategy * );
00545   void readGlobalOverrideCodec();
00546 
00547   QString renderAttachments( partNode *node, const QColor &bgColor );
00548 
00549 private:
00550   bool mHtmlMail, mHtmlLoadExternal, mHtmlOverride, mHtmlLoadExtOverride;
00551   int mAtmCurrent;
00552   QString mAtmCurrentName;
00553   KMMessage *mMessage;
00554 
00555   // See setOriginalMsg() for an explaination for those two.
00556   unsigned long mSerNumOfOriginalMessage;
00557   int mNodeIdOffset;
00558 
00559   // widgets:
00560   QSplitter * mSplitter;
00561   QHBox *mBox;
00562   KMail::HtmlStatusBar *mColorBar;
00563   KMMimePartTree* mMimePartTree;
00564   KHTMLPart *mViewer;
00565 
00566   const KMail::AttachmentStrategy * mAttachmentStrategy;
00567   const KMail::HeaderStrategy * mHeaderStrategy;
00568   const KMail::HeaderStyle * mHeaderStyle;
00569   bool mAutoDelete;
00571   QString mSaveAttachDir;
00572   static const int delay;
00573   QTimer mUpdateReaderWinTimer;
00574   QTimer mResizeTimer;
00575   QTimer mDelayedMarkTimer;
00576   QString mOverrideEncoding;
00577   QString mOldGlobalOverrideEncoding; // used to detect changes of the global override character encoding
00578   bool mMsgDisplay;
00579   bool mNoMDNsWhenEncrypted;
00580   unsigned long mLastSerNum;
00581 
00582   KMail::CSSHelper * mCSSHelper;
00583   bool mUseFixedFont;
00584   bool mPrinting;
00585   bool mShowColorbar;
00586   //bool mShowCompleteMessage;
00587   QStringList mTempFiles;
00588   QStringList mTempDirs;
00589   int mMimeTreeMode;
00590   bool mMimeTreeAtBottom;
00591   QValueList<int> mSplitterSizes;
00592   partNode* mRootNode;
00593   QString mIdOfLastViewedMessage;
00594   QWidget *mMainWindow;
00595   KActionCollection *mActionCollection;
00596   KAction *mMailToComposeAction, *mMailToReplyAction, *mMailToForwardAction,
00597       *mAddAddrBookAction, *mOpenAddrBookAction, *mCopyAction, *mCopyURLAction,
00598       *mUrlOpenAction, *mUrlSaveAsAction, *mAddBookmarksAction, *mStartIMChatAction, *mSelectAllAction;
00599   KToggleAction *mHeaderOnlyAttachmentsAction;
00600   KSelectAction *mSelectEncodingAction;
00601   KToggleAction *mToggleFixFontAction;
00602 
00603   KURL mHoveredUrl;
00604   KURL mClickedUrl;
00605   QPoint mLastClickPosition;
00606   QString mLastClickImagePath;
00607   bool mCanStartDrag;
00608 
00609   KMail::HtmlWriter * mHtmlWriter;
00610   std::map<QCString,KMail::Interface::BodyPartMemento*> mBodyPartMementoMap;
00611   // an attachment should be updated
00612   bool mAtmUpdate;
00613   int mChoice;
00614   unsigned long mWaitingForSerNum;
00615   float mSavedRelativePosition;
00616   int mLevelQuote;
00617   bool mDecrytMessageOverwrite;
00618   bool mShowSignatureDetails;
00619   bool mShowAttachmentQuicklist;
00620   bool mShowRawToltecMail;
00621   bool mExternalWindow;
00622 };
00623 
00624 
00625 #endif
00626 
KDE Home | KDE Accessibility Home | Description of Access Keys