@@ -18,7 +18,11 @@
19#include "UsersModelPrivate.h"
19#include "UsersModelPrivate.h"
21+#include "AccountsServiceDBusAdaptor.h"
22+#include "UsersModel.h"
21#include <glib.h>
24#include <glib.h>
22#include <QDir>
26#include <QDir>
23#include <QSettings>
27#include <QSettings>
24#include <QStringList>
28#include <QStringList>
@@ -27,7 +31,9 @@ namespace QLightDM
29UsersModelPrivate::UsersModelPrivate(UsersModel* parent)
33UsersModelPrivate::UsersModelPrivate(UsersModel* parent)
30− : q_ptr(parent)
35+ q_ptr(parent),
36+ m_service(new AccountsServiceDBusAdaptor(this))
32 QFileInfo demoFile(QDir::homePath() + "/.unity8-greeter-demo");
38 QFileInfo demoFile(QDir::homePath() + "/.unity8-greeter-demo");
33 QString currentUser = g_get_user_name();
39 QString currentUser = g_get_user_name();
@@ -43,15 +49,43 @@ UsersModelPrivate::UsersModelPrivate(UsersModel* parent)
43 entries.append({user, name, 0, 0, false, false, 0, 0});
49 entries.append({user, name, 0, 0, false, false, 0, 0});
46− // If we were using the actual liblightdm, we could just ask it
52+ entries.append({currentUser, 0, 0, 0, false, false, 0, 0});
47− // for the user's real name. But we aren't. We *should* ask
53+
48− // AccountsService for the real name, like liblightdm does internally,
54+ connect(m_service, &AccountsServiceDBusAdaptor::maybeChanged,
49− // but this is close enough since AS and passwd are always in sync.
55+ this, [this](const QString &user) {
50− QString realName = QString::fromUtf8(g_get_real_name()); // gets name from passwd entry
56+ if (user == entries[0].username) {
51− if (realName == QStringLiteral("Unknown")) { // glib doesn't translate this string
57+ updateName(true);
52− realName.clear();
58+ }
64+void UsersModelPrivate::updateName(bool async)
66+ auto pendingReply = m_service->getUserPropertyAsync(entries[0].username,
67+ QStringLiteral("org.freedesktop.Accounts.User"),
68+ QStringLiteral("RealName"));
69+ auto *watcher = new QDBusPendingCallWatcher(pendingReply, this);
71+ connect(watcher, &QDBusPendingCallWatcher::finished,
72+ this, [this](QDBusPendingCallWatcher* watcher) {
74+ QDBusPendingReply<QVariant> reply = *watcher;
75+ watcher->deleteLater();
76+ if (reply.isError()) {
77+ qWarning() << "Failed to get 'RealName' property - " << reply.error().message();
81+ const QString realName = reply.value().toString();
82+ if (entries[0].real_name != realName) {
83+ entries[0].real_name = realName;
84+ Q_EMIT dataChanged(0);
54− entries.append({currentUser, realName, 0, 0, false, false, 0, 0});
86+ });
88+ watcher->waitForFinished();