| 1 |
1 |
jhriggs |
/*
|
| 2 |
|
|
* Copyright (c) 2009, Jim Riggs, Christian Serving, L.L.C.
|
| 3 |
|
|
|
| 4 |
|
|
*
|
| 5 |
|
|
* Redistribution and use in source and binary forms, with or without
|
| 6 |
|
|
* modification, are permitted provided that the following conditions are
|
| 7 |
|
|
* met:
|
| 8 |
|
|
* * Redistributions of source code must retain the above copyright
|
| 9 |
|
|
* notice, this list of conditions and the following disclaimer.
|
| 10 |
|
|
* * Redistributions in binary form must reproduce the above
|
| 11 |
|
|
* copyright notice, this list of conditions and the following
|
| 12 |
|
|
* disclaimer in the documentation and/or other materials provided
|
| 13 |
|
|
* with the distribution.
|
| 14 |
|
|
* * Neither the name of Christian Serving, L.L.C. nor the names of
|
| 15 |
|
|
* its contributors may be used to endorse or promote products
|
| 16 |
|
|
* derived from this software without specific prior written
|
| 17 |
|
|
* permission.
|
| 18 |
|
|
*
|
| 19 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 20 |
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 21 |
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 22 |
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 23 |
|
|
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 24 |
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 25 |
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 26 |
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
|
| 27 |
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 28 |
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 29 |
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 30 |
|
|
*/
|
| 31 |
|
|
|
| 32 |
|
|
#import "TruePreviewPreferencesModule.h"
|
| 33 |
|
|
|
| 34 |
|
|
@implementation TruePreviewPreferencesModule
|
| 35 |
|
|
|
| 36 |
|
|
#pragma mark NSPreferencesModule instance methods
|
| 37 |
|
|
|
| 38 |
|
|
- (NSString*)preferencesNibName {
|
| 39 |
|
|
return @"TruePreviewPreferencesPanel";
|
| 40 |
|
|
}
|
| 41 |
|
|
|
| 42 |
|
|
- (void)willBeDisplayed {
|
| 43 |
|
|
[super willBeDisplayed];
|
| 44 |
17 |
jhriggs |
|
| 45 |
1 |
jhriggs |
// build the list of accounts
|
| 46 |
|
|
NSDictionary* theAccountDict = [[NSUserDefaults standardUserDefaults] objectForKey:@"TruePreviewAccountSettings"];
|
| 47 |
|
|
NSMutableArray* theAccounts = [NSMutableArray array];
|
| 48 |
17 |
jhriggs |
NSEnumerator* theEnum = [[[NSClassFromString(@"MailAccount") remoteAccounts] valueForKey:@"displayName"] objectEnumerator];
|
| 49 |
1 |
jhriggs |
NSString* theDisplayName = nil;
|
| 50 |
17 |
jhriggs |
|
| 51 |
1 |
jhriggs |
while (theDisplayName = [theEnum nextObject]) {
|
| 52 |
17 |
jhriggs |
NSMutableDictionary* theAccount = [NSMutableDictionary dictionaryWithObjectsAndKeys:
|
| 53 |
|
|
theDisplayName, @"displayName",
|
| 54 |
|
|
[NSNumber numberWithInt:TRUEPREVIEW_DELAY_DEFAULT], @"delay",
|
| 55 |
23 |
jhriggs |
[NSNumber numberWithInt:TRUEPREVIEW_DELAY_DEFAULT], @"reply",
|
| 56 |
|
|
[NSNumber numberWithInt:TRUEPREVIEW_DELAY_DEFAULT], @"forward",
|
| 57 |
17 |
jhriggs |
[NSNumber numberWithInt:TRUEPREVIEW_DELAY_DEFAULT], @"window",
|
| 58 |
|
|
[NSNumber numberWithInt:TRUEPREVIEW_DELAY_DEFAULT], @"scroll",
|
| 59 |
|
|
nil
|
| 60 |
1 |
jhriggs |
];
|
| 61 |
17 |
jhriggs |
|
| 62 |
|
|
[theAccount addEntriesFromDictionary:[theAccountDict objectForKey:theDisplayName]];
|
| 63 |
|
|
[theAccounts addObject:theAccount];
|
| 64 |
1 |
jhriggs |
}
|
| 65 |
|
|
|
| 66 |
|
|
// watch the array for changes to save the user defaults
|
| 67 |
|
|
[theAccounts
|
| 68 |
|
|
addObserver:self
|
| 69 |
|
|
toObjectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [theAccounts count])]
|
| 70 |
17 |
jhriggs |
forKeyPath:@"delay"
|
| 71 |
1 |
jhriggs |
options:0
|
| 72 |
|
|
context:theAccounts
|
| 73 |
|
|
];
|
| 74 |
|
|
[theAccounts
|
| 75 |
|
|
addObserver:self
|
| 76 |
|
|
toObjectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [theAccounts count])]
|
| 77 |
23 |
jhriggs |
forKeyPath:@"reply"
|
| 78 |
|
|
options:0
|
| 79 |
|
|
context:theAccounts
|
| 80 |
|
|
];
|
| 81 |
|
|
[theAccounts
|
| 82 |
|
|
addObserver:self
|
| 83 |
|
|
toObjectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [theAccounts count])]
|
| 84 |
|
|
forKeyPath:@"forward"
|
| 85 |
|
|
options:0
|
| 86 |
|
|
context:theAccounts
|
| 87 |
|
|
];
|
| 88 |
|
|
[theAccounts
|
| 89 |
|
|
addObserver:self
|
| 90 |
|
|
toObjectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [theAccounts count])]
|
| 91 |
17 |
jhriggs |
forKeyPath:@"window"
|
| 92 |
1 |
jhriggs |
options:0
|
| 93 |
|
|
context:theAccounts
|
| 94 |
|
|
];
|
| 95 |
17 |
jhriggs |
[theAccounts
|
| 96 |
|
|
addObserver:self
|
| 97 |
|
|
toObjectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [theAccounts count])]
|
| 98 |
|
|
forKeyPath:@"scroll"
|
| 99 |
|
|
options:0
|
| 100 |
|
|
context:theAccounts
|
| 101 |
|
|
];
|
| 102 |
|
|
|
| 103 |
1 |
jhriggs |
[fldAccountArrayController setContent:theAccounts];
|
| 104 |
|
|
}
|
| 105 |
|
|
|
| 106 |
|
|
#pragma mark NSKeyValueObserving instance methods
|
| 107 |
|
|
|
| 108 |
|
|
- (void)observeValueForKeyPath:(NSString*)inPath
|
| 109 |
|
|
ofObject:(id)inObject
|
| 110 |
|
|
change:(NSDictionary*)inChange
|
| 111 |
|
|
context:(void*)inContext {
|
| 112 |
|
|
NSMutableDictionary* theAccountDict = [NSMutableDictionary dictionary];
|
| 113 |
|
|
|
| 114 |
|
|
// build the account settings dictionary to save in the user defaults
|
| 115 |
23 |
jhriggs |
for (NSDictionary* theAccount in (NSArray*)inContext) {
|
| 116 |
1 |
jhriggs |
[theAccountDict setObject:theAccount forKey:[theAccount objectForKey:@"displayName"]];
|
| 117 |
|
|
}
|
| 118 |
|
|
|
| 119 |
|
|
[[NSUserDefaults standardUserDefaults] setObject:theAccountDict forKey:@"TruePreviewAccountSettings"];
|
| 120 |
17 |
jhriggs |
[[NSUserDefaults standardUserDefaults] synchronize];
|
| 121 |
1 |
jhriggs |
}
|
| 122 |
|
|
|
| 123 |
|
|
@end
|