void CoreAccountModel::update(const CoreAccountModel *other) {
clear();
- beginInsertRows(QModelIndex(), 0, other->_accounts.count() -1);
+ if (other->_accounts.count() > 0) {
+ beginInsertRows(QModelIndex(), 0, other->_accounts.count() -1);
+ _accounts = other->_accounts;
+ endInsertRows();
+ }
_internalAccount = other->internalAccount();
- _accounts = other->_accounts;
- endInsertRows();
+ _removedAccounts = other->_removedAccounts;
}
void CoreAccountModel::load() {
void CoreAccountModel::save() {
CoreAccountSettings s;
- s.clearAccounts();
+ foreach(AccountId id, _removedAccounts) {
+ s.removeAccount(id);
+ }
+ _removedAccounts.clear();
foreach(const CoreAccount &acc, accounts()) {
QVariantMap map = acc.toVariantMap(false); // TODO Hook into kwallet/password saving stuff
s.storeAccountData(acc.accountId(), map);
AccountId newId = 0;
const QList<AccountId> &ids = accountIds();
for(int i = 1; ; i++) {
- if(!ids.contains(i)) {
+ if(!_removedAccounts.contains(i) && !ids.contains(i)) {
newId = i;
break;
}
void CoreAccountModel::removeAccount(AccountId accId) {
takeAccount(accId);
+ _removedAccounts.insert(accId);
}
QModelIndex CoreAccountModel::accountIndex(AccountId accId) const {