29 #include <libkcal/incidence.h>
31 #include <tdelocale.h>
38 : mCalendar( calendar ), mCurrentMultiEntry( 0 ),
39 mUndoEntry( mEntries ), mRedoEntry( mEntries )
41 mEntries.setAutoDelete(
true );
46 if ( mCurrentMultiEntry ) mCurrentMultiEntry = 0;
47 Entry *entry = mUndoEntry.current();
53 emit redoAvailable( entry->text() );
55 mRedoEntry = mUndoEntry;
58 entry = mUndoEntry.current();
59 if ( entry ) emit undoAvailable( entry->text() );
60 else emit undoAvailable( TQString() );
65 if ( mCurrentMultiEntry ) mCurrentMultiEntry = 0;
66 Entry *entry = mRedoEntry.current();
69 emit undoAvailable( entry->text() );
74 mUndoEntry = mRedoEntry;
77 entry = mRedoEntry.current();
78 if ( entry ) emit redoAvailable( entry->text() );
79 else emit redoAvailable( TQString() );
82 void History::truncate()
84 while ( mUndoEntry.current() != mEntries.last() ) {
85 mEntries.removeLast();
87 mRedoEntry = TQPtrList<Entry>( mEntries );
88 emit redoAvailable( TQString() );
91 void History::recordDelete(
Incidence *incidence )
93 Entry *entry =
new EntryDelete( mCalendar, incidence );
94 if (mCurrentMultiEntry) {
95 mCurrentMultiEntry->appendEntry( entry );
98 mEntries.append( entry );
100 mRedoEntry = TQPtrList<Entry>( mEntries );
101 emit undoAvailable( entry->text() );
105 void History::recordAdd(
Incidence *incidence )
107 Entry *entry =
new EntryAdd( mCalendar, incidence );
108 if (mCurrentMultiEntry) {
109 mCurrentMultiEntry->appendEntry( entry );
112 mEntries.append( entry );
114 mRedoEntry = TQPtrList<Entry>( mEntries );
115 emit undoAvailable( entry->text() );
121 Entry *entry =
new EntryEdit( mCalendar, oldIncidence, newIncidence );
122 if (mCurrentMultiEntry) {
123 mCurrentMultiEntry->appendEntry( entry );
126 mEntries.append( entry );
128 mRedoEntry = TQPtrList<Entry>( mEntries );
129 emit undoAvailable( entry->text() );
133 void History::startMultiModify(
const TQString &description )
135 if ( mCurrentMultiEntry ) {
138 mCurrentMultiEntry =
new MultiEntry( mCalendar, description );
140 mEntries.append( mCurrentMultiEntry );
142 mRedoEntry = TQPtrList<Entry>( mEntries );
143 emit undoAvailable( mCurrentMultiEntry->text() );
146 void History::endMultiModify()
148 mCurrentMultiEntry = 0;
153 : mCalendar( calendar )
157 History::Entry::~Entry()
162 : Entry( calendar ), mIncidence( incidence->clone() )
166 History::EntryDelete::~EntryDelete()
171 void History::EntryDelete::undo()
174 mCalendar->addIncidence( mIncidence->clone() );
177 void History::EntryDelete::redo()
179 Incidence *incidence = mCalendar->incidence( mIncidence->uid() );
180 mCalendar->deleteIncidence( incidence );
183 TQString History::EntryDelete::text()
185 return i18n(
"Delete %1").arg(mIncidence->type().data());
190 : Entry( calendar ), mIncidence( incidence->clone() )
194 History::EntryAdd::~EntryAdd()
199 void History::EntryAdd::undo()
201 Incidence *incidence = mCalendar->incidence( mIncidence->uid() );
203 mCalendar->deleteIncidence( incidence );
206 void History::EntryAdd::redo()
209 mCalendar->addIncidence( mIncidence->clone() );
212 TQString History::EntryAdd::text()
214 return i18n(
"Add %1").arg(mIncidence->type().data());
220 : Entry( calendar ), mOldIncidence( oldIncidence->clone() ),
221 mNewIncidence( newIncidence->clone() )
225 History::EntryEdit::~EntryEdit()
227 delete mOldIncidence;
228 delete mNewIncidence;
231 void History::EntryEdit::undo()
233 Incidence *incidence = mCalendar->incidence( mNewIncidence->uid() );
235 mCalendar->deleteIncidence( incidence );
237 mCalendar->addIncidence( mOldIncidence->clone() );
240 void History::EntryEdit::redo()
242 Incidence *incidence = mCalendar->incidence( mOldIncidence->uid() );
244 mCalendar->deleteIncidence( incidence );
246 mCalendar->addIncidence( mNewIncidence->clone() );
249 TQString History::EntryEdit::text()
251 return i18n(
"Edit %1").arg(mNewIncidence->type().data());
254 History::MultiEntry::MultiEntry(
Calendar *calendar,
const TQString &text )
255 : Entry( calendar ), mText( text )
257 mEntries.setAutoDelete(
true );
260 History::MultiEntry::~MultiEntry()
264 void History::MultiEntry::appendEntry( Entry* entry )
266 mEntries.append( entry );
269 void History::MultiEntry::undo()
271 TQPtrListIterator<Entry> it( mEntries );
274 while ( (entry = it.current()) != 0 ) {
280 void History::MultiEntry::redo()
282 TQPtrListIterator<Entry> it( mEntries );
284 while ( (entry = it.current()) != 0 ) {
290 TQString History::MultiEntry::text()
295 #include "history.moc"