forked from sparkle-project/Sparkle
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SUUpdatePermissionPrompt.m
131 lines (110 loc) · 4.2 KB
/
SUUpdatePermissionPrompt.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
// SUUpdatePermissionPrompt.m
// Sparkle
//
// Created by Andy Matuschak on 1/24/08.
// Copyright 2008 Andy Matuschak. All rights reserved.
//
#import "SUUpdatePermissionPrompt.h"
#import "SUHost.h"
@implementation SUUpdatePermissionPrompt
- (BOOL)shouldAskAboutProfile
{
return [[host objectForInfoDictionaryKey:SUEnableSystemProfilingKey] boolValue];
}
- (id)initWithHost:(SUHost *)aHost systemProfile:(NSArray *)profile delegate:(id)d
{
self = [super initWithHost:aHost windowNibName:@"SUUpdatePermissionPrompt"];
if (self)
{
host = [aHost retain];
delegate = d;
isShowingMoreInfo = NO;
shouldSendProfile = [self shouldAskAboutProfile];
systemProfileInformationArray = [profile retain];
[self setShouldCascadeWindows:NO];
}
return self;
}
+ (void)promptWithHost:(SUHost *)aHost systemProfile:(NSArray *)profile delegate:(id)d
{
// If this is a background application we need to focus it in order to bring the prompt
// to the user's attention. Otherwise the prompt would be hidden behind other applications and
// the user would not know why the application was paused.
if ([aHost isBackgroundApplication]) { [NSApp activateIgnoringOtherApps:YES]; }
id prompt = [[[[self class] alloc] initWithHost:aHost systemProfile:profile delegate:d] autorelease];
[NSApp runModalForWindow:[prompt window]];
}
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], [host bundlePath]]; }
- (void)awakeFromNib
{
if (![self shouldAskAboutProfile])
{
NSRect frame = [[self window] frame];
frame.size.height -= [moreInfoButton frame].size.height;
[[self window] setFrame:frame display:YES];
}
}
- (void)dealloc
{
[host release];
[systemProfileInformationArray release];
[super dealloc];
}
- (NSImage *)icon
{
return [host icon];
}
- (NSString *)promptDescription
{
return [NSString stringWithFormat:SULocalizedString(@"Should %1$@ automatically check for updates? You can always check for updates manually from the %1$@ menu.", nil), [host name]];
}
- (IBAction)toggleMoreInfo:(id)sender
{
[self willChangeValueForKey:@"isShowingMoreInfo"];
isShowingMoreInfo = !isShowingMoreInfo;
[self didChangeValueForKey:@"isShowingMoreInfo"];
NSView *contentView = [[self window] contentView];
NSRect contentViewFrame = [contentView frame];
NSRect windowFrame = [[self window] frame];
NSRect profileMoreInfoViewFrame = [moreInfoView frame];
NSRect profileMoreInfoButtonFrame = [moreInfoButton frame];
NSRect descriptionFrame = [descriptionTextField frame];
if (isShowingMoreInfo)
{
// Add the subview
contentViewFrame.size.height += profileMoreInfoViewFrame.size.height;
profileMoreInfoViewFrame.origin.y = profileMoreInfoButtonFrame.origin.y - profileMoreInfoViewFrame.size.height;
profileMoreInfoViewFrame.origin.x = descriptionFrame.origin.x;
profileMoreInfoViewFrame.size.width = descriptionFrame.size.width;
windowFrame.size.height += profileMoreInfoViewFrame.size.height;
windowFrame.origin.y -= profileMoreInfoViewFrame.size.height;
[moreInfoView setFrame:profileMoreInfoViewFrame];
[moreInfoView setHidden:YES];
[contentView addSubview:moreInfoView
positioned:NSWindowBelow
relativeTo:moreInfoButton];
} else {
// Remove the subview
[moreInfoView setHidden:NO];
[moreInfoView removeFromSuperview];
contentViewFrame.size.height -= profileMoreInfoViewFrame.size.height;
windowFrame.size.height -= profileMoreInfoViewFrame.size.height;
windowFrame.origin.y += profileMoreInfoViewFrame.size.height;
}
[[self window] setFrame:windowFrame display:YES animate:YES];
[contentView setFrame:contentViewFrame];
[contentView setNeedsDisplay:YES];
[moreInfoView setHidden:(!isShowingMoreInfo)];
}
- (IBAction)finishPrompt:(id)sender
{
if (![delegate respondsToSelector:@selector(updatePermissionPromptFinishedWithResult:)])
[NSException raise:@"SUInvalidDelegate" format:@"SUUpdatePermissionPrompt's delegate (%@) doesn't respond to updatePermissionPromptFinishedWithResult:!", delegate];
[host setBool:shouldSendProfile forUserDefaultsKey:SUSendProfileInfoKey];
[delegate updatePermissionPromptFinishedWithResult:([sender tag] == 1 ? SUAutomaticallyCheck : SUDoNotAutomaticallyCheck)];
[[self window] close];
[NSApp stopModal];
[self autorelease];
}
@end