Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 127 lines (106 sloc) 3.859 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 SUEnableSystemProfi...
andym authored
14 - (BOOL)shouldAskAboutProfile
15 {
16 return [[hostBundle objectForInfoDictionaryKey:SUEnableSystemProfilingKey] boolValue];
17 }
18
19 - (id)initWithHostBundle:(NSBundle *)hb delegate:(id)d
20 {
ef89e42 Fixed a potential buffer overrun, made sure to assign to self in -init m...
andym authored
21 self = [super initWithHostBundle:hb windowNibName:@"SUUpdatePermissionPrompt"];
22 if (self)
23 {
24 hostBundle = [hb retain];
25 delegate = [d retain];
26 isShowingMoreInfo = NO;
27 shouldSendProfile = [self shouldAskAboutProfile];
28 [self setShouldCascadeWindows:NO];
29 }
8c3960f Finished integrating SparklePlus profiling! Just set SUEnableSystemProfi...
andym authored
30 return self;
31 }
32
33 + (void)promptWithHostBundle:(NSBundle *)hb delegate:(id)d
34 {
35 id prompt = [[[self class] alloc] initWithHostBundle:hb delegate:d];
fcf471d runModal like the old alert from Changeset 127. [NSApp runModalForWindow...
catlan authored
36 [NSApp runModalForWindow:[prompt window]];
8c3960f Finished integrating SparklePlus profiling! Just set SUEnableSystemProfi...
andym authored
37 }
38
39 - (void)awakeFromNib
40 {
41 if (![self shouldAskAboutProfile])
42 {
43 NSRect frame = [[self window] frame];
44 frame.size.height -= [moreInfoButton frame].size.height;
45 [[self window] setFrame:frame display:YES];
46 }
47 }
48
49 - (void)dealloc
50 {
51 [hostBundle release];
52 [super dealloc];
53 }
54
55 - (NSImage *)icon
56 {
57 return [hostBundle icon];
58 }
59
60 - (NSString *)description
61 {
62 return [NSString stringWithFormat:SULocalizedString(@"Should %1$@ automatically check for updates? You can always check for updates manually from the %1$@ menu.", nil), [hostBundle name]];
63 }
64
65 - (NSArray *)systemProfileInformationArray
66 {
67 return [[SUSystemProfiler sharedSystemProfiler] systemProfileArrayForHostBundle:hostBundle];
68 }
69
70 - (IBAction)toggleMoreInfo:(id)sender
71 {
72 [self willChangeValueForKey:@"isShowingMoreInfo"];
73 isShowingMoreInfo = !isShowingMoreInfo;
74 [self didChangeValueForKey:@"isShowingMoreInfo"];
75
76 NSView *contentView = [[self window] contentView];
77 NSRect contentViewFrame = [contentView frame];
78 NSRect windowFrame = [[self window] frame];
79
80 NSRect profileMoreInfoViewFrame = [moreInfoView frame];
81 NSRect profileMoreInfoButtonFrame = [moreInfoButton frame];
82 NSRect descriptionFrame = [descriptionTextField frame];
83
84 if (isShowingMoreInfo)
85 {
86 // Add the subview
87 contentViewFrame.size.height += profileMoreInfoViewFrame.size.height;
88 profileMoreInfoViewFrame.origin.y = profileMoreInfoButtonFrame.origin.y - profileMoreInfoViewFrame.size.height;
89 profileMoreInfoViewFrame.origin.x = descriptionFrame.origin.x;
90 profileMoreInfoViewFrame.size.width = descriptionFrame.size.width;
91
92 windowFrame.size.height += profileMoreInfoViewFrame.size.height;
93 windowFrame.origin.y -= profileMoreInfoViewFrame.size.height;
94
95 [moreInfoView setFrame:profileMoreInfoViewFrame];
96 [moreInfoView setHidden:YES];
97 [contentView addSubview:moreInfoView
98 positioned:NSWindowBelow
99 relativeTo:moreInfoButton];
100 } else {
101 // Remove the subview
102 [moreInfoView setHidden:NO];
103 [moreInfoView removeFromSuperview];
104 contentViewFrame.size.height -= profileMoreInfoViewFrame.size.height;
105
106 windowFrame.size.height -= profileMoreInfoViewFrame.size.height;
107 windowFrame.origin.y += profileMoreInfoViewFrame.size.height;
108 }
109 [[self window] setFrame:windowFrame display:YES animate:YES];
110 [contentView setFrame:contentViewFrame];
111 [contentView setNeedsDisplay:YES];
112 [moreInfoView setHidden:(!isShowingMoreInfo)];
113 }
114
115 - (IBAction)finishPrompt:(id)sender
116 {
117 if (![delegate respondsToSelector:@selector(updatePermissionPromptFinishedWithResult:)])
118 [NSException raise:@"SUInvalidDelegate" format:@"SUUpdatePermissionPrompt's delegate (%@) doesn't respond to updatePermissionPromptFinishedWithResult:!", delegate];
119 [[SUUserDefaults standardUserDefaults] setBool:shouldSendProfile forKey:SUSendProfileInfoKey];
120 [delegate updatePermissionPromptFinishedWithResult:([sender tag] == 1 ? SUAutomaticallyUpdate : SUDoNotAutomaticallyUpdate)];
121 [[self window] close];
fcf471d runModal like the old alert from Changeset 127. [NSApp runModalForWindow...
catlan authored
122 [NSApp stopModal];
8c3960f Finished integrating SparklePlus profiling! Just set SUEnableSystemProfi...
andym authored
123 [self autorelease];
124 }
125
904f68e Added beginnings of permission prompt.
andym authored
126 @end
Something went wrong with that request. Please try again.