Files
Sparkle/SUStatusController.m
T
andym 5d44acb0ac Finally got DMGs working properly on 10.5 through a somewhat less brittle method - ie, no more internetenable. Thanks to Steve Gehrman from CocoaTech.
Also fixed a bug with the host app extension method, the recursive find-the-app-in-the-archive method, and made the extension comparison case insensitive for extraction purposes.
2007-12-02 16:16:11 +00:00

155 lines
4.0 KiB
Objective-C

//
// SUStatusController.m
// Sparkle
//
// Created by Andy Matuschak on 3/14/06.
// Copyright 2006 Andy Matuschak. All rights reserved.
//
#import "SUStatusController.h"
#import "SUUtilities.h"
@interface SUStatusController (Private)
- (NSProgressIndicator *)progressBar;
- (void)setProgressBar:(NSProgressIndicator *)theProgressBar;
@end
@implementation SUStatusController
- initWithUtilities:(SUUtilities *)aUtility
{
NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"SUStatus" ofType:@"nib"];
if (!path) // slight hack to resolve issues with running in debug configurations
{
NSBundle *current = [NSBundle bundleForClass:[self class]];
NSString *frameworkPath = [[[NSBundle mainBundle] sharedFrameworksPath] stringByAppendingFormat:@"/Sparkle.framework", [current bundleIdentifier]];
NSBundle *framework = [NSBundle bundleWithPath:frameworkPath];
path = [framework pathForResource:@"SUStatus" ofType:@"nib"];
}
[super initWithWindowNibPath:path owner:self];
[self setShouldCascadeWindows:NO];
utilities = [aUtility retain];
return self;
}
- (void)dealloc
{
[utilities release];
[title release];
[statusText release];
[buttonTitle release];
[self setProgressBar:nil];
[super dealloc];
}
- (void)awakeFromNib
{
[[self window] center];
[[self window] setFrameAutosaveName:@"SUStatusFrame"];
// set progress bar to threaded animation
[[self progressBar] setUsesThreadedAnimation:YES];
}
- (NSString *)windowTitle
{
return [NSString stringWithFormat:SULocalizedString(@"Updating %@", nil), [utilities hostAppDisplayName]];
}
- (NSImage *)applicationIcon
{
return [utilities hostAppIcon];
}
- (void)beginActionWithTitle:(NSString *)aTitle maxProgressValue:(double)aMaxProgressValue statusText:(NSString *)aStatusText
{
[self willChangeValueForKey:@"title"];
title = [aTitle copy];
[self didChangeValueForKey:@"title"];
[self setMaxProgressValue:aMaxProgressValue];
[self setStatusText:aStatusText];
}
- (void)setButtonTitle:(NSString *)aButtonTitle target:target action:(SEL)action isDefault:(BOOL)isDefault
{
[self willChangeValueForKey:@"buttonTitle"];
buttonTitle = [aButtonTitle copy];
[self didChangeValueForKey:@"buttonTitle"];
[actionButton sizeToFit];
// Except we're going to add 15 px for padding.
[actionButton setFrameSize:NSMakeSize([actionButton frame].size.width + 15, [actionButton frame].size.height)];
// Now we have to move it over so that it's always 15px from the side of the window.
[actionButton setFrameOrigin:NSMakePoint([[self window] frame].size.width - 15 - [actionButton frame].size.width, [actionButton frame].origin.y)];
// Redisplay superview to clean up artifacts
[[actionButton superview] display];
[actionButton setTarget:target];
[actionButton setAction:action];
[actionButton setKeyEquivalent:isDefault ? @"\r" : @""];
}
- (void)setButtonEnabled:(BOOL)enabled
{
[actionButton setEnabled:enabled];
}
- (double)progressValue
{
return progressValue;
}
- (void)setProgressValue:(double)value
{
[self willChangeValueForKey:@"progressValue"];
progressValue = value;
[self didChangeValueForKey:@"progressValue"];
}
- (double)maxProgressValue
{
return maxProgressValue;
}
- (void)setMaxProgressValue:(double)value
{
[self willChangeValueForKey:@"maxProgressValue"];
maxProgressValue = value;
[self didChangeValueForKey:@"maxProgressValue"];
[self setProgressValue:0];
}
- (void)setStatusText:(NSString *)aStatusText
{
[self willChangeValueForKey:@"statusText"];
statusText = [aStatusText copy];
[self didChangeValueForKey:@"statusText"];
}
@end
@implementation SUStatusController (Private)
//----------------------------------------------------------
// progressBar
//----------------------------------------------------------
- (NSProgressIndicator *)progressBar
{
return mProgressBar;
}
- (void)setProgressBar:(NSProgressIndicator *)theProgressBar
{
if (mProgressBar != theProgressBar)
{
[mProgressBar release];
mProgressBar = [theProgressBar retain];
}
}
@end