Adding info into the UI for how devices are accessible

This commit is contained in:
Rob Emery
2025-11-25 16:42:06 +00:00
committed by Albert Vaca Cintora
parent 0de079a344
commit b06c4fa268
20 changed files with 110 additions and 16 deletions

View File

@@ -65,6 +65,8 @@ Kirigami.ScrollablePage {
return i18nc("@title:group device page section header", "Actions");
case "control":
return i18nc("@title:group device page section header", "Controls");
case "info":
return i18nc("@title:group device page section header", "Information");
}
}
Accessible.role: Accessible.List
@@ -76,13 +78,13 @@ Kirigami.ScrollablePage {
DelegateModelGroup {name: "loadedPlugins"}
]
filterOnGroup: "loadedPlugins"
property int numberPluginsLoaded: pluginsListView.plugins.filter(plugin => plugin.loaded).length ?? 0
property int numberPluginsLoaded: pluginsListView.plugins.filter(plugin => plugin.loaded || plugin.section === "info").length ?? 0
onNumberPluginsLoadedChanged: update()
function update() {
for (let i = 0; i < items.count; ++i) {
let item = items.get(i);
item.inLoadedPlugins = item.model.loaded
item.inLoadedPlugins = item.model.loaded || item.model.section === "info"
}
}
@@ -204,6 +206,11 @@ Kirigami.ScrollablePage {
}
section: "action"
device: root.currentDevice
},
PluginItem {
name: i18nd("kdeconnect-app", "Address: %1 via %2", root.currentDevice.reachableAddresses, root.currentDevice.activeProviderNames)
section: "info"
device: root.currentDevice
}
]

View File

@@ -48,20 +48,12 @@ FormCard.FormCardPage {
FormCard.FormCheckDelegate {
required property string modelData
readonly property string linkProviderId: modelData.split('|')[0]
readonly property string displayName: switch (linkProviderId) {
case 'BluetoothLinkProvider':
return i18nc("@info KDE Connect provider name", "Bluetooth")
case 'LoopbackLinkProvider':
return i18nc("@info KDE Connect provider name", "Loopback")
case 'LanLinkProvider':
return i18nc("@info KDE Connect provider name", "Network")
}
readonly property string displayName: modelData.split('|')[0]
checked: modelData.split('|')[1] === 'enabled'
text: displayName
onToggled: DaemonDbusInterface.setLinkProviderState(linkProviderId, checked);
onToggled: DaemonDbusInterface.setLinkProviderState(displayName, checked);
}
}
}

View File

