Skip to content

Commit

Permalink
finished external .plist prefs file support; includes code to migrate…
Browse files Browse the repository at this point in the history
… 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
Show file tree
Hide file tree
Showing 13 changed files with 371 additions and 201 deletions.
20 changes: 0 additions & 20 deletions CTFUserDefaultsController.h

This file was deleted.

50 changes: 0 additions & 50 deletions CTFUserDefaultsController.m

This file was deleted.

24 changes: 12 additions & 12 deletions ClickToFlash.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
844695F70F470D1F00DC783A /* CTFsIFRSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = 844695910F46FC6600DC783A /* CTFsIFRSupport.m */; };
845704550F4792320017F3F4 /* CTFWhitelist.m in Sources */ = {isa = PBXBuildFile; fileRef = 845704540F4792320017F3F4 /* CTFWhitelist.m */; };
8457045A0F47BC170017F3F4 /* CTFUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 845704590F47BC170017F3F4 /* CTFUtilities.m */; };
A41626600FCB535300181427 /* CTFPreferencesDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = A416265F0FCB535300181427 /* CTFPreferencesDictionary.m */; };
A461B6590FC8ECB20028C966 /* CTFUserDefaultsController.m in Sources */ = {isa = PBXBuildFile; fileRef = A461B6580FC8ECB20028C966 /* CTFUserDefaultsController.m */; };
A494CC2C0F9F2446007D5EEB /* ctf.icns in Resources */ = {isa = PBXBuildFile; fileRef = A494CC2B0F9F2446007D5EEB /* ctf.icns */; };
A4DEFC460FF33D2D00CCB6A8 /* CTFPreferencesDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = A4DEFC430FF33D2D00CCB6A8 /* CTFPreferencesDictionary.m */; };
A4DEFC470FF33D2D00CCB6A8 /* CTFUserDefaultsController.m in Sources */ = {isa = PBXBuildFile; fileRef = A4DEFC450FF33D2D00CCB6A8 /* CTFUserDefaultsController.m */; };
B5028E930F413553004886D7 /* HarnessAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = B5028E910F413553004886D7 /* HarnessAppDelegate.m */; };
B5CFF17A0F40EEF1005DB9CC /* WhitelistPanel.xib in Resources */ = {isa = PBXBuildFile; fileRef = 072189BC0F30D9C3008C8944 /* WhitelistPanel.xib */; };
B5CFF1870F40F000005DB9CC /* HarnessMain.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5CFF1860F40F000005DB9CC /* HarnessMain.xib */; };
Expand Down Expand Up @@ -157,11 +157,11 @@
845704540F4792320017F3F4 /* CTFWhitelist.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CTFWhitelist.m; path = Plugin/CTFWhitelist.m; sourceTree = "<group>"; };
845704580F47BC170017F3F4 /* CTFUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CTFUtilities.h; path = Plugin/CTFUtilities.h; sourceTree = "<group>"; };
845704590F47BC170017F3F4 /* CTFUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CTFUtilities.m; path = Plugin/CTFUtilities.m; sourceTree = "<group>"; };
A416265E0FCB535300181427 /* CTFPreferencesDictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CTFPreferencesDictionary.h; sourceTree = "<group>"; };
A416265F0FCB535300181427 /* CTFPreferencesDictionary.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CTFPreferencesDictionary.m; sourceTree = "<group>"; };
A461B6570FC8ECB20028C966 /* CTFUserDefaultsController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CTFUserDefaultsController.h; sourceTree = "<group>"; };
A461B6580FC8ECB20028C966 /* CTFUserDefaultsController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CTFUserDefaultsController.m; sourceTree = "<group>"; };
A494CC2B0F9F2446007D5EEB /* ctf.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = ctf.icns; sourceTree = "<group>"; };
A4DEFC420FF33D2D00CCB6A8 /* CTFPreferencesDictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CTFPreferencesDictionary.h; path = Plugin/CTFPreferencesDictionary.h; sourceTree = "<group>"; };
A4DEFC430FF33D2D00CCB6A8 /* CTFPreferencesDictionary.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CTFPreferencesDictionary.m; path = Plugin/CTFPreferencesDictionary.m; sourceTree = "<group>"; };
A4DEFC440FF33D2D00CCB6A8 /* CTFUserDefaultsController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CTFUserDefaultsController.h; path = Plugin/CTFUserDefaultsController.h; sourceTree = "<group>"; };
A4DEFC450FF33D2D00CCB6A8 /* CTFUserDefaultsController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CTFUserDefaultsController.m; path = Plugin/CTFUserDefaultsController.m; sourceTree = "<group>"; };
B5028E910F413553004886D7 /* HarnessAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = HarnessAppDelegate.m; path = "TestFiles/Debugging Harness/HarnessAppDelegate.m"; sourceTree = "<group>"; };
B5028E920F413553004886D7 /* HarnessAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HarnessAppDelegate.h; path = "TestFiles/Debugging Harness/HarnessAppDelegate.h"; sourceTree = "<group>"; };
B5CFF1740F40EEDB005DB9CC /* Whitelist Panel Harness.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Whitelist Panel Harness.app"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -229,10 +229,10 @@
children = (
55EB703D0E04A84F0016593D /* Plugin.m */,
55EB703C0E04A84F0016593D /* Plugin.h */,
A416265E0FCB535300181427 /* CTFPreferencesDictionary.h */,
A416265F0FCB535300181427 /* CTFPreferencesDictionary.m */,
A461B6570FC8ECB20028C966 /* CTFUserDefaultsController.h */,
A461B6580FC8ECB20028C966 /* CTFUserDefaultsController.m */,
A4DEFC420FF33D2D00CCB6A8 /* CTFPreferencesDictionary.h */,
A4DEFC430FF33D2D00CCB6A8 /* CTFPreferencesDictionary.m */,
A4DEFC440FF33D2D00CCB6A8 /* CTFUserDefaultsController.h */,
A4DEFC450FF33D2D00CCB6A8 /* CTFUserDefaultsController.m */,
845704580F47BC170017F3F4 /* CTFUtilities.h */,
845704590F47BC170017F3F4 /* CTFUtilities.m */,
6953E4340F3EDE9D0014ECF7 /* CTFMenubarMenuController.m */,
Expand Down Expand Up @@ -468,8 +468,8 @@
8457045A0F47BC170017F3F4 /* CTFUtilities.m in Sources */,
79E2EB930F86AAD3005CF170 /* SparkleManager.m in Sources */,
0038DE240FC0CCF0007B54E9 /* MATrackingArea.m in Sources */,
A461B6590FC8ECB20028C966 /* CTFUserDefaultsController.m in Sources */,
A41626600FCB535300181427 /* CTFPreferencesDictionary.m in Sources */,
A4DEFC460FF33D2D00CCB6A8 /* CTFPreferencesDictionary.m in Sources */,
A4DEFC470FF33D2D00CCB6A8 /* CTFUserDefaultsController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
// Created by Simone Manganelli on 2009-05-25.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
// the rationale for this class is so that we can monitor when
// defaults change, and update the *external* preference file accordingly.
// to do so, we need to monitor the mutable dictionary that represents the
// defaults. this class follows @bbum's suggestion at this URL:
// http://www.omnigroup.com/mailman/archive/macosx-dev/1999-April/007726.html

#import "CTFPreferencesDictionary.h"

Expand Down Expand Up @@ -43,7 +48,6 @@ - (void)dealloc;
- (void)setObject:(id)object forKey:(id)key;
{
[realMutableDictionary setObject:object forKey:key];
NSLog(@"posting a notification of defaults change");
[[NSNotificationCenter defaultCenter] postNotificationName:@"ClickToFlashPluginDefaultsDidChange" object:self];
}

Expand Down
36 changes: 36 additions & 0 deletions Plugin/CTFUserDefaultsController.h
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
124 changes: 124 additions & 0 deletions Plugin/CTFUserDefaultsController.m
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
13 changes: 8 additions & 5 deletions Plugin/CTFWhitelist.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ of this software and associated documentation files (the "Software"), to deal
#import "CTFUtilities.h"
#import "CTFMenubarMenuController.h"

#import "CTFUserDefaultsController.h"
#import "CTFPreferencesDictionary.h"


// NSNotification names
static NSString *sCTFWhitelistAdditionMade = @"CTFWhitelistAdditionMade";

// NSUserDefaults keys
// CTFUserDefaultsController keys
static NSString *sHostSiteInfoDefaultsKey = @"ClickToFlash_siteInfo";

typedef enum {
Expand Down Expand Up @@ -160,13 +163,13 @@ - (BOOL) _isHostWhitelisted

- (BOOL) _isWhiteListedForHostString:(NSString *)hostString
{
NSArray *hostWhitelist = [[NSUserDefaults standardUserDefaults] arrayForKey: sHostSiteInfoDefaultsKey];
NSArray *hostWhitelist = [[CTFUserDefaultsController standardUserDefaults] arrayForKey: sHostSiteInfoDefaultsKey];
return hostWhitelist && itemForSite(hostWhitelist, hostString) != nil;
}

- (NSMutableArray *) _mutableSiteInfo
{
NSMutableArray *hostWhitelist = [[[[NSUserDefaults standardUserDefaults] arrayForKey: sHostSiteInfoDefaultsKey] mutableCopy] autorelease];
NSMutableArray *hostWhitelist = [[[[CTFUserDefaultsController standardUserDefaults] arrayForKey: sHostSiteInfoDefaultsKey] mutableCopy] autorelease];
if (hostWhitelist == nil) {
hostWhitelist = [NSMutableArray array];
}
Expand All @@ -177,7 +180,7 @@ - (void) _addHostToWhitelist
{
NSMutableArray *siteInfo = [self _mutableSiteInfo];
[siteInfo addObject: whitelistItemForSite([self host])];
[[NSUserDefaults standardUserDefaults] setObject: siteInfo forKey: sHostSiteInfoDefaultsKey];
[[CTFUserDefaultsController standardUserDefaults] setObject: siteInfo forKey: sHostSiteInfoDefaultsKey];
[[NSNotificationCenter defaultCenter] postNotificationName: sCTFWhitelistAdditionMade object: self];
}

Expand All @@ -188,7 +191,7 @@ - (void) _removeHostFromWhitelist

if(foundIndex != NSNotFound) {
[siteInfo removeObjectAtIndex: foundIndex];
[[NSUserDefaults standardUserDefaults] setObject: siteInfo forKey: sHostSiteInfoDefaultsKey];
[[CTFUserDefaultsController standardUserDefaults] setObject: siteInfo forKey: sHostSiteInfoDefaultsKey];
}
}

Expand Down
7 changes: 5 additions & 2 deletions Plugin/CTFsIFRSupport.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ of this software and associated documentation files (the "Software"), to deal

#import "CTFsIFRSupport.h"

#import "CTFUserDefaultsController.h"
#import "CTFPreferencesDictionary.h"

typedef enum {
CTFSifrModeDoNothing = 0,
CTFSifrModeAutoLoadSifr = 1,
Expand Down Expand Up @@ -61,7 +64,7 @@ - (NSUInteger) _sifrVersionInstalled

- (BOOL) _shouldDeSIFR
{
if ([[NSUserDefaults standardUserDefaults] integerForKey: sSifrModeDefaultsKey] == CTFSifrModeDeSifr) {
if ([[CTFUserDefaultsController standardUserDefaults] integerForKey: sSifrModeDefaultsKey] == CTFSifrModeDeSifr) {
_sifrVersion = [self _sifrVersionInstalled];

if( _sifrVersion != 0 )
Expand All @@ -73,7 +76,7 @@ - (BOOL) _shouldDeSIFR

- (BOOL) _shouldAutoLoadSIFR
{
return [[NSUserDefaults standardUserDefaults] integerForKey: sSifrModeDefaultsKey] == CTFSifrModeAutoLoadSifr;
return [[CTFUserDefaultsController standardUserDefaults] integerForKey: sSifrModeDefaultsKey] == CTFSifrModeAutoLoadSifr;
}

- (void) _disableSIFR
Expand Down
Loading

0 comments on commit 39a3ae3

Please sign in to comment.