summaryrefslogtreecommitdiffstats
blob: ae1d9fd9c918700475a1934ab2b91077e889d77c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "Slimber/Cocoa/Slimber.h"

#include "Swiften/Base/foreach.h"
#include "Swiften/Elements/RosterPayload.h"
#include "Swiften/LinkLocal/AppleDNSSDService.h"
#include "Swiften/Application/Platform/PlatformApplication.h"
#include "Slimber/Cocoa/Menulet.h"
#include "Slimber/Server.h"
#include "Slimber/FileVCardCollection.h"

using namespace Swift;

Slimber::Slimber() {
	dnsSDService = boost::shared_ptr<AppleDNSSDService>(new AppleDNSSDService());

	linkLocalRoster = boost::shared_ptr<LinkLocalRoster>(new LinkLocalRoster(dnsSDService));
	linkLocalRoster->onRosterChanged.connect(boost::bind(&Slimber::handleRosterChanged, this));

	vCardCollection = new FileVCardCollection(PlatformApplication("Slimber").getSettingsDir());

	server = new Server(5222, 5562, linkLocalRoster, dnsSDService, vCardCollection);
	server->onSelfConnected.connect(boost::bind(&Slimber::handleSelfConnected, this, _1));

	menulet = [[Menulet alloc] init];
	handleRosterChanged();
}

Slimber::~Slimber() {
	[menulet release];
	delete server;
	delete vCardCollection;
}

void Slimber::handleSelfConnected(bool b) {
	[menulet setSelfConnected: b];
}

void Slimber::handleRosterChanged() {
	NSMutableArray* names = [[NSMutableArray alloc] init];
	boost::shared_ptr<RosterPayload> roster = linkLocalRoster->getRoster();
	foreach(const RosterItemPayload& item, roster->getItems()) {
		NSString* name = [NSString stringWithUTF8String: item.getName().getUTF8Data()];
		[names addObject: name];
		[name release];
	}

	[menulet setUserNames: names];
	[names release];
}