From c7bf51369ba1a590a1c2104ba4ff231faee158cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Remko=20Tron=C3=A7on?= <git@el-tramo.be>
Date: Sun, 2 Aug 2009 18:42:48 +0200
Subject: Slimber: Better error messages.


diff --git a/Slimber/MainController.cpp b/Slimber/MainController.cpp
index 4e238d2..9cd8c4d 100644
--- a/Slimber/MainController.cpp
+++ b/Slimber/MainController.cpp
@@ -1,6 +1,7 @@
 #include "Slimber/MainController.h"
 
 #include <boost/bind.hpp>
+#include <boost/lexical_cast.hpp>
 #include <iostream>
 
 #include "Swiften/Base/foreach.h"
@@ -86,7 +87,22 @@ void MainController::handleServicesChanged() {
 
 void MainController::handleServerStopped(boost::optional<ServerError> error) {
 	if (error) {
-		menuletController->setXMPPStatus("XMPP Server Error", MenuletController::Offline);
+		String message;
+		switch (error->getType()) {
+			case ServerError::C2SPortConflict: 
+				message = String("Error: Port ") + boost::lexical_cast<std::string>(server->getClientToServerPort()) + String(" in use");
+				break;
+			case ServerError::C2SError:
+				message = String("Local connection server error");
+			 break;
+			case ServerError::LinkLocalPortConflict: 
+				message = String("Error: Port ") + boost::lexical_cast<std::string>(server->getLinkLocalPort()) + String(" in use");
+				break;
+			case ServerError::LinkLocalError: 
+				message = String("External connection server error");
+				break;
+		}
+		menuletController->setXMPPStatus(message, MenuletController::Offline);
 	}
 	else {
 		menuletController->setXMPPStatus("XMPP Server Not Running", MenuletController::Offline);
@@ -94,7 +110,6 @@ void MainController::handleServerStopped(boost::optional<ServerError> error) {
 }
 
 void MainController::handleRestartRequested() {
-	std::cout << "RESTART!" << std::endl;
 	stop();
 	start();
 }
diff --git a/Slimber/Server.h b/Slimber/Server.h
index 372a3d3..3587c50 100644
--- a/Slimber/Server.h
+++ b/Slimber/Server.h
@@ -39,6 +39,14 @@ namespace Swift {
 			void start();
 			void stop();
 
+			int getLinkLocalPort() const {
+				return linkLocalConnectionPort;
+			}
+
+			int getClientToServerPort() const {
+				return clientConnectionPort;
+			}
+
 			boost::signal<void (bool)> onSelfConnected;
 			boost::signal<void (boost::optional<ServerError>)> onStopped;
 
-- 
cgit v0.10.2-6-g49f6