Fix some Qt and KF5 deprecation warnings

## Summary

Fixes a few warnings about deprecated fields and methods.

## Test Plan

Things still seem to be basically working 🤷
This commit is contained in:
Simon Redman 2022-10-17 21:17:49 +00:00
parent b9a089344e
commit 8cfa308140
6 changed files with 45 additions and 42 deletions

View file

@ -87,7 +87,7 @@ int main(int argc, char **argv)
DaemonDbusInterface iface; DaemonDbusInterface iface;
if (parser.isSet(QStringLiteral("my-id"))) { if (parser.isSet(QStringLiteral("my-id"))) {
QTextStream(stdout) << iface.selfId() << endl; QTextStream(stdout) << iface.selfId() << Qt::endl;
} else if (parser.isSet(QStringLiteral("l")) || parser.isSet(QStringLiteral("a"))) { } else if (parser.isSet(QStringLiteral("l")) || parser.isSet(QStringLiteral("a"))) {
bool available = false; bool available = false;
if (parser.isSet(QStringLiteral("a"))) { if (parser.isSet(QStringLiteral("a"))) {
@ -101,15 +101,15 @@ int main(int argc, char **argv)
bool displayCount = true; bool displayCount = true;
for (const QString &id : devices) { for (const QString &id : devices) {
if (parser.isSet(QStringLiteral("id-only"))) { if (parser.isSet(QStringLiteral("id-only"))) {
QTextStream(stdout) << id << endl; QTextStream(stdout) << id << Qt::endl;
displayCount = false; displayCount = false;
} else if (parser.isSet(QStringLiteral("name-only"))) { } else if (parser.isSet(QStringLiteral("name-only"))) {
DeviceDbusInterface deviceIface(id); DeviceDbusInterface deviceIface(id);
QTextStream(stdout) << deviceIface.name() << endl; QTextStream(stdout) << deviceIface.name() << Qt::endl;
displayCount = false; displayCount = false;
} else if (parser.isSet(QStringLiteral("id-name-only"))) { } else if (parser.isSet(QStringLiteral("id-name-only"))) {
DeviceDbusInterface deviceIface(id); DeviceDbusInterface deviceIface(id);
QTextStream(stdout) << id << ' ' << deviceIface.name() << endl; QTextStream(stdout) << id << ' ' << deviceIface.name() << Qt::endl;
displayCount = false; displayCount = false;
} else { } else {
DeviceDbusInterface deviceIface(id); DeviceDbusInterface deviceIface(id);
@ -123,13 +123,13 @@ int main(int argc, char **argv)
} else if (isTrusted) { } else if (isTrusted) {
statusInfo = i18n("(paired)"); statusInfo = i18n("(paired)");
} }
QTextStream(stdout) << "- " << deviceIface.name() << ": " << deviceIface.id() << ' ' << statusInfo << endl; QTextStream(stdout) << "- " << deviceIface.name() << ": " << deviceIface.id() << ' ' << statusInfo << Qt::endl;
} }
} }
if (displayCount) { if (displayCount) {
QTextStream(stderr) << i18np("1 device found", "%1 devices found", devices.size()) << endl; QTextStream(stderr) << i18np("1 device found", "%1 devices found", devices.size()) << Qt::endl;
} else if (devices.isEmpty()) { } else if (devices.isEmpty()) {
QTextStream(stderr) << i18n("No devices found") << endl; QTextStream(stderr) << i18n("No devices found") << Qt::endl;
} }
blockOnReply(iface.releaseDiscoveryMode(id)); blockOnReply(iface.releaseDiscoveryMode(id));
@ -158,7 +158,7 @@ int main(int argc, char **argv)
description.remove(QLatin1Char('\0')); description.remove(QLatin1Char('\0'));
// Output id and description // Output id and description
QTextStream(stdout) << id << '[' << description << ']' << endl; QTextStream(stdout) << id << '[' << description << ']' << Qt::endl;
} }
// Exit with 1 if we didn't find a device // Exit with 1 if we didn't find a device
@ -174,7 +174,7 @@ int main(int argc, char **argv)
if (device.isEmpty() && parser.isSet(QStringLiteral("name"))) { if (device.isEmpty() && parser.isSet(QStringLiteral("name"))) {
device = blockOnReply(iface.deviceIdByName(parser.value(QStringLiteral("name")))); device = blockOnReply(iface.deviceIdByName(parser.value(QStringLiteral("name"))));
if (device.isEmpty()) { if (device.isEmpty()) {
QTextStream(stderr) << "Couldn't find device: " << parser.value(QStringLiteral("name")) << endl; QTextStream(stderr) << "Couldn't find device: " << parser.value(QStringLiteral("name")) << Qt::endl;
return 1; return 1;
} }
} }
@ -182,12 +182,12 @@ int main(int argc, char **argv)
QTextStream(stderr) << i18n( QTextStream(stderr) << i18n(
"No device specified: Use -d <Device ID> or -n <Device Name> to specify a device. \nDevice ID's and names may be found using \"kdeconnect-cli " "No device specified: Use -d <Device ID> or -n <Device Name> to specify a device. \nDevice ID's and names may be found using \"kdeconnect-cli "
"-l\" \nView complete help with --help option") "-l\" \nView complete help with --help option")
<< endl; << Qt::endl;
return 1; return 1;
} }
if (!blockOnReply<QStringList>(iface.devices(false, false)).contains(device)) { if (!blockOnReply<QStringList>(iface.devices(false, false)).contains(device)) {
QTextStream(stderr) << "Couldn't find device with id \"" << device << "\". To specify a device by name use -n <devicename>" << endl; QTextStream(stderr) << "Couldn't find device with id \"" << device << "\". To specify a device by name use -n <devicename>" << Qt::endl;
return 1; return 1;
} }
@ -213,7 +213,7 @@ int main(int argc, char **argv)
blockOnReply(QDBusConnection::sessionBus().asyncCall(msg)); blockOnReply(QDBusConnection::sessionBus().asyncCall(msg));
for (const QString &url : qAsConst(urls)) { for (const QString &url : qAsConst(urls)) {
QTextStream(stdout) << i18n("Shared %1", url) << endl; QTextStream(stdout) << i18n("Shared %1", url) << Qt::endl;
} }
} else if (parser.isSet(QStringLiteral("share-text"))) { } else if (parser.isSet(QStringLiteral("share-text"))) {
QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"), QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"),
@ -222,23 +222,23 @@ int main(int argc, char **argv)
QStringLiteral("shareText")); QStringLiteral("shareText"));
msg.setArguments(QVariantList() << parser.value(QStringLiteral("share-text"))); msg.setArguments(QVariantList() << parser.value(QStringLiteral("share-text")));
blockOnReply(QDBusConnection::sessionBus().asyncCall(msg)); blockOnReply(QDBusConnection::sessionBus().asyncCall(msg));
QTextStream(stdout) << i18n("Shared text: %1", parser.value(QStringLiteral("share-text"))) << endl; QTextStream(stdout) << i18n("Shared text: %1", parser.value(QStringLiteral("share-text"))) << Qt::endl;
} else if (parser.isSet(QStringLiteral("lock")) || parser.isSet(QStringLiteral("unlock"))) { } else if (parser.isSet(QStringLiteral("lock")) || parser.isSet(QStringLiteral("unlock"))) {
LockDeviceDbusInterface iface(device); LockDeviceDbusInterface iface(device);
iface.setLocked(parser.isSet(QStringLiteral("lock"))); iface.setLocked(parser.isSet(QStringLiteral("lock")));
DeviceDbusInterface deviceIface(device); DeviceDbusInterface deviceIface(device);
if (parser.isSet(QStringLiteral("lock"))) { if (parser.isSet(QStringLiteral("lock"))) {
QTextStream(stdout) << i18nc("device has requested to lock peer device", "Requested to lock %1.", deviceIface.name()) << endl; QTextStream(stdout) << i18nc("device has requested to lock peer device", "Requested to lock %1.", deviceIface.name()) << Qt::endl;
} else { } else {
QTextStream(stdout) << i18nc("device has requested to unlock peer device", "Requested to unlock %1.", deviceIface.name()) << endl; QTextStream(stdout) << i18nc("device has requested to unlock peer device", "Requested to unlock %1.", deviceIface.name()) << Qt::endl;
} }
} else if (parser.isSet(QStringLiteral("pair"))) { } else if (parser.isSet(QStringLiteral("pair"))) {
DeviceDbusInterface dev(device); DeviceDbusInterface dev(device);
if (!dev.isReachable()) { if (!dev.isReachable()) {
// Device doesn't exist, go into discovery mode and wait up to 30 seconds for the device to appear // Device doesn't exist, go into discovery mode and wait up to 30 seconds for the device to appear
QEventLoop wait; QEventLoop wait;
QTextStream(stderr) << i18n("waiting for device...") << endl; QTextStream(stderr) << i18n("waiting for device...") << Qt::endl;
blockOnReply(iface.acquireDiscoveryMode(id)); blockOnReply(iface.acquireDiscoveryMode(id));
QObject::connect(&iface, &DaemonDbusInterface::deviceAdded, &iface, [&](const QString &deviceAddedId) { QObject::connect(&iface, &DaemonDbusInterface::deviceAdded, &iface, [&](const QString &deviceAddedId) {
@ -252,20 +252,20 @@ int main(int argc, char **argv)
} }
if (!dev.isReachable()) { if (!dev.isReachable()) {
QTextStream(stderr) << i18n("Device not found") << endl; QTextStream(stderr) << i18n("Device not found") << Qt::endl;
} else if (blockOnReply<bool>(dev.isTrusted())) { } else if (blockOnReply<bool>(dev.isTrusted())) {
QTextStream(stderr) << i18n("Already paired") << endl; QTextStream(stderr) << i18n("Already paired") << Qt::endl;
} else { } else {
QTextStream(stderr) << i18n("Pair requested") << endl; QTextStream(stderr) << i18n("Pair requested") << Qt::endl;
blockOnReply(dev.requestPair()); blockOnReply(dev.requestPair());
} }
blockOnReply(iface.releaseDiscoveryMode(id)); blockOnReply(iface.releaseDiscoveryMode(id));
} else if (parser.isSet(QStringLiteral("unpair"))) { } else if (parser.isSet(QStringLiteral("unpair"))) {
DeviceDbusInterface dev(device); DeviceDbusInterface dev(device);
if (!dev.isTrusted()) { if (!dev.isTrusted()) {
QTextStream(stderr) << i18n("Already not paired") << endl; QTextStream(stderr) << i18n("Already not paired") << Qt::endl;
} else { } else {
QTextStream(stderr) << i18n("Unpaired") << endl; QTextStream(stderr) << i18n("Unpaired") << Qt::endl;
blockOnReply(dev.unpair()); blockOnReply(dev.unpair());
} }
} else if (parser.isSet(QStringLiteral("ping")) || parser.isSet(QStringLiteral("ping-msg"))) { } else if (parser.isSet(QStringLiteral("ping")) || parser.isSet(QStringLiteral("ping-msg"))) {
@ -305,7 +305,7 @@ int main(int argc, char **argv)
reply.waitForFinished(); reply.waitForFinished();
} else { } else {
QTextStream(stderr) << i18n("error: should specify the SMS's recipient by passing --destination <phone number>") << endl; QTextStream(stderr) << i18n("error: should specify the SMS's recipient by passing --destination <phone number>") << Qt::endl;
return 1; return 1;
} }
} else if (parser.isSet(QStringLiteral("ring"))) { } else if (parser.isSet(QStringLiteral("ring"))) {
@ -324,7 +324,7 @@ int main(int argc, char **argv)
msg.setArguments({QUrl::fromLocalFile(fileName).toString()}); msg.setArguments({QUrl::fromLocalFile(fileName).toString()});
blockOnReply(QDBusConnection::sessionBus().asyncCall(msg)); blockOnReply(QDBusConnection::sessionBus().asyncCall(msg));
} else { } else {
QTextStream(stderr) << i18n("Please specify a filename for the photo") << endl; QTextStream(stderr) << i18n("Please specify a filename for the photo") << Qt::endl;
} }
} else if (parser.isSet(QStringLiteral("send-keys"))) { } else if (parser.isSet(QStringLiteral("send-keys"))) {
QString seq = parser.value(QStringLiteral("send-keys")); QString seq = parser.value(QStringLiteral("send-keys"));
@ -353,7 +353,7 @@ int main(int argc, char **argv)
for (int i = 0, rows = notifications.rowCount(); i < rows; ++i) { for (int i = 0, rows = notifications.rowCount(); i < rows; ++i) {
QModelIndex idx = notifications.index(i); QModelIndex idx = notifications.index(i);
QTextStream(stdout) << "- " << idx.data(NotificationsModel::AppNameModelRole).toString() << ": " QTextStream(stdout) << "- " << idx.data(NotificationsModel::AppNameModelRole).toString() << ": "
<< idx.data(NotificationsModel::NameModelRole).toString() << endl; << idx.data(NotificationsModel::NameModelRole).toString() << Qt::endl;
} }
} else if (parser.isSet(QStringLiteral("list-commands"))) { } else if (parser.isSet(QStringLiteral("list-commands"))) {
RemoteCommandsDbusInterface iface(device); RemoteCommandsDbusInterface iface(device);
@ -361,7 +361,7 @@ int main(int argc, char **argv)
for (auto it = cmds.constBegin(), itEnd = cmds.constEnd(); it != itEnd; ++it) { for (auto it = cmds.constBegin(), itEnd = cmds.constEnd(); it != itEnd; ++it) {
const QJsonObject cont = it->toObject(); const QJsonObject cont = it->toObject();
QTextStream(stdout) << it.key() << ": " << cont.value(QStringLiteral("name")).toString() << ": " QTextStream(stdout) << it.key() << ": " << cont.value(QStringLiteral("name")).toString() << ": "
<< cont.value(QStringLiteral("command")).toString() << endl; << cont.value(QStringLiteral("command")).toString() << Qt::endl;
} }
} else if (parser.isSet(QStringLiteral("execute-command"))) { } else if (parser.isSet(QStringLiteral("execute-command"))) {
RemoteCommandsDbusInterface iface(device); RemoteCommandsDbusInterface iface(device);
@ -369,9 +369,9 @@ int main(int argc, char **argv)
} else if (parser.isSet(QStringLiteral("encryption-info"))) { } else if (parser.isSet(QStringLiteral("encryption-info"))) {
DeviceDbusInterface dev(device); DeviceDbusInterface dev(device);
QString info = blockOnReply<QString>(dev.encryptionInfo()); // QSsl::Der = 1 QString info = blockOnReply<QString>(dev.encryptionInfo()); // QSsl::Der = 1
QTextStream(stdout) << info << endl; QTextStream(stdout) << info << Qt::endl;
} else { } else {
QTextStream(stderr) << i18n("Nothing to be done") << endl; QTextStream(stderr) << i18n("Nothing to be done") << Qt::endl;
} }
} }
QMetaObject::invokeMethod(&app, "quit", Qt::QueuedConnection); QMetaObject::invokeMethod(&app, "quit", Qt::QueuedConnection);

