summaryrefslogtreecommitdiffstats
path: root/copyworker.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'copyworker.cpp')
-rw-r--r--copyworker.cpp59
1 files changed, 27 insertions, 32 deletions
diff --git a/copyworker.cpp b/copyworker.cpp
index dbff451..0fbc802 100644
--- a/copyworker.cpp
+++ b/copyworker.cpp
@@ -13,27 +13,21 @@
CopyWorker::CopyWorker(QObject *parent) : QThread(parent), mMax(0) {}
-void CopyWorker::setDestination(const QString &destDir) {
- QFileInfo destFi(destDir);
- if(destFi.isDir()){
- mDest = destDir;
- }else{
- QString e = QString(tr("%1 is not a directory!")).arg(destFi.absoluteFilePath());
- emit error(e);
+void CopyWorker::enqueue(const QString &source, const QString &destination){
+ QMutexLocker l(&mSourceMx);
+ QPair<QString, QString> x = qMakePair<QString, QString>(source, destination);
+ if(!mFiles.contains(x)){
+ QFileInfo fi(source);
+ mFiles.append(x);
+ qint64 size = fi.size();
+ mMax += size / 1024 / 1024;
}
}
-void CopyWorker::addSource(const QString &path){
- QMutexLocker l(&mSourceMx);
- if(!mSources.contains(path)){
- QFileInfo fi(path);
- if(fi.exists() && fi.isFile()){
- mSources.append(path);
- qint64 size = fi.size();
- size = size / 1024 / 1024;
- mMax += size;
- }
- }
+void CopyWorker::appendData(const QString &source, const QVariant &data){
+ QList<QVariant> v = mData[source];
+ v << data;
+ mData.insert(source, v);
}
void CopyWorker::clear(){
@@ -41,46 +35,47 @@ void CopyWorker::clear(){
return;
}
QMutexLocker l(&mSourceMx);
- mSources.clear();
+ mFiles.clear();
mMax = 0;
}
void CopyWorker::run(){
- foreach(QString f, mSources){
- QFileInfo cur(f);
+ qint64 total = 0;
+ for(int i = 0; i < mFiles.size(); ++i){
+ QPair<QString, QString> p = mFiles.at(i);
+ QFileInfo cur(p.first);
if(!cur.exists()){
QString e = QString(tr("%1 has gone away from under us!")).arg(cur.fileName());
emit error(e);
- continue;
+ return;
}
- QString destFile = QString("%1/%2").arg(mDest).arg(cur.fileName());
- QFileInfo destFi(destFile);
+ QFileInfo destFi(p.second);
if(destFi.exists()){
QString e = QString(tr("%1 already exists!")).arg(destFi.absoluteFilePath());
emit error(e);
- continue;
+ return;
}
- QFile sourceQF(f);
- QFile destQF(destFile);
+ QFile sourceQF(p.first);
+ QFile destQF(p.second);
bool openSource = sourceQF.open(QIODevice::ReadOnly);
bool openDest = destQF.open(QIODevice::WriteOnly);
if(!openSource || !openDest){
QString e = QString(tr("Failed to open source or destination on %1!")).arg(cur.fileName());
emit error(e);
- continue;
+ return;
}
char *buf = new char[32768];
qint64 len = 0;
- int total = 0;
+ emit file(cur.fileName());
while(!sourceQF.atEnd()){
len = sourceQF.read(buf, 32768);
destQF.write(buf, len);
- total +=len;
+ total += len;
qint64 cur = total / 1024 / 1024;
emit bytesRead(cur);
}
delete buf;
- QString s = QString(tr("Done copying %1")).arg(cur.fileName());
- emit success(s);
}
+ QString s = QString(tr("Done copying %1 file(s)")).arg(QString::number(mFiles.size()));
+ emit success(s);
}