forked from samdeane/Sparkle
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSUStatusController.m
127 lines (105 loc) · 3.05 KB
/
SUStatusController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//
// SUStatusController.m
// Sparkle
//
// Created by Andy Matuschak on 3/14/06.
// Copyright 2006 Andy Matuschak. All rights reserved.
//
#import "SUUpdater.h"
#import "SUAppcast.h"
#import "SUAppcastItem.h"
#import "SUVersionComparisonProtocol.h"
#import "SUStatusController.h"
#import "SUHost.h"
@interface SUStatusController ()
@property (copy) NSString *title, *buttonTitle;
@property (retain) SUHost *host;
@end
@implementation SUStatusController
@synthesize progressValue;
@synthesize maxProgressValue;
@synthesize statusText;
@synthesize title;
@synthesize buttonTitle;
@synthesize host;
- (id)initWithHost:(SUHost *)aHost
{
self = [super initWithHost:aHost windowNibName:@"SUStatus"];
if (self)
{
self.host = aHost;
[self setShouldCascadeWindows:NO];
}
return self;
}
- (void)dealloc
{
self.host = nil;
self.title = nil;
self.statusText = nil;
self.buttonTitle = nil;
[super dealloc];
}
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@, %@>", [self class], [host bundlePath], [host installationPath]]; }
- (void)awakeFromNib
{
if ([host isBackgroundApplication]) {
[[self window] setLevel:NSFloatingWindowLevel];
}
[[self window] center];
[[self window] setFrameAutosaveName:@"SUStatusFrame"];
[progressBar setUsesThreadedAnimation:YES];
}
- (NSString *)windowTitle
{
return [NSString stringWithFormat:SULocalizedString(@"Updating %@", nil), [host name]];
}
- (NSImage *)applicationIcon
{
return [host icon];
}
- (void)beginActionWithTitle:(NSString *)aTitle maxProgressValue:(double)aMaxProgressValue statusText:(NSString *)aStatusText
{
self.title = aTitle;
self.maxProgressValue = aMaxProgressValue;
self.statusText = aStatusText;
}
- (void)setButtonTitle:(NSString *)aButtonTitle target:(id)target action:(SEL)action isDefault:(BOOL)isDefault
{
self.buttonTitle = aButtonTitle;
[[self window] self];
[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" : @""];
// 06/05/2008 Alex: Avoid a crash when cancelling during the extraction
[self setButtonEnabled: (target != nil)];
}
- (BOOL)progressBarShouldAnimate
{
return YES;
}
- (void)setButtonEnabled:(BOOL)enabled
{
[actionButton setEnabled:enabled];
}
- (BOOL)isButtonEnabled
{
return [actionButton isEnabled];
}
- (void)setMaxProgressValue:(double)value
{
if (value < 0.0) value = 0.0;
maxProgressValue = value;
[self setProgressValue:0.0];
[progressBar setIndeterminate:(value == 0.0)];
[progressBar startAnimation:self];
[progressBar setUsesThreadedAnimation: YES];
}
@end