summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Slimber/Cocoa')
-rw-r--r--Slimber/Cocoa/CocoaAction.h20
-rw-r--r--Slimber/Cocoa/CocoaAction.mm22
-rw-r--r--Slimber/Cocoa/CocoaController.h11
-rw-r--r--Slimber/Cocoa/CocoaController.mm19
-rw-r--r--Slimber/Cocoa/CocoaMenulet.h26
-rw-r--r--Slimber/Cocoa/CocoaMenulet.mm79
-rw-r--r--Slimber/Cocoa/Info.plist5
-rw-r--r--Slimber/Cocoa/MainController.h9
-rw-r--r--Slimber/Cocoa/MainController.mm15
-rw-r--r--Slimber/Cocoa/MainMenu.xib6
-rw-r--r--Slimber/Cocoa/Makefile.inc13
-rw-r--r--Slimber/Cocoa/Menulet.h16
-rw-r--r--Slimber/Cocoa/Menulet.m104
-rw-r--r--Slimber/Cocoa/Slimber.h28
-rw-r--r--Slimber/Cocoa/Slimber.mm61
15 files changed, 191 insertions, 243 deletions
diff --git a/Slimber/Cocoa/CocoaAction.h b/Slimber/Cocoa/CocoaAction.h
new file mode 100644
index 0000000..d02c8b5
--- /dev/null
+++ b/Slimber/Cocoa/CocoaAction.h
@@ -0,0 +1,20 @@
+#pragma once
+
+#include <Cocoa/Cocoa.h>
+#include <boost/function.hpp>
+
+@interface CocoaAction : NSObject {
+ boost::function<void ()>* function;
+}
+
+/**
+ * Acquires ownership of 'f'.
+ */
+- (id) initWithFunction: (boost::function<void()>*) f;
+
+/**
+ * Calls the functor passed as a parameter to the contsructor.
+ */
+- (void) doAction: (id) sender;
+
+@end
diff --git a/Slimber/Cocoa/CocoaAction.mm b/Slimber/Cocoa/CocoaAction.mm
new file mode 100644
index 0000000..15498a1
--- /dev/null
+++ b/Slimber/Cocoa/CocoaAction.mm
@@ -0,0 +1,22 @@
+#include "Slimber/Cocoa/CocoaAction.h"
+
+@implementation CocoaAction
+
+- (id) initWithFunction: (boost::function<void()>*) f {
+ if ([super init]) {
+ function = f;
+ }
+ return self;
+}
+
+- (void) dealloc {
+ delete function;
+ [super dealloc];
+}
+
+- (void) doAction: (id) sender {
+ (void) sender;
+ (*function)();
+}
+
+@end
diff --git a/Slimber/Cocoa/CocoaController.h b/Slimber/Cocoa/CocoaController.h
new file mode 100644
index 0000000..f4be87d
--- /dev/null
+++ b/Slimber/Cocoa/CocoaController.h
@@ -0,0 +1,11 @@
+#include <Cocoa/Cocoa.h>
+
+class MainController;
+class CocoaMenulet;
+
+@interface CocoaController : NSObject {
+ CocoaMenulet* menulet;
+ MainController* main;
+}
+
+@end
diff --git a/Slimber/Cocoa/CocoaController.mm b/Slimber/Cocoa/CocoaController.mm
new file mode 100644
index 0000000..437d85a
--- /dev/null
+++ b/Slimber/Cocoa/CocoaController.mm
@@ -0,0 +1,19 @@
+#include "Slimber/Cocoa/CocoaController.h"
+
+#include "Slimber/MainController.h"
+#include "Slimber/Cocoa/CocoaMenulet.h"
+
+@implementation CocoaController
+
+- (void) dealloc {
+ delete main;
+ delete menulet;
+ [super dealloc];
+}
+
+- (void) awakeFromNib {
+ menulet = new CocoaMenulet();
+ main = new MainController(menulet);
+}
+
+@end
diff --git a/Slimber/Cocoa/CocoaMenulet.h b/Slimber/Cocoa/CocoaMenulet.h
new file mode 100644
index 0000000..913731f
--- /dev/null
+++ b/Slimber/Cocoa/CocoaMenulet.h
@@ -0,0 +1,26 @@
+#pragma once
+
+#include <Cocoa/Cocoa.h>
+
+#include "Slimber/Menulet.h"
+#include "Slimber/Cocoa/CocoaAction.h"
+
+class CocoaMenulet : public Menulet {
+ public:
+ CocoaMenulet();
+ ~CocoaMenulet();
+
+ private:
+ virtual void clear();
+ virtual void addItem(const Swift::String& name, const Swift::String& icon);
+ virtual void addSeparator();
+ void setIcon(const Swift::String& icon);
+ virtual void addAboutItem();
+ virtual void addRestartItem();
+ virtual void addExitItem();
+
+ private:
+ NSStatusItem* statusItem;
+ NSMenu* menu;
+ CocoaAction* restartAction;
+};
diff --git a/Slimber/Cocoa/CocoaMenulet.mm b/Slimber/Cocoa/CocoaMenulet.mm
new file mode 100644
index 0000000..72ab000
--- /dev/null
+++ b/Slimber/Cocoa/CocoaMenulet.mm
@@ -0,0 +1,79 @@
+#include "Slimber/Cocoa/CocoaMenulet.h"
+
+#include <boost/function.hpp>
+
+using namespace Swift;
+
+CocoaMenulet::CocoaMenulet() {
+ restartAction = [[CocoaAction alloc] initWithFunction:
+ new boost::function<void()>(boost::ref(onRestartClicked))];
+ menu = [[NSMenu alloc] init];
+
+ statusItem = [[[NSStatusBar systemStatusBar]
+ statusItemWithLength: NSVariableStatusItemLength] retain];
+ [statusItem setHighlightMode: YES];
+ [statusItem setEnabled: YES];
+ [statusItem setToolTip: @"Slimber"];
+ [statusItem setMenu: menu];
+}
+
+CocoaMenulet::~CocoaMenulet() {
+ [statusItem release];
+ [menu release];
+ [restartAction release];
+}
+
+void CocoaMenulet::setIcon(const String& icon) {
+ NSString* path = [[NSBundle mainBundle] pathForResource:
+ [NSString stringWithUTF8String: icon.getUTF8Data()] ofType:@"png"];
+ NSImage* image = [[NSImage alloc] initWithContentsOfFile: path];
+ [statusItem setImage: image];
+ [image release];
+}
+
+void CocoaMenulet::clear() {
+ while ([menu numberOfItems] > 0) {
+ [menu removeItemAtIndex: 0];
+ }
+}
+
+void CocoaMenulet::addItem(const Swift::String& name, const String& icon) {
+ NSMenuItem* item = [[NSMenuItem alloc] initWithTitle:
+ [NSString stringWithUTF8String: name.getUTF8Data()]
+ action: NULL keyEquivalent: @""];
+ if (!icon.isEmpty()) {
+ NSString* path = [[NSBundle mainBundle] pathForResource:
+ [NSString stringWithUTF8String: icon.getUTF8Data()] ofType:@"png"];
+ NSImage* image = [[NSImage alloc] initWithContentsOfFile: path];
+ [item setImage: [[NSImage alloc] initWithContentsOfFile: path]];
+ [image release];
+ }
+ [menu addItem: item];
+ [item release];
+}
+
+void CocoaMenulet::addAboutItem() {
+ NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"About Slimber" action: @selector(orderFrontStandardAboutPanel:) keyEquivalent: @""];
+ [item setTarget: [NSApplication sharedApplication]];
+ [menu addItem: item];
+ [item release];
+}
+
+void CocoaMenulet::addRestartItem() {
+ NSMenuItem* item = [[NSMenuItem alloc] initWithTitle:
+ @"Restart" action: @selector(doAction:) keyEquivalent: @""];
+ [item setTarget: restartAction];
+ [menu addItem: item];
+ [item release];
+}
+
+void CocoaMenulet::addExitItem() {
+ NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"Exit" action: @selector(terminate:) keyEquivalent: @""];
+ [item setTarget: [NSApplication sharedApplication]];
+ [menu addItem: item];
+ [item release];
+}
+
+void CocoaMenulet::addSeparator() {
+ [menu addItem: [NSMenuItem separatorItem]];
+}
diff --git a/Slimber/Cocoa/Info.plist b/Slimber/Cocoa/Info.plist
index f934a10..d954dba 100644
--- a/Slimber/Cocoa/Info.plist
+++ b/Slimber/Cocoa/Info.plist
@@ -18,6 +18,8 @@
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
+ <key>CFBundleIconFile</key>
+ <string>Slimber</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
@@ -25,6 +27,7 @@
<key>LSUIElement</key>
<string>1</string>
<key>NSHumanReadableCopyright</key>
- <string>© 2009 Swift Development Team. All Rights Reserved.</string>
+ <string>© 2009 Swift Development Team.
+All Rights Reserved.</string>
</dict>
</plist>
diff --git a/Slimber/Cocoa/MainController.h b/Slimber/Cocoa/MainController.h
deleted file mode 100644
index c6e20c5..0000000
--- a/Slimber/Cocoa/MainController.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <Cocoa/Cocoa.h>
-
-class Slimber;
-
-@interface MainController : NSObject {
- Slimber* slimber;
-}
-
-@end
diff --git a/Slimber/Cocoa/MainController.mm b/Slimber/Cocoa/MainController.mm
deleted file mode 100644
index 30b7a16..0000000
--- a/Slimber/Cocoa/MainController.mm
+++ /dev/null
@@ -1,15 +0,0 @@
-#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 50e4ca3..bed7223 100644
--- a/Slimber/Cocoa/MainMenu.xib
+++ b/Slimber/Cocoa/MainMenu.xib
@@ -180,7 +180,7 @@
<string key="NSName">_NSMainMenu</string>
</object>
<object class="NSCustomObject" id="16040424">
- <string key="NSClassName">MainController</string>
+ <string key="NSClassName">CocoaController</string>
</object>
</object>
<object class="IBObjectContainer" key="IBDocument.Objects">
@@ -482,11 +482,11 @@
<object class="NSMutableArray" key="referencedPartialClassDescriptionsV3.1+">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBPartialClassDescription">
- <string key="className">MainController</string>
+ <string key="className">CocoaController</string>
<string key="superclassName">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBDocumentRelativeSource</string>
- <string key="minorKey">MainController.h</string>
+ <string key="minorKey">CocoaController.h</string>
</object>
</object>
</object>
diff --git a/Slimber/Cocoa/Makefile.inc b/Slimber/Cocoa/Makefile.inc
index 8cd72cd..cdb19b7 100644
--- a/Slimber/Cocoa/Makefile.inc
+++ b/Slimber/Cocoa/Makefile.inc
@@ -2,13 +2,14 @@ SLIMBER_COCOA_TARGET = Slimber/Cocoa/Slimber.app
SLIMBER_COCOA_BINARY = \
Slimber/Cocoa/Slimber
SLIMBER_COCOA_SOURCES = \
- Slimber/Cocoa/MainController.mm \
- Slimber/Cocoa/Slimber.mm \
Slimber/Cocoa/main.mm \
- Slimber/Cocoa/Menulet.m
+ Slimber/Cocoa/CocoaController.mm \
+ Slimber/Cocoa/CocoaMenulet.mm \
+ Slimber/Cocoa/CocoaAction.mm
SLIMBER_COCOA_XIBS = \
Slimber/Cocoa/MainMenu.xib
SLIMBER_COCOA_RESOURCES = \
+ Slimber/Resources/Slimber.icns \
Slimber/Resources/Credits.html \
Slimber/Resources/Online.png \
Slimber/Resources/Offline.png \
@@ -26,8 +27,8 @@ CLEANFILES += \
$(SLIMBER_COCOA_NIBS) \
$(SLIMBER_COCOA_TARGET) \
$(SLIMBER_COCOA_BINARY)
-//DEPS += \
-// $(SLIMBER_COCOA_SOURCES:.m=.dep) \
+DEPS += \
+ $(patsubst %.m, %.dep, $(patsubst %.mm, %.dep, $(SLIMBER_COCOA_SOURCES)))
.PHONY: slimber-cocoa
slimber-cocoa: $(SLIMBER_COCOA_TARGET)
@@ -42,5 +43,5 @@ $(SLIMBER_COCOA_TARGET): $(SLIMBER_COCOA_BINARY) $(SLIMBER_COCOA_NIBS) Slimber/C
cp $(SLIMBER_COCOA_NIBS) $(SLIMBER_COCOA_TARGET)/Contents/Resources
cp $(SLIMBER_COCOA_RESOURCES) $(SLIMBER_COCOA_TARGET)/Contents/Resources
-$(SLIMBER_COCOA_BINARY): $(SLIMBER_COCOA_OBJECTS) $(SWIFTEN_TARGET) $(SLIMBER_TRGET)
+$(SLIMBER_COCOA_BINARY): $(SLIMBER_COCOA_OBJECTS) $(SWIFTEN_TARGET) $(SLIMBER_TARGET)
$(QUIET_LINK)$(CXX) -o $@ $(SLIMBER_COCOA_OBJECTS) $(LDFLAGS) $(SLIMBER_TARGET) $(SWIFTEN_TARGET) $(LIBS) -framework Cocoa
diff --git a/Slimber/Cocoa/Menulet.h b/Slimber/Cocoa/Menulet.h
deleted file mode 100644
index fabaa80..0000000
--- a/Slimber/Cocoa/Menulet.h
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <Cocoa/Cocoa.h>
-
-@interface Menulet : NSObject {
- NSStatusItem* statusItem;
- NSMenu* statusMenu;
- NSImage* menuIcon;
- NSArray* userNames;
- BOOL selfOnline;
-}
-
-- (id) init;
-- (void) updateMenu;
-- (void) setUserNames: (NSArray*) names;
-- (void) setSelfConnected: (BOOL) online;
-
-@end
diff --git a/Slimber/Cocoa/Menulet.m b/Slimber/Cocoa/Menulet.m
deleted file mode 100644
index 1cc1f1f..0000000
--- a/Slimber/Cocoa/Menulet.m
+++ /dev/null
@@ -1,104 +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];
-
- userNames = [[NSArray alloc] init];
- selfOnline = NO;
-
- [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;
- if (selfOnline) {
- loggedInItem = [[NSMenuItem alloc] initWithTitle: @"You are logged in" action: NULL keyEquivalent: @""];
- path = [bundle pathForResource: @"Online" ofType:@"png"];
- }
- else {
- loggedInItem = [[NSMenuItem alloc] initWithTitle: @"You are not logged in" action: NULL keyEquivalent: @""];
- 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) setSelfConnected: (BOOL) online {
- selfOnline = online;
- [self updateMenu];
-}
-
-- (void) setUserNames: (NSArray*) names {
- [names retain];
- [userNames release];
- userNames = names;
- [self updateMenu];
-}
-
-@end
diff --git a/Slimber/Cocoa/Slimber.h b/Slimber/Cocoa/Slimber.h
deleted file mode 100644
index b62f9e5..0000000
--- a/Slimber/Cocoa/Slimber.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#pragma once
-
-#include <boost/shared_ptr.hpp>
-
-@class Menulet;
-namespace Swift {
- class Server;
- class VCardCollection;
- class LinkLocalServiceBrowser;
- class BonjourQuerier;
-}
-
-class Slimber {
- public:
- Slimber();
- ~Slimber();
-
- private:
- void handleSelfConnected(bool b);
- void handleServicesChanged();
-
- private:
- boost::shared_ptr<Swift::BonjourQuerier> dnsSDQuerier;
- Swift::LinkLocalServiceBrowser* linkLocalServiceBrowser;
- Swift::VCardCollection* vCardCollection;
- Swift::Server* server;
- Menulet* menulet;
-};
diff --git a/Slimber/Cocoa/Slimber.mm b/Slimber/Cocoa/Slimber.mm
deleted file mode 100644
index d4851c8..0000000
--- a/Slimber/Cocoa/Slimber.mm
+++ /dev/null
@@ -1,61 +0,0 @@
-#include "Slimber/Cocoa/Slimber.h"
-
-#include <boost/bind.hpp>
-
-#include "Swiften/Base/foreach.h"
-#include "Swiften/Application/Platform/PlatformApplication.h"
-#include "Swiften/LinkLocal/LinkLocalService.h"
-#include "Swiften/LinkLocal/LinkLocalServiceBrowser.h"
-#include "Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h"
-#include "Slimber/Cocoa/Menulet.h"
-#include "Slimber/Server.h"
-#include "Slimber/FileVCardCollection.h"
-
-using namespace Swift;
-
-Slimber::Slimber() {
- dnsSDQuerier = boost::shared_ptr<BonjourQuerier>(new BonjourQuerier());
- dnsSDQuerier->start();
-
- linkLocalServiceBrowser = new LinkLocalServiceBrowser(dnsSDQuerier);
- linkLocalServiceBrowser->onServiceAdded.connect(
- boost::bind(&Slimber::handleServicesChanged, this));
- linkLocalServiceBrowser->onServiceRemoved.connect(
- boost::bind(&Slimber::handleServicesChanged, this));
- linkLocalServiceBrowser->onServiceChanged.connect(
- boost::bind(&Slimber::handleServicesChanged, this));
- linkLocalServiceBrowser->start();
-
- vCardCollection = new FileVCardCollection(
- PlatformApplication("Slimber").getSettingsDir());
-
- server = new Server(5222, 5562, linkLocalServiceBrowser, vCardCollection);
- server->onSelfConnected.connect(
- boost::bind(&Slimber::handleSelfConnected, this, _1));
-
- menulet = [[Menulet alloc] init];
- handleServicesChanged();
-}
-
-Slimber::~Slimber() {
- [menulet release];
- delete server;
- delete vCardCollection;
- linkLocalServiceBrowser->stop();
- delete linkLocalServiceBrowser;
- dnsSDQuerier->stop();
-}
-
-void Slimber::handleSelfConnected(bool b) {
- [menulet setSelfConnected: b];
-}
-
-void Slimber::handleServicesChanged() {
- NSMutableArray* names = [[NSMutableArray alloc] init];
- foreach(const LinkLocalService& service, linkLocalServiceBrowser->getServices()) {
- [names addObject: [NSString stringWithUTF8String: service.getDescription().getUTF8Data()]];
- }
-
- [menulet setUserNames: names];
- [names release];
-}