Handle dbus errors in setWhenAvailable
This commit is contained in:
parent
942aa2a170
commit
02ff5bd6c5
4 changed files with 37 additions and 26 deletions
|
@ -31,9 +31,9 @@ DeviceIndicator::DeviceIndicator(DeviceDbusInterface *device)
|
||||||
addAction(battery);
|
addAction(battery);
|
||||||
setWhenAvailable(
|
setWhenAvailable(
|
||||||
device->hasPlugin(QStringLiteral("kdeconnect_battery")),
|
device->hasPlugin(QStringLiteral("kdeconnect_battery")),
|
||||||
[battery](bool available) {
|
[battery](bool error, bool available) {
|
||||||
battery->setVisible(available);
|
battery->setVisible(available && !error);
|
||||||
battery->setDisabled(available);
|
battery->setDisabled(true);
|
||||||
},
|
},
|
||||||
this);
|
this);
|
||||||
|
|
||||||
|
@ -41,9 +41,9 @@ DeviceIndicator::DeviceIndicator(DeviceDbusInterface *device)
|
||||||
addAction(connectivity);
|
addAction(connectivity);
|
||||||
setWhenAvailable(
|
setWhenAvailable(
|
||||||
device->hasPlugin(QStringLiteral("kdeconnect_connectivity_report")),
|
device->hasPlugin(QStringLiteral("kdeconnect_connectivity_report")),
|
||||||
[connectivity](bool available) {
|
[connectivity](bool error, bool available) {
|
||||||
connectivity->setVisible(available);
|
connectivity->setVisible(available && !error);
|
||||||
connectivity->setDisabled(available);
|
connectivity->setDisabled(true);
|
||||||
},
|
},
|
||||||
this);
|
this);
|
||||||
|
|
||||||
|
@ -58,8 +58,8 @@ DeviceIndicator::DeviceIndicator(DeviceDbusInterface *device)
|
||||||
});
|
});
|
||||||
setWhenAvailable(
|
setWhenAvailable(
|
||||||
device->hasPlugin(QStringLiteral("kdeconnect_sftp")),
|
device->hasPlugin(QStringLiteral("kdeconnect_sftp")),
|
||||||
[browse](bool available) {
|
[browse](bool error, bool available) {
|
||||||
browse->setVisible(available);
|
browse->setVisible(available && !error);
|
||||||
},
|
},
|
||||||
this);
|
this);
|
||||||
|
|
||||||
|
@ -72,8 +72,8 @@ DeviceIndicator::DeviceIndicator(DeviceDbusInterface *device)
|
||||||
});
|
});
|
||||||
setWhenAvailable(
|
setWhenAvailable(
|
||||||
device->hasPlugin(QStringLiteral("kdeconnect_clipboard")),
|
device->hasPlugin(QStringLiteral("kdeconnect_clipboard")),
|
||||||
[clipboard](bool available) {
|
[clipboard](bool error, bool available) {
|
||||||
clipboard->setVisible(available);
|
clipboard->setVisible(available && !error);
|
||||||
},
|
},
|
||||||
this);
|
this);
|
||||||
|
|
||||||
|
@ -86,8 +86,8 @@ DeviceIndicator::DeviceIndicator(DeviceDbusInterface *device)
|
||||||
});
|
});
|
||||||
setWhenAvailable(
|
setWhenAvailable(
|
||||||
device->hasPlugin(QStringLiteral("kdeconnect_findmyphone")),
|
device->hasPlugin(QStringLiteral("kdeconnect_findmyphone")),
|
||||||
[findDevice](bool available) {
|
[findDevice](bool error, bool available) {
|
||||||
findDevice->setVisible(available);
|
findDevice->setVisible(available && !error);
|
||||||
},
|
},
|
||||||
this);
|
this);
|
||||||
|
|
||||||
|
@ -106,8 +106,8 @@ DeviceIndicator::DeviceIndicator(DeviceDbusInterface *device)
|
||||||
});
|
});
|
||||||
setWhenAvailable(
|
setWhenAvailable(
|
||||||
device->hasPlugin(QStringLiteral("kdeconnect_share")),
|
device->hasPlugin(QStringLiteral("kdeconnect_share")),
|
||||||
[sendFile](bool available) {
|
[sendFile](bool error, bool available) {
|
||||||
sendFile->setVisible(available);
|
sendFile->setVisible(available && !error);
|
||||||
},
|
},
|
||||||
this);
|
this);
|
||||||
|
|
||||||
|
@ -120,8 +120,8 @@ DeviceIndicator::DeviceIndicator(DeviceDbusInterface *device)
|
||||||
});
|
});
|
||||||
setWhenAvailable(
|
setWhenAvailable(
|
||||||
device->hasPlugin(QStringLiteral("kdeconnect_sms")),
|
device->hasPlugin(QStringLiteral("kdeconnect_sms")),
|
||||||
[smsapp](bool available) {
|
[smsapp](bool error, bool available) {
|
||||||
smsapp->setVisible(available);
|
smsapp->setVisible(available && !error);
|
||||||
},
|
},
|
||||||
this);
|
this);
|
||||||
}
|
}
|
||||||
|
@ -135,11 +135,12 @@ DeviceIndicator::DeviceIndicator(DeviceDbusInterface *device)
|
||||||
addAction(menuAction);
|
addAction(menuAction);
|
||||||
setWhenAvailable(
|
setWhenAvailable(
|
||||||
device->hasPlugin(QStringLiteral("kdeconnect_remotecommands")),
|
device->hasPlugin(QStringLiteral("kdeconnect_remotecommands")),
|
||||||
[this, remoteCommandsMenu, menuAction](bool available) {
|
[this, remoteCommandsMenu, menuAction](bool error, bool available) {
|
||||||
menuAction->setVisible(available);
|
menuAction->setVisible(available && !error);
|
||||||
|
|
||||||
if (!available)
|
if (!available || error) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const auto cmds = QJsonDocument::fromJson(m_remoteCommandsInterface->commands()).object();
|
const auto cmds = QJsonDocument::fromJson(m_remoteCommandsInterface->commands()).object();
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ static void setWhenAvailable(const QDBusPendingReply<T> &pending, W func, QObjec
|
||||||
QObject::connect(watcher, &QDBusPendingCallWatcher::finished, parent, [func](QDBusPendingCallWatcher *watcher) {
|
QObject::connect(watcher, &QDBusPendingCallWatcher::finished, parent, [func](QDBusPendingCallWatcher *watcher) {
|
||||||
watcher->deleteLater();
|
watcher->deleteLater();
|
||||||
QDBusPendingReply<T> reply = *watcher;
|
QDBusPendingReply<T> reply = *watcher;
|
||||||
func(reply.value());
|
func(reply.isError(), reply.value());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
11
kcm/kcm.cpp
11
kcm/kcm.cpp
|
@ -51,9 +51,14 @@ KdeConnectKcm::KdeConnectKcm(QObject *parent, const KPluginMetaData &md, const Q
|
||||||
|
|
||||||
setWhenAvailable(
|
setWhenAvailable(
|
||||||
daemon->announcedName(),
|
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_label->setText(announcedName);
|
||||||
kcmUi.rename_edit->setText(announcedName);
|
kcmUi.rename_edit->setText(announcedName);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
this);
|
this);
|
||||||
connect(daemon, &DaemonDbusInterface::announcedNameChanged, kcmUi.rename_edit, &QLineEdit::setText);
|
connect(daemon, &DaemonDbusInterface::announcedNameChanged, kcmUi.rename_edit, &QLineEdit::setText);
|
||||||
|
@ -185,8 +190,10 @@ void KdeConnectKcm::resetDeviceView()
|
||||||
kcmUi.name_label->setText(currentDevice->name());
|
kcmUi.name_label->setText(currentDevice->name());
|
||||||
setWhenAvailable(
|
setWhenAvailable(
|
||||||
currentDevice->pairStateAsInt(),
|
currentDevice->pairStateAsInt(),
|
||||||
[this](int pairStateAsInt) {
|
[this](bool error, int pairStateAsInt) {
|
||||||
|
if (!error) {
|
||||||
setCurrentDevicePairState(pairStateAsInt);
|
setCurrentDevicePairState(pairStateAsInt);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
this);
|
this);
|
||||||
|
|
||||||
|
|
|
@ -101,8 +101,11 @@ void ConversationListModel::prepareConversationsList()
|
||||||
|
|
||||||
setWhenAvailable(
|
setWhenAvailable(
|
||||||
validThreadIDsReply,
|
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!
|
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) {
|
for (const QVariant &headMessage : convs) {
|
||||||
createRowFromMessage(qdbus_cast<ConversationMessage>(headMessage));
|
createRowFromMessage(qdbus_cast<ConversationMessage>(headMessage));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue