dfad2e960e6896a1bb9c4468ee01e3aebe9c0aef
[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 "coresession.h"
24 #include "coreusersettings.h"
25 #include "signalproxy.h"
26
27 CoreIdentity::CoreIdentity(IdentityId id, SignalProxy *proxy, CoreSession *parent)
28   : Identity(id, parent),
29     _certManager(new CoreCertManager(this)),
30     _coreSession(parent)
31 {
32   proxy->synchronize(_certManager);
33   connect(this, SIGNAL(idSet(IdentityId)), _certManager, SLOT(setId(IdentityId)));
34 }
35
36 CoreIdentity::CoreIdentity(const Identity &other, SignalProxy *proxy, CoreSession *parent)
37   : Identity(other, parent),
38     _certManager(new CoreCertManager(this)),
39     _coreSession(parent)
40 {
41   proxy->synchronize(_certManager);
42   connect(this, SIGNAL(idSet(IdentityId)), _certManager, SLOT(setId(IdentityId)));
43 }
44
45 void CoreIdentity::update(const QVariantMap &properties) {
46   SyncableObject::update(properties);
47   save();
48 }
49
50 void CoreIdentity::save() {
51   CoreUserSettings s(_coreSession->user());
52   s.storeIdentity(*this);
53 }
54
55 void CoreIdentity::setSslKey(const QByteArray &encoded) {
56   QSslKey key(encoded, QSsl::Rsa);
57   if(key.isNull())
58     key = QSslKey(encoded, QSsl::Dsa);
59   setSslKey(key);
60 }
61
62 void CoreIdentity::setSslCert(const QByteArray &encoded) {
63   setSslCert(QSslCertificate(encoded));
64 }
65
66
67 // ========================================
68 //  CoreCertManager
69 // ========================================
70 CoreCertManager::CoreCertManager(CoreIdentity *identity)
71   : CertManager(identity->id(), identity),
72     _identity(identity)
73 {
74   setAllowClientUpdates(true);
75 }
76
77 void CoreCertManager::setSslKey(const QByteArray &encoded) {
78   identity()->setSslKey(encoded);
79   CertManager::setSslKey(encoded);
80 }
81
82 void CoreCertManager::setSslCert(const QByteArray &encoded) {
83   identity()->setSslCert(encoded);
84   CertManager::setSslCert(encoded);
85 }
86
87 void CoreCertManager::setId(IdentityId id) {
88   renameObject(QString::number(id.toInt()));
89 }