File indexing completed on 2024-05-19 05:49:20

0001 /*
0002     Copyright (C) 2014 Harald Sitter <apachelogger@kubuntu.org>
0003 
0004     This program is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU General Public License as
0006     published by the Free Software Foundation; either version 2 of
0007     the License or (at your option) version 3 or any later version
0008     accepted by the membership of KDE e.V. (or its successor approved
0009     by the membership of KDE e.V.), which shall act as a proxy
0010     defined in Section 14 of version 3 of the license.
0011 
0012     This program is distributed in the hope that it will be useful,
0013     but WITHOUT ANY WARRANTY; without even the implied warranty of
0014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0015     GNU General Public License for more details.
0016 
0017     You should have received a copy of the GNU General Public License
0018     along with this program.  If not, see <http://www.gnu.org/licenses/>.
0019 */
0020 
0021 #ifndef DEVICE_H
0022 #define DEVICE_H
0023 
0024 #include <QDBusArgument>
0025 #include <QDebug>
0026 
0027 namespace QApt {
0028 class Package;
0029 }
0030 
0031 struct Driver
0032 {
0033     /** Constructor */
0034     Driver();
0035 
0036     /** the distribution package providing this driver */
0037     QString packageName;
0038     /** this is the recommended driver for the associated device */
0039     bool recommended;
0040     /** this driver is an official distribution driver (otherwise 3rd party) */
0041     bool fromDistro;
0042     /** this is a free driver */
0043     bool free;
0044     /** this driver is built into the platform (e.g. official xorg drivers) */
0045     bool builtin;
0046     /** driver was manually installed */
0047     bool manualInstall;
0048 
0049     /** most likely the active driver; dependent on fuzzy heuristics */
0050     bool fuzzyActive;
0051 
0052     /** QApt package pointer or nullptr if not initalized or found */
0053     QApt::Package *package;
0054 
0055     bool operator<(const Driver &other) const;
0056 };
0057 
0058 struct Device
0059 {
0060     /** /dev system id of the device */
0061     QString id;
0062     /** modalias */
0063     QString modalias;
0064     /** model e.g. "GK104 [GeForce GTX 660 OEM]" */
0065     QString model;
0066     /** vendor e.g. "NVIDIA Corporation" */
0067     QString vendor;
0068     /** list of applicable drivers */
0069     QList<Driver> drivers;
0070 };
0071 
0072 typedef QList<Device> DeviceList;
0073 Q_DECLARE_METATYPE(DeviceList)
0074 
0075 // -------------------------------------------------------------------------- //
0076 // --------------------------------- Debug ---------------------------------- //
0077 // -------------------------------------------------------------------------- //
0078 
0079 /**
0080  * QDebug operator for Device. This fung deep-debugs all members, without
0081  * additional operators for the specific member types.
0082  */
0083 QDebug operator<<(QDebug dbg, const Device &device);
0084 
0085 // -------------------------------------------------------------------------- //
0086 // ---------------------------------- DBus ---------------------------------- //
0087 // -------------------------------------------------------------------------- //
0088 
0089 // We are doing nested demarshalling as auto-marshalling into basic types
0090 // such as QMap<QString, QVariant> will not give us any advantage other than
0091 // flattening out the marshalling, thus causing shitty to read functions;
0092 // we'd still have to do string mapping and variant casting.
0093 
0094 /** demarshall driver */
0095 const QDBusArgument &operator>>(const QDBusArgument &argument, Driver &driver);
0096 /** demarshall list of drivers */
0097 const QDBusArgument &operator>>(const QDBusArgument &argument, QList<Driver> &driverList);
0098 /** demarshall device */
0099 const QDBusArgument &operator>>(const QDBusArgument &argument, Device &device);
0100 /** demarshall list of devices */
0101 const QDBusArgument &operator>>(const QDBusArgument &argument, DeviceList &deviceList);
0102 
0103 /** marshall list of devices. this function does nothing. */
0104 QDBusArgument &operator<<(QDBusArgument &argument, const DeviceList &deviceList);
0105 
0106 #endif // DEVICE_H