[pim/kmail] src: Move command to UndoInfoMoveItems
Laurent Montel <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 1c978305140f6a6d79e2c47037b5bc896391adff by Laurent Montel.
Committed on 23/07/2026 at 05:37.
Pushed by mlaurent into branch 'master'.
Move command to UndoInfoMoveItems
M +15 -5 src/undostack.cpp
M +7 -2 src/undostack.h
https://invent.kde.org/pim/kmail/-/commit/1c978305140f6a6d79e2c47037b5bc896391adff
diff --git a/src/undostack.cpp b/src/undostack.cpp
index 61beaa78b..1a413566e 100644
--- a/src/undostack.cpp
+++ b/src/undostack.cpp
@@ -39,7 +39,7 @@ QString UndoStack::undoInfo() const
{
if (!mStack.isEmpty()) {
UndoInfoMoveItems *info = mStack.first();
- return info->moveToTrash ? i18n("Move To Trash") : i18np("Move Message", "Move Messages", info->items.count());
+ return info->undoInfo();
} else {
return {};
}
@@ -87,21 +87,31 @@ void UndoStack::undo()
{
if (!mStack.isEmpty()) {
UndoInfoMoveItems *info = mStack.takeFirst();
+ info->undo();
Q_EMIT undoStackChanged();
- auto job = new Akonadi::ItemMoveJob(info->items, info->srcFolder, this);
- connect(job, &Akonadi::ItemMoveJob::result, this, &UndoStack::slotMoveResult);
- delete info;
} else {
// Sorry.. stack is empty..
KMessageBox::error(kmkernel->mainWin(), i18n("There is nothing to undo."));
}
}
-void UndoStack::slotMoveResult(KJob *job)
+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);
}
#include "moc_undostack.cpp"
diff --git a/src/undostack.h b/src/undostack.h
index 317184b50..c0e6f34f9 100644
--- a/src/undostack.h
+++ b/src/undostack.h
@@ -29,16 +29,22 @@ public:
};
/** A class for storing Undo information. */
-class UndoInfoMoveItems
+class UndoInfoMoveItems : public QObject
{
+ Q_OBJECT
public:
UndoInfoMoveItems() = default;
+ [[nodiscard]] QString undoInfo() const;
+ void undo();
int id = -1;
Akonadi::Item::List items;
Akonadi::Collection srcFolder;
Akonadi::Collection destFolder;
bool moveToTrash = false;
+
+private:
+ void slotMoveResult(KJob *);
};
class KMAILTESTS_TESTS_EXPORT UndoStack : public QObject
@@ -61,7 +67,6 @@ Q_SIGNALS:
private:
KMAIL_NO_EXPORT void clear();
- KMAIL_NO_EXPORT void slotMoveResult(KJob *);
QList<UndoInfoMoveItems *> mStack;
const int mSize = 0;
int mLastId = 0;