Expose pair requests on the KCM
This commit is contained in:
parent
b75d52fe31
commit
f65392ca6b
6 changed files with 90 additions and 15 deletions
|
@ -274,6 +274,11 @@ void Device::removePairingRequest(PairingHandler* handler)
|
||||||
Q_EMIT hasPairingRequestsChanged(!m_pairRequests.isEmpty());
|
Q_EMIT hasPairingRequestsChanged(!m_pairRequests.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Device::hasPairingRequests() const
|
||||||
|
{
|
||||||
|
return !m_pairRequests.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
void Device::acceptPairing()
|
void Device::acceptPairing()
|
||||||
{
|
{
|
||||||
if (m_pairRequests.isEmpty())
|
if (m_pairRequests.isEmpty())
|
||||||
|
|
|
@ -103,8 +103,6 @@ public:
|
||||||
int protocolVersion() { return m_protocolVersion; }
|
int protocolVersion() { return m_protocolVersion; }
|
||||||
QStringList supportedPlugins() const { return m_supportedPlugins.toList(); }
|
QStringList supportedPlugins() const { return m_supportedPlugins.toList(); }
|
||||||
|
|
||||||
bool hasPairingRequests() const { return !m_pairRequests.isEmpty(); }
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
///sends a @p np package to the device
|
///sends a @p np package to the device
|
||||||
///virtual for testing purposes.
|
///virtual for testing purposes.
|
||||||
|
@ -118,6 +116,7 @@ public Q_SLOTS:
|
||||||
|
|
||||||
Q_SCRIPTABLE void acceptPairing();
|
Q_SCRIPTABLE void acceptPairing();
|
||||||
Q_SCRIPTABLE void rejectPairing();
|
Q_SCRIPTABLE void rejectPairing();
|
||||||
|
Q_SCRIPTABLE bool hasPairingRequests() const;
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void privateReceivedPackage(const NetworkPackage& np);
|
void privateReceivedPackage(const NetworkPackage& np);
|
||||||
|
|
|
@ -77,7 +77,7 @@ Q_SIGNALS:
|
||||||
void nameChangedProxy(const QString &name);
|
void nameChangedProxy(const QString &name);
|
||||||
void trustedChangedProxy(bool paired);
|
void trustedChangedProxy(bool paired);
|
||||||
void reachableChangedProxy(bool reachable);
|
void reachableChangedProxy(bool reachable);
|
||||||
void hasPairingRequestsChangedProxy();
|
void hasPairingRequestsChangedProxy(bool);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QString m_id;
|
const QString m_id;
|
||||||
|
|
75
kcm/kcm.cpp
75
kcm/kcm.cpp
|
@ -95,6 +95,10 @@ KdeConnectKcm::KdeConnectKcm(QWidget *parent, const QVariantList&)
|
||||||
this, &KdeConnectKcm::resetSelection);
|
this, &KdeConnectKcm::resetSelection);
|
||||||
connect(kcmUi->deviceList->selectionModel(), &QItemSelectionModel::currentChanged,
|
connect(kcmUi->deviceList->selectionModel(), &QItemSelectionModel::currentChanged,
|
||||||
this, &KdeConnectKcm::deviceSelected);
|
this, &KdeConnectKcm::deviceSelected);
|
||||||
|
connect(kcmUi->accept_button, &QAbstractButton::clicked,
|
||||||
|
this, &KdeConnectKcm::acceptPairing);
|
||||||
|
connect(kcmUi->reject_button, &QAbstractButton::clicked,
|
||||||
|
this, &KdeConnectKcm::rejectPairing);
|
||||||
connect(kcmUi->pair_button, &QAbstractButton::clicked,
|
connect(kcmUi->pair_button, &QAbstractButton::clicked,
|
||||||
this, &KdeConnectKcm::requestPair);
|
this, &KdeConnectKcm::requestPair);
|
||||||
connect(kcmUi->unpair_button, &QAbstractButton::clicked,
|
connect(kcmUi->unpair_button, &QAbstractButton::clicked,
|
||||||
|
@ -189,6 +193,18 @@ void KdeConnectKcm::deviceSelected(const QModelIndex& current)
|
||||||
connect(currentDevice, SIGNAL(pluginsChanged()), this, SLOT(resetCurrentDevice()));
|
connect(currentDevice, SIGNAL(pluginsChanged()), this, SLOT(resetCurrentDevice()));
|
||||||
connect(currentDevice, SIGNAL(trustedChanged(bool)), this, SLOT(trustedChanged(bool)));
|
connect(currentDevice, SIGNAL(trustedChanged(bool)), this, SLOT(trustedChanged(bool)));
|
||||||
connect(currentDevice, SIGNAL(pairingError(QString)), this, SLOT(pairingFailed(QString)));
|
connect(currentDevice, SIGNAL(pairingError(QString)), this, SLOT(pairingFailed(QString)));
|
||||||
|
connect(currentDevice, &DeviceDbusInterface::hasPairingRequestsChangedProxy, this, &KdeConnectKcm::currentDevicePairingChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
void KdeConnectKcm::currentDevicePairingChanged(bool pairing)
|
||||||
|
{
|
||||||
|
if (pairing) {
|
||||||
|
setCurrentDeviceTrusted(RequestedByPeer);
|
||||||
|
} else {
|
||||||
|
setWhenAvailable(currentDevice->isTrusted(), [this](bool trusted) {
|
||||||
|
setCurrentDeviceTrusted(trusted ? Trusted : NotTrusted);
|
||||||
|
}, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KdeConnectKcm::resetCurrentDevice()
|
void KdeConnectKcm::resetCurrentDevice()
|
||||||
|
@ -211,7 +227,12 @@ void KdeConnectKcm::resetDeviceView()
|
||||||
|
|
||||||
kcmUi->name_label->setText(currentDevice->name());
|
kcmUi->name_label->setText(currentDevice->name());
|
||||||
setWhenAvailable(currentDevice->isTrusted(), [this](bool trusted) {
|
setWhenAvailable(currentDevice->isTrusted(), [this](bool trusted) {
|
||||||
setCurrentDeviceTrusted(trusted);
|
if (trusted)
|
||||||
|
setCurrentDeviceTrusted(Trusted);
|
||||||
|
else
|
||||||
|
setWhenAvailable(currentDevice->hasPairingRequests(), [this](bool haspr) {
|
||||||
|
setCurrentDeviceTrusted(haspr ? RequestedByPeer : NotTrusted);
|
||||||
|
}, this);
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
const QList<KPluginInfo> pluginInfo = KPluginInfo::fromMetaData(KPluginLoader::findPlugins(QStringLiteral("kdeconnect/")));
|
const QList<KPluginInfo> pluginInfo = KPluginInfo::fromMetaData(KPluginLoader::findPlugins(QStringLiteral("kdeconnect/")));
|
||||||
|
@ -238,8 +259,7 @@ void KdeConnectKcm::requestPair()
|
||||||
|
|
||||||
kcmUi->messages->hide();
|
kcmUi->messages->hide();
|
||||||
|
|
||||||
kcmUi->pair_button->setVisible(false);
|
setCurrentDeviceTrusted(Requested);
|
||||||
kcmUi->progressBar->setVisible(true);
|
|
||||||
|
|
||||||
currentDevice->requestPair();
|
currentDevice->requestPair();
|
||||||
|
|
||||||
|
@ -254,11 +274,29 @@ void KdeConnectKcm::unpair()
|
||||||
currentDevice->unpair();
|
currentDevice->unpair();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KdeConnectKcm::acceptPairing()
|
||||||
|
{
|
||||||
|
if (!currentDevice) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentDevice->acceptPairing();
|
||||||
|
}
|
||||||
|
|
||||||
|
void KdeConnectKcm::rejectPairing()
|
||||||
|
{
|
||||||
|
if (!currentDevice) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentDevice->rejectPairing();
|
||||||
|
}
|
||||||
|
|
||||||
void KdeConnectKcm::pairingFailed(const QString& error)
|
void KdeConnectKcm::pairingFailed(const QString& error)
|
||||||
{
|
{
|
||||||
if (sender() != currentDevice) return;
|
if (sender() != currentDevice) return;
|
||||||
|
|
||||||
trustedChanged(false);
|
setCurrentDeviceTrusted(NotTrusted);
|
||||||
|
|
||||||
kcmUi->messages->setText(i18n("Error trying to pair: %1",error));
|
kcmUi->messages->setText(i18n("Error trying to pair: %1",error));
|
||||||
kcmUi->messages->animatedShow();
|
kcmUi->messages->animatedShow();
|
||||||
|
@ -268,16 +306,31 @@ void KdeConnectKcm::trustedChanged(bool trusted)
|
||||||
{
|
{
|
||||||
DeviceDbusInterface* senderDevice = (DeviceDbusInterface*) sender();
|
DeviceDbusInterface* senderDevice = (DeviceDbusInterface*) sender();
|
||||||
if (senderDevice == currentDevice)
|
if (senderDevice == currentDevice)
|
||||||
setCurrentDeviceTrusted(trusted);
|
setCurrentDeviceTrusted(trusted ? Trusted : NotTrusted);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KdeConnectKcm::setCurrentDeviceTrusted(bool trusted)
|
void KdeConnectKcm::setCurrentDeviceTrusted(KdeConnectKcm::TrustStatus trusted)
|
||||||
{
|
{
|
||||||
kcmUi->pair_button->setVisible(!trusted);
|
kcmUi->accept_button->setVisible(trusted == RequestedByPeer);
|
||||||
kcmUi->unpair_button->setVisible(trusted);
|
kcmUi->reject_button->setVisible(trusted == RequestedByPeer);
|
||||||
kcmUi->progressBar->setVisible(false);
|
kcmUi->pair_button->setVisible(trusted == NotTrusted);
|
||||||
kcmUi->ping_button->setVisible(trusted);
|
kcmUi->unpair_button->setVisible(trusted == Trusted);
|
||||||
kcmUi->status_label->setText(trusted ? i18n("(paired)") : i18n("(not paired)"));
|
kcmUi->progressBar->setVisible(trusted == Requested);
|
||||||
|
kcmUi->ping_button->setVisible(trusted == Trusted);
|
||||||
|
switch (trusted) {
|
||||||
|
case Trusted:
|
||||||
|
kcmUi->status_label->setText(i18n("(paired)"));
|
||||||
|
break;
|
||||||
|
case NotTrusted:
|
||||||
|
kcmUi->status_label->setText(i18n("(not paired)"));
|
||||||
|
break;
|
||||||
|
case Requested:
|
||||||
|
kcmUi->status_label->setText(i18n("(incoming pair request)"));
|
||||||
|
break;
|
||||||
|
case RequestedByPeer:
|
||||||
|
kcmUi->status_label->setText(i18n("(pairing requested)"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KdeConnectKcm::pluginsConfigChanged()
|
void KdeConnectKcm::pluginsConfigChanged()
|
||||||
|
|
|
@ -60,9 +60,13 @@ private Q_SLOTS:
|
||||||
void renameDone();
|
void renameDone();
|
||||||
void setRenameMode(bool b);
|
void setRenameMode(bool b);
|
||||||
void resetCurrentDevice();
|
void resetCurrentDevice();
|
||||||
|
void currentDevicePairingChanged(bool pairing);
|
||||||
|
void acceptPairing();
|
||||||
|
void rejectPairing();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setCurrentDeviceTrusted(bool trusted);
|
enum TrustStatus { NotTrusted, Requested, RequestedByPeer, Trusted };
|
||||||
|
void setCurrentDeviceTrusted(TrustStatus trusted);
|
||||||
void resetDeviceView();
|
void resetDeviceView();
|
||||||
|
|
||||||
Ui::KdeConnectKcmUi* kcmUi;
|
Ui::KdeConnectKcmUi* kcmUi;
|
||||||
|
|
14
kcm/kcm.ui
14
kcm/kcm.ui
|
@ -203,6 +203,20 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="accept_button">
|
||||||
|
<property name="text">
|
||||||
|
<string>Accept</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="reject_button">
|
||||||
|
<property name="text">
|
||||||
|
<string>Reject</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pair_button">
|
<widget class="QPushButton" name="pair_button">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
|
Loading…
Reference in a new issue