Trying to fix daemon not detecting connection to phone via usb tethering

Probably it was not detecting connections to a wired interface either,
this should do the trick but it's a bit weird having to connect to
QNetworkConfigurationManager::configurationAdded() to know about that.
This commit is contained in:
Albert Vaca 2014-08-11 18:55:38 +02:00
parent a3b89da9c7
commit dfbe7c7bfc

View file

@ -27,6 +27,7 @@
#include <QNetworkSession>
#include <QNetworkConfigurationManager>
#include <QtCrypto>
#include <QNetworkAccessManager>
#include <KConfig>
#include <KConfigGroup>
@ -117,6 +118,9 @@ Daemon::Daemon(QObject *parent)
kWarning(debugArea()) << "Error: KDE Connect detects wrong permissions for private file " << config->group("myself").readEntry("privateKeyPath");
}
//Register on DBus
QDBusConnection::sessionBus().registerService("org.kde.kdeconnect");
QDBusConnection::sessionBus().registerObject("/modules/kdeconnect", this, QDBusConnection::ExportScriptableContents);
//Load backends (hardcoded by now, should be plugins in a future)
d->mLinkProviders.insert(new LanLinkProvider());
@ -133,20 +137,23 @@ Daemon::Daemon(QObject *parent)
Q_EMIT deviceAdded(id);
}
//Listen to connectivity changes
QNetworkSession* network = new QNetworkSession(QNetworkConfigurationManager().defaultConfiguration());
//Listen to new devices
Q_FOREACH (LinkProvider* a, d->mLinkProviders) {
connect(network, SIGNAL(stateChanged(QNetworkSession::State)),
a, SLOT(onNetworkChange(QNetworkSession::State)));
connect(a, SIGNAL(onConnectionReceived(NetworkPackage, DeviceLink*)),
this, SLOT(onNewDeviceLink(NetworkPackage, DeviceLink*)));
}
QDBusConnection::sessionBus().registerService("org.kde.kdeconnect");
QDBusConnection::sessionBus().registerObject("/modules/kdeconnect", this, QDBusConnection::ExportScriptableContents);
setDiscoveryEnabled(true);
//Listen to connectivity changes
QNetworkConfigurationManager* manager = new QNetworkConfigurationManager();
QNetworkSession* network = new QNetworkSession(manager->defaultConfiguration());
connect(manager, SIGNAL(configurationAdded(QNetworkConfiguration)),
this, SLOT(forceOnNetworkChange()));
Q_FOREACH (LinkProvider* a, d->mLinkProviders) {
connect(network, SIGNAL(stateChanged(QNetworkSession::State)),
a, SLOT(onNetworkChange(QNetworkSession::State)));
}
kDebug(debugArea()) << "KdeConnect daemon started";
}