From 188ff36e3fbfdc174ea75babc1deb3aebcf1472b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Remko=20Tron=C3=A7on?= <git@el-tramo.be>
Date: Sun, 2 Aug 2009 01:17:07 +0200
Subject: Report XMPP server errors in Slimber.


diff --git a/Slimber/Cocoa/Menulet.h b/Slimber/Cocoa/Menulet.h
index fabaa80..823213f 100644
--- a/Slimber/Cocoa/Menulet.h
+++ b/Slimber/Cocoa/Menulet.h
@@ -5,12 +5,13 @@
 	NSMenu* statusMenu;
 	NSImage* menuIcon;
 	NSArray* userNames;
-	BOOL selfOnline;
+	BOOL xmppOnline;
+	NSString* xmppStatus;
 }
 
 - (id) init;
 - (void) updateMenu;
 - (void) setUserNames: (NSArray*) names;
-- (void) setSelfConnected: (BOOL) online;
+- (void) setXMPPStatus: (NSString*) status online: (BOOL) online;
 
 @end
diff --git a/Slimber/Cocoa/Menulet.m b/Slimber/Cocoa/Menulet.m
index 1cc1f1f..2a62992 100644
--- a/Slimber/Cocoa/Menulet.m
+++ b/Slimber/Cocoa/Menulet.m
@@ -12,8 +12,9 @@
 		[statusItem setToolTip: @"Slimber"];	
 		[statusItem setMenu: statusMenu];
 
+		xmppStatus = @"";
+		xmppOnline = NO;
 		userNames = [[NSArray alloc] init];
-		selfOnline = NO;
 
 		[self updateMenu];
 	}
@@ -65,12 +66,11 @@
 	NSMenuItem* loggedInItem;
 	NSBundle* bundle = [NSBundle bundleForClass: [self class]];
 	NSString* path;
-	if (selfOnline) {
-		loggedInItem = [[NSMenuItem alloc] initWithTitle: @"You are logged in" action: NULL keyEquivalent: @""];
+	loggedInItem = [[NSMenuItem alloc] initWithTitle: xmppStatus action: NULL keyEquivalent: @""];
+	if (xmppOnline) {
 		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]];
@@ -89,8 +89,9 @@
 	[statusMenu addItem: exitMenuItem];
 }
 
-- (void) setSelfConnected: (BOOL) online {
-	selfOnline = online;
+- (void) setXMPPStatus: (NSString*) status online: (BOOL) online {
+	xmppStatus = status; // TODO: Should I retain status?
+	xmppOnline = online;
 	[self updateMenu];
 }
 
diff --git a/Slimber/Cocoa/Slimber.h b/Slimber/Cocoa/Slimber.h
index b62f9e5..fdce501 100644
--- a/Slimber/Cocoa/Slimber.h
+++ b/Slimber/Cocoa/Slimber.h
@@ -1,6 +1,9 @@
 #pragma once
 
 #include <boost/shared_ptr.hpp>
+#include <boost/optional.hpp>
+
+#include "Slimber/ServerError.h"
 
 @class Menulet;
 namespace Swift {
@@ -18,6 +21,7 @@ class Slimber {
 	private:
 		void handleSelfConnected(bool b);
 		void handleServicesChanged();
+		void handleServerStopped(boost::optional<Swift::ServerError> error);
 
 	private:
 		boost::shared_ptr<Swift::BonjourQuerier> dnsSDQuerier;
diff --git a/Slimber/Cocoa/Slimber.mm b/Slimber/Cocoa/Slimber.mm
index d4851c8..9e15614 100644
--- a/Slimber/Cocoa/Slimber.mm
+++ b/Slimber/Cocoa/Slimber.mm
@@ -30,11 +30,16 @@ Slimber::Slimber() {
 			PlatformApplication("Slimber").getSettingsDir());
 
 	server = new Server(5222, 5562, linkLocalServiceBrowser, vCardCollection);
+	server->onStopped.connect(
+			boost::bind(&Slimber::handleServerStopped, this, _1));
 	server->onSelfConnected.connect(
 			boost::bind(&Slimber::handleSelfConnected, this, _1));
 
 	menulet = [[Menulet alloc] init];
+	handleSelfConnected(false);
 	handleServicesChanged();
+
+	server->start();
 }
 
 Slimber::~Slimber() {
@@ -47,7 +52,12 @@ Slimber::~Slimber() {
 }
 
 void Slimber::handleSelfConnected(bool b) {
-	[menulet setSelfConnected: b];
+	if (b) {
+		[menulet setXMPPStatus: @"You are logged in" online: true];
+	}
+	else {
+		[menulet setXMPPStatus: @"You are not logged in" online: false];
+	}
 }
 
 void Slimber::handleServicesChanged() {
@@ -59,3 +69,12 @@ void Slimber::handleServicesChanged() {
 	[menulet setUserNames: names];
 	[names release];
 }
+
+void Slimber::handleServerStopped(boost::optional<ServerError> error) {
+	if (error) {
+		[menulet setXMPPStatus: @"XMPP Server Error." online: false];
+	}
+	else {
+		[menulet setXMPPStatus: @"XMPP Server Not Runnning." online: false];
+	}
+}
-- 
cgit v0.10.2-6-g49f6