summaryrefslogtreecommitdiffstats
path: root/smmodelsingleton.cpp
blob: d850c9d8514a5584603bb6f79c850ecf146eecaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
  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 "smmodelsingleton.h"
#include "seriestreemodel.h"
#include "filestreemodel.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")){
			QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL", "treedb");
			db.setHostName("hadante");
			db.setUserName("shemov");
			db.setPassword("shemov");
			db.setDatabaseName("shemov2");
			db.open();
		}
	}
	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("P") << tr("Size") << tr("Q") << tr("DvdNo") << 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);
		}
	}
	return mModels.contains(which) ? mModels.value(which ) : 0;
}