summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-21 09:11:26 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-21 09:11:26 (GMT)
commitabba8740ba29f05eef23a826e3095214f51bd0a4 (patch)
tree49c9c176669c6ff41c266b36f4c0e5beb028ba5c /Slimber
parent1642d13e5e8d593a36ef1945387794e0d13247be (diff)
downloadswift-abba8740ba29f05eef23a826e3095214f51bd0a4.zip
swift-abba8740ba29f05eef23a826e3095214f51bd0a4.tar.bz2
Create Slimber controller.
Diffstat (limited to 'Slimber')
-rw-r--r--Slimber/Cocoa/MainController.h9
-rw-r--r--Slimber/Cocoa/MainController.mm15
-rw-r--r--Slimber/Cocoa/MainMenu.xib45
-rw-r--r--Slimber/Cocoa/Makefile.inc6
-rw-r--r--Slimber/Cocoa/Menulet.h8
-rw-r--r--Slimber/Cocoa/Menulet.m48
-rw-r--r--Slimber/Cocoa/Slimber.h22
-rw-r--r--Slimber/Cocoa/Slimber.mm18
-rw-r--r--Slimber/Cocoa/main.mm13
9 files changed, 106 insertions, 78 deletions
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 <Cocoa/Cocoa.h>
+
+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 @@
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="205"/>
- <integer value="459"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -1115,13 +1114,7 @@
<string key="NSClassName">NSFontManager</string>
</object>
<object class="NSCustomObject" id="16040424">
- <string key="NSClassName">Menulet</string>
- </object>
- <object class="NSMenu" id="794994331">
- <string key="NSTitle"/>
- <object class="NSMutableArray" key="NSMenuItems">
- <bool key="EncodedWithXMLCoder">YES</bool>
- </object>
+ <string key="NSClassName">MainController</string>
</object>
</object>
<object class="IBObjectContainer" key="IBDocument.Objects">
@@ -1655,14 +1648,6 @@
</object>
<int key="connectionID">449</int>
</object>
- <object class="IBConnectionRecord">
- <object class="IBOutletConnection" key="connection">
- <string key="label">statusMenu</string>
- <reference key="source" ref="16040424"/>
- <reference key="destination" ref="794994331"/>
- </object>
- <int key="connectionID">463</int>
- </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -2550,14 +2535,6 @@
<reference key="object" ref="16040424"/>
<reference key="parent" ref="1049"/>
</object>
- <object class="IBObjectRecord">
- <int key="objectID">459</int>
- <reference key="object" ref="794994331"/>
- <object class="NSMutableArray" key="children">
- <bool key="EncodedWithXMLCoder">YES</bool>
- </object>
- <reference key="parent" ref="1049"/>
- </object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
@@ -2746,8 +2723,6 @@
<string>419.IBPluginDependency</string>
<string>420.IBPluginDependency</string>
<string>458.IBPluginDependency</string>
- <string>459.IBEditorWindowLastContentRect</string>
- <string>459.IBPluginDependency</string>
<string>5.IBPluginDependency</string>
<string>5.ImportedFromIB2</string>
<string>56.IBPluginDependency</string>
@@ -2969,8 +2944,6 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{342, 743}, {64, 6}}</string>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -3032,22 +3005,14 @@
<int key="maxID">463</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
- <object class="NSMutableArray" key="referencedPartialClassDescriptions">
+ <object class="NSMutableArray" key="referencedPartialClassDescriptionsV3.1+">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBPartialClassDescription">
- <string key="className">Menulet</string>
+ <string key="className">MainController</string>
<string key="superclassName">NSObject</string>
- <object class="NSMutableDictionary" key="actions">
- <string key="NS.key.0">updateStatus:</string>
- <string key="NS.object.0">id</string>
- </object>
- <object class="NSMutableDictionary" key="outlets">
- <string key="NS.key.0">statusMenu</string>
- <string key="NS.object.0">NSMenu</string>
- </object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
- <string key="majorKey">IBProjectSource</string>
- <string key="minorKey">Menulet.h</string>
+ <string key="majorKey">IBDocumentRelativeSource</string>
+ <string key="minorKey">MainController.h</string>
</object>
</object>
</object>
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 <Cocoa/Cocoa.h>
-
+#include <Cocoa/Cocoa.h>
@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 <string>
+#include <boost/bind.hpp>
+
+#include "Swiften/LinkLocal/DNSSDService.h"
+
+@class Menulet;
+namespace Swift {
+ class Server;
+}
+
+class Slimber {
+ public:
+ Slimber();
+ ~Slimber();
+
+ private:
+ boost::shared_ptr<Swift::DNSSDService> 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<AppleDNSSDService>(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 <Cocoa/Cocoa.h>
-#include <string>
-#include <boost/bind.hpp>
-#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> dnsSDService=
- boost::shared_ptr<AppleDNSSDService>(new AppleDNSSDService());
- Server server(5222, 5562, dnsSDService);
-
+ Swift::CocoaEventLoop eventLoop;
return NSApplicationMain(argc, const_cast<const char **>(argv));
}