summaryrefslogtreecommitdiffstats
path: root/dbanalyzer.cpp
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2011-12-16 11:52:56 +0100
committerArno <am@disconnect.de>2011-12-16 11:52:56 +0100
commitd3c5cf915f71ada6324277bc427796b9739c6cb8 (patch)
tree641ebcce1606d0e0c8b05b4486757b58e0c51857 /dbanalyzer.cpp
parentb0ed5d04a5934be074383541026d49afc0804adb (diff)
downloadSheMov-d3c5cf915f71ada6324277bc427796b9739c6cb8.tar.gz
SheMov-d3c5cf915f71ada6324277bc427796b9739c6cb8.tar.bz2
SheMov-d3c5cf915f71ada6324277bc427796b9739c6cb8.zip
DbAnalyzer first try
Well, trying to join the consistencyChecker and the check for stray actors/genres. First try :)
Diffstat (limited to 'dbanalyzer.cpp')
-rw-r--r--dbanalyzer.cpp160
1 files changed, 160 insertions, 0 deletions
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 <QSqlQuery>
+#include <QTableWidget>
+#include <QTreeView>
+#include <QPushButton>
+#include <QHBoxLayout>
+#include <QVBoxLayout>
+#include <QMutexLocker>
+#include <QTableWidget>
+#include <QModelIndex>
+
+#include <QDebug>
+
+#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<QList<QVariant> > noActors = mAnalyzer->noActors();
+ SmTreeItem *root = new SmTreeItem(columns);
+ foreach(QList<QVariant> 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<QVariant> 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!"));
+}