|
@@ -9,23 +9,155 @@ import Cocoa
|
|
|
|
|
|
typealias KMSecurityViewBatchAction = (_ view: KMSecurityView, _ files: [KMFileAttribute]) -> Void
|
|
|
typealias KMSecurityViewCancelAction = (_ view: KMSecurityView) -> Void
|
|
|
+typealias KMSecurityViewDoneAction = (_ view: KMSecurityView, _ model: KMSecureEncryptModel, _ files: [KMFileAttribute]) -> Void
|
|
|
|
|
|
class KMSecurityView: KMBaseXibView {
|
|
|
@IBOutlet weak var batchButton: NSButton!
|
|
|
@IBOutlet weak var cancelButton: NSButton!
|
|
|
@IBOutlet weak var doneButton: NSButton!
|
|
|
|
|
|
+ @IBOutlet weak var box1: NSBox!
|
|
|
+ @IBOutlet weak var boxLabel1: NSTextField!
|
|
|
+ @IBOutlet weak var openPwdCheckBtn: NSButton!
|
|
|
+ @IBOutlet weak var openPasswordPLabel: NSTextField!
|
|
|
+ @IBOutlet weak var openPassword: NSSecureTextField!
|
|
|
+
|
|
|
+ @IBOutlet weak var ownerPwdCheckBtn: NSButton!
|
|
|
+ @IBOutlet weak var ownerPasswordLabel: NSTextField!
|
|
|
+ @IBOutlet weak var ownerPassword: NSSecureTextField!
|
|
|
+ @IBOutlet weak var notPrintCheckBtn: NSButton!
|
|
|
+ @IBOutlet weak var notCopyCheckBtn: NSButton!
|
|
|
+
|
|
|
+ @IBOutlet weak var box2: NSBox!
|
|
|
+ @IBOutlet weak var boxLabel2: NSTextField!
|
|
|
+ @IBOutlet weak var titleTextField: NSTextField!
|
|
|
+ @IBOutlet weak var authorTextField: NSTextField!
|
|
|
+ @IBOutlet weak var subjectTextField: NSTextField!
|
|
|
+ @IBOutlet weak var keywordTextField: NSTextField!
|
|
|
+
|
|
|
+ @IBOutlet weak var titleLabel: NSTextField!
|
|
|
+ @IBOutlet weak var authorLabel: NSTextField!
|
|
|
+ @IBOutlet weak var subjectLabel: NSTextField!
|
|
|
+ @IBOutlet weak var keywordLabel: NSTextField!
|
|
|
+
|
|
|
var batchAction: KMSecurityViewBatchAction?
|
|
|
var cancelAction: KMSecurityViewCancelAction?
|
|
|
+ var doneAction: KMSecurityViewDoneAction?
|
|
|
+
|
|
|
+ var openPasswordString: String?
|
|
|
+ var ownerPasswordString: String?
|
|
|
|
|
|
var files: [KMFileAttribute] = []
|
|
|
+
|
|
|
+ private var model: KMSecureEncryptModel = KMSecureEncryptModel()
|
|
|
+ var canEncrypt: Bool = false
|
|
|
+
|
|
|
override func draw(_ dirtyRect: NSRect) {
|
|
|
super.draw(dirtyRect)
|
|
|
|
|
|
// Drawing code here.
|
|
|
}
|
|
|
|
|
|
+ override func setup() {
|
|
|
+ openPassword.delegate = self
|
|
|
+ ownerPassword.delegate = self
|
|
|
+
|
|
|
+ self.updateOwnerButtonState()
|
|
|
+ }
|
|
|
+
|
|
|
+ override func updateLanguage() {
|
|
|
+ batchButton.title = NSLocalizedString("Batch", comment: "")
|
|
|
+// cancelButton.title = NSLocalizedString("Remove All", comment: "")
|
|
|
+ doneButton.title = NSLocalizedString("Encrypt", comment: "")
|
|
|
+ cancelButton.title = NSLocalizedString("Close", comment: "")
|
|
|
+
|
|
|
+ boxLabel1.stringValue = NSLocalizedString("Password Security Settings", comment: "")
|
|
|
+ boxLabel2.stringValue = NSLocalizedString("Document Description", comment: "")
|
|
|
+ openPwdCheckBtn.title = NSLocalizedString("Require a password to open the document.", comment: "")
|
|
|
+ ownerPwdCheckBtn.title = NSLocalizedString("Restrict printing and copying of the document.", comment: "")
|
|
|
+ notPrintCheckBtn.title = NSLocalizedString("Restrict document printing", comment: "")
|
|
|
+ notCopyCheckBtn.title = NSLocalizedString("Restrict content copying", comment: "")
|
|
|
+ openPasswordPLabel.stringValue = NSLocalizedString("Open Password:", comment: "")
|
|
|
+ ownerPasswordLabel.stringValue = NSLocalizedString("Owner Password:", comment: "")
|
|
|
+ titleLabel.stringValue = NSLocalizedString("Title:", comment: "")
|
|
|
+ authorLabel.stringValue = NSLocalizedString("Author:", comment: "")
|
|
|
+ subjectLabel.stringValue = NSLocalizedString("Subject:", comment: "")
|
|
|
+ keywordLabel.stringValue = NSLocalizedString("Keywords:", comment: "")
|
|
|
+ }
|
|
|
+
|
|
|
+ override func reloadData() {
|
|
|
+
|
|
|
+ openPassword.isEnabled = model.openPasswordOn
|
|
|
+ ownerPassword.isEnabled = model.ownerPasswordOn
|
|
|
+
|
|
|
+ notPrintCheckBtn.isEnabled = model.printEnabled
|
|
|
+ notCopyCheckBtn.isEnabled = model.editEnabled
|
|
|
+
|
|
|
+ notPrintCheckBtn.state = model.printAllowed ?.off:.on
|
|
|
+ notCopyCheckBtn.state = model.editAllowed ?.off:.on
|
|
|
+
|
|
|
+ self.updateEncryptButtonEnabledState()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+extension KMSecurityView {
|
|
|
+ func updateEncryptButtonEnabledState() {
|
|
|
+ var enabled = false
|
|
|
+ if model.openPasswordOn {
|
|
|
+ if !model.openPassword.isEmpty {
|
|
|
+ enabled = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if enabled {
|
|
|
+ if model.ownerPasswordOn {
|
|
|
+ if (!model.ownerPassword.isEmpty && (!model.printAllowed || !model.editAllowed)) {
|
|
|
+ enabled = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if model.ownerPasswordOn {
|
|
|
+ if !model.ownerPassword.isEmpty && (!model.printAllowed || !model.editAllowed) {
|
|
|
+ enabled = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ self.canEncrypt = enabled
|
|
|
+ if enabled {
|
|
|
+ self.doneButton.isEnabled = true
|
|
|
+ } else {
|
|
|
+ self.doneButton.isEnabled = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func updatePasswordState() {
|
|
|
+ self.model.openPassword = openPassword.stringValue
|
|
|
+ self.model.ownerPassword = ownerPassword.stringValue
|
|
|
+ self.model.title = titleTextField.stringValue
|
|
|
+ self.model.author = titleTextField.stringValue
|
|
|
+ self.model.subject = titleTextField.stringValue
|
|
|
+ self.model.keywords = titleTextField.stringValue
|
|
|
+ self.reloadData()
|
|
|
+ }
|
|
|
|
|
|
+ func updateOwnerButtonState() {
|
|
|
+ if self.model.ownerPasswordOn {
|
|
|
+ self.model.printEnabled = true
|
|
|
+ self.model.editEnabled = true
|
|
|
+ self.model.printAllowed = false
|
|
|
+ self.model.editAllowed = false
|
|
|
+ } else {
|
|
|
+ self.model.printEnabled = false
|
|
|
+ self.model.editEnabled = false
|
|
|
+ self.model.printAllowed = true
|
|
|
+ self.model.editAllowed = true
|
|
|
+ }
|
|
|
+ self.reloadData()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+extension KMSecurityView {
|
|
|
@IBAction func batchButtonAction(_ sender: Any) {
|
|
|
guard let callBack = batchAction else { return }
|
|
|
|
|
@@ -39,7 +171,39 @@ class KMSecurityView: KMBaseXibView {
|
|
|
}
|
|
|
|
|
|
@IBAction func doneButtonAction(_ sender: Any) {
|
|
|
+ self.updatePasswordState()
|
|
|
+ guard let callBack = doneAction else { return }
|
|
|
|
|
|
+ callBack(self, model, files)
|
|
|
+ }
|
|
|
+
|
|
|
+ @IBAction func openPasswordButtonAction(_ sender: Any) {
|
|
|
+ self.model.openPasswordOn = self.openPwdCheckBtn.state == .on ? true:false
|
|
|
+ self.reloadData()
|
|
|
}
|
|
|
|
|
|
+ @IBAction func ownerPaasswordButtonAction(_ sender: Any) {
|
|
|
+ self.model.ownerPasswordOn = self.ownerPwdCheckBtn.state == .on ? true:false
|
|
|
+ self.updateOwnerButtonState()
|
|
|
+ }
|
|
|
+
|
|
|
+ @IBAction func printButtonAction(_ sender: Any) {
|
|
|
+ self.model.printAllowed = self.notPrintCheckBtn.state == .on ? false:true
|
|
|
+ self.reloadData()
|
|
|
+ }
|
|
|
+
|
|
|
+ @IBAction func copyButtonAction(_ sender: Any) {
|
|
|
+ self.model.editAllowed = self.notCopyCheckBtn.state == .on ? false:true
|
|
|
+ self.reloadData()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+extension KMSecurityView: NSTextFieldDelegate {
|
|
|
+ func controlTextDidEndEditing(_ obj: Notification) {
|
|
|
+ self.updatePasswordState()
|
|
|
+ }
|
|
|
+
|
|
|
+ func controlTextDidChange(_ obj: Notification) {
|
|
|
+ self.updatePasswordState()
|
|
|
+ }
|
|
|
}
|