-
Notifications
You must be signed in to change notification settings - Fork 222
/
Copy pathMenuMeterDefaults.m
735 lines (594 loc) · 23.6 KB
/
MenuMeterDefaults.m
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
//
// MenuMeterDefaults.m
//
// Preference (defaults) file reader/writer
//
// Copyright (c) 2002-2014 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 "MenuMeterDefaults.h"
#import "MenuMeterCPU.h"
#import "MenuMeterMem.h"
#import "MenuMeterDisk.h"
#import "MenuMeterNet.h"
///////////////////////////////////////////////////////////////
//
// Private
//
///////////////////////////////////////////////////////////////
@interface MenuMeterDefaults (PrivateMethods)
// Datatype read/write
- (double)loadDoublePref:(NSString *)prefName lowBound:(double)lowBound
highBound:(double)highBound defaultValue:(double)defaultValue;
- (void)saveDoublePref:(NSString *)prefName value:(double)value;
- (int)loadIntPref:(NSString *)prefName lowBound:(int)lowBound
highBound:(int)highBound defaultValue:(int)defaultValue;
- (void)saveIntPref:(NSString *)prefName value:(int)value;
- (int)loadBitFlagPref:(NSString *)prefName validFlags:(int)flags
defaultValue:(int)defaultValue;
- (void)saveBitFlagPref:(NSString *)prefName value:(int)value;
#ifndef ELCAPITAN
- (BOOL)loadBoolPref:(NSString *)prefName defaultValue:(BOOL)defaultValue;
- (void)saveBoolPref:(NSString *)prefName value:(BOOL)value;
#endif
- (NSColor *)loadColorPref:(NSString *)prefName defaultValue:(NSColor *)defaultValue;
- (void)saveColorPref:(NSString *)prefname value:(NSColor *)value;
- (NSString *)loadStringPref:(NSString *)prefName defaultValue:(NSString *)defaultValue;
- (void)saveStringPref:(NSString *)prefName value:(NSString *)value;
- (BOOL)isCatalinaOrLater;
@end
///////////////////////////////////////////////////////////////
//
// init/dealloc
//
///////////////////////////////////////////////////////////////
@implementation MenuMeterDefaults
#define kMigratedFromRagingMenaceToYujitach @"migratedFromRagingMenaceToYujitach"
+ (void)movePreferencesIfNecessary
{
if([[NSUserDefaults standardUserDefaults] boolForKey:kMigratedFromRagingMenaceToYujitach])
return;
NSData*data=[NSData dataWithContentsOfFile:[[NSString stringWithFormat:@"~/Library/Preferences/%@.plist", kMenuMeterDefaultsDomain] stringByExpandingTildeInPath]];
if(data){
NSError*error=nil;
NSDictionary*dict=[NSPropertyListSerialization propertyListWithData:data options:NSPropertyListImmutable format:nil error:&error];
if(dict){
NSData*defaultData=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kMenuMeterDefaultsDomain ofType:@"plist"]];
NSDictionary*defaultDict=[NSPropertyListSerialization propertyListWithData:defaultData options:NSPropertyListImmutable format:nil error:nil];
for(NSString*key in [dict allKeys]){
NSLog(@"migrating %@", key);
NSObject*value=[dict objectForKey:key];
NSObject*defaultValue=[defaultDict objectForKey:key];
if([value isEqualTo:defaultValue]){
NSLog(@"\t%@ has default value; no need to copy",key);
}else{
NSLog(@"\t%@ has non-default value; copying",key);
[[NSUserDefaults standardUserDefaults] setObject:[dict objectForKey:key] forKey:key];
}
}
}else{
NSLog(@"error reading old pref plist: %@",error);
}
}
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:kMigratedFromRagingMenaceToYujitach];
}
+ (MenuMeterDefaults*)sharedMenuMeterDefaults
{
static MenuMeterDefaults*foo=nil;
if(!foo){
foo=[[MenuMeterDefaults alloc] init];
}
return foo;
}
- (id)init {
// Allow super to init
self = [super init];
if (!self) {
return nil;
}
// Send on back
return self;
} // init
- (void)dealloc {
// Super do its thing
[[NSNotificationCenter defaultCenter] removeObserver:self];
} // dealloc
- (BOOL) isCatalinaOrLater {
static dispatch_once_t once;
static BOOL isCatalinaOrLater;
dispatch_once(&once,^{
if(@available(macOS 10.15, *)){
isCatalinaOrLater=YES;
}else{
isCatalinaOrLater=NO;
}
});
return isCatalinaOrLater;
}
///////////////////////////////////////////////////////////////
//
// CPU menu prefs
//
///////////////////////////////////////////////////////////////
- (double)cpuInterval {
return [self loadDoublePref:kCPUIntervalPref
lowBound:kCPUUpdateIntervalMin
highBound:kCPUUpdateIntervalMax
defaultValue:kCPUUpdateIntervalDefault];
} // cpuInterval
- (int)cpuDisplayMode {
return [self loadBitFlagPref:kCPUDisplayModePref
validFlags:(kCPUDisplayPercent | kCPUDisplayGraph | kCPUDisplayThermometer | kCPUDisplayHorizontalThermometer)
defaultValue:kCPUDisplayDefault];
} // cpuDisplayMode
- (int)cpuPercentDisplay {
return [self loadIntPref:kCPUPercentDisplayPref
lowBound:kCPUPercentDisplayLarge
highBound:kCPUPercentDisplaySplit
defaultValue:kCPUPercentDisplayDefault];
} // cpuPercentDisplay
- (int)cpuMaxProcessCount {
return [self loadIntPref:kCPUMaxProcessCountPref
lowBound:kCPUProcessCountMin
highBound:kCPUrocessCountMax
defaultValue:kCPUProcessCountDefault];
} // cpuMaxProcessCount
- (int)cpuGraphLength {
return [self loadIntPref:kCPUGraphLengthPref
lowBound:kCPUGraphWidthMin
highBound:kCPUGraphWidthMax
defaultValue:kCPUGraphWidthDefault];
} // cpuGraphLength
- (int)cpuHorizontalRows {
return [self loadIntPref:kCPUHorizontalRowsPref
lowBound:kCPUHorizontalRowsMin
highBound:kCPUHorizontalRowsMax
defaultValue:kCPUHorizontalRowsDefault];
} // cpuHorizontalRows
- (int)cpuMenuWidth {
return [self loadIntPref:kCPUMenuWidthPref
lowBound:kCPUMenuWidthMin
highBound:kCPUMenuWidthMax
defaultValue:kCPUMenuWidthDefault];
} // cpuMenuWidth
- (BOOL)cpuAvgAllProcs {
return [self loadBoolPref:kCPUAvgAllProcsPref defaultValue:kCPUAvgAllProcsDefault];
} // cpuAvgAllProcs
- (BOOL)cpuSumAllProcsPercent {
return [self loadBoolPref:kCPUSumAllProcsPercentPref defaultValue:kCPUSumAllProcsPercentDefault];
} // cpuSumAllProcsPercent
- (BOOL)cpuAvgLowerHalfProcs {
return [self loadBoolPref:kCPUAvgLowerHalfProcsPref defaultValue:kCPUAvgLowerHalfProcsDefault];
} // cpuAvgLowerHalfProcs
- (BOOL)cpuSortByUsage {
return [self loadBoolPref:kCPUSortByUsagePref defaultValue:kCPUSortByUsageDefault];
} // cpuSortByUsage
- (BOOL)cpuPowerMate {
return [self loadBoolPref:kCPUPowerMatePref defaultValue:kCPUPowerMateDefault];
} // cpuPowerMate
- (int)cpuPowerMateMode {
return [self loadIntPref:kCPUPowerMateMode
lowBound:kCPUPowerMateGlow
highBound:kCPUPowerMateInversePulse
defaultValue:kCPUPowerMateModeDefault];
} // cpuPowerMateMode
- (int)cpuTemperatureUnit {
return [self loadIntPref:kCPUTemperatureUnit
lowBound:kCPUTemperatureUnitCelsius
highBound:kCPUTemperatureUnitFahrenheit
defaultValue:kCPUTemperatureUnitCelsius];
}
- (NSString*)cpuTemperatureSensor{
return [self loadStringPref:kCPUTemperatureSensor defaultValue:kCPUTemperatureSensorDefault];
}
-(void)saveCpuTemperatureSensor:(NSString *)name{
[self saveStringPref:kCPUTemperatureSensor value:name];
}
- (NSColor *)cpuSystemColor {
return [self loadColorPref:kCPUSystemColorPref defaultValue:kCPUSystemColorDefault];
} // cpuSystemColor
- (NSColor *)cpuUserColor {
return [self loadColorPref:kCPUUserColorPref defaultValue:kCPUUserColorDefault];
} // cpuUserColor
- (BOOL)cpuShowTemperature {
return [self loadBoolPref:kCPUShowTemperature defaultValue:kCPUShowTemperatureDefault];
}
- (NSColor *)cpuTemperatureColor {
return [self loadColorPref:kCPUTemperatureColor defaultValue:kCPUTemperatureColorDefault];
} //cpuTemperatureColor
- (void)saveCpuInterval:(double)interval {
[self saveDoublePref:kCPUIntervalPref value:interval];
} // saveCpuInterval
- (void)saveCpuDisplayMode:(int)mode {
[self saveIntPref:kCPUDisplayModePref value:mode];
} // saveCpuDisplayMode
- (void)saveCpuPercentDisplay:(int)mode {
[self saveIntPref:kCPUPercentDisplayPref value:mode];
} // saveCpuPercentSplit
- (void)saveCpuMaxProcessCount:(int)maxCount {
[self saveIntPref:kCPUMaxProcessCountPref value:maxCount];
} // saveCpuMaxProcessCount
- (void)saveCpuGraphLength:(int)length {
[self saveIntPref:kCPUGraphLengthPref value:length];
} // saveCpuGraphLength
- (void)saveCpuHorizontalRows:(int)rows {
[self saveIntPref:kCPUHorizontalRowsPref value:rows];
} // saveCpuHorizontalRows
- (void)saveCpuMenuWidth:(int)rows {
[self saveIntPref:kCPUMenuWidthPref value:rows];
} // saveCpuMenuWidth
- (void)saveCpuAvgAllProcs:(BOOL)average {
[self saveBoolPref:kCPUAvgAllProcsPref value:average];
} // saveCpuAvgAllProcs
- (void)saveCpuSumAllProcsPercent:(BOOL)sum {
[self saveBoolPref:kCPUSumAllProcsPercentPref value:sum];
} // saveCpuSumAllProcsPercent
- (void)saveCpuAvgLowerHalfProcs:(BOOL)average {
[self saveBoolPref:kCPUAvgLowerHalfProcsPref value:average];
} // saveCpuAvgLowerHalfProcs
- (void)saveCpuSortByUsage:(BOOL)sort {
[self saveBoolPref:kCPUSortByUsagePref value:sort];
} // saveCpuSortByUsage
- (void)saveCpuPowerMate:(BOOL)active {
[self saveBoolPref:kCPUPowerMatePref value:active];
} // saveCpuPowerMate
- (void)saveCpuPowerMateMode:(int)mode {
[self saveIntPref:kCPUPowerMateMode value:mode];
} // saveCpuPowerMateMode
- (void)saveCpuTemperatureUnit:(int)unit {
[self saveIntPref:kCPUTemperatureUnit value:unit];
} // saveCpuPowerMateMode
- (void)saveCpuTemperature:(BOOL)show {
[self saveBoolPref: kCPUShowTemperature value:show];
} // saveCpuTemperature
- (void)saveCpuTemperatureColor:(NSColor *)color {
[self saveColorPref:kCPUTemperatureColor value:color];
}
- (void)saveCpuSystemColor:(NSColor *)color {
[self saveColorPref:kCPUSystemColorPref value:color];
} // saveCpuSystemColor
- (void)saveCpuUserColor:(NSColor *)color {
[self saveColorPref:kCPUUserColorPref value:color];
} // saveCpuUserColor
///////////////////////////////////////////////////////////////
//
// Disk menu prefs
//
///////////////////////////////////////////////////////////////
- (double)diskInterval {
return [self loadDoublePref:kDiskIntervalPref
lowBound:kDiskUpdateIntervalMin
highBound:kDiskUpdateIntervalMax
defaultValue:kDiskUpdateIntervalDefault];
} // diskInterval
- (int)diskImageset {
return [self loadIntPref:kDiskImageSetPref
lowBound:kDiskImageSetDefault
highBound:((int)[kDiskImageSets count] - 1)
defaultValue:kDiskImageSetDefault];
} // diskImageset
- (int)diskSelectMode {
return [self loadIntPref:kDiskSelectModePref
lowBound:kDiskSelectModeOpen
highBound:kDiskSelectModeEject
defaultValue:kDiskSelectModeDefault];
} // diskSelectMode
- (BOOL)diskSpaceForceBaseTwo {
return [self loadBoolPref:kDiskSpaceForceBaseTwoPref
defaultValue:kDiskSpaceForceBaseTwoDefault];
} // diskSpaceForceBaseTwo
- (void)saveDiskInterval:(double)interval {
[self saveDoublePref:kDiskIntervalPref value:interval];
} // saveDiskInterval
- (void)saveDiskImageset:(int)imageset {
[self saveIntPref:kDiskImageSetPref value:imageset];
} // saveDiskImageset
- (void)saveDiskSelectMode:(int)mode {
[self saveIntPref:kDiskSelectModePref value:mode];
} // saveDiskSelectMode
///////////////////////////////////////////////////////////////
//
// Mem menu prefs
//
///////////////////////////////////////////////////////////////
- (double)memInterval {
return [self loadDoublePref:kMemIntervalPref
lowBound:kMemUpdateIntervalMin
highBound:kMemUpdateIntervalMax
defaultValue:kMemUpdateIntervalDefault];
} // memInterval
- (int)memDisplayMode {
return [self loadIntPref:kMemDisplayModePref
lowBound:kMemDisplayPie
highBound:kMemDisplayNumber
defaultValue:kMemDisplayDefault];
} // memDisplayMode
- (BOOL)memPageIndicator {
return [self loadBoolPref:kMemPageIndicatorPref defaultValue:kMemPageIndicatorDefault];
} // memPageIndicator
- (BOOL)memUsedFreeLabel {
return [self loadBoolPref:kMemUsedFreeLabelPref defaultValue:kMemUsedFreeLabelDefault];
} // memUsedFreeLabel
- (BOOL)memPressure {
return [self loadBoolPref:kMemPressurePref defaultValue:kMemPressureDefault];
} // memUsedFreeLabel
- (int)memGraphLength {
return [self loadIntPref:kMemGraphLengthPref
lowBound:kMemGraphWidthMin
highBound:kMemGraphWidthMax
defaultValue:kMemGraphWidthDefault];
} // memGraphLength
- (NSColor *)memFreeColor {
return [self loadColorPref:kMemFreeColorPref defaultValue:kMemFreeColorDefault];
} // memFreeColor
- (NSColor *)memUsedColor {
return [self loadColorPref:kMemUsedColorPref defaultValue:kMemUsedColorDefault];
} // memUsedColor
- (NSColor *)memActiveColor {
return [self loadColorPref:kMemActiveColorPref defaultValue:kMemActiveColorDefault];
} // memActiveColor
- (NSColor *)memInactiveColor {
return [self loadColorPref:kMemInactiveColorPref defaultValue:kMemInactiveColorDefault];
} // memInactiveColor
- (NSColor *)memWireColor {
return [self loadColorPref:kMemWireColorPref defaultValue:kMemWireColorDefault];
} // memWireColor
- (NSColor *)memCompressedColor {
return [self loadColorPref:kMemCompressedColorPref defaultValue:kMemCompressedColorDefault];
} // memCompressedColor
- (NSColor *)memPageInColor {
return [self loadColorPref:kMemPageInColorPref defaultValue:kMemPageInColorDefault];
} // memPageinColor
- (NSColor *)memPageOutColor {
return [self loadColorPref:kMemPageOutColorPref defaultValue:kMemPageOutColorDefault];
} // memPageoutColor
- (void)saveMemInterval:(double)interval {
[self saveDoublePref:kMemIntervalPref value:interval];
} // saveMemInterval
- (void)saveMemDisplayMode:(int)mode {
[self saveIntPref:kMemDisplayModePref value:mode];
} // saveMemDisplayMode
- (void)saveMemUsedFreeLabel:(BOOL)label {
[self saveBoolPref:kMemUsedFreeLabelPref value:label];
} // saveMemUsedFreeLabel
- (void)saveMemPressure:(BOOL)label {
[self saveBoolPref:kMemPressurePref value:label];
} // saveMemPressure
- (void)saveMemPageIndicator:(BOOL)indicator {
[self saveBoolPref:kMemPageIndicatorPref value:indicator];
} // saveMemPageIndicator
- (void)saveMemGraphLength:(int)length {
[self saveIntPref:kMemGraphLengthPref value:length];
} // saveMemGraphLength
- (void)saveMemFreeColor:(NSColor *)color {
[self saveColorPref:kMemFreeColorPref value:color];
} // saveMemFreeColor
- (void)saveMemUsedColor:(NSColor *)color {
[self saveColorPref:kMemUsedColorPref value:color];
} // saveMemUsedColor
- (void)saveMemActiveColor:(NSColor *)color {
[self saveColorPref:kMemActiveColorPref value:color];
} // saveMemActiveColor
- (void)saveMemInactiveColor:(NSColor *)color {
[self saveColorPref:kMemInactiveColorPref value:color];
} // saveMemInactiveColor
- (void)saveMemWireColor:(NSColor *)color {
[self saveColorPref:kMemWireColorPref value:color];
} // saveMemWireColor
- (void)saveMemCompressedColor:(NSColor *)color {
[self saveColorPref:kMemCompressedColorPref value:color];
} // saveMemCompressedColor
- (void)saveMemPageInColor:(NSColor *)color {
[self saveColorPref:kMemPageInColorPref value:color];
} // saveMemPageinColor
- (void)saveMemPageOutColor:(NSColor *)color {
[self saveColorPref:kMemPageOutColorPref value:color];
} // saveMemPageoutColor
///////////////////////////////////////////////////////////////
//
// Net menu prefs
//
///////////////////////////////////////////////////////////////
- (double)netInterval {
return [self loadDoublePref:kNetIntervalPref
lowBound:kNetUpdateIntervalMin
highBound:kNetUpdateIntervalMax
defaultValue:kNetUpdateIntervalDefault];
} // netInterval
- (int)netDisplayMode {
return [self loadBitFlagPref:kNetDisplayModePref
validFlags:(kNetDisplayThroughput | kNetDisplayGraph | kNetDisplayArrows)
defaultValue:kNetDisplayDefault];
} // netDisplayMode
- (int)netDisplayOrientation {
return [self loadIntPref:kNetDisplayOrientationPref
lowBound:kNetDisplayOrientTxRx
highBound:kNetDisplayOrientRxTx
defaultValue:kNetDisplayOrientationDefault];
} // netDisplayOrientation
- (int)netScaleMode {
return [self loadIntPref:kNetScaleModePref
lowBound:kNetScaleInterfaceSpeed
highBound:kNetScalePeakTraffic
defaultValue:kNetScaleDefault];
} // netScaleMode
- (int)netScaleCalc {
return [self loadIntPref:kNetScaleCalcPref
lowBound:kNetScaleCalcLinear
highBound:kNetScaleCalcLog
defaultValue:kNetScaleCalcDefault];
} // netScaleCalc
- (BOOL)netThroughputLabel {
return [self loadBoolPref:kNetThroughputLabelPref defaultValue:kNetThroughputLabelDefault];
} // netThroughputLabel
- (BOOL)netThroughput1KBound {
return [self loadBoolPref:kNetThroughput1KBoundPref defaultValue:kNetThroughput1KBoundDefault];
} // netThroughput1KBound
- (BOOL)netThroughputBits {
return [self loadBoolPref:kNetThroughputBitsPref defaultValue:kNetThroughputBitsDefault];
} // netThroughputBits
- (int)netGraphStyle {
return [self loadIntPref:kNetGraphStylePref
lowBound:kNetGraphStyleStandard
highBound:kNetGraphStyleInverseOpposed
defaultValue:kNetGraphStyleDefault];
} // netGraphStyle
- (int)netGraphLength {
return [self loadIntPref:kNetGraphLengthPref
lowBound:kNetGraphWidthMin
highBound:kNetGraphWidthMax
defaultValue:kNetGraphWidthDefault];
} // netGraphLength
- (NSColor *)netTransmitColor {
return [self loadColorPref:kNetTransmitColorPref defaultValue:kNetTransmitColorDefault];
} // netTransmitColor
- (NSColor *)netReceiveColor {
return [self loadColorPref:kNetReceiveColorPref defaultValue:kNetReceiveColorDefault];
} // netReceiveColor
- (NSColor *)netInactiveColor {
return [self loadColorPref:kNetInactiveColorPref defaultValue:kNetInactiveColorDefault];
} // netInactiveColor
- (NSString *)netPreferInterface {
return [self loadStringPref:kNetPreferInterfacePref defaultValue:kNetPrimaryInterface];
} // netPreferInterface
- (void)saveNetInterval:(double)interval {
[self saveDoublePref:kNetIntervalPref value:interval];
} // saveNetInterval
- (void)saveNetDisplayMode:(int)mode {
[self saveIntPref:kNetDisplayModePref value:mode];
} // saveNetDisplayMode
- (void)saveNetDisplayOrientation:(int)orient {
[self saveIntPref:kNetDisplayOrientationPref value:orient];
} // saveNetDisplayOrientation
- (void)saveNetScaleMode:(int)mode {
[self saveIntPref:kNetScaleModePref value:mode];
} // saveNetScaleMode
- (void)saveNetScaleCalc:(int)calc {
[self saveIntPref:kNetScaleCalcPref value:calc];
} // saveNetScaleCalc
- (void)saveNetThroughputLabel:(BOOL)label {
[self saveBoolPref:kNetThroughputLabelPref value:label];
} // saveNetThroughputLabel
- (void)saveNetThroughput1KBound:(BOOL)label {
[self saveBoolPref:kNetThroughput1KBoundPref value:label];
} // saveNetThroughput1KBound
- (void)saveNetThroughputBits:(BOOL)label {
[self saveBoolPref:kNetThroughputBitsPref value:label];
} // saveNetThroughputBits
- (void)saveNetGraphStyle:(int)style {
[self saveIntPref:kNetGraphStylePref value:style];
} // saveNetGraphStyle
- (void)saveNetGraphLength:(int)length {
[self saveIntPref:kNetGraphLengthPref value:length];
} // saveNetGraphLength
- (void)saveNetTransmitColor:(NSColor *)color {
[self saveColorPref:kNetTransmitColorPref value:color];
} // saveNetTransmitColor
- (void)saveNetReceiveColor:(NSColor *)color {
[self saveColorPref:kNetReceiveColorPref value:color];
} // saveNetReceiveColor
- (void)saveNetInactiveColor:(NSColor *)color {
[self saveColorPref:kNetInactiveColorPref value:color];
} // saveNetInactiveColor
- (void)saveNetPreferInterface:(NSString *)interface {
[self saveStringPref:kNetPreferInterfacePref value:interface];
} // saveNetPreferInterface
///////////////////////////////////////////////////////////////
//
// Datatype read/write
//
///////////////////////////////////////////////////////////////
- (double)loadDoublePref:(NSString *)prefName lowBound:(double)lowBound
highBound:(double)highBound defaultValue:(double)defaultValue {
double returnVal = defaultValue;
NSNumber *prefValue = [[NSUserDefaults standardUserDefaults] objectForKey:prefName];
if (prefValue && [prefValue isKindOfClass:[NSNumber class]]) {
returnVal = [prefValue doubleValue];
// Floating point comparison needs some margin of error. Scale up
// and truncate
if ((floor(returnVal * 100) < floor(lowBound * 100)) ||
(ceil(returnVal * 100) > ceil(highBound * 100))) {
returnVal = defaultValue;
[self saveDoublePref:prefName value:returnVal];
}
}
return returnVal;
} // _loadDoublePref
- (void)saveDoublePref:(NSString *)prefName value:(double)value {
[[NSUserDefaults standardUserDefaults] setDouble:value forKey:prefName];
} // _saveDoublePref
- (int)loadIntPref:(NSString *)prefName lowBound:(int)lowBound
highBound:(int)highBound defaultValue:(int)defaultValue {
int returnValue=defaultValue;
if([[NSUserDefaults standardUserDefaults] objectForKey:prefName]){
returnValue=(int)[[NSUserDefaults standardUserDefaults] integerForKey:prefName];
}
if(returnValue > highBound || returnValue < lowBound){
returnValue = defaultValue;
}
return (int) returnValue;
} // _loadIntPref
- (void)saveIntPref:(NSString *)prefname value:(int)value {
[[NSUserDefaults standardUserDefaults] setInteger:value forKey:prefname];
} // _saveIntPref
- (int)loadBitFlagPref:(NSString *)prefName validFlags:(int)flags defaultValue:(int)defaultValue {
if([[NSUserDefaults standardUserDefaults] objectForKey:prefName]){
int returnValue=(int)[[NSUserDefaults standardUserDefaults] integerForKey:prefName];
if (((returnValue | flags) == flags)) {
return returnValue;
}
}
return defaultValue;
} // _loadBitFlagPref
- (void)saveBitFlagPref:(NSString *)prefName value:(int)value {
[[NSUserDefaults standardUserDefaults] setInteger:value forKey:prefName];
} // _saveBitFlagPref
- (BOOL)loadBoolPref:(NSString *)prefName defaultValue:(BOOL)defaultValue {
if([[NSUserDefaults standardUserDefaults] objectForKey:prefName]){
return [[NSUserDefaults standardUserDefaults] boolForKey:prefName];
}
return defaultValue;
} // _loadBoolPref
- (void)saveBoolPref:(NSString *)prefName value:(BOOL)value {
[[NSUserDefaults standardUserDefaults] setBool:value forKey:prefName];
} // _saveBoolPref
- (NSColor *)loadColorPref:(NSString *)prefName defaultValue:(NSColor *)defaultValue {
NSData* data = [[NSUserDefaults standardUserDefaults] objectForKey:prefName];
if(data){
NSColor*color=[NSUnarchiver unarchiveObjectWithData:data];
if(color){
return color;
}
}
return defaultValue;
} // _loadColorPref
- (void)saveColorPref:(NSString *)prefName value:(NSColor *)value {
if (value) {
[[NSUserDefaults standardUserDefaults] setObject:[NSArchiver archivedDataWithRootObject:value] forKey:prefName];
}
} // _saveColorPref
- (NSString *)loadStringPref:(NSString *)prefName defaultValue:(NSString *)defaultValue {
NSString*s=[[NSUserDefaults standardUserDefaults] objectForKey:prefName];
if(s){
return s;
}
return defaultValue;
} // _loadStringPref
- (void)saveStringPref:(NSString *)prefName value:(NSString *)value {
[[NSUserDefaults standardUserDefaults] setObject:value forKey:prefName];
} // _saveStringPref
@end