Commit af9170ae authored by Tomi Leppänen's avatar Tomi Leppänen

[nemo-systemsettings] Make setGuestEnabled asynchronous. Fixes JB#50772

Make setGuestEnabled call asynchronous and add an error signal.
Signed-off-by: Tomi Leppänen's avatarTomi Leppänen <tomi.leppanen@jolla.com>
parent f8f62d96
......@@ -452,18 +452,16 @@ void UserModel::setGuestEnabled(bool enabled)
if (enabled == m_guestEnabled)
return;
m_transitioning.insert(SAILFISH_USERMANAGER_GUEST_UID);
int row;
if (enabled) {
row = placeholder() ? m_users.count() - 1 : m_users.count();
} else {
row = m_uidsToRows.value(SAILFISH_USERMANAGER_GUEST_UID);
if (m_guestEnabled) {
m_transitioning.insert(SAILFISH_USERMANAGER_GUEST_UID);
auto idx = index(m_uidsToRows.value(SAILFISH_USERMANAGER_GUEST_UID), 0);
emit dataChanged(idx, idx, QVector<int>() << TransitioningRole);
}
QModelIndex idx = index(row, 0);
emit dataChanged(idx, idx, QVector<int>() << TransitioningRole);
createInterface();
m_dBusInterface->call(QStringLiteral("enableGuestUser"), enabled);
auto call = m_dBusInterface->asyncCall(QStringLiteral("enableGuestUser"), enabled);
auto *watcher = new QDBusPendingCallWatcher(call, this);
connect(watcher, &QDBusPendingCallWatcher::finished,
this, std::bind(&UserModel::enableGuestUserFinished, this, std::placeholders::_1, enabled));
}
void UserModel::userAddFinished(QDBusPendingCallWatcher *call)
......@@ -549,6 +547,22 @@ void UserModel::removeFromGroupsFinished(QDBusPendingCallWatcher *call, uint uid
call->deleteLater();
}
void UserModel::enableGuestUserFinished(QDBusPendingCallWatcher *call, bool enabling)
{
QDBusPendingReply<void> reply = *call;
if (reply.isError()) {
auto error = reply.error();
emit setGuestEnabledFailed(enabling, getErrorType(error));
qCWarning(lcUsersLog) << ((enabling) ? "Enabling" : "Disabling") << "guest user failed:" << error;
if (!enabling) {
m_transitioning.remove(SAILFISH_USERMANAGER_GUEST_UID);
auto idx = index(m_uidsToRows.value(SAILFISH_USERMANAGER_GUEST_UID), 0);
emit dataChanged(idx, idx, QVector<int>() << TransitioningRole);
}
} // else wait for signals
call->deleteLater();
}
void UserModel::createInterface()
{
if (!m_dBusInterface) {
......
......@@ -125,6 +125,7 @@ public:
signals:
void placeholderChanged();
void countChanged();
void guestEnabledChanged();
void userGroupsChanged(int row);
void userAddFailed(int error);
void userModifyFailed(int row, int error);
......@@ -132,7 +133,7 @@ signals:
void setCurrentUserFailed(int row, int error);
void addGroupsFailed(int row, int error);
void removeGroupsFailed(int row, int error);
void guestEnabledChanged();
void setGuestEnabledFailed(bool enabling, int error);
private slots:
void onUserAdded(const SailfishUserManagerEntry &entry);
......@@ -148,6 +149,7 @@ private slots:
void setCurrentUserFinished(QDBusPendingCallWatcher *call, uint uid);
void addToGroupsFinished(QDBusPendingCallWatcher *call, uint uid);
void removeFromGroupsFinished(QDBusPendingCallWatcher *call, uint uid);
void enableGuestUserFinished(QDBusPendingCallWatcher *call, bool enabling);
void createInterface();
void destroyInterface();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment