In the CLI interface, make it possible to refer a device by name
Only works with trusted devices
This commit is contained in:
parent
4d1cf58612
commit
c7429b56b7
3 changed files with 22 additions and 2 deletions
|
@ -60,6 +60,7 @@ int main(int argc, char** argv)
|
||||||
parser.addOption(QCommandLineOption("list-notifications", i18n("Display the notifications on a said device")));
|
parser.addOption(QCommandLineOption("list-notifications", i18n("Display the notifications on a said device")));
|
||||||
parser.addOption(QCommandLineOption("lock", i18n("Lock the specified device")));
|
parser.addOption(QCommandLineOption("lock", i18n("Lock the specified device")));
|
||||||
parser.addOption(QCommandLineOption(QStringList("device") << "d", i18n("Device ID"), "dev"));
|
parser.addOption(QCommandLineOption(QStringList("device") << "d", i18n("Device ID"), "dev"));
|
||||||
|
parser.addOption(QCommandLineOption(QStringList("name") << "n", i18n("Device Name"), "name"));
|
||||||
parser.addOption(QCommandLineOption("encryption-info", i18n("Get encryption info about said device")));
|
parser.addOption(QCommandLineOption("encryption-info", i18n("Get encryption info about said device")));
|
||||||
about.setupCommandLine(&parser);
|
about.setupCommandLine(&parser);
|
||||||
|
|
||||||
|
@ -110,10 +111,18 @@ int main(int argc, char** argv)
|
||||||
QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.kdeconnect", "/modules/kdeconnect", "org.kde.kdeconnect.daemon", "forceOnNetworkChange");
|
QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.kdeconnect", "/modules/kdeconnect", "org.kde.kdeconnect.daemon", "forceOnNetworkChange");
|
||||||
QDBusConnection::sessionBus().call(msg);
|
QDBusConnection::sessionBus().call(msg);
|
||||||
} else {
|
} else {
|
||||||
if(!parser.isSet("device")) {
|
QString device = parser.value("device");
|
||||||
|
if (device.isEmpty() && parser.isSet("name")) {
|
||||||
|
device = iface.deviceIdByName(parser.value("name"));
|
||||||
|
if (device.isEmpty()) {
|
||||||
|
QTextStream(stderr) << "Couldn't find device: " << parser.value("name") << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(device.isEmpty()) {
|
||||||
QTextStream(stderr) << i18n("No device specified") << endl;
|
QTextStream(stderr) << i18n("No device specified") << endl;
|
||||||
}
|
}
|
||||||
const QString device = parser.value("device");
|
|
||||||
if(parser.isSet("share")) {
|
if(parser.isSet("share")) {
|
||||||
QUrl url = QUrl::fromUserInput(parser.value("share"), QDir::currentPath());
|
QUrl url = QUrl::fromUserInput(parser.value("share"), QDir::currentPath());
|
||||||
parser.clearPositionalArguments();
|
parser.clearPositionalArguments();
|
||||||
|
|
|
@ -241,6 +241,15 @@ bool Daemon::isDiscoveringDevices() const
|
||||||
return !d->mDiscoveryModeAcquisitions.isEmpty();
|
return !d->mDiscoveryModeAcquisitions.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Daemon::deviceIdByName(const QString &name) const
|
||||||
|
{
|
||||||
|
foreach(Device* d, d->mDevices) {
|
||||||
|
if (d->name() == name && d->isTrusted())
|
||||||
|
return d->id();
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
Daemon::~Daemon()
|
Daemon::~Daemon()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,8 @@ public Q_SLOTS:
|
||||||
//Returns a list of ids. The respective devices can be manipulated using the dbus path: "/modules/kdeconnect/Devices/"+id
|
//Returns a list of ids. The respective devices can be manipulated using the dbus path: "/modules/kdeconnect/Devices/"+id
|
||||||
Q_SCRIPTABLE QStringList devices(bool onlyReachable = false, bool onlyPaired = false) const;
|
Q_SCRIPTABLE QStringList devices(bool onlyReachable = false, bool onlyPaired = false) const;
|
||||||
|
|
||||||
|
Q_SCRIPTABLE QString deviceIdByName(const QString &name) const;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
Q_SCRIPTABLE void deviceAdded(const QString& id);
|
Q_SCRIPTABLE void deviceAdded(const QString& id);
|
||||||
Q_SCRIPTABLE void deviceRemoved(const QString& id); //Note that paired devices will never be removed
|
Q_SCRIPTABLE void deviceRemoved(const QString& id); //Note that paired devices will never be removed
|
||||||
|
|
Loading…
Reference in a new issue