@@ -42,10 +42,12 @@ @interface AppDelegate ()
42
42
BOOL isOptionKeyPressed;
43
43
BOOL isCapacityWarning;
44
44
BOOL showParenthesis;
45
+ BOOL displayFahrenheit;
45
46
}
46
47
47
48
- (void )cacheBatteryIcon ;
48
49
- (NSImage *)loadBatteryIconNamed : (NSString *)iconName ;
50
+ - (double )convertCelsiusToFahrenheit : (double )celsius ;
49
51
50
52
@end
51
53
@@ -126,11 +128,19 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
126
128
parenthesisSubmenuItem.target = self;
127
129
showParenthesis = [[NSUserDefaults standardUserDefaults ] boolForKey: @" parentheses" ];
128
130
parenthesisSubmenuItem.state = (showParenthesis) ? NSOnState : NSOffState ;
131
+
132
+ // Display in Fahrenheit menu item
133
+ NSMenuItem *displayFahrenheitSubmenuItem = [[NSMenuItem alloc ] initWithTitle: NSLocalizedString(@" Display temperature in degrees Fahrenheit" , @" Display temperature in Fahrenheit setting" ) action: @selector (toggleFahrenheit: ) keyEquivalent: @" " ];
134
+ [displayFahrenheitSubmenuItem setTag: kBTRMenuFahrenheit ];
135
+ displayFahrenheitSubmenuItem.target = self;
136
+ displayFahrenheit = [[NSUserDefaults standardUserDefaults ] boolForKey: @" fahrenheit" ];
137
+ displayFahrenheitSubmenuItem.state = (displayFahrenheit) ? NSOnState : NSOffState ;
129
138
130
139
// Build the setting submenu
131
140
NSMenu *settingSubmenu = [[NSMenu alloc ] initWithTitle: @" Setting Menu" ];
132
141
[settingSubmenu addItem: advancedSubmenuItem];
133
142
[settingSubmenu addItem: parenthesisSubmenuItem];
143
+ [settingSubmenu addItem: displayFahrenheitSubmenuItem];
134
144
135
145
// Settings menu item
136
146
NSMenuItem *settingMenu = [[NSMenuItem alloc ] initWithTitle: NSLocalizedString(@" Settings" , @" Settings menuitem" ) action: nil keyEquivalent: @" " ];
@@ -382,7 +392,7 @@ - (void)updateStatusItemMenu
382
392
[NSString stringWithFormat: NSLocalizedString(@" Cycle count: %ld " , @" Advanced battery info menuitem" ), [cycleCount integerValue ]],
383
393
[NSString stringWithFormat: NSLocalizedString(@" Power usage: %.2f Watt" , @" Advanced battery info menuitem" ), [watt doubleValue ]],
384
394
timeSinceUnpluggedTranslated,
385
- [NSString stringWithFormat: NSLocalizedString(@" Temperature: %.1f °C" , @" Advanced battery info menuitem" ), [temperature doubleValue ]],
395
+ (displayFahrenheit) ? [ NSString stringWithFormat: NSLocalizedString( @" Temperature: %.1f °F " , @" Advanced battery info menuitem " ), [ self convertCelsiusToFahrenheit: [temperature doubleValue ]]] : [NSString stringWithFormat: NSLocalizedString(@" Temperature: %.1f °C" , @" Advanced battery info menuitem" ), [temperature doubleValue ]],
386
396
nil ];
387
397
388
398
NSDictionary *advancedAttributedStyle = [NSDictionary dictionaryWithObjectsAndKeys:
@@ -622,6 +632,28 @@ - (void)toggleParenthesis:(id)sender
622
632
[self updateStatusItem ];
623
633
}
624
634
635
+ - (void )toggleFahrenheit : (id )sender
636
+ {
637
+ NSMenuItem *item = sender;
638
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults ];
639
+
640
+ if ([defaults boolForKey: @" fahrenheit" ])
641
+ {
642
+ item.state = NSOffState ;
643
+ displayFahrenheit = NO ;
644
+ [defaults setBool: NO forKey: @" fahrenheit" ];
645
+ }
646
+ else
647
+ {
648
+ item.state = NSOnState ;
649
+ displayFahrenheit = YES ;
650
+ [defaults setBool: YES forKey: @" fahrenheit" ];
651
+ }
652
+ [defaults synchronize ];
653
+
654
+ [self updateStatusItem ];
655
+ }
656
+
625
657
- (void )notify : (NSString *)message
626
658
{
627
659
[self notify: @" Battery Time Remaining" message: message];
@@ -697,6 +729,11 @@ - (void)optionKeyPressed
697
729
}
698
730
}
699
731
732
+ - (double )convertCelsiusToFahrenheit : (double )celsius
733
+ {
734
+ return ((celsius * 9.0 ) / 5.0 + 32.0 );
735
+ }
736
+
700
737
#pragma mark - NSUserNotificationCenterDelegate methods
701
738
702
739
// Force show notification
@@ -792,4 +829,4 @@ - (void)menuDidClose:(NSMenu *)menu
792
829
optionKeyPressedTimer = nil ;
793
830
}
794
831
795
- @end
832
+ @end
0 commit comments