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>
|
8250
|
23 |
#include <QSysInfo>
|
|
24 |
#include <QApplication>
|
|
25 |
#include <QDesktopWidget>
|
8252
|
26 |
#include <QProcess>
|
8250
|
27 |
|
8252
|
28 |
#include <string>
|
8250
|
29 |
|
|
30 |
#ifdef Q_WS_WIN
|
|
31 |
#define WINVER 0x0500
|
|
32 |
#include <windows.h>
|
8252
|
33 |
#else
|
|
34 |
#include <unistd.h>
|
|
35 |
#include <sys/types.h>
|
8250
|
36 |
#endif
|
|
37 |
|
|
38 |
#ifdef Q_WS_MAC
|
8252
|
39 |
#include <sys/sysctl.h>
|
8250
|
40 |
#endif
|
6700
|
41 |
|
|
42 |
#include "pagefeedback.h"
|
|
43 |
#include "hwconsts.h"
|
|
44 |
|
|
45 |
QLayout * PageFeedback::bodyLayoutDefinition()
|
|
46 |
{
|
|
47 |
QVBoxLayout * pageLayout = new QVBoxLayout();
|
|
48 |
QHBoxLayout * summaryLayout = new QHBoxLayout();
|
|
49 |
|
|
50 |
info = new QLabel();
|
|
51 |
info->setText(
|
|
52 |
"<style type=\"text/css\">"
|
|
53 |
"a { color: #ffcc00; }"
|
|
54 |
"</style>"
|
|
55 |
"<div align=\"center\"><h1>Please give us a feedback!</h1>"
|
|
56 |
"<h3>We are always happy about suggestions, ideas or bug reports.<h3>"
|
|
57 |
"<h4>The feedback will be posted as a new issue on our Google Code page.<h4>"
|
|
58 |
"</div>"
|
|
59 |
);
|
|
60 |
pageLayout->addWidget(info);
|
|
61 |
|
|
62 |
label_summary = new QLabel();
|
|
63 |
label_summary->setText(QLabel::tr("Summary "));
|
|
64 |
summaryLayout->addWidget(label_summary);
|
|
65 |
summary = new QLineEdit();
|
|
66 |
summaryLayout->addWidget(summary);
|
|
67 |
pageLayout->addLayout(summaryLayout);
|
|
68 |
|
|
69 |
label_description = new QLabel();
|
|
70 |
label_description->setText(QLabel::tr("Description"));
|
|
71 |
pageLayout->addWidget(label_description, 0, Qt::AlignHCenter);
|
|
72 |
description = new QTextBrowser();
|
8252
|
73 |
|
|
74 |
// Gather some information about the system and embed it into the report
|
8250
|
75 |
QDesktopWidget* screen = QApplication::desktop();
|
|
76 |
QString os_version = "Operating system: ";
|
|
77 |
QString qt_version = QString("Qt version: ") + QT_VERSION_STR + QString("\n");
|
8252
|
78 |
QString total_ram = "Total RAM: ";
|
|
79 |
QString available_ram = "Available RAM: ";
|
|
80 |
QString number_of_cores = "Number of cores: ";
|
|
81 |
QString compiler_bits = "Compiler architecture: ";
|
|
82 |
QString compiler_version = "Compiler version: ";
|
|
83 |
QString kernel_line = "Kernel: ";
|
8250
|
84 |
QString screen_size = "Size of the screen(s): " +
|
|
85 |
QString::number(screen->width()) + "x" + QString::number(screen->height()) + "\n";
|
8252
|
86 |
QString number_of_screens = "Number of screens: " + QString::number(screen->screenCount()) + "\n";
|
|
87 |
std::string processor_name = "Processor: ";
|
|
88 |
|
|
89 |
// platform specific code
|
8250
|
90 |
#ifdef Q_WS_MACX
|
8252
|
91 |
number_of_cores += QString::number(sysconf(_SC_NPROCESSORS_ONLN)) + "\n";
|
8250
|
92 |
|
|
93 |
uint64_t memsize, memavail;
|
|
94 |
size_t len = sizeof(memsize);
|
|
95 |
static int mib_s[2] = { CTL_HW, HW_MEMSIZE };
|
|
96 |
static int mib_a[2] = { CTL_HW, HW_USERMEM };
|
|
97 |
if (sysctl (mib_s, 2, &memsize, &len, NULL, 0) == 0)
|
8252
|
98 |
total_ram += QString::number(memsize/1024/1024) + " MB\n";
|
8250
|
99 |
else
|
8252
|
100 |
total_ram += "Error getting total RAM information\n";
|
|
101 |
if (sysctl (mib_a, 2, &memavail, &len, NULL, 0) == 0)
|
|
102 |
available_ram += QString::number(memavail/1024/1024) + " MB\n";
|
8250
|
103 |
else
|
8252
|
104 |
available_ram += "Error getting available RAM information\n";
|
|
105 |
|
8250
|
106 |
int mib[] = {CTL_KERN, KERN_OSRELEASE};
|
|
107 |
sysctl(mib, sizeof mib / sizeof(int), NULL, &len, NULL, 0);
|
|
108 |
|
|
109 |
char *kernelVersion = (char *)malloc(sizeof(char)*len);
|
|
110 |
sysctl(mib, sizeof mib / sizeof(int), kernelVersion, &len, NULL, 0);
|
|
111 |
|
|
112 |
QString kernelVersionStr = QString(kernelVersion);
|
|
113 |
free(kernelVersion);
|
|
114 |
int major_version = kernelVersionStr.split(".").first().toUInt() - 4;
|
|
115 |
int minor_version = kernelVersionStr.split(".").at(1).toUInt();
|
|
116 |
os_version += QString("Mac OS X 10.%1.%2").arg(major_version).arg(minor_version) + " ";
|
|
117 |
|
|
118 |
switch(major_version)
|
|
119 |
{
|
|
120 |
case 4: os_version += "\"Tiger\"\n"; break;
|
|
121 |
case 5: os_version += "\"Leopard\"\n"; break;
|
|
122 |
case 6: os_version += "\"Snow Leopard\"\n"; break;
|
|
123 |
case 7: os_version += "\"Lion\"\n"; break;
|
|
124 |
case 8: os_version += "\"Mountain Lion\"\n"; break;
|
|
125 |
default: os_version += "\"Unknown version\"\n"; break;
|
|
126 |
}
|
|
127 |
#endif
|
|
128 |
#ifdef Q_WS_WIN
|
|
129 |
SYSTEM_INFO sysinfo;
|
|
130 |
GetSystemInfo(&sysinfo);
|
8252
|
131 |
number_of_cores += QString::number(sysinfo.dwNumberOfProcessors) + "\n";
|
8250
|
132 |
MEMORYSTATUSEX status;
|
|
133 |
status.dwLength = sizeof(status);
|
|
134 |
GlobalMemoryStatusEx(&status);
|
|
135 |
total_ram = QString::number(status.ullTotalPhys);
|
|
136 |
|
|
137 |
switch(QSysInfo::WinVersion())
|
|
138 |
{
|
8252
|
139 |
case QSysInfo::WV_2000: os_version += "Windows 2000\n"; break;
|
|
140 |
case QSysInfo::WV_XP: os_version += "Windows XP\n"; break;
|
|
141 |
case QSysInfo::WV_VISTA: os_version += "Windows Vista\n"; break;
|
|
142 |
case QSysInfo::WV_WINDOWS7: os_version += "Windows 7\n"; break;
|
|
143 |
default: os_version += "Windows (Unknown version)\n"; break;
|
8250
|
144 |
}
|
8252
|
145 |
kernel_line += "Windows kernel\n";
|
8250
|
146 |
#endif
|
|
147 |
#ifdef Q_WS_X11
|
8252
|
148 |
number_of_cores += QString::number(sysconf(_SC_NPROCESSORS_ONLN)) + "\n";
|
8250
|
149 |
long pages = sysconf(_SC_PHYS_PAGES),
|
|
150 |
available_pages = sysconf(_SC_AVPHYS_PAGES),
|
|
151 |
page_size = sysconf(_SC_PAGE_SIZE);
|
8252
|
152 |
total_ram += QString::number(pages * page_size) + "\n";
|
|
153 |
available_ram += QString::number(available_pages * page_size) + "\n";
|
|
154 |
os_version += "GNU/Linux or BSD\n";
|
8250
|
155 |
#endif
|
8252
|
156 |
|
|
157 |
// uname -a
|
|
158 |
#if defined(Q_WS_X11) || defined(Q_WS_MACX)
|
|
159 |
QProcess *process = new QProcess();
|
|
160 |
QStringList arguments = QStringList("-a");
|
|
161 |
process->start("uname", arguments);
|
|
162 |
if (process->waitForFinished())
|
|
163 |
kernel_line += QString(process->readAll());
|
|
164 |
delete process;
|
|
165 |
#endif
|
|
166 |
|
|
167 |
// cpu info
|
8250
|
168 |
uint32_t registers[4];
|
8252
|
169 |
uint32_t i;
|
8250
|
170 |
|
|
171 |
i = 0x80000002;
|
|
172 |
asm volatile
|
|
173 |
("cpuid" : "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3])
|
|
174 |
: "a" (i), "c" (0));
|
|
175 |
processor_name += std::string((const char *)®isters[0], 4);
|
|
176 |
processor_name += std::string((const char *)®isters[1], 4);
|
|
177 |
processor_name += std::string((const char *)®isters[2], 4);
|
|
178 |
processor_name += std::string((const char *)®isters[3], 4);
|
|
179 |
i = 0x80000003;
|
|
180 |
asm volatile
|
|
181 |
("cpuid" : "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3])
|
|
182 |
: "a" (i), "c" (0));
|
|
183 |
processor_name += std::string((const char *)®isters[0], 4);
|
|
184 |
processor_name += std::string((const char *)®isters[1], 4);
|
|
185 |
processor_name += std::string((const char *)®isters[2], 4);
|
|
186 |
processor_name += std::string((const char *)®isters[3], 4);
|
|
187 |
i = 0x80000004;
|
|
188 |
asm volatile
|
|
189 |
("cpuid" : "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3])
|
|
190 |
: "a" (i), "c" (0));
|
|
191 |
processor_name += std::string((const char *)®isters[0], 4);
|
|
192 |
processor_name += std::string((const char *)®isters[1], 4);
|
|
193 |
processor_name += std::string((const char *)®isters[2], 4);
|
|
194 |
processor_name += std::string((const char *)®isters[3], 3);
|
8252
|
195 |
|
|
196 |
// compiler
|
|
197 |
#ifdef __GNUC__
|
|
198 |
compiler_version += "GCC " + QString(__VERSION__) + "\n";
|
|
199 |
#else
|
|
200 |
compiler_version += "Unknown\n";
|
|
201 |
#endif
|
|
202 |
|
8250
|
203 |
if(sizeof(void*) == 4)
|
8252
|
204 |
compiler_bits += "i386\n";
|
|
205 |
else if(sizeof(void*) == 8)
|
|
206 |
compiler_bits += "x86_64\n";
|
|
207 |
|
|
208 |
// add everything to the field of text
|
8250
|
209 |
description->setText(
|
8252
|
210 |
"\n\n\n\n\n"
|
8250
|
211 |
"System information:\n"
|
|
212 |
+ qt_version
|
|
213 |
+ os_version
|
|
214 |
+ total_ram
|
|
215 |
+ available_ram
|
|
216 |
+ screen_size
|
|
217 |
+ number_of_screens
|
8252
|
218 |
+ QString::fromStdString(processor_name + "\n")
|
8250
|
219 |
+ number_of_cores
|
8252
|
220 |
+ compiler_version
|
|
221 |
+ compiler_bits
|
|
222 |
+ kernel_line
|
8250
|
223 |
);
|
6700
|
224 |
description->setReadOnly(false);
|
|
225 |
pageLayout->addWidget(description);
|
|
226 |
|
|
227 |
return pageLayout;
|
|
228 |
}
|
|
229 |
|
|
230 |
QLayout * PageFeedback::footerLayoutDefinition()
|
|
231 |
{
|
|
232 |
QHBoxLayout * bottomLayout = new QHBoxLayout();
|
|
233 |
|
|
234 |
bottomLayout->setStretch(0,1);
|
|
235 |
//TODO: create logo for send button
|
|
236 |
BtnSend = addButton("Send", bottomLayout, 0, false);
|
|
237 |
bottomLayout->insertStretch(0);
|
|
238 |
|
|
239 |
return bottomLayout;
|
|
240 |
}
|
|
241 |
|
|
242 |
void PageFeedback::connectSignals()
|
|
243 |
{
|
|
244 |
//TODO
|
|
245 |
}
|
|
246 |
|
|
247 |
PageFeedback::PageFeedback(QWidget* parent) : AbstractPage(parent)
|
|
248 |
{
|
|
249 |
initPage();
|
|
250 |
|
|
251 |
}
|