Set the device's announcedName when it's available

No need to block on it
This commit is contained in:
Aleix Pol 2017-01-13 14:21:37 +01:00
parent 8c9253440d
commit c822ef8104
3 changed files with 16 additions and 14 deletions

View file

@ -22,18 +22,6 @@
#include <QFileDialog> #include <QFileDialog>
#include <KLocalizedString> #include <KLocalizedString>
template <typename T, typename W>
static void setWhenAvailable(const QDBusPendingReply<T> &pending, W func, QObject* parent)
{
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pending, parent);
QObject::connect(watcher, &QDBusPendingCallWatcher::finished,
parent, [func](QDBusPendingCallWatcher* watcher) {
watcher->deleteLater();
QDBusPendingReply<T> reply = *watcher;
func(reply.value());
});
}
class BatteryAction : public QAction class BatteryAction : public QAction
{ {
Q_OBJECT Q_OBJECT

View file

@ -180,4 +180,16 @@ public:
~RemoteCommandsDbusInterface() override; ~RemoteCommandsDbusInterface() override;
}; };
template <typename T, typename W>
static void setWhenAvailable(const QDBusPendingReply<T> &pending, W func, QObject* parent)
{
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pending, parent);
QObject::connect(watcher, &QDBusPendingCallWatcher::finished,
parent, [func](QDBusPendingCallWatcher* watcher) {
watcher->deleteLater();
QDBusPendingReply<T> reply = *watcher;
func(reply.value());
});
}
#endif #endif

View file

@ -79,8 +79,10 @@ KdeConnectKcm::KdeConnectKcm(QWidget *parent, const QVariantList&)
kcmUi->noDeviceLinks->setWordWrap(false); kcmUi->noDeviceLinks->setWordWrap(false);
QTimer::singleShot(0, [this] { kcmUi->noDeviceLinks->setWordWrap(true); }); QTimer::singleShot(0, [this] { kcmUi->noDeviceLinks->setWordWrap(true); });
kcmUi->rename_label->setText(daemon->announcedName()); setWhenAvailable(daemon->announcedName(), [this](const QString& announcedName) {
kcmUi->rename_edit->setText(daemon->announcedName()); kcmUi->rename_label->setText(announcedName);
kcmUi->rename_edit->setText(announcedName);
}, this);
connect(daemon, SIGNAL(announcedNameChanged(QString)), connect(daemon, SIGNAL(announcedNameChanged(QString)),
kcmUi->rename_edit, SLOT(setText(QString))); kcmUi->rename_edit, SLOT(setText(QString)));
connect(daemon, SIGNAL(announcedNameChanged(QString)), connect(daemon, SIGNAL(announcedNameChanged(QString)),