DeviceModel.h 3.18 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/**************************************************************************
*   Copyright (C) 2009-2010 Trever Fischer <tdfischer@fedoraproject.org>  *
*   Copyright (C) 2015 Kai Uwe Broulik <kde@privat.broulik.de>            *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
*   This program is distributed in the hope that it will be useful,       *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU General Public License for more details.                          *
*                                                                         *
*   You should have received a copy of the GNU General Public License     *
*   along with this program; if not, write to the                         *
*   Free Software Foundation, Inc.,                                       *
*   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
***************************************************************************/

21 22 23
#ifndef DEVICEMODEL_H
#define DEVICEMODEL_H

24 25 26 27 28
#include <QAbstractItemModel>
#include <QModelIndex>
#include <QVariant>
#include <QList>
#include <QHash>
29

30 31
class AutomounterSettings;

32 33 34 35 36
class DeviceModel : public QAbstractItemModel
{
    Q_OBJECT

public:
37
    explicit DeviceModel(AutomounterSettings *m_settings, QObject *parent = nullptr);
38
    ~DeviceModel() override = default;
39 40 41 42 43 44 45 46 47 48 49

    enum DeviceType {
        Attached,
        Detatched
    };

    enum {
        UdiRole = Qt::UserRole,
        TypeRole
    };

50 51 52
    Qt::ItemFlags flags(const QModelIndex &index) const override;
    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
53

54 55
    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    int columnCount(const QModelIndex &parent = QModelIndex()) const override;
56

57 58
    QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
    QModelIndex parent(const QModelIndex &index) const override;
59

60
    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
61

62 63 64
    void setAutomaticMountOnLogin(bool automaticLogin);
    void setAutomaticMountOnPlugin(bool automaticAttached);

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
public slots:
    void forgetDevice(const QString &udi);
    void reload();

private slots:
    void deviceAttached(const QString &udi);
    void deviceRemoved(const QString &udi);

private:
    void addNewDevice(const QString &udi);

    QList<QString> m_attached;
    QList<QString> m_disconnected;
    QHash<QString, bool> m_loginForced;
    QHash<QString, bool> m_attachedForced;
80 81
    bool m_automaticLogin;
    bool m_automaticAttached;
82
    AutomounterSettings *m_settings;
83 84 85
};

#endif