This repository has been archived by the owner on Sep 1, 2020. It is now read-only.
forked from myeyesareblind/pass-ios
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPasswordsViewController.mm
111 lines (91 loc) · 4.18 KB
/
PasswordsViewController.mm
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
/*
* Copyright (C) 2012 Brian A. Mattern <[email protected]>.
* Copyright (C) 2015 David Beitey <[email protected]>.
* All Rights Reserved.
* This file is licensed under the GPLv2+.
* Please see COPYING for more information
*/
#import <UIKit/UIKit.h>
#import "PasswordsViewController.h"
#import "PassDataController.h"
#import "PassEntry.h"
#import "PassEntryViewController.h"
#import "Valet/Valet.h"
@implementation PasswordsViewController
@synthesize entries;
- (void)viewDidLoad {
[super viewDidLoad];
if (self.title == nil) {
self.title = NSLocalizedString(@"Passwords", @"Password title");
}
UIBarButtonItem *clearButton = [[UIBarButtonItem alloc] initWithTitle:@"Clear Keychain" style:UIBarButtonItemStylePlain target:self action:@selector(clearPassphrase) ];
self.navigationItem.rightBarButtonItem = clearButton;
}
- (void)clearPassphrase {
// TODO Refactor into shared function
VALSecureEnclaveValet *keychain = [[VALSecureEnclaveValet alloc] initWithIdentifier:@"Pass" accessControl:VALAccessControlUserPresence];
[keychain removeObjectForKey:@"gpg-passphrase-touchid"];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Keychain cleared" message:@"Passphrase has been removed from the keychain" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.entries numEntries];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"EntryCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
PassEntry *entry = [self.entries entryAtIndex:indexPath.row];
cell.textLabel.text = entry.name;
if (entry.is_dir)
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
else
cell.accessoryType = UITableViewCellAccessoryNone;
return cell;
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
// Return unique, capitalised first letters of entries
NSMutableArray *firstLetters = [[NSMutableArray alloc] init];
[firstLetters addObject:UITableViewIndexSearch];
for (int i = 0; i < [self.entries numEntries]; i++) {
NSString *letterString = [[[self.entries entryAtIndex:i].name substringToIndex:1] uppercaseString];
if (![firstLetters containsObject:letterString]) {
[firstLetters addObject:letterString];
}
}
return firstLetters;
}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
for (int i = 0; i < [self.entries numEntries]; i++) {
NSString *letterString = [[[self.entries entryAtIndex:i].name substringToIndex:1] uppercaseString];
if ([letterString isEqualToString:title]) {
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
break;
}
}
return 1;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
PassEntry *entry = [self.entries entryAtIndex:indexPath.row];
if (entry.is_dir) {
// push subdir view onto stack
PasswordsViewController *subviewController = [[PasswordsViewController alloc] init];
subviewController.entries = [[PassDataController alloc] initWithPath:entry.path];
subviewController.title = entry.name;
[[self navigationController] pushViewController:subviewController animated:YES];
} else {
PassEntryViewController *detailController = [[PassEntryViewController alloc] init];
detailController.entry = entry;
[[self navigationController] pushViewController:detailController animated:YES];
}
}
@end