File indexing completed on 2024-05-12 05:35:55

0001 /*
0002     SPDX-FileCopyrightText: 2009-2010 Trever Fischer <tdfischer@fedoraproject.org>
0003     SPDX-FileCopyrightText: 2015 Kai Uwe Broulik <kde@privat.broulik.de>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #pragma once
0009 
0010 #include <QAbstractItemModel>
0011 #include <QHash>
0012 #include <QList>
0013 #include <QModelIndex>
0014 #include <QVariant>
0015 
0016 class AutomounterSettings;
0017 
0018 class DeviceModel : public QAbstractItemModel
0019 {
0020     Q_OBJECT
0021 
0022 public:
0023     explicit DeviceModel(AutomounterSettings *m_settings, QObject *parent = nullptr);
0024     ~DeviceModel() override = default;
0025 
0026     enum DeviceType {
0027         Attached,
0028         Detached,
0029     };
0030 
0031     enum {
0032         UdiRole = Qt::UserRole,
0033         TypeRole,
0034     };
0035 
0036     enum {
0037         RowAll,
0038         RowAttached,
0039         RowDetached,
0040     };
0041 
0042     Qt::ItemFlags flags(const QModelIndex &index) const override;
0043     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0044     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0045 
0046     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0047     int columnCount(const QModelIndex &parent = QModelIndex()) const override;
0048 
0049     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
0050     QModelIndex parent(const QModelIndex &index) const override;
0051 
0052     bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
0053 
0054     void setAutomaticMountOnLogin(bool automaticLogin);
0055     void setAutomaticMountOnPlugin(bool automaticAttached);
0056     void setAutomaticUnknown(bool automaticUnknown);
0057 
0058     void updateCheckedColumns(int column = -1);
0059 
0060 public Q_SLOTS:
0061     void forgetDevice(const QString &udi);
0062     void reload();
0063 
0064 private Q_SLOTS:
0065     void deviceAttached(const QString &udi);
0066     void deviceRemoved(const QString &udi);
0067 
0068 private:
0069     void addNewDevice(const QString &udi);
0070 
0071     QList<QString> m_attached;
0072     QList<QString> m_disconnected;
0073     AutomounterSettings *const m_settings;
0074 };