putting it all together: core is now capable to connect to ircservers using a proxy...
[quassel.git] / src / core / coreidentity.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-08 by the Quassel Project                          *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #include "coreidentity.h"
22
23 #include "signalproxy.h"
24
25 CoreIdentity::CoreIdentity(IdentityId id, QObject *parent)
26   : Identity(id, parent),
27     _certManager(*this)
28 {
29   connect(this, SIGNAL(idSet(IdentityId)), &_certManager, SLOT(setId(IdentityId)));
30 }
31
32 CoreIdentity::CoreIdentity(const Identity &other, QObject *parent)
33   : Identity(other, parent),
34     _certManager(*this)
35 {
36   connect(this, SIGNAL(idSet(IdentityId)), &_certManager, SLOT(setId(IdentityId)));
37 }
38
39 CoreIdentity::CoreIdentity(const CoreIdentity &other, QObject *parent)
40   : Identity(other, parent),
41     _sslKey(other._sslKey),
42     _sslCert(other._sslCert),
43     _certManager(*this)
44 {
45   connect(this, SIGNAL(idSet(IdentityId)), &_certManager, SLOT(setId(IdentityId)));
46 }
47
48 void CoreIdentity::synchronize(SignalProxy *proxy) {
49   proxy->synchronize(this);
50   proxy->synchronize(&_certManager);
51 }
52
53 void CoreIdentity::setSslKey(const QByteArray &encoded) {
54   QSslKey key(encoded, QSsl::Rsa);
55   if(key.isNull())
56     key = QSslKey(encoded, QSsl::Dsa);
57   setSslKey(key);
58 }
59
60 void CoreIdentity::setSslCert(const QByteArray &encoded) {
61   setSslCert(QSslCertificate(encoded));
62 }
63
64 CoreIdentity &CoreIdentity::operator=(const CoreIdentity &identity) {
65   Identity::operator=(identity);
66   _sslKey = identity._sslKey;
67   _sslCert = identity._sslCert;
68   return *this;
69 }
70
71 // ========================================
72 //  CoreCertManager
73 // ========================================
74 CoreCertManager::CoreCertManager(CoreIdentity &identity)
75   : CertManager(identity.id()),
76     identity(identity)
77 {
78   setAllowClientUpdates(true);
79 }
80
81 void CoreCertManager::setSslKey(const QByteArray &encoded) {
82   identity.setSslKey(encoded);
83   CertManager::setSslKey(encoded);
84 }
85
86 void CoreCertManager::setSslCert(const QByteArray &encoded) {
87   identity.setSslCert(encoded);
88   CertManager::setSslCert(encoded);
89 }
90
91 void CoreCertManager::setId(IdentityId id) {
92   renameObject(QString::number(id.toInt()));
93 }