From 6ff2a36700f91a1a0b4a56754cdf2e817289036d Mon Sep 17 00:00:00 2001
From: Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com>
Date: Tue, 10 Mar 2015 16:04:07 -0400
Subject: [PATCH] account: Restore path based accessors for certificate

They will complement the Certificate* based ones

Refs #67838
---
 src/account.cpp            | 33 +++++++++++++++++++++++++++------
 src/account.h              |  9 ++++++---
 src/accountstatusmodel.cpp |  2 +-
 3 files changed, 34 insertions(+), 10 deletions(-)

diff --git a/src/account.cpp b/src/account.cpp
index 4c30853c..7e40e9c1 100644
--- a/src/account.cpp
+++ b/src/account.cpp
@@ -1054,25 +1054,46 @@ void Account::setTlsPassword(const QString& detail)
    d_ptr->setAccountProperty(DRing::Account::ConfProperties::TLS::PASSWORD, detail);
 }
 
+///Set the certificate authority list file
+void Account::setTlsCaListCertificate(const QString& path)
+{
+   Certificate* cert = CertificateModel::instance()->getCertificate(path);
+   setTlsCaListCertificate(cert);
+}
+
+///Set the certificate
+void Account::setTlsCertificate(const QString& path)
+{
+   Certificate* cert = CertificateModel::instance()->getCertificate(path);
+   setTlsCertificate(cert);
+}
+
+///Set the private key
+void Account::setTlsPrivateKeyCertificate(const QString& path)
+{
+   Certificate* cert = CertificateModel::instance()->getCertificate(path);
+   setTlsPrivateKeyCertificate(cert);
+}
+
 ///Set the certificate authority list file
 void Account::setTlsCaListCertificate(Certificate* cert)
 {
-   d_ptr->m_pCaCert = cert; //FIXME memory leak
-   d_ptr->setAccountProperty(DRing::Account::ConfProperties::TLS::CA_LIST_FILE, cert?cert->path().toLocalFile():QString());
+   d_ptr->m_pCaCert = cert;
+   d_ptr->setAccountProperty(DRing::Account::ConfProperties::TLS::CA_LIST_FILE, cert?cert->path().path():QString());
 }
 
 ///Set the certificate
 void Account::setTlsCertificate(Certificate* cert)
 {
-   d_ptr->m_pTlsCert = cert; //FIXME memory leak
-   d_ptr->setAccountProperty(DRing::Account::ConfProperties::TLS::CERTIFICATE_FILE, cert?cert->path().toLocalFile():QString());
+   d_ptr->m_pTlsCert = cert;
+   d_ptr->setAccountProperty(DRing::Account::ConfProperties::TLS::CERTIFICATE_FILE, cert?cert->path().path():QString());
 }
 
 ///Set the private key
 void Account::setTlsPrivateKeyCertificate(Certificate* cert)
 {
-   d_ptr->m_pPrivateKey = cert; //FIXME memory leak
-   d_ptr->setAccountProperty(DRing::Account::ConfProperties::TLS::PRIVATE_KEY_FILE, cert?cert->path().toLocalFile():QString());
+   d_ptr->m_pPrivateKey = cert;
+   d_ptr->setAccountProperty(DRing::Account::ConfProperties::TLS::PRIVATE_KEY_FILE, cert?cert->path().path():QString());
 }
 
 ///Set the TLS server
diff --git a/src/account.h b/src/account.h
index 4ea0b842..998a9687 100644
--- a/src/account.h
+++ b/src/account.h
@@ -91,9 +91,9 @@ class LIB_EXPORT Account : public QObject {
    Q_PROPERTY(QString        mailbox                      READ mailbox                       WRITE setMailbox                     )
    Q_PROPERTY(QString        proxy                        READ proxy                         WRITE setProxy                       )
    Q_PROPERTY(QString        tlsPassword                  READ tlsPassword                   WRITE setTlsPassword                 )
-//    Q_PROPERTY(QString        tlsCaListFile                READ tlsCaListFile                 WRITE setTlsCaListFile               )
-//    Q_PROPERTY(QString        tlsCertificateFile           READ tlsCertificateFile            WRITE setTlsCertificateFile          )
-//    Q_PROPERTY(QString        tlsPrivateKeyFile            READ tlsPrivateKeyFile             WRITE setTlsPrivateKeyFile           )
+   Q_PROPERTY(Certificate*   tlsCaListCertificate         READ tlsCaListCertificate          WRITE setTlsCaListCertificate        )
+   Q_PROPERTY(Certificate*   tlsCertificate               READ tlsCertificate                WRITE setTlsCertificate              )
+   Q_PROPERTY(Certificate*   tlsPrivateKeyCertificate     READ tlsPrivateKeyCertificate      WRITE setTlsPrivateKeyCertificate    )
    Q_PROPERTY(QString        tlsServerName                READ tlsServerName                 WRITE setTlsServerName               )
    Q_PROPERTY(QString        sipStunServer                READ sipStunServer                 WRITE setSipStunServer               )
    Q_PROPERTY(QString        publishedAddress             READ publishedAddress              WRITE setPublishedAddress            )
@@ -332,6 +332,9 @@ class LIB_EXPORT Account : public QObject {
       void setTlsCaListCertificate          (Certificate* cert      );
       void setTlsCertificate                (Certificate* cert      );
       void setTlsPrivateKeyCertificate      (Certificate* cert      );
+      void setTlsCaListCertificate          (const QString& detail  );
+      void setTlsCertificate                (const QString& detail  );
+      void setTlsPrivateKeyCertificate      (const QString& detail  );
       void setTlsServerName                 (const QString& detail  );
       void setSipStunServer                 (const QString& detail  );
       void setPublishedAddress              (const QString& detail  );
diff --git a/src/accountstatusmodel.cpp b/src/accountstatusmodel.cpp
index db91f0c4..be13ab4b 100644
--- a/src/accountstatusmodel.cpp
+++ b/src/accountstatusmodel.cpp
@@ -430,7 +430,7 @@ void AccountStatusModel::addSipRegistrationEvent(const QString& fallbackMessage,
 
 void AccountStatusModel::addTransportEvent(const QString& fallbackMessage, int errorCode)
 {
-   if (!d_ptr->m_lRows.size() || errorCode != d_ptr->m_pAccount->lastTransportErrorCode()) {
+   if ((!d_ptr->m_lRows.size()) || errorCode != d_ptr->m_pAccount->lastTransportErrorCode()) {
       beginInsertRows(QModelIndex(), d_ptr->m_lRows.size(), d_ptr->m_lRows.size());
       d_ptr->m_lRows << new AccountStatusRow(fallbackMessage, errorCode, Type::TRANSPORT);
       endInsertRows();
-- 
GitLab