123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- //
- // KMVerificationActivateViewController.m
- // Cisdem PDFMaster
- //
- // Created by 王帅 on 2018/5/8.
- //
- #import "KMVerificationActivateViewController.h"
- #import <PDF_Reader_Pro-Swift.h>
- #import "GBDeviceInfo.h"
- @interface KMVerificationActivateViewController ()
- @property (nonatomic,assign) IBOutlet NSTextField *label;
- @property (nonatomic,assign) IBOutlet NSTextField *sublabel;
- @property (nonatomic,assign) IBOutlet NSView *textFieldView;
- @property (nonatomic,assign) IBOutlet NSTextField *textField;
- @property (nonatomic,assign) IBOutlet NSTextField *textLabel;
- @property (nonatomic,assign) IBOutlet NSButton *clickHereButton;
- @property (nonatomic,assign) IBOutlet KMCustomButton *backButton;
- @property (nonatomic,assign) IBOutlet KMCustomButton *continueButton;
- @property (nonatomic, retain) CALayer *continueButtonLayer;
- @end
- @implementation KMVerificationActivateViewController
- #pragma mark Init Methods
- - (instancetype)init {
- if (self = [super initWithNibName:@"KMVerificationActivateViewController" bundle:nil]) {
-
- }
- return self;
- }
- - (void)dealloc {
-
- }
- #pragma mark View Methods
- - (void)loadView {
- [super loadView];
- // Do view setup here.
- self.textFieldView.wantsLayer = YES;
- self.textFieldView.layer.masksToBounds = YES;
- self.textFieldView.layer.cornerRadius = 1.0;
- self.textFieldView.layer.borderWidth = 1.0;
- self.textFieldView.layer.borderColor = [NSColor lightGrayColor].CGColor;
-
- self.backButton.wantsLayer = YES;
- self.backButton.layer.masksToBounds = YES;
- self.backButton.layer.cornerRadius = 1.0;
-
- self.continueButton.wantsLayer = YES;
- self.continueButton.layer.masksToBounds = YES;
- self.continueButton.layer.cornerRadius = 1.0;
- self.label.stringValue = NSLocalizedString(@"Please enter your license", nil);
- self.sublabel.stringValue = NSLocalizedString(@"If you have already purchased Cisdem PDFMaster for Mac, you should find your license in an email confirmation.", nil);
- self.textLabel.stringValue = NSLocalizedString(@"Can't find your license?", nil);
-
- [self.textField.cell setPlaceholderString:NSLocalizedString(@"License Number", nil)];
-
- NSMutableAttributedString *attributedTitle = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"Click here", nil)];
- NSRange range = NSMakeRange(0, attributedTitle.length);
- [attributedTitle addAttribute:NSFontAttributeName value:self.clickHereButton.font range:range];
- [attributedTitle addAttribute:NSForegroundColorAttributeName value:[KMAppearance KMColor_Layout_H0] range:range];
- [attributedTitle addAttribute:NSUnderlineStyleAttributeName value:@(YES) range:range];
- self.clickHereButton.attributedTitle = attributedTitle;
- self.backButton.title = NSLocalizedString(@"Cancel", nil);
- self.continueButton.title = NSLocalizedString(@"Continue", nil);
- [self.backButton setTitleColor:[KMAppearance KMColor_Layout_H0]];
- [self.continueButton setTitleColor:[NSColor whiteColor]];
-
- self.continueButtonLayer = [CALayer layer];
- [self.continueButton.layer addSublayer:self.continueButtonLayer];
- self.continueButtonLayer.frame = CGRectMake(0, 0, CGRectGetWidth(_continueButton.bounds), CGRectGetHeight(_continueButton.bounds));
- self.continueButtonLayer.backgroundColor = [KMAppearance KMColor_Status_Sel].CGColor;
- self.continueButtonLayer.cornerRadius = 0;
- self.continueButtonLayer.hidden = YES;
- __block KMVerificationActivateViewController *blockSelf = self;
- self.continueButton.mouseMoveCallback = ^(BOOL mouseEntered) {
- if (mouseEntered)
- blockSelf.continueButtonLayer.hidden = NO;
- else
- blockSelf.continueButtonLayer.hidden = YES;
- };
- self.backButton.mouseMoveCallback = nil;
-
- [self.label setTextColor:[KMAppearance KMColor_Layout_H0]];
- [self.sublabel setTextColor:[KMAppearance KM_242424_Color75]];
- [self.textLabel setTextColor:[KMAppearance KMColor_Layout_H0]];
-
- self.type = KMVerificationTypeActivate;
- }
- - (void)viewDidAppear {
- [super viewDidAppear];
- [self.textField becomeFirstResponder];
- }
- - (void)setType:(KMVerificationType)type {
- if (type == KMVerificationTypeActivateAIInfo) {
- self.textLabel.hidden = YES;
- self.clickHereButton.hidden = YES;
- self.label.stringValue = NSLocalizedString(@"Please Enter AI License", nil);
- self.sublabel.stringValue = NSLocalizedString(@"For Cisdem PDFMaster Permanent/Premium License, please click Cisdem PDFMaster on the menubar, then tap \"Enter License\".", nil);
- [self.textField.cell setPlaceholderString:NSLocalizedString(@"AI-XXXX-XXXX-XXXX-XXXX", nil)];
- } else {
- self.textLabel.hidden = NO;
- self.clickHereButton.hidden = NO;
- self.label.stringValue = NSLocalizedString(@"Please enter your license", nil);
- self.sublabel.stringValue = NSLocalizedString(@"If you have already purchased Cisdem PDFMaster for Mac, you should find your license in an email confirmation.", nil);
- [self.textField.cell setPlaceholderString:NSLocalizedString(@"XXXX-XXXX-XXXX-XXXX", nil)];
- }
- }
- #pragma mark Button Actions
- - (IBAction)backButtonAction:(id)sender {
- if (self.callback) {
- self.callback(0, self.textField.stringValue);
- }
- }
- - (IBAction)continueButtonAction:(id)sender {
- NSString *lineString = self.textField.stringValue;
- lineString = [lineString stringByReplacingOccurrencesOfString:@" " withString:@""];
- if (lineString.length > 0) {
- self.textFieldView.layer.borderColor = [NSColor lightGrayColor].CGColor;
- } else {
- self.textFieldView.layer.borderColor = [NSColor redColor].CGColor;
- NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
- defaultButton:NSLocalizedString(@"Try Again", nil)
- alternateButton:nil
- otherButton:nil
- informativeTextWithFormat:NSLocalizedString(@"License number can not be empty.", nil), nil];
- [alert runModal];
- return;
- }
- if (self.callback) {
- self.callback(1, lineString);
- }
- }
- - (IBAction)clickHereButtonAction:(id)sender {
- unsigned major, minor, bugFix;
- [self getSystemVersionMajor:&major minor:&minor bugFix:&bugFix];
- NSString *versionString = [NSString stringWithFormat:@"%@ - %u.%u.%u", [GBDeviceInfo deviceInfo].rawSystemInfoString, major, minor, bugFix];
- //application version (use short version preferentially)
- NSString *tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
- if ([tAppVersion length] < 1)
- {
- tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
- }
-
- NSString* subjects = [[self getAppNameForSupportEmail] stringByAppendingFormat:NSLocalizedString(@" - %@;Feedback;%@", nil) ,tAppVersion,versionString];
- [KMMailHelper newEmailWithContacts:@"support@cisdem.com" andSubjects:subjects];
- }
- - (NSString *)getAppNameForSupportEmail
- {
- NSString *tAppName = @"Cisdem PDFMaster";
-
- // 桌机版
- VerificationManager *tManager = [VerificationManager manager];
- switch ([tManager status]) {
- case ActivityStatusTrial:
- tAppName = [tAppName stringByAppendingString:@" Trial"];
- break;
-
- case ActivityStatusVerification:
- tAppName = [tAppName stringByAppendingString:@" Verification"];
- break;
-
- case ActivityStatusTrialExpire:
- tAppName = [tAppName stringByAppendingString:@" TrialExpire"];
- break;
-
- case ActivityStatusVerifExpire:
- tAppName = [tAppName stringByAppendingString:@" VerifExpire"];
- break;
-
- default:
- break;
- }
-
- return tAppName;
- }
- - (void)getSystemVersionMajor:(unsigned *)major
- minor:(unsigned *)minor
- bugFix:(unsigned *)bugFix;
- {
- OSErr err;
- SInt32 systemVersion, versionMajor, versionMinor, versionBugFix;
-
- if ([[NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion)]) {
- NSOperatingSystemVersion osSystemVersion = [[NSProcessInfo processInfo] operatingSystemVersion];
-
- *major = (unsigned)osSystemVersion.majorVersion;
- *minor = (unsigned)osSystemVersion.minorVersion;
- *bugFix = (unsigned)osSystemVersion.patchVersion;
-
- return;
- } else {
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored "-Wdeprecated-declarations"
- if ((err = Gestalt(gestaltSystemVersion, &systemVersion)) != noErr) goto fail;
- if (systemVersion < 0x1040)
- {
- if (major) *major = ((systemVersion & 0xF000) >> 12) * 10 +
- ((systemVersion & 0x0F00) >> 8);
- if (minor) *minor = (systemVersion & 0x00F0) >> 4;
- if (bugFix) *bugFix = (systemVersion & 0x000F);
- }
- else
- {
- if ((err = Gestalt(gestaltSystemVersionMajor, &versionMajor)) != noErr) goto fail;
- if ((err = Gestalt(gestaltSystemVersionMinor, &versionMinor)) != noErr) goto fail;
- if ((err = Gestalt(gestaltSystemVersionBugFix, &versionBugFix)) != noErr) goto fail;
- if (major) *major = versionMajor;
- if (minor) *minor = versionMinor;
- if (bugFix) *bugFix = versionBugFix;
- }
-
- return;
- #pragma clang diagnostic pop
- }
-
- fail:
- NSLog(@"Unable to obtain system version: %ld", (long)err);
- if (major) *major = 10;
- if (minor) *minor = 0;
- if (bugFix) *bugFix = 0;
- }
- - (void)setEnabled:(BOOL)enabled {
- self.backButton.enabled = enabled;
- self.continueButton.enabled = enabled;
- self.textField.enabled = enabled;
- }
- #pragma mark NSTextFieldDelegate
- - (void)controlTextDidChange:(NSNotification *)notification {
- self.textFieldView.layer.borderColor = [NSColor lightGrayColor].CGColor;
- }
- @end
|