~ubuntu-branches/ubuntu/trusty/krusader/trusty

« back to all changes in this revision

Viewing changes to krusader/VFS/preserveattrcopyjob.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-08-08 13:47:36 UTC
  • mfrom: (1.2.19 upstream)
  • Revision ID: james.westby@ubuntu.com-20110808134736-8e630ivgd2c3sgg5
Tags: 1:2.4.0~beta1-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Krusader modifications:
2
 
//
3
 
// Replace: CopyJob -> PreserveAttrCopyJob
4
 
// Replace: COPYJOB -> PRESERVEATTRCOPYJOB
5
 
// Compile fixes
6
 
 
7
 
 
8
 
// -*- c++ -*-
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>
12
 
 
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.
17
 
 
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.
22
 
 
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.
27
 
*/
28
 
 
29
 
#ifndef PRESERVEATTRCOPYJOB_H
30
 
#define PRESERVEATTRCOPYJOB_H
31
 
 
32
 
#include <sys/types.h> // time_t
33
 
 
34
 
#include <QtCore/QObject>
35
 
#include <QtCore/QStringList>
36
 
 
37
 
#include <kurl.h>
38
 
#include <kio/jobclasses.h>
39
 
#include <kio/copyjob.h>
40
 
 
41
 
class QTimer;
42
 
 
43
 
enum DestinationState {
44
 
    DEST_NOT_STATED,
45
 
    DEST_IS_DIR,
46
 
    DEST_IS_FILE,
47
 
    DEST_DOESNT_EXIST
48
 
};
49
 
 
50
 
class Attributes
51
 
{
52
 
public:
53
 
    Attributes();
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);
56
 
 
57
 
    time_t   time;
58
 
    uid_t    uid;
59
 
    gid_t    gid;
60
 
    mode_t   mode;
61
 
    QString  acl;
62
 
};
63
 
 
64
 
/**
65
 
 * States:
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)
76
 
 *     done.
77
 
 */
78
 
enum PreserveAttrCopyJobState {
79
 
    STATE_STATING,
80
 
    STATE_RENAMING,
81
 
    STATE_LISTING,
82
 
    STATE_CREATING_DIRS,
83
 
    STATE_CONFLICT_CREATING_DIRS,
84
 
    STATE_COPYING_FILES,
85
 
    STATE_CONFLICT_COPYING_FILES,
86
 
    STATE_DELETING_DIRS,
87
 
    STATE_SETTING_DIR_ATTRIBUTES
88
 
};
89
 
 
90
 
namespace KIO
91
 
