diff --git a/src/account.cpp b/src/account.cpp index a1be8ca50f478d2ded53bd730dda417be9c1cec0..f6af5e45bcd3231b91bd4e89e1a33a9ba081676d 100644 --- a/src/account.cpp +++ b/src/account.cpp @@ -137,6 +137,29 @@ void Account::slotPresenceMessageChanged(const QString& message) emit changed(this); } +void Account::slotUpdateCertificate() +{ + Certificate* cert = qobject_cast<Certificate*>(sender()); + if (cert) { + switch (cert->type()) { + case Certificate::Type::AUTHORITY: + if (accountDetail(Account::MapField::TLS::CA_LIST_FILE) != cert->path().toString()) + setAccountDetail(Account::MapField::TLS::CA_LIST_FILE, cert->path().toString()); + break; + case Certificate::Type::USER: + if (accountDetail(Account::MapField::TLS::CERTIFICATE_FILE) != cert->path().toString()) + setAccountDetail(Account::MapField::TLS::CERTIFICATE_FILE, cert->path().toString()); + break; + case Certificate::Type::PRIVATE_KEY: + if (accountDetail(Account::MapField::TLS::PRIVATE_KEY_FILE) != cert->path().toString()) + setAccountDetail(Account::MapField::TLS::PRIVATE_KEY_FILE, cert->path().toString()); + break; + case Certificate::Type::NONE: + break; + }; + } +} + /***************************************************************************** * * * Getters * @@ -467,8 +490,10 @@ int Account::tlsListenerPort() const ///Return the account TLS certificate authority list file Certificate* Account::tlsCaListCertificate() const { - if (!m_pCaCert) + if (!m_pCaCert) { const_cast<Account*>(this)->m_pCaCert = new Certificate(Certificate::Type::AUTHORITY,this); + connect(m_pCaCert,SIGNAL(changed()),this,SLOT(slotUpdateCertificate())); + } const_cast<Account*>(this)->m_pCaCert->setPath(accountDetail(Account::MapField::TLS::CA_LIST_FILE)); return m_pCaCert; } @@ -476,8 +501,10 @@ Certificate* Account::tlsCaListCertificate() const ///Return the account TLS certificate Certificate* Account::tlsCertificate() const { - if (!m_pTlsCert) + if (!m_pTlsCert) { const_cast<Account*>(this)->m_pTlsCert = new Certificate(Certificate::Type::USER,this); + connect(m_pTlsCert,SIGNAL(changed()),this,SLOT(slotUpdateCertificate())); + } const_cast<Account*>(this)->m_pTlsCert->setPath(accountDetail(Account::MapField::TLS::CERTIFICATE_FILE)); return m_pTlsCert; } @@ -485,8 +512,10 @@ Certificate* Account::tlsCertificate() const ///Return the account private key Certificate* Account::tlsPrivateKeyCertificate() const { - if (!m_pPrivateKey) + if (!m_pPrivateKey) { const_cast<Account*>(this)->m_pPrivateKey = new Certificate(Certificate::Type::PRIVATE_KEY,this); + connect(m_pPrivateKey,SIGNAL(changed()),this,SLOT(slotUpdateCertificate())); + } const_cast<Account*>(this)->m_pPrivateKey->setPath(accountDetail(Account::MapField::TLS::PRIVATE_KEY_FILE)); return m_pPrivateKey; } @@ -887,18 +916,21 @@ void Account::setTlsPassword(const QString& detail) ///Set the certificate authority list file void Account::setTlsCaListCertificate(Certificate* cert) { + m_pCaCert = cert; //FIXME memory leak setAccountDetail(Account::MapField::TLS::CA_LIST_FILE, cert?cert->path().toLocalFile():QString()); } ///Set the certificate void Account::setTlsCertificate(Certificate* cert) { + m_pTlsCert = cert; //FIXME memory leak setAccountDetail(Account::MapField::TLS::CERTIFICATE_FILE, cert?cert->path().toLocalFile():QString()); } ///Set the private key void Account::setTlsPrivateKeyCertificate(Certificate* cert) { + m_pPrivateKey = cert; //FIXME memory leak setAccountDetail(Account::MapField::TLS::PRIVATE_KEY_FILE, cert?cert->path().toLocalFile():QString()); } diff --git a/src/account.h b/src/account.h index 81f83d12c4154e4e61cf87704b7dae437ab585d4..0c9aca6d10db063f83abb8137a730dedcbd02b50 100644 --- a/src/account.h +++ b/src/account.h @@ -466,6 +466,7 @@ class LIB_EXPORT Account : public QObject { private Q_SLOTS: void slotPresentChanged (bool present ); void slotPresenceMessageChanged(const QString& ); + void slotUpdateCertificate ( ); private: //Constructors diff --git a/src/certificate.cpp b/src/certificate.cpp index b40f76c3fb309265a7d2e5d38aa2cb47a950daae..4570537b46e07aa1f33923ed17bea98a0cb87038 100644 --- a/src/certificate.cpp +++ b/src/certificate.cpp @@ -38,6 +38,7 @@ QUrl Certificate::path() const void Certificate::setPath(const QUrl& path) { m_Path = path; + emit changed(); } bool Certificate::isExpired() const diff --git a/src/certificate.h b/src/certificate.h index 14b6850906cc3e74e2470690ca6b14b5471e0bcd..753ae7d42725cbafd39988e57e91e0b14a360b05 100644 --- a/src/certificate.h +++ b/src/certificate.h @@ -58,6 +58,9 @@ private: QUrl m_Path; Certificate::Type m_Type; //TODO + +Q_SIGNALS: + void changed(); }; Q_DECLARE_METATYPE(Certificate*)