Changeset - c04ca9251707
[Not reviewed]
0 2 0
Jan Kaluza - 15 years ago 2011-04-11 14:31:20
hanzz.k@gmail.com
Factory::createBuddy
2 files changed with 29 insertions and 0 deletions:
0 comments (0 inline, 0 general)
include/transport/factory.h
Show inline comments
 
@@ -6,37 +6,43 @@
 
 * 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"
 
#include "transport/conversation.h"
 
#include "transport/buddy.h"
 
#include "transport/storagebackend.h"
 

	
 
namespace Transport {
 

	
 
class Conversation;
 
class Buddy;
 
class ConversationManager;
 
class RosterManager;
 

	
 
class Factory {
 
	public:
 
		
 
		virtual Conversation *createConversation(ConversationManager *conversationManager, const std::string &legacyName) = 0;
 

	
 
		virtual Buddy *createBuddy(RosterManager *rosterManager, const BuddyInfo &buddyInfo) = 0;
 
};
 

	
 
}
spectrum/src/main.cpp
Show inline comments
 
@@ -439,48 +439,71 @@ static void handleUserDestroyed(User *user, UserManager *userManager, Config *co
 
		purple_account_set_enabled(account, "spectrum", FALSE);
 

	
 
		// Remove conversations.
 
		// This has to be called before m_account->ui_data = NULL;, because it uses
 
		// ui_data to call SpectrumMessageHandler::purpleConversationDestroyed() callback.
 
		GList *iter;
 
		for (iter = purple_get_conversations(); iter; ) {
 
			PurpleConversation *conv = (PurpleConversation*) iter->data;
 
			iter = iter->next;
 
			if (purple_conversation_get_account(conv) == account)
 
				purple_conversation_destroy(conv);
 
		}
 

	
 
		account->ui_data = NULL;
 
// 		Transport::instance()->collector()->collect(m_account);
 
	}
 
}
 

	
 
class SpectrumFactory : public Factory {
 
	public:
 
		Conversation *createConversation(ConversationManager *conversationManager, const std::string &legacyName) {
 
			PurpleConversation *conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, (PurpleAccount *) conversationManager->getUser()->getData() , legacyName.c_str());
 
			return (Conversation *) conv->ui_data;
 
		}
 

	
 
		Buddy *createBuddy(RosterManager *rosterManager, const BuddyInfo &buddyInfo) {
 
			PurpleAccount *account = (PurpleAccount *) rosterManager->getUser()->getData();
 
			std::string group = buddyInfo.groups[0];
 
			PurpleGroup *g = purple_find_group(group.c_str());
 
			if (!g) {
 
				g = purple_group_new(group.c_str());
 
				purple_blist_add_group(g, NULL);
 
			}
 

	
 
			PurpleBuddy *buddy = purple_find_buddy_in_group(account, buddyInfo.legacyName.c_str(), g);
 
			if (!buddy) {
 
				// create contact
 
				PurpleContact *contact = purple_contact_new();
 
				purple_blist_add_contact(contact, g, NULL);
 

	
 
				// create buddy
 
				buddy = purple_buddy_new(account, buddyInfo.legacyName.c_str(), buddyInfo.alias.c_str());
 
				purple_blist_add_buddy(buddy, contact, g, NULL);
 
				purple_blist_server_alias_buddy(buddy, buddyInfo.alias.c_str());
 
			}
 
			return (Buddy *) buddy->node.ui_data;
 
		}
 
};
 

	
 
int main(int argc, char **argv) {
 
	GError *error = NULL;
 
	GOptionContext *context;
 
	context = g_option_context_new("config_file_name or profile name");
 
	g_option_context_add_main_entries(context, options_entries, "");
 
	if (!g_option_context_parse (context, &argc, &argv, &error)) {
 
		std::cout << "option parsing failed: " << error->message << "\n";
 
		return -1;
 
	}
 

	
 
	if (ver) {
 
// 		std::cout << VERSION << "\n";
 
		std::cout << "verze\n";
 
		g_option_context_free(context);
 
		return 0;
 
	}
 

	
 
	if (argc != 2) {
 
#ifdef WIN32
 
		std::cout << "Usage: spectrum.exe <configuration_file.cfg>\n";
 
#else
 

	
0 comments (0 inline, 0 general)