diff options
Diffstat (limited to 'Slimber/Cocoa')
-rw-r--r-- | Slimber/Cocoa/Makefile.inc | 2 | ||||
-rw-r--r-- | Slimber/Cocoa/Menulet.h | 3 | ||||
-rw-r--r-- | Slimber/Cocoa/Menulet.m | 36 | ||||
-rw-r--r-- | Slimber/Cocoa/Slimber.h | 3 | ||||
-rw-r--r-- | Slimber/Cocoa/Slimber.mm | 5 |
5 files changed, 43 insertions, 6 deletions
diff --git a/Slimber/Cocoa/Makefile.inc b/Slimber/Cocoa/Makefile.inc index e858430..be03429 100644 --- a/Slimber/Cocoa/Makefile.inc +++ b/Slimber/Cocoa/Makefile.inc @@ -16,7 +16,7 @@ SLIMBER_COCOA_RESOURCES = \ SLIMBER_COCOA_NIBS = \ $(SLIMBER_COCOA_XIBS:.xib=.nib) SLIMBER_COCOA_OBJECTS = \ - $(patsubst %.mm,%.o,$(patsubst %.cpp,%.o, $(SLIMBER_COCOA_SOURCES))) + $(patsubst %.m,%.o,$(patsubst %.mm,%.o,$(patsubst %.cpp,%.o, $(SLIMBER_COCOA_SOURCES)))) CLEANFILES += \ Slimber/Cocoa/PkgInfo \ $(SLIMBER_COCOA_OBJECTS) \ diff --git a/Slimber/Cocoa/Menulet.h b/Slimber/Cocoa/Menulet.h index 46c4faa..dfe07a0 100644 --- a/Slimber/Cocoa/Menulet.h +++ b/Slimber/Cocoa/Menulet.h @@ -4,9 +4,12 @@ NSStatusItem* statusItem; NSMenu* statusMenu; NSImage* menuIcon; + BOOL selfOnline; } - (id) init; - (void) updateMenu; +- (void) setUsersOnline: (BOOL) online; +- (void) setSelfConnected: (BOOL) online; @end diff --git a/Slimber/Cocoa/Menulet.m b/Slimber/Cocoa/Menulet.m index 613d05d..f72078e 100644 --- a/Slimber/Cocoa/Menulet.m +++ b/Slimber/Cocoa/Menulet.m @@ -12,10 +12,8 @@ [statusItem setToolTip: @"Slimber"]; [statusItem setMenu: statusMenu]; - NSBundle* bundle = [NSBundle bundleForClass: [self class]]; - NSString* path = [bundle pathForResource: @"Offline" ofType:@"png"]; - menuIcon = [[NSImage alloc] initWithContentsOfFile: path]; - [statusItem setImage: menuIcon]; + [self setUsersOnline: NO]; + selfOnline = NO; [self updateMenu]; } @@ -29,11 +27,21 @@ } - (void) updateMenu { + while ([statusMenu numberOfItems] > 0) { + [statusMenu removeItemAtIndex: 0]; + } + NSMenuItem* statusMenuItem = [[NSMenuItem alloc] initWithTitle: @"Online Users" action: NULL keyEquivalent: @""]; [statusMenu addItem: statusMenuItem]; [statusMenu addItem: [NSMenuItem separatorItem]]; - NSMenuItem* loggedInItem = [[NSMenuItem alloc] initWithTitle: @"You are not logged in" action: NULL keyEquivalent: @""]; + NSMenuItem* loggedInItem; + if (selfOnline) { + loggedInItem = [[NSMenuItem alloc] initWithTitle: @"You are logged in" action: NULL keyEquivalent: @""]; + } + else { + loggedInItem = [[NSMenuItem alloc] initWithTitle: @"You are not logged in" action: NULL keyEquivalent: @""]; + } [statusMenu addItem: loggedInItem]; [statusMenu addItem: [NSMenuItem separatorItem]]; @@ -42,4 +50,22 @@ [statusMenu addItem: exitMenuItem]; } +- (void) setUsersOnline: (BOOL) online { + NSBundle* bundle = [NSBundle bundleForClass: [self class]]; + NSString* path; + if (online) { + path = [bundle pathForResource: @"Online" ofType:@"png"]; + } + else { + path = [bundle pathForResource: @"Offline" ofType:@"png"]; + } + menuIcon = [[NSImage alloc] initWithContentsOfFile: path]; + [statusItem setImage: menuIcon]; +} + +- (void) setSelfConnected: (BOOL) online { + selfOnline = online; + [self updateMenu]; +} + @end diff --git a/Slimber/Cocoa/Slimber.h b/Slimber/Cocoa/Slimber.h index 1ee9040..f5a02d7 100644 --- a/Slimber/Cocoa/Slimber.h +++ b/Slimber/Cocoa/Slimber.h @@ -16,6 +16,9 @@ class Slimber { ~Slimber(); private: + void handleSelfConnected(bool b); + + private: boost::shared_ptr<Swift::DNSSDService> dnsSDService; Swift::Server* server; Menulet* menulet; diff --git a/Slimber/Cocoa/Slimber.mm b/Slimber/Cocoa/Slimber.mm index 4bf72fe..74d95ef 100644 --- a/Slimber/Cocoa/Slimber.mm +++ b/Slimber/Cocoa/Slimber.mm @@ -9,6 +9,7 @@ using namespace Swift; Slimber::Slimber() { dnsSDService = boost::shared_ptr<AppleDNSSDService>(new AppleDNSSDService()); server = new Server(5222, 5562, dnsSDService); + server->onSelfConnected.connect(boost::bind(&Slimber::handleSelfConnected, this, _1)); menulet = [[Menulet alloc] init]; } @@ -16,3 +17,7 @@ Slimber::~Slimber() { delete server; [menulet release]; } + +void Slimber::handleSelfConnected(bool b) { + [menulet setSelfConnected: b]; +} |