korganizer

history.h
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of TQt, and distribute the resulting executable,
00022     without including the source code for TQt in the source distribution.
00023 */
00024 #ifndef KORG_HISTORY_H
00025 #define KORG_HISTORY_H
00026 
00027 #include <tqobject.h>
00028 #include <tqptrlist.h>
00029 
00030 namespace KCal {
00031 
00032 class Calendar;
00033 class Incidence;
00034 
00035 }
00036 
00037 namespace KOrg {
00038 
00039 class History : public TQObject
00040 {
00041     Q_OBJECT
00042   
00043   public:
00044     History( KCal::Calendar * );
00045 
00046     void recordDelete( KCal::Incidence * );
00047     void recordAdd( KCal::Incidence * );
00048     void recordEdit( KCal::Incidence *oldIncidence,
00049                      KCal::Incidence *newIncidence );
00050     void startMultiModify( const TQString &description );
00051     void endMultiModify();
00052 
00053   public slots:
00054     void undo();
00055     void redo();
00056 
00057   signals:
00058     void undone();
00059     void redone();
00060 
00061     void undoAvailable( const TQString & );
00062     void redoAvailable( const TQString & );
00063 
00064   protected:
00065     void truncate();
00066 
00067   private:
00068   
00069     class Entry
00070     {
00071       public:
00072         Entry( KCal::Calendar * );
00073         virtual ~Entry();
00074     
00075         virtual void undo() = 0;
00076         virtual void redo() = 0;
00077 
00078         virtual TQString text() = 0;
00079 
00080       protected:
00081         KCal::Calendar *mCalendar;
00082     };
00083 
00084     class EntryDelete : public Entry
00085     {
00086       public:
00087         EntryDelete( KCal::Calendar *, KCal::Incidence * );
00088         ~EntryDelete();
00089         
00090         void undo();
00091         void redo();
00092     
00093         TQString text();
00094     
00095       private:
00096         KCal::Incidence *mIncidence;
00097     };
00098 
00099     class EntryAdd : public Entry
00100     {
00101       public:
00102         EntryAdd( KCal::Calendar *, KCal::Incidence * );
00103         ~EntryAdd();
00104         
00105         void undo();
00106         void redo();
00107 
00108         TQString text();
00109 
00110       private:
00111         KCal::Incidence *mIncidence;
00112     };
00113     
00114     class EntryEdit : public Entry
00115     {
00116       public:
00117         EntryEdit( KCal::Calendar *calendar, KCal::Incidence *oldIncidence,
00118                    KCal::Incidence *newIncidence );
00119         ~EntryEdit();
00120         
00121         void undo();
00122         void redo();
00123       
00124         TQString text();
00125       
00126       private:
00127         KCal::Incidence *mOldIncidence;
00128         KCal::Incidence *mNewIncidence;
00129     };
00130 
00131     class MultiEntry : public Entry
00132     {
00133       public:
00134         MultiEntry( KCal::Calendar *calendar, const TQString &text );
00135         ~MultiEntry();
00136         
00137         void appendEntry( Entry* entry );
00138         void undo();
00139         void redo();
00140       
00141         TQString text();
00142       
00143       private:
00144         TQPtrList<Entry> mEntries;
00145         TQString mText;
00146     };
00147 
00148     KCal::Calendar *mCalendar;
00149     MultiEntry *mCurrentMultiEntry;
00150 
00151     TQPtrList<Entry> mEntries;
00152     TQPtrListIterator<Entry> mUndoEntry;
00153     TQPtrListIterator<Entry> mRedoEntry;
00154 };
00155 
00156 }
00157 #endif