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 #include "Device.h"
0022 
0023 #include <QDebug>
0024 
0025 #warning code copy waaaaaaaaaaaaaaaaaaaaaaaah
0026 
0027 Driver::Driver()
0028     : packageName()
0029     , recommended(false)
0030     , fromDistro(false)
0031     , free(false)
0032     , builtin(false)
0033     , manualInstall(false)
0034     // Set by manager; qapt dependent:
0035     , fuzzyActive(false)
0036     , package(nullptr)
0037 {
0038 }
0039 
0040 bool Driver::operator<(const Driver &other) const
0041 {
0042     return (packageName < other.packageName);
0043 }
0044 
0045 QDebug operator<<(QDebug dbg, const Device &device)
0046 {
0047     dbg.nospace() << "Dev(";
0048     dbg.nospace() << "\n  id: " << device.id;
0049     dbg.nospace() << "\n  modalias: " << device.modalias;
0050     dbg.nospace() << "\n  model: " << device.model;
0051     dbg.nospace() << "\n  vendor: " << device.vendor;
0052     foreach (const Driver &driver, device.drivers) {
0053         dbg.nospace() << "\n  driver(" << driver.packageName;
0054         dbg.nospace() << " recommended[" << driver.recommended << "]";
0055         dbg.nospace() << " free[" << driver.free << "]";
0056         dbg.nospace() << " fromDistro[" << driver.fromDistro << "]";
0057         dbg.nospace() << " builtin[" << driver.builtin << "]";
0058         dbg.nospace() << " manualInstall[" << driver.manualInstall << "]";
0059         dbg.nospace() << " fuzzyActive[" << driver.fuzzyActive << "]";
0060         dbg.nospace() << " package[" << driver.package << "]";
0061         dbg.nospace() << ")";
0062     }
0063     dbg.nospace() << "\n)";
0064     return dbg.maybeSpace();
0065 }
0066 
0067 const QDBusArgument &operator>>(const QDBusArgument &argument, Driver &driver)
0068 {
0069     argument.beginMap();
0070     while (!argument.atEnd()) {
0071         QString key;
0072         bool value;
0073         argument.beginMapEntry();
0074         argument >> key >> value;
0075         if (key == QLatin1String("recommended")) {
0076             driver.recommended = value;
0077         } else if (key == QLatin1String("free")) {
0078             driver.free = value;
0079         } else if (key == QLatin1String("from_distro")) {
0080             driver.fromDistro = value;
0081         } else if (key == QLatin1String("builtin")) {
0082             driver.builtin = value;
0083         } else if (key == QLatin1String("manual_install")) {
0084             driver.manualInstall = value;
0085         }
0086         argument.endMapEntry();
0087     }
0088 
0089     argument.endMap();
0090     return argument;
0091 }
0092 
0093 const QDBusArgument &operator>>(const QDBusArgument &argument, QList<Driver> &driverList)
0094 {
0095     argument.beginMap();
0096     while (!argument.atEnd()) {
0097         Driver driver;
0098         argument.beginMapEntry();
0099         argument >> driver.packageName >> driver;
0100         argument.endMapEntry();
0101         driverList.append(driver);
0102     }
0103     argument.endMap();
0104     return argument;
0105 }
0106 
0107 const QDBusArgument &operator>>(const QDBusArgument &argument, Device &device)
0108 {
0109     argument.beginMap();
0110 
0111     while (!argument.atEnd()) {
0112         QString key;
0113         QVariant value;
0114 
0115         argument.beginMapEntry();
0116         argument >> key >> value;
0117 
0118         if (key == QLatin1String("modalias")) {
0119             device.modalias = value.toString();
0120         } else if (key == QLatin1String("vendor")) {
0121             device.vendor = value.toString();
0122         } else if (key == QLatin1String("model")) {
0123             device.model = value.toString();
0124         } else if (value.canConvert<QDBusArgument>()) {
0125             QDBusArgument arg = value.value<QDBusArgument>();
0126             arg >> device.drivers;
0127         }
0128 
0129         argument.endMapEntry();
0130     }
0131 
0132     argument.endMap();
0133     return argument;
0134 }
0135 
0136 const QDBusArgument &operator>>(const QDBusArgument &argument, DeviceList &deviceList)
0137 {
0138     qDebug() << Q_FUNC_INFO;
0139     argument.beginMap();
0140     while (!argument.atEnd()) {
0141         Device device;
0142         argument.beginMapEntry();
0143         argument >> device.id >> device;
0144         argument.endMapEntry();
0145         deviceList.append(device);
0146         qDebug() << device;
0147     }
0148     argument.endMap();
0149     return argument;
0150 }
0151 
0152 QDBusArgument &operator<<(QDBusArgument &argument, const DeviceList &deviceList)
0153 {
0154     Q_UNUSED(deviceList);
0155     qDebug() << Q_FUNC_INFO << "is noop";
0156     argument.beginMap(QVariant::String, QVariant::Map);
0157     argument.endMap();
0158     return argument;
0159 }