File indexing completed on 2025-01-05 05:09:31

0001 /*
0002     SPDX-FileCopyrightText: 2010-2012 Daniel Nicoletti <dantti12@gmail.com>
0003     SPDX-FileCopyrightText: 2023 Mike Noe <noeerover@gmail.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef PPD_MODEL_H
0009 #define PPD_MODEL_H
0010 
0011 #include <QStandardItemModel>
0012 #include <kcupslib_export.h>
0013 #include <qqmlregistration.h>
0014 
0015 struct DriverMatch {
0016     QString ppd;
0017     QString match;
0018 };
0019 
0020 typedef QList<DriverMatch> DriverMatchList;
0021 
0022 class KCUPSLIB_EXPORT PPDModel : public QStandardItemModel
0023 {
0024     Q_OBJECT
0025     QML_ELEMENT
0026 
0027 public:
0028     enum Role { PPDName = Qt::UserRole, PPDMake, PPDMakeAndModel };
0029     Q_ENUM(Role)
0030 
0031     explicit PPDModel(QObject *parent = nullptr);
0032     void setPPDs(const QList<QVariantMap> &ppds, const DriverMatchList &driverMatch = DriverMatchList());
0033 
0034     Qt::ItemFlags flags(const QModelIndex &index) const override;
0035     virtual QHash<int, QByteArray> roleNames() const override;
0036 
0037     Q_INVOKABLE void load();
0038 
0039 Q_SIGNALS:
0040     void error(const QString &msg);
0041     void loaded();
0042 
0043 private:
0044     QStandardItem *createPPDItem(const QVariantMap &ppd, bool recommended);
0045     QStandardItem *findCreateMake(const QString &make);
0046 
0047     QList<QVariantMap> m_ppds;
0048     QHash<int, QByteArray> m_roles;
0049 };
0050 
0051 Q_DECLARE_METATYPE(DriverMatchList)
0052 Q_DECLARE_METATYPE(DriverMatch)
0053 
0054 #endif