@@ -18,7 +18,10 @@
19#include "UsersModelPrivate.h"
19#include "UsersModelPrivate.h"
21+#include "AccountsServiceDBusAdaptor.h"
21#include <glib.h>
23#include <glib.h>
22#include <QDir>
25#include <QDir>
23#include <QSettings>
26#include <QSettings>
24#include <QStringList>
27#include <QStringList>
@@ -27,7 +30,9 @@ namespace QLightDM
29UsersModelPrivate::UsersModelPrivate(UsersModel* parent)
32UsersModelPrivate::UsersModelPrivate(UsersModel* parent)
33+ : QObject((QObject*)parent),
30− : q_ptr(parent)
34+ q_ptr(parent),
35+ m_service(new AccountsServiceDBusAdaptor(this))
32 QFileInfo demoFile(QDir::homePath() + "/.unity8-greeter-demo");
37 QFileInfo demoFile(QDir::homePath() + "/.unity8-greeter-demo");
33 QString currentUser = g_get_user_name();
38 QString currentUser = g_get_user_name();
@@ -43,15 +48,44 @@ UsersModelPrivate::UsersModelPrivate(UsersModel* parent)
43 entries.append({user, name, 0, 0, false, false, 0, 0});
48 entries.append({user, name, 0, 0, false, false, 0, 0});
46− // If we were using the actual liblightdm, we could just ask it
51+ entries.append({currentUser, 0, 0, 0, false, false, 0, 0});
47− // for the user's real name. But we aren't. We *should* ask
52+
48− // AccountsService for the real name, like liblightdm does internally,
53+ connect(m_service, &AccountsServiceDBusAdaptor::maybeChanged,
49− // but this is close enough since AS and passwd are always in sync.
54+ this, [this](const QString &user) {
50− QString realName = QString::fromUtf8(g_get_real_name()); // gets name from passwd entry
55+ if (user == entries[0].username) {
51− if (realName == QStringLiteral("Unknown")) { // glib doesn't translate this string
56+ updateName(true);
52− realName.clear();
57+ }
63+void UsersModelPrivate::updateName(bool async)
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);
70+ connect(watcher, &QDBusPendingCallWatcher::finished,
71+ this, [this](QDBusPendingCallWatcher* watcher) {
73+ QDBusPendingReply<QVariant> reply = *watcher;
74+ watcher->deleteLater();
75+ if (reply.isError()) {
76+ qWarning() << "Failed to get 'RealName' property - " << reply.error().message();
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);
54− entries.append({currentUser, realName, 0, 0, false, false, 0, 0});
85+ });
87+ watcher->waitForFinished();