@@ -39,10 +39,12 @@ @interface AppDelegate ()
39
39
BOOL isOptionKeyPressed;
40
40
BOOL isCapacityWarning;
41
41
BOOL showParenthesis;
42
+ BOOL displayFahrenheit;
42
43
}
43
44
44
45
- (void )cacheBatteryIcon ;
45
46
- (NSImage *)loadBatteryIconNamed : (NSString *)iconName ;
47
+ - (double )convertCelsiusToFahrenheit : (double )celsius ;
46
48
47
49
@end
48
50
@@ -123,11 +125,19 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
123
125
parenthesisSubmenuItem.target = self;
124
126
showParenthesis = [[NSUserDefaults standardUserDefaults ] boolForKey: @" parentheses" ];
125
127
parenthesisSubmenuItem.state = (showParenthesis) ? NSOnState : NSOffState ;
128
+
129
+ // Display in Fahrenheit menu item
130
+ NSMenuItem *displayFahrenheitSubmenuItem = [[NSMenuItem alloc ] initWithTitle: NSLocalizedString(@" Display temperature in degrees Fahrenheit" , @" Display temperature in Fahrenheit setting" ) action: @selector (toggleFahrenheit: ) keyEquivalent: @" " ];
131
+ [displayFahrenheitSubmenuItem setTag: kBTRMenuFahrenheit ];
132
+ displayFahrenheitSubmenuItem.target = self;
133
+ displayFahrenheit = [[NSUserDefaults standardUserDefaults ] boolForKey: @" fahrenheit" ];
134
+ displayFahrenheitSubmenuItem.state = (displayFahrenheit) ? NSOnState : NSOffState ;
126
135
127
136
// Build the setting submenu
128
137
NSMenu *settingSubmenu = [[NSMenu alloc ] initWithTitle: @" Setting Menu" ];
129
138
[settingSubmenu addItem: advancedSubmenuItem];
130
139
[settingSubmenu addItem: parenthesisSubmenuItem];
140
+ [settingSubmenu addItem: displayFahrenheitSubmenuItem];
131
141
132
142
// Settings menu item
133
143
NSMenuItem *settingMenu = [[NSMenuItem alloc ] initWithTitle: NSLocalizedString(@" Settings" , @" Settings menuitem" ) action: nil keyEquivalent: @" " ];
@@ -328,11 +338,11 @@ - (void)updateStatusItemMenu
328
338
329
339
[self .statusItem.menu itemWithTag: kBTRMenuPowerSourcePercent ].title = [NSString stringWithFormat: NSLocalizedString(@" %ld %% left ( %ld /%ld mAh )" , @" Advanced percentage left menuitem" ), self .currentPercent, [currentBatteryPower integerValue ], [maxBatteryPower integerValue ]];
330
340
331
- // Each item in array will be a row in menu
341
+ // Each item in array will be a row in menu
332
342
NSArray *advancedBatteryInfoTexts = [NSArray arrayWithObjects:
333
343
[NSString stringWithFormat: NSLocalizedString(@" Cycle count: %ld " , @" Advanced battery info menuitem" ), [cycleCount integerValue ]],
334
344
[NSString stringWithFormat: NSLocalizedString(@" Power usage: %.2f Watt" , @" Advanced battery info menuitem" ), [watt doubleValue ]],
335
- [NSString stringWithFormat: NSLocalizedString(@" Temperature: %.1f °C" , @" Advanced battery info menuitem" ), [temperature doubleValue ]],
345
+ (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 ]],
336
346
nil ];
337
347
338
348
NSDictionary *advancedAttributedStyle = [NSDictionary dictionaryWithObjectsAndKeys:
@@ -572,6 +582,28 @@ - (void)toggleParenthesis:(id)sender
572
582
[self updateStatusItem ];
573
583
}
574
584
585
+ - (void )toggleFahrenheit : (id )sender
586
+ {
587
+ NSMenuItem *item = sender;
588
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults ];
589
+
590
+ if ([defaults boolForKey: @" fahrenheit" ])
591
+ {
592
+ item.state = NSOffState ;
593
+ displayFahrenheit = NO ;
594
+ [defaults setBool: NO forKey: @" fahrenheit" ];
595
+ }
596
+ else
597
+ {
598
+ item.state = NSOnState ;
599
+ displayFahrenheit = YES ;
600
+ [defaults setBool: YES forKey: @" fahrenheit" ];
601
+ }
602
+ [defaults synchronize ];
603
+
604
+ [self updateStatusItem ];
605
+ }
606
+
575
607
- (void )notify : (NSString *)message
576
608
{
577
609
[self notify: @" Battery Time Remaining" message: message];
@@ -647,6 +679,11 @@ - (void)optionKeyPressed
647
679
}
648
680
}
649
681
682
+ - (double )convertCelsiusToFahrenheit : (double )celsius
683
+ {
684
+ return ((celsius * 9.0 ) / 5.0 + 32.0 );
685
+ }
686
+
650
687
#pragma mark - NSUserNotificationCenterDelegate methods
651
688
652
689
// Force show notification
0 commit comments