summaryrefslogtreecommitdiffstats
path: root/smglobals.cpp
blob: aff8e1b27afd44a8388207b472531c0d67810541 (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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
  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 <QtWidgets/QMessageBox>
#include <QSettings>
#include <QDir>
#include <QFile>
#include <QDataStream>
#include <QFileInfo>
#include <QTemporaryFile>
#include <QProcess>

#include "smglobals.h"
#include "archivemodel.h"
#include "mappingtablemodel.h"
#include "mappingtreemodel.h"
#include "pictureviewer2.h"
#include "picfilesmodel.h"
#include "configurationdialog.h"
#include "archivecontroller.h"
#include "archivebrowsermodel.h"

#include <X11/Xlib.h>
#include <X11/extensions/Xfixes.h>


SmGlobals *SmGlobals::mInstance = 0;

SmGlobals::~SmGlobals(){
	foreach(QAbstractItemModel *model, mModels.values()){
        model->deleteLater();
	}
}

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."));
                ConfigurationDialog configDlg;
                configDlg.exec();
                QMessageBox::information(0, tr("Notice"), tr("I will exit now. Start me again!"));
                exit(EXIT_SUCCESS);
			}
		}
	}
	return mInstance;
}

QAbstractItemModel *SmGlobals::model(const QString &which){
    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);
		}
    }else if(which == "MappingTree"){
        if(!mModels.contains("MappingTree")){
            QStringList headers = QStringList() << tr("Name") << tr("Id") << tr("Date") << tr("Parent") << tr("PPID");
            MappingTreeModel *model = new MappingTreeModel(headers);
            mModels.insert(which, model);
        }
    }else if(which == "PicFiles"){
        if(!mModels.contains("PicFiles")){
            QStringList headers = QStringList() << tr("Filename") << tr("Size") << tr("Format") << tr("Full Path") << tr("Id") << tr("Added") << tr("Md5Sum") << tr("Pic. Size");
            PicFilesModel *model = new PicFilesModel(headers);
            mModels.insert(which, model);
        }
    }else if(which == "ArchiveModel"){
        if(!mModels.contains("ArchiveModel")){
            QStringList headers = QStringList() << tr("Series") << tr("Series ID") << tr("Series part ID") << tr("Part") << tr("Type") << tr("Favorite") << tr("Subtitle") << tr("Count");
            ArchiveModel *model = new ArchiveModel(headers);
            mModels.insert(which, model);
        }
    }else if(which == "BrowserModel"){
        if(!mModels.contains("BrowserModel")){
            QStringList headers = QStringList() << QChar(0x26A7) << tr("Name") << tr("Generic Id") << tr("Node Type") << tr("Size") << tr("Quality") << tr("File Type") << tr("Full Path") << tr("Selected");
            ArchiveBrowserModel *model = new ArchiveBrowserModel(headers);
            mModels.insert(which, model);
        }
    }
	return mModels.contains(which) ? mModels.value(which) : 0;
}

PictureViewer2 *SmGlobals::pictureViewer() {
	if(!mPictureViewer){
        mPictureViewer = new PictureViewer2;
	}
	return mPictureViewer;
}

QSize SmGlobals::cursorSize() {
	if(!mCursorSize.isValid()){
        Display *dpy = XOpenDisplay(0);
        XFixesCursorImage *curImage = XFixesGetCursorImage(dpy);
		mCursorSize = QSize(curImage->width, curImage->height);
		XFree(curImage);
	}
	return mCursorSize;
}

QIcon SmGlobals::iconFor(const QString &type){
    QString settingsS = QString("ui/%1icon").arg(type);
    QSettings s;
    QString iconS = s.value(settingsS, "Dildo").toString();
    QIcon retval = QIcon(mIcons.value(iconS));
    return retval;
}

SmGlobals::SmGlobals() : mPictureViewer(0), mArchiveController(0){
	mIcons.insert("Dildo", ":/dildo.png");
	mIcons.insert("Dick to left", ":/back_dick.png");
	mIcons.insert("Dick pointing up", ":/up_dick.png");
	mIcons.insert("Chastity belt", ":/chastity_belt.png");
	mIcons.insert("Clitoris", ":/clitoris.png");
	mIcons.insert("Gaping ass", ":/gaping_ass.png");
	mIcons.insert("Nipple pointing up", ":/nipple_up.png");
	mIcons.insert("Bald pussy", ":/bald_pussy.png");
	mIcons.insert("Prince Albert", ":/prince_albert.png");
	mIcons.insert("Diaper", ":/diaper.png");
	mIcons.insert("High heels", ":/higheels.png");
	mIcons.insert("Ball gag", ":/ball_gag.png");
	mIcons.insert("French Maid Dress", ":/french_maid_dress.png");
	mIcons.insert("Shackles", ":/shackles.png");
	mIcons.insert("Steel collar", ":/steel_collar.png");
	mIcons.insert("Butt plug", ":/butt_plug.png");
	mIcons.insert("Hourglass figure", ":/hourglass_figure.png");
	mIcons.insert("Big ass", ":/big_ass.png");
	mIcons.insert("Big tit", ":/big_tit.png");
	mIcons.insert("Bizarre amputee", ":/bizarre_amputee.png");
	mIcons.insert("Spreading pants", ":/spreadingpants.png");
	mIcons.insert("Leather dog hood", ":/dog_hood.png");
	mIcons.insert("Male chastity belt", ":/male_chastity_belt.png");
	mIcons.insert("Anal stretcher", ":/analstretcher.png");
    mIcons.insert("Big balls", ":/big_balls.png");
    mIcons.insert("Big pierced balls", ":/huge_balls_pierced.png");
    mIcons.insert("Huge bra", ":/huge_bra.png");
    mIcons.insert("Squirting nipple", ":/squirting_nipple.png");
    mIcons.insert("Dick in a cage", ":/dick_in_cage.png");
    mIcons.insert("Used tampon", ":/used_tampon.png");
    mIcons.insert("Clean tampon", ":/clean_tampon.png");
    mFiletypeMap.insert(FT_MOVIE, tr("Movie"));
    mFiletypeMap.insert(FT_FRONTCOVER, tr("Front Cover"));
    mFiletypeMap.insert(FT_BACKCOVER, tr("Back Cover"));
    mFiletypeMap.insert(FT_GENERALCOVER, tr("General Cover"));
    mFiletypeMap.insert(FT_ORIGIN, tr("Origin"));
    QSettings s;
    mReencReasons = s.value("ui/reasons").toStringList();
}

void SmGlobals::registerWidget(const QString &name, QWidget *w){
    mWidgets.insert(name, w);
}

void SmGlobals::setReencReasons(const QStringList reasons){
    mReencReasons = reasons;
    qSort(mReencReasons);
    QSettings s;
    s.setValue("ui/reasons", mReencReasons);
}