summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-21 10:07:49 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-21 10:07:49 (GMT)
commitabd4d8981ebc5ad579102002483f410a5d4d79da (patch)
treeddf347f77653c64d81e8e087f34d1243c6b68d0d /Slimber/Cocoa
parentabba8740ba29f05eef23a826e3095214f51bd0a4 (diff)
downloadswift-abd4d8981ebc5ad579102002483f410a5d4d79da.zip
swift-abd4d8981ebc5ad579102002483f410a5d4d79da.tar.bz2
Update the "You are logged in" menu.
Diffstat (limited to 'Slimber/Cocoa')
-rw-r--r--Slimber/Cocoa/Makefile.inc2
-rw-r--r--Slimber/Cocoa/Menulet.h3
-rw-r--r--Slimber/Cocoa/Menulet.m36
-rw-r--r--Slimber/Cocoa/Slimber.h3
-rw-r--r--Slimber/Cocoa/Slimber.mm5
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];
+}