blob: e8d794c4fb2b46332cea48f8b7c388f778a62eb2 [file] [log] [blame]
Alexandre Lisionf5fc4792015-03-17 09:15:43 -04001/*
Alexandre Lision7f01b072015-09-15 14:57:05 -04002 * Copyright (C) 2015 Savoir-faire Linux Inc.
Alexandre Lisionf5fc4792015-03-17 09:15:43 -04003 * 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 Lisionf5fc4792015-03-17 09:15:43 -040018 */
19#import "AccSecurityVC.h"
20
Alexandre Lision4de68ce2015-04-24 18:22:49 -040021#import <QUrl>
22#import <certificate.h>
23#import <tlsmethodmodel.h>
24#import <qitemselectionmodel.h>
25#import <ciphermodel.h>
Alexandre Lision7f3164c2015-06-12 11:45:37 -040026#import <accountmodel.h>
Alexandre Lision4de68ce2015-04-24 18:22:49 -040027
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 Lision24805d52015-08-12 14:29:11 -040039@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 Lisionf5fc4792015-03-17 09:15:43 -040064
Alexandre Lision81c97212015-06-17 15:51:53 -040065@property QNSTreeController *treeController;
Alexandre Lision4de68ce2015-04-24 18:22:49 -040066@property CertificateWC* certificateWC;
67
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040068@end
69
70@implementation AccSecurityVC
Alexandre Lision4de68ce2015-04-24 18:22:49 -040071@synthesize treeController;
Alexandre Lision4de68ce2015-04-24 18:22:49 -040072@synthesize certificateWC;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040073
74- (void)awakeFromNib
75{
76 NSLog(@"INIT Security VC");
Alexandre Lision4de68ce2015-04-24 18:22:49 -040077 [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 Lisiond3aa3ad2015-10-23 14:28:41 -040082 QObject::connect(AccountModel::instance().selectionModel(),
Alexandre Lision7f3164c2015-06-12 11:45:37 -040083 &QItemSelectionModel::currentChanged,
84 [=](const QModelIndex &current, const QModelIndex &previous) {
85 if(!current.isValid())
86 return;
87 [self loadAccount];
88 });
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040089}
90
Alexandre Lision7f3164c2015-06-12 11:45:37 -040091- (Account*) currentAccount
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040092{
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -040093 auto accIdx = AccountModel::instance().selectionModel()->currentIndex();
94 return AccountModel::instance().getAccountByModelIndex(accIdx);
Alexandre Lision7f3164c2015-06-12 11:45:37 -040095}
96
97- (void)loadAccount
98{
99 auto account = [self currentAccount];
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400100
101 [self updateControlsWithTag:PVK_PASSWORD_TAG];
102 [self updateControlsWithTag:OUTGOING_TLS_SRV_NAME];
103 [self updateControlsWithTag:TLS_NEGOTIATION_TAG];
104
Alexandre Lision81c97212015-06-17 15:51:53 -0400105 QModelIndex qTlsMethodIdx = account->tlsMethodModel()->selectionModel()->currentIndex();
Alexandre Lision24805d52015-08-12 14:29:11 -0400106 [tlsMethodList removeAllItems];
107 [tlsMethodList addItemWithTitle:qTlsMethodIdx.data(Qt::DisplayRole).toString().toNSString()];
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400108
Alexandre Lision81c97212015-06-17 15:51:53 -0400109 treeController = [[QNSTreeController alloc] initWithQModel:account->cipherModel()];
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400110 [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 Lision24805d52015-08-12 14:29:11 -0400118 [useTLS setState:account->isTlsEnabled()];
119 [tlsContainer setHidden:!account->isTlsEnabled()];
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400120
Alexandre Lision24805d52015-08-12 14:29:11 -0400121 [useSRTP setState:account->isSrtpEnabled()];
122 [srtpRTPFallback setState:account->isSrtpRtpFallback()];
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400123 [srtpRTPFallback setEnabled:useSRTP.state];
124
Alexandre Lision24805d52015-08-12 14:29:11 -0400125 if(account->tlsCaListCertificate() != nil) {
126 [caListPathControl setURL:[NSURL fileURLWithPath:account->tlsCaListCertificate()->path().toNSString()]];
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400127 } else {
128 [caListPathControl setURL:nil];
129 }
130
Alexandre Lision24805d52015-08-12 14:29:11 -0400131 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 Lision4de68ce2015-04-24 18:22:49 -0400149 } else {
150 [certificatePathControl setURL:nil];
151 }
152
Alexandre Lision24805d52015-08-12 14:29:11 -0400153 if (account->tlsCaListCertificate())
154 [showCAButton setHidden:!(account->tlsCaListCertificate()->isValid() == Certificate::CheckValues::PASSED)];
155 else
156 [showCAButton setHidden:YES];
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400157
Alexandre Lision24805d52015-08-12 14:29:11 -0400158 [verifyCertAsServerButton setState:account->isTlsVerifyServer()];
159 [verifyCertAsClientButton setState:account->isTlsVerifyClient()];
160 [requireCertButton setState:account->isTlsRequireClientCertificate()];
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400161}
162
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400163- (IBAction)chooseTlsMethod:(id)sender {
164 int index = [sender indexOfSelectedItem];
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400165 QModelIndex qIdx = [self currentAccount]->tlsMethodModel()->index(index, 0);
166 [self currentAccount]->tlsMethodModel()->selectionModel()->setCurrentIndex(qIdx, QItemSelectionModel::ClearAndSelect);
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400167}
168
169- (IBAction)toggleUseTLS:(id)sender {
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400170 [self currentAccount]->setTlsEnabled([sender state]);
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400171 [tlsContainer setHidden:![sender state]];
172}
173
174- (IBAction)toggleUseSRTP:(id)sender {
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400175 [self currentAccount]->setSrtpEnabled([sender state]);
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400176 [srtpRTPFallback setEnabled:[sender state]];
177}
178- (IBAction)toggleRTPFallback:(id)sender {
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400179 [self currentAccount]->setSrtpRtpFallback([sender state]);
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400180}
181
182- (IBAction)toggleVerifyCertAsClient:(id)sender {
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400183 [self currentAccount]->setTlsVerifyClient([sender state]);
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400184}
185
186- (IBAction)toggleVerifyCertServer:(id)sender {
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400187 [self currentAccount]->setTlsVerifyServer([sender state]);
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400188}
189
190- (IBAction)toggleRequireCert:(id)sender {
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400191 [self currentAccount]->setTlsRequireClientCertificate([sender state]);
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400192}
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 Lision7f3164c2015-06-12 11:45:37 -0400198 [self currentAccount]->cipherModel()->setData([self currentAccount]->cipherModel()->index(row, 0, QModelIndex()),
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400199 cell.state == NSOnState ? Qt::Unchecked : Qt::Checked, Qt::CheckStateRole);
200}
201
202- (void) updateControlsWithTag:(NSInteger) tag
203{
204 switch (tag) {
Alexandre Lision24805d52015-08-12 14:29:11 -0400205 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 Lision4de68ce2015-04-24 18:22:49 -0400211 break;
212 case OUTGOING_TLS_SRV_NAME:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400213 [outgoingTlsServerName setStringValue:[self currentAccount]->tlsServerName().toNSString()];
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400214 break;
215 case TLS_NEGOTIATION_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400216 [tlsNegotiationTimeout setIntegerValue:[self currentAccount]->tlsNegotiationTimeoutSec()];
217 [tlsNegotiationTimeoutStepper setIntegerValue:[self currentAccount]->tlsNegotiationTimeoutSec()];
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400218 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 Lision7f3164c2015-06-12 11:45:37 -0400241 [self currentAccount]->setTlsPassword([[sender stringValue] UTF8String]);
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400242 break;
243 case OUTGOING_TLS_SRV_NAME:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400244 [self currentAccount]->setTlsServerName([[sender stringValue] UTF8String]);
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400245 break;
246 case TLS_NEGOTIATION_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400247 [self currentAccount]->setTlsNegotiationTimeoutSec([sender integerValue]);
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400248 break;
249 default:
250 break;
251 }
252 [self updateControlsWithTag:[sender tag]];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400253}
254
255#pragma mark - NSPathControl delegate methods
Alexandre Lision24805d52015-08-12 14:29:11 -0400256
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 Lision4de68ce2015-04-24 18:22:49 -0400272}
273
Alexandre Lision24805d52015-08-12 14:29:11 -0400274- (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 Lision4de68ce2015-04-24 18:22:49 -0400295}
296
Alexandre Lision24805d52015-08-12 14:29:11 -0400297- (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 Lision4de68ce2015-04-24 18:22:49 -0400311}
312
313- (IBAction)showCA:(id)sender
314{
315 certificateWC = [[CertificateWC alloc] initWithWindowNibName:@"CertificateWindow"];
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400316 [certificateWC setCertificate:[self currentAccount]->tlsCaListCertificate()];
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400317 [self.view.window beginSheet:certificateWC.window completionHandler:nil];
318}
319
320- (IBAction)showEndpointCertificate:(id)sender
321{
322 certificateWC = [[CertificateWC alloc] initWithWindowNibName:@"CertificateWindow"];
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400323 [certificateWC setCertificate:[self currentAccount]->tlsCertificate()];
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400324 [self.view.window beginSheet:certificateWC.window completionHandler:nil];}
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400325
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 Lision4de68ce2015-04-24 18:22:49 -0400336
Alexandre Lision24805d52015-08-12 14:29:11 -0400337 if(pathControl == caListPathControl) {
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400338 [openPanel setTitle:NSLocalizedString(@"Choose a CA list", @"Open panel title")];
Alexandre Lision24805d52015-08-12 14:29:11 -0400339 } else if (pathControl == certificatePathControl) {
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400340 [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 Lision922380d2015-09-15 10:25:17 -0400345 [openPanel setPrompt:NSLocalizedString(@"Choose CA", @"Open panel prompt for 'Choose a file'")];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400346 [openPanel setDelegate:self];
347}
348
349- (void)pathControl:(NSPathControl *)pathControl willPopUpMenu:(NSMenu *)menu
350{
Alexandre Lision24805d52015-08-12 14:29:11 -0400351 NSMenuItem *item;
352 if(pathControl == caListPathControl) {
Alexandre Lision7f01b072015-09-15 14:57:05 -0400353 item = [menu addItemWithTitle:NSLocalizedString(@"Remove value", @"Contextual menu entry")
354 action:@selector(caListPathControlSingleClick:) keyEquivalent:@""];
Alexandre Lision24805d52015-08-12 14:29:11 -0400355 } else if (pathControl == certificatePathControl) {
Alexandre Lision7f01b072015-09-15 14:57:05 -0400356 item = [menu addItemWithTitle:NSLocalizedString(@"Remove value", @"Contextual menu entry")
357 action:@selector(certificatePathControlSingleClick:) keyEquivalent:@""];
Alexandre Lision24805d52015-08-12 14:29:11 -0400358 } else {
Alexandre Lision7f01b072015-09-15 14:57:05 -0400359 item = [menu addItemWithTitle:NSLocalizedString(@"Remove value", @"Contextual menu entry")
360 action:@selector(pvkFilePathControlSingleClick:) keyEquivalent:@""];
Alexandre Lision24805d52015-08-12 14:29:11 -0400361 }
362 [item setTarget:self]; // or whatever target you want
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400363}
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 Lisionf5fc4792015-03-17 09:15:43 -0400386}
387
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400388#pragma mark - NSMenuDelegate methods
389
390- (BOOL)menu:(NSMenu *)menu updateItem:(NSMenuItem *)item atIndex:(NSInteger)index shouldCancel:(BOOL)shouldCancel
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400391{
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400392 QModelIndex qIdx;
393
394 if([menu.title isEqualToString:@"tlsmethodlist"])
395 {
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400396 qIdx = [self currentAccount]->tlsMethodModel()->index(index);
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400397 [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 Lision7f3164c2015-06-12 11:45:37 -0400405 return [self currentAccount]->tlsMethodModel()->rowCount();
Alexandre Lision4de68ce2015-04-24 18:22:49 -0400406}
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 Lisionf5fc4792015-03-17 09:15:43 -0400477}
478
479@end