From f3e75e58e57e5a49a79da8a88d25f17c784812b6 Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Tue, 6 Apr 2010 21:16:57 +0100
Subject: Don't minimise+restore new chats that want focus on OS X.

Resolves: 217

diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp
index db340ac..61d9bb4 100644
--- a/Swift/Controllers/Chat/ChatsManager.cpp
+++ b/Swift/Controllers/Chat/ChatsManager.cpp
@@ -138,7 +138,6 @@ void ChatsManager::setEnabled(bool enabled) {
 
 void ChatsManager::handleChatRequest(const String &contact) {
 	ChatController* controller = getChatControllerOrFindAnother(JID(contact));
-	controller->showChatWindow();
 	controller->activateChatWindow();
 }
 
diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp
index a1ca9cc..c726b7b 100644
--- a/Swift/Controllers/Chat/MUCController.cpp
+++ b/Swift/Controllers/Chat/MUCController.cpp
@@ -47,7 +47,6 @@ MUCController::MUCController (
 	muc_->onOccupantPresenceChange.connect(boost::bind(&MUCController::handleOccupantPresenceChange, this, _1));
 	muc_->onOccupantLeft.connect(boost::bind(&MUCController::handleOccupantLeft, this, _1, _2, _3));
 	chatWindow_->convertToMUC();
-	chatWindow_->show();
 	if (avatarManager_ != NULL) {
 		avatarChangedConnection_ = (avatarManager_->onAvatarChanged.connect(boost::bind(&MUCController::handleAvatarChanged, this, _1, _2)));
 	} 
diff --git a/Swift/QtUI/QtChatTabs.cpp b/Swift/QtUI/QtChatTabs.cpp
index 67cd8ae..8ce4ac8 100644
--- a/Swift/QtUI/QtChatTabs.cpp
+++ b/Swift/QtUI/QtChatTabs.cpp
@@ -49,6 +49,7 @@ void QtChatTabs::handleWidgetShown() {
 	if (!widget) {
 		return;
 	}
+	checkForFirstShow();
 	if (tabs_->indexOf(widget) >= 0) {
 		return;
 	}
@@ -59,10 +60,11 @@ void QtChatTabs::handleWidgetShown() {
 void QtChatTabs::handleWantsToActivate() {
 	QtTabbable* widget = qobject_cast<QtTabbable*>(sender());
 	Q_ASSERT(widget);
-	Q_ASSERT(tabs_->indexOf(widget) >= 0);
 	//Un-minimize and bring to front.
 	setWindowState(windowState() & ~Qt::WindowMinimized);
 	setWindowState(windowState() | Qt::WindowActive);
+	show();
+	widget->show();
 	tabs_->setCurrentWidget(widget);
 	widget->setFocus();
 	activateWindow();
@@ -124,4 +126,10 @@ void QtChatTabs::moveEvent(QMoveEvent*) {
 	emit geometryChanged();	
 }
 
+void QtChatTabs::checkForFirstShow() {
+	if (!isVisible()) {
+		showMinimized();
+	}
+}
+
 }
diff --git a/Swift/QtUI/QtChatTabs.h b/Swift/QtUI/QtChatTabs.h
index 12ab3b8..1869b41 100644
--- a/Swift/QtUI/QtChatTabs.h
+++ b/Swift/QtUI/QtChatTabs.h
@@ -30,6 +30,7 @@ namespace Swift {
 			void handleWidgetShown();
 			void handleWantsToActivate();
 		private:
+			void checkForFirstShow();
 			QtTabWidget* tabs_;
 	};
 }
diff --git a/Swift/QtUI/QtChatWindowFactory.cpp b/Swift/QtUI/QtChatWindowFactory.cpp
index ff927c9..ba1719e 100644
--- a/Swift/QtUI/QtChatWindowFactory.cpp
+++ b/Swift/QtUI/QtChatWindowFactory.cpp
@@ -26,10 +26,6 @@ QtChatWindowFactory::QtChatWindowFactory(QtTreeWidgetFactory *treeWidgetFactory,
 ChatWindow* QtChatWindowFactory::createChatWindow(const JID &contact) {
 	QtChatWindow *chatWindow = new QtChatWindow(P2QSTRING(contact.toString()), treeWidgetFactory_);
 	tabs_->addTab(chatWindow);
-	if (!tabs_->isVisible()) {
-		tabs_->showMinimized();
-		//tabs_->minimise();
-	}
 	//chatWindow->show();
 	return chatWindow;
 }
-- 
cgit v0.10.2-6-g49f6