From 416e20360efab8b12bfaa223c287b6d49dc2a3b8 Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Tue, 15 Sep 2009 22:33:52 +0100
Subject: Collapse an enable and disable method into setEnabled(bool).


diff --git a/Swift/Controllers/ChatControllerBase.cpp b/Swift/Controllers/ChatControllerBase.cpp
index 7d11401..baa715b 100644
--- a/Swift/Controllers/ChatControllerBase.cpp
+++ b/Swift/Controllers/ChatControllerBase.cpp
@@ -16,6 +16,7 @@ ChatControllerBase::ChatControllerBase(const JID& self, StanzaChannel* stanzaCha
 	chatWindow_ = chatWindowFactory_->createChatWindow(toJID);
 	chatWindow_->onAllMessagesRead.connect(boost::bind(&ChatControllerBase::handleAllMessagesRead, this));
 	chatWindow_->onSendMessageRequest.connect(boost::bind(&ChatControllerBase::handleSendMessageRequest, this, _1));
+	setEnabled(stanzaChannel->isAvailable() && iqRouter->isAvailable());
 }
 
 ChatControllerBase::~ChatControllerBase() {
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp
index a8fec70..63c854f 100644
--- a/Swift/Controllers/MainController.cpp
+++ b/Swift/Controllers/MainController.cpp
@@ -168,7 +168,7 @@ void MainController::handleConnected() {
 		initialPresence = boost::shared_ptr<Presence>(new Presence());
 	}
 	initialPresence->addPayload(capsInfo_);
-	enableManagers();
+	setManagersEnabled(true);
 	sendPresence(initialPresence);
 }
 
@@ -278,30 +278,20 @@ void MainController::signout() {
 }
 
 void MainController::logout() {
-	disableManagers();
+	setManagersEnabled(false);
 }
 
-void MainController::disableManagers() {
+void MainController::setManagersEnabled(bool enabled) {
 	foreach (JIDChatControllerPair controllerPair, chatControllers_) {
-		controllerPair.second->setEnabled(false);
+		//printf("Setting enabled on %d to %d\n", controllerPair.second, enabled);
+		controllerPair.second->setEnabled(enabled);
 	}
 	foreach (JIDMUCControllerPair controllerPair, mucControllers_) {
-		controllerPair.second->setEnabled(false);
+		controllerPair.second->setEnabled(enabled);
 	}
-	rosterController_->setEnabled(false);
+	rosterController_->setEnabled(enabled);
 }
 
-void MainController::enableManagers() {
-	foreach (JIDChatControllerPair controllerPair, chatControllers_) {
-		controllerPair.second->setEnabled(true);
-	}
-	foreach (JIDMUCControllerPair controllerPair, mucControllers_) {
-		controllerPair.second->setEnabled(true);
-	}
-	rosterController_->setEnabled(true);
-}
-
-
 void MainController::handleChatRequest(const String &contact) {
 	ChatController* controller = getChatController(JID(contact));
 	controller->showChatWindow();
diff --git a/Swift/Controllers/MainController.h b/Swift/Controllers/MainController.h
index 3fbe9b4..a52ebba 100644
--- a/Swift/Controllers/MainController.h
+++ b/Swift/Controllers/MainController.h
@@ -74,8 +74,7 @@ namespace Swift {
 	
 		private:	
 			void performLoginFromCachedCredentials();
-			void enableManagers();
-			void disableManagers();
+			void setManagersEnabled(bool enabled);
 			Client* client_;
 			ChatWindowFactory* chatWindowFactory_;
 			MainWindowFactory* mainWindowFactory_;
-- 
cgit v0.10.2-6-g49f6