forked from laullon/MenuMeters
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMenuMeterNetExtra.m
More file actions
1765 lines (1616 loc) · 72.1 KB
/
MenuMeterNetExtra.m
File metadata and controls
1765 lines (1616 loc) · 72.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// MenuMeterNetExtra.m
//
// Menu Extra implementation
//
// Copyright (c) 2002-2009 Alex Harper
//
// This file is part of MenuMeters.
//
// MenuMeters is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// MenuMeters is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with MenuMeters; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
#import "MenuMeterNetExtra.h"
///////////////////////////////////////////////////////////////
//
// Private methods and constants
//
///////////////////////////////////////////////////////////////
// Apple network settings we'll try to use
#define kAppleNetworkConnectDefaultsDomain CFSTR("com.apple.networkConnect")
@interface MenuMeterNetExtra (PrivateMethods)
// Image renderers
- (void)renderGraphIntoImage:(NSImage *)image;
- (void)renderActivityIntoImage:(NSImage *)image;
- (void)renderThroughputIntoImage:(NSImage *)image;
// Timer callbacks
- (void)updateNetActivityDisplay:(NSTimer *)timer;
- (void)updateMenuWhenDown;
// Menu actions
- (void)openNetworkUtil:(id)sender;
- (void)openNetworkPrefs:(id)sender;
- (void)openInternetConnect:(id)sender;
- (void)switchDisplay:(id)sender;
- (void)copyAddress:(id)sender;
- (void)pppConnect:(id)sender;
- (void)pppDisconnect:(id)sender;
// Prefs
- (void)configFromPrefs:(NSNotification *)notification;
// Data formatting
- (NSString *)throughputStringForBPS:(double)bps;
- (NSString *)throughputStringForBytes:(double)bytes inInterval:(NSTimeInterval)interval;
- (NSString *)menubarThroughputStringForBytes:(double)bytes inInterval:(NSTimeInterval)interval;
- (NSString *)stringForBytes:(double)bytes;
@end
///////////////////////////////////////////////////////////////
//
// Localized strings
//
///////////////////////////////////////////////////////////////
#define kTxLabel @"Tx:"
#define kRxLabel @"Rx:"
#define kPPPTitle @"PPP:"
#define kTCPIPTitle @"TCP/IP:"
#define kIPv4Title @"IPv4:"
#define kIPv6Title @"IPv6:"
#define kTCPIPInactiveTitle @"Inactive"
#define kAppleTalkTitle @"AppleTalk:"
#define kAppleTalkFormat @"Net: %@ Node: %@ Zone: %@"
#define kThroughputTitle @"Throughput:"
#define kPeakThroughputTitle @"Peak Throughput:"
#define kTrafficTotalTitle @"Traffic Totals:"
#define kTrafficTotalFormat @"%@ %@ (%@ bytes)"
#define kOpenNetworkUtilityTitle @"Open Network Utility"
#define kOpenNetworkPrefsTitle @"Open Network Preferences"
#define kOpenInternetConnectTitle @"Open Internet Connect"
#define kSelectPrimaryInterfaceTitle @"Display primary interface"
#define kSelectInterfaceTitle @"Display this interface"
#define kCopyIPv4Title @"Copy IPv4 address"
#define kCopyIPv6Title @"Copy IPv6 address"
#define kPPPConnectTitle @"Connect"
#define kPPPDisconnectTitle @"Disconnect"
#define kNoInterfaceErrorMessage @"No Active Interfaces"
#define kGbpsLabel @"Gbps"
#define kMbpsLabel @"Mbps"
#define kKbpsLabel @"Kbps"
#define kByteLabel @"B"
#define kKBLabel @"KB"
#define kMBLabel @"MB"
#define kGBLabel @"GB"
#define kBytePerSecondLabel @"B/s"
#define kKBPerSecondLabel @"KB/s"
#define kMBPerSecondLabel @"MB/s"
#define kGBPerSecondLabel @"GB/s"
#define kPPPNoConnectTitle @"Not Connected"
#define kPPPConnectingTitle @"Connecting..."
#define kPPPConnectedTitle @"Connected"
#define kPPPConnectedWithTimeTitle @"Connected %02d:%02d:%02d"
#define kPPPDisconnectingTitle @"Disconnecting..."
///////////////////////////////////////////////////////////////
//
// init/unload/dealloc
//
///////////////////////////////////////////////////////////////
@implementation MenuMeterNetExtra
- initWithBundle:(NSBundle *)bundle {
self = [super initWithBundle:bundle];
if (!self) {
return nil;
}
// Panther check
SInt32 systemVersion = 0;
OSStatus err = Gestalt(gestaltSystemVersion, &systemVersion);
if (err != noErr) {
[self release];
return nil;
}
isPantherOrLater = NO;
if (systemVersion >= 0x1030) {
isPantherOrLater = YES;
}
if (systemVersion >= 0x1050) {
isLeopardOrLater = YES;
}
// Load our pref bundle, we do this as a bundle because we are a plugin
// to SystemUIServer and as a result cannot have the same class loaded
// from every meter. Using a shared bundle each loads fixes this.
NSString *prefBundlePath = [[[bundle bundlePath] stringByDeletingLastPathComponent]
stringByAppendingPathComponent:kPrefBundleName];
ourPrefs = [[[[NSBundle bundleWithPath:prefBundlePath] principalClass] alloc] init];
if (!ourPrefs) {
NSLog(@"MenuMeterCPU unable to connect to preferences. Abort.");
[self release];
return nil;
}
// Build our data gatherers
netConfig = [[MenuMeterNetConfig alloc] init];
netStats = [[MenuMeterNetStats alloc] init];
pppControl = [[MenuMeterNetPPP sharedPPP] retain];
netHistoryData = [[NSMutableArray array] retain];
netHistoryIntervals = [[NSMutableArray array] retain];
if (!(netConfig && netStats && pppControl && netHistoryData)) {
NSLog(@"MenuMeterNet unable to load data gatherers/controllers. Abort.");
[self release];
return nil;
}
// Setup our menu
extraMenu = [[NSMenu alloc] initWithTitle:@""];
if (!extraMenu) {
[self release];
return nil;
}
// Disable menu autoenabling
[extraMenu setAutoenablesItems:NO];
// Menu is regenerated in the menu method always so no futher setup
// Set the menu extra view up
// Get our view
extraView = [[MenuMeterNetView alloc] initWithFrame:[[self view] frame] menuExtra:self];
if (!extraView) {
[self release];
return nil;
}
[self setView:extraView];
// Localizable strings
localizedStrings = [[NSDictionary dictionaryWithObjectsAndKeys:
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kTxLabel value:nil table:nil],
kTxLabel,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kRxLabel value:nil table:nil],
kRxLabel,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kPPPTitle value:nil table:nil],
kPPPTitle,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kTCPIPTitle value:nil table:nil],
kTCPIPTitle,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kIPv4Title value:nil table:nil],
kIPv4Title,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kIPv6Title value:nil table:nil],
kIPv6Title,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kTCPIPInactiveTitle value:nil table:nil],
kTCPIPInactiveTitle,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kAppleTalkTitle value:nil table:nil],
kAppleTalkTitle,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kAppleTalkFormat value:nil table:nil],
kAppleTalkFormat,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kThroughputTitle value:nil table:nil],
kThroughputTitle,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kPeakThroughputTitle value:nil table:nil],
kPeakThroughputTitle,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kTrafficTotalTitle value:nil table:nil],
kTrafficTotalTitle,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kTrafficTotalFormat value:nil table:nil],
kTrafficTotalFormat,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kOpenNetworkUtilityTitle value:nil table:nil],
kOpenNetworkUtilityTitle,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kOpenNetworkPrefsTitle value:nil table:nil],
kOpenNetworkPrefsTitle,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kOpenInternetConnectTitle value:nil table:nil],
kOpenInternetConnectTitle,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kNoInterfaceErrorMessage value:nil table:nil],
kNoInterfaceErrorMessage,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kSelectPrimaryInterfaceTitle value:nil table:nil],
kSelectPrimaryInterfaceTitle,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kSelectInterfaceTitle value:nil table:nil],
kSelectInterfaceTitle,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kCopyIPv4Title value:nil table:nil],
kCopyIPv4Title,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kCopyIPv6Title value:nil table:nil],
kCopyIPv6Title,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kPPPConnectTitle value:nil table:nil],
kPPPConnectTitle,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kPPPDisconnectTitle value:nil table:nil],
kPPPDisconnectTitle,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kGbpsLabel value:nil table:nil],
kGbpsLabel,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kMbpsLabel value:nil table:nil],
kMbpsLabel,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kKbpsLabel value:nil table:nil],
kKbpsLabel,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kByteLabel value:nil table:nil],
kByteLabel,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kKBLabel value:nil table:nil],
kKBLabel,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kMBLabel value:nil table:nil],
kMBLabel,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kGBLabel value:nil table:nil],
kGBLabel,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kBytePerSecondLabel value:nil table:nil],
kBytePerSecondLabel,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kKBPerSecondLabel value:nil table:nil],
kKBPerSecondLabel,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kMBPerSecondLabel value:nil table:nil],
kMBPerSecondLabel,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kGBPerSecondLabel value:nil table:nil],
kGBPerSecondLabel,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kPPPNoConnectTitle value:nil table:nil],
kPPPNoConnectTitle,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kPPPConnectingTitle value:nil table:nil],
kPPPConnectingTitle,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kPPPConnectedTitle value:nil table:nil],
kPPPConnectedTitle,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kPPPConnectedWithTimeTitle value:nil table:nil],
kPPPConnectedWithTimeTitle,
[[NSBundle bundleForClass:[self class]] localizedStringForKey:kPPPDisconnectingTitle value:nil table:nil],
kPPPDisconnectingTitle,
nil] retain];
// Set up a NumberFormatter for localization. This is based on code contributed by Mike Fischer
// (mike.fischer at fi-works.de) for use in MenuMeters.
NSNumberFormatter *tempFormat = [[[NSNumberFormatter alloc] init] autorelease];
[tempFormat setLocalizesFormat:YES];
[tempFormat setFormat:@"###0.0"];
// Go through an archive/unarchive cycle to work around a bug on pre-10.2.2 systems
// see http://cocoa.mamasam.com/COCOADEV/2001/12/2/21029.php
bytesFormatter = [[NSUnarchiver unarchiveObjectWithData:[NSArchiver archivedDataWithRootObject:tempFormat]] retain];
tempFormat = [[[NSNumberFormatter alloc] init] autorelease];
[tempFormat setLocalizesFormat:YES];
[tempFormat setFormat:@"#,##0"];
prettyIntFormatter = [[NSUnarchiver unarchiveObjectWithData:[NSArchiver archivedDataWithRootObject:tempFormat]] retain];
// Register for pref changes
[[NSDistributedNotificationCenter defaultCenter] addObserver:self
selector:@selector(configFromPrefs:)
name:kNetMenuBundleID
object:kPrefChangeNotification];
// And configure directly from prefs on first load
[self configFromPrefs:nil];
// Fake a timer call to config initial values
[self updateNetActivityDisplay:nil];
// And hand ourself back to SystemUIServer
NSLog(@"MenuMeterNet loaded.");
return self;
} // initWithBundle
- (void)willUnload {
// Stop the timer
[updateTimer invalidate]; // Released by the runloop
updateTimer = nil;
// Unregister pref change notifications
[[NSDistributedNotificationCenter defaultCenter] removeObserver:self
name:nil
object:nil];
// Let the pref panel know we have been removed
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:kNetMenuBundleID
object:kNetMenuUnloadNotification];
// Let super do the rest
[super willUnload];
} // willUnload
- (void)dealloc {
[extraView release];
[extraMenu release];
[updateTimer invalidate]; // Released by the runloop
[ourPrefs release];
[netConfig release];
[netStats release];
[pppControl release];
[localizedStrings release];
[bytesFormatter release];
[prettyIntFormatter release];
[txColor release];
[rxColor release];
[inactiveColor release];
[lastSampleDate release];
[netHistoryData release];
[netHistoryIntervals release];
[upArrow release];
[downArrow release];
[throughputLabel release];
[inactiveThroughputLabel release];
[preferredInterfaceConfig release];
[updateMenuItems release];
[super dealloc];
} // dealloc
///////////////////////////////////////////////////////////////
//
// NSMenuExtra view callbacks
//
///////////////////////////////////////////////////////////////
- (NSImage *)image {
// Image to render into (and return to view)
NSImage *currentImage = [[[NSImage alloc] initWithSize:NSMakeSize((float)menuWidth,
[extraView frame].size.height - 1)] autorelease];
if (!currentImage) return nil;
// Don't render without data
if (![netHistoryData count]) return nil;
// Draw displays
if ([ourPrefs netDisplayMode] & kNetDisplayGraph) {
[self renderGraphIntoImage:currentImage];
}
if ([ourPrefs netDisplayMode] & kNetDisplayArrows) {
[self renderActivityIntoImage:currentImage];
}
if ([ourPrefs netDisplayMode] & kNetDisplayThroughput) {
[self renderThroughputIntoImage:currentImage];
}
// Send it back for the view to render
return currentImage;
} // image
// Boy does this need refactoring... *sigh*
- (NSMenu *)menu {
// New cache
[updateMenuItems release];
updateMenuItems = [[NSMutableDictionary dictionary] retain];//
// Empty the menu
while ([extraMenu numberOfItems]) {
[extraMenu removeItemAtIndex:0];
}
// Hostname
NSString *hostname = [[netConfig computerName] retain];
if (hostname) {
[[extraMenu addItemWithTitle:hostname action:nil keyEquivalent:@""] setEnabled:NO];
[extraMenu addItem:[NSMenuItem separatorItem]];
}
// Interface detail array
BOOL pppPresent = NO;
NSArray *interfaceDetails = [netConfig interfaceDetails];
if ([interfaceDetails count]) {
NSEnumerator *detailEnum = [interfaceDetails objectEnumerator];
NSDictionary *details = nil;
while ((details = [detailEnum nextObject])) {
// Array entry is a service/interface
NSMutableDictionary *interfaceUpdateMenuItems = [NSMutableDictionary dictionary];
NSString *interfaceDescription = [details objectForKey:@"name"];
NSString *speed = nil;
BOOL foundSelectedInterface = NO;
// Best guess if this is an active interface, default to assume it is active
BOOL isActiveInterface = YES;
if ([details objectForKey:@"linkactive"]) {
isActiveInterface = [[details objectForKey:@"linkactive"] boolValue];
}
if ([details objectForKey:@"pppstatus"]) {
if ([(NSNumber *)[[details objectForKey:@"pppstatus"] objectForKey:@"status"] unsignedIntValue] == PPP_IDLE) {
isActiveInterface = NO;
}
}
// Calc speed
if ([details objectForKey:@"linkspeed"] && isActiveInterface) {
if ([[details objectForKey:@"linkspeed"] doubleValue] > 1000000000) {
speed = [NSString stringWithFormat:@" %.0f%@",
([[details objectForKey:@"linkspeed"] doubleValue] / 1000000000),
[localizedStrings objectForKey:kGbpsLabel]];
} else if ([[details objectForKey:@"linkspeed"] doubleValue] > 1000000) {
speed = [NSString stringWithFormat:@" %.0f%@",
([[details objectForKey:@"linkspeed"] doubleValue] / 1000000),
[localizedStrings objectForKey:kMbpsLabel]];
} else {
speed = [NSString stringWithFormat:@" %@%@",
[bytesFormatter stringForObjectValue:
[NSNumber numberWithDouble:([[details objectForKey:@"linkspeed"] doubleValue] / 1000)]],
[localizedStrings objectForKey:kKbpsLabel]];
}
}
// Weird string cat because some of these values may not be present
// Also skip device name bit if the driver name (UserDefined name) already includes it (SourceForge wireless driver)
if ([details objectForKey:@"devicename"] &&
![interfaceDescription hasSuffix:[NSString stringWithFormat:@"(%@)", [details objectForKey:@"devicename"]]]) {
// If there is a PPP name use it too
if ([details objectForKey:@"devicepppname"]) {
interfaceDescription = [NSString stringWithFormat:@"%@ (%@, %@)",
interfaceDescription,
[details objectForKey:@"devicename"],
[details objectForKey:@"devicepppname"]];
} else {
interfaceDescription = [NSString stringWithFormat:@"%@ (%@)",
interfaceDescription,
[details objectForKey:@"devicename"]];
}
}
if (speed || [details objectForKey:@"connectiontype"]) {
interfaceDescription = [NSString stringWithFormat:@"%@ -%@%@",
interfaceDescription,
([details objectForKey:@"connectiontype"] ?
[NSString stringWithFormat:@" %@", [details objectForKey:@"connectiontype"]] : @""),
(speed ? speed : @"")];
}
NSMenuItem *titleItem = (NSMenuItem *)[extraMenu addItemWithTitle:interfaceDescription action:nil keyEquivalent:@""];
// PPP Status
if ([details objectForKey:@"pppstatus"]) {
// PPP is present
pppPresent = YES;
NSMenuItem *pppStatusItem = nil;
// Use the connection type title for PPP when we can
if ([details objectForKey:@"connectiontype"]) {
[[extraMenu addItemWithTitle:[NSString stringWithFormat:kMenuIndentFormat,
[NSString stringWithFormat:@"%@:", [details objectForKey:@"connectiontype"]]]
action:nil
keyEquivalent:@""] setEnabled:NO];
} else {
[[extraMenu addItemWithTitle:[NSString stringWithFormat:kMenuIndentFormat, [localizedStrings objectForKey:kPPPTitle]]
action:nil
keyEquivalent:@""] setEnabled:NO];
}
switch ([(NSNumber *)[[details objectForKey:@"pppstatus"] objectForKey:@"status"] unsignedIntValue]) {
case PPP_IDLE:
pppStatusItem = (NSMenuItem *)[extraMenu addItemWithTitle:[NSString stringWithFormat:kMenuDoubleIndentFormat,
[localizedStrings objectForKey:kPPPNoConnectTitle]]
action:nil
keyEquivalent:@""];
break;
case PPP_INITIALIZE:
case PPP_CONNECTLINK:
case PPP_STATERESERVED:
case PPP_ESTABLISH:
case PPP_AUTHENTICATE:
case PPP_CALLBACK:
case PPP_NETWORK:
case PPP_HOLDOFF:
case PPP_ONHOLD:
case PPP_WAITONBUSY:
pppStatusItem = (NSMenuItem *)[extraMenu addItemWithTitle:[NSString stringWithFormat:kMenuDoubleIndentFormat,
[localizedStrings objectForKey:kPPPConnectingTitle]]
action:nil
keyEquivalent:@""];
break;
case PPP_RUNNING:
if ([[details objectForKey:@"pppstatus"] objectForKey:@"timeElapsed"]) {
uint32_t secs = [[[details objectForKey:@"pppstatus"] objectForKey:@"timeElapsed"] unsignedIntValue];
uint32_t hours = secs / (60 * 60);
secs %= (60 * 60);
uint32_t mins = secs / 60;
secs %= 60;
pppStatusItem = (NSMenuItem *)[extraMenu addItemWithTitle:[NSString stringWithFormat:kMenuDoubleIndentFormat,
[NSString stringWithFormat:
[localizedStrings objectForKey:kPPPConnectedWithTimeTitle],
hours, mins, secs]]
action:nil
keyEquivalent:@""];
} else {
pppStatusItem = (NSMenuItem *)[extraMenu addItemWithTitle:[NSString stringWithFormat:kMenuDoubleIndentFormat, kPPPConnectedTitle]
action:nil
keyEquivalent:@""];
}
break;
case PPP_TERMINATE:
case PPP_DISCONNECTLINK:
pppStatusItem = (NSMenuItem *)[extraMenu addItemWithTitle:[NSString stringWithFormat:kMenuIndentFormat,
[localizedStrings objectForKey:kPPPDisconnectingTitle]]
action:nil
keyEquivalent:@""];
break;
};
if (pppStatusItem) {
[pppStatusItem setEnabled:NO];
[interfaceUpdateMenuItems setObject:pppStatusItem forKey:@"pppstatusitem"];
}
}
// TCP/IP
[[extraMenu addItemWithTitle:[NSString stringWithFormat:kMenuIndentFormat, [localizedStrings objectForKey:kTCPIPTitle]]
action:nil
keyEquivalent:@""] setEnabled:NO];
if ([[details objectForKey:@"ipv4addresses"] count] && [[details objectForKey:@"ipv6addresses"] count]) {
[[extraMenu addItemWithTitle:[NSString stringWithFormat:kMenuDoubleIndentFormat, [localizedStrings objectForKey:kIPv4Title]]
action:nil
keyEquivalent:@""] setEnabled:NO];
NSEnumerator *addressEnum = [[details objectForKey:@"ipv4addresses"] objectEnumerator];
NSString *address = nil;
while ((address = [addressEnum nextObject])) {
[[extraMenu addItemWithTitle:[NSString stringWithFormat:kMenuTripleIndentFormat, address]
action:nil
keyEquivalent:@""] setEnabled:NO];
}
[[extraMenu addItemWithTitle:[NSString stringWithFormat:kMenuDoubleIndentFormat, [localizedStrings objectForKey:kIPv6Title]]
action:nil
keyEquivalent:@""] setEnabled:NO];
addressEnum = [[details objectForKey:@"ipv6addresses"] objectEnumerator];
while ((address = [addressEnum nextObject])) {
[[extraMenu addItemWithTitle:[NSString stringWithFormat:kMenuTripleIndentFormat, address]
action:nil
keyEquivalent:@""] setEnabled:NO];
}
} else if ([[details objectForKey:@"ipv4addresses"] count]) {
NSEnumerator *addressEnum = [[details objectForKey:@"ipv4addresses"] objectEnumerator];
NSString *address = nil;
while ((address = [addressEnum nextObject])) {
[[extraMenu addItemWithTitle:[NSString stringWithFormat:kMenuDoubleIndentFormat, address]
action:nil
keyEquivalent:@""] setEnabled:NO];
}
} else {
[[extraMenu addItemWithTitle:[NSString stringWithFormat:kMenuDoubleIndentFormat,
[localizedStrings objectForKey:kTCPIPInactiveTitle]]
action:nil
keyEquivalent:@""] setEnabled:NO];
}
// AppleTalk
if ([details objectForKey:@"appletalknetid"]) {
[[extraMenu addItemWithTitle:[NSString stringWithFormat:kMenuIndentFormat,
[localizedStrings objectForKey:kAppleTalkTitle]]
action:nil
keyEquivalent:@""] setEnabled:NO];
[[extraMenu addItemWithTitle:[NSString stringWithFormat:kMenuDoubleIndentFormat,
[NSString stringWithFormat:[localizedStrings objectForKey:kAppleTalkFormat],
[details objectForKey:@"appletalknetid"],
[details objectForKey:@"appletalknodeid"],
[details objectForKey:@"appletalkzone"]]]
action:nil
keyEquivalent:@""] setEnabled:NO];
}
// Throughput
NSNumber *sampleIntervalNum = [netHistoryIntervals lastObject];
NSDictionary *throughputDetails = nil;
NSString *throughputInterface = nil;
// Do some dancing to make sure to get serial and VPN PPP interfaces, but not PPPoE
if ([netHistoryData lastObject] && ([details objectForKey:@"devicename"] || [details objectForKey:@"devicepppname"])) {
if ([details objectForKey:@"devicepppname"] && ![[details objectForKey:@"devicename"] hasPrefix:@"en"]) {
throughputInterface = [details objectForKey:@"devicepppname"];
throughputDetails = [[netHistoryData lastObject] objectForKey:[details objectForKey:@"devicepppname"]];
} else {
throughputInterface = [details objectForKey:@"devicename"];
throughputDetails = [[netHistoryData lastObject] objectForKey:[details objectForKey:@"devicename"]];
}
}
// Do we have throughput info on an active interface?
if (isActiveInterface && sampleIntervalNum && throughputInterface && throughputDetails) {
NSNumber *throughputOutNumber = [throughputDetails objectForKey:@"deltaout"];
NSNumber *throughputInNumber = [throughputDetails objectForKey:@"deltain"];
if (throughputOutNumber && throughputInNumber) {
[[extraMenu addItemWithTitle:[NSString stringWithFormat:kMenuIndentFormat, [localizedStrings objectForKey:kThroughputTitle]]
action:nil
keyEquivalent:@""] setEnabled:NO];
NSMenuItem *throughputItem = (NSMenuItem *)[extraMenu addItemWithTitle:[NSString stringWithFormat:kMenuDoubleIndentFormat,
[NSString stringWithFormat:@"%@ %@",
[localizedStrings objectForKey:kTxLabel],
[self throughputStringForBytes:[throughputOutNumber doubleValue]
inInterval:[sampleIntervalNum doubleValue]]]]
action:nil
keyEquivalent:@""];
[throughputItem setEnabled:NO];
[interfaceUpdateMenuItems setObject:throughputItem forKey:@"deltaoutitem"];
throughputItem = (NSMenuItem *)[extraMenu addItemWithTitle:[NSString stringWithFormat:kMenuDoubleIndentFormat,
[NSString stringWithFormat:@"%@ %@",
[localizedStrings objectForKey:kRxLabel],
[self throughputStringForBytes:[throughputInNumber doubleValue]
inInterval:[sampleIntervalNum doubleValue]]]]
action:nil
keyEquivalent:@""];
[throughputItem setEnabled:NO];
[interfaceUpdateMenuItems setObject:throughputItem forKey:@"deltainitem"];
}
// Add peak throughput
NSNumber *peakNumber = [throughputDetails objectForKey:@"peak"];
if (peakNumber) {
[[extraMenu addItemWithTitle:[NSString stringWithFormat:kMenuIndentFormat, [localizedStrings objectForKey:kPeakThroughputTitle]]
action:nil
keyEquivalent:@""] setEnabled:NO];
NSMenuItem *peakItem = (NSMenuItem *)[extraMenu addItemWithTitle:[NSString stringWithFormat:kMenuDoubleIndentFormat,
[self throughputStringForBPS:[peakNumber doubleValue]]]
action:nil
keyEquivalent:@""];
[peakItem setEnabled:NO];
[interfaceUpdateMenuItems setObject:peakItem forKey:@"peakitem"];
}
// Add traffic totals
throughputOutNumber = [throughputDetails objectForKey:@"totalout"];
throughputInNumber = [throughputDetails objectForKey:@"totalin"];
if (throughputOutNumber && throughputInNumber) {
[[extraMenu addItemWithTitle:[NSString stringWithFormat:kMenuIndentFormat, [localizedStrings objectForKey:kTrafficTotalTitle]]
action:nil
keyEquivalent:@""] setEnabled:NO];
NSMenuItem *totalItem = (NSMenuItem *)[extraMenu addItemWithTitle:[NSString stringWithFormat:kMenuDoubleIndentFormat,
[NSString stringWithFormat:[localizedStrings objectForKey:kTrafficTotalFormat],
[localizedStrings objectForKey:kTxLabel],
[self stringForBytes:[throughputOutNumber doubleValue]],
[prettyIntFormatter stringForObjectValue:throughputOutNumber]]]
action:nil
keyEquivalent:@""];
[totalItem setEnabled:NO];
[interfaceUpdateMenuItems setObject:totalItem forKey:@"totaloutitem"];
totalItem = (NSMenuItem *)[extraMenu addItemWithTitle:[NSString stringWithFormat:kMenuDoubleIndentFormat,
[NSString stringWithFormat:[localizedStrings objectForKey:kTrafficTotalFormat],
[localizedStrings objectForKey:kRxLabel],
[self stringForBytes:[throughputInNumber doubleValue]],
[prettyIntFormatter stringForObjectValue:throughputInNumber]]]
action:nil
keyEquivalent:@""];
[totalItem setEnabled:NO];
[interfaceUpdateMenuItems setObject:totalItem forKey:@"totalinitem"];
}
// Store the name to use in throughput reads for items we will update later
[interfaceUpdateMenuItems setObject:throughputInterface forKey:@"throughinterface"];
}
// Store the update items we built for this interface if needed
if ([interfaceUpdateMenuItems count]) {
[updateMenuItems setObject:interfaceUpdateMenuItems forKey:[details objectForKey:@"service"]];
}
// Now set up the submenu for this interface
NSMenu *interfaceSubmenu = [[[NSMenu alloc] initWithTitle:@""] autorelease];
// Disable menu autoenabling
[interfaceSubmenu setAutoenablesItems:NO];
// Add the submenu
[titleItem setSubmenu:interfaceSubmenu];
// PPP controller if needed and we can control the connection type on this OS version
if ([details objectForKey:@"pppstatus"] &&
([[details objectForKey:@"connectiontype"] isEqualToString:@"PPP"] || isPantherOrLater)) {
NSMenuItem *pppControlItem = nil;
switch ([(NSNumber *)[[details objectForKey:@"pppstatus"] objectForKey:@"status"] unsignedIntValue]) {
case PPP_IDLE:
pppControlItem = (NSMenuItem *)[interfaceSubmenu addItemWithTitle:[localizedStrings objectForKey:kPPPConnectTitle]
action:@selector(pppConnect:)
keyEquivalent:@""];
break;
case PPP_INITIALIZE:
case PPP_CONNECTLINK:
case PPP_STATERESERVED:
case PPP_ESTABLISH:
case PPP_AUTHENTICATE:
case PPP_CALLBACK:
case PPP_NETWORK:
case PPP_HOLDOFF:
case PPP_ONHOLD:
case PPP_WAITONBUSY:
case PPP_RUNNING:
pppControlItem = (NSMenuItem *)[interfaceSubmenu addItemWithTitle:[localizedStrings objectForKey:kPPPDisconnectTitle]
action:@selector(pppDisconnect:)
keyEquivalent:@""];
break;
case PPP_TERMINATE:
case PPP_DISCONNECTLINK:
pppControlItem = (NSMenuItem *)[interfaceSubmenu addItemWithTitle:[localizedStrings objectForKey:kPPPConnectTitle]
action:@selector(pppConnect:)
keyEquivalent:@""];
break;
};
[pppControlItem setTarget:self];
[pppControlItem setRepresentedObject:[details objectForKey:@"service"]];
[interfaceSubmenu addItem:[NSMenuItem separatorItem]];
}
// Add interface selection submenus
BOOL hadInterfaceSelector = NO;
if ([[details objectForKey:@"primary"] boolValue]) {
NSMenuItem *primarySwitchItem = (NSMenuItem *)[interfaceSubmenu addItemWithTitle:[localizedStrings objectForKey:kSelectPrimaryInterfaceTitle]
action:@selector(switchDisplay:)
keyEquivalent:@""];
[primarySwitchItem setRepresentedObject:kNetPrimaryInterface];
[primarySwitchItem setTarget:self];
if ([[ourPrefs netPreferInterface] isEqualToString:kNetPrimaryInterface]) {
[primarySwitchItem setEnabled:NO];
} else {
[primarySwitchItem setEnabled:YES];
}
hadInterfaceSelector = YES;
}
// Other choose interface
if ([details objectForKey:@"devicename"]) {
NSMenuItem *interfaceSwitchItem = (NSMenuItem *)[interfaceSubmenu addItemWithTitle:[localizedStrings objectForKey:kSelectInterfaceTitle]
action:@selector(switchDisplay:)
keyEquivalent:@""];
[interfaceSwitchItem setRepresentedObject:[details objectForKey:@"devicename"]];
[interfaceSwitchItem setTarget:self];
// Disable if this is preferred
if ([[details objectForKey:@"devicename"] isEqualToString:[ourPrefs netPreferInterface]]) {
[interfaceSwitchItem setEnabled:NO];
}
hadInterfaceSelector = YES;
}
if (hadInterfaceSelector) {
[interfaceSubmenu addItem:[NSMenuItem separatorItem]];
}
// Checkmark the interface menu if we haven't found one already
if (!foundSelectedInterface) {
if ([[ourPrefs netPreferInterface] isEqualToString:kNetPrimaryInterface] && [[details objectForKey:@"primary"] boolValue]) {
// This is the primary and the primary is preferred
[titleItem setState:NSOnState];
foundSelectedInterface = YES;
} else if (preferredInterfaceConfig && [details objectForKey:@"devicename"]) {
// Is this device the one being graphed?
if ([[details objectForKey:@"devicename"] isEqualToString:[preferredInterfaceConfig objectForKey:@"name"]] ||
[[details objectForKey:@"devicename"] isEqualToString:[preferredInterfaceConfig objectForKey:@"statname"]]) {
[titleItem setState:NSOnState];
foundSelectedInterface = YES;
}
} else if (preferredInterfaceConfig && [details objectForKey:@"devicepppname"]) {
if ([[details objectForKey:@"devicepppname"] isEqualToString:[preferredInterfaceConfig objectForKey:@"name"]] ||
[[details objectForKey:@"devicepppname"] isEqualToString:[preferredInterfaceConfig objectForKey:@"statname"]]) {
[titleItem setState:NSOnState];
foundSelectedInterface = YES;
}
}
}
// Copy IP
NSMenuItem *copyIPItem = (NSMenuItem *)[interfaceSubmenu addItemWithTitle:[localizedStrings objectForKey:kCopyIPv4Title]
action:@selector(copyAddress:)
keyEquivalent:@""];
[copyIPItem setTarget:self];
if ([[details objectForKey:@"ipv4addresses"] count]) {
[copyIPItem setRepresentedObject:[details objectForKey:@"ipv4addresses"]];
} else {
[copyIPItem setEnabled:NO];
}
if ([[details objectForKey:@"ipv6addresses"] count]) {
copyIPItem = (NSMenuItem *)[interfaceSubmenu addItemWithTitle:[localizedStrings objectForKey:kCopyIPv6Title]
action:@selector(copyAddress:)
keyEquivalent:@""];
[copyIPItem setTarget:self];
if ([[details objectForKey:@"ipv6addresses"] count]) {
[copyIPItem setRepresentedObject:[details objectForKey:@"ipv6addresses"]];
} else {
[copyIPItem setEnabled:NO];
}
}
}
} else {
[[extraMenu addItemWithTitle:[localizedStrings objectForKey:kNoInterfaceErrorMessage]
action:nil
keyEquivalent:@""] setEnabled:NO];
}
// Add utility items
[extraMenu addItem:[NSMenuItem separatorItem]];
[[extraMenu addItemWithTitle:[localizedStrings objectForKey:kOpenNetworkUtilityTitle]
action:@selector(openNetworkUtil:)
keyEquivalent:@""] setTarget:self];
[[extraMenu addItemWithTitle:[localizedStrings objectForKey:kOpenNetworkPrefsTitle]
action:@selector(openNetworkPrefs:)
keyEquivalent:@""] setTarget:self];
// Open Internet Connect if PPP
if (pppPresent && !isLeopardOrLater) {
[[extraMenu addItemWithTitle:[localizedStrings objectForKey:kOpenInternetConnectTitle]
action:@selector(openInternetConnect:)
keyEquivalent:@""] setTarget:self];
}
// Send the menu back to SystemUIServer
return extraMenu;
} // menu
///////////////////////////////////////////////////////////////
//
// Image renderers
//
///////////////////////////////////////////////////////////////
- (void)renderGraphIntoImage:(NSImage *)image {
// Cache style and other values for duration of this method
int graphStyle = [ourPrefs netGraphStyle];
BOOL rxOnTop = ([ourPrefs netDisplayOrientation] == kNetDisplayOrientRxTx) ? YES : NO;
NSSize imageSize = [image size];
float graphHeight = (float)floor((imageSize.height - 1) / 2);
// Graph paths
NSBezierPath *topPath = [NSBezierPath bezierPath];
NSBezierPath *bottomPath = [NSBezierPath bezierPath];
if ((graphStyle == kNetGraphStyleOpposed) || (graphStyle == kNetGraphStyleInverseOpposed)) {
[bottomPath moveToPoint:NSMakePoint(0, 0)];
[bottomPath lineToPoint:NSMakePoint(0, 0.5f)];
[topPath moveToPoint:NSMakePoint(0, imageSize.height)];
[topPath lineToPoint:NSMakePoint(0, imageSize.height - 0.5f)];
} else if (graphStyle == kNetGraphStyleCentered) {
[topPath moveToPoint:NSMakePoint(0, graphHeight + 1)];
[topPath lineToPoint:NSMakePoint(0, graphHeight + 1.5f)];
[bottomPath moveToPoint:NSMakePoint(0, graphHeight)];
[bottomPath lineToPoint:NSMakePoint(0, graphHeight - 0.5f)];
} else {
[topPath moveToPoint:NSMakePoint(0, graphHeight + 1)];
[topPath lineToPoint:NSMakePoint(0, graphHeight + 1.5f)];
[bottomPath moveToPoint:NSMakePoint(0, 0)];
[bottomPath lineToPoint:NSMakePoint(0, 0.5f)];
}
// Get scale (scale is based on latest primary data, not historical)
float scaleFactor = 0;
switch ([ourPrefs netScaleMode]) {
case kNetScaleInterfaceSpeed:
if ([preferredInterfaceConfig objectForKey:@"speed"]) {
scaleFactor = [[preferredInterfaceConfig objectForKey:@"speed"] floatValue] / 8; // Convert to bytes
}
break;
case kNetScalePeakTraffic:
if (![preferredInterfaceConfig objectForKey:@"statname"]) break;
if (![netHistoryData count]) break;
NSDictionary *primaryStats = [[netHistoryData objectAtIndex:0]
objectForKey:[preferredInterfaceConfig objectForKey:@"statname"]];
if (![primaryStats objectForKey:@"peak"]) break;
scaleFactor = [[primaryStats objectForKey:@"peak"] floatValue];
break;
}
if (scaleFactor > 0) {
switch ([ourPrefs netScaleCalc]) {
case kNetScaleCalcLinear:
// Nothing
break;
case kNetScaleCalcSquareRoot:
scaleFactor = sqrtf(scaleFactor);
break;
case kNetScaleCalcCubeRoot:
scaleFactor = cbrtf(scaleFactor);
break;
case kNetScaleCalcLog:
scaleFactor = logf(scaleFactor);
break;
}
}
// Loop over pixels in desired width until we're out of data
int renderPosition = 0;
float renderHeight = graphHeight - 0.5f; // Save room for baseline
for (renderPosition = 0; renderPosition < [ourPrefs netGraphLength]; renderPosition++) {
// No data at this position?
if ((renderPosition >= [netHistoryData count]) ||
(renderPosition >= [netHistoryIntervals count])) break;
// Can't scale by zero
if (scaleFactor <= 0) continue;
// Grab history data
NSDictionary *netHistoryEntry = [netHistoryData objectAtIndex:renderPosition];
if (!netHistoryData) continue;
float sampleInterval = [[netHistoryIntervals objectAtIndex:renderPosition] floatValue];
if (sampleInterval <= 0) continue;
// Grab stats for the primary
if (![preferredInterfaceConfig objectForKey:@"statname"]) continue;
NSDictionary *primaryStats = [netHistoryEntry objectForKey:[preferredInterfaceConfig objectForKey:@"statname"]];
if (!primaryStats) continue;
// Calc scaled values
float txValue = [[primaryStats objectForKey:@"deltaout"] floatValue] / sampleInterval;
float rxValue = [[primaryStats objectForKey:@"deltain"] floatValue] / sampleInterval;
switch ([ourPrefs netScaleCalc]) {
case kNetScaleCalcLinear:
txValue = txValue / scaleFactor;
rxValue = rxValue / scaleFactor;
break;
case kNetScaleCalcSquareRoot:
txValue = sqrtf(txValue) / scaleFactor;
rxValue = sqrtf(rxValue) / scaleFactor;
break;
case kNetScaleCalcCubeRoot:
txValue = cbrtf(txValue) / scaleFactor;
rxValue = cbrtf(rxValue) / scaleFactor;
break;
case kNetScaleCalcLog:
txValue = logf(txValue) / scaleFactor;
rxValue = logf(rxValue) / scaleFactor;
break;
}
// Bound
if (txValue > 1) { txValue = 1; }
if (rxValue > 1) { rxValue = 1; }
if (txValue < 0) { txValue = 0; }
if (rxValue < 0) { rxValue = 0; }
// Update paths
if (graphStyle == kNetGraphStyleInverseOpposed) {
if (rxOnTop) {
[topPath lineToPoint:NSMakePoint(renderPosition, imageSize.height - (rxValue * renderHeight) - 0.5f)];
[bottomPath lineToPoint:NSMakePoint(renderPosition, (txValue * renderHeight) + 0.5f)];
} else {
[topPath lineToPoint:NSMakePoint(renderPosition, imageSize.height - (txValue * renderHeight) - 0.5f)];
[bottomPath lineToPoint:NSMakePoint(renderPosition, (rxValue * renderHeight) + 0.5f)];
}
} else if (graphStyle == kNetGraphStyleOpposed) {
if (rxOnTop) {
[topPath lineToPoint:NSMakePoint(renderPosition, imageSize.height - (txValue * renderHeight) - 0.5f)];
[bottomPath lineToPoint:NSMakePoint(renderPosition, (rxValue * renderHeight) + 0.5f)];
} else {
[topPath lineToPoint:NSMakePoint(renderPosition, imageSize.height - (rxValue * renderHeight) - 0.5f)];
[bottomPath lineToPoint:NSMakePoint(renderPosition, (txValue * renderHeight) + 0.5f)];
}
} else if (graphStyle == kNetGraphStyleCentered) {
if (rxOnTop) {
[topPath lineToPoint:NSMakePoint(renderPosition, (rxValue * renderHeight) + graphHeight + 1.5f)];
[bottomPath lineToPoint:NSMakePoint(renderPosition, graphHeight - (txValue * renderHeight) - 0.5f)];
} else {
[topPath lineToPoint:NSMakePoint(renderPosition, (txValue * renderHeight) + graphHeight + 1.5f)];
[bottomPath lineToPoint:NSMakePoint(renderPosition, graphHeight - (rxValue * renderHeight) - 0.5f)];
}
} else {
if (rxOnTop) {
[topPath lineToPoint:NSMakePoint(renderPosition, (rxValue * renderHeight) + graphHeight + 1.5f)];
[bottomPath lineToPoint:NSMakePoint(renderPosition, (txValue * renderHeight) + 0.5f)];
} else {
[topPath lineToPoint:NSMakePoint(renderPosition, (txValue * renderHeight) + graphHeight + 1.5f)];
[bottomPath lineToPoint:NSMakePoint(renderPosition, (rxValue * renderHeight) + 0.5f)];
}
}
}
// Return to lower edge (fill will close the graph)
if ((graphStyle == kNetGraphStyleOpposed) || (graphStyle == kNetGraphStyleInverseOpposed)) {
[topPath lineToPoint:NSMakePoint(renderPosition - 1, imageSize.height - 0.5f)];
[topPath lineToPoint:NSMakePoint(renderPosition - 1, imageSize.height)];
[bottomPath lineToPoint:NSMakePoint(renderPosition - 1, 0.5f)];
[bottomPath lineToPoint:NSMakePoint(renderPosition - 1, 0)];
} else if (graphStyle == kNetGraphStyleCentered) {
[topPath lineToPoint:NSMakePoint(renderPosition - 1, graphHeight + 1.5f)];
[topPath lineToPoint:NSMakePoint(renderPosition - 1, graphHeight + 1)];
[bottomPath lineToPoint:NSMakePoint(renderPosition - 1, graphHeight - 0.5f)];
[bottomPath lineToPoint:NSMakePoint(renderPosition - 1, graphHeight)];
} else {
[topPath lineToPoint:NSMakePoint(renderPosition - 1, graphHeight + 1.5f)];
[topPath lineToPoint:NSMakePoint(renderPosition - 1, graphHeight + 1)];
[bottomPath lineToPoint:NSMakePoint(renderPosition - 1, 0.5f)];
[bottomPath lineToPoint:NSMakePoint(renderPosition - 1, 0)];
}
// Draw
[image lockFocus];
if (![preferredInterfaceConfig objectForKey:@"interfaceup"]) {
[inactiveColor set];
[topPath fill];
[bottomPath fill];
} else {
if (rxOnTop) {
[rxColor set];
[topPath fill];
[txColor set];
[bottomPath fill];
} else {
[rxColor set];
[bottomPath fill];
[txColor set];