From 4eb8f4d3c3963743c80e3411edd39cdc7884bf62 Mon Sep 17 00:00:00 2001 From: danielmartin Date: Wed, 10 Apr 2013 23:37:27 +0200 Subject: [PATCH] Add option to display temperature in degrees Fahrenheit --- Battery Time Remaining/AppDelegate.h | 1 + Battery Time Remaining/AppDelegate.m | 41 +++++++++++++++++- .../de.lproj/Localizable.strings | Bin 4442 -> 4906 bytes .../en.lproj/Localizable.strings | Bin 4210 -> 4686 bytes .../es.lproj/Localizable.strings | Bin 4360 -> 4840 bytes .../fr.lproj/Localizable.strings | Bin 3912 -> 4394 bytes .../it.lproj/Localizable.strings | Bin 3362 -> 3838 bytes .../ko.lproj/Localizable.strings | Bin 3018 -> 3412 bytes .../nl.lproj/Localizable.strings | Bin 3412 -> 3880 bytes .../pl.lproj/Localizable.strings | Bin 3832 -> 4314 bytes .../pt.lproj/Localizable.strings | Bin 3494 -> 3970 bytes .../ru.lproj/Localizable.strings | Bin 4458 -> 4936 bytes .../sk.lproj/Localizable.strings | Bin 3510 -> 3974 bytes .../sv.lproj/Localizable.strings | Bin 4302 -> 4764 bytes .../zh-Hans.lproj/Localizable.strings | Bin 3312 -> 3700 bytes 15 files changed, 40 insertions(+), 2 deletions(-) diff --git a/Battery Time Remaining/AppDelegate.h b/Battery Time Remaining/AppDelegate.h index 801d18b..fa0ad64 100644 --- a/Battery Time Remaining/AppDelegate.h +++ b/Battery Time Remaining/AppDelegate.h @@ -22,6 +22,7 @@ #define kBTRMenuEnergySaverSetting 9 #define kBTRMenuUpdater 10 #define kBTRMenuQuitKey 11 +#define kBTRMenuFahrenheit 12 #endif diff --git a/Battery Time Remaining/AppDelegate.m b/Battery Time Remaining/AppDelegate.m index 64f6c28..1732ca2 100644 --- a/Battery Time Remaining/AppDelegate.m +++ b/Battery Time Remaining/AppDelegate.m @@ -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 @@ -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:@""]; @@ -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: @@ -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]; @@ -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 diff --git a/Battery Time Remaining/de.lproj/Localizable.strings b/Battery Time Remaining/de.lproj/Localizable.strings index 9aeab647763348ba618ef99df7db69d7fca6f00d..9dcc92ecd7a63e8eab85704d8c1a7829e2adae45 100644 GIT binary patch delta 263 zcmcbmv`TG*0Ow>24k7(ihFpdMhE#?khD3%EhEgD%%AmlI$&d#m-GE{lV39l^oeC5! znOw-BTaQmq3Q%1-SWhZLF?KT;lz`&4K&-?N1vWJuNP_GO0n+HMfw{#U?7|d~i9(pp o+RVr~lYR0Wb~|wmY_4X|oUALL&*(NeRzMd>%ClHcJ|-{)0Mpqv4*&oF delta 20 ccmZ3bc1vl40Ow{ot}gb;dMrAVrwL5~07_N{!T8Qmrqg2{#a7XcrDIQ9Sl delta 20 ccmX@7@=0OC8IH+$+%}sPxK^-D?h!l$09``}P5=M^ diff --git a/Battery Time Remaining/es.lproj/Localizable.strings b/Battery Time Remaining/es.lproj/Localizable.strings index b48c63571154528158530834e6e0e91079bd672a..9f2980718feb3b5ca9a41e9773e0322d0d542bc0 100644 GIT binary patch delta 262 zcmeBBdZD`E2ghU)4k7(ihFpdMhE#?khD3%EhEgD%%AmlI$&d#m-GE{lV39l^oeC5! znLM9adU6JbkUc(qDL}R9V120!#W>7a$RX{T12kU&Xe*{!An{bN8$jkHGNdr%<21>Z oNp|uLZoSPWoILE4=keN!YhZIYgXZLm{Q8V;lNkj-q@lod0KB0&qW}N^ delta 24 gcmaE%+M%@J2ghU|CcepEc=R?0aPhEDRuDP?0D27w#Q*>R diff --git a/Battery Time Remaining/fr.lproj/Localizable.strings b/Battery Time Remaining/fr.lproj/Localizable.strings index 36b0a71dd8e52dd6dc608899e3395ef93dc0dd80..fff5298579c64356afe4fbc25f9d2db8a928f11c 100644 GIT binary patch delta 262 zcmX>hw@PV)2&bb9LncEpLjgk$Ln1>Zg91YdLn=cqke|v>1QaP@Ce9h_Qh_#MH)AV@ymKOw?Jv=6PX*f!GwCHRb2hVb ezGj`=z-}k5fz7E5nv)y(^cmeIZv>MM`O*QjjX8V( delta 20 ccmZ3bbV6=}2Zg91az^Ifm|l>+M1~Zg*;w^$ l)@Gl{I{6%{owx=z=P+na4&~8jber4?CL3AIC%@q_0|0HRG4KEY delta 16 Xcmew-yGUw-75nBOjxN^83;5yyH{%8b diff --git a/Battery Time Remaining/ko.lproj/Localizable.strings b/Battery Time Remaining/ko.lproj/Localizable.strings index e9ed068d1b1a61ca66101790cbae4f7ba365c2a1..e489a6563faa0b34d1ca56831946120c238a2ed1 100644 GIT binary patch delta 208 zcmX>leno0S6WiodtU~&!47m&i45kxjB#RAIoGO iPCIc8Y_>CKPUh#SZ@9Qt(G#U~%&5z&O{0jW=90O`bG)8=&cZq|ttgeI}+h-+YT3WMh4 ZW*&V;x5=A%^qJfkChM@8O_t)d0ss>mEcSUML8T;lojvCg~6AT9x#fbK4k zI7n0hWVQ@YSt%~VH|Mh7WSwllEHrr?kB+zoHh(Z^PQK2g&*(OpomZd9jbX9^tJ&l{ GUJC&806PW% delta 20 ccmZpYUnaewhJEuCj#I3Y^;k6~d+}QU08ds1#sB~S diff --git a/Battery Time Remaining/ru.lproj/Localizable.strings b/Battery Time Remaining/ru.lproj/Localizable.strings index 38b44fc9a15d2d57de64e5f903579d27d9f1fb3e..c0112e8b71e20d2502ee023430f04f28cc3ff569 100644 GIT binary patch delta 283 zcmaE*bV6-|2Ipiy4k7(ihFpdMhE#?khD3%EhEgD%%AmlI$&d#m-GE{lV39l^oeC5! znLM9adh#L;p?ZA!Qh;jH!TM4eim{u+pac}R1!5%zc@{esD;5J5b0BtN@nKP5aAGlK zv0{tGHQE3G delta 24 gcmX@1_DX4k2Iu5^LVTM8xKh|B^RehmULv#v0CZ6ZqW}N^ diff --git a/Battery Time Remaining/sk.lproj/Localizable.strings b/Battery Time Remaining/sk.lproj/Localizable.strings index 4a4f0eb47ca10a4dc00db39253049f8c0d4ef1f7..2276003d0786f29869f2655ee20a5b4575294bcb 100644 GIT binary patch delta 212 zcmdlc-6p?bAN%BUY(kSi@Q6q&Fk~|1F(@#&F(fi%FcdMQ0(lugGLxZXGCR92NR2j3 zO$tyv9jqpmp%{mrXm(la5}>*Qh8%``h7yKSpt>?3E(Ws;7(5vB8IplEV6~AUar1ii k*{qWd*zCkLusMlAbMj*zeMYy*!o2E0av_WP`8FCp47*ZLE7!nyu7)pV3DuV(;CPN;ObOVZIfJO3vbShA^ zWO6jO^yC0`p)h>