summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-08-02 12:48:16 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-08-02 12:50:02 (GMT)
commit04d48741240c61d75933d24084915a98d257d444 (patch)
treef8c23a2ff7e0d60174d520c6dbeb40007632dac7
parent2a3da91e474f645fe8d83cb2809dcc4b9bfe6a32 (diff)
downloadswift-contrib-04d48741240c61d75933d24084915a98d257d444.zip
swift-contrib-04d48741240c61d75933d24084915a98d257d444.tar.bz2
Slimber: Add restart menu.
-rw-r--r--Slimber/Cocoa/CocoaMenulet.h3
-rw-r--r--Slimber/Cocoa/CocoaMenulet.mm10
-rw-r--r--Slimber/Cocoa/CocoaMenuletDelegate.h14
-rw-r--r--Slimber/Cocoa/CocoaMenuletDelegate.mm17
-rw-r--r--Slimber/Cocoa/Makefile.inc5
-rw-r--r--Slimber/MainController.cpp7
-rw-r--r--Slimber/MainController.h1
-rw-r--r--Slimber/Menulet.h5
-rw-r--r--Slimber/MenuletController.cpp2
-rw-r--r--Slimber/MenuletController.h3
-rw-r--r--Slimber/UnitTest/MenuletControllerTest.cpp10
11 files changed, 73 insertions, 4 deletions
diff --git a/Slimber/Cocoa/CocoaMenulet.h b/Slimber/Cocoa/CocoaMenulet.h
index 86f0eaa..73f5c2b 100644
--- a/Slimber/Cocoa/CocoaMenulet.h
+++ b/Slimber/Cocoa/CocoaMenulet.h
@@ -3,6 +3,7 @@
#include <Cocoa/Cocoa.h>
#include "Slimber/Menulet.h"
+#include "Slimber/Cocoa/CocoaMenuletDelegate.h"
class CocoaMenulet : public Menulet {
public:
@@ -15,9 +16,11 @@ class CocoaMenulet : public Menulet {
virtual void addSeparator();
void setIcon(const Swift::String& icon);
virtual void addAboutItem();
+ virtual void addRestartItem();
virtual void addExitItem();
private:
NSStatusItem* statusItem;
NSMenu* menu;
+ CocoaMenuletDelegate* delegate;
};
diff --git a/Slimber/Cocoa/CocoaMenulet.mm b/Slimber/Cocoa/CocoaMenulet.mm
index c159aa8..f9981e0 100644
--- a/Slimber/Cocoa/CocoaMenulet.mm
+++ b/Slimber/Cocoa/CocoaMenulet.mm
@@ -3,6 +3,7 @@
using namespace Swift;
CocoaMenulet::CocoaMenulet() {
+ delegate = [[CocoaMenuletDelegate alloc] initWithMenulet: this];
menu = [[NSMenu alloc] init];
statusItem = [[[NSStatusBar systemStatusBar]
@@ -14,8 +15,10 @@ CocoaMenulet::CocoaMenulet() {
}
CocoaMenulet::~CocoaMenulet() {
+ [delegate release];
[statusItem release];
[menu release];
+ [delegate release];
}
void CocoaMenulet::setIcon(const String& icon) {
@@ -54,6 +57,13 @@ void CocoaMenulet::addAboutItem() {
[item release];
}
+void CocoaMenulet::addRestartItem() {
+ NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"Restart" action: @selector(handleRestartClicked:) keyEquivalent: @""];
+ [item setTarget: delegate];
+ [menu addItem: item];
+ [item release];
+}
+
void CocoaMenulet::addExitItem() {
NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"Exit" action: @selector(terminate:) keyEquivalent: @""];
[item setTarget: [NSApplication sharedApplication]];
diff --git a/Slimber/Cocoa/CocoaMenuletDelegate.h b/Slimber/Cocoa/CocoaMenuletDelegate.h
new file mode 100644
index 0000000..5c28130
--- /dev/null
+++ b/Slimber/Cocoa/CocoaMenuletDelegate.h
@@ -0,0 +1,14 @@
+#pragma once
+
+#include <Cocoa/Cocoa.h>
+
+class CocoaMenulet;
+
+@interface CocoaMenuletDelegate : NSObject {
+ CocoaMenulet* menulet;
+}
+
+- (id) initWithMenulet: (CocoaMenulet*) m;
+- (void) handleRestartClicked: (id) sender;
+
+@end
diff --git a/Slimber/Cocoa/CocoaMenuletDelegate.mm b/Slimber/Cocoa/CocoaMenuletDelegate.mm
new file mode 100644
index 0000000..f4a7d7b
--- /dev/null
+++ b/Slimber/Cocoa/CocoaMenuletDelegate.mm
@@ -0,0 +1,17 @@
+#include "Slimber/Cocoa/CocoaMenuletDelegate.h"
+#include "Slimber/Cocoa/CocoaMenulet.h"
+
+@implementation CocoaMenuletDelegate
+
+- (id) initWithMenulet: (CocoaMenulet*) m {
+ if ([super init]) {
+ menulet = m;
+ }
+ return self;
+}
+
+- (void) handleRestartClicked: (id) sender {
+ menulet->onRestartClicked();
+}
+
+@end
diff --git a/Slimber/Cocoa/Makefile.inc b/Slimber/Cocoa/Makefile.inc
index 6d225a7..5ea1154 100644
--- a/Slimber/Cocoa/Makefile.inc
+++ b/Slimber/Cocoa/Makefile.inc
@@ -4,7 +4,8 @@ SLIMBER_COCOA_BINARY = \
SLIMBER_COCOA_SOURCES = \
Slimber/Cocoa/main.mm \
Slimber/Cocoa/CocoaController.mm \
- Slimber/Cocoa/CocoaMenulet.mm
+ Slimber/Cocoa/CocoaMenulet.mm \
+ Slimber/Cocoa/CocoaMenuletDelegate.mm
SLIMBER_COCOA_XIBS = \
Slimber/Cocoa/MainMenu.xib
SLIMBER_COCOA_RESOURCES = \
@@ -26,7 +27,7 @@ CLEANFILES += \
$(SLIMBER_COCOA_TARGET) \
$(SLIMBER_COCOA_BINARY)
DEPS += \
- $(SLIMBER_COCOA_SOURCES:.mm=.dep)
+ $(patsubst %.m, %.dep, $(patsubst %.mm, %.dep, $(SLIMBER_COCOA_SOURCES)))
.PHONY: slimber-cocoa
slimber-cocoa: $(SLIMBER_COCOA_TARGET)
diff --git a/Slimber/MainController.cpp b/Slimber/MainController.cpp
index 2d196a5..d723f3f 100644
--- a/Slimber/MainController.cpp
+++ b/Slimber/MainController.cpp
@@ -1,6 +1,7 @@
#include "Slimber/MainController.h"
#include <boost/bind.hpp>
+#include <iostream>
#include "Swiften/Base/foreach.h"
#include "Swiften/Application/Platform/PlatformApplication.h"
@@ -37,6 +38,8 @@ MainController::MainController(Menulet* menulet) : menulet(menulet) {
boost::bind(&MainController::handleSelfConnected, this, _1));
menuletController = new MenuletController(menulet);
+ menuletController->onRestartRequested.connect(boost::bind(
+ &MainController::handleRestartRequested, this));
handleSelfConnected(false);
handleServicesChanged();
@@ -78,3 +81,7 @@ void MainController::handleServerStopped(boost::optional<ServerError> error) {
menuletController->setXMPPStatus("XMPP Server Not Running", MenuletController::Offline);
}
}
+
+void MainController::handleRestartRequested() {
+ std::cout << "RESTART!" << std::endl;
+}
diff --git a/Slimber/MainController.h b/Slimber/MainController.h
index 8d355fe..4ff9afd 100644
--- a/Slimber/MainController.h
+++ b/Slimber/MainController.h
@@ -24,6 +24,7 @@ class MainController {
void handleSelfConnected(bool b);
void handleServicesChanged();
void handleServerStopped(boost::optional<Swift::ServerError> error);
+ void handleRestartRequested();
private:
Menulet* menulet;
diff --git a/Slimber/Menulet.h b/Slimber/Menulet.h
index 631fbbd..1b8ed18 100644
--- a/Slimber/Menulet.h
+++ b/Slimber/Menulet.h
@@ -1,5 +1,7 @@
#pragma once
+#include <boost/signal.hpp>
+
#include "Swiften/Base/String.h"
class Menulet {
@@ -9,7 +11,10 @@ class Menulet {
virtual void clear() = 0;
virtual void addItem(const Swift::String& name, const Swift::String& icon = Swift::String()) = 0;
virtual void addAboutItem() = 0;
+ virtual void addRestartItem() = 0;
virtual void addExitItem() = 0;
virtual void addSeparator() = 0;
virtual void setIcon(const Swift::String&) = 0;
+
+ boost::signal<void ()> onRestartClicked;
};
diff --git a/Slimber/MenuletController.cpp b/Slimber/MenuletController.cpp
index ec11785..1532459 100644
--- a/Slimber/MenuletController.cpp
+++ b/Slimber/MenuletController.cpp
@@ -10,6 +10,7 @@ using namespace Swift;
MenuletController::MenuletController(Menulet* menulet) :
menulet(menulet), xmppStatus(Offline) {
+ menulet->onRestartClicked.connect(boost::ref(onRestartRequested));
update();
}
@@ -45,5 +46,6 @@ void MenuletController::update() {
menulet->addSeparator();
menulet->addAboutItem();
menulet->addSeparator();
+ menulet->addRestartItem();
menulet->addExitItem();
}
diff --git a/Slimber/MenuletController.h b/Slimber/MenuletController.h
index 4073900..5e45038 100644
--- a/Slimber/MenuletController.h
+++ b/Slimber/MenuletController.h
@@ -1,6 +1,7 @@
#pragma once
#include <vector>
+#include <boost/signal.hpp>
#include "Swiften/Base/String.h"
@@ -19,6 +20,8 @@ class MenuletController {
void setXMPPStatus(const Swift::String& message, Status status);
void setUserNames(const std::vector<Swift::String>&);
+ boost::signal<void ()> onRestartRequested;
+
private:
void update();
diff --git a/Slimber/UnitTest/MenuletControllerTest.cpp b/Slimber/UnitTest/MenuletControllerTest.cpp
index d50e2c0..c666679 100644
--- a/Slimber/UnitTest/MenuletControllerTest.cpp
+++ b/Slimber/UnitTest/MenuletControllerTest.cpp
@@ -28,7 +28,7 @@ class MenuletControllerTest : public CppUnit::TestFixture {
void testConstructor() {
MenuletController testling(menulet);
- CPPUNIT_ASSERT_EQUAL(7, static_cast<int>(menulet->items.size()));
+ CPPUNIT_ASSERT_EQUAL(8, static_cast<int>(menulet->items.size()));
int i = 0;
CPPUNIT_ASSERT_EQUAL(String("No online users"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(String("-"), menulet->items[i++]);
@@ -36,6 +36,7 @@ class MenuletControllerTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(String("-"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(String("*About*"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(String("-"), menulet->items[i++]);
+ CPPUNIT_ASSERT_EQUAL(String("*Restart*"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(String("*Exit*"), menulet->items[i++]);
}
@@ -44,7 +45,7 @@ class MenuletControllerTest : public CppUnit::TestFixture {
testling.setXMPPStatus("You are connected", MenuletController::Online);
- CPPUNIT_ASSERT_EQUAL(7, static_cast<int>(menulet->items.size()));
+ CPPUNIT_ASSERT_EQUAL(8, static_cast<int>(menulet->items.size()));
int i = 0;
CPPUNIT_ASSERT_EQUAL(String("No online users"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(String("-"), menulet->items[i++]);
@@ -52,6 +53,7 @@ class MenuletControllerTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(String("-"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(String("*About*"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(String("-"), menulet->items[i++]);
+ CPPUNIT_ASSERT_EQUAL(String("*Restart*"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(String("*Exit*"), menulet->items[i++]);
}
@@ -123,6 +125,10 @@ class MenuletControllerTest : public CppUnit::TestFixture {
items.push_back("*About*");
}
+ virtual void addRestartItem() {
+ items.push_back("*Restart*");
+ }
+
virtual void addExitItem() {
items.push_back("*Exit*");
}