// // P4ServerStatusImageTransformer.m // MBMenuExtra // // Created by Michael Bishop on 12/29/09. // Copyright 2009 Perforce Software. All rights reserved. // #import "P4ServerStatusImageTransformer.h" #import "P4ServerEntry.h" @implementation P4ServerStatusImageTransformer + (Class)transformedValueClass { return [NSImage class]; } + (BOOL)allowsReverseTransformation { return NO; } -(NSImage*)P4m_imageNamed:(NSString*)name { NSBundle *thisBundle = [NSBundle bundleForClass:[self class]]; NSString * imagePath = nil; if (!(imagePath = [thisBundle pathForImageResource:name])) return nil; return [[[NSImage alloc] initByReferencingFile:imagePath] autorelease]; } - (id)transformedValue:(id)value { if (value == nil) return nil; int status = [value intValue]; NSImage * image = nil; if ( status == P4ServerStatusOffline ) image = [self P4m_imageNamed:@"red" ]; else if ( status == P4ServerStatusConnecting ) image = [self P4m_imageNamed:@"yellow" ]; else if ( status == P4ServerStatusError ) image = [self P4m_imageNamed:@"yellow" ]; else if ( status == P4ServerStatusOnline ) image = [self P4m_imageNamed:@"green" ]; return image; } @end @implementation P4ServerStatusMessageTransformer + (Class)transformedValueClass { return [NSImage class]; } + (BOOL)allowsReverseTransformation { return NO; } - (id)transformedValue:(id)value { if (value == nil) return nil; int status = [value intValue]; NSString * message = nil; if ( status == P4ServerStatusOffline ) message = NSLocalizedString( @"Offline", @"Server status message: Offline" ); else if ( status == P4ServerStatusConnecting ) message = NSLocalizedString( @"Connecting...", @"Server status message: Connecting..." ); else if ( status == P4ServerStatusError ) message = NSLocalizedString( @"Connection Error", @"Server status message: Error" ); else if ( status == P4ServerStatusOnline ) message = NSLocalizedString( @"Connected", @"Server status message: Connected" ); return message; } @end