Alexander Afanasyev | 14b0948 | 2013-10-11 18:24:45 +0200 | [diff] [blame] | 1 | /* -*- Mode: objc; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
Ilya Moiseenko | 1dc76da | 2013-09-30 11:53:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * @copyright See LICENCE for copyright and license information. |
| 4 | * |
| 5 | * @author Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 6 | * @author Ilya Moiseenko <iliamo@ucla.edu> |
| 7 | */ |
| 8 | |
Ilya Moiseenko | 6819250 | 2013-09-30 14:27:48 -0700 | [diff] [blame] | 9 | #include "config.h" |
Ilya Moiseenko | 1dc76da | 2013-09-30 11:53:36 -0700 | [diff] [blame] | 10 | #import "preference-delegate.h" |
Alexander Afanasyev | 4e1c7e9 | 2013-10-11 18:25:09 +0200 | [diff] [blame] | 11 | #import "menu-delegate.h" |
Ilya Moiseenko | 1dc76da | 2013-09-30 11:53:36 -0700 | [diff] [blame] | 12 | |
| 13 | @implementation PreferenceDelegate |
| 14 | |
| 15 | -(IBAction)showPreferencesPanel:(id)sender |
| 16 | { |
| 17 | [preferencesPanel setContentView:generalSettingsView]; |
| 18 | [preferencesPanel makeKeyAndOrderFront:sender]; |
| 19 | [preferencesPanel setLevel: NSStatusWindowLevel]; |
Ilya Moiseenko | b4aca05 | 2013-10-06 15:10:19 -0700 | [diff] [blame] | 20 | |
Ilya Moiseenko | b4aca05 | 2013-10-06 15:10:19 -0700 | [diff] [blame] | 21 | tableController.m_tableView = fibTableView; |
Ilya Moiseenko | 1dc76da | 2013-09-30 11:53:36 -0700 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | -(IBAction)openGeneralSettings:(id)sender |
| 25 | { |
| 26 | [preferencesPanel setContentView:generalSettingsView]; |
| 27 | } |
| 28 | |
| 29 | -(IBAction)openForwardingSettings:(id)sender |
| 30 | { |
| 31 | [preferencesPanel setContentView:forwardingSettingsView]; |
| 32 | } |
| 33 | |
| 34 | -(IBAction)openSecuritySettings:(id)sender |
| 35 | { |
| 36 | [preferencesPanel setContentView:securitySettingsView]; |
| 37 | } |
| 38 | |
| 39 | -(IBAction)switchSoftwareUpdates:(id)sender |
| 40 | { |
| 41 | if ([(NSButton*)sender state] == NSOnState) |
| 42 | { |
| 43 | _allowSoftwareUpdates = true; |
| 44 | } |
| 45 | else |
| 46 | { |
| 47 | _allowSoftwareUpdates = false; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | -(IBAction)switchHubDiscovery:(id)sender |
| 52 | { |
| 53 | if ([(NSButton*)sender state] == NSOnState) |
| 54 | { |
| 55 | _enableHubDiscovery = true; |
| 56 | } |
| 57 | else |
| 58 | { |
| 59 | _enableHubDiscovery = false; |
| 60 | } |
| 61 | } |
| 62 | |
Ilya Moiseenko | b4aca05 | 2013-10-06 15:10:19 -0700 | [diff] [blame] | 63 | -(void)updateFibStatus:(NSXMLDocument*)status; |
Ilya Moiseenko | e7058e7 | 2013-10-02 15:56:45 -0700 | [diff] [blame] | 64 | { |
Ilya Moiseenko | b4aca05 | 2013-10-06 15:10:19 -0700 | [diff] [blame] | 65 | [tableController loadStatus:status]; |
| 66 | [fibTableView reloadData]; |
Ilya Moiseenko | e7058e7 | 2013-10-02 15:56:45 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Ilya Moiseenko | 6819250 | 2013-09-30 14:27:48 -0700 | [diff] [blame] | 69 | -(IBAction)addFibEntry:(id)sender |
| 70 | { |
| 71 | [NSApp endSheet:prefixRegistrationSheet]; |
| 72 | [prefixRegistrationSheet orderOut:sender]; |
| 73 | |
Ilya Moiseenko | 6819250 | 2013-09-30 14:27:48 -0700 | [diff] [blame] | 74 | NSString *prefixName = [namePrefixText stringValue]; |
Ilya Moiseenko | b4aca05 | 2013-10-06 15:10:19 -0700 | [diff] [blame] | 75 | NSString *tunnelType = [tunnelCombobox itemObjectValueAtIndex:[tunnelCombobox indexOfSelectedItem]]; |
| 76 | NSString *endpoint = [endpointText stringValue]; |
Alexander Afanasyev | 4e1c7e9 | 2013-10-11 18:25:09 +0200 | [diff] [blame] | 77 | |
| 78 | NSOperation *operation = [NSBlockOperation blockOperationWithBlock:^{ |
Ilya Moiseenko | b4aca05 | 2013-10-06 15:10:19 -0700 | [diff] [blame] | 79 | NSTask *task = [[NSTask alloc] init]; |
| 80 | [task setLaunchPath: @NDND_FIB_COMMAND]; |
| 81 | [task setArguments: [NSArray arrayWithObjects: @"add", prefixName, tunnelType, endpoint, nil]]; |
| 82 | [task launch]; |
| 83 | [task waitUntilExit]; |
| 84 | }]; |
Ilya Moiseenko | 6819250 | 2013-09-30 14:27:48 -0700 | [diff] [blame] | 85 | |
Alexander Afanasyev | 4e1c7e9 | 2013-10-11 18:25:09 +0200 | [diff] [blame] | 86 | [(MenuDelegate*)[[NSApplication sharedApplication] delegate] updateStatusWithDependency:operation]; |
Ilya Moiseenko | 6819250 | 2013-09-30 14:27:48 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | -(IBAction)removeFibEntry:(id)sender |
| 90 | { |
Ilya Moiseenko | b4aca05 | 2013-10-06 15:10:19 -0700 | [diff] [blame] | 91 | NSInteger selectedRow = [fibTableView selectedRow]; |
| 92 | |
| 93 | if(selectedRow == -1) |
| 94 | return; |
| 95 | |
| 96 | NSString *faceID = [tableController getFaceByRowIndex:selectedRow]; |
| 97 | if (faceID == nil) |
| 98 | return; |
Ilya Moiseenko | 6819250 | 2013-09-30 14:27:48 -0700 | [diff] [blame] | 99 | |
Ilya Moiseenko | b4aca05 | 2013-10-06 15:10:19 -0700 | [diff] [blame] | 100 | NSString *prefix = [tableController getPrefixByRowIndex:selectedRow]; |
| 101 | if (prefix == nil) |
| 102 | return; |
| 103 | |
Alexander Afanasyev | 4e1c7e9 | 2013-10-11 18:25:09 +0200 | [diff] [blame] | 104 | NSOperation *operation = [NSBlockOperation blockOperationWithBlock:^{ |
Ilya Moiseenko | b4aca05 | 2013-10-06 15:10:19 -0700 | [diff] [blame] | 105 | NSTask *task = [[NSTask alloc] init]; |
| 106 | [task setLaunchPath: @NDND_FIB_COMMAND]; |
| 107 | [task setArguments: [NSArray arrayWithObjects: @"del", prefix, @"face", faceID, nil]]; |
| 108 | [task launch]; |
| 109 | [task waitUntilExit]; |
| 110 | }]; |
Alexander Afanasyev | 4e1c7e9 | 2013-10-11 18:25:09 +0200 | [diff] [blame] | 111 | |
| 112 | [(MenuDelegate*)[[NSApplication sharedApplication] delegate] updateStatusWithDependency:operation]; |
Ilya Moiseenko | 6819250 | 2013-09-30 14:27:48 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | - (IBAction) showFibEntrySheet:(id)sender |
| 116 | { |
Ilya Moiseenko | b4aca05 | 2013-10-06 15:10:19 -0700 | [diff] [blame] | 117 | [NSApp beginSheet:prefixRegistrationSheet |
Ilya Moiseenko | 6819250 | 2013-09-30 14:27:48 -0700 | [diff] [blame] | 118 | modalForWindow:preferencesPanel |
| 119 | modalDelegate:self |
| 120 | didEndSelector:nil |
| 121 | contextInfo:nil]; |
| 122 | |
Ilya Moiseenko | b4aca05 | 2013-10-06 15:10:19 -0700 | [diff] [blame] | 123 | [tunnelCombobox selectItemAtIndex:0]; |
Ilya Moiseenko | 6819250 | 2013-09-30 14:27:48 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | -(IBAction)hideFibEntrySheet:(id)sender |
| 127 | { |
Ilya Moiseenko | b4aca05 | 2013-10-06 15:10:19 -0700 | [diff] [blame] | 128 | [NSApp endSheet:prefixRegistrationSheet]; |
| 129 | [prefixRegistrationSheet orderOut:sender]; |
Ilya Moiseenko | 6819250 | 2013-09-30 14:27:48 -0700 | [diff] [blame] | 130 | } |
Ilya Moiseenko | 1dc76da | 2013-09-30 11:53:36 -0700 | [diff] [blame] | 131 | |
Ilya Moiseenko | e7058e7 | 2013-10-02 15:56:45 -0700 | [diff] [blame] | 132 | |
| 133 | -(IBAction)openRoutingStatusPage:(id)sender |
| 134 | { |
| 135 | NSURL *pageURL = [NSURL URLWithString:@"http://netlab.cs.memphis.edu/script/htm/status.htm"]; |
| 136 | |
| 137 | [[NSWorkspace sharedWorkspace] openURL: pageURL]; |
| 138 | } |
| 139 | |
| 140 | -(IBAction)openTrafficMapPage:(id)sender |
| 141 | { |
| 142 | |
| 143 | NSURL *pageURL = [NSURL URLWithString:@"http://ndnmap.arl.wustl.edu"]; |
| 144 | |
| 145 | [[NSWorkspace sharedWorkspace] openURL: pageURL]; |
| 146 | } |
| 147 | |
| 148 | |
Ilya Moiseenko | 1dc76da | 2013-09-30 11:53:36 -0700 | [diff] [blame] | 149 | @end |