Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / platform / DARWIN / AFSPreference / AFSCommanderPref.m
1 //
2 // AFSCommanderPref.m
3 // AFSCommander
4 //
5 // Created by Claudio Bisegni on 10/05/07.
6 // Copyright (c) 2007 INFN - National Institute of Nuclear Physics. All rights reserved.
7 //
8
9 #import "AFSCommanderPref.h"
10 #import "IpConfiguratorCommander.h"
11 #import "TokenCredentialController.h"
12 #import "InfoController.h"
13 #import "TaskUtil.h"
14 #import "PListManager.h"
15 #import "DialogUtility.h"
16 #import "NSString+search.h"
17 #include <sys/param.h>
18 #include <sys/stat.h>
19 #include <sys/wait.h>
20 #include <sys/types.h>
21 #include <sys/fcntl.h>
22 #include <sys/errno.h>
23 #include <unistd.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #import <CoreServices/CoreServices.h>
27
28
29 #define ADD_CELL_CONTROL_TAG 1
30 #define REMOVE_CELL_CONTROL_TAG 2
31
32 #define TABLE_TOKENS_LIST 1
33 #define TABLE_CELL_LIST 2
34 #define TABLE_LINK_LIST 3
35
36 #define TAB_TOKENS 1
37 #define TAB_CELL_SERV_DB 2
38 #define TAB_CACHE 3
39 #define TAB_LINK 4
40
41 //CellServDB table id
42 #define CELLSRVDB_TABLE_USR_DFLT_CHECK_COLUMN 0
43 #define CELLSRVDB_TABLE_DFLT_CHECK_COLUMN 1
44 #define CELLSRVDB_TABLE_NAME_COLUMN 2
45 #define CELLSRVDB_TABLE_DESCRIPTION_COLUMN 3
46
47 //Link Table
48 #define TABLE_COLUMN_LINK_NAME 0
49 #define TABLE_COLUMN_LINK_PATH 1
50
51
52 @implementation AFSCommanderPref
53
54 // -------------------------------------------------------------------------------
55 // initWithBundle:
56 // -------------------------------------------------------------------------------
57 - (id)initWithBundle:(NSBundle *)bundle
58 {
59 if ( ( self = [super initWithBundle:bundle] ) != nil ) {
60 //appID = kAfsCommanderID;
61 prefStartUp = 1;
62 }
63 return self;
64 }
65
66 // -------------------------------------------------------------------------------
67 // mainView:
68 // -------------------------------------------------------------------------------
69 - (NSView *) mainView {
70 if (prefStartUp == 1){
71 SInt32 osxMJVers = 0;
72 SInt32 osxMnVers = 0;
73 if (Gestalt(gestaltSystemVersionMajor, &osxMJVers) == noErr && Gestalt(gestaltSystemVersionMinor, &osxMnVers) == noErr) {
74 if (osxMJVers == 10 && osxMnVers>= 5) {
75 [afsCommanderView setFrameSize:NSMakeSize(668, [afsCommanderView frame].size.height)];
76 prefStartUp = 0;
77 }
78 }
79 }
80
81 return afsCommanderView;
82 }
83
84 // -------------------------------------------------------------------------------
85 // mainViewDidLoad:
86 // -------------------------------------------------------------------------------
87 - (void) mainViewDidLoad
88 {
89 //CellServDB Table
90 [cellList setDelegate:self];
91 [cellList setTarget:self];
92 [cellList setDoubleAction:@selector(tableDoubleAction:)];
93
94 // Setup security.
95 AuthorizationItem items = {kAuthorizationRightExecute, 0, NULL, 0};
96 AuthorizationRights rights = {1, &items};
97 [authView setAuthorizationRights:&rights];
98 authView.delegate = self;
99 [authView updateStatus:nil];
100 }
101
102 // -------------------------------------------------------------------------------
103 // didSelect:
104 // -------------------------------------------------------------------------------
105 - (void) didSelect
106 {
107 //try to install the launchd file for backgrounder
108 //Remove launchd ctrl file
109 @try {
110 [PListManager installBackgrounderLaunchdFile:YES
111 resourcePath:[[self bundle] resourcePath]];
112 }
113 @catch (NSException * e) {
114 NSDictionary *excecptDic = [e userInfo];
115 NSNumber *keyNum = [excecptDic objectForKey:@"agent_folder_error"];
116 if(keyNum && [keyNum boolValue]) {
117 // the dir HOME_LAUNCHD_AGENT_FOLDER (PListManager.h) must be created
118 NSBeginAlertSheet([[NSString stringWithString:kDoYouWantCreateTheDirectory] stringByAppendingString:HOME_LAUNCHD_AGENT_FOLDER],
119 @"Create", @"Cancel", nil,
120 [[self mainView] window], self, @selector(credentialAtLoginTimeEventCreationLaunchAgentDir:returnCode:contextInfo:), NULL,
121 nil, @"", nil);
122 }
123 }
124 @finally {
125
126 }
127
128
129 // Set Developer info
130 [textFieldDevInfoLabel setStringValue:kDevelopInfo];
131 // creating the lock
132 tokensLock = [[NSLock alloc] init];
133
134 //Initialization cellservdb and token list
135 filteredCellDB = nil;
136 tokenList = nil;
137
138 [self readPreferenceFile];
139
140 // alloc the afs property mananger
141 afsProperty = [[AFSPropertyManager alloc] init];
142
143 // register preference pane to detect menuextra killed by user
144 [[NSDistributedNotificationCenter defaultCenter] addObserver:self
145 selector:@selector(refreshTokensNotify:)
146 name:kAfsCommanderID
147 object:kMExtraTokenOperation];
148
149 [[NSDistributedNotificationCenter defaultCenter] addObserver:self
150 selector:@selector(refreshGui:)
151 name:kAfsCommanderID
152 object:kMenuExtraEventOccured];
153
154 //Register for mount/unmount afs volume
155 [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self
156 selector:@selector(afsVolumeMountChange:)
157 name:NSWorkspaceDidMountNotification object:nil];
158
159 [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self
160 selector:@selector(afsVolumeMountChange:)
161 name:NSWorkspaceDidUnmountNotification object:nil];
162
163 // set self as table data source
164 [cellList setDataSource:self];
165 [tokensTable setDataSource:self];
166 //[tableViewLink setDataSource:self];
167 //check the afs state
168 [self setAfsStatus];
169
170 // let show the configuration after prefpane is open
171 [self refreshConfiguration:nil];
172
173 // refresh the token list
174 //[self refreshTokens:nil];
175
176 //refresh table to reflect the NSSearchField contained text
177 [self searchCellTextEvent:nil];
178 }
179
180 // -------------------------------------------------------------------------------
181 // credentialAtLoginTimeEventCreationLaunchAgentDir:
182 // -------------------------------------------------------------------------------
183 - (void) credentialAtLoginTimeEventCreationLaunchAgentDir:(NSWindow*)alert returnCode:(int)returnCode contextInfo:(void *)contextInfo {
184 [alert close];
185 switch (returnCode) {
186 case 1:
187 if([[NSFileManager defaultManager] createDirectoryAtPath:[HOME_LAUNCHD_AGENT_FOLDER stringByExpandingTildeInPath]
188 withIntermediateDirectories:NO
189 attributes:nil
190 error:nil]) {
191
192 //Create the file
193 [PListManager installBackgrounderLaunchdFile:YES
194 resourcePath:[[self bundle] resourcePath]];
195 [self showMessage:kDirectoryCreated];
196 } else {
197 [self showMessage:kErrorCreatingDirectory];
198 }
199 break;
200 case 0:
201 break;
202 }
203 }
204
205
206 // -------------------------------------------------------------------------------
207 // willUnselect:
208 // -------------------------------------------------------------------------------
209 - (void)willUnselect
210 {
211 // remove self as datasource
212 [cellList setDataSource:nil];
213 [tokensTable setDataSource:nil];
214
215 //release the afs property manager
216 if(afsProperty) [afsProperty release];
217 //release tokens list
218 if(tokenList) [tokenList release];
219 //Remove the cell temp array
220 if(filteredCellDB) [filteredCellDB release];
221
222 [self writePreferenceFile];
223
224 // unregister preference pane to detect menuextra killed by user
225 [[NSDistributedNotificationCenter defaultCenter] removeObserver:self
226 name:kAfsCommanderID
227 object:kMExtraClosedNotification];
228 [[NSDistributedNotificationCenter defaultCenter] removeObserver:self
229 name:kAfsCommanderID
230 object:kMExtraTokenOperation];
231 [[NSDistributedNotificationCenter defaultCenter] removeObserver:self
232 name:kAfsCommanderID
233 object:kMenuExtraEventOccured];
234 [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self
235 name:NSWorkspaceDidMountNotification object:nil];
236 [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self
237 name:NSWorkspaceDidUnmountNotification object:nil];
238
239 [self stopTimer];
240 [tokensLock release];
241 }
242
243
244 // -------------------------------------------------------------------------------
245 // startTimer:
246 // -------------------------------------------------------------------------------
247 - (void)startTimer{
248 //start the time for check tokens validity
249 if(timerForCheckTokensList) return;
250 timerForCheckTokensList = [NSTimer scheduledTimerWithTimeInterval:TOKENS_REFRESH_TIME_IN_SEC
251 target:self
252 selector:@selector(refreshTokens:)
253 userInfo:nil
254 repeats:YES];
255 [timerForCheckTokensList fire];
256 }
257
258 // -------------------------------------------------------------------------------
259 // stopTimer:
260 // -------------------------------------------------------------------------------
261 - (void)stopTimer{
262 if(!timerForCheckTokensList) return;
263 [timerForCheckTokensList invalidate];
264 timerForCheckTokensList = nil;
265 }
266
267
268 // -------------------------------------------------------------------------------
269 // readPreferenceFile:
270 // -------------------------------------------------------------------------------
271 - (void) readPreferenceFile
272 {
273 // read the preference for aklog use
274 NSNumber *useAklogPrefValue = (NSNumber*)CFPreferencesCopyValue((CFStringRef)PREFERENCE_USE_AKLOG, (CFStringRef)kAfsCommanderID,
275 kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
276 NSNumber *aklogTokenAtLogin = (NSNumber*)CFPreferencesCopyValue((CFStringRef)PREFERENCE_AKLOG_TOKEN_AT_LOGIN, (CFStringRef)kAfsCommanderID,
277 kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
278 [useAklogCheck setState:[useAklogPrefValue intValue]];
279 [aklogCredentialAtLoginTime setEnabled:useAklogPrefValue && [useAklogPrefValue boolValue]];
280 [aklogCredentialAtLoginTime setState:aklogTokenAtLogin && [aklogTokenAtLogin boolValue]];
281
282 //check krb5 at login time
283 [installKRB5AuthAtLoginButton setState:[PListManager checkKrb5AtLoginTimeLaunchdEnable]];
284
285 //check for AFS enable at startup
286 NSNumber *afsEnableStartupTime = (NSNumber*)CFPreferencesCopyValue((CFStringRef)PREFERENCE_START_AFS_AT_STARTUP,
287 (CFStringRef)kAfsCommanderID, kCFPreferencesAnyUser, kCFPreferencesAnyHost);
288 if(afsEnableStartupTime)
289 startAFSAtLogin = [afsEnableStartupTime boolValue];
290 else
291 startAFSAtLogin = false;
292 //set the check button state
293 [checkButtonAfsAtBootTime setState:startAFSAtLogin];
294
295 NSNumber *showStatusMenu = (NSNumber*)CFPreferencesCopyValue((CFStringRef)PREFERENCE_SHOW_STATUS_MENU, (CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
296 [(NSButton*)afsMenucheckBox setState: [showStatusMenu boolValue]];
297
298 //backgrounder state
299 [backgrounderActivationCheck setState:[PListManager launchdJobState:BACKGROUNDER_P_FILE]];
300
301 //link enabled status
302 NSNumber *linkEnabledStatus = (NSNumber*)CFPreferencesCopyValue((CFStringRef)PREFERENCE_USE_LINK, (CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
303 [checkEnableLink setState:[linkEnabledStatus boolValue]];
304
305 //check the user preference for manage the renew
306 NSNumber *checkRenew = (NSNumber*)CFPreferencesCopyValue((CFStringRef)PREFERENCE_KRB5_CHECK_ENABLE, (CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
307 if(checkRenew)[nsButtonEnableDisableKrb5RenewCheck setState:[checkRenew intValue]];
308
309 NSNumber *renewTime = (NSNumber*)CFPreferencesCopyValue((CFStringRef)PREFERENCE_KRB5_RENEW_TIME, (CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
310 if(!renewTime) renewTime = [NSNumber numberWithInt:PREFERENCE_KRB5_RENEW_TIME_DEFAULT_VALUE];
311
312 //update gui
313 NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
314 NSDateComponents *weekdayComponents = [gregorian components:(NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit)
315 fromDate:[NSDate dateWithTimeIntervalSince1970:[renewTime intValue]]];
316 [nsTextFieldKrb5RenewTimeD setIntValue:[weekdayComponents day]-1];
317 [nsTextFieldKrb5RenewTimeH setIntValue:[weekdayComponents hour]-1];
318 [nsTextFieldKrb5RenewTimeM setIntValue:[weekdayComponents minute]];
319 [nsTextFieldKrb5RenewTimeS setIntValue:[weekdayComponents second]];
320 [nsStepperKrb5RenewTimeD setIntValue:[weekdayComponents day]-1];
321 [nsStepperKrb5RenewTimeH setIntValue:[weekdayComponents hour]-1];
322 [nsStepperKrb5RenewTimeM setIntValue:[weekdayComponents minute]];
323 [nsStepperKrb5RenewTimeS setIntValue:[weekdayComponents second]];
324
325 NSNumber *renewCheckTimeInterval = (NSNumber*)CFPreferencesCopyValue((CFStringRef)PREFERENCE_KRB5_RENEW_CHECK_TIME_INTERVALL, (CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
326 if(renewCheckTimeInterval && [renewCheckTimeInterval intValue])[nsTextFieldKrb5RenewCheckIntervall setIntValue:[renewCheckTimeInterval intValue]];
327 else [nsTextFieldKrb5RenewCheckIntervall setIntValue:PREFERENCE_KRB5_RENEW_CHECK_TIME_INTERVALL_DEFAULT_VALUE];
328
329 NSNumber *expireTimeForRenew = (NSNumber*)CFPreferencesCopyValue((CFStringRef)PREFERENCE_KRB5_SEC_TO_EXPIRE_TIME_FOR_RENEW, (CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
330 if(expireTimeForRenew && [expireTimeForRenew intValue])[nsTextFieldKrb5SecToExpireDateForRenew setIntValue:[expireTimeForRenew intValue]];
331 else [nsTextFieldKrb5SecToExpireDateForRenew setIntValue:PREFERENCE_KRB5_SEC_TO_EXPIRE_TIME_FOR_RENEW_DEFAULT_VALUE];
332
333 //link configuration
334 NSData *prefData = (NSData*)CFPreferencesCopyValue((CFStringRef)PREFERENCE_LINK_CONFIGURATION, (CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
335 NSDictionary *linkDict = (NSMutableDictionary*)[NSPropertyListSerialization propertyListFromData:prefData
336 mutabilityOption:NSPropertyListMutableContainers
337 format:nil
338 errorDescription:nil];
339 linkConfiguration = [linkDict mutableCopy];
340 }
341
342 // -------------------------------------------------------------------------------
343 // willUnselect:
344 // -------------------------------------------------------------------------------
345 - (void) writePreferenceFile
346 {
347 //Set the preference for afs path
348 //Set the preference for aklog use
349 CFPreferencesSetValue((CFStringRef)PREFERENCE_USE_AKLOG,
350 (CFNumberRef)[NSNumber numberWithInt:[useAklogCheck state]],
351 (CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
352
353 //set AFS enable state at startup
354 CFPreferencesSetValue((CFStringRef)PREFERENCE_START_AFS_AT_STARTUP,
355 (CFNumberRef)[NSNumber numberWithBool:startAFSAtLogin],
356 (CFStringRef)kAfsCommanderID, kCFPreferencesAnyUser, kCFPreferencesAnyHost);
357
358 //set aklog at login
359 CFPreferencesSetValue((CFStringRef)PREFERENCE_AKLOG_TOKEN_AT_LOGIN,
360 (CFNumberRef)[NSNumber numberWithBool:[aklogCredentialAtLoginTime state]],
361 (CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
362
363 //set aklog at login
364 CFPreferencesSetValue((CFStringRef)PREFERENCE_SHOW_STATUS_MENU,
365 (CFNumberRef)[NSNumber numberWithBool:[(NSButton*)afsMenucheckBox state]],
366 (CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
367
368 //preference for link
369 CFPreferencesSetValue((CFStringRef)PREFERENCE_USE_LINK,
370 (CFNumberRef)[NSNumber numberWithBool:[checkEnableLink state]],
371 (CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
372
373 //preference for renew time
374 //NSLog(@"%d %d %d %d", [nsTextFieldKrb5RenewTimeD intValue],[nsTextFieldKrb5RenewTimeH intValue],[nsTextFieldKrb5RenewTimeM intValue],[nsTextFieldKrb5RenewTimeS intValue]);
375 NSInteger totalSeconds = ([nsTextFieldKrb5RenewTimeD intValue]*24*60*60)+
376 ([nsTextFieldKrb5RenewTimeH intValue]*60*60)+
377 ([nsTextFieldKrb5RenewTimeM intValue]*60)+
378 [nsTextFieldKrb5RenewTimeS intValue];
379
380 CFPreferencesSetValue((CFStringRef)PREFERENCE_KRB5_RENEW_TIME,
381 (CFNumberRef)[NSNumber numberWithInt:totalSeconds],
382 (CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
383
384 //expire time for renew
385 CFPreferencesSetValue((CFStringRef)PREFERENCE_KRB5_SEC_TO_EXPIRE_TIME_FOR_RENEW,
386 (CFNumberRef)[NSNumber numberWithInt:[nsTextFieldKrb5SecToExpireDateForRenew intValue]],
387 (CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
388
389 //sec to expiretime for renew job
390 CFPreferencesSetValue((CFStringRef)PREFERENCE_KRB5_RENEW_CHECK_TIME_INTERVALL,
391 (CFNumberRef)[NSNumber numberWithInt:[nsTextFieldKrb5RenewCheckIntervall intValue]],
392 (CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
393
394 CFPreferencesSynchronize((CFStringRef)kAfsCommanderID, kCFPreferencesAnyUser, kCFPreferencesAnyHost);
395 CFPreferencesSynchronize((CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
396 [[NSDistributedNotificationCenter defaultCenter] postNotificationName:kAFSMenuExtraID object:kPrefChangeNotification];
397 }
398
399 // -------------------------------------------------------------------------------
400 // saveConfiguration:
401 // -------------------------------------------------------------------------------
402 - (IBAction) saveConfiguration:(id) sender
403 {
404 @try{
405 [afsProperty setCellName:[afsProperty getDefaultCellName]];
406
407 //save configurations
408 [afsProperty saveConfigurationFiles:YES];
409
410 //Reload all configuration
411 [self refreshConfiguration:nil];
412
413 //refresh table to reflect the NSSearchField contained text
414 [self searchCellTextEvent:nil];
415
416 //Show dialog for notifity al saving process ar gone ell
417 [self showMessage:kConfigurationSaved];
418 }@catch(NSException *e){
419 [self showMessage:[e reason]];
420 } @finally {
421 [cellList reloadData];
422 }
423 }
424
425 // -------------------------------------------------------------------------------
426 // saveCacheManagerParam:
427 // -------------------------------------------------------------------------------
428 - (IBAction) saveCacheManagerParam:(id) sender
429 {
430 @try{
431 //Update the value form view to afs property manager class
432 [self updateCacheParamFromView];
433 [afsProperty saveCacheConfigurationFiles:YES];
434 [self showMessage:kSavedCacheConfiguration];
435 }@catch(NSException *e){
436 [self showMessage:[e reason]];
437 } @finally {
438 [cellList reloadData];
439 }
440 }
441
442 // -------------------------------------------------------------------------------
443 // refreshConfiguration:
444 // -------------------------------------------------------------------------------
445 - (IBAction) refreshConfiguration:(id) sender
446 {
447 NSString *afsBasePath = PREFERENCE_AFS_SYS_PAT_STATIC;
448 @try{
449 // set the afs path
450 [afsProperty setPath:afsBasePath];
451
452 // load configuration
453 [afsProperty loadConfiguration];
454
455 //set the afs version label
456 [afsVersionLabel setStringValue:[afsProperty getAfsVersion]];
457
458 //set the current default cell
459 [afsDefaultCellLabel setStringValue:[afsProperty getDefaultCellName]];
460
461 // Update cache view
462 [self fillCacheParamView];
463
464 //Filter the cellServDb and allocate filtered array
465 [self filterCellServDB:nil];
466
467 }@catch(NSException *e){
468 [self showMessage:[e reason]];
469 } @finally {
470 [cellList reloadData];
471 }
472 }
473
474 // -------------------------------------------------------------------------------
475 // fillCacheParamView:
476 // -------------------------------------------------------------------------------
477 -(void) fillCacheParamView
478 {
479 [dynRoot setState:[afsProperty dynRoot]?NSOnState:NSOffState];
480 [afsDB setState:[afsProperty afsDB]?NSOnState:NSOffState];
481 [statCacheEntry setIntValue:[afsProperty statCacheEntry]];
482 [dCacheDim setIntValue:[afsProperty dCacheDim]];
483 [cacheDimension setIntValue:[afsProperty cacheDimension]];
484 [daemonNumber setIntValue:[afsProperty daemonNumber]];
485 [afsRootMountPoint setStringValue:[afsProperty afsRootMountPoint]];
486 [nVolEntry setIntValue:[afsProperty nVolEntry]];
487
488 //new version property
489 //[verbose setEnabled:[afsProperty useAfsdConfConfigFile]];
490 [verbose setState:[afsProperty verbose]?NSOnState:NSOffState];
491
492 }
493
494 // -------------------------------------------------------------------------------
495 // updateCacheParamFromView:
496 // -------------------------------------------------------------------------------
497 -(void) updateCacheParamFromView
498 {
499 NSString *tmpAfsPath = [afsRootMountPoint stringValue];
500 if(!tmpAfsPath || ([tmpAfsPath length] == 0) || ([tmpAfsPath characterAtIndex:0] != '/'))
501 @throw [NSException exceptionWithName:@"updateCacheParamFromView"
502 reason:kBadAfsRootMountPoint
503 userInfo:nil];
504
505 [afsProperty setDynRoot:[dynRoot state]==NSOnState];
506 [afsProperty setAfsDB:[afsDB state]==NSOnState];
507 [afsProperty setStatCacheEntry:[statCacheEntry intValue]];
508 [afsProperty setDCacheDim:[dCacheDim intValue]];
509 [afsProperty setCacheDimension:[cacheDimension intValue]];
510 [afsProperty setDaemonNumber:[daemonNumber intValue]];
511 [afsProperty setAfsRootMountPoint:tmpAfsPath];
512 [afsProperty setNVolEntry:[nVolEntry intValue]];
513 [afsProperty setVerbose:[verbose state]==NSOnState];
514 }
515
516
517 // -------------------------------------------------------------------------------
518 // showCellIP:
519 // -------------------------------------------------------------------------------
520 - (IBAction) showCellIP:(id) sender
521 {
522 int rowSelected = [((NSTableView *) cellList) selectedRow];
523 [self modifyCellByIDX:rowSelected];
524 }
525
526 // -------------------------------------------------------------------------------
527 // modifyCellByIDX:
528 // -------------------------------------------------------------------------------
529 -(void) modifyCellByIDX:(int) idx
530 {
531 [self modifyCell:[self getCellByIDX:idx]];
532 }
533
534 // -------------------------------------------------------------------------------
535 // modifyCellByIDX:
536 // -------------------------------------------------------------------------------
537 -(void) modifyCell:(DBCellElement*) cellElement
538 {
539 [NSBundle loadNibNamed:@"IpPanel" owner:self];
540 [((IpConfiguratorCommander*) ipConfControllerCommander) setWorkCell:cellElement];
541 [NSApp beginSheet: ipConfigurationSheet
542 modalForWindow: [[self mainView] window]
543 modalDelegate: self
544 didEndSelector: @selector(didEndSheet:returnCode:contextInfo:)
545 contextInfo: nil];
546 }
547
548 // -------------------------------------------------------------------------------
549 // addMoifyCell:
550 // -------------------------------------------------------------------------------
551 - (IBAction) addRemoveCell:(id) sender
552 {
553 switch([((NSControl*) sender) tag]){
554 case ADD_CELL_CONTROL_TAG:
555 {
556 DBCellElement *newCell = [[DBCellElement alloc] init];
557 if(!newCell) break;
558
559 [newCell setCellName:kNewCellName];
560 [newCell setCellComment:kNewCellComment];
561 //cellArray = ;
562 [[afsProperty getCellList] addObject:newCell];
563 [newCell release];
564
565 //Modify new cell
566 [self modifyCell:newCell];
567 }
568 break;
569
570 case REMOVE_CELL_CONTROL_TAG:
571 {
572 int index = 0;
573 NSIndexSet *selectedIndex = [(NSTableView*)cellList selectedRowIndexes];
574 if( [selectedIndex count] > 0) {
575 index = [selectedIndex firstIndex];
576 do {
577 DBCellElement *cellElement = (DBCellElement*)[filteredCellDB objectAtIndex:index];
578 [[afsProperty getCellList] removeObject:cellElement];
579 } while ((index = [selectedIndex indexGreaterThanIndex:index]) != NSNotFound);
580 }
581 }
582 break;
583 }
584 //Filter the cellServDb and allocate filtered array
585 [self searchCellTextEvent:nil];
586 [cellList deselectAll:nil];
587 [cellList reloadData];
588 }
589
590 // -------------------------------------------------------------------------------
591 // startStopAfs:
592 // -------------------------------------------------------------------------------
593 - (IBAction) startStopAfs:(id) sender
594 {
595 BOOL currentAfsState = NO;
596 @try {
597 currentAfsState = [afsProperty checkAfsStatus];
598 // make the parameter to call the root helper app
599 if(currentAfsState){
600 //shutdown afs
601 NSLog(@"Shutting down afs");
602 [afsProperty shutdown];
603 } else {
604 //Start afs
605 NSLog(@"Starting up afs");
606 [afsProperty startup];
607 }
608 [self refreshGui:nil];
609 }
610 @catch (NSException * e) {
611 [self showMessage:[e reason]];
612 }
613 @finally {
614 }
615 }
616
617 // -------------------------------------------------------------------------------
618 // info:
619 // -------------------------------------------------------------------------------
620 - (void) refreshGui:(NSNotification *)notification{
621 BOOL afsIsUp = [afsProperty checkAfsStatus];
622 [self setAfsStatus];
623 [tokensButton setEnabled:afsIsUp];
624 [unlogButton setEnabled:afsIsUp];
625
626 }
627
628 // -------------------------------------------------------------------------------
629 // -(void) refreshTokensNotify:(NSNotification*)notification
630 // -------------------------------------------------------------------------------
631 -(void) refreshTokensNotify:(NSNotification*)notification {
632 [self refreshTokens:nil];
633 }
634
635 // -------------------------------------------------------------------------------
636 // afsVolumeMountChange: Track the afs volume state change
637 // -------------------------------------------------------------------------------
638 // XXX should use mountdir not /afs
639 - (void) afsVolumeMountChange:(NSNotification *)notification{
640 // Check if is mounted or unmounted afs
641 if([[[notification userInfo] objectForKey:@"NSDevicePath"] isEqualToString:@"/afs"]){
642 [self setAfsStatus];
643 [self refreshTokens:nil];
644 }
645 }
646
647 // -------------------------------------------------------------------------------
648 // info:
649 // -------------------------------------------------------------------------------
650 - (IBAction) info:(id) sender
651 {
652 [infoController showHtmlResource:[[self bundle] pathForResource:@"license" ofType:@"rtf"]];
653
654 [NSApp beginSheet: infoSheet
655 modalForWindow: [[self mainView] window]
656 modalDelegate: self
657 didEndSelector: @selector(didEndInfoSheet:returnCode:contextInfo:)
658 contextInfo: nil];
659 }
660
661 // -------------------------------------------------------------------------------
662 // tableDoubleAction:
663 // -------------------------------------------------------------------------------
664 - (IBAction) tableDoubleAction:(id) sender
665 {
666 [self showCellIP:nil];
667 }
668
669 // -------------------------------------------------------------------------------
670 // getNewToken:
671 // -------------------------------------------------------------------------------
672 - (IBAction) getNewToken:(id) sender
673 {
674 BOOL useAklog = [useAklogCheck state] == NSOnState;
675 if(useAklog){
676 //[AFSPropertyManager aklog];
677 [afsProperty getTokens:false
678 usr:nil
679 pwd:nil];
680 [self refreshTokens:nil];
681 //Inform afs menuextra to updata afs status
682 [[NSDistributedNotificationCenter defaultCenter] postNotificationName:kAFSMenuExtraID object:kMExtraAFSStateChange];
683
684 } else {
685 [NSBundle loadNibNamed:@"CredentialPanel" owner:self];
686 [NSApp beginSheet: credentialSheet
687 modalForWindow: [[self mainView] window]
688 modalDelegate: self
689 didEndSelector: @selector(didEndCredentialSheet:returnCode:contextInfo:)
690 contextInfo: nil];
691 }
692 }
693
694
695 // -------------------------------------------------------------------------------
696 // getCurrentCellInDB:
697 // -------------------------------------------------------------------------------
698 - (IBAction) unlog:(id) sender
699 {
700 int index = -1;
701 NSIndexSet *selectedIndex = [tokensTable selectedRowIndexes];
702 if( [selectedIndex count] > 0) {
703 index = [selectedIndex firstIndex];
704 do {
705 NSString *tokenDesc = [tokenList objectAtIndex:index];
706 NSString *cellToUnlog = [tokenDesc estractTokenByDelimiter:@"afs@"
707 endToken:@" "];
708 [afsProperty unlog:cellToUnlog];
709 } while ((index = [selectedIndex indexGreaterThanIndex: index]) != NSNotFound);
710 } else {
711 [afsProperty unlog:nil];
712 }
713 [self refreshTokens:nil];
714 //Inform afs menuextra to updata afs status
715 [[NSDistributedNotificationCenter defaultCenter] postNotificationName:kAFSMenuExtraID object:kMExtraAFSStateChange];
716 }
717
718
719 // -------------------------------------------------------------------------------
720 // aklogSwitchEvent:
721 // -------------------------------------------------------------------------------
722 - (IBAction) aklogSwitchEvent:(id) sender
723 {
724 //afs menu extra is loaded inform it to read preference
725 @try {
726 if(![useAklogCheck state]) {
727 //deselect the checkbox
728 [aklogCredentialAtLoginTime setState:NO];
729 }
730
731 [self writePreferenceFile];
732
733 //Enable disable aklog at login time checkbox according the useAklog checkbox
734 [aklogCredentialAtLoginTime setEnabled:[useAklogCheck state]];
735
736 }
737 @catch (NSException * e) {
738 [self showMessage:[e reason]];
739 }
740 }
741
742 // -------------------------------------------------------------------------------
743 // credentialAtLoginTimeEvent:
744 // -------------------------------------------------------------------------------
745 - (IBAction) credentialAtLoginTimeEvent:(id) sender {
746 [self writePreferenceFile];
747 }
748
749 // -------------------------------------------------------------------------------
750 // afsStartupSwitchEvent:
751 // -------------------------------------------------------------------------------
752 - (IBAction) afsStartupSwitchEvent:(id) sender {
753 NSString *rootHelperApp = [[self bundle] pathForResource:@"afshlp" ofType:@""];
754 //get the new state
755 startAFSAtLogin = [checkButtonAfsAtBootTime state];
756 [PListManager launchctlStringCommandAuth:startAFSAtLogin?@"load":@"unload"
757 option:[NSArray arrayWithObjects:@"-w", nil]
758 plistName:@AFS_DAEMON_PATH
759 helper:rootHelperApp
760 withAuthRef:[[authView authorization] authorizationRef]];
761 }
762
763
764 // -------------------------------------------------------------------------------
765 // afsMenuActivationEvent:
766 // -------------------------------------------------------------------------------
767 - (IBAction) krb5KredentialAtLoginTimeEvent:(id) sender {
768 NSString *rootHelperApp = [[self bundle] pathForResource:@"afshlp" ofType:@""];
769 [PListManager krb5TiketAtLoginTime:[installKRB5AuthAtLoginButton state] helper:rootHelperApp];
770
771 //check if all is gone well
772 [installKRB5AuthAtLoginButton setState:[PListManager checkKrb5AtLoginTimeLaunchdEnable]];
773 }
774
775 // -------------------------------------------------------------------------------
776 // afsMenuActivationEvent:
777 // -------------------------------------------------------------------------------
778 -(IBAction) afsMenuActivationEvent:(id) sender
779 {
780 CFPreferencesSetValue((CFStringRef)PREFERENCE_SHOW_STATUS_MENU,
781 (CFNumberRef)[NSNumber numberWithBool:[(NSButton*)afsMenucheckBox state]],
782 (CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
783
784 CFPreferencesSynchronize((CFStringRef)kAfsCommanderID, kCFPreferencesAnyUser, kCFPreferencesAnyHost);
785 CFPreferencesSynchronize((CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
786
787 //notify the backgrounder
788 [[NSDistributedNotificationCenter defaultCenter] postNotificationName:kAFSMenuExtraID object:kMExtraAFSMenuChangeState];
789 }
790
791 // -------------------------------------------------------------------------------
792 // searchCellTextEvent:
793 // Fileter the CellServDB list according to NSSearch content
794 // -------------------------------------------------------------------------------
795 - (IBAction) searchCellTextEvent:(id) sender
796 {
797 NSString *searchText = [[textSearchField stringValue] lowercaseString]; //filter string
798 [self filterCellServDB:searchText];
799 [((NSTableView*)cellList) reloadData];
800 }
801
802 // -------------------------------------------------------------------------------
803 // clearCellServDBFiltering:
804 // clear the NSSearchField and showw all CellServDB table
805 // -------------------------------------------------------------------------------
806 - (void) clearCellServDBFiltering {
807 //Clear the text search
808 [textSearchField setStringValue:@""];
809 //load the temp array with all cell servdb
810 [self searchCellTextEvent:nil];
811 }
812 // --------------------------------------o-----------------------------------------
813 // filterCellServDB:
814 // make the NSMutableArray with all cellservdb or filtered element
815 // -------------------------------------------------------------------------------
816 - (void) filterCellServDB:(NSString*)textToFilter {
817 DBCellElement *cellElement; //Filtered element
818 BOOL doFilter = !(textToFilter == nil || ([textToFilter length] == 0));
819
820 // We can do filtering and make the temp array
821 if(filteredCellDB){
822 [filteredCellDB release];
823 }
824 filteredCellDB = [[NSMutableArray alloc] init];
825 NSEnumerator *e = [[afsProperty getCellList] objectEnumerator];
826 while(cellElement = (DBCellElement*)[e nextObject]) {
827 // check if the element can be get
828 if(doFilter) {
829 //Get the CellServDB array enumerator
830 NSRange rsltRng = [[[cellElement getCellName] lowercaseString] rangeOfString:textToFilter];
831 if(rsltRng.location != NSNotFound) {
832 //we can add this cell to filtered
833 [filteredCellDB addObject:[cellElement retain]];
834 }
835 } else {
836 [filteredCellDB addObject:[cellElement retain]];
837
838 }
839 }
840 }
841
842 // -------------------------------------------------------------------------------
843 // getCurrentCellInDB:
844 // -------------------------------------------------------------------------------
845 - (DBCellElement*) getCurrentCellInDB
846 {
847 int rowSelected = [cellList selectedRow];
848 return [self getCellByIDX:rowSelected];
849 }
850
851 // -------------------------------------------------------------------------------
852 // getCurrentCellInDB:
853 // -------------------------------------------------------------------------------
854 - (DBCellElement*) getCellByIDX:(int) idx
855 {
856 DBCellElement *cellElement = (DBCellElement*)[filteredCellDB objectAtIndex:idx];
857 return cellElement;
858 }
859
860 // -------------------------------------------------------------------------------
861 // showMessage:
862 // -------------------------------------------------------------------------------
863 -(void) showMessage:(NSString*) message{
864 NSAlert *alert = [[NSAlert alloc] init];
865
866 [alert setMessageText:message];
867 [alert beginSheetModalForWindow:[[self mainView] window]
868 modalDelegate:nil
869 didEndSelector:nil
870 contextInfo:nil];
871 [alert release];
872 }
873
874 // -------------------------------------------------------------------------------
875 // setAfsStatus:
876 // -------------------------------------------------------------------------------
877 -(void) setAfsStatus
878 {
879 BOOL afsIsUp = [afsProperty checkAfsStatus];
880 BOOL afsEnabledAtStartup = NO;
881 NSString *rootHelperApp = [[self bundle] pathForResource:@"afshlp" ofType:@""];
882
883 if ([self isUnlocked]) {
884 afsEnabledAtStartup = (
885 [TaskUtil executeTaskWithAuth:@"/bin/launchctl"
886 arguments:[NSArray arrayWithObjects:@"list",
887 @"org.openafs.filesystems.afs", nil]
888 helper:rootHelperApp
889 withAuthRef:[[authView authorization] authorizationRef]
890 ] == noErr)?YES:NO;
891 [checkButtonAfsAtBootTime setState:afsEnabledAtStartup];
892 }
893
894 [startStopButton setTitle: (afsIsUp?kAfsButtonShutdown:kAfsButtonStartup)];
895
896 NSMutableAttributedString *colorTitle =[[NSMutableAttributedString alloc] initWithAttributedString:[startStopButton attributedTitle]];
897 NSRange titleRange = NSMakeRange(0, [colorTitle length]);
898
899 [colorTitle addAttribute:NSForegroundColorAttributeName
900 value:(afsIsUp?[NSColor redColor]:[NSColor blackColor])
901 range:titleRange];
902
903 [startStopButton setAttributedTitle:colorTitle];
904 if(afsIsUp) {
905 [self startTimer];
906 } else {
907 [self stopTimer];
908 }
909 }
910
911 // -------------------------------------------------------------------------------
912 // refreshToken:
913 // -------------------------------------------------------------------------------
914 - (void) refreshTokens:(NSTimer*)theTimer;
915 {
916 if(![tokensLock tryLock]) return;
917 if(tokenList){
918 [tokenList release];
919 }
920
921 tokenList = [afsProperty getTokenList];
922 [tokensTable reloadData];
923 [tokensLock unlock];
924 }
925
926 // -------------------------------------------------------------------------------
927 // removeExtra:
928 // -------------------------------------------------------------------------------
929 - (IBAction) addLink:(id) sender {
930 [NSBundle loadNibNamed:@"SymLinkEdit" owner:self];
931
932 [NSApp beginSheet: lyncCreationSheet
933 modalForWindow: [[self mainView] window]
934 modalDelegate: self
935 didEndSelector: @selector(didEndSymlinkSheet:returnCode:contextInfo:)
936 contextInfo: nil];
937 }
938
939 // -------------------------------------------------------------------------------
940 // removeExtra:
941 // -------------------------------------------------------------------------------
942 - (IBAction) removeLink:(id) sender {
943 if(!linkConfiguration) return;
944 int index = 0;
945 NSArray *keys = [linkConfiguration allKeys];
946 NSIndexSet *linkToRemove = [tableViewLink selectedRowIndexes];
947 if( [linkToRemove count] > 0) {
948 index = [linkToRemove firstIndex];
949 do {
950 [linkConfiguration removeObjectForKey:[keys objectAtIndex:index]];
951 } while ((index = [linkToRemove indexGreaterThanIndex:index]) != -1);
952 }
953
954 //write the new configuration
955 NSData *prefData = nil;
956 if([linkConfiguration count] > 0) {
957 prefData = [NSPropertyListSerialization dataWithPropertyList:linkConfiguration
958 format:NSPropertyListXMLFormat_v1_0
959 options:0
960 error:nil];
961 }
962 CFPreferencesSetValue((CFStringRef)PREFERENCE_LINK_CONFIGURATION,
963 (CFDataRef)prefData,
964 (CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
965
966 CFPreferencesSynchronize((CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
967
968 //reload the new data
969 [tableViewLink reloadData];
970 }
971
972 // -------------------------------------------------------------------------------
973 // removeExtra:
974 // -------------------------------------------------------------------------------
975 - (IBAction) enableLink:(id) sender {
976 [self writePreferenceFile];
977 }
978
979 // -------------------------------------------------------------------------------
980 // removeExtra:
981 // -------------------------------------------------------------------------------
982 - (IBAction) manageBackgrounderActivation:(id)sender {
983 [PListManager launchctlCommand:[(NSButton*)sender state]
984 userDomain:YES
985 option:[NSArray arrayWithObjects:@"-S", @"Aqua", nil]
986 plistName:[NSString stringWithFormat:@"%@.plist", BACKGROUNDER_P_FILE]];
987 //read the status to check that all is gone well
988 [backgrounderActivationCheck setState:[PListManager launchdJobState:BACKGROUNDER_P_FILE]];
989 }
990
991 // -------------------------------------------------------------------------------
992 // tableViewLinkPerformClick:
993 // -------------------------------------------------------------------------------
994 - (IBAction) tableViewLinkPerformClick:(id) sender {
995 NSLog(@"tableViewLinkPerformClick");
996 }
997
998 // -------------------------------------------------------------------------------
999 // - (void)tabView:(NSTabView *)tabView willSelectTabViewItem: (NSTabViewItem *)tabViewItem
1000 // -------------------------------------------------------------------------------
1001 - (void)tabView:(NSTabView *)tabView willSelectTabViewItem: (NSTabViewItem *)tabViewItem
1002 {
1003 //check to see if the cache param tab is the tab that will be selected
1004 if([((NSString*)[tabViewItem identifier]) intValue] == TAB_LINK)
1005 {
1006 [tableViewLink reloadData];
1007 }
1008 }
1009 // -------------------------------------------------------------------------------
1010 // tableViewLinkPerformClick:
1011 // -------------------------------------------------------------------------------
1012 - (IBAction) enableDisableKrb5RenewCheck:(id) sender {
1013 //NSLog(@"enableDisableKrb5RenewCheck");
1014 CFPreferencesSetValue((CFStringRef)PREFERENCE_KRB5_CHECK_ENABLE,
1015 (CFNumberRef) [NSNumber numberWithInt:[(NSButton*)sender intValue]],
1016 (CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
1017 CFPreferencesSynchronize((CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
1018 //notify the backgrounder
1019 [[NSDistributedNotificationCenter defaultCenter] postNotificationName:kAFSMenuExtraID object:kPrefChangeNotification];
1020 }
1021 // -------------------------------------------------------------------------------
1022 // tableViewLinkPerformClick:
1023 // -------------------------------------------------------------------------------
1024 - (IBAction) krb5RenewParamChange:(id) sender {
1025 }
1026
1027
1028 - (BOOL)isUnlocked {
1029 return [authView authorizationState] == SFAuthorizationViewUnlockedState;
1030 }
1031
1032 - (void)authorizationViewDidAuthorize:(SFAuthorizationView *)view {
1033 // enable things
1034 [startStopButton setEnabled:[self isUnlocked]];
1035 [checkButtonAfsAtBootTime setEnabled:[self isUnlocked]];
1036 [self setAfsStatus];
1037 [installKRB5AuthAtLoginButton setEnabled:[self isUnlocked]];
1038 }
1039
1040 - (void)authorizationViewDidDeauthorize:(SFAuthorizationView *)view {
1041 // disable things
1042 [startStopButton setEnabled:[self isUnlocked]];
1043 [checkButtonAfsAtBootTime setEnabled:[self isUnlocked]];
1044 [installKRB5AuthAtLoginButton setEnabled:[self isUnlocked]];
1045 }
1046 @end
1047
1048 @implementation AFSCommanderPref (NSTableDataSource)
1049
1050
1051 // -------------------------------------------------------------------------------
1052 // tableView:
1053 // Manage the checkbox of CellServDB Table
1054
1055 // -------------------------------------------------------------------------------
1056 - (void)tableView:(NSTableView *)table
1057 setObjectValue:(id)data
1058 forTableColumn:(NSTableColumn *)col
1059 row:(int)row
1060 {
1061 NSString *identifier = (NSString*)[col identifier];
1062 switch([table tag]){
1063 case TABLE_TOKENS_LIST:
1064 break;
1065
1066 case TABLE_CELL_LIST:
1067 // we are editing checkbox for cellservdb table
1068 if([identifier intValue] == CELLSRVDB_TABLE_USR_DFLT_CHECK_COLUMN) {
1069 // set the user default cell
1070 DBCellElement *cellElement = (DBCellElement*)[filteredCellDB objectAtIndex:row];
1071 [afsProperty setDefaultCellByName:[cellElement getCellName]];
1072 //[afsDefaultCellLabel setStringValue:[afsProperty getDefaultCellName]];
1073 [((NSTableView*)cellList) reloadData];
1074 } else if([identifier intValue] == CELLSRVDB_TABLE_DFLT_CHECK_COLUMN) {
1075 // set the cell for wich the user want to get token
1076 DBCellElement *cellElement = (DBCellElement*)[filteredCellDB objectAtIndex:row];
1077 [cellElement setUserDefaultForToken:![cellElement userDefaultForToken]];
1078 }
1079 break;
1080 }
1081 }
1082
1083
1084 // -------------------------------------------------------------------------------
1085 // tableView:
1086 // refresh delegate method for two AFSCommander table
1087 // -------------------------------------------------------------------------------
1088 - (id) tableView:(NSTableView *) aTableView
1089 objectValueForTableColumn:(NSTableColumn *) aTableColumn
1090 row:(int) rowIndex
1091 {
1092 id result = nil;
1093 NSString *identifier = (NSString*)[aTableColumn identifier];
1094 switch([aTableView tag]){
1095 case TABLE_TOKENS_LIST:
1096 //We are refreshing tokens table
1097 result = [self getTableTokensListValue:[identifier intValue] row:rowIndex];
1098 break;
1099
1100 case TABLE_CELL_LIST:
1101 //We are refreshing cell db table
1102 result = [self getTableCelListValue:[identifier intValue] row:rowIndex];
1103 break;
1104
1105 case TABLE_LINK_LIST:
1106 result = [self getTableLinkValue:[identifier intValue] row:rowIndex];
1107 break;
1108 }
1109 return result;
1110 }
1111
1112
1113 // -------------------------------------------------------------------------------
1114 // getTableCelListValue:
1115 // -------------------------------------------------------------------------------
1116 - (id)getTableTokensListValue:(int) colId row:(int)row
1117 {
1118 id result = nil;
1119 if(!tokenList) return nil;
1120 switch(colId){
1121 case 0:
1122 result = (NSString*)[tokenList objectAtIndex:row];
1123 break;
1124 }
1125 return result;
1126 }
1127
1128
1129 // -------------------------------------------------------------------------------
1130 // getTableCelListValue:
1131 // -------------------------------------------------------------------------------
1132 - (id)getTableCelListValue:(int) colId row:(int)row
1133 {
1134 id result = nil;
1135 //NSMutableArray *cellArray = [afsProperty getCellList];
1136 DBCellElement *cellElement = (DBCellElement*)[filteredCellDB objectAtIndex:row];
1137 switch(colId){
1138 case CELLSRVDB_TABLE_USR_DFLT_CHECK_COLUMN:
1139 result = [NSNumber numberWithInt:[cellElement userDefaultForCell]];
1140 break;
1141
1142 case CELLSRVDB_TABLE_DFLT_CHECK_COLUMN:
1143 result = [NSNumber numberWithInt:[cellElement userDefaultForToken]];
1144 break;
1145 case CELLSRVDB_TABLE_NAME_COLUMN:
1146 result = [cellElement getCellName];
1147 break;
1148
1149 case CELLSRVDB_TABLE_DESCRIPTION_COLUMN:
1150 result = [cellElement getCellComment];
1151 break;
1152 }
1153 return result;
1154 }
1155
1156 // -------------------------------------------------------------------------------
1157 // getTableCelListValue:
1158 // -------------------------------------------------------------------------------
1159 - (id)getTableLinkValue:(int) colId row:(int)row
1160 {
1161 id result = nil;
1162 NSArray *allKey = [linkConfiguration allKeys];
1163 switch(colId){
1164 case TABLE_COLUMN_LINK_NAME:
1165 result = [allKey objectAtIndex:row];
1166 break;
1167
1168 case TABLE_COLUMN_LINK_PATH:
1169 result = [linkConfiguration objectForKey:[allKey objectAtIndex:row]];
1170 break;
1171 }
1172 return result;
1173 }
1174
1175
1176 // -------------------------------------------------------------------------------
1177 // numberOfRowsInTableView:
1178 // -------------------------------------------------------------------------------
1179 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
1180 {
1181 int rowCount = 0;
1182 switch([aTableView tag]){
1183 case TABLE_TOKENS_LIST:
1184 if(tokenList) rowCount = [tokenList count];
1185 break;
1186
1187 case TABLE_CELL_LIST:
1188 if(filteredCellDB) rowCount = [filteredCellDB count];
1189 break;
1190
1191 case TABLE_LINK_LIST:
1192 if(linkConfiguration) rowCount = [linkConfiguration count];
1193 break;
1194 }
1195 return rowCount;
1196 }
1197 @end
1198
1199
1200 @implementation AFSCommanderPref (TableDelegate)
1201 // -------------------------------------------------------------------------------
1202 // selectionShouldChangeInTableView:
1203 // -------------------------------------------------------------------------------
1204 - (BOOL)selectionShouldChangeInTableView:(NSTableView *)aTable
1205 {
1206 switch([aTable tag]){
1207 case TABLE_TOKENS_LIST:
1208 break;
1209
1210 case TABLE_CELL_LIST:
1211 [self tableViewCellmanageButtonState:[aTable selectedRow]];
1212 break;
1213
1214 case TABLE_LINK_LIST:
1215 break;
1216
1217
1218 }
1219
1220 return YES;
1221 }
1222
1223 // -------------------------------------------------------------------------------
1224 // tableView:
1225 // -------------------------------------------------------------------------------
1226 - (BOOL)tableView:(NSTableView *)aTable shouldSelectRow:(int)aRow
1227 {
1228 switch([aTable tag]){
1229 case TABLE_TOKENS_LIST:
1230 break;
1231
1232 case TABLE_CELL_LIST:
1233 [self tableViewCellmanageButtonState:aRow];
1234 break;
1235
1236 case TABLE_LINK_LIST:
1237 break;
1238 }
1239 return YES;
1240 }
1241
1242 // -------------------------------------------------------------------------------
1243 // tableView:
1244 // -------------------------------------------------------------------------------
1245 - (void)tableViewSelectionDidChange:(NSNotification *)aNotification {
1246 NSTableView *aTable = [aNotification object];
1247 switch([aTable tag]){
1248 case TABLE_TOKENS_LIST:
1249 break;
1250
1251 case TABLE_CELL_LIST:
1252 break;
1253
1254 case TABLE_LINK_LIST:
1255 [self tableViewLinkmanageButtonState:[aTable selectedRowIndexes]];
1256 break;
1257 }
1258 }
1259 // -------------------------------------------------------------------------------
1260 // manageButtonState:
1261 // -------------------------------------------------------------------------------
1262 -(void) tableViewCellmanageButtonState:(int) rowSelected {
1263 [cellIpButton setEnabled:rowSelected >= 0];
1264 [removeCellButton setEnabled:rowSelected >= 0];
1265 }
1266
1267 // -------------------------------------------------------------------------------
1268 // manageButtonState:
1269 // -------------------------------------------------------------------------------
1270 -(void) tableViewLinkmanageButtonState:(NSIndexSet *) rowsSelectedIndex {
1271 [buttonRemoveLink setEnabled:[rowsSelectedIndex count]>0];
1272 }
1273 @end
1274
1275
1276 @implementation AFSCommanderPref (ModalDelegate)
1277 // -------------------------------------------------------------------------------
1278 // didEndSheet:
1279 // -------------------------------------------------------------------------------
1280 - (void)didEndSheet:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
1281 {
1282 [sheet orderOut:self];
1283 //Filter the cellServDb and allocate filtered array
1284 [self searchCellTextEvent:nil];
1285 [cellList reloadData];
1286 }
1287
1288 // -------------------------------------------------------------------------------
1289 // Klog credential request
1290 // -------------------------------------------------------------------------------
1291 - (void)didEndCredentialSheet:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
1292 {
1293 if([((TokenCredentialController*)credentialCommander) takenToken] == YES){
1294 /*[AFSPropertyManager klog:[((TokenCredentialController*)credentialCommander) uName]
1295 uPwd:[((TokenCredentialController*)credentialCommander) uPwd] ];*/
1296 [afsProperty getTokens:true
1297 usr:[((TokenCredentialController*)credentialCommander) uName]
1298 pwd:[((TokenCredentialController*)credentialCommander) uPwd]];
1299 }
1300 [sheet orderOut:self];
1301 [self refreshTokens:nil];
1302 //Inform afs menuextra to updata afs status
1303 [[NSDistributedNotificationCenter defaultCenter] postNotificationName:kAFSMenuExtraID object:kMExtraAFSStateChange];
1304 }
1305
1306 // -------------------------------------------------------------------------------
1307 // Klog credential request
1308 // -------------------------------------------------------------------------------
1309 - (void)didEndInfoSheet:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
1310 {
1311 [sheet orderOut:self];
1312 }
1313
1314 // -------------------------------------------------------------------------------
1315 // symlink edite
1316 // -------------------------------------------------------------------------------
1317 - (void)didEndSymlinkSheet:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
1318 {
1319 [lyncCreationSheet orderOut:self];
1320 [self readPreferenceFile];
1321 [tableViewLink reloadData];
1322 }
1323 @end