X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fclientidentity.cpp;fp=src%2Fclient%2Fclientidentity.cpp;h=1d93d64b73dbf38e257c8e879af275dde1f24fd6;hp=0000000000000000000000000000000000000000;hb=ac21cc48d22f0cf58a98b74754fa94564a8e3f45;hpb=4493458caaa821deb69a0cddf13beb98394977bb diff --git a/src/client/clientidentity.cpp b/src/client/clientidentity.cpp new file mode 100644 index 00000000..1d93d64b --- /dev/null +++ b/src/client/clientidentity.cpp @@ -0,0 +1,99 @@ +/*************************************************************************** + * Copyright (C) 2005-08 by the Quassel Project * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "clientidentity.h" + +#include "client.h" +#include "signalproxy.h" + +CertIdentity::CertIdentity(IdentityId id, QObject *parent) + : Identity(id, parent), + _certManager(0), + _isDirty(false) +{ +} + +CertIdentity::CertIdentity(const Identity &other, QObject *parent) + : Identity(other, parent), + _certManager(0), + _isDirty(false) +{ +} + +CertIdentity::CertIdentity(const CertIdentity &other, QObject *parent) + : Identity(other, parent), + _certManager(0), + _isDirty(other._isDirty), + _sslKey(other._sslKey), + _sslCert(other._sslCert) +{ +} + +void CertIdentity::enableEditSsl(bool enable) { + if(!enable || _certManager) + return; + + _certManager = new ClientCertManager(id(), this); + if(isValid()) { // this means we are not a newly created Identity but have a proper Id + Client::signalProxy()->synchronize(_certManager); + connect(_certManager, SIGNAL(updated(const QVariantMap &)), this, SLOT(markClean())); + connect(_certManager, SIGNAL(initDone()), this, SLOT(markClean())); + } +} + +void CertIdentity::setSslKey(const QSslKey &key) { + if(key.toPem() == _sslKey.toPem()) + return; + _sslKey = key; + _isDirty = true; +} + +void CertIdentity::setSslCert(const QSslCertificate &cert) { + if(cert.toPem() == _sslCert.toPem()) + return; + _sslCert = cert; + _isDirty = true; +} + +void CertIdentity::requestUpdateSslSettings() { + if(!_certManager) + return; + + _certManager->requestUpdate(_certManager->toVariantMap()); +} + +void CertIdentity::markClean() { + _isDirty = false; + emit sslSettingsUpdated(); +} + +// ======================================== +// ClientCertManager +// ======================================== +void ClientCertManager::setSslKey(const QByteArray &encoded) { + QSslKey key(encoded, QSsl::Rsa); + if(key.isNull()) + key = QSslKey(encoded, QSsl::Dsa); + _certIdentity->setSslKey(key); +} + +void ClientCertManager::setSslCert(const QByteArray &encoded) { + _certIdentity->setSslCert(QSslCertificate(encoded)); +}