summaryrefslogtreecommitdiffstats
blob: 415caf6c11a64dd8c03caee8fcaf4b4b4783961c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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 std::string& subject, const std::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;
	};
}