summaryrefslogtreecommitdiffstats
path: root/src/networksettings
diff options
context:
space:
mode:
Diffstat (limited to 'src/networksettings')
-rw-r--r--src/networksettings/connman/qnetworksettingsmanager_p.cpp55
-rw-r--r--src/networksettings/connman/qnetworksettingsmanager_p.h10
-rw-r--r--src/networksettings/connman/qnetworksettingsservice_p.cpp10
-rw-r--r--src/networksettings/connman/qnetworksettingsuseragent_p.cpp62
-rw-r--r--src/networksettings/connman/qnetworksettingsuseragent_p.h3
-rw-r--r--src/networksettings/qnetworksettingsmanager.cpp52
-rw-r--r--src/networksettings/qnetworksettingsmanager.h9
-rw-r--r--src/networksettings/qnetworksettingsservice.cpp6
-rw-r--r--src/networksettings/qnetworksettingsservice.h4
-rw-r--r--src/networksettings/qnetworksettingsservicemodel.cpp12
-rw-r--r--src/networksettings/qnetworksettingsservicemodel.h1
-rw-r--r--src/networksettings/qnetworksettingsuseragent.cpp12
-rw-r--r--src/networksettings/qnetworksettingsuseragent.h3
13 files changed, 222 insertions, 17 deletions
diff --git a/src/networksettings/connman/qnetworksettingsmanager_p.cpp b/src/networksettings/connman/qnetworksettingsmanager_p.cpp
index b3373ee..ea9e682 100644
--- a/src/networksettings/connman/qnetworksettingsmanager_p.cpp
+++ b/src/networksettings/connman/qnetworksettingsmanager_p.cpp
@@ -44,6 +44,7 @@ QNetworkSettingsManagerPrivate::QNetworkSettingsManagerPrivate(QNetworkSettingsM
, m_serviceFilter(Q_NULLPTR)
, m_manager(Q_NULLPTR)
, m_agent(Q_NULLPTR)
+ , m_currentWifiConnection(Q_NULLPTR)
{
qDBusRegisterMetaType<ConnmanMapStruct>();
qDBusRegisterMetaType<ConnmanMapStructList>();
@@ -86,6 +87,40 @@ void QNetworkSettingsManagerPrivate::requestInput(const QString& service, const
emit m_agent->showUserCredentialsInput();
}
+void QNetworkSettingsManagerPrivate::connectBySsid(const QString &name)
+{
+ m_unnamedServicesForSsidConnection = m_unnamedServices;
+ tryNextConnection();
+ m_currentSsid = name;
+}
+
+void QNetworkSettingsManagerPrivate::clearConnectionState()
+{
+ m_unnamedServicesForSsidConnection.clear();
+ m_currentSsid.clear();
+}
+
+void QNetworkSettingsManagerPrivate::tryNextConnection()
+{
+ Q_Q(QNetworkSettingsManager);
+ QNetworkSettingsService* service = nullptr;
+ if (!m_currentSsid.isEmpty()) {
+ service = m_serviceModel->getByName(m_currentSsid);
+ m_currentSsid.clear();
+ }
+ if (!service) {
+ if (!m_unnamedServicesForSsidConnection.isEmpty()) {
+ service = *m_unnamedServicesForSsidConnection.begin();
+ m_unnamedServicesForSsidConnection.erase(m_unnamedServicesForSsidConnection.begin());
+ } else {
+ q->clearConnectionState();
+ }
+ }
+ if (service) {
+ service->doConnectService();
+ }
+}
+
void QNetworkSettingsManagerPrivate::getServicesFinished(QDBusPendingCallWatcher *watcher)
{
Q_Q(QNetworkSettingsManager);
@@ -129,6 +164,11 @@ void QNetworkSettingsManagerPrivate::onServicesChanged(ConnmanMapStructList chan
{
foreach (QDBusObjectPath path, removed) {
m_serviceModel->removeService(path.path());
+ auto serviceIter = m_unnamedServices.find(path.path());
+ if (serviceIter != m_unnamedServices.end()) {
+ serviceIter.value()->deleteLater();
+ m_unnamedServices.erase(serviceIter);
+ }
}
QStringList newServices;
@@ -155,6 +195,14 @@ void QNetworkSettingsManagerPrivate::handleNewService(const QString &servicePath
QNetworkSettingsService *service = new QNetworkSettingsService(servicePath, this);
+ connect(service, &QNetworkSettingsService::connectionStateCleared,
+ q, &QNetworkSettingsManager::clearConnectionState);
+
+ connect(service, &QNetworkSettingsService::serviceConnected,
+ q, &QNetworkSettingsManager::setCurrentWifiConnection);
+ connect(service, &QNetworkSettingsService::serviceDisconnected,
+ q, &QNetworkSettingsManager::clearCurrentWifiConnection);
+
if (service->name().length() > 0 && service->type() != QNetworkSettingsType::Unknown) {
m_serviceModel->append(service);
emit q->servicesChanged();
@@ -179,8 +227,15 @@ void QNetworkSettingsManagerPrivate::serviceReady()
Q_Q(QNetworkSettingsManager);
QNetworkSettingsService* service = qobject_cast<QNetworkSettingsService*>(sender());
+
+ if (service->type() != QNetworkSettingsType::Unknown
+ && service->type() == QNetworkSettingsType::Wifi) {
+ m_unnamedServices.insert(service->id(), service);
+ }
+
if (service->name().length() > 0 && service->type() != QNetworkSettingsType::Unknown) {
service->disconnect(this);
+ m_unnamedServices.remove(service->id());
m_serviceModel->append(service);
emit q->servicesChanged();
if (service->type() == QNetworkSettingsType::Wired) {
diff --git a/src/networksettings/connman/qnetworksettingsmanager_p.h b/src/networksettings/connman/qnetworksettingsmanager_p.h
index 579d857..cfc2e64 100644
--- a/src/networksettings/connman/qnetworksettingsmanager_p.h
+++ b/src/networksettings/connman/qnetworksettingsmanager_p.h
@@ -42,6 +42,7 @@
#include <QObject>
#include <QtDBus>
+#include <QMap>
#include "connmancommon.h"
#include "qnetworksettingsmanager.h"
#include "qnetworksettingsinterfacemodel.h"
@@ -66,6 +67,11 @@ public:
QNetworkSettingsInterfaceModel* interfaceModel() {return &m_interfaceModel;}
QNetworkSettingsServiceModel* serviceModel() const {return m_serviceModel;}
QNetworkSettingsServiceFilter* serviceFilter() const {return m_serviceFilter;}
+ void connectBySsid(const QString &name);
+ void clearConnectionState();
+ void tryNextConnection();
+ void setCurrentWifiConnection(QNetworkSettingsService *connection) {m_currentWifiConnection = connection;}
+ QNetworkSettingsService* currentWifiConnection() const {return m_currentWifiConnection;}
public slots:
void getServicesFinished(QDBusPendingCallWatcher *watcher);
@@ -78,10 +84,14 @@ private:
protected:
QNetworkSettingsInterfaceModel m_interfaceModel;
QNetworkSettingsServiceModel *m_serviceModel;
+ QMap<QString, QNetworkSettingsService*> m_unnamedServices;
+ QMap<QString, QNetworkSettingsService*> m_unnamedServicesForSsidConnection;
QNetworkSettingsServiceFilter *m_serviceFilter;
private:
NetConnmanManagerInterface *m_manager;
QNetworkSettingsUserAgent *m_agent;
+ QString m_currentSsid;
+ QNetworkSettingsService *m_currentWifiConnection;
};
QT_END_NAMESPACE
diff --git a/src/networksettings/connman/qnetworksettingsservice_p.cpp b/src/networksettings/connman/qnetworksettingsservice_p.cpp
index 3912ec2..65653aa 100644
--- a/src/networksettings/connman/qnetworksettingsservice_p.cpp
+++ b/src/networksettings/connman/qnetworksettingsservice_p.cpp
@@ -396,8 +396,14 @@ void QNetworkSettingsServicePrivate::updateProperty(const QString& key, const QV
}
else if (key == PropertyState) {
QString value = qdbus_cast<QString>(val);
+ QNetworkSettingsState oldState;
+ oldState.setState(m_state.state());
value >> m_state;
emit q->stateChanged();
+ if (m_state.state() == QNetworkSettingsState::Ready && m_type.type() == QNetworkSettingsType::Wifi)
+ emit q->serviceConnected(q);
+ if (m_state.state() == QNetworkSettingsState::Disconnect && m_type.type() == QNetworkSettingsType::Wifi)
+ emit q->serviceDisconnected(q);
}
else if (key == PropertyName) {
m_name = qdbus_cast<QString>(val);
@@ -407,6 +413,10 @@ void QNetworkSettingsServicePrivate::updateProperty(const QString& key, const QV
QString value = qdbus_cast<QString>(val);
value >> m_type;
emit q->typeChanged();
+ if (m_state.state() == QNetworkSettingsState::Ready && m_type.type() == QNetworkSettingsType::Wifi)
+ emit q->serviceConnected(q);
+ if (m_state.state() == QNetworkSettingsState::Disconnect && m_type.type() == QNetworkSettingsType::Wifi)
+ emit q->serviceDisconnected(q);
}
else if (key == PropertyStrength) {
m_wifiConfig.setSignalStrength(val.toInt());
diff --git a/src/networksettings/connman/qnetworksettingsuseragent_p.cpp b/src/networksettings/connman/qnetworksettingsuseragent_p.cpp
index e9e8063..5052b74 100644
--- a/src/networksettings/connman/qnetworksettingsuseragent_p.cpp
+++ b/src/networksettings/connman/qnetworksettingsuseragent_p.cpp
@@ -67,7 +67,10 @@ void QNetworkSettingsUserAgentPrivate::ReportError(const QDBusObjectPath &path,
Q_Q(QNetworkSettingsUserAgent);
Q_UNUSED(path);
Q_UNUSED(param);
- emit q->error();
+ if (!m_ssid.isEmpty())
+ q->requestNextConnection();
+ else
+ emit q->error();
}
void QNetworkSettingsUserAgentPrivate::registerAgent()
@@ -80,28 +83,55 @@ QVariantMap QNetworkSettingsUserAgentPrivate::RequestInput(const QDBusObjectPath
{
Q_Q(QNetworkSettingsUserAgent);
Q_UNUSED(path);
- Q_UNUSED(params);
- msg.setDelayedReply(true);
-
- m_pendingReply = true;
- m_pendingMessage = msg;
- emit q->showUserCredentialsInput();
- return QVariantMap();
+ QVariant name = params[PropertyName];
+ if (!name.isValid()) {
+ m_ssid.clear();
+ }
+ QVariantMap response;
+ QVariant passPhrase = params[PropertyPassphrase];
+ if (name.isValid() && !m_ssid.isEmpty()) {
+ response[PropertyName] = m_ssid;
+ }
+ if (passPhrase.isValid()) {
+ if (!m_passphrase.isEmpty()) {
+ response[PropertyPassphrase] = m_passphrase;
+ } else {
+ msg.setDelayedReply(true);
+ m_pendingMessage = msg;
+ m_pendingReply = true;
+ emit q->showUserCredentialsInput();
+ return QVariantMap();
+ }
+ }
+ return response;
}
void QNetworkSettingsUserAgentPrivate::setPassphrase(const QString& passphrase)
{
m_passphrase = passphrase;
- if (!m_pendingReply)
- return;
+ if (m_pendingReply) {
+ QVariantMap response;
+ if (!m_ssid.isEmpty()) {
+ response[PropertyName] = m_ssid;
+ }
+ response[PropertyPassphrase] = m_passphrase;
+ QDBusMessage reply = m_pendingMessage.createReply();
+ reply << response;
+ m_pendingReply = false;
+ QDBusConnection::systemBus().send(reply);
+ }
+}
- QVariantMap response;
- response[PropertyPassphrase] = m_passphrase;
+void QNetworkSettingsUserAgentPrivate::setSsidAndPassphrase(const QString &ssid, const QString &passphrase)
+{
+ m_ssid = ssid;
+ m_passphrase = passphrase;
+}
- QDBusMessage reply = m_pendingMessage.createReply();
- reply << response;
- m_pendingReply = false;
- QDBusConnection::systemBus().send(reply);
+void QNetworkSettingsUserAgentPrivate::clearConnectionState()
+{
+ m_passphrase.clear();
+ m_ssid.clear();
}
QT_END_NAMESPACE
diff --git a/src/networksettings/connman/qnetworksettingsuseragent_p.h b/src/networksettings/connman/qnetworksettingsuseragent_p.h
index 180eea5..31170d3 100644
--- a/src/networksettings/connman/qnetworksettingsuseragent_p.h
+++ b/src/networksettings/connman/qnetworksettingsuseragent_p.h
@@ -65,6 +65,8 @@ public:
QString passphrase() const {return m_passphrase;}
void cancel();
void release();
+ void setSsidAndPassphrase(const QString &ssid, const QString &passphrase);
+ void clearConnectionState();
public Q_SLOTS: // Dbus methods
void ReportError(const QDBusObjectPath &path, const QString &param);
QVariantMap RequestInput(const QDBusObjectPath &path, const QVariantMap &params,
@@ -75,6 +77,7 @@ private:
QDBusMessage m_pendingMessage;
bool m_pendingReply;
QString m_passphrase;
+ QString m_ssid;
};
QT_END_NAMESPACE
diff --git a/src/networksettings/qnetworksettingsmanager.cpp b/src/networksettings/qnetworksettingsmanager.cpp
index 71aa081..cda66e7 100644
--- a/src/networksettings/qnetworksettingsmanager.cpp
+++ b/src/networksettings/qnetworksettingsmanager.cpp
@@ -32,6 +32,7 @@
#include "qnetworksettingsinterface.h"
#include "qnetworksettingsinterfacemodel.h"
#include "qnetworksettingsmanager_p.h"
+#include "qnetworksettingsuseragent.h"
#include <QStringListModel>
QT_BEGIN_NAMESPACE
@@ -66,6 +67,55 @@ QNetworkSettingsService* QNetworkSettingsManager::service(const QString& name, i
return nullptr;
}
+void QNetworkSettingsManager::connectBySsid(const QString &name, const QString &passphrase)
+{
+ Q_D(QNetworkSettingsManager);
+ QNetworkSettingsUserAgent* agent = userAgent();
+ if (agent)
+ agent->setSsidAndPassphrase(name, passphrase);
+ d->connectBySsid(name);
+}
+
+void QNetworkSettingsManager::clearConnectionState()
+{
+ Q_D(QNetworkSettingsManager);
+ d->clearConnectionState();
+ QNetworkSettingsUserAgent* agent = userAgent();
+ if (agent)
+ agent->clearConnectionState();
+}
+
+void QNetworkSettingsManager::tryNextConnection()
+{
+ Q_D(QNetworkSettingsManager);
+ d->tryNextConnection();
+}
+
+void QNetworkSettingsManager::clearCurrentWifiConnection(QNetworkSettingsService* service)
+{
+ Q_D(QNetworkSettingsManager);
+ QNetworkSettingsService *currentService = d->currentWifiConnection();
+ if (service == currentService) {
+ d->setCurrentWifiConnection(nullptr);
+ emit currentWifiConnectionChanged();
+ }
+}
+
+void QNetworkSettingsManager::setCurrentWifiConnection(QNetworkSettingsService* service)
+{
+ Q_D(QNetworkSettingsManager);
+ QNetworkSettingsService *currentService = d->currentWifiConnection();
+ d->setCurrentWifiConnection(service);
+ if (service != currentService)
+ emit currentWifiConnectionChanged();
+}
+
+QNetworkSettingsService* QNetworkSettingsManager::currentWifiConnection()
+{
+ Q_D(QNetworkSettingsManager);
+ return d->currentWifiConnection();
+}
+
QNetworkSettingsInterface* QNetworkSettingsManager::interface(int type, int instance)
{
Q_D(QNetworkSettingsManager);
@@ -86,6 +136,8 @@ void QNetworkSettingsManager::setUserAgent(QNetworkSettingsUserAgent *agent)
{
Q_D(QNetworkSettingsManager);
d->setUserAgent(agent);
+ connect(agent, &QNetworkSettingsUserAgent::requestNextConnection,
+ this, &QNetworkSettingsManager::tryNextConnection);
}
QNetworkSettingsUserAgent* QNetworkSettingsManager::userAgent()
diff --git a/src/networksettings/qnetworksettingsmanager.h b/src/networksettings/qnetworksettingsmanager.h
index 3ce5095..103bc77 100644
--- a/src/networksettings/qnetworksettingsmanager.h
+++ b/src/networksettings/qnetworksettingsmanager.h
@@ -50,6 +50,7 @@ class Q_DECL_EXPORT QNetworkSettingsManager : public QObject
Q_PROPERTY(QNetworkSettingsServiceFilter* services READ services NOTIFY servicesChanged)
Q_PROPERTY(QNetworkSettingsInterfaceModel* interfaces READ interfaces NOTIFY interfacesChanged)
Q_PROPERTY(QNetworkSettingsUserAgent* userAgent READ userAgent CONSTANT)
+ Q_PROPERTY(QNetworkSettingsService* currentWifiConnection READ currentWifiConnection NOTIFY currentWifiConnectionChanged)
public:
explicit QNetworkSettingsManager(QObject* parent = Q_NULLPTR);
@@ -59,12 +60,18 @@ public:
QNetworkSettingsUserAgent* userAgent();
Q_INVOKABLE QNetworkSettingsService* service(const QString& name, int type);
+ Q_INVOKABLE void connectBySsid(const QString& name, const QString &passphrase);
+ void clearConnectionState();
+ void tryNextConnection();
+ void clearCurrentWifiConnection(QNetworkSettingsService* service);
+ void setCurrentWifiConnection(QNetworkSettingsService* service);
+ QNetworkSettingsService* currentWifiConnection();
Q_INVOKABLE QNetworkSettingsInterface* interface(int type, int instance);
Q_SIGNALS:
void servicesChanged();
void interfacesChanged();
-
+ void currentWifiConnectionChanged();
protected:
QNetworkSettingsManagerPrivate *d_ptr;
diff --git a/src/networksettings/qnetworksettingsservice.cpp b/src/networksettings/qnetworksettingsservice.cpp
index 0c142b2..d3ea020 100644
--- a/src/networksettings/qnetworksettingsservice.cpp
+++ b/src/networksettings/qnetworksettingsservice.cpp
@@ -322,6 +322,12 @@ void QNetworkSettingsService::setupNetworkSettingsProxy()
*/
void QNetworkSettingsService::connectService()
{
+ emit connectionStateCleared();
+ doConnectService();
+}
+
+void QNetworkSettingsService::doConnectService()
+{
Q_D(QNetworkSettingsService);
d->connectService();
}
diff --git a/src/networksettings/qnetworksettingsservice.h b/src/networksettings/qnetworksettingsservice.h
index 4f3ad00..6f5a87e 100644
--- a/src/networksettings/qnetworksettingsservice.h
+++ b/src/networksettings/qnetworksettingsservice.h
@@ -74,6 +74,7 @@ public:
Q_INVOKABLE void setupNetworkSettingsProxy();
//Wireless config
Q_INVOKABLE void connectService();
+ void doConnectService();
Q_INVOKABLE void disconnectService();
Q_INVOKABLE void removeService();
Q_SIGNALS:
@@ -86,6 +87,9 @@ Q_SIGNALS:
void domainsChanged();
void nameserversChanged();
void wirelessChanged();
+ void connectionStateCleared();
+ void serviceConnected(QNetworkSettingsService* service);
+ void serviceDisconnected(QNetworkSettingsService* service);
protected:
QNetworkSettingsServicePrivate *d_ptr;
diff --git a/src/networksettings/qnetworksettingsservicemodel.cpp b/src/networksettings/qnetworksettingsservicemodel.cpp
index 3040dab..0fe3f47 100644
--- a/src/networksettings/qnetworksettingsservicemodel.cpp
+++ b/src/networksettings/qnetworksettingsservicemodel.cpp
@@ -162,6 +162,18 @@ void QNetworkSettingsServiceModel::updated(int row)
dataChanged(createIndex(row, 0), createIndex(row, 0));
}
+QNetworkSettingsService* QNetworkSettingsServiceModel::getByName(const QString& name)
+{
+ QNetworkSettingsService* ret = nullptr;
+ foreach (QNetworkSettingsService* item, m_items) {
+ if (item->name() == name) {
+ ret = item;
+ break;
+ }
+ }
+ return ret;
+}
+
QList<QNetworkSettingsService*> QNetworkSettingsServiceModel::getModel()
{
return m_items;
diff --git a/src/networksettings/qnetworksettingsservicemodel.h b/src/networksettings/qnetworksettingsservicemodel.h
index 91f3b6d..8c34e89 100644
--- a/src/networksettings/qnetworksettingsservicemodel.h
+++ b/src/networksettings/qnetworksettingsservicemodel.h
@@ -52,6 +52,7 @@ public:
void remove(int row);
bool removeService(const QString &id);
void updated(int row);
+ QNetworkSettingsService* getByName(const QString& name);
QList<QNetworkSettingsService*> getModel();
enum Roles {
diff --git a/src/networksettings/qnetworksettingsuseragent.cpp b/src/networksettings/qnetworksettingsuseragent.cpp
index 8740cf4..cdf1e45 100644
--- a/src/networksettings/qnetworksettingsuseragent.cpp
+++ b/src/networksettings/qnetworksettingsuseragent.cpp
@@ -55,4 +55,16 @@ QString QNetworkSettingsUserAgent::passphrase() const
return d->passphrase();
}
+void QNetworkSettingsUserAgent::setSsidAndPassphrase(const QString &ssid, const QString &passphrase)
+{
+ Q_D(QNetworkSettingsUserAgent);
+ d->setSsidAndPassphrase(ssid, passphrase);
+}
+
+void QNetworkSettingsUserAgent::clearConnectionState()
+{
+ Q_D(QNetworkSettingsUserAgent);
+ d->clearConnectionState();
+}
+
QT_END_NAMESPACE
diff --git a/src/networksettings/qnetworksettingsuseragent.h b/src/networksettings/qnetworksettingsuseragent.h
index 2f6cf12..7b76c15 100644
--- a/src/networksettings/qnetworksettingsuseragent.h
+++ b/src/networksettings/qnetworksettingsuseragent.h
@@ -43,11 +43,14 @@ public:
Q_INVOKABLE void setPassphrase(const QString &passphrase);
Q_INVOKABLE void cancelInput();
QString passphrase() const;
+ void setSsidAndPassphrase(const QString &ssid, const QString &passphrase);
+ void clearConnectionState();
Q_SIGNALS:
void showUserCredentialsInput();
void error();
void ready(bool cancel);
+ void requestNextConnection();
private:
QNetworkSettingsUserAgentPrivate *d_ptr;