korganizer Library API Documentation

history.cpp

00001 /* 00002 This file is part of KOrganizer. 00003 00004 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of Qt, and distribute the resulting executable, 00022 without including the source code for Qt in the source distribution. 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 ), mCurrentMultiEntry( 0 ), 00038 mUndoEntry( mEntries ), mRedoEntry( mEntries ) 00039 { 00040 mEntries.setAutoDelete( true ); 00041 } 00042 00043 void History::undo() 00044 { 00045 if ( mCurrentMultiEntry ) mCurrentMultiEntry = 0; 00046 Entry *entry = mUndoEntry.current(); 00047 if ( !entry ) return; 00048 00049 entry->undo(); 00050 emit undone(); 00051 00052 emit redoAvailable( entry->text() ); 00053 00054 mRedoEntry = mUndoEntry; 00055 --mUndoEntry; 00056 00057 entry = mUndoEntry.current(); 00058 if ( entry ) emit undoAvailable( entry->text() ); 00059 else emit undoAvailable( QString::null ); 00060 } 00061 00062 void History::redo() 00063 { 00064 if ( mCurrentMultiEntry ) mCurrentMultiEntry = 0; 00065 Entry *entry = mRedoEntry.current(); 00066 if ( !entry ) return; 00067 00068 emit undoAvailable( entry->text() ); 00069 00070 entry->redo(); 00071 emit redone(); 00072 00073 mUndoEntry = mRedoEntry; 00074 ++mRedoEntry; 00075 00076 entry = mRedoEntry.current(); 00077 if ( entry ) emit redoAvailable( entry->text() ); 00078 else emit redoAvailable( QString::null ); 00079 } 00080 00081 void History::truncate() 00082 { 00083 while ( mUndoEntry.current() != mEntries.last() ) { 00084 mEntries.removeLast(); 00085 } 00086 mRedoEntry = QPtrList<Entry>( mEntries ); 00087 emit redoAvailable( QString::null ); 00088 } 00089 00090 void History::recordDelete( Incidence *incidence ) 00091 { 00092 Entry *entry = new EntryDelete( mCalendar, incidence ); 00093 if (mCurrentMultiEntry) { 00094 mCurrentMultiEntry->appendEntry( entry ); 00095 } else { 00096 truncate(); 00097 mEntries.append( entry ); 00098 mUndoEntry.toLast(); 00099 mRedoEntry = QPtrList<Entry>( mEntries ); 00100 emit undoAvailable( entry->text() ); 00101 } 00102 } 00103 00104 void History::recordAdd( Incidence *incidence ) 00105 { 00106 Entry *entry = new EntryAdd( mCalendar, incidence ); 00107 if (mCurrentMultiEntry) { 00108 mCurrentMultiEntry->appendEntry( entry ); 00109 } else { 00110 truncate(); 00111 mEntries.append( entry ); 00112 mUndoEntry.toLast(); 00113 mRedoEntry = QPtrList<Entry>( mEntries ); 00114 emit undoAvailable( entry->text() ); 00115 } 00116 } 00117 00118 void History::recordEdit( Incidence *oldIncidence, Incidence *newIncidence ) 00119 { 00120 Entry *entry = new EntryEdit( mCalendar, oldIncidence, newIncidence ); 00121 if (mCurrentMultiEntry) { 00122 mCurrentMultiEntry->appendEntry( entry ); 00123 } else { 00124 truncate(); 00125 mEntries.append( entry ); 00126 mUndoEntry.toLast(); 00127 mRedoEntry = QPtrList<Entry>( mEntries ); 00128 emit undoAvailable( entry->text() ); 00129 } 00130 } 00131 00132 void History::startMultiModify( const QString &description ) 00133 { 00134 if ( mCurrentMultiEntry ) { 00135 endMultiModify(); 00136 } 00137 mCurrentMultiEntry = new MultiEntry( mCalendar, description ); 00138 truncate(); 00139 mEntries.append( mCurrentMultiEntry ); 00140 mUndoEntry.toLast(); 00141 mRedoEntry = QPtrList<Entry>( mEntries ); 00142 emit undoAvailable( mCurrentMultiEntry->text() ); 00143 } 00144 00145 void History::endMultiModify() 00146 { 00147 mCurrentMultiEntry = 0; 00148 } 00149 00150 00151 History::Entry::Entry( KCal::Calendar *calendar ) 00152 : mCalendar( calendar ) 00153 { 00154 } 00155 00156 History::Entry::~Entry() 00157 { 00158 } 00159 00160 History::EntryDelete::EntryDelete( Calendar *calendar, Incidence *incidence ) 00161 : Entry( calendar ), mIncidence( incidence->clone() ) 00162 { 00163 } 00164 00165 History::EntryDelete::~EntryDelete() 00166 { 00167 delete mIncidence; 00168 } 00169 00170 void History::EntryDelete::undo() 00171 { 00172 mCalendar->addIncidence( mIncidence->clone() ); 00173 } 00174 00175 void History::EntryDelete::redo() 00176 { 00177 Incidence *incidence = mCalendar->incidence( mIncidence->uid() ); 00178 mCalendar->deleteIncidence( incidence ); 00179 } 00180 00181 QString History::EntryDelete::text() 00182 { 00183 return i18n("Delete %1").arg(mIncidence->type()); 00184 } 00185 00186 00187 History::EntryAdd::EntryAdd( Calendar *calendar, Incidence *incidence ) 00188 : Entry( calendar ), mIncidence( incidence->clone() ) 00189 { 00190 } 00191 00192 History::EntryAdd::~EntryAdd() 00193 { 00194 delete mIncidence; 00195 } 00196 00197 void History::EntryAdd::undo() 00198 { 00199 Incidence *incidence = mCalendar->incidence( mIncidence->uid() ); 00200 mCalendar->deleteIncidence( incidence ); 00201 } 00202 00203 void History::EntryAdd::redo() 00204 { 00205 mCalendar->addIncidence( mIncidence->clone() ); 00206 } 00207 00208 QString History::EntryAdd::text() 00209 { 00210 return i18n("Add %1").arg(mIncidence->type()); 00211 } 00212 00213 00214 History::EntryEdit::EntryEdit( Calendar *calendar, Incidence *oldIncidence, 00215 Incidence *newIncidence ) 00216 : Entry( calendar ), mOldIncidence( oldIncidence->clone() ), 00217 mNewIncidence( newIncidence->clone() ) 00218 { 00219 } 00220 00221 History::EntryEdit::~EntryEdit() 00222 { 00223 delete mOldIncidence; 00224 delete mNewIncidence; 00225 } 00226 00227 void History::EntryEdit::undo() 00228 { 00229 Incidence *incidence = mCalendar->incidence( mNewIncidence->uid() ); 00230 if ( incidence ) 00231 mCalendar->deleteIncidence( incidence ); 00232 mCalendar->addIncidence( mOldIncidence->clone() ); 00233 } 00234 00235 void History::EntryEdit::redo() 00236 { 00237 Incidence *incidence = mCalendar->incidence( mOldIncidence->uid() ); 00238 if ( incidence ) 00239 mCalendar->deleteIncidence( incidence ); 00240 mCalendar->addIncidence( mNewIncidence->clone() ); 00241 } 00242 00243 QString History::EntryEdit::text() 00244 { 00245 return i18n("Edit %1").arg(mNewIncidence->type()); 00246 } 00247 00248 History::MultiEntry::MultiEntry( Calendar *calendar, QString text ) 00249 : Entry( calendar ), mText( text ) 00250 { 00251 mEntries.setAutoDelete( true ); 00252 } 00253 00254 History::MultiEntry::~MultiEntry() 00255 { 00256 } 00257 00258 void History::MultiEntry::appendEntry( Entry* entry ) 00259 { 00260 mEntries.append( entry ); 00261 } 00262 00263 void History::MultiEntry::undo() 00264 { 00265 QPtrListIterator<Entry> it( mEntries ); 00266 it.toLast(); 00267 Entry *entry; 00268 while ( (entry = it.current()) != 0 ) { 00269 --it; 00270 entry->undo(); 00271 } 00272 } 00273 00274 void History::MultiEntry::redo() 00275 { 00276 QPtrListIterator<Entry> it( mEntries ); 00277 Entry *entry; 00278 while ( (entry = it.current()) != 0 ) { 00279 ++it; 00280 entry->redo(); 00281 } 00282 } 00283 00284 QString History::MultiEntry::text() 00285 { 00286 return mText; 00287 } 00288 00289 #include "history.moc"
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:53:20 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003