Refactoring

This commit is contained in:
Rob Emery 2024-10-09 16:25:50 +01:00 committed by Carl Schwan
parent e82d2e5e4a
commit e2e36e698c
No known key found for this signature in database
GPG key ID: 02325448204E452A
6 changed files with 28 additions and 26 deletions

View file

@ -18,7 +18,7 @@ BluetoothLinkProvider::BluetoothLinkProvider(bool isDisabled)
, mServiceDiscoveryAgent(new QBluetoothServiceDiscoveryAgent(this)) , mServiceDiscoveryAgent(new QBluetoothServiceDiscoveryAgent(this))
, connectTimer(new QTimer(this)) , connectTimer(new QTimer(this))
{ {
this->disabled = isDisabled; this->mDisabled = isDisabled;
connectTimer->setInterval(30000); connectTimer->setInterval(30000);
connectTimer->setSingleShot(false); connectTimer->setSingleShot(false);
@ -33,7 +33,7 @@ BluetoothLinkProvider::BluetoothLinkProvider(bool isDisabled)
void BluetoothLinkProvider::onStart() void BluetoothLinkProvider::onStart()
{ {
qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider::onStart executed"; qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider::onStart executed";
if (!disabled) { if (!mDisabled) {
tryToInitialise(); tryToInitialise();
} }
} }
@ -60,7 +60,7 @@ void BluetoothLinkProvider::tryToInitialise()
void BluetoothLinkProvider::onStop() void BluetoothLinkProvider::onStop()
{ {
if (!disabled) { if (!mDisabled) {
qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider::onStop executed"; qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider::onStop executed";
if (!mBluetoothServer) { if (!mBluetoothServer) {
return; return;
@ -76,17 +76,17 @@ void BluetoothLinkProvider::onStop()
void BluetoothLinkProvider::enable() void BluetoothLinkProvider::enable()
{ {
if (disabled) { if (mDisabled) {
disabled = false; mDisabled = false;
tryToInitialise(); tryToInitialise();
} }
} }
void BluetoothLinkProvider::disable() void BluetoothLinkProvider::disable()
{ {
if (!disabled) { if (!mDisabled) {
disabled = true; mDisabled = true;
this->onStop(); onStop();
mBluetoothServer = nullptr; mBluetoothServer = nullptr;
mServiceDiscoveryAgent = nullptr; mServiceDiscoveryAgent = nullptr;
@ -96,7 +96,7 @@ void BluetoothLinkProvider::disable()
void BluetoothLinkProvider::onNetworkChange() void BluetoothLinkProvider::onNetworkChange()
{ {
qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider::onNetworkChange executed"; qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider::onNetworkChange executed";
if (!disabled) { if (!mDisabled) {
tryToInitialise(); tryToInitialise();
} }
} }

View file

@ -74,7 +74,7 @@ private:
QBluetoothServiceInfo mKdeconnectService; QBluetoothServiceInfo mKdeconnectService;
QBluetoothServiceDiscoveryAgent *mServiceDiscoveryAgent; QBluetoothServiceDiscoveryAgent *mServiceDiscoveryAgent;
QTimer *connectTimer; QTimer *connectTimer;
bool disabled; bool mDisabled;
QMap<QString, DeviceLink *> mLinks; QMap<QString, DeviceLink *> mLinks;

View file

@ -52,7 +52,7 @@ LanLinkProvider::LanLinkProvider(bool testMode, bool isDisabled)
, m_mdnsDiscovery(this) , m_mdnsDiscovery(this)
#endif #endif
{ {
this->disabled = isDisabled; this->m_disabled = isDisabled;
m_combineNetworkChangeTimer.setInterval(0); // increase this if waiting a single event-loop iteration is not enough m_combineNetworkChangeTimer.setInterval(0); // increase this if waiting a single event-loop iteration is not enough
m_combineNetworkChangeTimer.setSingleShot(true); m_combineNetworkChangeTimer.setSingleShot(true);
@ -88,22 +88,22 @@ LanLinkProvider::~LanLinkProvider()
void LanLinkProvider::enable() void LanLinkProvider::enable()
{ {
if (disabled == true) { if (m_disabled == true) {
disabled = false; m_disabled = false;
this->onStart(); onStart();
} }
} }
void LanLinkProvider::disable() void LanLinkProvider::disable()
{ {
if (disabled == false) { if (m_disabled == false) {
this->onStop(); onStop();
disabled = true; m_disabled = true;
} }
} }
void LanLinkProvider::onStart() void LanLinkProvider::onStart()
{ {
if (disabled) { if (m_disabled) {
return; return;
} }
@ -139,7 +139,7 @@ void LanLinkProvider::onStart()
void LanLinkProvider::onStop() void LanLinkProvider::onStop()
{ {
if (disabled) { if (m_disabled) {
return; return;
} }
#ifdef KDECONNECT_MDNS #ifdef KDECONNECT_MDNS
@ -152,7 +152,7 @@ void LanLinkProvider::onStop()
void LanLinkProvider::onNetworkChange() void LanLinkProvider::onNetworkChange()
{ {
if (disabled) { if (m_disabled) {
return; return;
} }
if (m_combineNetworkChangeTimer.isActive()) { if (m_combineNetworkChangeTimer.isActive()) {
@ -165,7 +165,7 @@ void LanLinkProvider::onNetworkChange()
// I'm in a new network, let's be polite and introduce myself // I'm in a new network, let's be polite and introduce myself
void LanLinkProvider::combinedOnNetworkChange() void LanLinkProvider::combinedOnNetworkChange()
{ {
if (disabled) { if (m_disabled) {
return; return;
} }
if (!m_server->isListening()) { if (!m_server->isListening()) {

View file

@ -95,7 +95,7 @@ private:
const bool m_testMode; const bool m_testMode;
QTimer m_combineNetworkChangeTimer; QTimer m_combineNetworkChangeTimer;
bool disabled; bool m_disabled;
#ifdef KDECONNECT_MDNS #ifdef KDECONNECT_MDNS
MdnsDiscovery m_mdnsDiscovery; MdnsDiscovery m_mdnsDiscovery;

View file

@ -157,7 +157,7 @@ QStringList Daemon::linkProviders() const
QStringList returnValue; QStringList returnValue;
for (LinkProvider *a : std::as_const(d->m_linkProviders)) { for (LinkProvider *a : std::as_const(d->m_linkProviders)) {
QString line = QString(a->name()); QString line(a->name());
if (status[QStringLiteral("enabled")].contains(a->name())) { if (status[QStringLiteral("enabled")].contains(a->name())) {
line += QStringLiteral("|enabled"); line += QStringLiteral("|enabled");
@ -184,7 +184,7 @@ void Daemon::setProviderStatus(const QStringList &providerStatus)
QString providerName = components.at(0); QString providerName = components.at(0);
QString providerStatus = components.at(1); QString providerStatus = components.at(1);
auto linkProviders = this->getLinkProviders(); const auto linkProviders = this->getLinkProviders();
for (LinkProvider *provider : linkProviders) { for (LinkProvider *provider : linkProviders) {
if (provider->name() == providerName) { if (provider->name() == providerName) {
if (providerStatus == QStringLiteral("enabled")) { if (providerStatus == QStringLiteral("enabled")) {

View file

@ -85,8 +85,10 @@ void KdeConnectConfig::setLinkProviderStatus(const QStringList enabledProviders,
QMap<QString, QStringList> KdeConnectConfig::linkProviderStatus() const QMap<QString, QStringList> KdeConnectConfig::linkProviderStatus() const
{ {
return {{QStringLiteral("enabled"), d->m_config->value(QStringLiteral("enabled_providers")).toStringList()}, return {
{QStringLiteral("disabled"), d->m_config->value(QStringLiteral("disabled_providers")).toStringList()}}; {QStringLiteral("enabled"), d->m_config->value(QStringLiteral("enabled_providers")).toStringList()},
{QStringLiteral("disabled"), d->m_config->value(QStringLiteral("disabled_providers")).toStringList()},
};
} }
DeviceType KdeConnectConfig::deviceType() DeviceType KdeConnectConfig::deviceType()