root/branches/perian-1.1/Update Checker Sources/SUStatusController.m

Revision 269, 3.1 kB (checked in by durin42, 2 years ago)

Initial non-working updater app - it gets as far as downloading an update, but
it doesn't know how to unarchive yet. I've grabbed a bunch of sources from
Sparkle (duh from the filenames) but this is all we'll use from there, as from
here on out our mission is quite different from theirs. I've not yet tested
the appcast support very thoroughly, but it seems to be working in my initial
tests. I need to change it from NSUserDefaults to CFPreferencesCopyAppValue,
and fix the appcast URL in the Info.plist (note to other devs: the current URL
resolves to a nonroutable IP - you've been warned!).
I'll do unarchiving in a bit - but first I need to think about some things. I
think the solution Graham offered of using a shell script and exec() will be best.

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 "SUStatusController.h"
10 #import "SUUtilities.h"
11
12 @implementation SUStatusController
13
14 - init
15 {
16         NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"SUStatus" ofType:@"nib"];
17         if (!path) // slight hack to resolve issues with running in debug configurations
18         {
19                 NSBundle *current = [NSBundle bundleForClass:[self class]];
20                 NSString *frameworkPath = [[[NSBundle mainBundle] sharedFrameworksPath] stringByAppendingFormat:@"/Sparkle.framework", [current bundleIdentifier]];
21                 NSBundle *framework = [NSBundle bundleWithPath:frameworkPath];
22                 path = [framework pathForResource:@"SUStatus" ofType:@"nib"];
23         }
24         [super initWithWindowNibPath:path owner:self];
25         [self setShouldCascadeWindows:NO];
26         return self;
27 }
28
29 - (void)dealloc
30 {
31         [title release];
32         [statusText release];
33         [buttonTitle release];
34         [super dealloc];
35 }
36
37 - (void)awakeFromNib
38 {
39         [[self window] center];
40         [[self window] setFrameAutosaveName:@"SUStatusFrame"];
41 }
42
43 - (NSString *)windowTitle
44 {
45         return [NSString stringWithFormat:SULocalizedString(@"Updating %@", nil), SUHostAppDisplayName()];
46 }
47
48 - (NSImage *)applicationIcon
49 {
50         return [NSApp applicationIconImage];
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         buttonTitle = [aButtonTitle copy];
67         [self didChangeValueForKey:@"buttonTitle"];     
68        
69         [actionButton sizeToFit];
70         // Except we're going to add 15 px for padding.
71         [actionButton setFrameSize:NSMakeSize([actionButton frame].size.width + 15, [actionButton frame].size.height)];
72         // Now we have to move it over so that it's always 15px from the side of the window.
73         [actionButton setFrameOrigin:NSMakePoint([[self window] frame].size.width - 15 - [actionButton frame].size.width, [actionButton frame].origin.y)];     
74         // Redisplay superview to clean up artifacts
75         [[actionButton superview] display];
76        
77         [actionButton setTarget:target];
78         [actionButton setAction:action];
79         [actionButton setKeyEquivalent:isDefault ? @"\r" : @""];
80 }
81
82 - (void)setButtonEnabled:(BOOL)enabled
83 {
84         [actionButton setEnabled:enabled];
85 }
86
87 - (double)progressValue
88 {
89         return progressValue;
90 }
91
92 - (void)setProgressValue:(double)value
93 {
94         [self willChangeValueForKey:@"progressValue"];
95         progressValue = value;
96         [self didChangeValueForKey:@"progressValue"];   
97 }
98
99 - (double)maxProgressValue
100 {
101         return maxProgressValue;
102 }
103
104 - (void)setMaxProgressValue:(double)value
105 {
106         [self willChangeValueForKey:@"maxProgressValue"];
107         maxProgressValue = value;
108         [self didChangeValueForKey:@"maxProgressValue"];
109         [self setProgressValue:0];
110 }
111
112 - (void)setStatusText:(NSString *)aStatusText
113 {
114         [self willChangeValueForKey:@"statusText"];
115         statusText = [aStatusText copy];
116         [self didChangeValueForKey:@"statusText"];     
117 }
118
119 @end
Note: See TracBrowser for help on using the browser.