Alexander Afanasyev | 88f0b3a | 2013-09-24 23:52:08 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 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 | |
| 9 | #import "menu-delegate.h" |
| 10 | |
Ilya Moiseenko | 2dffcf5 | 2013-09-27 15:08:04 -0700 | [diff] [blame] | 11 | #define NDND_START_COMMAND @"/opt/local/bin/ndndstart" |
| 12 | #define NDND_STOP_COMMAND @"/opt/local/bin/ndndstop" |
| 13 | #define NDND_STATUS_COMMAND @"/opt/local/bin/ndndstatus" |
| 14 | |
Alexander Afanasyev | 88f0b3a | 2013-09-24 23:52:08 -0700 | [diff] [blame] | 15 | @implementation MenuDelegate |
| 16 | |
| 17 | - (void)applicationDidFinishLaunching:(NSNotification *)aNotification |
| 18 | { |
| 19 | // Insert code here to initialize your application |
| 20 | } |
| 21 | |
Alexander Afanasyev | 88f0b3a | 2013-09-24 23:52:08 -0700 | [diff] [blame] | 22 | -(void)awakeFromNib |
| 23 | { |
| 24 | statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength]; |
Alexander Afanasyev | 88f0b3a | 2013-09-24 23:52:08 -0700 | [diff] [blame] | 25 | [statusItem setMenu:statusMenu]; |
Ilya Moiseenko | 350b9b5 | 2013-09-25 16:38:41 -0700 | [diff] [blame] | 26 | [statusItem setToolTip:@"NDN Control Center"]; |
| 27 | [statusItem setEnabled:YES]; |
Alexander Afanasyev | 88f0b3a | 2013-09-24 23:52:08 -0700 | [diff] [blame] | 28 | [statusItem setHighlightMode:YES]; |
Ilya Moiseenko | 350b9b5 | 2013-09-25 16:38:41 -0700 | [diff] [blame] | 29 | //[statusItem setTarget:self]; |
| 30 | |
| 31 | NSBundle *bundle = [NSBundle bundleForClass:[self class]]; |
Ilya Moiseenko | a10ef8d | 2013-09-25 17:23:05 -0700 | [diff] [blame] | 32 | NSString *path = [bundle pathForResource:@"FlatDisconnected" ofType:@"png"]; |
Ilya Moiseenko | 350b9b5 | 2013-09-25 16:38:41 -0700 | [diff] [blame] | 33 | menuIcon = [[NSImage alloc] initWithContentsOfFile:path]; |
| 34 | [statusItem setTitle:@""]; |
| 35 | [statusItem setImage:menuIcon]; |
Ilya Moiseenko | a10ef8d | 2013-09-25 17:23:05 -0700 | [diff] [blame] | 36 | |
Ilya Moiseenko | 0126432 | 2013-09-26 15:34:21 -0700 | [diff] [blame] | 37 | |
Ilya Moiseenko | 0126432 | 2013-09-26 15:34:21 -0700 | [diff] [blame] | 38 | [connectionStatus setView: connectionStatusView]; |
| 39 | [connectionStatus setTarget:self]; |
| 40 | [daemonStatus setView: daemonStatusView]; |
| 41 | [daemonStatus setTarget:self]; |
| 42 | |
Ilya Moiseenko | a10ef8d | 2013-09-25 17:23:05 -0700 | [diff] [blame] | 43 | daemonStarted = false; |
Ilya Moiseenko | 90f40c9 | 2013-09-27 15:52:01 -0700 | [diff] [blame^] | 44 | //[NSApp activateIgnoringOtherApps:YES]; |
Ilya Moiseenko | a10ef8d | 2013-09-25 17:23:05 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | -(IBAction)switchDaemon:(id)sender |
| 48 | { |
| 49 | if (daemonStarted) |
| 50 | { |
| 51 | daemonStarted = false; |
| 52 | [sender setTitle:@"Start"]; |
Ilya Moiseenko | 0126432 | 2013-09-26 15:34:21 -0700 | [diff] [blame] | 53 | [connectionStatusText setStringValue:@"Disconnected"]; |
Ilya Moiseenko | a10ef8d | 2013-09-25 17:23:05 -0700 | [diff] [blame] | 54 | |
Ilya Moiseenko | 2dffcf5 | 2013-09-27 15:08:04 -0700 | [diff] [blame] | 55 | NSTask *task = [[NSTask alloc] init]; |
| 56 | [task setLaunchPath: NDND_STOP_COMMAND]; |
| 57 | [task launch]; |
| 58 | |
Ilya Moiseenko | a10ef8d | 2013-09-25 17:23:05 -0700 | [diff] [blame] | 59 | NSBundle *bundle = [NSBundle bundleForClass:[self class]]; |
| 60 | NSString *path = [bundle pathForResource:@"FlatDisconnected" ofType:@"png"]; |
| 61 | menuIcon = [[NSImage alloc] initWithContentsOfFile:path]; |
| 62 | [statusItem setImage:menuIcon]; |
| 63 | } |
| 64 | else |
| 65 | { |
| 66 | daemonStarted = true; |
| 67 | [sender setTitle:@"Stop"]; |
Ilya Moiseenko | 0126432 | 2013-09-26 15:34:21 -0700 | [diff] [blame] | 68 | [connectionStatusText setStringValue:@"Connected"]; |
Ilya Moiseenko | a10ef8d | 2013-09-25 17:23:05 -0700 | [diff] [blame] | 69 | |
Ilya Moiseenko | 2dffcf5 | 2013-09-27 15:08:04 -0700 | [diff] [blame] | 70 | NSTask *task = [[NSTask alloc] init]; |
| 71 | [task setLaunchPath: NDND_START_COMMAND]; |
| 72 | [task launch]; |
| 73 | |
Ilya Moiseenko | a10ef8d | 2013-09-25 17:23:05 -0700 | [diff] [blame] | 74 | NSBundle *bundle = [NSBundle bundleForClass:[self class]]; |
| 75 | NSString *path = [bundle pathForResource:@"FlatConnected" ofType:@"png"]; |
| 76 | menuIcon = [[NSImage alloc] initWithContentsOfFile:path]; |
| 77 | [statusItem setImage:menuIcon]; |
| 78 | } |
Ilya Moiseenko | 350b9b5 | 2013-09-25 16:38:41 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | -(IBAction)openDaemonStatus:(id)sender |
| 82 | { |
Ilya Moiseenko | 350b9b5 | 2013-09-25 16:38:41 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | -(IBAction)openRoutingStatusPage:(id)sender |
| 86 | { |
| 87 | NSURL *pageURL = [NSURL URLWithString:@"http://netlab.cs.memphis.edu/script/htm/status.htm"]; |
| 88 | |
| 89 | [[NSWorkspace sharedWorkspace] openURL: pageURL]; |
| 90 | } |
| 91 | |
| 92 | -(IBAction)openTrafficMapPage:(id)sender |
| 93 | { |
| 94 | |
| 95 | NSURL *pageURL = [NSURL URLWithString:@"http://ndnmap.arl.wustl.edu"]; |
| 96 | |
| 97 | [[NSWorkspace sharedWorkspace] openURL: pageURL]; |
Alexander Afanasyev | 88f0b3a | 2013-09-24 23:52:08 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Ilya Moiseenko | 0126432 | 2013-09-26 15:34:21 -0700 | [diff] [blame] | 100 | -(void)menu:(NSMenu *)menu willHighlightItem:(NSMenuItem *)item |
| 101 | { |
| 102 | |
| 103 | if( ([item view]!=nil) && (item == daemonStatus) ) |
| 104 | { |
| 105 | [statusPopover showRelativeToRect:[[item view] bounds] |
| 106 | ofView:[item view] |
| 107 | preferredEdge:NSMinXEdge]; |
Ilya Moiseenko | 0126432 | 2013-09-26 15:34:21 -0700 | [diff] [blame] | 108 | } |
| 109 | else |
| 110 | { |
| 111 | [statusPopover performClose:nil]; |
| 112 | } |
| 113 | } |
| 114 | |
Ilya Moiseenko | 2dffcf5 | 2013-09-27 15:08:04 -0700 | [diff] [blame] | 115 | -(IBAction)openNDNDPreferences:(id)sender |
| 116 | { |
Ilya Moiseenko | 90f40c9 | 2013-09-27 15:52:01 -0700 | [diff] [blame^] | 117 | [preferencesPanel setContentView:generalSettingsView]; |
Ilya Moiseenko | 2dffcf5 | 2013-09-27 15:08:04 -0700 | [diff] [blame] | 118 | [preferencesPanel makeKeyAndOrderFront:sender]; |
| 119 | [preferencesPanel setLevel: NSStatusWindowLevel]; |
| 120 | } |
Ilya Moiseenko | 90f40c9 | 2013-09-27 15:52:01 -0700 | [diff] [blame^] | 121 | |
| 122 | -(IBAction)openGeneralSettings:(id)sender |
| 123 | { |
| 124 | [preferencesPanel setContentView:generalSettingsView]; |
| 125 | } |
| 126 | |
| 127 | -(IBAction)openForwardingSettings:(id)sender |
| 128 | { |
| 129 | [preferencesPanel setContentView:forwardingSettingsView]; |
| 130 | } |
| 131 | |
| 132 | -(IBAction)openSecuritySettings:(id)sender |
| 133 | { |
| 134 | [preferencesPanel setContentView:securitySettingsView]; |
| 135 | } |
| 136 | |
| 137 | -(IBAction)switchSoftwareUpdates:(id)sender |
| 138 | { |
| 139 | if ([(NSButton*)sender state] == NSOnState) |
| 140 | { |
| 141 | allowSoftwareUpdates = true; |
| 142 | } |
| 143 | else |
| 144 | { |
| 145 | allowSoftwareUpdates = false; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | -(IBAction)switchHubDiscovery:(id)sender |
| 150 | { |
| 151 | if ([(NSButton*)sender state] == NSOnState) |
| 152 | { |
| 153 | enableHubDiscovery = true; |
| 154 | } |
| 155 | else |
| 156 | { |
| 157 | enableHubDiscovery = false; |
| 158 | } |
| 159 | } |
| 160 | |
Alexander Afanasyev | 88f0b3a | 2013-09-24 23:52:08 -0700 | [diff] [blame] | 161 | @end |