@@ -154,7 +154,10 @@ int main(int argc, char **argv)
} else if (isPaired) {
statusInfo = i18n("(paired)");
}
QTextStream(stdout) << "- " << deviceIface.name() << ": " << deviceIface.id() << ' ' << statusInfo << Qt::endl;
QTextStream(stdout) << "- " << deviceIface.name() << ": " << deviceIface.id() << QStringLiteral(" on ")
<< deviceIface.reachableAddresses().join(QStringLiteral(", ")) << QStringLiteral(" via ")
<< deviceIface.activeProviderNames().join(QStringLiteral(", ")) << ' ' << statusInfo << Qt::endl;
}
}
if (displayCount) {

View File

@@ -31,7 +31,12 @@ AsyncLinkProvider::AsyncLinkProvider(bool isDisabled)
QString AsyncLinkProvider::name()
{
return QStringLiteral("BluetoothLinkProvider");
return QStringLiteral("AsyncLinkProvider");
}
QString AsyncLinkProvider::displayName()
{
return i18nc("@info", "Bluetooth");
}
int AsyncLinkProvider::priority()

View File

@@ -34,6 +34,8 @@ public:
AsyncLinkProvider(bool isDisabled);
QString name() override;
QString displayName() override;
int priority() override;
void enable() override;
void disable() override;

View File

@@ -33,6 +33,11 @@ BluetoothDeviceLink::BluetoothDeviceLink(const DeviceInfo &deviceInfo,
connect(socket.data(), &MultiplexChannel::aboutToClose, this, &QObject::deleteLater);
}
QString BluetoothDeviceLink::address() const
{
return mConnection->address().toString();
}
bool BluetoothDeviceLink::sendPacket(NetworkPacket &np)
{
if (np.hasPayload()) {

View File

@@ -35,6 +35,8 @@ public:
return mDeviceInfo;
}
QString address() const override;
private Q_SLOTS:
void dataReceived();

View File

@@ -37,6 +37,11 @@ public:
return QStringLiteral("SynchronousBluetoothLinkProvider");
}
QString displayName() override
{
return i18nc("@info", "Bluetooth");
}
int priority() override
{
return 10;

View File

@@ -107,6 +107,11 @@ bool ConnectionMultiplexer::isOpen() const
return mSocket->isOpen();
}
QBluetoothAddress ConnectionMultiplexer::address() const
{
return mSocket->peerAddress();
}
bool ConnectionMultiplexer::tryParseMessage()
{
mSocket->startTransaction();

View File

@@ -7,6 +7,7 @@
#ifndef CONNECTIONMULTIPLEXER_H
#define CONNECTIONMULTIPLEXER_H
#include <QBluetoothAddress>
#include <QByteArray>
#include <QHash>
#include <QObject>
@@ -67,6 +68,11 @@ public:
*/
bool isOpen() const;
/**
* Returns the address of the connected device for display.
*/
QBluetoothAddress address() const;
private:
/**
* The underlying connection

View File

@@ -15,6 +15,8 @@ DeviceLink::DeviceLink(const QString &deviceId, LinkProvider *parent)
parent->onLinkDestroyed(deviceId, this);
});
this->priorityFromProvider = parent->priority();
this->displayNameFromProvider = parent->displayName();
this->nameFromProvider = parent->name();
}
#include "moc_devicelink.cpp"

View File

@@ -30,12 +30,26 @@ public:
return priorityFromProvider;
}
QString provider() const
{
return nameFromProvider;
}
QString providerName() const
{
return displayNameFromProvider;
}
virtual bool sendPacket(NetworkPacket &np) = 0;
virtual DeviceInfo deviceInfo() const = 0;
virtual QString address() const = 0;
private:
int priorityFromProvider;
QString nameFromProvider;
QString displayNameFromProvider;
Q_SIGNALS:
void receivedPacket(const NetworkPacket &np);

View File

@@ -35,6 +35,11 @@ public:
return m_deviceInfo;
}
QString address() const override
{
return hostAddress().toString();
}
QHostAddress hostAddress() const;
private Q_SLOTS:

View File

@@ -38,6 +38,11 @@ public:
return QStringLiteral("LanLinkProvider");
}
QString displayName() override
{
return i18nc("@info", "LAN");
}
int priority() override
{
return 20;

View File

@@ -7,6 +7,7 @@
#ifndef LINKPROVIDER_H
#define LINKPROVIDER_H
#include <KLocalizedString>
#include <QObject>
#include "networkpacket.h"
@@ -22,6 +23,7 @@ public:
LinkProvider();
virtual QString name() = 0;
virtual QString displayName() = 0;
virtual int priority() = 0;
virtual void enable() = 0;

View File

@@ -21,6 +21,11 @@ public:
virtual bool sendPacket(NetworkPacket &np) override;
virtual DeviceInfo deviceInfo() const override;
QString address() const override
{
return QStringLiteral("127.0.0.1");
}
};
#endif

View File

@@ -22,6 +22,12 @@ public:
{
return QStringLiteral("LoopbackLinkProvider");
}
QString displayName() override
{
return i18nc("@info", "Loopback");
}
int priority() override
{
return 0;

View File

@@ -164,7 +164,7 @@ QStringList Daemon::linkProviders() const
QStringList returnValue;
for (LinkProvider *a : std::as_const(d->m_linkProviders)) {
QString line(a->name());
QString line(a->displayName());
if (disabledLinkProviders.contains(a->name())) {
line += QStringLiteral("|disabled");
@@ -186,7 +186,7 @@ void Daemon::setLinkProviderState(const QString &linkProviderName, bool enabled)
LinkProvider *providerByName = nullptr;
const auto allLinkProviders = getLinkProviders();
for (LinkProvider *provider : allLinkProviders) {
if (provider->name() == linkProviderName) {
if (provider->displayName() == linkProviderName) {
providerByName = provider;
break;
}

View File

@@ -128,6 +128,24 @@ bool Device::isReachable() const
return !d->m_deviceLinks.isEmpty();
}
QStringList Device::reachableAddresses() const
{
QList<QString> addresses;
for (const DeviceLink *deviceLink : std::as_const(d->m_deviceLinks)) {
addresses.append(deviceLink->address());
}
return addresses;
}
QStringList Device::activeProviderNames() const
{
QList<QString> providers;
for (const DeviceLink *deviceLink : std::as_const(d->m_deviceLinks)) {
providers.append(deviceLink->providerName());
}
return providers;
}
int Device::protocolVersion()
{
return d->m_deviceInfo.protocolVersion;

View File

@@ -29,6 +29,8 @@ class KDECONNECTCORE_EXPORT Device : public QObject
Q_PROPERTY(QString verificationKey READ verificationKey NOTIFY pairStateChanged)
Q_PROPERTY(QString statusIconName READ statusIconName NOTIFY statusIconNameChanged)
Q_PROPERTY(bool isReachable READ isReachable NOTIFY reachableChanged)
Q_PROPERTY(QStringList reachableAddresses READ reachableAddresses CONSTANT)
Q_PROPERTY(QStringList activeProviderNames READ activeProviderNames CONSTANT)
Q_PROPERTY(bool isPaired READ isPaired NOTIFY pairStateChanged)
Q_PROPERTY(bool isPairRequested READ isPairRequested NOTIFY pairStateChanged)
Q_PROPERTY(bool isPairRequestedByPeer READ isPairRequestedByPeer NOTIFY pairStateChanged)
@@ -84,6 +86,9 @@ public:
Q_SCRIPTABLE bool isPairRequestedByPeer() const;
virtual bool isReachable() const;
virtual QStringList reachableAddresses() const;
virtual QStringList activeProviderNames() const;
Q_SCRIPTABLE QStringList loadedPlugins() const;
Q_SCRIPTABLE bool hasPlugin(const QString &name) const;