kalarm

undo.h
Go to the documentation of this file.
1 /*
2  * undo.h - undo/redo facility
3  * Program: kalarm
4  * Copyright (C) 2005 by David Jarvie <software@astrojar.org.uk>
5  *
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.
10  *
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.
15  *
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.
19  */
20 
21 #ifndef UNDO_H
22 #define UNDO_H
23 
26 #include <tqvaluelist.h>
27 #include <tqstringlist.h>
28 
29 class KAEvent;
30 class UndoItem;
31 
32 
33 class Undo : public TQObject
34 {
35  TQ_OBJECT
36 
37  public:
38  enum Type { NONE, UNDO, REDO };
39 
40  static Undo* instance();
41  static void saveAdd(const KAEvent&);
42  static void saveEdit(const KAEvent& oldEvent, const KAEvent& newEvent);
43  static void saveDelete(const KAEvent&);
44  static void saveDeletes(const TQValueList<KAEvent>&);
45  static void saveReactivate(const KAEvent&);
46  static void saveReactivates(const TQValueList<KAEvent>&);
47  static bool undo(TQWidget* parent, const TQString& action)
48  { return undo(mUndoList.begin(), UNDO, parent, action); }
49  static bool undo(int id, TQWidget* parent, const TQString& action)
50  { return undo(findItem(id, UNDO), UNDO, parent, action); }
51  static bool redo(TQWidget* parent, const TQString& action)
52  { return undo(mRedoList.begin(), REDO, parent, action); }
53  static bool redo(int id, TQWidget* parent, const TQString& action)
54  { return undo(findItem(id, REDO), REDO, parent, action); }
55  static void clear();
56  static bool haveUndo() { return !mUndoList.isEmpty(); }
57  static bool haveRedo() { return !mRedoList.isEmpty(); }
58  static TQString actionText(Type);
59  static TQString actionText(Type, int id);
60  static TQString description(Type, int id);
61  static TQValueList<int> ids(Type);
62  static void emitChanged();
63 
64  // Types for use by UndoItem class and its descendants
65  typedef TQValueList<UndoItem*> List;
66 
67  signals:
68  void changed(const TQString& undo, const TQString& redo);
69 
70  protected:
71  // Methods for use by UndoItem class
72  static void add(UndoItem*, bool undo);
73  static void remove(UndoItem*, bool undo);
74  static void replace(UndoItem* old, UndoItem* New);
75 
76  private:
77  typedef TQValueList<UndoItem*>::Iterator Iterator;
78 
79  Undo(TQObject* parent) : TQObject(parent) { }
80  static void removeRedos(const TQString& eventID);
81  static bool undo(Iterator, Type, TQWidget* parent, const TQString& action);
82  static UndoItem* getItem(int id, Type);
83  static Iterator findItem(int id, Type);
84  void emitChanged(const TQString& undo, const TQString& redo)
85  { emit changed(undo, redo); }
86 
87  static Undo* mInstance; // the one and only Undo instance
88  static List mUndoList; // edit history for undo, latest undo first
89  static List mRedoList; // edit history for redo, latest redo first
90 
91  friend class UndoItem;
92 };
93 
94 #endif // UNDO_H
KAEvent corresponds to a KCal::Event instance.
Definition: alarmevent.h:232