KMBatchSecurityView.swift 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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.stringValue = KMLocalizedString("Encrypt")
  24. self.titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  25. self.titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-bold")
  26. self.presenter.initPresenter(view: self)
  27. self.encryptButton.properties = ComponentButtonProperty(type: .primary,
  28. size: .m,
  29. state: .normal,
  30. buttonText: KMLocalizedString("Apply"),
  31. keepPressState: false)
  32. self.encryptButton.setTarget(self, action: #selector(encryptButtonAction(_:)))
  33. self.encryptButton.reloadData()
  34. }
  35. override func reloadData() {
  36. if (self.filesData.count != 0) {
  37. self.encryptButton.properties.isDisabled = false
  38. } else {
  39. self.encryptButton.properties.isDisabled = true
  40. }
  41. }
  42. override func bacthProcessingNotification() {
  43. self.securityContentView.isDisable = self.isDisable
  44. self.encryptButton.properties.isDisabled = self.isDisable
  45. self.encryptButton.reloadData()
  46. }
  47. }
  48. protocol KMBatchSecurityViewAction { }
  49. extension KMBatchSecurityView: KMBatchCompressViewAction {
  50. func encryptButtonAction(_ sender: ComponentButton) {
  51. if KMMemberInfo.shared.isLogin == false {
  52. KMLoginWindowsController.shared.showWindow(nil)
  53. return
  54. }
  55. self.securityContentView.updatePasswordState()
  56. self.data.openPasswordString = self.securityContentView.model.openPassword
  57. self.data.isOpenPassword = self.securityContentView.model.openPasswordOn
  58. self.data.permissionString = self.securityContentView.model.ownerPassword
  59. self.data.isPermission = self.securityContentView.model.ownerPasswordOn
  60. if self.securityContentView.model.printAllowed {
  61. self.data.restrictOptions.insert(.print)
  62. } else {
  63. self.data.restrictOptions.remove(.print)
  64. }
  65. if self.securityContentView.model.editAllowed {
  66. self.data.restrictOptions.insert(.copy)
  67. } else {
  68. self.data.restrictOptions.remove(.copy)
  69. }
  70. if self.data.openPasswordString == self.data.permissionString {
  71. let alert = NSAlert()
  72. alert.alertStyle = .critical
  73. alert.messageText = KMLocalizedString("The Open and Owner passwords cannot be the same. Please change either the Open or the Owner Password.", comment: "")
  74. alert.runModal()
  75. return
  76. }
  77. self.batchExport?(self, self.data)
  78. }
  79. }
  80. extension KMBatchSecurityView: KMBatchSecurityViewPresenterDelegate {
  81. func showData(presenter: KMBatchSecurityViewPresenter, data: KMBatchSecurityViewModel) {
  82. self.data = data
  83. self.reloadData()
  84. }
  85. }