@@ -18,7 +18,10 @@
1818
1919#include "UsersModelPrivate.h"
2020
21+#include "AccountsServiceDBusAdaptor.h"
22+
2123#include <glib.h>
24+#include <QDebug>
2225#include <QDir>
2326#include <QSettings>
2427#include <QStringList>
@@ -27,7 +30,9 @@ namespace QLightDM
2730{
2831
2932UsersModelPrivate::UsersModelPrivate(UsersModel* parent)
30− : q_ptr(parent)
33+ : QObject((QObject*)parent),
34+ q_ptr(parent),
35+ m_service(new AccountsServiceDBusAdaptor(this))
3136{
3237 QFileInfo demoFile(QDir::homePath() + "/.unity8-greeter-demo");
3338 QString currentUser = g_get_user_name();
@@ -43,15 +48,44 @@ UsersModelPrivate::UsersModelPrivate(UsersModel* parent)
4348 entries.append({user, name, 0, 0, false, false, 0, 0});
4449 }
4550 } else {
46− // If we were using the actual liblightdm, we could just ask it
47− // for the user's real name. But we aren't. We *should* ask
48− // AccountsService for the real name, like liblightdm does internally,
49− // but this is close enough since AS and passwd are always in sync.
50− QString realName = QString::fromUtf8(g_get_real_name()); // gets name from passwd entry
51− if (realName == QStringLiteral("Unknown")) { // glib doesn't translate this string
52− realName.clear();
51+ entries.append({currentUser, 0, 0, 0, false, false, 0, 0});
52+
53+ connect(m_service, &AccountsServiceDBusAdaptor::maybeChanged,
54+ this, [this](const QString &user) {
55+ if (user == entries[0].username) {
56+ updateName(true);
57+ }
58+ });
59+ updateName(false);
60+ }
61+}
62+
63+void UsersModelPrivate::updateName(bool async)
64+{
65+ auto pendingReply = m_service->getUserPropertyAsync(entries[0].username,
66+ QStringLiteral("org.freedesktop.Accounts.User"),
67+ QStringLiteral("RealName"));
68+ auto *watcher = new QDBusPendingCallWatcher(pendingReply, this);
69+
70+ connect(watcher, &QDBusPendingCallWatcher::finished,
71+ this, [this](QDBusPendingCallWatcher* watcher) {
72+
73+ QDBusPendingReply<QVariant> reply = *watcher;
74+ watcher->deleteLater();
75+ if (reply.isError()) {
76+ qWarning() << "Failed to get 'RealName' property - " << reply.error().message();
77+ return;
78+ }
79+
80+ const QString realName = reply.value().toString();
81+ if (entries[0].real_name != realName) {
82+ entries[0].real_name = realName;
83+ Q_EMIT dataChanged(0);
5384 }
54− entries.append({currentUser, realName, 0, 0, false, false, 0, 0});
85+ });
86+ if (!async) {
87+ watcher->waitForFinished();
88+ delete watcher;
5589 }
5690}
5791