author | unc0rr |
Sat, 08 Dec 2012 20:23:13 +0400 | |
changeset 8274 | 7324298dbcc1 |
parent 8270 | 16a52ad5a362 |
child 8277 | cd2bae15a9a3 |
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), |
8274 | 179 |
#ifndef Q_OS_FREEBSD |
8250 | 180 |
available_pages = sysconf(_SC_AVPHYS_PAGES), |
8274 | 181 |
#else |
182 |
available_pages = 0, |
|
183 |
#endif |
|
8250 | 184 |
page_size = sysconf(_SC_PAGE_SIZE); |
8252 | 185 |
total_ram += QString::number(pages * page_size) + "\n"; |
186 |
os_version += "GNU/Linux or BSD\n"; |
|
8250 | 187 |
#endif |
8252 | 188 |
|
189 |
// uname -a |
|
190 |
#if defined(Q_WS_X11) || defined(Q_WS_MACX) |
|
191 |
QProcess *process = new QProcess(); |
|
192 |
QStringList arguments = QStringList("-a"); |
|
193 |
process->start("uname", arguments); |
|
194 |
if (process->waitForFinished()) |
|
195 |
kernel_line += QString(process->readAll()); |
|
196 |
delete process; |
|
197 |
#endif |
|
198 |
||
199 |
// cpu info |
|
8250 | 200 |
uint32_t registers[4]; |
8252 | 201 |
uint32_t i; |
8250 | 202 |
|
203 |
i = 0x80000002; |
|
204 |
asm volatile |
|
205 |
("cpuid" : "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]) |
|
206 |
: "a" (i), "c" (0)); |
|
207 |
processor_name += std::string((const char *)®isters[0], 4); |
|
208 |
processor_name += std::string((const char *)®isters[1], 4); |
|
209 |
processor_name += std::string((const char *)®isters[2], 4); |
|
210 |
processor_name += std::string((const char *)®isters[3], 4); |
|
211 |
i = 0x80000003; |
|
212 |
asm volatile |
|
213 |
("cpuid" : "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]) |
|
214 |
: "a" (i), "c" (0)); |
|
215 |
processor_name += std::string((const char *)®isters[0], 4); |
|
216 |
processor_name += std::string((const char *)®isters[1], 4); |
|
217 |
processor_name += std::string((const char *)®isters[2], 4); |
|
218 |
processor_name += std::string((const char *)®isters[3], 4); |
|
219 |
i = 0x80000004; |
|
220 |
asm volatile |
|
221 |
("cpuid" : "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]) |
|
222 |
: "a" (i), "c" (0)); |
|
223 |
processor_name += std::string((const char *)®isters[0], 4); |
|
224 |
processor_name += std::string((const char *)®isters[1], 4); |
|
225 |
processor_name += std::string((const char *)®isters[2], 4); |
|
226 |
processor_name += std::string((const char *)®isters[3], 3); |
|
8252 | 227 |
|
228 |
// compiler |
|
229 |
#ifdef __GNUC__ |
|
230 |
compiler_version += "GCC " + QString(__VERSION__) + "\n"; |
|
231 |
#else |
|
232 |
compiler_version += "Unknown\n"; |
|
233 |
#endif |
|
234 |
||
8250 | 235 |
if(sizeof(void*) == 4) |
8252 | 236 |
compiler_bits += "i386\n"; |
237 |
else if(sizeof(void*) == 8) |
|
238 |
compiler_bits += "x86_64\n"; |
|
239 |
||
240 |
// add everything to the field of text |
|
8250 | 241 |
description->setText( |
8270
16a52ad5a362
strip available ram entry, add notice for entering email
koda
parents:
8268
diff
changeset
|
242 |
"Don't forget to mention your email or you won't be able to receive updates on this topic!" |
8252 | 243 |
"\n\n\n\n\n" |
8250 | 244 |
"System information:\n" |
245 |
+ qt_version |
|
246 |
+ os_version |
|
247 |
+ total_ram |
|
248 |
+ screen_size |
|
249 |
+ number_of_screens |
|
8252 | 250 |
+ QString::fromStdString(processor_name + "\n") |
8250 | 251 |
+ number_of_cores |
8252 | 252 |
+ compiler_version |
253 |
+ compiler_bits |
|
254 |
+ kernel_line |
|
8250 | 255 |
); |
8268 | 256 |
} |
257 |
||
258 |
QNetworkAccessManager * PageFeedback::GetNetManager() |
|
259 |
{ |
|
260 |
if (netManager) return netManager; |
|
261 |
netManager = new QNetworkAccessManager(this); |
|
262 |
connect(netManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(NetReply(QNetworkReply*))); |
|
263 |
return netManager; |
|
264 |
} |
|
265 |
||
266 |
void PageFeedback::LoadCaptchaImage() |
|
267 |
{ |
|
268 |
QNetworkAccessManager *netManager = GetNetManager(); |
|
269 |
QUrl captchaURL("http://hedgewars.org/feedback/?gencaptcha"); |
|
270 |
QNetworkRequest req(captchaURL); |
|
271 |
genCaptchaRequest = netManager->get(req); |
|
272 |
} |
|
273 |
||
274 |
void PageFeedback::NetReply(QNetworkReply *reply) |
|
275 |
{ |
|
276 |
if (reply == genCaptchaRequest) |
|
277 |
{ |
|
278 |
if (reply->error() != QNetworkReply::NoError) |
|
279 |
{ |
|
280 |
qDebug() << "Error generating captcha image: " << reply->errorString(); |
|
281 |
ShowErrorMessage(QMessageBox::tr("Failed to generate captcha")); |
|
282 |
return; |
|
283 |
} |
|
6700 | 284 |
|
8268 | 285 |
bool okay; |
286 |
QByteArray body = reply->readAll(); |
|
287 |
captchaID = QString(body).toInt(&okay); |
|
288 |
||
289 |
if (!okay) |
|
290 |
{ |
|
291 |
qDebug() << "Failed to get captcha ID: " << body; |
|
292 |
ShowErrorMessage(QMessageBox::tr("Failed to generate captcha")); |
|
293 |
return; |
|
294 |
} |
|
295 |
||
296 |
QString url = "http://hedgewars.org/feedback/?captcha&id="; |
|
297 |
url += QString::number(captchaID); |
|
298 |
||
299 |
QNetworkAccessManager *netManager = GetNetManager(); |
|
300 |
QUrl captchaURL(url); |
|
301 |
QNetworkRequest req(captchaURL); |
|
302 |
captchaImageRequest = netManager->get(req); |
|
303 |
} |
|
304 |
else if (reply == captchaImageRequest) |
|
305 |
{ |
|
306 |
if (reply->error() != QNetworkReply::NoError) |
|
307 |
{ |
|
308 |
qDebug() << "Error loading captcha image: " << reply->errorString(); |
|
309 |
ShowErrorMessage(QMessageBox::tr("Failed to download captcha")); |
|
310 |
return; |
|
311 |
} |
|
312 |
||
313 |
QByteArray imageData = reply->readAll(); |
|
314 |
QPixmap pixmap; |
|
315 |
pixmap.loadFromData(imageData); |
|
316 |
label_captcha->setPixmap(pixmap); |
|
317 |
captcha_code->setText(""); |
|
318 |
} |
|
6700 | 319 |
} |
320 |
||
321 |
QLayout * PageFeedback::footerLayoutDefinition() |
|
322 |
{ |
|
323 |
QHBoxLayout * bottomLayout = new QHBoxLayout(); |
|
8268 | 324 |
QHBoxLayout * captchaLayout = new QHBoxLayout(); |
325 |
QVBoxLayout * captchaInputLayout = new QVBoxLayout(); |
|
6700 | 326 |
|
8268 | 327 |
label_captcha = new QLabel(); |
328 |
label_captcha->setStyleSheet("border: 3px solid #ffcc00; border-radius: 4px"); |
|
329 |
label_captcha->setText("<div style='width: 200px; height: 100px;'>loading<br>captcha</div>"); |
|
330 |
captchaLayout->addWidget(label_captcha); |
|
331 |
||
332 |
label_captcha_input = new QLabel(); |
|
333 |
label_captcha_input->setText(QLabel::tr("Type the security code:")); |
|
334 |
captchaInputLayout->addWidget(label_captcha_input); |
|
335 |
captchaInputLayout->setAlignment(label_captcha, Qt::AlignBottom); |
|
336 |
captcha_code = new QLineEdit(); |
|
337 |
captcha_code->setFixedSize(165, 30); |
|
338 |
captchaInputLayout->addWidget(captcha_code); |
|
339 |
captchaInputLayout->setAlignment(captcha_code, Qt::AlignTop); |
|
340 |
captchaLayout->addLayout(captchaInputLayout); |
|
341 |
captchaLayout->setAlignment(captchaInputLayout, Qt::AlignLeft); |
|
342 |
||
343 |
captchaLayout->insertSpacing(-1, 40); |
|
344 |
bottomLayout->addLayout(captchaLayout); |
|
345 |
||
6700 | 346 |
//TODO: create logo for send button |
8268 | 347 |
BtnSend = addButton("Send Feedback", bottomLayout, 0, false); |
348 |
BtnSend->setFixedSize(120, 40); |
|
349 |
||
350 |
bottomLayout->setStretchFactor(captchaLayout, 0); |
|
351 |
bottomLayout->setStretchFactor(BtnSend, 1); |
|
6700 | 352 |
|
353 |
return bottomLayout; |
|
354 |
} |
|
355 |
||
356 |
void PageFeedback::connectSignals() |
|
357 |
{ |
|
358 |
//TODO |
|
359 |
} |
|
360 |
||
8268 | 361 |
void PageFeedback::ShowErrorMessage(const QString & msg) |
362 |
{ |
|
363 |
QMessageBox msgMsg(this); |
|
364 |
msgMsg.setIcon(QMessageBox::Warning); |
|
365 |
msgMsg.setWindowTitle(QMessageBox::tr("Hedgewars - Error")); |
|
366 |
msgMsg.setText(msg); |
|
367 |
msgMsg.setWindowModality(Qt::WindowModal); |
|
368 |
msgMsg.exec(); |
|
369 |
} |
|
370 |
||
6700 | 371 |
PageFeedback::PageFeedback(QWidget* parent) : AbstractPage(parent) |
372 |
{ |
|
373 |
initPage(); |
|
8268 | 374 |
netManager = NULL; |
6700 | 375 |
} |