From 9470b2eb602489b290f8df1aaf515712d9ea3dbf Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Mon, 12 Apr 2010 14:16:23 +0000
Subject: Populate ErrorEvent for server disconnections.

Resolves: #303

diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp
index 1c83d1d..e20e9f8 100644
--- a/Swift/Controllers/MainController.cpp
+++ b/Swift/Controllers/MainController.cpp
@@ -161,6 +161,10 @@ void MainController::resetClient() {
 
 void MainController::handleConnected() {
 	loginWindow_->setIsLoggingIn(false);
+	if (lastDisconnectError_) {
+		lastDisconnectError_->conclude();
+		lastDisconnectError_ = boost::shared_ptr<ErrorEvent>();
+	}
 	//FIXME: this freshLogin thing is temporary so I can see what's what before I split into a seperate method.
 	bool freshLogin = rosterController_ == NULL;
 	if (freshLogin) {
@@ -348,6 +352,10 @@ void MainController::handleError(const ClientError& error) {
 	if (!rosterController_) { //hasn't been logged in yet
 		signOut();
 		loginWindow_->setMessage(message);
+	} else {
+		message = "Disconnected from " + jid_.getDomain() + ": ";
+		lastDisconnectError_ = boost::shared_ptr<ErrorEvent>(new ErrorEvent(JID(jid_.getDomain()), message));
+		eventController_->handleIncomingEvent(lastDisconnectError_);
 	}
 	logout();
 	if (rosterController_) {
diff --git a/Swift/Controllers/MainController.h b/Swift/Controllers/MainController.h
index 0056c21..5ed3641 100644
--- a/Swift/Controllers/MainController.h
+++ b/Swift/Controllers/MainController.h
@@ -23,6 +23,7 @@
 #include "Swiften/Elements/Presence.h"
 #include "Swiften/Settings/SettingsProvider.h"
 #include "Swiften/Elements/CapsInfo.h"
+#include "Swiften/Events/ErrorEvent.h"
 #include "Swiften/Roster/XMPPRoster.h"
 
 namespace Swift {
@@ -125,5 +126,6 @@ namespace Swift {
 			String password_;
 			String certificateFile_;
 			ChatListWindowFactory* chatListWindowFactory_;
+			boost::shared_ptr<ErrorEvent> lastDisconnectError_;
 	};
 }
diff --git a/Swift/QtUI/EventViewer/QtEventWindow.cpp b/Swift/QtUI/EventViewer/QtEventWindow.cpp
index 65b946a..b32c4cf 100644
--- a/Swift/QtUI/EventViewer/QtEventWindow.cpp
+++ b/Swift/QtUI/EventViewer/QtEventWindow.cpp
@@ -53,7 +53,7 @@ void QtEventWindow::handleItemActivated(const QModelIndex& item) {
 		QtSubscriptionRequestWindow* window = QtSubscriptionRequestWindow::getWindow(subscriptionEvent, this);
 		window->show();
 	} else if (errorEvent) {
-		errorEvent->onConclusion();
+		errorEvent->conclude();
 	} else {
 		qWarning() << "Trying to activate an unexpected event";
 	}
-- 
cgit v0.10.2-6-g49f6