blob: f0c83c7aa6212464d0decb0e749dba46b7f22cbe [file] [log] [blame]
Alexander Afanasyev14b09482013-10-11 18:24:45 +02001/* -*- Mode: objc; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
Ilya Moiseenko1dc76da2013-09-30 11:53:36 -07002/*
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 Moiseenko68192502013-09-30 14:27:48 -07009#include "config.h"
Ilya Moiseenko1dc76da2013-09-30 11:53:36 -070010#import "preference-delegate.h"
Alexander Afanasyev4e1c7e92013-10-11 18:25:09 +020011#import "menu-delegate.h"
Ilya Moiseenko1dc76da2013-09-30 11:53:36 -070012
13@implementation PreferenceDelegate
14
15-(IBAction)showPreferencesPanel:(id)sender
16{
17 [preferencesPanel setContentView:generalSettingsView];
18 [preferencesPanel makeKeyAndOrderFront:sender];
19 [preferencesPanel setLevel: NSStatusWindowLevel];
Ilya Moiseenkob4aca052013-10-06 15:10:19 -070020
Ilya Moiseenkob4aca052013-10-06 15:10:19 -070021 tableController.m_tableView = fibTableView;
Ilya Moiseenko1dc76da2013-09-30 11:53:36 -070022}
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 Moiseenkob4aca052013-10-06 15:10:19 -070063-(void)updateFibStatus:(NSXMLDocument*)status;
Ilya Moiseenkoe7058e72013-10-02 15:56:45 -070064{
Ilya Moiseenkob4aca052013-10-06 15:10:19 -070065 [tableController loadStatus:status];
66 [fibTableView reloadData];
Ilya Moiseenkoe7058e72013-10-02 15:56:45 -070067}
68
Ilya Moiseenko68192502013-09-30 14:27:48 -070069-(IBAction)addFibEntry:(id)sender
70{
71 [NSApp endSheet:prefixRegistrationSheet];
72 [prefixRegistrationSheet orderOut:sender];
73
Ilya Moiseenko68192502013-09-30 14:27:48 -070074 NSString *prefixName = [namePrefixText stringValue];
Ilya Moiseenkob4aca052013-10-06 15:10:19 -070075 NSString *tunnelType = [tunnelCombobox itemObjectValueAtIndex:[tunnelCombobox indexOfSelectedItem]];
76 NSString *endpoint = [endpointText stringValue];
Alexander Afanasyev4e1c7e92013-10-11 18:25:09 +020077
78 NSOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
Ilya Moiseenkob4aca052013-10-06 15:10:19 -070079 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 Moiseenko68192502013-09-30 14:27:48 -070085
Alexander Afanasyev4e1c7e92013-10-11 18:25:09 +020086 [(MenuDelegate*)[[NSApplication sharedApplication] delegate] updateStatusWithDependency:operation];
Ilya Moiseenko68192502013-09-30 14:27:48 -070087}
88
89-(IBAction)removeFibEntry:(id)sender
90{
Ilya Moiseenkob4aca052013-10-06 15:10:19 -070091 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 Moiseenko68192502013-09-30 14:27:48 -070099
Ilya Moiseenkob4aca052013-10-06 15:10:19 -0700100 NSString *prefix = [tableController getPrefixByRowIndex:selectedRow];
101 if (prefix == nil)
102 return;
103
Alexander Afanasyev4e1c7e92013-10-11 18:25:09 +0200104 NSOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
Ilya Moiseenkob4aca052013-10-06 15:10:19 -0700105 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 Afanasyev4e1c7e92013-10-11 18:25:09 +0200111
112 [(MenuDelegate*)[[NSApplication sharedApplication] delegate] updateStatusWithDependency:operation];
Ilya Moiseenko68192502013-09-30 14:27:48 -0700113}
114
115- (IBAction) showFibEntrySheet:(id)sender
116{
Ilya Moiseenkob4aca052013-10-06 15:10:19 -0700117 [NSApp beginSheet:prefixRegistrationSheet
Ilya Moiseenko68192502013-09-30 14:27:48 -0700118 modalForWindow:preferencesPanel
119 modalDelegate:self
120 didEndSelector:nil
121 contextInfo:nil];
122
Ilya Moiseenkob4aca052013-10-06 15:10:19 -0700123 [tunnelCombobox selectItemAtIndex:0];
Ilya Moiseenko68192502013-09-30 14:27:48 -0700124}
125
126-(IBAction)hideFibEntrySheet:(id)sender
127{
Ilya Moiseenkob4aca052013-10-06 15:10:19 -0700128 [NSApp endSheet:prefixRegistrationSheet];
129 [prefixRegistrationSheet orderOut:sender];
Ilya Moiseenko68192502013-09-30 14:27:48 -0700130}
Ilya Moiseenko1dc76da2013-09-30 11:53:36 -0700131
Ilya Moiseenkoe7058e72013-10-02 15:56:45 -0700132
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 Moiseenko1dc76da2013-09-30 11:53:36 -0700149@end