Commit 1d10226d authored by Àlex Fiestas's avatar Àlex Fiestas
Browse files

Added AccountModel::setData

Atm the only property we are not updating is the Face
since there is no GUI for it.
parent 5cd8047f
......@@ -117,6 +117,90 @@ QVariant AccountModel::data(const QModelIndex& index, int role) const
return QVariant();
}
bool AccountModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
if(!index.isValid()) {
return false;
}
if (index.row() >= m_users.count()) {
return false;
}
Account* acc = m_users.value(m_userPath.at(index.row()));
if (!acc) {
return false;
}
if (role == AccountModel::RealName) {
QDBusPendingReply <void > reply = acc->SetRealName(value.toString());
reply.waitForFinished();
if (reply.isError()) {
qDebug() << reply.error().name();
qDebug() << reply.error().message();
return false;
}
emit dataChanged(index, index);
return true;
}
if (role == AccountModel::Username) {
QDBusPendingReply <void > reply = acc->SetUserName(value.toString());
reply.waitForFinished();
if (reply.isError()) {
qDebug() << reply.error().name();
qDebug() << reply.error().message();
return false;
}
emit dataChanged(index, index);
return true;
}
if (role == AccountModel::Email) {
QDBusPendingReply <void > reply = acc->SetEmail(value.toString());
reply.waitForFinished();
if (reply.isError()) {
qDebug() << reply.error().name();
qDebug() << reply.error().message();
return false;
}
emit dataChanged(index, index);
return true;
}
if (role == AccountModel::Administrator) {
int userType = value.toBool() ? 1 : 0;
QDBusPendingReply <void > reply = acc->SetAccountType(userType);
reply.waitForFinished();
if (reply.isError()) {
qDebug() << reply.error().name();
qDebug() << reply.error().message();
return false;
}
emit dataChanged(index, index);
return true;
}
if (role == AccountModel::AutomaticLogin) {
QDBusPendingReply <void > reply = acc->SetAutomaticLogin(value.toBool());
reply.waitForFinished();
if (reply.isError()) {
qDebug() << reply.error().name();
qDebug() << reply.error().message();
return false;
}
emit dataChanged(index, index);
return true;
}
return QAbstractItemModel::setData(index, value, role);
}
QVariant AccountModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role != Qt::DisplayRole) {
......
......@@ -45,6 +45,7 @@ class AccountModel : public QAbstractListModel
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex& index, int role) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
public Q_SLOTS:
void UserAdded(const QDBusObjectPath &path);
......
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