undostack.h 1.54 KB
Newer Older
1
2
3
/*
    This file is part of KMail

4
5
    SPDX-FileCopyrightText: 1999 Waldo Bastian <bastian@kde.org>
    SPDX-FileCopyrightText: 2003 Zack Rusin <zack@kde.org>
6

7
    SPDX-License-Identifier: GPL-2.0-only
8
9
*/

10
11
#ifndef UNDOSTACK_H
#define UNDOSTACK_H
12

Laurent Montel's avatar
Laurent Montel committed
13
#include "kmail_private_export.h"
Laurent Montel's avatar
Laurent Montel committed
14
#include <QList>
Andreas Gungl's avatar
Andreas Gungl committed
15
#include <QObject>
Laurent Montel's avatar
Laurent Montel committed
16
17
#include <AkonadiCore/collection.h>
#include <AkonadiCore/item.h>
Laurent Montel's avatar
Laurent Montel committed
18

19
20
class KJob;

Laurent Montel's avatar
Laurent Montel committed
21
namespace KMail {
Marc Mutz's avatar
Marc Mutz committed
22
/** A class for storing Undo information. */
23
class UndoInfo
24
25
{
public:
Laurent Montel's avatar
Laurent Montel committed
26
27
28
29
    UndoInfo()
    {
    }

Laurent Montel's avatar
Laurent Montel committed
30
    int id = -1;
Laurent Montel's avatar
Indent    
Laurent Montel committed
31
32
33
    Akonadi::Item::List items;
    Akonadi::Collection srcFolder;
    Akonadi::Collection destFolder;
Laurent Montel's avatar
Laurent Montel committed
34
    bool moveToTrash = false;
35
};
36

Laurent Montel's avatar
Laurent Montel committed
37
class KMAILTESTS_TESTS_EXPORT UndoStack : public QObject
38
{
Laurent Montel's avatar
Indent    
Laurent Montel committed
39
    Q_OBJECT
40

41
public:
Laurent Montel's avatar
Indent    
Laurent Montel committed
42
43
    explicit UndoStack(int size);
    ~UndoStack();
44

Laurent Montel's avatar
Indent    
Laurent Montel committed
45
    void clear();
Laurent Montel's avatar
Laurent Montel committed
46
47
    Q_REQUIRED_RESULT int  size() const;
    Q_REQUIRED_RESULT int  newUndoAction(const Akonadi::Collection &srcFolder, const Akonadi::Collection &destFolder);
Laurent Montel's avatar
Laurent Montel committed
48
    void addMsgToAction(int undoId, const Akonadi::Item &item);
Laurent Montel's avatar
Laurent Montel committed
49
    Q_REQUIRED_RESULT bool isEmpty() const;
Laurent Montel's avatar
Indent    
Laurent Montel committed
50
    void undo();
51

Laurent Montel's avatar
Laurent Montel committed
52
53
    void pushSingleAction(const Akonadi::Item &item, const Akonadi::Collection &, const Akonadi::Collection &destFolder);
    void folderDestroyed(const Akonadi::Collection &folder);
54

Laurent Montel's avatar
Laurent Montel committed
55
    Q_REQUIRED_RESULT QString undoInfo() const;
56

Laurent Montel's avatar
Laurent Montel committed
57
58
Q_SIGNALS:
    void undoStackChanged();
Laurent Montel's avatar
Indent    
Laurent Montel committed
59

Laurent Montel's avatar
Laurent Montel committed
60
private:
Laurent Montel's avatar
Laurent Montel committed
61
    Q_DISABLE_COPY(UndoStack)
Laurent Montel's avatar
Laurent Montel committed
62
    void slotMoveResult(KJob *);
Laurent Montel's avatar
Laurent Montel committed
63
    QList<UndoInfo *> mStack;
Laurent Montel's avatar
Laurent Montel committed
64
    const int mSize = 0;
Laurent Montel's avatar
Laurent Montel committed
65
66
    int mLastId = 0;
    UndoInfo *mCachedInfo = nullptr;
67
};
68
69
}

70
#endif