libkonq Library API Documentation

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., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
00018 */
00019 #ifndef __konq_undo_h__
00020 #define __konq_undo_h__
00021 
00022 #include <qobject.h>
00023 #include <qstring.h>
00024 #include <qvaluestack.h>
00025 
00026 #include <dcopobject.h>
00027 
00028 #include <kurl.h>
00029 
00030 #include <libkonq_export.h>
00031 
00032 namespace KIO
00033 {
00034   class Job;
00035 }
00036 
00037 class KonqUndoJob;
00038 
00039 struct KonqBasicOperation
00040 {
00041   typedef QValueStack<KonqBasicOperation> Stack;
00042 
00043   KonqBasicOperation()
00044   { m_valid = false; }
00045 
00046   bool m_valid;
00047   bool m_directory;
00048   bool m_renamed;
00049   bool m_link;
00050   KURL m_src;
00051   KURL m_dst;
00052   QString m_target;
00053 };
00054 
00055 struct KonqCommand
00056 {
00057   typedef QValueStack<KonqCommand> Stack;
00058 
00059   enum Type { COPY, MOVE, LINK, MKDIR };
00060 
00061   KonqCommand()
00062   { m_valid = false; }
00063 
00064   bool m_valid;
00065 
00066   Type m_type;
00067   KonqBasicOperation::Stack m_opStack;
00068   KURL::List m_src;
00069   KURL m_dst;
00070 };
00071 
00072 class KonqCommandRecorder : public QObject
00073 {
00074   Q_OBJECT
00075 public:
00076   KonqCommandRecorder( KonqCommand::Type op, const KURL::List &src, const KURL &dst, KIO::Job *job );
00077   virtual ~KonqCommandRecorder();
00078 
00079 private slots:
00080   void slotResult( KIO::Job *job );
00081 
00082   void slotCopyingDone( KIO::Job *, const KURL &from, const KURL &to, bool directory, bool renamed );
00083   void slotCopyingLinkDone( KIO::Job *, const KURL &from, const QString &target, const KURL &to );
00084 
00085 private:
00086   class KonqCommandRecorderPrivate;
00087   KonqCommandRecorderPrivate *d;
00088 };
00089 
00090 class LIBKONQ_EXPORT KonqUndoManager : public QObject, public DCOPObject
00091 {
00092   Q_OBJECT
00093   K_DCOP
00094   friend class KonqUndoJob;
00095 public:
00096   enum UndoState { MAKINGDIRS, MOVINGFILES, REMOVINGDIRS, REMOVINGFILES };
00097 
00098   KonqUndoManager();
00099   virtual ~KonqUndoManager();
00100 
00101   static void incRef();
00102   static void decRef();
00103   static KonqUndoManager *self();
00104 
00105   void addCommand( const KonqCommand &cmd );
00106 
00107   bool undoAvailable() const;
00108   QString undoText() const;
00109 
00110 public slots:
00111   void undo();
00112 
00113 signals:
00114   void undoAvailable( bool avail );
00115   void undoTextChanged( const QString &text );
00116 
00117 protected:
00121   void stopUndo( bool step );
00122 
00123 private:
00124 k_dcop:
00125   virtual ASYNC push( const KonqCommand &cmd );
00126   virtual ASYNC pop();
00127   virtual ASYNC lock();
00128   virtual ASYNC unlock();
00129 
00130   virtual KonqCommand::Stack get() const;
00131 
00132 private slots:
00133   void slotResult( KIO::Job *job );
00134 
00135 private:
00136   void undoStep();
00137 
00138   void undoMakingDirectories();
00139   void undoMovingFiles();
00140   void undoRemovingFiles();
00141   void undoRemovingDirectories();
00142 
00143   void broadcastPush( const KonqCommand &cmd );
00144   void broadcastPop();
00145   void broadcastLock();
00146   void broadcastUnlock();
00147 
00148   bool initializeFromKDesky();
00149 
00150   class KonqUndoManagerPrivate;
00151   KonqUndoManagerPrivate *d;
00152   static KonqUndoManager *s_self;
00153   static unsigned long s_refCnt;
00154 };
00155 
00156 QDataStream &operator<<( QDataStream &stream, const KonqBasicOperation &op );
00157 QDataStream &operator>>( QDataStream &stream, KonqBasicOperation &op );
00158 
00159 QDataStream &operator<<( QDataStream &stream, const KonqCommand &cmd );
00160 QDataStream &operator>>( QDataStream &stream, KonqCommand &cmd );
00161 
00162 #endif
KDE Logo
This file is part of the documentation for libkonq Library Version 3.3.90.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Apr 4 11:21:34 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003