summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Client/Client.cpp8
-rw-r--r--Swiften/Client/Client.h4
-rw-r--r--Swiften/Client/DummyNickManager.h23
-rw-r--r--Swiften/Client/NickManager.cpp14
-rw-r--r--Swiften/Client/NickManager.h22
-rw-r--r--Swiften/Client/NickManagerImpl.cpp45
-rw-r--r--Swiften/Client/NickManagerImpl.h33
-rw-r--r--Swiften/Client/NickResolver.cpp4
-rw-r--r--Swiften/Client/NickResolver.h2
-rw-r--r--Swiften/SConscript2
10 files changed, 153 insertions, 4 deletions
diff --git a/Swiften/Client/Client.cpp b/Swiften/Client/Client.cpp
index dcc8a79..d3dcd3e 100644
--- a/Swiften/Client/Client.cpp
+++ b/Swiften/Client/Client.cpp
@@ -24,6 +24,7 @@
#include "Swiften/Client/NickResolver.h"
#include "Swiften/Presence/SubscriptionManager.h"
#include "Swiften/TLS/BlindCertificateTrustChecker.h"
+#include <Swiften/Client/NickManagerImpl.h>
namespace Swift {
@@ -53,6 +54,7 @@ Client::Client(EventLoop* eventLoop, NetworkFactories* networkFactories, const J
capsManager = new CapsManager(getStorages()->getCapsStorage(), getStanzaChannel(), getIQRouter());
entityCapsManager = new EntityCapsManager(capsManager, getStanzaChannel());
+ nickManager = new NickManagerImpl(jid.toBare(), vcardManager);
nickResolver = new NickResolver(jid.toBare(), roster, vcardManager, mucRegistry);
blindCertificateTrustChecker = new BlindCertificateTrustChecker();
@@ -62,6 +64,7 @@ Client::~Client() {
delete blindCertificateTrustChecker;
delete nickResolver;
+ delete nickManager;
delete entityCapsManager;
delete capsManager;
@@ -121,8 +124,13 @@ EntityCapsProvider* Client::getEntityCapsProvider() const {
return entityCapsManager;
}
+
void Client::setAlwaysTrustCertificates() {
setCertificateTrustChecker(blindCertificateTrustChecker);
}
+NickManager* Client::getNickManager() const {
+ return nickManager;
+}
+
}
diff --git a/Swiften/Client/Client.h b/Swiften/Client/Client.h
index 6fa3a34..975d499 100644
--- a/Swiften/Client/Client.h
+++ b/Swiften/Client/Client.h
@@ -30,6 +30,7 @@ namespace Swift {
class NickResolver;
class SubscriptionManager;
class ClientDiscoManager;
+ class NickManager;
/**
* Provides the core functionality for writing XMPP client software.
@@ -115,6 +116,8 @@ namespace Swift {
EntityCapsProvider* getEntityCapsProvider() const;
+ NickManager* getNickManager() const;
+
NickResolver* getNickResolver() const {
return nickResolver;
}
@@ -158,6 +161,7 @@ namespace Swift {
AvatarManager* avatarManager;
CapsManager* capsManager;
EntityCapsManager* entityCapsManager;
+ NickManager* nickManager;
NickResolver* nickResolver;
SubscriptionManager* subscriptionManager;
MUCManager* mucManager;
diff --git a/Swiften/Client/DummyNickManager.h b/Swiften/Client/DummyNickManager.h
new file mode 100644
index 0000000..27a42c0
--- /dev/null
+++ b/Swiften/Client/DummyNickManager.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Client/NickManager.h>
+
+namespace Swift {
+ class VCardManager;
+
+ class DummyNickManager : public NickManager {
+ public:
+ String getOwnNick() const {
+ return "";
+ }
+
+ void setOwnNick(const String& nick) {
+ }
+ };
+}
diff --git a/Swiften/Client/NickManager.cpp b/Swiften/Client/NickManager.cpp
new file mode 100644
index 0000000..90e3217
--- /dev/null
+++ b/Swiften/Client/NickManager.cpp
@@ -0,0 +1,14 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <Swiften/Client/NickManager.h>
+
+namespace Swift {
+
+NickManager::~NickManager() {
+}
+
+}
diff --git a/Swiften/Client/NickManager.h b/Swiften/Client/NickManager.h
new file mode 100644
index 0000000..e918b07
--- /dev/null
+++ b/Swiften/Client/NickManager.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/boost_bsignals.h>
+#include <Swiften/Base/String.h>
+
+namespace Swift {
+ class NickManager {
+ public:
+ virtual ~NickManager();
+
+ virtual String getOwnNick() const = 0;
+ virtual void setOwnNick(const String& nick) = 0;
+
+ boost::signal<void (const String&)> onOwnNickChanged;
+ };
+}
diff --git a/Swiften/Client/NickManagerImpl.cpp b/Swiften/Client/NickManagerImpl.cpp
new file mode 100644
index 0000000..09f8de5
--- /dev/null
+++ b/Swiften/Client/NickManagerImpl.cpp
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <Swiften/Client/NickManagerImpl.h>
+
+#include <boost/bind.hpp>
+
+#include <Swiften/VCards/VCardManager.h>
+
+namespace Swift {
+
+NickManagerImpl::NickManagerImpl(const JID& ownJID, VCardManager* vcardManager) : ownJID(ownJID), vcardManager(vcardManager) {
+ vcardManager->onVCardChanged.connect(boost::bind(&NickManagerImpl::handleVCardReceived, this, _1, _2));
+}
+
+NickManagerImpl::~NickManagerImpl() {
+ vcardManager->onVCardChanged.disconnect(boost::bind(&NickManagerImpl::handleVCardReceived, this, _1, _2));
+}
+
+String NickManagerImpl::getOwnNick() const {
+ return ownJID;
+}
+
+void NickManagerImpl::setOwnNick(const String&) {
+}
+
+void NickManagerImpl::handleVCardReceived(const JID& jid, VCard::ref vcard) {
+ if (!jid.equals(ownJID, JID::WithoutResource)) {
+ return;
+ }
+
+ String nick;
+ if (!vcard->getNickname().isEmpty()) {
+ nick = vcard->getNickname();
+ }
+ if (ownNick != nick) {
+ ownNick = nick;
+ onOwnNickChanged(ownNick);
+ }
+}
+
+}
diff --git a/Swiften/Client/NickManagerImpl.h b/Swiften/Client/NickManagerImpl.h
new file mode 100644
index 0000000..87c9711
--- /dev/null
+++ b/Swiften/Client/NickManagerImpl.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Client/NickManager.h>
+#include <Swiften/Elements/VCard.h>
+#include <Swiften/JID/JID.h>
+#include <Swiften/Base/String.h>
+
+namespace Swift {
+ class VCardManager;
+
+ class NickManagerImpl : public NickManager {
+ public:
+ NickManagerImpl(const JID& ownJID, VCardManager* vcardManager);
+ ~NickManagerImpl();
+
+ String getOwnNick() const;
+ void setOwnNick(const String& nick);
+
+ private:
+ void handleVCardReceived(const JID& jid, VCard::ref vCard);
+
+ private:
+ JID ownJID;
+ VCardManager* vcardManager;
+ String ownNick;
+ };
+}
diff --git a/Swiften/Client/NickResolver.cpp b/Swiften/Client/NickResolver.cpp
index c151dfa..9bfe269 100644
--- a/Swiften/Client/NickResolver.cpp
+++ b/Swiften/Client/NickResolver.cpp
@@ -16,6 +16,7 @@
// FIXME: The NickResolver currently relies on the vcard being requested by the client on login.
// The VCardManager should get an onConnected() signal (which is signalled when the stanzachannel is available(, and each time this is emitted,
// the nickresolver should request the vcard.
+// FIXME: The ownJID functionality should probably be removed, and NickManager should be used directly.
namespace Swift {
@@ -67,9 +68,6 @@ void NickResolver::handleVCardReceived(const JID& jid, VCard::ref ownVCard) {
ownNick_ = ownVCard->getFullName();
}
}
- if (ownNick_ != initialNick) {
- onOwnNickChanged(ownNick_);
- }
}
}
diff --git a/Swiften/Client/NickResolver.h b/Swiften/Client/NickResolver.h
index 806afb8..de7d64a 100644
--- a/Swiften/Client/NickResolver.h
+++ b/Swiften/Client/NickResolver.h
@@ -22,8 +22,8 @@ namespace Swift {
String jidToNick(const JID& jid);
- boost::signal<void (const String&)> onOwnNickChanged;
boost::signal<void (const JID&, const String& /*previousNick*/)> onNickChanged;
+
private:
void handleVCardReceived(const JID& jid, VCard::ref vCard);
void handleJIDUpdated(const JID& jid, const String& previousNick, const std::vector<String>& groups);
diff --git a/Swiften/SConscript b/Swiften/SConscript
index c5198a6..a4eb75d 100644
--- a/Swiften/SConscript
+++ b/Swiften/SConscript
@@ -49,6 +49,8 @@ if env["SCONS_STAGE"] == "build" :
"Client/MemoryStorages.cpp",
"Client/FileStorages.cpp",
"Client/NickResolver.cpp",
+ "Client/NickManager.cpp",
+ "Client/NickManagerImpl.cpp",
"Compress/ZLibCodecompressor.cpp",
"Compress/ZLibDecompressor.cpp",
"Compress/ZLibCompressor.cpp",