Skip to content

HTTPS clone URL

Subversion checkout URL

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