123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- //
- // KMDeviceBrowserWindowController.swift
- // PDF Reader Pro
- //
- // 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?
-
- static let shared = KMDeviceBrowserWindowController(windowNibName: "KMDeviceBrowserWindowController")
-
- deinit {
- KMPrint("KMDeviceBrowserWindowController 已释放.")
-
- self.deviceBrowserView?.delegate = nil
- self.cameraDeviceView?.delegate = nil
- self.scannerDeviceView?.delegate = nil
- }
-
- override func windowDidLoad() {
- super.windowDidLoad()
- if (self.type == .camera) {
- self.deviceBrowserView.displaysLocalScanners = false;
- self.deviceBrowserView.displaysNetworkScanners = false;
- } else if (self.type == .scanner) {
- self.deviceBrowserView.displaysLocalCameras = false;
- self.deviceBrowserView.displaysNetworkCameras = false;
- }
-
- self.cameraDeviceView.downloadSelectedControlLabel = NSLocalizedString("Import", comment: "")
- self.cameraDeviceView.downloadAllControlLabel = NSLocalizedString("Import All", comment: "")
- self.window!.title = NSLocalizedString("Import", comment: "")
- }
-
- }
- 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 != nil {
- if (device!.className == "ICCameraDevice") {
- cameraDeviceView.cameraDevice = (device as! ICCameraDevice)
- cameraDeviceView.isHidden = false
- scannerDeviceView.isHidden = true
- } else if (device.className == "ICScannerDevice") {
- scannerDeviceView.scannerDevice = (device as! ICScannerDevice)
- scannerDeviceView.isHidden = false
- cameraDeviceView.isHidden = true
- } else {
- cameraDeviceView.isHidden = true
- scannerDeviceView.isHidden = true
- }
- }
- }
-
- func deviceBrowserView(_ deviceBrowserView: IKDeviceBrowserView!, didEncounterError error: Error!) {
- KMPrint("111")
- }
- }
- extension KMDeviceBrowserWindowController: IKCameraDeviceViewDelegate {
- func cameraDeviceView(_ cameraDeviceView: IKCameraDeviceView, didDownloadFile file: ICCameraFile, location url: URL, fileData data: Data?, error: Error?) {
- file.imageRepresentationType()
- if error == nil {
- importCameraFileCallback?(url as NSURL)
- }
- }
- }
- 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)
- }
- }
- }
- }
|