Injecting disabled status from the very start

This commit is contained in:
Rob Emery 2024-10-07 22:07:11 +01:00 committed by Carl Schwan
parent 9800664360
commit fd07c7bea6
No known key found for this signature in database
GPG key ID: 02325448204E452A
5 changed files with 23 additions and 16 deletions

View file

@ -13,11 +13,12 @@
#include <QBluetoothServiceInfo>
BluetoothLinkProvider::BluetoothLinkProvider()
BluetoothLinkProvider::BluetoothLinkProvider(bool isDisabled)
: mServiceUuid(QBluetoothUuid(QStringLiteral("185f3df4-3268-4e3f-9fca-d4d5059915bd")))
, mServiceDiscoveryAgent(new QBluetoothServiceDiscoveryAgent(this))
, connectTimer(new QTimer(this))
{
this->disabled = isDisabled;
connectTimer->setInterval(30000);
connectTimer->setSingleShot(false);
@ -32,7 +33,7 @@ BluetoothLinkProvider::BluetoothLinkProvider()
void BluetoothLinkProvider::onStart()
{
qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider::onStart executed";
if (enabled) {
if (!disabled) {
tryToInitialise();
}
}
@ -59,7 +60,7 @@ void BluetoothLinkProvider::tryToInitialise()
void BluetoothLinkProvider::onStop()
{
if (enabled) {
if (!disabled) {
qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider::onStop executed";
if (!mBluetoothServer) {
return;
@ -75,16 +76,16 @@ void BluetoothLinkProvider::onStop()
void BluetoothLinkProvider::enable()
{
if (enabled == false) {
enabled = true;
if (disabled) {
disabled = false;
tryToInitialise();
}
}
void BluetoothLinkProvider::disable()
{
if (enabled == true) {
enabled = false;
if (!disabled) {
disabled = true;
this->onStop();
mBluetoothServer = nullptr;
@ -95,7 +96,7 @@ void BluetoothLinkProvider::disable()
void BluetoothLinkProvider::onNetworkChange()
{
qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider::onNetworkChange executed";
if (enabled) {
if (!disabled) {
tryToInitialise();
}
}

View file

@ -29,7 +29,8 @@ class KDECONNECTCORE_EXPORT BluetoothLinkProvider : public LinkProvider
Q_OBJECT
public:
BluetoothLinkProvider();
BluetoothLinkProvider(bool disabled = false);
virtual ~BluetoothLinkProvider();
QString name() override
@ -73,7 +74,7 @@ private:
QBluetoothServiceInfo mKdeconnectService;
QBluetoothServiceDiscoveryAgent *mServiceDiscoveryAgent;
QTimer *connectTimer;
bool enabled;
bool disabled;
QMap<QString, DeviceLink *> mLinks;

View file

@ -42,7 +42,7 @@ static const int MAX_REMEMBERED_IDENTITY_PACKETS = 42;
static const long MILLIS_DELAY_BETWEEN_CONNECTIONS_TO_SAME_DEVICE = 500;
LanLinkProvider::LanLinkProvider(bool testMode)
LanLinkProvider::LanLinkProvider(bool testMode, bool isDisabled)
: m_server(new Server(this))
, m_udpSocket(this)
, m_tcpPort(0)
@ -52,6 +52,8 @@ LanLinkProvider::LanLinkProvider(bool testMode)
, m_mdnsDiscovery(this)
#endif
{
this->disabled = isDisabled;
m_combineNetworkChangeTimer.setInterval(0); // increase this if waiting a single event-loop iteration is not enough
m_combineNetworkChangeTimer.setSingleShot(true);
connect(&m_combineNetworkChangeTimer, &QTimer::timeout, this, &LanLinkProvider::combinedOnNetworkChange);

View file

@ -30,7 +30,7 @@ public:
/**
* @param testMode Some special overrides needed while testing
*/
LanLinkProvider(bool testMode = false);
LanLinkProvider(bool testMode = false, bool disabled = false);
~LanLinkProvider() override;
QString name() override

View file

@ -72,13 +72,16 @@ void Daemon::init()
qCDebug(KDECONNECT_CORE) << "DBus registration complete";
auto configInstance = KdeConnectConfig::instance();
auto status = configInstance.getLinkProviderStatus();
// Load backends
if (d->m_testMode)
if (d->m_testMode) {
d->m_linkProviders.insert(new LoopbackLinkProvider());
else {
d->m_linkProviders.insert(new LanLinkProvider());
} else {
d->m_linkProviders.insert(new LanLinkProvider(false, status[QStringLiteral("disabled")].contains(QStringLiteral("LanLinkProvider"))));
#ifdef KDECONNECT_BLUETOOTH
d->m_linkProviders.insert(new BluetoothLinkProvider());
d->m_linkProviders.insert(new BluetoothLinkProvider(status[QStringLiteral("disabled")].contains(QStringLiteral("BluetoothLinkProvider"))));
#endif
#ifdef KDECONNECT_LOOPBACK
d->m_linkProviders.insert(new LoopbackLinkProvider());