Commit 437de5df authored by Tomi Leppänen's avatar Tomi Leppänen

[nemo-systemsettings] Add ErrorType enum to UserModel. Contributes to JB#49466

Remove name argument from failure signals as it wasn't used anyway and
that information can be obtained by knowing which row is affected.
Signed-off-by: Tomi Leppänen's avatarTomi Leppänen <tomi.leppanen@jolla.com>
parent b138822c
...@@ -42,13 +42,32 @@ ...@@ -42,13 +42,32 @@
#include <QString> #include <QString>
#include <functional> #include <functional>
#include <sailfishusermanagerinterface.h> #include <sailfishusermanagerinterface.h>
#include <grp.h>
#include <sys/types.h> #include <sys/types.h>
#include <grp.h>
namespace { namespace {
const auto UserManagerService = QStringLiteral(SAILFISH_USERMANAGER_DBUS_INTERFACE); const auto UserManagerService = QStringLiteral(SAILFISH_USERMANAGER_DBUS_INTERFACE);
const auto UserManagerPath = QStringLiteral(SAILFISH_USERMANAGER_DBUS_OBJECT_PATH); const auto UserManagerPath = QStringLiteral(SAILFISH_USERMANAGER_DBUS_OBJECT_PATH);
const auto UserManagerInterface = QStringLiteral(SAILFISH_USERMANAGER_DBUS_INTERFACE); const auto UserManagerInterface = QStringLiteral(SAILFISH_USERMANAGER_DBUS_INTERFACE);
const QHash<const QString, int> errorTypeMap = {
{ QStringLiteral(SailfishUserManagerErrorBusy), UserModel::Busy },
{ QStringLiteral(SailfishUserManagerErrorHomeCreateFailed), UserModel::HomeCreateFailed },
{ QStringLiteral(SailfishUserManagerErrorHomeRemoveFailed), UserModel::HomeRemoveFailed },
{ QStringLiteral(SailfishUserManagerErrorGroupCreateFailed), UserModel::GroupCreateFailed },
{ QStringLiteral(SailfishUserManagerErrorUserAddFailed), UserModel::UserAddFailed },
{ QStringLiteral(SailfishUserManagerErrorUserModifyFailed), UserModel::UserModifyFailed },
{ QStringLiteral(SailfishUserManagerErrorUserRemoveFailed), UserModel::UserRemoveFailed },
{ QStringLiteral(SailfishUserManagerErrorGetUidFailed), UserModel::GetUidFailed },
};
int getErrorType(QDBusError &error)
{
if (error.type() != QDBusError::Other)
return error.type();
return errorTypeMap.value(error.name(), UserModel::OtherError);
}
} }
UserModel::UserModel(QObject *parent) UserModel::UserModel(QObject *parent)
...@@ -93,12 +112,12 @@ void UserModel::setPlaceholder(bool value) ...@@ -93,12 +112,12 @@ void UserModel::setPlaceholder(bool value)
return; return;
if (value) { if (value) {
auto row = m_users.count(); int row = m_users.count();
beginInsertRows(QModelIndex(), row, row); beginInsertRows(QModelIndex(), row, row);
m_users.append(UserInfo::placeholder()); m_users.append(UserInfo::placeholder());
endInsertRows(); endInsertRows();
} else { } else {
auto row = m_users.count()-1; int row = m_users.count()-1;
beginRemoveRows(QModelIndex(), row, row); beginRemoveRows(QModelIndex(), row, row);
m_users.remove(row); m_users.remove(row);
endRemoveRows(); endRemoveRows();
...@@ -325,7 +344,7 @@ void UserModel::onCurrentUserChangeFailed(uint uid) ...@@ -325,7 +344,7 @@ void UserModel::onCurrentUserChangeFailed(uint uid)
{ {
if (m_uidsToRows.contains(uid)) { if (m_uidsToRows.contains(uid)) {
int row = m_uidsToRows[uid]; int row = m_uidsToRows[uid];
emit setCurrentUserFailed(row, m_users[row].name()); emit setCurrentUserFailed(row, Failure);
} }
} }
...@@ -333,8 +352,9 @@ void UserModel::userAddFinished(QDBusPendingCallWatcher *call, int row) ...@@ -333,8 +352,9 @@ void UserModel::userAddFinished(QDBusPendingCallWatcher *call, int row)
{ {
QDBusPendingReply<uint> reply = *call; QDBusPendingReply<uint> reply = *call;
if (reply.isError()) { if (reply.isError()) {
emit userAddFailed(); auto error = reply.error();
qWarning() << "Adding user with usermanager failed:" << reply.error(); emit userAddFailed(getErrorType(error));
qCWarning(lcUsersLog) << "Adding user with usermanager failed:" << error;
} else { } else {
uint uid = reply.value(); uint uid = reply.value();
// Check that this was not just added to the list by onUserAdded // Check that this was not just added to the list by onUserAdded
...@@ -354,8 +374,9 @@ void UserModel::userModifyFinished(QDBusPendingCallWatcher *call, int row) ...@@ -354,8 +374,9 @@ void UserModel::userModifyFinished(QDBusPendingCallWatcher *call, int row)
{ {
QDBusPendingReply<void> reply = *call; QDBusPendingReply<void> reply = *call;
if (reply.isError()) { if (reply.isError()) {
emit userModifyFailed(row, m_users.at(row).name()); auto error = reply.error();
qWarning() << "Modifying user with usermanager failed:" << reply.error(); emit userModifyFailed(row, getErrorType(error));
qCWarning(lcUsersLog) << "Modifying user with usermanager failed:" << error;
reset(row); reset(row);
} // else awesome! (data was changed already) } // else awesome! (data was changed already)
call->deleteLater(); call->deleteLater();
...@@ -365,8 +386,9 @@ void UserModel::userRemoveFinished(QDBusPendingCallWatcher *call, int row) ...@@ -365,8 +386,9 @@ void UserModel::userRemoveFinished(QDBusPendingCallWatcher *call, int row)
{ {
QDBusPendingReply<void> reply = *call; QDBusPendingReply<void> reply = *call;
if (reply.isError()) { if (reply.isError()) {
emit userRemoveFailed(row, m_users.at(row).name()); auto error = reply.error();
qWarning() << "Removing user with usermanager failed:" << reply.error(); emit userRemoveFailed(row, getErrorType(error));
qCWarning(lcUsersLog) << "Removing user with usermanager failed:" << error;
} // else awesome! (waiting for signal to alter data) } // else awesome! (waiting for signal to alter data)
call->deleteLater(); call->deleteLater();
} }
...@@ -375,8 +397,9 @@ void UserModel::setCurrentUserFinished(QDBusPendingCallWatcher *call, int row) ...@@ -375,8 +397,9 @@ void UserModel::setCurrentUserFinished(QDBusPendingCallWatcher *call, int row)
{ {
QDBusPendingReply<void> reply = *call; QDBusPendingReply<void> reply = *call;
if (reply.isError()) { if (reply.isError()) {
emit setCurrentUserFailed(row, m_users.at(row).name()); auto error = reply.error();
qWarning() << "Switching user with usermanager failed:" << reply.error(); emit setCurrentUserFailed(row, getErrorType(error));
qCWarning(lcUsersLog) << "Switching user with usermanager failed:" << error;
} // else user switching was initiated successfully } // else user switching was initiated successfully
call->deleteLater(); call->deleteLater();
} }
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#define USERMODEL_H #define USERMODEL_H
#include <QAbstractListModel> #include <QAbstractListModel>
#include <QDBusError>
#include <QHash> #include <QHash>
#include <QVector> #include <QVector>
...@@ -66,6 +67,21 @@ public: ...@@ -66,6 +67,21 @@ public:
}; };
Q_ENUM(UserType) Q_ENUM(UserType)
enum ErrorType {
Failure = QDBusError::Failed,
OtherError = QDBusError::Other,
InvalidArgs = QDBusError::InvalidArgs,
Busy = 100,
HomeCreateFailed,
HomeRemoveFailed,
GroupCreateFailed,
UserAddFailed,
UserModifyFailed,
UserRemoveFailed,
GetUidFailed,
};
Q_ENUM(ErrorType)
explicit UserModel(QObject *parent = 0); explicit UserModel(QObject *parent = 0);
~UserModel(); ~UserModel();
...@@ -86,10 +102,10 @@ public: ...@@ -86,10 +102,10 @@ public:
signals: signals:
void placeholderChanged(); void placeholderChanged();
void userAddFailed(); void userAddFailed(int error);
void userModifyFailed(int row, const QString &name); void userModifyFailed(int row, int error);
void userRemoveFailed(int row, const QString &name); void userRemoveFailed(int row, int error);
void setCurrentUserFailed(int row, const QString &name); void setCurrentUserFailed(int row, int error);
private slots: private slots:
void onUserAdded(const SailfishUserManagerEntry &entry); void onUserAdded(const SailfishUserManagerEntry &entry);
......
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