Changeset - 76c678dd6f1d
[Not reviewed]
0 5 6
HanzZ - 14 years ago 2011-04-01 23:54:29
hanzz.k@gmail.com
Working conversation from legacy -> XMPP
11 files changed with 377 insertions and 6 deletions:
0 comments (0 inline, 0 general)
include/transport/abstractconversation.h
Show inline comments
 
new file 100644
 
/**
 
 * XMPP - libpurple transport
 
 *
 
 * Copyright (C) 2009, Jan Kaluza <hanzz@soc.pidgin.im>
 
 *
 
 * This program is free software; you can redistribute it and/or modify
 
 * it under the terms of the GNU General Public License as published by
 
 * the Free Software Foundation; either version 2 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * This program is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#pragma once
 

	
 
#include <string>
 
#include <algorithm>
 
#include "transport/transport.h"
 

	
 
#include "Swiften/Swiften.h"
 
#include "Swiften/Elements/Message.h"
 

	
 
namespace Transport {
 

	
 
class ConversationManager;
 

	
 
class AbstractConversation {
 
	public:
 
		/// Constructor.
 
		AbstractConversation(ConversationManager *conversationManager, const std::string &legacyName);
 

	
 
		/// Destructor
 
		virtual ~AbstractConversation();
 

	
 
		const std::string &getLegacyName() { return m_legacyName; }
 

	
 
		void handleMessage(boost::shared_ptr<Swift::Message> &message);
 

	
 
		virtual void sendMessage(boost::shared_ptr<Swift::Message> &message) = 0;
 

	
 
	private:
 
		ConversationManager *m_conversationManager;
 
		std::string m_legacyName;
 
};
 

	
 
}
include/transport/conversationmanager.h
Show inline comments
 
new file 100644
 
/**
 
 * XMPP - libpurple transport
 
 *
 
 * Copyright (C) 2009, Jan Kaluza <hanzz@soc.pidgin.im>
 
 *
 
 * This program is free software; you can redistribute it and/or modify
 
 * it under the terms of the GNU General Public License as published by
 
 * the Free Software Foundation; either version 2 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * This program is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#pragma once
 

	
 
#include <string>
 
#include <algorithm>
 
#include <map>
 
#include "Swiften/Swiften.h"
 

	
 
namespace Transport {
 

	
 
class AbstractConversation;
 
class User;
 
class Component;
 

	
 
class ConversationManager {
 
	public:
 
		/// Creates new ConversationManager.
 
		/// \param user User associated with this ConversationManager.
 
		/// \param component Transport instance associated with this roster.
 
		ConversationManager(User *user, Component *component);
 

	
 
		/// Destructor.
 
		virtual ~ConversationManager();
 

	
 
		/// Returns user associated with this manager.
 
		/// \return User
 
		User *getUser() { return m_user; }
 

	
 
		Component *getComponent() { return m_component; }
 

	
 
		void setConversation(AbstractConversation *conv);
 

	
 
		void unsetConversation(AbstractConversation *conv);
 

	
 
	private:
 
		Component *m_component;
 
		User *m_user;
 

	
 
		std::map<std::string, AbstractConversation *> m_convs;
 
};
 

	
 
}
include/transport/rostermanager.h
Show inline comments
 
@@ -54,6 +54,8 @@ class RosterManager {
 
		/// \param buddy AbstractBuddy.
 
		void unsetBuddy(AbstractBuddy *buddy);
 

	
 
		AbstractBuddy *getBuddy(const std::string &name);
 

	
 
		/// Returns user associated with this roster.
 
		/// \return User
 
		User *getUser() { return m_user; }
include/transport/user.h
Show inline comments
 
@@ -30,6 +30,7 @@ namespace Transport {
 

	
 
class Component;
 
class RosterManager;
 
class ConversationManager;
 
struct UserInfo;
 

	
 
/// Represents online XMPP user.
 
@@ -55,6 +56,8 @@ class User {
 

	
 
		RosterManager *getRosterManager() { return m_rosterManager; }
 

	
 
		ConversationManager *getConversationManager() { return m_conversationManager; }
 

	
 

	
 
		Component *getComponent() { return m_component; }
 

	
 
@@ -77,6 +80,7 @@ class User {
 
		Swift::JID m_jid;
 
		Component *m_component;
 
		RosterManager *m_rosterManager;
 
		ConversationManager *m_conversationManager;
 
		Swift::EntityCapsManager *m_entityCapsManager;
 
		Swift::PresenceOracle *m_presenceOracle;
 
		UserInfo m_userInfo;
spectrum/src/main.cpp
Show inline comments
 
@@ -13,6 +13,7 @@
 
#include "transport/rostermanager.h"
 
#include "spectrumeventloop.h"
 
#include "spectrumbuddy.h"
 
#include "spectrumconversation.h"
 
#include "geventloop.h"
 

	
 
#define Log(X, STRING) std::cout << "[SPECTRUM] " << X << " " << STRING << "\n";
 
@@ -109,8 +110,8 @@ static void NodeRemoved(PurpleBlistNode *node, void *data) {
 
		return;
 
	PurpleBuddy *buddy = (PurpleBuddy *) node;
 
	
 
	PurpleAccount *account = purple_buddy_get_account(buddy);
 
	User *user = (User *) account->ui_data;
 
// 	PurpleAccount *account = purple_buddy_get_account(buddy);
 
// 	User *user = (User *) account->ui_data;
 
	if (buddy->node.ui_data) {
 
		SpectrumBuddy *s_buddy = (SpectrumBuddy *) buddy->node.ui_data;
 
		s_buddy->removeBuddy(buddy);
 
@@ -139,6 +140,63 @@ static PurpleBlistUiOps blistUiOps =
 
	NULL
 
};
 

	
 
static void conv_new(PurpleConversation *conv) {
 
	PurpleAccount *account = purple_conversation_get_account(conv);
 
	User *user = (User *) account->ui_data;
 

	
 
	if (!user)
 
		return;
 

	
 
	std::string name = purple_conversation_get_name(conv);
 
	size_t pos = name.find("/");
 
	if (pos != std::string::npos)
 
		name.erase((int) pos, name.length() - (int) pos);
 

	
 
	SpectrumConversation *s_conv = new SpectrumConversation(user->getConversationManager(), name, conv);
 
	conv->ui_data = s_conv;
 
}
 

	
 
static void conv_destroy(PurpleConversation *conv) {
 
	SpectrumConversation *s_conv = (SpectrumConversation *) conv->ui_data;
 
	if (s_conv) {
 
		delete s_conv;
 
	}
 
}
 

	
 
static void conv_write_im(PurpleConversation *conv, const char *who, const char *message, PurpleMessageFlags flags, time_t mtime) {
 
	SpectrumConversation *s_conv = (SpectrumConversation *) conv->ui_data;
 
	if (!s_conv)
 
		return;
 

	
 
	boost::shared_ptr<Swift::Message> msg(new Swift::Message());
 
	msg->setBody(message);
 

	
 
	s_conv->handleMessage(msg);
 
}
 

	
 
static PurpleConversationUiOps conversation_ui_ops =
 
{
 
	conv_new,
 
	conv_destroy,
 
	NULL,//conv_write_chat,                              /* write_chat           */
 
	conv_write_im,             /* write_im             */
 
	NULL,//conv_write_conv,           /* write_conv           */
 
	NULL,//conv_chat_add_users,       /* chat_add_users       */
 
	NULL,//conv_chat_rename_user,     /* chat_rename_user     */
 
	NULL,//conv_chat_remove_users,    /* chat_remove_users    */
 
	NULL,//pidgin_conv_chat_update_user,     /* chat_update_user     */
 
	NULL,//pidgin_conv_present_conversation, /* present              */
 
	NULL,//pidgin_conv_has_focus,            /* has_focus            */
 
	NULL,//pidgin_conv_custom_smiley_add,    /* custom_smiley_add    */
 
	NULL,//pidgin_conv_custom_smiley_write,  /* custom_smiley_write  */
 
	NULL,//pidgin_conv_custom_smiley_close,  /* custom_smiley_close  */
 
	NULL,//pidgin_conv_send_confirm,         /* send_confirm         */
 
	NULL,
 
	NULL,
 
	NULL,
 
	NULL
 
};
 

	
 
