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 <QNetworkSession>
#include <QNetworkConfigurationManager> #include <QNetworkConfigurationManager>
#include <QtCrypto> #include <QtCrypto>
#include <QNetworkAccessManager>
#include <KConfig> #include <KConfig>
#include <KConfigGroup> #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"); 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) //Load backends (hardcoded by now, should be plugins in a future)
d->mLinkProviders.insert(new LanLinkProvider()); d->mLinkProviders.insert(new LanLinkProvider());
@ -132,21 +136,24 @@ Daemon::Daemon(QObject *parent)
d->mDevices[id] = device; d->mDevices[id] = device;
Q_EMIT deviceAdded(id); Q_EMIT deviceAdded(id);
} }
//Listen to connectivity changes //Listen to new devices
QNetworkSession* network = new QNetworkSession(QNetworkConfigurationManager().defaultConfiguration());
Q_FOREACH (LinkProvider* a, d->mLinkProviders) { Q_FOREACH (LinkProvider* a, d->mLinkProviders) {
connect(network, SIGNAL(stateChanged(QNetworkSession::State)),
a, SLOT(onNetworkChange(QNetworkSession::State)));
connect(a, SIGNAL(onConnectionReceived(NetworkPackage, DeviceLink*)), connect(a, SIGNAL(onConnectionReceived(NetworkPackage, DeviceLink*)),
this, SLOT(onNewDeviceLink(NetworkPackage, DeviceLink*))); this, SLOT(onNewDeviceLink(NetworkPackage, DeviceLink*)));
} }
QDBusConnection::sessionBus().registerService("org.kde.kdeconnect");
QDBusConnection::sessionBus().registerObject("/modules/kdeconnect", this, QDBusConnection::ExportScriptableContents);
setDiscoveryEnabled(true); 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"; kDebug(debugArea()) << "KdeConnect daemon started";
} }