author | koda |
Sat, 08 Dec 2012 15:35:03 +0100 | |
changeset 8270 | 16a52ad5a362 |
parent 8268 | fe4e94311585 |
child 8274 | 7324298dbcc1 |
permissions | -rw-r--r-- |
6700 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
6952 | 3 |
* Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com> |
6700 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*/ |
|
18 |
||
19 |
#include <QHBoxLayout> |
|
20 |
#include <QLineEdit> |
|
21 |
#include <QTextBrowser> |
|
22 |
#include <QLabel> |
|
8268 | 23 |
#include <QHttp> |
8250 | 24 |
#include <QSysInfo> |
8268 | 25 |
#include <QDebug> |
26 |
#include <QBuffer> |
|
8250 | 27 |
#include <QApplication> |
28 |
#include <QDesktopWidget> |
|
8268 | 29 |
#include <QNetworkReply> |
8252 | 30 |
#include <QProcess> |
8268 | 31 |
#include <QMessageBox> |
8250 | 32 |
|
8252 | 33 |
#include <string> |
8250 | 34 |
|
35 |
#ifdef Q_WS_WIN |
|
36 |
#define WINVER 0x0500 |
|
37 |
#include <windows.h> |
|
8252 | 38 |
#else |
39 |
#include <unistd.h> |
|
40 |
#include <sys/types.h> |
|
8250 | 41 |
#endif |
42 |
||
43 |
#ifdef Q_WS_MAC |
|
8252 | 44 |
#include <sys/sysctl.h> |
8250 | 45 |
#endif |
6700 | 46 |
|
8258
c14b27abe452
fix build on linux for me ( the uint32_t releated breakage )
sheepluva
parents:
8252
diff
changeset
|
47 |
#include <stdint.h> |
c14b27abe452
fix build on linux for me ( the uint32_t releated breakage )
sheepluva
parents:
8252
diff
changeset
|
48 |
|
6700 | 49 |
#include "pagefeedback.h" |
50 |
#include "hwconsts.h" |
|
51 |
||
52 |
QLayout * PageFeedback::bodyLayoutDefinition() |
|
53 |
{ |
|
54 |
QVBoxLayout * pageLayout = new QVBoxLayout(); |
|
55 |
QHBoxLayout * summaryLayout = new QHBoxLayout(); |
|
8268 | 56 |
QHBoxLayout * emailLayout = new QHBoxLayout(); |
57 |
QHBoxLayout * combinedTopLayout = new QHBoxLayout(); |
|
6700 | 58 |
|
59 |
info = new QLabel(); |
|
60 |
info->setText( |
|
61 |
"<style type=\"text/css\">" |
|
62 |
"a { color: #ffcc00; }" |
|
63 |
"</style>" |
|
64 |
"<div align=\"center\"><h1>Please give us a feedback!</h1>" |
|
65 |
"<h3>We are always happy about suggestions, ideas or bug reports.<h3>" |
|
66 |
"<h4>The feedback will be posted as a new issue on our Google Code page.<h4>" |
|
8268 | 67 |
//"<h4>Your email is optional, but if given, you will be notified of responses.<h4>" |
6700 | 68 |
"</div>" |
69 |
); |
|
70 |
pageLayout->addWidget(info); |
|
71 |
||
72 |
label_summary = new QLabel(); |
|
8268 | 73 |
label_summary->setText(QLabel::tr("Summary")); |
6700 | 74 |
summaryLayout->addWidget(label_summary); |
75 |
summary = new QLineEdit(); |
|
76 |
summaryLayout->addWidget(summary); |
|
8268 | 77 |
combinedTopLayout->addLayout(summaryLayout); |
78 |
||
79 |
label_email = new QLabel(); |
|
80 |
label_email->setText(QLabel::tr("Your Email")); |
|
81 |
emailLayout->addWidget(label_email); |
|
82 |
email = new QLineEdit(); |
|
83 |
emailLayout->addWidget(email); |
|
84 |
||
85 |
// Email -- although implemented -- doesn't seem to work as intended. |
|
86 |
// It's sent in the XML as a <issues:cc> , the <entry>, but it doesn't seem |
|
87 |
// to actually do anything. If you figure out how to fix that, uncomment these lines |
|
88 |
// and the line above in the 'info' QLabel to re-enable this feature. |
|
8270
16a52ad5a362
strip available ram entry, add notice for entering email
koda
parents:
8268
diff
changeset
|
89 |
combinedTopLayout->addLayout(emailLayout); |
16a52ad5a362
strip available ram entry, add notice for entering email
koda
parents:
8268
diff
changeset
|
90 |
combinedTopLayout->insertSpacing(1, 50); |
8268 | 91 |
|
92 |
pageLayout->addLayout(combinedTopLayout); |
|
6700 | 93 |
|
94 |
label_description = new QLabel(); |
|
95 |
label_description->setText(QLabel::tr("Description")); |
|
96 |
pageLayout->addWidget(label_description, 0, Qt::AlignHCenter); |
|
97 |
description = new QTextBrowser(); |
|
8252 | 98 |
|
8268 | 99 |
EmbedSystemInfo(); |
100 |
||
101 |
description->setReadOnly(false); |
|
102 |
pageLayout->addWidget(description); |
|
103 |
||
104 |
return pageLayout; |
|
105 |
} |
|
106 |
||
107 |
void PageFeedback::EmbedSystemInfo() |
|
108 |
{ |
|
8252 | 109 |
// Gather some information about the system and embed it into the report |
8250 | 110 |
QDesktopWidget* screen = QApplication::desktop(); |
111 |
QString os_version = "Operating system: "; |
|
112 |
QString qt_version = QString("Qt version: ") + QT_VERSION_STR + QString("\n"); |
|
8252 | 113 |
QString total_ram = "Total RAM: "; |
114 |
QString number_of_cores = "Number of cores: "; |
|
115 |
QString compiler_bits = "Compiler architecture: "; |
|
116 |
QString compiler_version = "Compiler version: "; |
|
117 |
QString kernel_line = "Kernel: "; |
|
8250 | 118 |
QString screen_size = "Size of the screen(s): " + |
119 |
QString::number(screen->width()) + "x" + QString::number(screen->height()) + "\n"; |
|
8252 | 120 |
QString number_of_screens = "Number of screens: " + QString::number(screen->screenCount()) + "\n"; |
121 |
std::string processor_name = "Processor: "; |
|
122 |
||
123 |
// platform specific code |
|
8250 | 124 |
#ifdef Q_WS_MACX |
8252 | 125 |
number_of_cores += QString::number(sysconf(_SC_NPROCESSORS_ONLN)) + "\n"; |
8250 | 126 |
|
8270
16a52ad5a362
strip available ram entry, add notice for entering email
koda
parents:
8268
diff
changeset
|
127 |
uint64_t memsize; |
8250 | 128 |
size_t len = sizeof(memsize); |
129 |
static int mib_s[2] = { CTL_HW, HW_MEMSIZE }; |
|
130 |
if (sysctl (mib_s, 2, &memsize, &len, NULL, 0) == 0) |
|
8252 | 131 |
total_ram += QString::number(memsize/1024/1024) + " MB\n"; |
8250 | 132 |
else |
8252 | 133 |
total_ram += "Error getting total RAM information\n"; |
134 |
||
8270
16a52ad5a362
strip available ram entry, add notice for entering email
koda
parents:
8268
diff
changeset
|
135 |
int mib[] = {CTL_KERN, KERN_OSRELEASE}; |
8250 | 136 |
sysctl(mib, sizeof mib / sizeof(int), NULL, &len, NULL, 0); |
137 |
||
138 |
char *kernelVersion = (char *)malloc(sizeof(char)*len); |
|
139 |
sysctl(mib, sizeof mib / sizeof(int), kernelVersion, &len, NULL, 0); |
|
140 |
||
141 |
QString kernelVersionStr = QString(kernelVersion); |
|
142 |
free(kernelVersion); |
|
143 |
int major_version = kernelVersionStr.split(".").first().toUInt() - 4; |
|
144 |
int minor_version = kernelVersionStr.split(".").at(1).toUInt(); |
|
145 |
os_version += QString("Mac OS X 10.%1.%2").arg(major_version).arg(minor_version) + " "; |
|
146 |
||
147 |
switch(major_version) |
|
148 |
{ |
|
149 |
case 4: os_version += "\"Tiger\"\n"; break; |
|
150 |
case 5: os_version += "\"Leopard\"\n"; break; |
|
151 |
case 6: os_version += "\"Snow Leopard\"\n"; break; |
|
152 |
case 7: os_version += "\"Lion\"\n"; break; |
|
153 |
case 8: os_version += "\"Mountain Lion\"\n"; break; |
|
154 |
default: os_version += "\"Unknown version\"\n"; break; |
|
155 |
} |
|
156 |
#endif |
|
157 |
#ifdef Q_WS_WIN |
|
158 |
SYSTEM_INFO sysinfo; |
|
159 |
GetSystemInfo(&sysinfo); |
|
8252 | 160 |
number_of_cores += QString::number(sysinfo.dwNumberOfProcessors) + "\n"; |
8250 | 161 |
MEMORYSTATUSEX status; |
162 |
status.dwLength = sizeof(status); |
|
163 |
GlobalMemoryStatusEx(&status); |
|
8270
16a52ad5a362
strip available ram entry, add notice for entering email
koda
parents:
8268
diff
changeset
|
164 |
total_ram += QString::number(status.ullTotalPhys); |
8250 | 165 |
|
166 |
switch(QSysInfo::WinVersion()) |
|
167 |
{ |
|
8252 | 168 |
case QSysInfo::WV_2000: os_version += "Windows 2000\n"; break; |
169 |
case QSysInfo::WV_XP: os_version += "Windows XP\n"; break; |
|
170 |
case QSysInfo::WV_VISTA: os_version += "Windows Vista\n"; break; |
|
171 |
case QSysInfo::WV_WINDOWS7: os_version += "Windows 7\n"; break; |
|
172 |
default: os_version += "Windows (Unknown version)\n"; break; |
|
8250 | 173 |
} |
8252 | 174 |
kernel_line += "Windows kernel\n"; |
8250 | 175 |
#endif |
176 |
#ifdef Q_WS_X11 |
|
8252 | 177 |
number_of_cores += QString::number(sysconf(_SC_NPROCESSORS_ONLN)) + "\n"; |
8250 | 178 |
long pages = sysconf(_SC_PHYS_PAGES), |
179 |
available_pages = sysconf(_SC_AVPHYS_PAGES), |
|
180 |
page_size = sysconf(_SC_PAGE_SIZE); |
|
8252 | 181 |
total_ram += QString::number(pages * page_size) + "\n"; |
182 |
os_version += "GNU/Linux or BSD\n"; |
|
8250 | 183 |
#endif |
8252 | 184 |
|
185 |
// uname -a |
|
186 |
#if defined(Q_WS_X11) || defined(Q_WS_MACX) |
|
187 |
QProcess *process = new QProcess(); |
|
188 |
QStringList arguments = QStringList("-a"); |
|
189 |
process->start("uname", arguments); |
|
190 |
if (process->waitForFinished()) |
|
191 |
kernel_line += QString(process->readAll()); |
|
192 |
delete process; |
|
193 |
#endif |
|
194 |
||
195 |
// cpu info |
|
8250 | 196 |
uint32_t registers[4]; |
8252 | 197 |
uint32_t i; |
8250 | 198 |
|
199 |
i = 0x80000002; |
|
200 |
asm volatile |
|
201 |
("cpuid" : "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]) |
|
202 |
: "a" (i), "c" (0)); |
|
203 |
processor_name += std::string((const char *)®isters[0], 4); |
|
204 |
processor_name += std::string((const char *)®isters[1], 4); |
|
205 |
processor_name += std::string((const char *)®isters[2], 4); |
|
206 |
processor_name += std::string((const char *)®isters[3], 4); |
|
207 |
i = 0x80000003; |
|
208 |
asm volatile |
|
209 |
("cpuid" : "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]) |
|
210 |
: "a" (i), "c" (0)); |
|
211 |
processor_name += std::string((const char *)®isters[0], 4); |
|
212 |
processor_name += std::string((const char *)®isters[1], 4); |
|
213 |
processor_name += std::string((const char *)®isters[2], 4); |
|
214 |
processor_name += std::string((const char *)®isters[3], 4); |
|
215 |
i = 0x80000004; |
|
216 |
asm volatile |
|
217 |
("cpuid" : "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]) |
|
218 |
: "a" (i), "c" (0)); |
|
219 |
processor_name += std::string((const char *)®isters[0], 4); |
|
220 |
processor_name += std::string((const char *)®isters[1], 4); |
|
221 |
processor_name += std::string((const char *)®isters[2], 4); |
|
222 |
processor_name += std::string((const char *)®isters[3], 3); |
|
8252 | 223 |
|
224 |
// compiler |
|
225 |
#ifdef __GNUC__ |
|
226 |
compiler_version += "GCC " + QString(__VERSION__) + "\n"; |
|
227 |
#else |
|
228 |
compiler_version += "Unknown\n"; |
|
229 |
#endif |
|
230 |
||
8250 | 231 |
if(sizeof(void*) == 4) |
8252 | 232 |
compiler_bits += "i386\n"; |
233 |
else if(sizeof(void*) == 8) |
|
234 |
compiler_bits += "x86_64\n"; |
|
235 |
||
236 |
// add everything to the field of text |
|
8250 | 237 |
description->setText( |
8270
16a52ad5a362
strip available ram entry, add notice for entering email
koda
parents:
8268
diff
changeset
|
238 |
"Don't forget to mention your email or you won't be able to receive updates on this topic!" |
8252 | 239 |
"\n\n\n\n\n" |
8250 | 240 |
"System information:\n" |
241 |
+ qt_version |
|
242 |
+ os_version |
|
243 |
+ total_ram |
|
244 |
+ screen_size |
|
245 |
+ number_of_screens |
|
8252 | 246 |
+ QString::fromStdString(processor_name + "\n") |
8250 | 247 |
+ number_of_cores |
8252 | 248 |
+ compiler_version |
249 |
+ compiler_bits |
|
250 |
+ kernel_line |
|
8250 | 251 |
); |
8268 | 252 |
} |
253 |
||
254 |
QNetworkAccessManager * PageFeedback::GetNetManager() |
|
255 |
{ |
|
256 |
if (netManager) return netManager; |
|
257 |
netManager = new QNetworkAccessManager(this); |
|
258 |
connect(netManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(NetReply(QNetworkReply*))); |
|
259 |
return netManager; |
|
260 |
} |
|
261 |
||
262 |
void PageFeedback::LoadCaptchaImage() |
|
263 |
{ |
|
264 |
QNetworkAccessManager *netManager = GetNetManager(); |
|
265 |
QUrl captchaURL("http://hedgewars.org/feedback/?gencaptcha"); |
|
266 |
QNetworkRequest req(captchaURL); |
|
267 |
genCaptchaRequest = netManager->get(req); |
|
268 |
} |
|
269 |
||
270 |
void PageFeedback::NetReply(QNetworkReply *reply) |
|
271 |
{ |
|
272 |
if (reply == genCaptchaRequest) |
|
273 |
{ |
|
274 |
if (reply->error() != QNetworkReply::NoError) |
|
275 |
{ |
|
276 |
qDebug() << "Error generating captcha image: " << reply->errorString(); |
|
277 |
ShowErrorMessage(QMessageBox::tr("Failed to generate captcha")); |
|
278 |
return; |
|
279 |
} |
|
6700 | 280 |
|
8268 | 281 |
bool okay; |
282 |
QByteArray body = reply->readAll(); |
|
283 |
captchaID = QString(body).toInt(&okay); |
|
284 |
||
285 |
if (!okay) |
|
286 |
{ |
|
287 |
qDebug() << "Failed to get captcha ID: " << body; |
|
288 |
ShowErrorMessage(QMessageBox::tr("Failed to generate captcha")); |
|
289 |
return; |
|
290 |
} |
|
291 |
||
292 |
QString url = "http://hedgewars.org/feedback/?captcha&id="; |
|
293 |
url += QString::number(captchaID); |
|
294 |
||
295 |
QNetworkAccessManager *netManager = GetNetManager(); |
|
296 |
QUrl captchaURL(url); |
|
297 |
QNetworkRequest req(captchaURL); |
|
298 |
captchaImageRequest = netManager->get(req); |
|
299 |
} |
|
300 |
else if (reply == captchaImageRequest) |
|
301 |
{ |
|
302 |
if (reply->error() != QNetworkReply::NoError) |
|
303 |
{ |
|
304 |
qDebug() << "Error loading captcha image: " << reply->errorString(); |
|
305 |
ShowErrorMessage(QMessageBox::tr("Failed to download captcha")); |
|
306 |
return; |
|
307 |
} |
|
308 |
||
309 |
QByteArray imageData = reply->readAll(); |
|
310 |
QPixmap pixmap; |
|
311 |
pixmap.loadFromData(imageData); |
|
312 |
label_captcha->setPixmap(pixmap); |
|
313 |
captcha_code->setText(""); |
|
314 |
} |
|
6700 | 315 |
} |
316 |
||
317 |
QLayout * PageFeedback::footerLayoutDefinition() |
|
318 |
{ |
|
319 |
QHBoxLayout * bottomLayout = new QHBoxLayout(); |
|
8268 | 320 |
QHBoxLayout * captchaLayout = new QHBoxLayout(); |
321 |
QVBoxLayout * captchaInputLayout = new QVBoxLayout(); |
|
6700 | 322 |
|
8268 | 323 |
label_captcha = new QLabel(); |
324 |
label_captcha->setStyleSheet("border: 3px solid #ffcc00; border-radius: 4px"); |
|
325 |
label_captcha->setText("<div style='width: 200px; height: 100px;'>loading<br>captcha</div>"); |
|
326 |
captchaLayout->addWidget(label_captcha); |
|
327 |
||
328 |
label_captcha_input = new QLabel(); |
|
329 |
label_captcha_input->setText(QLabel::tr("Type the security code:")); |
|
330 |
captchaInputLayout->addWidget(label_captcha_input); |
|
331 |
captchaInputLayout->setAlignment(label_captcha, Qt::AlignBottom); |
|
332 |
captcha_code = new QLineEdit(); |
|
333 |
captcha_code->setFixedSize(165, 30); |
|
334 |
captchaInputLayout->addWidget(captcha_code); |
|
335 |
captchaInputLayout->setAlignment(captcha_code, Qt::AlignTop); |
|
336 |
captchaLayout->addLayout(captchaInputLayout); |
|
337 |
captchaLayout->setAlignment(captchaInputLayout, Qt::AlignLeft); |
|
338 |
||
339 |
captchaLayout->insertSpacing(-1, 40); |
|
340 |
bottomLayout->addLayout(captchaLayout); |
|
341 |
||
6700 | 342 |
//TODO: create logo for send button |
8268 | 343 |
BtnSend = addButton("Send Feedback", bottomLayout, 0, false); |
344 |
BtnSend->setFixedSize(120, 40); |
|
345 |
||
346 |
bottomLayout->setStretchFactor(captchaLayout, 0); |
|
347 |
bottomLayout->setStretchFactor(BtnSend, 1); |
|
6700 | 348 |
|
349 |
return bottomLayout; |
|
350 |
} |
|
351 |
||
352 |
void PageFeedback::connectSignals() |
|
353 |
{ |
|
354 |
//TODO |
|
355 |
} |
|
356 |
||
8268 | 357 |
void PageFeedback::ShowErrorMessage(const QString & msg) |
358 |
{ |
|
359 |
QMessageBox msgMsg(this); |
|
360 |
msgMsg.setIcon(QMessageBox::Warning); |
|
361 |
msgMsg.setWindowTitle(QMessageBox::tr("Hedgewars - Error")); |
|
362 |
msgMsg.setText(msg); |
|
363 |
msgMsg.setWindowModality(Qt::WindowModal); |
|
364 |
msgMsg.exec(); |
|
365 |
} |
|
366 |
||
6700 | 367 |
PageFeedback::PageFeedback(QWidget* parent) : AbstractPage(parent) |
368 |
{ |
|
369 |
initPage(); |
|
8268 | 370 |
netManager = NULL; |
6700 | 371 |
} |