aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPNotificationsPreferencePane.m
diff options
context:
space:
mode:
authorMax <post@wickenrode.com>2014-12-31 05:36:48 +0100
committerMax <post@wickenrode.com>2014-12-31 05:36:48 +0100
commit918324e27b6b4753307fa6a8166b3d7227f97b35 (patch)
tree04b77b2385e4d5e085cad7b6dd98659f9dd847c3 /Source/SPNotificationsPreferencePane.m
parent42593525e55ad5daa01b3edde3c4cce653559f72 (diff)
downloadsequelpro-918324e27b6b4753307fa6a8166b3d7227f97b35.tar.gz
sequelpro-918324e27b6b4753307fa6a8166b3d7227f97b35.tar.bz2
sequelpro-918324e27b6b4753307fa6a8166b3d7227f97b35.zip
Change how Growl status is displayed in prefs
The current status of Growl/Notification center will now be shown as a label beneath the "Enable notifications" checkbox.
Diffstat (limited to 'Source/SPNotificationsPreferencePane.m')
-rw-r--r--Source/SPNotificationsPreferencePane.m81
1 files changed, 72 insertions, 9 deletions
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