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 | |
| 11 | @implementation MenuDelegate |
| 12 | |
| 13 | - (void)applicationDidFinishLaunching:(NSNotification *)aNotification |
| 14 | { |
| 15 | // Insert code here to initialize your application |
| 16 | } |
| 17 | |
Alexander Afanasyev | 88f0b3a | 2013-09-24 23:52:08 -0700 | [diff] [blame] | 18 | -(void)awakeFromNib |
| 19 | { |
| 20 | statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength]; |
Alexander Afanasyev | 88f0b3a | 2013-09-24 23:52:08 -0700 | [diff] [blame] | 21 | [statusItem setMenu:statusMenu]; |
Ilya Moiseenko | 350b9b5 | 2013-09-25 16:38:41 -0700 | [diff] [blame] | 22 | [statusItem setToolTip:@"NDN Control Center"]; |
| 23 | [statusItem setEnabled:YES]; |
| 24 | //[statusItem setTitle:@"Status"]; |
Alexander Afanasyev | 88f0b3a | 2013-09-24 23:52:08 -0700 | [diff] [blame] | 25 | [statusItem setHighlightMode:YES]; |
Ilya Moiseenko | 350b9b5 | 2013-09-25 16:38:41 -0700 | [diff] [blame] | 26 | //[statusItem setTarget:self]; |
| 27 | |
| 28 | NSBundle *bundle = [NSBundle bundleForClass:[self class]]; |
Ilya Moiseenko | a10ef8d | 2013-09-25 17:23:05 -0700 | [diff] [blame] | 29 | NSString *path = [bundle pathForResource:@"FlatDisconnected" ofType:@"png"]; |
Ilya Moiseenko | 350b9b5 | 2013-09-25 16:38:41 -0700 | [diff] [blame] | 30 | menuIcon = [[NSImage alloc] initWithContentsOfFile:path]; |
| 31 | [statusItem setTitle:@""]; |
| 32 | [statusItem setImage:menuIcon]; |
Ilya Moiseenko | a10ef8d | 2013-09-25 17:23:05 -0700 | [diff] [blame] | 33 | |
Ilya Moiseenko | 0126432 | 2013-09-26 15:34:21 -0700 | [diff] [blame^] | 34 | |
| 35 | |
| 36 | [connectionStatus setView: connectionStatusView]; |
| 37 | [connectionStatus setTarget:self]; |
| 38 | [daemonStatus setView: daemonStatusView]; |
| 39 | [daemonStatus setTarget:self]; |
| 40 | |
Ilya Moiseenko | a10ef8d | 2013-09-25 17:23:05 -0700 | [diff] [blame] | 41 | daemonStarted = false; |
| 42 | } |
| 43 | |
| 44 | -(IBAction)switchDaemon:(id)sender |
| 45 | { |
| 46 | if (daemonStarted) |
| 47 | { |
| 48 | daemonStarted = false; |
| 49 | [sender setTitle:@"Start"]; |
Ilya Moiseenko | 0126432 | 2013-09-26 15:34:21 -0700 | [diff] [blame^] | 50 | //[connectionStatus setTitle:@"NDN disconnected"]; |
| 51 | [connectionStatusText setStringValue:@"Disconnected"]; |
Ilya Moiseenko | a10ef8d | 2013-09-25 17:23:05 -0700 | [diff] [blame] | 52 | |
| 53 | NSBundle *bundle = [NSBundle bundleForClass:[self class]]; |
| 54 | NSString *path = [bundle pathForResource:@"FlatDisconnected" ofType:@"png"]; |
| 55 | menuIcon = [[NSImage alloc] initWithContentsOfFile:path]; |
| 56 | [statusItem setImage:menuIcon]; |
| 57 | } |
| 58 | else |
| 59 | { |
| 60 | daemonStarted = true; |
| 61 | [sender setTitle:@"Stop"]; |
Ilya Moiseenko | 0126432 | 2013-09-26 15:34:21 -0700 | [diff] [blame^] | 62 | //[connectionStatus setTitle:@"NDN connected"]; |
| 63 | [connectionStatusText setStringValue:@"Connected"]; |
Ilya Moiseenko | a10ef8d | 2013-09-25 17:23:05 -0700 | [diff] [blame] | 64 | |
| 65 | NSBundle *bundle = [NSBundle bundleForClass:[self class]]; |
| 66 | NSString *path = [bundle pathForResource:@"FlatConnected" ofType:@"png"]; |
| 67 | menuIcon = [[NSImage alloc] initWithContentsOfFile:path]; |
| 68 | [statusItem setImage:menuIcon]; |
| 69 | } |
Ilya Moiseenko | 350b9b5 | 2013-09-25 16:38:41 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | -(IBAction)openDaemonStatus:(id)sender |
| 73 | { |
Ilya Moiseenko | 350b9b5 | 2013-09-25 16:38:41 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | -(IBAction)openRoutingStatusPage:(id)sender |
| 77 | { |
| 78 | NSURL *pageURL = [NSURL URLWithString:@"http://netlab.cs.memphis.edu/script/htm/status.htm"]; |
| 79 | |
| 80 | [[NSWorkspace sharedWorkspace] openURL: pageURL]; |
| 81 | } |
| 82 | |
| 83 | -(IBAction)openTrafficMapPage:(id)sender |
| 84 | { |
| 85 | |
| 86 | NSURL *pageURL = [NSURL URLWithString:@"http://ndnmap.arl.wustl.edu"]; |
| 87 | |
| 88 | [[NSWorkspace sharedWorkspace] openURL: pageURL]; |
Alexander Afanasyev | 88f0b3a | 2013-09-24 23:52:08 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Ilya Moiseenko | 0126432 | 2013-09-26 15:34:21 -0700 | [diff] [blame^] | 91 | -(void)menu:(NSMenu *)menu willHighlightItem:(NSMenuItem *)item |
| 92 | { |
| 93 | |
| 94 | if( ([item view]!=nil) && (item == daemonStatus) ) |
| 95 | { |
| 96 | [statusPopover showRelativeToRect:[[item view] bounds] |
| 97 | ofView:[item view] |
| 98 | preferredEdge:NSMinXEdge]; |
| 99 | |
| 100 | } |
| 101 | else |
| 102 | { |
| 103 | [statusPopover performClose:nil]; |
| 104 | } |
| 105 | } |
| 106 | |
Alexander Afanasyev | 88f0b3a | 2013-09-24 23:52:08 -0700 | [diff] [blame] | 107 | @end |