8a159c7821616a536684ba5657f781e12f2bf4e5
[case] / src / fileoperator.cpp
1 // case - file manager for N900
2 // Copyright (C) 2010 Lukas Hrazky <lukkash@email.cz>
3 // 
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 // 
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 // 
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17
18 #include "fileoperator.h"
19
20 #include <QtGui>
21 #include <QDir>
22 #include <QMessageBox>
23 #include <QHBoxLayout>
24 #include <QChar>
25
26 #include <math.h>
27 #include <errno.h>
28 #include <iostream>
29
30
31 #define BLOCK_SIZE 524288
32
33
34 #define SHOW_ERROR_PROMPT(promptString, fileName)                                           \
35     response = FileOperator::NONE;                                                          \
36     if (ignoreAll[errno]) {                                                                 \
37         response = FileOperator::IGNORE;                                                    \
38     } else {                                                                                \
39         char buf[255];                                                                      \
40         char *realBuf = strerror_r(errno, buf, 255);                                        \
41         emit showErrorPrompt(this, promptString + " " + realBuf + ".", fileName, errno);    \
42         waitCond.wait(&mutex);                                                              \
43     }
44
45
46 #define ERROR_PROMPT(operation, promptString, fileName)                                     \
47 {                                                                                           \
48     response = FileOperator::NONE;                                                          \
49     while (!abort && operation) {                                                           \
50         SHOW_ERROR_PROMPT(promptString, fileName)                                           \
51         if (response == FileOperator::IGNORE) {                                             \
52             break;                                                                          \
53         }                                                                                   \
54     }                                                                                       \
55 }
56
57
58 #define SPECIAL_COPY_ERROR_PROMPT(operation, promptString, fileName)                        \
59 {                                                                                           \
60     ERROR_PROMPT(operation, promptString, fileName)                                         \
61     if (abort || response == FileOperator::IGNORE) {                                        \
62         if (!abort) {                                                                       \
63             updateProgress(fileSizeMap[path]);                                              \
64             removeExcludeFiles.insert(path);                                                \
65         }                                                                                   \
66         return;                                                                             \
67     }                                                                                       \
68 }
69
70
71 #define OVERWRITE_PROMPT(file, newFile)                                                     \
72 {                                                                                           \
73     response = FileOperator::NONE;                                                          \
74                                                                                             \
75     if (newFile.exists()) {                                                                 \
76         if (overwriteAll != FileOperator::NONE) {                                           \
77             response = overwriteAll;                                                        \
78         } else {                                                                            \
79             bool dirOverDir = false;                                                        \
80             if (newFile.isDir() && file.isDir()) dirOverDir = true;                         \
81             emit showOverwritePrompt(this, newFile.absoluteFilePath(), dirOverDir);         \
82             waitCond.wait(&mutex);                                                          \
83         }                                                                                   \
84     }                                                                                       \
85 }
86
87
88 FileOperator::FileOperator(QWidget *parent) : QWidget(parent) {
89     QHBoxLayout *layout = new QHBoxLayout;
90     layout->setContentsMargins(0, 0, 0, 0);
91     layout->setSpacing(0);
92     setLayout(layout);
93 }
94
95
96 QString FileOperator::shortenPath(const QString &path) {
97     QString homePath = QFSFileEngine::homePath();
98     QString result = path;
99     if (path.indexOf(homePath, 0) == 0) {
100         result.replace(0, homePath.size(), "~");
101     }
102
103     return result;
104 }
105
106
107 void FileOperator::deleteFiles(const QFileInfoList &files) {
108     QString title, desc;
109     if (files.size() == 1) {
110         title = tr("Delete file");
111         desc = tr("Are you sure you want to delete %1?")
112             .arg(FileOperator::shortenPath(files[0].absoluteFilePath()));
113     } else {
114         title = tr("Delete files");
115         desc = tr("You are about to delete %1 files. Are you sure you want to continue?").arg(files.size());
116     }
117
118     int confirm = QMessageBox::warning(
119         0,
120         title,
121         desc,
122         QMessageBox::Yes,
123         QMessageBox::No
124     );
125
126     if(confirm == QMessageBox::Yes) {
127         caterNewThread(new DeleteThread(files));
128     }
129 }
130
131
132 void FileOperator::copyFiles(const QFileInfoList &files, QDir &destination) {
133     QString title, desc;
134     if (files.size() == 1) {
135         title = tr("Copy file");
136         desc = tr("Are you sure you want to copy %1 to %2?")
137             .arg(FileOperator::shortenPath(files[0].absoluteFilePath()))
138             .arg(FileOperator::shortenPath(destination.absolutePath()));
139     } else {
140         title = tr("Copy files");
141         desc = tr("You are about to copy %1 files to %2. Are you sure you want to continue?")
142             .arg(files.size()).arg(FileOperator::shortenPath(destination.absolutePath()));
143     }
144
145     int confirm = QMessageBox::warning(
146         0,
147         title,
148         desc,
149         QMessageBox::Yes,
150         QMessageBox::No
151     );
152
153     if(confirm == QMessageBox::Yes) {
154         caterNewThread(new CopyThread(files, destination));
155     }
156 }
157
158
159 void FileOperator::moveFiles(const QFileInfoList &files, QDir &destination) {
160     // for move we don't wanna move to the same dir
161     if (files[0].absolutePath() == destination.absolutePath()) return;
162
163     QString title, desc;
164     if (files.size() == 1) {
165         title = tr("Move file");
166         desc = tr("Are you sure you want to move %1 to %2?")
167             .arg(FileOperator::shortenPath(files[0].absoluteFilePath()))
168             .arg(FileOperator::shortenPath(destination.absolutePath()));
169     } else {
170         title = tr("Move files");
171         desc = tr("You are about to move %1 files to %2. Are you sure you want to continue?")
172             .arg(files.size()).arg(FileOperator::shortenPath(destination.absolutePath()));
173     }
174
175     int confirm = QMessageBox::warning(
176         0,
177         title,
178         desc,
179         QMessageBox::Yes,
180         QMessageBox::No
181     );
182
183     if(confirm == QMessageBox::Yes) {
184         caterNewThread(new MoveThread(files, destination));
185     }
186 }
187
188
189 void FileOperator::showErrorPrompt(FileManipulatorThread* manipulator,
190     const QString &message,
191     const QString &fileName,
192     const int err)
193 {
194     QMessageBox msgBox;
195     msgBox.addButton(QMessageBox::Cancel);
196     QAbstractButton *abortButton = msgBox.addButton(tr("Abort"), QMessageBox::DestructiveRole);
197     QAbstractButton *retryButton = msgBox.addButton(QMessageBox::Retry);
198     QAbstractButton *ignoreButton = msgBox.addButton(QMessageBox::Ignore);
199     QAbstractButton *ignoreAllButton = msgBox.addButton(tr("Ignore All"), QMessageBox::AcceptRole);
200     msgBox.setText(message.arg(FileOperator::shortenPath(fileName)));
201
202     msgBox.exec();
203
204     if (msgBox.clickedButton() == abortButton) {
205         manipulator->setResponse(ABORT);
206     } else if (msgBox.clickedButton() == retryButton) {
207         manipulator->setResponse(RETRY);
208     } else if (msgBox.clickedButton() == ignoreButton) {
209         manipulator->setResponse(IGNORE);
210     } else if (msgBox.clickedButton() == ignoreAllButton) {
211         manipulator->setResponse(IGNORE, true, err);
212     }
213 }
214
215
216 void FileOperator::showOverwritePrompt(
217     FileManipulatorThread* manipulator,
218     const QString &fileName,
219     const bool dirOverDir)
220 {
221     QMessageBox msgBox;
222     msgBox.addButton(QMessageBox::Cancel);
223     QAbstractButton *yesButton = msgBox.addButton(QMessageBox::Yes);
224     QAbstractButton *yesToAllButton = msgBox.addButton(QMessageBox::YesToAll);
225     QAbstractButton *noButton = msgBox.addButton(QMessageBox::No);
226     QAbstractButton *noToAllButton = msgBox.addButton(QMessageBox::NoToAll);
227     QAbstractButton *abortButton = msgBox.addButton(tr("Abort"), QMessageBox::DestructiveRole);
228     QAbstractButton *askButton = 0;
229
230     if (dirOverDir) {
231         msgBox.setText(tr("Directory %1 already exists. Overwrite the files inside?")
232             .arg(FileOperator::shortenPath(fileName)));
233         askButton = msgBox.addButton(tr("Ask"), QMessageBox::AcceptRole);
234     } else {
235         msgBox.setText(tr("File %1 already exists. Overwrite?").arg(FileOperator::shortenPath(fileName)));
236     }
237
238     msgBox.exec();
239
240     if (msgBox.clickedButton() == abortButton) {
241         manipulator->setResponse(ABORT);
242     } else if (msgBox.clickedButton() == yesButton) {
243         manipulator->setResponse(OVERWRITE);
244     } else if (msgBox.clickedButton() == yesToAllButton) {
245         manipulator->setResponse(OVERWRITE, true);
246     } else if (msgBox.clickedButton() == noButton) {
247         manipulator->setResponse(KEEP);
248     } else if (msgBox.clickedButton() == noToAllButton) {
249         manipulator->setResponse(KEEP, true);
250     } else if (msgBox.clickedButton() == askButton) {
251         manipulator->setResponse(NONE, true);
252     }
253 }
254
255
256 void FileOperator::remove(FileManipulatorThread* manipulator) {
257     manipulator->wait();
258     layout()->removeWidget(manipulator->progressBar);
259     manipulatorList.removeAll(manipulator);
260     delete manipulator;
261 }
262
263
264 void FileOperator::setBarSize(FileManipulatorThread* manipulator, unsigned int size) {
265     if (!manipulator->progressBar->maximum()) {
266         manipulator->startTime = time(0);
267     }
268     manipulator->progressBar->setMinimum(0);
269     manipulator->progressBar->setMaximum(size);
270 }
271
272
273 void FileOperator::updateProgress(FileManipulatorThread* manipulator, int value) {
274     manipulator->setText(value);
275 }
276
277
278 void FileOperator::caterNewThread(FileManipulatorThread *thread) {
279     manipulatorList.append(thread);
280
281     connect(thread, SIGNAL(showErrorPrompt(FileManipulatorThread*, const QString&, const QString&, const int)),
282         this, SLOT(showErrorPrompt(FileManipulatorThread*, const QString&, const QString&, const int)));
283     connect(thread, SIGNAL(showOverwritePrompt(FileManipulatorThread*, const QString&, bool)),
284         this, SLOT(showOverwritePrompt(FileManipulatorThread*, const QString&, bool)));
285     connect(thread, SIGNAL(finished(FileManipulatorThread*)),
286         this, SLOT(remove(FileManipulatorThread*)));
287     connect(thread, SIGNAL(setBarSize(FileManipulatorThread*, unsigned int)),
288         this, SLOT(setBarSize(FileManipulatorThread*, unsigned int)));
289     connect(thread, SIGNAL(updateProgress(FileManipulatorThread*, int)),
290         this, SLOT(updateProgress(FileManipulatorThread*, int)));
291
292     thread->progressBar->setValue(0);
293
294     layout()->addWidget(thread->progressBar);
295     thread->start(QThread::LowestPriority);
296 }
297
298
299 FileManipulatorThread::FileManipulatorThread(const QFileInfoList files, QDir dest) :
300     progressBar(new QProgressBar()),
301     startTime(0),
302     files(files),
303     dest(dest),
304     response(FileOperator::NONE),
305     overwriteAll(FileOperator::NONE),
306     abort(false),
307     lastTimeUpdate(0),
308     barSize(0),
309     barValue(0),
310     fileSize(0),
311     fileValue(0)
312 {
313     memset(ignoreAll, false, sizeof(ignoreAll));
314     progressBar->setMaximum(0);
315     QFont barFont = progressBar->font();
316     barFont.setPointSize(12);
317     progressBar->setFont(barFont);
318     progressBar->setFormat(tr("Gathering information..."));
319     progressBar->setMinimumHeight(44);
320     progressBar->setStyle(new QPlastiqueStyle);
321     //progressBar->setStyle(new QMotifStyle);
322 }
323
324
325 FileManipulatorThread::~FileManipulatorThread() {
326     if (progressBar->value() < progressBar->maximum()) {
327         std::cout << "WARNING: deleting a progressbar which's value " << progressBar->value() <<
328             " has not reached maximum of " << progressBar->maximum() << std::endl;
329     }
330     delete progressBar;
331 }
332
333
334 void FileManipulatorThread::setResponse(
335     const FileOperator::Response response,
336     const bool applyToAll,
337     const int err)
338 {
339     mutex.lock();
340
341     this->response = response;
342
343     if (applyToAll) {
344         if (response == FileOperator::KEEP
345             || response == FileOperator::OVERWRITE
346             || response == FileOperator::NONE)
347         {
348             overwriteAll = response;
349         }
350
351         if (response == FileOperator::IGNORE) {
352             ignoreAll[err] = true;
353         }
354     }
355
356     if (response == FileOperator::ABORT) abort = true;
357
358     mutex.unlock();
359     waitCond.wakeAll();
360 }
361
362
363 void FileManipulatorThread::processFiles(const QFileInfoList &files) {
364     for (QFileInfoList::const_iterator it = files.begin(); it != files.end(); ++it) {
365         perform(*it);
366         if (abort) break;
367     }
368 }
369
370
371 bool FileManipulatorThread::remove(QString &fileName, const bool doUpdates) {
372     return remove(QFileInfo(fileName), doUpdates);
373 }
374
375
376 bool FileManipulatorThread::remove(const QFileInfoList &files, const bool doUpdates) {
377     bool res = true;
378     for (QFileInfoList::const_iterator it = files.begin(); it != files.end(); ++it) {
379         if (!remove(*it, doUpdates)) res = false;
380         if (abort) break;
381     }
382     return res;
383 }
384
385
386 bool FileManipulatorThread::remove(const QFileInfo &file, const bool doUpdates) {
387     std::cout << "DELETING " << file.absoluteFilePath().toStdString() << std::endl;
388
389     QString path = file.absoluteFilePath();
390
391     if (removeExcludeFiles.contains(path)) {
392         if (doUpdates) updateProgress(1);
393         return false;
394     }
395
396     QFSFileEngine engine(path);
397
398     if (doUpdates) updateFile(path);
399
400     if (file.isDir()) {
401         if (!remove(listDirFiles(path), doUpdates)) {
402             if (doUpdates) updateProgress(1);
403             return false;
404         }
405
406         if (!listDirFiles(path).size()) {
407             ERROR_PROMPT(!engine.rmdir(path, false), tr("Error deleting directory %1."), path)
408         }
409     } else {
410         ERROR_PROMPT(!engine.remove(), tr("Error deleting file %1."), path)
411     }
412
413     if (!abort && doUpdates) updateProgress(1);
414
415     if (abort || response == FileOperator::IGNORE) return false;
416     return true;
417 }
418
419
420 void FileManipulatorThread::copy(const QFileInfo &file) {
421     std::cout << "COPYING " << file.absoluteFilePath().toStdString()
422         << " to " << dest.absolutePath().toStdString() << std::endl;
423
424     QString path(file.absoluteFilePath());
425     QString newPath(dest.absolutePath() + "/" + file.fileName());
426     QFSFileEngine engine(path);
427     QFSFileEngine newEngine(newPath);
428     QFileInfo newFile(newPath);
429
430     updateFile(path);
431
432     // hack to prevent asking about the same file if we already asked in the rename(...) function
433     if (overwriteAll == FileOperator::DONT_ASK_ONCE) {
434         overwriteAll = FileOperator::NONE;
435     } else {
436         OVERWRITE_PROMPT(file, newFile)
437     }
438
439     if (abort) return;
440
441     if (response == FileOperator::KEEP) {
442         updateProgress(fileSizeMap[path]);
443         removeExcludeFiles.insert(path);
444         return;
445     }
446
447     if (file.isDir()) {
448         FileOperator::Response overwriteResponse = response;
449
450         if (newFile.exists() && !newFile.isDir()) {
451             if(!remove(newPath)) {
452                 updateProgress(fileSizeMap[path]);
453                 return;
454             }
455             newFile = QFileInfo(newPath);
456         }
457
458         if (!newFile.exists()) {
459             SPECIAL_COPY_ERROR_PROMPT(!engine.mkdir(newPath, false),
460                 tr("Error creating directory %1."), newPath)
461         }
462
463         updateProgress(1);
464         
465         QDir destBackup = dest;
466         dest = newPath;
467
468         FileOperator::Response tmpResp = overwriteAll;
469         overwriteAll = overwriteResponse;
470
471         processFiles(listDirFiles(path));
472
473         overwriteAll = tmpResp;
474
475         ERROR_PROMPT(!newEngine.setPermissions(file.permissions()),
476             tr("Error setting permissions for directory %1."), newPath)
477
478         if (abort) return;
479
480         dest = destBackup;
481     } else {
482         SPECIAL_COPY_ERROR_PROMPT(engine.isSequential(), tr("Cannot copy sequential file %1."), path)
483
484         if (newFile.exists() && newFile.isDir()) {
485             SPECIAL_COPY_ERROR_PROMPT(!remove(newPath),
486                 tr("Cannot replace directory %1 due to previous errors."), newPath)
487         }
488
489         SPECIAL_COPY_ERROR_PROMPT(!engine.open(QIODevice::ReadOnly), tr("Error reading file %1."), path)
490
491         bool ignore = false;
492         while (!abort && !ignore) {
493             engine.seek(0);
494             fileValue = 0;
495
496             ERROR_PROMPT(!newEngine.open(QIODevice::WriteOnly | QIODevice::Truncate),
497                 tr("Error writing file %1."), newPath)
498
499             if (abort || response == FileOperator::IGNORE) {
500                 if (response == FileOperator::IGNORE) {
501                     updateProgress(fileSizeMap[path]);
502                     removeExcludeFiles.insert(path);
503                     ignore = true;
504                 }
505                 break;
506             }
507
508             bool error = false;
509             char block[BLOCK_SIZE];
510             qint64 bytes;
511             while ((bytes = engine.read(block, sizeof(block))) > 0) {
512                 if (bytes == -1 || bytes != newEngine.write(block, bytes)) {
513                     if (bytes == -1) {
514                         SHOW_ERROR_PROMPT(tr("Error while reading from file %1."), path);
515                     } else {
516                         SHOW_ERROR_PROMPT(tr("Error while writing to file %1."), newPath);
517                     }
518
519                     if (!abort) {
520                         if (response == FileOperator::IGNORE) {
521                             updateProgress(fileSizeMap[path] - fileValue);
522                             removeExcludeFiles.insert(path);
523                             ignore = true;
524                         } else {
525                             updateProgress(-fileValue);
526                         }
527                     }
528                     error = true;
529                     break;
530                 }
531
532                 updateProgress(1);
533             }
534
535             if (!error) break;
536         }
537
538         engine.close();
539         newEngine.close();
540
541         if (abort || ignore) {
542             newEngine.remove();
543         } else {
544             ERROR_PROMPT(!newEngine.setPermissions(file.permissions()),
545                 tr("Error setting permissions for file %1."), newPath)
546         }
547     }
548 }
549
550
551 unsigned int FileManipulatorThread::calculateFileSize(const QFileInfoList &files,
552     const bool count,
553     const bool addSize)
554 {
555     unsigned int res = 0;
556
557     for (QFileInfoList::const_iterator it = files.begin(); it != files.end(); ++it) {
558         unsigned int size = 0;
559
560         if (it->isDir()) {
561             size += calculateFileSize(listDirFiles(it->absoluteFilePath()), count, addSize);
562         }
563
564         if (addSize) {
565             if (it->isDir()) {
566                 ++size;
567             } else {
568                 size += ceil(static_cast<float>(it->size()) / BLOCK_SIZE);
569             }
570             fileSizeMap[it->absoluteFilePath()] = size;
571         }
572
573         if (count) {
574             ++size;
575         }
576
577         res += size;
578     }
579
580     return res;
581 }
582
583
584 QFileInfoList FileManipulatorThread::listDirFiles(const QString &dirPath) {
585     QDir dir = dirPath;
586     return dir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries | QDir::System | QDir::Hidden);
587 }
588
589
590 void FileManipulatorThread::setBarSize(unsigned int size) {
591     barSize = size;
592     emit setBarSize(this, size);
593 }
594
595
596 void FileManipulatorThread::updateProgress(int value) {
597     barValue += value;
598     fileValue += value;
599     emit updateProgress(this, value);
600 }
601
602
603 void FileManipulatorThread::updateFile(const QString &name) {
604     fileValue = 0;
605     fileName = FileOperator::shortenPath(name);
606     emit updateProgress(this, 0);
607 }
608
609
610 void FileManipulatorThread::setText(int value) {
611     if (progressBar->value() + value > progressBar->maximum()) {
612         std::cout << "WARNING: exceeding progressbar maximum (" << progressBar->maximum()
613             << ") by " << value << std::endl;
614     }
615  
616     time_t now = time(0);
617     if (lastTimeUpdate < now) {
618         lastTimeUpdate = now;
619
620         time_t elapsed = now - startTime;
621         time_t remaining = (time_t) ((float) elapsed / barValue * (barSize - barValue));
622         struct tm *ts = gmtime(&remaining);
623         
624         if (remaining < 60) {
625             strftime(timeBuf, sizeof(timeBuf), "%Ss", ts);
626         } else if (remaining < 3600) {
627             strftime(timeBuf, sizeof(timeBuf), "%M:%S", ts);
628         } else {
629             strftime(timeBuf, sizeof(timeBuf), "%H:%M:%S", ts);
630         }
631     }
632
633     progressBar->setFormat(barText.arg(fileName) + "\n%p%   ETA " + timeBuf);
634     progressBar->setValue(progressBar->value() + value);
635 }
636
637
638 DeleteThread::DeleteThread(const QFileInfoList &files) : FileManipulatorThread(files) {
639     barText = tr("deleting %1");
640 }
641
642
643 void DeleteThread::run() {
644     mutex.lock();
645
646     setBarSize(calculateFileSize(files, true));
647
648     processFiles(files);
649
650     sleep(0.5);
651     emit finished(this);
652 }
653
654
655 void DeleteThread::perform(const QFileInfo &file) {
656     remove(file, true);
657 }
658
659
660 CopyThread::CopyThread(const QFileInfoList &files, QDir &dest) : FileManipulatorThread(files, dest) {
661     barText = tr("copying %1");
662 }
663
664
665 void CopyThread::run() {
666     mutex.lock();
667
668     setBarSize(calculateFileSize(files, false, true));
669
670     processFiles(files);
671
672     sleep(0.5);
673     emit finished(this);
674 }
675
676
677 void CopyThread::perform(const QFileInfo &file) {
678     copy(file);
679 }
680
681
682 MoveThread::MoveThread(const QFileInfoList &files, QDir &dest) : FileManipulatorThread(files, dest) {
683     barText = tr("moving %1");
684 }
685
686
687 void MoveThread::run() {
688     mutex.lock();
689
690     rename(files, dest);
691
692     sleep(0.5);
693     emit finished(this);
694 }
695
696
697 void MoveThread::rename(const QFileInfoList &files, const QDir &dest) {
698     setBarSize(barSize + files.size());
699
700     for (int i = 0; i < files.size(); ++i) {
701         QString path = files[i].absoluteFilePath();
702         QFSFileEngine engine(path);
703         QString newPath = dest.absolutePath() + "/" + files[i].fileName();
704
705         updateFile(path);
706
707         OVERWRITE_PROMPT(files[i], QFileInfo(newPath))
708
709         if (response == FileOperator::KEEP) {
710             if (abort) break;
711             updateProgress(1);
712             continue;
713         }
714
715         while (!abort && !engine.rename(newPath)) {
716             // source and target are on different partitions
717             // this should happen on the first file, unless some are skipped by overwrite prompt
718             // we calculate the actual file sizes, because from now on copy & remove takes over
719             if (errno == EXDEV) {
720                 overwriteAll = response;
721                 // hack: we already checked the first file we are sending to processFiles(...)
722                 // so we don't want to ask about this one again
723                 if (overwriteAll == FileOperator::NONE) overwriteAll = FileOperator::DONT_ASK_ONCE;
724
725                 QFileInfoList remainingFiles = files.mid(i);
726
727                 setBarSize(barValue + calculateFileSize(remainingFiles, true, true));
728
729                 processFiles(remainingFiles);
730
731                 barText = tr("deleting %1");
732
733                 remove(remainingFiles, true);
734
735                 // just to quit the loops, we are done
736                 abort = true;
737             // the target is nonempty dir. lets call this recursively and rename the contents one by one
738             } else if (errno == ENOTEMPTY || errno == EEXIST) {
739                 FileOperator::Response tmpResp = overwriteAll;
740                 overwriteAll = response;
741
742                 rename(listDirFiles(path), QDir(newPath));
743                 if (abort) break;
744
745                 overwriteAll = tmpResp;
746
747                 ERROR_PROMPT(!engine.rmdir(path, false), tr("Error deleting directory %1."), path)
748
749                 break;
750             // source and target are nonmatching types(file and dir)
751             // remove the target and let it loop once again
752             } else if (errno == ENOTDIR || errno == EISDIR) {
753                 if (!remove(newPath)) break;
754             } else {
755                 SHOW_ERROR_PROMPT(tr("Error moving %1."), path)
756
757                 if (response == FileOperator::IGNORE) {
758                     break;
759                 }
760             }
761         }
762             
763         if (abort) break;
764         updateProgress(1);
765     }
766 }
767
768
769 void MoveThread::perform(const QFileInfo &file) {
770     copy(file);
771 }