123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- //
- // KMDeviceBrowserWindowController.swift
- // PDF Master
- //
- // Created by wanjun on 2023/3/29.
- //
- import Cocoa
- import Quartz
- typealias ImportCameraFileCallback = (_ url: NSURL) -> ()
- typealias ImportScannerFileCallback = (_ url: NSURL) -> Void
- class KMDeviceBrowserWindowController: NSWindowController {
- @IBOutlet weak var splitView: NSSplitView!
- @IBOutlet weak var deviceBrowserView: IKDeviceBrowserView!
- @IBOutlet weak var cameraDeviceView: IKCameraDeviceView!
- @IBOutlet weak var scannerDeviceView: IKScannerDeviceView!
-
- var type: ICDeviceType = .camera
-
- var importCameraFileCallback: ImportCameraFileCallback?
- var importScannerFileCallback: ImportScannerFileCallback?
- override func windowDidLoad() {
- super.windowDidLoad()
-
- self.deviceBrowserView.displaysLocalCameras = false
- self.deviceBrowserView.displaysNetworkCameras = false
-
- self.splitView.setPosition(300.0, ofDividerAt: 0)
- }
-
- }
- extension KMDeviceBrowserWindowController: NSSplitViewDelegate {
- func splitView(_ splitView: NSSplitView, constrainMinCoordinate proposedMinimumPosition: CGFloat, ofSubviewAt dividerIndex: Int) -> CGFloat {
- return 150.0
- }
-
- func splitView(_ splitView: NSSplitView, constrainMaxCoordinate proposedMaximumPosition: CGFloat, ofSubviewAt dividerIndex: Int) -> CGFloat {
- return 300.0
- }
- }
- extension KMDeviceBrowserWindowController: IKDeviceBrowserViewDelegate {
- func deviceBrowserView(_ deviceBrowserView: IKDeviceBrowserView!, selectionDidChange device: ICDevice!) {
- // if (device.type == .camera) {
- // cameraDeviceView.cameraDevice = (device as! ICCameraDevice)
- // cameraDeviceView.isHidden = false
- // cameraDeviceView.isHidden = true
- // } else if (device.type == .scanner) {
- // scannerDeviceView.scannerDevice = (device as! ICScannerDevice)
- // scannerDeviceView.isHidden = false
- // scannerDeviceView.isHidden = true
- // } else {
- // scannerDeviceView.isHidden = true
- // scannerDeviceView.isHidden = true
- // }
- if device != nil {
- scannerDeviceView.scannerDevice = (device as! ICScannerDevice)
- cameraDeviceView.isHidden = false
- cameraDeviceView.isHidden = true
- }
- }
-
- func deviceBrowserView(_ deviceBrowserView: IKDeviceBrowserView!, didEncounterError error: Error!) {
- print("111")
- }
- }
- extension KMDeviceBrowserWindowController: IKCameraDeviceViewDelegate {
- func cameraDeviceView(_ cameraDeviceView: IKCameraDeviceView!, didDownloadFile file: ICCameraFile!, location url: URL!, fileData data: Data!, error: Error!) {
- // if (!error &&
- // [file.UTI isEqualToString:(NSString *)kUTTypeImage]) {
- // if (self.importCameraFileCallback) {
- // self.importCameraFileCallback(url);
- // }
- // }
- print("获取图片完成")
- }
- }
- extension KMDeviceBrowserWindowController: IKScannerDeviceViewDelegate {
- func scannerDeviceView(_ scannerDeviceView: IKScannerDeviceView!, didScanTo url: URL!, fileData data: Data!, error: Error!) {
- if ((error == nil) && (url != nil)) {
- if let callback = importScannerFileCallback {
- callback(url! as NSURL)
- }
- }
- }
- }
|