Handle dbus errors in setWhenAvailable

This commit is contained in:
Albert Vaca Cintora 2024-09-09 13:31:31 +02:00
parent 942aa2a170
commit 02ff5bd6c5
No known key found for this signature in database
4 changed files with 37 additions and 26 deletions

View file

@ -31,9 +31,9 @@ DeviceIndicator::DeviceIndicator(DeviceDbusInterface *device)
addAction(battery);
setWhenAvailable(
device->hasPlugin(QStringLiteral("kdeconnect_battery")),
[battery](bool available) {
battery->setVisible(available);
battery->setDisabled(available);
[battery](bool error, bool available) {
battery->setVisible(available && !error);
battery->setDisabled(true);
},
this);
@ -41,9 +41,9 @@ DeviceIndicator::DeviceIndicator(DeviceDbusInterface *device)
addAction(connectivity);
setWhenAvailable(
device->hasPlugin(QStringLiteral("kdeconnect_connectivity_report")),
[connectivity](bool available) {
connectivity->setVisible(available);
connectivity->setDisabled(available);
[connectivity](bool error, bool available) {
connectivity->setVisible(available && !error);
connectivity->setDisabled(true);
},
this);
@ -58,8 +58,8 @@ DeviceIndicator::DeviceIndicator(DeviceDbusInterface *device)
});
setWhenAvailable(
device->hasPlugin(QStringLiteral("kdeconnect_sftp")),
[browse](bool available) {
browse->setVisible(available);
[browse](bool error, bool available) {
browse->setVisible(available && !error);
},
this);
@ -72,8 +72,8 @@ DeviceIndicator::DeviceIndicator(DeviceDbusInterface *device)
});
setWhenAvailable(
device->hasPlugin(QStringLiteral("kdeconnect_clipboard")),
[clipboard](bool available) {
clipboard->setVisible(available);
[clipboard](bool error, bool available) {
clipboard->setVisible(available && !error);
},
this);
@ -86,8 +86,8 @@ DeviceIndicator::DeviceIndicator(DeviceDbusInterface *device)
});
setWhenAvailable(
device->hasPlugin(QStringLiteral("kdeconnect_findmyphone")),
[findDevice](bool available) {
findDevice->setVisible(available);
[findDevice](bool error, bool available) {
findDevice->setVisible(available && !error);
},
this);
@ -106,8 +106,8 @@ DeviceIndicator::DeviceIndicator(DeviceDbusInterface *device)
});
setWhenAvailable(
device->hasPlugin(QStringLiteral("kdeconnect_share")),
[sendFile](bool available) {
sendFile->setVisible(available);
[sendFile](bool error, bool available) {
sendFile->setVisible(available && !error);
},
this);
@ -120,8 +120,8 @@ DeviceIndicator::DeviceIndicator(DeviceDbusInterface *device)
});
setWhenAvailable(
device->hasPlugin(QStringLiteral("kdeconnect_sms")),
[smsapp](bool available) {
smsapp->setVisible(available);
[smsapp](bool error, bool available) {
smsapp->setVisible(available && !error);
},
this);
}
@ -135,11 +135,12 @@ DeviceIndicator::DeviceIndicator(DeviceDbusInterface *device)
addAction(menuAction);
setWhenAvailable(
device->hasPlugin(QStringLiteral("kdeconnect_remotecommands")),
[this, remoteCommandsMenu, menuAction](bool available) {
menuAction->setVisible(available);
[this, remoteCommandsMenu, menuAction](bool error, bool available) {
menuAction->setVisible(available && !error);
if (!available)
if (!available || error) {
return;
}
const auto cmds = QJsonDocument::fromJson(m_remoteCommandsInterface->commands()).object();

View file

@ -38,7 +38,7 @@ static void setWhenAvailable(const QDBusPendingReply<T> &pending, W func, QObjec
QObject::connect(watcher, &QDBusPendingCallWatcher::finished, parent, [func](QDBusPendingCallWatcher *watcher) {
watcher->deleteLater();
QDBusPendingReply<T> reply = *watcher;
func(reply.value());
func(reply.isError(), reply.value());
});
}

View file

@ -51,9 +51,14 @@ KdeConnectKcm::KdeConnectKcm(QObject *parent, const KPluginMetaData &md, const Q
setWhenAvailable(
daemon->announcedName(),
[this](const QString &announcedName) {
[this](bool error, const QString &announcedName) {
kcmUi.renameShow_button->setEnabled(!error);
if (error) {
kcmUi.rename_label->setText(i18n("Error: KDE Connect is not running"));
} else {
kcmUi.rename_label->setText(announcedName);
kcmUi.rename_edit->setText(announcedName);
}
},
this);
connect(daemon, &DaemonDbusInterface::announcedNameChanged, kcmUi.rename_edit, &QLineEdit::setText);
@ -185,8 +190,10 @@ void KdeConnectKcm::resetDeviceView()
kcmUi.name_label->setText(currentDevice->name());
setWhenAvailable(
currentDevice->pairStateAsInt(),
[this](int pairStateAsInt) {
[this](bool error, int pairStateAsInt) {
if (!error) {
setCurrentDevicePairState(pairStateAsInt);
}
},
this);

View file

@ -101,8 +101,11 @@ void ConversationListModel::prepareConversationsList()
setWhenAvailable(
validThreadIDsReply,
[this](const QVariantList &convs) {
[this](bool error, const QVariantList &convs) {
clear(); // If we clear before we receive the reply, there might be a (several second) visual gap!
if (error) {
return;
}
for (const QVariant &headMessage : convs) {
createRowFromMessage(qdbus_cast<ConversationMessage>(headMessage));
}