1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_PRINTERINFOMANAGER_HXX
21 #define INCLUDED_VCL_PRINTERINFOMANAGER_HXX
25 #include <unordered_map>
26 #include <unordered_set>
28 #include <vcl/dllapi.h>
29 #include <vcl/prntypes.hxx>
34 #include "jobdata.hxx"
39 class SystemQueueInfo
;
41 struct PrinterInfo
: JobData
44 OUString m_aDriverName
;
47 // a user defined comment
49 // a command line to pipe a PS-file to
51 // a command line to pipe a PS-file to in case of direct print
52 OUString m_aQuickCommand
;
53 // a list of special features separated by ',' not used by psprint
54 // but assigned from the outside (currently for "fax","pdf=","autoqueue","external_dialog")
56 // auth-info-required, potential [domain],[username],[password] to prompt for to authenticate printing
57 OUString m_aAuthInfoRequired
;
58 PrinterSetupMode meSetupMode
;
62 , meSetupMode(PrinterSetupMode::SingleJob
)
66 class VCL_DLLPUBLIC PrinterInfoManager
69 enum class Type
{ Default
= 0, CUPS
= 1, CPD
= 2 };
71 struct SystemPrintQueue
78 // needed for checkPrintersChanged: files (not necessarily existent)
79 // and their last known modification time
82 // the file in question
84 // the last know modification time or 0, if file did not exist
85 TimeValue m_aModified
;
88 // internal data to describe a printer
91 // configuration file containing this printer
92 // empty means a freshly added printer that has to be saved yet
94 // details other config files that have this printer
95 // in case of removal all have to be removed
96 std::unordered_set
< OUString
> m_aAlternateFiles
;
97 // the corresponding info and job data
101 std::unordered_map
< OUString
, Printer
> m_aPrinters
;
102 PrinterInfo m_aGlobalDefaults
;
103 std::vector
< WatchFile
> m_aWatchFiles
;
104 OUString m_aDefaultPrinter
;
105 OUString m_aSystemPrintCommand
;
107 std::vector
< SystemPrintQueue
> m_aSystemPrintQueues
;
109 std::unique_ptr
<SystemQueueInfo
>
113 bool m_bUseIncludeFeature
;
115 OUString m_aSystemDefaultPaper
;
117 PrinterInfoManager( Type eType
= Type::Default
);
119 virtual void initialize();
121 // fill default paper if not configured in config file
122 // default paper is e.g. locale dependent
123 // if a paper is already set it will not be overwritten
124 void setDefaultPaper( PPDContext
& rInfo
) const;
128 // there can only be one
129 static PrinterInfoManager
& get();
131 // get PrinterInfoManager type
132 Type
getType() const { return m_eType
; }
134 // lists the names of all known printers
135 void listPrinters( std::vector
< OUString
>& rVector
) const;
137 // gets info about a named printer
138 const PrinterInfo
& getPrinterInfo( const OUString
& rPrinter
) const;
140 // gets the name of the default printer
141 const OUString
& getDefaultPrinter() const { return m_aDefaultPrinter
; }
143 virtual void setupJobContextData( JobData
& rData
);
145 // check if the printer configuration has changed
146 // if bwait is true, then this method waits for eventual asynchronous
147 // printer discovery to finish
148 virtual bool checkPrintersChanged( bool bWait
);
150 // abstract print command
151 // returns a stdio FILE* that a postscript file may be written to
152 // this may either be a regular file or the result of popen()
153 virtual FILE* startSpool( const OUString
& rPrinterName
, bool bQuickCommand
);
154 // close the FILE* returned by startSpool and does the actual spooling
155 // set bBanner to "false" will attempt to suppress banner printing
156 // set bBanner to "true" will rely on the system default
157 // returns true on success
158 virtual bool endSpool( const OUString
& rPrinterName
, const OUString
& rJobTitle
, FILE* pFile
, const JobData
& rDocumentJobData
, bool bBanner
, const OUString
&rFaxNumber
);
160 bool getUseIncludeFeature() const { return m_bUseIncludeFeature
; }
161 bool getUseJobPatch() const { return m_bUseJobPatch
; }
163 // check whether a printer's feature string contains a subfeature
164 bool checkFeatureToken( const OUString
& rPrinterName
, const char* pToken
) const;
166 virtual ~PrinterInfoManager();
171 #endif // INCLUDED_VCL_PRINTERINFOMANAGER_HXX
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */