forked from machinecodex/CodexFab_LicenseExample
/
XMLicensingWindowController.m
161 lines (111 loc) · 3.7 KB
/
XMLicensingWindowController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//
// CodexFab LicenseExample
//
// XMLicensingWindowController.m
//
// Creates a pretty animating Licensing window. Modify for your own needs.
//
// Licensed under CC Attribution License 3.0 <http://creativecommons.org/licenses/by/3.0/>
//
// Based on MSZLinkedView by Marcus Zarra
// <http://www.cimgf.com/2008/03/03/core-animation-tutorial-wizard-dialog-with-transitions/>
//
// Created by Alex Clarke on 10/06/09.
// Copyright 2009 MachineCodex Software Australia. All rights reserved.
// <http://www.machinecodex.com>
#import "XMAppDelegate.h"
#import "XMLicensingWindowController.h"
#import "XMArgumentKeys.h"
static XMLicensingWindowController *_sharedLicensingWindowController = nil;
@implementation XMLicensingWindowController
@synthesize isLicensed;
@synthesize userInfo;
@synthesize currentView;
#pragma mark -
#pragma mark Singleton
+ (XMLicensingWindowController *)sharedLicensingWindowController
{
if (!_sharedLicensingWindowController) {
_sharedLicensingWindowController = [[self alloc] initWithWindowNibName:[self nibName]];
}
return _sharedLicensingWindowController;
}
+ (NSString *)nibName {
return @"Licensing";
}
#pragma mark Initialisation
- (id)initWithWindow:(NSWindow *)window {
if (self = [super initWithWindow:window]) {
}
return self;
}
-(void)dealloc {
[userInfo release];
[super dealloc];
}
- (void)awakeFromNib {
NSView *contentView = [[self window] contentView];
[contentView setWantsLayer:YES];
[contentView addSubview:[self currentView]];
transition = [CATransition animation];
[transition setType:kCATransitionFade];
[transition setSubtype:kCATransitionFromLeft];
NSDictionary *ani = [NSDictionary dictionaryWithObject:transition forKey:@"subviews"];
[contentView setAnimations:ani];
[[self window] setLevel:NSFloatingWindowLevel];
[[self window] setHidesOnDeactivate:YES];
[self showLicensedStatus:self.isLicensed];
}
#pragma mark User interface
- (IBAction) goToWebStore:(id)sender {
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:kXMWebStoreURL]];
}
- (void)setCurrentView:(MSZLinkedView*)newView {
if (!currentView) {
currentView = newView;
return;
}
NSView *contentView = [[self window] contentView];
[[contentView animator] replaceSubview:currentView with:newView];
currentView = newView;
}
- (IBAction) trial:(id)sender {
// Proceed with trial...
[self close:self];
}
- (IBAction) quit:(id)sender {
[[NSApplication sharedApplication] terminate:self];
}
- (IBAction) registerApp:(id)sender {
BOOL requestEndEditing = [[self window] makeFirstResponder:[self window]]; // Request end editing
if (!requestEndEditing) [[self window] endEditingFor:nil]; // If request fails, force end editing
// Broadcast notification of a changed registration information.
[[NSNotificationCenter defaultCenter] postNotificationName:XMDidChangeRegistrationNotification object:self];
}
- (void) showLicensedStatus:(BOOL)status {
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
NSString * regCode = [defaults valueForKey:kXMRegCode];
NSString * name = [defaults valueForKey:kXMRegName];
if (![regCode length] && ![name length]) {
[self setCurrentView: viewA];
return;
}
if (status == TRUE)
[self setCurrentView: viewB];
else
[self setCurrentView:viewC];
}
- (IBAction)close:(id)sender {
[[self window] orderOut:nil];
}
- (IBAction)nextView:(id)sender {
if (![[self currentView] nextView]) return;
[transition setSubtype:kCATransitionFromRight];
[self setCurrentView:[[self currentView] nextView]];
}
- (IBAction)previousView:(id)sender {
if (![[self currentView] previousView]) return;
[transition setSubtype:kCATransitionFromLeft];
[self setCurrentView:[[self currentView] previousView]];
}
@end