1c36cf2e9Sopenharmony_ci/* 2c36cf2e9Sopenharmony_ci * Copyright (c) 2023-2023 Huawei Device Co., Ltd. 3c36cf2e9Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4c36cf2e9Sopenharmony_ci * you may not use this file except in compliance with the License. 5c36cf2e9Sopenharmony_ci * You may obtain a copy of the License at 6c36cf2e9Sopenharmony_ci * 7c36cf2e9Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8c36cf2e9Sopenharmony_ci * 9c36cf2e9Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10c36cf2e9Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11c36cf2e9Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12c36cf2e9Sopenharmony_ci * See the License for the specific language governing permissions and 13c36cf2e9Sopenharmony_ci * limitations under the License. 14c36cf2e9Sopenharmony_ci */ 15c36cf2e9Sopenharmony_ci 16c36cf2e9Sopenharmony_ciimport { PrinterFoundType } from '../model/PrintBean'; 17c36cf2e9Sopenharmony_ci 18c36cf2e9Sopenharmony_ci/** 19c36cf2e9Sopenharmony_ci * printer utils 20c36cf2e9Sopenharmony_ci */ 21c36cf2e9Sopenharmony_ciexport class PrinterUtils { 22c36cf2e9Sopenharmony_ci private static usb: string = 'USB'; 23c36cf2e9Sopenharmony_ci private static p2p: string = 'P2P'; 24c36cf2e9Sopenharmony_ci 25c36cf2e9Sopenharmony_ci /** 26c36cf2e9Sopenharmony_ci * convert printer type 27c36cf2e9Sopenharmony_ci * 28c36cf2e9Sopenharmony_ci * @param printerId printerId 29c36cf2e9Sopenharmony_ci */ 30c36cf2e9Sopenharmony_ci public static getPrinterFoundType(printerId: string): PrinterFoundType { 31c36cf2e9Sopenharmony_ci if (printerId == null || printerId.length < 0) { 32c36cf2e9Sopenharmony_ci return PrinterFoundType.FROM_P2P; 33c36cf2e9Sopenharmony_ci } 34c36cf2e9Sopenharmony_ci 35c36cf2e9Sopenharmony_ci let upPrinterId = printerId.toUpperCase(); 36c36cf2e9Sopenharmony_ci if (upPrinterId.includes(this.usb)) { 37c36cf2e9Sopenharmony_ci return PrinterFoundType.FROM_USB; 38c36cf2e9Sopenharmony_ci } else if (upPrinterId.includes(this.p2p)) { 39c36cf2e9Sopenharmony_ci return PrinterFoundType.FROM_P2P; 40c36cf2e9Sopenharmony_ci } else { 41c36cf2e9Sopenharmony_ci return PrinterFoundType.FROM_LOCAL_NET; 42c36cf2e9Sopenharmony_ci } 43c36cf2e9Sopenharmony_ci } 44c36cf2e9Sopenharmony_ci}