From 7a7e2b16cb19b67c5d80dfd842f2d91d20d4e472 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 8 Nov 2017 09:17:18 -0500 Subject: [PATCH] [libcalamares] Some extra system-information functions --- .../utils/CalamaresUtilsSystem.cpp | 31 ++++++++++++++++++- src/libcalamares/utils/CalamaresUtilsSystem.h | 16 +++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.cpp b/src/libcalamares/utils/CalamaresUtilsSystem.cpp index 656a57c10..35f394364 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.cpp +++ b/src/libcalamares/utils/CalamaresUtilsSystem.cpp @@ -232,7 +232,7 @@ System::targetEnvOutput( const QString& command, QPair -System::getTotalMemoryB() +System::getTotalMemoryB() const { #ifdef Q_OS_LINUX struct sysinfo i; @@ -257,4 +257,33 @@ System::getTotalMemoryB() } +QString +System::getCpuDescription() const +{ + QString model; + +#ifdef Q_OS_LINUX + QFile file("/proc/cpuinfo"); + if ( file.open(QIODevice::ReadOnly | QIODevice::Text) ) + while ( !file.atEnd() ) + { + QByteArray line = file.readLine(); + if ( line.startsWith( "model name" ) && (line.indexOf( ':' ) > 0) ) + { + model = QString::fromLatin1( line.right(line.length() - line.indexOf( ':' ) ) ); + break; + } + } +#elif defined( Q_OS_FREEBSD ) + // This would use sysctl "hw.model", which has a string value +#endif + return model.simplified(); } + +quint64 +System::getTotalDiskB() const +{ + return 0; +} + +} // namespace diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.h b/src/libcalamares/utils/CalamaresUtilsSystem.h index 1ccdfb516..34ab7ecbd 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.h +++ b/src/libcalamares/utils/CalamaresUtilsSystem.h @@ -112,7 +112,21 @@ public: * * @return size, guesstimate-factor */ - DLLEXPORT QPair getTotalMemoryB(); + DLLEXPORT QPair getTotalMemoryB() const; + + /** + * @brief getCpuDescription returns a string describing the CPU. + * + * Returns the value of the "model name" line in /proc/cpuinfo. + */ + DLLEXPORT QString getCpuDescription() const; + + /** + * @brief getTotalDiskB returns the total disk attached, in bytes. + * + * If nothing can be found, returns a 0. + */ + DLLEXPORT quint64 getTotalDiskB() const; private: static System* s_instance;