summaryrefslogtreecommitdiffstats
path: root/network/wifinetworkmodel.h
diff options
context:
space:
mode:
authorMatt Porter <mporter@konsulko.com>2018-07-13 15:00:38 -0400
committerMatt Porter <mporter@konsulko.com>2018-07-25 19:20:05 -0400
commit1cc398602a32f2a5a816efe643ff2fe35b1cd42f (patch)
treee8e258f9187876e4da40c8024be36115252e7a96 /network/wifinetworkmodel.h
parent7427e664e232ed59bdffa37c63435a19febee778 (diff)
network: add wifinetworkmodel
Add WifiNetworkModel which exposes a QAbstractListModel of WiFi networks to QML. Bug-AGL: SPEC-1541 Change-Id: I1f4d41f1d1ceaa9b06a4b3df8b0b1cf41ea97ed2 Signed-off-by: Matt Porter <mporter@konsulko.com>
Diffstat (limited to 'network/wifinetworkmodel.h')
-rw-r--r--network/wifinetworkmodel.h68
1 files changed, 68 insertions, 0 deletions
diff --git a/network/wifinetworkmodel.h b/network/wifinetworkmodel.h
new file mode 100644
index 0000000..27e635a
--- /dev/null
+++ b/network/wifinetworkmodel.h
@@ -0,0 +1,68 @@
+#ifndef WIFI_NETWORK_MODEL_H
+#define WIFI_NETWORK_MODEL_H
+
+#include <QAbstractListModel>
+#include <QStringList>
+#include <QtQml/QQmlContext>
+#include <QJsonObject>
+
+class WifiNetwork
+{
+ public:
+ WifiNetwork(const QString &address,
+ const QString &security,
+ const QString &service,
+ const QString &ssid,
+ const QString &state,
+ const int &strength);
+ QString address() const;
+ QString service() const;
+ QString ssid() const;
+ QString security() const;
+ QString state() const;
+ int strength() const;
+ void setAddress(const QString address);
+ void setState(const QString state);
+ void setStrength(const int strength);
+
+ private:
+ QString m_address;
+ QString m_security;
+ QString m_service;
+ QString m_ssid;
+ QString m_state;
+ int m_strength;
+};
+
+class WifiNetworkModel : public QAbstractListModel
+{
+ Q_OBJECT
+
+ public:
+ enum WifiNetworkRoles {
+ AddressRole = Qt::UserRole + 1,
+ SecurityRole,
+ ServiceRole,
+ SsidRole,
+ StateRole,
+ StrengthRole
+ };
+
+ WifiNetworkModel(QObject *parent = Q_NULLPTR);
+
+ void addNetwork(WifiNetwork *network);
+ void removeNetwork(WifiNetwork *network);
+ void removeAllNetworks();
+ WifiNetwork *getNetwork(QString service);
+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+ void updateProperties(QString service, QJsonObject properties);
+
+ protected:
+ QHash<int, QByteArray> roleNames() const;
+
+ private:
+ QList<WifiNetwork *> m_networks;
+ QModelIndex indexOf(WifiNetwork *network);
+};
+#endif // WIFI_NETWORK_MODEL_H