diff options
author | Remko Tronçon <git@el-tramo.be> | 2009-07-21 11:24:26 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2009-07-21 11:30:57 (GMT) |
commit | 052f685338462a8c0c6d9785864e7549290d7037 (patch) | |
tree | f076b9981c62dc6913badf675c22caf6cbfcd874 /Slimber/Cocoa/Slimber.mm | |
parent | 06a69020da6ffb527bb2a31f1da2158df2a4d3de (diff) | |
download | swift-contrib-052f685338462a8c0c6d9785864e7549290d7037.zip swift-contrib-052f685338462a8c0c6d9785864e7549290d7037.tar.bz2 |
Show list of connected users.
Diffstat (limited to 'Slimber/Cocoa/Slimber.mm')
-rw-r--r-- | Slimber/Cocoa/Slimber.mm | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/Slimber/Cocoa/Slimber.mm b/Slimber/Cocoa/Slimber.mm index 74d95ef..d64cd58 100644 --- a/Slimber/Cocoa/Slimber.mm +++ b/Slimber/Cocoa/Slimber.mm @@ -1,5 +1,7 @@ #include "Slimber/Cocoa/Slimber.h" +#include "Swiften/Base/foreach.h" +#include "Swiften/Elements/RosterPayload.h" #include "Swiften/LinkLocal/AppleDNSSDService.h" #include "Slimber/Cocoa/Menulet.h" #include "Slimber/Server.h" @@ -8,9 +10,15 @@ using namespace Swift; Slimber::Slimber() { dnsSDService = boost::shared_ptr<AppleDNSSDService>(new AppleDNSSDService()); - server = new Server(5222, 5562, dnsSDService); + + linkLocalRoster = boost::shared_ptr<LinkLocalRoster>(new LinkLocalRoster(dnsSDService)); + linkLocalRoster->onRosterChanged.connect(boost::bind(&Slimber::handleRosterChanged, this)); + + server = new Server(5222, 5562, linkLocalRoster, dnsSDService); server->onSelfConnected.connect(boost::bind(&Slimber::handleSelfConnected, this, _1)); + menulet = [[Menulet alloc] init]; + handleRosterChanged(); } Slimber::~Slimber() { @@ -21,3 +29,16 @@ Slimber::~Slimber() { 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]; +} |