-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathScanResultsWC.m
173 lines (148 loc) · 4.53 KB
/
ScanResultsWC.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
//
// ScanResultsWC.m
// APIScanner
//
// Created by Andrew Schenk on 9/7/10.
// Copyright 2010 Chimp Studios. All rights reserved.
//
#import "ScanResultsWC.h"
#import "ServerSyncer.h"
#import "SBJSON.h"
#import "Pweep.h"
#import "Constants.h"
@implementation ScanResultsWC
@synthesize flagged;
-(void)windowDidLoad
{
if ([flagged count] < 1) {
[scroll removeFromSuperview];
[table removeFromSuperview];
[checkBtn removeFromSuperview];
[submitBtn removeFromSuperview];
}
NSMutableArray *arr = [[NSMutableArray alloc] initWithCapacity:[flagged count]];
for(id thing in flagged) {
NSNumber *boolVal = [NSNumber numberWithBool:NO];
[arr addObject:boolVal];
}
feedback = [[NSMutableArray alloc] initWithArray:arr];
[feedback retain];
[arr release];
}
-(void)windowWillClose:(id)sender
{
//[self release];
}
#pragma mark NSTableView Data Source
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
{
return [flagged count];
}
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(NSInteger)rowIndex
{
Pweep* pweep = [[flagged objectAtIndex:rowIndex] objectForKey:@"Pweep"];
if ([aTableColumn.identifier isEqualToString:@"Signature"]) {
NSTextFieldCell *cell = [[[NSTextFieldCell alloc] initTextCell:pweep.Signature] autorelease];
return cell;
}
if ([aTableColumn.identifier isEqualToString:@"Likelihood"]) {
int percentage = [pweep.Level intValue];
NSTextFieldCell *cell = [[[NSTextFieldCell alloc] initTextCell:[NSString stringWithFormat:@"%i%@", percentage, @"%"]] autorelease];
if (percentage > 70) {
[cell setTextColor:[NSColor greenColor]];
} else if (percentage >= 50 && percentage <= 70) {
[cell setTextColor:[NSColor brownColor]];
} else if (percentage >= 25 && percentage < 50) {
[cell setTextColor:[NSColor orangeColor]];
} else {
[cell setTextColor:[NSColor redColor]];
}
[cell setAlignment:NSCenterTextAlignment];
return cell;
}
if ([aTableColumn.identifier isEqualToString:@"CName"]) {
NSString *classNme = [[flagged objectAtIndex:rowIndex] objectForKey:@"Class"];
NSTextFieldCell *cell = [[[NSTextFieldCell alloc] initTextCell:classNme] autorelease];
return cell;
}
if ([aTableColumn.identifier isEqualToString:@"SDK"]) {
NSTextFieldCell *cell = [[[NSTextFieldCell alloc] initTextCell:pweep.SDK_Version] autorelease];
return cell;
}
if ([aTableColumn.identifier isEqualToString:@"Appropriate"]) {
BOOL value = [[feedback objectAtIndex:rowIndex] boolValue];
return [NSNumber numberWithInteger:(value ? NSOnState : NSOffState)];
}
return nil;
}
- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject
forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{
if (feedback) {
if ([feedback count] > rowIndex && rowIndex >= 0) {
NSNumber *boolVal = [feedback objectAtIndex:rowIndex];
[feedback replaceObjectAtIndex:rowIndex withObject:[NSNumber numberWithBool:![boolVal boolValue]]];
}
}
}
- (BOOL)tableView:(NSTableView *)aTableView shouldSelectTableColumn:(NSTableColumn *)aTableColumn
{
if ([aTableColumn.identifier isEqualToString:@"Appropriate"]) {
return NO;
}
return YES;
}
#pragma mark -
#pragma mark Feedback
-(IBAction)checkAll:(id)sender
{
if ([[checkBtn title] isEqualToString:@"Check All"]) {
for(int i=0; i< [feedback count]; i++) {
[feedback replaceObjectAtIndex:i withObject:[NSNumber numberWithBool:YES]];
}
[checkBtn setTitle:@"Uncheck All"];
} else {
for(int i=0; i< [feedback count]; i++) {
[feedback replaceObjectAtIndex:i withObject:[NSNumber numberWithBool:NO]];
}
[checkBtn setTitle:@"Check All"];
}
[table reloadData];
}
-(IBAction)submitFeedback:(id)sender
{
// open source version does not include any community feedback features.
}
#pragma mark -
#pragma mark NSURLConnection
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
[feedbackConnection release];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
if (!connData) {
connData = [[NSMutableData alloc] initWithCapacity:0];
[connData retain];
}
[connData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *sdata = [[NSString alloc] initWithData:connData encoding:NSUTF8StringEncoding];
//NSLog(@"sdata -> %@", sdata);
[sdata release];
[connData release];
[feedbackConnection release];
ServerSyncer *syncer = [[ServerSyncer alloc] init];
[syncer startSync];
[syncer release];
}
-(void)dealloc
{
[flagged release];
[feedback release];
[super dealloc];
}
@end