Status windows with buttons now scale properly.
[MenuTunes.git] / MTBlingController.m
1 //
2 //  MTBlingController.m
3 //  MenuTunes
4 //
5 //  Created by Matthew L. Judy on Tue Aug 19 2003.
6 //  Copyright (c) 2003 iThink Software. All rights reserved.
7 //
8
9 #import "MTBlingController.h"
10 #import "MTeSerialNumber.h"
11 #import "MainController.h"
12
13 #define APP_SUPPORT_PATH_STRING [@"~/Library/Application Support/MenuTunes/" stringByExpandingTildeInPath]
14 #define LICENSE_PATH_STRING [APP_SUPPORT_PATH_STRING stringByAppendingString:@"/.license"]
15
16
17 @interface MTBlingController (Private)
18 - (void)showPanel;
19 @end
20
21
22 @implementation MTBlingController
23
24
25 - (void)_HEY {}
26 - (void)_SUCKA {}
27 - (void)_QUIT {}
28 - (void)_HACKING {}
29 - (void)_AND {}
30 - (void)_GO {}
31 - (void)_BUY {}
32 - (void)_IT {}
33 - (void)_YOU {}
34 - (void)_TIGHTWAD {}
35 - (void)_HAHAHA {}
36 - (void)_LOLOL {}
37 - (void)_FIVERSKATES {}
38
39 - (id)init
40 {
41     if ( ( self = [super init] ) ) {
42         checkDone = 0;
43     }
44     return self;
45 }
46
47
48 - (void)showPanel
49 {
50     if ( ! window ) {
51         window = [MTShizzleWindow sharedWindowForSender:self];
52     }
53     [NSApp activateIgnoringOtherApps:YES];
54     [window center];
55     [window orderFrontRegardless];
56     [window makeKeyWindow];
57 //  [window setLevel:NSStatusWindowLevel];
58 }
59
60 - (void)showPanelIfNeeded
61 {
62     if ( ! (checkDone == 2475) ) {
63         if ( ! ([self checkKeyFile] == 7465) ) {
64             [self showPanel];
65         } else {
66             checkDone = 2475;
67         }
68     }
69 }
70
71 - (void)goToTheStore:(id)sender
72 {
73     [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://store.eSellerate.net/s.asp?s=STR090894476"]];
74 }
75
76 - (void)registerLater:(id)sender
77 {
78     [window orderOut:self];
79 }
80
81 - (void)verifyKey:(id)sender
82 {
83     NSString *o = [window owner];
84     NSString *k = [window key];
85
86     MTeSerialNumber *s = [[[MTeSerialNumber alloc] initWithSerialNumber:k
87                                                                    name:o
88                                                                   extra:nil
89                                                               publisher:@"04611"] autorelease];
90     if ( ([s isValid] == ITeSerialNumberIsValid) && ( [[[s infoDictionary] objectForKey:@"appIdentifier"] isEqualToString:@"MT"] ) ) {
91     
92         NSFileManager *fm = [NSFileManager defaultManager];
93         
94         if ( ! [fm fileExistsAtPath:APP_SUPPORT_PATH_STRING] ) {
95             [fm createDirectoryAtPath:APP_SUPPORT_PATH_STRING attributes:nil];
96         }
97         
98         [[NSDictionary dictionaryWithObjectsAndKeys:
99             o, @"Owner",
100             k, @"Key",
101             nil] writeToFile:LICENSE_PATH_STRING atomically:YES];
102
103         checkDone = 2475;
104
105         NSBeginInformationalAlertSheet(NSLocalizedString(@"validated_title", @"Validated Title"),
106                                        @"Thank You!", nil, nil,
107                                        window,
108                                        self,
109                                        @selector(finishValidSheet:returnCode:contextInfo:),
110                                        nil,
111                                        nil,
112                                        NSLocalizedString(@"validated_msg", @"Validated Message"));
113
114     } else {
115     
116         NSBeginAlertSheet(NSLocalizedString(@"failed_title", @"Failed Title"),
117                           @"Try Again", nil, nil,
118                           window,
119                           self,
120                           nil, nil, nil,
121                           NSLocalizedString(@"failed_msg", @"Failed Message"));
122     }
123     [[MainController sharedController] blingTime];
124 }
125
126 - (int)checkKeyFile
127 {
128     NSString        *p = LICENSE_PATH_STRING;
129     MTeSerialNumber *k = [[[MTeSerialNumber alloc] initWithContentsOfFile:p
130                                                                     extra:@""
131                                                                 publisher:@"04611"] autorelease];
132     if ( k && ([k isValid] == ITeSerialNumberIsValid) && ( [[[k infoDictionary] objectForKey:@"appIdentifier"] isEqualToString:@"MT"] )) {
133         return 7465;
134     } else {
135         [[NSFileManager defaultManager] removeFileAtPath:p handler:nil];
136         return 0;
137     }
138
139 }
140
141 - (int)checkDone
142 {
143     if ( ! (checkDone == 2475) ) {
144         if ( ! ([self checkKeyFile] == 7465) ) {
145             checkDone = 0;
146         } else {
147             checkDone = 2475;
148         }
149     }
150     return checkDone;
151 }
152
153 - (void)finishValidSheet:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
154 {
155     [window orderOut:self];
156 }
157
158 @end