summaryrefslogtreecommitdiffstats
path: root/filewidget.cpp
diff options
context:
space:
mode:
authorArno <arno@disconnect.de>2018-06-13 09:27:59 +0200
committerArno <arno@disconnect.de>2018-06-13 09:27:59 +0200
commit10a8921bbcd9802ad2425e8cee1e5ca70fb0b241 (patch)
tree86fe45d0a7f343e2063290201603be1fc5f375e9 /filewidget.cpp
parenta32ed8a8ec53537a6723ece20c7d2f5c5738626b (diff)
downloadShemovCleaner-10a8921bbcd9802ad2425e8cee1e5ca70fb0b241.tar.gz
ShemovCleaner-10a8921bbcd9802ad2425e8cee1e5ca70fb0b241.tar.bz2
ShemovCleaner-10a8921bbcd9802ad2425e8cee1e5ca70fb0b241.zip
Speed up file copy
Hmm, as it turns out QFile does a much better, e.g. faster, job than my open-coded file copy with a progress dialog. I always wondered why it only did 150-170Mbit. I thought that it was just the calculation, but now I have 400 Mbit, and it still stalls at 150 Mbit. QFile::copy maxes out the line, so get rid of the ProgressDialog and show a status message instead. Copy can be canceled by the context menu, but FileCopier will always finish the current file, because I don't want to lock and unlock the CancelMutex during copy. Besides, QFile::copy doesn't admit that :)
Diffstat (limited to 'filewidget.cpp')
-rw-r--r--filewidget.cpp46
1 files changed, 6 insertions, 40 deletions
diff --git a/filewidget.cpp b/filewidget.cpp
index 7a7e361..d1600f6 100644
--- a/filewidget.cpp
+++ b/filewidget.cpp
@@ -46,20 +46,13 @@
#include "helper.h"
#include "globals.h"
#include "viewer.h"
-#include "progressdialog.h"
#include "searchdialog.h"
FileWidget::FileWidget(QWidget *parent) : QWidget(parent), mCopyToMenu(0) {
mFileCopier = new FileCopier(this);
- mCopyProgress = new ProgressDialog;
mFileCache.setMaxCost(500);
readCache();
- connect(mFileCopier, &FileCopier::newFile, this, &FileWidget::setupProgress);
- connect(mFileCopier, &FileCopier::bytesRead, this, &FileWidget::setCopyProgress);
- connect(mFileCopier, &FileCopier::bytesReadIntval, this, &FileWidget::setCopySummary);
- connect(mFileCopier, &FileCopier::finished, this, &FileWidget::hideCopyProgress);
- connect(mFileCopier, &FileCopier::success, this, &FileWidget::copySuccess);
- connect(mCopyProgress, &ProgressDialog::cancelled, this, &FileWidget::hideCopyProgress);
+ connect(mFileCopier, &FileCopier::message, this, &FileWidget::statusMessage);
setupGui();
}
@@ -146,7 +139,6 @@ void FileWidget::setupGui(){
createActions();
mMimeData = new QMimeData;
mFileView->setFocus();
- mCopyProgress->setVisible(false);
QSettings s;
QString startMimeFilter = s.value("currentmimefilter").toString();
@@ -196,6 +188,8 @@ void FileWidget::createActions(){
connect(searchGoogleA, &QAction::triggered, this, &FileWidget::searchGoogle);
QAction *searchDlgA = new QAction(QIcon(":/system-search.png"), tr("Search dialog..."), this);
connect(searchDlgA, &QAction::triggered, mSearchDlg, &SearchDialog::show);
+ mCancelCopyA = new QAction(QIcon(":/chastity_belt.png"), tr("Cancel copy"), this);
+ connect(mCancelCopyA, &QAction::triggered, mFileCopier, &FileCopier::cancel);
QMenu *fileMenu = new QMenu(tr("&File"));
fileMenu->addAction(mSelDirA);
@@ -704,29 +698,6 @@ void FileWidget::addAsOrigin(){
mOrignDlg->show();
}
-void FileWidget::setupProgress(QString file, QString dest, qint64 size){
- mCopyProgress->setMaximum(size / 1024 / 1024);
- mCopyProgress->setValue(0);
- QFileInfo fi(file);
- QString srcLabel = QString(tr("Copying %1")).arg(fi.fileName());
- QFileInfo fi2(dest);
- QString dstLabel = QString(tr("to %2")).arg(QDir::toNativeSeparators(fi2.absolutePath()));
- mCopyProgress->setLabelText(srcLabel, dstLabel);
-}
-
-void FileWidget::setCopyProgress(qint64 bytes){
- int val = bytes / 1024 / 1024;
- mCopyProgress->setValue(val);
-}
-
-void FileWidget::setCopySummary(qint64 bytes, qint64 elapsed, int total, int copying){
- if(elapsed != 0){
- float rate = bytes * 8 / (elapsed / 1000.0) / 1024 / 1024.0;
- QString sum = QString("%1/%2 file(s), @ %3 MB/s").arg(QString::number(copying+1)).arg(QString::number(total)).arg(QString::number(rate, 'f', 2));
- mCopyProgress->setSummary(sum);
- }
-}
-
void FileWidget::copyFiles(QString destDir){
QModelIndexList files = mFileView->selectionModel()->selectedRows();
if(!files.isEmpty()){
@@ -739,20 +710,12 @@ void FileWidget::copyFiles(QString destDir){
QString destFile = QString("%1%2%3").arg(destDir).arg(QDir::separator()).arg(fi.fileName());
mFileCopier->addJob(fp, destFile);
}
- mCopyProgress->show();
if(!mFileCopier->isRunning()){
mFileCopier->start();
}
}
}
-void FileWidget::hideCopyProgress(){
- if(mFileCopier->isRunning()){
- mFileCopier->cancel();
- }
- mCopyProgress->hide();
-}
-
void FileWidget::copySuccess(bool success, QString source){
if(success){
QFileInfo fi(source);
@@ -980,6 +943,9 @@ void FileWidget::contextMenuEvent(QContextMenuEvent *e){
}
}
contextMenu.addMenu(mCopyToMenu);
+ if(mFileCopier->isRunning()){
+ contextMenu.addAction(mCancelCopyA);
+ }
contextMenu.addAction(createSeparator());
contextMenu.addActions(actions());
contextMenu.exec(e->globalPos());