{
92
 
 
93
 
/**
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.
97
 
 *
98
 
 * @see KIO::copy()
99
 
 * @see KIO::copyAs()
100
 
 * @see KIO::move()
101
 
 * @see KIO::moveAs()
102
 
 * @see KIO::link()
103
 
 * @see KIO::linkAs()
104
 
 */
105
 
class PreserveAttrCopyJob : public Job
106
 
{
107
 
 
108
 
    Q_OBJECT
109
 
 
110
 
public:
111
 
    /**
112
 
     * Defines the mode of the operation
113
 
     */
114
 
    PreserveAttrCopyJob(const KUrl::List& src, const KUrl& dest, CopyJob::CopyMode mode, bool asMethod);
115
 
    virtual ~PreserveAttrCopyJob();
116
 
 
117
 
    /**
118
 
     * Returns the list of source URLs.
119
 
     * @return the list of source URLs.
120
 
     */
121
 
    KUrl::List srcUrls() const;
122
 
 
123
 
    /**
124
 
     * Returns the destination URL.
125
 
     * @return the destination URL
126
 
     */
127
 
    KUrl destUrl() const;
128
 
 
129
 
    /**
130
 
     * By default the permissions of the copied files will be those of the source files.
131
 
     *
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)
135
 
     */
136
 
    void setDefaultPermissions(bool b);
137
 
 
138
 
    /**
139
 
     * Reimplemented for internal reasons
140
 
     */
141
 
    virtual bool doSuspend();
142
 
 
143
 
signals:
144
 
 
145
 
    /**
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
149
 
    */
150
 
    void totalFiles(KJob *job, unsigned long files);
151
 
    /**
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
155
 
    */
156
 
    void totalDirs(KJob *job, unsigned long dirs);
157
 
 
158
 
    /**
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.
164
 
    */
165
 
    void aboutToCreate(KIO::Job *job, const QList<KIO::CopyInfo> &files);
166
 
 
167
 
    /**
168
 
    * Sends the number of processed files.
169
 
    * @param job the job that emitted this signal
170
 
    * @param files the number of processed files
171
 
    */
172
 
    void processedFiles(KIO::Job *job, unsigned long files);
173
 
    /**
174
 
    * Sends the number of processed directories.
175
 
    * @param job the job that emitted this signal
176
 
    * @param dirs the number of processed dirs
177
 
    */
178
 
    void processedDirs(KIO::Job *job, unsigned long dirs);
179
 
 
180
 
    /**
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
184
 
    *             being copied
185
 
    * @param dest the destination of the current operation
186
 
     */
187
 
    void copying(KIO::Job *job, const KUrl& src, const KUrl& dest);
188
 
    /**
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
192
 
    *             being linked
193
 
    * @param to the destination of the current operation
194
 
     */
195
 
    void linking(KIO::Job *job, const QString& target, const KUrl& to);
196
 
    /**
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
200
 
    *             being moved
201
 
    * @param to the destination of the current operation
202
 
     */
203
 
    void moving(KIO::Job *job, const KUrl& from, const KUrl& to);
204
 
    /**
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
208
 
     */
209
 
    void creatingDir(KIO::Job *job, const KUrl& dir);
210
 
    /**
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
215
 
     */
216
 
    void renamed(KIO::Job *job, const KUrl& from, const KUrl& to);
217
 
 
218
 
    /**
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.
221
 
    *
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
231
 
     */
232
 
    void copyingDone(KIO::Job *job, const KUrl &from, const KUrl &to, time_t mtime, bool directory, bool renamed);
233
 
    /**
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
241
 
     */
242
 
    void copyingLinkDone(KIO::Job *job, const KUrl &from, const QString& target, const KUrl& to);
243
 
protected Q_SLOTS:
244
 
    virtual void slotResult(KJob *job);
245
 
 
246
 
protected:
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.
251
 
    KUrl m_globalDest;
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)
257
 
    bool m_bURLDirty;
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;
262
 
 
263
 
    CopyJob::CopyMode m_mode;
264
 
    bool m_asMethod;
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;
271
 
    int m_processedDirs;
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;
280
 
    bool m_bOnlyRenames;
281
 
    KUrl m_dest;
282
 
    KUrl m_currentDest;
283
 
    //
284
 
    QStringList m_skipList;
285
 
    QStringList m_overwriteList;
286
 
    bool m_bAutoSkip;
287
 
    bool m_bOverwriteAll;
288
 
    int m_conflictError;
289
 
 
290
 
    QTimer *m_reportTimer;
291
 
    //these both are used for progress dialog reporting
292
 
    KUrl m_currentSrcURL;
293
 
    KUrl m_currentDestURL;
294
 
 
295
 
    QMap<KUrl, Attributes> fileAttributes;
296
 
    QList<KUrl>       directoriesToStamp;
297
 
    QList<KUrl>       originalDirectories;
298
 
 
299
 
public:
300
 
    void statCurrentSrc();
301
 
    void statNextSrc();
302
 
 
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);
312
 
    void copyNextFile();
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();
319
 
 
320
 
    void startRenameJob(const KUrl &slave_url);
321
 
    bool shouldOverwrite(const QString& path) const;
322
 
    bool shouldSkip(const QString& path) const;
323
 
    void skipSrc();
324
 
 
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);
328
 
 
329
 
public slots:
330
 
    void slotStart();
331
 
    void slotEntries(KIO::Job*, const KIO::UDSEntryList& list);
332
 
    void slotFinished();
333
 
    /**
334
 
     * Forward signal from subjob
335
 
     */
336
 
    void slotProcessedSize(KJob*, qulonglong data_size);
337
 
    /**
338
 
     * Forward signal from subjob
339
 
     * @param size the total size
340
 
     */
341
 
    void slotTotalSize(KJob*, qulonglong size);
342
 
 
343
 
    void slotReport();
344
 
};
345
 
}
346
 
 
347
 
#endif