From b8a793f4a1afcd27cf03da7b620dd7a4f7f5813f Mon Sep 17 00:00:00 2001 From: Arno Date: Mon, 1 Nov 2010 20:25:59 +0100 Subject: Finished database consistency check Made the database consistency check work and added a filter to only show error messages in the output. The cause of the inconsistency still has to be investigated, though. --- consistencycheck.cpp | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'consistencycheck.cpp') diff --git a/consistencycheck.cpp b/consistencycheck.cpp index 38aa4a1..b281942 100644 --- a/consistencycheck.cpp +++ b/consistencycheck.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include #include @@ -18,6 +18,10 @@ #include #include #include +#include +#include + +#include #include "consistencycheck.h" #include "helper.h" @@ -25,10 +29,13 @@ ConsistencyCheck::ConsistencyCheck(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f), mChecker(0){ // setup widget mCheckLabel = new QLabel(tr("Checking database consistency")); - mDisplay = new QTextEdit; + mDisplay = new QPlainTextEdit; + mDisplay->setReadOnly(true); mCancelExit = new QPushButton(tr("Cancel")); mCheckDb = new QPushButton(tr("Check database")); mCheckFs = new QPushButton(tr("Check Filesystem")); + mErrorsOnly = new QCheckBox(tr("Show only errors")); + connect(mErrorsOnly, SIGNAL(stateChanged(int)), this, SLOT(showErrorsChanged(int))); QHBoxLayout *buttonLayout = new QHBoxLayout; buttonLayout->addWidget(mCheckDb); buttonLayout->addWidget(mCheckFs); @@ -48,6 +55,7 @@ ConsistencyCheck::ConsistencyCheck(QWidget *parent, Qt::WindowFlags f) : QDialog QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(mCheckLabel); mainLayout->addWidget(mDisplay); + mainLayout->addWidget(mErrorsOnly); mainLayout->addLayout(buttonLayout); setWindowTitle(tr("Checking consistency")); setLayout(mainLayout); @@ -80,7 +88,10 @@ void ConsistencyCheck::addMessage(const QString &message){ }else{ fmt.setForeground(QBrush(Qt::red)); } - cursor.insertBlock(); + QTextBlock curBlock = cursor.block(); + if(!curBlock.text().isEmpty()){ + cursor.insertBlock(); + } cursor.setCharFormat(fmt); cursor.insertText(message); } @@ -95,6 +106,21 @@ void ConsistencyCheck::cancelExit(){ } } +void ConsistencyCheck::showErrorsChanged(int state){ + QTextDocument *doc = mDisplay->document(); + 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); + } + } + } + mDisplay->viewport()->update(); +} + ConsistencyChecker::ConsistencyChecker(QObject *parent) : QThread(parent), mCanceled(false), mMode(-1), mStatus(Ok){ mDb = QSqlDatabase::cloneDatabase(QSqlDatabase::database("treedb"), "checkerDb"); if(!mDb.open()){ @@ -155,7 +181,8 @@ void ConsistencyChecker::dbCheck(){ if(mimeType.startsWith("image")){ emit consistencyMsg(QString(tr("OK: %1")).arg(fileName)); }else{ - emit consistencyMsg(QString(tr("FOUND: %1")).arg(fileName)); + QString msg = QString(tr("FOUND: %1 (DVD: %2)")).arg(fullPath).arg(dvdNo); + emit consistencyMsg(msg); } } } -- cgit v1.2.3-70-g09d2