diff --git a/src/accountinfo.cpp b/src/accountinfo.cpp --- a/src/accountinfo.cpp +++ b/src/accountinfo.cpp @@ -153,29 +153,38 @@ qCDebug(USER_MANAGER_LOG) << "Saving on Index: " << m_index.row(); QList failed; - if (m_infoToSave.contains(AccountModel::Username) && - !m_model->setData(m_index, m_infoToSave[AccountModel::Username], AccountModel::Username)) { + AccountModel::Result res = AccountModel::Result::Ok; + bool hadAuthFailure = false; + if (m_infoToSave.contains(AccountModel::Username) && !hadAuthFailure && + (res = m_model->setDataWithResult(m_index, m_infoToSave[AccountModel::Username], AccountModel::Username)) != AccountModel::Result::Ok) { failed.append(AccountModel::Username); + hadAuthFailure |= res == AccountModel::Result::AuthError; } - if (m_infoToSave.contains(AccountModel::RealName) && - !m_model->setData(m_index, m_infoToSave[AccountModel::RealName], AccountModel::RealName)) { + if (m_infoToSave.contains(AccountModel::RealName) && !hadAuthFailure && + (res = m_model->setDataWithResult(m_index, m_infoToSave[AccountModel::RealName], AccountModel::RealName)) != AccountModel::Result::Ok) { failed.append(AccountModel::RealName); + hadAuthFailure |= res == AccountModel::Result::AuthError; } - if (m_infoToSave.contains(AccountModel::Email) && - !m_model->setData(m_index, m_infoToSave[AccountModel::Email], AccountModel::Email)) { + if (m_infoToSave.contains(AccountModel::Email) && !hadAuthFailure && + (res = m_model->setDataWithResult(m_index, m_infoToSave[AccountModel::Email], AccountModel::Email)) != AccountModel::Result::Ok) { failed.append(AccountModel::Email); + hadAuthFailure |= res == AccountModel::Result::AuthError; } - if (m_infoToSave.contains(AccountModel::Administrator) && - !m_model->setData(m_index, m_info->administrator->isChecked(), AccountModel::Administrator)) { + if (m_infoToSave.contains(AccountModel::Administrator) && !hadAuthFailure && + (res = m_model->setDataWithResult(m_index, m_info->administrator->isChecked(), AccountModel::Administrator)) != AccountModel::Result::Ok) { failed.append(AccountModel::Administrator); + hadAuthFailure |= res == AccountModel::Result::AuthError; } - if (m_infoToSave.contains(AccountModel::AutomaticLogin) && - !m_model->setData(m_index, m_info->automaticLogin->isChecked(), AccountModel::AutomaticLogin)) { + if (m_infoToSave.contains(AccountModel::AutomaticLogin) && !hadAuthFailure && + (res = m_model->setDataWithResult(m_index, m_info->automaticLogin->isChecked(), AccountModel::AutomaticLogin)) != AccountModel::Result::Ok) { failed.append(AccountModel::AutomaticLogin); + hadAuthFailure |= res == AccountModel::Result::AuthError; } - if (m_infoToSave.contains(AccountModel::Password)) { - if (!m_model->setData(m_index, m_infoToSave[AccountModel::Password], AccountModel::Password)) { + if (!m_infoToSave.contains(AccountModel::Password)) { + if (!hadAuthFailure && + (res = m_model->setDataWithResult(m_index, m_infoToSave[AccountModel::Password], AccountModel::Password)) != AccountModel::Result::Ok) { failed.append(AccountModel::Password); + hadAuthFailure |= res == AccountModel::Result::AuthError; } } if (m_infoToSave.contains(AccountModel::Face)) { @@ -207,7 +216,7 @@ } if (!failed.isEmpty()) { - qCDebug(USER_MANAGER_LOG) << "Failed Roles: " << failed; + qCDebug(USER_MANAGER_LOG) << "Failed Roles: " << failed << (hadAuthFailure ? " had auth failure" : ""); } m_info->username->setEnabled(false); diff --git a/src/lib/accountmodel.h b/src/lib/accountmodel.h --- a/src/lib/accountmodel.h +++ b/src/lib/accountmodel.h @@ -57,18 +57,24 @@ Created }; + enum Result { + Ok, + Error, + AuthError + }; + explicit AccountModel(QObject* parent); ~AccountModel() override; int rowCount(const QModelIndex& parent = QModelIndex()) const override; QVariant data(const QModelIndex& index, int role) const override; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; - bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; + AccountModel::Result setDataWithResult(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) override; bool removeAccountKeepingFiles(int row, bool keepFile = false); void setDpr(qreal dpr); QVariant newUserData(int role) const; - bool newUserSetData(const QModelIndex& index, const QVariant& value, int roleInt); + Result newUserSetData(const QModelIndex& index, const QVariant& value, int roleInt); public Q_SLOTS: void UserAdded(const QDBusObjectPath &dbusPah); @@ -82,7 +88,7 @@ void addAccountToCache(const QString &path, OrgFreedesktopAccountsUserInterface *acc, int pos = -1); void replaceAccount(const QString &path, OrgFreedesktopAccountsUserInterface *acc, int pos); void removeAccount(const QString &path); - bool checkForErrors(QDBusPendingReply reply) const; + AccountModel::Result checkForErrors(QDBusPendingReply reply) const; QString cryptPassword(const QString &password) const; UserSession* m_sessions; QStringList m_userPath; diff --git a/src/lib/accountmodel.cpp b/src/lib/accountmodel.cpp --- a/src/lib/accountmodel.cpp +++ b/src/lib/accountmodel.cpp @@ -176,67 +176,75 @@ return QVariant(); } -bool AccountModel::setData(const QModelIndex& index, const QVariant& value, int role) +AccountModel::Result AccountModel::setDataWithResult(const QModelIndex& index, const QVariant& value, int role) { - if(!index.isValid()) { - return false; + qDebug() << "AccountModel::setDataWithResult"; + if (!index.isValid()) { + return Result::Error; } if (index.row() >= m_users.count()) { - return false; + return Result::Error; } QString path = m_userPath.at(index.row()); Account* acc = m_users.value(path); if (!acc) { return newUserSetData(index, value, role); } + Result res; switch(role) { //The modification of the face file should be done outside case AccountModel::Face: - if (checkForErrors(acc->SetIconFile(value.toString()))) { - return false; + res = checkForErrors(acc->SetIconFile(value.toString())); + if (res != Result::Ok) { + return res; } emit dataChanged(index, index); - return true; + return Result::Ok; case AccountModel::RealName: - if (checkForErrors(acc->SetRealName(value.toString()))) { - return false; + res = checkForErrors(acc->SetRealName(value.toString())); + if (res != Result::Ok) { + return res; } m_kEmailSettings.setSetting(KEMailSettings::RealName, value.toString()); emit dataChanged(index, index); - return true; + return Result::Ok; case AccountModel::Username: - if (checkForErrors(acc->SetUserName(value.toString()))) { - return false; + res = checkForErrors(acc->SetUserName(value.toString())); + if (res != Result::Ok) { + return res; } emit dataChanged(index, index); - return true; + return Result::Ok; case AccountModel::Password: - if (checkForErrors(acc->SetPassword(cryptPassword(value.toString()), QString()))) { - return false; + res = checkForErrors(acc->SetPassword(cryptPassword(value.toString()), QString())); + if (res != Result::Ok) { + return res; } emit dataChanged(index, index); - return true; + return Result::Ok; case AccountModel::Email: - if (checkForErrors(acc->SetEmail(value.toString()))) { - return false; + res = checkForErrors(acc->SetEmail(value.toString())); + if (res != Result::Ok) { + return res; } m_kEmailSettings.setSetting(KEMailSettings::EmailAddress, value.toString()); emit dataChanged(index, index); - return true; + return Result::Ok; case AccountModel::Administrator: - if (checkForErrors(acc->SetAccountType(value.toBool() ? 1 : 0))) { - return false; + res = checkForErrors(acc->SetAccountType(value.toBool() ? 1 : 0)); + if (res != Result::Ok) { + return res; } emit dataChanged(index, index); - return true; + return Result::Ok; case AccountModel::AutomaticLogin: { const bool autoLoginSet = value.toBool(); @@ -247,31 +255,34 @@ if (autoLoginSet && m_autoLoginSettings.autoLoginUser() != username) { if (m_autoLoginSettings.setAutoLoginUser(username)) { emit dataChanged(createIndex(0, 0), createIndex(rowCount(), 0)); - return true; + return Result::Ok; } - return false; + return Result::Error; } //if the checkbox is not set and the SDDM config is set to us, then clear it else if (!autoLoginSet && m_autoLoginSettings.autoLoginUser() == username) { if (m_autoLoginSettings.setAutoLoginUser(QString())) { emit dataChanged(index, index); - return true; + return Result::Ok; } - return false; + return Result::Error; } - return true; + return Result::Ok; } case AccountModel::Logged: m_loggedAccounts[path] = value.toBool(); emit dataChanged(index, index); - return true; + return Result::Ok; case AccountModel::Created: qFatal("AccountModel NewAccount should never be set"); - return false; - + return Result::Ok; } - return QAbstractItemModel::setData(index, value, role); + if (QAbstractItemModel::setData(index, value, role)) { + return Result::Ok; + } else { + return Result::Error; + } } bool AccountModel::removeRows(int row, int count, const QModelIndex& parent) @@ -293,23 +304,23 @@ QVariant AccountModel::newUserData(int role) const { switch(role) { - case Qt::DisplayRole || AccountModel::FriendlyName: + case Qt::DisplayRole | AccountModel::FriendlyName: return i18n("New User"); - case Qt::DecorationRole || AccountModel::Face: + case Qt::DecorationRole | AccountModel::Face: return QIcon::fromTheme(QStringLiteral("list-add-user")); case AccountModel::Created: return false; } return QVariant(); } -bool AccountModel::newUserSetData(const QModelIndex &index, const QVariant& value, int roleInt) +AccountModel::Result AccountModel::newUserSetData(const QModelIndex &index, const QVariant& value, int roleInt) { AccountModel::Role role = static_cast(roleInt); m_newUserData[role] = value; QList roles = m_newUserData.keys(); if (!roles.contains(Username) || !roles.contains(RealName)) { - return true; + return Result::Ok; } // defaults to non-administrator @@ -325,7 +336,10 @@ qCDebug(USER_MANAGER_LOG) << reply.error().name(); qCDebug(USER_MANAGER_LOG) << reply.error().message(); m_newUserData.clear(); - return false; + if (reply.error().type() == QDBusError::AccessDenied) { + return Result::AuthError; + } + return Result::Error; } m_newUserData.remove(Username); @@ -335,7 +349,7 @@ //If we don't have anything else to set just return if (m_newUserData.isEmpty()) { - return true; + return Result::Ok; } QHash::const_iterator i = m_newUserData.constBegin(); @@ -347,7 +361,7 @@ m_newUserData.clear(); - return true; + return Result::Ok; } void AccountModel::addAccount(const QString& path) @@ -397,16 +411,23 @@ m_loggedAccounts.remove(path); } -bool AccountModel::checkForErrors(QDBusPendingReply reply) const +AccountModel::Result AccountModel::checkForErrors(QDBusPendingReply reply) const { reply.waitForFinished(); if (reply.isError()) { qCDebug(USER_MANAGER_LOG) << reply.error().name(); qCDebug(USER_MANAGER_LOG) << reply.error().message(); - return true; + qDebug() << reply.error().name(); + qDebug() << reply.error().message(); + qDebug() << reply.error().type(); + if (reply.error().type() == QDBusError::AccessDenied) { + return Result::AuthError; + } + return Result::Error; } + qDebug() << reply.isError() << reply.isFinished(); - return false; + return Result::Ok; } QVariant AccountModel::headerData(int section, Qt::Orientation orientation, int role) const