diff options
author | Arno <arno@disconnect.de> | 2016-12-06 12:14:47 +0100 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2016-12-06 12:14:47 +0100 |
commit | 997ed9156ba7a1942cebd487fd5cc2818220fa78 (patch) | |
tree | 3b9d5a63b9235e3fa9ce8e4f9078991fc14738b3 | |
parent | a68cf88e69c65014f2e528aa26db42b4808c3b64 (diff) | |
download | ShemovCleaner-997ed9156ba7a1942cebd487fd5cc2818220fa78.tar.gz ShemovCleaner-997ed9156ba7a1942cebd487fd5cc2818220fa78.tar.bz2 ShemovCleaner-997ed9156ba7a1942cebd487fd5cc2818220fa78.zip |
Add a summary to ProgressDialog
Show how many files we have, and display the transfer rate in Megabytes
per second. Can't believe that it worked right from the start :)
-rw-r--r-- | filecopier.cpp | 12 | ||||
-rw-r--r-- | filecopier.h | 1 | ||||
-rw-r--r-- | filewidget.cpp | 8 | ||||
-rw-r--r-- | filewidget.h | 1 | ||||
-rw-r--r-- | progressdialog.cpp | 2 | ||||
-rw-r--r-- | progressdialog.h | 2 |
6 files changed, 26 insertions, 0 deletions
diff --git a/filecopier.cpp b/filecopier.cpp index e652339..001b317 100644 --- a/filecopier.cpp +++ b/filecopier.cpp @@ -1,5 +1,6 @@ #include <QMutexLocker> #include <QFile> +#include <QElapsedTimer> #include "filecopier.h" @@ -21,6 +22,7 @@ void FileCopier::run(){ int bufsize = 16 * 1024 * 1024; char *buf = new char[bufsize]; mCancel = false; + QElapsedTimer et; while(!mJobs.isEmpty()){ mAddJobMutex.lock(); auto first = mJobs.constBegin(); @@ -39,6 +41,9 @@ void FileCopier::run(){ emit newFile(source, dest, sFile.size()); int read = 0; qint64 total = 0; + qint64 elapsed = 0; + qint64 bytesSinceEl = 0; + et.start(); while(!sFile.atEnd()){ mCancelMutex.lock(); bool cancel = mCancel; @@ -51,6 +56,13 @@ void FileCopier::run(){ 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 = 0; + bytesSinceEl = 0; + } emit bytesRead(total); } emit success(true, source); diff --git a/filecopier.h b/filecopier.h index 96702a3..81d8496 100644 --- a/filecopier.h +++ b/filecopier.h @@ -18,6 +18,7 @@ class FileCopier : public QThread { void newFile(const QString &source, const QString & dest, qint64 size); void success(bool s, QString source); void bytesRead(qint64 bytes); + void bytesReadIntval(qint64 bytes, qint64 msecs); private: QHash<QString, QString> mJobs; diff --git a/filewidget.cpp b/filewidget.cpp index a539f82..6b5770f 100644 --- a/filewidget.cpp +++ b/filewidget.cpp @@ -47,6 +47,7 @@ FileWidget::FileWidget(QWidget *parent) : QWidget(parent), mCopyToMenu(0), mCopy mCopyProgress = new ProgressDialog; connect(mFileCopier, SIGNAL(newFile(QString,QString,qint64)), this, SLOT(setupProgress(QString,QString,qint64))); connect(mFileCopier, SIGNAL(bytesRead(qint64)), this, SLOT(setCopyProgress(qint64))); + connect(mFileCopier, SIGNAL(bytesReadIntval(qint64,qint64)), this, SLOT(setCopySummary(qint64,qint64))); connect(mFileCopier, SIGNAL(finished()), this, SLOT(hideCopyProgress())); connect(mFileCopier, SIGNAL(success(bool,QString)), this, SLOT(copySuccess(bool,QString))); connect(mCopyProgress, SIGNAL(cancelled()), this, SLOT(hideCopyProgress())); @@ -526,6 +527,13 @@ void FileWidget::setCopyProgress(qint64 bytes){ mCopyProgress->setValue(val); } +void FileWidget::setCopySummary(qint64 bytes, qint64 elapsed){ + QHash<QString,QString> jobs = mFileCopier->jobs(); + float rate = bytes / (elapsed / 1000) / 1024 / 1024.0; + QString sum = QString("%1 file(s), @ %2 MB/s").arg(QString::number(jobs.count() + 1)).arg(QString::number(rate, 'f', 2)); + mCopyProgress->setSummary(sum); +} + void FileWidget::copyFiles(QString destDir){ QModelIndexList files = mFileView->selectionModel()->selectedRows(); if(!files.isEmpty()){ diff --git a/filewidget.h b/filewidget.h index 62d0630..d48aa80 100644 --- a/filewidget.h +++ b/filewidget.h @@ -67,6 +67,7 @@ class FileWidget : public QWidget { void addAsOrigin(); void setupProgress(QString file, QString dest, qint64 size); void setCopyProgress(qint64 bytes); + void setCopySummary(qint64 bytes, qint64 elapsed); void copyFiles(QString destDir); void hideCopyProgress(); void copySuccess(bool success, QString source); diff --git a/progressdialog.cpp b/progressdialog.cpp index 2f51857..d95f1e1 100644 --- a/progressdialog.cpp +++ b/progressdialog.cpp @@ -8,6 +8,7 @@ ProgressDialog::ProgressDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(par mSrc = new QLabel; mDst = new QLabel; mProgress = new QProgressBar; + mSum = new QLabel(tr("Wait for it...")); QPushButton *cancelBtn = new QPushButton(tr("Cancel")); connect(cancelBtn, SIGNAL(clicked()), this, SIGNAL(cancelled())); QHBoxLayout *btnLayout = new QHBoxLayout; @@ -18,6 +19,7 @@ ProgressDialog::ProgressDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(par mainLayout->addWidget(mSrc); mainLayout->addWidget(mDst); mainLayout->addWidget(mProgress); + mainLayout->addWidget(mSum); mainLayout->addLayout(btnLayout); setMaximumWidth(400); setMinimumWidth(400); diff --git a/progressdialog.h b/progressdialog.h index 35ede38..86a31bc 100644 --- a/progressdialog.h +++ b/progressdialog.h @@ -11,6 +11,7 @@ class ProgressDialog : public QDialog { ProgressDialog(QWidget *parent = 0, Qt::WindowFlags f = 0); void setLabelText(const QString &src, const QString &dst); void setMaximum(int max) { mProgress->setMaximum(max); } + void setSummary(const QString &sum) { mSum->setText(sum); } public slots: void setValue(int val); @@ -21,6 +22,7 @@ class ProgressDialog : public QDialog { private: QLabel *mSrc; QLabel *mDst; + QLabel *mSum; QProgressBar *mProgress; }; |