summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArno <arno@disconnect.de>2019-11-23 15:53:37 +0100
committerArno <arno@disconnect.de>2019-11-23 15:53:37 +0100
commit980f94e493c349c6c86f1b3d05753ce3cfba38d8 (patch)
treef5267e2fc7ad9c58668ee62834e8e006c3bf32bd
parent30d61398cbb8a2694b648d3fceb119fbeaf756a1 (diff)
downloadShemovCleaner-980f94e493c349c6c86f1b3d05753ce3cfba38d8.tar.gz
ShemovCleaner-980f94e493c349c6c86f1b3d05753ce3cfba38d8.tar.bz2
ShemovCleaner-980f94e493c349c6c86f1b3d05753ce3cfba38d8.zip
Fix race in updateCopying
If the storage is fast enough, passing a bool to updateCopying does not suffice. Then the SIGNAL with inProgress == true could arrive *after* the work is already done, leaving the copy indicator in an inconsitent state. So check the QThread directly by ->isRunning() instead of passing a bool.
-rw-r--r--filecopier.cpp2
-rw-r--r--filecopier.h2
-rw-r--r--shemovcleaner.cpp12
-rw-r--r--shemovcleaner.h2
4 files changed, 9 insertions, 9 deletions
diff --git a/filecopier.cpp b/filecopier.cpp
index dd3f679..a77e051 100644
--- a/filecopier.cpp
+++ b/filecopier.cpp
@@ -25,7 +25,7 @@ void FileCopier::run(){
mAddJobMutex.unlock();
QString msg = QString(tr("Copy: %1 (%2/%3)")).arg(source).arg(QString::number(mCopied + 1)).arg(QString::number(mTotal));
QString cmsg = QString("%1/%2").arg(QString::number(mCopied + 1)).arg(QString::number(mTotal));
- emit copying(true, cmsg);
+ emit copying(cmsg);
emit message(msg);
QFile sFile(source);
if(sFile.copy(dest)){
diff --git a/filecopier.h b/filecopier.h
index 8836749..36f0d6c 100644
--- a/filecopier.h
+++ b/filecopier.h
@@ -15,7 +15,7 @@ class FileCopier : public QThread {
signals:
void message(const QString &msg);
- void copying(bool copying, const QString &msg);
+ void copying(const QString &msg);
private:
QHash<QString, QString> mJobs;
diff --git a/shemovcleaner.cpp b/shemovcleaner.cpp
index 634eaf4..32b9d01 100644
--- a/shemovcleaner.cpp
+++ b/shemovcleaner.cpp
@@ -38,7 +38,6 @@ ShemovCleaner::ShemovCleaner(QWidget *parent, Qt::WindowFlags f) : QMainWindow(p
splash.show();
qApp->processEvents();
openDatabase();
- createStatusBar();
createGlobalActions();
splash.showMessage(tr("Reading torrents..."), Qt::AlignHCenter, Qt::darkGreen);
@@ -56,6 +55,7 @@ ShemovCleaner::ShemovCleaner(QWidget *parent, Qt::WindowFlags f) : QMainWindow(p
qApp->processEvents();
mTab->addTab(mTorrentTab, tr("&Torrents"));
mTab->addTab(mFileTab, tr("Fi&les"));
+ createStatusBar();
setCentralWidget(mTab);
connect(mTorrentTab, &TorrentWidget::statusMessage, this, &ShemovCleaner::statusBarMessage);
@@ -68,10 +68,10 @@ ShemovCleaner::ShemovCleaner(QWidget *parent, Qt::WindowFlags f) : QMainWindow(p
connect(mTab, &QTabWidget::currentChanged, this, &ShemovCleaner::tabChanged);
connect(this, &ShemovCleaner::configurationChanged, mFileTab, &FileWidget::readSettings);
connect(mFileTab->fileCopier(), &FileCopier::copying, this, &ShemovCleaner::updateCopying);
- connect(mFileTab->fileCopier(), &FileCopier::finished, [=] { updateCopying(false, QString());} );
+ connect(mFileTab->fileCopier(), &FileCopier::finished, [=] { updateCopying(QString());} );
connect(mFileTab->fileCopier(), &FileCopier::finished, mFileTab, &FileWidget::gatherData);
mCopying->installEventFilter(this);
- updateCopying(false, QString());
+ updateCopying(QString());
QMenu *helpMenu = new QMenu(tr("&Help"));
QAction *aboutThisA = new QAction(tr("About ShemovCleaner..."), this);
@@ -134,9 +134,9 @@ void ShemovCleaner::updateFreeSpace(const QString &path){
mFree->setPixmap(QPixmap::fromImage(img));
}
-void ShemovCleaner::updateCopying(bool inProgress, const QString &count){
+void ShemovCleaner::updateCopying(const QString &count){
QImage img(mCopying->size(), QImage::Format_ARGB32);
- if(inProgress){
+ if(mFileTab->fileCopier()->isRunning()){
img.fill(Qt::red);
QPainter p(&img);
QFont f(qApp->font());
@@ -236,7 +236,7 @@ void ShemovCleaner::createStatusBar(){
statusBar()->addPermanentWidget(mDuration);
statusBar()->addPermanentWidget(mDrive);
statusBar()->addPermanentWidget(mFree);
- updateCopying(false, QString());
+ updateCopying(QString());
}
void ShemovCleaner::createGlobalActions(){
diff --git a/shemovcleaner.h b/shemovcleaner.h
index db6399f..4553df8 100644
--- a/shemovcleaner.h
+++ b/shemovcleaner.h
@@ -21,7 +21,7 @@ class ShemovCleaner : public QMainWindow {
void setSelectionCount(const QString &msg);
void setDuration(const QString &msg);
void updateFreeSpace(const QString &path);
- void updateCopying(bool inProgress, const QString &count);
+ void updateCopying(const QString &count);
void configure();
void tabChanged(int idx);
void aboutThisProgram();