blob: b6a66865443a08b9e3bb356dcd03e2579ab47b9c [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
Ilya Moiseenkob4aca052013-10-06 15:10:19 -070039-(void)updateFibStatus:(NSXMLDocument*)status;
Ilya Moiseenkoe7058e72013-10-02 15:56:45 -070040{
Ilya Moiseenkob4aca052013-10-06 15:10:19 -070041 [tableController loadStatus:status];
42 [fibTableView reloadData];
Ilya Moiseenkoe7058e72013-10-02 15:56:45 -070043}
44
Ilya Moiseenko68192502013-09-30 14:27:48 -070045-(IBAction)addFibEntry:(id)sender
46{
47 [NSApp endSheet:prefixRegistrationSheet];
48 [prefixRegistrationSheet orderOut:sender];
49
Ilya Moiseenko68192502013-09-30 14:27:48 -070050 NSString *prefixName = [namePrefixText stringValue];
Ilya Moiseenkob4aca052013-10-06 15:10:19 -070051 NSString *tunnelType = [tunnelCombobox itemObjectValueAtIndex:[tunnelCombobox indexOfSelectedItem]];
52 NSString *endpoint = [endpointText stringValue];
Alexander Afanasyev4e1c7e92013-10-11 18:25:09 +020053
54 NSOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
Ilya Moiseenkob4aca052013-10-06 15:10:19 -070055 NSTask *task = [[NSTask alloc] init];
56 [task setLaunchPath: @NDND_FIB_COMMAND];
57 [task setArguments: [NSArray arrayWithObjects: @"add", prefixName, tunnelType, endpoint, nil]];
58 [task launch];
59 [task waitUntilExit];
60 }];
Ilya Moiseenko68192502013-09-30 14:27:48 -070061
Alexander Afanasyev4e1c7e92013-10-11 18:25:09 +020062 [(MenuDelegate*)[[NSApplication sharedApplication] delegate] updateStatusWithDependency:operation];
Ilya Moiseenko68192502013-09-30 14:27:48 -070063}
64
65-(IBAction)removeFibEntry:(id)sender
66{
Ilya Moiseenkob4aca052013-10-06 15:10:19 -070067 NSInteger selectedRow = [fibTableView selectedRow];
68
69 if(selectedRow == -1)
70 return;
71
72 NSString *faceID = [tableController getFaceByRowIndex:selectedRow];
73 if (faceID == nil)
74 return;
Ilya Moiseenko68192502013-09-30 14:27:48 -070075
Ilya Moiseenkob4aca052013-10-06 15:10:19 -070076 NSString *prefix = [tableController getPrefixByRowIndex:selectedRow];
77 if (prefix == nil)
78 return;
79
Alexander Afanasyev4e1c7e92013-10-11 18:25:09 +020080 NSOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
Ilya Moiseenkob4aca052013-10-06 15:10:19 -070081 NSTask *task = [[NSTask alloc] init];
82 [task setLaunchPath: @NDND_FIB_COMMAND];
83 [task setArguments: [NSArray arrayWithObjects: @"del", prefix, @"face", faceID, nil]];
84 [task launch];
85 [task waitUntilExit];
86 }];
Alexander Afanasyev4e1c7e92013-10-11 18:25:09 +020087
88 [(MenuDelegate*)[[NSApplication sharedApplication] delegate] updateStatusWithDependency:operation];
Ilya Moiseenko68192502013-09-30 14:27:48 -070089}
90
91- (IBAction) showFibEntrySheet:(id)sender
92{
Ilya Moiseenkob4aca052013-10-06 15:10:19 -070093 [NSApp beginSheet:prefixRegistrationSheet
Ilya Moiseenko68192502013-09-30 14:27:48 -070094 modalForWindow:preferencesPanel
95 modalDelegate:self
96 didEndSelector:nil
97 contextInfo:nil];
98
Ilya Moiseenkob4aca052013-10-06 15:10:19 -070099 [tunnelCombobox selectItemAtIndex:0];
Ilya Moiseenko68192502013-09-30 14:27:48 -0700100}
101
102-(IBAction)hideFibEntrySheet:(id)sender
103{
Ilya Moiseenkob4aca052013-10-06 15:10:19 -0700104 [NSApp endSheet:prefixRegistrationSheet];
105 [prefixRegistrationSheet orderOut:sender];
Ilya Moiseenko68192502013-09-30 14:27:48 -0700106}
Ilya Moiseenko1dc76da2013-09-30 11:53:36 -0700107
Ilya Moiseenkoe7058e72013-10-02 15:56:45 -0700108
109-(IBAction)openRoutingStatusPage:(id)sender
110{
111 NSURL *pageURL = [NSURL URLWithString:@"http://netlab.cs.memphis.edu/script/htm/status.htm"];
112
113 [[NSWorkspace sharedWorkspace] openURL: pageURL];
114}
115
116-(IBAction)openTrafficMapPage:(id)sender
117{
118
119 NSURL *pageURL = [NSURL URLWithString:@"http://ndnmap.arl.wustl.edu"];
120
121 [[NSWorkspace sharedWorkspace] openURL: pageURL];
122}
123
124
Ilya Moiseenko1dc76da2013-09-30 11:53:36 -0700125@end