root/trunk/Update Checker Sources/SUUpdateAlert.m

Revision 522, 4.5 kB (checked in by gbooker, 1 year ago)

Correct sizing of the release notes so it doesn't crowd the buttons.

Fixes #182

Line 
1 //
2 //  SUUpdateAlert.m
3 //  Sparkle
4 //
5 //  Created by Andy Matuschak on 3/12/06.
6 //  Copyright 2006 Andy Matuschak. All rights reserved.
7 //
8
9 #import "SUUpdateAlert.h"
10 #import "SUAppcastItem.h"
11 #import "SUUtilities.h"
12 #import <WebKit/WebKit.h>
13
14 @implementation SUUpdateAlert
15
16 - initWithAppcastItem:(SUAppcastItem *)item
17 {
18         NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"SUUpdateAlert" ofType:@"nib"];
19         if (!path) // slight hack to resolve issues with running with in configurations
20         {
21                 NSBundle *current = [NSBundle bundleForClass:[self class]];
22                 NSBundle *framework = [NSBundle mainBundle];
23                 path = [framework pathForResource:@"SUUpdateAlert" ofType:@"nib"];
24         }
25        
26         [super initWithWindowNibPath:path owner:self];
27        
28         updateItem = [item retain];
29         [self setShouldCascadeWindows:NO];
30        
31         return self;
32 }
33
34 - (void)dealloc
35 {
36         [updateItem release];
37         [super dealloc];
38 }
39
40 - (void)endWithSelection:(SUUpdateAlertChoice)choice
41 {
42         [releaseNotesView stopLoading:self];
43         [releaseNotesView setFrameLoadDelegate:nil];
44         [releaseNotesView setPolicyDelegate:nil];
45         [self close];
46         if ([delegate respondsToSelector:@selector(updateAlert:finishedWithChoice:)])
47                 [delegate updateAlert:self finishedWithChoice:choice];
48 }
49
50 - (IBAction)installUpdate:sender
51 {
52         [self endWithSelection:SUInstallUpdateChoice];
53 }
54
55 - (IBAction)skipThisVersion:sender
56 {
57         [self endWithSelection:SUSkipThisVersionChoice];
58 }
59
60 - (IBAction)remindMeLater:sender
61 {
62         [self endWithSelection:SURemindMeLaterChoice];
63 }
64
65 - (void)displayReleaseNotes
66 {
67         [releaseNotesView setFrameLoadDelegate:self];
68         [releaseNotesView setPolicyDelegate:self];
69        
70         // Stick a nice big spinner in the middle of the web view until the page is loaded.
71         NSRect frame = [[releaseNotesView superview] frame];
72         releaseNotesSpinner = [[[NSProgressIndicator alloc] initWithFrame:NSMakeRect(NSMidX(frame)-16, NSMidY(frame)-16, 32, 32)] autorelease];
73         [releaseNotesSpinner setStyle:NSProgressIndicatorSpinningStyle];
74         [releaseNotesSpinner startAnimation:self];
75         webViewFinishedLoading = NO;
76         [[releaseNotesView superview] addSubview:releaseNotesSpinner];
77        
78         // If there's a release notes URL, load it; otherwise, just stick the contents of the description into the web view.
79         if ([updateItem releaseNotesURL])
80         {
81                 [[releaseNotesView mainFrame] loadRequest:[NSURLRequest requestWithURL:[updateItem releaseNotesURL] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30]];
82         }
83         else
84         {
85                 [[releaseNotesView mainFrame] loadHTMLString:[updateItem description] baseURL:nil];
86         }       
87 }
88
89 - (void)awakeFromNib
90 {       
91         [[self window] setLevel:NSFloatingWindowLevel];
92         [[self window] setFrameAutosaveName:@"SUUpdateAlertFrame"];
93                
94         // We're gonna do some frame magic to match the window's size to the description field and the presence of the release notes view.
95         NSRect frame = [[self window] frame];
96        
97 /*      // Resize the window to be appropriate for not having a huge release notes view.
98         frame.size.height -= [releaseNotesView frame].size.height;
99         // No resizing!
100         [[self window] setShowsResizeIndicator:NO];
101         [[self window] setMinSize:frame.size];
102         [[self window] setMaxSize:frame.size];*/
103
104 /*      NSRect boxFrame = [[[releaseNotesView superview] superview] frame];
105         boxFrame.origin.y -= 20;
106         boxFrame.size.height += 20;
107         [[[releaseNotesView superview] superview] setFrame:boxFrame];*/
108        
109         [[self window] setFrame:frame display:NO];
110         [[self window] center];
111        
112         [self displayReleaseNotes];
113 }
114
115 - (BOOL)windowShouldClose:note
116 {
117         [self endWithSelection:SURemindMeLaterChoice];
118         return YES;
119 }
120
121 - (NSImage *)applicationIcon
122 {
123         return [NSApp applicationIconImage];
124 }
125
126 - (NSString *)titleText
127 {
128         return [NSString stringWithFormat:SULocalizedString(@"A new version of %@ is available!", nil), SUHostAppDisplayName()];
129 }
130
131 - (NSString *)descriptionText
132 {
133         return [NSString stringWithFormat:SULocalizedString(@"%@ %@ is now available (you have %@). Would you like to download it now?", nil), SUHostAppDisplayName(), [updateItem versionString], SUHostAppVersionString()];   
134 }
135
136 - (void)webView:(WebView *)sender didFinishLoadForFrame:frame
137 {
138     if ([frame parentFrame] == nil) {
139         webViewFinishedLoading = YES;
140                 [releaseNotesSpinner setHidden:YES];
141                 [sender display]; // necessary to prevent weird scroll bar artifacting
142     }
143 }
144
145 - (void)webView:sender decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:frame decisionListener:listener
146 {
147     if (webViewFinishedLoading == YES) {
148         [[NSWorkspace sharedWorkspace] openURL:[request URL]];
149                
150         [listener ignore];
151     }   
152     else {
153         [listener use];
154     }
155 }
156
157 - (void)setDelegate:del
158 {
159         delegate = del;
160 }
161
162 @end
Note: See TracBrowser for help on using the browser.