Skip to content

Commit

Permalink
[nemo-systemsettings] Make setGuestEnabled asynchronous. Fixes JB#50772
Browse files Browse the repository at this point in the history
Make setGuestEnabled call asynchronous and add an error signal.

Signed-off-by: Tomi Leppänen <tomi.leppanen@jolla.com>
  • Loading branch information
Tomin1 committed Aug 11, 2020
1 parent f8f62d9 commit af9170a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
34 changes: 24 additions & 10 deletions src/usermodel.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion src/usermodel.h
Expand Up @@ -125,14 +125,15 @@ class SYSTEMSETTINGS_EXPORT UserModel: public QAbstractListModel
signals:
void placeholderChanged();
void countChanged();
void guestEnabledChanged();
void userGroupsChanged(int row);
void userAddFailed(int error);
void userModifyFailed(int row, int error);
void userRemoveFailed(int row, int error);
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);
Expand All @@ -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();
Expand Down

0 comments on commit af9170a

Please sign in to comment.