KMDeviceBrowserWindowController.swift 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // KMDeviceBrowserWindowController.swift
  3. // PDF Master
  4. //
  5. // Created by wanjun on 2023/3/29.
  6. //
  7. import Cocoa
  8. import Quartz
  9. typealias ImportCameraFileCallback = (_ url: NSURL) -> ()
  10. typealias ImportScannerFileCallback = (_ url: NSURL) -> Void
  11. class KMDeviceBrowserWindowController: NSWindowController {
  12. @IBOutlet weak var splitView: NSSplitView!
  13. @IBOutlet weak var deviceBrowserView: IKDeviceBrowserView!
  14. @IBOutlet weak var cameraDeviceView: IKCameraDeviceView!
  15. @IBOutlet weak var scannerDeviceView: IKScannerDeviceView!
  16. var type: ICDeviceType = .camera
  17. var importCameraFileCallback: ImportCameraFileCallback?
  18. var importScannerFileCallback: ImportScannerFileCallback?
  19. override func windowDidLoad() {
  20. super.windowDidLoad()
  21. self.deviceBrowserView.displaysLocalCameras = false
  22. self.deviceBrowserView.displaysNetworkCameras = false
  23. self.splitView.setPosition(300.0, ofDividerAt: 0)
  24. }
  25. }
  26. extension KMDeviceBrowserWindowController: NSSplitViewDelegate {
  27. func splitView(_ splitView: NSSplitView, constrainMinCoordinate proposedMinimumPosition: CGFloat, ofSubviewAt dividerIndex: Int) -> CGFloat {
  28. return 150.0
  29. }
  30. func splitView(_ splitView: NSSplitView, constrainMaxCoordinate proposedMaximumPosition: CGFloat, ofSubviewAt dividerIndex: Int) -> CGFloat {
  31. return 300.0
  32. }
  33. }
  34. extension KMDeviceBrowserWindowController: IKDeviceBrowserViewDelegate {
  35. func deviceBrowserView(_ deviceBrowserView: IKDeviceBrowserView!, selectionDidChange device: ICDevice!) {
  36. // if (device.type == .camera) {
  37. // cameraDeviceView.cameraDevice = (device as! ICCameraDevice)
  38. // cameraDeviceView.isHidden = false
  39. // cameraDeviceView.isHidden = true
  40. // } else if (device.type == .scanner) {
  41. // scannerDeviceView.scannerDevice = (device as! ICScannerDevice)
  42. // scannerDeviceView.isHidden = false
  43. // scannerDeviceView.isHidden = true
  44. // } else {
  45. // scannerDeviceView.isHidden = true
  46. // scannerDeviceView.isHidden = true
  47. // }
  48. if device != nil {
  49. scannerDeviceView.scannerDevice = (device as! ICScannerDevice)
  50. cameraDeviceView.isHidden = false
  51. cameraDeviceView.isHidden = true
  52. }
  53. }
  54. func deviceBrowserView(_ deviceBrowserView: IKDeviceBrowserView!, didEncounterError error: Error!) {
  55. print("111")
  56. }
  57. }
  58. extension KMDeviceBrowserWindowController: IKCameraDeviceViewDelegate {
  59. func cameraDeviceView(_ cameraDeviceView: IKCameraDeviceView!, didDownloadFile file: ICCameraFile!, location url: URL!, fileData data: Data!, error: Error!) {
  60. // if (!error &&
  61. // [file.UTI isEqualToString:(NSString *)kUTTypeImage]) {
  62. // if (self.importCameraFileCallback) {
  63. // self.importCameraFileCallback(url);
  64. // }
  65. // }
  66. print("获取图片完成")
  67. }
  68. }
  69. extension KMDeviceBrowserWindowController: IKScannerDeviceViewDelegate {
  70. func scannerDeviceView(_ scannerDeviceView: IKScannerDeviceView!, didScanTo url: URL!, fileData data: Data!, error: Error!) {
  71. if ((error == nil) && (url != nil)) {
  72. if let callback = importScannerFileCallback {
  73. callback(url! as NSURL)
  74. }
  75. }
  76. }
  77. }