// // KMBatchSecurityView.swift // PDF Master // // Created by lizhe on 2023/1/16. // import Cocoa import KMComponentLibrary class KMBatchSecurityView: KMBatchSettingItemView { @IBOutlet weak var titleLabel: NSTextField! @IBOutlet weak var titleContentView: NSView! @IBOutlet weak var encryptButton: ComponentButton! @IBOutlet weak var securityContentView: KMSecurityContentView! var data: KMBatchSecurityViewModel = KMBatchSecurityViewModel() var presenter: KMBatchSecurityViewPresenter = KMBatchSecurityViewPresenter() override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) // Drawing code here. } override func setup() { super.setup() self.titleContentView.border(ComponentLibrary.shared.getComponentColorFromKey("colorBorder/divider"), 0.5, 0) self.titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2") self.titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-bold") self.presenter.initPresenter(view: self) self.encryptButton.properties = ComponentButtonProperty(type: .primary, size: .m, state: .normal, buttonText: KMLocalizedString("Apply"), keepPressState: false) self.encryptButton.setTarget(self, action: #selector(encryptButtonAction(_:))) self.encryptButton.reloadData() } override func reloadData() { if (self.filesData.count != 0) { self.encryptButton.properties.isDisabled = false } else { self.encryptButton.properties.isDisabled = true } } override func bacthProcessingNotification() { self.securityContentView.isDisable = self.isDisable self.encryptButton.properties.isDisabled = self.isDisable self.encryptButton.reloadData() } } protocol KMBatchSecurityViewAction { } extension KMBatchSecurityView: KMBatchCompressViewAction { func encryptButtonAction(_ sender: ComponentButton) { self.securityContentView.updatePasswordState() self.data.openPasswordString = self.securityContentView.model.openPassword self.data.isOpenPassword = self.securityContentView.model.openPasswordOn self.data.permissionString = self.securityContentView.model.ownerPassword self.data.isPermission = self.securityContentView.model.ownerPasswordOn if self.securityContentView.model.printAllowed { self.data.restrictOptions.insert(.print) } else { self.data.restrictOptions.remove(.print) } if self.securityContentView.model.editAllowed { self.data.restrictOptions.insert(.copy) } else { self.data.restrictOptions.remove(.copy) } if self.data.openPasswordString == self.data.permissionString { let alert = NSAlert() alert.alertStyle = .critical alert.messageText = KMLocalizedString("The Open and Owner passwords cannot be the same. Please change either the Open or the Owner Password.", comment: "") alert.runModal() return } self.batchExport?(self, self.data) } } extension KMBatchSecurityView: KMBatchSecurityViewPresenterDelegate { func showData(presenter: KMBatchSecurityViewPresenter, data: KMBatchSecurityViewModel) { self.data = data self.reloadData() } }