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 <bastian@kde.org>

svn path=/trunk/kdepim/; revision=227174
wilder-work
Zack Rusin 23 years ago
parent fd60e1ec56
commit ce6e3a2f1a
  1. 2
      kmkernel.cpp
  2. 7
      kmkernel.h
  3. 15
      kmmessage.cpp
  4. 9
      kmreaderwin.cpp
  5. 50
      mailsourceviewer.cpp
  6. 9
      mailsourceviewer.h
  7. 33
      undostack.cpp
  8. 15
      undostack.h

@ -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);

@ -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;

@ -50,6 +50,7 @@ using namespace KMime::Types;
#if ALLOW_GUI
#include <kmessagebox.h>
#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;

@ -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 ---
}

@ -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());
}

@ -34,6 +34,7 @@
#include <ktextbrowser.h>
/**
* A tiny little class to use for displaying raw messages, textual
* attachments etc.
@ -42,10 +43,14 @@
*
* @author Carsten Pfeiffer <pfeiffer@kde.org>
*/
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

@ -2,6 +2,7 @@
This file is part of KMail
Copyright (C) 1999 Waldo Bastian (bastian@kde.org)
Copyright (c) 2003 Zack Rusin <zack@kde.org>
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 <klocale.h>
#include <kdebug.h>
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<KMUndoInfo> itr( mStack );
QPtrListIterator<UndoInfo> 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<ulong>::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"

@ -2,6 +2,7 @@
This file is part of KMail
Copyright (C) 1999 Waldo Bastian (bastian@kde.org)
Copyright (c) 2003 Zack Rusin <zack@kde.org>
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<KMUndoInfo> mStack;
QPtrList<UndoInfo> mStack;
int mSize;
int mLastId;
KMUndoInfo *mCachedInfo;
UndoInfo *mCachedInfo;
signals:
void undoStackChanged();
};
}
#endif

Loading…
Cancel
Save