blob: 1e2b1c10701bf91af4d088c564c82b687d11fac6 [file] [log] [blame]
Alexander Afanasyev88f0b3a2013-09-24 23:52:08 -07001/* -*- 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 Afanasyev88f0b3a2013-09-24 23:52:08 -070018-(void)awakeFromNib
19{
20 statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
Alexander Afanasyev88f0b3a2013-09-24 23:52:08 -070021 [statusItem setMenu:statusMenu];
Ilya Moiseenko350b9b52013-09-25 16:38:41 -070022 [statusItem setToolTip:@"NDN Control Center"];
23 [statusItem setEnabled:YES];
24 //[statusItem setTitle:@"Status"];
Alexander Afanasyev88f0b3a2013-09-24 23:52:08 -070025 [statusItem setHighlightMode:YES];
Ilya Moiseenko350b9b52013-09-25 16:38:41 -070026 //[statusItem setTarget:self];
27
28 NSBundle *bundle = [NSBundle bundleForClass:[self class]];
Ilya Moiseenkoa10ef8d2013-09-25 17:23:05 -070029 NSString *path = [bundle pathForResource:@"FlatDisconnected" ofType:@"png"];
Ilya Moiseenko350b9b52013-09-25 16:38:41 -070030 menuIcon = [[NSImage alloc] initWithContentsOfFile:path];
31 [statusItem setTitle:@""];
32 [statusItem setImage:menuIcon];
Ilya Moiseenkoa10ef8d2013-09-25 17:23:05 -070033
Ilya Moiseenko01264322013-09-26 15:34:21 -070034
35
36 [connectionStatus setView: connectionStatusView];
37 [connectionStatus setTarget:self];
38 [daemonStatus setView: daemonStatusView];
39 [daemonStatus setTarget:self];
40
Ilya Moiseenkoa10ef8d2013-09-25 17:23:05 -070041 daemonStarted = false;
42}
43
44-(IBAction)switchDaemon:(id)sender
45{
46 if (daemonStarted)
47 {
48 daemonStarted = false;
49 [sender setTitle:@"Start"];
Ilya Moiseenko01264322013-09-26 15:34:21 -070050 //[connectionStatus setTitle:@"NDN disconnected"];
51 [connectionStatusText setStringValue:@"Disconnected"];
Ilya Moiseenkoa10ef8d2013-09-25 17:23:05 -070052
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 Moiseenko01264322013-09-26 15:34:21 -070062 //[connectionStatus setTitle:@"NDN connected"];
63 [connectionStatusText setStringValue:@"Connected"];
Ilya Moiseenkoa10ef8d2013-09-25 17:23:05 -070064
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 Moiseenko350b9b52013-09-25 16:38:41 -070070}
71
72-(IBAction)openDaemonStatus:(id)sender
73{
Ilya Moiseenko350b9b52013-09-25 16:38:41 -070074}
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 Afanasyev88f0b3a2013-09-24 23:52:08 -070089}
90
Ilya Moiseenko01264322013-09-26 15:34:21 -070091-(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 Afanasyev88f0b3a2013-09-24 23:52:08 -0700107@end