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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
/*
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 <QX11Info>
#include <X11/Xlib.h>
#include <X11/extensions/Xfixes.h>
#include "smglobals.h"
#include "seriestreemodel.h"
#include "filestreemodel.h"
#include "mappingtablemodel.h"
#include "pictureviewer.h"
SmGlobals *SmGlobals::mInstance = 0;
SmGlobals::~SmGlobals(){
foreach(QAbstractItemModel *model, mModels.values()){
delete model;
}
QSqlDatabase::removeDatabase("treedb");
}
SmGlobals *SmGlobals::instance(){
if(!mInstance){
mInstance = new SmGlobals;
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 *SmGlobals::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 (int)") << tr("Type") << tr("Md5 sum") << tr("Series part ID") << tr("File ID") << tr("Seriespart") << tr("Display name") << tr("Dur./Size") << tr("Series name");
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;
}
PictureViewer *SmGlobals::pictureViewer() {
if(!mPictureViewer){
mPictureViewer = new PictureViewer;
}
return mPictureViewer;
}
QSize SmGlobals::cursorSize() {
if(!mCursorSize.isValid()){
XFixesCursorImage *curImage = XFixesGetCursorImage(QX11Info::display());
mCursorSize = QSize(curImage->width, curImage->height);
XFree(curImage);
}
return mCursorSize;
}
SmGlobals::SmGlobals() : mPictureViewer(0) {}
|