/src/libreoffice/vcl/inc/printerinfomanager.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | #pragma once |
21 | | |
22 | | #include <memory> |
23 | | #include <vector> |
24 | | #include <unordered_map> |
25 | | #include <unordered_set> |
26 | | |
27 | | #include <vcl/dllapi.h> |
28 | | #include <vcl/prntypes.hxx> |
29 | | #include <osl/time.h> |
30 | | |
31 | | #include <cstdio> |
32 | | |
33 | | #include "jobdata.hxx" |
34 | | |
35 | | namespace psp |
36 | | { |
37 | | |
38 | | class SystemQueueInfo; |
39 | | |
40 | | struct PrinterInfo : JobData |
41 | | { |
42 | | // basename of PPD |
43 | | OUString m_aDriverName; |
44 | | // can be the queue |
45 | | OUString m_aLocation; |
46 | | // a user defined comment |
47 | | OUString m_aComment; |
48 | | // a command line to pipe a PS-file to |
49 | | OUString m_aCommand; |
50 | | // a command line to pipe a PS-file to in case of direct print |
51 | | OUString m_aQuickCommand; |
52 | | // a list of special features separated by ',' not used by psprint |
53 | | // but assigned from the outside (currently for "fax","pdf=","autoqueue","external_dialog") |
54 | | OUString m_aFeatures; |
55 | | // auth-info-required, potential [domain],[username],[password] to prompt for to authenticate printing |
56 | | OUString m_aAuthInfoRequired; |
57 | | PrinterSetupMode meSetupMode; |
58 | | |
59 | | PrinterInfo() |
60 | 0 | : JobData() |
61 | 0 | , meSetupMode(PrinterSetupMode::SingleJob) |
62 | 0 | {} |
63 | | }; |
64 | | |
65 | | class VCL_DLLPUBLIC PrinterInfoManager |
66 | | { |
67 | | public: |
68 | | enum class Type { Default = 0, CUPS = 1, CPD = 2 }; |
69 | | |
70 | | struct SystemPrintQueue |
71 | | { |
72 | | OUString m_aQueue; |
73 | | OUString m_aLocation; |
74 | | OUString m_aComment; |
75 | | }; |
76 | | protected: |
77 | | // needed for checkPrintersChanged: files (not necessarily existent) |
78 | | // and their last known modification time |
79 | | struct WatchFile |
80 | | { |
81 | | // the file in question |
82 | | OUString m_aFilePath; |
83 | | // the last know modification time or 0, if file did not exist |
84 | | TimeValue m_aModified; |
85 | | }; |
86 | | |
87 | | std::unordered_map<OUString, PrinterInfo> m_aPrinters; |
88 | | PrinterInfo m_aGlobalDefaults; |
89 | | std::vector< WatchFile > m_aWatchFiles; |
90 | | OUString m_aDefaultPrinter; |
91 | | OUString m_aSystemPrintCommand; |
92 | | |
93 | | std::vector< SystemPrintQueue > m_aSystemPrintQueues; |
94 | | |
95 | | std::unique_ptr<SystemQueueInfo> |
96 | | m_pQueueInfo; |
97 | | |
98 | | Type m_eType; |
99 | | OUString m_aSystemDefaultPaper; |
100 | | |
101 | | PrinterInfoManager( Type eType = Type::Default ); |
102 | | |
103 | | virtual void initialize(); |
104 | | |
105 | | // fill default paper if not configured in config file |
106 | | // default paper is e.g. locale dependent |
107 | | // if a paper is already set it will not be overwritten |
108 | | void setDefaultPaper( PPDContext& rInfo ) const; |
109 | | |
110 | | public: |
111 | | |
112 | | // there can only be one |
113 | | static PrinterInfoManager& get(); |
114 | | |
115 | | // get PrinterInfoManager type |
116 | 0 | Type getType() const { return m_eType; } |
117 | | |
118 | | // retrieve all known printers |
119 | 0 | const std::unordered_map<OUString, PrinterInfo>& getPrinters() const { return m_aPrinters; } |
120 | | |
121 | | // gets info about a named printer |
122 | | const PrinterInfo& getPrinterInfo( const OUString& rPrinter ) const; |
123 | | |
124 | | // gets the name of the default printer |
125 | 0 | const OUString& getDefaultPrinter() const { return m_aDefaultPrinter; } |
126 | | |
127 | | virtual void setupJobContextData( JobData& rData ); |
128 | | |
129 | | // check if the printer configuration has changed |
130 | | // if bwait is true, then this method waits for eventual asynchronous |
131 | | // printer discovery to finish |
132 | | virtual bool checkPrintersChanged( bool bWait ); |
133 | | |
134 | | // abstract print command |
135 | | // returns a stdio FILE* that a postscript file may be written to |
136 | | // this may either be a regular file or the result of popen() |
137 | | virtual FILE* startSpool( const OUString& rPrinterName, bool bQuickCommand ); |
138 | | // close the FILE* returned by startSpool and does the actual spooling |
139 | | // set bBanner to "false" will attempt to suppress banner printing |
140 | | // set bBanner to "true" will rely on the system default |
141 | | // returns true on success |
142 | | virtual bool endSpool( const OUString& rPrinterName, const OUString& rJobTitle, FILE* pFile, const JobData& rDocumentJobData, bool bBanner, const OUString &rFaxNumber ); |
143 | | |
144 | | // check whether a printer's feature string contains a subfeature |
145 | | bool checkFeatureToken( const OUString& rPrinterName, std::string_view pToken ) const; |
146 | | |
147 | | virtual ~PrinterInfoManager(); |
148 | | }; |
149 | | |
150 | | } // namespace |
151 | | |
152 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |