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
24 #include <unordered_map>
26 #include <vcl/dllapi.h>
27 #include <vcl/helper.hxx>
28 #include <vcl/jobdata.hxx>
29 #include <osl/file.hxx>
36 class SystemQueueInfo
;
38 struct PrinterInfo
: JobData
41 OUString m_aDriverName
;
44 // a user defined comment
46 // a command line to pipe a PS-file to
48 // a command line to pipe a PS-file to in case of direct print
49 OUString m_aQuickCommand
;
50 // a list of special features separated by ',' not used by psprint
51 // but assigned from the outside (currently for "fax","pdf=","autoqueue","external_dialog")
53 bool m_bPapersizeFromSetup
;
57 , m_bPapersizeFromSetup(false)
61 class VCL_DLLPUBLIC PrinterInfoManager
64 enum Type
{ Default
= 0, CUPS
= 1 };
66 struct SystemPrintQueue
73 // needed for checkPrintersChanged: files (not necessarily existent)
74 // and their last known modification time
77 // the file in question
79 // the last know modification time or 0, if file did not exist
80 TimeValue m_aModified
;
83 // internal data to describe a printer
86 // configuration file containing this printer
87 // empty means a freshly added printer that has to be saved yet
89 // details other config files that have this printer
90 // in case of removal all have to be removed
91 std::list
< OUString
> m_aAlternateFiles
;
92 // group in m_aFile containing the printer
93 // this must be unique over all configuration files
94 // it usually should be the printer name
96 // whether changes need to be saved
98 // the corresponding info and job data
102 std::unordered_map
< OUString
, Printer
, OUStringHash
> m_aPrinters
;
103 PrinterInfo m_aGlobalDefaults
;
104 std::list
< WatchFile
> m_aWatchFiles
;
105 OUString m_aDefaultPrinter
;
106 OUString m_aSystemPrintCommand
;
108 std::list
< SystemPrintQueue
> m_aSystemPrintQueues
;
110 SystemQueueInfo
* m_pQueueInfo
;
113 bool m_bUseIncludeFeature
;
115 OUString m_aSystemDefaultPaper
;
117 PrinterInfoManager( Type eType
= 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;
126 void initSystemDefaultPaper();
129 // there can only be one
130 static PrinterInfoManager
& get();
131 // only called by SalData destructor, frees the global instance
132 static void release();
134 // get PrinterInfoManager type
135 Type
getType() const { return m_eType
; }
137 // lists the names of all known printers
138 void listPrinters( std::list
< OUString
>& rList
) const;
140 // gets the number of known printers
141 int countPrinters() const { return m_aPrinters
.size(); }
143 // gets info about a named printer
144 const PrinterInfo
& getPrinterInfo( const OUString
& rPrinter
) const;
146 // gets the name of the default printer
147 const OUString
& getDefaultPrinter() const { return m_aDefaultPrinter
; }
149 virtual void setupJobContextData( JobData
& rData
);
151 // changes the info about a named printer
152 virtual void changePrinterInfo( const OUString
& rPrinter
, const PrinterInfo
& rNewInfo
);
154 // check if the printer configuration has changed
155 // if bwait is true, then this method waits for eventual asynchronous
156 // printer discovery to finish
157 virtual bool checkPrintersChanged( bool bWait
);
159 // members for administration
161 // add a named printer
162 // addPrinter fails if a printer with the same name already exists
163 // or the driver does not exist
164 virtual bool addPrinter( const OUString
& rPrinterName
, const OUString
& rDriverName
);
166 // remove a named printer
167 // this fails if the config file belonging to this printer
169 // if bCheckOnly is true, the printer is not really removed;
170 // this is for checking if the removal would fail
171 virtual bool removePrinter( const OUString
& rPrinterName
, bool bCheckOnly
= false );
173 // save the changes to all printers. this fails if there
174 // is no writable config file at all
175 virtual bool writePrinterConfig();
177 // set a new default printer
178 // fails if the specified printer does not exist
179 virtual bool setDefaultPrinter( const OUString
& rPrinterName
);
181 // primarily used internally
182 // returns the printer queue names
183 const std::list
< SystemPrintQueue
>& getSystemPrintQueues();
185 // abstract print command
186 // returns a stdio FILE* that a postscript file may be written to
187 // this may either be a regular file or the result of popen()
188 virtual FILE* startSpool( const OUString
& rPrinterName
, bool bQuickCommand
);
189 // close the FILE* returned by startSpool and does the actual spooling
190 // set bBanner to "false" will attempt to suppress banner printing
191 // set bBanner to "true" will rely on the system default
192 // returns true on success
193 virtual bool endSpool( const OUString
& rPrinterName
, const OUString
& rJobTitle
, FILE* pFile
, const JobData
& rDocumentJobData
, bool bBanner
, const OUString
&rFaxNumber
);
195 bool getUseIncludeFeature() const { return m_bUseIncludeFeature
; }
196 bool getUseJobPatch() const { return m_bUseJobPatch
; }
198 // check whether a printer's feature string contains a subfeature
199 bool checkFeatureToken( const OUString
& rPrinterName
, const char* pToken
) const;
201 // Starts printing in a batch mode, in which all printing will be done together instead of separate jobs.
202 // If the implementation supports it, calls to endSpool() will only delay the printing until flushBatchPrint()
203 // is called to print all delayed jobs.
204 // Returns false if failed or not supported (in which case endSpool() will print normally).
205 virtual bool startBatchPrint();
206 // Actually spools all delayed print jobs, if enabled, and disables batch mode.
207 virtual bool flushBatchPrint();
208 // Returns true batch printing is supported at all.
209 virtual bool supportsBatchPrint() const;
211 virtual ~PrinterInfoManager();
216 #endif // INCLUDED_VCL_PRINTERINFOMANAGER_HXX
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */