From bb31d6f3a20e8989e182fa78b1bf2edaa2156dea Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Remko=20Tron=C3=A7on?= <git@el-tramo.be>
Date: Mon, 4 Oct 2010 21:48:09 +0200
Subject: Disable the notifier when going to DND.

Resolves: #572

diff --git a/SwifTools/Notifier/GrowlNotifier.cpp b/SwifTools/Notifier/GrowlNotifier.cpp
index 3eb580a..066c4d0 100644
--- a/SwifTools/Notifier/GrowlNotifier.cpp
+++ b/SwifTools/Notifier/GrowlNotifier.cpp
@@ -70,7 +70,7 @@ GrowlNotifier::GrowlNotifier(const String& name) {
 	Growl_SetDelegate(&delegate_);
 }
 
-void GrowlNotifier::showMessage(Type type, const String& subject, const String& description, const boost::filesystem::path& picturePath, boost::function<void()> callback) {
+void GrowlNotifier::doShowMessage(Type type, const String& subject, const String& description, const boost::filesystem::path& picturePath, boost::function<void()> callback) {
 	ByteArray picture;
 	picture.readFromFile(picturePath.string());
 
diff --git a/SwifTools/Notifier/GrowlNotifier.h b/SwifTools/Notifier/GrowlNotifier.h
index 5d618e6..379181d 100644
--- a/SwifTools/Notifier/GrowlNotifier.h
+++ b/SwifTools/Notifier/GrowlNotifier.h
@@ -24,7 +24,7 @@ namespace Swift {
 		public:
 			GrowlNotifier(const String& name);
 
-			virtual void showMessage(Type type, const String& subject, const String& description, const boost::filesystem::path& picture, boost::function<void()> callback);
+			virtual void doShowMessage(Type type, const String& subject, const String& description, const boost::filesystem::path& picture, boost::function<void()> callback);
 		
 		private:
 			Growl_Delegate delegate_;
diff --git a/SwifTools/Notifier/LoggingNotifier.h b/SwifTools/Notifier/LoggingNotifier.h
index eea07ef..138d1c5 100644
--- a/SwifTools/Notifier/LoggingNotifier.h
+++ b/SwifTools/Notifier/LoggingNotifier.h
@@ -12,7 +12,7 @@
 namespace Swift {
 	class LoggingNotifier : public Notifier {
 		public:
-			virtual void showMessage(Type type, const String& subject, const String& description, const boost::filesystem::path& picture, boost::function<void()> callback) {
+			virtual void doShowMessage(Type type, const String& subject, const String& description, const boost::filesystem::path& picture, boost::function<void()> callback) {
 				notifications.push_back(Notification(type, subject, description, picture, callback));
 			}
 
diff --git a/SwifTools/Notifier/Notifier.cpp b/SwifTools/Notifier/Notifier.cpp
index 7a7ed13..ec6a12f 100644
--- a/SwifTools/Notifier/Notifier.cpp
+++ b/SwifTools/Notifier/Notifier.cpp
@@ -8,9 +8,18 @@
 
 namespace Swift {
 
+Notifier::Notifier() : enabled(true) {
+}
+
 Notifier::~Notifier() {
 }
 
+void Notifier::showMessage(Type type, const String& subject, const String& description, const boost::filesystem::path& picture, boost::function<void()> callback) {
+	if (enabled) {
+		doShowMessage(type, subject, description, picture, callback);
+	}
+}
+
 String Notifier::typeToString(Type type) {
 	switch (type) {
 		case ContactAvailable: return "Contact Becomes Available";
diff --git a/SwifTools/Notifier/Notifier.h b/SwifTools/Notifier/Notifier.h
index f1a89ef..dab6e90 100644
--- a/SwifTools/Notifier/Notifier.h
+++ b/SwifTools/Notifier/Notifier.h
@@ -14,6 +14,7 @@
 namespace Swift {
 	class Notifier {
 		public:
+			Notifier();
 			virtual ~Notifier();
 
 			enum Type { ContactAvailable, ContactUnavailable, ContactStatusChange, IncomingMessage, SystemMessage };
@@ -26,11 +27,26 @@ namespace Swift {
 				const String& subject, 
 				const String& description, 
 				const boost::filesystem::path& picture,
+				boost::function<void()> callback);
+
+			void setEnabled(bool b) {
+				enabled = b;
+			}
+
+		private:
+			virtual void doShowMessage(
+				Type type,
+				const String& subject, 
+				const String& description, 
+				const boost::filesystem::path& picture,
 				boost::function<void()> callback) = 0;
 
 		protected:
 			String typeToString(Type type);
 			static std::vector<Type> getAllTypes();
 			static std::vector<Type> getDefaultTypes();
+
+		private:
+			bool enabled;
 	};
 }
diff --git a/SwifTools/Notifier/NullNotifier.h b/SwifTools/Notifier/NullNotifier.h
index e97329b..0b0b3df 100644
--- a/SwifTools/Notifier/NullNotifier.h
+++ b/SwifTools/Notifier/NullNotifier.h
@@ -11,7 +11,7 @@
 namespace Swift {
 	class NullNotifier : public Notifier {
 		public:
-			virtual void showMessage(Type, const String&, const String&, const boost::filesystem::path&, boost::function<void()>) {
+			virtual void doShowMessage(Type, const String&, const String&, const boost::filesystem::path&, boost::function<void()>) {
 			}
 	};
 }
diff --git a/SwifTools/Notifier/SnarlNotifier.cpp b/SwifTools/Notifier/SnarlNotifier.cpp
index 1cd3f9d..9162ff7 100644
--- a/SwifTools/Notifier/SnarlNotifier.cpp
+++ b/SwifTools/Notifier/SnarlNotifier.cpp
@@ -33,7 +33,7 @@ SnarlNotifier::~SnarlNotifier() {
 	}
 }
 
-void SnarlNotifier::showMessage(Type type, const String& subject, const String& description, const boost::filesystem::path& picture, boost::function<void()> callback) {
+void SnarlNotifier::doShowMessage(Type type, const String& subject, const String& description, const boost::filesystem::path& picture, boost::function<void()> callback) {
 	int timeout = (type == Type::IncomingMessage || type == Type::SystemMessage) ? MESSAGE_NOTIFICATION_TIMEOUT : STATUS_NOTIFICATION_TIMEOUT;
 	int notificationID = snarl.ShowMessageEx(typeToString(type).getUTF8Data(), subject.getUTF8Data(), description.getUTF8Data(), timeout, picture.string().c_str(), window->getID(), SWIFT_SNARLNOTIFIER_MESSAGE_ID);
 	if (notificationID > 0) {
diff --git a/SwifTools/Notifier/SnarlNotifier.h b/SwifTools/Notifier/SnarlNotifier.h
index 2f64166..0fad5c7 100644
--- a/SwifTools/Notifier/SnarlNotifier.h
+++ b/SwifTools/Notifier/SnarlNotifier.h
@@ -19,7 +19,7 @@ namespace Swift {
 			SnarlNotifier(const String& name, Win32NotifierWindow* window, const boost::filesystem::path& icon);
 			~SnarlNotifier();
 
-			virtual void showMessage(Type type, const String& subject, const String& description, const boost::filesystem::path& picture, boost::function<void()> callback);
+			virtual void doShowMessage(Type type, const String& subject, const String& description, const boost::filesystem::path& picture, boost::function<void()> callback);
 		
 		private:
 			void handleMessageReceived(MSG* message);
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp
index d4093f0..3cf2907 100644
--- a/Swift/Controllers/MainController.cpp
+++ b/Swift/Controllers/MainController.cpp
@@ -335,6 +335,7 @@ void MainController::sendPresence(boost::shared_ptr<Presence> presence) {
 	rosterController_->getWindow()->setMyStatusType(presence->getShow());
 	rosterController_->getWindow()->setMyStatusText(presence->getStatus());
 	systemTrayController_->setMyStatusType(presence->getShow());
+	notifier_->setEnabled(presence->getShow() != StatusShow::DND);
 
 	// Add information and send
 	if (!vCardPhotoHash_.isEmpty()) {
-- 
cgit v0.10.2-6-g49f6