style button is smaller now
[quassel.git] / src / core / coreidentity.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-09 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 INIT_SYNCABLE_OBJECT(CoreIdentity)
26 CoreIdentity::CoreIdentity(IdentityId id, QObject *parent)
27   : Identity(id, parent)
28 #ifdef HAVE_SSL
29   , _certManager(*this)
30 #endif
31 {
32 #ifdef HAVE_SSL
33   connect(this, SIGNAL(idSet(IdentityId)), &_certManager, SLOT(setId(IdentityId)));
34   connect(&_certManager, SIGNAL(updated()), this, SIGNAL(updated()));
35 #endif
36 }
37
38 CoreIdentity::CoreIdentity(const Identity &other, QObject *parent)
39   : Identity(other, parent)
40 #ifdef HAVE_SSL
41   , _certManager(*this)
42 #endif
43 {
44 #ifdef HAVE_SSL
45   connect(this, SIGNAL(idSet(IdentityId)), &_certManager, SLOT(setId(IdentityId)));
46   connect(&_certManager, SIGNAL(updated()), this, SIGNAL(updated()));
47 #endif
48 }
49
50 CoreIdentity::CoreIdentity(const CoreIdentity &other, QObject *parent)
51   : Identity(other, parent)
52 #ifdef HAVE_SSL
53   , _sslKey(other._sslKey),
54     _sslCert(other._sslCert),
55     _certManager(*this)
56 #endif
57 {
58 #ifdef HAVE_SSL
59   connect(this, SIGNAL(idSet(IdentityId)), &_certManager, SLOT(setId(IdentityId)));
60   connect(&_certManager, SIGNAL(updated()), this, SIGNAL(updated()));
61 #endif
62 }
63
64 void CoreIdentity::synchronize(SignalProxy *proxy) {
65   proxy->synchronize(this);
66 #ifdef HAVE_SSL
67   proxy->synchronize(&_certManager);
68 #endif
69 }
70
71 #ifdef HAVE_SSL
72 void CoreIdentity::setSslKey(const QByteArray &encoded) {
73   QSslKey key(encoded, QSsl::Rsa);
74   if(key.isNull())
75     key = QSslKey(encoded, QSsl::Dsa);
76   setSslKey(key);
77 }
78
79 void CoreIdentity::setSslCert(const QByteArray &encoded) {
80   setSslCert(QSslCertificate(encoded));
81 }
82 #endif
83
84 CoreIdentity &CoreIdentity::operator=(const CoreIdentity &identity) {
85   Identity::operator=(identity);
86 #ifdef HAVE_SSL
87   _sslKey = identity._sslKey;
88   _sslCert = identity._sslCert;
89 #endif
90   return *this;
91 }
92
93 #ifdef HAVE_SSL
94 // ========================================
95 //  CoreCertManager
96 // ========================================
97 INIT_SYNCABLE_OBJECT(CoreCertManager)
98 CoreCertManager::CoreCertManager(CoreIdentity &identity)
99   : CertManager(identity.id()),
100     identity(identity)
101 {
102   setAllowClientUpdates(true);
103 }
104
105 void CoreCertManager::setId(IdentityId id) {
106   renameObject(QString::number(id.toInt()));
107 }
108
109 void CoreCertManager::setSslKey(const QByteArray &encoded) {
110   identity.setSslKey(encoded);
111   CertManager::setSslKey(encoded);
112 }
113
114 void CoreCertManager::setSslCert(const QByteArray &encoded) {
115   identity.setSslCert(encoded);
116   CertManager::setSslCert(encoded);
117 }
118 #endif //HAVE_SSL