View file

@ -95,7 +95,8 @@ QStringList PluginLoader::incomingCapabilities() const
{ {
QSet<QString> ret; QSet<QString> ret;
for (const KPluginMetaData &service : qAsConst(plugins)) { for (const KPluginMetaData &service : qAsConst(plugins)) {
ret += KPluginMetaData::readStringList(service.rawData(), QStringLiteral("X-KdeConnect-SupportedPacketType")).toSet(); QStringList rawValues = service.value(QStringLiteral("X-KdeConnect-SupportedPacketType"), QStringList());
ret += QSet<QString>(rawValues.begin(), rawValues.end());
} }
return ret.values(); return ret.values();
} }
@ -104,7 +105,8 @@ QStringList PluginLoader::outgoingCapabilities() const
{ {
QSet<QString> ret; QSet<QString> ret;
for (const KPluginMetaData &service : qAsConst(plugins)) { for (const KPluginMetaData &service : qAsConst(plugins)) {
ret += KPluginMetaData::readStringList(service.rawData(), QStringLiteral("X-KdeConnect-OutgoingPacketType")).toSet(); QStringList rawValues = service.value(QStringLiteral("X-KdeConnect-OutgoingPacketType"), QStringList());
ret += QSet<QString>(rawValues.begin(), rawValues.end());
} }
return ret.values(); return ret.values();
} }

