Changeset View
Changeset View
Standalone View
Standalone View
Modules/samba/smbmountmodel.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | SPDX-FileCopyrightText: 2020 Harald Sitter <sitter@kde.org> | ||||
3 | SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL | ||||
4 | */ | ||||
5 | | ||||
6 | #ifndef SMBMOUNTMODEL_H | ||||
7 | #define SMBMOUNTMODEL_H | ||||
8 | | ||||
9 | #include <QAbstractListModel> | ||||
10 | #include <QList> | ||||
11 | #include <Solid/Device> | ||||
12 | | ||||
13 | /** | ||||
14 | * Model of cifs mount entires. Implementing properties | ||||
15 | * as columns rather than roles. | ||||
16 | */ | ||||
17 | class SmbMountModel : public QAbstractListModel | ||||
18 | { | ||||
19 | Q_OBJECT | ||||
20 | public: | ||||
21 | enum class ColumnRole { | ||||
22 | Share, | ||||
23 | Path, | ||||
24 | Accessible, | ||||
25 | ColumnCount, // End marker | ||||
26 | }; | ||||
27 | | ||||
28 | explicit SmbMountModel(QObject *parent = nullptr); | ||||
29 | ~SmbMountModel() override; | ||||
30 | | ||||
31 | int rowCount(const QModelIndex &parent) const override; | ||||
32 | int columnCount(const QModelIndex &parent) const override; | ||||
33 | QVariant headerData(int section, Qt::Orientation orientation, int role) const override; | ||||
34 | QVariant data(const QModelIndex &index, int role) const override; | ||||
35 | bool hasChildren(const QModelIndex &parent) const override; | ||||
36 | | ||||
37 | private slots: | ||||
38 | void addDevice(const QString &udi); | ||||
39 | void removeDevice(const QString &udi); | ||||
40 | void reloadData(); | ||||
41 | | ||||
42 | private: | ||||
43 | inline QList<Solid::Device>::const_iterator deviceForUdi(const QString &udi) const | ||||
44 | { | ||||
45 | return std::find_if(m_devices.constBegin(), m_devices.constEnd(), | ||||
46 | [&udi](const Solid::Device &device) { | ||||
47 | return device.udi() == udi; | ||||
48 | }); | ||||
49 | } | ||||
50 | | ||||
51 | QList<Solid::Device> m_devices; | ||||
52 | }; | ||||
53 | | ||||
54 | #endif // SMBMOUNTMODEL_H |