This repository was archived by the owner on Mar 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAISFPreferences.m
More file actions
201 lines (152 loc) · 5.5 KB
/
Copy pathAISFPreferences.m
File metadata and controls
201 lines (152 loc) · 5.5 KB
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
/*
* Adium SpamFilter Plugin - Blacklist annoying messages in Adium
* Copyright (C) 2010 Thijs Alkemade
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program; if not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#import "AISFPreferences.h"
static AISFPreferences *sharedInstance = nil;
@implementation AISFPreferences
@synthesize shouldIgnoreAuthorizationRequests;
+ (AISFPreferences *)sharedInstance
{
@synchronized(self) {
if (!sharedInstance) {
sharedInstance = [[self alloc] init];
}
}
return sharedInstance;
}
- (AIPreferenceCategory)category
{
return AIPref_Advanced;
}
- (NSString *)label
{
return @"Spam Filter";
}
- (NSString *)nibName
{
return @"SFPreferences";
}
- (NSImage *)image
{
return [NSImage imageNamed:@"msg-block-contact"];
}
- (IBAction)save:(id)sender
{
AILogWithSignature(@"Saving: %@", self.shouldIgnoreAuthorizationRequests);
NSMutableArray *blacklistCopy = [[blacklist mutableCopy] autorelease];
// Never save a blank term.
[blacklistCopy removeObject:@""];
[adium.preferenceController setPreference:blacklistCopy
forKey:KEY_SF_FILTERS
group:PREF_GROUP_SPAMFILTER];
[adium.preferenceController setPreference:self.shouldIgnoreAuthorizationRequests
forKey:KEY_SF_SHOULD_BLOCK_AUTH
group:PREF_GROUP_SPAMFILTER];
[tableView reloadData];
}
- (IBAction)add:(id)sender
{
[currentlyEditing release]; currentlyEditing = nil;
[addField setStringValue:@""];
[addField becomeFirstResponder];
[NSApp beginSheet:addSheet modalForWindow:[view window]
modalDelegate:self didEndSelector:NULL
contextInfo:NULL];
}
- (IBAction)cancel:(id)sender
{
[addSheet orderOut:nil];
[NSApp endSheet:addSheet];
}
- (IBAction)accept:(id)sender
{
AILogWithSignature(@"Adding %@ to blacklist", [addField stringValue]);
if (!currentlyEditing) {
NSMutableDictionary *newWord = [NSMutableDictionary dictionaryWithObjectsAndKeys:[addField stringValue], KEY_SF_PHRASE,
[NSNumber numberWithBool:([phraseIsCaseSensitive state] == NSOnState)], KEY_SF_CASE_SENSITIVE,
[NSNumber numberWithBool:([phraseIsRegularExpression state] == NSOnState)], KEY_SF_REGEX, nil];
[blacklist addObject:newWord];
} else {
[currentlyEditing setValue:[addField stringValue] forKey:KEY_SF_PHRASE];
[currentlyEditing setValue:[NSNumber numberWithBool:([phraseIsCaseSensitive state] == NSOnState)] forKey:KEY_SF_CASE_SENSITIVE];
[currentlyEditing setValue:[NSNumber numberWithBool:([phraseIsRegularExpression state] == NSOnState)] forKey:KEY_SF_REGEX];
}
[self save:nil];
[addSheet orderOut:nil];
[NSApp endSheet:addSheet];
[tableView reloadData];
}
/*!
* @brief Remove the selected rows
*/
- (IBAction)remove:(id)sender
{
NSIndexSet *indexes = [tableView selectedRowIndexes];
[blacklist removeObjectsAtIndexes:indexes];
[self save:nil];
[tableView reloadData];
[tableView deselectAll:nil];
}
- (NSView *)view
{
return [[super view] retain];
}
/*!
* @brief The view loaded
*/
- (void)viewDidLoad
{
[label_explanation setStringValue:@"Messages are hidden when they match one of the following phrases. If case sensitive is enabled, \"sPaM\" will not match \"spam\"."];
blacklist = [[NSMutableArray alloc] initWithArray:[adium.preferenceController preferenceForKey:KEY_SF_FILTERS group:PREF_GROUP_SPAMFILTER]];
self.shouldIgnoreAuthorizationRequests = [adium.preferenceController preferenceForKey:KEY_SF_SHOULD_BLOCK_AUTH group:PREF_GROUP_SPAMFILTER];
[super viewDidLoad];
}
- (void)viewWillClose
{
[blacklist release]; blacklist = nil;
[[super view] release];
[super viewWillClose];
}
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
return [[blacklist objectAtIndex:row] valueForKey:[tableColumn identifier]];
}
- (void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
NSMutableDictionary *word = [[blacklist objectAtIndex:row] mutableCopy];
[word setValue:[object copy] forKey:[tableColumn identifier]];
[blacklist replaceObjectAtIndex:row withObject:word];
[self save:nil];
}
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
return [blacklist count];
}
- (void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
if ([[tableColumn identifier] isEqualToString:KEY_SF_CASE_SENSITIVE] || [[tableColumn identifier] isEqualToString:KEY_SF_REGEX]) {
[cell setTitle:@""];
}
}
- (void)editObject:(NSDictionary *)inObject
{
currentlyEditing = [inObject retain];
[addField setStringValue:[inObject valueForKey:KEY_SF_PHRASE]];
[phraseIsCaseSensitive setState:[[inObject valueForKey:KEY_SF_CASE_SENSITIVE] integerValue]];
[phraseIsRegularExpression setState:[[inObject valueForKey:KEY_SF_REGEX] integerValue]];
[addSheet makeKeyAndOrderFront:self];
[addSheet setLevel:NSModalPanelWindowLevel];
}
@end