Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 1 | /* |
Alexandre Lision | 9fe374b | 2016-01-06 10:17:31 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2016 Savoir-faire Linux Inc. |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 3 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 18 | */ |
| 19 | #import "AccSecurityVC.h" |
| 20 | |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 21 | #import <QUrl> |
| 22 | #import <certificate.h> |
| 23 | #import <tlsmethodmodel.h> |
| 24 | #import <qitemselectionmodel.h> |
| 25 | #import <ciphermodel.h> |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 26 | #import <accountmodel.h> |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 27 | |
| 28 | #import "QNSTreeController.h" |
| 29 | #import "CertificateWC.h" |
| 30 | |
| 31 | // Tags for views |
| 32 | #define PVK_PASSWORD_TAG 0 |
| 33 | #define OUTGOING_TLS_SRV_NAME 1 |
| 34 | #define TLS_NEGOTIATION_TAG 2 |
| 35 | |
| 36 | #define COLUMNID_NAME @"CipherNameColumn" |
| 37 | #define COLUMNID_STATE @"CipherStateColumn" |
| 38 | |
Alexandre Lision | 24805d5 | 2015-08-12 14:29:11 -0400 | [diff] [blame] | 39 | @interface AccSecurityVC () { |
| 40 | __unsafe_unretained IBOutlet NSOutlineView *cipherListView; |
| 41 | __unsafe_unretained IBOutlet NSButton *useTLS; |
| 42 | __unsafe_unretained IBOutlet NSView *tlsContainer; |
| 43 | |
| 44 | __unsafe_unretained IBOutlet NSView *pvkContainer; |
| 45 | __unsafe_unretained IBOutlet NSImageView *pvkPasswordValidation; |
| 46 | |
| 47 | __unsafe_unretained IBOutlet NSButton *showUserCertButton; |
| 48 | __unsafe_unretained IBOutlet NSButton *showCAButton; |
| 49 | __unsafe_unretained IBOutlet NSSecureTextField *pvkPasswordField; |
| 50 | __unsafe_unretained IBOutlet NSTextField *outgoingTlsServerName; |
| 51 | __unsafe_unretained IBOutlet NSTextField *tlsNegotiationTimeout; |
| 52 | __unsafe_unretained IBOutlet NSStepper *tlsNegotiationTimeoutStepper; |
| 53 | __unsafe_unretained IBOutlet NSPathControl *caListPathControl; |
| 54 | __unsafe_unretained IBOutlet NSPathControl *certificatePathControl; |
| 55 | __unsafe_unretained IBOutlet NSPathControl *pvkPathControl; |
| 56 | __unsafe_unretained IBOutlet NSPopUpButton *tlsMethodList; |
| 57 | __unsafe_unretained IBOutlet NSButton *srtpRTPFallback; |
| 58 | __unsafe_unretained IBOutlet NSButton *useSRTP; |
| 59 | |
| 60 | __unsafe_unretained IBOutlet NSButton *verifyCertAsClientButton; |
| 61 | __unsafe_unretained IBOutlet NSButton *verifyCertAsServerButton; |
| 62 | __unsafe_unretained IBOutlet NSButton *requireCertButton; |
| 63 | } |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 64 | |
Alexandre Lision | 81c9721 | 2015-06-17 15:51:53 -0400 | [diff] [blame] | 65 | @property QNSTreeController *treeController; |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 66 | @property CertificateWC* certificateWC; |
| 67 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 68 | @end |
| 69 | |
| 70 | @implementation AccSecurityVC |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 71 | @synthesize treeController; |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 72 | @synthesize certificateWC; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 73 | |
| 74 | - (void)awakeFromNib |
| 75 | { |
| 76 | NSLog(@"INIT Security VC"); |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 77 | [pvkPasswordField setTag:PVK_PASSWORD_TAG]; |
| 78 | [outgoingTlsServerName setTag:OUTGOING_TLS_SRV_NAME]; |
| 79 | [tlsNegotiationTimeoutStepper setTag:TLS_NEGOTIATION_TAG]; |
| 80 | [tlsNegotiationTimeout setTag:TLS_NEGOTIATION_TAG]; |
| 81 | |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 82 | QObject::connect(AccountModel::instance().selectionModel(), |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 83 | &QItemSelectionModel::currentChanged, |
| 84 | [=](const QModelIndex ¤t, const QModelIndex &previous) { |
| 85 | if(!current.isValid()) |
| 86 | return; |
| 87 | [self loadAccount]; |
| 88 | }); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 89 | } |
| 90 | |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 91 | - (Account*) currentAccount |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 92 | { |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 93 | auto accIdx = AccountModel::instance().selectionModel()->currentIndex(); |
| 94 | return AccountModel::instance().getAccountByModelIndex(accIdx); |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | - (void)loadAccount |
| 98 | { |
| 99 | auto account = [self currentAccount]; |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 100 | |
| 101 | [self updateControlsWithTag:PVK_PASSWORD_TAG]; |
| 102 | [self updateControlsWithTag:OUTGOING_TLS_SRV_NAME]; |
| 103 | [self updateControlsWithTag:TLS_NEGOTIATION_TAG]; |
| 104 | |
Alexandre Lision | 81c9721 | 2015-06-17 15:51:53 -0400 | [diff] [blame] | 105 | QModelIndex qTlsMethodIdx = account->tlsMethodModel()->selectionModel()->currentIndex(); |
Alexandre Lision | 24805d5 | 2015-08-12 14:29:11 -0400 | [diff] [blame] | 106 | [tlsMethodList removeAllItems]; |
| 107 | [tlsMethodList addItemWithTitle:qTlsMethodIdx.data(Qt::DisplayRole).toString().toNSString()]; |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 108 | |
Alexandre Lision | 81c9721 | 2015-06-17 15:51:53 -0400 | [diff] [blame] | 109 | treeController = [[QNSTreeController alloc] initWithQModel:account->cipherModel()]; |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 110 | [treeController setAvoidsEmptySelection:NO]; |
| 111 | [treeController setAlwaysUsesMultipleValuesMarker:YES]; |
| 112 | [treeController setChildrenKeyPath:@"children"]; |
| 113 | |
| 114 | [cipherListView bind:@"content" toObject:treeController withKeyPath:@"arrangedObjects" options:nil]; |
| 115 | [cipherListView bind:@"sortDescriptors" toObject:treeController withKeyPath:@"sortDescriptors" options:nil]; |
| 116 | [cipherListView bind:@"selectionIndexPaths" toObject:treeController withKeyPath:@"selectionIndexPaths" options:nil]; |
| 117 | |
Alexandre Lision | 24805d5 | 2015-08-12 14:29:11 -0400 | [diff] [blame] | 118 | [useTLS setState:account->isTlsEnabled()]; |
| 119 | [tlsContainer setHidden:!account->isTlsEnabled()]; |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 120 | |
Alexandre Lision | 24805d5 | 2015-08-12 14:29:11 -0400 | [diff] [blame] | 121 | [useSRTP setState:account->isSrtpEnabled()]; |
| 122 | [srtpRTPFallback setState:account->isSrtpRtpFallback()]; |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 123 | [srtpRTPFallback setEnabled:useSRTP.state]; |
| 124 | |
Alexandre Lision | 24805d5 | 2015-08-12 14:29:11 -0400 | [diff] [blame] | 125 | if(account->tlsCaListCertificate() != nil) { |
| 126 | [caListPathControl setURL:[NSURL fileURLWithPath:account->tlsCaListCertificate()->path().toNSString()]]; |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 127 | } else { |
| 128 | [caListPathControl setURL:nil]; |
| 129 | } |
| 130 | |
Alexandre Lision | 24805d5 | 2015-08-12 14:29:11 -0400 | [diff] [blame] | 131 | auto tlsCert = account->tlsCertificate(); |
| 132 | |
| 133 | if(tlsCert != nil) { |
| 134 | [certificatePathControl setURL:[NSURL fileURLWithPath:tlsCert->path().toNSString()]]; |
| 135 | if(tlsCert->requirePrivateKey()) { |
| 136 | [pvkContainer setHidden:NO]; |
| 137 | if(!account->tlsPrivateKey().isEmpty()) { |
| 138 | [pvkPathControl setURL:[NSURL fileURLWithPath:account->tlsPrivateKey().toNSString()]]; |
| 139 | if (tlsCert->requirePrivateKeyPassword()) { |
| 140 | [pvkPasswordField setHidden:NO]; |
| 141 | } else |
| 142 | [pvkPasswordField setHidden:YES]; |
| 143 | } else { |
| 144 | [pvkPathControl setURL:nil]; |
| 145 | } |
| 146 | } else { |
| 147 | [pvkContainer setHidden:YES]; |
| 148 | } |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 149 | } else { |
| 150 | [certificatePathControl setURL:nil]; |
| 151 | } |
| 152 | |
Alexandre Lision | 24805d5 | 2015-08-12 14:29:11 -0400 | [diff] [blame] | 153 | if (account->tlsCaListCertificate()) |
| 154 | [showCAButton setHidden:!(account->tlsCaListCertificate()->isValid() == Certificate::CheckValues::PASSED)]; |
| 155 | else |
| 156 | [showCAButton setHidden:YES]; |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 157 | |
Alexandre Lision | 24805d5 | 2015-08-12 14:29:11 -0400 | [diff] [blame] | 158 | [verifyCertAsServerButton setState:account->isTlsVerifyServer()]; |
| 159 | [verifyCertAsClientButton setState:account->isTlsVerifyClient()]; |
| 160 | [requireCertButton setState:account->isTlsRequireClientCertificate()]; |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 161 | } |
| 162 | |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 163 | - (IBAction)chooseTlsMethod:(id)sender { |
| 164 | int index = [sender indexOfSelectedItem]; |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 165 | QModelIndex qIdx = [self currentAccount]->tlsMethodModel()->index(index, 0); |
| 166 | [self currentAccount]->tlsMethodModel()->selectionModel()->setCurrentIndex(qIdx, QItemSelectionModel::ClearAndSelect); |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | - (IBAction)toggleUseTLS:(id)sender { |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 170 | [self currentAccount]->setTlsEnabled([sender state]); |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 171 | [tlsContainer setHidden:![sender state]]; |
| 172 | } |
| 173 | |
| 174 | - (IBAction)toggleUseSRTP:(id)sender { |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 175 | [self currentAccount]->setSrtpEnabled([sender state]); |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 176 | [srtpRTPFallback setEnabled:[sender state]]; |
| 177 | } |
| 178 | - (IBAction)toggleRTPFallback:(id)sender { |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 179 | [self currentAccount]->setSrtpRtpFallback([sender state]); |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | - (IBAction)toggleVerifyCertAsClient:(id)sender { |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 183 | [self currentAccount]->setTlsVerifyClient([sender state]); |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | - (IBAction)toggleVerifyCertServer:(id)sender { |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 187 | [self currentAccount]->setTlsVerifyServer([sender state]); |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | - (IBAction)toggleRequireCert:(id)sender { |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 191 | [self currentAccount]->setTlsRequireClientCertificate([sender state]); |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | - (IBAction)toggleCipher:(id)sender { |
| 195 | NSInteger row = [sender clickedRow]; |
| 196 | NSTableColumn *col = [sender tableColumnWithIdentifier:COLUMNID_STATE]; |
| 197 | NSButtonCell *cell = [col dataCellForRow:row]; |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 198 | [self currentAccount]->cipherModel()->setData([self currentAccount]->cipherModel()->index(row, 0, QModelIndex()), |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 199 | cell.state == NSOnState ? Qt::Unchecked : Qt::Checked, Qt::CheckStateRole); |
| 200 | } |
| 201 | |
| 202 | - (void) updateControlsWithTag:(NSInteger) tag |
| 203 | { |
| 204 | switch (tag) { |
Alexandre Lision | 24805d5 | 2015-08-12 14:29:11 -0400 | [diff] [blame] | 205 | case PVK_PASSWORD_TAG: { |
| 206 | [pvkPasswordField setStringValue:[self currentAccount]->tlsPassword().toNSString()]; |
| 207 | BOOL passMatch = [self currentAccount]->tlsCertificate() && |
| 208 | [self currentAccount]->tlsCertificate()->privateKeyMatch() == Certificate::CheckValues::PASSED; |
| 209 | [pvkPasswordValidation setImage:[NSImage imageNamed:passMatch?@"ic_action_accept":@"ic_action_cancel"]]; |
| 210 | } |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 211 | break; |
| 212 | case OUTGOING_TLS_SRV_NAME: |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 213 | [outgoingTlsServerName setStringValue:[self currentAccount]->tlsServerName().toNSString()]; |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 214 | break; |
| 215 | case TLS_NEGOTIATION_TAG: |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 216 | [tlsNegotiationTimeout setIntegerValue:[self currentAccount]->tlsNegotiationTimeoutSec()]; |
| 217 | [tlsNegotiationTimeoutStepper setIntegerValue:[self currentAccount]->tlsNegotiationTimeoutSec()]; |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 218 | break; |
| 219 | default: |
| 220 | break; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | #pragma mark - NSTextFieldDelegate methods |
| 225 | |
| 226 | -(void)controlTextDidChange:(NSNotification *)notif |
| 227 | { |
| 228 | NSTextField *textField = [notif object]; |
| 229 | NSRange test = [[textField currentEditor] selectedRange]; |
| 230 | |
| 231 | [self valueDidChange:textField]; |
| 232 | //FIXME: saving account lose focus because in NSTreeController we remove and reinsert row so View selction change |
| 233 | [textField.window makeFirstResponder:textField]; |
| 234 | [[textField currentEditor] setSelectedRange:test]; |
| 235 | } |
| 236 | |
| 237 | - (IBAction) valueDidChange: (id) sender |
| 238 | { |
| 239 | switch ([sender tag]) { |
| 240 | case PVK_PASSWORD_TAG: |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 241 | [self currentAccount]->setTlsPassword([[sender stringValue] UTF8String]); |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 242 | break; |
| 243 | case OUTGOING_TLS_SRV_NAME: |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 244 | [self currentAccount]->setTlsServerName([[sender stringValue] UTF8String]); |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 245 | break; |
| 246 | case TLS_NEGOTIATION_TAG: |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 247 | [self currentAccount]->setTlsNegotiationTimeoutSec([sender integerValue]); |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 248 | break; |
| 249 | default: |
| 250 | break; |
| 251 | } |
| 252 | [self updateControlsWithTag:[sender tag]]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | #pragma mark - NSPathControl delegate methods |
Alexandre Lision | 24805d5 | 2015-08-12 14:29:11 -0400 | [diff] [blame] | 256 | |
| 257 | - (IBAction)caListPathControlSingleClick:(id)sender |
| 258 | { |
| 259 | NSURL* fileURL; |
| 260 | if ([sender isKindOfClass:[NSMenuItem class]]) { |
| 261 | fileURL = nil; |
| 262 | } else { |
| 263 | fileURL = [[sender clickedPathComponentCell] URL]; |
| 264 | } |
| 265 | [self->caListPathControl setURL:fileURL]; |
| 266 | [self currentAccount]->setTlsCaListCertificate([[fileURL path] UTF8String]); |
| 267 | |
| 268 | if ([self currentAccount]->tlsCaListCertificate()->isValid() == Certificate::CheckValues::PASSED) { |
| 269 | [showCAButton setHidden:NO]; |
| 270 | } else |
| 271 | [showCAButton setHidden:YES]; |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 272 | } |
| 273 | |
Alexandre Lision | 24805d5 | 2015-08-12 14:29:11 -0400 | [diff] [blame] | 274 | - (IBAction)certificatePathControlSingleClick:(id)sender |
| 275 | { |
| 276 | NSURL* fileURL; |
| 277 | if ([sender isKindOfClass:[NSMenuItem class]]) { |
| 278 | fileURL = nil; |
| 279 | } else { |
| 280 | fileURL = [[sender clickedPathComponentCell] URL]; |
| 281 | } |
| 282 | [self->certificatePathControl setURL:fileURL]; |
| 283 | [self currentAccount]->setTlsCertificate([[fileURL path] UTF8String]); |
| 284 | |
| 285 | auto cert = [self currentAccount]->tlsCertificate(); |
| 286 | |
| 287 | if (cert) { |
| 288 | [showUserCertButton setHidden:!(cert->isValid() == Certificate::CheckValues::PASSED)]; |
| 289 | [pvkContainer setHidden:!cert->requirePrivateKey()]; |
| 290 | } else { |
| 291 | [showUserCertButton setHidden:YES]; |
| 292 | [pvkContainer setHidden:YES]; |
| 293 | } |
| 294 | |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 295 | } |
| 296 | |
Alexandre Lision | 24805d5 | 2015-08-12 14:29:11 -0400 | [diff] [blame] | 297 | - (IBAction)pvkFilePathControlSingleClick:(id)sender |
| 298 | { |
| 299 | NSURL* fileURL; |
| 300 | if ([sender isKindOfClass:[NSMenuItem class]]) { |
| 301 | fileURL = nil; |
| 302 | } else { |
| 303 | fileURL = [[sender clickedPathComponentCell] URL]; |
| 304 | } |
| 305 | [self currentAccount]->setTlsPrivateKey([[fileURL path] UTF8String]); |
| 306 | if([self currentAccount]->tlsCertificate()->requirePrivateKeyPassword()) { |
| 307 | [pvkPasswordField setHidden:NO]; |
| 308 | } else { |
| 309 | [pvkPasswordField setHidden:YES]; |
| 310 | } |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | - (IBAction)showCA:(id)sender |
| 314 | { |
| 315 | certificateWC = [[CertificateWC alloc] initWithWindowNibName:@"CertificateWindow"]; |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 316 | [certificateWC setCertificate:[self currentAccount]->tlsCaListCertificate()]; |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 317 | [self.view.window beginSheet:certificateWC.window completionHandler:nil]; |
| 318 | } |
| 319 | |
| 320 | - (IBAction)showEndpointCertificate:(id)sender |
| 321 | { |
| 322 | certificateWC = [[CertificateWC alloc] initWithWindowNibName:@"CertificateWindow"]; |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 323 | [certificateWC setCertificate:[self currentAccount]->tlsCertificate()]; |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 324 | [self.view.window beginSheet:certificateWC.window completionHandler:nil];} |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 325 | |
| 326 | /* |
| 327 | Delegate method of NSPathControl to determine how the NSOpenPanel will look/behave. |
| 328 | */ |
| 329 | - (void)pathControl:(NSPathControl *)pathControl willDisplayOpenPanel:(NSOpenPanel *)openPanel |
| 330 | { |
| 331 | NSLog(@"willDisplayOpenPanel"); |
| 332 | [openPanel setAllowsMultipleSelection:NO]; |
| 333 | [openPanel setCanChooseDirectories:NO]; |
| 334 | [openPanel setCanChooseFiles:YES]; |
| 335 | [openPanel setResolvesAliases:YES]; |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 336 | |
Alexandre Lision | 24805d5 | 2015-08-12 14:29:11 -0400 | [diff] [blame] | 337 | if(pathControl == caListPathControl) { |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 338 | [openPanel setTitle:NSLocalizedString(@"Choose a CA list", @"Open panel title")]; |
Alexandre Lision | 24805d5 | 2015-08-12 14:29:11 -0400 | [diff] [blame] | 339 | } else if (pathControl == certificatePathControl) { |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 340 | [openPanel setTitle:NSLocalizedString(@"Choose a certificate", @"Open panel title")]; |
| 341 | } else { |
| 342 | [openPanel setTitle:NSLocalizedString(@"Choose a private key file", @"Open panel title")]; |
| 343 | } |
| 344 | |
Alexandre Lision | 922380d | 2015-09-15 10:25:17 -0400 | [diff] [blame] | 345 | [openPanel setPrompt:NSLocalizedString(@"Choose CA", @"Open panel prompt for 'Choose a file'")]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 346 | [openPanel setDelegate:self]; |
| 347 | } |
| 348 | |
| 349 | - (void)pathControl:(NSPathControl *)pathControl willPopUpMenu:(NSMenu *)menu |
| 350 | { |
Alexandre Lision | 24805d5 | 2015-08-12 14:29:11 -0400 | [diff] [blame] | 351 | NSMenuItem *item; |
| 352 | if(pathControl == caListPathControl) { |
Alexandre Lision | 7f01b07 | 2015-09-15 14:57:05 -0400 | [diff] [blame] | 353 | item = [menu addItemWithTitle:NSLocalizedString(@"Remove value", @"Contextual menu entry") |
| 354 | action:@selector(caListPathControlSingleClick:) keyEquivalent:@""]; |
Alexandre Lision | 24805d5 | 2015-08-12 14:29:11 -0400 | [diff] [blame] | 355 | } else if (pathControl == certificatePathControl) { |
Alexandre Lision | 7f01b07 | 2015-09-15 14:57:05 -0400 | [diff] [blame] | 356 | item = [menu addItemWithTitle:NSLocalizedString(@"Remove value", @"Contextual menu entry") |
| 357 | action:@selector(certificatePathControlSingleClick:) keyEquivalent:@""]; |
Alexandre Lision | 24805d5 | 2015-08-12 14:29:11 -0400 | [diff] [blame] | 358 | } else { |
Alexandre Lision | 7f01b07 | 2015-09-15 14:57:05 -0400 | [diff] [blame] | 359 | item = [menu addItemWithTitle:NSLocalizedString(@"Remove value", @"Contextual menu entry") |
| 360 | action:@selector(pvkFilePathControlSingleClick:) keyEquivalent:@""]; |
Alexandre Lision | 24805d5 | 2015-08-12 14:29:11 -0400 | [diff] [blame] | 361 | } |
| 362 | [item setTarget:self]; // or whatever target you want |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | #pragma mark - NSOpenSavePanelDelegate delegate methods |
| 366 | |
| 367 | - (void)panel:(id)sender willExpand:(BOOL)expanding |
| 368 | { |
| 369 | //NSLog(@"willExpand"); |
| 370 | } |
| 371 | |
| 372 | - (NSString *)panel:(id)sender userEnteredFilename:(NSString *)filename confirmed:(BOOL)okFlag |
| 373 | { |
| 374 | //NSLog(@"userEnteredFilename"); |
| 375 | } |
| 376 | |
| 377 | - (void)panelSelectionDidChange:(id)sender |
| 378 | { |
| 379 | //NSLog(@"panelSelectionDidChange"); |
| 380 | } |
| 381 | |
| 382 | - (BOOL)panel:(id)sender validateURL:(NSURL *)url error:(NSError **)outError |
| 383 | { |
| 384 | NSLog(@"validateURL"); |
| 385 | return YES; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 386 | } |
| 387 | |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 388 | #pragma mark - NSMenuDelegate methods |
| 389 | |
| 390 | - (BOOL)menu:(NSMenu *)menu updateItem:(NSMenuItem *)item atIndex:(NSInteger)index shouldCancel:(BOOL)shouldCancel |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 391 | { |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 392 | QModelIndex qIdx; |
| 393 | |
| 394 | if([menu.title isEqualToString:@"tlsmethodlist"]) |
| 395 | { |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 396 | qIdx = [self currentAccount]->tlsMethodModel()->index(index); |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 397 | [item setTitle:qIdx.data(Qt::DisplayRole).toString().toNSString()]; |
| 398 | } |
| 399 | return YES; |
| 400 | } |
| 401 | |
| 402 | - (NSInteger)numberOfItemsInMenu:(NSMenu *)menu |
| 403 | { |
| 404 | if([menu.title isEqualToString:@"tlsmethodlist"]) |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 405 | return [self currentAccount]->tlsMethodModel()->rowCount(); |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | #pragma mark - NSOutlineViewDelegate methods |
| 409 | |
| 410 | // ------------------------------------------------------------------------------- |
| 411 | // shouldSelectItem:item |
| 412 | // ------------------------------------------------------------------------------- |
| 413 | - (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item; |
| 414 | { |
| 415 | return YES; |
| 416 | } |
| 417 | |
| 418 | // ------------------------------------------------------------------------------- |
| 419 | // dataCellForTableColumn:tableColumn:item |
| 420 | // ------------------------------------------------------------------------------- |
| 421 | - (NSCell *)outlineView:(NSOutlineView *)outlineView dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item |
| 422 | { |
| 423 | NSCell *returnCell = [tableColumn dataCell]; |
| 424 | return returnCell; |
| 425 | } |
| 426 | |
| 427 | // ------------------------------------------------------------------------------- |
| 428 | // textShouldEndEditing:fieldEditor |
| 429 | // ------------------------------------------------------------------------------- |
| 430 | - (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor |
| 431 | { |
| 432 | if ([[fieldEditor string] length] == 0) |
| 433 | { |
| 434 | // don't allow empty node names |
| 435 | return NO; |
| 436 | } |
| 437 | else |
| 438 | { |
| 439 | return YES; |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | // ------------------------------------------------------------------------------- |
| 444 | // shouldEditTableColumn:tableColumn:item |
| 445 | // |
| 446 | // Decide to allow the edit of the given outline view "item". |
| 447 | // ------------------------------------------------------------------------------- |
| 448 | - (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item |
| 449 | { |
| 450 | return NO; |
| 451 | } |
| 452 | |
| 453 | // ------------------------------------------------------------------------------- |
| 454 | // outlineView:willDisplayCell:forTableColumn:item |
| 455 | // ------------------------------------------------------------------------------- |
| 456 | - (void)outlineView:(NSOutlineView *)olv willDisplayCell:(NSCell*)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item |
| 457 | { |
| 458 | QModelIndex qIdx = [treeController toQIdx:((NSTreeNode*)item)]; |
| 459 | if(!qIdx.isValid()) |
| 460 | return; |
| 461 | |
| 462 | if ([[tableColumn identifier] isEqualToString:COLUMNID_NAME]) |
| 463 | { |
| 464 | cell.title = qIdx.data(Qt::DisplayRole).toString().toNSString(); |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | // ------------------------------------------------------------------------------- |
| 469 | // outlineViewSelectionDidChange:notification |
| 470 | // ------------------------------------------------------------------------------- |
| 471 | - (void)outlineViewSelectionDidChange:(NSNotification *)notification |
| 472 | { |
| 473 | // ask the tree controller for the current selection |
| 474 | if([[treeController selectedNodes] count] > 0) { |
| 475 | |
| 476 | } |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | @end |