KMBatchSecurityView.swift 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // KMBatchSecurityView.swift
  3. // PDF Master
  4. //
  5. // Created by lizhe on 2023/1/16.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class KMBatchSecurityView: KMBatchSettingItemView {
  10. @IBOutlet weak var titleLabel: NSTextField!
  11. @IBOutlet weak var titleContentView: NSView!
  12. @IBOutlet weak var encryptButton: ComponentButton!
  13. @IBOutlet weak var securityContentView: KMSecurityContentView!
  14. var data: KMBatchSecurityViewModel = KMBatchSecurityViewModel()
  15. var presenter: KMBatchSecurityViewPresenter = KMBatchSecurityViewPresenter()
  16. override func draw(_ dirtyRect: NSRect) {
  17. super.draw(dirtyRect)
  18. // Drawing code here.
  19. }
  20. override func setup() {
  21. super.setup()
  22. self.titleContentView.border(ComponentLibrary.shared.getComponentColorFromKey("colorBorder/divider"), 0.5, 0)
  23. self.titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  24. self.titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-bold")
  25. self.presenter.initPresenter(view: self)
  26. self.encryptButton.properties = ComponentButtonProperty(type: .primary,
  27. size: .m,
  28. state: .normal,
  29. buttonText: KMLocalizedString("Apply"),
  30. keepPressState: false)
  31. self.encryptButton.setTarget(self, action: #selector(encryptButtonAction(_:)))
  32. self.encryptButton.reloadData()
  33. }
  34. override func reloadData() {
  35. if (self.filesData.count != 0) {
  36. self.encryptButton.properties.isDisabled = false
  37. } else {
  38. self.encryptButton.properties.isDisabled = true
  39. }
  40. }
  41. override func bacthProcessingNotification() {
  42. self.securityContentView.isDisable = self.isDisable
  43. self.encryptButton.properties.isDisabled = self.isDisable
  44. self.encryptButton.reloadData()
  45. }
  46. }
  47. protocol KMBatchSecurityViewAction { }
  48. extension KMBatchSecurityView: KMBatchCompressViewAction {
  49. func encryptButtonAction(_ sender: ComponentButton) {
  50. self.securityContentView.updatePasswordState()
  51. self.data.openPasswordString = self.securityContentView.model.openPassword
  52. self.data.isOpenPassword = self.securityContentView.model.openPasswordOn
  53. self.data.permissionString = self.securityContentView.model.ownerPassword
  54. self.data.isPermission = self.securityContentView.model.ownerPasswordOn
  55. if self.securityContentView.model.printAllowed {
  56. self.data.restrictOptions.insert(.print)
  57. } else {
  58. self.data.restrictOptions.remove(.print)
  59. }
  60. if self.securityContentView.model.editAllowed {
  61. self.data.restrictOptions.insert(.copy)
  62. } else {
  63. self.data.restrictOptions.remove(.copy)
  64. }
  65. if self.data.openPasswordString == self.data.permissionString {
  66. let alert = NSAlert()
  67. alert.alertStyle = .critical
  68. alert.messageText = KMLocalizedString("The Open and Owner passwords cannot be the same. Please change either the Open or the Owner Password.", comment: "")
  69. alert.runModal()
  70. return
  71. }
  72. self.batchExport?(self, self.data)
  73. }
  74. }
  75. extension KMBatchSecurityView: KMBatchSecurityViewPresenterDelegate {
  76. func showData(presenter: KMBatchSecurityViewPresenter, data: KMBatchSecurityViewModel) {
  77. self.data = data
  78. self.reloadData()
  79. }
  80. }