Extras/HardwareGrowler/AppController.m
changeset 4204 2564276c9d5c
parent 4144 c78b283d2fca
child 4205 f3398597ecdd
     1.1 --- a/Extras/HardwareGrowler/AppController.m	Mon Jul 07 19:34:48 2008 +0000
     1.2 +++ b/Extras/HardwareGrowler/AppController.m	Tue May 05 00:40:54 2009 -0700
     1.3 @@ -185,6 +185,60 @@
     1.4  	return iSyncIconData;
     1.5  }
     1.6  
     1.7 +static CFDataRef powerBatteryIcon(void)
     1.8 +{
     1.9 +	static CFDataRef batteryIconData = NULL;
    1.10 +	char imagePath[PATH_MAX];
    1.11 +
    1.12 +	if (!batteryIconData) {
    1.13 +		CFURLRef imageURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(),
    1.14 +													CFSTR("Power-Battery"),
    1.15 +													CFSTR("png"),
    1.16 +													/*subDirName*/ NULL);
    1.17 +		if (CFURLGetFileSystemRepresentation(imageURL, false, (UInt8 *)imagePath, sizeof(imagePath)))
    1.18 +			batteryIconData = (CFDataRef)readFile(imagePath);
    1.19 +		CFRelease(imageURL);
    1.20 +	}
    1.21 +
    1.22 +	return batteryIconData;
    1.23 +}
    1.24 +
    1.25 +static CFDataRef powerACIcon(void)
    1.26 +{
    1.27 +	static CFDataRef ACPowerIconData = NULL;
    1.28 +	char imagePath[PATH_MAX];
    1.29 +
    1.30 +	if (!ACPowerIconData) {
    1.31 +		CFURLRef imageURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(),
    1.32 +													CFSTR("Power-AC"),
    1.33 +													CFSTR("png"),
    1.34 +													/*subDirName*/ NULL);
    1.35 +		if (CFURLGetFileSystemRepresentation(imageURL, false, (UInt8 *)imagePath, sizeof(imagePath)))
    1.36 +			ACPowerIconData = (CFDataRef)readFile(imagePath);
    1.37 +		CFRelease(imageURL);
    1.38 +	}
    1.39 +
    1.40 +	return ACPowerIconData;
    1.41 +}
    1.42 +
    1.43 +static CFDataRef powerACChargingIcon(void)
    1.44 +{
    1.45 +	static CFDataRef ACChargingPowerIconData = NULL;
    1.46 +	char imagePath[PATH_MAX];
    1.47 +
    1.48 +	if (!ACChargingPowerIconData) {
    1.49 +		CFURLRef imageURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(),
    1.50 +													CFSTR("Power-ACCharging"),
    1.51 +													CFSTR("png"),
    1.52 +													/*subDirName*/ NULL);
    1.53 +		if (CFURLGetFileSystemRepresentation(imageURL, false, (UInt8 *)imagePath, sizeof(imagePath)))
    1.54 +			ACChargingPowerIconData = (CFDataRef)readFile(imagePath);
    1.55 +		CFRelease(imageURL);
    1.56 +	}
    1.57 +
    1.58 +	return ACChargingPowerIconData;
    1.59 +}
    1.60 +
    1.61  #pragma mark Firewire
    1.62  
    1.63  void AppController_fwDidConnect(CFStringRef deviceName) {
    1.64 @@ -483,7 +537,7 @@
    1.65  	NSString		*title = nil;
    1.66  	NSMutableString *description = [NSMutableString string];
    1.67  	NSString		*notificationName = nil;
    1.68 -	CFDataRef		imageData = iSyncIcon();
    1.69 +	CFDataRef		imageData = NULL;
    1.70  
    1.71  	BOOL		haveBatteryTime = (batteryTime != -1);
    1.72  	BOOL		haveBatteryPercentage = (batteryPercentage != -1);
    1.73 @@ -497,6 +551,9 @@
    1.74  			if (haveBatteryTime) [description appendFormat:NSLocalizedString(@"Time to charge: %i", nil), batteryTime];
    1.75  			if (haveBatteryTime && haveBatteryPercentage) [description appendString:@"\n"];
    1.76  			if (haveBatteryPercentage) [description appendFormat:NSLocalizedString(@"Current charge: %d%%", nil), batteryPercentage];
    1.77 +			imageData = powerACChargingIcon();
    1.78 +		} else {
    1.79 +			imageData = powerACIcon();
    1.80  		}
    1.81  
    1.82  		notificationName = (NSString *)NotifierPowerOnACNotification;
    1.83 @@ -510,6 +567,8 @@
    1.84  
    1.85  		notificationName = (NSString *)NotifierPowerOnBatteryNotification;
    1.86  
    1.87 +		imageData = powerBatteryIcon();
    1.88 +
    1.89  	} else if (powerSource == HGUPSPower) {
    1.90  		title = NSLocalizedString(@"On UPS power", nil);
    1.91