From af9170ae81ef814830fef012373094ede15f817b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomi=20Lepp=C3=A4nen?= Date: Tue, 11 Aug 2020 10:54:46 +0300 Subject: [PATCH] [nemo-systemsettings] Make setGuestEnabled asynchronous. Fixes JB#50772 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make setGuestEnabled call asynchronous and add an error signal. Signed-off-by: Tomi Leppänen --- src/usermodel.cpp | 34 ++++++++++++++++++++++++---------- src/usermodel.h | 4 +++- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/usermodel.cpp b/src/usermodel.cpp index eec2375..aa5f2c5 100644 --- a/src/usermodel.cpp +++ b/src/usermodel.cpp @@ -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() << TransitioningRole); } - QModelIndex idx = index(row, 0); - emit dataChanged(idx, idx, QVector() << 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 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() << TransitioningRole); + } + } // else wait for signals + call->deleteLater(); +} + void UserModel::createInterface() { if (!m_dBusInterface) { diff --git a/src/usermodel.h b/src/usermodel.h index f3f60bc..d2a62c4 100644 --- a/src/usermodel.h +++ b/src/usermodel.h @@ -125,6 +125,7 @@ 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); @@ -132,7 +133,7 @@ class SYSTEMSETTINGS_EXPORT UserModel: public QAbstractListModel 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();