diff options
Diffstat (limited to 'smmodelsingleton.cpp')
-rw-r--r-- | smmodelsingleton.cpp | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/smmodelsingleton.cpp b/smmodelsingleton.cpp deleted file mode 100644 index 41959a5..0000000 --- a/smmodelsingleton.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - 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 <QSqlDatabase> -#include <QAbstractItemModel> -#include <QStringList> -#include <QMessageBox> -#include <QSettings> - -#include "smmodelsingleton.h" -#include "seriestreemodel.h" -#include "filestreemodel.h" -#include "mappingtablemodel.h" - -SmModelSingleton *SmModelSingleton::mInstance = 0; - -SmModelSingleton::~SmModelSingleton(){ - foreach(QAbstractItemModel *model, mModels.values()){ - delete model; - } - QSqlDatabase::removeDatabase("treedb"); -} - -SmModelSingleton *SmModelSingleton::instance(){ - if(!mInstance){ - mInstance = new SmModelSingleton; - if(!QSqlDatabase::contains("treedb")){ - QSettings s; - QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL", "treedb"); - db.setHostName(s.value("database/hostname").toString()); - db.setUserName(s.value("database/dbuser").toString()); - db.setPassword(s.value("database/dbpass").toString()); - db.setDatabaseName(s.value("database/dbname").toString()); - if(!db.open()){ - QMessageBox::critical(0, tr("Error"), tr("Could not open database. Please configure it and restart program.")); - } - } - } - return mInstance; -} - -QAbstractItemModel *SmModelSingleton::model(const QString &which){ - if(which == "SeriesModel"){ - if(!mModels.contains(which)){ - QStringList headers = QStringList() << tr("Series") << tr("Series ID") << tr("Series part ID") << tr("Part") << tr("Type"); - SeriesTreeModel *model = new SeriesTreeModel(headers); - mModels.insert(which, model); - } - }else if(which == "FilesModel"){ - if(!mModels.contains(which)){ - QStringList headers = QStringList() << tr("Name") << tr("Part") << tr("Size") << tr("Qual.") << tr("Dvd") << tr("Full Path") << tr("Size") << tr("Type") << tr("Md5 sum") << tr("Series part ID") << tr("File ID"); - FilesTreeModel *model = new FilesTreeModel(headers); - mModels.insert(which, model); - } - }else if(which == "actors"){ - if(!mModels.contains(which)){ - QStringList headers = QStringList() << tr("Actor") << tr("Id"); - MappingTableModel *model = new MappingTableModel(headers, "actors"); - mModels.insert(which, model); - } - }else if(which == "genres"){ - if(!mModels.contains(which)){ - QStringList headers = QStringList() << tr("Genre") << tr("Id"); - MappingTableModel *model = new MappingTableModel(headers, "genres"); - mModels.insert(which, model); - } - } - return mModels.contains(which) ? mModels.value(which) : 0; -} |