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 ), 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 if( incidence ) 00198 mCalendar->deleteIncidence( incidence ); 00199 mCalendar->addIncidence( mOldIncidence->clone() ); 00200 } 00201 00202 void History::EntryEdit::redo() 00203 { 00204 Incidence *incidence = mCalendar->incidence( mOldIncidence->uid() ); 00205 if( incidence ) 00206 mCalendar->deleteIncidence( incidence ); 00207 mCalendar->addIncidence( mNewIncidence->clone() ); 00208 } 00209 00210 QString History::EntryEdit::text() 00211 { 00212 return i18n("Edit %1").arg(mNewIncidence->type()); 00213 } 00214 00215 #include "history.moc"
KDE Logo
This file is part of the documentation for korganizer Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:12 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003