Better wording
[kdepim.git] / korganizer / history.h
blob579dc839fc5de53fe4e526d64c86a601c0644916
1 /*
2 This file is part of KOrganizer.
4 Copyright (c) 2003 Cornelius Schumacher <schumacher@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.
20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable,
22 without including the source code for Qt in the source distribution.
25 #ifndef KORG_HISTORY_H
26 #define KORG_HISTORY_H
28 #include <calendarsupport/incidencechanger.h>
30 #include <Akonadi/Collection>
31 #include <Akonadi/Item>
33 #include <QObject>
34 #include <QStack>
36 namespace KOrg {
38 class History : public QObject
40 Q_OBJECT
41 public:
42 History( CalendarSupport::Calendar *, QWidget *parent );
44 void recordDelete( const Akonadi::Item & );
45 void recordAdd( const Akonadi::Item & );
46 void recordEdit( const Akonadi::Item &oldItem,
47 const Akonadi::Item &newItem );
48 void startMultiModify( const QString &description );
49 void endMultiModify();
51 public slots:
52 void undo();
53 void redo();
55 private slots:
56 void incidenceChangeFinished( const Akonadi::Item &,
57 const Akonadi::Item &,
58 CalendarSupport::IncidenceChanger::WhatChanged,
59 bool );
61 void incidenceAddFinished( const Akonadi::Item &, bool );
63 void incidenceDeleteFinished( const Akonadi::Item &, bool );
65 signals:
66 void undone();
67 void redone();
69 void undoAvailable( const QString & );
70 void redoAvailable( const QString & );
72 private:
73 class Entry;
74 void disableHistory();
76 // Called as soon as the modify jobs finish
77 void finishUndo( bool success );
78 void finishRedo( bool success );
80 protected:
81 void truncate();
82 void addEntry( Entry *entry );
84 private:
86 class Entry
88 public:
89 Entry( CalendarSupport::Calendar *, CalendarSupport::IncidenceChanger * );
90 virtual ~Entry();
92 virtual bool undo() = 0;
93 virtual bool redo() = 0;
95 virtual QString text() = 0;
97 void setItemId( Akonadi::Item::Id );
98 Akonadi::Item::Id itemId();
100 protected:
101 CalendarSupport::Calendar *mCalendar;
102 CalendarSupport::IncidenceChanger *mChanger;
103 Akonadi::Item::Id mItemId;
106 class EntryDelete : public Entry
108 public:
109 EntryDelete( CalendarSupport::Calendar *, CalendarSupport::IncidenceChanger *,
110 const Akonadi::Item & );
112 ~EntryDelete();
114 bool undo();
115 bool redo();
117 QString text();
119 private:
120 KCalCore::Incidence::Ptr mIncidence;
121 Akonadi::Collection mCollection;
122 QString mParentUid;
125 class EntryAdd : public Entry
127 public:
128 EntryAdd( CalendarSupport::Calendar *, CalendarSupport::IncidenceChanger *,
129 const Akonadi::Item & );
131 ~EntryAdd();
133 bool undo();
134 bool redo();
136 QString text();
137 private:
138 KCalCore::Incidence::Ptr mIncidence;
139 Akonadi::Collection mCollection;
140 QString mParentUid;
143 class EntryEdit : public Entry
145 public:
146 EntryEdit( CalendarSupport::Calendar *calendar,
147 CalendarSupport::IncidenceChanger *,
148 const Akonadi::Item &oldItem,
149 const Akonadi::Item &newItem );
150 ~EntryEdit();
152 bool undo();
153 bool redo();
155 QString text();
157 private:
158 KCalCore::Incidence::Ptr mOldIncidence;
159 KCalCore::Incidence::Ptr mNewIncidence;
162 class MultiEntry : public Entry
164 public:
165 MultiEntry( CalendarSupport::Calendar *calendar, const QString &text );
166 ~MultiEntry();
168 void appendEntry( Entry *entry );
169 bool undo();
170 bool redo();
172 QString text();
173 void itemCreated( Akonadi::Item::Id );
175 private:
176 QList<Entry*> mEntries;
177 QString mText;
180 CalendarSupport::Calendar *mCalendar;
181 MultiEntry *mCurrentMultiEntry;
182 QWidget *mParent;
183 CalendarSupport::IncidenceChanger *mChanger;
185 QStack<Entry*> mUndoEntries;
186 QStack<Entry*> mRedoEntries;
188 // If this is not 0 there's a modify job running that didn't end yet
189 Entry *mCurrentRunningEntry;
191 enum Operation {
192 UNDO,
193 REDO
196 // When the job ends we must know if we were doing a undo or redo
197 Operation mCurrentRunningOperation;
201 #endif