-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpconfig.cpp
179 lines (149 loc) · 3.54 KB
/
gpconfig.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
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
#include "gpconfig.h"
#include <QtDebug>
#include <QSpinBox>
#include <QCheckBox>
#include <QTextStream>
#include <QUrl>
#include <QList>
#include <QSettings>
#include <QLabel>
#include "palette.h"
static QList<GameConfig> m_config;
GameParam* GameParam::createObject(QString text, const QStringList& params)
{
if(params.empty())
return 0;
switch(params[0].toLong())
{
case 2: // input range
if(params.size() >= 3)
return new GameParamInputRange(text, params);
else
{
qCritical("Invalid param count (GameParamInputRange), got only %d\n", params.size());
return 0;
}
case 3: // boolean
return new GameParamBoolean(text);
default:
return 0;
}
}
GameParamInputRange::GameParamInputRange(QString text, const QStringList& params)
: GameParam(text)
{
m_min = params[1].toLong();
m_max = params[2].toLong();
}
void GameParamInputRange::createWidget(QString value, QWidget** left, QWidget** right)
{
QSpinBox* pBox = new QSpinBox;
*left = new QLabel(m_strText);
*right = pBox;
applyPalette(*left, PaletteMain);
applyPalette(*right, PaletteEdit);
pBox->setRange(m_min,m_max);
pBox->setValue(value.toLong());
}
QString GameParamInputRange::getWidgetValue(QWidget* pWidget)
{
QSpinBox* pBox = (QSpinBox*) pWidget;
return QString::number(pBox->value());
}
GameParamBoolean::GameParamBoolean(QString text)
: GameParam(text)
{
}
void GameParamBoolean::createWidget(QString value, QWidget** left, QWidget** right)
{
QCheckBox* box = new QCheckBox(m_strText);
if(value.startsWith("true", Qt::CaseInsensitive))
box->setCheckState(Qt::Checked);
applyPalette(box, PaletteCheck);
*right = box;
*left = 0;
}
QString GameParamBoolean::getWidgetValue(QWidget* pWidget)
{
QCheckBox* box = (QCheckBox*) pWidget;
return (box->checkState() == Qt::Checked) ? "True" : "False";
}
bool haveGameConfig()
{
return !m_config.empty();
}
QString processGameConfig(QBuffer& buffer)
{
QTextStream stream(&buffer);
QString skin;
while(!stream.atEnd())
{
GameConfig conf;
QStringList params = stream.readLine().trimmed().split('\t');
if(!params.size())
continue;
if(params[0] == "skin")
{
skin = params[1];
}
else if(params.size() == 5)
{
conf.id = params[0];
conf.command = params[1];
conf.name = params[2];
conf.protoid = params[3].toLong();
conf.poffset = params[4].toLong();
m_config.append(conf);
}
}
return skin;
}
QList<GameConfig>& getGameConfig()
{
return m_config;
}
QString getStartCommand(QString format, QString id, QString ip, QString port, QString nick, QString password)
{
QString cmd = "\"", def;
QSettings settings;
int limpos;
qDebug() << "Format string:" << format;
format.replace(":s", "");
format.replace("%5", "%2");
format.replace("%6", "%3");
foreach(GameConfig cfg, m_config)
{
if(cfg.id == id)
{
def = cfg.command;
break;
}
}
qDebug() << "Format string:" << format;
qDebug() << "Game command:" << settings.value(QString("games/")+id, cmd).toString();
cmd += settings.value(QString("games/")+id, def).toString();
cmd += "\" ";
format = format.arg(ip).arg(port);
if(format.contains("%2"))
format = format.arg(nick);
limpos = format.indexOf("%3:.");
if(limpos != -1)
{
QByteArray ascii = format.toAscii();
int num = atoi(ascii.constData()+limpos+4);
password.truncate( num );
format.replace(QString("%3:.%1s").arg(num), "%3");
}
cmd += format.arg(password);
qDebug() << "Command to execute:" << cmd;
return cmd;
}
bool haveGameConfig(QString id)
{
foreach(GameConfig cfg, m_config)
{
if(cfg.id == id)
return true;
}
return false;
}