From 0a88cbb890213472c4e780593f4bd3866f7588e4 Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Sun, 3 Oct 2010 15:46:20 +0100
Subject: Only jump the Mac dock when a Notice is generated.

Release-Notes: The Mac Dock icon has stopped jumping when it shouldn't.

Resolves: #444
Resolves: #453

diff --git a/Swift/Controllers/Chat/ChatController.cpp b/Swift/Controllers/Chat/ChatController.cpp
index 07243a2..18076d8 100644
--- a/Swift/Controllers/Chat/ChatController.cpp
+++ b/Swift/Controllers/Chat/ChatController.cpp
@@ -88,6 +88,7 @@ bool ChatController::isIncomingMessageFromMe(boost::shared_ptr<Message>) {
 
 void ChatController::preHandleIncomingMessage(boost::shared_ptr<MessageEvent> messageEvent) {
 	eventController_->handleIncomingEvent(messageEvent);
+	chatWindow_->flash();
 	boost::shared_ptr<Message> message = messageEvent->getStanza();
 	JID from = message->getFrom();
 	if (!from.equals(toJID_, JID::WithResource)) {
diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp
index 5b98fcd..3b799d9 100644
--- a/Swift/Controllers/Chat/MUCController.cpp
+++ b/Swift/Controllers/Chat/MUCController.cpp
@@ -229,6 +229,7 @@ void MUCController::preHandleIncomingMessage(boost::shared_ptr<MessageEvent> mes
 	boost::shared_ptr<Message> message = messageEvent->getStanza();
 	if (joined_ && messageTargetsMe(message) && !message->getPayload<Delay>()) {
 		eventController_->handleIncomingEvent(messageEvent);
+		chatWindow_->flash();
 	}
 	if (joined_) {
 		String nick = message->getFrom().getResource();
diff --git a/Swift/Controllers/UIInterfaces/ChatWindow.h b/Swift/Controllers/UIInterfaces/ChatWindow.h
index 1ee632c..a07f90b 100644
--- a/Swift/Controllers/UIInterfaces/ChatWindow.h
+++ b/Swift/Controllers/UIInterfaces/ChatWindow.h
@@ -57,6 +57,7 @@ namespace Swift {
 			virtual void setTabComplete(TabComplete* completer) = 0;
 			virtual void replaceLastMessage(const String& message) = 0;
 			virtual void setAckState(const String& id, AckState state) = 0;
+			virtual void flash() = 0;
 
 			boost::signal<void ()> onClosed;
 			boost::signal<void ()> onAllMessagesRead;
diff --git a/Swift/Controllers/UnitTest/MockChatWindow.h b/Swift/Controllers/UnitTest/MockChatWindow.h
index 4e7a117..03adcfe 100644
--- a/Swift/Controllers/UnitTest/MockChatWindow.h
+++ b/Swift/Controllers/UnitTest/MockChatWindow.h
@@ -35,6 +35,7 @@ namespace Swift {
 			virtual void setTabComplete(TabComplete*) {};
 			virtual void replaceLastMessage(const Swift::String&) {};
 			void setAckState(const String& /*id*/, AckState /*state*/) {};
+			virtual void flash() {};
 
 			boost::signal<void ()> onClosed;
 			boost::signal<void ()> onAllMessagesRead;
diff --git a/Swift/QtUI/QtChatTabs.cpp b/Swift/QtUI/QtChatTabs.cpp
index 937e5e0..86a6ab3 100644
--- a/Swift/QtUI/QtChatTabs.cpp
+++ b/Swift/QtUI/QtChatTabs.cpp
@@ -69,6 +69,7 @@ void QtChatTabs::addTab(QtTabbable* tab) {
 	connect(tab, SIGNAL(requestNextTab()), this, SLOT(handleRequestedNextTab()), Qt::UniqueConnection);
 	connect(tab, SIGNAL(requestActiveTab()), this, SLOT(handleRequestedActiveTab()), Qt::UniqueConnection);
 	connect(tab, SIGNAL(requestPreviousTab()), this, SLOT(handleRequestedPreviousTab()), Qt::UniqueConnection);
+	connect(tab, SIGNAL(requestFlash()), this, SLOT(flash()), Qt::UniqueConnection);
 	setSizePolicy(policy);
 }
 
@@ -168,9 +169,8 @@ void QtChatTabs::handleTabTitleUpdated(QWidget* widget) {
 	}
 	tabs_->setTabText(index, tabbable->getCount() > 0 ? QString("(%1) %2").arg(tabbable->getCount()).arg(tabbable->windowTitle()) : tabbable->windowTitle());
 	QColor tabTextColor;
-	bool flash = false;
 	switch (tabbable->getWidgetAlertState()) {
-	case QtTabbable::WaitingActivity : flash = true; tabTextColor = QColor(217, 20, 43); break;
+	case QtTabbable::WaitingActivity : tabTextColor = QColor(217, 20, 43); break;
 	case QtTabbable::ImpendingActivity : tabTextColor = QColor(27, 171, 32); break;
 	default : tabTextColor = QColor();
 	}
@@ -185,12 +185,12 @@ void QtChatTabs::handleTabTitleUpdated(QWidget* widget) {
 	
 	QtTabbable* current = qobject_cast<QtTabbable*>(tabs_->currentWidget());
 	setWindowTitle(unread > 0 ? QString("(%1) %2").arg(unread).arg(current->windowTitle()) : current->windowTitle());
+}
 
-	if (flash) {
+void QtChatTabs::flash() {
 #ifndef SWIFTEN_PLATFORM_MACOSX
-		QApplication::alert(this, 3000);
+	QApplication::alert(this, 3000);
 #endif
-	}
 }
 
 void QtChatTabs::resizeEvent(QResizeEvent*) {
diff --git a/Swift/QtUI/QtChatTabs.h b/Swift/QtUI/QtChatTabs.h
index 807b3c1..233c574 100644
--- a/Swift/QtUI/QtChatTabs.h
+++ b/Swift/QtUI/QtChatTabs.h
@@ -39,6 +39,7 @@ namespace Swift {
 			void handleRequestedPreviousTab();
 			void handleRequestedNextTab();
 			void handleRequestedActiveTab();
+			void flash();
 
 		private:
 			void checkForFirstShow();
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp
index a644b86..6913747 100644
--- a/Swift/QtUI/QtChatWindow.cpp
+++ b/Swift/QtUI/QtChatWindow.cpp
@@ -278,6 +278,10 @@ String QtChatWindow::addMessage(const String &message, const String &senderName,
 	return id;
 }
 
+void QtChatWindow::flash() {
+	emit requestFlash();
+}
+
 void QtChatWindow::setAckState(String const& id, ChatWindow::AckState state) {
 	QString xml;
 	switch (state) {
diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h
index 333aa44..2b64f83 100644
--- a/Swift/QtUI/QtChatWindow.h
+++ b/Swift/QtUI/QtChatWindow.h
@@ -53,9 +53,11 @@ namespace Swift {
 			int getCount();
 			void replaceLastMessage(const String& message);
 			void setAckState(const String& id, AckState state);
+			void flash();
 
 		signals:
 			void geometryChanged();
+			void requestFlash();
 
 		protected slots:
 			void qAppFocusChanged(QWidget* old, QWidget* now);
-- 
cgit v0.10.2-6-g49f6