summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--network/abstractnetworkmodel.cpp56
-rw-r--r--network/abstractnetworkmodel.h32
-rw-r--r--network/connectionprofile.cpp57
-rw-r--r--network/connectionprofile.h34
4 files changed, 179 insertions, 0 deletions
diff --git a/network/abstractnetworkmodel.cpp b/network/abstractnetworkmodel.cpp
new file mode 100644
index 0000000..6eada6a
--- /dev/null
+++ b/network/abstractnetworkmodel.cpp
@@ -0,0 +1,56 @@
+#include "abstractnetworkmodel.h"
+#include "connectionprofile.h"
+#include <QDebug>
+
+
+AbstractNetworkModel::AbstractNetworkModel(QObject *parent)
+ : QAbstractListModel(parent)
+{
+}
+
+void AbstractNetworkModel::addNetwork(ConnectionProfile *network)
+{
+ beginInsertRows(QModelIndex(), rowCount(), rowCount());
+ m_networks << network;
+ endInsertRows();
+}
+
+void AbstractNetworkModel::removeNetwork(ConnectionProfile *network)
+{
+ int row = m_networks.indexOf(network);
+ beginRemoveRows(QModelIndex(), row, row);
+ m_networks.removeAt(row);
+ endRemoveRows();
+ delete network;
+}
+
+void AbstractNetworkModel::removeAllNetworks()
+{
+ beginRemoveRows(QModelIndex(), 0, m_networks.count() - 1);
+ qDeleteAll(m_networks.begin(), m_networks.end());
+ m_networks.clear();
+ endRemoveRows();
+}
+
+ConnectionProfile *AbstractNetworkModel::getNetwork(QString service)
+{
+ for (auto network : m_networks) {
+ if (network->service() == service)
+ return network;
+ }
+
+ return nullptr;
+}
+
+int AbstractNetworkModel::rowCount(const QModelIndex &parent) const
+{
+ Q_UNUSED(parent);
+ return m_networks.count();
+}
+
+QModelIndex AbstractNetworkModel::indexOf(ConnectionProfile *network)
+{
+ int row = m_networks.indexOf(network);
+
+ return index(row);
+}
diff --git a/network/abstractnetworkmodel.h b/network/abstractnetworkmodel.h
new file mode 100644
index 0000000..1b0db43
--- /dev/null
+++ b/network/abstractnetworkmodel.h
@@ -0,0 +1,32 @@
+#ifndef ABSTRACT_NETWORK_MODEL_H
+#define ABSTRACT_NETWORK_MODEL_H
+
+#include <QAbstractListModel>
+#include <QStringList>
+#include <QtQml/QQmlContext>
+#include <QJsonObject>
+
+#include "connectionprofile.h"
+
+class AbstractNetworkModel : public QAbstractListModel
+{
+ Q_OBJECT
+
+ public:
+ AbstractNetworkModel(QObject *parent = Q_NULLPTR);
+ virtual QString getType() const = 0;
+
+ void addNetwork(ConnectionProfile *network);
+ void removeNetwork(ConnectionProfile *network);
+ void removeAllNetworks();
+ ConnectionProfile *getNetwork(QString service);
+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
+
+ virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const = 0;
+ virtual void updateProperties(QString service, QJsonObject properties) =0;
+
+ protected:
+ QList<ConnectionProfile *> m_networks;
+ QModelIndex indexOf(ConnectionProfile *network);
+};
+#endif // ABSTRACT_NETWORK_MODEL_H
diff --git a/network/connectionprofile.cpp b/network/connectionprofile.cpp
new file mode 100644
index 0000000..8e30e47
--- /dev/null
+++ b/network/connectionprofile.cpp
@@ -0,0 +1,57 @@
+#include "connectionprofile.h"
+
+ConnectionProfile::ConnectionProfile(const QString &address,
+ const QString &security,
+ const QString &service,
+ const QString &state,
+ const QString &ssid,
+ const int &strength)
+ : m_address(address), m_security(security), m_service(service),
+ m_state(state), m_ssid(ssid), m_strength(strength)
+{
+}
+
+QString ConnectionProfile::address() const
+{
+ return m_address;
+}
+
+QString ConnectionProfile::security() const
+{
+ return m_security;
+}
+
+QString ConnectionProfile::service() const
+{
+ return m_service;
+}
+
+QString ConnectionProfile::state() const
+{
+ return m_state;
+}
+
+QString ConnectionProfile::ssid() const
+{
+ return m_ssid;
+}
+
+int ConnectionProfile::strength() const
+{
+ return m_strength;
+}
+
+void ConnectionProfile::setAddress(const QString address)
+{
+ m_address = address;
+}
+
+void ConnectionProfile::setState(const QString state)
+{
+ m_state = state;
+}
+
+void ConnectionProfile::setStrength(const int strength)
+{
+ m_strength = strength;
+}
diff --git a/network/connectionprofile.h b/network/connectionprofile.h
new file mode 100644
index 0000000..1f5bafa
--- /dev/null
+++ b/network/connectionprofile.h
@@ -0,0 +1,34 @@
+#ifndef CONNECTION_PROFILE_H
+#define CONNECTION_PROFILE_H
+
+#include <QString>
+
+class ConnectionProfile
+{
+ public:
+ ConnectionProfile(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_state;
+ QString m_ssid;
+ int m_strength;
+};
+
+#endif // CONNECTION_PROFILE_H
'n391' href='#n391'>391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442