From 509c20d24b59e09e7aeb5045abebad8a370bb3ba Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Sat, 29 Aug 2009 22:28:20 +0100
Subject: Experimental fix for stuff in background, chats coming to front when
 opened etc.


diff --git a/Swift/Controllers/ChatControllerBase.cpp b/Swift/Controllers/ChatControllerBase.cpp
index 1780680..92b77b5 100644
--- a/Swift/Controllers/ChatControllerBase.cpp
+++ b/Swift/Controllers/ChatControllerBase.cpp
@@ -80,6 +80,9 @@ void ChatControllerBase::showChatWindow() {
 	chatWindow_->show();
 }
 
+void ChatControllerBase::activateChatWindow() {
+	chatWindow_->activate();
+}
 
 void ChatControllerBase::handleIncomingMessage(boost::shared_ptr<MessageEvent> messageEvent) {
 	unreadMessages_.push_back(messageEvent);
diff --git a/Swift/Controllers/ChatControllerBase.h b/Swift/Controllers/ChatControllerBase.h
index 144572b..3eadcc5 100644
--- a/Swift/Controllers/ChatControllerBase.h
+++ b/Swift/Controllers/ChatControllerBase.h
@@ -26,6 +26,7 @@ namespace Swift {
 		public:
 			virtual ~ChatControllerBase();
 			void showChatWindow();
+			void activateChatWindow();
 			void setAvailableServerFeatures(boost::shared_ptr<DiscoInfo> info);
 			void handleIncomingMessage(boost::shared_ptr<MessageEvent> message);
 
diff --git a/Swift/Controllers/ChatWindow.h b/Swift/Controllers/ChatWindow.h
index 36788cf..816b843 100644
--- a/Swift/Controllers/ChatWindow.h
+++ b/Swift/Controllers/ChatWindow.h
@@ -24,6 +24,7 @@ namespace Swift {
 
 			virtual void setName(const String& name) = 0;
 			virtual void show() = 0;
+			virtual void activate() = 0;
 			virtual void setAvailableSecurityLabels(const std::vector<SecurityLabel>& labels) = 0;
 			virtual void setSecurityLabelsEnabled(bool enabled) = 0;
 			virtual void setUnreadMessageCount(int count) = 0;
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp
index 78f5f65..873023a 100644
--- a/Swift/Controllers/MainController.cpp
+++ b/Swift/Controllers/MainController.cpp
@@ -244,7 +244,9 @@ void MainController::logout() {
 
 
 void MainController::handleChatRequest(const String &contact) {
-	getChatController(JID(contact))->showChatWindow();
+	ChatController* controller = getChatController(JID(contact));
+	controller->showChatWindow();
+	controller->activateChatWindow();
 }
 
 ChatController* MainController::getChatController(const JID &contact) {
diff --git a/Swift/QtUI/QtChatTabs.cpp b/Swift/QtUI/QtChatTabs.cpp
index a896dc9..e79b2ef 100644
--- a/Swift/QtUI/QtChatTabs.cpp
+++ b/Swift/QtUI/QtChatTabs.cpp
@@ -1,6 +1,7 @@
 #include "QtChatTabs.h"
 
 #include <QCloseEvent>
+#include <QtGlobal>
 #include <QTabWidget>
 #include <QLayout>
 
@@ -36,6 +37,7 @@ void QtChatTabs::addTab(QtTabbable* tab) {
 	connect(tab, SIGNAL(titleUpdated()), this, SLOT(handleTabTitleUpdated()));
 	connect(tab, SIGNAL(windowClosing()), this, SLOT(handleTabClosing()));
 	connect(tab, SIGNAL(windowOpening()), this, SLOT(handleWidgetShown()));
+	connect(tab, SIGNAL(wantsToActivate()), this, SLOT(handleWantsToActivate()));
 }
 
 void QtChatTabs::handleWidgetShown() {
@@ -50,6 +52,15 @@ void QtChatTabs::handleWidgetShown() {
 	show();
 }
 
+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 | Qt::WindowActive);
+	tabs_->setCurrentWidget(widget);
+}
+
 void QtChatTabs::handleTabClosing() {
 	QWidget* widget = qobject_cast<QWidget*>(sender());
 	if (!widget) {
diff --git a/Swift/QtUI/QtChatTabs.h b/Swift/QtUI/QtChatTabs.h
index 97967c9..87b8b10 100644
--- a/Swift/QtUI/QtChatTabs.h
+++ b/Swift/QtUI/QtChatTabs.h
@@ -10,6 +10,7 @@ namespace Swift {
 		public:
 			QtChatTabs();
 			void addTab(QtTabbable* tab);
+			void minimise();
 
 		protected slots:
 			void closeEvent(QCloseEvent* event);
@@ -19,6 +20,7 @@ namespace Swift {
 			void handleTabTitleUpdated();
 			void handleTabCloseRequested(int index);
 			void handleWidgetShown();
+			void handleWantsToActivate();
 		private:
 			QTabWidget* tabs_;
 	};
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp
index b7987b9..7e71b7f 100644
--- a/Swift/QtUI/QtChatWindow.cpp
+++ b/Swift/QtUI/QtChatWindow.cpp
@@ -195,4 +195,8 @@ void QtChatWindow::show() {
 	emit windowOpening();
 }
 
+void QtChatWindow::activate() {
+	emit wantsToActivate();
+}
+
 }
diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h
index ea4983f..80961f8 100644
--- a/Swift/QtUI/QtChatWindow.h
+++ b/Swift/QtUI/QtChatWindow.h
@@ -23,6 +23,7 @@ namespace Swift {
 			void addSystemMessage(const String& message);
 			void addErrorMessage(const String& errorMessage);
 			void show();
+			void activate();
 			void setUnreadMessageCount(int count);
 			void convertToMUC();
 			TreeWidget *getTreeWidget();
diff --git a/Swift/QtUI/QtChatWindowFactory.cpp b/Swift/QtUI/QtChatWindowFactory.cpp
index 47c943f..b3efeac 100644
--- a/Swift/QtUI/QtChatWindowFactory.cpp
+++ b/Swift/QtUI/QtChatWindowFactory.cpp
@@ -17,7 +17,10 @@ QtChatWindowFactory::QtChatWindowFactory(QtTreeWidgetFactory *treeWidgetFactory,
 ChatWindow* QtChatWindowFactory::createChatWindow(const JID &contact) {
 	QtChatWindow *chatWindow = new QtChatWindow(P2QSTRING(contact.toString()), treeWidgetFactory_);
 	tabs_->addTab(chatWindow);
-	tabs_->show();
+	if (!tabs_->isVisible()) {
+		tabs_->showMinimized();
+		//tabs_->minimise();
+	}
 	//chatWindow->show();
 	return chatWindow;
 }
diff --git a/Swift/QtUI/QtTabbable.h b/Swift/QtUI/QtTabbable.h
index ebd495e..e3dd47b 100644
--- a/Swift/QtUI/QtTabbable.h
+++ b/Swift/QtUI/QtTabbable.h
@@ -15,5 +15,6 @@ namespace Swift {
 			void titleUpdated();
 			void windowClosing();
 			void windowOpening();
+			void wantsToActivate();
 	};
 }
-- 
cgit v0.10.2-6-g49f6