static void transport_core_ui_init(void)
 
{
 
	purple_blist_set_ui_ops(&blistUiOps);
 
@@ -147,7 +205,7 @@ static void transport_core_ui_init(void)
 
// 	purple_request_set_ui_ops(&requestUiOps);
 
// 	purple_xfers_set_ui_ops(getXferUiOps());
 
// 	purple_connections_set_ui_ops(&conn_ui_ops);
 
// 	purple_conversations_set_ui_ops(&conversation_ui_ops);
 
	purple_conversations_set_ui_ops(&conversation_ui_ops);
 
// #ifndef WIN32
 
// 	purple_dnsquery_set_ui_ops(getDNSUiOps());
 
// #endif
 
@@ -196,6 +254,8 @@ static bool initPurple(Config &cfg) {
 
	bool ret;
 

	
 
	purple_util_set_user_dir("./");
 
	remove("./accounts.xml");
 
	remove("./blist.xml");
 

	
 
// 	if (m_configuration.logAreas & LOG_AREA_PURPLE)
 
		purple_debug_set_ui_ops(&debugUiOps);
spectrum/src/spectrumconversation.cpp
Show inline comments
 
new file 100644
 
/**
 
 * XMPP - libpurple transport
 
 *
 
 * Copyright (C) 2009, Jan Kaluza <hanzz@soc.pidgin.im>
 
 *
 
 * This program is free software; you can redistribute it and/or modify
 
 * it under the terms of the GNU General Public License as published by
 
 * the Free Software Foundation; either version 2 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * This program is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#include "spectrumconversation.h"
 
#include "transport/user.h"
 

	
 
#define Log(X, STRING) std::cout << "[SPECTRUM] " << X << " " << STRING << "\n";
 

	
 
SpectrumConversation::SpectrumConversation(ConversationManager *conversationManager, const std::string &legacyName, PurpleConversation *conv) : AbstractConversation(conversationManager, legacyName), m_conv(conv) {
 
}
 

	
 
SpectrumConversation::~SpectrumConversation() {
 
}
 

	
 
void SpectrumConversation::sendMessage(boost::shared_ptr<Swift::Message> &message) {
 
	
 
}
 

	
 

	
spectrum/src/spectrumconversation.h
Show inline comments
 
new file 100644
 
/**
 
 * XMPP - libpurple transport
 
 *
 
 * Copyright (C) 2009, Jan Kaluza <hanzz@soc.pidgin.im>
 
 *
 
 * This program is free software; you can redistribute it and/or modify
 
 * it under the terms of the GNU General Public License as published by
 
 * the Free Software Foundation; either version 2 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * This program is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#pragma once
 

	
 
#include <string>
 
#include "purple.h"
 
#include "account.h"
 
#include "glib.h"
 
#include <algorithm>
 
#include "transport/abstractconversation.h"
 
#include "transport/conversationmanager.h"
 

	
 
using namespace Transport;
 

	
 
// Wrapper for PurpleBuddy
 
class SpectrumConversation : public AbstractConversation {
 
	public:
 
		SpectrumConversation(ConversationManager *conversationManager, const std::string &legacyName, PurpleConversation *conv);
 
		virtual ~SpectrumConversation();
 
		
 
		PurpleConversation *getConversation() { return m_conv; }
 

	
 
		void sendMessage(boost::shared_ptr<Swift::Message> &message);
 

	
 
	private:
 
		PurpleConversation *m_conv;
 
};
 

	
src/abstractconversation.cpp
Show inline comments
 
new file 100644
 
/**
 
 * XMPP - libpurple transport
 
 *
 
 * Copyright (C) 2009, Jan Kaluza <hanzz@soc.pidgin.im>
 
 *
 
 * This program is free software; you can redistribute it and/or modify
 
 * it under the terms of the GNU General Public License as published by
 
 * the Free Software Foundation; either version 2 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * This program is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#include <iostream>
 
#include "transport/abstractconversation.h"
 
#include "transport/conversationmanager.h"
 
#include "transport/user.h"
 
#include "transport/transport.h"
 
#include "transport/abstractbuddy.h"
 
#include "transport/rostermanager.h"
 

	
 
namespace Transport {
 

	
 
AbstractConversation::AbstractConversation(ConversationManager *conversationManager, const std::string &legacyName) : m_conversationManager(conversationManager) {
 
	m_conversationManager->setConversation(this);
 
	m_legacyName = legacyName;
 
}
 

	
 
AbstractConversation::~AbstractConversation() {
 
	m_conversationManager->unsetConversation(this);
 
}
 

	
 
void AbstractConversation::handleMessage(boost::shared_ptr<Swift::Message> &message) {
 
	message->setTo(m_conversationManager->getUser()->getJID().toBare());
 
	AbstractBuddy *buddy = m_conversationManager->getUser()->getRosterManager()->getBuddy(m_legacyName);
 
	if (buddy) {
 
		std::cout << m_legacyName << " 222222\n";
 
		message->setFrom(buddy->getJID());
 
	}
 
	else {
 
		std::cout << m_legacyName << " 1111111\n";
 
		// TODO: escape from and setFrom
 
	}
 
	m_conversationManager->getComponent()->getStanzaChannel()->sendMessage(message);
 
}
 

	
 
}
src/conversationmanager.cpp
Show inline comments
 
new file 100644
 
/**
 
 * XMPP - libpurple transport
 
 *
 
 * Copyright (C) 2009, Jan Kaluza <hanzz@soc.pidgin.im>
 
 *
 
 * This program is free software; you can redistribute it and/or modify
 
 * it under the terms of the GNU General Public License as published by
 
 * the Free Software Foundation; either version 2 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * This program is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#include "transport/conversationmanager.h"
 
#include "transport/abstractconversation.h"
 
#include "transport/usermanager.h"
 
#include "transport/abstractbuddy.h"
 
#include "transport/user.h"
 
#include "Swiften/Roster/SetRosterRequest.h"
 
#include "Swiften/Elements/RosterPayload.h"
 
#include "Swiften/Elements/RosterItemPayload.h"
 

	
 
namespace Transport {
 

	
 
ConversationManager::ConversationManager(User *user, Component *component){
 
	m_user = user;
 
	m_component = component;
 
}
 

	
 
ConversationManager::~ConversationManager() {
 
}
 

	
 
void ConversationManager::setConversation(AbstractConversation *conv) {
 
	m_convs[conv->getLegacyName()] = conv;
 
}
 

	
 
void ConversationManager::unsetConversation(AbstractConversation *conv) {
 
	m_convs.erase(conv->getLegacyName());
 
}
 

	
 
}
 
\ No newline at end of file
src/rostermanager.cpp
Show inline comments
 
@@ -53,14 +53,14 @@ void RosterManager::sendBuddyRosterPush(AbstractBuddy *buddy) {
 
	payload->addItem(item);
 

	
 
	Swift::SetRosterRequest::ref request = Swift::SetRosterRequest::create(payload, m_component->getIQRouter(), m_user->getJID().toBare());
 
	request->onResponse.connect(boost::bind(&RosterManager::handleBuddyRosterPushResponse, this, _1, buddy->getSafeName()));
 
	request->onResponse.connect(boost::bind(&RosterManager::handleBuddyRosterPushResponse, this, _1, buddy->getName()));
 
	request->send();
 
}
 

	
 
void RosterManager::setBuddyCallback(AbstractBuddy *buddy) {
 
	m_setBuddyTimer->onTick.disconnect(boost::bind(&RosterManager::setBuddyCallback, this, buddy));
 

	
 
	m_buddies[buddy->getSafeName()] = buddy;
 
	m_buddies[buddy->getName()] = buddy;
 
	onBuddySet(buddy);
 

	
 
	if (m_component->inServerMode()) {
 
@@ -73,7 +73,7 @@ void RosterManager::setBuddyCallback(AbstractBuddy *buddy) {
 
}
 

	
 
void RosterManager::unsetBuddy(AbstractBuddy *buddy) {
 
	m_buddies.erase(buddy->getSafeName());
 
	m_buddies.erase(buddy->getName());
 
	onBuddyUnset(buddy);
 
}
 

	
 
@@ -83,4 +83,8 @@ void RosterManager::handleBuddyRosterPushResponse(Swift::ErrorPayload::ref error
 
	}
 
}
 

	
 
AbstractBuddy *RosterManager::getBuddy(const std::string &name) {
 
	return m_buddies[name];
 
}
 

	
 
}
 
\ No newline at end of file
src/user.cpp
Show inline comments
 
@@ -22,6 +22,7 @@
 
#include "transport/transport.h"
 
#include "transport/storagebackend.h"
 
#include "transport/rostermanager.h"
 
#include "transport/conversationmanager.h"
 
#include "Swiften/Swiften.h"
 

	
 
namespace Transport {
 
@@ -40,10 +41,12 @@ User::User(const Swift::JID &jid, UserInfo &userInfo, Component *component) {
 
	m_reconnectTimer->onTick.connect(boost::bind(&User::onConnectingTimeout, this)); 
 

	
 
	m_rosterManager = new RosterManager(this, m_component);
 
	m_conversationManager = new ConversationManager(this, m_component);
 
}
 

	
 
User::~User(){
 
	delete m_rosterManager;
 
	delete m_conversationManager;
 
}
 

	
 
const Swift::JID &User::getJID() {
0 comments (0 inline, 0 general)