diff options
author | Lorn Potter <lorn.potter@jollamobile.com> | 2013-09-07 05:44:08 +1000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-10 22:03:41 +0200 |
commit | 1d193dc874dedd916ed2b9fe2ad8b56a4fbf5304 (patch) | |
tree | 63ace07eed1d062996945c5f35170115025bdab8 /src/systeminfo/linux/qdeviceinfo_linux.cpp | |
parent | 47258c5861ee05e1f550200f3b65191b3897fb3a (diff) |
Add operating system name and board name functions
Change-Id: I438e98a942ee8dc574d11459f88244b20291435e
Reviewed-by: Lorn Potter <lorn.potter@jollamobile.com>
Diffstat (limited to 'src/systeminfo/linux/qdeviceinfo_linux.cpp')
-rw-r--r-- | src/systeminfo/linux/qdeviceinfo_linux.cpp | 91 |
1 files changed, 59 insertions, 32 deletions
diff --git a/src/systeminfo/linux/qdeviceinfo_linux.cpp b/src/systeminfo/linux/qdeviceinfo_linux.cpp index 2ff71984..a4ddba9e 100644 --- a/src/systeminfo/linux/qdeviceinfo_linux.cpp +++ b/src/systeminfo/linux/qdeviceinfo_linux.cpp @@ -72,6 +72,8 @@ QDeviceInfoPrivate::QDeviceInfoPrivate(QDeviceInfo *parent) , imeiBuffer(QStringList()) , uniqueDeviceIDBuffer(QString()) , timer(0) + , boardNameString(QString()) + , osName(QString()) #if !defined(QT_NO_OFONO) , ofonoWrapper(0) #endif // QT_NO_OFONO @@ -286,7 +288,9 @@ QString QDeviceInfoPrivate::manufacturer() } } } - + if (manufacturerBuffer.isEmpty()) { + manufacturerBuffer = findInRelease(QStringLiteral("BUILD")); + } return manufacturerBuffer; } @@ -325,20 +329,9 @@ QString QDeviceInfoPrivate::model() QString QDeviceInfoPrivate::productName() { if (productNameBuffer.isEmpty()) { - QFile release(QStringLiteral("/etc/os-release")); - if (release.open(QIODevice::ReadOnly)) { - QTextStream stream(&release); - QString line; - do { - line = stream.readLine(); - if (line.startsWith(QStringLiteral("PRETTY_NAME"))) { - productNameBuffer = line.split(QStringLiteral("=")).at(1).simplified().remove("\""); - break; - } - } while (!line.isNull()); - release.close(); - } + productNameBuffer = findInRelease(QStringLiteral("PRETTY_NAME")).remove("\""); } + if (productNameBuffer.isEmpty()) { QProcess lsbRelease; lsbRelease.start(QStringLiteral("/usr/bin/lsb_release"), @@ -405,25 +398,9 @@ QString QDeviceInfoPrivate::version(QDeviceInfo::Version type) case QDeviceInfo::Os: if (versionBuffer[0].isEmpty()) { - QStringList releaseFies = QDir(QStringLiteral("/etc/")).entryList(QStringList() << QStringLiteral("*-release")); - foreach (const QString &file, releaseFies) { - if (!versionBuffer[0].isEmpty()) - continue; - QFile release(QStringLiteral("/etc/") + file); - if (release.open(QIODevice::ReadOnly)) { - QTextStream stream(&release); - QString line; - do { - line = stream.readLine(); - if (line.left(8) == QStringLiteral("VERSION=")) { - versionBuffer[0] = line.split(QStringLiteral("=")).at(1).simplified(); - break; - } - } while (!line.isNull()); - release.close(); - } - } + versionBuffer[0] = findInRelease(QStringLiteral("VERSION_ID")); } + if (versionBuffer[0].isEmpty() && QFile::exists(QStringLiteral("/usr/bin/lsb_release"))) { QProcess lsbRelease; lsbRelease.start(QStringLiteral("/usr/bin/lsb_release"), @@ -450,6 +427,56 @@ QString QDeviceInfoPrivate::version(QDeviceInfo::Version type) return QString(); } +QString QDeviceInfoPrivate::operatingSystemName() +{ + if (osName.isEmpty()) { + osName = findInRelease(QStringLiteral("NAME=")); + } + + return osName; +} + +QString QDeviceInfoPrivate::boardName() +{ + if (boardNameString.isEmpty()) { + QFile boardfile(QStringLiteral("/etc/boardname")); + if (boardfile.open(QIODevice::ReadOnly)) + boardNameString = QString::fromLocal8Bit(boardfile.readAll().simplified().data()); + } + + if (boardNameString.isEmpty()) { + // for dmi enabled kernels + QFile file(QStringLiteral("/sys/devices/virtual/dmi/id/board_name")); + if (file.open(QIODevice::ReadOnly)) + boardNameString = QString::fromLocal8Bit(file.readAll().simplified().data()); + } + return boardNameString; +} + +QString QDeviceInfoPrivate::findInRelease(const QString &searchTerm) +{ + QString result; + QStringList releaseFies = QDir(QStringLiteral("/etc/")).entryList(QStringList() << QStringLiteral("*-release")); + foreach (const QString &file, releaseFies) { + if (!result.isEmpty()) + continue; + QFile release(QStringLiteral("/etc/") + file); + if (release.open(QIODevice::ReadOnly)) { + QTextStream stream(&release); + QString line; + do { + line = stream.readLine(); + if (line.left(searchTerm.size()) == searchTerm) { + result = line.split(QStringLiteral("=")).at(1).simplified(); + break; + } + } while (!line.isNull()); + release.close(); + } + } + return result; +} + extern QMetaMethod proxyToSourceSignal(const QMetaMethod &, QObject *); void QDeviceInfoPrivate::connectNotify(const QMetaMethod &signal) |