Changeset - 35e56d515d97
[Not reviewed]
0 4 0
Jan Kaluza - 14 years ago 2011-04-11 14:03:15
hanzz.k@gmail.com
handleVCardReceived - not connected to libpurple yet...
4 files changed with 14 insertions and 0 deletions:
0 comments (0 inline, 0 general)
include/transport/buddy.h
Show inline comments
 
@@ -84,48 +84,52 @@ class Buddy {
 
		void setSubscription(const std::string &subscription);
 

	
 
		/// Returns current subscription
 
		/// \return subscription "to", "from", "both", "ask"
 
		const std::string &getSubscription();
 

	
 
		/// Sets this buddy's flags.
 
		/// \param flags flags
 
		void setFlags(BuddyFlag flags);
 

	
 
		/// Returns this buddy's flags.
 
		/// \param flags flags
 
		BuddyFlag getFlags();
 

	
 
		/// Returns RosterManager associated with this buddy
 
		/// \return rosterManager
 
		RosterManager *getRosterManager() { return m_rosterManager; }
 

	
 
		/// Returns legacy network username which does not contain unsafe characters,
 
		/// so it can be used in JIDs.
 
		std::string getSafeName();
 

	
 
		void buddyChanged();
 

	
 
		void handleVCardReceived(const std::string &id, const Swift::JID &to, Swift::VCard::ref vcard);
 

	
 
		virtual void getVCard(const std::string &id, const Swift::JID &to) = 0;
 

	
 
		/// Returns legacy network username of this buddy. (for example UIN for ICQ,
 
		/// JID for Jabber, ...).
 
		/// \return legacy network username
 
		virtual std::string getName() = 0;
 

	
 
		/// Returns alias (nickname) of this buddy.
 
		/// \return alias (nickname)
 
		virtual std::string getAlias() = 0;
 

	
 
		/// Returns list of groups this buddy is in.
 
		/// \return groups
 
		virtual std::vector<std::string> getGroups() = 0;
 

	
 
		/// Returns current legacy network status and statuMessage of this buddy.
 
		/// \param status current status/show is stored here
 
		/// \param statusMessage current status message is stored here
 
		/// \return true if status was stored successfully
 
		virtual bool getStatus(Swift::StatusShow &status, std::string &statusMessage) = 0;
 

	
 
		/// Returns SHA-1 hash of buddy icon (avatar) or empty string if there is no avatar
 
		/// for this buddy.
 
		/// \return avatar hash or empty string.
 
		virtual std::string getIconHash() = 0;
 

	
spectrum/src/spectrumbuddy.cpp
Show inline comments
 
@@ -111,24 +111,28 @@ std::string SpectrumBuddy::getIconHash() {
 
			dot = strchr(hash, '.');
 
			if (dot)
 
				*dot = '\0';
 

	
 
			std::string ret(hash);
 
			g_free(avatarHash);
 
			return ret;
 
		}
 
		else {
 
			std::string ret(avatarHash);
 
			g_free(avatarHash);
 
			return ret;
 
		}
 
	}
 

	
 
	return "";
 
}
 

	
 
std::vector<std::string> SpectrumBuddy::getGroups() {
 
	std::vector<std::string> groups;
 
	groups.push_back(purple_group_get_name(purple_buddy_get_group(m_buddy)) ? std::string(purple_group_get_name(purple_buddy_get_group(m_buddy))) : std::string("Buddies"));
 
	return groups;
 
}
 

	
 
void SpectrumBuddy::getVCard(const std::string &id, const Swift::JID &to) {
 
	
 
}
 

	
spectrum/src/spectrumbuddy.h
Show inline comments
 
@@ -25,33 +25,34 @@
 
#include "purple.h"
 
#include "account.h"
 
#include "glib.h"
 
#include <algorithm>
 
#include "transport/buddy.h"
 
#include "transport/rostermanager.h"
 

	
 
using namespace Transport;
 

	
 
// Wrapper for PurpleBuddy
 
class SpectrumBuddy : public Buddy {
 
	public:
 
		SpectrumBuddy(RosterManager *rosterManager, long id, PurpleBuddy *buddy);
 
		virtual ~SpectrumBuddy();
 

	
 
		std::string getAlias();
 
		std::string getName();
 
		bool getStatus(Swift::StatusShow &status, std::string &statusMessage);
 
		std::string getIconHash();
 
		std::vector<std::string> getGroups();
 

	
 
		void addBuddy(PurpleBuddy *buddy) { m_buddies.push_back(buddy); }
 
		void removeBuddy(PurpleBuddy *buddy) { m_buddies.remove(buddy); }
 
		int getBuddiesCount() { return m_buddies.size(); }
 
		void getVCard(const std::string &id, const Swift::JID &to);
 
		
 
		PurpleBuddy *getBuddy() { return m_buddy; }
 

	
 
	private:
 
		PurpleBuddy *m_buddy;
 
		std::list<PurpleBuddy *> m_buddies;
 
};
 

	
 
#endif
src/buddy.cpp
Show inline comments
 
@@ -132,39 +132,44 @@ std::string Buddy::getSafeName() {
 
	}
 
	std::string name = getName();
 
// 	Transport::instance()->protocol()->prepareUsername(name, purple_buddy_get_account(m_buddy));
 
	if (getFlags() & BUDDY_JID_ESCAPING) {
 
		name = Swift::JID::getEscapedNode(name);
 
	}
 
	else {
 
		if (name.find_last_of("@") != std::string::npos) {
 
			name.replace(name.find_last_of("@"), 1, "%");
 
		}
 
	}
 
// 	if (name.empty()) {
 
// 		Log("SpectrumBuddy::getSafeName", "Name is EMPTY! Previous was " << getName() << ".");
 
// 	}
 
	return name;
 
}
 

	
 
void Buddy::buddyChanged() {
 
	Swift::Presence::ref presence = generatePresenceStanza(255);
 
	if (presence) {
 
		m_rosterManager->getUser()->getComponent()->getStanzaChannel()->sendPresence(presence);
 
	}
 
}
 

	
 
void Buddy::handleVCardReceived(const std::string &id, const Swift::JID &to, Swift::VCard::ref vcard) {
 
	boost::shared_ptr<Swift::GenericRequest<Swift::VCard> > request(new Swift::GenericRequest<Swift::VCard>(Swift::IQ::Result, m_rosterManager->getUser()->getJID(), vcard, m_rosterManager->getUser()->getComponent()->getIQRouter()));
 
	request->send();
 
}
 

	
 
std::string Buddy::JIDToLegacyName(const Swift::JID &jid) {
 
	std::string name;
 
	if (jid.getUnescapedNode() == jid.getNode()) {
 
		name = jid.getNode();
 
		if (name.find_last_of("%") != std::string::npos) {
 
			name.replace(name.find_last_of("%"), 1, "@");
 
		}
 
	}
 
	else {
 
		name = jid.getUnescapedNode();
 
	}
 
	return name;
 
}
 

	
 
}
0 comments (0 inline, 0 general)