KMBatchSecurityView.swift 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. if KMMemberInfo.shared.isLogin == false {
  51. KMLoginWindowsController.shared.showWindow(nil)
  52. return
  53. }
  54. self.securityContentView.updatePasswordState()
  55. self.data.openPasswordString = self.securityContentView.model.openPassword
  56. self.data.isOpenPassword = self.securityContentView.model.openPasswordOn
  57. self.data.permissionString = self.securityContentView.model.ownerPassword
  58. self.data.isPermission = self.securityContentView.model.ownerPasswordOn
  59. if self.securityContentView.model.printAllowed {
  60. self.data.restrictOptions.insert(.print)
  61. } else {
  62. self.data.restrictOptions.remove(.print)
  63. }
  64. if self.securityContentView.model.editAllowed {
  65. self.data.restrictOptions.insert(.copy)
  66. } else {
  67. self.data.restrictOptions.remove(.copy)
  68. }
  69. if self.data.openPasswordString == self.data.permissionString {
  70. let alert = NSAlert()
  71. alert.alertStyle = .critical
  72. alert.messageText = KMLocalizedString("The Open and Owner passwords cannot be the same. Please change either the Open or the Owner Password.", comment: "")
  73. alert.runModal()
  74. return
  75. }
  76. self.batchExport?(self, self.data)
  77. }
  78. }
  79. extension KMBatchSecurityView: KMBatchSecurityViewPresenterDelegate {
  80. func showData(presenter: KMBatchSecurityViewPresenter, data: KMBatchSecurityViewModel) {
  81. self.data = data
  82. self.reloadData()
  83. }
  84. }