author | Drew Gottlieb |
Sat, 08 Dec 2012 15:06:30 +0100 | |
changeset 8268 | fe4e94311585 |
parent 8258 | c14b27abe452 |
child 8270 | 16a52ad5a362 |
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. |
|
89 |
//combinedTopLayout->addLayout(emailLayout); |
|
90 |
//combinedTopLayout->insertSpacing(1, 50); |
|
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 available_ram = "Available RAM: "; |
|
115 |
QString number_of_cores = "Number of cores: "; |
|
116 |
QString compiler_bits = "Compiler architecture: "; |
|
117 |
QString compiler_version = "Compiler version: "; |
|
118 |
QString kernel_line = "Kernel: "; |
|
8250 | 119 |
QString screen_size = "Size of the screen(s): " + |
120 |
QString::number(screen->width()) + "x" + QString::number(screen->height()) + "\n"; |
|
8252 | 121 |
QString number_of_screens = "Number of screens: " + QString::number(screen->screenCount()) + "\n"; |
122 |
std::string processor_name = "Processor: "; |
|
123 |
||
124 |
// platform specific code |
|
8250 | 125 |
#ifdef Q_WS_MACX |
8252 | 126 |
number_of_cores += QString::number(sysconf(_SC_NPROCESSORS_ONLN)) + "\n"; |
8250 | 127 |
|
128 |
uint64_t memsize, memavail; |
|
129 |
size_t len = sizeof(memsize); |
|
130 |
static int mib_s[2] = { CTL_HW, HW_MEMSIZE }; |
|
131 |
static int mib_a[2] = { CTL_HW, HW_USERMEM }; |
|
132 |
if (sysctl (mib_s, 2, &memsize, &len, NULL, 0) == 0) |
|
8252 | 133 |
total_ram += QString::number(memsize/1024/1024) + " MB\n"; |
8250 | 134 |
else |
8252 | 135 |
total_ram += "Error getting total RAM information\n"; |
136 |
if (sysctl (mib_a, 2, &memavail, &len, NULL, 0) == 0) |
|
137 |
available_ram += QString::number(memavail/1024/1024) + " MB\n"; |
|
8250 | 138 |
else |
8252 | 139 |
available_ram += "Error getting available RAM information\n"; |
140 |
||
8250 | 141 |
int mib[] = {CTL_KERN, KERN_OSRELEASE}; |
142 |
sysctl(mib, sizeof mib / sizeof(int), NULL, &len, NULL, 0); |
|
143 |
||
144 |
char *kernelVersion = (char *)malloc(sizeof(char)*len); |
|
145 |
sysctl(mib, sizeof mib / sizeof(int), kernelVersion, &len, NULL, 0); |
|
146 |
||
147 |
QString kernelVersionStr = QString(kernelVersion); |
|
148 |
free(kernelVersion); |
|
149 |
int major_version = kernelVersionStr.split(".").first().toUInt() - 4; |
|
150 |
int minor_version = kernelVersionStr.split(".").at(1).toUInt(); |
|
151 |
os_version += QString("Mac OS X 10.%1.%2").arg(major_version).arg(minor_version) + " "; |
|
152 |
||
153 |
switch(major_version) |
|
154 |
{ |
|
155 |
case 4: os_version += "\"Tiger\"\n"; break; |
|
156 |
case 5: os_version += "\"Leopard\"\n"; break; |
|
157 |
case 6: os_version += "\"Snow Leopard\"\n"; break; |
|
158 |
case 7: os_version += "\"Lion\"\n"; break; |
|
159 |
case 8: os_version += "\"Mountain Lion\"\n"; break; |
|
160 |
default: os_version += "\"Unknown version\"\n"; break; |
|
161 |
} |
|
162 |
#endif |
|
163 |
#ifdef Q_WS_WIN |
|
164 |
SYSTEM_INFO sysinfo; |
|
165 |
GetSystemInfo(&sysinfo); |
|
8252 | 166 |
number_of_cores += QString::number(sysinfo.dwNumberOfProcessors) + "\n"; |
8250 | 167 |
MEMORYSTATUSEX status; |
168 |
status.dwLength = sizeof(status); |
|
169 |
GlobalMemoryStatusEx(&status); |
|
170 |
total_ram = QString::number(status.ullTotalPhys); |
|
171 |
||
172 |
switch(QSysInfo::WinVersion()) |
|
173 |
{ |
|
8252 | 174 |
case QSysInfo::WV_2000: os_version += "Windows 2000\n"; break; |
175 |
case QSysInfo::WV_XP: os_version += "Windows XP\n"; break; |
|
176 |
case QSysInfo::WV_VISTA: os_version += "Windows Vista\n"; break; |
|
177 |
case QSysInfo::WV_WINDOWS7: os_version += "Windows 7\n"; break; |
|
178 |
default: os_version += "Windows (Unknown version)\n"; break; |
|
8250 | 179 |
} |
8252 | 180 |
kernel_line += "Windows kernel\n"; |
8250 | 181 |
#endif |
182 |
#ifdef Q_WS_X11 |
|
8252 | 183 |
number_of_cores += QString::number(sysconf(_SC_NPROCESSORS_ONLN)) + "\n"; |
8250 | 184 |
long pages = sysconf(_SC_PHYS_PAGES), |
185 |
available_pages = sysconf(_SC_AVPHYS_PAGES), |
|
186 |
page_size = sysconf(_SC_PAGE_SIZE); |
|
8252 | 187 |
total_ram += QString::number(pages * page_size) + "\n"; |
188 |
available_ram += QString::number(available_pages * page_size) + "\n"; |
|
189 |
os_version += "GNU/Linux or BSD\n"; |
|
8250 | 190 |
#endif |
8252 | 191 |
|
192 |
// uname -a |
|
193 |
#if defined(Q_WS_X11) || defined(Q_WS_MACX) |
|
194 |
QProcess *process = new QProcess(); |
|
195 |
QStringList arguments = QStringList("-a"); |
|
196 |
process->start("uname", arguments); |
|
197 |
if (process->waitForFinished()) |
|
198 |
kernel_line += QString(process->readAll()); |
|
199 |
delete process; |
|
200 |
#endif |
|
201 |
||
202 |
// cpu info |
|
8250 | 203 |
uint32_t registers[4]; |
8252 | 204 |
uint32_t i; |
8250 | 205 |
|
206 |
i = 0x80000002; |
|
207 |
asm volatile |
|
208 |
("cpuid" : "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]) |
|
209 |
: "a" (i), "c" (0)); |
|
210 |
processor_name += std::string((const char *)®isters[0], 4); |
|
211 |
processor_name += std::string((const char *)®isters[1], 4); |
|
212 |
processor_name += std::string((const char *)®isters[2], 4); |
|
213 |
processor_name += std::string((const char *)®isters[3], 4); |
|
214 |
i = 0x80000003; |
|
215 |
asm volatile |
|
216 |
("cpuid" : "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]) |
|
217 |
: "a" (i), "c" (0)); |
|
218 |
processor_name += std::string((const char *)®isters[0], 4); |
|
219 |
processor_name += std::string((const char *)®isters[1], 4); |
|
220 |
processor_name += std::string((const char *)®isters[2], 4); |
|
221 |
processor_name += std::string((const char *)®isters[3], 4); |
|
222 |
i = 0x80000004; |
|
223 |
asm volatile |
|
224 |
("cpuid" : "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]) |
|
225 |
: "a" (i), "c" (0)); |
|
226 |
processor_name += std::string((const char *)®isters[0], 4); |
|
227 |
processor_name += std::string((const char *)®isters[1], 4); |
|
228 |
processor_name += std::string((const char *)®isters[2], 4); |
|
229 |
processor_name += std::string((const char *)®isters[3], 3); |
|
8252 | 230 |
|
231 |
// compiler |
|
232 |
#ifdef __GNUC__ |
|
233 |
compiler_version += "GCC " + QString(__VERSION__) + "\n"; |
|
234 |
#else |
|
235 |
compiler_version += "Unknown\n"; |
|
236 |
#endif |
|
237 |
||
8250 | 238 |
if(sizeof(void*) == 4) |
8252 | 239 |
compiler_bits += "i386\n"; |
240 |
else if(sizeof(void*) == 8) |
|
241 |
compiler_bits += "x86_64\n"; |
|
242 |
||
243 |
// add everything to the field of text |
|
8250 | 244 |
description->setText( |
8252 | 245 |
"\n\n\n\n\n" |
8250 | 246 |
"System information:\n" |
247 |
+ qt_version |
|
248 |
+ os_version |
|
249 |
+ total_ram |
|
250 |
+ available_ram |
|
251 |
+ screen_size |
|
252 |
+ number_of_screens |
|
8252 | 253 |
+ QString::fromStdString(processor_name + "\n") |
8250 | 254 |
+ number_of_cores |
8252 | 255 |
+ compiler_version |
256 |
+ compiler_bits |
|
257 |
+ kernel_line |
|
8250 | 258 |
); |
8268 | 259 |
} |
260 |
||
261 |
QNetworkAccessManager * PageFeedback::GetNetManager() |
|
262 |
{ |
|
263 |
if (netManager) return netManager; |
|
264 |
netManager = new QNetworkAccessManager(this); |
|
265 |
connect(netManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(NetReply(QNetworkReply*))); |
|
266 |
return netManager; |
|
267 |
} |
|
268 |
||
269 |
void PageFeedback::LoadCaptchaImage() |
|
270 |
{ |
|
271 |
QNetworkAccessManager *netManager = GetNetManager(); |
|
272 |
QUrl captchaURL("http://hedgewars.org/feedback/?gencaptcha"); |
|
273 |
QNetworkRequest req(captchaURL); |
|
274 |
genCaptchaRequest = netManager->get(req); |
|
275 |
} |
|
276 |
||
277 |
void PageFeedback::NetReply(QNetworkReply *reply) |
|
278 |
{ |
|
279 |
if (reply == genCaptchaRequest) |
|
280 |
{ |
|
281 |
if (reply->error() != QNetworkReply::NoError) |
|
282 |
{ |
|
283 |
qDebug() << "Error generating captcha image: " << reply->errorString(); |
|
284 |
ShowErrorMessage(QMessageBox::tr("Failed to generate captcha")); |
|
285 |
return; |
|
286 |
} |
|
6700 | 287 |
|
8268 | 288 |
bool okay; |
289 |
QByteArray body = reply->readAll(); |
|
290 |
captchaID = QString(body).toInt(&okay); |
|
291 |
||
292 |
if (!okay) |
|
293 |
{ |
|
294 |
qDebug() << "Failed to get captcha ID: " << body; |
|
295 |
ShowErrorMessage(QMessageBox::tr("Failed to generate captcha")); |
|
296 |
return; |
|
297 |
} |
|
298 |
||
299 |
QString url = "http://hedgewars.org/feedback/?captcha&id="; |
|
300 |
url += QString::number(captchaID); |
|
301 |
||
302 |
QNetworkAccessManager *netManager = GetNetManager(); |
|
303 |
QUrl captchaURL(url); |
|
304 |
QNetworkRequest req(captchaURL); |
|
305 |
captchaImageRequest = netManager->get(req); |
|
306 |
} |
|
307 |
else if (reply == captchaImageRequest) |
|
308 |
{ |
|
309 |
if (reply->error() != QNetworkReply::NoError) |
|
310 |
{ |
|
311 |
qDebug() << "Error loading captcha image: " << reply->errorString(); |
|
312 |
ShowErrorMessage(QMessageBox::tr("Failed to download captcha")); |
|
313 |
return; |
|
314 |
} |
|
315 |
||
316 |
QByteArray imageData = reply->readAll(); |
|
317 |
QPixmap pixmap; |
|
318 |
pixmap.loadFromData(imageData); |
|
319 |
label_captcha->setPixmap(pixmap); |
|
320 |
captcha_code->setText(""); |
|
321 |
} |
|
6700 | 322 |
} |
323 |
||
324 |
QLayout * PageFeedback::footerLayoutDefinition() |
|
325 |
{ |
|
326 |
QHBoxLayout * bottomLayout = new QHBoxLayout(); |
|
8268 | 327 |
QHBoxLayout * captchaLayout = new QHBoxLayout(); |
328 |
QVBoxLayout * captchaInputLayout = new QVBoxLayout(); |
|
6700 | 329 |
|
8268 | 330 |
label_captcha = new QLabel(); |
331 |
label_captcha->setStyleSheet("border: 3px solid #ffcc00; border-radius: 4px"); |
|
332 |
label_captcha->setText("<div style='width: 200px; height: 100px;'>loading<br>captcha</div>"); |
|
333 |
captchaLayout->addWidget(label_captcha); |
|
334 |
||
335 |
label_captcha_input = new QLabel(); |
|
336 |
label_captcha_input->setText(QLabel::tr("Type the security code:")); |
|
337 |
captchaInputLayout->addWidget(label_captcha_input); |
|
338 |
captchaInputLayout->setAlignment(label_captcha, Qt::AlignBottom); |
|
339 |
captcha_code = new QLineEdit(); |
|
340 |
captcha_code->setFixedSize(165, 30); |
|
341 |
captchaInputLayout->addWidget(captcha_code); |
|
342 |
captchaInputLayout->setAlignment(captcha_code, Qt::AlignTop); |
|
343 |
captchaLayout->addLayout(captchaInputLayout); |
|
344 |
captchaLayout->setAlignment(captchaInputLayout, Qt::AlignLeft); |
|
345 |
||
346 |
captchaLayout->insertSpacing(-1, 40); |
|
347 |
bottomLayout->addLayout(captchaLayout); |
|
348 |
||
6700 | 349 |
//TODO: create logo for send button |
8268 | 350 |
BtnSend = addButton("Send Feedback", bottomLayout, 0, false); |
351 |
BtnSend->setFixedSize(120, 40); |
|
352 |
||
353 |
bottomLayout->setStretchFactor(captchaLayout, 0); |
|
354 |
bottomLayout->setStretchFactor(BtnSend, 1); |
|
6700 | 355 |
|
356 |
return bottomLayout; |
|
357 |
} |
|
358 |
||
359 |
void PageFeedback::connectSignals() |
|
360 |
{ |
|
361 |
//TODO |
|
362 |
} |
|
363 |
||
8268 | 364 |
void PageFeedback::ShowErrorMessage(const QString & msg) |
365 |
{ |
|
366 |
QMessageBox msgMsg(this); |
|
367 |
msgMsg.setIcon(QMessageBox::Warning); |
|
368 |
msgMsg.setWindowTitle(QMessageBox::tr("Hedgewars - Error")); |
|
369 |
msgMsg.setText(msg); |
|
370 |
msgMsg.setWindowModality(Qt::WindowModal); |
|
371 |
msgMsg.exec(); |
|
372 |
} |
|
373 |
||
6700 | 374 |
PageFeedback::PageFeedback(QWidget* parent) : AbstractPage(parent) |
375 |
{ |
|
376 |
initPage(); |
|
8268 | 377 |
netManager = NULL; |
6700 | 378 |
} |