From d3c5cf915f71ada6324277bc427796b9739c6cb8 Mon Sep 17 00:00:00 2001 From: Arno Date: Fri, 16 Dec 2011 11:52:56 +0100 Subject: DbAnalyzer first try Well, trying to join the consistencyChecker and the check for stray actors/genres. First try :) --- dbanalyzer.cpp | 160 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 dbanalyzer.cpp (limited to 'dbanalyzer.cpp') diff --git a/dbanalyzer.cpp b/dbanalyzer.cpp new file mode 100644 index 0000000..87d3dd2 --- /dev/null +++ b/dbanalyzer.cpp @@ -0,0 +1,160 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "dbanalyzer.h" +#include "smtreemodel.h" +#include "smtreeitem.h" + +DbAnalyzerDialog::DbAnalyzerDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){ + //create tab widget + mTab = new QTabWidget; + + //setup analyzer + mAnalyzer = new DbAnalyzer(this); + + // no actors + QWidget *noActorsT = new QWidget; + QStringList noActorsHeaders = QStringList() << tr("Series") << tr("Series part") << tr("Series Id") << tr("Seriespart"); + mNoActorsV = new QTreeView; + mNoActorsM = new SmTreeModel(noActorsHeaders, this); + mNoActorsV->setModel(mNoActorsM); + QVBoxLayout *noActorsL = new QVBoxLayout; + noActorsL->addWidget(mNoActorsV); + mNoActorsV->setColumnHidden(1, true); + mNoActorsV->setColumnHidden(2, true); + mNoActorsV->setColumnHidden(3, true); + mNoActorsV->setEditTriggers(QTreeView::NoEditTriggers); + mNoActorsV->setSelectionBehavior(QAbstractItemView::SelectRows); + mNoActorsV->setSelectionMode(QAbstractItemView::SingleSelection); + connect(mNoActorsV, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(noActorsDoubleClicked(QModelIndex))); + noActorsT->setLayout(noActorsL); + + //buttons + mCancel = new QPushButton(tr("Cancel")); + connect(mCancel, SIGNAL(clicked()), this, SLOT(cancelAnalyzer())); + mClose = new QPushButton(tr("Close")); + connect(mClose, SIGNAL(clicked()), this, SLOT(accept())); + + //setup dialog + mTab->addTab(noActorsT, tr("No Actors")); + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(mTab); + QHBoxLayout *buttonLayout = new QHBoxLayout; + buttonLayout->addStretch(); + buttonLayout->addWidget(mCancel); + buttonLayout->addWidget(mClose); + mainLayout->addLayout(buttonLayout); + setLayout(mainLayout); + setMinimumWidth(500); + + //get things going + connect(mAnalyzer, SIGNAL(started()), this, SLOT(analyzerStarted())); + connect(mAnalyzer, SIGNAL(finished()), this, SLOT(analyzerFinished())); + mAnalyzer->start(); +} + +void DbAnalyzerDialog::cancelAnalyzer(){ + mAnalyzer->setCancel(true); +} + +void DbAnalyzerDialog::analyzerStarted(){ + mCancel->setEnabled(true); + mClose->setEnabled(false); +} + +void DbAnalyzerDialog::analyzerFinished(){ + mCancel->setEnabled(false); + mClose->setEnabled(true); + populateNoActors(); +} + +void DbAnalyzerDialog::noActorsDoubleClicked(const QModelIndex &idx){ + qDebug() << idx; + if(!idx.isValid()){ + return; + } + QModelIndex seriesPartIdx = mNoActorsM->index(idx.row(), 3, idx.parent()); + QModelIndex seriesIdx = mNoActorsM->index(idx.row(), 2, idx.parent()); + qDebug() << seriesPartIdx << seriesIdx; + //if(spIdx.isValid()){ + emit partClicked(seriesPartIdx.data().toInt(), seriesIdx.data().toInt()); + //} +} + +void DbAnalyzerDialog::populateNoActors(){ + const int columns = 4; + QList > noActors = mAnalyzer->noActors(); + SmTreeItem *root = new SmTreeItem(columns); + foreach(QList l, noActors){ + SmTreeItem *child = new SmTreeItem(l, root); + root->appendChild(child); + } + mNoActorsM->setRoot(root); + mNoActorsV->resizeColumnToContents(0); +} + +DbAnalyzer::DbAnalyzer(QObject *parent) : QThread(parent), mCanceled(false), mStatus(Fail) { + mDb = QSqlDatabase::cloneDatabase(QSqlDatabase::database("treedb"), "analyzerDB"); + mDb.open(); + mStatus = mDb.isOpen() ? Ok : Fail; + mNoActorQuery = new QSqlQuery(mDb); + mNoActorQuery->prepare("SELECT series.tseries_name, seriesparts.iseriespart, series.iseries_id, seriesparts.iseriesparts_id FROM series, seriesparts LEFT JOIN seriesparts_actormap ON seriesparts.iseriesparts_id = seriesparts_actormap.iseriesparts_id WHERE iactors_id IS NULL AND seriesparts.iseries_id = series.iseries_id ORDER BY tseries_name"); +} + +DbAnalyzer::~DbAnalyzer(){ + delete mNoActorQuery; + mDb.close(); +} + +void DbAnalyzer::setCancel(bool canceled){ + QMutexLocker m(&mCancelMutex); + mCanceled = canceled; +} + +void DbAnalyzer::run(){ + noActorsCheck(); +} + +void DbAnalyzer::noActorsCheck(){ + if(!mNoActorQuery->exec()){ + mStatus = Fail; + return; + } + emit message(tr("Fetching movies without actors")); + while(mNoActorQuery->next()){ + if(mCanceled){ + break; + } + QList res; + for(int i = 0; i < 4; ++i){ + if(i == 0){ + if(mNoActorQuery->value(1).toInt() > 1){ + QString title = QString("%1 %2").arg(mNoActorQuery->value(0).toString(), mNoActorQuery->value(1).toString()); + res << title; + continue; + }else{ + res << mNoActorQuery->value(0); + } + } + res << mNoActorQuery->value(i); + } + mNoActorR << res; + } + emit message(tr("Done!")); +} -- cgit v1.2.3-70-g09d2