Fixed launch player with MenuTunes checkbox in prefs.
[MenuTunes.git] / MTShizzleWindow.m
1 #import "MTShizzleWindow.h"
2
3 @interface MTShizzleWindow (Private)
4 - (void)setBling:(id)bling;
5 - (void)buildWindow;
6 - (void)setTargets;
7 @end
8
9 @implementation MTShizzleWindow
10
11 static MTShizzleWindow *_privateSharedWindow = nil;
12
13 + (id)sharedWindowForSender:(id)sender
14 {
15     if( _privateSharedWindow ) {
16         [_privateSharedWindow setBling:sender];
17         return _privateSharedWindow;
18     } else {
19         _privateSharedWindow = [[MTShizzleWindow alloc]
20                         initWithContentRect:NSMakeRect(0, 0, 385, 353)
21                         styleMask:NSTitledWindowMask
22                         backing:NSBackingStoreBuffered
23                         defer:YES];
24         [_privateSharedWindow setBling:sender];
25         return _privateSharedWindow;
26     }
27 }
28
29 - (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag
30 {
31     if ( (self = [super initWithContentRect:contentRect
32                         styleMask:styleMask
33                         backing:backingType
34                         defer:flag]) ) {
35         [self buildWindow];
36     }
37     return self;
38 }
39
40 - (void)dealloc
41 {
42     [regMessage release];
43     [regBenefits release];
44     [enterInfo release];
45     [owner release];
46     [key release];
47     [ownerEntry release];
48     [keyEntry release];
49     [registerButton release];
50     [regLater release];
51     [verifyKey release];
52     [contentView release];
53     [box release];
54     [super dealloc];
55 }
56
57 - (void)setBling:(id)bling
58 {
59     _sender = bling;
60     [self setTargets];
61 }
62
63 - (void)buildWindow
64 {
65     unichar returnChar = '\r';
66     
67     [self setReleasedWhenClosed:NO];
68     [self setTitle:[NSString stringWithFormat:@"Register %@", @"MenuTunes"]];
69     contentView = [self contentView];
70     
71     regMessage = [[NSTextField alloc] initWithFrame:NSMakeRect(20, 282, 345, 51)];
72     [regMessage setStringValue:[NSString stringWithFormat:@"%@ is shareware.  If you find it to be a valuable tool, please click the button below to buy your copy.  Your support is greatly appreciated.", @"MenuTunes"]];
73     [regMessage setBordered:NO];
74     [regMessage setBezeled:NO];
75     [regMessage setEditable:NO];
76     [regMessage setSelectable:NO];
77     [regMessage setDrawsBackground:NO];
78     [contentView addSubview:regMessage];
79     
80     //Make me gray!
81     box = [[NSBox alloc] initWithFrame:NSMakeRect(20, 181, 345, 81)];
82     [box setTitlePosition:NSNoTitle];
83     [box setBorderType:NSBezelBorder];
84     [contentView addSubview:box];
85     
86     //This isn't tall enough
87     registerButton = [[NSButton alloc] initWithFrame:NSMakeRect(24, 13, 115, 49)];
88     [registerButton setImage:[NSImage imageNamed:@"esellerate"]];
89     [registerButton setButtonType:NSMomentaryPushButton];
90     [registerButton setBezelStyle:NSRegularSquareBezelStyle];
91     [registerButton setTarget:_sender];
92     [registerButton setAction:@selector(goToTheStore:)];
93     [[box contentView] addSubview:registerButton];
94     
95     regBenefits = [[NSTextField alloc] initWithFrame:NSMakeRect(152, 16, 175, 42)];
96     [regBenefits setStringValue:[NSString stringWithUTF8String:"• Register instantly and easily.\n• Fast, secure transaction.\n• Major credit cards accepted."]];
97     [regBenefits setBordered:NO];
98     [regBenefits setBezeled:NO];
99     [regBenefits setEditable:NO];
100     [regBenefits setSelectable:NO];
101     [regBenefits setDrawsBackground:NO];
102     [regBenefits setFont:[NSFont fontWithName:@"Lucida Grande" size:11]];
103     [[box contentView] addSubview:regBenefits];
104     
105     enterInfo = [[NSTextField alloc] initWithFrame:NSMakeRect(20, 148, 345, 17)];
106     [enterInfo setStringValue:@"Please enter your registration information below."];
107     [enterInfo setBordered:NO];
108     [enterInfo setBezeled:NO];
109     [enterInfo setEditable:NO];
110     [enterInfo setSelectable:NO];
111     [enterInfo setDrawsBackground:NO];
112     [enterInfo setFont:[NSFont fontWithName:@"Lucida Grande" size:13]];
113     [contentView addSubview:enterInfo];
114     
115     owner = [[NSTextField alloc] initWithFrame:NSMakeRect(20, 126, 345, 14)];
116     [owner setStringValue:@"License Owner:"];
117     [owner setBordered:NO];
118     [owner setBezeled:NO];
119     [owner setEditable:NO];
120     [owner setSelectable:NO];
121     [owner setDrawsBackground:NO];
122     [owner setFont:[NSFont fontWithName:@"Lucida Grande" size:11]];
123     [contentView addSubview:owner];
124     
125     key = [[NSTextField alloc] initWithFrame:NSMakeRect(20, 82, 345, 14)];
126     [key setStringValue:@"License Key:"];
127     [key setBordered:NO];
128     [key setBezeled:NO];
129     [key setEditable:NO];
130     [key setSelectable:NO];
131     [key setDrawsBackground:NO];
132     [key setFont:[NSFont fontWithName:@"Lucida Grande" size:11]];
133     [contentView addSubview:key];
134     
135     ownerEntry = [[NSTextField alloc] initWithFrame:NSMakeRect(20, 104, 345, 22)];
136     [ownerEntry setTarget:_sender];
137     [ownerEntry setAction:@selector(verifyKey:)];
138     [contentView addSubview:ownerEntry];
139     
140     keyEntry = [[NSTextField alloc] initWithFrame:NSMakeRect(20, 60, 345, 22)];
141     [keyEntry setTarget:_sender];
142     [keyEntry setAction:@selector(verifyKey:)];
143     [contentView addSubview:keyEntry];
144     
145     regLater = [[NSButton alloc] initWithFrame:NSMakeRect(138, 16, 116, 25)];
146     [regLater setTitle:@"Register Later"];
147     [regLater setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]];
148     [regLater setTarget:_sender];
149     [regLater setAction:@selector(registerLater:)];
150     [regLater setBezelStyle:NSRoundedBezelStyle];
151     [contentView addSubview:regLater];
152     
153     verifyKey = [[NSButton alloc] initWithFrame:NSMakeRect(255, 16, 116, 25)];
154     [verifyKey setTitle:@"Verify Key"];
155     [verifyKey setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]];
156     [verifyKey setTarget:_sender];
157     [verifyKey setAction:@selector(verifyKey:)];
158     [verifyKey setBezelStyle:NSRoundedBezelStyle];
159     [verifyKey setKeyEquivalent:[NSString stringWithCharacters:&returnChar length:1]];
160     [contentView addSubview:verifyKey];
161 }
162
163 - (void)setTargets
164 {
165     [registerButton setTarget:_sender];
166     [ownerEntry setTarget:_sender];
167     [keyEntry setTarget:_sender];
168     [regLater setTarget:_sender];
169     [verifyKey setTarget:_sender];
170 }
171
172 - (NSString *)owner
173 {
174     return [ownerEntry stringValue];
175 }
176
177 - (NSString *)key
178 {
179     return [keyEntry stringValue];
180 }
181
182 @end