summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-10-23 08:22:10 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-10-23 08:22:10 (GMT)
commit96be62f4a700e3bd50f4b6f177f02e5820a09106 (patch)
treefc2f49e7a9874c147ba04795d60a9a941dd2b624 /SwifTools/Notifier
parentfd7d3f4f994159a4990f3a0029597d4c14f727a9 (diff)
downloadswift-96be62f4a700e3bd50f4b6f177f02e5820a09106.zip
swift-96be62f4a700e3bd50f4b6f177f02e5820a09106.tar.bz2
Don't lose notification enabledness when the user changes status.
Resolves: #651 Release-Notes: The notification toggle on Linux will now be respected.
Diffstat (limited to 'SwifTools/Notifier')
-rw-r--r--SwifTools/Notifier/GrowlNotifier.cpp2
-rw-r--r--SwifTools/Notifier/GrowlNotifier.h2
-rw-r--r--SwifTools/Notifier/LoggingNotifier.h2
-rw-r--r--SwifTools/Notifier/Notifier.cpp9
-rw-r--r--SwifTools/Notifier/Notifier.h18
-rw-r--r--SwifTools/Notifier/NullNotifier.h2
-rw-r--r--SwifTools/Notifier/SnarlNotifier.h2
-rw-r--r--SwifTools/Notifier/TogglableNotifier.h54
8 files changed, 59 insertions, 32 deletions
diff --git a/SwifTools/Notifier/GrowlNotifier.cpp b/SwifTools/Notifier/GrowlNotifier.cpp
index 066c4d0..3eb580a 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::doShowMessage(Type type, const String& subject, const String& description, const boost::filesystem::path& picturePath, boost::function<void()> callback) {
+void GrowlNotifier::showMessage(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 379181d..5d618e6 100644
--- a/SwifTools/Notifier/GrowlNotifier.h
+++ b/SwifTools/Notifier/GrowlNotifier.h
@@ -24,7 +24,7 @@ namespace Swift {
public:
GrowlNotifier(const String& name);
- virtual void doShowMessage(Type type, const String& subject, const String& description, const boost::filesystem::path& picture, boost::function<void()> callback);
+ virtual void showMessage(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 138d1c5..eea07ef 100644
--- a/SwifTools/Notifier/LoggingNotifier.h
+++ b/SwifTools/Notifier/LoggingNotifier.h
@@ -12,7 +12,7 @@
namespace Swift {
class LoggingNotifier : public Notifier {
public:
- virtual void doShowMessage(Type type, const String& subject, const String& description, const boost::filesystem::path& picture, boost::function<void()> callback) {
+ virtual void showMessage(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 c03970b..2c2660e 100644
--- a/SwifTools/Notifier/Notifier.cpp
+++ b/SwifTools/Notifier/Notifier.cpp
@@ -11,18 +11,9 @@ namespace Swift {
const int Notifier::DEFAULT_STATUS_NOTIFICATION_TIMEOUT_SECONDS = 3;
const int Notifier::DEFAULT_MESSAGE_NOTIFICATION_TIMEOUT_SECONDS = 5;
-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 e609867..b7c705e 100644
--- a/SwifTools/Notifier/Notifier.h
+++ b/SwifTools/Notifier/Notifier.h
@@ -14,7 +14,6 @@
namespace Swift {
class Notifier {
public:
- Notifier();
virtual ~Notifier();
enum Type { ContactAvailable, ContactUnavailable, ContactStatusChange, IncomingMessage, SystemMessage };
@@ -27,20 +26,6 @@ namespace Swift {
const String& subject,
const String& description,
const boost::filesystem::path& picture,
- boost::function<void()> callback);
-
- void setEnabled(bool b) {
- enabled = b;
- }
-
- bool getEnabled() const {return enabled;}
-
- private:
- virtual void doShowMessage(
- Type type,
- const String& subject,
- const String& description,
- const boost::filesystem::path& picture,
boost::function<void()> callback) = 0;
protected:
@@ -50,8 +35,5 @@ namespace Swift {
static const int DEFAULT_STATUS_NOTIFICATION_TIMEOUT_SECONDS;
static const int DEFAULT_MESSAGE_NOTIFICATION_TIMEOUT_SECONDS;
-
- private:
- bool enabled;
};
}
diff --git a/SwifTools/Notifier/NullNotifier.h b/SwifTools/Notifier/NullNotifier.h
index 0b0b3df..e97329b 100644
--- a/SwifTools/Notifier/NullNotifier.h
+++ b/SwifTools/Notifier/NullNotifier.h
@@ -11,7 +11,7 @@
namespace Swift {
class NullNotifier : public Notifier {
public:
- virtual void doShowMessage(Type, const String&, const String&, const boost::filesystem::path&, boost::function<void()>) {
+ virtual void showMessage(Type, const String&, const String&, const boost::filesystem::path&, boost::function<void()>) {
}
};
}
diff --git a/SwifTools/Notifier/SnarlNotifier.h b/SwifTools/Notifier/SnarlNotifier.h
index 83d4715..2350e29 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 doShowMessage(Type type, const String& subject, const String& description, const boost::filesystem::path& picture, boost::function<void()> callback);
+ virtual void showMessage(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/SwifTools/Notifier/TogglableNotifier.h b/SwifTools/Notifier/TogglableNotifier.h
new file mode 100644
index 0000000..1e87807
--- /dev/null
+++ b/SwifTools/Notifier/TogglableNotifier.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include "SwifTools/Notifier/Notifier.h"
+
+namespace Swift {
+ class TogglableNotifier : public Notifier {
+ public:
+ TogglableNotifier(Notifier* notifier) : notifier(notifier), persistentEnabled(true), temporarilyDisabled(false) {
+ }
+
+ /**
+ * Set a long-term (usually user-set) enabled.
+ * This may be temporarily overriden by the application, e.g. if the
+ * user is marked DND.
+ */
+ void setPersistentEnabled(bool b) {
+ persistentEnabled = b;
+ }
+
+ /**
+ * Set a temporary override to stop notifications without changing the
+ * long-term state. e.g. if the user goes DND, but the persistent
+ * enabled shouldn't be lost when they become available again.
+ */
+ void setTemporarilyDisabled(bool b) {
+ temporarilyDisabled = b;
+ }
+
+ /**
+ * Get the result of applying the temporary override to the persistent
+ * enabledness.
+ */
+ bool getCurrentlyEnabled() const {
+ return persistentEnabled && !temporarilyDisabled;
+ }
+
+ virtual void showMessage(Type type, const String& subject, const String& description, const boost::filesystem::path& picture, boost::function<void()> callback) {
+ if (getCurrentlyEnabled()) {
+ notifier->showMessage(type, subject, description, picture, callback);
+ }
+ }
+
+ private:
+ Notifier* notifier;
+ bool persistentEnabled;
+ bool temporarilyDisabled;
+ };
+}