unison

Fork of Unison, a bi-directional file synchronization tool
git clone git://git.laack.co/unison.git
Log | Files | Refs | README | LICENSE

PreferencesController.m (2876B)


      1 #import "PreferencesController.h"
      2 #import "Bridge.h"
      3 
      4 @implementation PreferencesController
      5 
      6 - (void)reset
      7 {
      8     [profileNameText setStringValue:@""];
      9     [firstRootText setStringValue:@""];
     10     [secondRootUser setStringValue:@""];
     11     [secondRootHost setStringValue:@""];
     12     [secondRootText setStringValue:@""];
     13     [remoteButtonCell setState:NSOnState];
     14     [localButtonCell setState:NSOffState];
     15     [secondRootUser setSelectable:YES];
     16     [secondRootUser setEditable:YES];
     17     [secondRootHost setSelectable:YES];
     18     [secondRootHost setEditable:YES];
     19 }
     20 
     21 - (BOOL)validatePrefs
     22 {
     23     NSString *profileName = [profileNameText stringValue];
     24     if ((profileName == nil) | [profileName isEqualTo:@""]) {
     25         // FIX: should check for already existing names too
     26         NSRunAlertPanel(@"Error",@"You must enter a profile name",@"OK",nil,nil);
     27         return NO;
     28     }
     29     NSString *firstRoot = [firstRootText stringValue];
     30     if ((firstRoot == nil) | [firstRoot isEqualTo:@""]) {
     31         NSRunAlertPanel(@"Error",@"You must enter a first root",@"OK",nil,nil);
     32         return NO;
     33     }
     34     NSString *secondRoot;
     35     if ([remoteButtonCell state] == NSOnState) {
     36         NSString *user = [secondRootUser stringValue];
     37         if ((user == nil) | [user isEqualTo:@""]) {
     38             NSRunAlertPanel(@"Error",@"You must enter a user",@"OK",nil,nil);
     39             return NO;
     40         }
     41         NSString *host = [secondRootHost stringValue];
     42         if ((host == nil) | [host isEqualTo:@""]) {
     43             NSRunAlertPanel(@"Error",@"You must enter a host",@"OK",nil,nil);
     44             return NO;
     45         }
     46         NSString *file = [secondRootText stringValue];
     47         // OK for empty file, e.g., ssh://foo@bar/
     48         secondRoot = [NSString stringWithFormat:@"ssh://%@@%@/%@",user,host,file];
     49     }
     50     else {
     51         secondRoot = [secondRootText stringValue];
     52         if ((secondRoot == nil) | [secondRoot isEqualTo:@""]) {
     53             NSRunAlertPanel(@"Error",@"You must enter a second root file",@"OK",nil,nil);
     54             return NO;
     55         }
     56     }
     57         ocamlCall("xSSS", "unisonProfileInit", profileName, firstRoot, secondRoot);
     58     return YES;
     59 }
     60 
     61 /* The target when enter is pressed in any of the text fields */
     62 // FIX: this is broken, it takes tab, mouse clicks, etc.
     63 - (IBAction)anyEnter:(id)sender
     64 {
     65     NSLog(@"enter");
     66     [self validatePrefs];
     67 }
     68 
     69 - (IBAction)localClick:(id)sender
     70 {
     71     NSLog(@"local");
     72     [secondRootUser setStringValue:@""];
     73     [secondRootHost setStringValue:@""];
     74     [secondRootUser setSelectable:NO];
     75     [secondRootUser setEditable:NO];
     76     [secondRootHost setSelectable:NO];
     77     [secondRootHost setEditable:NO];
     78 }
     79 
     80 - (IBAction)remoteClick:(id)sender
     81 {
     82     NSLog(@"remote");
     83     [secondRootUser setSelectable:YES];
     84     [secondRootUser setEditable:YES];
     85     [secondRootHost setSelectable:YES];
     86     [secondRootHost setEditable:YES];
     87 }
     88 
     89 @end