summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-09-12 18:29:39 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-09-13 19:19:52 (GMT)
commitef1052bbdb315aaa1c6254098ea05638d9a25b2f (patch)
tree482277f649f6c0fc00027514ea8986861fe33437 /SwifTools
parent3ae8cccfe9c6bfed5dda5f024a5cb046ccfc9793 (diff)
downloadswift-contrib-ef1052bbdb315aaa1c6254098ea05638d9a25b2f.zip
swift-contrib-ef1052bbdb315aaa1c6254098ea05638d9a25b2f.tar.bz2
Added presence notifier.
Diffstat (limited to 'SwifTools')
-rw-r--r--SwifTools/Notifier/GrowlNotifier.cpp18
-rw-r--r--SwifTools/Notifier/LoggingNotifier.h30
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;
+ };
+}