From 6d3b28f9b12964b161b5a7ac0038435cfdd6e27b Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 31 Jul 2010 11:05:59 +0200 Subject: Added database maintenance code Implemented a function in MappingTableModel to remove all actors/genres with no references in the according mapping table. Available through the "File" menu. --- archivetreeview.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'archivetreeview.cpp') diff --git a/archivetreeview.cpp b/archivetreeview.cpp index 1ae3cc8..1d66fbe 100644 --- a/archivetreeview.cpp +++ b/archivetreeview.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include "archivetreeview.h" #include "smglobals.h" @@ -99,6 +100,34 @@ void ArchiveTreeView::setFileViewMode(int mode){ constructWindowTitle(); } +void ArchiveTreeView::cleanDatabase(const QString &table){ + MappingTableModel *model = 0; + if(table == "genres"){ + model = mGenresModel; + }else if(table == "actors"){ + model = mActorsModel; + } + Q_ASSERT(model); + QHash zeroUsers = model->zeroUsers(); + if(zeroUsers.isEmpty()){ + QMessageBox::information(this, tr("Message"), tr("Nothing to clean up!")); + return; + } + QString message = QString(tr("

Really delete these items from %1?

")).arg(table); + message.append("

    "); + QStringList userNames = zeroUsers.keys(); + qSort(userNames); + foreach(QString s, userNames){ + message.append(QString("
  • %1
  • ").arg(s)); + } + message.append("
"); + int answer = QMessageBox::question(this, tr("Question"), message, QMessageBox::Yes | QMessageBox::No); + if(answer == QMessageBox::Yes){ + QList ids = zeroUsers.values(); + model->deleteItems(ids); + } +} + void ArchiveTreeView::currentChanged(const QItemSelection &selected, const QItemSelection &deselected){ Q_UNUSED(selected); Q_UNUSED(deselected); -- cgit v1.2.3-70-g09d2