/
pchandler.cpp
146 lines (122 loc) · 3.8 KB
/
pchandler.cpp
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
#include <iostream>
#include "pchandler.h"
#include <qobject.h>
#include <qsqldatabase.h>
#include <sys/types.h>
#include <unistd.h>
#include <mythtv/mythcontext.h>
#include <qfile.h>
#include <qdom.h>
#include <string>
#include "pcsettingsdlg.h"
using namespace std;
PCHandler::~PCHandler()
{
}
void PCHandler::processGames()
{
QString thequery;
QSqlDatabase* db = QSqlDatabase::database();
thequery = "DELETE FROM gamemetadata WHERE system = \"PC\";";
db->exec(thequery);
QString GameDoc = gContext->GetSetting("PCGameList");
if(!QFile::exists(GameDoc))
return;
QDomDocument doc;
QFile f(GameDoc);
if (!f.open(IO_ReadOnly))
{
cout << "Can't open: " << GameDoc << endl;
return;
}
QString errorMsg;
int errorLine = 0;
int errorColumn = 0;
if (!doc.setContent(&f, false, &errorMsg, &errorLine, &errorColumn))
{
cout << "Error parsing: " << GameDoc << endl;
cout << "at line: " << errorLine << " column: " << errorColumn << endl;
cout << errorMsg << endl;
f.close();
return;
}
f.close();
QDomElement docElem = doc.documentElement();
QDomNode n = docElem.firstChild();
while (!n.isNull())
{
QDomElement e = n.toElement();
if (!e.isNull())
{
if (e.tagName() == "game")
{
QString GameName = "";
QString Command = "";
QString Genre = "";
int Year = 0;
QDomNode i = e.firstChild();
while (!i.isNull())
{
QDomElement setting = i.toElement();
if (!setting.isNull())
{
if (setting.tagName() == "name")
GameName = setting.text();
else if (setting.tagName() == "command")
Command = setting.text();
else if (setting.tagName() == "genre")
Genre = setting.text();
else if (setting.tagName() == "year")
Year = setting.text().toInt();
}
i = i.nextSibling();
}
if(GameName != "" && Command != "")
{
thequery = QString("INSERT INTO gamemetadata "
"(system, romname, gamename, genre, year) "
"VALUES (\"PC\", \"%1\", \"%2\", \"%3\", %4);")
.arg(Command.latin1())
.arg(GameName.latin1()).arg(Genre.latin1())
.arg(Year);
db->exec(thequery);
}
}
}
n = n.nextSibling();
}
}
void PCHandler::start_game(RomInfo * romdata)
{
// Run the game and wait for it to terminate.
FILE* command = popen(romdata->Romname(), "w");
pclose(command);
}
void PCHandler::edit_settings(QWidget *parent,RomInfo * romdata)
{
PCRomInfo *pcdata = dynamic_cast<PCRomInfo*>(romdata);
PCSettingsDlg settingsdlg(parent, "gamesettings", true);
QString ImageFile;
if(pcdata->FindImage("screenshot", &ImageFile))
settingsdlg.SetScreenshot(ImageFile);
settingsdlg.Show(pcdata);
}
void PCHandler::edit_system_settings(QWidget *parent,RomInfo * romdata)
{
romdata = romdata;
PCSettingsDlg settingsDlg(parent, "pcsettings", true, true);
settingsDlg.Show(NULL);
}
PCHandler* PCHandler::getHandler(void)
{
if(!pInstance)
{
pInstance = new PCHandler();
}
return pInstance;
}
PCRomInfo* PCHandler::create_rominfo(RomInfo *parent)
{
return new PCRomInfo(*parent);
}
PCHandler* PCHandler::pInstance = 0;