diff options
Diffstat (limited to 'SwifTools')
-rw-r--r-- | SwifTools/Notifier/GrowlNotifier.cpp | 18 | ||||
-rw-r--r-- | SwifTools/Notifier/LoggingNotifier.h | 30 |
2 files changed, 43 insertions, 5 deletions
diff --git a/SwifTools/Notifier/GrowlNotifier.cpp b/SwifTools/Notifier/GrowlNotifier.cpp index 4c671ac..7ea7193 100644 --- a/SwifTools/Notifier/GrowlNotifier.cpp +++ b/SwifTools/Notifier/GrowlNotifier.cpp @@ -17,22 +17,30 @@ namespace { struct Context { Context() {} - Context(const boost::function<void()>& callback) : callback(callback) {} + Context(const boost::function<void()>& callback) : callback(new boost::function<void()>(callback)) {} - boost::function<void()> callback; + boost::function<void()>* callback; }; - void notificationClicked(CFPropertyListRef growlContext) { + void processNotification(CFPropertyListRef growlContext, bool activateCallback) { Context context; CFDataRef growlContextData = (CFDataRef) CFArrayGetValueAtIndex((CFArrayRef) growlContext, 0); assert(CFDataGetLength(growlContextData) == sizeof(Context)); CFDataGetBytes(growlContextData, CFRangeMake(0, CFDataGetLength(growlContextData)), (UInt8*) &context); - context.callback(); + if (activateCallback) { + (*context.callback)(); + } + delete context.callback; + } + + void notificationClicked(CFPropertyListRef growlContext) { + processNotification(growlContext, true); } - void notificationTimedout(CFPropertyListRef) { + void notificationTimedout(CFPropertyListRef growlContext) { + processNotification(growlContext, false); } } diff --git a/SwifTools/Notifier/LoggingNotifier.h b/SwifTools/Notifier/LoggingNotifier.h new file mode 100644 index 0000000..93349d9 --- /dev/null +++ b/SwifTools/Notifier/LoggingNotifier.h @@ -0,0 +1,30 @@ +/* + * 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" +#include "Swiften/Base/ByteArray.h" + +namespace Swift { + class LoggingNotifier : public Notifier { + public: + virtual void showMessage(Type type, const String& subject, const String& description, const ByteArray& picture, boost::function<void()> callback) { + notifications.push_back(Notification(type, subject, description, picture, callback)); + } + + struct Notification { + Notification(Type type, const String& subject, const String& description, const ByteArray& picture, boost::function<void()> callback) : type(type), subject(subject), description(description), picture(picture), callback(callback) {} + Type type; + String subject; + String description; + ByteArray picture; + boost::function<void()> callback; + }; + + std::vector<Notification> notifications; + }; +} |