diff options
| author | Remko Tronçon <git@el-tramo.be> | 2011-12-24 10:08:47 (GMT) |
|---|---|---|
| committer | Remko Tronçon <git@el-tramo.be> | 2011-12-24 11:00:04 (GMT) |
| commit | 3e2a3a4cdb0b6bc0cf79423c48400c544830177a (patch) | |
| tree | dcc53224fd0b0ed0bd704a4b097f5c425dbd672e /SwifTools/Notifier/GrowlNotifier.mm | |
| parent | f69d027b7e3b4260e514a77f7195ec511977b63e (diff) | |
| download | swift-contrib-3e2a3a4cdb0b6bc0cf79423c48400c544830177a.zip swift-contrib-3e2a3a4cdb0b6bc0cf79423c48400c544830177a.tar.bz2 | |
Enable "Show notifications" toggle when Growl isn't installed.
Diffstat (limited to 'SwifTools/Notifier/GrowlNotifier.mm')
| -rw-r--r-- | SwifTools/Notifier/GrowlNotifier.mm | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/SwifTools/Notifier/GrowlNotifier.mm b/SwifTools/Notifier/GrowlNotifier.mm index 108259a..cb4790e 100644 --- a/SwifTools/Notifier/GrowlNotifier.mm +++ b/SwifTools/Notifier/GrowlNotifier.mm @@ -16,69 +16,75 @@ #pragma GCC diagnostic ignored "-Wold-style-cast" namespace { struct Context { Context(const boost::function<void()>& callback) : callback(new boost::function<void()>(callback)) {} boost::function<void()>* callback; }; } namespace Swift { class GrowlNotifier::Private { public: boost::intrusive_ptr<GrowlNotifierDelegate> delegate; }; GrowlNotifier::GrowlNotifier(const std::string& name) { p = boost::make_shared<Private>(); p->delegate = boost::intrusive_ptr<GrowlNotifierDelegate>([[GrowlNotifierDelegate alloc] init], false); p->delegate.get().name = STD2NSSTRING(name); NSMutableArray* allNotifications = [[NSMutableArray alloc] init]; foreach(Type type, getAllTypes()) { [allNotifications addObject: STD2NSSTRING(typeToString(type))]; } NSMutableArray* defaultNotifications = [[NSMutableArray alloc] init]; foreach(Type type, getDefaultTypes()) { [defaultNotifications addObject: STD2NSSTRING(typeToString(type))]; } p->delegate.get().registrationDictionary = [[[NSDictionary alloc] initWithObjects: [NSArray arrayWithObjects: allNotifications, defaultNotifications, nil] forKeys: [NSArray arrayWithObjects: GROWL_NOTIFICATIONS_ALL, GROWL_NOTIFICATIONS_DEFAULT, nil]] autorelease]; + + [allNotifications release]; + [defaultNotifications release]; [GrowlApplicationBridge setGrowlDelegate: p->delegate.get()]; } void GrowlNotifier::showMessage(Type type, const std::string& subject, const std::string& description, const boost::filesystem::path& picturePath, boost::function<void()> callback) { ByteArray picture; readByteArrayFromFile(picture, picturePath.string()); - Context* contextPtr = new Context(callback); - NSData* context = [NSData dataWithBytes: &contextPtr length: sizeof(contextPtr)]; + Context* context = new Context(callback); [GrowlApplicationBridge notifyWithTitle: STD2NSSTRING(subject) description: STD2NSSTRING(description) notificationName: STD2NSSTRING(typeToString(type)) iconData: [NSData dataWithBytes: vecptr(picture) length: picture.size()] priority: 0 isSticky: NO - clickContext: context]; + clickContext: [NSData dataWithBytes: &context length: sizeof(context)]]; } void GrowlNotifier::handleNotificationClicked(void* rawData) { Context* context = *(Context**) [((NSData*) rawData) bytes]; if (!context->callback->empty()) { (*context->callback)(); } delete context; } void GrowlNotifier::handleNotificationTimedOut(void* rawData) { delete *(Context**) [((NSData*) rawData) bytes]; } +bool GrowlNotifier::isExternallyConfigured() const { + return ![GrowlApplicationBridge isMistEnabled]; +} + } |
Swift