diff options
author | Kevin Smith <git@kismith.co.uk> | 2012-03-14 13:12:24 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2012-03-14 13:24:44 (GMT) |
commit | f90fce80371ac12d97c6adc65a9437e4a3a7b268 (patch) | |
tree | 9e277bc46ae0a0cf3e54aa252d1a5c630e35ec83 /SwifTools | |
parent | 1089374439fa6073800679817198e3c39283113e (diff) | |
download | swift-contrib-f90fce80371ac12d97c6adc65a9437e4a3a7b268.zip swift-contrib-f90fce80371ac12d97c6adc65a9437e4a3a7b268.tar.bz2 |
Dispose of notification callbacks once the account signs out.
Fixes segfaults caused by clicking notifications after
the handlers had been freed.
Does not fix GrowlNotifier, which needs fixing later.
Diffstat (limited to 'SwifTools')
-rw-r--r-- | SwifTools/Notifier/GrowlNotifier.h | 3 | ||||
-rw-r--r-- | SwifTools/Notifier/LoggingNotifier.h | 2 | ||||
-rw-r--r-- | SwifTools/Notifier/Notifier.h | 3 | ||||
-rw-r--r-- | SwifTools/Notifier/NullNotifier.h | 1 | ||||
-rw-r--r-- | SwifTools/Notifier/SnarlNotifier.h | 4 | ||||
-rw-r--r-- | SwifTools/Notifier/TogglableNotifier.h | 4 |
6 files changed, 17 insertions, 0 deletions
diff --git a/SwifTools/Notifier/GrowlNotifier.h b/SwifTools/Notifier/GrowlNotifier.h index f4e6803..f1fb8c6 100644 --- a/SwifTools/Notifier/GrowlNotifier.h +++ b/SwifTools/Notifier/GrowlNotifier.h @@ -23,14 +23,17 @@ namespace Swift { ~GrowlNotifier(); virtual void showMessage(Type type, const std::string& subject, const std::string& description, const boost::filesystem::path& picture, boost::function<void()> callback); virtual bool isExternallyConfigured() const; // Called by the delegate. Don't call. void handleNotificationClicked(void* data); void handleNotificationTimedOut(void* data); + virtual void purgeCallbacks() { +#warning FIXME: Implement + } private: class Private; boost::shared_ptr<Private> p; }; } diff --git a/SwifTools/Notifier/LoggingNotifier.h b/SwifTools/Notifier/LoggingNotifier.h index 32e0610..3d62593 100644 --- a/SwifTools/Notifier/LoggingNotifier.h +++ b/SwifTools/Notifier/LoggingNotifier.h @@ -19,12 +19,14 @@ namespace Swift { struct Notification { Notification(Type type, const std::string& subject, const std::string& description, const boost::filesystem::path& picture, boost::function<void()> callback) : type(type), subject(subject), description(description), picture(picture), callback(callback) {} Type type; std::string subject; std::string description; boost::filesystem::path picture; boost::function<void()> callback; }; + virtual void purgeCallbacks() {} + std::vector<Notification> notifications; }; } diff --git a/SwifTools/Notifier/Notifier.h b/SwifTools/Notifier/Notifier.h index 1bcd58d..9537ec1 100644 --- a/SwifTools/Notifier/Notifier.h +++ b/SwifTools/Notifier/Notifier.h @@ -30,18 +30,21 @@ namespace Swift { virtual bool isAvailable() const { return true; } virtual bool isExternallyConfigured() const { return false; } + /** Remove any pending callbacks. */ + virtual void purgeCallbacks() = 0; + protected: std::string typeToString(Type type); static std::vector<Type> getAllTypes(); static std::vector<Type> getDefaultTypes(); static const int DEFAULT_STATUS_NOTIFICATION_TIMEOUT_SECONDS; static const int DEFAULT_MESSAGE_NOTIFICATION_TIMEOUT_SECONDS; }; } diff --git a/SwifTools/Notifier/NullNotifier.h b/SwifTools/Notifier/NullNotifier.h index 2fa9c11..576dd85 100644 --- a/SwifTools/Notifier/NullNotifier.h +++ b/SwifTools/Notifier/NullNotifier.h @@ -7,11 +7,12 @@ #pragma once #include <SwifTools/Notifier/Notifier.h> namespace Swift { class NullNotifier : public Notifier { public: virtual void showMessage(Type, const std::string&, const std::string&, const boost::filesystem::path&, boost::function<void()>) { } + virtual void purgeCallbacks() { }; } diff --git a/SwifTools/Notifier/SnarlNotifier.h b/SwifTools/Notifier/SnarlNotifier.h index c96dfa6..eb0eb5a 100644 --- a/SwifTools/Notifier/SnarlNotifier.h +++ b/SwifTools/Notifier/SnarlNotifier.h @@ -16,18 +16,22 @@ namespace Swift { class SnarlNotifier : public Notifier { public: SnarlNotifier(const std::string& name, Win32NotifierWindow* window, const boost::filesystem::path& icon); ~SnarlNotifier(); virtual void showMessage(Type type, const std::string& subject, const std::string& description, const boost::filesystem::path& picture, boost::function<void()> callback); virtual bool isAvailable() const; + virtual void purgeCallbacks() { + notifications.clear(); + } + private: void handleMessageReceived(MSG* message); private: Snarl::V41::SnarlInterface snarl; Win32NotifierWindow* window; bool available; typedef std::map<int, boost::function<void()> > NotificationsMap; NotificationsMap notifications; diff --git a/SwifTools/Notifier/TogglableNotifier.h b/SwifTools/Notifier/TogglableNotifier.h index 7abfd42..a4f0bb6 100644 --- a/SwifTools/Notifier/TogglableNotifier.h +++ b/SwifTools/Notifier/TogglableNotifier.h @@ -44,15 +44,19 @@ namespace Swift { if (getCurrentlyEnabled() || notifier->isExternallyConfigured()) { notifier->showMessage(type, subject, description, picture, callback); } } virtual bool isExternallyConfigured() const { return notifier->isExternallyConfigured(); } + virtual void purgeCallbacks() { + notifier->purgeCallbacks(); + } + private: Notifier* notifier; bool persistentEnabled; bool temporarilyDisabled; }; } |