Develop Kerberos renew system for ticket
[openafs.git] / src / platform / DARWIN / AFSPreference / LynkCreationController.m
1 //
2 //  LynkCreationController.m
3 //  OpenAFS
4 //
5 //  Created by MacDeveloper on 03/06/08.
6 //  Copyright 2008 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "LynkCreationController.h"
10 #import "global.h"
11
12 @implementation LynkCreationController
13
14 -(NSPanel*)getView {
15         return lynkCreationSheet;
16 }
17
18 - (IBAction) save:(id) sender {
19         NSMutableDictionary *linkConfiguration = nil;
20         if([[[textFieldLinkDestPath stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length] == 0 ||
21            [[[textfieldLinkName stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length] == 0 )
22                 return;
23         
24         //load all configuration
25         NSData *prefData = (NSData*)CFPreferencesCopyValue((CFStringRef)PREFERENCE_LINK_CONFIGURATION,  (CFStringRef)kAfsCommanderID,  kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
26         if(prefData) {
27                 linkConfiguration = [NSPropertyListSerialization propertyListFromData:prefData
28                                                                                                                          mutabilityOption:NSPropertyListMutableContainers
29                                                                                                                                            format:nil
30                                                                                                                          errorDescription:nil];
31         } else {
32                 linkConfiguration = [NSMutableDictionary dictionaryWithCapacity:1];
33         }
34
35         [linkConfiguration setObject:[textFieldLinkDestPath stringValue] 
36                                                   forKey:[textfieldLinkName stringValue]];
37         
38         //save new configuration
39         prefData = [NSPropertyListSerialization dataWithPropertyList:linkConfiguration
40                                                                                                                   format:NSPropertyListXMLFormat_v1_0
41                                                                                                                  options:0
42                                                                                                                    error:nil];
43         CFPreferencesSetValue((CFStringRef)PREFERENCE_LINK_CONFIGURATION,
44                                                   (CFDataRef)prefData,
45                                                   (CFStringRef)kAfsCommanderID,  kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
46         CFPreferencesSynchronize((CFStringRef)kAfsCommanderID,  kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
47         [NSApp endSheet:lynkCreationSheet];
48 }
49
50 - (IBAction) cancell:(id) sender{
51         [NSApp endSheet:lynkCreationSheet];
52 }
53
54 - (IBAction) selectLinkDest:(id) sender {
55         NSOpenPanel *openPanel = [NSOpenPanel openPanel];
56         [openPanel setCanChooseFiles:NO];
57         [openPanel setCanChooseDirectories:YES];
58         [openPanel setAllowsMultipleSelection:NO];
59         choiceResult = [openPanel runModalForTypes:nil];
60         switch(choiceResult){
61                 case NSOKButton:
62                         if([[openPanel filenames] count] == 1)  {
63                                 [textFieldLinkDestPath setStringValue:[[openPanel filenames] objectAtIndex:0]];
64                         }
65                         break;
66                         
67                 case NSCancelButton:
68                         [textFieldLinkDestPath setStringValue:@""];
69                         break;
70         }
71 }
72 @end