Added localized strings to everything, I think. Hope I didn't miss anything.
[MenuTunes.git] / MTShizzleWindow.m
1 #import "MTShizzleWindow.h"
2 #import "MainController.h"
3
4 @interface MTShizzleWindow (Private)
5 - (void)setBling:(id)bling;
6 - (void)buildWindow;
7 - (void)setTargets;
8 @end
9
10 @implementation MTShizzleWindow
11
12 static MTShizzleWindow *_privateSharedWindow = nil;
13
14 + (id)sharedWindowForSender:(id)sender
15 {
16     if( _privateSharedWindow ) {
17         [_privateSharedWindow setBling:sender];
18         return _privateSharedWindow;
19     } else {
20         _privateSharedWindow = [[MTShizzleWindow alloc]
21                         initWithContentRect:NSMakeRect(0, 0, 385, 353)
22                         styleMask:NSTitledWindowMask
23                         backing:NSBackingStoreBuffered
24                         defer:YES];
25         [_privateSharedWindow setBling:sender];
26         return _privateSharedWindow;
27     }
28 }
29
30 - (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag
31 {
32     if ( (self = [super initWithContentRect:contentRect
33                         styleMask:styleMask
34                         backing:backingType
35                         defer:flag]) ) {
36                 [self setLevel:NSStatusWindowLevel];
37         [self buildWindow];
38     }
39     return self;
40 }
41
42 - (void)makeKeyAndOrderFront:(id)sender {
43     if ( ( [[NSDate date] timeIntervalSinceDate:[[MainController sharedController] getBlingTime]] >= 604800 ) && ([[regLater title] isEqualToString:@"Register Later"]) ) {
44         [regLater setTitle:@"Quit"];
45         [regLater setTarget:[NSApplication sharedApplication]];
46         [regLater setAction:@selector(terminate:)];
47     }
48     [super makeKeyAndOrderFront:sender];
49 }        
50
51 - (void)dealloc
52 {
53     [regMessage release];
54     [regBenefits release];
55     [enterInfo release];
56     [owner release];
57     [key release];
58     [ownerEntry release];
59     [keyEntry release];
60     [registerButton release];
61     [regLater release];
62     [verifyKey release];
63     [contentView release];
64     [box release];
65     [super dealloc];
66 }
67
68 - (void)setBling:(id)bling
69 {
70     _sender = bling;
71     [self setTargets];
72 }
73
74 - (void)buildWindow
75 {
76     unichar returnChar = '\r';
77     
78     [self setReleasedWhenClosed:NO];
79     [self setTitle:NSLocalizedString(@"registerMenuTunes", @"Register MenuTunes")];
80     contentView = [self contentView];
81     
82     regMessage = [[NSTextField alloc] initWithFrame:NSMakeRect(20, 282, 345, 51)];
83     [regMessage setStringValue:NSLocalizedString(@"sharewareMessage", @"MenuTunes 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.")];
84     [regMessage setBordered:NO];
85     [regMessage setBezeled:NO];
86     [regMessage setEditable:NO];
87     [regMessage setSelectable:NO];
88     [regMessage setDrawsBackground:NO];
89     [contentView addSubview:regMessage];
90     
91     //Make me gray!
92     box = [[NSBox alloc] initWithFrame:NSMakeRect(20, 181, 345, 81)];
93     [box setTitlePosition:NSNoTitle];
94     [box setBorderType:NSBezelBorder];
95     [contentView addSubview:box];
96     
97     //This isn't tall enough
98     registerButton = [[NSButton alloc] initWithFrame:NSMakeRect(24, 13, 115, 49)];
99     [registerButton setImage:[NSImage imageNamed:@"esellerate"]];
100     [registerButton setButtonType:NSMomentaryPushButton];
101     [registerButton setBezelStyle:NSRegularSquareBezelStyle];
102     [registerButton setTarget:_sender];
103     [registerButton setAction:@selector(goToTheStore:)];
104     [[box contentView] addSubview:registerButton];
105     
106     regBenefits = [[NSTextField alloc] initWithFrame:NSMakeRect(152, 16, 175, 42)];
107     [regBenefits setStringValue:NSLocalizedString(@"regPoints", @"Registration Points")];
108     [regBenefits setBordered:NO];
109     [regBenefits setBezeled:NO];
110     [regBenefits setEditable:NO];
111     [regBenefits setSelectable:NO];
112     [regBenefits setDrawsBackground:NO];
113     [regBenefits setFont:[NSFont fontWithName:@"LucidaGrande" size:11]];
114     [[box contentView] addSubview:regBenefits];
115     
116     enterInfo = [[NSTextField alloc] initWithFrame:NSMakeRect(20, 148, 345, 17)];
117     [enterInfo setStringValue:NSLocalizedString(@"regInfo", @"Please enter your registration information below.")];
118     [enterInfo setBordered:NO];
119     [enterInfo setBezeled:NO];
120     [enterInfo setEditable:NO];
121     [enterInfo setSelectable:NO];
122     [enterInfo setDrawsBackground:NO];
123     [enterInfo setFont:[NSFont fontWithName:@"Lucida Grande" size:13]];
124     [contentView addSubview:enterInfo];
125     
126     owner = [[NSTextField alloc] initWithFrame:NSMakeRect(20, 126, 345, 14)];
127     [owner setStringValue:NSLocalizedString(@"licenseOwner", @"License Owner:")];
128     [owner setBordered:NO];
129     [owner setBezeled:NO];
130     [owner setEditable:NO];
131     [owner setSelectable:NO];
132     [owner setDrawsBackground:NO];
133     [owner setFont:[NSFont fontWithName:@"Lucida Grande" size:11]];
134     [contentView addSubview:owner];
135     
136     key = [[NSTextField alloc] initWithFrame:NSMakeRect(20, 82, 345, 14)];
137     [key setStringValue:NSLocalizedString(@"licenseKey", @"License Key:")];
138     [key setBordered:NO];
139     [key setBezeled:NO];
140     [key setEditable:NO];
141     [key setSelectable:NO];
142     [key setDrawsBackground:NO];
143     [key setFont:[NSFont fontWithName:@"Lucida Grande" size:11]];
144     [contentView addSubview:key];
145     
146     ownerEntry = [[NSTextField alloc] initWithFrame:NSMakeRect(20, 104, 345, 22)];
147     [ownerEntry setTarget:_sender];
148     [ownerEntry setAction:@selector(verifyKey:)];
149     [contentView addSubview:ownerEntry];
150     
151     keyEntry = [[NSTextField alloc] initWithFrame:NSMakeRect(20, 60, 345, 22)];
152     [keyEntry setTarget:_sender];
153     [keyEntry setAction:@selector(verifyKey:)];
154     [contentView addSubview:keyEntry];
155     
156     regLater = [[NSButton alloc] initWithFrame:NSMakeRect(138, 16, 116, 25)];
157     [regLater setTitle:NSLocalizedString(@"registerLater", @"Register Later")];
158     [regLater setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]];
159     [regLater setTarget:_sender];
160     [regLater setAction:@selector(registerLater:)];
161     [regLater setBezelStyle:NSRoundedBezelStyle];
162     [contentView addSubview:regLater];
163     
164     verifyKey = [[NSButton alloc] initWithFrame:NSMakeRect(255, 16, 116, 25)];
165     [verifyKey setTitle:NSLocalizedString(@"verifyKey", @"Verify Key")];
166     [verifyKey setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]];
167     [verifyKey setTarget:_sender];
168     [verifyKey setAction:@selector(verifyKey:)];
169     [verifyKey setBezelStyle:NSRoundedBezelStyle];
170     [verifyKey setKeyEquivalent:[NSString stringWithCharacters:&returnChar length:1]];
171     [contentView addSubview:verifyKey];
172 }
173
174 - (void)setTargets
175 {
176     [registerButton setTarget:_sender];
177     [ownerEntry setTarget:_sender];
178     [keyEntry setTarget:_sender];
179     [regLater setTarget:_sender];
180     [verifyKey setTarget:_sender];
181 }
182
183 - (NSString *)owner
184 {
185     return [ownerEntry stringValue];
186 }
187
188 - (NSString *)key
189 {
190     return [keyEntry stringValue];
191 }
192
193 @end