1
// Krusader modifications:
3
// Replace: CopyJob -> PreserveAttrCopyJob
4
// Replace: COPYJOB -> PRESERVEATTRCOPYJOB
9
/* This file is part of the KDE libraries
10
Copyright 2000 Stephan Kulow <coolo@kde.org>
11
Copyright 2000-2006 David Faure <faure@kde.org>
13
This library is free software; you can redistribute it and/or
14
modify it under the terms of the GNU Library General Public
15
License as published by the Free Software Foundation; either
16
version 2 of the License, or (at your option) any later version.
18
This library is distributed in the hope that it will be useful,
19
but WITHOUT ANY WARRANTY; without even the implied warranty of
20
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21
Library General Public License for more details.
23
You should have received a copy of the GNU Library General Public License
24
along with this library; see the file COPYING.LIB. If not, write to
25
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26
Boston, MA 02110-1301, USA.
29
#ifndef PRESERVEATTRCOPYJOB_H
30
#define PRESERVEATTRCOPYJOB_H
32
#include <sys/types.h> // time_t
34
#include <QtCore/QObject>
35
#include <QtCore/QStringList>
38
#include <kio/jobclasses.h>
39
#include <kio/copyjob.h>
43
enum DestinationState {
54
Attributes(time_t tIn, uid_t uIn, gid_t gIn, mode_t modeIn, const QString & aclIn);
55
Attributes(time_t tIn, QString user, QString group, mode_t modeIn, const QString & aclIn);
66
* STATE_STATING for the dest
67
* STATE_STATING for each src url (statNextSrc)
68
* for each: if dir -> STATE_LISTING (filling 'd->dirs' and 'd->files')
69
* but if direct rename possible: STATE_RENAMING instead.
70
* STATE_CREATING_DIRS (createNextDir, iterating over 'd->dirs')
71
* if conflict: STATE_CONFLICT_CREATING_DIRS
72
* STATE_COPYING_FILES (copyNextFile, iterating over 'd->files')
73
* if conflict: STATE_CONFLICT_COPYING_FILES
74
* STATE_DELETING_DIRS (deleteNextDir) (if moving)
75
* STATE_SETTING_DIR_ATTRIBUTES (setNextDirAttribute, iterating over d->m_directoriesCopied)
78
enum PreserveAttrCopyJobState {
83
STATE_CONFLICT_CREATING_DIRS,
85
STATE_CONFLICT_COPYING_FILES,
87
STATE_SETTING_DIR_ATTRIBUTES
94
* PreserveAttrCopyJob is used to move, copy or symlink files and directories.
95
* Don't create the job directly, but use KIO::copy(),
96
* KIO::move(), KIO::link() and friends.
105
class PreserveAttrCopyJob : public Job
112
* Defines the mode of the operation
114
PreserveAttrCopyJob(const KUrl::List& src, const KUrl& dest, CopyJob::CopyMode mode, bool asMethod);
115
virtual ~PreserveAttrCopyJob();
118
* Returns the list of source URLs.
119
* @return the list of source URLs.
121
KUrl::List srcUrls() const;
124
* Returns the destination URL.
125
* @return the destination URL
127
KUrl destUrl() const;
130
* By default the permissions of the copied files will be those of the source files.
132
* But when copying "template" files to "new" files, people prefer the umask
133
* to apply, rather than the template's permissions.
134
* For that case, call setDefaultPermissions(true)
136
void setDefaultPermissions(bool b);
139
* Reimplemented for internal reasons
141
virtual bool doSuspend();
146
* Emitted when the total number of files is known.
147
* @param job the job that emitted this signal
148
* @param files the total number of files
150
void totalFiles(KJob *job, unsigned long files);
152
* Emitted when the toal number of direcotries is known.
153
* @param job the job that emitted this signal
154
* @param dirs the total number of directories
156
void totalDirs(KJob *job, unsigned long dirs);
159
* Emitted when it is known which files / directories are going
160
* to be created. Note that this may still change e.g. when
161
* existing files with the same name are discovered.
162
* @param job the job that emitted this signal
163
* @param files a list of items that are about to be created.
165
void aboutToCreate(KIO::Job *job, const QList<KIO::CopyInfo> &files);
168
* Sends the number of processed files.
169
* @param job the job that emitted this signal
170
* @param files the number of processed files
172
void processedFiles(KIO::Job *job, unsigned long files);
174
* Sends the number of processed directories.
175
* @param job the job that emitted this signal
176
* @param dirs the number of processed dirs
178
void processedDirs(KIO::Job *job, unsigned long dirs);
181
* The job is copying a file or directory.
182
* @param job the job that emitted this signal
183
* @param src the URL of the file or directory that is currently
185
* @param dest the destination of the current operation
187
void copying(KIO::Job *job, const KUrl& src, const KUrl& dest);
189
* The job is creating a symbolic link.
190
* @param job the job that emitted this signal
191
* @param target the URL of the file or directory that is currently
193
* @param to the destination of the current operation
195
void linking(KIO::Job *job, const QString& target, const KUrl& to);
197
* The job is moving a file or directory.
198
* @param job the job that emitted this signal
199
* @param from the URL of the file or directory that is currently
201
* @param to the destination of the current operation
203
void moving(KIO::Job *job, const KUrl& from, const KUrl& to);
205
* The job is creating the directory @p dir.
206
* @param job the job that emitted this signal
207
* @param dir the directory that is currently being created
209
void creatingDir(KIO::Job *job, const KUrl& dir);
211
* The user chose to rename @p from to @p to.
212
* @param job the job that emitted this signal
213
* @param from the original name
214
* @param to the new name
216
void renamed(KIO::Job *job, const KUrl& from, const KUrl& to);
219
* The job emits this signal when copying or moving a file or directory successfully finished.
220
* This signal is mainly for the Undo feature.
222
* @param job the job that emitted this signal
223
* @param from the source URL
224
* @param to the destination URL
225
* @param mtime the modification time of the source file, hopefully set on the destination file
226
* too (when the kioslave supports it).
227
* @param directory indicates whether a file or directory was successfully copied/moved.
228
* true for a directory, false for file
229
* @param renamed indicates that the destination URL was created using a
230
* rename operation (i.e. fast directory moving). true if is has been renamed
232
void copyingDone(KIO::Job *job, const KUrl &from, const KUrl &to, time_t mtime, bool directory, bool renamed);
234
* The job is copying or moving a symbolic link, that points to target.
235
* The new link is created in @p to. The existing one is/was in @p from.
236
* This signal is mainly for the Undo feature.
237
* @param job the job that emitted this signal
238
* @param from the source URL
239
* @param target the target
240
* @param to the destination URL
242
void copyingLinkDone(KIO::Job *job, const KUrl &from, const QString& target, const KUrl& to);
244
virtual void slotResult(KJob *job);
247
// This is the dest URL that was initially given to PreserveAttrCopyJob
248
// It is copied into m_dest, which can be changed for a given src URL
249
// (when using the RENAME dialog in slotResult),
250
// and which will be reset for the next src URL.
252
// The state info about that global dest
253
DestinationState m_globalDestinationState;
254
// See setDefaultPermissions
255
bool m_defaultPermissions;
256
// Whether URLs changed (and need to be emitted by the next slotReport call)
258
// Used after copying all the files into the dirs, to set mtime (TODO: and permissions?)
259
// after the copy is done
260
QLinkedList<CopyInfo> m_directoriesCopied;
261
QLinkedList<CopyInfo>::const_iterator m_directoriesCopiedIterator;
263
CopyJob::CopyMode m_mode;
265
DestinationState destinationState;
266
PreserveAttrCopyJobState state;
267
KIO::filesize_t m_totalSize;
268
KIO::filesize_t m_processedSize;
269
KIO::filesize_t m_fileProcessedSize;
270
int m_processedFiles;
272
QList<CopyInfo> files;
273
QList<CopyInfo> dirs;
274
KUrl::List dirsToRemove;
275
KUrl::List m_srcList;
276
KUrl::List::Iterator m_currentStatSrc;
277
bool m_bCurrentSrcIsDir;
278
bool m_bCurrentOperationIsLink;
279
bool m_bSingleFileCopy;
284
QStringList m_skipList;
285
QStringList m_overwriteList;
287
bool m_bOverwriteAll;
290
QTimer *m_reportTimer;
291
//these both are used for progress dialog reporting
292
KUrl m_currentSrcURL;
293
KUrl m_currentDestURL;
295
QMap<KUrl, Attributes> fileAttributes;
296
QList<KUrl> directoriesToStamp;
297
QList<KUrl> originalDirectories;
300
void statCurrentSrc();
303
// Those aren't slots but submethods for slotResult.
304
void slotResultStating(KJob * job);
305
void startListing(const KUrl & src);
306
void slotResultCreatingDirs(KJob * job);
307
void slotResultConflictCreatingDirs(KJob * job);
308
void createNextDir();
309
void slotResultCopyingFiles(KJob * job);
310
void slotResultConflictCopyingFiles(KJob * job);
311
KIO::Job* linkNextFile(const KUrl& uSource, const KUrl& uDest, JobFlags flags);
313
void slotResultDeletingDirs(KJob * job);
314
void deleteNextDir();
315
void skip(const KUrl & sourceURL);
316
void slotResultRenaming(KJob * job);
317
void slotResultSettingDirAttributes(KJob * job);
318
void setNextDirAttribute();
320
void startRenameJob(const KUrl &slave_url);
321
bool shouldOverwrite(const QString& path) const;
322
bool shouldSkip(const QString& path) const;
325
void saveEntries(KIO::Job*, const KIO::UDSEntryList &list);
326
void slotAboutToCreate(const QList< KIO::CopyInfo > &files);
327
void slotCopyingDone(const KUrl &from, const KUrl &to, bool postpone);
331
void slotEntries(KIO::Job*, const KIO::UDSEntryList& list);
334
* Forward signal from subjob
336
void slotProcessedSize(KJob*, qulonglong data_size);
338
* Forward signal from subjob
339
* @param size the total size
341
void slotTotalSize(KJob*, qulonglong size);