From ce6e3a2f1a6af890000194b5946b8e747ead6995 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Thu, 22 May 2003 00:40:27 +0000 Subject: [PATCH] Switch KMTextBrowser to KMail::MailSourceViewer and KMUndoStack to KMail::UndoStack. Waldo, would you mind if I added the Qt clause which we discussed some time ago on the KMail list to the undostack.{h,cpp} files? CCMAIL: Waldo Bastian svn path=/trunk/kdepim/; revision=227174 --- kmkernel.cpp | 2 +- kmkernel.h | 7 ++++--- kmmessage.cpp | 15 ++++++------- kmreaderwin.cpp | 9 ++++---- mailsourceviewer.cpp | 50 ++++++++++++++++++++++---------------------- mailsourceviewer.h | 9 ++++++-- undostack.cpp | 33 ++++++++++++++++------------- undostack.h | 15 ++++++++----- 8 files changed, 78 insertions(+), 62 deletions(-) diff --git a/kmkernel.cpp b/kmkernel.cpp index 0955236f8..565861187 100644 --- a/kmkernel.cpp +++ b/kmkernel.cpp @@ -661,7 +661,7 @@ void KMKernel::init() foldersPath = QDir::homeDirPath() + QString("/Mail"); transferMail(); } - the_undoStack = new KMUndoStack(20); + the_undoStack = new UndoStack(20); the_folderMgr = new KMFolderMgr(foldersPath); the_imapFolderMgr = new KMFolderMgr(locateLocal("data","kmail/imap"), KMImapDir); the_searchFolderMgr = new KMFolderMgr(locateLocal("data","kmail/search"), KMSearchDir); diff --git a/kmkernel.h b/kmkernel.h index 89d6bf44d..ffd5c2f21 100644 --- a/kmkernel.h +++ b/kmkernel.h @@ -16,14 +16,15 @@ namespace KIO { } namespace KMail { class MailServiceImpl; + class UndoStack; } using KMail::MailServiceImpl; +using KMail::UndoStack; class KConfig; class KMMsgIndex; class QLabel; class KMFolder; class KMFolderMgr; -class KMUndoStack; class KMAcctMgr; class KMFilterMgr; class KMFilterActionDict; @@ -143,7 +144,7 @@ public: KMFolderMgr *folderMgr() { return the_folderMgr; } KMFolderMgr *imapFolderMgr() { return the_imapFolderMgr; } KMFolderMgr *searchFolderMgr() { return the_searchFolderMgr; } - KMUndoStack *undoStack() { return the_undoStack; } + UndoStack *undoStack() { return the_undoStack; } KMAcctMgr *acctMgr() { return the_acctMgr; } KMFilterMgr *filterMgr() { return the_filterMgr; } KMFilterMgr *popFilterMgr() { return the_popFilterMgr; } @@ -228,7 +229,7 @@ private: KMFolder *the_draftsFolder; KMFolderMgr *the_folderMgr, *the_imapFolderMgr, *the_searchFolderMgr; - KMUndoStack *the_undoStack; + UndoStack *the_undoStack; KMAcctMgr *the_acctMgr; KMFilterMgr *the_filterMgr; KMFilterMgr *the_popFilterMgr; diff --git a/kmmessage.cpp b/kmmessage.cpp index 36193954d..7fb325b24 100644 --- a/kmmessage.cpp +++ b/kmmessage.cpp @@ -50,6 +50,7 @@ using namespace KMime::Types; #if ALLOW_GUI #include #include "mailsourceviewer.h" +using KMail::MailSourceViewer; #endif // needed temporarily until KMime is replacing the partNode helper class: @@ -3099,24 +3100,24 @@ void KMMessage::viewSource(const QString& aCaption, const QTextCodec *codec, kernel->networkCodec()->toUnicode(asString()); #if ALLOW_GUI - KMTextBrowser *browser = new KMTextBrowser(); // deletes itself upon close - if (!aCaption.isEmpty()) browser->setCaption(aCaption); - browser->setText(str); + MailSourceViewer *viewer = new MailSourceViewer(); // deletes itself upon close + if (!aCaption.isEmpty()) viewer->setCaption(aCaption); + viewer->setText(str); if (fixedfont) - browser->setFont(KGlobalSettings::fixedFont()); + viewer->setFont(KGlobalSettings::fixedFont()); // Well, there is no widget to be seen here, so we have to use QCursor::pos() // Update: (GS) I'm not going to make this code behave according to Xinerama // configuration because this is quite the hack. if (QApplication::desktop()->isVirtualDesktop()) { int scnum = QApplication::desktop()->screenNumber(QCursor::pos()); - browser->resize(QApplication::desktop()->screenGeometry(scnum).width()/2, + viewer->resize(QApplication::desktop()->screenGeometry(scnum).width()/2, 2*QApplication::desktop()->screenGeometry(scnum).height()/3); } else { - browser->resize(QApplication::desktop()->geometry().width()/2, + viewer->resize(QApplication::desktop()->geometry().width()/2, 2*QApplication::desktop()->geometry().height()/3); } - browser->show(); + viewer->show(); #else //not ALLOW_GUI kdDebug(5006) << "Message source: " << (aCaption.isEmpty() ? "" : (const char*)aCaption) << "\n" << str << "\n--- end of message ---" << endl; diff --git a/kmreaderwin.cpp b/kmreaderwin.cpp index 026d7cad7..42fa2b0f3 100644 --- a/kmreaderwin.cpp +++ b/kmreaderwin.cpp @@ -21,6 +21,7 @@ #include "kmcommands.h" #include "kmmsgpartdlg.h" #include "mailsourceviewer.h" +using KMail::MailSourceViewer; #include "partNode.h" #include "linklocator.h" #include "kmmsgdict.h" @@ -3095,16 +3096,16 @@ void KMReaderWin::setMsgPart( KMMessagePart* aMsgPart, setCaption(i18n("View Attachment: ") + pname); show(); } else { - KMTextBrowser *browser = new KMTextBrowser(); // deletes itself + MailSourceViewer *viewer = new MailSourceViewer(); // deletes itself QString str = aMsgPart->bodyDecoded(); // A QString cannot handle binary data. So if it's shorter than the // attachment, we assume the attachment is binary: if( str.length() < (unsigned) aMsgPart->decodedSize() ) { str += i18n("\n[KMail: Attachment contains binary data. Trying to show first %1 characters.]").arg(str.length()); } - browser->setText(str); - browser->resize(500, 550); - browser->show(); + viewer->setText(str); + viewer->resize(500, 550); + viewer->show(); } // ---Sven's view text, html and image attachments in html widget end --- } diff --git a/mailsourceviewer.cpp b/mailsourceviewer.cpp index 271011af7..976410a51 100644 --- a/mailsourceviewer.cpp +++ b/mailsourceviewer.cpp @@ -40,33 +40,33 @@ namespace KMail { - class MailSourceHighlighter : public QSyntaxHighlighter - { - public: - MailSourceHighlighter( QTextEdit* edit ) - : QSyntaxHighlighter( edit ) - {} - int highlightParagraph( const QString& text, int ) { - QRegExp regexp( "^([\\w-]+:\\s)" ); - if( regexp.search( text ) != -1 ) { - QFont font = textEdit()->currentFont(); - font.setBold( true ); - setFormat( 0, regexp.matchedLength(), font ); - } - return 0; +class MailSourceHighlighter : public QSyntaxHighlighter +{ +public: + MailSourceHighlighter( QTextEdit* edit ) + : QSyntaxHighlighter( edit ) + {} + int highlightParagraph( const QString& text, int ) { + QRegExp regexp( "^([\\w-]+:\\s)" ); + if( regexp.search( text ) != -1 ) { + QFont font = textEdit()->currentFont(); + font.setBold( true ); + setFormat( 0, regexp.matchedLength(), font ); } - }; + return 0; + } +}; +MailSourceViewer::MailSourceViewer( QWidget *parent, const char *name ) + : KTextBrowser( parent, name ) +{ + setWFlags( WDestructiveClose ); + QAccel *accel = new QAccel( this, "browser close-accel" ); + accel->connectItem( accel->insertItem( Qt::Key_Escape ), this , SLOT( close() )); + setTextFormat( Qt::PlainText ); + setWordWrap( KTextBrowser::NoWrap ); + new MailSourceHighlighter( this ); + KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon()); } -KMTextBrowser::KMTextBrowser( QWidget *parent, const char *name ) - : KTextBrowser( parent, name ) -{ - setWFlags( WDestructiveClose ); - QAccel *accel = new QAccel( this, "browser close-accel" ); - accel->connectItem( accel->insertItem( Qt::Key_Escape ), this , SLOT( close() )); - setTextFormat( Qt::PlainText ); - setWordWrap( KTextBrowser::NoWrap ); - new KMail::MailSourceHighlighter( this ); - KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon()); } diff --git a/mailsourceviewer.h b/mailsourceviewer.h index 4e103d7ea..9a267b894 100644 --- a/mailsourceviewer.h +++ b/mailsourceviewer.h @@ -34,6 +34,7 @@ #include + /** * A tiny little class to use for displaying raw messages, textual * attachments etc. @@ -42,10 +43,14 @@ * * @author Carsten Pfeiffer */ -class KMTextBrowser : public KTextBrowser +namespace KMail { + +class MailSourceViewer : public KTextBrowser { public: - KMTextBrowser( QWidget *parent = 0, const char *name = 0 ); + MailSourceViewer( QWidget *parent = 0, const char *name = 0 ); }; +} + #endif // MAILSOURCEVIEWER_H diff --git a/undostack.cpp b/undostack.cpp index eeace8f72..15d0535e0 100644 --- a/undostack.cpp +++ b/undostack.cpp @@ -2,6 +2,7 @@ This file is part of KMail Copyright (C) 1999 Waldo Bastian (bastian@kde.org) + Copyright (c) 2003 Zack Rusin This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -30,22 +31,23 @@ #include #include +namespace KMail { -KMUndoStack::KMUndoStack(int size) +UndoStack::UndoStack(int size) : QObject(0, "undostack"), mSize(size), mLastId(0), mCachedInfo(0) { mStack.setAutoDelete(true); } -void KMUndoStack::clear() +void UndoStack::clear() { mStack.clear(); } -int KMUndoStack::newUndoAction( KMFolder *srcFolder, KMFolder *destFolder ) +int UndoStack::newUndoAction( KMFolder *srcFolder, KMFolder *destFolder ) { - KMUndoInfo *info = new KMUndoInfo; + UndoInfo *info = new UndoInfo; info->id = ++mLastId; info->srcFolder = srcFolder; info->destFolder = destFolder; @@ -56,10 +58,10 @@ int KMUndoStack::newUndoAction( KMFolder *srcFolder, KMFolder *destFolder ) return info->id; } -void KMUndoStack::addMsgToAction( int undoId, ulong serNum ) +void UndoStack::addMsgToAction( int undoId, ulong serNum ) { if ( !mCachedInfo || mCachedInfo->id != undoId ) { - QPtrListIterator itr( mStack ); + QPtrListIterator itr( mStack ); while ( itr.current() ) { if ( itr.current()->id == undoId ) { mCachedInfo = itr.current(); @@ -73,7 +75,7 @@ void KMUndoStack::addMsgToAction( int undoId, ulong serNum ) mCachedInfo->serNums.append( serNum ); } -void KMUndoStack::undo() +void UndoStack::undo() { KMMessage *msg; ulong serNum; @@ -81,7 +83,7 @@ void KMUndoStack::undo() KMFolder *curFolder; if ( mStack.count() > 0 ) { - KMUndoInfo *info = mStack.take(0); + UndoInfo *info = mStack.take(0); emit undoStackChanged(); QValueList::iterator itr; info->destFolder->open(); @@ -109,17 +111,17 @@ void KMUndoStack::undo() } void -KMUndoStack::pushSingleAction(ulong serNum, KMFolder *folder, KMFolder *destFolder) +UndoStack::pushSingleAction(ulong serNum, KMFolder *folder, KMFolder *destFolder) { int id = newUndoAction( folder, destFolder ); addMsgToAction( id, serNum ); } void -KMUndoStack::msgDestroyed( KMMsgBase* /*msg*/) +UndoStack::msgDestroyed( KMMsgBase* /*msg*/) { /* - for(KMUndoInfo *info = mStack.first(); info; ) + for(UndoInfo *info = mStack.first(); info; ) { if (info->msgIdMD5 == msg->msgIdMD5()) { @@ -133,12 +135,12 @@ KMUndoStack::msgDestroyed( KMMsgBase* /*msg*/) } void -KMUndoStack::folderDestroyed( KMFolder *folder) +UndoStack::folderDestroyed( KMFolder *folder) { - for(KMUndoInfo *info = mStack.first(); info; ) + for( UndoInfo *info = mStack.first(); info; ) { - if ((info->srcFolder == folder) || - (info->destFolder == folder)) + if ( (info->srcFolder == folder) || + (info->destFolder == folder) ) { mStack.removeRef( info ); info = mStack.current(); @@ -149,5 +151,6 @@ KMUndoStack::folderDestroyed( KMFolder *folder) emit undoStackChanged(); } +} #include "undostack.moc" diff --git a/undostack.h b/undostack.h index ae3d52095..7354f477f 100644 --- a/undostack.h +++ b/undostack.h @@ -2,6 +2,7 @@ This file is part of KMail Copyright (C) 1999 Waldo Bastian (bastian@kde.org) + Copyright (c) 2003 Zack Rusin This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -28,8 +29,10 @@ class KMFolder; class KMMsgBase; +namespace KMail { + /** A class for storing Undo information. */ -class KMUndoInfo +class UndoInfo { public: int id; @@ -38,12 +41,12 @@ public: KMFolder *destFolder; }; -class KMUndoStack : public QObject +class UndoStack : public QObject { Q_OBJECT public: - KMUndoStack(int size); + UndoStack(int size); void clear(); int size() const { return mStack.count(); } @@ -55,13 +58,15 @@ public: void msgDestroyed( KMMsgBase *msg); void folderDestroyed( KMFolder *folder); protected: - QPtrList mStack; + QPtrList mStack; int mSize; int mLastId; - KMUndoInfo *mCachedInfo; + UndoInfo *mCachedInfo; signals: void undoStackChanged(); }; +} + #endif