Changeset View
Changeset View
Standalone View
Standalone View
cli/kdeconnect-cli.cpp
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | 38 | { | |||
---|---|---|---|---|---|
46 | KAboutData::setApplicationData(about); | 46 | KAboutData::setApplicationData(about); | ||
47 | 47 | | |||
48 | about.addAuthor( i18n("Aleix Pol Gonzalez"), QString(), QStringLiteral("aleixpol@kde.org") ); | 48 | about.addAuthor( i18n("Aleix Pol Gonzalez"), QString(), QStringLiteral("aleixpol@kde.org") ); | ||
49 | about.addAuthor( i18n("Albert Vaca Cintora"), QString(), QStringLiteral("albertvaka@gmail.com") ); | 49 | about.addAuthor( i18n("Albert Vaca Cintora"), QString(), QStringLiteral("albertvaka@gmail.com") ); | ||
50 | QCommandLineParser parser; | 50 | QCommandLineParser parser; | ||
51 | parser.addOption(QCommandLineOption(QStringList(QStringLiteral("l")) << QStringLiteral("list-devices"), i18n("List all devices"))); | 51 | parser.addOption(QCommandLineOption(QStringList(QStringLiteral("l")) << QStringLiteral("list-devices"), i18n("List all devices"))); | ||
52 | parser.addOption(QCommandLineOption(QStringList(QStringLiteral("a")) << QStringLiteral("list-available"), i18n("List available (paired and reachable) devices"))); | 52 | parser.addOption(QCommandLineOption(QStringList(QStringLiteral("a")) << QStringLiteral("list-available"), i18n("List available (paired and reachable) devices"))); | ||
53 | parser.addOption(QCommandLineOption(QStringLiteral("id-only"), i18n("Make --list-devices or --list-available print only the devices id, to ease scripting"))); | 53 | parser.addOption(QCommandLineOption(QStringLiteral("id-only"), i18n("Make --list-devices or --list-available print only the devices id, to ease scripting"))); | ||
54 | parser.addOption(QCommandLineOption(QStringLiteral("name-only"), i18n("Make --list-devices or --list-available print only the devices name, to ease scripting"))); | ||||
55 | parser.addOption(QCommandLineOption(QStringLiteral("id-name-only"), i18n("Make --list-devices or --list-available print only the devices id and name, to ease scripting"))); | ||||
54 | parser.addOption(QCommandLineOption(QStringLiteral("refresh"), i18n("Search for devices in the network and re-establish connections"))); | 56 | parser.addOption(QCommandLineOption(QStringLiteral("refresh"), i18n("Search for devices in the network and re-establish connections"))); | ||
55 | parser.addOption(QCommandLineOption(QStringLiteral("pair"), i18n("Request pairing to a said device"))); | 57 | parser.addOption(QCommandLineOption(QStringLiteral("pair"), i18n("Request pairing to a said device"))); | ||
56 | parser.addOption(QCommandLineOption(QStringLiteral("ring"), i18n("Find the said device by ringing it."))); | 58 | parser.addOption(QCommandLineOption(QStringLiteral("ring"), i18n("Find the said device by ringing it."))); | ||
57 | parser.addOption(QCommandLineOption(QStringLiteral("unpair"), i18n("Stop pairing to a said device"))); | 59 | parser.addOption(QCommandLineOption(QStringLiteral("unpair"), i18n("Stop pairing to a said device"))); | ||
58 | parser.addOption(QCommandLineOption(QStringLiteral("ping"), i18n("Sends a ping to said device"))); | 60 | parser.addOption(QCommandLineOption(QStringLiteral("ping"), i18n("Sends a ping to said device"))); | ||
59 | parser.addOption(QCommandLineOption(QStringLiteral("ping-msg"), i18n("Same as ping but you can set the message to display"), i18n("message"))); | 61 | parser.addOption(QCommandLineOption(QStringLiteral("ping-msg"), i18n("Same as ping but you can set the message to display"), i18n("message"))); | ||
60 | parser.addOption(QCommandLineOption(QStringLiteral("share"), i18n("Share a file to a said device"), QStringLiteral("path"))); | 62 | parser.addOption(QCommandLineOption(QStringLiteral("share"), i18n("Share a file to a said device"), QStringLiteral("path"))); | ||
61 | parser.addOption(QCommandLineOption(QStringLiteral("list-notifications"), i18n("Display the notifications on a said device"))); | 63 | parser.addOption(QCommandLineOption(QStringLiteral("list-notifications"), i18n("Display the notifications on a said device"))); | ||
Show All 23 Lines | 85 | } else if (parser.isSet(QStringLiteral("l")) || parser.isSet(QStringLiteral("a"))) { | |||
85 | if (parser.isSet(QStringLiteral("a"))) { | 87 | if (parser.isSet(QStringLiteral("a"))) { | ||
86 | reachable = true; | 88 | reachable = true; | ||
87 | } else { | 89 | } else { | ||
88 | blockOnReply(iface.acquireDiscoveryMode(id)); | 90 | blockOnReply(iface.acquireDiscoveryMode(id)); | ||
89 | QThread::sleep(2); | 91 | QThread::sleep(2); | ||
90 | } | 92 | } | ||
91 | const QStringList devices = blockOnReply<QStringList>(iface.devices(reachable, paired)); | 93 | const QStringList devices = blockOnReply<QStringList>(iface.devices(reachable, paired)); | ||
92 | 94 | | |||
95 | bool displayCount = true; | ||||
93 | for (const QString& id : devices) { | 96 | for (const QString& id : devices) { | ||
94 | if (parser.isSet(QStringLiteral("id-only"))) { | 97 | if (parser.isSet(QStringLiteral("id-only"))) { | ||
95 | QTextStream(stdout) << id << endl; | 98 | QTextStream(stdout) << id << endl; | ||
99 | displayCount = false; | ||||
100 | } else if (parser.isSet(QStringLiteral("name-only"))) { | ||||
101 | DeviceDbusInterface deviceIface(id); | ||||
102 | QTextStream(stdout) << deviceIface.name() << endl; | ||||
103 | displayCount = false; | ||||
104 | } else if (parser.isSet(QStringLiteral("id-name-only"))) { | ||||
105 | DeviceDbusInterface deviceIface(id); | ||||
106 | QTextStream(stdout) << id << ' ' << deviceIface.name() << endl; | ||||
107 | displayCount = false; | ||||
96 | } else { | 108 | } else { | ||
97 | DeviceDbusInterface deviceIface(id); | 109 | DeviceDbusInterface deviceIface(id); | ||
98 | QString statusInfo; | 110 | QString statusInfo; | ||
99 | const bool isReachable = deviceIface.isReachable(); | 111 | const bool isReachable = deviceIface.isReachable(); | ||
100 | const bool isTrusted = deviceIface.isTrusted(); | 112 | const bool isTrusted = deviceIface.isTrusted(); | ||
101 | if (isReachable && isTrusted) { | 113 | if (isReachable && isTrusted) { | ||
102 | statusInfo = i18n("(paired and reachable)"); | 114 | statusInfo = i18n("(paired and reachable)"); | ||
103 | } else if (isReachable) { | 115 | } else if (isReachable) { | ||
104 | statusInfo = i18n("(reachable)"); | 116 | statusInfo = i18n("(reachable)"); | ||
105 | } else if (isTrusted) { | 117 | } else if (isTrusted) { | ||
106 | statusInfo = i18n("(paired)"); | 118 | statusInfo = i18n("(paired)"); | ||
107 | } | 119 | } | ||
108 | QTextStream(stdout) << "- " << deviceIface.name() | 120 | QTextStream(stdout) << "- " << deviceIface.name() | ||
109 | << ": " << deviceIface.id() << ' ' << statusInfo << endl; | 121 | << ": " << deviceIface.id() << ' ' << statusInfo << endl; | ||
110 | } | 122 | } | ||
111 | } | 123 | } | ||
112 | if (!parser.isSet(QStringLiteral("id-only"))) { | 124 | if (displayCount) { | ||
113 | QTextStream(stdout) << i18np("1 device found", "%1 devices found", devices.size()) << endl; | 125 | QTextStream(stdout) << i18np("1 device found", "%1 devices found", devices.size()) << endl; | ||
114 | } else if (devices.isEmpty()) { | 126 | } else if (devices.isEmpty()) { | ||
115 | QTextStream(stderr) << i18n("No devices found") << endl; | 127 | QTextStream(stderr) << i18n("No devices found") << endl; | ||
116 | } | 128 | } | ||
117 | 129 | | |||
118 | blockOnReply(iface.releaseDiscoveryMode(id)); | 130 | blockOnReply(iface.releaseDiscoveryMode(id)); | ||
119 | } else if(parser.isSet(QStringLiteral("refresh"))) { | 131 | } else if(parser.isSet(QStringLiteral("refresh"))) { | ||
120 | QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"), QStringLiteral("/modules/kdeconnect"), QStringLiteral("org.kde.kdeconnect.daemon"), QStringLiteral("forceOnNetworkChange")); | 132 | QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"), QStringLiteral("/modules/kdeconnect"), QStringLiteral("org.kde.kdeconnect.daemon"), QStringLiteral("forceOnNetworkChange")); | ||
▲ Show 20 Lines • Show All 142 Lines • Show Last 20 Lines |