source: trunk/Sparkle/SUStatusController.m @ 1046

Revision 134, 2.8 KB checked in by speck, 4 years ago (diff)

Simple display of suspects in preference panel.

Line 
1//
2//  SUStatusController.m
3//  Sparkle
4//
5//  Created by Andy Matuschak on 3/14/06.
6//  Copyright 2006 Andy Matuschak. All rights reserved.
7//
8
9#import "Sparkle.h"
10#import "SUStatusController.h"
11
12@implementation SUStatusController
13
14- (id)initWithHost:(SUHost *)aHost
15{
16    self = [super initWithHost:aHost windowNibName:@"SUStatus"];
17    if (self)
18    {
19        host = [aHost retain];
20        [self setShouldCascadeWindows:NO];
21    }
22    return self;
23}
24
25- (void)dealloc
26{
27    [host release];
28    [title release];
29    [statusText release];
30    [buttonTitle release];
31    [super dealloc];
32}
33
34- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], [host bundlePath]]; }
35
36- (void)awakeFromNib
37{
38    [[self window] center];
39    [[self window] setFrameAutosaveName:@"SUStatusFrame"];
40    [progressBar setUsesThreadedAnimation:YES];
41}
42
43- (NSString *)windowTitle
44{
45    return [NSString stringWithFormat:SULocalizedString(@"Updating %@", nil), [host name]];
46}
47
48- (NSImage *)applicationIcon
49{
50    return [host icon];
51}
52
53- (void)beginActionWithTitle:(NSString *)aTitle maxProgressValue:(double)aMaxProgressValue statusText:(NSString *)aStatusText
54{
55    [self willChangeValueForKey:@"title"];
56    title = [aTitle copy];
57    [self didChangeValueForKey:@"title"];
58   
59    [self setMaxProgressValue:aMaxProgressValue];
60    [self setStatusText:aStatusText];
61}
62
63- (void)setButtonTitle:(NSString *)aButtonTitle target:target action:(SEL)action isDefault:(BOOL)isDefault
64{
65    [self willChangeValueForKey:@"buttonTitle"];
66    if (buttonTitle != aButtonTitle)
67    {
68        [buttonTitle release];
69        buttonTitle = [aButtonTitle copy];
70    }
71    [self didChangeValueForKey:@"buttonTitle"];
72   
73    [self window];
74    [actionButton sizeToFit];
75    // Except we're going to add 15 px for padding.
76    [actionButton setFrameSize:NSMakeSize([actionButton frame].size.width + 15, [actionButton frame].size.height)];
77    // Now we have to move it over so that it's always 15px from the side of the window.
78    [actionButton setFrameOrigin:NSMakePoint([[self window] frame].size.width - 15 - [actionButton frame].size.width, [actionButton frame].origin.y)]; 
79    // Redisplay superview to clean up artifacts
80    [[actionButton superview] display];
81   
82    [actionButton setTarget:target];
83    [actionButton setAction:action];
84    [actionButton setKeyEquivalent:isDefault ? @"\r" : @""];
85}
86
87- (BOOL)progressBarShouldAnimate
88{
89    return YES;
90}
91
92- (void)setButtonEnabled:(BOOL)enabled
93{
94    [actionButton setEnabled:enabled];
95}
96
97- (double)progressValue
98{
99    return progressValue;
100}
101
102- (void)setProgressValue:(double)value
103{
104    progressValue = value;
105}
106
107- (double)maxProgressValue
108{
109    return maxProgressValue;
110}
111
112- (void)setMaxProgressValue:(double)value
113{
114    if (value < 0) value = 0;
115    maxProgressValue = value;
116    [self setProgressValue:0];
117    [progressBar startAnimation:self];
118}
119
120- (void)setStatusText:(NSString *)aStatusText
121{
122    if (statusText != aStatusText)
123    {
124        [statusText release];
125        statusText = [aStatusText copy];
126    }
127}
128
129@end
Note: See TracBrowser for help on using the repository browser.