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 print from '@ohos.print';
17c36cf2e9Sopenharmony_ciimport { Log, PrinterExtensionInfo } from '@ohos/common';
18c36cf2e9Sopenharmony_ciimport AppStorageHelper from '../Common/Adapter/AppStorageHelper';
19c36cf2e9Sopenharmony_ciimport {AppStorageKeyName} from '@ohos/common';
20c36cf2e9Sopenharmony_ciimport {PrintExtensionModel} from '../Model/PrintExtensionModel';
21c36cf2e9Sopenharmony_ci
22c36cf2e9Sopenharmony_ciconst TAG = '[PrintExtensionController]:';
23c36cf2e9Sopenharmony_ci
24c36cf2e9Sopenharmony_ci/**
25c36cf2e9Sopenharmony_ci * PrintExtensionController
26c36cf2e9Sopenharmony_ci *
27c36cf2e9Sopenharmony_ci */
28c36cf2e9Sopenharmony_ciexport class PrintExtensionController {
29c36cf2e9Sopenharmony_ci    private mPrintExtensionModel : PrintExtensionModel = new PrintExtensionModel()
30c36cf2e9Sopenharmony_ci
31c36cf2e9Sopenharmony_ci    /**
32c36cf2e9Sopenharmony_ci     * init
33c36cf2e9Sopenharmony_ci     *
34c36cf2e9Sopenharmony_ci     */
35c36cf2e9Sopenharmony_ci    public init() : void {
36c36cf2e9Sopenharmony_ci        Log.info(TAG, 'PrintExtensionController init')
37c36cf2e9Sopenharmony_ci        AppStorageHelper.createValue<Array<PrinterExtensionInfo>>(this.getModel().getPrintExtensions, AppStorageKeyName.PRINT_EXTENSION_LIST_NAME)
38c36cf2e9Sopenharmony_ci    }
39c36cf2e9Sopenharmony_ci
40c36cf2e9Sopenharmony_ci    /**
41c36cf2e9Sopenharmony_ci     * get all printExtension
42c36cf2e9Sopenharmony_ci     */
43c36cf2e9Sopenharmony_ci    public getAllPrintExtension() : void {
44c36cf2e9Sopenharmony_ci        Log.info(TAG, 'queryPrinterCapability')
45c36cf2e9Sopenharmony_ci        print.queryAllPrinterExtensionInfos().then((data)=> {
46c36cf2e9Sopenharmony_ci            Log.info(TAG, 'start connect Printer success data : ' )
47c36cf2e9Sopenharmony_ci            this.getModel().dealGetAllPrintExtension(data)
48c36cf2e9Sopenharmony_ci        }).catch((err)=> {
49c36cf2e9Sopenharmony_ci            Log.error(TAG, 'failed to get AllPrintExtension because ' + JSON.stringify(err));
50c36cf2e9Sopenharmony_ci        });
51c36cf2e9Sopenharmony_ci    }
52c36cf2e9Sopenharmony_ci
53c36cf2e9Sopenharmony_ci    /**
54c36cf2e9Sopenharmony_ci     * get model
55c36cf2e9Sopenharmony_ci     *
56c36cf2e9Sopenharmony_ci     * @return PrintExtensionModel
57c36cf2e9Sopenharmony_ci     */
58c36cf2e9Sopenharmony_ci    public getModel() : PrintExtensionModel {
59c36cf2e9Sopenharmony_ci        return this.mPrintExtensionModel
60c36cf2e9Sopenharmony_ci    }
61c36cf2e9Sopenharmony_ci}