konq_undo.h
00001 /* This file is part of the KDE project 00002 Copyright (C) 2000 Simon Hausmann <hausmann@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 #ifndef __konq_undo_h__ 00020 #define __konq_undo_h__ 00021 00022 #include <tqobject.h> 00023 #include <tqstring.h> 00024 #include <tqvaluestack.h> 00025 00026 #include <dcopobject.h> 00027 00028 #include <kurl.h> 00029 #include <libkonq_export.h> 00030 00031 namespace KIO 00032 { 00033 class Job; 00034 } 00035 00036 class KonqUndoJob; 00037 00038 struct KonqBasicOperation 00039 { 00040 typedef TQValueStack<KonqBasicOperation> Stack; 00041 00042 KonqBasicOperation() 00043 { m_valid = false; } 00044 00045 bool m_valid; 00046 bool m_directory; 00047 bool m_renamed; 00048 bool m_link; 00049 KURL m_src; 00050 KURL m_dst; 00051 TQString m_target; 00052 }; 00053 00054 struct KonqCommand 00055 { 00056 typedef TQValueStack<KonqCommand> Stack; 00057 00058 enum Type { COPY, MOVE, LINK, MKDIR, TRASH }; 00059 00060 KonqCommand() 00061 { m_valid = false; } 00062 00063 bool m_valid; 00064 00065 Type m_type; 00066 KonqBasicOperation::Stack m_opStack; 00067 KURL::List m_src; 00068 KURL m_dst; 00069 }; 00070 00071 class KonqCommandRecorder : public TQObject 00072 { 00073 Q_OBJECT 00074 public: 00075 KonqCommandRecorder( KonqCommand::Type op, const KURL::List &src, const KURL &dst, KIO::Job *job ); 00076 virtual ~KonqCommandRecorder(); 00077 00078 private slots: 00079 void slotResult( KIO::Job *job ); 00080 00081 void slotCopyingDone( KIO::Job *, const KURL &from, const KURL &to, bool directory, bool renamed ); 00082 void slotCopyingLinkDone( KIO::Job *, const KURL &from, const TQString &target, const KURL &to ); 00083 00084 private: 00085 class KonqCommandRecorderPrivate; 00086 KonqCommandRecorderPrivate *d; 00087 }; 00088 00089 class LIBKONQ_EXPORT KonqUndoManager : public TQObject, public DCOPObject 00090 { 00091 Q_OBJECT 00092 K_DCOP 00093 friend class KonqUndoJob; 00094 public: 00095 enum UndoState { MAKINGDIRS, MOVINGFILES, REMOVINGDIRS, REMOVINGFILES }; 00096 00097 KonqUndoManager(); 00098 virtual ~KonqUndoManager(); 00099 00100 static void incRef(); 00101 static void decRef(); 00102 static KonqUndoManager *self(); 00103 00104 void addCommand( const KonqCommand &cmd ); 00105 00106 bool undoAvailable() const; 00107 TQString undoText() const; 00108 00109 public slots: 00110 void undo(); 00111 00112 signals: 00113 void undoAvailable( bool avail ); 00114 void undoTextChanged( const TQString &text ); 00115 00116 protected: 00120 void stopUndo( bool step ); 00121 00122 private: 00123 k_dcop: 00124 virtual ASYNC push( const KonqCommand &cmd ); 00125 virtual ASYNC pop(); 00126 virtual ASYNC lock(); 00127 virtual ASYNC unlock(); 00128 00129 virtual KonqCommand::Stack get() const; 00130 00131 private slots: 00132 void slotResult( KIO::Job *job ); 00133 00134 private: 00135 void undoStep(); 00136 00137 void undoMakingDirectories(); 00138 void undoMovingFiles(); 00139 void undoRemovingFiles(); 00140 void undoRemovingDirectories(); 00141 00142 void broadcastPush( const KonqCommand &cmd ); 00143 void broadcastPop(); 00144 void broadcastLock(); 00145 void broadcastUnlock(); 00146 00147 void addDirToUpdate( const KURL& url ); 00148 bool initializeFromKDesky(); 00149 00150 class KonqUndoManagerPrivate; 00151 KonqUndoManagerPrivate *d; 00152 static KonqUndoManager *s_self; 00153 static unsigned long s_refCnt; 00154 }; 00155 00156 TQDataStream &operator<<( TQDataStream &stream, const KonqBasicOperation &op ); 00157 TQDataStream &operator>>( TQDataStream &stream, KonqBasicOperation &op ); 00158 00159 TQDataStream &operator<<( TQDataStream &stream, const KonqCommand &cmd ); 00160 TQDataStream &operator>>( TQDataStream &stream, KonqCommand &cmd ); 00161 00162 #endif