File indexing completed on 2024-04-21 16:20:18

0001 /*
0002     SPDX-FileCopyrightText: 2016-2018 Jan Grulich <jgrulich@redhat.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #ifndef PLASMA_NM_CREATABLE_CONNECTIONS_MODEL_H
0008 #define PLASMA_NM_CREATABLE_CONNECTIONS_MODEL_H
0009 
0010 #include <NetworkManagerQt/ConnectionSettings>
0011 #include <QAbstractListModel>
0012 
0013 class Q_DECL_EXPORT CreatableConnectionItem : public QObject
0014 {
0015     Q_OBJECT
0016 public:
0017     explicit CreatableConnectionItem(const QString &typeName,
0018                                      const QString &typeSection, // Visible properties
0019                                      const QString &description,
0020                                      const QString &icon, // Visible properties
0021                                      NetworkManager::ConnectionSettings::ConnectionType type, // Properties needed for creating
0022                                      const QString &vpnType = QString(), // Properties needed for creating
0023                                      const QString &specificType = QString(), // Properties needed for creating
0024                                      bool shared = false, // Properties needed for creating
0025                                      QObject *parent = nullptr);
0026     explicit CreatableConnectionItem(QObject *parent = nullptr);
0027     ~CreatableConnectionItem() override;
0028 
0029     NetworkManager::ConnectionSettings::ConnectionType connectionType() const;
0030     void setConnectionType(NetworkManager::ConnectionSettings::ConnectionType type);
0031 
0032     QString description() const;
0033     void setDescription(const QString &description);
0034 
0035     QString icon() const;
0036     void setIcon(const QString &icon);
0037 
0038     QString specificType() const;
0039     void setSpecificType(const QString &specificType);
0040 
0041     bool shared() const;
0042     void setShared(bool shared);
0043 
0044     QString typeName() const;
0045     void setTypeName(const QString &typeName);
0046 
0047     QString typeSection() const;
0048     void setTypeSection(const QString &typeSection);
0049 
0050     QString vpnType() const;
0051     void setVpnType(const QString &vpnType);
0052 
0053 private:
0054     bool m_shared;
0055     NetworkManager::ConnectionSettings::ConnectionType m_connectionType;
0056     QString m_description;
0057     QString m_icon;
0058     QString m_specificType;
0059     QString m_typeName;
0060     QString m_typeSection;
0061     QString m_vpnType;
0062 };
0063 
0064 class Q_DECL_EXPORT CreatableConnectionsModel : public QAbstractListModel
0065 {
0066     Q_OBJECT
0067 public:
0068     explicit CreatableConnectionsModel(QObject *parent = nullptr);
0069     ~CreatableConnectionsModel() override;
0070 
0071     enum ItemRole {
0072         ConnectionDescription = Qt::UserRole + 1,
0073         ConnectionIcon,
0074         ConnectionSpeficType,
0075         ConnectionShared,
0076         ConnectionType,
0077         ConnectionTypeName,
0078         ConnectionTypeSection,
0079         ConnectionVpnType,
0080     };
0081 
0082     int rowCount(const QModelIndex &parent) const override;
0083     QVariant data(const QModelIndex &index, int role) const override;
0084     QHash<int, QByteArray> roleNames() const override;
0085 
0086 private:
0087     void populateModel();
0088     QList<CreatableConnectionItem *> m_list;
0089 };
0090 
0091 #endif // PLASMA_NM_CREATABLE_CONNECTIONS_MODEL_H