[not working] try to pass the pair state through dbus as an enum

This commit is contained in:
Albert Vaca Cintora 2023-06-02 19:18:06 +02:00
parent a56ff23770
commit 1e392220da
5 changed files with 14 additions and 21 deletions

View file

@ -224,7 +224,7 @@ void Device::requestPairing()
{
qCDebug(KDECONNECT_CORE) << "Request pairing";
d->m_pairingHandler->requestPairing();
Q_EMIT pairStateChanged(pairStateAsInt());
Q_EMIT pairStateChanged(pairState());
}
void Device::unpair()
@ -248,7 +248,7 @@ void Device::cancelPairing()
void Device::pairingHandler_incomingPairRequest()
{
Q_ASSERT(d->m_pairingHandler->pairState() == PairState::RequestedByPeer);
Q_EMIT pairStateChanged(pairStateAsInt());
Q_EMIT pairStateChanged(pairState());
}
void Device::pairingHandler_pairingSuccessful()
@ -257,14 +257,14 @@ void Device::pairingHandler_pairingSuccessful()
KdeConnectConfig::instance().addTrustedDevice(id(), name(), type());
KdeConnectConfig::instance().setDeviceProperty(d->m_deviceId, QStringLiteral("certificate"), QString::fromLatin1(certificate().toPem()));
reloadPlugins(); // Will load/unload plugins
Q_EMIT pairStateChanged(pairStateAsInt());
Q_EMIT pairStateChanged(pairState());
}
void Device::pairingHandler_pairingFailed(const QString &errorMessage)
{
Q_ASSERT(d->m_pairingHandler->pairState() == PairState::NotPaired);
Q_EMIT pairingFailed(errorMessage);
Q_EMIT pairStateChanged(pairStateAsInt());
Q_EMIT pairStateChanged(pairState());
}
void Device::pairingHandler_unpaired()
@ -273,7 +273,7 @@ void Device::pairingHandler_unpaired()
qCDebug(KDECONNECT_CORE) << "Unpaired";
KdeConnectConfig::instance().removeTrustedDevice(id());
reloadPlugins(); // Will load/unload plugins
Q_EMIT pairStateChanged(pairStateAsInt());
Q_EMIT pairStateChanged(pairState());
}
static bool lessThan(DeviceLink *p1, DeviceLink *p2)
@ -381,11 +381,6 @@ PairState Device::pairState() const
return d->m_pairingHandler->pairState();
}
int Device::pairStateAsInt() const
{
return (int)pairState();
}
bool Device::isPaired() const
{
return d->m_pairingHandler->pairState() == PairState::Paired;

View file

@ -30,7 +30,7 @@ class KDECONNECTCORE_EXPORT Device : public QObject
Q_PROPERTY(bool isPaired READ isPaired NOTIFY pairStateChanged)
Q_PROPERTY(bool isPairRequested READ isPairRequested NOTIFY pairStateChanged)
Q_PROPERTY(bool isPairRequestedByPeer READ isPairRequestedByPeer NOTIFY pairStateChanged)
Q_PROPERTY(int pairState READ pairStateAsInt NOTIFY pairStateChanged)
Q_PROPERTY(PairState pairState READ pairState NOTIFY pairStateChanged)
Q_PROPERTY(QStringList supportedPlugins READ supportedPlugins NOTIFY pluginsChanged)
public:
@ -76,7 +76,6 @@ public:
void removeLink(DeviceLink *);
PairState pairState() const;
Q_SCRIPTABLE int pairStateAsInt() const; // Hack because qdbus doesn't like enums
Q_SCRIPTABLE bool isPaired() const;
Q_SCRIPTABLE bool isPairRequested() const;
Q_SCRIPTABLE bool isPairRequestedByPeer() const;
@ -125,7 +124,7 @@ private Q_SLOTS:
Q_SIGNALS:
Q_SCRIPTABLE void pluginsChanged();
Q_SCRIPTABLE void reachableChanged(bool reachable);
Q_SCRIPTABLE void pairStateChanged(int pairState); // Hack because qdbus doesn't like enums
Q_SCRIPTABLE void pairStateChanged(PairState pairState);
Q_SCRIPTABLE void pairingFailed(const QString &error);
Q_SCRIPTABLE void nameChanged(const QString &name);
Q_SCRIPTABLE void typeChanged(const QString &type);

View file

@ -59,7 +59,7 @@ class KDECONNECTINTERFACES_EXPORT DeviceDbusInterface : public OrgKdeKdeconnectD
Q_PROPERTY(bool isPaired READ isPaired NOTIFY pairStateChangedProxy)
Q_PROPERTY(bool isPairRequested READ isPairRequested NOTIFY pairStateChangedProxy)
Q_PROPERTY(bool isPairRequestedByPeer READ isPairRequestedByPeer NOTIFY pairStateChangedProxy)
Q_PROPERTY(int pairState READ pairState NOTIFY pairStateChangedProxy)
Q_PROPERTY(PairState pairState READ pairState NOTIFY pairStateChangedProxy)
Q_PROPERTY(QString name READ name NOTIFY nameChangedProxy)
public:
@ -71,7 +71,7 @@ public:
Q_SIGNALS:
void nameChangedProxy(const QString &name);
void pairStateChangedProxy(int pairState);
void pairStateChangedProxy(PairState pairState);
void reachableChangedProxy(bool reachable);
private:

View file

@ -207,9 +207,9 @@ void KdeConnectKcm::resetDeviceView()
kcmUi->name_label->setText(currentDevice->name());
setWhenAvailable(
currentDevice->pairStateAsInt(),
[this](int pairStateAsInt) {
setCurrentDevicePairState(pairStateAsInt);
currentDevice->pairState(),
[this](PairState pairState) {
setCurrentDevicePairState(pairState);
},
this);
@ -279,9 +279,8 @@ void KdeConnectKcm::pairingFailed(const QString &error)
}
void KdeConnectKcm::setCurrentDevicePairState(int pairStateAsInt)
void KdeConnectKcm::setCurrentDevicePairState(PairState pairState)
{
PairState state = (PairState)pairStateAsInt; // Hack because qdbus doesn't like enums
kcmUi->accept_button->setVisible(state == PairState::RequestedByPeer);
kcmUi->reject_button->setVisible(state == PairState::RequestedByPeer);
kcmUi->cancel_button->setVisible(state == PairState::Requested);

View file

@ -47,7 +47,7 @@ private Q_SLOTS:
void renameDone();
void setRenameMode(bool b);
void resetCurrentDevice();
void setCurrentDevicePairState(int pairStateAsInt);
void setCurrentDevicePairState(PairState pairState);
void acceptPairing();
void cancelPairing();