operatingsystem.cpp
2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "operatingsystem.h"
OperatingSystem::OperatingSystem()
{
this->nomeOs = this->coletaNomeOs();
this->idOs = this->coletaIdOs();
}
/*pegarOS
* @return: int;
* retorna um id referente a versão do SO.
* 48 = Windows XP
* 128 = Windows Vista
* 144 = Windows 7
* 160 = Windows 8
* 176 = Windows 8.1
* [enum] = Linux
*/
int OperatingSystem::coletaIdOs(){
#if defined (Q_OS_WIN)
return QSysInfo::WindowsVersion;
#elif defined (Q_OS_LINUX)
ConsoleObject console;
QStringList catOutput = console("cat /etc/*release").split("\n");
QString line;
foreach(line, catOutput) {
if(line.contains("PRETTY_NAME")) {
if( line.contains("Arch"))
return LINUX_ARCH;
else if( line.contains("Debian"))
return LINUX_DEBIAN;
else if( line.contains("Ubuntu"))
return LINUX_UBUNTU;
}
}
#else
return -1;
#endif
}
QString OperatingSystem::coletaNomeOs()
{
#if defined(Q_OS_WIN)
QStringList params;
QJsonValue osName;
params << "Name";
osName = wmi::wmiSearch("Win32_OperatingSystem", params);
if (!osName.isNull()){
QString retorno = osName.toObject()["Name"].toString();
retorno = retorno.left(retorno.indexOf("|"));
return retorno;
}
#elif defined(Q_OS_LINUX)
ConsoleObject console;
QStringList catOutput = console("cat /etc/*release").split("\n");
QString line;
foreach(line, catOutput) {
if(line.contains("PRETTY_NAME")) {
QStringList split = line.split("=");
QString nomeDistro = split[1].mid(1, split[1].size()-2 );
return nomeDistro;
}
}
#endif
return "";
}
QJsonObject OperatingSystem::toJsonObject()
{
QJsonObject json;
json["idOs"] = QJsonValue::fromVariant(QVariant::fromValue(this->idOs));
json["nomeOs"] = QJsonValue::fromVariant(this->nomeOs);
// qDebug() << json;
return json;
}
QString OperatingSystem::getNomeOs()
{
return this->nomeOs;
}
int OperatingSystem::getIdOs() const
{
return this->idOs;
}