Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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