forked from rentzsch/clicktoflash
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finished external .plist prefs file support; includes code to migrate…
… existing parasitic prefs from com.apple.Safari.plist to the new external file
- Loading branch information
Simone Manganelli
authored and
Simone Manganelli
committed
Jun 25, 2009
1 parent
4a239f7
commit 39a3ae3
Showing
13 changed files
with
371 additions
and
201 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// CTFUserDefaultsController.h | ||
// ClickToFlash | ||
// | ||
// Created by Simone Manganelli on 2009-05-23. | ||
// Copyright 2009 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
#import "CTFPreferencesDictionary.h" | ||
|
||
|
||
@interface CTFUserDefaultsController : NSUserDefaultsController { | ||
CTFPreferencesDictionary *userDefaultsDict; | ||
BOOL hasInited; | ||
} | ||
|
||
+ (CTFUserDefaultsController *)standardUserDefaults; | ||
- (void)setUpExternalPrefsDictionary; | ||
|
||
- (void)pluginDefaultsDidChange:(NSNotification *)notification; | ||
- (CTFPreferencesDictionary *)values; | ||
- (CTFPreferencesDictionary *)dictionaryRepresentation; | ||
- (void)setValues:(CTFPreferencesDictionary *)newUserDefaultsDict; | ||
|
||
- (id)objectForKey:(NSString *)defaultName; | ||
- (void)setObject:(id)value forKey:(NSString *)defaultName; | ||
- (int)integerForKey:(NSString *)defaultName; | ||
- (void)setIntegerForKey:(int)value forKey:(NSString *)defaultName; | ||
- (BOOL)boolForKey:(NSString *)defaultName; | ||
- (void)setBool:(BOOL)value forKey:(NSString *)defaultName; | ||
- (NSArray *)arrayForKey:(NSString *)defaultName; | ||
- (void)removeObjectForKey:(NSString *)defaultName; | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// | ||
// CTFUserDefaultsController.m | ||
// ClickToFlash | ||
// | ||
// Created by Simone Manganelli on 2009-05-23. | ||
// Copyright 2009 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import "CTFUserDefaultsController.h" | ||
|
||
static CTFUserDefaultsController *sharedInstance = nil; | ||
|
||
@implementation CTFUserDefaultsController | ||
|
||
+ (CTFUserDefaultsController *)standardUserDefaults; | ||
{ | ||
if (! sharedInstance) sharedInstance = [[self alloc] init]; | ||
return sharedInstance; | ||
} | ||
|
||
- (id)init; | ||
{ | ||
if (! sharedInstance) { | ||
if ((self = [super init])) { | ||
hasInited = YES; | ||
} | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (void)dealloc; | ||
{ | ||
[userDefaultsDict release]; | ||
[super dealloc]; | ||
} | ||
|
||
- (void)setUpExternalPrefsDictionary; | ||
{ | ||
[[NSNotificationCenter defaultCenter] addObserver:self | ||
selector:@selector(pluginDefaultsDidChange:) | ||
name:@"ClickToFlashPluginDefaultsDidChange" | ||
object:nil]; | ||
[self setValues:[CTFPreferencesDictionary dictionaryWithDictionary: | ||
[[NSUserDefaults standardUserDefaults] persistentDomainForName:@"com.github.rentzsch.clicktoflash"]] | ||
]; | ||
} | ||
|
||
- (CTFPreferencesDictionary *)values; | ||
{ | ||
// I have no idea why, but -init, -initWithDefaults:initialValues:, | ||
// and +sharedUserDefaultsController all never seem to get called. Only | ||
// -awakeFromNib gets called, and that's too late for bindings; | ||
|
||
// so instead, we just wait for the initial call to access values, | ||
// and if that call detects that the user defaults dictionary hasn't | ||
// been set up yet, it sets it up and *then* returns the values | ||
|
||
if (! userDefaultsDict) [self setUpExternalPrefsDictionary]; | ||
return userDefaultsDict; | ||
} | ||
|
||
- (CTFPreferencesDictionary *)dictionaryRepresentation; | ||
{ | ||
return [self values]; | ||
} | ||
|
||
- (void)setValues:(CTFPreferencesDictionary *)newUserDefaultsDict; | ||
{ | ||
if (! userDefaultsDict) userDefaultsDict = [[CTFPreferencesDictionary alloc] init]; | ||
[userDefaultsDict removeAllObjects]; | ||
[userDefaultsDict addEntriesFromDictionary:newUserDefaultsDict]; | ||
} | ||
|
||
- (void)pluginDefaultsDidChange:(NSNotification *)notification; | ||
{ | ||
[[NSUserDefaults standardUserDefaults] setPersistentDomain:userDefaultsDict | ||
forName:@"com.github.rentzsch.clicktoflash"]; | ||
} | ||
|
||
- (id)objectForKey:(NSString *)defaultName; | ||
{ | ||
return [[self values] objectForKey:defaultName]; | ||
} | ||
|
||
- (void)setObject:(id)value forKey:(NSString *)defaultName; | ||
{ | ||
[[self values] setObject:value forKey:defaultName]; | ||
} | ||
|
||
- (int)integerForKey:(NSString *)defaultName; | ||
{ | ||
return [[[self values] objectForKey:defaultName] intValue]; | ||
} | ||
|
||
- (void)setIntegerForKey:(int)value forKey:(NSString *)defaultName; | ||
{ | ||
[[self values] setObject:[NSNumber numberWithInt:value] forKey:defaultName]; | ||
} | ||
|
||
- (BOOL)boolForKey:(NSString *)defaultName; | ||
{ | ||
return [[[self values] objectForKey:defaultName] boolValue]; | ||
} | ||
|
||
- (void)setBool:(BOOL)value forKey:(NSString *)defaultName; | ||
{ | ||
[[self values] setObject:[NSNumber numberWithBool:value] forKey:defaultName]; | ||
} | ||
|
||
- (NSArray *)arrayForKey:(NSString *)defaultName; | ||
{ | ||
id value = [[self values] objectForKey:defaultName]; | ||
id valueToReturn = nil; | ||
if ([[value className] isEqualToString:@"NSCFArray"]) valueToReturn = value; | ||
return valueToReturn; | ||
} | ||
|
||
- (void)removeObjectForKey:(NSString *)defaultName; | ||
{ | ||
[[self values] removeObjectForKey:defaultName]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.