history.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "history.h"
00026
00027 #include <libkcal/calendar.h>
00028 #include <libkcal/incidence.h>
00029
00030 #include <klocale.h>
00031 #include <kdebug.h>
00032
00033 using namespace KCal;
00034 using namespace KOrg;
00035
00036 History::History( KCal::Calendar *calendar )
00037 : mCalendar( calendar ), mUndoEntry( mEntries ), mRedoEntry( mEntries )
00038 {
00039 mEntries.setAutoDelete( true );
00040 }
00041
00042 void History::undo()
00043 {
00044 Entry *entry = mUndoEntry.current();
00045 if ( !entry ) return;
00046
00047 entry->undo();
00048 emit undone();
00049
00050 emit redoAvailable( entry->text() );
00051
00052 mRedoEntry = mUndoEntry;
00053 --mUndoEntry;
00054
00055 entry = mUndoEntry.current();
00056 if ( entry ) emit undoAvailable( entry->text() );
00057 else emit undoAvailable( QString::null );
00058 }
00059
00060 void History::redo()
00061 {
00062 Entry *entry = mRedoEntry.current();
00063 if ( !entry ) return;
00064
00065 emit undoAvailable( entry->text() );
00066
00067 entry->redo();
00068 emit redone();
00069
00070 mUndoEntry = mRedoEntry;
00071 ++mRedoEntry;
00072
00073 entry = mRedoEntry.current();
00074 if ( entry ) emit redoAvailable( entry->text() );
00075 else emit redoAvailable( QString::null );
00076 }
00077
00078 void History::truncate()
00079 {
00080 while ( mUndoEntry.current() != mEntries.last() ) {
00081 mEntries.removeLast();
00082 }
00083 mRedoEntry = QPtrList<Entry>( mEntries );
00084 emit redoAvailable( QString::null );
00085 }
00086
00087 void History::recordDelete( Incidence *incidence )
00088 {
00089 truncate();
00090 Entry *entry = new EntryDelete( mCalendar, incidence );
00091 mEntries.append( entry );
00092 mUndoEntry.toLast();
00093 mRedoEntry = QPtrList<Entry>( mEntries );
00094 emit undoAvailable( entry->text() );
00095 }
00096
00097 void History::recordAdd( Incidence *incidence )
00098 {
00099 truncate();
00100 Entry *entry = new EntryAdd( mCalendar, incidence );
00101 mEntries.append( entry );
00102 mUndoEntry.toLast();
00103 mRedoEntry = QPtrList<Entry>( mEntries );
00104 emit undoAvailable( entry->text() );
00105 }
00106
00107 void History::recordEdit( Incidence *oldIncidence, Incidence *newIncidence )
00108 {
00109 truncate();
00110 Entry *entry = new EntryEdit( mCalendar, oldIncidence, newIncidence );
00111 mEntries.append( entry );
00112 mUndoEntry.toLast();
00113 mRedoEntry = QPtrList<Entry>( mEntries );
00114 emit undoAvailable( entry->text() );
00115 }
00116
00117
00118 History::Entry::Entry( KCal::Calendar *calendar )
00119 : mCalendar( calendar )
00120 {
00121 }
00122
00123 History::Entry::~Entry()
00124 {
00125 }
00126
00127 History::EntryDelete::EntryDelete( Calendar *calendar, Incidence *incidence )
00128 : Entry( calendar ), mIncidence( incidence->clone() )
00129 {
00130 }
00131
00132 History::EntryDelete::~EntryDelete()
00133 {
00134 delete mIncidence;
00135 }
00136
00137 void History::EntryDelete::undo()
00138 {
00139 mCalendar->addIncidence( mIncidence->clone() );
00140 }
00141
00142 void History::EntryDelete::redo()
00143 {
00144 Incidence *incidence = mCalendar->incidence( mIncidence->uid() );
00145 mCalendar->deleteIncidence( incidence );
00146 }
00147
00148 QString History::EntryDelete::text()
00149 {
00150 return i18n("Delete %1").arg(mIncidence->type());
00151 }
00152
00153
00154 History::EntryAdd::EntryAdd( Calendar *calendar, Incidence *incidence )
00155 : Entry( calendar ), mIncidence( incidence->clone() )
00156 {
00157 }
00158
00159 History::EntryAdd::~EntryAdd()
00160 {
00161 delete mIncidence;
00162 }
00163
00164 void History::EntryAdd::undo()
00165 {
00166 Incidence *incidence = mCalendar->incidence( mIncidence->uid() );
00167 mCalendar->deleteIncidence( incidence );
00168 }
00169
00170 void History::EntryAdd::redo()
00171 {
00172 mCalendar->addIncidence( mIncidence->clone() );
00173 }
00174
00175 QString History::EntryAdd::text()
00176 {
00177 return i18n("Add %1").arg(mIncidence->type());
00178 }
00179
00180
00181 History::EntryEdit::EntryEdit( Calendar *calendar, Incidence *oldIncidence,
00182 Incidence *newIncidence )
00183 : Entry( calendar ), mOldIncidence( oldIncidence->clone() ),
00184 mNewIncidence( newIncidence->clone() )
00185 {
00186 }
00187
00188 History::EntryEdit::~EntryEdit()
00189 {
00190 delete mOldIncidence;
00191 delete mNewIncidence;
00192 }
00193
00194 void History::EntryEdit::undo()
00195 {
00196 Incidence *incidence = mCalendar->incidence( mNewIncidence->uid() );
00197 mCalendar->deleteIncidence( incidence );
00198 mCalendar->addIncidence( mOldIncidence->clone() );
00199 }
00200
00201 void History::EntryEdit::redo()
00202 {
00203 Incidence *incidence = mCalendar->incidence( mOldIncidence->uid() );
00204 mCalendar->deleteIncidence( incidence );
00205 mCalendar->addIncidence( mNewIncidence->clone() );
00206 }
00207
00208 QString History::EntryEdit::text()
00209 {
00210 return i18n("Edit %1").arg(mNewIncidence->type());
00211 }
00212
00213 #include "history.moc"
This file is part of the documentation for korganizer Library Version 3.2.2.