- : QAbstractListModel(parent),
- _internalAccount(0)
-{
- update(other);
-}
-
-void CoreAccountModel::update(const CoreAccountModel *other) {
- clear();
- beginInsertRows(QModelIndex(), 0, other->_accounts.count() -1);
- _internalAccount = other->internalAccount();
- _accounts = other->_accounts;
- endInsertRows();
-}
-
-void CoreAccountModel::load() {
- clear();
- CoreAccountSettings s;
- foreach(AccountId accId, s.knownAccounts()) {
- QVariantMap map = s.retrieveAccountData(accId);
- CoreAccount acc;
- acc.fromVariantMap(map); // TODO Hook into kwallet/password saving stuff
- insertAccount(acc);
- }
- if(Quassel::runMode() == Quassel::Monolithic && !internalAccount().isValid()) {
- // Make sure we have an internal account in monolithic mode
- CoreAccount intAcc;
- intAcc.setInternal(true);
- insertAccount(intAcc);
- }
-}
-
-void CoreAccountModel::save() {
- CoreAccountSettings s;
- foreach(const CoreAccount &acc, accounts()) {
- if(acc.isInternal())
- continue; // FIXME don't save internal for now - but make sure to handle this correctly once mono can do remotes!
- // we'll have to ensure that autoConnectAccount works with internal as well then
- QVariantMap map = acc.toVariantMap(true); // TODO Hook into kwallet/password saving stuff
- s.storeAccountData(acc.accountId(), map);
- }
-}
-
-void CoreAccountModel::clear() {
- if(rowCount()) {
- beginRemoveRows(QModelIndex(), 0, rowCount()-1);
- _internalAccount = 0;
- _accounts.clear();
- endRemoveRows();
- }