Fix kdeconnect-cli after DevicesModel refactoring

Can't use the model anymore as it is asynchronous, so just use the dbus
interfaces directly.
This commit is contained in:
Aleix Pol 2015-03-16 02:58:22 +01:00
parent fda4556dfc
commit 021bb1781a

View file

@ -63,35 +63,35 @@ int main(int argc, char** argv)
about.processCommandLine(&parser); about.processCommandLine(&parser);
if(parser.isSet("l") || parser.isSet("a")) { if(parser.isSet("l") || parser.isSet("a")) {
DevicesModel devices; DaemonDbusInterface iface;
bool paired = true, reachable = false;
if (parser.isSet("a")) { if (parser.isSet("a")) {
devices.setDisplayFilter(DevicesModel::StatusFlag::StatusPaired | DevicesModel::StatusFlag::StatusReachable); reachable = true;
} }
int deviceCount = devices.rowCount(); QDBusPendingReply<QStringList> reply = iface.devices(paired, reachable);
for(int i=0; i < deviceCount; ++i) { reply.waitForFinished();
QModelIndex idx = devices.index(i);
const QStringList devices = reply.value();
foreach (const QString& id, devices) {
if (parser.isSet("id-only")) { if (parser.isSet("id-only")) {
QTextStream(stdout) << idx.data(DevicesModel::ModelRoles::IdModelRole).toString() << endl; QTextStream(stdout) << id << endl;
} else { } else {
DeviceDbusInterface deviceIface(id);
QString statusInfo; QString statusInfo;
switch(idx.data(DevicesModel::StatusModelRole).toInt()) { const bool isReachable = deviceIface.isReachable(), isPaired = deviceIface.isPaired();
case DevicesModel::StatusPaired: if (isReachable && isPaired) {
statusInfo = i18n("(paired)"); statusInfo = i18n("(paired and reachable)");
break; } else if (isReachable) {
case DevicesModel::StatusReachable: statusInfo = i18n("(reachable)");
statusInfo = i18n("(reachable)"); } else if (isPaired)
break; statusInfo = i18n("(paired)");
case DevicesModel::StatusReachable | DevicesModel::StatusPaired: QTextStream(stdout) << "- " << deviceIface.name()
statusInfo = i18n("(paired and reachable)"); << ": " << deviceIface.id() << ' ' << statusInfo << endl;
break;
}
QTextStream(stdout) << "- " << idx.data(Qt::DisplayRole).toString()
<< ": " << idx.data(DevicesModel::IdModelRole).toString() << ' ' << statusInfo << endl;
} }
} }
if (!parser.isSet("id-only")) { if (!parser.isSet("id-only")) {
QTextStream(stdout) << i18n("%1 device(s) found", deviceCount) << endl; QTextStream(stdout) << i18np("1 device found", "%1 devices found", devices.size()) << endl;
} else if (!deviceCount) { } else if (devices.isEmpty()) {
QTextStream(stderr) << i18n("No devices found") << endl; QTextStream(stderr) << i18n("No devices found") << endl;
} }
} else if(parser.isSet("refresh")) { } else if(parser.isSet("refresh")) {