blob: d91e780d16bf601f63245be8464eb1a74e8055aa [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
Ilya Moiseenko2dffcf52013-09-27 15:08:04 -070011#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 Afanasyev88f0b3a2013-09-24 23:52:08 -070015@implementation MenuDelegate
16
17- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
18{
19 // Insert code here to initialize your application
20}
21
Alexander Afanasyev88f0b3a2013-09-24 23:52:08 -070022-(void)awakeFromNib
23{
24 statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
Alexander Afanasyev88f0b3a2013-09-24 23:52:08 -070025 [statusItem setMenu:statusMenu];
Ilya Moiseenko350b9b52013-09-25 16:38:41 -070026 [statusItem setToolTip:@"NDN Control Center"];
27 [statusItem setEnabled:YES];
Alexander Afanasyev88f0b3a2013-09-24 23:52:08 -070028 [statusItem setHighlightMode:YES];
Ilya Moiseenko350b9b52013-09-25 16:38:41 -070029 //[statusItem setTarget:self];
30
31 NSBundle *bundle = [NSBundle bundleForClass:[self class]];
Ilya Moiseenkoa10ef8d2013-09-25 17:23:05 -070032 NSString *path = [bundle pathForResource:@"FlatDisconnected" ofType:@"png"];
Ilya Moiseenko350b9b52013-09-25 16:38:41 -070033 menuIcon = [[NSImage alloc] initWithContentsOfFile:path];
34 [statusItem setTitle:@""];
35 [statusItem setImage:menuIcon];
Ilya Moiseenkoa10ef8d2013-09-25 17:23:05 -070036
Ilya Moiseenko01264322013-09-26 15:34:21 -070037
Ilya Moiseenko01264322013-09-26 15:34:21 -070038 [connectionStatus setView: connectionStatusView];
39 [connectionStatus setTarget:self];
40 [daemonStatus setView: daemonStatusView];
41 [daemonStatus setTarget:self];
42
Ilya Moiseenkoa10ef8d2013-09-25 17:23:05 -070043 daemonStarted = false;
Ilya Moiseenko90f40c92013-09-27 15:52:01 -070044 //[NSApp activateIgnoringOtherApps:YES];
Ilya Moiseenkoa10ef8d2013-09-25 17:23:05 -070045}
46
47-(IBAction)switchDaemon:(id)sender
48{
49 if (daemonStarted)
50 {
51 daemonStarted = false;
52 [sender setTitle:@"Start"];
Ilya Moiseenko01264322013-09-26 15:34:21 -070053 [connectionStatusText setStringValue:@"Disconnected"];
Ilya Moiseenkoa10ef8d2013-09-25 17:23:05 -070054
Ilya Moiseenko2dffcf52013-09-27 15:08:04 -070055 NSTask *task = [[NSTask alloc] init];
56 [task setLaunchPath: NDND_STOP_COMMAND];
57 [task launch];
58
Ilya Moiseenkoa10ef8d2013-09-25 17:23:05 -070059 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 Moiseenko01264322013-09-26 15:34:21 -070068 [connectionStatusText setStringValue:@"Connected"];
Ilya Moiseenkoa10ef8d2013-09-25 17:23:05 -070069
Ilya Moiseenko2dffcf52013-09-27 15:08:04 -070070 NSTask *task = [[NSTask alloc] init];
71 [task setLaunchPath: NDND_START_COMMAND];
72 [task launch];
73
Ilya Moiseenkoa10ef8d2013-09-25 17:23:05 -070074 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 Moiseenko350b9b52013-09-25 16:38:41 -070079}
80
81-(IBAction)openDaemonStatus:(id)sender
82{
Ilya Moiseenko350b9b52013-09-25 16:38:41 -070083}
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 Afanasyev88f0b3a2013-09-24 23:52:08 -070098}
99
Ilya Moiseenko01264322013-09-26 15:34:21 -0700100-(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 Moiseenko01264322013-09-26 15:34:21 -0700108 }
109 else
110 {
111 [statusPopover performClose:nil];
112 }
113}
114
Ilya Moiseenko2dffcf52013-09-27 15:08:04 -0700115-(IBAction)openNDNDPreferences:(id)sender
116{
Ilya Moiseenko90f40c92013-09-27 15:52:01 -0700117 [preferencesPanel setContentView:generalSettingsView];
Ilya Moiseenko2dffcf52013-09-27 15:08:04 -0700118 [preferencesPanel makeKeyAndOrderFront:sender];
119 [preferencesPanel setLevel: NSStatusWindowLevel];
120}
Ilya Moiseenko90f40c92013-09-27 15:52:01 -0700121
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 Afanasyev88f0b3a2013-09-24 23:52:08 -0700161@end