File indexing completed on 2022-09-27 16:37:10

0001 /*
0002     SPDX-FileCopyrightText: 2010 Daniel Nicoletti <dantti12@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef DEVICES_MODEL_H
0008 #define DEVICES_MODEL_H
0009 
0010 #include <QStandardItemModel>
0011 #include <QDBusMessage>
0012 #include <QRegExp>
0013 
0014 #include <KCupsPrinter.h>
0015 
0016 typedef QMap<QString, QString> MapSS;
0017 typedef QMap<QString, MapSS> MapSMapSS;
0018 
0019 class KCupsRequest;
0020 class DevicesModel : public QStandardItemModel
0021 {
0022     Q_OBJECT
0023 public:
0024     enum Role {
0025         DeviceClass = Qt::UserRole + 2,
0026         DeviceId,
0027         DeviceInfo,
0028         DeviceMakeAndModel,
0029         DeviceUri,
0030         DeviceUris,
0031         DeviceLocation
0032     };
0033     Q_ENUM(Role)
0034 
0035     enum Kind {
0036         Other,
0037         Local,
0038         Networked,
0039         OtherNetworked
0040     };
0041     Q_ENUM(Kind)
0042 
0043     explicit DevicesModel(QObject *parent = nullptr);
0044 
0045 signals:
0046     void loaded();
0047     void parentAdded(const QModelIndex &index);
0048     void errorMessage(const QString &message);
0049 
0050 public slots:
0051     void update();
0052     void insertDevice(const QString &device_class,
0053                       const QString &device_id,
0054                       const QString &device_info,
0055                       const QString &device_make_and_model,
0056                       const QString &device_uri,
0057                       const QString &device_location,
0058                       const QStringList &grouped_uris = QStringList());
0059     void insertDevice(const QString &device_class,
0060                       const QString &device_id,
0061                       const QString &device_info,
0062                       const QString &device_make_and_model,
0063                       const QString &device_uri,
0064                       const QString &device_location,
0065                       const KCupsPrinters &grouped_printers);
0066 
0067 private slots:
0068     QStandardItem* createItem(const QString &device_class,
0069                               const QString &device_id,
0070                               const QString &device_info,
0071                               const QString &device_make_and_model,
0072                               const QString &device_uri,
0073                               const QString &device_location,
0074                               bool grouped);
0075     void gotDevice(const QString &device_class,
0076                    const QString &device_id,
0077                    const QString &device_info,
0078                    const QString &device_make_and_model,
0079                    const QString &device_uri,
0080                    const QString &device_location);
0081     void finished();
0082     void getGroupedDevicesSuccess(const QDBusMessage &message);
0083     void getGroupedDevicesFailed(const QDBusError &error, const QDBusMessage &message);
0084     void groupedDevicesFallback();
0085 
0086 private:
0087     QStandardItem *findCreateCategory(const QString &category, Kind kind);
0088 
0089     KCupsRequest *m_request;
0090     MapSMapSS m_mappedDevices;
0091     QRegExp m_rx;
0092     QStringList m_blacklistedURIs;
0093 };
0094 
0095 Q_DECLARE_METATYPE(MapSS)
0096 Q_DECLARE_METATYPE(MapSMapSS)
0097 
0098 #endif