Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 130 lines (109 sloc) 4.186 kB
904f68e Added beginnings of permission prompt.
andym authored
1 //
2 // SUUpdatePermissionPrompt.m
3 // Sparkle
4 //
5 // Created by Andy Matuschak on 1/24/08.
6 // Copyright 2008 Andy Matuschak. All rights reserved.
7 //
8
9 #import "SUUpdatePermissionPrompt.h"
10
f815eec @andymatuschak Fixes 243884
andymatuschak authored
11 #import "SUHost.h"
904f68e Added beginnings of permission prompt.
andym authored
12
13 @implementation SUUpdatePermissionPrompt
14
8c3960f Finished integrating SparklePlus profiling! Just set SUEnableSystemPr…
andym authored
15 - (BOOL)shouldAskAboutProfile
16 {
98832c4 @andymatuschak Beginnings of insane SUHost-based refactoring to get rid of NSBundle+…
andymatuschak authored
17 return [[host objectForInfoDictionaryKey:SUEnableSystemProfilingKey] boolValue];
8c3960f Finished integrating SparklePlus profiling! Just set SUEnableSystemPr…
andym authored
18 }
19
4da902b @andymatuschak Fixes 251968
andymatuschak authored
20 - (id)initWithHost:(SUHost *)aHost systemProfile:(NSArray *)profile delegate:(id)d
8c3960f Finished integrating SparklePlus profiling! Just set SUEnableSystemPr…
andym authored
21 {
c42e3a3 @andymatuschak Fixed 251010
andymatuschak authored
22 self = [super initWithHost:aHost windowNibName:@"SUUpdatePermissionPrompt"];
ef89e42 Fixed a potential buffer overrun, made sure to assign to self in -ini…
andym authored
23 if (self)
24 {
c42e3a3 @andymatuschak Fixed 251010
andymatuschak authored
25 host = [aHost retain];
ef89e42 Fixed a potential buffer overrun, made sure to assign to self in -ini…
andym authored
26 delegate = [d retain];
27 isShowingMoreInfo = NO;
28 shouldSendProfile = [self shouldAskAboutProfile];
4da902b @andymatuschak Fixes 251968
andymatuschak authored
29 systemProfileInformationArray = [profile retain];
ef89e42 Fixed a potential buffer overrun, made sure to assign to self in -ini…
andym authored
30 [self setShouldCascadeWindows:NO];
31 }
8c3960f Finished integrating SparklePlus profiling! Just set SUEnableSystemPr…
andym authored
32 return self;
33 }
34
4da902b @andymatuschak Fixes 251968
andymatuschak authored
35 + (void)promptWithHost:(SUHost *)aHost systemProfile:(NSArray *)profile delegate:(id)d
8c3960f Finished integrating SparklePlus profiling! Just set SUEnableSystemPr…
andym authored
36 {
cec9166 @mattstevens Improved notification handling for otherwise UI-less background appli…
mattstevens authored
37 // If this is a background application we need to focus it in order to bring the prompt
38 // to the user's attention. Otherwise the prompt would be hidden behind other applications and
39 // the user would not know why the application was paused.
4da902b @andymatuschak Fixes 251968
andymatuschak authored
40 if ([aHost isBackgroundApplication]) { [NSApp activateIgnoringOtherApps:YES]; }
cec9166 @mattstevens Improved notification handling for otherwise UI-less background appli…
mattstevens authored
41
4da902b @andymatuschak Fixes 251968
andymatuschak authored
42 id prompt = [[[self class] alloc] initWithHost:aHost systemProfile:profile delegate:d];
fcf471d runModal like the old alert from Changeset 127. [NSApp runModalForWin…
catlan authored
43 [NSApp runModalForWindow:[prompt window]];
8c3960f Finished integrating SparklePlus profiling! Just set SUEnableSystemPr…
andym authored
44 }
45
46 - (void)awakeFromNib
47 {
48 if (![self shouldAskAboutProfile])
49 {
50 NSRect frame = [[self window] frame];
51 frame.size.height -= [moreInfoButton frame].size.height;
52 [[self window] setFrame:frame display:YES];
53 }
54 }
55
56 - (void)dealloc
57 {
98832c4 @andymatuschak Beginnings of insane SUHost-based refactoring to get rid of NSBundle+…
andymatuschak authored
58 [host release];
4da902b @andymatuschak Fixes 251968
andymatuschak authored
59 [systemProfileInformationArray release];
8c3960f Finished integrating SparklePlus profiling! Just set SUEnableSystemPr…
andym authored
60 [super dealloc];
61 }
62
63 - (NSImage *)icon
64 {
98832c4 @andymatuschak Beginnings of insane SUHost-based refactoring to get rid of NSBundle+…
andymatuschak authored
65 return [host icon];
8c3960f Finished integrating SparklePlus profiling! Just set SUEnableSystemPr…
andym authored
66 }
67
35fa5ca Made the update permission prompt localizable and fixed a bug with th…
andym authored
68 - (NSString *)promptDescription
8c3960f Finished integrating SparklePlus profiling! Just set SUEnableSystemPr…
andym authored
69 {
98832c4 @andymatuschak Beginnings of insane SUHost-based refactoring to get rid of NSBundle+…
andymatuschak authored
70 return [NSString stringWithFormat:SULocalizedString(@"Should %1$@ automatically check for updates? You can always check for updates manually from the %1$@ menu.", nil), [host name]];
8c3960f Finished integrating SparklePlus profiling! Just set SUEnableSystemPr…
andym authored
71 }
72
73 - (IBAction)toggleMoreInfo:(id)sender
74 {
75 [self willChangeValueForKey:@"isShowingMoreInfo"];
76 isShowingMoreInfo = !isShowingMoreInfo;
77 [self didChangeValueForKey:@"isShowingMoreInfo"];
78
79 NSView *contentView = [[self window] contentView];
80 NSRect contentViewFrame = [contentView frame];
81 NSRect windowFrame = [[self window] frame];
82
83 NSRect profileMoreInfoViewFrame = [moreInfoView frame];
84 NSRect profileMoreInfoButtonFrame = [moreInfoButton frame];
85 NSRect descriptionFrame = [descriptionTextField frame];
86
87 if (isShowingMoreInfo)
88 {
89 // Add the subview
90 contentViewFrame.size.height += profileMoreInfoViewFrame.size.height;
91 profileMoreInfoViewFrame.origin.y = profileMoreInfoButtonFrame.origin.y - profileMoreInfoViewFrame.size.height;
92 profileMoreInfoViewFrame.origin.x = descriptionFrame.origin.x;
93 profileMoreInfoViewFrame.size.width = descriptionFrame.size.width;
94
95 windowFrame.size.height += profileMoreInfoViewFrame.size.height;
96 windowFrame.origin.y -= profileMoreInfoViewFrame.size.height;
97
98 [moreInfoView setFrame:profileMoreInfoViewFrame];
99 [moreInfoView setHidden:YES];
100 [contentView addSubview:moreInfoView
101 positioned:NSWindowBelow
102 relativeTo:moreInfoButton];
103 } else {
104 // Remove the subview
105 [moreInfoView setHidden:NO];
106 [moreInfoView removeFromSuperview];
107 contentViewFrame.size.height -= profileMoreInfoViewFrame.size.height;
108
109 windowFrame.size.height -= profileMoreInfoViewFrame.size.height;
110 windowFrame.origin.y += profileMoreInfoViewFrame.size.height;
111 }
112 [[self window] setFrame:windowFrame display:YES animate:YES];
113 [contentView setFrame:contentViewFrame];
114 [contentView setNeedsDisplay:YES];
115 [moreInfoView setHidden:(!isShowingMoreInfo)];
116 }
117
118 - (IBAction)finishPrompt:(id)sender
119 {
120 if (![delegate respondsToSelector:@selector(updatePermissionPromptFinishedWithResult:)])
121 [NSException raise:@"SUInvalidDelegate" format:@"SUUpdatePermissionPrompt's delegate (%@) doesn't respond to updatePermissionPromptFinishedWithResult:!", delegate];
98832c4 @andymatuschak Beginnings of insane SUHost-based refactoring to get rid of NSBundle+…
andymatuschak authored
122 [host setBool:shouldSendProfile forUserDefaultsKey:SUSendProfileInfoKey];
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
123 [delegate updatePermissionPromptFinishedWithResult:([sender tag] == 1 ? SUAutomaticallyCheck : SUDoNotAutomaticallyCheck)];
8c3960f Finished integrating SparklePlus profiling! Just set SUEnableSystemPr…
andym authored
124 [[self window] close];
fcf471d runModal like the old alert from Changeset 127. [NSApp runModalForWin…
catlan authored
125 [NSApp stopModal];
8c3960f Finished integrating SparklePlus profiling! Just set SUEnableSystemPr…
andym authored
126 [self autorelease];
127 }
128
904f68e Added beginnings of permission prompt.
andym authored
129 @end
Something went wrong with that request. Please try again.