Add another crash guard, should cover Andy's LDAP crashes.
[kdepim.git] / korganizer / history.h
blobe9cc3b36342d8677dd2cc11495108284a30d2f2f
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.
24 #ifndef KORG_HISTORY_H
25 #define KORG_HISTORY_H
27 #include <calendarsupport/incidencechanger.h>
29 #include <Akonadi/Item>
30 #include <Akonadi/Collection>
32 #include <KCalCore/Incidence>
34 #include <QObject>
35 #include <QStack>
36 #include <QList>
38 namespace CalendarSupport {
39 class Calendar;
42 namespace KOrg {
44 class History : public QObject
46 Q_OBJECT
47 public:
48 History( CalendarSupport::Calendar *, QWidget *parent );
50 void recordDelete( const Akonadi::Item & );
51 void recordAdd( const Akonadi::Item & );
52 void recordEdit( const Akonadi::Item &oldItem,
53 const Akonadi::Item &newItem );
54 void startMultiModify( const QString &description );
55 void endMultiModify();
57 public slots:
58 void undo();
59 void redo();
60 private slots:
61 void incidenceChangeFinished( const Akonadi::Item &,
62 const Akonadi::Item &,
63 CalendarSupport::IncidenceChanger::WhatChanged,
64 bool);
66 void incidenceAddFinished( const Akonadi::Item &, bool );
68 void incidenceDeleteFinished( const Akonadi::Item &, bool );
70 signals:
71 void undone();
72 void redone();
74 void undoAvailable( const QString & );
75 void redoAvailable( const QString & );
77 private:
78 class Entry;
79 void disableHistory();
81 // Called as soon as the modify jobs finish
82 void finishUndo( bool success );
83 void finishRedo( bool success );
85 protected:
86 void truncate();
87 void addEntry( Entry *entry );
89 private:
91 class Entry
93 public:
94 Entry( CalendarSupport::Calendar *, CalendarSupport::IncidenceChanger * );
95 virtual ~Entry();
97 virtual bool undo() = 0;
98 virtual bool redo() = 0;
100 virtual QString text() = 0;
102 void setItemId( Akonadi::Item::Id );
103 Akonadi::Item::Id itemId();
105 protected:
106 CalendarSupport::Calendar *mCalendar;
107 CalendarSupport::IncidenceChanger *mChanger;
108 Akonadi::Item::Id mItemId;
111 class EntryDelete : public Entry
113 public:
114 EntryDelete( CalendarSupport::Calendar *, CalendarSupport::IncidenceChanger *, const Akonadi::Item & );
115 ~EntryDelete();
117 bool undo();
118 bool redo();
120 QString text();
122 private:
123 KCalCore::Incidence::Ptr mIncidence;
124 Akonadi::Collection mCollection;
125 QString mParentUid;
128 class EntryAdd : public Entry
130 public:
131 EntryAdd( CalendarSupport::Calendar *, CalendarSupport::IncidenceChanger *, const Akonadi::Item & );
132 ~EntryAdd();
134 bool undo();
135 bool redo();
137 QString text();
138 private:
139 KCalCore::Incidence::Ptr mIncidence;
140 Akonadi::Collection mCollection;
141 QString mParentUid;
144 class EntryEdit : public Entry
146 public:
147 EntryEdit( CalendarSupport::Calendar *calendar,
148 CalendarSupport::IncidenceChanger *,
149 const Akonadi::Item &oldItem,
150 const Akonadi::Item &newItem );
151 ~EntryEdit();
153 bool undo();
154 bool redo();
156 QString text();
158 private:
159 KCalCore::Incidence::Ptr mOldIncidence;
160 KCalCore::Incidence::Ptr mNewIncidence;
163 class MultiEntry : public Entry
165 public:
166 MultiEntry( CalendarSupport::Calendar *calendar, const QString &text );
167 ~MultiEntry();
169 void appendEntry( Entry *entry );
170 bool undo();
171 bool redo();
173 QString text();
174 void itemCreated( Akonadi::Item::Id );
176 private:
177 QList<Entry*> mEntries;
178 QString mText;
181 CalendarSupport::Calendar *mCalendar;
182 MultiEntry *mCurrentMultiEntry;
183 QWidget *mParent;
184 CalendarSupport::IncidenceChanger *mChanger;
186 QStack<Entry*> mUndoEntries;
187 QStack<Entry*> mRedoEntries;
189 // If this is not 0 there's a modify job running that didn't end yet
190 Entry *mCurrentRunningEntry;
192 enum Operation {
193 UNDO,
194 REDO
197 // When the job ends we must know if we were doing a undo or redo
198 Operation mCurrentRunningOperation;
202 #endif