From 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kmail/undostack.cpp | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 kmail/undostack.cpp (limited to 'kmail/undostack.cpp') diff --git a/kmail/undostack.cpp b/kmail/undostack.cpp new file mode 100644 index 000000000..f1729f3a7 --- /dev/null +++ b/kmail/undostack.cpp @@ -0,0 +1,157 @@ +/* + 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 + version 2 as published by the Free Software Foundation. + + This software is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "undostack.h" + +#include "kmmainwin.h" +#include "kmfolder.h" +#include "kmmsgdict.h" + +#include +#include +#include + +namespace KMail { + +UndoStack::UndoStack(int size) + : QObject(0, "undostack"), mSize(size), mLastId(0), + mCachedInfo(0) +{ + mStack.setAutoDelete(true); +} + +void UndoStack::clear() +{ + mStack.clear(); +} + +int UndoStack::newUndoAction( KMFolder *srcFolder, KMFolder *destFolder ) +{ + UndoInfo *info = new UndoInfo; + info->id = ++mLastId; + info->srcFolder = srcFolder; + info->destFolder = destFolder; + if ((int) mStack.count() == mSize) + mStack.removeLast(); + mStack.prepend( info ); + emit undoStackChanged(); + return info->id; +} + +void UndoStack::addMsgToAction( int undoId, ulong serNum ) +{ + if ( !mCachedInfo || mCachedInfo->id != undoId ) { + QPtrListIterator itr( mStack ); + while ( itr.current() ) { + if ( itr.current()->id == undoId ) { + mCachedInfo = itr.current(); + break; + } + ++itr; + } + } + + Q_ASSERT( mCachedInfo ); + mCachedInfo->serNums.append( serNum ); +} + +void UndoStack::undo() +{ + KMMessage *msg; + ulong serNum; + int idx = -1; + KMFolder *curFolder; + if ( mStack.count() > 0 ) + { + UndoInfo *info = mStack.take(0); + emit undoStackChanged(); + QValueList::iterator itr; + KMFolderOpener openDestFolder(info->destFolder, "undodest"); + for( itr = info->serNums.begin(); itr != info->serNums.end(); ++itr ) { + serNum = *itr; + KMMsgDict::instance()->getLocation(serNum, &curFolder, &idx); + if ( idx == -1 || curFolder != info->destFolder ) { + kdDebug(5006)<<"Serious undo error!"<getMsg( idx ); + info->srcFolder->moveMsg( msg ); + if ( info->srcFolder->count() > 1 ) + info->srcFolder->unGetMsg( info->srcFolder->count() - 1 ); + } + delete info; + } + else + { + // Sorry.. stack is empty.. + KMessageBox::sorry( kmkernel->mainWin(), i18n("There is nothing to undo.")); + } +} + +void +UndoStack::pushSingleAction(ulong serNum, KMFolder *folder, KMFolder *destFolder) +{ + int id = newUndoAction( folder, destFolder ); + addMsgToAction( id, serNum ); +} + +void +UndoStack::msgDestroyed( KMMsgBase* /*msg*/) +{ + /* + for(UndoInfo *info = mStack.first(); info; ) + { + if (info->msgIdMD5 == msg->msgIdMD5()) + { + mStack.removeRef( info ); + info = mStack.current(); + } + else + info = mStack.next(); + } + */ +} + +void +UndoStack::folderDestroyed( KMFolder *folder) +{ + for( UndoInfo *info = mStack.first(); info; ) + { + if ( (info->srcFolder == folder) || + (info->destFolder == folder) ) + { + mStack.removeRef( info ); + info = mStack.current(); + } + else + info = mStack.next(); + } + emit undoStackChanged(); +} + +} + +#include "undostack.moc" -- cgit v1.2.1