diff --git a/src/lib/accountmodel.h b/src/lib/accountmodel.h --- a/src/lib/accountmodel.h +++ b/src/lib/accountmodel.h @@ -79,6 +79,7 @@ const QString accountPathForUid(uint uid) const; void addAccount(const QString &path); 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; QString cryptPassword(const QString &password) const; diff --git a/src/lib/accountmodel.cpp b/src/lib/accountmodel.cpp --- a/src/lib/accountmodel.cpp +++ b/src/lib/accountmodel.cpp @@ -93,8 +93,8 @@ addAccount(path.path()); } - //Adding fake "new user" directly into cache - addAccountToCache("new-user", 0); + // Adding fake "new user" directly into cache + addAccountToCache("new-user", nullptr); m_kEmailSettings.setProfile(m_kEmailSettings.defaultProfileName()); @@ -368,19 +368,25 @@ void AccountModel::addAccountToCache(const QString& path, Account* acc, int pos) { if (pos > -1) { - if (m_userPath.count() > 0) { - m_userPath.replace(pos, path); - } else { - m_userPath.insert(pos, path); - } + m_userPath.insert(pos, path); } else { m_userPath.append(path); } m_users.insert(path, acc); m_loggedAccounts[path] = false; } +void AccountModel::replaceAccount(const QString &path, OrgFreedesktopAccountsUserInterface *acc, int pos) +{ + if (pos >= m_userPath.size() || pos < 0) { + return; + } + m_userPath.replace(pos, path); + + m_users.insert(path, acc); + m_loggedAccounts[path] = false; +} void AccountModel::removeAccount(const QString& path) { @@ -429,13 +435,13 @@ } connect(acc, SIGNAL(Changed()), SLOT(Changed())); - //First, we modify "new-user" to become the new created user + // First, we modify "new-user" to become the new created user int row = rowCount(); - addAccountToCache(path, acc, row - 1); + replaceAccount(path, acc, row - 1); QModelIndex changedIndex = index(row - 1, 0); emit dataChanged(changedIndex, changedIndex); - //Then we add new-user again. + // Then we add new-user again. beginInsertRows(QModelIndex(), row, row); addAccountToCache("new-user", 0); endInsertRows();