SVN_SILENT made messages (.desktop file)
[kdepim.git] / kalarm / undo.h
blob352da15b037d019f210e47a2210a349c75b64a41
1 /*
2 * undo.h - undo/redo facility
3 * Program: kalarm
4 * Copyright © 2005-2011 by David Jarvie <djarvie@kde.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #ifndef UNDO_H
22 #define UNDO_H
24 /** @file undo.h - undo/redo facility */
26 #include "autodeletelist.h"
28 #include <kalarmcal/kaevent.h>
30 #ifdef USE_AKONADI
31 #include <akonadi/collection.h>
32 #endif
33 #include <QList>
34 #include <QStringList>
36 #ifndef USE_AKONADI
37 class AlarmResource;
38 #endif
39 class UndoItem;
40 using namespace KAlarmCal;
43 class Undo : public QObject
45 Q_OBJECT
46 public:
47 enum Type { NONE, UNDO, REDO };
48 // N.B. The Event structure must be constructed before the action for
49 // which the undo is being created is carried out, since the
50 // don't-show-errors status is not contained within the KAEvent itself.
51 struct Event
53 Event() {}
54 #ifdef USE_AKONADI
55 Event(const KAEvent&, const Akonadi::Collection&);
56 #else
57 Event(const KAEvent&, AlarmResource*);
58 #endif
59 KAEvent event;
60 #ifdef USE_AKONADI
61 mutable Akonadi::Collection collection;
62 #else
63 AlarmResource* resource;
64 #endif
65 QStringList dontShowErrors;
67 class EventList : public QList<Event>
69 public:
70 #ifdef USE_AKONADI
71 void append(const KAEvent& e, const Akonadi::Collection& c) { QList<Event>::append(Event(e, c)); }
72 #else
73 void append(const KAEvent& e, AlarmResource* r) { QList<Event>::append(Event(e, r)); }
74 #endif
77 static Undo* instance();
78 #ifdef USE_AKONADI
79 static void saveAdd(const KAEvent&, const Akonadi::Collection&, const QString& name = QString());
80 #else
81 static void saveAdd(const KAEvent&, AlarmResource*, const QString& name = QString());
82 #endif
83 static void saveAdds(const EventList&, const QString& name = QString());
84 static void saveEdit(const Event& oldEvent, const KAEvent& newEvent);
85 static void saveDelete(const Event&, const QString& name = QString());
86 static void saveDeletes(const EventList&, const QString& name = QString());
87 #ifdef USE_AKONADI
88 static void saveReactivate(const KAEvent&, const Akonadi::Collection&, const QString& name = QString());
89 #else
90 static void saveReactivate(const KAEvent&, AlarmResource*, const QString& name = QString());
91 #endif
92 static void saveReactivates(const EventList&, const QString& name = QString());
93 static bool undo(QWidget* parent, const QString& action)
94 { return undo(0, UNDO, parent, action); }
95 static bool undo(int id, QWidget* parent, const QString& action)
96 { return undo(findItem(id, UNDO), UNDO, parent, action); }
97 static bool redo(QWidget* parent, const QString& action)
98 { return undo(0, REDO, parent, action); }
99 static bool redo(int id, QWidget* parent, const QString& action)
100 { return undo(findItem(id, REDO), REDO, parent, action); }
101 static void clear();
102 static bool haveUndo() { return !mUndoList.isEmpty(); }
103 static bool haveRedo() { return !mRedoList.isEmpty(); }
104 static QString actionText(Type);
105 static QString actionText(Type, int id);
106 static QString description(Type, int id);
107 static QList<int> ids(Type);
108 static void emitChanged();
110 // Types for use by UndoItem class and its descendants
111 typedef AutoDeleteList<UndoItem> List;
113 signals:
114 void changed(const QString& undo, const QString& redo);
116 protected:
117 // Methods for use by UndoItem class
118 static void add(UndoItem*, bool undo);
119 static void remove(UndoItem*, bool undo);
120 static void replace(UndoItem* old, UndoItem* New);
122 private:
123 Undo(QObject* parent) : QObject(parent) { }
124 static void removeRedos(const QString& eventID);
125 static bool undo(int index, Type, QWidget* parent, const QString& action);
126 static UndoItem* getItem(int id, Type);
127 static int findItem(int id, Type);
128 void emitChanged(const QString& undo, const QString& redo)
129 { emit changed(undo, redo); }
131 static Undo* mInstance; // the one and only Undo instance
132 static List mUndoList; // edit history for undo, latest undo first
133 static List mRedoList; // edit history for redo, latest redo first
135 friend class UndoItem;
138 #endif // UNDO_H
140 // vim: et sw=4: