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>
|
|
26 |
#include <string>
|
|
27 |
|
|
28 |
#ifndef Q_WS_WIN
|
|
29 |
#include <unistd.h>
|
|
30 |
#endif
|
|
31 |
|
|
32 |
#ifdef Q_WS_WIN
|
|
33 |
#define WINVER 0x0500
|
|
34 |
#include <windows.h>
|
|
35 |
#endif
|
|
36 |
|
|
37 |
#ifdef Q_WS_MAC
|
|
38 |
#include <sys/types.h>
|
|
39 |
#include <sys/sysctl.h>
|
|
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();
|
8250
|
73 |
QDesktopWidget* screen = QApplication::desktop();
|
|
74 |
QString os_version = "Operating system: ";
|
|
75 |
QString qt_version = QString("Qt version: ") + QT_VERSION_STR + QString("\n");
|
|
76 |
QString total_ram = "Total RAM: unknown\n";
|
|
77 |
QString available_ram = "Available RAM: unknown\n";
|
|
78 |
QString number_of_cores = "Number of cores: unknown";
|
|
79 |
QString screen_size = "Size of the screen(s): " +
|
|
80 |
QString::number(screen->width()) + "x" + QString::number(screen->height()) + "\n";
|
|
81 |
QString number_of_screens = "Number of screens: " +
|
|
82 |
QString::number(screen->screenCount()) + "\n";
|
|
83 |
#ifdef Q_WS_MACX
|
|
84 |
number_of_cores = "Number of cores: " +
|
|
85 |
QString::number(sysconf(_SC_NPROCESSORS_ONLN));
|
|
86 |
|
|
87 |
uint64_t memsize, memavail;
|
|
88 |
size_t len = sizeof(memsize);
|
|
89 |
static int mib_s[2] = { CTL_HW, HW_MEMSIZE };
|
|
90 |
static int mib_a[2] = { CTL_HW, HW_USERMEM };
|
|
91 |
if (sysctl (mib_s, 2, &memsize, &len, NULL, 0) == 0)
|
|
92 |
total_ram = "Total RAM: " + QString::number(memsize/1024/1024) + " MB\n";
|
|
93 |
else
|
|
94 |
total_ram = "Error getting total RAM information\n";
|
|
95 |
if (sysctl (mib_a, 2, &memavail, &len, NULL, 0) == 0)
|
|
96 |
available_ram = "Available RAM: " + QString::number(memavail/1024/1024) + " MB\n";
|
|
97 |
else
|
|
98 |
available_ram = "Error getting available RAM information\n";
|
|
99 |
|
|
100 |
int mib[] = {CTL_KERN, KERN_OSRELEASE};
|
|
101 |
sysctl(mib, sizeof mib / sizeof(int), NULL, &len, NULL, 0);
|
|
102 |
|
|
103 |
char *kernelVersion = (char *)malloc(sizeof(char)*len);
|
|
104 |
sysctl(mib, sizeof mib / sizeof(int), kernelVersion, &len, NULL, 0);
|
|
105 |
|
|
106 |
QString kernelVersionStr = QString(kernelVersion);
|
|
107 |
free(kernelVersion);
|
|
108 |
int major_version = kernelVersionStr.split(".").first().toUInt() - 4;
|
|
109 |
int minor_version = kernelVersionStr.split(".").at(1).toUInt();
|
|
110 |
os_version += QString("Mac OS X 10.%1.%2").arg(major_version).arg(minor_version) + " ";
|
|
111 |
|
|
112 |
switch(major_version)
|
|
113 |
{
|
|
114 |
case 4: os_version += "\"Tiger\"\n"; break;
|
|
115 |
case 5: os_version += "\"Leopard\"\n"; break;
|
|
116 |
case 6: os_version += "\"Snow Leopard\"\n"; break;
|
|
117 |
case 7: os_version += "\"Lion\"\n"; break;
|
|
118 |
case 8: os_version += "\"Mountain Lion\"\n"; break;
|
|
119 |
default: os_version += "\"Unknown version\"\n"; break;
|
|
120 |
}
|
|
121 |
#endif
|
|
122 |
#ifdef Q_WS_WIN
|
|
123 |
SYSTEM_INFO sysinfo;
|
|
124 |
GetSystemInfo(&sysinfo);
|
|
125 |
number_of_cores = "Number of cores: " + QString::number(sysinfo.dwNumberOfProcessors) + "\n";
|
|
126 |
MEMORYSTATUSEX status;
|
|
127 |
status.dwLength = sizeof(status);
|
|
128 |
GlobalMemoryStatusEx(&status);
|
|
129 |
total_ram = QString::number(status.ullTotalPhys);
|
|
130 |
|
|
131 |
switch(QSysInfo::WinVersion())
|
|
132 |
{
|
|
133 |
case QSysInfo::WV_2000:
|
|
134 |
os_version += "Windows 2000\n";
|
|
135 |
break;
|
|
136 |
case QSysInfo::WV_XP:
|
|
137 |
os_version += "Windows XP\n";
|
|
138 |
break;
|
|
139 |
case QSysInfo::WV_VISTA:
|
|
140 |
os_version += "Windows Vista\n";
|
|
141 |
break;
|
|
142 |
case QSysInfo::WV_WINDOWS7:
|
|
143 |
os_version += "Windows 7\n";
|
|
144 |
break;
|
|
145 |
default:
|
|
146 |
os_version += "Windows\n";
|
|
147 |
}
|
|
148 |
#endif
|
|
149 |
#ifdef Q_WS_X11
|
|
150 |
number_of_cores = "Number of cores: " + QString::number(sysconf(_SC_NPROCESSORS_ONLN)) + "\n";
|
|
151 |
long pages = sysconf(_SC_PHYS_PAGES),
|
|
152 |
available_pages = sysconf(_SC_AVPHYS_PAGES),
|
|
153 |
page_size = sysconf(_SC_PAGE_SIZE);
|
|
154 |
total_ram = "Total RAM: " + QString::number(pages * page_size) + "\n";
|
|
155 |
available_ram = "Available RAM: " + QString::number(available_pages * page_size) + "\n";
|
|
156 |
os_version += "Linux\n";
|
|
157 |
#endif
|
|
158 |
|
|
159 |
/* Get the processor's type string using the CPUID instruction. */
|
|
160 |
std::string processor_name = "Processor: ";
|
|
161 |
uint32_t registers[4];
|
|
162 |
unsigned i;
|
|
163 |
|
|
164 |
i = 0x80000002;
|
|
165 |
asm volatile
|
|
166 |
("cpuid" : "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3])
|
|
167 |
: "a" (i), "c" (0));
|
|
168 |
processor_name += std::string((const char *)®isters[0], 4);
|
|
169 |
processor_name += std::string((const char *)®isters[1], 4);
|
|
170 |
processor_name += std::string((const char *)®isters[2], 4);
|
|
171 |
processor_name += std::string((const char *)®isters[3], 4);
|
|
172 |
i = 0x80000003;
|
|
173 |
asm volatile
|
|
174 |
("cpuid" : "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3])
|
|
175 |
: "a" (i), "c" (0));
|
|
176 |
processor_name += std::string((const char *)®isters[0], 4);
|
|
177 |
processor_name += std::string((const char *)®isters[1], 4);
|
|
178 |
processor_name += std::string((const char *)®isters[2], 4);
|
|
179 |
processor_name += std::string((const char *)®isters[3], 4);
|
|
180 |
i = 0x80000004;
|
|
181 |
asm volatile
|
|
182 |
("cpuid" : "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3])
|
|
183 |
: "a" (i), "c" (0));
|
|
184 |
processor_name += std::string((const char *)®isters[0], 4);
|
|
185 |
processor_name += std::string((const char *)®isters[1], 4);
|
|
186 |
processor_name += std::string((const char *)®isters[2], 4);
|
|
187 |
processor_name += std::string((const char *)®isters[3], 3);
|
|
188 |
|
|
189 |
QString processor_bits = "Number of bits: unknown";
|
|
190 |
|
|
191 |
if(sizeof(void*) == 4)
|
|
192 |
processor_bits = "Number of bits: 32 (probably)";
|
|
193 |
else
|
|
194 |
if(sizeof(void*) == 8)
|
|
195 |
processor_bits = "Number of bits: 64 (probably)";
|
|
196 |
|
|
197 |
description->setText(
|
|
198 |
"\n\n\n"
|
|
199 |
"System information:\n"
|
|
200 |
+ qt_version
|
|
201 |
+ os_version
|
|
202 |
+ total_ram
|
|
203 |
+ available_ram
|
|
204 |
+ screen_size
|
|
205 |
+ number_of_screens
|
|
206 |
+ number_of_cores
|
|
207 |
+ QString::fromStdString(processor_name + "\n")
|
|
208 |
+ processor_bits
|
|
209 |
);
|
6700
|
210 |
description->setReadOnly(false);
|
|
211 |
pageLayout->addWidget(description);
|
|
212 |
|
|
213 |
return pageLayout;
|
|
214 |
}
|
|
215 |
|
|
216 |
QLayout * PageFeedback::footerLayoutDefinition()
|
|
217 |
{
|
|
218 |
QHBoxLayout * bottomLayout = new QHBoxLayout();
|
|
219 |
|
|
220 |
bottomLayout->setStretch(0,1);
|
|
221 |
//TODO: create logo for send button
|
|
222 |
BtnSend = addButton("Send", bottomLayout, 0, false);
|
|
223 |
bottomLayout->insertStretch(0);
|
|
224 |
|
|
225 |
return bottomLayout;
|
|
226 |
}
|
|
227 |
|
|
228 |
void PageFeedback::connectSignals()
|
|
229 |
{
|
|
230 |
//TODO
|
|
231 |
}
|
|
232 |
|
|
233 |
PageFeedback::PageFeedback(QWidget* parent) : AbstractPage(parent)
|
|
234 |
{
|
|
235 |
initPage();
|
|
236 |
|
|
237 |
}
|