Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / apps / lib / konq / konq_fileundomanager.h
blob32c8725925cd45885c12f9c58bf8939199dff17a
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.
20 #ifndef KONQ_FILEUNDOMANAGER_H
21 #define KONQ_FILEUNDOMANAGER_H
23 #include <QtCore/QObject>
24 #include <kurl.h>
25 #include <sys/types.h> // time_t
27 #include <libkonq_export.h>
29 namespace KIO
31 class Job;
33 struct KonqBasicOperation;
34 class KonqCommand;
35 class KonqUndoJob;
36 class KJob;
38 /**
39 * KonqFileUndoManager: makes it possible to undo kio jobs.
40 * This class is a singleton, use self() to access its only instance.
42 class LIBKONQ_EXPORT KonqFileUndoManager : public QObject
44 Q_OBJECT
45 public:
46 virtual ~KonqFileUndoManager();
48 static void incRef();
49 static void decRef();
50 static KonqFileUndoManager *self();
52 // Interface for the gui handling of KonqFileUndoManager
53 class LIBKONQ_EXPORT UiInterface
55 public:
56 UiInterface( QWidget* );
57 virtual ~UiInterface() {}
59 void setShowProgressInfo( bool b ) { m_showProgressInfo = b; }
60 bool showProgressInfo() const { return m_showProgressInfo; }
62 /**
63 * Called when an undo job errors; default implementation displays a message box.
65 virtual void jobError( KIO::Job* job );
67 /**
68 * Called when we are about to remove those files.
69 * Return true if we should proceed with deleting them.
71 virtual bool confirmDeletion( const KUrl::List& files );
73 /**
74 * Called when dest was modified since it was copied from src.
75 * Note that this is called after confirmDeletion.
76 * Return true if we should proceed with deleting dest.
78 virtual bool copiedFileWasModified( const KUrl& src, const KUrl& dest, time_t srcTime, time_t destTime );
79 private:
80 QWidget* m_parentWidget;
81 bool m_showProgressInfo;
84 /**
85 * Set a new UiInterface implementation.
86 * This deletes the previous one.
88 void setUiInterface( UiInterface* ui );
90 enum CommandType { COPY, MOVE, RENAME, LINK, MKDIR, TRASH };
92 /**
93 * Record this job while it's happening and add a command for it so that the user can undo it.
94 * @param op the type of job - which is also the type of command that will be created for it
95 * @param src list of source urls
96 * @param dst destination url
97 * @param job the job to record
99 void recordJob( CommandType op, const KUrl::List &src, const KUrl &dst, KIO::Job *job );
101 bool undoAvailable() const;
102 QString undoText() const;
105 * These two functions are useful when wrapping KonqFileUndoManager and adding custom commands.
106 * Each command has a unique ID. You can get a new serial number for a custom command
107 * with newCommandSerialNumber(), and then when you want to undo, check if the command
108 * KonqFileUndoManager would undo is newer or older than your custom command.
110 quint64 newCommandSerialNumber();
111 quint64 currentCommandSerialNumber();
113 public Q_SLOTS:
114 // TODO: add QWidget* parameter for error boxes
115 /// Undoes the last command
116 void undo();
118 /// @internal called by KonqFileUndoManagerAdaptor
119 QByteArray get() const;
121 Q_SIGNALS:
122 /// Emitted when the value of undoAvailable() changes
123 void undoAvailable( bool avail );
125 /// Emitted when the value of undoText() changes
126 void undoTextChanged( const QString &text );
128 /// Emitted when an undo job finishes. Used for unit testing.
129 void undoJobFinished();
131 // The four signals below are emitted to DBus
132 void push( const QByteArray &command );
133 void pop();
134 void lock();
135 void unlock();
137 private Q_SLOTS:
138 // Those four are connected to DBUS signals
139 void slotPush( QByteArray command ); // const ref doesn't work due to QDataStream
140 void slotPop();
141 void slotLock();
142 void slotUnlock();
144 private Q_SLOTS:
145 void slotResult( KJob *job );
147 private:
148 KonqFileUndoManager();
150 friend class KonqUndoJob;
151 /// called by KonqUndoJob
152 void stopUndo( bool step );
154 friend class KonqCommandRecorder;
155 /// called by KonqCommandRecorder
156 void addCommand( const KonqCommand &cmd );
158 void pushCommand( const KonqCommand& cmd );
159 void undoStep();
161 void stepMakingDirectories();
162 void stepMovingFiles();
163 void stepRemovingLinks();
164 void stepRemovingDirectories();
166 void broadcastPush( const KonqCommand &cmd );
167 void broadcastPop();
168 void broadcastLock();
169 void broadcastUnlock();
171 void addDirToUpdate( const KUrl& url );
172 bool initializeFromKDesky();
174 class KonqFileUndoManagerPrivate;
175 KonqFileUndoManagerPrivate *d;
176 static KonqFileUndoManager *s_self;
179 #endif