Account: Save accepted SSL certs immediatly #3617
authorMarkus Goetz <markus@woboq.com>
Fri, 14 Aug 2015 09:31:01 +0000 (11:31 +0200)
committerMarkus Goetz <markus@woboq.com>
Fri, 14 Aug 2015 09:31:01 +0000 (11:31 +0200)
src/gui/accountmanager.cpp
src/gui/accountmanager.h
src/libsync/account.cpp
src/libsync/account.h

index a90ab9e65d0ee1724e1aac4545e5edb0a7947fab..1ef1935c295522885117df39330d708c8624792e 100644 (file)
@@ -129,6 +129,14 @@ void AccountManager::save(bool saveCredentials)
     }
 }
 
+void AccountManager::wantsAccountSavedSlot(AccountPtr a)
+{
+    auto settings = Account::settingsWithGroup(QLatin1String(accountsC));
+    settings->beginGroup(a->id());
+    save(a, *settings, true);
+    settings->endGroup();
+}
+
 void AccountManager::save(const AccountPtr& acc, QSettings& settings, bool saveCredentials)
 {
     settings.setValue(QLatin1String(urlC), acc->_url.toString());
@@ -206,6 +214,9 @@ AccountState *AccountManager::addAccount(const AccountPtr& newAccount)
     }
     newAccount->_id = id;
 
+    QObject::connect(newAccount.data(), SIGNAL(wantsAccountSaved(AccountPtr)),
+            this, SLOT(wantsAccountSavedSlot(AccountPtr)));
+
     AccountStatePtr newAccountState(new AccountState(newAccount));
     _accounts << newAccountState;
     emit accountAdded(newAccountState.data());
index 033ec2a29ebad750ee1feb50de67db3aaaac1c8d..eed8e43e37c685e077bfed5e4a92d8f3ef30710f 100644 (file)
@@ -78,6 +78,9 @@ private:
     bool isAccountIdAvailable(const QString& id) const;
     QString generateFreeAccountId() const;
 
+public slots:
+    void wantsAccountSavedSlot(AccountPtr a);
+
 
 Q_SIGNALS:
     void accountAdded(AccountState *account);
index 690925277da6fcef362a32409757ae76f6d3e8a1..1c75a08abcee7a2d1db3746e2709bef53f2ac95c 100644 (file)
@@ -399,6 +399,7 @@ void Account::slotHandleSslErrors(QNetworkReply *reply , QList<QSslError> errors
     if (_sslErrorHandler->handleErrors(errors, reply->sslConfiguration(), &approvedCerts, sharedFromThis())) {
         QSslSocket::addDefaultCaCertificates(approvedCerts);
         addApprovedCerts(approvedCerts);
+        emit wantsAccountSaved(sharedFromThis());
         // all ssl certs are known and accepted. We can ignore the problems right away.
 //         qDebug() << out << "Certs are known and trusted! This is not an actual error.";
 
index c64ea3f572ffa1d78733752e4eaae9959ea4c0a8..4f98aa8390d16fea424b83d6d91be696bbbc09e6 100644 (file)
@@ -167,6 +167,9 @@ signals:
     /// Forwards from QNetworkAccessManager::proxyAuthenticationRequired().
     void proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*);
 
+    // e.g. when the approved SSL certificates changed
+    void wantsAccountSaved(AccountPtr acc);
+
 protected Q_SLOTS:
     void slotHandleSslErrors(QNetworkReply*,QList<QSslError>);
     void slotCredentialsFetched();