[pim/kmail] src: Remove undostack
Laurent Montel <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 280879446124b47cd0ac0542da1230116b62918f by Laurent Montel.
Committed on 27/07/2026 at 06:55.
Pushed by mlaurent into branch 'master'.
Remove undostack
M +0 -2 src/CMakeLists.txt
M +7 -7 src/kmcommands.cpp
M +0 -10 src/kmkernel.cpp
M +0 -3 src/kmkernel.h
M +5 -4 src/kmmainwidget.cpp
D +0 -137 src/undostack.cpp
D +0 -88 src/undostack.h
https://invent.kde.org/pim/kmail/-/commit/280879446124b47cd0ac0542da1230116b62918f
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 077cdcf8d..1f89dd38f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -178,7 +178,6 @@ target_sources(
kmreaderwin.cpp
kmsystemtray.cpp
unityservicemanager.cpp
- undostack.cpp
kmundoredomanager.h
kmundoredomanager.cpp
kmkernel.cpp
@@ -308,7 +307,6 @@ target_sources(
kmreaderwin.h
kmsystemtray.h
unityservicemanager.h
- undostack.h
kmkernel.h
kmcommands.h
kmreadermainwin.h
diff --git a/src/kmcommands.cpp b/src/kmcommands.cpp
index 3ca7ed39f..d5aadac04 100644
--- a/src/kmcommands.cpp
+++ b/src/kmcommands.cpp
@@ -34,6 +34,7 @@
#include "kmail_debug.h"
#include "kmreadermainwin.h"
+#include "kmundoredomanager.h"
#include "secondarywindow.h"
#include "util.h"
#include "widgets/collectionpane.h"
@@ -43,7 +44,6 @@
#include "editor/composer.h"
#include "kmmainwidget.h"
-#include "undostack.h"
#include <KIdentityManagementCore/IdentityManager>
@@ -1516,16 +1516,16 @@ KMCommand::Result KMMoveCommand::execute()
return lhs.storageCollectionId() < rhs.storageCollectionId();
});
Akonadi::Collection parent;
- int undoId = -1;
+ QUndoCommand *command = nullptr;
for (const Akonadi::Item &item : std::as_const(retrievedList)) {
if (!item.isValid() || item.storageCollectionId() == -1) {
continue;
}
if (parent.id() != item.storageCollectionId()) {
parent = Akonadi::Collection(item.storageCollectionId());
- undoId = kmkernel->undoStack()->newUndoMoveAction(parent, mDestFolder);
+ command = kmkernel->undoRedoManager()->newUndoMoveAction(parent, mDestFolder);
}
- kmkernel->undoStack()->addMsgToMoveAction(undoId, item);
+ kmkernel->undoRedoManager()->addMsgToMoveAction(command, item);
}
} else {
auto job = new Akonadi::ItemDeleteJob(retrievedList, this);
@@ -1642,16 +1642,16 @@ KMCommand::Result KMTrashMsgCommand::execute()
return lhs.storageCollectionId() < rhs.storageCollectionId();
});
Akonadi::Collection parent;
- int undoId = -1;
+ QUndoCommand *command = nullptr;
for (const Akonadi::Item &item : std::as_const(*trashIt)) {
if (!item.isValid() || item.storageCollectionId() == -1) {
continue;
}
if (parent.id() != item.storageCollectionId()) {
parent = Akonadi::Collection(item.storageCollectionId());
- undoId = kmkernel->undoStack()->newUndoMoveAction(parent, trash);
+ command = kmkernel->undoRedoManager()->newUndoMoveAction(parent, trash);
}
- kmkernel->undoStack()->addMsgToMoveAction(undoId, item);
+ kmkernel->undoRedoManager()->addMsgToMoveAction(command, item);
}
} else {
auto job = new Akonadi::ItemDeleteJob(*trashIt, this);
diff --git a/src/kmkernel.cpp b/src/kmkernel.cpp
index 17f86d334..414c428a2 100644
--- a/src/kmkernel.cpp
+++ b/src/kmkernel.cpp
@@ -14,7 +14,6 @@ using PimCommon::BroadcastStatus;
#include "kmmainwin.h"
#include "kmreadermainwin.h"
#include "kmundoredomanager.h"
-#include "undostack.h"
#if !KMAIL_FORCE_DISABLE_AKONADI_SEARCH
#include "search/checkindexingmanager.h"
@@ -680,11 +679,6 @@ void KMKernel::setXmlGuiInstanceName(const QString &instance)
mXmlGuiInstance = instance;
}
-KMail::UndoStack *KMKernel::undoStack() const
-{
- return the_undoStack;
-}
-
void KMKernel::resumeNetworkJobs()
{
if (KMailSettings::self()->networkState() == KMailSettings::EnumNetworkState::Online) {
@@ -947,8 +941,6 @@ void KMKernel::init()
// keep a reference on the key cache to avoid expensive reinitialization on each use
mKeyCache = initKeyCache();
- the_undoStack = new KMail::UndoStack(20);
-
the_msgSender = new MessageComposer::AkonadiSender;
// filterMgr->dump();
@@ -1032,8 +1024,6 @@ void KMKernel::cleanup()
// Write the config while all other managers are alive
delete the_msgSender;
the_msgSender = nullptr;
- delete the_undoStack;
- the_undoStack = nullptr;
delete mConfigureDialog;
mConfigureDialog = nullptr;
diff --git a/src/kmkernel.h b/src/kmkernel.h
index 7eeb2c8b8..90428c0dd 100644
--- a/src/kmkernel.h
+++ b/src/kmkernel.h
@@ -62,7 +62,6 @@ class AutoCorrection;
namespace KMail
{
class MailServiceImpl;
-class UndoStack;
class UnityServiceManager;
class KMUndoRedoManager;
}
@@ -417,7 +416,6 @@ public:
[[nodiscard]] const QString xmlGuiInstanceName() const;
void setXmlGuiInstanceName(const QString &instance);
- [[nodiscard]] KMail::UndoStack *undoStack() const;
MessageComposer::MessageSender *msgSender() override;
void openFilterDialog(bool createDummyFilter = true) override;
@@ -597,7 +595,6 @@ private:
KMAIL_NO_EXPORT QSharedPointer<MailCommon::FolderSettings> currentFolderCollection();
KMAIL_NO_EXPORT void saveConfig();
- KMail::UndoStack *the_undoStack = nullptr;
KMail::KMUndoRedoManager *const mUndoRedoManager;
MessageComposer::AkonadiSender *the_msgSender = nullptr;
/** is this the first start? read from config */
diff --git a/src/kmmainwidget.cpp b/src/kmmainwidget.cpp
index dd0db19fe..a6def3c56 100644
--- a/src/kmmainwidget.cpp
+++ b/src/kmmainwidget.cpp
@@ -18,7 +18,6 @@
#include "kmreadermainwin.h"
#include "kmundoredomanager.h"
#include "searchdialog/searchwindowdialog.h"
-#include "undostack.h"
#include "util.h"
#include "widgets/vacationscriptindicatorwidget.h"
#include "widgets/zoomlabelwidget.h"
@@ -2245,7 +2244,7 @@ void KMMainWidget::slotCcFilter()
//-----------------------------------------------------------------------------
void KMMainWidget::slotUndo()
{
- kmkernel->undoStack()->undo();
+ // TODO kmkernel->undoStack()->undo();
updateMessageActions();
updateFolderMenu();
}
@@ -3595,7 +3594,7 @@ void KMMainWidget::setupActions()
menutimer->setObjectName(QLatin1StringView("menutimer"));
menutimer->setSingleShot(true);
connect(menutimer, &QTimer::timeout, this, &KMMainWidget::updateMessageActionsDelayed);
- connect(kmkernel->undoStack(), &KMail::UndoStack::undoStackChanged, this, &KMMainWidget::slotUpdateUndo);
+ // TODO connect(kmkernel->undoStack(), &KMail::UndoStack::undoStackChanged, this, &KMMainWidget::slotUpdateUndo);
updateMessageActions();
updateFolderMenu();
@@ -4041,7 +4040,7 @@ void KMMainWidget::updateMessageActionsDelayed()
slotUpdateOnlineStatus(static_cast<GlobalSettingsBase::EnumNetworkState::type>(KMailSettings::self()->networkState()));
if (QAction *act = action(QStringLiteral("kmail_undo"))) {
- act->setEnabled(kmkernel->undoStack() && !kmkernel->undoStack()->isEmpty());
+ // TODO act->setEnabled(kmkernel->undoStack() && !kmkernel->undoStack()->isEmpty());
}
// Enable / disable all filters.
@@ -4286,6 +4285,7 @@ QList<KActionCollection *> KMMainWidget::actionCollections() const
//-----------------------------------------------------------------------------
void KMMainWidget::slotUpdateUndo()
{
+#if 0 // TODO
if (actionCollection()->action(QStringLiteral("kmail_undo"))) {
QAction *act = actionCollection()->action(QStringLiteral("kmail_undo"));
act->setEnabled(!kmkernel->undoStack()->isEmpty());
@@ -4296,6 +4296,7 @@ void KMMainWidget::slotUpdateUndo()
act->setText(i18n("&Undo: \"%1\"", kmkernel->undoStack()->undoInfo()));
}
}
+#endif
}
//-----------------------------------------------------------------------------
diff --git a/src/undostack.cpp b/src/undostack.cpp
deleted file mode 100644
index a9eb3ad99..000000000
--- a/src/undostack.cpp
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- This file is part of KMail
-
- SPDX-FileCopyrightText: 1999 Waldo Bastian <[email protected]>
- SPDX-FileCopyrightText: 2003 Zack Rusin <[email protected]>
- SPDX-FileCopyrightText: 2026 Laurent Montel <[email protected]>
-
- SPDX-License-Identifier: GPL-2.0-only
-*/
-
-#include "undostack.h"
-
-#include "kmkernel.h"
-#include <Akonadi/ItemMoveJob>
-#include <KJob>
-
-#include <KLocalizedString>
-#include <KMessageBox>
-
-using namespace KMail;
-
-UndoStack::UndoStack(int size)
- : QObject(nullptr)
- , mSize(size)
-{
-}
-
-UndoStack::~UndoStack()
-{
- clear();
-}
-
-void UndoStack::clear()
-{
- qDeleteAll(mStack);
- mStack.clear();
-}
-
-QString UndoStack::undoInfo() const
-{
- if (!mStack.isEmpty()) {
- UndoInfoBase *info = mStack.first();
- return info->undoInfo();
- } else {
- return {};
- }
-}
-
-int UndoStack::newUndoMoveAction(const Akonadi::Collection &srcFolder, const Akonadi::Collection &destFolder)
-{
- auto info = new UndoInfoMoveItems;
- info->id = ++mLastId;
- info->srcFolder = srcFolder;
- info->destFolder = destFolder;
- info->moveToTrash = (destFolder == CommonKernel->trashCollectionFolder());
- if (static_cast<int>(mStack.count()) == mSize) {
- delete mStack.last();
- mStack.removeLast();
- }
- mStack.prepend(info);
- Q_EMIT undoStackChanged();
- return info->id;
-}
-
-void UndoStack::addMsgToMoveAction(int undoId, const Akonadi::Item &item)
-{
- if (!mCachedInfo || mCachedInfo->id != undoId) {
- QList<UndoInfoBase *>::const_iterator itr = mStack.constBegin();
- while (itr != mStack.constEnd()) {
- if ((*itr)->id == undoId) {
- mCachedInfo = (*itr);
- break;
- }
- ++itr;
- }
- }
-
- Q_ASSERT(mCachedInfo);
- UndoInfoMoveItems *moveItems = dynamic_cast<UndoInfoMoveItems *>(mCachedInfo);
- moveItems->items.append(item);
-}
-
-bool UndoStack::isEmpty() const
-{
- return mStack.isEmpty();
-}
-
-void UndoStack::undo()
-{
- if (!mStack.isEmpty()) {
- UndoInfoBase *info = mStack.takeFirst();
- info->undo();
- Q_EMIT undoStackChanged();
- } else {
- // Sorry.. stack is empty..
- KMessageBox::error(kmkernel->mainWin(), i18n("There is nothing to undo."));
- }
-}
-
-UndoInfoMoveItems::UndoInfoMoveItems() = default;
-
-UndoInfoMoveItems::~UndoInfoMoveItems() = default;
-
-void UndoInfoMoveItems::slotMoveResult(KJob *job)
-{
- if (job->error()) {
- KMessageBox::error(kmkernel->mainWin(), i18n("Cannot move message. %1", job->errorString()));
- }
- deleteLater();
-}
-
-QString UndoInfoMoveItems::undoInfo() const
-{
- return moveToTrash ? i18n("Move To Trash") : i18np("Move Message", "Move Messages", items.count());
-}
-
-void UndoInfoMoveItems::undo()
-{
- auto job = new Akonadi::ItemMoveJob(items, srcFolder, this);
- connect(job, &Akonadi::ItemMoveJob::result, this, &UndoInfoMoveItems::slotMoveResult);
-}
-
-UndoInfoChangeStatusItems::UndoInfoChangeStatusItems() = default;
-
-UndoInfoChangeStatusItems::~UndoInfoChangeStatusItems() = default;
-
-QString UndoInfoChangeStatusItems::undoInfo() const
-{
- return i18n("Change Message Status");
-}
-
-void UndoInfoChangeStatusItems::undo()
-{
- // TODO
-}
-
-#include "moc_undostack.cpp"
diff --git a/src/undostack.h b/src/undostack.h
deleted file mode 100644
index f42652427..000000000
--- a/src/undostack.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- This file is part of KMail
-
- SPDX-FileCopyrightText: 1999 Waldo Bastian <[email protected]>
- SPDX-FileCopyrightText: 2003 Zack Rusin <[email protected]>
- SPDX-FileCopyrightText: 2026 Laurent Montel <[email protected]>
-
- SPDX-License-Identifier: GPL-2.0-only
-*/
-
-#pragma once
-
-#include "kmail_private_export.h"
-#include <Akonadi/Collection>
-#include <Akonadi/Item>
-#include <QList>
-#include <QObject>
-
-class KJob;
-
-namespace KMail
-{
-class UndoInfoBase
-{
-public:
- UndoInfoBase() = default;
- virtual ~UndoInfoBase() { };
- virtual void undo() = 0;
- [[nodiscard]] virtual QString undoInfo() const = 0;
- int id = -1;
-};
-
-class UndoInfoChangeStatusItems : public QObject, public UndoInfoBase
-{
- Q_OBJECT
-public:
- UndoInfoChangeStatusItems();
- ~UndoInfoChangeStatusItems() override;
- [[nodiscard]] QString undoInfo() const override;
- void undo() override;
- Akonadi::Item::List items;
-};
-
-/** A class for storing Undo information. */
-class UndoInfoMoveItems : public QObject, public UndoInfoBase
-{
- Q_OBJECT
-public:
- UndoInfoMoveItems();
- ~UndoInfoMoveItems() override;
- [[nodiscard]] QString undoInfo() const override;
-
- void undo() override;
- Akonadi::Item::List items;
- Akonadi::Collection srcFolder;
- Akonadi::Collection destFolder;
- bool moveToTrash = false;
-
-private:
- void slotMoveResult(KJob *);
-};
-
-class KMAILTESTS_TESTS_EXPORT UndoStack : public QObject
-{
- Q_OBJECT
-
-public:
- explicit UndoStack(int size);
- ~UndoStack() override;
-
- [[nodiscard]] int newUndoMoveAction(const Akonadi::Collection &srcFolder, const Akonadi::Collection &destFolder);
- void addMsgToMoveAction(int undoId, const Akonadi::Item &item);
- [[nodiscard]] bool isEmpty() const;
- void undo();
-
- [[nodiscard]] QString undoInfo() const;
-
-Q_SIGNALS:
- void undoStackChanged();
-
-private:
- KMAIL_NO_EXPORT void clear();
- QList<UndoInfoBase *> mStack;
- const int mSize = 0;
- int mLastId = 0;
- UndoInfoBase *mCachedInfo = nullptr;
-};
-}