author | nemo |
Mon, 10 Dec 2012 10:32:51 -0500 | |
changeset 8289 | 302a2521fe7a |
parent 8277 | cd2bae15a9a3 |
child 8328 | 03684c667664 |
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\">" |
|
8277
cd2bae15a9a3
hides the 'email' prompt on the feedback page (as that doesn't work, so it's a misleading/useless feature), makes the "please add your email" text a little nicer and more noticeable, and makes the "feedback" and "downloadable content" buttons on the main menu a little bit larger, and more clickable.
Drew Gottlieb
parents:
8274
diff
changeset
|
62 |
"a { color: #fc0; }" |
cd2bae15a9a3
hides the 'email' prompt on the feedback page (as that doesn't work, so it's a misleading/useless feature), makes the "please add your email" text a little nicer and more noticeable, and makes the "feedback" and "downloadable content" buttons on the main menu a little bit larger, and more clickable.
Drew Gottlieb
parents:
8274
diff
changeset
|
63 |
"b { color: #0df; }" |
6700 | 64 |
"</style>" |
65 |
"<div align=\"center\"><h1>Please give us a feedback!</h1>" |
|
66 |
"<h3>We are always happy about suggestions, ideas or bug reports.<h3>" |
|
8277
cd2bae15a9a3
hides the 'email' prompt on the feedback page (as that doesn't work, so it's a misleading/useless feature), makes the "please add your email" text a little nicer and more noticeable, and makes the "feedback" and "downloadable content" buttons on the main menu a little bit larger, and more clickable.
Drew Gottlieb
parents:
8274
diff
changeset
|
67 |
"<h4>The feedback will be posted as a new issue on our Google Code page.<br />" |
cd2bae15a9a3
hides the 'email' prompt on the feedback page (as that doesn't work, so it's a misleading/useless feature), makes the "please add your email" text a little nicer and more noticeable, and makes the "feedback" and "downloadable content" buttons on the main menu a little bit larger, and more clickable.
Drew Gottlieb
parents:
8274
diff
changeset
|
68 |
"<b>Don't forget to mention your email or you won't be able to receive updates on this topic!</b><br /></h4>" |
8268 | 69 |
//"<h4>Your email is optional, but if given, you will be notified of responses.<h4>" |
6700 | 70 |
"</div>" |
71 |
); |
|
72 |
pageLayout->addWidget(info); |
|
73 |
||
74 |
label_summary = new QLabel(); |
|
8268 | 75 |
label_summary->setText(QLabel::tr("Summary")); |
6700 | 76 |
summaryLayout->addWidget(label_summary); |
77 |
summary = new QLineEdit(); |
|
78 |
summaryLayout->addWidget(summary); |
|
8268 | 79 |
combinedTopLayout->addLayout(summaryLayout); |
80 |
||
81 |
label_email = new QLabel(); |
|
82 |
label_email->setText(QLabel::tr("Your Email")); |
|
83 |
emailLayout->addWidget(label_email); |
|
84 |
email = new QLineEdit(); |
|
85 |
emailLayout->addWidget(email); |
|
86 |
||
87 |
// Email -- although implemented -- doesn't seem to work as intended. |
|
88 |
// It's sent in the XML as a <issues:cc> , the <entry>, but it doesn't seem |
|
89 |
// to actually do anything. If you figure out how to fix that, uncomment these lines |
|
90 |
// and the line above in the 'info' QLabel to re-enable this feature. |
|
8277
cd2bae15a9a3
hides the 'email' prompt on the feedback page (as that doesn't work, so it's a misleading/useless feature), makes the "please add your email" text a little nicer and more noticeable, and makes the "feedback" and "downloadable content" buttons on the main menu a little bit larger, and more clickable.
Drew Gottlieb
parents:
8274
diff
changeset
|
91 |
// UPDATE: I found out that CC only works if that email is a member of the |
cd2bae15a9a3
hides the 'email' prompt on the feedback page (as that doesn't work, so it's a misleading/useless feature), makes the "please add your email" text a little nicer and more noticeable, and makes the "feedback" and "downloadable content" buttons on the main menu a little bit larger, and more clickable.
Drew Gottlieb
parents:
8274
diff
changeset
|
92 |
// Google Code project. So this feature is pretty much useless atm. |
cd2bae15a9a3
hides the 'email' prompt on the feedback page (as that doesn't work, so it's a misleading/useless feature), makes the "please add your email" text a little nicer and more noticeable, and makes the "feedback" and "downloadable content" buttons on the main menu a little bit larger, and more clickable.
Drew Gottlieb
parents:
8274
diff
changeset
|
93 |
/* |
8270
16a52ad5a362
strip available ram entry, add notice for entering email
koda
parents:
8268
diff
changeset
|
94 |
combinedTopLayout->addLayout(emailLayout); |
16a52ad5a362
strip available ram entry, add notice for entering email
koda
parents:
8268
diff
changeset
|
95 |
combinedTopLayout->insertSpacing(1, 50); |
8277
cd2bae15a9a3
hides the 'email' prompt on the feedback page (as that doesn't work, so it's a misleading/useless feature), makes the "please add your email" text a little nicer and more noticeable, and makes the "feedback" and "downloadable content" buttons on the main menu a little bit larger, and more clickable.
Drew Gottlieb
parents:
8274
diff
changeset
|
96 |
*/ |
8268 | 97 |
|
98 |
pageLayout->addLayout(combinedTopLayout); |
|
6700 | 99 |
|
100 |
label_description = new QLabel(); |
|
101 |
label_description->setText(QLabel::tr("Description")); |
|
102 |
pageLayout->addWidget(label_description, 0, Qt::AlignHCenter); |
|
103 |
description = new QTextBrowser(); |
|
8252 | 104 |
|
8268 | 105 |
EmbedSystemInfo(); |
106 |
||
107 |
description->setReadOnly(false); |
|
108 |
pageLayout->addWidget(description); |
|
109 |
||
110 |
return pageLayout; |
|
111 |
} |
|
112 |
||
113 |
void PageFeedback::EmbedSystemInfo() |
|
114 |
{ |
|
8252 | 115 |
// Gather some information about the system and embed it into the report |
8250 | 116 |
QDesktopWidget* screen = QApplication::desktop(); |
117 |
QString os_version = "Operating system: "; |
|
118 |
QString qt_version = QString("Qt version: ") + QT_VERSION_STR + QString("\n"); |
|
8252 | 119 |
QString total_ram = "Total RAM: "; |
120 |
QString number_of_cores = "Number of cores: "; |
|
121 |
QString compiler_bits = "Compiler architecture: "; |
|
122 |
QString compiler_version = "Compiler version: "; |
|
123 |
QString kernel_line = "Kernel: "; |
|
8250 | 124 |
QString screen_size = "Size of the screen(s): " + |
125 |
QString::number(screen->width()) + "x" + QString::number(screen->height()) + "\n"; |
|
8252 | 126 |
QString number_of_screens = "Number of screens: " + QString::number(screen->screenCount()) + "\n"; |
127 |
std::string processor_name = "Processor: "; |
|
128 |
||
129 |
// platform specific code |
|
8250 | 130 |
#ifdef Q_WS_MACX |
8252 | 131 |
number_of_cores += QString::number(sysconf(_SC_NPROCESSORS_ONLN)) + "\n"; |
8250 | 132 |
|
8270
16a52ad5a362
strip available ram entry, add notice for entering email
koda
parents:
8268
diff
changeset
|
133 |
uint64_t memsize; |
8250 | 134 |
size_t len = sizeof(memsize); |
135 |
static int mib_s[2] = { CTL_HW, HW_MEMSIZE }; |
|
136 |
if (sysctl (mib_s, 2, &memsize, &len, NULL, 0) == 0) |
|
8252 | 137 |
total_ram += QString::number(memsize/1024/1024) + " MB\n"; |
8250 | 138 |
else |
8252 | 139 |
total_ram += "Error getting total RAM information\n"; |
140 |
||
8270
16a52ad5a362
strip available ram entry, add notice for entering email
koda
parents:
8268
diff
changeset
|
141 |
int mib[] = {CTL_KERN, KERN_OSRELEASE}; |
8250 | 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); |
|
8270
16a52ad5a362
strip available ram entry, add notice for entering email
koda
parents:
8268
diff
changeset
|
170 |
total_ram += QString::number(status.ullTotalPhys); |
8250 | 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), |
8274 | 185 |
#ifndef Q_OS_FREEBSD |
8250 | 186 |
available_pages = sysconf(_SC_AVPHYS_PAGES), |
8274 | 187 |
#else |
188 |
available_pages = 0, |
|
189 |
#endif |
|
8250 | 190 |
page_size = sysconf(_SC_PAGE_SIZE); |
8252 | 191 |
total_ram += QString::number(pages * page_size) + "\n"; |
192 |
os_version += "GNU/Linux or BSD\n"; |
|
8250 | 193 |
#endif |
8252 | 194 |
|
195 |
// uname -a |
|
196 |
#if defined(Q_WS_X11) || defined(Q_WS_MACX) |
|
197 |
QProcess *process = new QProcess(); |
|
198 |
QStringList arguments = QStringList("-a"); |
|
199 |
process->start("uname", arguments); |
|
200 |
if (process->waitForFinished()) |
|
201 |
kernel_line += QString(process->readAll()); |
|
202 |
delete process; |
|
203 |
#endif |
|
204 |
||
205 |
// cpu info |
|
8289 | 206 |
quint32 registers[4]; |
207 |
quint32 i; |
|
8250 | 208 |
|
209 |
i = 0x80000002; |
|
210 |
asm volatile |
|
211 |
("cpuid" : "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]) |
|
212 |
: "a" (i), "c" (0)); |
|
213 |
processor_name += std::string((const char *)®isters[0], 4); |
|
214 |
processor_name += std::string((const char *)®isters[1], 4); |
|
215 |
processor_name += std::string((const char *)®isters[2], 4); |
|
216 |
processor_name += std::string((const char *)®isters[3], 4); |
|
217 |
i = 0x80000003; |
|
218 |
asm volatile |
|
219 |
("cpuid" : "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]) |
|
220 |
: "a" (i), "c" (0)); |
|
221 |
processor_name += std::string((const char *)®isters[0], 4); |
|
222 |
processor_name += std::string((const char *)®isters[1], 4); |
|
223 |
processor_name += std::string((const char *)®isters[2], 4); |
|
224 |
processor_name += std::string((const char *)®isters[3], 4); |
|
225 |
i = 0x80000004; |
|
226 |
asm volatile |
|
227 |
("cpuid" : "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]) |
|
228 |
: "a" (i), "c" (0)); |
|
229 |
processor_name += std::string((const char *)®isters[0], 4); |
|
230 |
processor_name += std::string((const char *)®isters[1], 4); |
|
231 |
processor_name += std::string((const char *)®isters[2], 4); |
|
232 |
processor_name += std::string((const char *)®isters[3], 3); |
|
8252 | 233 |
|
234 |
// compiler |
|
235 |
#ifdef __GNUC__ |
|
236 |
compiler_version += "GCC " + QString(__VERSION__) + "\n"; |
|
237 |
#else |
|
238 |
compiler_version += "Unknown\n"; |
|
239 |
#endif |
|
240 |
||
8250 | 241 |
if(sizeof(void*) == 4) |
8252 | 242 |
compiler_bits += "i386\n"; |
243 |
else if(sizeof(void*) == 8) |
|
244 |
compiler_bits += "x86_64\n"; |
|
245 |
||
246 |
// add everything to the field of text |
|
8250 | 247 |
description->setText( |
8252 | 248 |
"\n\n\n\n\n" |
8250 | 249 |
"System information:\n" |
250 |
+ qt_version |
|
251 |
+ os_version |
|
252 |
+ total_ram |
|
253 |
+ screen_size |
|
254 |
+ number_of_screens |
|
8252 | 255 |
+ QString::fromStdString(processor_name + "\n") |
8250 | 256 |
+ number_of_cores |
8252 | 257 |
+ compiler_version |
258 |
+ compiler_bits |
|
259 |
+ kernel_line |
|
8250 | 260 |
); |
8268 | 261 |
} |
262 |
||
263 |
QNetworkAccessManager * PageFeedback::GetNetManager() |
|
264 |
{ |
|
265 |
if (netManager) return netManager; |
|
266 |
netManager = new QNetworkAccessManager(this); |
|
267 |
connect(netManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(NetReply(QNetworkReply*))); |
|
268 |
return netManager; |
|
269 |
} |
|
270 |
||
271 |
void PageFeedback::LoadCaptchaImage() |
|
272 |
{ |
|
273 |
QNetworkAccessManager *netManager = GetNetManager(); |
|
274 |
QUrl captchaURL("http://hedgewars.org/feedback/?gencaptcha"); |
|
275 |
QNetworkRequest req(captchaURL); |
|
276 |
genCaptchaRequest = netManager->get(req); |
|
277 |
} |
|
278 |
||
279 |
void PageFeedback::NetReply(QNetworkReply *reply) |
|
280 |
{ |
|
281 |
if (reply == genCaptchaRequest) |
|
282 |
{ |
|
283 |
if (reply->error() != QNetworkReply::NoError) |
|
284 |
{ |
|
285 |
qDebug() << "Error generating captcha image: " << reply->errorString(); |
|
286 |
ShowErrorMessage(QMessageBox::tr("Failed to generate captcha")); |
|
287 |
return; |
|
288 |
} |
|
6700 | 289 |
|
8268 | 290 |
bool okay; |
291 |
QByteArray body = reply->readAll(); |
|
292 |
captchaID = QString(body).toInt(&okay); |
|
293 |
||
294 |
if (!okay) |
|
295 |
{ |
|
296 |
qDebug() << "Failed to get captcha ID: " << body; |
|
297 |
ShowErrorMessage(QMessageBox::tr("Failed to generate captcha")); |
|
298 |
return; |
|
299 |
} |
|
300 |
||
301 |
QString url = "http://hedgewars.org/feedback/?captcha&id="; |
|
302 |
url += QString::number(captchaID); |
|
303 |
||
304 |
QNetworkAccessManager *netManager = GetNetManager(); |
|
305 |
QUrl captchaURL(url); |
|
306 |
QNetworkRequest req(captchaURL); |
|
307 |
captchaImageRequest = netManager->get(req); |
|
308 |
} |
|
309 |
else if (reply == captchaImageRequest) |
|
310 |
{ |
|
311 |
if (reply->error() != QNetworkReply::NoError) |
|
312 |
{ |
|
313 |
qDebug() << "Error loading captcha image: " << reply->errorString(); |
|
314 |
ShowErrorMessage(QMessageBox::tr("Failed to download captcha")); |
|
315 |
return; |
|
316 |
} |
|
317 |
||
318 |
QByteArray imageData = reply->readAll(); |
|
319 |
QPixmap pixmap; |
|
320 |
pixmap.loadFromData(imageData); |
|
321 |
label_captcha->setPixmap(pixmap); |
|
322 |
captcha_code->setText(""); |
|
323 |
} |
|
6700 | 324 |
} |
325 |
||
326 |
QLayout * PageFeedback::footerLayoutDefinition() |
|
327 |
{ |
|
328 |
QHBoxLayout * bottomLayout = new QHBoxLayout(); |
|
8268 | 329 |
QHBoxLayout * captchaLayout = new QHBoxLayout(); |
330 |
QVBoxLayout * captchaInputLayout = new QVBoxLayout(); |
|
6700 | 331 |
|
8268 | 332 |
label_captcha = new QLabel(); |
333 |
label_captcha->setStyleSheet("border: 3px solid #ffcc00; border-radius: 4px"); |
|
334 |
label_captcha->setText("<div style='width: 200px; height: 100px;'>loading<br>captcha</div>"); |
|
335 |
captchaLayout->addWidget(label_captcha); |
|
336 |
||
337 |
label_captcha_input = new QLabel(); |
|
338 |
label_captcha_input->setText(QLabel::tr("Type the security code:")); |
|
339 |
captchaInputLayout->addWidget(label_captcha_input); |
|
340 |
captchaInputLayout->setAlignment(label_captcha, Qt::AlignBottom); |
|
341 |
captcha_code = new QLineEdit(); |
|
342 |
captcha_code->setFixedSize(165, 30); |
|
343 |
captchaInputLayout->addWidget(captcha_code); |
|
344 |
captchaInputLayout->setAlignment(captcha_code, Qt::AlignTop); |
|
345 |
captchaLayout->addLayout(captchaInputLayout); |
|
346 |
captchaLayout->setAlignment(captchaInputLayout, Qt::AlignLeft); |
|
347 |
||
348 |
captchaLayout->insertSpacing(-1, 40); |
|
349 |
bottomLayout->addLayout(captchaLayout); |
|
350 |
||
6700 | 351 |
//TODO: create logo for send button |
8268 | 352 |
BtnSend = addButton("Send Feedback", bottomLayout, 0, false); |
353 |
BtnSend->setFixedSize(120, 40); |
|
354 |
||
355 |
bottomLayout->setStretchFactor(captchaLayout, 0); |
|
356 |
bottomLayout->setStretchFactor(BtnSend, 1); |
|
6700 | 357 |
|
358 |
return bottomLayout; |
|
359 |
} |
|
360 |
||
361 |
void PageFeedback::connectSignals() |
|
362 |
{ |
|
363 |
//TODO |
|
364 |
} |
|
365 |
||
8268 | 366 |
void PageFeedback::ShowErrorMessage(const QString & msg) |
367 |
{ |
|
368 |
QMessageBox msgMsg(this); |
|
369 |
msgMsg.setIcon(QMessageBox::Warning); |
|
370 |
msgMsg.setWindowTitle(QMessageBox::tr("Hedgewars - Error")); |
|
371 |
msgMsg.setText(msg); |
|
372 |
msgMsg.setWindowModality(Qt::WindowModal); |
|
373 |
msgMsg.exec(); |
|
374 |
} |
|
375 |
||
6700 | 376 |
PageFeedback::PageFeedback(QWidget* parent) : AbstractPage(parent) |
377 |
{ |
|
378 |
initPage(); |
|
8268 | 379 |
netManager = NULL; |
6700 | 380 |
} |