From 59433fdbc15862c167490597546956894fec0a37 Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 5 Mar 2016 06:54:56 +0100 Subject: Do not connect CopyWorker on every invokation I connected the CopyWorker SIGNALS to the ArchiveBrowser SLOTS on every copy. Of course that made the success dialogs pop up as many times as there were copy operations. Fix it by moving the connect call into the constructor. --- archivebrowser.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'archivebrowser.cpp') diff --git a/archivebrowser.cpp b/archivebrowser.cpp index fbeb50d..1459dac 100644 --- a/archivebrowser.cpp +++ b/archivebrowser.cpp @@ -80,7 +80,9 @@ ArchiveBrowser::ArchiveBrowser(QWidget *parent) : QWidget(parent), mSelectedSize //copyworker mUSBProgress = 0; mCopyWorker = new CopyWorker(this); - + connect(mCopyWorker, SIGNAL(error(QString)), this, SLOT(copyError(QString))); + connect(mCopyWorker, SIGNAL(success(QString)), this, SLOT(copySuccess(QString))); + connect(mCopyWorker, SIGNAL(file(QString)), this, SLOT(setCopyFile(QString))); } void ArchiveBrowser::browserSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected) { @@ -213,9 +215,6 @@ void ArchiveBrowser::moveToUSB(){ } mUSBProgress = new QProgressDialog(this); connect(mCopyWorker, SIGNAL(bytesRead(int)), mUSBProgress, SLOT(setValue(int))); - connect(mCopyWorker, SIGNAL(error(QString)), this, SLOT(copyError(QString))); - connect(mCopyWorker, SIGNAL(success(QString)), this, SLOT(copySuccess(QString))); - connect(mCopyWorker, SIGNAL(file(QString)), this, SLOT(setCopyFile(QString))); mUSBProgress->setLabelText(tr("Copying files...")); mUSBProgress->setMinimum(0); mUSBProgress->setMaximum(mCopyWorker->max()); @@ -289,15 +288,19 @@ void ArchiveBrowser::resetAll() { void ArchiveBrowser::copyError(QString error){ mUSBProgress->hide(); QMessageBox::critical(this, tr("Copy Error"), error); - mUSBProgress->disconnect(); - mUSBProgress->deleteLater(); + mCopyWorker->disconnect(mUSBProgress); + QProgressDialog *old = mUSBProgress; + old->deleteLater(); + mUSBProgress = 0; } void ArchiveBrowser::copySuccess(QString success){ mUSBProgress->hide(); QMessageBox::information(this, tr("Copy Success"), success); - mUSBProgress->disconnect(); - mUSBProgress->deleteLater(); + mCopyWorker->disconnect(mUSBProgress); + QProgressDialog *old = mUSBProgress; + old->deleteLater(); + mUSBProgress = 0; QString msg = QString(tr("Delete source files and update database?")); int q = QMessageBox::question(this, tr("Question"), msg); if(q == QMessageBox::Yes){ -- cgit v1.2.3-70-g09d2