aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/SPNotificationsPreferencePane.h3
-rw-r--r--Source/SPNotificationsPreferencePane.m81
2 files changed, 75 insertions, 9 deletions
diff --git a/Source/SPNotificationsPreferencePane.h b/Source/SPNotificationsPreferencePane.h
index e9650928..cf0f4c42 100644
--- a/Source/SPNotificationsPreferencePane.h
+++ b/Source/SPNotificationsPreferencePane.h
@@ -38,5 +38,8 @@
* Notifications preference pane controller.
*/
@interface SPNotificationsPreferencePane : SPPreferencePane <SPPreferencePaneProtocol>
+{
+ IBOutlet NSTextField *growlStatusLabel;
+}
@end
diff --git a/Source/SPNotificationsPreferencePane.m b/Source/SPNotificationsPreferencePane.m
index dcd713e2..3c64a1ff 100644
--- a/Source/SPNotificationsPreferencePane.m
+++ b/Source/SPNotificationsPreferencePane.m
@@ -29,23 +29,66 @@
// More info at <https://github.com/sequelpro/sequelpro>
#import "SPNotificationsPreferencePane.h"
+#import <Growl/Growl.h>
+#import "SPGrowlController.h"
+
+static NSString *_runningApplicationsKeyPath = @"runningApplications";
@implementation SPNotificationsPreferencePane
+- (instancetype)init
+{
+ self = [super init];
+ if (self) {
+ // this notification is posted by the GrowlApplicationBridge right after
+ // it would have called -[delegate growlIsReady], so we'll just use this
+ // as a shortcut.
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(growlLaunchedNotifcation:)
+ name:GROWL_IS_READY
+ object:nil];
+ // we need to initialize the GrowlApplicationBridge for the notification to actually work
+ [SPGrowlController sharedGrowlController];
+ // Growl doesn't tell use when it exits (even though they DO monitor it).
+ // This code replicates what it does internally.
+ [[NSWorkspace sharedWorkspace] addObserver:self
+ forKeyPath:_runningApplicationsKeyPath
+ options:NSKeyValueObservingOptionNew
+ context:nil];
+ // TODO: we are only really interested in this notification while we are visible.
+ }
+ return self;
+}
+
+-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
+ //check if growl has exited
+ if(object == [NSWorkspace sharedWorkspace] && [keyPath isEqualToString:_runningApplicationsKeyPath]){
+ [self updateGrowlStatusLabel];
+ }
+}
+
+- (void)dealloc
+{
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+ [[NSWorkspace sharedWorkspace] removeObserver:self forKeyPath:_runningApplicationsKeyPath];
+ [super dealloc];
+}
+
+- (void)growlLaunchedNotifcation:(NSNotification *)notification
+{
+ [self updateGrowlStatusLabel];
+}
+
+- (void)preferencePaneWillBeShown
+{
+ [self updateGrowlStatusLabel];
+}
+
#pragma mark -
#pragma mark Bindings
-/**
- * Displays an informational message regarding Growl notifications if enabled.
- */
- (void)setGrowlEnabled:(BOOL)value
{
- if (value) {
- NSBeginInformationalAlertSheet(NSLocalizedString(@"Growl notification preferences", "Growl notification preferences alert title"),
- nil, nil, nil, [[self view] window], self, nil, nil, nil,
- NSLocalizedString(@"All Growl notifications are enabled by default. To change which notifications are displayed, go to the Growl Preference Pane in the System Preferences and choose what notifications Growl should display from Sequel Pro.", @"Growl notification preferences alert message"));
- }
-
[prefs setBool:value forKey:SPGrowlEnabled];
}
@@ -57,6 +100,26 @@
return [prefs boolForKey:SPGrowlEnabled];
}
+- (void)updateGrowlStatusLabel
+{
+ NSString *text;
+ if([GrowlApplicationBridge isGrowlRunning]) {
+ text = NSLocalizedString(@"Growl will be used for sending notifications.\nAdvanced settings can be configured via Growl.",@"Preferences : Notifications : growl status text : growl installed and running");
+ }
+ else {
+ text = @"";
+
+ if(NSClassFromString(@"NSUserNotificationCenter")) { //this is what growl does
+ //10.8+
+ text = NSLocalizedString(@"Notification Center will be used for sending notifications. ",@"Preferences : Notifications : growl status text : growl not installed, Apple's Notificiation Center is used instead. (KEEP the SPACE at the end)");
+ }
+ //else case would be embedded growl ("Mist", 10.6 - 10.7), but telling that would IMHO be more confusing for the user.
+
+ text = [text stringByAppendingString:NSLocalizedString(@"Install Growl for advanced control over notifications.",@"Preferences : Notifications : growl status text : additional hint when embedded Growl ('Mist') or Notification Center is used.")];
+ }
+ [growlStatusLabel setStringValue:text];
+}
+
#pragma mark -
#pragma mark Preference pane protocol methods