KMVerificationActivateViewController.m 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. //
  2. // KMVerificationActivateViewController.m
  3. // Cisdem PDFMaster
  4. //
  5. // Created by 王帅 on 2018/5/8.
  6. //
  7. #import "KMVerificationActivateViewController.h"
  8. #import <PDF_Reader_Pro-Swift.h>
  9. #import "GBDeviceInfo.h"
  10. @interface KMVerificationActivateViewController ()
  11. @property (nonatomic,assign) IBOutlet NSTextField *label;
  12. @property (nonatomic,assign) IBOutlet NSTextField *sublabel;
  13. @property (nonatomic,assign) IBOutlet NSView *textFieldView;
  14. @property (nonatomic,assign) IBOutlet NSTextField *textField;
  15. @property (nonatomic,assign) IBOutlet NSTextField *textLabel;
  16. @property (nonatomic,assign) IBOutlet NSButton *clickHereButton;
  17. @property (nonatomic,assign) IBOutlet KMCustomButton *backButton;
  18. @property (nonatomic,assign) IBOutlet KMCustomButton *continueButton;
  19. @property (nonatomic, retain) CALayer *continueButtonLayer;
  20. @end
  21. @implementation KMVerificationActivateViewController
  22. #pragma mark Init Methods
  23. - (instancetype)init {
  24. if (self = [super initWithNibName:@"KMVerificationActivateViewController" bundle:nil]) {
  25. }
  26. return self;
  27. }
  28. - (void)dealloc {
  29. }
  30. #pragma mark View Methods
  31. - (void)loadView {
  32. [super loadView];
  33. // Do view setup here.
  34. self.textFieldView.wantsLayer = YES;
  35. self.textFieldView.layer.masksToBounds = YES;
  36. self.textFieldView.layer.cornerRadius = 1.0;
  37. self.textFieldView.layer.borderWidth = 1.0;
  38. self.textFieldView.layer.borderColor = [NSColor lightGrayColor].CGColor;
  39. self.backButton.wantsLayer = YES;
  40. self.backButton.layer.masksToBounds = YES;
  41. self.backButton.layer.cornerRadius = 1.0;
  42. self.continueButton.wantsLayer = YES;
  43. self.continueButton.layer.masksToBounds = YES;
  44. self.continueButton.layer.cornerRadius = 1.0;
  45. self.label.stringValue = NSLocalizedString(@"Please enter your license", nil);
  46. self.sublabel.stringValue = NSLocalizedString(@"If you have already purchased Cisdem PDFMaster for Mac, you should find your license in an email confirmation.", nil);
  47. self.textLabel.stringValue = NSLocalizedString(@"Can't find your license?", nil);
  48. [self.textField.cell setPlaceholderString:NSLocalizedString(@"License Number", nil)];
  49. NSMutableAttributedString *attributedTitle = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"Click here", nil)];
  50. NSRange range = NSMakeRange(0, attributedTitle.length);
  51. [attributedTitle addAttribute:NSFontAttributeName value:self.clickHereButton.font range:range];
  52. [attributedTitle addAttribute:NSForegroundColorAttributeName value:[KMAppearance KMColor_Layout_H0] range:range];
  53. [attributedTitle addAttribute:NSUnderlineStyleAttributeName value:@(YES) range:range];
  54. self.clickHereButton.attributedTitle = attributedTitle;
  55. self.backButton.title = NSLocalizedString(@"Cancel", nil);
  56. self.continueButton.title = NSLocalizedString(@"Continue", nil);
  57. [self.backButton setTitleColor:[KMAppearance KMColor_Layout_H0]];
  58. [self.continueButton setTitleColor:[NSColor whiteColor]];
  59. self.continueButtonLayer = [CALayer layer];
  60. [self.continueButton.layer addSublayer:self.continueButtonLayer];
  61. self.continueButtonLayer.frame = CGRectMake(0, 0, CGRectGetWidth(_continueButton.bounds), CGRectGetHeight(_continueButton.bounds));
  62. self.continueButtonLayer.backgroundColor = [KMAppearance KMColor_Status_Sel].CGColor;
  63. self.continueButtonLayer.cornerRadius = 0;
  64. self.continueButtonLayer.hidden = YES;
  65. __block KMVerificationActivateViewController *blockSelf = self;
  66. self.continueButton.mouseMoveCallback = ^(BOOL mouseEntered) {
  67. if (mouseEntered)
  68. blockSelf.continueButtonLayer.hidden = NO;
  69. else
  70. blockSelf.continueButtonLayer.hidden = YES;
  71. };
  72. self.backButton.mouseMoveCallback = nil;
  73. [self.label setTextColor:[KMAppearance KMColor_Layout_H0]];
  74. [self.sublabel setTextColor:[KMAppearance KM_242424_Color75]];
  75. [self.textLabel setTextColor:[KMAppearance KMColor_Layout_H0]];
  76. self.type = KMVerificationTypeActivate;
  77. }
  78. - (void)viewDidAppear {
  79. [super viewDidAppear];
  80. [self.textField becomeFirstResponder];
  81. }
  82. - (void)setType:(KMVerificationType)type {
  83. if (type == KMVerificationTypeActivateAIInfo) {
  84. self.textLabel.hidden = YES;
  85. self.clickHereButton.hidden = YES;
  86. self.label.stringValue = NSLocalizedString(@"Please Enter AI License", nil);
  87. self.sublabel.stringValue = NSLocalizedString(@"For Cisdem PDFMaster Permanent/Premium License, please click Cisdem PDFMaster on the menubar, then tap \"Enter License\".", nil);
  88. [self.textField.cell setPlaceholderString:NSLocalizedString(@"AI-XXXX-XXXX-XXXX-XXXX", nil)];
  89. } else {
  90. self.textLabel.hidden = NO;
  91. self.clickHereButton.hidden = NO;
  92. self.label.stringValue = NSLocalizedString(@"Please enter your license", nil);
  93. self.sublabel.stringValue = NSLocalizedString(@"If you have already purchased Cisdem PDFMaster for Mac, you should find your license in an email confirmation.", nil);
  94. [self.textField.cell setPlaceholderString:NSLocalizedString(@"XXXX-XXXX-XXXX-XXXX", nil)];
  95. }
  96. }
  97. #pragma mark Button Actions
  98. - (IBAction)backButtonAction:(id)sender {
  99. if (self.callback) {
  100. self.callback(0, self.textField.stringValue);
  101. }
  102. }
  103. - (IBAction)continueButtonAction:(id)sender {
  104. NSString *lineString = self.textField.stringValue;
  105. lineString = [lineString stringByReplacingOccurrencesOfString:@" " withString:@""];
  106. if (lineString.length > 0) {
  107. self.textFieldView.layer.borderColor = [NSColor lightGrayColor].CGColor;
  108. } else {
  109. self.textFieldView.layer.borderColor = [NSColor redColor].CGColor;
  110. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  111. defaultButton:NSLocalizedString(@"Try Again", nil)
  112. alternateButton:nil
  113. otherButton:nil
  114. informativeTextWithFormat:NSLocalizedString(@"License number can not be empty.", nil), nil];
  115. [alert runModal];
  116. return;
  117. }
  118. if (self.callback) {
  119. self.callback(1, lineString);
  120. }
  121. }
  122. - (IBAction)clickHereButtonAction:(id)sender {
  123. unsigned major, minor, bugFix;
  124. [self getSystemVersionMajor:&major minor:&minor bugFix:&bugFix];
  125. NSString *versionString = [NSString stringWithFormat:@"%@ - %u.%u.%u", [GBDeviceInfo deviceInfo].rawSystemInfoString, major, minor, bugFix];
  126. //application version (use short version preferentially)
  127. NSString *tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
  128. if ([tAppVersion length] < 1)
  129. {
  130. tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
  131. }
  132. NSString* subjects = [[self getAppNameForSupportEmail] stringByAppendingFormat:NSLocalizedString(@" - %@;Feedback;%@", nil) ,tAppVersion,versionString];
  133. [KMMailHelper newEmailWithContacts:@"support@cisdem.com" andSubjects:subjects];
  134. }
  135. - (NSString *)getAppNameForSupportEmail
  136. {
  137. NSString *tAppName = @"Cisdem PDFMaster";
  138. // 桌机版
  139. VerificationManager *tManager = [VerificationManager manager];
  140. switch ([tManager status]) {
  141. case ActivityStatusTrial:
  142. tAppName = [tAppName stringByAppendingString:@" Trial"];
  143. break;
  144. case ActivityStatusVerification:
  145. tAppName = [tAppName stringByAppendingString:@" Verification"];
  146. break;
  147. case ActivityStatusTrialExpire:
  148. tAppName = [tAppName stringByAppendingString:@" TrialExpire"];
  149. break;
  150. case ActivityStatusVerifExpire:
  151. tAppName = [tAppName stringByAppendingString:@" VerifExpire"];
  152. break;
  153. default:
  154. break;
  155. }
  156. return tAppName;
  157. }
  158. - (void)getSystemVersionMajor:(unsigned *)major
  159. minor:(unsigned *)minor
  160. bugFix:(unsigned *)bugFix;
  161. {
  162. OSErr err;
  163. SInt32 systemVersion, versionMajor, versionMinor, versionBugFix;
  164. if ([[NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion)]) {
  165. NSOperatingSystemVersion osSystemVersion = [[NSProcessInfo processInfo] operatingSystemVersion];
  166. *major = (unsigned)osSystemVersion.majorVersion;
  167. *minor = (unsigned)osSystemVersion.minorVersion;
  168. *bugFix = (unsigned)osSystemVersion.patchVersion;
  169. return;
  170. } else {
  171. #pragma clang diagnostic push
  172. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  173. if ((err = Gestalt(gestaltSystemVersion, &systemVersion)) != noErr) goto fail;
  174. if (systemVersion < 0x1040)
  175. {
  176. if (major) *major = ((systemVersion & 0xF000) >> 12) * 10 +
  177. ((systemVersion & 0x0F00) >> 8);
  178. if (minor) *minor = (systemVersion & 0x00F0) >> 4;
  179. if (bugFix) *bugFix = (systemVersion & 0x000F);
  180. }
  181. else
  182. {
  183. if ((err = Gestalt(gestaltSystemVersionMajor, &versionMajor)) != noErr) goto fail;
  184. if ((err = Gestalt(gestaltSystemVersionMinor, &versionMinor)) != noErr) goto fail;
  185. if ((err = Gestalt(gestaltSystemVersionBugFix, &versionBugFix)) != noErr) goto fail;
  186. if (major) *major = versionMajor;
  187. if (minor) *minor = versionMinor;
  188. if (bugFix) *bugFix = versionBugFix;
  189. }
  190. return;
  191. #pragma clang diagnostic pop
  192. }
  193. fail:
  194. NSLog(@"Unable to obtain system version: %ld", (long)err);
  195. if (major) *major = 10;
  196. if (minor) *minor = 0;
  197. if (bugFix) *bugFix = 0;
  198. }
  199. - (void)setEnabled:(BOOL)enabled {
  200. self.backButton.enabled = enabled;
  201. self.continueButton.enabled = enabled;
  202. self.textField.enabled = enabled;
  203. }
  204. #pragma mark NSTextFieldDelegate
  205. - (void)controlTextDidChange:(NSNotification *)notification {
  206. self.textFieldView.layer.borderColor = [NSColor lightGrayColor].CGColor;
  207. }
  208. @end