| 1 |
masaki |
205 |
// |
| 2 |
|
|
// XspfQTPreference.m |
| 3 |
|
|
// XspfQT |
| 4 |
|
|
// |
| 5 |
|
|
// Created by Hori,Masaki on 09/03/29. |
| 6 |
|
|
// Copyright 2009 masakih. All rights reserved. |
| 7 |
|
|
// |
| 8 |
|
|
|
| 9 |
|
|
#import "XspfQTPreference.h" |
| 10 |
|
|
|
| 11 |
|
|
XspfQTPreference *XspfQTPref = nil; |
| 12 |
|
|
|
| 13 |
|
|
static const CGFloat beginingPreloadPercentPreset = 0.85; |
| 14 |
|
|
|
| 15 |
masaki |
207 |
static NSString *BeginningPreloadPercentKey = @"beginingPreloadPercent"; |
| 16 |
|
|
static NSString *EnablePreloadingKey = @"EnablePreloading"; |
| 17 |
|
|
|
| 18 |
masaki |
205 |
@implementation XspfQTPreference |
| 19 |
|
|
static XspfQTPreference *sharedInstance = nil; |
| 20 |
|
|
|
| 21 |
|
|
+ (XspfQTPreference *)sharedInstance |
| 22 |
|
|
{ |
| 23 |
|
|
@synchronized(self) { |
| 24 |
|
|
if (sharedInstance == nil) { |
| 25 |
|
|
[[self alloc] init]; // assignment not done here |
| 26 |
|
|
} |
| 27 |
|
|
} |
| 28 |
|
|
return sharedInstance; |
| 29 |
|
|
} |
| 30 |
|
|
|
| 31 |
|
|
+ (id)allocWithZone:(NSZone *)zone |
| 32 |
|
|
{ |
| 33 |
|
|
@synchronized(self) { |
| 34 |
|
|
if (sharedInstance == nil) { |
| 35 |
|
|
sharedInstance = [super allocWithZone:zone]; |
| 36 |
|
|
XspfQTPref = sharedInstance; |
| 37 |
|
|
return sharedInstance; // assignment and return on first allocation |
| 38 |
|
|
} |
| 39 |
|
|
} |
| 40 |
|
|
return nil; //on subsequent allocation attempts return nil |
| 41 |
|
|
} |
| 42 |
|
|
|
| 43 |
|
|
- (id)copyWithZone:(NSZone *)zone |
| 44 |
|
|
{ |
| 45 |
|
|
return self; |
| 46 |
|
|
} |
| 47 |
|
|
|
| 48 |
|
|
- (id)retain |
| 49 |
|
|
{ |
| 50 |
|
|
return self; |
| 51 |
|
|
} |
| 52 |
|
|
|
| 53 |
|
|
- (unsigned)retainCount |
| 54 |
|
|
{ |
| 55 |
|
|
return UINT_MAX; //denotes an object that cannot be released |
| 56 |
|
|
} |
| 57 |
|
|
|
| 58 |
|
|
- (void)release |
| 59 |
|
|
{ |
| 60 |
|
|
//do nothing |
| 61 |
|
|
} |
| 62 |
|
|
|
| 63 |
|
|
- (id)autorelease |
| 64 |
|
|
{ |
| 65 |
|
|
return self; |
| 66 |
|
|
} |
| 67 |
|
|
|
| 68 |
|
|
#pragma mark- |
| 69 |
|
|
- (id)init |
| 70 |
|
|
{ |
| 71 |
|
|
self = [super init]; |
| 72 |
|
|
|
| 73 |
|
|
id ud = [NSUserDefaults standardUserDefaults]; |
| 74 |
masaki |
207 |
if([ud doubleForKey:BeginningPreloadPercentKey] == 0.0) { |
| 75 |
|
|
[ud setDouble:beginingPreloadPercentPreset forKey:BeginningPreloadPercentKey]; |
| 76 |
masaki |
205 |
} |
| 77 |
|
|
|
| 78 |
|
|
id dController = [NSUserDefaultsController sharedUserDefaultsController]; |
| 79 |
masaki |
207 |
[self bind:BeginningPreloadPercentKey |
| 80 |
masaki |
205 |
toObject:dController |
| 81 |
|
|
withKeyPath:@"values.beginingPreloadPercent" |
| 82 |
|
|
options:nil]; |
| 83 |
|
|
|
| 84 |
|
|
return self; |
| 85 |
|
|
} |
| 86 |
|
|
- (void)dealloc |
| 87 |
|
|
{ |
| 88 |
masaki |
207 |
[self unbind:BeginningPreloadPercentKey]; |
| 89 |
masaki |
205 |
|
| 90 |
|
|
[super dealloc]; |
| 91 |
|
|
} |
| 92 |
|
|
|
| 93 |
|
|
- (BOOL)preloadingEnabled |
| 94 |
|
|
{ |
| 95 |
masaki |
207 |
return [[NSUserDefaults standardUserDefaults] boolForKey:EnablePreloadingKey]; |
| 96 |
masaki |
205 |
} |
| 97 |
|
|
- (CGFloat)beginingPreloadPercent |
| 98 |
|
|
{ |
| 99 |
|
|
if(beginingPreloadPercent == 0.0) { |
| 100 |
|
|
return beginingPreloadPercentPreset; |
| 101 |
|
|
} |
| 102 |
|
|
|
| 103 |
|
|
return beginingPreloadPercent; |
| 104 |
|
|
} |
| 105 |
|
|
- (void)setBeginingPreloadPercent:(CGFloat)newPercent |
| 106 |
|
|
{ |
| 107 |
|
|
if(newPercent <= 0 || newPercent >= 1) return; |
| 108 |
|
|
beginingPreloadPercent = newPercent; |
| 109 |
|
|
// NSLog(@"set percent %f.", newPercent); |
| 110 |
|
|
} |
| 111 |
|
|
@end |