KMNHomeQuickToolManager.swift 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. //
  2. // KMNHomeQuickToolManager.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by 丁林圭 on 2024/10/12.
  6. //
  7. import Cocoa
  8. @objc public enum HomeQuickToolType: Int, CaseIterable{
  9. case Batch = 0 // 批量处理
  10. case MergePDF // 合并
  11. case ImageToPDF // 图片转PDF
  12. case OCR // 批量OCR
  13. case ConvertPDF // 转换PDF
  14. case PDFToWord // PDF转Word
  15. case PDFToExcel // PDF转Excel
  16. case Compression // 压缩
  17. case PDFToPPT // PDF转PPT
  18. case Security // 安全
  19. case FileCompare // 文件对比
  20. case Watermark // 水印
  21. case Insert // 插入
  22. case Extract // 提取
  23. case DigitalSignature //数字签名
  24. case Print //print
  25. }
  26. //MARK: - KMNHomeQuickToolMode
  27. class KMNHomeQuickToolMode: NSObject {
  28. var toolImageName: String = "" //图片名称
  29. var toolTitle: String = "" //主标题
  30. var toolSubtitle: String = "" //副标题
  31. var quickToolType: HomeQuickToolType = .Batch //副标题
  32. var isNewState: Bool = false //是否新的功能
  33. class func toolModeData(type: HomeQuickToolType) -> KMNHomeQuickToolMode {
  34. let mode: KMNHomeQuickToolMode = KMNHomeQuickToolMode()
  35. mode.quickToolType = type
  36. switch type {
  37. case .Batch:
  38. mode.toolTitle = KMLocalizedString("Batch")
  39. mode.toolSubtitle = KMLocalizedString("Batch convert, compress, secure, watermark PDFs")
  40. mode.toolImageName = "KMNImageNameQuickToolBatch"
  41. mode.isNewState = true
  42. break
  43. case .OCR:
  44. mode.toolTitle = KMLocalizedString("OCR")
  45. mode.toolSubtitle = KMLocalizedString("Recognize text from images or scanned PDF with OCR")
  46. mode.toolImageName = "KMNImageNameQuickToolOCR"
  47. break
  48. case .ConvertPDF:
  49. mode.toolTitle = KMLocalizedString("Convert PDF")
  50. mode.toolSubtitle = KMLocalizedString("Convert PDFs to Word/HTML/TXT/JPEG/PNG files")
  51. mode.toolImageName = "KMNImageNameQuickToolConvert"
  52. mode.isNewState = true
  53. break
  54. case .ImageToPDF:
  55. mode.toolTitle = KMLocalizedString("Image To PDF")
  56. mode.toolSubtitle = KMLocalizedString("Convert JPEG/JPG/PNG/TIFF/BMP/PSD files to PDFs")
  57. mode.toolImageName = "KMNImageNameQuickToolImageToPDF"
  58. break
  59. case .MergePDF:
  60. mode.toolTitle = KMLocalizedString("Merge")
  61. mode.toolSubtitle = KMLocalizedString("Combine multiple documents into a new PDF file")
  62. mode.toolImageName = "KMNImageNameQuickToolMerge"
  63. break
  64. case .Compression:
  65. mode.toolTitle = KMLocalizedString("Compress")
  66. mode.toolSubtitle = KMLocalizedString("Reduce files size to make sure you can easily send them by email.")
  67. mode.toolImageName = "KMNImageNameQuickToolCompress"
  68. break
  69. case .Security:
  70. mode.toolTitle = KMLocalizedString("Security")
  71. mode.toolSubtitle = KMLocalizedString("Easily batch encrypt PDFs or decrypt the protected files")
  72. mode.toolImageName = "KMNImageNameQuickToolSecurity"
  73. break
  74. case .FileCompare:
  75. mode.toolTitle = KMLocalizedString("Compare")
  76. mode.toolSubtitle = KMLocalizedString("Compare the differences between two files")
  77. mode.toolImageName = "KMNImageNameQuickToolCompare"
  78. break
  79. case .PDFToPPT:
  80. mode.toolTitle = KMLocalizedString("PDF To PPT")
  81. mode.toolSubtitle = KMLocalizedString("Turn your PDF into a formatted PPT file that you can edit")
  82. mode.toolImageName = "KMNImageNameQuickToolToPPT"
  83. break
  84. case .PDFToExcel:
  85. mode.toolTitle = KMLocalizedString("PDF To Excel")
  86. mode.toolSubtitle = KMLocalizedString("Turn PDF table into a formatted Excel file")
  87. mode.toolImageName = "KMNImageNameQuickToolToExcel"
  88. break
  89. case .PDFToWord:
  90. mode.toolTitle = KMLocalizedString("PDF To Word")
  91. mode.toolSubtitle = KMLocalizedString("Convert PDFs to Word, Fonts & formatting get converted")
  92. mode.toolImageName = "KMNImageNameQuickToolToWord"
  93. break
  94. case .Watermark:
  95. mode.toolTitle = KMLocalizedString("Watermark")
  96. mode.toolSubtitle = KMLocalizedString("Protect PDFs with image/text watermarks from plagiarism")
  97. mode.toolImageName = "KMNImageNameQuickToolWater"
  98. break
  99. case .Extract:
  100. mode.toolTitle = KMLocalizedString("Extract")
  101. mode.toolSubtitle = KMLocalizedString("Extract selected pages to a new PDF")
  102. mode.toolImageName = "KMNImageNameQuickToolExtra"
  103. break
  104. case .Insert:
  105. mode.toolTitle = KMLocalizedString("Insert")
  106. mode.toolSubtitle = KMLocalizedString("Inserting pages into an existing PDF")
  107. mode.toolImageName = "KMNImageNameQuickToolInsert"
  108. case .DigitalSignature:
  109. mode.toolTitle = KMLocalizedString("Digital Signature")
  110. mode.toolSubtitle = KMLocalizedString("Delete/Rotate/Copy/Paste PDF pages")
  111. mode.toolImageName = "KMNImageNameQuickToolDigitalSignature"
  112. case .Print:
  113. mode.toolTitle = KMLocalizedString("Print")
  114. mode.toolSubtitle = KMLocalizedString("Powerful PDF printer allows to print PDF from any computer without much hassle")
  115. mode.toolImageName = "KMNImageNameQuickToolPrint"
  116. mode.isNewState = true
  117. }
  118. return mode
  119. }
  120. }
  121. class KMNHomeQuickToolManager: NSObject {
  122. var quickToolsItemMutableArray: [Int] = [] {
  123. didSet {
  124. UserDefaults.standard.set(quickToolsItemMutableArray, forKey: "kmnHomeQucikToolsItemArrayKey")
  125. UserDefaults.standard.synchronize()
  126. }
  127. }
  128. var fullToolsItemMutableArray: [Int] = [] {
  129. didSet {
  130. UserDefaults.standard.set(fullToolsItemMutableArray, forKey: "kmnHomeQucikToolsFullItemsArrayKey")
  131. UserDefaults.standard.synchronize()
  132. }
  133. }
  134. var collapseTools: Bool = false {
  135. didSet {
  136. UserDefaults.standard.set(collapseTools ? "1":"0", forKey: "quickToolsCollapseKey")
  137. UserDefaults.standard.synchronize()
  138. }
  139. }
  140. static let defaultManager: KMNHomeQuickToolManager = {
  141. let singleton = KMNHomeQuickToolManager()
  142. return singleton
  143. }()
  144. private override init() {
  145. let key = "kmnHomeQucikToolsItemArrayKey"
  146. if UserDefaults.standard.object(forKey: key) != nil {
  147. quickToolsItemMutableArray = UserDefaults.standard.array(forKey: key) as? [Int] ?? []
  148. } else {
  149. quickToolsItemMutableArray = [HomeQuickToolType.Batch.rawValue,
  150. HomeQuickToolType.MergePDF.rawValue,
  151. HomeQuickToolType.ImageToPDF.rawValue,
  152. HomeQuickToolType.OCR.rawValue,
  153. HomeQuickToolType.ConvertPDF.rawValue,
  154. HomeQuickToolType.PDFToWord.rawValue,
  155. HomeQuickToolType.PDFToExcel.rawValue,
  156. HomeQuickToolType.Compression.rawValue]
  157. UserDefaults.standard.set(quickToolsItemMutableArray, forKey: key)
  158. UserDefaults.standard.synchronize()
  159. }
  160. if UserDefaults.standard.object(forKey: "quickToolsCollapseKey") != nil {
  161. self.collapseTools = UserDefaults.standard.bool(forKey: "quickToolsCollapseKey")
  162. } else {
  163. self.collapseTools = false
  164. UserDefaults.standard.setValue(collapseTools ? "1" : "0", forKey: "quickToolsCollapseKey")
  165. UserDefaults.standard.synchronize()
  166. }
  167. let fullKey = "kmnHomeQucikToolsFullItemsArrayKey"
  168. if UserDefaults.standard.object(forKey: fullKey) != nil {
  169. fullToolsItemMutableArray = UserDefaults.standard.array(forKey: fullKey) as? [Int] ?? []
  170. } else {
  171. fullToolsItemMutableArray = [HomeQuickToolType.Batch.rawValue,
  172. HomeQuickToolType.MergePDF.rawValue,
  173. HomeQuickToolType.ImageToPDF.rawValue,
  174. HomeQuickToolType.OCR.rawValue,
  175. HomeQuickToolType.ConvertPDF.rawValue,
  176. HomeQuickToolType.PDFToWord.rawValue,
  177. HomeQuickToolType.PDFToExcel.rawValue,
  178. HomeQuickToolType.Compression.rawValue,
  179. HomeQuickToolType.PDFToPPT.rawValue,
  180. HomeQuickToolType.Security.rawValue,
  181. HomeQuickToolType.FileCompare.rawValue,
  182. HomeQuickToolType.Watermark.rawValue,
  183. HomeQuickToolType.Insert.rawValue,
  184. HomeQuickToolType.Extract.rawValue,
  185. HomeQuickToolType.DigitalSignature.rawValue,
  186. HomeQuickToolType.Print.rawValue]
  187. UserDefaults.standard.set(fullToolsItemMutableArray, forKey: fullKey)
  188. UserDefaults.standard.synchronize()
  189. }
  190. }
  191. }