Subversion Repositories TruePreview

[/] [trunk/] [Source/] [TruePreviewPreferencesModule.m] - Blame information for rev 51

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1 jhriggs
/*
2 42 jhriggs
 * Copyright (c) 2009-2011, Jim Riggs, Christian Serving, L.L.C.
3 1 jhriggs
 * All rights reserved.
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 47 jhriggs
  TRUEPREVIEW_LOG();
40
 
41 1 jhriggs
  return @"TruePreviewPreferencesPanel";
42
}
43
 
44
- (void)willBeDisplayed {
45 47 jhriggs
  TRUEPREVIEW_LOG();
46
 
47 1 jhriggs
  [super willBeDisplayed];
48 17 jhriggs
 
49 1 jhriggs
  // build the list of accounts
50
  NSDictionary* theAccountDict = [[NSUserDefaults standardUserDefaults] objectForKey:@"TruePreviewAccountSettings"];
51
  NSMutableArray* theAccounts = [NSMutableArray array];
52 17 jhriggs
  NSEnumerator* theEnum = [[[NSClassFromString(@"MailAccount") remoteAccounts] valueForKey:@"displayName"] objectEnumerator];
53 1 jhriggs
  NSString* theDisplayName = nil;
54 17 jhriggs
 
55 1 jhriggs
  while (theDisplayName = [theEnum nextObject]) {
56 17 jhriggs
    NSMutableDictionary* theAccount = [NSMutableDictionary dictionaryWithObjectsAndKeys:
57
      theDisplayName, @"displayName",
58
      [NSNumber numberWithInt:TRUEPREVIEW_DELAY_DEFAULT], @"delay",
59 23 jhriggs
      [NSNumber numberWithInt:TRUEPREVIEW_DELAY_DEFAULT], @"reply",
60
      [NSNumber numberWithInt:TRUEPREVIEW_DELAY_DEFAULT], @"forward",
61 17 jhriggs
      [NSNumber numberWithInt:TRUEPREVIEW_DELAY_DEFAULT], @"window",
62
      [NSNumber numberWithInt:TRUEPREVIEW_DELAY_DEFAULT], @"scroll",
63
      nil
64 1 jhriggs
    ];
65 17 jhriggs
 
66
    [theAccount addEntriesFromDictionary:[theAccountDict objectForKey:theDisplayName]];
67
    [theAccounts addObject:theAccount];
68 1 jhriggs
  }
69
 
70
  // watch the array for changes to save the user defaults
71
  [theAccounts
72
    addObserver:self
73
    toObjectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [theAccounts count])]
74 17 jhriggs
    forKeyPath:@"delay"
75 1 jhriggs
    options:0
76
    context:theAccounts
77
  ];
78
  [theAccounts
79
    addObserver:self
80
    toObjectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [theAccounts count])]
81 23 jhriggs
    forKeyPath:@"reply"
82
    options:0
83
    context:theAccounts
84
  ];
85
  [theAccounts
86
    addObserver:self
87
    toObjectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [theAccounts count])]
88
    forKeyPath:@"forward"
89
    options:0
90
    context:theAccounts
91
  ];
92
  [theAccounts
93
    addObserver:self
94
    toObjectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [theAccounts count])]
95 17 jhriggs
    forKeyPath:@"window"
96 1 jhriggs
    options:0
97
    context:theAccounts
98
  ];
99 17 jhriggs
  [theAccounts
100
    addObserver:self
101
    toObjectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [theAccounts count])]
102
    forKeyPath:@"scroll"
103
    options:0
104
    context:theAccounts
105
  ];
106
 
107 1 jhriggs
  [fldAccountArrayController setContent:theAccounts];
108
}
109
 
110
#pragma mark NSKeyValueObserving instance methods
111
 
112
- (void)observeValueForKeyPath:(NSString*)inPath
113
    ofObject:(id)inObject
114
    change:(NSDictionary*)inChange
115
    context:(void*)inContext {
116 47 jhriggs
  TRUEPREVIEW_LOG(@"%@, %@, %@, %p", inPath, inObject, inChange, inContext);
117
 
118 1 jhriggs
  NSMutableDictionary* theAccountDict = [NSMutableDictionary dictionary];
119
 
120
  // build the account settings dictionary to save in the user defaults
121 23 jhriggs
  for (NSDictionary* theAccount in (NSArray*)inContext) {
122 1 jhriggs
    [theAccountDict setObject:theAccount forKey:[theAccount objectForKey:@"displayName"]];
123
  }
124
 
125
  [[NSUserDefaults standardUserDefaults] setObject:theAccountDict forKey:@"TruePreviewAccountSettings"];
126 17 jhriggs
  [[NSUserDefaults standardUserDefaults] synchronize];
127 1 jhriggs
}
128
 
129 47 jhriggs
#pragma mark Instance methods
130
 
131
- (NSString*)truePreviewVersion {
132
  return [[[NSBundle bundleForClass:[TruePreview class]] infoDictionary] objectForKey:@"CFBundleVersion"];
133
}
134
 
135 1 jhriggs
@end