File indexing completed on 2024-03-24 15:44:19

0001 /***************************************************************************
0002  *   Copyright (C) 2012-2016 by Daniel Nicoletti <dantti12@gmail.com>      *
0003  *                                                                         *
0004  *   This program is free software; you can redistribute it and/or modify  *
0005  *   it under the terms of the GNU General Public License as published by  *
0006  *   the Free Software Foundation; either version 2 of the License, or     *
0007  *   (at your option) any later version.                                   *
0008  *                                                                         *
0009  *   This program is distributed in the hope that it will be useful,       *
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0012  *   GNU General Public License for more details.                          *
0013  *                                                                         *
0014  *   You should have received a copy of the GNU General Public License     *
0015  *   along with this program; see the file COPYING. If not, write to       *
0016  *   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,  *
0017  *   Boston, MA 02110-1301, USA.                                           *
0018  ***************************************************************************/
0019 
0020 #include "DmiUtils.h"
0021 
0022 #include <QFile>
0023 #include <QStringList>
0024 
0025 QString DmiUtils::deviceModel()
0026 {
0027     QString ret;
0028     const QStringList sysfsNames = {QStringLiteral("/sys/class/dmi/id/product_name"), QStringLiteral("/sys/class/dmi/id/board_name")};
0029 
0030     for (const QString &filename : sysfsNames) {
0031         QFile file(filename);
0032         if (file.open(QIODevice::ReadOnly)) {
0033             QString tmp = file.readAll();
0034             tmp = tmp.simplified();
0035             if (!tmp.isEmpty()) {
0036                 ret = tmp;
0037                 break;
0038             }
0039         }
0040     }
0041     return ret;
0042 }
0043 
0044 QString DmiUtils::deviceVendor()
0045 {
0046     QString ret;
0047     const QStringList sysfsVendors = {QStringLiteral("/sys/class/dmi/id/sys_vendor"),
0048                                       QStringLiteral("/sys/class/dmi/id/chassis_vendor"),
0049                                       QStringLiteral("/sys/class/dmi/id/board_vendor")};
0050 
0051     for (const QString &filename : sysfsVendors) {
0052         QFile file(filename);
0053         if (file.open(QIODevice::ReadOnly)) {
0054             QString tmp = file.readAll().simplified();
0055             tmp = tmp.simplified();
0056             if (!tmp.isEmpty()) {
0057                 ret = tmp;
0058                 break;
0059             }
0060         }
0061     }
0062     return ret;
0063 }