blob: c4c0790534e47fdadf18107c48112a40bc370432 [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 Moiseenko2dffcf52013-09-27 15:08:04 -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];
108
109 }
110 else
111 {
112 [statusPopover performClose:nil];
113 }
114}
115
Ilya Moiseenko2dffcf52013-09-27 15:08:04 -0700116-(IBAction)openNDNDPreferences:(id)sender
117{
118 [preferencesPanel makeKeyAndOrderFront:sender];
119 [preferencesPanel setLevel: NSStatusWindowLevel];
120}
121//
Alexander Afanasyev88f0b3a2013-09-24 23:52:08 -0700122@end