22
28
#include "systeminfo.h"
24
#define LSB_RELEASE "/usr/bin/lsb_release"
26
SystemInfo::SystemInfo() : QObject(QCoreApplication::instance())
31
static QString lsbRelease(const QStringList& args)
30
timezone_str_ = "N/A";
34
#if defined(Q_WS_X11) || defined(Q_WS_MAC)
40
strftime(str, 256, fmt, localtime(&x));
41
if(strcmp(fmt, str)) {
45
s.truncate(s.length()-2);
46
timezone_offset_ = s.toInt();
49
strftime(str, 256, fmt, localtime(&x));
54
// attempt to get LSB version before trying the distro-specific approach
55
if(QFileInfo(LSB_RELEASE).exists())
57
os_str_ = lsbRelease(QStringList("-ds"));
59
if(!os_str_.isEmpty())
33
QStringList path = QString(qgetenv("PATH")).split(':');
36
foreach(QString dirname, path) {
38
QFileInfo cand(dir.filePath("lsb_release"));
39
if (cand.isExecutable()) {
40
found = cand.absoluteFilePath();
45
if (found.isEmpty()) {
50
process.start(found, args, QIODevice::ReadOnly);
52
if(!process.waitForStarted())
53
return QString(); // process failed to start
55
QTextStream stream(&process);
58
while(process.waitForReadyRead())
59
ret += stream.readAll();
66
static QString unixHeuristicDetect() {
65
os_str_.sprintf("%s", u.sysname);
72
ret.sprintf("%s", u.sysname);
67
74
// get description about os
133
140
switch ( osInfo[i].flags ) {
138
os_str_ = osInfo[i].name;
145
ret = osInfo[i].name;
140
147
case OsAppendFile:
141
os_str_ = osInfo[i].name + " (" + desc + ")";
148
ret = osInfo[i].name + " (" + desc + ")";
161
SystemInfo::SystemInfo() : QObject(QCoreApplication::instance())
164
timezone_offset_ = 0;
165
timezone_str_ = "N/A";
169
#if defined(Q_WS_X11) || defined(Q_WS_MAC)
175
strftime(str, 256, fmt, localtime(&x));
176
if(strcmp(fmt, str)) {
180
s.truncate(s.length()-2);
181
timezone_offset_ = s.toInt();
184
strftime(str, 256, fmt, localtime(&x));
188
#if defined(Q_WS_X11)
189
// attempt to get LSB version before trying the distro-specific approach
190
os_str_ = lsbRelease(QStringList() << "--description" << "--short");
192
if(os_str_.isEmpty()) {
193
os_str_ = unixHeuristicDetect();
148
196
#elif defined(Q_WS_MAC)
149
197
QSysInfo::MacVersion v = QSysInfo::MacintoshVersion;
150
198
if(v == QSysInfo::MV_10_3)
153
201
os_str_ = "Mac OS X 10.4";
154
202
else if(v == QSysInfo::MV_10_5)
155
203
os_str_ = "Mac OS X 10.5";
204
#if QT_VERSION >= 0x040500
205
else if(v == QSysInfo::MV_10_6)
206
os_str_ = "Mac OS X 10.6";
157
209
os_str_ = "Mac OS X";
194
246
os_str_ = "Windows Server 2003";
195
247
else if(v == QSysInfo::WV_VISTA)
196
248
os_str_ = "Windows Vista";
249
#if QT_VERSION >= 0x040500
250
else if(v == QSysInfo::WV_WINDOWS7)
251
os_str_ = "Windows 7";
197
253
else if(v == QSysInfo::WV_NT_based)
198
254
os_str_ = "Windows NT";
202
#if defined(Q_WS_X11)
203
QString SystemInfo::lsbRelease(const QStringList& args)
206
process.start(LSB_RELEASE, args, QIODevice::ReadOnly);
208
if(!process.waitForStarted())
209
return QString(); // process failed to start
211
QTextStream stream(&process);
214
while(process.waitForReadyRead())
215
ret += stream.readAll();
218
return ret.trimmed();
222
258
SystemInfo* SystemInfo::instance()