diff --git a/AppController.m b/AppController.m index 3c5d99d49..3de231139 100644 --- a/AppController.m +++ b/AppController.m @@ -25,11 +25,17 @@ // Listen to the remote in exclusive mode, only when Cog is the active application - (void)applicationDidBecomeActive:(NSNotification *)notification { - [remote startListening: self]; + BOOL onlyOnActive = [[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"remoteOnlyOnActive"] boolValue]; + if (onlyOnActive) { + [remote startListening: self]; + } } - (void)applicationDidResignActive:(NSNotification *)motification { - [remote stopListening: self]; + BOOL onlyOnActive = [[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"remoteOnlyOnActive"] boolValue]; + if (onlyOnActive) { + [remote stopListening: self]; + } } /* Helper method for the remote control interface in order to trigger forward/backward and volume @@ -179,9 +185,6 @@ increase/decrease as long as the user holds the left/right, plus/minus button */ - (void)awakeFromNib { -// [self initDefaults]; - - // DBLog(@"AWAKe"); [playButton setToolTip:NSLocalizedString(@"PlayButtonTooltip", @"")]; [prevButton setToolTip:NSLocalizedString(@"PrevButtonTooltip", @"")]; [nextButton setToolTip:NSLocalizedString(@"NextButtonTooltip", @"")]; @@ -200,6 +203,10 @@ increase/decrease as long as the user holds the left/right, plus/minus button */ [self registerHotKeys]; + //Init Remote + + + NSString *filename = @"~/Library/Application Support/Cog/Default.playlist"; [playlistController loadPlaylist:[filename stringByExpandingTildeInPath]]; } @@ -336,6 +343,7 @@ increase/decrease as long as the user holds the left/right, plus/minus button */ - (void)initDefaults { NSMutableDictionary *userDefaultsValuesDict = [NSMutableDictionary dictionary]; + [userDefaultsValuesDict setObject:[NSNumber numberWithInt:35] forKey:@"hotKeyPlayKeyCode"]; [userDefaultsValuesDict setObject:[NSNumber numberWithInt:(NSControlKeyMask|NSCommandKeyMask)] forKey:@"hotKeyPlayModifiers"]; [userDefaultsValuesDict setObject:[NSNumber numberWithInt:'P'] forKey:@"hotKeyPlayCharacter"]; @@ -350,6 +358,8 @@ increase/decrease as long as the user holds the left/right, plus/minus button */ [userDefaultsValuesDict setObject:[@"~/Music" stringByExpandingTildeInPath] forKey:@"fileDrawerRootPath"]; + [userDefaultsValuesDict setObject:[NSNumber numberWithBool:YES] forKey:@"remoteOnlyOnActive"]; + //Register and sync defaults [[NSUserDefaults standardUserDefaults] registerDefaults:userDefaultsValuesDict]; [[NSUserDefaults standardUserDefaults] synchronize]; @@ -378,6 +388,16 @@ increase/decrease as long as the user holds the left/right, plus/minus button */ else if ([keyPath isEqualToString:@"values.fileDrawerRootPath"]) { [fileTreeController setRootPath:[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"fileDrawerRootPath"]]; } + else if ([keyPath isEqualToString:@"values.remoteOnlyOnActive"]) { + BOOL onlyOnActive = [[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"remoteOnlyOnActive"] boolValue]; + if (!onlyOnActive || [NSApp isActive]) { + [remote startListening: self]; + } + if (onlyOnActive && ![NSApp isActive]) { //Setting a preference without being active? *shrugs* + [remote stopListening: self]; + } + } + } - (void)registerHotKeys diff --git a/Preferences/General/English.lproj/Preferences.nib/classes.nib b/Preferences/General/English.lproj/Preferences.nib/classes.nib index 9f01cf40d..72cf708ff 100644 --- a/Preferences/General/English.lproj/Preferences.nib/classes.nib +++ b/Preferences/General/English.lproj/Preferences.nib/classes.nib @@ -29,7 +29,11 @@ { CLASS = PrefPaneController; LANGUAGE = ObjC; - OUTLETS = {fileDrawerPane = FileDrawerPane; hotKeyPane = HotKeyPane; }; + OUTLETS = { + fileDrawerPane = FileDrawerPane; + hotKeyPane = HotKeyPane; + remotePane = RemotePane; + }; SUPERCLASS = NSObject; }, { @@ -37,6 +41,13 @@ LANGUAGE = ObjC; OUTLETS = {view = NSView; }; SUPERCLASS = NSObject; + }, + { + ACTIONS = {takeBool = id; }; + CLASS = RemotePane; + LANGUAGE = ObjC; + OUTLETS = {onlyOnActive = NSButton; }; + SUPERCLASS = PreferencePane; } ); IBVersion = 1; diff --git a/Preferences/General/English.lproj/Preferences.nib/info.nib b/Preferences/General/English.lproj/Preferences.nib/info.nib index 35c4bff4d..22f69960d 100644 --- a/Preferences/General/English.lproj/Preferences.nib/info.nib +++ b/Preferences/General/English.lproj/Preferences.nib/info.nib @@ -3,22 +3,25 @@ IBDocumentLocation - 137 120 356 240 0 0 1680 1028 + 202 336 356 240 0 0 1680 1028 IBEditorPositions 10 - 499 669 506 102 0 0 1680 1028 + 587 659 506 102 0 0 1680 1028 11 703 634 273 151 0 0 1680 1028 + 43 + 671 662 337 96 0 0 1680 1028 IBFramework Version 446.1 IBOpenObjects - 11 10 + 43 + 11 IBSystem Version - 8K1106 + 8L2127 diff --git a/Preferences/General/English.lproj/Preferences.nib/keyedobjects.nib b/Preferences/General/English.lproj/Preferences.nib/keyedobjects.nib index c126c7efa..e26c32448 100644 Binary files a/Preferences/General/English.lproj/Preferences.nib/keyedobjects.nib and b/Preferences/General/English.lproj/Preferences.nib/keyedobjects.nib differ diff --git a/Preferences/General/General.xcodeproj/project.pbxproj b/Preferences/General/General.xcodeproj/project.pbxproj index 0d9fa75c5..28685d58d 100644 --- a/Preferences/General/General.xcodeproj/project.pbxproj +++ b/Preferences/General/General.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 172D72480B891FEF00D095BB /* RemotePane.m in Sources */ = {isa = PBXBuildFile; fileRef = 172D72470B891FEF00D095BB /* RemotePane.m */; }; + 172D72AD0B8926CA00D095BB /* apple_remote.png in Resources */ = {isa = PBXBuildFile; fileRef = 172D72AC0B8926CA00D095BB /* apple_remote.png */; }; 8D5B49B0048680CD000E48DA /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C167DFE841241C02AAC07 /* InfoPlist.strings */; }; 8D5B49B4048680CD000E48DA /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */; }; 8E07AA870AAC8EA200A4B32F /* FileDrawerPane.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E07AA7F0AAC8EA200A4B32F /* FileDrawerPane.m */; }; @@ -27,6 +29,9 @@ 089C167EFE841241C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = ""; }; 089C167FFE841241C02AAC07 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = ""; }; 1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = ""; }; + 172D72460B891FEF00D095BB /* RemotePane.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = RemotePane.h; sourceTree = ""; }; + 172D72470B891FEF00D095BB /* RemotePane.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = RemotePane.m; sourceTree = ""; }; + 172D72AC0B8926CA00D095BB /* apple_remote.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = apple_remote.png; path = Icons/apple_remote.png; sourceTree = ""; }; 32DBCF630370AF2F00C91783 /* General_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = General_Prefix.pch; sourceTree = ""; }; 8D5B49B6048680CD000E48DA /* General.preferencePane */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = General.preferencePane; sourceTree = BUILT_PRODUCTS_DIR; }; 8D5B49B7048680CD000E48DA /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = Info.plist; sourceTree = ""; }; @@ -137,6 +142,8 @@ 8E07AA7F0AAC8EA200A4B32F /* FileDrawerPane.m */, 8E07AA800AAC8EA200A4B32F /* HotKeyPane.h */, 8E07AA810AAC8EA200A4B32F /* HotKeyPane.m */, + 172D72460B891FEF00D095BB /* RemotePane.h */, + 172D72470B891FEF00D095BB /* RemotePane.m */, ); name = Panes; sourceTree = ""; @@ -173,6 +180,7 @@ 8E07ABD90AAC95AF00A4B32F /* Icons */ = { isa = PBXGroup; children = ( + 172D72AC0B8926CA00D095BB /* apple_remote.png */, 8E07ABDA0AAC95BC00A4B32F /* file_drawer.png */, 8E07ABDB0AAC95BC00A4B32F /* hot_keys.png */, ); @@ -224,6 +232,7 @@ 8E07ABDC0AAC95BC00A4B32F /* file_drawer.png in Resources */, 8E07ABDD0AAC95BC00A4B32F /* hot_keys.png in Resources */, 8E07AC050AAC968C00A4B32F /* Preferences.nib in Resources */, + 172D72AD0B8926CA00D095BB /* apple_remote.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -241,6 +250,7 @@ 8E6C12160AACAE4100819171 /* NDHotKeyControl.m in Sources */, 8E6C12170AACAE4100819171 /* NDHotKeyEvent.m in Sources */, 8E6C13A00AACBAB500819171 /* HotKeyControl.m in Sources */, + 172D72480B891FEF00D095BB /* RemotePane.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Preferences/General/PrefPaneController.h b/Preferences/General/PrefPaneController.h index 3af4f9a26..955385239 100644 --- a/Preferences/General/PrefPaneController.h +++ b/Preferences/General/PrefPaneController.h @@ -11,13 +11,16 @@ #import "HotKeyPane.h" #import "FileDrawerPane.h" +#import "RemotePane.h" @interface PrefPaneController : NSObject { IBOutlet HotKeyPane *hotKeyPane; IBOutlet FileDrawerPane *fileDrawerPane; + IBOutlet RemotePane *remotePane; } -- (FileDrawerPane *)fileDrawerPane; - (HotKeyPane *)hotKeyPane; +- (FileDrawerPane *)fileDrawerPane; +- (RemotePane *)remotePane; @end diff --git a/Preferences/General/PrefPaneController.m b/Preferences/General/PrefPaneController.m index 71f7740a6..85ebbc161 100644 --- a/Preferences/General/PrefPaneController.m +++ b/Preferences/General/PrefPaneController.m @@ -18,7 +18,7 @@ PrefPaneController *prefPaneController = [[PrefPaneController alloc] init]; loaded = [NSBundle loadNibNamed:@"Preferences" owner:prefPaneController]; - return [NSArray arrayWithObjects: [prefPaneController hotKeyPane], [prefPaneController fileDrawerPane], nil]; + return [NSArray arrayWithObjects: [prefPaneController hotKeyPane], [prefPaneController fileDrawerPane], [prefPaneController remotePane], nil]; } - (HotKeyPane *)hotKeyPane @@ -31,4 +31,9 @@ return fileDrawerPane; } +- (RemotePane *)remotePane +{ + return remotePane; +} + @end diff --git a/Preferences/General/RemotePane.h b/Preferences/General/RemotePane.h new file mode 100644 index 000000000..edf0b1f95 --- /dev/null +++ b/Preferences/General/RemotePane.h @@ -0,0 +1,19 @@ +// +// FileDrawerPane.h +// Preferences +// +// Created by Vincent Spader on 9/4/06. +// Copyright 2006 Vincent Spader. All rights reserved. +// + +#import +#import "PreferencePane.h" + + +@interface RemotePane : PreferencePane { + IBOutlet NSButton *onlyOnActive; +} + +- (IBAction)takeBool:(id)sender; + +@end diff --git a/Preferences/General/RemotePane.m b/Preferences/General/RemotePane.m new file mode 100644 index 000000000..095a6eabd --- /dev/null +++ b/Preferences/General/RemotePane.m @@ -0,0 +1,27 @@ +// +// FileDrawerPane.m +// Preferences +// +// Created by Vincent Spader on 9/4/06. +// Copyright 2006 Vincent Spader. All rights reserved. +// + +#import "RemotePane.h" + + +@implementation RemotePane + +- (void)awakeFromNib +{ + [self setName:@"Remote"]; + [self setIcon:@"apple_remote"]; + + [onlyOnActive setState:[[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"remoteOnlyOnActive"] boolValue]]; +} + +- (IBAction)takeBool:(id)sender +{ + [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:[onlyOnActive state]] forKey:@"remoteOnlyOnActive"]; +} + +@end