summaryrefslogtreecommitdiffstats
path: root/filecopier.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'filecopier.cpp')
-rw-r--r--filecopier.cpp42
1 files changed, 24 insertions, 18 deletions
diff --git a/filecopier.cpp b/filecopier.cpp
index 001b317..1588d6e 100644
--- a/filecopier.cpp
+++ b/filecopier.cpp
@@ -4,24 +4,21 @@
#include "filecopier.h"
-FileCopier::FileCopier(QObject *parent) : QThread(parent), mCancel(false){}
+FileCopier::FileCopier(QObject *parent) : QThread(parent), mCancel(false), mTotal(0), mCopied(0){}
void FileCopier::addJob(const QString &source, const QString &dest){
QMutexLocker l(&mAddJobMutex);
if(!mJobs.contains(source)){
mJobs[source] = dest;
+ ++mTotal;
}
}
-QHash<QString, QString> FileCopier::jobs(){
- QMutexLocker l(&mAddJobMutex);
- return mJobs;
-}
-
void FileCopier::run(){
- int bufsize = 16 * 1024 * 1024;
+ int bufsize = 32 * 1024 * 1024;
char *buf = new char[bufsize];
mCancel = false;
+ mCopied = 0;
QElapsedTimer et;
while(!mJobs.isEmpty()){
mAddJobMutex.lock();
@@ -45,31 +42,40 @@ void FileCopier::run(){
qint64 bytesSinceEl = 0;
et.start();
while(!sFile.atEnd()){
- mCancelMutex.lock();
- bool cancel = mCancel;
- mCancelMutex.unlock();
- if(cancel){
- QFile::remove(dest);
- emit success(false, source);
- goto cleanup;
- }
read = sFile.read(buf, bufsize);
dFile.write(buf, read);
total += read;
bytesSinceEl += read;
- elapsed += et.restart();
- if(elapsed > 5000){ //5 seconds
- emit bytesReadIntval(bytesSinceEl, elapsed);
+ elapsed = et.elapsed();
+ if(elapsed > 1000){
+ mCancelMutex.lock();
+ bool cancel = mCancel;
+ mCancelMutex.unlock();
+ if(cancel){
+ dFile.close();
+ QFile::remove(dest);
+ emit success(false, source);
+ goto cleanup;
+ }
+ mCountMutex.lock();
+ emit bytesReadIntval(bytesSinceEl, elapsed, mTotal, mCopied);
+ mCountMutex.unlock();
elapsed = 0;
bytesSinceEl = 0;
+ et.restart();
}
emit bytesRead(total);
}
emit success(true, source);
+ ++mCopied;
+ emit bytesReadIntval(bytesSinceEl, elapsed, mTotal, mCopied);
+ et.restart();
}
cleanup:
delete buf;
+ mTotal = 0;
+ mJobs.clear();
}
void FileCopier::cancel(){