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