1 /* This file is part of the KDE project
2 Copyright (C) 2000 Simon Hausmann <hausmann@kde.org>
3 Copyright (C) 2006 David Faure <faure@kde.org>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
24 #include <QtCore/QStack>
25 #include <QUndoCommand>
27 struct KonqBasicOperation
29 typedef QStack
<KonqBasicOperation
> Stack
;
37 enum Type
{ File
, Link
, Directory
};
46 // ### I considered inheriting this from QUndoCommand.
47 // ### but since it is being copied by value in the code, we can't use that.
48 // Alternatively the data here should be contained into the QUndoCommand-subclass.
49 // This way we could copy the data in the manager code.
51 // ### also it would need to implement undo() itself (well, it can call the undomanager for it)
55 typedef QStack
<KonqCommand
> Stack
;
63 //KonqCommand( Type type, KonqBasicOperation::Stack& opStack, const KUrl::List& src, const KUrl& dest )
64 // : m_type( type ), m_opStack( opStack ), m_src( src ), m_dest( dest )
66 // // if using QUndoCommand: setText(...); // see code in KonqFileUndoManager::undoText()
69 //virtual void undo() {} // TODO
70 //virtual void redo() {} // TODO
72 // TODO: is ::TRASH missing?
73 bool isMoveCommand() const { return m_type
== KonqFileUndoManager::MOVE
|| m_type
== KonqFileUndoManager::RENAME
; }
77 KonqFileUndoManager::CommandType m_type
;
78 KonqBasicOperation::Stack m_opStack
;
81 quint64 m_serialNumber
;
84 // This class listens to a job, collects info while it's running (for copyjobs)
85 // and when the job terminates, on success, it calls addCommand in the undomanager.
86 class KonqCommandRecorder
: public QObject
90 KonqCommandRecorder( KonqFileUndoManager::CommandType op
, const KUrl::List
&src
, const KUrl
&dst
, KIO::Job
*job
);
91 virtual ~KonqCommandRecorder();
94 void slotResult( KJob
*job
);
96 void slotCopyingDone( KIO::Job
*, const KUrl
&from
, const KUrl
&to
, time_t, bool directory
, bool renamed
);
97 void slotCopyingLinkDone( KIO::Job
*, const KUrl
&from
, const QString
&target
, const KUrl
&to
);
103 QDataStream
&operator<<( QDataStream
&stream
, const KonqBasicOperation
&op
)
105 stream
<< op
.m_valid
<< (qint8
)op
.m_type
<< op
.m_renamed
106 << op
.m_src
<< op
.m_dst
<< op
.m_target
<< (qint64
)op
.m_mtime
;
109 QDataStream
&operator>>( QDataStream
&stream
, KonqBasicOperation
&op
)
113 stream
>> op
.m_valid
>> type
>> op
.m_renamed
114 >> op
.m_src
>> op
.m_dst
>> op
.m_target
>> mtime
;
115 op
.m_type
= static_cast<KonqBasicOperation::Type
>(type
);
120 QDataStream
&operator<<( QDataStream
&stream
, const KonqCommand
&cmd
)
122 stream
<< cmd
.m_valid
<< (qint8
)cmd
.m_type
<< cmd
.m_opStack
<< cmd
.m_src
<< cmd
.m_dst
;
126 QDataStream
&operator>>( QDataStream
&stream
, KonqCommand
&cmd
)
129 stream
>> cmd
.m_valid
>> type
>> cmd
.m_opStack
>> cmd
.m_src
>> cmd
.m_dst
;
130 cmd
.m_type
= static_cast<KonqFileUndoManager::CommandType
>( type
);
134 #endif /* KONQ_UNDO_P_H */