-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCookiesController.m
81 lines (68 loc) · 2.37 KB
/
CookiesController.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
//
// CookiesController.m
// cookiecutter
//
// Created by Pascal Friederich on 30.09.09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "CookiesController.h"
@implementation CookiesController
@synthesize cookiesTable;
-(void) initCookiesDataSource {
cookiesFileLocation = [[NSString stringWithString:cookiesFileLocation] stringByExpandingTildeInPath];
if([[NSFileManager defaultManager] fileExistsAtPath:cookiesFileLocation]){
NSLog(@"Reading plist file");
originalCookiesData = [NSMutableArray arrayWithContentsOfFile:cookiesFileLocation];
filteredCookiesData = originalCookiesData;
}else{
NSAlert *alert = [NSAlert alertWithMessageText:@"No Cookies file found!"
defaultButton:@"Exit"
alternateButton:nil
otherButton:nil
informativeTextWithFormat:@"Was looking for a cookies file at \n%@", cookiesFileLocation];
[alert setAlertStyle:NSCriticalAlertStyle];
[alert runModal];
[[NSApplication sharedApplication] terminate:self];
}
}
-(void) awakeFromNib {
cookiesFileLocation = @"~/Library/Cookies/Cookies.plist";
[self initCookiesDataSource];
}
#pragma mark -
#pragma mark Table View data source stuff
- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
return [[filteredCookiesData objectAtIndex:rowIndex] objectForKey:[[aTableColumn headerCell] title]];
}
- (int)numberOfRowsInTableView:(NSTableView *)aTableView
{
return filteredCookiesData.count;
}
#pragma mark -
#pragma mark IBActions
-(IBAction) saveCookies:(id)sender {
[originalCookiesData writeToFile:cookiesFileLocation atomically:YES];
}
-(IBAction) reloadCookies:(id)sender {
[self initCookiesDataSource];
[self.cookiesTable reloadData];
}
-(IBAction) applySearchFilter:(id)sender{
NSString *searchString = [sender stringValue];
if (![searchString length] == 0) {
NSLog(@"search with %@", searchString);
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Domain contains[c] %@", searchString];
NSArray *filteredArray = [originalCookiesData filteredArrayUsingPredicate:predicate];
[filteredArray count];
NSLog(@"Found %i matching", [filteredArray count]);
filteredCookiesData = [NSMutableArray arrayWithArray:filteredArray];
}else {
NSLog(@"Reset to all cookies");
filteredCookiesData = originalCookiesData;
}
[self.cookiesTable reloadData];
}
@end