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