summaryrefslogtreecommitdiffstats
path: root/consistencycheck.cpp
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2010-11-05 15:20:44 +0100
committerArno <am@disconnect.de>2010-11-05 15:20:44 +0100
commit8230ea0228bd300316529c852858f7105ee75a3d (patch)
tree3ce0da30007449722bb233cb22b309e25ed13eec /consistencycheck.cpp
parentb8a793f4a1afcd27cf03da7b620dd7a4f7f5813f (diff)
downloadSheMov-8230ea0228bd300316529c852858f7105ee75a3d.tar.gz
SheMov-8230ea0228bd300316529c852858f7105ee75a3d.tar.bz2
SheMov-8230ea0228bd300316529c852858f7105ee75a3d.zip
Let ConsistencyChecker run in QThread
Until now ConsistencyChecker ran in the GUI-Thread. According to the docs the event loop of the QThread needs to be started to run something in the thread. So use a QTimer::singleShot() to start the check function.
Diffstat (limited to 'consistencycheck.cpp')
-rw-r--r--consistencycheck.cpp52
1 files changed, 32 insertions, 20 deletions
diff --git a/consistencycheck.cpp b/consistencycheck.cpp
index b281942..7e02304 100644
--- a/consistencycheck.cpp
+++ b/consistencycheck.cpp
@@ -20,8 +20,7 @@
#include <QBrush>
#include <QTextBlock>
#include <QCheckBox>
-
-#include <QDebug>
+#include <QTimer>
#include "consistencycheck.h"
#include "helper.h"
@@ -31,7 +30,7 @@ ConsistencyCheck::ConsistencyCheck(QWidget *parent, Qt::WindowFlags f) : QDialog
mCheckLabel = new QLabel(tr("Checking database consistency"));
mDisplay = new QPlainTextEdit;
mDisplay->setReadOnly(true);
- mCancelExit = new QPushButton(tr("Cancel"));
+ mCancelExit = new QPushButton(tr("Close"));
mCheckDb = new QPushButton(tr("Check database"));
mCheckFs = new QPushButton(tr("Check Filesystem"));
mErrorsOnly = new QCheckBox(tr("Show only errors"));
@@ -41,7 +40,7 @@ ConsistencyCheck::ConsistencyCheck(QWidget *parent, Qt::WindowFlags f) : QDialog
buttonLayout->addWidget(mCheckFs);
buttonLayout->addStretch();
buttonLayout->addWidget(mCancelExit);
- connect(mCancelExit, SIGNAL(clicked()), this, SLOT(cancelExit()));
+ connect(mCancelExit, SIGNAL(clicked()), this, SLOT(accept()));
// signal mapper
QSignalMapper *mapper = new QSignalMapper(this);
@@ -51,6 +50,11 @@ ConsistencyCheck::ConsistencyCheck(QWidget *parent, Qt::WindowFlags f) : QDialog
mapper->setMapping(mCheckFs, ConsistencyCheck::FsCheck);
connect(mapper, SIGNAL(mapped(int)), this, SLOT(startChecker(int)));
+ //misc
+ mChecker = new ConsistencyChecker(this);
+ connect(mChecker, SIGNAL(started()), this, SLOT(checkerStarted()));
+ connect(mChecker, SIGNAL(finished()), this, SLOT(checkerFinished()));
+
// main layout
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(mCheckLabel);
@@ -62,7 +66,6 @@ ConsistencyCheck::ConsistencyCheck(QWidget *parent, Qt::WindowFlags f) : QDialog
}
void ConsistencyCheck::startChecker(int checkerType){
- mChecker = new ConsistencyChecker;
if(mChecker->status() == ConsistencyChecker::Fail){
return;
}
@@ -96,14 +99,25 @@ void ConsistencyCheck::addMessage(const QString &message){
cursor.insertText(message);
}
-void ConsistencyCheck::cancelExit(){
- if(mChecker->isRunning()){
- mChecker->cancel(true);
- mCancelExit->setText(tr("Close"));
- connect(mCancelExit, SIGNAL(clicked()), this, SLOT(accept()));
- }else{
- close();
- }
+void ConsistencyCheck::checkerStarted(){
+ mCheckDb->setEnabled(false);
+ mCheckFs->setEnabled(false);
+ mCancelExit->setText(tr("Cancel"));
+ mCancelExit->disconnect();
+ connect(mCancelExit, SIGNAL(clicked()), this, SLOT(cancelChecker()));
+}
+
+void ConsistencyCheck::checkerFinished(){
+ mCheckDb->setEnabled(true);
+ mCheckFs->setEnabled(true);
+ mCancelExit->setText(tr("Close"));
+ mCancelExit->disconnect();
+ connect(mCancelExit, SIGNAL(clicked()), this, SLOT(accept()));
+ mChecker->setCancel(false);
+}
+
+void ConsistencyCheck::cancelChecker(){
+ mChecker->setCancel(true);
}
void ConsistencyCheck::showErrorsChanged(int state){
@@ -111,7 +125,6 @@ void ConsistencyCheck::showErrorsChanged(int state){
for(QTextBlock it = doc->begin(); it != doc->end(); it = it.next()){
if(it.text().startsWith("OK")){
if(state == Qt::Checked){
- qDebug() << it.text();
it.setVisible(false);
}else{
it.setVisible(true);
@@ -134,12 +147,9 @@ void ConsistencyChecker::check(){
}
}
-void ConsistencyChecker::cancel(bool cancel){
- if(!cancel){
- return;
- }
+void ConsistencyChecker::setCancel(bool cancel){
QMutexLocker locker(&mCancelMutex);
- mCanceled = true;
+ mCanceled = cancel;
}
ConsistencyChecker::~ConsistencyChecker(){
@@ -149,7 +159,8 @@ ConsistencyChecker::~ConsistencyChecker(){
void ConsistencyChecker::run(){
switch(mMode){
case ConsistencyCheck::DbCheck:
- dbCheck();
+ QTimer::singleShot(0, this, SLOT(dbCheck()));
+ exec();
break;
default:
;
@@ -187,6 +198,7 @@ void ConsistencyChecker::dbCheck(){
}
}
}
+ quit();
}
QString ConsistencyChecker::archivePath(const QString &fileName, const QString &md5sum) const {