Skip to content

Commit 320849b

Browse files
committed
Merge #62
2 parents c64def1 + 4eb8f4d commit 320849b

File tree

14 files changed

+40
-2
lines changed

14 files changed

+40
-2
lines changed

Battery Time Remaining/AppDelegate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#define kBTRMenuEnergySaverSetting 9
2323
#define kBTRMenuUpdater 10
2424
#define kBTRMenuQuitKey 11
25+
#define kBTRMenuFahrenheit 12
2526

2627
#endif
2728

Battery Time Remaining/AppDelegate.m

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ @interface AppDelegate ()
4242
BOOL isOptionKeyPressed;
4343
BOOL isCapacityWarning;
4444
BOOL showParenthesis;
45+
BOOL displayFahrenheit;
4546
}
4647

4748
- (void)cacheBatteryIcon;
4849
- (NSImage *)loadBatteryIconNamed:(NSString *)iconName;
50+
- (double)convertCelsiusToFahrenheit:(double)celsius;
4951

5052
@end
5153

@@ -126,11 +128,19 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
126128
parenthesisSubmenuItem.target = self;
127129
showParenthesis = [[NSUserDefaults standardUserDefaults] boolForKey:@"parentheses"];
128130
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;
129138

130139
// Build the setting submenu
131140
NSMenu *settingSubmenu = [[NSMenu alloc] initWithTitle:@"Setting Menu"];
132141
[settingSubmenu addItem:advancedSubmenuItem];
133142
[settingSubmenu addItem:parenthesisSubmenuItem];
143+
[settingSubmenu addItem:displayFahrenheitSubmenuItem];
134144

135145
// Settings menu item
136146
NSMenuItem *settingMenu = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Settings", @"Settings menuitem") action:nil keyEquivalent:@""];
@@ -382,7 +392,7 @@ - (void)updateStatusItemMenu
382392
[NSString stringWithFormat:NSLocalizedString(@"Cycle count: %ld", @"Advanced battery info menuitem"), [cycleCount integerValue]],
383393
[NSString stringWithFormat:NSLocalizedString(@"Power usage: %.2f Watt", @"Advanced battery info menuitem"), [watt doubleValue]],
384394
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]],
386396
nil];
387397

388398
NSDictionary *advancedAttributedStyle = [NSDictionary dictionaryWithObjectsAndKeys:
@@ -622,6 +632,28 @@ - (void)toggleParenthesis:(id)sender
622632
[self updateStatusItem];
623633
}
624634

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+
625657
- (void)notify:(NSString *)message
626658
{
627659
[self notify:@"Battery Time Remaining" message:message];
@@ -697,6 +729,11 @@ - (void)optionKeyPressed
697729
}
698730
}
699731

732+
- (double)convertCelsiusToFahrenheit:(double)celsius
733+
{
734+
return ((celsius * 9.0) / 5.0 + 32.0);
735+
}
736+
700737
#pragma mark - NSUserNotificationCenterDelegate methods
701738

702739
// Force show notification
@@ -792,4 +829,4 @@ - (void)menuDidClose:(NSMenu *)menu
792829
optionKeyPressedTimer = nil;
793830
}
794831

795-
@end
832+
@end
464 Bytes
Binary file not shown.
480 Bytes
Binary file not shown.
482 Bytes
Binary file not shown.
476 Bytes
Binary file not shown.
394 Bytes
Binary file not shown.
468 Bytes
Binary file not shown.
482 Bytes
Binary file not shown.
476 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)