View file

@ -16,7 +16,7 @@ Q_REQUIRED_RESULT T blockOnReply(QDBusPendingReply<T> reply)
{ {
reply.waitForFinished(); reply.waitForFinished();
if (reply.isError()) { if (reply.isError()) {
QTextStream(stderr) << i18n("error: ") << reply.error().message() << endl; QTextStream(stderr) << i18n("error: ") << reply.error().message() << Qt::endl;
exit(1); exit(1);
} }
return reply.value(); return reply.value();
@ -26,7 +26,7 @@ void blockOnReply(QDBusPendingReply<void> reply)
{ {
reply.waitForFinished(); reply.waitForFinished();
if (reply.isError()) { if (reply.isError()) {
QTextStream(stderr) << i18n("error: ") << reply.error().message() << endl; QTextStream(stderr) << i18n("error: ") << reply.error().message() << Qt::endl;
exit(1); exit(1);
} }
} }

View file

@ -50,7 +50,7 @@ KIO::Error toKioError(const QDBusError::ErrorType type)
case QDBusError::TimedOut: case QDBusError::TimedOut:
return KIO::ERR_SERVER_TIMEOUT; return KIO::ERR_SERVER_TIMEOUT;
default: default:
return KIO::ERR_SLAVE_DEFINED; return KIO::ERR_WORKER_DEFINED;
}; };
}; };
@ -132,21 +132,21 @@ KIO::WorkerResult KioKdeconnect::listDevice(const QString &device)
devsRepl.waitForFinished(); devsRepl.waitForFinished();
if (!devsRepl.value().contains(device)) { if (!devsRepl.value().contains(device)) {
return KIO::WorkerResult::fail(KIO::ERR_SLAVE_DEFINED, i18n("No such device: %0").arg(device)); return KIO::WorkerResult::fail(KIO::ERR_WORKER_DEFINED, i18n("No such device: %0").arg(device));
} }
DeviceDbusInterface dev(device); DeviceDbusInterface dev(device);
if (!dev.isTrusted()) { if (!dev.isTrusted()) {
return KIO::WorkerResult::fail(KIO::ERR_SLAVE_DEFINED, i18n("%0 is not paired").arg(dev.name())); return KIO::WorkerResult::fail(KIO::ERR_WORKER_DEFINED, i18n("%0 is not paired").arg(dev.name()));
} }
if (!dev.isReachable()) { if (!dev.isReachable()) {
return KIO::WorkerResult::fail(KIO::ERR_SLAVE_DEFINED, i18n("%0 is not connected").arg(dev.name())); return KIO::WorkerResult::fail(KIO::ERR_WORKER_DEFINED, i18n("%0 is not connected").arg(dev.name()));
} }
if (!dev.hasPlugin(QStringLiteral("kdeconnect_sftp"))) { if (!dev.hasPlugin(QStringLiteral("kdeconnect_sftp"))) {
return KIO::WorkerResult::fail(KIO::ERR_SLAVE_DEFINED, i18n("%0 has no Remote Filesystem plugin").arg(dev.name())); return KIO::WorkerResult::fail(KIO::ERR_WORKER_DEFINED, i18n("%0 has no Remote Filesystem plugin").arg(dev.name()));
} }
} }
@ -155,7 +155,7 @@ KIO::WorkerResult KioKdeconnect::listDevice(const QString &device)
} }
if (!mountreply.value()) { if (!mountreply.value()) {
return KIO::WorkerResult::fail(KIO::ERR_SLAVE_DEFINED, interface.getMountError()); return KIO::WorkerResult::fail(KIO::ERR_WORKER_DEFINED, interface.getMountError());
} }
QDBusReply<QVariantMap> urlreply = interface.getDirectories(); QDBusReply<QVariantMap> urlreply = interface.getDirectories();
@ -205,7 +205,7 @@ KIO::WorkerResult KioKdeconnect::listDir(const QUrl &url)
qCDebug(KDECONNECT_KIO) << "Listing..." << url; qCDebug(KDECONNECT_KIO) << "Listing..." << url;
if (!m_dbusInterface->isValid()) { if (!m_dbusInterface->isValid()) {
return KIO::WorkerResult::fail(KIO::Error::ERR_SLAVE_DEFINED, i18n("Could not contact background service.")); return KIO::WorkerResult::fail(KIO::Error::ERR_WORKER_DEFINED, i18n("Could not contact background service."));
} }
QString currentDevice = url.host(); QString currentDevice = url.host();

