summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Slimber/Cocoa/Menulet.m')
-rw-r--r--Slimber/Cocoa/Menulet.m36
1 files changed, 31 insertions, 5 deletions
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