forked from jerrykrinock/ClassesObjC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSSContactInfoReviewer.m
259 lines (218 loc) · 8.44 KB
/
SSContactInfoReviewer.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#import "SSContactInfoReviewer.h"
#import <AddressBook/ABAddressBook.h>
#import <AddressBook/ABMultiValue.h>
#import "SSApp/SSUtils.h"
#import "SSApp/SSUtilityCategories.h"
#import "SSYLocalize/NSString+Localize.h"
extern NSString* gCFBundleVersion ;
NSString* TransmittedKeyForKey(NSString* key) {
NSString* txKey ;
if ([key isEqualToString:@"failed"]) {
txKey = @"ProblemWith" ;
}
else {
txKey = [key capitalizedString] ;
}
return txKey ;
}
@implementation SSContactInfoReviewer
SSAOm( NSString*, displayText, setDisplayText)
SSAOm( NSDictionary*, miscellaneousInfo, setMiscellaneousInfo)
SSAOm( NSArray*, apps, setApps)
SSAOm( NSArray*, appVersions, setAppVersions)
SSAOm( NSString*, runningVersion, setRunningVersion)
- (id)initWithDisplayText:(NSString*)displayText
appsToReportVersion:(NSArray*)apps
miscellaneousInfo:(NSDictionary*)miscellaneousInfo {
SSLog(5, "Prolog SSContactInfoReviewer init") ;
self = [super initWithWindowNibName:@"SSContactInfoWindow"];
if (self != 0) // Make sure it worked!
{
[self setDisplayText:displayText] ;
[self setApps:apps] ;
[self setMiscellaneousInfo:miscellaneousInfo] ;
}
SSLog(5, "Epilog SSContactInfoReviewer init") ;
return self;
}
- (void)dealloc {
[self setDisplayText:nil] ;
[self setApps:nil] ;
[self setAppVersions:nil] ;
[self setRunningVersion:nil] ;
[self setMiscellaneousInfo:nil] ;
[super dealloc] ;
}
- (void)awakeFromNib
{
SSLog(5, "Prolog SSContactInfoReviewer awakeFromNib") ;
ABPerson* me = [[ABAddressBook sharedAddressBook] me] ;
ABMultiValue *emails = [me valueForProperty:kABEmailProperty];
NSString* email = [emails valueAtIndex:[emails indexForIdentifier:[emails primaryIdentifier]]];
NSString* firstName = [me valueForProperty:kABFirstNameProperty];
NSString* lastName = [me valueForProperty:kABLastNameProperty];
if (!firstName)
firstName = @"" ;
if (!lastName)
lastName = @"" ;
if (!email)
email = @"" ;
/* More info (tested but not used)
ABMultiValue *addresses = [me valueForProperty:kABAddressProperty] ;
NSDictionary* address = [addresses valueAtIndex:[addresses indexForIdentifier:[addresses primaryIdentifier]]];
NSString* street = [address objectForKey:kABAddressStreetKey] ;
NSString* city = [address objectForKey:kABAddressCityKey] ;
NSString* state = [address objectForKey:kABAddressStateKey] ;
NSString* zip = [address objectForKey:kABAddressZIPKey] ;
NSString* country = [address objectForKey:kABAddressCountryKey] ;
NSString* countryCode = [address objectForKey:kABAddressCountryCodeKey] ;
ABMultiValue *phones = [me valueForProperty:kABPhoneProperty] ;
NSString* phone = [phones valueAtIndex:[phones indexForIdentifier:[phones primaryIdentifier]]] ;
*/
[[self window] setTitle:[NSString localize:@"report"]] ;
[buttonOK setTitle:[NSString localize:@"ok"]] ;
[buttonCancel setTitle:[NSString localize:@"cancel"]] ;
[labelIntro setStringValue:[self displayText]] ;
[labelEmail setStringValue:[NSString localize:@"email"]] ;
[labelName setStringValue:[[NSString localize:@"name"] capitalizedString]] ;
[labelAnythingElse setStringValue:[NSString localize:@"anythingElse"]] ;
[textEmail setStringValue:email] ;
[textFirstName setStringValue:firstName] ;
[textLastName setStringValue:lastName] ;
// Fill contents of textUneditable
NSMutableString* uneditableText = [[NSMutableString alloc] init] ;
NSString* aLineOfText ;
// 1. Get Running Version (also, set ivar runningVersion)
NSBundle* mainBundle = [NSBundle mainBundle] ;
NSString* runningVersion = [NSString stringWithFormat:@"%@ %@ (%@)",
[mainBundle objectForInfoDictionaryKey:@"CFBundleName"], // CFBundleName may be localized
[mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"],
[mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"]] ;
[uneditableText appendFormat:@"Running: %@\n", runningVersion] ;
[self setRunningVersion:runningVersion] ;
// 2. Installed app versions (also, set ivar appVersions)
NSMutableArray* appVersions = [[NSMutableArray alloc] init] ;
NSEnumerator* e = [[self apps] objectEnumerator] ;
NSString* app ;
while ((app = [e nextObject])) {
NSString* appVersion = SSVersionStringForAppNamed(app) ;
NSString* lineItem = [NSString localizeFormat:@"version%0%1",
app,
appVersion] ;
[uneditableText appendString:lineItem] ;
[appVersions addObject:appVersion] ;
[uneditableText appendString:@"\n"] ;
}
[self setAppVersions:appVersions] ;
[appVersions release] ;
// 3. add appKit version
aLineOfText = [NSString localizeFormat:@"version%0%1",
@"@f",
@"Cocoa AppKit",
[NSString stringWithFormat:@"%f", NSAppKitVersionNumber]] ;
[uneditableText appendString:aLineOfText] ;
[uneditableText appendString:@"\n"] ;
// 4. add date
aLineOfText = [[NSString alloc] initWithFormat:@"%@: %@\n",
[NSString localize:@"date"],
[NSDate date] ] ;
[uneditableText appendString:aLineOfText] ;
[aLineOfText release] ;
// 5. add language
aLineOfText = [[NSString alloc] initWithFormat:@"%@: %@\n",
[NSString localize:@"languageCode"],
[NSString languageCodeLoaded]] ;
[uneditableText appendString:aLineOfText] ;
[aLineOfText release] ;
// 6. add miscellaneous info
[uneditableText appendString:[[self miscellaneousInfo] formatAsList]] ;
// 7. set to UI and clean up
[textUneditable setStringValue:uneditableText] ;
[uneditableText release] ;
[textAnythingElse setFont:[NSFont systemFontOfSize:12.0]] ;
// above uses the setFont: method of NSText, of which NSTextView is a subclass
SSLog(5, "Epilog SSContactInfoReviewer awakeFromNib") ;
}
- (NSDictionary*)info
{
SSLog(5, "Prolog SSContactInfoReviewer info") ;
[NSApp runModalForWindow:[self window]] ;
// The above causes this thread to block.
// User corrects the fields in the windows
// and pushes a button which sets the value of sendIt
// Now, send the corrected info if user wanted it send
NSMutableDictionary* info ;
if (sendIt)
{
// Build the info dictionary
NSDictionary* someItems ;
// 1. Start with the values from the editable fields in the window
info = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
[textLastName stringValue], SSSafeString(@"LastName"),
[textFirstName stringValue],SSSafeString(@"FirstName"),
[textEmail stringValue], SSSafeString(@"Email"),
[[textAnythingElse textStorage] string], @"AnythingElse",
nil] ;
// 2. Add the miscellaneousInfo
NSArray* miscellaneousKeys = [[self miscellaneousInfo] allKeys] ;
NSArray* miscellaneousValues = [[self miscellaneousInfo] allValues] ;
// Translate keys to transmittedKeys
NSEnumerator * e = [miscellaneousKeys objectEnumerator] ;
NSMutableArray* miscellaneousTransmittedKeys = [[NSMutableArray alloc] init] ;
NSString* key ;
while ((key = [e nextObject])) {
[miscellaneousTransmittedKeys addObject:TransmittedKeyForKey(key)] ;
}
someItems =
[[NSDictionary alloc] initWithObjects:miscellaneousValues
forKeys:miscellaneousTransmittedKeys] ;
[miscellaneousTransmittedKeys release] ;
[info addEntriesFromDictionary:someItems] ;
[someItems release] ;
// 3. Add the language code and AppKitVersion
someItems = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSString languageCodeLoaded], @"Language",
[NSString stringWithFormat:@"%f", NSAppKitVersionNumber], @"AppKit",
nil] ;
[info addEntriesFromDictionary:someItems] ;
[someItems release] ;
// 4. Add the app versions
someItems = [[NSDictionary alloc] initWithObjects:[self appVersions] forKeys:[self apps]] ;
[info addEntriesFromDictionary:someItems] ;
[someItems release] ;
// 5. Add the Running Version
[info setObject:[self runningVersion]
forKey:@"RunningVersion"] ;
}
else
info = nil ;
NSDictionary* output = [info copy] ;
[info release] ;
SSLog(5, "Epilog SSContactInfoReviewer info returning:\n%@", output) ;
return [output autorelease] ;
}
- (IBAction)ok:(id)sender
{
sendIt = YES ;
[NSApp stopModal] ;
[[self window] close] ;
}
- (IBAction)cancel:(id)sender
{
sendIt = NO ;
[NSApp stopModal] ;
[[self window] close] ;
}
+ (NSDictionary*)infoWithDisplayText:(NSString*)displayText
appsToReportVersion:(NSArray*)apps
miscellaneousInfo:(NSDictionary*)miscellaneousInfo {
SSContactInfoReviewer* instance = [[SSContactInfoReviewer alloc]
initWithDisplayText:displayText
appsToReportVersion:(NSArray*)apps
miscellaneousInfo:(NSDictionary*)miscellaneousInfo ] ;
// Do search
NSDictionary* info = [instance info] ;
[instance release] ;
return info ;
}
@end