author | Drew Gottlieb |
Sat, 08 Dec 2012 15:06:30 +0100 | |
branch | flibqtfrontend |
changeset 8269 | c71721d371dc |
parent 8259 | 02e32be01232 |
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> |
|
8269 | 23 |
#include <QHttp> |
8253 | 24 |
#include <QSysInfo> |
8269 | 25 |
#include <QDebug> |
26 |
#include <QBuffer> |
|
8253 | 27 |
#include <QApplication> |
28 |
#include <QDesktopWidget> |
|
8269 | 29 |
#include <QNetworkReply> |
8255 | 30 |
#include <QProcess> |
8269 | 31 |
#include <QMessageBox> |
8253 | 32 |
|
8255 | 33 |
#include <string> |
8253 | 34 |
|
35 |
#ifdef Q_WS_WIN |
|
36 |
#define WINVER 0x0500 |
|
37 |
#include <windows.h> |
|
8255 | 38 |
#else |
39 |
#include <unistd.h> |
|
40 |
#include <sys/types.h> |
|
8253 | 41 |
#endif |
42 |
||
43 |
#ifdef Q_WS_MAC |
|
8255 | 44 |
#include <sys/sysctl.h> |
8253 | 45 |
#endif |
6700 | 46 |
|
8259
02e32be01232
fix build on linux for me ( the uint32_t releated breakage )
sheepluva
parents:
8255
diff
changeset
|
47 |
#include <stdint.h> |
02e32be01232
fix build on linux for me ( the uint32_t releated breakage )
sheepluva
parents:
8255
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(); |
|
8269 | 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>" |
|
8269 | 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(); |
|
8269 | 73 |
label_summary->setText(QLabel::tr("Summary")); |
6700 | 74 |
summaryLayout->addWidget(label_summary); |
75 |
summary = new QLineEdit(); |
|
76 |
summaryLayout->addWidget(summary); |
|
8269 | 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(); |
|
8255 | 98 |
|
8269 | 99 |
EmbedSystemInfo(); |
100 |
||
101 |
description->setReadOnly(false); |
|
102 |
pageLayout->addWidget(description); |
|
103 |
||
104 |
return pageLayout; |
|
105 |
} |
|
106 |
||
107 |
void PageFeedback::EmbedSystemInfo() |
|
108 |
{ |
|
8255 | 109 |
// Gather some information about the system and embed it into the report |
8253 | 110 |
QDesktopWidget* screen = QApplication::desktop(); |
111 |
QString os_version = "Operating system: "; |
|
112 |
QString qt_version = QString("Qt version: ") + QT_VERSION_STR + QString("\n"); |
|
8255 | 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: "; |
|
8253 | 119 |
QString screen_size = "Size of the screen(s): " + |
120 |
QString::number(screen->width()) + "x" + QString::number(screen->height()) + "\n"; |
|
8255 | 121 |
QString number_of_screens = "Number of screens: " + QString::number(screen->screenCount()) + "\n"; |
122 |
std::string processor_name = "Processor: "; |
|
123 |
||
124 |
// platform specific code |
|
8253 | 125 |
#ifdef Q_WS_MACX |
8255 | 126 |
number_of_cores += QString::number(sysconf(_SC_NPROCESSORS_ONLN)) + "\n"; |
8253 | 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) |
|
8255 | 133 |
total_ram += QString::number(memsize/1024/1024) + " MB\n"; |
8253 | 134 |
else |
8255 | 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"; |
|
8253 | 138 |
else |
8255 | 139 |
available_ram += "Error getting available RAM information\n"; |
140 |
||
8253 | 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); |
|
8255 | 166 |
number_of_cores += QString::number(sysinfo.dwNumberOfProcessors) + "\n"; |
8253 | 167 |
MEMORYSTATUSEX status; |
168 |
status.dwLength = sizeof(status); |
|
169 |
GlobalMemoryStatusEx(&status); |
|
170 |
total_ram = QString::number(status.ullTotalPhys); |
|
171 |
||
172 |
switch(QSysInfo::WinVersion()) |
|
173 |
{ |
|
8255 | 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; |
|
8253 | 179 |
} |
8255 | 180 |
kernel_line += "Windows kernel\n"; |
8253 | 181 |
#endif |
182 |
#ifdef Q_WS_X11 |
|
8255 | 183 |
number_of_cores += QString::number(sysconf(_SC_NPROCESSORS_ONLN)) + "\n"; |
8253 | 184 |
long pages = sysconf(_SC_PHYS_PAGES), |
185 |
available_pages = sysconf(_SC_AVPHYS_PAGES), |
|
186 |
page_size = sysconf(_SC_PAGE_SIZE); |
|
8255 | 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"; |
|
8253 | 190 |
#endif |
8255 | 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 |
|
8253 | 203 |
uint32_t registers[4]; |
8255 | 204 |
uint32_t i; |
8253 | 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); |
|
8255 | 230 |
|
231 |
// compiler |
|
232 |
#ifdef __GNUC__ |
|
233 |
compiler_version += "GCC " + QString(__VERSION__) + "\n"; |
|
234 |
#else |
|
235 |
compiler_version += "Unknown\n"; |
|
236 |
#endif |
|
237 |
||
8253 | 238 |
if(sizeof(void*) == 4) |
8255 | 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 |
|
8253 | 244 |
description->setText( |
8255 | 245 |
"\n\n\n\n\n" |
8253 | 246 |
"System information:\n" |
247 |
+ qt_version |
|
248 |
+ os_version |
|
249 |
+ total_ram |
|
250 |
+ available_ram |
|
251 |
+ screen_size |
|
252 |
+ number_of_screens |
|
8255 | 253 |
+ QString::fromStdString(processor_name + "\n") |
8253 | 254 |
+ number_of_cores |
8255 | 255 |
+ compiler_version |
256 |
+ compiler_bits |
|
257 |
+ kernel_line |
|
8253 | 258 |
); |
8269 | 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 |
|
8269 | 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(); |
|
8269 | 327 |
QHBoxLayout * captchaLayout = new QHBoxLayout(); |
328 |
QVBoxLayout * captchaInputLayout = new QVBoxLayout(); |
|
6700 | 329 |
|
8269 | 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 |
8269 | 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 |
||
8269 | 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(); |
|
8269 | 377 |
netManager = NULL; |
6700 | 378 |
} |