Handle removal of accounts a bit better
authorManuel Nickschas <sputnick@quassel-irc.org>
Wed, 25 Nov 2009 21:37:45 +0000 (22:37 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sat, 28 Nov 2009 23:39:41 +0000 (00:39 +0100)
We don't want to always clear and rewrite them all, in order to not lose additional
accountValues. So remember which accounts have been removed from the model, and only
delete those.

Also, useSsl should be on by default.

src/client/clientsettings.h
src/client/coreaccount.cpp
src/client/coreaccountmodel.cpp
src/client/coreaccountmodel.h

index 0e4b410..6aacdfe 100644 (file)
@@ -73,7 +73,6 @@ public:
   void setJumpKeyMap(const QHash<int, BufferId> &keyMap);
   QHash<int, BufferId> jumpKeyMap();
 
   void setJumpKeyMap(const QHash<int, BufferId> &keyMap);
   QHash<int, BufferId> jumpKeyMap();
 
-protected:
   void setAccountValue(const QString &key, const QVariant &data);
   QVariant accountValue(const QString &key, const QVariant &def = QVariant());
 
   void setAccountValue(const QString &key, const QVariant &data);
   QVariant accountValue(const QString &key, const QVariant &def = QVariant());
 
index d0c8a53..a9444ce 100644 (file)
@@ -25,7 +25,7 @@ CoreAccount::CoreAccount(AccountId accountId) {
   _internal = false;
   _port = 4242;
   _storePassword = false;
   _internal = false;
   _port = 4242;
   _storePassword = false;
-  _useSsl = false;
+  _useSsl = true;
   _useProxy = false;
   _proxyType = QNetworkProxy::Socks5Proxy;
   _proxyPort = 8080;
   _useProxy = false;
   _proxyType = QNetworkProxy::Socks5Proxy;
   _proxyPort = 8080;
index 1734c78..1ab159c 100644 (file)
@@ -42,6 +42,7 @@ void CoreAccountModel::update(const CoreAccountModel *other) {
   beginInsertRows(QModelIndex(), 0, other->_accounts.count() -1);
   _internalAccount = other->internalAccount();
   _accounts = other->_accounts;
   beginInsertRows(QModelIndex(), 0, other->_accounts.count() -1);
   _internalAccount = other->internalAccount();
   _accounts = other->_accounts;
+  _removedAccounts = other->_removedAccounts;
   endInsertRows();
 }
 
   endInsertRows();
 }
 
@@ -65,7 +66,10 @@ void CoreAccountModel::load() {
 
 void CoreAccountModel::save() {
   CoreAccountSettings s;
 
 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);
   foreach(const CoreAccount &acc, accounts()) {
     QVariantMap map = acc.toVariantMap(false);  // TODO Hook into kwallet/password saving stuff
     s.storeAccountData(acc.accountId(), map);
@@ -141,7 +145,7 @@ AccountId CoreAccountModel::createOrUpdateAccount(const CoreAccount &newAcc) {
     AccountId newId = 0;
     const QList<AccountId> &ids = accountIds();
     for(int i = 1; ; i++) {
     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;
       }
         newId = i;
         break;
       }
@@ -200,6 +204,7 @@ CoreAccount CoreAccountModel::takeAccount(AccountId accId) {
 
 void CoreAccountModel::removeAccount(AccountId accId) {
   takeAccount(accId);
 
 void CoreAccountModel::removeAccount(AccountId accId) {
   takeAccount(accId);
+  _removedAccounts.insert(accId);
 }
 
 QModelIndex CoreAccountModel::accountIndex(AccountId accId) const {
 }
 
 QModelIndex CoreAccountModel::accountIndex(AccountId accId) const {
index 0dc22cf..1c31469 100644 (file)
@@ -70,8 +70,8 @@ private:
   int listIndex(AccountId);
 
   QList<CoreAccount> _accounts;
   int listIndex(AccountId);
 
   QList<CoreAccount> _accounts;
+  QSet<AccountId> _removedAccounts;
   AccountId _internalAccount;
   AccountId _internalAccount;
-
 };
 
 // Inlines
 };
 
 // Inlines