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 93 94 95 96
|
/*
* Copyright (C) 2022 Guido Berhoerster <guido+ubports@berhoerster.name>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <QSysInfo>
#include <fstream>
#include <memory>
#include <sstream>
#include <unistd.h>
#include <QCoreApplication>
#include <QSysInfo>
#include "systeminfo.h"
SystemInfo::SystemInfo(QObject *parent) : QObject(parent)
{
}
SystemInfo::~SystemInfo()
{
}
QString SystemInfo::buildAbi()
{
return QSysInfo::buildAbi();
}
QString SystemInfo::cpuArch()
{
return QSysInfo::currentCpuArchitecture();
}
QString SystemInfo::kernelVersion()
{
return QSysInfo::kernelVersion();
}
static std::string dmi_devicename()
{
std::string str1;
std::string str2;
std::ifstream dmi_vendor("/sys/devices/virtual/dmi/id/sys_vendor");
std::ifstream dmi_model("/sys/devices/virtual/dmi/id/product_name");
std::getline(dmi_vendor, str1);
std::getline(dmi_model, str2);
return str1 + " " + str2;
}
static std::string devicetree_devicename()
{
std::string str;
std::ifstream devicetree_model("/proc/device-tree/model");
std::getline(devicetree_model, str);
return str;
}
QString SystemInfo::prettyName()
{
QString str = "unknown";
#ifdef ENABLE_DEVICEINFO
DeviceInfo info;
str = QString::fromStdString(info.prettyName());
#endif
if (str.toStdString() == "unknown"
|| str.toStdString() == "Generic device"
|| str.toStdString() == "Generic Halium device"
|| str.toStdString() == "Generic linux device") {
// Fallback if we happen to stumble onto default values.
if (access("/sys/devices/virtual/dmi", F_OK) != -1) {
return QString::fromStdString(dmi_devicename());
} else {
return QString::fromStdString(devicetree_devicename());
}
}
return str;
}
QString SystemInfo::distribution()
{
return QSysInfo::prettyProductName();
}
|