diff options
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]; +} |