From abba8740ba29f05eef23a826e3095214f51bd0a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Tue, 21 Jul 2009 11:11:26 +0200 Subject: Create Slimber controller. diff --git a/Slimber/Cocoa/MainController.h b/Slimber/Cocoa/MainController.h new file mode 100644 index 0000000..c6e20c5 --- /dev/null +++ b/Slimber/Cocoa/MainController.h @@ -0,0 +1,9 @@ +#include + +class Slimber; + +@interface MainController : NSObject { + Slimber* slimber; +} + +@end diff --git a/Slimber/Cocoa/MainController.mm b/Slimber/Cocoa/MainController.mm new file mode 100644 index 0000000..30b7a16 --- /dev/null +++ b/Slimber/Cocoa/MainController.mm @@ -0,0 +1,15 @@ +#include "MainController.h" +#include "Slimber.h" + +@implementation MainController + +- (void) dealloc { + delete slimber; + [super dealloc]; +} + +- (void) awakeFromNib { + slimber = new Slimber(); +} + +@end diff --git a/Slimber/Cocoa/MainMenu.xib b/Slimber/Cocoa/MainMenu.xib index 5959306..a5eb7e1 100644 --- a/Slimber/Cocoa/MainMenu.xib +++ b/Slimber/Cocoa/MainMenu.xib @@ -9,7 +9,6 @@ YES - YES @@ -1115,13 +1114,7 @@ NSFontManager - Menulet - - - - - YES - + MainController @@ -1655,14 +1648,6 @@ 449 - - - statusMenu - - - - 463 - @@ -2550,14 +2535,6 @@ - - 459 - - - YES - - - @@ -2746,8 +2723,6 @@ 419.IBPluginDependency 420.IBPluginDependency 458.IBPluginDependency - 459.IBEditorWindowLastContentRect - 459.IBPluginDependency 5.IBPluginDependency 5.ImportedFromIB2 56.IBPluginDependency @@ -2969,8 +2944,6 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{342, 743}, {64, 6}} - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -3032,22 +3005,14 @@ 463 - + YES - Menulet + MainController NSObject - - updateStatus: - id - - - statusMenu - NSMenu - - IBProjectSource - Menulet.h + IBDocumentRelativeSource + MainController.h diff --git a/Slimber/Cocoa/Makefile.inc b/Slimber/Cocoa/Makefile.inc index 6f0aa13..e858430 100644 --- a/Slimber/Cocoa/Makefile.inc +++ b/Slimber/Cocoa/Makefile.inc @@ -3,7 +3,9 @@ SLIMBER_COCOA_BINARY = \ Slimber/Cocoa/Slimber SLIMBER_COCOA_SOURCES = \ Slimber/Server.cpp \ - Slimber/Cocoa/main.m \ + Slimber/Cocoa/MainController.mm \ + Slimber/Cocoa/Slimber.mm \ + Slimber/Cocoa/main.mm \ Slimber/Cocoa/Menulet.m SLIMBER_COCOA_XIBS = \ Slimber/Cocoa/MainMenu.xib @@ -14,7 +16,7 @@ SLIMBER_COCOA_RESOURCES = \ SLIMBER_COCOA_NIBS = \ $(SLIMBER_COCOA_XIBS:.xib=.nib) SLIMBER_COCOA_OBJECTS = \ - $(patsubst %.m,%.o,$(patsubst %.cpp,%.o, $(SLIMBER_COCOA_SOURCES))) + $(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 c676630..46c4faa 100644 --- a/Slimber/Cocoa/Menulet.h +++ b/Slimber/Cocoa/Menulet.h @@ -1,12 +1,12 @@ -#import - +#include @interface Menulet : NSObject { NSStatusItem* statusItem; - IBOutlet NSMenu* statusMenu; + NSMenu* statusMenu; NSImage* menuIcon; } --(IBAction) updateStatus: (id) sender; +- (id) init; +- (void) updateMenu; @end diff --git a/Slimber/Cocoa/Menulet.m b/Slimber/Cocoa/Menulet.m index 2f0f465..613d05d 100644 --- a/Slimber/Cocoa/Menulet.m +++ b/Slimber/Cocoa/Menulet.m @@ -2,36 +2,44 @@ @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]; + + NSBundle* bundle = [NSBundle bundleForClass: [self class]]; + NSString* path = [bundle pathForResource: @"Offline" ofType:@"png"]; + menuIcon = [[NSImage alloc] initWithContentsOfFile: path]; + [statusItem setImage: menuIcon]; + + [self updateMenu]; + } + return self; +} + - (void) dealloc { [statusItem release]; [menuIcon release]; [super dealloc]; } -- (void) awakeFromNib { - statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength: NSVariableStatusItemLength] retain]; - [statusItem setHighlightMode: YES]; - [statusItem setEnabled: YES]; - [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]; - - NSMenuItem* statusMenuItem = [[NSMenuItem alloc] initWithTitle: @"Online Users" action: NULL keyEquivalent:@""]; +- (void) updateMenu { + 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 = [[NSMenuItem alloc] initWithTitle: @"You are not logged in" action: NULL keyEquivalent: @""]; [statusMenu addItem: loggedInItem]; -} + [statusMenu addItem: [NSMenuItem separatorItem]]; -- (IBAction) updateStatus: (id) sender { - [statusItem setTitle: [NSString stringWithString:@"Boo"]]; - NSMenuItem* statusMenuItem = [[NSMenuItem alloc] initWithTitle: @"Foo" action: @selector(updateStatus:) keyEquivalent:@""]; - [statusMenuItem setTitle:[NSString stringWithString:@"Boo"]]; - [statusMenu insertItem: statusMenuItem atIndex:1]; + NSMenuItem* exitMenuItem = [[NSMenuItem alloc] initWithTitle: @"Exit" action: @selector(terminate:) keyEquivalent: @""]; + [exitMenuItem setTarget: [NSApplication sharedApplication]]; + [statusMenu addItem: exitMenuItem]; } @end diff --git a/Slimber/Cocoa/Slimber.h b/Slimber/Cocoa/Slimber.h new file mode 100644 index 0000000..1ee9040 --- /dev/null +++ b/Slimber/Cocoa/Slimber.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include + +#include "Swiften/LinkLocal/DNSSDService.h" + +@class Menulet; +namespace Swift { + class Server; +} + +class Slimber { + public: + Slimber(); + ~Slimber(); + + private: + boost::shared_ptr dnsSDService; + Swift::Server* server; + Menulet* menulet; +}; diff --git a/Slimber/Cocoa/Slimber.mm b/Slimber/Cocoa/Slimber.mm new file mode 100644 index 0000000..4bf72fe --- /dev/null +++ b/Slimber/Cocoa/Slimber.mm @@ -0,0 +1,18 @@ +#include "Slimber/Cocoa/Slimber.h" + +#include "Swiften/LinkLocal/AppleDNSSDService.h" +#include "Slimber/Cocoa/Menulet.h" +#include "Slimber/Server.h" + +using namespace Swift; + +Slimber::Slimber() { + dnsSDService = boost::shared_ptr(new AppleDNSSDService()); + server = new Server(5222, 5562, dnsSDService); + menulet = [[Menulet alloc] init]; +} + +Slimber::~Slimber() { + delete server; + [menulet release]; +} diff --git a/Slimber/Cocoa/main.mm b/Slimber/Cocoa/main.mm index e777e0d..e267477 100644 --- a/Slimber/Cocoa/main.mm +++ b/Slimber/Cocoa/main.mm @@ -1,19 +1,8 @@ #include -#include -#include -#include "Swiften/LinkLocal/AppleDNSSDService.h" #include "Swiften/EventLoop/Cocoa/CocoaEventLoop.h" -#include "Slimber/Server.h" - -using namespace Swift; int main(int argc, char *argv[]) { - CocoaEventLoop eventLoop; - - boost::shared_ptr dnsSDService= - boost::shared_ptr(new AppleDNSSDService()); - Server server(5222, 5562, dnsSDService); - + Swift::CocoaEventLoop eventLoop; return NSApplicationMain(argc, const_cast(argv)); } -- cgit v0.10.2-6-g49f6