Skip to content

Add option to display temperature in degrees Fahrenheit #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 5, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Battery Time Remaining/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define kBTRMenuEnergySaverSetting 9
#define kBTRMenuUpdater 10
#define kBTRMenuQuitKey 11
#define kBTRMenuFahrenheit 12

#endif

Expand Down
41 changes: 39 additions & 2 deletions Battery Time Remaining/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ @interface AppDelegate ()
BOOL isOptionKeyPressed;
BOOL isCapacityWarning;
BOOL showParenthesis;
BOOL displayFahrenheit;
}

- (void)cacheBatteryIcon;
- (NSImage *)loadBatteryIconNamed:(NSString *)iconName;
- (double)convertCelsiusToFahrenheit:(double)celsius;

@end

Expand Down Expand Up @@ -123,11 +125,19 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
parenthesisSubmenuItem.target = self;
showParenthesis = [[NSUserDefaults standardUserDefaults] boolForKey:@"parentheses"];
parenthesisSubmenuItem.state = (showParenthesis) ? NSOnState : NSOffState;

// Display in Fahrenheit menu item
NSMenuItem *displayFahrenheitSubmenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Display temperature in degrees Fahrenheit", @"Display temperature in Fahrenheit setting") action:@selector(toggleFahrenheit:) keyEquivalent:@""];
[displayFahrenheitSubmenuItem setTag:kBTRMenuFahrenheit];
displayFahrenheitSubmenuItem.target = self;
displayFahrenheit = [[NSUserDefaults standardUserDefaults] boolForKey:@"fahrenheit"];
displayFahrenheitSubmenuItem.state = (displayFahrenheit) ? NSOnState : NSOffState;

// Build the setting submenu
NSMenu *settingSubmenu = [[NSMenu alloc] initWithTitle:@"Setting Menu"];
[settingSubmenu addItem:advancedSubmenuItem];
[settingSubmenu addItem:parenthesisSubmenuItem];
[settingSubmenu addItem:displayFahrenheitSubmenuItem];

// Settings menu item
NSMenuItem *settingMenu = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Settings", @"Settings menuitem") action:nil keyEquivalent:@""];
Expand Down Expand Up @@ -328,11 +338,11 @@ - (void)updateStatusItemMenu

[self.statusItem.menu itemWithTag:kBTRMenuPowerSourcePercent].title = [NSString stringWithFormat: NSLocalizedString(@"%ld %% left ( %ld/%ld mAh )", @"Advanced percentage left menuitem"), self.currentPercent, [currentBatteryPower integerValue], [maxBatteryPower integerValue]];

// Each item in array will be a row in menu
// Each item in array will be a row in menu
NSArray *advancedBatteryInfoTexts = [NSArray arrayWithObjects:
[NSString stringWithFormat:NSLocalizedString(@"Cycle count: %ld", @"Advanced battery info menuitem"), [cycleCount integerValue]],
[NSString stringWithFormat:NSLocalizedString(@"Power usage: %.2f Watt", @"Advanced battery info menuitem"), [watt doubleValue]],
[NSString stringWithFormat:NSLocalizedString(@"Temperature: %.1f°C", @"Advanced battery info menuitem"), [temperature doubleValue]],
(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]],
nil];

NSDictionary *advancedAttributedStyle = [NSDictionary dictionaryWithObjectsAndKeys:
Expand Down Expand Up @@ -572,6 +582,28 @@ - (void)toggleParenthesis:(id)sender
[self updateStatusItem];
}

- (void)toggleFahrenheit:(id)sender
{
NSMenuItem *item = sender;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

if ([defaults boolForKey:@"fahrenheit"])
{
item.state = NSOffState;
displayFahrenheit = NO;
[defaults setBool:NO forKey:@"fahrenheit"];
}
else
{
item.state = NSOnState;
displayFahrenheit = YES;
[defaults setBool:YES forKey:@"fahrenheit"];
}
[defaults synchronize];

[self updateStatusItem];
}

- (void)notify:(NSString *)message
{
[self notify:@"Battery Time Remaining" message:message];
Expand Down Expand Up @@ -647,6 +679,11 @@ - (void)optionKeyPressed
}
}

- (double)convertCelsiusToFahrenheit:(double)celsius
{
return ((celsius * 9.0) / 5.0 + 32.0);
}

#pragma mark - NSUserNotificationCenterDelegate methods

// Force show notification
Expand Down
Binary file modified Battery Time Remaining/de.lproj/Localizable.strings
Binary file not shown.
Binary file modified Battery Time Remaining/en.lproj/Localizable.strings
Binary file not shown.
Binary file modified Battery Time Remaining/es.lproj/Localizable.strings
Binary file not shown.
Binary file modified Battery Time Remaining/fr.lproj/Localizable.strings
Binary file not shown.
Binary file modified Battery Time Remaining/it.lproj/Localizable.strings
Binary file not shown.
Binary file modified Battery Time Remaining/ko.lproj/Localizable.strings
Binary file not shown.
Binary file modified Battery Time Remaining/nl.lproj/Localizable.strings
Binary file not shown.
Binary file modified Battery Time Remaining/pl.lproj/Localizable.strings
Binary file not shown.
Binary file modified Battery Time Remaining/pt.lproj/Localizable.strings
Binary file not shown.
Binary file modified Battery Time Remaining/ru.lproj/Localizable.strings
Binary file not shown.
Binary file modified Battery Time Remaining/sk.lproj/Localizable.strings
Binary file not shown.
Binary file modified Battery Time Remaining/sv.lproj/Localizable.strings
Binary file not shown.
Binary file modified Battery Time Remaining/zh-Hans.lproj/Localizable.strings
Binary file not shown.