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