author | dag10 |
Mon, 14 Jan 2013 13:28:03 +0100 | |
changeset 8384 | a6e7a95f3b2e |
parent 8383 | b557c73a7593 |
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> |
8328 | 32 |
#include <QCheckBox> |
8250 | 33 |
|
8252 | 34 |
#include <string> |
8250 | 35 |
|
36 |
#ifdef Q_WS_WIN |
|
37 |
#define WINVER 0x0500 |
|
38 |
#include <windows.h> |
|
8252 | 39 |
#else |
40 |
#include <unistd.h> |
|
41 |
#include <sys/types.h> |
|
8250 | 42 |
#endif |
43 |
||
44 |
#ifdef Q_WS_MAC |
|
8252 | 45 |
#include <sys/sysctl.h> |
8250 | 46 |
#endif |
6700 | 47 |
|
8258
c14b27abe452
fix build on linux for me ( the uint32_t releated breakage )
sheepluva
parents:
8252
diff
changeset
|
48 |
#include <stdint.h> |
c14b27abe452
fix build on linux for me ( the uint32_t releated breakage )
sheepluva
parents:
8252
diff
changeset
|
49 |
|
6700 | 50 |
#include "pagefeedback.h" |
8383 | 51 |
#include "MessageDialog.h" |
6700 | 52 |
#include "hwconsts.h" |
53 |
||
54 |
QLayout * PageFeedback::bodyLayoutDefinition() |
|
55 |
{ |
|
56 |
QVBoxLayout * pageLayout = new QVBoxLayout(); |
|
57 |
QHBoxLayout * summaryLayout = new QHBoxLayout(); |
|
8268 | 58 |
QHBoxLayout * emailLayout = new QHBoxLayout(); |
8328 | 59 |
QHBoxLayout * descriptionLayout = new QHBoxLayout(); |
8268 | 60 |
QHBoxLayout * combinedTopLayout = new QHBoxLayout(); |
8328 | 61 |
QHBoxLayout * systemLayout = new QHBoxLayout(); |
6700 | 62 |
|
63 |
info = new QLabel(); |
|
64 |
info->setText( |
|
65 |
"<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
|
66 |
"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
|
67 |
"b { color: #0df; }" |
6700 | 68 |
"</style>" |
8328 | 69 |
"<div align=\"center\"><h1>Please give us feedback!</h1>" |
70 |
"<h3>We are always happy about suggestions, ideas, or bug reports.<h3>" |
|
71 |
"<h4>Your email address is optional, but we may want to contact you.<h4>" |
|
6700 | 72 |
"</div>" |
73 |
); |
|
74 |
pageLayout->addWidget(info); |
|
75 |
||
8328 | 76 |
QVBoxLayout * summaryEmailLayout = new QVBoxLayout(); |
77 |
||
78 |
const int labelWidth = 90; |
|
8268 | 79 |
|
80 |
label_email = new QLabel(); |
|
81 |
label_email->setText(QLabel::tr("Your Email")); |
|
8328 | 82 |
label_email->setFixedWidth(labelWidth); |
8268 | 83 |
emailLayout->addWidget(label_email); |
84 |
email = new QLineEdit(); |
|
85 |
emailLayout->addWidget(email); |
|
8328 | 86 |
summaryEmailLayout->addLayout(emailLayout); |
8268 | 87 |
|
8328 | 88 |
label_summary = new QLabel(); |
89 |
label_summary->setText(QLabel::tr("Summary")); |
|
90 |
label_summary->setFixedWidth(labelWidth); |
|
91 |
summaryLayout->addWidget(label_summary); |
|
92 |
summary = new QLineEdit(); |
|
93 |
summaryLayout->addWidget(summary); |
|
94 |
summaryEmailLayout->addLayout(summaryLayout); |
|
95 |
||
96 |
combinedTopLayout->addLayout(summaryEmailLayout); |
|
97 |
||
98 |
||
99 |
CheckSendSpecs = new QCheckBox(); |
|
100 |
CheckSendSpecs->setText(QLabel::tr("Send system information")); |
|
101 |
CheckSendSpecs->setChecked(true); |
|
102 |
systemLayout->addWidget(CheckSendSpecs); |
|
103 |
BtnViewInfo = addButton("View", systemLayout, 1, false); |
|
104 |
BtnViewInfo->setFixedSize(60, 30); |
|
105 |
connect(BtnViewInfo, SIGNAL(clicked()), this, SLOT(ShowSpecs())); |
|
106 |
combinedTopLayout->addLayout(systemLayout); |
|
107 |
||
108 |
combinedTopLayout->setStretch(0, 1); |
|
109 |
combinedTopLayout->insertSpacing(1, 20); |
|
8268 | 110 |
|
111 |
pageLayout->addLayout(combinedTopLayout); |
|
6700 | 112 |
|
113 |
label_description = new QLabel(); |
|
114 |
label_description->setText(QLabel::tr("Description")); |
|
8328 | 115 |
label_description->setFixedWidth(labelWidth); |
116 |
descriptionLayout->addWidget(label_description, 0, Qt::AlignTop); |
|
6700 | 117 |
description = new QTextBrowser(); |
8268 | 118 |
description->setReadOnly(false); |
8328 | 119 |
descriptionLayout->addWidget(description); |
120 |
pageLayout->addLayout(descriptionLayout); |
|
8268 | 121 |
|
122 |
return pageLayout; |
|
123 |
} |
|
124 |
||
8328 | 125 |
QNetworkAccessManager * PageFeedback::GetNetManager() |
126 |
{ |
|
127 |
if (netManager) return netManager; |
|
128 |
netManager = new QNetworkAccessManager(this); |
|
129 |
connect(netManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(NetReply(QNetworkReply*))); |
|
130 |
return netManager; |
|
131 |
} |
|
132 |
||
133 |
void PageFeedback::LoadCaptchaImage() |
|
134 |
{ |
|
135 |
QNetworkAccessManager *netManager = GetNetManager(); |
|
136 |
QUrl captchaURL("http://hedgewars.org/feedback/?gencaptcha"); |
|
137 |
QNetworkRequest req(captchaURL); |
|
138 |
genCaptchaRequest = netManager->get(req); |
|
139 |
} |
|
140 |
||
141 |
void PageFeedback::NetReply(QNetworkReply *reply) |
|
142 |
{ |
|
143 |
if (reply == genCaptchaRequest) |
|
144 |
{ |
|
145 |
if (reply->error() != QNetworkReply::NoError) |
|
146 |
{ |
|
147 |
qDebug() << "Error generating captcha image: " << reply->errorString(); |
|
8383 | 148 |
MessageDialog::ShowErrorMessage(QMessageBox::tr("Failed to generate captcha"), this); |
8328 | 149 |
return; |
150 |
} |
|
151 |
||
152 |
bool okay; |
|
153 |
QByteArray body = reply->readAll(); |
|
154 |
captchaID = QString(body).toInt(&okay); |
|
155 |
||
156 |
if (!okay) |
|
157 |
{ |
|
158 |
qDebug() << "Failed to get captcha ID: " << body; |
|
8383 | 159 |
MessageDialog::ShowErrorMessage(QMessageBox::tr("Failed to generate captcha"), this); |
8328 | 160 |
return; |
161 |
} |
|
162 |
||
163 |
QString url = "http://hedgewars.org/feedback/?captcha&id="; |
|
164 |
url += QString::number(captchaID); |
|
165 |
||
166 |
QNetworkAccessManager *netManager = GetNetManager(); |
|
167 |
QUrl captchaURL(url); |
|
168 |
QNetworkRequest req(captchaURL); |
|
169 |
captchaImageRequest = netManager->get(req); |
|
170 |
} |
|
171 |
else if (reply == captchaImageRequest) |
|
172 |
{ |
|
173 |
if (reply->error() != QNetworkReply::NoError) |
|
174 |
{ |
|
175 |
qDebug() << "Error loading captcha image: " << reply->errorString(); |
|
8383 | 176 |
MessageDialog::ShowErrorMessage(QMessageBox::tr("Failed to download captcha"), this); |
8328 | 177 |
return; |
178 |
} |
|
179 |
||
180 |
QByteArray imageData = reply->readAll(); |
|
181 |
QPixmap pixmap; |
|
182 |
pixmap.loadFromData(imageData); |
|
183 |
label_captcha->setPixmap(pixmap); |
|
184 |
captcha_code->setText(""); |
|
185 |
} |
|
186 |
} |
|
187 |
||
188 |
QLayout * PageFeedback::footerLayoutDefinition() |
|
189 |
{ |
|
190 |
QHBoxLayout * bottomLayout = new QHBoxLayout(); |
|
191 |
QHBoxLayout * captchaLayout = new QHBoxLayout(); |
|
192 |
QVBoxLayout * captchaInputLayout = new QVBoxLayout(); |
|
193 |
||
194 |
label_captcha = new QLabel(); |
|
195 |
label_captcha->setStyleSheet("border: 3px solid #ffcc00; border-radius: 4px"); |
|
196 |
label_captcha->setText("<div style='width: 200px; height: 100px;'>loading<br>captcha</div>"); |
|
197 |
captchaLayout->addWidget(label_captcha); |
|
198 |
||
199 |
label_captcha_input = new QLabel(); |
|
200 |
label_captcha_input->setText(QLabel::tr("Type the security code:")); |
|
201 |
captchaInputLayout->addWidget(label_captcha_input); |
|
202 |
captchaInputLayout->setAlignment(label_captcha, Qt::AlignBottom); |
|
203 |
captcha_code = new QLineEdit(); |
|
204 |
captcha_code->setFixedSize(165, 30); |
|
205 |
captchaInputLayout->addWidget(captcha_code); |
|
206 |
captchaInputLayout->setAlignment(captcha_code, Qt::AlignTop); |
|
207 |
captchaLayout->addLayout(captchaInputLayout); |
|
208 |
captchaLayout->setAlignment(captchaInputLayout, Qt::AlignLeft); |
|
209 |
||
210 |
captchaLayout->insertSpacing(-1, 40); |
|
211 |
bottomLayout->addLayout(captchaLayout); |
|
212 |
||
213 |
//TODO: create logo for send button |
|
214 |
BtnSend = addButton("Send Feedback", bottomLayout, 0, false); |
|
215 |
BtnSend->setFixedSize(120, 40); |
|
216 |
||
217 |
bottomLayout->setStretchFactor(captchaLayout, 0); |
|
218 |
bottomLayout->setStretchFactor(BtnSend, 1); |
|
219 |
||
220 |
return bottomLayout; |
|
221 |
} |
|
222 |
||
223 |
void PageFeedback::GenerateSpecs() |
|
8268 | 224 |
{ |
8252 | 225 |
// Gather some information about the system and embed it into the report |
8250 | 226 |
QDesktopWidget* screen = QApplication::desktop(); |
227 |
QString os_version = "Operating system: "; |
|
228 |
QString qt_version = QString("Qt version: ") + QT_VERSION_STR + QString("\n"); |
|
8252 | 229 |
QString total_ram = "Total RAM: "; |
230 |
QString number_of_cores = "Number of cores: "; |
|
231 |
QString compiler_bits = "Compiler architecture: "; |
|
232 |
QString compiler_version = "Compiler version: "; |
|
233 |
QString kernel_line = "Kernel: "; |
|
8250 | 234 |
QString screen_size = "Size of the screen(s): " + |
235 |
QString::number(screen->width()) + "x" + QString::number(screen->height()) + "\n"; |
|
8252 | 236 |
QString number_of_screens = "Number of screens: " + QString::number(screen->screenCount()) + "\n"; |
237 |
std::string processor_name = "Processor: "; |
|
238 |
||
239 |
// platform specific code |
|
8250 | 240 |
#ifdef Q_WS_MACX |
8252 | 241 |
number_of_cores += QString::number(sysconf(_SC_NPROCESSORS_ONLN)) + "\n"; |
8250 | 242 |
|
8270
16a52ad5a362
strip available ram entry, add notice for entering email
koda
parents:
8268
diff
changeset
|
243 |
uint64_t memsize; |
8250 | 244 |
size_t len = sizeof(memsize); |
245 |
static int mib_s[2] = { CTL_HW, HW_MEMSIZE }; |
|
246 |
if (sysctl (mib_s, 2, &memsize, &len, NULL, 0) == 0) |
|
8252 | 247 |
total_ram += QString::number(memsize/1024/1024) + " MB\n"; |
8250 | 248 |
else |
8252 | 249 |
total_ram += "Error getting total RAM information\n"; |
250 |
||
8270
16a52ad5a362
strip available ram entry, add notice for entering email
koda
parents:
8268
diff
changeset
|
251 |
int mib[] = {CTL_KERN, KERN_OSRELEASE}; |
8250 | 252 |
sysctl(mib, sizeof mib / sizeof(int), NULL, &len, NULL, 0); |
253 |
||
254 |
char *kernelVersion = (char *)malloc(sizeof(char)*len); |
|
255 |
sysctl(mib, sizeof mib / sizeof(int), kernelVersion, &len, NULL, 0); |
|
256 |
||
257 |
QString kernelVersionStr = QString(kernelVersion); |
|
258 |
free(kernelVersion); |
|
259 |
int major_version = kernelVersionStr.split(".").first().toUInt() - 4; |
|
260 |
int minor_version = kernelVersionStr.split(".").at(1).toUInt(); |
|
261 |
os_version += QString("Mac OS X 10.%1.%2").arg(major_version).arg(minor_version) + " "; |
|
262 |
||
263 |
switch(major_version) |
|
264 |
{ |
|
265 |
case 4: os_version += "\"Tiger\"\n"; break; |
|
266 |
case 5: os_version += "\"Leopard\"\n"; break; |
|
267 |
case 6: os_version += "\"Snow Leopard\"\n"; break; |
|
268 |
case 7: os_version += "\"Lion\"\n"; break; |
|
269 |
case 8: os_version += "\"Mountain Lion\"\n"; break; |
|
270 |
default: os_version += "\"Unknown version\"\n"; break; |
|
271 |
} |
|
272 |
#endif |
|
273 |
#ifdef Q_WS_WIN |
|
274 |
SYSTEM_INFO sysinfo; |
|
275 |
GetSystemInfo(&sysinfo); |
|
8252 | 276 |
number_of_cores += QString::number(sysinfo.dwNumberOfProcessors) + "\n"; |
8250 | 277 |
MEMORYSTATUSEX status; |
278 |
status.dwLength = sizeof(status); |
|
279 |
GlobalMemoryStatusEx(&status); |
|
8270
16a52ad5a362
strip available ram entry, add notice for entering email
koda
parents:
8268
diff
changeset
|
280 |
total_ram += QString::number(status.ullTotalPhys); |
8250 | 281 |
|
282 |
switch(QSysInfo::WinVersion()) |
|
283 |
{ |
|
8252 | 284 |
case QSysInfo::WV_2000: os_version += "Windows 2000\n"; break; |
285 |
case QSysInfo::WV_XP: os_version += "Windows XP\n"; break; |
|
286 |
case QSysInfo::WV_VISTA: os_version += "Windows Vista\n"; break; |
|
287 |
case QSysInfo::WV_WINDOWS7: os_version += "Windows 7\n"; break; |
|
288 |
default: os_version += "Windows (Unknown version)\n"; break; |
|
8250 | 289 |
} |
8252 | 290 |
kernel_line += "Windows kernel\n"; |
8250 | 291 |
#endif |
292 |
#ifdef Q_WS_X11 |
|
8252 | 293 |
number_of_cores += QString::number(sysconf(_SC_NPROCESSORS_ONLN)) + "\n"; |
8250 | 294 |
long pages = sysconf(_SC_PHYS_PAGES), |
8274 | 295 |
#ifndef Q_OS_FREEBSD |
8250 | 296 |
available_pages = sysconf(_SC_AVPHYS_PAGES), |
8274 | 297 |
#else |
298 |
available_pages = 0, |
|
299 |
#endif |
|
8250 | 300 |
page_size = sysconf(_SC_PAGE_SIZE); |
8252 | 301 |
total_ram += QString::number(pages * page_size) + "\n"; |
302 |
os_version += "GNU/Linux or BSD\n"; |
|
8250 | 303 |
#endif |
8252 | 304 |
|
305 |
// uname -a |
|
306 |
#if defined(Q_WS_X11) || defined(Q_WS_MACX) |
|
307 |
QProcess *process = new QProcess(); |
|
308 |
QStringList arguments = QStringList("-a"); |
|
309 |
process->start("uname", arguments); |
|
310 |
if (process->waitForFinished()) |
|
311 |
kernel_line += QString(process->readAll()); |
|
312 |
delete process; |
|
313 |
#endif |
|
314 |
||
315 |
// cpu info |
|
8289 | 316 |
quint32 registers[4]; |
317 |
quint32 i; |
|
8250 | 318 |
|
319 |
i = 0x80000002; |
|
320 |
asm volatile |
|
321 |
("cpuid" : "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]) |
|
322 |
: "a" (i), "c" (0)); |
|
323 |
processor_name += std::string((const char *)®isters[0], 4); |
|
324 |
processor_name += std::string((const char *)®isters[1], 4); |
|
325 |
processor_name += std::string((const char *)®isters[2], 4); |
|
326 |
processor_name += std::string((const char *)®isters[3], 4); |
|
327 |
i = 0x80000003; |
|
328 |
asm volatile |
|
329 |
("cpuid" : "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]) |
|
330 |
: "a" (i), "c" (0)); |
|
331 |
processor_name += std::string((const char *)®isters[0], 4); |
|
332 |
processor_name += std::string((const char *)®isters[1], 4); |
|
333 |
processor_name += std::string((const char *)®isters[2], 4); |
|
334 |
processor_name += std::string((const char *)®isters[3], 4); |
|
335 |
i = 0x80000004; |
|
336 |
asm volatile |
|
337 |
("cpuid" : "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]) |
|
338 |
: "a" (i), "c" (0)); |
|
339 |
processor_name += std::string((const char *)®isters[0], 4); |
|
340 |
processor_name += std::string((const char *)®isters[1], 4); |
|
341 |
processor_name += std::string((const char *)®isters[2], 4); |
|
342 |
processor_name += std::string((const char *)®isters[3], 3); |
|
8252 | 343 |
|
344 |
// compiler |
|
345 |
#ifdef __GNUC__ |
|
346 |
compiler_version += "GCC " + QString(__VERSION__) + "\n"; |
|
347 |
#else |
|
348 |
compiler_version += "Unknown\n"; |
|
349 |
#endif |
|
350 |
||
8250 | 351 |
if(sizeof(void*) == 4) |
8252 | 352 |
compiler_bits += "i386\n"; |
353 |
else if(sizeof(void*) == 8) |
|
354 |
compiler_bits += "x86_64\n"; |
|
355 |
||
8328 | 356 |
// concat system info |
357 |
specs = qt_version |
|
8250 | 358 |
+ os_version |
359 |
+ total_ram |
|
360 |
+ screen_size |
|
361 |
+ number_of_screens |
|
8252 | 362 |
+ QString::fromStdString(processor_name + "\n") |
8250 | 363 |
+ number_of_cores |
8252 | 364 |
+ compiler_version |
365 |
+ compiler_bits |
|
8328 | 366 |
+ kernel_line; |
6700 | 367 |
} |
368 |
||
369 |
void PageFeedback::connectSignals() |
|
370 |
{ |
|
371 |
//TODO |
|
372 |
} |
|
373 |
||
8328 | 374 |
void PageFeedback::ShowSpecs() |
375 |
{ |
|
376 |
QMessageBox msgMsg(this); |
|
377 |
msgMsg.setIcon(QMessageBox::Information); |
|
378 |
msgMsg.setWindowTitle(QMessageBox::tr("System Information Preview")); |
|
379 |
msgMsg.setText(specs); |
|
380 |
msgMsg.setTextFormat(Qt::PlainText); |
|
381 |
msgMsg.setWindowModality(Qt::WindowModal); |
|
382 |
msgMsg.setStyleSheet("background: #0A0533;"); |
|
383 |
msgMsg.exec(); |
|
384 |
} |
|
385 |
||
6700 | 386 |
PageFeedback::PageFeedback(QWidget* parent) : AbstractPage(parent) |
387 |
{ |
|
388 |
initPage(); |
|
8268 | 389 |
netManager = NULL; |
8328 | 390 |
GenerateSpecs(); |
6700 | 391 |
} |