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