123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- //
- // KMSecurityContentView.swift
- // PDF Reader Pro
- //
- // Created by lizhe on 2025/1/8.
- //
- import Cocoa
- import KMComponentLibrary
- class KMSecurityContentView: BaseXibView {
- @IBOutlet weak var titleLabel: NSTextField!
- @IBOutlet var openPwdCheckBox: ComponentCheckBox!
- @IBOutlet var openPasswordView: ComponentPasswordView!
- @IBOutlet weak var openPwdCheckBoxWidthConstraint: NSLayoutConstraint!
-
- @IBOutlet var ownerPwdCheckBox: ComponentCheckBox!
- @IBOutlet var ownerPasswordView: ComponentPasswordView!
- @IBOutlet weak var ownerPwdCheckBoxWidthConstraint: NSLayoutConstraint!
-
- @IBOutlet var notPrintCheckBox: ComponentCheckBox!
- @IBOutlet var notCopyCheckBox: ComponentCheckBox!
-
- var isDisable: Bool = false {
- didSet {
- self.reloadData()
- }
- }
-
- var model: KMSecureEncryptModel = KMSecureEncryptModel()
-
- override func draw(_ dirtyRect: NSRect) {
- super.draw(dirtyRect)
- // Drawing code here.
- }
-
- override func setup() {
- updateLanguage()
- self.updateOwnerButtonState()
- }
-
- func updateLanguage() {
- titleLabel.stringValue = KMLocalizedString("Password Security Settings")
- titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/1")
- titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-medium")
-
- openPwdCheckBox.properties = ComponentCheckBoxProperty(size: .s, state: .normal, showhelp: true, text: KMLocalizedString("Require a password to open the document.", comment: ""), checkboxType: .normal)
- openPwdCheckBox.setTarget(self, action: #selector(openPasswordButtonAction(_:)))
- openPwdCheckBox.reloadData()
-
- openPwdCheckBoxWidthConstraint.constant = openPwdCheckBox.properties.propertyInfo.viewWidth
-
- openPasswordView.properties = ComponentPasswordProperty(size: .m,
- state: .normal,
- isError: false,
- placeholderString: "Please enter password",
- text: "",
- isDisabled: false,
- errorText: "Here is the error message description.")
- openPasswordView.toolTip = KMLocalizedString("Here is the error message description.")
- openPasswordView.delegate = self
- openPasswordView.reloadData()
-
- ownerPwdCheckBox.properties = ComponentCheckBoxProperty(size: .s, state: .normal, showhelp: true, text: KMLocalizedString("Require a password to open the document.", comment: ""), checkboxType: .normal)
- ownerPwdCheckBox.setTarget(self, action: #selector(ownerPaasswordButtonAction(_:)))
-
- ownerPasswordView.properties = ComponentPasswordProperty(size: .m,
- state: .normal,
- isError: false,
- placeholderString: "Please enter password",
- text: "",
- isDisabled: false,
- errorText: "Here is the error message description.")
- openPasswordView.toolTip = KMLocalizedString("Here is the error message description.")
- ownerPasswordView.delegate = self
- ownerPwdCheckBoxWidthConstraint.constant = openPwdCheckBox.properties.propertyInfo.viewWidth
-
- notPrintCheckBox.properties = ComponentCheckBoxProperty(size: .s, state: .normal, text: KMLocalizedString("Restrict document printing", comment: ""), checkboxType: .normal)
- notPrintCheckBox.setTarget(self, action: #selector(printButtonAction(_:)))
-
- notCopyCheckBox.properties = ComponentCheckBoxProperty(size: .s, state: .normal, text: KMLocalizedString("Restrict content copying", comment: ""), checkboxType: .normal)
- notCopyCheckBox.setTarget(self, action: #selector(copyButtonAction(_:)))
- }
-
- func reloadData() {
- self.notPrintCheckBox.properties.isDisabled = self.isDisable
- self.notPrintCheckBox.reloadData()
- self.notCopyCheckBox.properties.isDisabled = self.isDisable
- self.notCopyCheckBox.reloadData()
- self.openPwdCheckBox.properties.isDisabled = self.isDisable
- self.openPwdCheckBox.reloadData()
- self.openPasswordView.properties.isDisabled = self.isDisable
- self.openPasswordView.reloadData()
- self.ownerPwdCheckBox.properties.isDisabled = self.isDisable
- self.ownerPwdCheckBox.reloadData()
- self.ownerPasswordView.properties.isDisabled = self.isDisable
- self.ownerPasswordView.reloadData()
-
- let openPWisdiable = model.openPasswordOn ? false : true
- if openPasswordView.properties.isDisabled != openPWisdiable {
- openPasswordView.properties.isDisabled = model.openPasswordOn ? false : true
- openPasswordView.reloadData()
- }
-
- let ownerPWisdiable = model.ownerPasswordOn ? false : true
- if ownerPasswordView.properties.isDisabled != ownerPWisdiable {
- ownerPasswordView.properties.isDisabled = model.ownerPasswordOn ? false : true
- ownerPasswordView.reloadData()
- }
-
- notPrintCheckBox.properties.isDisabled = model.printEnabled ? false : true
- notPrintCheckBox.properties.checkboxType = model.printAllowed ? .normal : .selected
- notPrintCheckBox.reloadData()
-
- notCopyCheckBox.properties.isDisabled = model.editEnabled ? false : true
- notCopyCheckBox.properties.checkboxType = model.editAllowed ? .normal : .selected
- notCopyCheckBox.reloadData()
- }
-
- func updatePasswordState() {
- self.model.openPassword = openPasswordView.properties.text
- self.model.ownerPassword = ownerPasswordView.properties.text
-
- // 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 KMSecurityContentView {
- @objc func openPasswordButtonAction(_ sender: Any) {
- self.model.openPasswordOn = self.openPwdCheckBox.properties.checkboxType == .selected ? true:false
- self.reloadData()
- }
-
- @objc func ownerPaasswordButtonAction(_ sender: Any) {
- self.model.ownerPasswordOn = self.ownerPwdCheckBox.properties.checkboxType == .selected ? true:false
- self.updateOwnerButtonState()
- }
-
- @objc func printButtonAction(_ sender: Any) {
- self.model.printAllowed = self.notPrintCheckBox.properties.checkboxType == .selected ? false:true
-
- self.reloadData()
- }
-
- @objc func copyButtonAction(_ sender: Any) {
- self.model.editAllowed = self.notCopyCheckBox.properties.checkboxType == .selected ? false:true
-
- self.reloadData()
- }
- }
- //MARK: - ComponentPasswordViewDelegate
- extension KMSecurityContentView: ComponentPasswordViewDelegate {
- func componentPasswordViewDidChanged(inputView: ComponentPasswordView) {
- // self.updatePasswordState()
- }
-
- func componentPasswordViewDidEndEditing(inputView: ComponentPasswordView) {
- // self.updatePasswordState()
- }
- }
|