View file

@ -38,9 +38,10 @@ bool SftpPlugin::startBrowsing()
bool SftpPlugin::receivePacket(const NetworkPacket &np) bool SftpPlugin::receivePacket(const NetworkPacket &np)
{ {
if (!(expectedFields - np.body().keys().toSet()).isEmpty()) { QSet<QString> receivedFields(np.body().keys().begin(), np.body().keys().end());
if (!(expectedFields - receivedFields).isEmpty()) {
qCWarning(KDECONNECT_PLUGIN_SFTP) << "Invalid packet received."; qCWarning(KDECONNECT_PLUGIN_SFTP) << "Invalid packet received.";
for (QString missingField : (expectedFields - np.body().keys().toSet()).toList()) { for (QString missingField : (expectedFields - receivedFields)) {
qCWarning(KDECONNECT_PLUGIN_SFTP) << "Field" << missingField << "missing from packet."; qCWarning(KDECONNECT_PLUGIN_SFTP) << "Field" << missingField << "missing from packet.";
} }
return false; return false;

View file

@ -32,8 +32,8 @@ void ConversationsSortFilterProxyModel::setConversationsFilterRole(int role)
bool ConversationsSortFilterProxyModel::lessThan(const QModelIndex &leftIndex, const QModelIndex &rightIndex) const bool ConversationsSortFilterProxyModel::lessThan(const QModelIndex &leftIndex, const QModelIndex &rightIndex) const
{ {
QVariant leftDataTimeStamp = sourceModel()->data(leftIndex, ConversationListModel::DateRole); qlonglong leftDataTimeStamp = sourceModel()->data(leftIndex, ConversationListModel::DateRole).toLongLong();
QVariant rightDataTimeStamp = sourceModel()->data(rightIndex, ConversationListModel::DateRole); qlonglong rightDataTimeStamp = sourceModel()->data(rightIndex, ConversationListModel::DateRole).toLongLong();
if (leftDataTimeStamp == rightDataTimeStamp) { if (leftDataTimeStamp == rightDataTimeStamp) {
QVariant leftDataName = sourceModel()->data(leftIndex, Qt::DisplayRole); QVariant leftDataName = sourceModel()->data(leftIndex, Qt::DisplayRole);