summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-08-02 08:27:38 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-08-02 11:08:12 (GMT)
commit7368b120827e4e9da659da62398bb37a68c19ab5 (patch)
tree150034061db35320a13460b5dfb3613f0f4093b0 /Slimber/Cocoa/Menulet.m
parent188ff36e3fbfdc174ea75babc1deb3aebcf1472b (diff)
downloadswift-contrib-7368b120827e4e9da659da62398bb37a68c19ab5.zip
swift-contrib-7368b120827e4e9da659da62398bb37a68c19ab5.tar.bz2
Slimber: Abstract controllers out of Cocoa UI.
Diffstat (limited to 'Slimber/Cocoa/Menulet.m')
-rw-r--r--Slimber/Cocoa/Menulet.m105
1 files changed, 0 insertions, 105 deletions
diff --git a/Slimber/Cocoa/Menulet.m b/Slimber/Cocoa/Menulet.m
deleted file mode 100644
index 2a62992..0000000
--- a/Slimber/Cocoa/Menulet.m
+++ /dev/null
@@ -1,105 +0,0 @@
-#import "Menulet.h"
-
-@implementation Menulet
-
-- (id) init {
- if ([super init]) {
- statusMenu = [[NSMenu alloc] init];
-
- statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength: NSVariableStatusItemLength] retain];
- [statusItem setHighlightMode: YES];
- [statusItem setEnabled: YES];
- [statusItem setToolTip: @"Slimber"];
- [statusItem setMenu: statusMenu];
-
- xmppStatus = @"";
- xmppOnline = NO;
- userNames = [[NSArray alloc] init];
-
- [self updateMenu];
- }
- return self;
-}
-
-- (void) dealloc {
- [statusItem release];
- [menuIcon release];
- [super dealloc];
-}
-
-- (void) updateIcon: (BOOL) online {
- NSBundle* bundle = [NSBundle bundleForClass: [self class]];
- NSString* path;
- if (online) {
- path = [bundle pathForResource: @"UsersOnline" ofType:@"png"];
- }
- else {
- path = [bundle pathForResource: @"UsersOffline" ofType:@"png"];
- }
- [statusItem setImage: [[NSImage alloc] initWithContentsOfFile: path]];
-}
-
-- (void) updateMenu {
- // Clear the menu
- while ([statusMenu numberOfItems] > 0) {
- [statusMenu removeItemAtIndex: 0];
- }
-
- // User items
- if ([userNames count] > 0) {
- [statusMenu addItem: [[NSMenuItem alloc] initWithTitle: @"Online users:" action: NULL keyEquivalent: @""]];
- int i;
- for (i = 0; i < [userNames count]; ++i) {
- NSString* text = [NSString stringWithFormat: @" %@", [userNames objectAtIndex: i]];
- NSMenuItem* userItem = [[NSMenuItem alloc] initWithTitle: text action: NULL keyEquivalent: @""];
- [statusMenu addItem: userItem];
- [userItem release];
- }
- }
- else {
- [statusMenu addItem: [[NSMenuItem alloc] initWithTitle: @"No online users" action: NULL keyEquivalent: @""]];
- }
- [self updateIcon: [userNames count] > 0];
- [statusMenu addItem: [NSMenuItem separatorItem]];
-
- // Self item
- NSMenuItem* loggedInItem;
- NSBundle* bundle = [NSBundle bundleForClass: [self class]];
- NSString* path;
- loggedInItem = [[NSMenuItem alloc] initWithTitle: xmppStatus action: NULL keyEquivalent: @""];
- if (xmppOnline) {
- path = [bundle pathForResource: @"Online" ofType:@"png"];
- }
- else {
- path = [bundle pathForResource: @"Offline" ofType:@"png"];
- }
- [loggedInItem setImage: [[NSImage alloc] initWithContentsOfFile: path]];
- [statusMenu addItem: loggedInItem];
- [statusMenu addItem: [NSMenuItem separatorItem]];
-
- // About menu
- NSMenuItem* aboutMenuItem = [[NSMenuItem alloc] initWithTitle: @"About Slimber" action: @selector(orderFrontStandardAboutPanel:) keyEquivalent: @""];
- [aboutMenuItem setTarget: [NSApplication sharedApplication]];
- [statusMenu addItem: aboutMenuItem];
- [statusMenu addItem: [NSMenuItem separatorItem]];
-
- // Exit item
- NSMenuItem* exitMenuItem = [[NSMenuItem alloc] initWithTitle: @"Exit" action: @selector(terminate:) keyEquivalent: @""];
- [exitMenuItem setTarget: [NSApplication sharedApplication]];
- [statusMenu addItem: exitMenuItem];
-}
-
-- (void) setXMPPStatus: (NSString*) status online: (BOOL) online {
- xmppStatus = status; // TODO: Should I retain status?
- xmppOnline = online;
- [self updateMenu];
-}
-
-- (void) setUserNames: (NSArray*) names {
- [names retain];
- [userNames release];
- userNames = names;
- [self updateMenu];
-}
-
-@end